-- *************************************************** -- General information about this script -- *************************************************** ScriptName = "GE_Bones_for_ShapesV2" -- *************************************************** -- General information about this script -- *************************************************** GE_Bones_for_ShapesV2 = {} function GE_Bones_for_ShapesV2:Name() return "Bones for Shapes" end function GE_Bones_for_ShapesV2:Version() return "0.1" end function GE_Bones_for_ShapesV2:Description() return "Create a set of bones ready for shape sort script" end function GE_Bones_for_ShapesV2:Creator() return "Genete" end function GE_Bones_for_ShapesV2:UILabel() return "GE: Create Bones for Shapes V2" end function GE_Bones_for_ShapesV2:IsEnabled(moho) if(moho:ParentSkeleton() ~= nil and moho:CountShapes()>0) then return true else return false end end -- *************************************************** -- The guts of this script -- *************************************************** function GE_Bones_for_ShapesV2:Run(moho) local skel = moho:ParentSkeleton() local mesh = moho:Mesh() if (skel == nil or mesh == nil) then print ("Please run the script inside a Vector layer being it a child of a Bone layer") return end local cshapes = mesh:CountShapes() if (cshapes == 0) then print ("There must be almost one shape") return end local bones = skel:CountBones() if (bones == 0) then print ("There must be almost one bone") return end local selected = -1 for k=0, bones-1 do if (skel:Bone(k).fSelected == true) then selected = k break end end if (selected == -1) then print ("Almost one bone must be selected") return end moho.document:PrepUndo(moho.layer:Parent()) moho.document:SetDirty() for i=0, cshapes -1 do local ebone = nil local add = true for j = 0, skel:CountBones()-1 do ebone = skel:Bone(j) local bname = ebone:Name() local subName = string.sub(bname, -3) local name = string.sub(bname, 1, -4) local sID = tonumber(name) if (subName == ".sh" and sID == i and add == true) then add = false print("Found bone " .. i .. ".sh") local v = LM.Vector2:new_local() v:Set(0.01*i,-0.05*(i+1)) ebone.fParent = selected ebone.fAnimPos:SetValue(0, v) ebone.fAnimAngle:SetValue(0,0.0) ebone.fLength = 0.05 ebone.fStrength = 0 break else add = true end end if (add == true) then local bone = skel:AddBone(0) local v = LM.Vector2:new_local() v:Set(0.01*i,-0.05*(i+1)) bone.fParent = selected bone:SetName( i .. ".sh") bone.fAnimPos:SetValue(0, v) bone.fAnimAngle:SetValue(0,0.0) bone.fLength = 0.05 bone.fStrength = 0 end end end