devNotes 4-21-16 tcq implementation – hex mapping and indexing

gdgbdgfb

 

    void Create_GP(int depth)
    {
        for(int i = 0; i<20; i++)
        {
            Vector3 v0 = aMD.vertices[aMD.triangles[i*3]];
            Vector3 v1 = aMD.vertices[aMD.triangles[i*3 +1]];
            Vector3 v2 = aMD.vertices[aMD.triangles[i*3 + 2]];
            Color col = getWhite();
            subdivide(v0, v1, v2, depth, col);
        }
    }

    void addTriangle(Vector3 v0, Vector3 v1, Vector3 v2, Color col)
    {

        mD_Tri.Clear();
        mD_Tri = MeshDraft.Triangle(v0, v1, v2);
        mD_Tri.Paint(col);

        aMD_IcosaSphere.AddTriQual(mD_Tri);
    }

    void subdivide(Vector3 v1, Vector3 v2, Vector3 v3, int depth, Color col)
    {
        Vector3 v12, v23, v31;
        Vector3 v12_n, v23_n, v31_n;
        int i;

        if (depth == 0)
        {
            addTriangle(v1, v2, v3, col);
            return;
        }

        v12 = (v1 + v2) / 2.0f;
        v23 = (v2 + v3) / 2.0f;
        v31 = (v3 + v1) / 2.0f;

        /* extrude midpoints to lie on unit sphere */
        v12_n = v12.normalized * radius;
        v23_n = v23.normalized * radius;
        v31_n = v31.normalized * radius;

        /* recursively subdivide new triangles */
        subdivide(v1, v12_n, v31_n, depth - 1, col);
        subdivide(v2, v23_n, v12_n, depth - 1, col);
        subdivide(v3, v31_n, v23_n, depth - 1, col);
        subdivide(v12_n, v23_n, v31_n, depth - 1, col);
    }

 

Untitled-17

New Mesh Generation from IcoSphere

 

Subdivide as above

 

 

 

http://bmcbioinformatics.biomedcentral.com/articles/10.1186/1471-2105-11-352

unroll

Instead of stamping, unroll it.

hiohihihi

 

dgfbfgddbg

        int iQuality = TriQual.UNDEFINED;

        float x, y;

        for (int i = 0; i < numVerts - 2; i += 3)
        {
            //Triangle Center Location for test
            vTC = tCent[tL[i]];//requires this.transform at origin - can generalize

            if (Vector3.Dot(vTC, transform.forward) > 0f) //mirrors directly backwards otherwise
            {
                //project onto UV Plane
                vTCProjection.x = Vector3.Dot(vTC, transform.right) * cosaHedra.radius / Vector3.Dot(vTC, transform.forward);
                vTCProjection.y = Vector3.Dot(vTC, transform.up) * cosaHedra.radius / Vector3.Dot(vTC, transform.forward);
                vTCProjection.z = 0f; //2D UV Plane

                if (vTCProjection.magnitude < m_fRadius_UV)//in range of texture
                {
                    //Determine Triangle Center quality here
                    iQuality = Find_UV_PointQuality(vTCProjection);

                    for (int k = i; k < i + 3; k++)
                    {
                        vVert = vL[tL[k]];
                        vVProj.x = Vector3.Dot(vVert, transform.right) * cosaHedra.radius / Vector3.Dot(vVert, transform.forward);
                        vVProj.y = Vector3.Dot(vVert, transform.up) * cosaHedra.radius / Vector3.Dot(vVert, transform.forward);
                        vVProj.z = 0f;

                        vVProj /= m_fRadius_UV * 2;

                        x = 0.5f + vVProj.x;
                        y = 0.5f + vVProj.y;


                        if (x >= 0 && x <= 1 && y >= 0 && y <= 1)//Check if each triangle vertex is within bounds of texture
                        {
                            uv[k - i] = new Vector2(x, y);
                        }
                        else reject = true;
                    }
                    if (!reject && iQuality < tQual[tL[i]])
                    {
                        for (int k = i; k < i + 3; k++)
                        {
                            uvL[tL[k]] = uv[k - i];
                            tQual[tL[i]] = iQuality;
                        }
                    }
                    reject = false;
                }
            }
        }
        cosaHedra.writeMesh();

