Hello, when using the “copy bone weights” script that comes with the new Blender, it tends to weight vertices to more than 4 bones. Because I am exporting to NIF format I cannot have any vertexes belonging to more than four vertex groups. Is it possible for someone to write a python script to sort out the lowest-influence vertex weights on all verts in a mesh and cull it out, so each vert has a max of 4 influences at most? It would be very very helpful I would be very appreciative…
Maybe it’s not so simple if nobody wanted to take up on it ^^;;
This could be added to mesh clean script or as newscript. Iv had that request once before, though not in regards to bone weight copy.
Writing this script is fairly trivial and you might want to have a go.
My bone exporter uses the 4 highest weights so its not too big a problem- but I could use that functionality also
This reduces to 4 of the smallest users
MAXUSERS= 4 from Blender import Scene import BPyMesh scn= Scene.GetCurrent() ob= scn.getActiveObject() me= ob.getData(mesh=1) groupNames, vWeightDict= BPyMesh.meshWeight2Dict(me) # Loop through the list of weight dicts for wd in vWeightDict: if len(wd)>MAXUSERS: items= wd.items() # get a copy of the items to sort items.sort(lambda i1, i2: cmp(i1, i2)) # sort by weights, smallest to biggest for weightGroup, weightValue in items[0:-MAXUSERS]: # remove all except the last MAXUSERS del wd[weightGroup] # Copy weights back to the mesh. BPyMesh.dict2MeshWeight(me, groupNames, vWeightDict)
so if I understand it correctly, using that script would require running it after entering it in the blender text editor every time? Or how would I format it to be a usable .py file?
Does it have to be run from a specific mode like object or edit mode?
What’s trivial to a guru is still sanskrit to the uninitiated
running in the text window if you like or you could make it a menu item…
add this header and copy into your scripts dir
#!BPY """ Name: 'Limit Weights...' Blender: 242 Group: 'WeightPaint' Tooltip: 'Limit the number of used verts.' """ Then restart blender and access it from the weight paint menu.
You’re a real prize package Cambo, thank you very much!
Is it OK if I host the script on a website? I try to take things I learn and teach other people who play TES4:Oblivion to create models, and this + weight copy really should help lower the bar to entry for people who haven’t been doing this stuff for a while, which is the goal.
I will do a Cambo is Awesome dance. I do this just for you
Sure, do whatever you like with it…
Ill include the functionality in 2.43, but thats a way off