There seems to be an issue with resetting mesh weights
What is the way to make certain vertices be unaffected by bones?
In this PG, I set the weightIDs to -1 but it becomes all spaghettified.
Note: I know that I could set all the weightIDs to 0 (the first bone index) but this simply binds the vertex to the first bone. I would like the vertex to be affected by no bones, while preserving the vertex position
Iâm not sure thereâs a way to do exactly what youâre trying to do. Messing with rigging data at runtime is fraught to say the leastâthis is really the sort of thing that should be done in a DCC tool like Blender or Mayaâand in this particular case changing this data retroactively may expose you to all sorts of implementation details within the engine code. For example, the way Babylon applies a skeleton to a mesh accumulates the influences into a matrix to do all the multiplication once; but if there are no influences, that matrix will be full of zeros, which is not a valid homogeneous transform. I donât know for sure whether this particular code is whatâs causing the exact behavior youâre seeing, but trying to manipulate this sort of mesh data at runtime will expose you to many situations where low-level assumptions may be accidentally broken, causing problems.
If you have access to the mesh and can do what youâre trying to do offline, I would definitely recommend changing the rigging using a DCC tool such as Blender. If you absolutely have to do it at runtime, though, Iâd recommend splitting the mesh in two, taking the vertices you donât want to be affected by a skeleton into a separate mesh to which you simply never apply a skeleton. That should allow you to achieve the effect of having certain vertices unaffected by the rigging without having to try to modify the rigging logic itself at runtime. Hope this helps, and best of luck!
Thank you @syntheticmagus , I know that you can use DCC tools but I would very much like to do everything in runtime to create a simple rigging tool all with BJS. I know that itâs possible. In fact Iâm close but this is one of the last few glitches that I need to resolve
Is there really no other solution other than to split the mesh into weighted/non-weighted?
Couldnât we technically tweak those lines in mesh.ts to make sure that if itâs all zeros it just leaves the base mesh vertex untouched?
Iâm not really familiar enough with that part of the code to be sure what all effects that might have. It sounds reasonable enough to me, but if thatâs a behavior you need then I think the next step is to make an official feature request on Babylon.js. Thatâll get the matter in front of the team members who know this stuff best and, if itâs as simple and innocuous a change as it looks to be, it should be a quick fix!
Unfortunately changing applySkeleton wouldnât quite work (PG here)
I think weâd need to change the shaders itself
Do you know where I can find the relevant shader code?
You have to set mesh.computeBonesUsingShaders to false for that CPU skinning function to be used. Otherwise the shader version is implemented here: bonesDeclaration.fx and bonesVertex.fx
It was missing some type declarations (for VertexBuffer and Matrix) and finalMatrix needed to be changed from const to let.
IDK about the shader part thou, maybe better to just create an extra bone with identity matrix to avoid any branching? Will be interesting to see what the core devs think of the issue.
For example hereâs what I meant by adding an extra bone for the identity matrix, then any vertices that are transformed only by this bone should be unaffected by the skeleton (i.e. it should be the same as if you null the skeleton on line 57 since youâre doing it for all vertices I think).
Also you could try using bones.length for the matrix index for vertices that should be unaffected by the skeleton, but then youâd have to change that value if you later add or remove a bone - since identity matrix is copied to the end of the bone transforms array, the index to use for it depends on the number of bones (well according to my reading of the source code here.
If you want it to look the same as before could try using getPositionData to bake the current bone transforms into the vertices. The normals are still wrong but I think the upcoming getNormalsData function could help bake those into the vertices as well.
Yea I know
Though in the end this approach doesnât solve the problem of arbitrary vertices having no weights, which is what the original post was asking about
I think the only option is to change the shader code itself
Hmm on rereading your first post of the thread I feel like this does address it, the vertices are âaffected by no bones, while preserving the vertex positionâ like you want as far as I can tellâŚ
But if you want to do arbitrary vertices, instead of all them you like in your PG, then you could change the position and matrices data for just those vertices instead of changing it for all of themâŚ
Or maybe an easier, better way will be found after all.
I realized that in 3D software e.g. Maya, if a mesh is skinned i.e. has matricesWeights, then these weights cannot be removed unless they âunbind skinâ.
If a bone weight is removed (eroded via subtractive weightpaint) from a vertex, then Maya re-assigns this bone weight to a different bone instead. The effective total weight for a vertex is always normalized to 1.
And I think this approach makes sense.
So Iâm going to close this topic here since the original question, while makes sense on paper, isnât necessarily a good approach and is not compatible with approaches in existing 3D tools