Code: Select all
-- finally, test for translation by dragging a curve
local selCount = 0
local selBone = nil
for i = 0, skel:CountBones() - 1 do
local bone = skel:Bone(i)
if (bone.fSelected) then
selCount = selCount + 1
selBone = bone
if (selCount > 1) then
break
end
end
end
if (selCount == 1 and selBone ~= nil and self.showPath) then
local translationWhen = -20000
local g = mouseEvent.view:Graphics()
local m = LM.Matrix:new_local()
local vec = LM.Vector2:new_local()
local pt = LM.Point:new_local()
local totalTimingOffset = moho.layer:TotalTimingOffset()
moho.layer:GetFullTransform(moho.frame, m, moho.document)
-- First see if any keyframes were picked
for i = 0, selBone.fAnimPos:CountKeys() - 1 do
local frame = selBone.fAnimPos:GetKeyWhen(i)
vec = selBone.fAnimPos:GetValue(frame)
m:Transform(vec)
g:WorldToScreen(vec, pt)
if (math.abs(pt.x - mouseEvent.pt.x) < self.TOLERANCE and math.abs(pt.y - mouseEvent.pt.y) < self.TOLERANCE) then
translationWhen = frame
self.trPathBone = selBone
break
end
end
-- If no keyframes were picked, try picking a random point along the curve.
if (translationWhen <= -10000) then
local startFrame = selBone.fAnimPos:GetKeyWhen(0)
local endFrame = selBone.fAnimPos:Duration()
if (endFrame > startFrame) then
local oldVec = LM.Vector2:new_local()
g:Clear(0, 0, 0, 0)
g:SetColor(255, 255, 255)
g:BeginPicking(mouseEvent.pt, 4)
for frame = startFrame, endFrame do
vec = selBone.fAnimPos:GetValue(frame)
m:Transform(vec)
if (frame > startFrame) then
g:DrawLine(oldVec.x, oldVec.y, vec.x, vec.y)
end
if (g:Pick()) then
translationWhen = frame
self.trPathBone = selBone
break
end
oldVec:Set(vec)
end
end
end
if (translationWhen > -10000) then
self.translationFrame = translationWhen
return 0
end
end
this is part of code in boneTranslate tool.