what is test for translation by dragging a curve?

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
davoodice2
Posts: 381
Joined: Tue Jun 15, 2021 1:14 pm

what is test for translation by dragging a curve?

Post by davoodice2 »

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
Hello friends. I don't know what does this code. anybody can help me?
this is part of code in boneTranslate tool.
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
User avatar
synthsin75
Posts: 10013
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: what is test for translation by dragging a curve?

Post by synthsin75 »

If you have show path enabled on the tool, it will display the translation path. If you click on this path, you can pull it around and set new keyframes on the timeline, at that time on the path...without having to be on that frame.
User avatar
davoodice2
Posts: 381
Joined: Tue Jun 15, 2021 1:14 pm

Re: what is test for translation by dragging a curve?

Post by davoodice2 »

synthsin75 wrote: Mon Nov 08, 2021 4:26 pm If you have show path enabled on the tool, it will display the translation path. If you click on this path, you can pull it around and set new keyframes on the timeline, at that time on the path...without having to be on that frame.
thank you again.
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
Post Reply