Hello guys! Well... I almost thought that I'd got it! And after only a few hours of scripting!!!

But well, finally seems that there is a problem with Origin movement and X/Y/Z rotation interaction... the problem seems occurs after Translation Layer keyframes are wrote, cause the firs time you play the animation all seems right, but the second time (when keys still have been wrote) a weird and unexpected results start to occur... Anyway this is a very first idea and sure it requires more work, but well... I only put it here just in case somebody with scripting powers had any suggestion or advice to can get reliable results meantime I keep on experimenting

...Well, here is the 1.0.2 beta version:
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
Well, if you want to try it, the only thing you have to take into account is have a bone called
Origin inside the Bone Layer where script is embedded and nothing more, the Origin of the own bone layer will be traslated with it and so animatable along the time, very useful (if someday it works fine

) in many situations, I think... CIAO!