Multi layer Magnet Script?

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Breinmeester
Posts: 303
Joined: Thu May 13, 2010 2:01 pm

Post by Breinmeester »

capricorn33 wrote: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... :-)
Hey Capricorn,
In my very sparse free time I managed to fool around with this a little and Ive found something that might be of use to you. It doesn't really work for what Im doing, but it might suffice your needs.

https://rapidshare.com/files/4250009215 ... racker.zip

Embed the script on the 'locator' layer and the layer translate will follow a point in the vector layer below, even when it's transformed using bones or layer transformations.

Code: Select all


	local mesh = moho:LayerAsVector(targetvectorlayer):Mesh()
	local pt = mesh:Point(1)
	local v = LM.Vector2:new_local()
	local dv = LM.Vector2:new_local()
	local k = LM.Vector3:new_local()
	local m = LM.Matrix:new_local()
	
	v:Set(pt.fAnimPos:GetValue(moho.frame))
	dv = pt.fPos - v
	
	-- Do transformations:
	targetvectorlayer:GetFullTransform(moho.frame, m, moho.document)
	m:Transform(v)
	v = v + dv
	
	k.x = v.x
	k.y = v.y
		
	-- Set result:
	thislayer.fTranslation:SetValue(moho.frame, k)

User avatar
capricorn33
Posts: 249
Joined: Sun Oct 02, 2005 9:49 am
Location: Finland
Contact:

Post by capricorn33 »

Breinmeester wrote: Ive found something that might be of use to you. It doesn't really work for what Im doing, but it might suffice your needs.

https://rapidshare.com/files/4250009215 ... racker.zip


Really? I have to try it out ASAP. :-)

There seems to be something wrong with that rapidshare link you provided... I tried in two different browsers and get file error in both... (?)

cap
capricorn ( - just call me "cap")
children's tv pro, character animator
User avatar
capricorn33
Posts: 249
Joined: Sun Oct 02, 2005 9:49 am
Location: Finland
Contact:

Post by capricorn33 »

ok, I got the rapidhare link at last... and...

- OMG OMG - it works!!! :shock:

This might be EXACTLY what I need to get my tracker script in order!
Fantastic, Breinmeester!

Too bad it doesn't solve your own problems with the multilayer-magnet, though...


Anyway, I'll be back just as soon as I have had a little time to experiment with this one. Might be a fully functional tracker tool coming up soon... 8)
capricorn ( - just call me "cap")
children's tv pro, character animator
Breinmeester
Posts: 303
Joined: Thu May 13, 2010 2:01 pm

Post by Breinmeester »

Well, I've found some problems with it. Especially a combination of layer rotate and bones doesn't seem to work.

I'll keep on searching.
User avatar
capricorn33
Posts: 249
Joined: Sun Oct 02, 2005 9:49 am
Location: Finland
Contact:

Re: Multi layer Magnet Script?

Post by capricorn33 »

Breinmeester,

I think I cracked it!
My pointtracking code works now, it reacts correctly to all
point / bone / layer transformation!

The problem, as I understood after having studied your code for a while and reading some of the old discussions on the subject, seemed to be that you have to use fPos, not fAnimPos, to get the bone influence included correctly in the transform.

I needed to collect positions from several frames for my tracking device, but since fPos only returns the current position from the current frame, I had to control the framevalue using SetCurFrame.

Something like this (a snippet from my pointtracker, the for-loop that is getting all the point position values):

Code: Select all


for frame = 0, moho.document:EndFrame() do
	moho:SetCurFrame(frame)
	pv = pt.fPos	
	layer:GetFullTransform(frame, m, moho.document)
	m:Transform(pv) 		
	-- ...and then on to draw()-routines using pv for positioning...

end
It simply works!

This means that the 'GetFullTransform' DOES work just as it should, and if you are having problems getting point positions to match across layers for your multilayer-magnet uses, then the problem is elsewhere.

I hope this is of any help to you, it certainly solved my problem completely.

