-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************

ScriptName = "AE_CreateJointHelper"

-- **************************************************
-- General information about this script
-- **************************************************

AE_CreateJointHelper = {}

function AE_CreateJointHelper:Name()
	return "Create Joint Helper"
end

function AE_CreateJointHelper:Version()
	return "1.1"
end

function AE_CreateJointHelper:UILabel()
	return "Create Joint Helper"
end

function AE_CreateJointHelper:Creator()
	return "Alexandra Evseeva"
end

function AE_CreateJointHelper:Description()
	return "Create child bone driven with its single sibling"
end


-- **************************************************
-- Recurring values
-- **************************************************

-- AE_CreateJointHelper.value1 = false

-- **************************************************
-- Is Enabled
-- **************************************************

function AE_CreateJointHelper:IsEnabled(moho)
	return moho:Skeleton()
end


-- **************************************************
-- The guts of this script
-- **************************************************

function AE_CreateJointHelper:Run(moho)

	moho.document:PrepUndo(moho.layer)
	moho.document:SetDirty()
	
	local skel = moho:Skeleton()
	local boneID = skel:SelectedBoneID()
	local bone = skel:Bone(boneID)
	if not bone then return end
	if skel:CountBoneChildren(boneID)<1 then return end
	local childID = skel:GetFirstChildBone(boneID)
	local newBone = skel:AddBone(0)
	newBone:SetName(bone:Name().."helper")
	newBone.fAnimParent:SetValue(0, boneID)
	newBone.fParent = boneID
	skel:UpdateBoneMatrix(skel:BoneID(newBone))
	local pos = LM.Vector2:new_local()
	pos:Set(bone.fLength, 0)
	newBone.fAnimPos:SetValue(0, pos)
	--newBone.fAnimAngle:SetValue(0, -math.pi/2)
	newBone.fAnimAngle:SetValue(0, skel:Bone(childID).fAnimAngle:GetValue(0)/2-math.pi/2)
	newBone.fLength = bone.fLength/2
	newBone.fStrength = 0
	newBone.fAngleControlParent = childID
	newBone.fAngleControlScale = 0.5
	newBone.fIgnoredByIK = true
	newBone.fShy = true
end





Create joint helper
Listed

Script type: Button/Menu

Uploaded: Sep 15 2020, 11:06

Create a bone rotating half of joint angle
This script, and all other scripts on this site are distributed as free software under the GNU General Public License 3.0 or later.
Downloads count: 6