

Moderators: Víctor Paredes, Belgarath, slowtiger
Code: Select all
function LayerScript(moho)
if (moho.frame == 0) then
return
end
local skel = moho:Skeleton()
if (skel == nil) then
print("No skeleton found in layer:", moho.layer:Name())
return
end
local matrix = LM.Matrix:new_local()
local beforeVec = LM.Vector3:new_local()
local afterVec = LM.Vector3:new_local()
local origin = LM.Vector2:new_local()
moho.layer:GetFullTransform(moho.frame, matrix, nil)
matrix:Transform(beforeVec)
moho.layer:GetFullTransform(moho.frame, matrix, moho.document)
for i = 0, skel:CountBones() - 1 do
local originBone = skel:Bone(i)
if (originBone:Name() == "Origin") then
originBone = originBone.fAnimPos:GetValue(moho.frame)
moho.layer:SetOrigin(originBone)
end
end
moho.layer:GetFullTransform(moho.frame, matrix, nil)
matrix:Transform(afterVec)
local newLayerPos = moho.layer.fTranslation.value + beforeVec - afterVec
local v = newLayerPos - moho.layer.fTranslation.value
if (v:Mag() > 0.000001) then
moho.layer.fTranslation:SetValue(moho.frame, newLayerPos)
moho:NewKeyframe(CHANNEL_LAYER_T)
end
moho.document:DepthSort()
skel:UpdateBoneMatrix()
end