Ejemplo n.º 1
0
        public BlendShape ToBlendShape()
        {
            var shapeFrames = new BlendShapeFrame[frames.Length];

            for (int i = 0; i < shapeFrames.Length; i++)
            {
                shapeFrames[i] = frames[i].ToBlendShapeFrame();
            }
            return(new BlendShape(shapeName, shapeFrames));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the blend shapes of a mesh.
        /// </summary>
        /// <param name="mesh">The mesh.</param>
        /// <returns>The mesh blend shapes.</returns>
        public static BlendShape[] GetMeshBlendShapes(Mesh mesh)
        {
            if (mesh == null)
            {
                throw new ArgumentNullException(nameof(mesh));
            }

            int vertexCount     = mesh.vertexCount;
            int blendShapeCount = mesh.blendShapeCount;

            if (blendShapeCount == 0)
            {
                return(null);
            }

            var blendShapes = new BlendShape[blendShapeCount];

            for (int blendShapeIndex = 0; blendShapeIndex < blendShapeCount; blendShapeIndex++)
            {
                string shapeName  = mesh.GetBlendShapeName(blendShapeIndex);
                int    frameCount = mesh.GetBlendShapeFrameCount(blendShapeIndex);
                var    frames     = new BlendShapeFrame[frameCount];

                for (int frameIndex = 0; frameIndex < frameCount; frameIndex++)
                {
                    float frameWeight = mesh.GetBlendShapeFrameWeight(blendShapeIndex, frameIndex);

                    var deltaVertices = new Vector3[vertexCount];
                    var deltaNormals  = new Vector3[vertexCount];
                    var deltaTangents = new Vector3[vertexCount];
                    mesh.GetBlendShapeFrameVertices(blendShapeIndex, frameIndex, deltaVertices, deltaNormals, deltaTangents);

                    frames[frameIndex] = new BlendShapeFrame(frameWeight, deltaVertices, deltaNormals, deltaTangents);
                }

                blendShapes[blendShapeIndex] = new BlendShape(shapeName, frames);
            }

            return(blendShapes);
        }