Code: Select all
function LayerScript(moho)
local mesh = moho:Mesh()
if (mesh == nil) then
return
end
if (mesh:CountShapes() <= 0) then
return
end
mesh:RaiseShape(0, true)
end
My idea is to reify the shapes of one layer in a group layer. That is, if you have a layer "Person" whose stacking order you want to animate, you would select your Person layer then click the "Animate Shapes" tool. That tool would create a new Group Layer, set to invisible, called "Person Shapes". The Person Shapes layer would be automatically populated with one sublayer per shape in the original Person layer. Each sublayer would contain a duplicate of the shape at frame zero. These duplicate shapes would not be rendered (the Group Layer would be set to invisible). However, since the shapes are exact duplicates of the Person layer shapes, an embedded script could match group-sublayers to shapes in the original layer.
One could then animate the shape stack ordering for the Person layer by modifying the Z coordinates of the shape sublayers. The embedded script would, for every frame, create an array of shapes ordered by the Z coordinates, and then iterate over the array, invoking raiseToFront.
To make the example more concrete: Let's say you have a Person layer, that has five shapes: Left Leg, Right Leg, Body, Left Arm, Right Arm. Then after using the Animate Shapes tool on the Person layer, your layers would look like:
Code: Select all
+ Person
+ Person Shapes
---+ Left Leg
---+ Right Leg
---+ Body
---+ Left Arm
---+ Right Arm
This technique would provide a number of advantages:
1. It's persistent across loading and saving of the document. The only caveat is, if you change a shape, you'd have to somehow re-save that shape into the group layer.
2. Each shape gets its own animation channel for stack ordering; altering the ordering happens with ordinary keyframes. So working with this should be intuitive.
3. By making Person invisible and Person Shapes visible, you can see the stack ordering as you're animating it.
Can any of the script gurus out there think of a reason why this won't work? It's going to take some effort...