A fully functional point tracking device is coming up soon!
:)
capricorn ( - just call me "cap")
children's tv pro, character animator
User avatar
A.Evseeva
Posts: 61
Joined: Wed Apr 08, 2015 8:43 am
Contact:

Re: Multi layer Magnet Script?

Post by A.Evseeva »

I suppose the problem with GetFullTransform() was that it considers camera transformation. After multiplication with inverted camera matrix it realy allows to get point positions to match across layers.
Please try my version of multilayer-magnet:
https://yadi.sk/d/zhWmkgtW3JnDz7
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Multi layer Magnet Script?

Post by synthsin75 »

A.Evseeva wrote:I suppose the problem with GetFullTransform() was that it considers camera transformation. After multiplication with inverted camera matrix it realy allows to get point positions to match across layers.
Please try my version of multilayer-magnet:
https://yadi.sk/d/zhWmkgtW3JnDz7
Thanks for the script. I haven't tried it yet, but I did check it out so I could let others know there's nothing malicious in the code (can't always trust new members until we've got a chance to know them). For non-Russian members, to download, just click the underlined text (no need to install anything) and then the download button in the upper right hand corner.
User avatar
DK
Posts: 2849
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Re: Multi layer Magnet Script?

Post by DK »

Be very interested to hear your feedback on this script Wes.

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

Re: Multi layer Magnet Script?

Post by synthsin75 »

DK wrote:Be very interested to hear your feedback on this script Wes.

Cheers
D.K
It doesn't play well with bones, and doesn't work at all with any layer rotation. So...not a finished tool, IMO.

But if you're only using it to move points of multiple layers on frame zero, it'll probably serve that purpose just fine.
User avatar
A.Evseeva
Posts: 61
Joined: Wed Apr 08, 2015 8:43 am
Contact:

Re: Multi layer Magnet Script?

Post by A.Evseeva »

Synthsin75, thank You very much for testing.
My supposition about camera matrix was wrong. And I found a very strange thing:

Code: Select all

vec2:Set(vec1)
some_matrix:Transform(vec2)
some_matrix:Invert()
some_matrix:Transform(vec2)
It seems to me, vec2 must be equal to vec1 after these operations. But it does not.
Any ideas, what is wrong?
User avatar
hayasidist
Posts: 3492
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Multi layer Magnet Script?

Post by hayasidist »

you might find this post in other other place useful ...

http://www.kelleytown.com/forum/animato ... hichpage=2
User avatar
A.Evseeva
Posts: 61
Joined: Wed Apr 08, 2015 8:43 am
Contact:

Re: Multi layer Magnet Script?

Post by A.Evseeva »

Wow! It was very, very useful!!
Now it seems to me the script can work with rotated layers.
New version is here: ae_magnet.lua
(Now it's on my own host, not yandex)
chucky
Posts: 4650
Joined: Sun Jan 28, 2007 4:24 am

Re: Multi layer Magnet Script?

Post by chucky »

Hey guys!
Good to see you around again Cap!
and welcome to A.Evseeva what a great script to start with- unless you are an old dog with a new name of course. :wink:
Great to see this being worked on!
I LOVED the multilayer magnet in the LOST WIGGLE tool, it was a little fussy but was great for making smart actions for a bunch of phonemes.
So... I can't get this one to work yet though... what's the trick?

Any chance of a video tute if there is a special 'flick of the wrist' to make it work?
User avatar
A.Evseeva
Posts: 61
Joined: Wed Apr 08, 2015 8:43 am
Contact:

Re: Multi layer Magnet Script?

Post by A.Evseeva »

Chucky, what is your problem with it? Do You use it as a tool?
It is an improvment of built-in magnet tool, lm_magnet.lua, so you have to put it into tools folder, adding built-in icons and cursor to it (rename all the files the same way).
chucky
Posts: 4650
Joined: Sun Jan 28, 2007 4:24 am

Re: Multi layer Magnet Script?

Post by chucky »

Yes I use it as a tool.
I have three layers ( in a group) all duplicates with the same vectors on them.
I use the multimagnet and select all three layers, then I pass the magnet over... only the top layers vectors move.

Do I completely misunderstand the tool?
Post Reply