Move curvature key from frame x to frame y Moho 12

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
strider2000
Posts: 506
Joined: Sat Mar 07, 2015 5:14 pm
Contact:

Move curvature key from frame x to frame y Moho 12

Post by strider2000 »

OK,
This one is over my head. I've been trying things for hours and can't figure it out. All I want to do is programmatically move a curvature key from one frame to another. It seems like

Code: Select all

local vecChannel = curve:Curvature(pointNum) 

as per http://www.lostmarble.com/forum/viewtop ... ys#p139010
would give me the channel I want, but I don't see the keys I expect. I'm thinking that would have worked fine prior to Moho 12.

I have seen
http://mohoscripting.com/snippets/5 - Moho curvature to bezier handles conversion
but
  • I don't yet follow it well enough to get it working
  • It seems to be focused on getting the control handles, which is not directly what I'm trying to do
I've also seen
http://mohoscripting.com/snippets/4 - Iterate through all the channels in the layer
and I can get it to work for simple cases (ie I tried a 2 point example with only 1 key, after frame 0, so I just moved subchannels 6, 7, 8 and 9), but
  • It's a different interface than what I expected. I'm guessing there's a way to get the subchannels from a channel, rather than "moho.layer:Channel(i, j, moho.document)", but I haven't figured that out yet.
  • The subchannel id for "moho.layer:Channel(i, j, moho.document)" seems to be a multiple of the number of points. (snippet 5 seems to imply that as well). This may be the only way to get to it, but it seems much more complex than I was expecting.
  • It seems far more complex than what I'm trying to do
It may be that moving the curvature keys is much more complex than I expected, for legacy reasons, but I'm hoping that I'm just missing something simple, about curvature, and that it's obvious to others.

Thanks for any help!
User avatar
strider2000
Posts: 506
Joined: Sat Mar 07, 2015 5:14 pm
Contact:

Re: Move curvature key from frame x to frame y Moho 12

Post by strider2000 »

Bummer, I should have posted this to scripting. I don't know how to just move it over. Sorry :(
User avatar
Víctor Paredes
Site Admin
Posts: 5646
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Re: Move curvature key from frame x to frame y Moho 12

Post by Víctor Paredes »

strider2000 wrote: Tue Jul 23, 2019 12:09 am Bummer, I should have posted this to scripting. I don't know how to just move it over. Sorry :(
Moved :)
Image Image Image Image
Moho Product Manager

www.mohoanimation.com
Rigged animation supervisor in My father's dragon - Lead Moho artist in Wolfwalkers - Cartoon Saloon - My personal Youtube Channel
User avatar
strider2000
Posts: 506
Joined: Sat Mar 07, 2015 5:14 pm
Contact:

Re: Move curvature key from frame x to frame y Moho 12

Post by strider2000 »

Thank you Victor :)
User avatar
synthsin75
Posts: 9935
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Move curvature key from frame x to frame y Moho 12

Post by synthsin75 »

This is how you move keyframes: AnimChannel:SetKeyWhen(id, when)
User avatar
strider2000
Posts: 506
Joined: Sat Mar 07, 2015 5:14 pm
Contact:

Re: Move curvature key from frame x to frame y Moho 12

Post by strider2000 »

