*NEW* Bezier Group

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

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

*NEW* Bezier Group

Post by synthsin75 »

Ever wish bezier keyframes were more useful for multiple selected points in the Motion Graph?

Wish granted!

Here's a button script that allows you to modify bezier keyframes for a selection of points all at once in the Motion Graph.
https://drive.google.com/uc?export=down ... Zi1m59lhXv
  • Feature removed (not useful)If you hit the button on frame zero, you can choose whether the X & Y axes bezier handles are locked together. If you select Yes, manipulating one bezier handle will also move the other.
    I don't know how useful this will be, so I'd love some feedback on it.
  • If you hit the button on frames greater than zero, it does:
    • If you've selected some points, it stores this selection so they can be manipulated by the keyframe bezier handles. The selection is stored as a point group called "Bezier group", in case you need to reselect it. And it will automatically select only one point so the beziers can show in the motion graph (be sure to click the channel icon a couple of times to show the keyframes, see the User Manual p.362).
      • If there are keyframes selected, it will automatically convert these to bezier interpolation, otherwise it will convert all keys of the selected points to bezier.
      • If there is a store selection, and only one of its points are selected, hitting the button toggles to showing the selection, in case you want to add/remove points
      • If your selected points aren't all keyframed on the same frames, you will be asked whether you want to remove the unmatched points from the stored selection or add keyframes to match. "Remove from selection" will remove the points that have fewer keyframes, and "Add keyframes" will key all points to match.
    • If there are zero points selected, it will remove the point group and layer script*, so there's no need to use Gather Media, but all your existing changes will remain.


*For those interested in what the script is doing in the background:
This script uses an embedded layer script to lock bezier handles together and propagate changes to the stored selection. But you don't need to install the layer script. What I've done is if the layer script doesn't exist, this button writes it (to your scripts/ScriptResources folder) and embeds it. It only requires that the user has chosen a Custom Content Folder.


Merry Christmas everyone!!
Last edited by synthsin75 on Tue Mar 26, 2024 11:42 pm, edited 3 times in total.
chucky
Posts: 4650
Joined: Sun Jan 28, 2007 4:24 am

Re: *NEW* Bezier Group

Post by chucky »

Wow, Wes thank you, this sounds incredible and very useful, I wanted to do this many times.
It sounds ingenious and very sly.
Installing now.
chucky
Posts: 4650
Joined: Sun Jan 28, 2007 4:24 am

Re: *NEW* Bezier Group

Post by chucky »

Works great Wes.
So Is that because it has to run as a layer script while editing, it does go pretty slow, but when editing is finished, we can just uncheck the layer script and the fl rns fast and smooth, with the applied changes.
A very clever way around and major roadblock.
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: *NEW* Bezier Group

Post by synthsin75 »

chucky wrote:Works great Wes.
So Is that because it has to run as a layer script while editing, it does go pretty slow, but when editing is finished, we can just uncheck the layer script and the fl rns fast and smooth, with the applied changes.
A very clever way around and major roadblock.
Thanks, Chucky. Yep, and if you use the button on a frame greater than zero with no points selected, it will remove the layerscript for you.

Thinking about it, I could actually do that every time more than one point is selected, since you wouldn't be editing bezier keys. I'll see about adding that.


Let me know if the locked axes handles are useful.

EDIT: I've updated the link with a version that *should* improve performance, and if it doesn't, hitting the button to toggle showing the selection will also remove the layerscript.
User avatar
hayasidist
Posts: 3492
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: *NEW* Bezier Group

Post by hayasidist »

Well that's neat! The idea of holding the layer script as a text string and writing it / managing its activation from within the tool is inspired and inspiring! Nice one. (All sorts of ideas have popped into my head about that one - e.g. how much configuration might be achievable by having the tool 'inspect its runtime environment' to create (partial) strings tailored for the target layer -- e.g. to cut down the "set-up" work a layerscript has to do-- before writing the layerscript .lua?!)

