Bone Point binding from switch layers

Wondering how to accomplish a certain animation task? Ask here.

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Ok...I swapped the order of the layers but get this lua error...."Meshinstance: wrong order - swap the source and the copy" which is why I had them around the wrong way. The error runs everytime the timeline plays......what could be the problem?

D.K
User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Ahhh....sorry....read back...now I have it...thanks for the help. This script is brilliant synthsin75 and Vern!!!!! Many many thanks to you both and Fazek!!!

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

Post by synthsin75 »

I so happy to be able to renew interest in this awesome script. Fazek was the man.
User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Well done...I must admit not being used to scripts I had difficulty understanding what it actually did and how to implement it. Now I understand I am going to use this script ALL THE TIME! This is an area where some basic tutorials would be extremely appreciated. :wink:

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

Post by synthsin75 »

Yeah, my planned advanced masking tutorials were going to be all about meshinstance, but for now I'm waiting to see if the response to the intermediate one warrants any more. :roll:
User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Just found a huge bug with Meshinstance. It does'nt output to SWF. Also any layer binding to bones goes haywire when output to SWF as well. Looks fine in the preview though.

EDIT: Is it possible to fix this with scrpting?

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

Post by synthsin75 »

If I had to guess, I'd say that that just falls into the catagory of a layer not being optimized for SWF (little red dot on layer). But I don't usually use Flash, so I couldn't really say for sure.
User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

That's odd....

EDIT: This needs some more testing?

D.K
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

The only fix I could think of would be to modify the script temporally for SWF output so all point motion is converted to keys. Then remove the scripts, bind the layers and it's ready for flash out put.

------

Scripts are generally not flash friendly due to how the movements are created. AS exports the motion it "knows about". A script is doing stuff that the AS flash export has no clue about.

When you export to a movie, it renders the screen and saves that as the "frame image". When exporting to flash, there is no preview, no rendering, it could be that most scripts are "ignored" completely during flash export. It is converting key framed or bone controlled motion to the SWF format. The scripts need to have a preview to work.

So if a script can be modified to "hard code" the motion into built in AS standardized motion, the SWF export will work.

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

Post by synthsin75 »

I was just helping DK out, and it seems that as long as the layer is optimized for SWF, the script still works. But optimized seems to mean that you can't do selective point binding, so it doesn't really do the meshinstance from bone motion to a switch layer. Point motion is fine though.

I'll keep testing this. :wink:
User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Hi sythsin75.
I just sent Vern the file too to see if he could figure it. Meantime, I came up wth a temp solution, I put a bone in the switch layer, binded the points that needed to be Meshinstanced and just hand animated the bone.

D.K
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post by Genete »

Hi guys
I've following this thread since the beggining. Honestly I have not have time to test that great script from fazek but I bet that it is awesome.

Regarding to the swf output I believe that the solution that heyvern's suggested is a good one. I would like to see if the script can be modified in that way. Nothing to promise because the script seems to be a little complex.

DK, forget my comments on my PM. As stated by the script instructions you should be able to produce layer transformations on the duplicated layers:
This is a layer script for creating duplicate instances
of a vector layer's mesh points in other layers.

There is one "source" vector layer and any number of
"copy" vector layers. The script must be applied both to
the source and to all of the copy layers. The source and
the copy layer could be anywhere in the layers tree, but
the source layer's script must be executed first (must be
lower on the list). If the order is wrong, you get an
error message to swap the source and copy layers.

The copy layers must have a name composed from the name
of the source layer and a ".dup" extension, For example if
the source layer has the name "NAME" then the copy layers
must have the name "NAME.dup".

The script copies the actual position of the points in the
mesh. The original positions of the copy layers are unused
(even their bone transformations), so you can modify the
copy layers' points only through the source layer.

You can transform (replace, rotate etc.) the copy layers
through layer transformations.

License: Free

I am waiting your ideas and suggestions at:

viewtopic.php?t=3507

Fazek
EDIT: Mmm it is a complex script and it is awesome. I'll give a try when be at home.

Cheers!
-G
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post by Genete »

