Sort shapes using bones

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

Moderators: Fahim, Distinct Sun, Víctor Paredes, erey, Belgarath, slowtiger

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

Sort shapes using bones

Post by Genete » Wed Aug 15, 2007 10:08 am

Yeaaaaah!
Until next AS update or version you can freely play with this script embedded into the vector layer:

http://www.darthfurby.com/genete/Script ... pesort.zip
http://www.darthfurby.com/genete/Script ... racter.swf

UPDATED VERSION. DOWNLOAD THIS SCRIPT!!
http://www.darthfurby.com/genete/Script ... onesv2.lua
(It have better optimized code that prevent for weird sorting and gain in performance.)
NOTE: for the above example files the keyframes should be tweaked a little. This new version of the script ONLY do the job WHEN there is a keyframe on the timeline of any of the specially named bones (see below) if no keyframe then there is no shape sort. Insert the keyframes just at the moment you need it (like if you were using a switch layer) and the shape sort would be performed in that moment (and only in that moment and not in an interpolated place of the bones). Play with the sample files to see what happen.


CONTENT OF shapesort.zip

character.anme : a sample file
samplesort.anme: another sample file
sort_shapes_by_bones.lua: the embedded script

Installation: just unzip the file in a folder and press play to the samples.

USAGE
1) Create your model as a normal vector - bone layer model (vectors layers inside a bone layer and rigged if needed)
2) For the vector layer that you want the shape sort, count the number of shapes (let's say there are 14 shapes in the vector layer)
3) Create as many bones as shapes you have count. No more no less bones. You can still having other bones for the rig but the name of the just created bones must be special. Set the strength of the new bones to 0 to avoid region or flexible binding. In the example you should create 14 bones. I recommend to create all them with the same orientation at first and separated one from other by its Y position (like in the examples). Later you can rotate some of them to distinguish from the other.
4) Set the names of the created bones to be like this:
0.sh
1.sh
2.sh
and so on

In the example the last bone must be 13.sh (We have started from 0 so there are 14 bones exactly).
4) Link the bones (14 in the example) to another root bone (no matter its name) That root bone would define the X origin of the (14) bones.
5) BE SURE that the just created 14 bones have a different X position BEFORE embed the script. If not, if two bones have exactly the same X value the script would mess up the shapes and its names (the names of the bones are changed EVERY TIME the script is called - it is strange but needed)
6) Embed the lua file to the vector layer and start to play with the just created 14 bones. Their relative X positions defines the shapes stack order. DONT move them using Grid snap just use translate bones tools and do it manually.

LIMITATIONS:
Only for one vector layer for each bone root layer. If there are more vector layers on the bone folder then they cannot have embedded the script. If it is embedded then the shapes would be also sorted in the same way although it could be no sense for the animation.

If you create less bones than shapes then the script could mess up your shapes. It would not crash but strange results could happen. If you create more named bones there is no problem.

KNOWN BUGS AND NO IDEA HOW TO SOLVE IT:
Don't use Raise shape or Lower shape buttons or any of the related menu entries. I have crashed AS pressing too much the Raise Shape button in the middle of the timeline. :shock: :shock: :shock: :shock:

TO DO:
Create a button tool that select the corresponding bone to the previous selected shape. I mean: select a shape then press the button tool and it would select the corresponding bone.
Create a menu script to auto add the needed bones for the selected vector layer. It would run all the shapes and create a bone for each. It can automatically create the proper bone's name and place it in the correct position. It would help a lot.

Hope you enjoy this script.

-G
Last edited by Genete on Sat Aug 25, 2007 11:59 pm, edited 5 times in total.
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post by Genete » Wed Aug 15, 2007 10:17 am

TIPS:
Use fazek's Translate Points/Bones to translate selected bones at the same time. It would help a lot on maintain the local order of the group of bones and place them above or below others (I mean, in terms of shape stack). I used it in the example.

Meanwhile I create the button tool to identify the bone that corresponds to the shape you can name the shapes using the auto name bones and shapes option. Then to find the bone just look to the shape's name and discount one from its number. Then find the bone with the corresponding name. For example if shape's name is "9" then its corresponding bone name should be "8.sh"

-G
tatrik
Posts: 28
Joined: Tue Aug 11, 2009 6:38 pm
Location: turkey

Re: Sort shapes using bones

Post by tatrik » Wed Jan 16, 2013 9:53 pm

Hi Genete. I tried your shape sort script in AS9. I can only use the first version since the final version didn't work in AS9. The problem with the first version is that the first time you sort the shape order it works as you want but when you open the file the second time the order of the shapes shuffled all over again. I guess the script does not consider the first time order of the shapes and their changes overtime. I think it is a fantastic script and you can use it with smart bones functionality of AS9. Could you please update this useful script?
Post Reply