public BlendShapeContainer(BlendShape blendShape) { shapeName = blendShape.ShapeName; frames = new BlendShapeFrameContainer[blendShape.Frames.Length]; for (int i = 0; i < frames.Length; i++) { frames[i] = new BlendShapeFrameContainer(blendShape.Frames[i]); } }
/// <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); }