- Home /
How can i get current state(position) of vertices of animated mesh(SkinnedMeshRenderer)?
The question is how can i get the positions. I don't need to calculate them in every frame. I need to calculate vertex-positions in definite frame of animation.
Hmmmm I'm confused, Paulius says unity would not give you access to those, but if you copy the vertex directly from the mesh as I did and then read the coordinates... isn't that what you are looking for?
This always returns me same vertex positions despite current animation frame. This is the problem. I need this to export scene, where some objects are animated.
Please don't post question or comments as answers. Welcome to UnityAnswers!
Same problem here, "Skinned $$anonymous$$esh Remderer" Animated mesh, baked
function Update(){
var mesh = GetComponent("Skinned$$anonymous$$eshRenderer").shared$$anonymous$$esh;
vertices = mesh.vertices;
}
I don't think that data is accessible, vertices remain in same place and mesh bends.. Any solution to this? Is there not a simple way to access the vertices new positions one update.
Yeah, I'm looking for a solution to this. Any updates?
Answer by pcpc33 · Oct 19, 2013 at 06:34 PM
I'm not sure if this has a solution in Unity 3. In unity 4 the following works for me:
SkinnedMeshRenderer skin = model.GetComponent<SkinnedMeshRenderer>();
Mesh baked = new Mesh();
skin.BakeMesh(baked);
Baked will contain all the current vertex positions of the skinned and animated mesh. It seems to work slowly though, as far as I can tell, so be careful how often you call this.
Answer by Paulius-Liekis · Nov 28, 2012 at 09:46 AM
Unity doesn't give you access to those. The only thing you can do is to replicate the same code in scripts and calculate those vertex-positions. It's ok for simple things, but doing it every frame would be too expensive.
Edit: Look at this link: http://forum.unity3d.com/threads/14378-Raycast-without-colliders It has a sample how to update MeshCollider from SkinnedMeshRenderer manually in scripts. It does almost exactly what you need.
If i understood correct i can't get vertex positions in any way?
Answer by MrVerdoux · Nov 28, 2012 at 10:42 AM
Well it depends on what vertex you are looking for. Do you want them all? If so you could make a copy of them by using your mesh component like this.
Vector3 actualVertices;
MeshFilter meshFilter = (MeshFilter) gameObject.GetComponent("MeshFilter");
actualVertices = meshFilter.mesh.vertices;
The question is about Skinned$$anonymous$$eshRenderer, not about rigid meshes (i.e. $$anonymous$$eshFilter).
Answer by angelonit · May 08 at 10:12 PM
Sorry to necro but this worked for me so here it is:
Transform tOwner;
SkinnedMeshRenderer skinnedMeshRenderer;
List<Vector3> meshVertices = new List<Vector3>();
public void GetVertices()
{
Mesh mesh = new Mesh();
skinnedMeshRenderer.BakeMesh(mesh, true);
mesh.GetVertices(meshVertices);
tOwner = skinnedMeshRenderer.transform;
}
public Vector3 GetPositionFromVertex(int i)
{
Vector3 worldPosVertex = tOwner.localToWorldMatrix.MultiplyPoint3x4(meshVertices[i]);
return worldPosVertex;
}
Your answer
Follow this Question
Related Questions
Null Reference Exception Assigning Vertices to Mesh 0 Answers
Why vertex positions appear (0.0, 0.0, 0.0) ? 1 Answer
Voxel mesh generation not working. 1 Answer
Best Way to Link Vertices into Mesh 0 Answers
Grouping vertices? 1 Answer