[Closed] Remove unused bones from a Skin Mod
Hello maxscript masters,
This is probably a simple script but after a few hours and with my very weak programming skills I was unable to make anything working. My project needs a script that will find all unused bones (without weights) in a skin mod and remove them (from the mod only!).
I tried to find a function that will get all weights per bone, and than use a cycle to check if there is an empty one, but it seams it’s not that simple. Any help is welcome.
Thanks in advance for spending time reading this!
Regards
Yes this function is useful and I’ve been using it for years
(
local weightThresh = 0.0001
local objs = selection as array
for obj in objs do (
select obj
for m in obj.modifiers where classof m == Skin do (
modPanel.setCurrentObject m
local vertCount = skinOps.GetNumberVertices m
local bonesCount = skinOps.GetNumberBones m
local unusedBones = #{1..bonesCount}
for v = 1 to vertCount do (
local vertWeightCount = skinOps.GetVertexWeightCount m v
for i = 1 to vertWeightCount do (
local weight = skinOps.GetVertexWeight m v i
if weight >= weightThresh then (
local boneID = skinOps.GetVertexWeightBoneID m v i
unusedBones[boneID] = false
)
)
)
for i = bonesCount to 1 by -1 where unusedBones[i] do (
skinOps.SelectBone m i
skinOps.RemoveBone m
)
format "% Bones where removed from %.%
" unusedBones.numberSet obj.name m.name
)
)
)
Holy cow, so it’s not 3-4 lines like I thought You RULE, MatanH! Thank you very much and wish you all best!
Regards
just curious… what is a practical use of removing bones from a skin by weight threshold?
I also use this usually after converting skin wrap to skin. You could set weights to zero but I like to clean up useless thinds when I rig. I find it easier to work like this. You can call it OCD if you want
Hello again
Let me explain my case: we create add-ons for characters (clothes, armor etc). In order to copy the weights we use Skin Wrap and than fix the problematic areas. Then we use a plugin that extra polishes and smooths the skin and this plugin really hates bones that are there but not in use (they mess up the calculations) It can be done on hand of course but sometimes they are just too many. This script is a huge help
my OCD has left further… i prefer to initialize a skin without bones i will never need
but… in many cases i prefer to add bones with no influence to have the right (continuous) hierarchy for example .
how the ‘optimized’ skin bones list will look like if a hand-bone doesn’t have an influence instead of lower-arm and fingers?