- Home /
Needed a new feature of unity: Expose blend shape vertex datam, already on vote
What this does? Mesh.GetBlendShapeFrameVertices
So I'm combining skinned meshes at runtime, now everything is working, except for the blend shapes from the head mesh not being saved(or get lost), So now I'm finding a way to somehow save blendshapes from mesh parts first BEFORE combining them, so I can then save it to the new combined mesh. I saw this function Mesh.GetBlendShapeFrameVertices looks like can help me do the job, but this function doesn't return a value or something? I don't know what this does? There's also this function Mesh.AddBlendShapeFrame
Answer by Bunny83 · Sep 23, 2016 at 04:13 AM
Isn't the documentation quite clear what the method does?
Mesh.GetBlendShapeFrameVertices
shapeIndex The shape index of the frame.
frameIndex The frame index to get the weight from.
deltaVertices Delta vertices output array for the frame being retreived.
deltaNormals Delta normals output array for the frame being retreived.
deltaTangents Delta tangents output array for the frame being retreived.
Furthermore:
Retreives deltaVertices, deltaNormals and deltaTangents of a blend shape frame.
deltaVetrices, deltaNormals and deltaTangents arrays must be of size = Mesh.vertexCount.
Add Mesh vertices, normals or tangents to convert from frame deltas to full vectors.
deltaNormals or deltaTangents may be set to null if there is no normals or tangents to be
retreived for a frame.
So you simply have to pass the blendshape index and the frame index of the frame you want to retrieve. Furthermore you need to pass 3 arrays which will be filled with the data you're interested in. The arrays have to be initialized with the vertexCount of the mesh, so each array has "vertexCount" elements.
Mesh.AddBlendShapeFrame basically does exacly the opposite. You have to pass the blendshape name and the blend weight along with the 3 arrays. This will add a new frame to a specific blendshape.
Of course when you combine two skinned meshes, you would need to merge the arrays from both meshes according to their vertices.
Yow, thank you for explaining it to me, so now all I have to do is something like:
old$$anonymous$$esh.GetBlendShapeFrameVertices( old$$anonymous$$esh.arguments.... );
combine$$anonymous$$esh.AddBlendShapeFrame( old$$anonymous$$esh.arguments....);
Thank you, I hope this will make the blend shapes working on the new combine mesh
Although, now my problem is merging the arrays together.hmmm...
So I modified my script, new blend shape was added, but it doesn't seem to work, when I set it's weight to 100 manually in the editor, nothing happens? This is how I do it
Vector3[] blendVertices = new Vector3[smr.shared$$anonymous$$esh.vertexCount];
Vector3[] blendNormals = new Vector3[smr.shared$$anonymous$$esh.vertexCount];
Vector3[] blendTangents = new Vector3[smr.shared$$anonymous$$esh.vertexCount];
Debug.Log("Getting Blendshape");
smr.shared$$anonymous$$esh.GetBlendShapeFrameVertices(0, 0, blendVertices, blendNormals, blendTangents);
And then after combining the mesh:
Vector3[] temp = new Vector3[combined.shared$$anonymous$$esh.vertexCount];
Vector3[] temp2 = new Vector3[combined.shared$$anonymous$$esh.vertexCount];
Vector3[] temp3 = new Vector3[combined.shared$$anonymous$$esh.vertexCount];
//This seems to be the part that's not working right, I assume this will merge them?
for(int i = 0; i < blendVertices.Length; i++)
{
temp[i] = blendVertices[i];
temp2[i] = blendNormals[i];
temp3[i] = blendTangents[i];
}
combined.shared$$anonymous$$esh.AddBlendShapeFrame("blink", 0, temp, temp2, temp3);
Hi! This is how I copy blend shapes to a new mesh:
// Copy blend shape data from my$$anonymous$$esh to tmp$$anonymous$$esh
Vector3[] dVertices = new Vector3[my$$anonymous$$esh.vertexCount];
Vector3[] dNormals = new Vector3[my$$anonymous$$esh.vertexCount];
Vector3[] dTangents= new Vector3[my$$anonymous$$esh.vertexCount];
for (int shape = 0; shape < my$$anonymous$$esh.blendShapeCount; shape++) {
for (int frame = 0; frame < my$$anonymous$$esh.GetBlendShapeFrameCount(shape); frame++) {
string shapeName = my$$anonymous$$esh.GetBlendShapeName(shape);
float frameWeight = my$$anonymous$$esh.GetBlendShapeFrameWeight(shape, frame);
my$$anonymous$$esh.GetBlendShapeFrameVertices(shape, frame, dVertices, dNormals, dTangents);
tmp$$anonymous$$esh.AddBlendShapeFrame(shapeName, frameWeight, dVertices, dNormals, dTangents);
}
}