Multi layer Magnet Script?
Moderators: Víctor Paredes, Belgarath, slowtiger
-
- Posts: 303
- Joined: Thu May 13, 2010 2:01 pm
-
- Posts: 303
- Joined: Thu May 13, 2010 2:01 pm
Ok, Ive picked this up. It had some challenges for me, but I got it to work and even added some useful extras to the magnet tool. But Ive stumbled upon a problem:
The tool works depending on its location on the group layer. If the points of a child layer have been transformed by something (layer translate, layer, rotate, layer scale, or bones) the location of the tool and the points selected will missmatch.
For example: say I have a group layer and in it is a vector layer. But the vector layer has been translated 0.5 to the rigfht on the x-axis with layer translate. If I use my new magnet tool on the group layer, it will deform the points in the vector childlayer, but the points it selects to deform are 0.5 to the right from the tool point, instead of right where I click. This same missmatch will happen if the childlayer has been rotated or scaled with the layer tools, or if it is transformed by bones.
To fix this I need to compensate for the transformations. How would I do that?
Or: is there a way to get the points' screen location, independant of any transformations?
Anyone?? Rudiger???
The tool works depending on its location on the group layer. If the points of a child layer have been transformed by something (layer translate, layer, rotate, layer scale, or bones) the location of the tool and the points selected will missmatch.
For example: say I have a group layer and in it is a vector layer. But the vector layer has been translated 0.5 to the rigfht on the x-axis with layer translate. If I use my new magnet tool on the group layer, it will deform the points in the vector childlayer, but the points it selects to deform are 0.5 to the right from the tool point, instead of right where I click. This same missmatch will happen if the childlayer has been rotated or scaled with the layer tools, or if it is transformed by bones.
To fix this I need to compensate for the transformations. How would I do that?
Or: is there a way to get the points' screen location, independant of any transformations?
Anyone?? Rudiger???
-
- Posts: 303
- Joined: Thu May 13, 2010 2:01 pm
Ok, Ive been looking around and found something about the FullTransform matrix. So this is what i wrote:
But it doesn't work. As far as I figured, I need to transform the vector mouseVec which is used to calculate the influence over the points in a layer's mesh. And i need to transform it using GetFullTransform which is all the transformation done by parent layers.
How would i implement this? Please help. If i can get this to work i can share a multi layer magnet tool.
Thanks!
Code: Select all
local transformMatrix = LM.Matrix:new_local()
layer:GetFullTransform(moho.frame, transformMatrix, moho.document)
transformMatrix:Transform(mouseVec)
How would i implement this? Please help. If i can get this to work i can share a multi layer magnet tool.
Thanks!
- capricorn33
- Posts: 249
- Joined: Sun Oct 02, 2005 9:49 am
- Location: Finland
- Contact:
You know I'm having the exact same problem with another script that I am working on right now... Sorry Breinmeester, I don't have any answers to give you but I would ALSO be very, very interested - no, THRILLED - if anyone could share some kind of insight to this enigma (regarding how to get the position of a point affected by bones and layer transformation.... )
All this matrix stuff makes my brain hurt big time and I'm really worried that my head might be about to explode from trying to figure this out...
So if anyone can help out I can also promise to share a very cool arc tracking device when I'm finished with it...
All this matrix stuff makes my brain hurt big time and I'm really worried that my head might be about to explode from trying to figure this out...
So if anyone can help out I can also promise to share a very cool arc tracking device when I'm finished with it...
capricorn ( - just call me "cap")
children's tv pro, character animator
children's tv pro, character animator
-
- Posts: 303
- Joined: Thu May 13, 2010 2:01 pm
Breinmeester....this is something I have been wanting for years!!! It would be an amazing time saving tool for animating multilayered AS characters. If you have created it you will be worshipped as an AS god!
Cheers
D.K
Cheers
D.K
http://www.creativetvandmedia.com
My store on Renderosity:
https://www.renderosity.com/mod/bcs/?uid=921315
My store on Renderosity:
https://www.renderosity.com/mod/bcs/?uid=921315
- capricorn33
- Posts: 249
- Joined: Sun Oct 02, 2005 9:49 am
- Location: Finland
- Contact:
-
- Posts: 303
- Joined: Thu May 13, 2010 2:01 pm
This worked for me:
Code: Select all
for i = 0, mesh:CountPoints() - 1 do -- do for every point in the layer's mesh the following:
local pt = mesh:Point(i) -- store a point of the mesh in 'pt'
local v = pt.fPos -- set 'v' as the screen position of the point in 'pt'
local pvec = LM.Vector2:new_local() -- create a new vector 'pvec' to calculate with
local m = LM.Matrix:new_local() -- create a new matrix called 'm'
layer:GetFullTransform(moho.frame, m, moho.document) -- get all of the transformations for the layer on the current frame and store it in matrix 'm'
pvec:Set(pt.fAnimPos:GetValue(moho.frame)) -- store the animation position of point 'pt' on the current frame in vector 'pvec'
m:Transform(pvec) -- transform vector 'pvec' using matrix 'm' to compensate for all of the transformations parent layers and bones force upon the points location
v = pvec -- set the screen position of point 'pt' to be the transformed vector 'pvec'
end
- capricorn33
- Posts: 249
- Joined: Sun Oct 02, 2005 9:49 am
- Location: Finland
- Contact:
Billiant, Breinmeester !
Or should I say; a very good start, at least.
It helped me get the right result with combined point translation and layer transformation in my arc tracking tool - which is already bloody fantastic!!!
But still no luck with influence by bones, though...
Seems like the GetFullTransform isn't picking up parent bone layer's influence on the vectorlayer that I am tracking points on....
Did you get the bones influence included correctly in your magnet script?
Or should I say; a very good start, at least.
It helped me get the right result with combined point translation and layer transformation in my arc tracking tool - which is already bloody fantastic!!!
But still no luck with influence by bones, though...
Seems like the GetFullTransform isn't picking up parent bone layer's influence on the vectorlayer that I am tracking points on....
Did you get the bones influence included correctly in your magnet script?
capricorn ( - just call me "cap")
children's tv pro, character animator
children's tv pro, character animator
-
- Posts: 303
- Joined: Thu May 13, 2010 2:01 pm
- capricorn33
- Posts: 249
- Joined: Sun Oct 02, 2005 9:49 am
- Location: Finland
- Contact:
BTW, I suppose you already noticed that Ramón included a multilayer magnet in his latest tool, the "lost wiggle tool" ...?
viewtopic.php?t=16862
It works fine, but it still has the same kind of problems as we are discussing here, though...
viewtopic.php?t=16862
It works fine, but it still has the same kind of problems as we are discussing here, though...
capricorn ( - just call me "cap")
children's tv pro, character animator
children's tv pro, character animator
-
- Posts: 303
- Joined: Thu May 13, 2010 2:01 pm
No, i didn't. Would be nice to see how he did it. Did he fix the bone transform issue?
I added a few things to my Magnet tool, like the possibillity to adjust the strength of the tool's influence, the possibillity to have every point in a layer's mesh keyframed when the tool is used and the possibillity to adjust only the active sublayer of a switch group (so you dont have to open the group and select the active layer, but use the tool on the switch layer itself instead). I'm hoping to implement 'effect selected points onl' (which has been written before, so that won't be to hard) and write my own custom other logarithms to effect the mesh using the tool, so it will become more of a sculpt tool.
Im working on the problem in the very little spare time i have left. If there is someone out there who can help me, please do. This is an issue i'm sure more coders have stumbled upon and will in the future as well.
So i started looking at fRestMatrix and fPtMatrix for the parent bone of the point in the loop and try to have the vector transformed correctly. Im not sure what fRestMatrix, fMovedMatrix and fPtMatrix do exactly, so if someone knows more, please jump in.
I wrote the following. It doesn't work and i know some reasons why it doesn't. Im just posting it so people can jump in and think along:
I added a few things to my Magnet tool, like the possibillity to adjust the strength of the tool's influence, the possibillity to have every point in a layer's mesh keyframed when the tool is used and the possibillity to adjust only the active sublayer of a switch group (so you dont have to open the group and select the active layer, but use the tool on the switch layer itself instead). I'm hoping to implement 'effect selected points onl' (which has been written before, so that won't be to hard) and write my own custom other logarithms to effect the mesh using the tool, so it will become more of a sculpt tool.
Im working on the problem in the very little spare time i have left. If there is someone out there who can help me, please do. This is an issue i'm sure more coders have stumbled upon and will in the future as well.
So i started looking at fRestMatrix and fPtMatrix for the parent bone of the point in the loop and try to have the vector transformed correctly. Im not sure what fRestMatrix, fMovedMatrix and fPtMatrix do exactly, so if someone knows more, please jump in.
I wrote the following. It doesn't work and i know some reasons why it doesn't. Im just posting it so people can jump in and think along:
Code: Select all
if layer:LayerType() == MOHO.LT_BONE then
local k = pt.fParent
local bm = LM.Matrix:new_local()
local pm = LM.Matrix:new_local()
local skel = moho:Skeleton()
local parbone = skel:Bone(k)
bm:Set(parbone.fRestMatrix)
pm:Set(parbone.fPtMatrix)
bm:Multiply(pm)
bm:Transform(pvec)
end
- capricorn33
- Posts: 249
- Joined: Sun Oct 02, 2005 9:49 am
- Location: Finland
- Contact:
No, sadly, the bone transformation issue is still there...Breinmeester wrote:Would be nice to see how he did it. Did he fix the bone transform issue?
And if you want to see "how he did it" it's right there to look at. (He has some clever use of lists for keeping order to the meshes and points... you have to manually select the different layers you want the magnet to operate on).
I also did a little mod of my own to it, making it possible to let the magnet operate on pre-selected points only... so now I have the option to switch between two types of magnet. (By default it activates all points within the magnet radius, automatically...)
Hey, I like your list of features for your upcoming magnet tool. Looks like it is going to be another "must-have".
keep it going.
capricorn ( - just call me "cap")
children's tv pro, character animator
children's tv pro, character animator
-
- Posts: 303
- Joined: Thu May 13, 2010 2:01 pm
Yeah, I did that as well, so when a group layer is selected it well detect on mouse down wether it is necessary to compute a layer's mesh or that it's out of range of the magnet's influence.capricorn33 wrote:(He has some clever use of lists for keeping order to the meshes and points... you have to manually select the different layers you want the magnet to operate on).
I want to implement manual selection of layers as well, but when a group layer is selected it will process all it's childeren's (and children's chrildren's and so on) layers. Except when the group layer is a switch layer and 'process selected child only' is checked.
I have had no time to try out the method i posted above, but hope to find some time later this week.