Convert a bone layer to a switch layer

Have you come up with a good Moho trick? Need help solving an animation problem? Come on in.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Convert a bone layer to a switch layer

Post by Genete »

For non well planner users like me there is a typical situation that sometimes can be a big problem.

You happily started to build a model inside a bone layer. Perhaps you do multiple vector layers prepared for shape order (for exapmple limbs avobe or behind the body). But finaly you realize that those shapes should go sometimes avobe and some times behind the others. Mmm some solutions to the problem: duplicate the layer and use visibility option (this should be done at he end of the animation to maintain animation of the duplicate layer same as original...) or use sort layers by true distance and animate them properly (but you have to sort all the layers at the same time for a proper layer ordering... maybe with actions...)

Finally you decided to put all the shapes in a single layer and use a switch layer instead a bone layer (remember switch layers are bone layers too!!!). In this way you can duplicate the vector layer and properly order the shapes and animate them thru time by a switch keyframe. Remember that all the layers are moved by bones like the original because bone binding is maintained. The only difference is the shape order.

How can I convert this bone layer into a switch layer and save all my bone setup?

You have to do this

1) MAKE A BACK UP OF YUOR ORIGINAL FILE :wink:

2) Search for this section in your moho / anme file. You have only serach for the name of the bone layer: "bone-layer" in this case. Change the layer_type value from 4 to 5.

Code: Select all

### layers
layer_type 4
{
	### generic layer values
	name "bone-layer"
	quality_flags 1022
	origin 0 0
	parent_bone -2
	visible true
	render_only false
	edit_only false
	scale_compensation true
	rotate_to_follow false
	face_camera false
	masking 0
	blend_mode 0
	camera_immune false
	dof_immune false
3) Then scroll down and search for this section:

Code: Select all

### bone layer values
	expanded true
	group_mask 0
	depth_sort false
	distance_sort false
and substitute those (erase the old and write the news) lines for this:

Code: Select all

### switch layer values
	expanded true
	switch_data ""
	switch_interpolation false
	switch_keys
	[
		keys 1
			0 0 0.1 0.5 ""
	]
which are the values for a just new switch layer without any switch keyframe in its channel.

The best thing is to start form a switch layer from the begining but if you have this situation this could help.

I readed this tip from heyvern inside another thread but now I cannot find it now.
Hope it were useful.

*****PLEASE MAKE BACKUP FIRST!!!*********

Regards
Genete
Last edited by Genete on Sun Aug 05, 2007 8:59 am, edited 1 time in total.
larpon
Posts: 32
Joined: Sat Jun 10, 2006 9:17 pm

Wicked solution.. but..

Post by larpon »

Genete.. this could really save my day.. but before I do this (on a backup of the file)

Can I copy the actions to the bones too?

I have this in my bone layer values section:

Code: Select all

### bone layer values
	expanded true
	group_mask 0
	depth_sort false
	distance_sort false
	skeleton
	[
		binding_mode 1
		bones 14
			"arm upper left" 4 -1 1 -1 1 1 -1 1 false 0.228636 0.120817 0.001882 -0.009242
			false -1.221731 1.221731
			[
				keys 1
					0 1 0.1 0.5 false
				actions 6
					"Starting point"
					[
						keys 2
...
now.. I really want to save my actions here...

So how do I add them like this:

Code: Select all

### switch layer values 
   expanded true 
   switch_data "" 
   switch_interpolation false 
   switch_keys 
   [
		binding_mode 1
		bones 14
			"arm upper left" 4 -1 1 -1 1 1 -1 1 false 0.228636 0.120817 0.001882 -0.009242
			false -1.221731 1.221731
			[
				keys 1
					0 1 0.1 0.5 false
				actions 6
					"Starting point"
					[
						keys 2
...
Or am I wrong here?
larpon
Posts: 32
Joined: Sat Jun 10, 2006 9:17 pm

Post by larpon »

Alright.. found out this worked for me:

keeping the "skeleton [...]" part instead of the "switch_keys [...]" part works

Code: Select all

	### switch layer values 
	expanded true 
	switch_data "" 
	switch_interpolation false 
	skeleton
	[
		binding_mode 1
		bones 14
			"arm upper left" 4 -1 1 -1 1 1 -1 1 false 0.228636 0.120817 0.001882 -0.009242
			false -1.221731 1.221731
			[
				keys 1
					0 1 0.1 0.5 false
				actions 6
					"Starting point"
					[
						keys 2
...
User avatar
Víctor Paredes
Site Admin
Posts: 5814
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Post by Víctor Paredes »

it's too difficult to make a script which could do this automatically?
sorry if i'm too lazy :roll: , but i think that it would be an useful menu script
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

I was thinking about a script for this as well. The trouble is you have to edit the file that is open. I don't know if this would work.

Might be possible to duplicate the bone layer as a switch... but that is even more complicated.

It could work maybe by writing a duplicate anme file to the disk making the edits at the same time.

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

Post by Genete »

selgin wrote:it's too difficult to make a script which could do this automatically?
sorry if i'm too lazy :roll: , but i think that it would be an useful menu script
With the current opened anme file and during its edition in AS???
I don't dare to do that. For sure I'll crash the anme file AS and even linux system... :lol:

Maybe you can create a switch layer and translate all the stuff from one bone layer to a switch layer but imagine what could happen to the actions of the bone layer if any...
But really it is easier to do by hand only using a simple text editor. For sure you are not changing form a bone layer to a switch layer every other minute...
-G
User avatar
Víctor Paredes
Site Admin
Posts: 5814
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Post by Víctor Paredes »

oh, sorry, i didn't imagine it were so terrible
excuse my ignorance :)
i will make it by hand.
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

I hope that this might be in an upgrade at some point.

It would be fairly simple to have this done within the application. It is such a simple change to the file.

It might be trickier going from a switch to a bone, but going from bone to switch is simple.

-vern
larpon
Posts: 32
Joined: Sat Jun 10, 2006 9:17 pm

Post by larpon »

Hmm... I feel kind of sad I didn't post this when we had the discussion

I know this is a late answer.. But I was crusing the forums and fell over this thread again...

I actually think a convert script could be written to do the job.

Now, I haven't fiddled with scripts yet...
But if you can manipulate a file from the script, save the current project, and load (or reload) a project just by scripting... I don't see why this couldn't be done (pretty sure for a Linux version, not sure about Windows yet)..

Now having worked with AS for some years now and judging from it's project filesizes and my knowledge from being a programmer (primarily on Linux) ... my guess is that AS loads it's files into memory for processing/loading, and when that's done, release the filehandle.. leaving the original file alone on the disk... (from a programmers view anything else would be madness, unless the file is really big and need to be loaded in chunks, or if the program needs to check the file for updates in some interval, which I can't see AS would do for any reason)
A quick test on my machine were to open the file in a text editor while AS had it open, make a change, save it.. and reload it.. no problems.. so if you can do it manually my guess is you can do it automatically as well :)

If my presumptions on this is correct it's "just" the following steps to do it automatically:

1) Save the current project (maybe take a backup if possible so the user can get his stuff back before we attack it :D or alternatively the script can work on this backup file, but hey, what could possibly go wrong, right?)

2) Manipulate the file we just saved, find all entries we need to change to make the layer translation, save the changes from the script

3) (re)load the file from AS

4) Be happy :)

If LUA can't read files into a buffer in memory I guess it's a no go (unless it can execute shell commands).. but I can't see why it shouldn't be able to?

Now as Genete mentioned this (hopefully) isn't something you would be doing very often so maybe just translate the current selected bone layer would be the best to do.. or make a list of all bone layers in the project the user could choose from.. or the mad way... just convert all bone layers..

Now I've only done the write test in Linux and I know that Windows has a nasty habit of locking files in use by programs... but if AS loads the file into memory.. nothing stops us from manipulating the file on the disk from the script (other than missing script features)...

I'm 100% sure it can be done in an external script on Linux (without the save/load feature from within AS that is)..

So why not from LUA? ;)

