Hi,
Is there a function in the API that returns the absolute position of a mesh point on the moho viewport?
I know the Mesh Point fPos returns the position relative to the layer the mesh is on. But of course the layer itself could have rotated, translated or resized, or it might be in a group layer that has been rotated, translated or resized.. etc. and this will not be reflected in the value fPos contains. Or is it something left for us to calculate? I'm just wondering this must be a common need so perhaps the API has a utility function that already does this for us? No point reinventing the wheel..
Thank you.
Absolute position of mesh points
Moderators: Víctor Paredes, Belgarath, slowtiger
- synthsin75
- Posts: 10266
- Joined: Mon Jan 14, 2008 11:20 pm
- Location: Oklahoma
- Contact:
Re: Absolute position of mesh points
The only ones are more about converting than giving an absolute position:
https://mohoscripting.com/methods/272
https://mohoscripting.com/methods/22
https://mohoscripting.com/methods/272
https://mohoscripting.com/methods/22
- Wes
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Donations: https://www.paypal.com/paypalme/synthsin75 (Thx, everyone.)
https://www.youtube.com/user/synthsin75
Scripting reference: https://mohoscripting.com/
Re: Absolute position of mesh points
Sorry I didn't explain clearly. I'm looking for an API function that will return the absolute position of mesh points in the moho vector coordinate system ie y-axis values 1 to -1. By absolute I meant it having taken into account any transformations performed on the layer hosting the mesh, and the transformations performed on the group layers above it. I want to place another shape (another layer) precisely on a mesh point without it having to go through the same transformations as the layer that mesh point is on, if that makes any sense.
I have not test them yet but I think the functions you kindly shared are related to converting between moho coordiantes and screen pixel co-ordinates, I see in the examples they are used to convert between mouse movements in the user interface and moho coordinates?
Thank you.
I have not test them yet but I think the functions you kindly shared are related to converting between moho coordiantes and screen pixel co-ordinates, I see in the examples they are used to convert between mouse movements in the user interface and moho coordinates?
Thank you.
- hayasidist
- Posts: 3841
- Joined: Wed Feb 16, 2011 8:12 pm
- Location: Kent, England
Re: Absolute position of mesh points
to answer your question about an API function - no.
but what you can do is work out where the point will be without all the transforms. Take a look at this (sadly the Kelleytown links are dead) http://www.lostmarble.com/forum/viewtop ... 93#p160993
the "bake vector" script does a whole lot more than just position - so you can skip over all the stuff about shape attributes if all you want is {x,y} - the part of the code you'll probably find useful is in function bakeVector()
The script is from 2017 and has not been updated for new moho features, but it still works sufficiently well for most purposes.
but what you can do is work out where the point will be without all the transforms. Take a look at this (sadly the Kelleytown links are dead) http://www.lostmarble.com/forum/viewtop ... 93#p160993
the "bake vector" script does a whole lot more than just position - so you can skip over all the stuff about shape attributes if all you want is {x,y} - the part of the code you'll probably find useful is in function bakeVector()
The script is from 2017 and has not been updated for new moho features, but it still works sufficiently well for most purposes.
Re: Absolute position of mesh points
Thank you Hayasidist,
Its surprising there is no API utility function for that. Thank you for your script, it does a hell of a lot more than I need.
I only needed to take in to account resizng, translation and rotation in 2d, so in the end I didn't need use a matrix and stuck to just simple trigonometry to work out the rotation around the z axis, and resize and translation were straight forward as long as I remembered not to assume the origin was always 0,0. To refresh my trig, search took me to this website: https://www.tutorialandexample.com/2d-rotation shockingly the equations given are wrong - some have wrong angles, and the matrix has the +/- mixed up.. propably just horrendous typos? Oh well its good to know I still have a few grey cells working to notice such mistakes lol.
In case anyone else needs to work out rotation:
if p(x,y) is rotated by angle A around origin(ox,oy) to position p(x1,y1) then
x1 = (x-ox)cosA - (y-oy)sinA + ox
y1 = (x-ox)sinA + (y-oy)cosA +oy
Thank you.
Its surprising there is no API utility function for that. Thank you for your script, it does a hell of a lot more than I need.
I only needed to take in to account resizng, translation and rotation in 2d, so in the end I didn't need use a matrix and stuck to just simple trigonometry to work out the rotation around the z axis, and resize and translation were straight forward as long as I remembered not to assume the origin was always 0,0. To refresh my trig, search took me to this website: https://www.tutorialandexample.com/2d-rotation shockingly the equations given are wrong - some have wrong angles, and the matrix has the +/- mixed up.. propably just horrendous typos? Oh well its good to know I still have a few grey cells working to notice such mistakes lol.
In case anyone else needs to work out rotation:
if p(x,y) is rotated by angle A around origin(ox,oy) to position p(x1,y1) then
x1 = (x-ox)cosA - (y-oy)sinA + ox
y1 = (x-ox)sinA + (y-oy)cosA +oy
Thank you.