Example #1
0
    public override void Embody(Form parent)
    {
        int[]     triangles = mesh.mesh.triangles;
        Vector3[] verts     = mesh.mesh.vertices;
        Vector2[] uvs       = mesh.mesh.uv;
        Vector4[] tans      = mesh.mesh.tangents;
        Vector3[] nors      = mesh.mesh.normals;

        float[] triangleAreas = new float[triangles.Length / 3];
        float   totalArea     = 0;

        int tri0;
        int tri1;
        int tri2;

        for (int i = 0; i < triangles.Length / 3; i++)
        {
            tri0 = i * 3;
            tri1 = tri0 + 1;
            tri2 = tri0 + 2;

            tri0 = triangles[tri0];
            tri1 = triangles[tri1];
            tri2 = triangles[tri2];

            float area = 1;

            if (noiseType == "even")
            {
                area = HELP.AreaOfTriangle(verts[tri0], verts[tri1], verts[tri2]);
            }
            else if (noiseType == "fractal")
            {
                area = HELP.NoiseTriangleArea(noiseSize, verts[tri0], verts[tri1], verts[tri2]);
                area = Mathf.Pow(area, 10);
            }

            triangleAreas[i] = area;
            totalArea       += area;
        }

        for (int i = 0; i < triangleAreas.Length; i++)
        {
            triangleAreas[i] /= totalArea;
        }

        float[] values = new float[count * structSize];

        int index = 0;


        Vector3 pos;
        Vector3 uv;
        Vector3 tan;
        Vector3 nor;
        int     baseTri;

        for (int i = 0; i < count; i++)
        {
            baseTri = 3 * HELP.getTri(Random.value, triangleAreas);
            tri0    = baseTri + 0;
            tri1    = baseTri + 1;
            tri2    = baseTri + 2;

            tri0 = triangles[tri0];
            tri1 = triangles[tri1];
            tri2 = triangles[tri2];

            pos = HELP.GetRandomPointInTriangle(i, verts[tri0], verts[tri1], verts[tri2]);

            float a0 = HELP.AreaOfTriangle(pos, verts[tri1], verts[tri2]);
            float a1 = HELP.AreaOfTriangle(pos, verts[tri0], verts[tri2]);
            float a2 = HELP.AreaOfTriangle(pos, verts[tri0], verts[tri1]);

            float aTotal = a0 + a1 + a2;

            float p0 = a0 / aTotal;
            float p1 = a1 / aTotal;
            float p2 = a2 / aTotal;

            nor = (nors[tri0] * p0 + nors[tri1] * p1 + nors[tri2] * p2).normalized;
            uv  = uvs[tri0] * p0 + uvs[tri1] * p1 + uvs[tri2] * p2;
            tan = (HELP.ToV3(tans[tri0]) * p0 + HELP.ToV3(tans[tri1]) * p1 + HELP.ToV3(tans[tri2]) * p2).normalized;


//            print( pos);
            values[index++] = pos.x;
            values[index++] = pos.y;
            values[index++] = pos.z;

            values[index++] = 0;
            values[index++] = 0;
            values[index++] = 0;

            values[index++] = nor.x;
            values[index++] = nor.y;
            values[index++] = nor.z;

            values[index++] = tan.x;
            values[index++] = tan.y;
            values[index++] = tan.z;

            values[index++] = uv.x;
            values[index++] = uv.y;

            values[index++] = i;
            values[index++] = i / count;
        }


        SetData(values);
    }