Any thoughts on this?

edit---
Wow almost 2 years! This post could be so much in vain
Last edited by larpon on Mon Feb 23, 2009 6:13 am, edited 1 time in total.
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

This ALMOST works as you describe. I've been fiddling with editing files from the source using lua.

You can't open files using lua. Period, end of story. You can edit and save another copy of a file but you can't open it using lua. You can open and read any file with lua but you can't open an AS file INTO AS. The user would have to open any changed or newly created or modified file.

Not a huge problem I suppose. I just wish you could make changes via lua and immediately update the currently open file.

-vern
larpon
Posts: 32
Joined: Sat Jun 10, 2006 9:17 pm

Post by larpon »

heyvern wrote:... You can edit and save another copy of a file but you can't open it using lua. ...
darn :/

Hmm.. so only things possible would be either do it without reading the file and manipulate internally... (which is not quite possible as I understand? or?)

or.. the nasty: if LUA can execute commands on the system.. ehehe.. dare I say it...

from lua execute another instance of AS with the saved file as argument (don't even know if you can open files from the commandline with it but it seems likely to me) .. and then quit the instance of AS we're running (probably not possible either)

Now this would be ugly and probably scare everyone away.. but it would complete the save, modify, load -cycle of a file... utter sh** and desperate haha
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Let me explain further. My original response may have been misleading.

AS with a custom tool or menu or button script can open any file for reading, writing etc. No problem. It can open an AS file piece of cake, search and find any attribute. This is handy when there is no script reference for a particular item like key frame interpolation.

It is also WICKED FREAKING FAST. Lua can open and read huge text files VERY FREAKING FAST.

So now you have the AS file open in lua within AS. You can make changes and save to a new file with a new name (or overwrite the current file... but that is scary to me).

What do you do now? In a perfect world you just open that new file in AS right? Wrong. You can't. There is no lua command to "open" an AS file in the currently running instance of AS. You can use the lua os.execute command but... as you said that opens a new instance of AS which can be a real pain (I've found my scripts sometimes don't work at all in a second instance. Or some tools become "deactivated").

I've actually been trying to overcome this PC ONLY limitation for an "open recent item" script. You see it works great on a Mac. Opening an AS file through lua using the os.execute command opens the file in the current instance. This is only a problem on the PC.

I've been looking at some external program creation software for targeting the current instance of AS... but... I just don't have the time I wish I had to pursue this.

----

In conclusion, if this opening of the file is not a huge problem (it really isn't. The file is modified or exists, the user can just open it themselves) then you are good to go. It is a small inconvenience... but an annoying one. I am hoping there will be a simple addition to the script interface in the next version with a lua command to "open" an AS file IN AS.

EDIT: The "drag and drop" loading of AS files does not open a new instance of AS. I was trying to use a sort of "quick keys" or "macro" type thingy to do this, similar to the panel arranger tool someone created. Haven't had any luck yet.

-vern
larpon
Posts: 32
Joined: Sat Jun 10, 2006 9:17 pm

Post by larpon »

Yeah... Another addition to the wish list :)

I guess we'll have to wait and do it manually or semi-automatic then...

Thank you for your time to discuss the issue :)
User avatar
Víctor Paredes
Site Admin
Posts: 5814
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Post by Víctor Paredes »

ok, what if the script creates a new anme file?
this shouldn't crash AS, right?
Post Reply