ghnfhgn7

    public void Paint_UV(float fCelHeight)
    {
        Vector3 cPos = transform.forward * cosaHedra.radius;//m_vPointingLoc

        ICO_ArgosDraft = cosaHedra.getArgosMeshDraft();
        List<int> tL = ICO_ArgosDraft.triangles;
        List<Vector3> vL = ICO_ArgosDraft.vertices;
        List<Vector2> uvL = ICO_ArgosDraft.uv;
        List<int> tQual = ICO_ArgosDraft.vQual;//triangle center quality
        List<Vector3> tCent = ICO_ArgosDraft.vTriCenter;

        int numVerts = tL.Count;

        Vector3 vTCProjection;      //Tri Center Projection
        Vector3 vTC;                //Tri Center Location
        Vector3 vVProj;             //Tri Vertex Projection
        Vector2[] uv = new Vector2[3];
        bool reject = false;

        Vector3 vIn;
        Vector3 vUp;
        Vector3 vRight;

        int iQuality = TriQual.UNDEFINED;

        float x, y;

        for (int i = 0; i < numVerts - 2; i += 3)
        {
            vTC = tCent[tL[i]];//requires this.transform at origin - can generalize

            //project onto UV Plane
            vTCProjection.x = Vector3.Dot(vTC, transform.right) * cosaHedra.radius / Vector3.Dot(vTC, transform.forward);
            vTCProjection.y = Vector3.Dot(vTC, transform.up) * cosaHedra.radius / Vector3.Dot(vTC, transform.forward);
            vTCProjection.z = 0f; //2D UV Plane

            if (vTCProjection.magnitude < m_fRadius_UV)//in range of texture
            {
                //Determine quality here
                iQuality = Find_UV_PointQuality(vTCProjection);

                for (int k = i; k < i + 3; k++)
                {
                    vUp = transform.up;
                    vIn = vL[tL[k]].normalized;
                    vRight = Vector3.Cross(vUp, vIn);
                    Vector3.Normalize(vRight);
                    vUp = Vector3.Cross(vIn, vRight);
                    vVProj = vL[tL[k]] - m_vPointingLoc;  //TODO NOT PROJ YET - push out to plane of UV - Avoid Lensing

                    vVProj /= m_fRadius_UV * 2;

                    x = 0.5f + Vector3.Dot(vVProj, vRight);
                    y = 0.5f + Vector3.Dot(vVProj, vUp);


                    if (x >= 0 && x <= 1 && y >= 0 && y <= 1)//Check if each triangle vertex is within bounds of texture
                    {
                        uv[k - i] = new Vector2(x, y);
                    }
                    else reject = true;
                }
                if (!reject)
                {
                    for (int k = i; k < i + 3; k++)
                    {
                        uvL[tL[k]] = uv[k - i];
                    }
                }
                reject = false;
            }
        }
        cosaHedra.writeMesh();
    }

 

    Vector2[] vQualCenter = new[]
    {
        new Vector2( 0, 0),                            //A
        new Vector2( 0, 1),                            //B  (m_fCelHt)
        new Vector2( Mathf.Sqrt(3f)/2f, 0.5f),         //C	
        new Vector2( Mathf.Sqrt(3f)/2f, -0.5f),        //D
        new Vector2( 0, -1),                           //E
        new Vector2( -Mathf.Sqrt(3f)/2f, -0.5f),       //F
        new Vector2( -Mathf.Sqrt(3f)/2f, 0.5f),        //G
        new Vector2( 0, 2),                            //H
        new Vector2( 3f/(2f*Mathf.Sqrt(3f)), 3f/2f),   //I ***
        new Vector2( Mathf.Sqrt(3f), 1f),              //J 
        new Vector2( 3f/Mathf.Sqrt(3f), 0),            //K ***
        new Vector2( Mathf.Sqrt(3f), -1f),             //L 
        new Vector2( 3f/(2f*Mathf.Sqrt(3f)), -3f/2f),  //M ***
        new Vector2( 0, -2),                           //N           
        new Vector2( -3f/(2f*Mathf.Sqrt(3f)), -3f/2f), //O ***
        new Vector2( -Mathf.Sqrt(3f), -1f),            //P
        new Vector2( -3f/Mathf.Sqrt(3f), 0),           //Q ***
        new Vector2( -Mathf.Sqrt(3f), 1f),             //R
        new Vector2( -3f/(2f*Mathf.Sqrt(3f)), 3f/2f),  //S ***
    };

sdfgdfsg14

Dial_2