I have encountered a couple of "features" with the tool (probably arising from the way I'm (mis-)using it) for your consideration:
-- using the add point tool on frame 0 to add a point to an existing Bezier group, Moho adds the point to the group and adds keys where expected which I can then move without the tool / layerscript noticing (i.e. no "mismatched keys" dialogue)
-- probably related to the above (i.e. after adding points), but not wholly sure how I got there: I have a layer with no layerscript but a I do have Bezier group - on frame 0 invoking the tool I get the "lock..?" question but whether I say Y or N the layerscript isn't (re)-applied.
-- again not sure how I got there - starting from a new empty layer - add a triangle (lm_shape); invoke the tool... I end up with a layer with the layerscript but no Bezier group - so no key syncing takes place -- this is a second layer in a doc.
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: *NEW* Bezier Group

Post by synthsin75 »

hayasidist wrote:Well that's neat! The idea of holding the layer script as a text string and writing it / managing its activation from within the tool is inspired and inspiring! Nice one. (All sorts of ideas have popped into my head about that one - e.g. how much configuration might be achievable by having the tool 'inspect its runtime environment' to create (partial) strings tailored for the target layer -- e.g. to cut down the "set-up" work a layerscript has to do-- before writing the layerscript .lua?!)
Thanks, Paul. Yeah, I'm tempted to implement almost every layerscript I can like this from now on. Especially for things like my animated hide edge tool, the user wouldn't have to worry about making sure the script is installed to the right location. I could even put a checkbox to show and toggle embedding.

Just last night I wrote a small menu script to reload all layerscripts in the file, so I didn't have to keep finding the right layer and unembedded/reembedding all the time while testing. Life saver.

Code: Select all

-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************

ScriptName = "Syn_ReloadLayerScripts"

-- **************************************************
-- General information about this script
-- **************************************************

Syn_ReloadLayerScripts = {}

function Syn_ReloadLayerScripts:Name()
	return "Reload Layer Scripts"
end

function Syn_ReloadLayerScripts:Version()
	return "0.1"
end

function Syn_ReloadLayerScripts:Description()
	return "Reloads all layer scripts"
end

function Syn_ReloadLayerScripts:Creator()
	return "(c) 2018 J.Wesley Fowler (synthsin75)"
end

function Syn_ReloadLayerScripts:UILabel()
	return "SYN: RELOAD LAYER SCRIPTS"
end

-- **************************************************
-- The guts of this script
-- **************************************************

function Syn_ReloadLayerScripts:Run(moho)
	local count = 0
	repeat
		local layer = moho.document:LayerByAbsoluteID(count)
		if layer then
			count = count + 1
			local script = layer:LayerScript()
			layer:SetLayerScript("")
			layer:SetLayerScript(script)
		end
	until not layer 
end
I have encountered a couple of "features" with the tool (probably arising from the way I'm (mis-)using it) for your consideration:
-- using the add point tool on frame 0 to add a point to an existing Bezier group, Moho adds the point to the group and adds keys where expected which I can then move without the tool / layerscript noticing (i.e. no "mismatched keys" dialogue)
Ah, yeah that's probably because I'm using both a point group and a stored table. I probably need to nix the table so I don't have to worry about both always being updated.
-- probably related to the above (i.e. after adding points), but not wholly sure how I got there: I have a layer with no layerscript but a I do have Bezier group - on frame 0 invoking the tool I get the "lock..?" question but whether I say Y or N the layerscript isn't (re)-applied.
Right now frame zero only handles the locked option. It doesn't do anything else. If you have more than one point selected (not editing bezier handles), it removes the layerscript for performance.
-- again not sure how I got there - starting from a new empty layer - add a triangle (lm_shape); invoke the tool... I end up with a layer with the layerscript but no Bezier group - so no key syncing takes place -- this is a second layer in a doc.
I'll have to check on that one.

Thanks for checking things for me, Paul.
Do you think the locked bezier handles are useful, or should that feature be abandoned?
I've also debated making this a tool (or a tool version) that would free up the options from frame zero. I kind of like using it with another tool selected though.
User avatar
hayasidist
Posts: 3492
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: *NEW* Bezier Group

Post by hayasidist »

synthsin75 wrote:Do you think the locked bezier handles are useful, or should that feature be abandoned?
I've not found a use for it yet.

And at first I was a bit unsure as to whether simply copying the Bezier info to all the selected points would achieve some of the transitions I imagined - but it works well if you can get one point trajectory right.

My thoughts right now are (incomplete) but maybe an option something like "symmetrical out / in" could be more useful???


as a bit more of rambling thinking:

Where I'd like a lot more (native!!) support is in creating a good "rolling" motion (as in request 35035 in the usual place). And when I responded to this topic: viewtopic.php?f=3&p=185943#p185705 I had something of a blend of Penny's ideas: viewtopic.php?f=9&t=32578#p185968 and my follow curve tool: viewtopic.php?f=12&t=25384&p=182189#p180927 in mind --- IOW the UI is not the Moho motion graph editor but some higher order "preview" window that (e.g.) allows you to define the translation and/or rotation of the "centre" of the selection and the tool sets the Bezier params for all the points in the shape so it keeps its proper form as it moves (i.e. prevents the "shrinking" effect when rotating an object more than a few degrees). Now I freely acknowledge that this is not trivial and outside the scope of the (great) tool you've just provided.
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: *NEW* Bezier Group

Post by synthsin75 »

hayasidist wrote:
synthsin75 wrote:Do you think the locked bezier handles are useful, or should that feature be abandoned?
I've not found a use for it yet.

And at first I was a bit unsure as to whether simply copying the Bezier info to all the selected points would achieve some of the transitions I imagined - but it works well if you can get one point trajectory right.

My thoughts right now are (incomplete) but maybe an option something like "symmetrical out / in" could be more useful???
I have been toying with the idea of other kinds of locks/constraints, like symmetrical.
as a bit more of rambling thinking:

Where I'd like a lot more (native!!) support is in creating a good "rolling" motion (as in request 35035 in the usual place). And when I responded to this topic: viewtopic.php?f=3&p=185943#p185705 I had something of a blend of Penny's ideas: viewtopic.php?f=9&t=32578#p185968 and my follow curve tool: viewtopic.php?f=12&t=25384&p=182189#p180927 in mind --- IOW the UI is not the Moho motion graph editor but some higher order "preview" window that (e.g.) allows you to define the translation and/or rotation of the "centre" of the selection and the tool sets the Bezier params for all the points in the shape so it keeps its proper form as it moves (i.e. prevents the "shrinking" effect when rotating an object more than a few degrees). Now I freely acknowledge that this is not trivial and outside the scope of the (great) tool you've just provided.
Yeah, beziers could solve the problem of having to key every frame when doing a point rotation, in order to maintain volume. That sounds like math that is more up your alley than mine.
chucky
Posts: 4650
Joined: Sun Jan 28, 2007 4:24 am

Re: *NEW* Bezier Group

Post by chucky »

This script is reminding me of the days when people first started mucking around with the 2.5 d stuff that predated smart actions.
This kind of ingenuity can kick off a wave of creative thinking and new approaches and solutions for old problems.
Bravo Wes...so impressed.
I really try to keep away from layer scripts as a rule, but this really changes the way they work and have to be managed.
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: *NEW* Bezier Group

Post by synthsin75 »

I've updated this script, same link: https://sites.google.com/site/synthsin/ ... ects=0&d=1

I've removed the locked handle option, so you can set and toggle point selection on frame zero now.
I've also added code to check the layerscript version and update it if needed.


Hopefully this addresses all (most?) the issues you found, Paul. This does open up the interesting possibility of storing layerscripts as layer scriptdata strings. You'd just always need one script installed to actually write and embed them. That script could even read existing embedded scripts into scriptdata. It wouldn't really help file portability though, since you'd still need that one script installed on any copy of Moho you use the file in.


Chucky, while probably every layerscript could be written and embedded by a tool/menu/button script, some (like the one used for my animated hide edge tool) would still require using Gather Media to make the file portable. But yeah, much easier to have a tool write/embed a layerscript than navigating to wherever you put it.
User avatar
hayasidist
Posts: 3492
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: *NEW* Bezier Group

Post by hayasidist »

Hi Wes, I'm on family duty today so I won't be able to give the new version a good workout just yet -- but a quick thought - you might like to strip out comments as well as white space.

this should take out all of the --[=[ <blah> ]=]

Code: Select all

	clean = string.gsub (clean, "%-%-%[%=%[.-%]%=%]", "")
	clean = string.gsub (clean, "%s+", " ") 
and obviously adaptable for other comment syntaxes but since there aren't any in your file ...
Last edited by hayasidist on Sat Dec 29, 2018 12:41 pm, edited 1 time in total.
chucky
Posts: 4650
Joined: Sun Jan 28, 2007 4:24 am

Re: *NEW* Bezier Group

Post by chucky »

some (like the one used for my animated hide edge tool) would still require using Gather Media to make the file portable.
Ahhh I think I understand better now
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: *NEW* Bezier Group

Post by synthsin75 »

hayasidist wrote:Hi Wes, I'm on family duty today so I won't be able to give the new version a good workout just yet -- but a quick thought - you might like to strip out comments as well as white space.

this should take out all of the --[=[ <blah> ]=]

Code: Select all

	clean = string.gsub (clean, "%-%-%[%=%[.-%]%=%]", "")
	clean = string.gsub (clean, "%s+", " ") 
and obviously adaptable for other comment syntaxes but since there aren't any in your file ...
I'm already doing:

Code: Select all

layerscript = string.gsub(layerscript, "%s+", " ") --compress whitespace
Which is why I'm using "--[=[long block]=]" comments instead of just "--line" comments, since the latter would comment out the rest of a single-line script. And I can't use regular "--[[block]]" comments because the multi-line string uses "[[long quote/literal string]]" brackets where the Lua parser reads the first closing "]]" as the end of the string.

And I still want the layer script to include this information:

Code: Select all

-- **************************************************
-- Syn_BezierMatch (c)2018 J.Wesley Fowler (synthsin75)
--
-- For use with syn_bezier_group.lua
-- **************************************************
I suppose I could use different length long block comments ("--[=[**]=]" versus "--[==[**]==]", etc.) to remove the code I may end up using later (like for in/out symmetry), but I doubt that small bit of code has any appreciable performance difference in a script that already has compressed whitespace. If you have reason to believe otherwise, let me know.
User avatar
hayasidist
Posts: 3492
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: *NEW* Bezier Group

Post by hayasidist »

Hi Wes, Sorry -- it's still not doing it for me...

here's the sequence:

new moho file (unsaved)
just the one default vector layer
frame 0: create a rectangle (lm_shape) and select all points
frame 25: shape not moved - use translate point tool to create a (smooth interp) key
frame 50: move the shape (smooth interp key created)
frame 75: move again (smooth interp key created)

frame 0: all points selected; select the frame 50 key; invoke your tool: All as expected: Just the frame 50 Key becomes Bezier; Bezier group created; one point selected; layerscript file shows as active in the layer.

frame 60: in motion graph move Bezier handles for the frame 50 key. Changes not propagated to other points?!

Check that Bezier Group and layerscript still showing as present - OK
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: *NEW* Bezier Group

Post by synthsin75 »

Thanks, Paul. Those steps also showed another problem. It deselects the keyframe, and when you toggle to show the selection, it then makes all keys bezier.

I'll see about fixing these.
Post Reply