Try this (I've not tested in AS). I've modified the script to perform a point motion keyframe on each frame for the duplicated layers. As well as the duplicated layers should never be modified you wouldn't take care of those bunch of keyframes. I hope it would allow to export to swf properly.

Please test it in a dummy file, not ready for production files. At this moment I cannot test it in AS (not in this computer).

-G

Code: Select all

--[[
	MeshInstance: Instancing the positions of mesh points on vector layers
	1. Use NAME for the name of the source layer, and NAME.dup for all of the other layers.
	2. Set this script for all of the layers (ie. for the original and for the instances)
	3. Modify always the source layer only.
]]--

-- written by Fazek

function LayerScript(moho)
	local mesh= moho:Mesh()
	if (mesh == nil) then return end

	local ownLayer= moho.layer
	local name= ownLayer:Name()
	local tab
	local mi= ownLayer.FA_MeshInst
	local len= mesh:CountPoints()

	if (string.sub(name,-4) == ".dup") then
--copy instance
		if (mi and ownLayer.FA_MeshInstName == name) then
	--cached
			if (mi[2] ~= moho.frame) then
				print("MeshInstance: wrong order - swap the source and the copy!")
				return
			end
			tab= mi[1]

			if (mi[3] < len) then len= mi[3] end

			for p= 1, len do
				local pt= mesh:Point(p - 1)
				pt.fPos.x= tab[p][1]
				pt.fPos.y= tab[p][2]
			end
		else
			local srcName= string.sub(name,1,-5)

		-- recursive search for the source

			local stack= {}
			local sp= 0
			local document= moho.document

			for i= 0, document:CountLayers() - 1 do
				local layer= document:Layer(i)
				local parent= nil
				local sub= 0

				while true do

					if (layer:IsGroupType()) then
						table.insert(stack, { parent, sub - 1 })
						sp= sp + 1
						parent= moho:LayerAsGroup(layer)
						sub= parent:CountLayers()
					elseif (layer:Name() == srcName) then
						local mi= layer.FA_MeshInst

						if (mi) then

							if (mi[2] == moho.frame) then
								tab= mi[1]

								if (mi[3] < len) then len= mi[3] end
								-------------------------------MODIFICATIONS BY GENETE
								local vec = LM.Vector2:newlocal() ---<<< This create a needed 2D vector
								for p= 1, len do
									local pt= mesh:Point(p - 1)
									local animpos=pt.fAnimPos  ---<<< This wrap the AnimPosition channel of the point to move.
									vec.Set(tab[p][1],tab[p]2])) ---<<< This fills the 2D vector with the proper values
									animpos.SetValue(moho.frame, vec) ---<<< Now add a keyframe at the current frame to move the point
									--******** Those lines are commented to avoid point motion
									--pt.fPos.x= tab[p][1]
									--pt.fPos.y= tab[p][2]
									--********
								end
								-------------------------------END OF MODIFICATIONS BY GENETE
								ownLayer.FA_MeshInst= mi
								ownLayer.FA_MeshInstName= name
								return
							end
						end
						print("MeshInstance: wrong order - swap the source and the copy!")
						return
					end

					if (sub > 0) then
						sub= sub - 1
						layer= parent:Layer(sub)
					else
						sub= -1

						while (sp > 0) do
							parent, sub= stack[sp][1], stack[sp][2]
							table.remove(stack)
							sp= sp - 1

							if (sub >= 0) then
								layer= parent:Layer(sub)
								break
							end
						end

						if (sub < 0) then
							break
						end
					end
				end
			end
		end
	else
--source
		tab= {}

		for p= 0, len - 1 do
			local pt= mesh:Point(p)
			table.insert(tab, { pt.fPos.x, pt.fPos.y })
		end
	--trick: FA_MeshInst won't change in the address space (no orphans)

		if (mi and not ownLayer.FA_MeshInstName == name) then
	--cached
			mi[1]= tab
			mi[2]= moho.frame
			mi[3]= len
		else
			ownLayer.FA_MeshInst= { tab, moho.frame, len }
			ownLayer.FA_MeshInstName= name

			mi= ownLayer.FA_MeshInst
			name= name..".dup"

	--avoid orphaning: update all dependencies

		-- recursive search for the copy

			local stack= {}
			local sp= 0
			local document= moho.document

			for i= 0, document:CountLayers() - 1 do
				local layer= document:Layer(i)
				local parent= nil
				local sub= 0

				while true do

					if (layer:IsGroupType()) then
						table.insert(stack, { parent, sub - 1 })
						sp= sp + 1
						parent= moho:LayerAsGroup(layer)
						sub= parent:CountLayers()
					elseif (layer:LayerType() == MOHO.LT_VECTOR and layer:Name() == name) then
						layer.FA_MeshInst= mi
						layer.FA_MeshInstName= name
					end

					if (sub > 0) then
						sub= sub - 1
						layer= parent:Layer(sub)
					else
						sub= -1

						while (sp > 0) do
							parent, sub= stack[sp][1], stack[sp][2]
							table.remove(stack)
							sp= sp - 1

							if (sub >= 0) then
								layer= parent:Layer(sub)
								break
							end
						end

						if (sub < 0) then
							break
						end
					end
				end
			end
		end
	end
end
User avatar
DK
Posts: 2895
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Hi Genete.
I tried copy paste the code into a text file, saved as meshinstance2.lua but for some reason AS does not recognise it. It's probably something I am doing.

EDIT:
I get this error.

Image


D.K
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

There seems to be an extra ")" on line 72:

Code: Select all

                           vec.Set(tab[p][1],tab[p]2])) ---<<< This fills the 2D vector with the proper values
Next to the [2] in brackets is an extra parenths.

------

On another note regarding the problem that DK was having.

It was a confusing "illusion". It only looked like the layer binding wasn't happening. What was really happening is that since the mesh instance script can't export to SWF the head in his file wasn't moving at all... but the eye bound to the bone WERE moving.

While watching the animation both DK and I were fooled by it. It looked as if the head motion was there when it really wasn't... making it look like the bound layer (the eyes) was acting crazy.

The bound layer WAS working properly... but the mesh instancing wasn't... creating a bizarre confusing illusion.

It took me a few minutes to figure it out... I laughed out loud when I realized what was happening.

-vern
Post Reply