Exemplo n.º 1
0
    bool SidesMesh(ref int numVertsCreated)
    {
        float scale   = .2f;
        float reduce  = .86f;
        float partial = .5f;
        float distance;
        int   rInt;

        Random.InitState(42);
        Vector3 normalA, normalB;
        float   scaleA, scaleB;
        Vector3 farSideNormal, topNormal, farTopNormal, sideNormal, partialTopNormal, farPartialSideNormal;

        Vector3[] middle = new Vector3[2];
        Vector3[,] positions = new Vector3[3, 6];

        Color32 color = new Color32(102, 51, 0, 255);

        int i;

        for (i = 0; i < data.sideA.Count; i++)
        {
            scale = materials.GetSideScale(data.sideMaterial[i]);

            int firstVert = numVertsCreated;
            farSideNormal = new Vector3(1, 0, 1);
            topNormal     = new Vector3(0, 1, 0);
            normalA       = (Vector3)data.points[data.sideA[i]] - data.points[data.sideB[i]];

            Vector3.OrthoNormalize(ref normalA, ref topNormal, ref farSideNormal);
            if (Vector3.SignedAngle(topNormal, farSideNormal, normalA) < 0)
            {
                farSideNormal = -farSideNormal;
            }

            distance = Vector3.Distance(data.points[data.sideA[i]], data.points[data.sideB[i]]);



            farSideNormal *= scale;
            topNormal     *= scale;

            farTopNormal = topNormal * reduce;
            sideNormal   = farSideNormal * reduce;

            partialTopNormal     = topNormal * partial;
            farPartialSideNormal = farSideNormal * partial;

            normalA *= scale;
            normalB  = normalA;
            scaleA   = 1;
            scaleB   = 1;


            normalA *= data.sharedPointA[i];
            //scaleB = .9f;

            normalB *= data.sharedPointB[i];


            rInt = Random.Range(0, 64);

            if (distance > 1 && !materials.IsUniform(data.sideMaterial[i]))
            {
                middle[0] = ((Vector3)data.points[data.sideA[i]] * 2 + data.points[data.sideB[i]]) / 3;
                middle[1] = (data.points[data.sideA[i]] + (Vector3)data.points[data.sideB[i]] * 2) / 3;
            }
            else
            {
                middle[0] = ((Vector3)data.points[data.sideA[i]] + data.points[data.sideB[i]]) / 2;
                middle[1] = middle[0];

                farTopNormal         *= .9f;
                farSideNormal        *= .9f;
                farPartialSideNormal *= .9f;
            }

            topNormal        *= scaleA;
            partialTopNormal *= scaleA;
            sideNormal       *= scaleA;
            positions[0, 0]   = data.points[data.sideA[i]] + normalA + topNormal;
            positions[0, 1]   = data.points[data.sideA[i]] + normalA + partialTopNormal + sideNormal;
            positions[0, 2]   = data.points[data.sideA[i]] + normalA - partialTopNormal + sideNormal;
            positions[0, 3]   = data.points[data.sideA[i]] + normalA - topNormal;
            positions[0, 4]   = data.points[data.sideA[i]] + normalA - partialTopNormal - sideNormal;
            positions[0, 5]   = data.points[data.sideA[i]] + normalA + partialTopNormal - sideNormal;

            positions[1, 0] = middle[(rInt) % 2] + farTopNormal - farPartialSideNormal;
            rInt           /= 2;
            positions[1, 1] = middle[(rInt) % 2] + farTopNormal + farPartialSideNormal;
            rInt           /= 2;
            positions[1, 2] = middle[(rInt) % 2] + farSideNormal;
            rInt           /= 2;
            positions[1, 3] = middle[(rInt) % 2] - farTopNormal + farPartialSideNormal;
            rInt           /= 2;
            positions[1, 4] = middle[(rInt) % 2] - farTopNormal - farPartialSideNormal;
            rInt           /= 2;
            positions[1, 5] = middle[(rInt) % 2] - farSideNormal;

            topNormal        /= scaleA;
            partialTopNormal /= scaleA;
            sideNormal       /= scaleA;
            topNormal        *= scaleB;
            partialTopNormal *= scaleB;
            sideNormal       *= scaleB;
            positions[2, 0]   = data.points[data.sideB[i]] - normalB + topNormal;
            positions[2, 1]   = data.points[data.sideB[i]] - normalB + partialTopNormal + sideNormal;
            positions[2, 2]   = data.points[data.sideB[i]] - normalB - partialTopNormal + sideNormal;
            positions[2, 3]   = data.points[data.sideB[i]] - normalB - topNormal;
            positions[2, 4]   = data.points[data.sideB[i]] - normalB - partialTopNormal - sideNormal;
            positions[2, 5]   = data.points[data.sideB[i]] - normalB + partialTopNormal - sideNormal;
            int iPosition;

            if (distance > 1 && !materials.IsUniform(data.sideMaterial[i]))
            {
                for (iPosition = 0; iPosition < 6; iPosition++)
                {
                    verts[numVertsCreated++] = positions[0, iPosition];
                    verts[numVertsCreated++] = positions[1, iPosition];
                    verts[numVertsCreated++] = positions[1, (iPosition + 1) % 6];

                    verts[numVertsCreated++] = positions[1, (iPosition + 1) % 6];
                    verts[numVertsCreated++] = positions[0, (iPosition + 1) % 6];
                    verts[numVertsCreated++] = positions[0, iPosition];

                    verts[numVertsCreated++] = positions[2, iPosition];
                    verts[numVertsCreated++] = positions[1, (iPosition + 1) % 6];
                    verts[numVertsCreated++] = positions[1, iPosition];

                    verts[numVertsCreated++] = positions[1, (iPosition + 1) % 6];
                    verts[numVertsCreated++] = positions[2, iPosition];
                    verts[numVertsCreated++] = positions[2, (iPosition + 1) % 6];
                }
            }
            else
            {
                for (iPosition = 0; iPosition < 6; iPosition++)
                {
                    verts[numVertsCreated++] = positions[0, iPosition];
                    verts[numVertsCreated++] = positions[1, iPosition];
                    verts[numVertsCreated++] = positions[2, iPosition];

                    verts[numVertsCreated++] = positions[1, (iPosition + 1) % 6];
                    verts[numVertsCreated++] = positions[0, (iPosition + 1) % 6];
                    verts[numVertsCreated++] = positions[0, iPosition];

                    verts[numVertsCreated++] = positions[2, iPosition];
                    verts[numVertsCreated++] = positions[1, (iPosition + 1) % 6];
                    verts[numVertsCreated++] = positions[0, iPosition];

                    verts[numVertsCreated++] = positions[1, (iPosition + 1) % 6];
                    verts[numVertsCreated++] = positions[2, iPosition];
                    verts[numVertsCreated++] = positions[2, (iPosition + 1) % 6];
                }
            }

            for (int tri = 0; tri < 4; tri++)
            {
                verts[numVertsCreated++] = positions[0, 0];
                verts[numVertsCreated++] = positions[0, tri + 1];
                verts[numVertsCreated++] = positions[0, tri + 2];

                verts[numVertsCreated++] = positions[2, 0];
                verts[numVertsCreated++] = positions[2, tri + 2];
                verts[numVertsCreated++] = positions[2, tri + 1];
            }

            Color32 thisColor = materials.GetColor(data.sideMaterial[i]);
            for (int iColor = firstVert; iColor < numVertsCreated; iColor++)
            {
                vertColors[iColor] = thisColor;
            }
        }

        return(true);
    }