Example #1
0
        public static Engine.VPT.Mesh ToVpMesh(this Mesh unityMesh)
        {
            var vpMesh = new Engine.VPT.Mesh(unityMesh.name);

            vpMesh.Vertices = new Vertex3DNoTex2[unityMesh.vertexCount];
            var unityVertices = unityMesh.vertices;
            var unityNormals  = unityMesh.normals;

            for (int i = 0; i < vpMesh.Vertices.Length; i++)
            {
                var unityVertex = unityVertices[i];
                var unityNormal = unityNormals[i];
                var unityUv     = unityMesh.uv[i];
                vpMesh.Vertices[i] = new Vertex3DNoTex2(
                    unityVertex.x, unityVertex.y, unityVertex.z,
                    unityNormal.x, unityNormal.y, unityNormal.z,
                    unityUv.x, -unityUv.y);
            }
            vpMesh.Indices = unityMesh.triangles;

            if (unityMesh.blendShapeCount > 0)
            {
                int animationIndex = unityMesh.GetBlendShapeIndex(AnimationShape);

                // use the first blendshape if none with default name
                if (animationIndex < 0)
                {
                    animationIndex = 0;
                }

                Vector3[] deltaVertices = new Vector3[unityMesh.vertexCount];
                Vector3[] deltaNormals  = new Vector3[unityMesh.vertexCount];

                int frameCount = unityMesh.GetBlendShapeFrameCount(animationIndex);
                for (int i = 0; i < frameCount; i++)
                {
                    unityMesh.GetBlendShapeFrameVertices(animationIndex, i, deltaVertices, deltaNormals, null);

                    Engine.VPT.Mesh.VertData[] frameData = new Engine.VPT.Mesh.VertData[unityMesh.vertexCount];
                    for (int j = 0; j < unityMesh.vertexCount; j++)
                    {
                        Vector3 vertex = deltaVertices[j] + unityVertices[j];
                        Vector3 normal = deltaNormals[j] + unityNormals[j];
                        frameData[j] = new Engine.VPT.Mesh.VertData(
                            vertex.x, vertex.y, vertex.z,
                            normal.x, normal.y, normal.z);
                    }

                    vpMesh.AnimationFrames.Add(frameData);
                }
            }

            return(vpMesh);
        }
Example #2
0
 public static Vector3 ToUnityNormalVector3(this Engine.VPT.Mesh.VertData vpVert)
 {
     return(new Vector3(vpVert.Nx, vpVert.Ny, vpVert.Nz));
 }
Example #3
0
 public static Vector3 ToUnityVector3(this Engine.VPT.Mesh.VertData vpVert)
 {
     return(new Vector3(vpVert.X, vpVert.Y, vpVert.Z));
 }