- Home /
Grouping vertexes using bones
I have a mesh that I want to change using a script during runtime. But I only want to change certain vertexes in the mesh. In Blender these vertexes form a vertex group but you don't see this in Unity. Therefor I added a bone for each group and connected these with the vertex group giving them weight 1.
My idea was to find the correct groups in Unity by looping through Mesh.boneWeights and seeing if the weight to a certain bone was equal to 1. But how do I find out which bone index corresponds to which bone?
Answer by Bunny83 · Jun 14, 2011 at 12:48 PM
You shouldn't look for a certain weight. Just search the bone Transform by name. If you found your bone GameObject you can search for it in the bones array. When you've found your bone you have the index. Now you can check the boneWeights array and find all vertices that have your bone index and a weight > 0.
So I can only do this if I have a Skinned$$anonymous$$eshRenderer component? Because basically I'm not rendering the mesh, only adapting it to use as colliders.
It seems so... The bone references are stored in the Skinned$$anonymous$$eshRenderer. Without that information it's nearly impossible to figure out what bone has what index.
A Skinned$$anonymous$$eshRenderer can't be attached like a "normal" component from the menu because you would need to setup the bones yourself. It is created during import so the bones get correctly linked.
I can't see any "logic" behind the bones order (seems random to me: index 0 is the right leg, index 1 is BIP001). It has no relation to the bone-names or the order in 3dsmax...
Your answer
Follow this Question
Related Questions
Procedural Skinned mesh? 1 Answer
Bones move mesh in editor but not in run?? 1 Answer
Skinning character (attaching mesh to skeleton) 2 Answers
Skinning a mesh by Code... 1 Answer