My problem is that I can't figure out which channel is the correct one. I thought it would be M_Curve:Curvature(), but it's not :(
When I call CountKeys() on the AnimVal I get back from Curvature, it's always 1, even though the channel, as I see in the UI, clearly has more than 1 key.
User avatar
synthsin75
Posts: 9935
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Move curvature key from frame x to frame y Moho 12

Post by synthsin75 »

M_Curve:Curvature(id) requires the point ID on the curve. The LM freehand tool has an example of this.
User avatar
strider2000
Posts: 506
Joined: Sat Mar 07, 2015 5:14 pm
Contact:

Re: Move curvature key from frame x to frame y Moho 12

Post by strider2000 »

Hmm ... that's what I'm using. I must be doing something wrong. I'll check out the LM freehand tool.
Thanks.
Stan
Posts: 199
Joined: Sun Apr 19, 2009 3:22 pm

Re: Move curvature key from frame x to frame y Moho 12

Post by Stan »

strider2000 wrote: Mon Jul 22, 2019 5:37 am All I want to do is programmatically move a curvature key from one frame to another.
That should be as simple as:

Code: Select all

M_Curve:GetCurvature(ptID, frame)
M_Curve:SetCurvature(ptID, curvature, frame)
http://mohoscripting.com/classes/M_Curve
________________________________________________________________________
https://mohoscripting.com/ - Unofficial Moho Lua scripting documentation
https://mohoscripts.com/ - The best place to publish and download scripts for Moho
User avatar
strider2000
Posts: 506
Joined: Sat Mar 07, 2015 5:14 pm
Contact:

Re: Move curvature key from frame x to frame y Moho 12

Post by strider2000 »

That will copy, but not move. I can't delete the original key. I'm sure it's the subchannels that are messing me up. Right now it's looking like there's no easy way to do it :(
User avatar
hayasidist
Posts: 3492
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Move curvature key from frame x to frame y Moho 12

Post by hayasidist »

sorry for the briefest of replies and for the fact I can't yet spend the time to try out what I'm suggesting -- if you're still stuck in a week or so, I'll be able to take a longer look at this.

But for now…

it might be as simple as M_Curve:Curvature:DeleteKey(when)

if not .. there are five subchannels on a curvature key -- scan the layer's channels and get the channel info data for the point's curvature channel ( http://mohoscripting.com/methods/552 ) and loop through the subchannels

Code: Select all

		local subChans = chInfo.subChannelCount
		for k = 0, subChans - 1 do
			-- delete key on the subchannel
		end

hope that moves you forward!
User avatar
strider2000
Posts: 506
Joined: Sat Mar 07, 2015 5:14 pm
Contact:

Re: Move curvature key from frame x to frame y Moho 12

Post by strider2000 »

Thanks hayasidist.

Here's my latest status, for anyone else that might be interested in this.
  • M_Curve:Curvature:DeleteKey(when) and looping through subchannels both delete keys
  • I'm able to get the key frames now, by going to any of the subchannels, for a point, and building a key frame list
  • channel:SetKeyWhen(key, frame) fails really weirdly, when I have more than one key. It works only on the last key, even if I give it a valid earlier key
  • GetCurvature/SetCurvature on the curve seem to work, but again only on the last key, but weirdly, it seems to properly update the timeline, but all destination keys seem to have the same value
So, I'm getting close, using channels to identify the current key frames and using curve operations to copy and delete keys and the appropriate key frames. But just having trouble if there's more than one key.

For those that are interested, I basically have a number of older characters that use the technique of combining + and - bone angles in a single action. They work fine, but with the improved action menu I'm preferring the 2 actions. It's less error prone for me. Anyway, I thought, "Oh cool. I'll just write a script to split them up. This should be easy :)" Well, by now I could have done it all by hand :( If I only had one key frame or only needed to copy a key frame I'd be done :(

At this point, it's now just an interest of a puzzle "How do I do it?" For my characters, I'm just going to split the actions manually.

hayasidist, I have a day job project that has a dead line next month, so today was my last day for about a month. So, no rush at all. I would be interested if you figure it out.

All,
If I finally figure it out, I'll post here, in case someone else is wanting to do the same thing.
User avatar
synthsin75
Posts: 9935
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Move curvature key from frame x to frame y Moho 12

Post by synthsin75 »

Code: Select all

	---[=[--move a keyframe
	local layer = moho.layer
	local ch = MOHO.MohoLayerChannel:new_local()
	local chanCnt = layer:CountChannels()-1
	for i=0, chanCnt do
		layer:GetChannelInfo(i, ch)
		--print(ch.name:Buffer(), "    ", ch.subChannelCount)
		for j=0, ch.subChannelCount-1 do
			local chan = layer:Channel(i, j, moho.document)
			if (ch.name:Buffer() == "Point Curvature") then
				chan:SetKeyWhen(1, 50)
			end
		end
	end
	--]=]
You can uncomment the print line to find the name of a specific animation channel, and you can't move ID zero keys, just like you can't move frame zero keys manually.
Post Reply