Example #1
0
    // Update is called once per frame
    public void WhileDown(Ray ray)
    {
        RaycastHit hit;

        if (person.Raycast(ray, out hit, 100.0f))
        {
            down = true;

            hitPoint  = hit.point;
            hitUV     = hit.textureCoord;
            hitNormal = hit.normal;
            traceRepresent.transform.position = hitPoint;

            triIDs = new Vector3(
                person.sharedMesh.triangles[hit.triangleIndex * 3 + 0],
                person.sharedMesh.triangles[hit.triangleIndex * 3 + 1],
                person.sharedMesh.triangles[hit.triangleIndex * 3 + 2]);


            bary = hit.barycentricCoordinate;

            hitTangent  = bary.x * HELP.ToV3(person.sharedMesh.tangents[(int)triIDs.x]);
            hitTangent += bary.y * HELP.ToV3(person.sharedMesh.tangents[(int)triIDs.y]);
            hitTangent += bary.z * HELP.ToV3(person.sharedMesh.tangents[(int)triIDs.z]);
        }
        else
        {
            down = false;
        }
    }
Example #2
0
        public override void Embody()
        {
            Vector3[] verts = mesh.vertices;
            Vector2[] uvs   = mesh.uv;
            Vector3[] nors  = mesh.normals;
            Vector4[] tans  = mesh.tangents;
            DebugThis("" + mesh.tangents.Length);
            DebugThis("" + mesh.vertices.Length);

            bool hasTan = false;

            if (tans.Length == verts.Length)
            {
                hasTan = true;
            }

            bool hasUV = false;

            if (uvs.Length == verts.Length)
            {
                hasUV = true;
            }

            int index = 0;


            // print("Creatings");

            float[] values = new float[count * structSize];
            for (int i = 0; i < count; i++)
            {
                if (transformVerts)
                {
                    verts[i] = transform.TransformPoint(verts[i]);
                }
                values[index++] = verts[i].x;
                values[index++] = verts[i].y;
                values[index++] = verts[i].z;

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

                if (transformVerts)
                {
                    nors[i] = transform.TransformDirection(nors[i]);
                }
                values[index++] = nors[i].x;
                values[index++] = nors[i].y;
                values[index++] = nors[i].z;


                if (hasTan)
                {
                    Vector3 tT = transform.TransformDirection(HELP.ToV3(tans[i]));
                    if (i < 10)
                    {
                        DebugThis("" + tT.x);
                    }

                    if (transformVerts)
                    {
                        tans[i] = new Vector4(tT.x, tT.y, tT.z, tans[i].w);
                    }

                    values[index++] = tans[i].x;
                    values[index++] = tans[i].y;
                    values[index++] = tans[i].z;
                }
                else
                {
                    values[index++] = 0;
                    values[index++] = 0;
                    values[index++] = 0;
                }

                if (hasUV)
                {
                    values[index++] = uvs[i].x;
                    values[index++] = uvs[i].y;
                }
                else
                {
                    values[index++] = 0;
                    values[index++] = 0;
                }

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

            SetData(values);
        }
Example #3
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 #4
0
        public override void Embody()
        {
            Vector3[] verts  = new Vector3[count];
            Vector3[] nors   = new Vector3[count];
            Vector3[] tans   = new Vector3[count];
            Vector2[] uvs    = new Vector2[count];
            int[]     meshID = new int[count];

            int index = 0;

            for (int i = 0; i < meshes.Length; i++)
            {
                Vector3[] v = meshes[i].GetComponent <MeshFilter>().sharedMesh.vertices;
                Vector3[] n = meshes[i].GetComponent <MeshFilter>().sharedMesh.normals;
                Vector4[] t = meshes[i].GetComponent <MeshFilter>().sharedMesh.tangents;
                Vector2[] u = meshes[i].GetComponent <MeshFilter>().sharedMesh.uv;

                for (int j = 0; j < v.Length; j++)
                {
                    verts[index]  = meshes[i].transform.TransformPoint(v[j]);
                    nors[index]   = meshes[i].transform.TransformDirection(n[j]);
                    tans[index]   = meshes[i].transform.TransformDirection(HELP.ToV3(t[j]));
                    uvs[index]    = u[j];
                    meshID[index] = i;
                    index        += 1;
                }
            }


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

            for (int i = 0; i < count; i++)
            {
                //DebugThis( "" +verts[i].x );

                values[index++] = verts[i].x;
                values[index++] = verts[i].y;
                values[index++] = verts[i].z;

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

                values[index++] = nors[i].x;
                values[index++] = nors[i].y;
                values[index++] = nors[i].z;


                values[index++] = tans[i].x;
                values[index++] = tans[i].y;
                values[index++] = tans[i].z;


                values[index++] = uvs[i].x;
                values[index++] = uvs[i].y;

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

            SetData(values);
        }