void BuildBlendShapes() { _blendShapes = new BlendShape[attributeMeshes.Length]; for (int i = 0; i < attributeMeshes.Length; i++) { if (attributeMeshes [i] == null) { continue; } _blendShapes[i] = new BlendShape(); Vector3[] attributeMeshVertices = attributeMeshes[i].vertices; Vector3[] attributeMeshNormals = attributeMeshes[i].normals; Vector3[] workMeshVertices = _workingMesh.vertices; Vector3[] workMeshNormals = _workingMesh.normals; List <BlendShapeVertex> vertices = new List <BlendShapeVertex>(_workingMesh.vertexCount); for (int j = 0; j < _workingMesh.vertexCount; j++) { if (workMeshVertices[j] != attributeMeshVertices[j]) { BlendShapeVertex blendShapeVertex = new BlendShapeVertex(); blendShapeVertex.originalIndex = j; blendShapeVertex.position = attributeMeshVertices[j] - workMeshVertices[j]; // blendShapeVertex.normal = attributeMeshNormals[j] - workMeshNormals[j]; vertices.Add(blendShapeVertex); } } _blendShapes[i].vertices = vertices.ToArray(); } }
void BuildBlendShapes() { blendShape = new BlendShape(); blendShape.vertices = new BlendShapeVertex[workingMesh.vertexCount]; for ( int j = 0; j < workingMesh.vertexCount; j++) { BlendShapeVertex blendShapeVertex = new BlendShapeVertex(); blendShapeVertex.originalIndex = j; blendShapeVertex.position = attributeMesh.vertices[j] - workingMesh.vertices[j]; blendShapeVertex.normal = attributeMesh.normals[j] - workingMesh.normals[j]; blendShape.vertices[j] = blendShapeVertex; } }
void BuildBlendShapes() { blendShapes = new BlendShape[attributes.Length]; //For each attribute figure out which vertices are affected, then store their info in the blend shape object. for (int i = 0; i < attributes.Length; i++) { //Populate blendShapes array with new blend shapes blendShapes[i] = new BlendShape(); /** TODO: Make this a little more stylish! * UGLY hack to compensate the lack of dynamic arrays in C#. Feel free to improve! */ int blendShapeCounter = 0; for (int j = 0; j < workingMesh.vertexCount; j++) { if (workingMesh.vertices[j] != attributeMeshes[i].vertices[j]) { blendShapeCounter++; } } blendShapes[i].vertices = new BlendShapeVertex[blendShapeCounter]; blendShapeCounter = 0; for (int j = 0; j < workingMesh.vertexCount; j++) { //If the vertex is affected, populate a blend shape vertex with that info if (workingMesh.vertices[j] != attributeMeshes[i].vertices[j]) { //Create a blend shape vertex and populate its data. BlendShapeVertex blendShapeVertex = new BlendShapeVertex(); blendShapeVertex.originalIndex = j; blendShapeVertex.position = attributeMeshes[i].vertices[j] - workingMesh.vertices[j]; blendShapeVertex.normal = attributeMeshes[i].normals[j] - workingMesh.normals[j]; //Add new blend shape vertex to blendShape object. blendShapes[i].vertices[blendShapeCounter] = blendShapeVertex; blendShapeCounter++; } } //Convert blendShapes.vertices to builtin array //blendShapes[i].vertices = blendShapes[i].vertices.ToBuiltin(BlendShapeVertex); } }
private static BlendShapeData MergeBlendShapes([NotNull, ItemNotNull] IReadOnlyList <Mesh> meshes) { var vertices = new List <BlendShapeVertex>(); var shapes = new List <MeshBlendShape>(); var channels = new List <MeshBlendShapeChannel>(); var weights = new List <float>(); uint meshVertexIndexStart = 0; var totalFrameCount = 0; uint totalVertexCount = 0; foreach (var mesh in meshes) { var meshShape = mesh.Shape; if (meshShape != null) { var channelFrameCount = 0; foreach (var channel in meshShape.Channels) { var chan = new MeshBlendShapeChannel(); chan.Name = channel.Name; chan.FrameIndex = channel.FrameIndex + totalFrameCount; chan.FrameCount = channel.FrameCount; chan.NameHash = channel.NameHash; channelFrameCount += channel.FrameCount; channels.Add(chan); } totalFrameCount += channelFrameCount; weights.AddRange(meshShape.FullWeights); uint shapeVertexCount = 0; foreach (var s in meshShape.Shapes) { var shape = new MeshBlendShape(); shape.FirstVertex = s.FirstVertex + totalVertexCount; shape.HasNormals = s.HasNormals; shape.HasTangents = s.HasTangents; shape.VertexCount = s.VertexCount; shapeVertexCount += s.VertexCount; shapes.Add(shape); } totalVertexCount += shapeVertexCount; foreach (var v in meshShape.Vertices) { var vertex = new BlendShapeVertex(); vertex.Index = v.Index + meshVertexIndexStart; vertex.Vertex = v.Vertex; vertex.Normal = v.Normal; vertex.Tangent = v.Tangent; vertices.Add(vertex); } } meshVertexIndexStart += (uint)mesh.VertexCount; } return(new BlendShapeData(vertices.ToArray(), shapes.ToArray(), channels.ToArray(), weights.ToArray())); }
internal static BlendShapeData ReadBlendShapeData([NotNull] this BinaryReader reader) { var vertexCount = reader.ReadInt32(); var vertices = new BlendShapeVertex[vertexCount]; for (var i = 0; i < vertexCount; ++i) { vertices[i] = ReadBlendShapeVertex(reader); } var shapeCount = reader.ReadInt32(); var shapes = new MeshBlendShape[shapeCount]; for (var i = 0; i < shapeCount; ++i) { shapes[i] = ReadMeshBlendShape(reader); } var channelCount = reader.ReadInt32(); var channels = new MeshBlendShapeChannel[channelCount]; for (var i = 0; i < channelCount; ++i) { channels[i] = ReadMeshBlendShapeChannel(reader); } var weightCount = reader.ReadInt32(); var weights = new float[weightCount]; for (var i = 0; i < weightCount; ++i) { weights[i] = reader.ReadSingle(); } return(new BlendShapeData(vertices, shapes, channels, weights)); BlendShapeVertex ReadBlendShapeVertex(BinaryReader r) { var vertex = new BlendShapeVertex(); vertex.Vertex = r.ReadVector3(); vertex.Normal = r.ReadVector3(); vertex.Tangent = r.ReadVector3(); vertex.Index = r.ReadUInt32(); return(vertex); } MeshBlendShape ReadMeshBlendShape(BinaryReader r) { var shape = new MeshBlendShape(); shape.FirstVertex = r.ReadUInt32(); shape.VertexCount = r.ReadUInt32(); shape.HasNormals = r.ReadBoolean(); shape.HasTangents = r.ReadBoolean(); r.AlignBy(4); return(shape); } MeshBlendShapeChannel ReadMeshBlendShapeChannel(BinaryReader r) { var channel = new MeshBlendShapeChannel(); channel.Name = r.ReadAlignedString(); channel.NameHash = r.ReadUInt32(); channel.FrameIndex = r.ReadInt32(); channel.FrameCount = r.ReadInt32(); return(channel); } }
void BuildBlendShapes() { blendShapes = new BlendShape[attributes.Length]; //For each attribute figure out which vertices are affected, then store their info in the blend shape object. for (int i = 0; i < attributes.Length; i++) { //Populate blendShapes array with new blend shapes blendShapes[i] = new BlendShape(); /** TODO: Make this a little more stylish! * UGLY hack to compensate the lack of dynamic arrays in C#. Feel free to improve! */ int blendShapeCounter = 0; for (int j = 0; j < workingMesh.vertexCount; j++) { if (workingMesh.vertices[j] != attributeMeshes[i].vertices[j]) { blendShapeCounter++; } } blendShapes[i].vertices = new BlendShapeVertex[blendShapeCounter]; blendShapeCounter = 0; for (int j = 0; j < workingMesh.vertexCount; j++) { //If the vertex is affected, populate a blend shape vertex with that info if (workingMesh.vertices[j] != attributeMeshes[i].vertices[j]) { //Create a blend shape vertex and populate its data. BlendShapeVertex blendShapeVertex = new BlendShapeVertex(); blendShapeVertex.originalIndex = j; blendShapeVertex.position = attributeMeshes[i].vertices[j] - workingMesh.vertices[j]; blendShapeVertex.normal = attributeMeshes[i].normals[j] - workingMesh.normals[j]; //Add new blend shape vertex to blendShape object. blendShapes[i].vertices[blendShapeCounter]=blendShapeVertex; blendShapeCounter++; } } //Convert blendShapes.vertices to builtin array //blendShapes[i].vertices = blendShapes[i].vertices.ToBuiltin(BlendShapeVertex); } }