Exemple #1
0
        public static Mesh ToVpMesh(this UnityEngine.Mesh unityMesh)
        {
            var vpMesh = new Mesh(unityMesh.name)
            {
                Vertices = new Vertex3DNoTex2[unityMesh.vertexCount]
            };
            var unityVertices = unityMesh.vertices;
            var unityNormals  = unityMesh.normals;

            for (var 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)
            {
                var animationIndex = unityMesh.GetBlendShapeIndex(AnimationShape);

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

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

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

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

                    vpMesh.AnimationFrames.Add(frameData);
                }
            }

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