Example #2
0
    public override void Embody()
    {
        float[] triangleAreas = new float[tris.count / 3];

        int[]   triData  = tris.GetIntData();
        float[] vertData = verts.GetFloatData();

        float totalArea = 0;

        int tri0;
        int tri1;
        int tri2;

        for (int i = 0; i < tris.count / 3; i++)
        {
            tri0 = i * 3;
            tri1 = tri0 + 1;
            tri2 = tri0 + 2;

            tri0 = triData[tri0];
            tri1 = triData[tri1];
            tri2 = triData[tri2];

            float area = 1;

            Vector3 p0  = extractToVector(tri0, 0, vertData, verts);
            Vector3 p1  = extractToVector(tri1, 0, vertData, verts);
            Vector3 p2  = extractToVector(tri2, 0, vertData, verts);
            Vector2 uv0 = extractToVector2(tri0, 12, vertData, verts);
            Vector2 uv1 = extractToVector2(tri1, 12, vertData, verts);
            Vector2 uv2 = extractToVector2(tri2, 12, vertData, verts);



            if (noiseType == NoiseType.MiddleBand)
            {
                float Y = 1 - ((1 - uv0.y) + (1 - uv1.y) + (1 - uv2.y)) / 3;
                area  = Mathf.Clamp(Mathf.Min(Y * 2, (1 - Y)) * 4.5f, 0, 4); //((1-uv0.y) + (1-uv1.y) + (1-uv2.y) ) / 3;
                area *= area * area;                                         // * area * area*area;
            }
            else if (noiseType == NoiseType.CenterOut)
            {
            }
            else if (noiseType == NoiseType.Even)
            {
                float Y = 1 - ((1 - uv0.y) + (1 - uv1.y) + (1 - uv2.y)) / 3;
                area = Y;
            }
            else if (noiseType == NoiseType.OuterRing)
            {
                float Y = 1 - ((1 - uv0.y) + (1 - uv1.y) + (1 - uv2.y)) / 3;
                area = Y * Y;
            }



            triangleAreas[i] = area;
            totalArea       += area;
        }

        for (int i = 0; i < triangleAreas.Length; i++)
        {
            triangleAreas[i] /= totalArea;
        }

        float[] values = new float[count * structSize];

        int index = 0;


        Vector3 pos;
        //Vector3 uv;
        //Vector3 tan;
        //Vector3 nor;
        int baseTri;

        for (int i = 0; i < count; i++)
        {
            baseTri = 3 * HELP.getTri(Random.value, triangleAreas);

            if (specialInCenter && i == 0)
            {
                baseTri = 0;
            }

            tri0 = baseTri + 0;
            tri1 = baseTri + 1;
            tri2 = baseTri + 2;

            tri0 = triData[tri0];
            tri1 = triData[tri1];
            tri2 = triData[tri2];

            Vector3 v0 = extractToVector(tri0, 0, vertData, verts);
            Vector3 v1 = extractToVector(tri1, 0, vertData, verts);
            Vector3 v2 = extractToVector(tri2, 0, vertData, verts);

            pos = HELP.GetRandomPointInTriangle(i, v0, v1, v2);

            float a0 = HELP.AreaOfTriangle(pos, v1, v2);
            float a1 = HELP.AreaOfTriangle(pos, v0, v2);
            float a2 = HELP.AreaOfTriangle(pos, v0, v1);

            float aTotal = a0 + a1 + a2;

            float p0 = a0 / aTotal;
            float p1 = a1 / aTotal;
            float p2 = a2 / aTotal;


            values[index++] = 0;
            values[index++] = 0;
            values[index++] = 0;

            values[index++] = 0;
            values[index++] = 0;
            values[index++] = 0;

            values[index++] = 0;
            values[index++] = 0;
            values[index++] = 0;

            values[index++] = 0;
            values[index++] = 0;
            values[index++] = 0;

            values[index++] = 0;
            values[index++] = 0;


            values[index++] = (float)i / (float)count;

            values[index++] = tri0;
            values[index++] = tri1;
            values[index++] = tri2;

            values[index++] = p0;
            values[index++] = p1;
            values[index++] = p2;

            values[index++] = 1;

            if (specialInCenter)
            {
                values[index++] = 1;
            }
            else
            {
                values[index++] = triangleAreas[baseTri / 3] * 1000;
            }
            values[index++] = 0;
        }


        SetData(values);
    }
Example #3
0
        public override void Embody()
        {
            float[] triangleAreas = new float[tris.count / 3];

            int[]   triData  = tris.GetIntData();
            float[] vertData = verts.GetFloatData();

            float totalArea = 0;

            int tri0;
            int tri1;
            int tri2;

            for (int i = 0; i < tris.count / 3; i++)
            {
                tri0 = i * 3;
                tri1 = tri0 + 1;
                tri2 = tri0 + 2;

                tri0 = triData[tri0];
                tri1 = triData[tri1];
                tri2 = triData[tri2];

                float area = 1;

                Vector3 p0 = extractToVector(tri0, 0, vertData, verts);
                Vector3 p1 = extractToVector(tri1, 0, vertData, verts);
                Vector3 p2 = extractToVector(tri2, 0, vertData, verts);

                if (noiseType == "even")
                {
                    area = HELP.AreaOfTriangle(p0, p1, p2);
                }
                else if (noiseType == "fractal")
                {
                    area = HELP.NoiseTriangleArea(noiseSize, p0, p1, p2);
                    area = Mathf.Pow(area, 10);
                }

                triangleAreas[i] = area;
                totalArea       += area;
            }

            for (int i = 0; i < triangleAreas.Length; i++)
            {
                triangleAreas[i] /= totalArea;
            }

            float[] values = new float[count * structSize];

            int index = 0;


            Vector3 pos;
            Vector3 uv;
            Vector3 tan;
            Vector3 nor;
            int     baseTri;

            for (int i = 0; i < count; i++)
            {
                baseTri = 3 * HELP.getTri(Random.value, triangleAreas);

                tri0 = baseTri + 0;
                tri1 = baseTri + 1;
                tri2 = baseTri + 2;

                tri0 = triData[tri0];
                tri1 = triData[tri1];
                tri2 = triData[tri2];

                Vector3 v0 = extractToVector(tri0, 0, vertData, verts);
                Vector3 v1 = extractToVector(tri1, 0, vertData, verts);
                Vector3 v2 = extractToVector(tri2, 0, vertData, verts);

                pos = HELP.GetRandomPointInTriangle(i, v0, v1, v2);

                float a0 = HELP.AreaOfTriangle(pos, v1, v2);
                float a1 = HELP.AreaOfTriangle(pos, v0, v2);
                float a2 = HELP.AreaOfTriangle(pos, v0, v1);

                float aTotal = a0 + a1 + a2;

                float p0 = a0 / aTotal;
                float p1 = a1 / aTotal;
                float p2 = a2 / aTotal;


                values[index++] = 0;
                values[index++] = 0;
                values[index++] = 0;

                values[index++] = 0;
                values[index++] = 0;
                values[index++] = 0;

                values[index++] = 0;
                values[index++] = 0;
                values[index++] = 0;

                values[index++] = 0;
                values[index++] = 0;
                values[index++] = 0;

                values[index++] = 0;
                values[index++] = 0;


                values[index++] = (float)i / (float)count;

                values[index++] = tri0;
                values[index++] = tri1;
                values[index++] = tri2;

                values[index++] = p0;
                values[index++] = p1;
                values[index++] = p2;

                values[index++] = 1;
                values[index++] = 0;
                values[index++] = 0;
            }


            SetData(values);
        }
        public override void Embody()
        {
            print("Embodying particles on dynamic mesh");

            float[] triangleAreas = new float[tris.count / 3];

            int[]   triData  = tris.GetIntData();
            float[] vertData = verts.GetFloatData();


            print(tris.count);
            print(verts.count);

            float totalArea = 0;

            int tri0;
            int tri1;
            int tri2;

            for (int i = 0; i < tris.count / 3; i++)
            {
                /*tri0 = i * 3;
                 * tri1 = tri0 + 1;
                 * tri2 = tri0 + 2;
                 *
                 * tri0 = triData[tri0];
                 * tri1 = triData[tri1];
                 * tri2 = triData[tri2];
                 *
                 * float area = 1;
                 *
                 * Vector3 p0 = extractToVector(tri0,0,vertData,verts);
                 * Vector3 p1 = extractToVector(tri1,0,vertData,verts);
                 * Vector3 p2 = extractToVector(tri2,0,vertData,verts);
                 *
                 * if( noiseType=="even"){
                 * area = HELP.AreaOfTriangle (p0, p1, p2);
                 * }else if( noiseType =="fractal" ){
                 * area = HELP.NoiseTriangleArea(noiseSize, p0, p1, p2);
                 * area = Mathf.Pow( area, 10);
                 * }*/

                triangleAreas[i] = 1;
                totalArea       += 1;
            }

            for (int i = 0; i < triangleAreas.Length; i++)
            {
                triangleAreas[i] /= totalArea;
            }

            float[] values = new float[count * structSize];

            int index = 0;


            Vector3 pos;
            int     baseTri;

            for (int i = 0; i < count; i++)
            {
                baseTri = 3 * HELP.getTri(Random.value, triangleAreas);

                tri0 = baseTri + 0;
                tri1 = baseTri + 1;
                tri2 = baseTri + 2;

                tri0 = triData[tri0];
                tri1 = triData[tri1];
                tri2 = triData[tri2];

                Vector3 v0 = new Vector3(1, 0, 0); //extractToVector(tri0,0,vertData,verts);
                Vector3 v1 = new Vector3(0, 1, 0); //extractToVector(tri1,0,vertData,verts);
                Vector3 v2 = new Vector3(0, 0, 1); //extractToVector(tri2,0,vertData,verts);

                pos = HELP.GetRandomPointInTriangle(i, v0, v1, v2);

                float a0 = HELP.AreaOfTriangle(pos, v1, v2);
                float a1 = HELP.AreaOfTriangle(pos, v0, v2);
                float a2 = HELP.AreaOfTriangle(pos, v0, v1);

                float aTotal = a0 + a1 + a2;

                float p0 = a0 / aTotal;
                float p1 = a1 / aTotal;
                float p2 = a2 / aTotal;

                //if( aTotal == 0 ){ print("hellloo"); }


                values[index++] = 0;
                values[index++] = 0;
                values[index++] = 0;

                values[index++] = 0;
                values[index++] = 0;
                values[index++] = 0;

                values[index++] = 0;
                values[index++] = 0;
                values[index++] = 0;

                values[index++] = 0;
                values[index++] = 0;
                values[index++] = 0;

                values[index++] = 0;
                values[index++] = 0;


                values[index++] = (float)i / (float)count;

                values[index++] = tri0;
                values[index++] = tri1;
                values[index++] = tri2;

                values[index++] = p0;
                values[index++] = p1;
                values[index++] = p2;

                values[index++] = 1;
                values[index++] = 0;
                values[index++] = 0;
            }


            SetData(values);
        }