31
ASL Scripts / LIA - Links In Anim8or
« on: January 30, 2014, 11:15:22 pm »Links In Anim8or
Pseudo Hierarchy System
Pseudo Hierarchy System
A while back I started this hierarchy thing, but never finished it. I restarted it and it's now in a releasable state. As mentioned in the previous topic, I don't expect this scriptset to be very useful to many. I wrote it only for the XSI export script. I expect this toolset to become redundant, assuming Steve implements native hierarchy support into Anim8or in the future.
What is LIA?
Anim8or doesn't have a hierarchy system in the object editor. This means that you can't set one object as the child or parent of another object. Yes, you can fake this using groups, but if you do it this way then any changes you make to an item deep in the hierarchy would require you to ungroup everything, change it, and then regroup it again, which is a lot of work ripe with the opportunity for error.
LIA is a simple naming system that appends ".ChildOf." to the name of a shape, which then tells whatever script that uses LIA that that shape is a child of whatever is named afterwards. If cube01 were a child of sphere01, cube01's name would be "cube01.ChildOf.sphere01".
With just this, a hierarchy system is born.
What is LIA good for?
Scripts that require hierarchy as a fundamental part of their features. For example, export scripts for formats used in game engines that require a certain parent/child relationship between various nodes. If you need to implement hierarchy in your script, pack the LIA scriptset with it and implement the preprocessor in your own script.
How do I use the LIA tools?
LIA currently comes with 5 tools, available in the Scripts menu in the Object Editor when installed correctly:
- List Hierarchy - Prints out the current Hierarchy in the console
- Set Parent - Marks the selected shape as the parent
- Set Child - If a parent has been set, any selected shapes are then assigned as children of that parent
- Unlink All - Clears all hierarchy information from all shapes in the current object, restoring their old names
- Unlink Selected - Same as Unlink All, except only for those shapes that are selected
Warning: This is a system that relies on naming. If you get funny results, double check what you're doing. The console may print out some errors to help with troubleshooting, but the best way to use these tools successfully is to know exactly what you want, what these scripts do, and what the results should be.
How do I use LIA in my own scripts?
Doing so isn't quite as straightforward as I'd like. It's a naming convention, and all you have to do is follow the logic of how it works, as described earlier.
I mentioned the preprocessor. This is just what I call a block of code in the "LIA - List Hierarchy.a8s" file. In this block of code, it sorts it all for you into two arrays. If you loop through these from 0 to its size - 1, you get:
- $LIA_sorted_index[index]: Returns the index number of the shape in presorted order. Use this number in the shape array that's returned when you use the [object].GetShapes() function.
- $LIA_sorted_level[index]: Returns the level, to help you determine if the shape in $LIA_sorted_index is a child, sibling, or parent of the previous or next shape in the array.
Another useful array is $LIA_realNames. Using the same index number as the GetShapes() array, it'll return its real name without all the .ChildOf. mess.
Also included $LIA_locOffsets and $LIA_rotOffsets arrays, should someone need transform data relative to its parent rather than relative to the world.
Take a look at the List Hierarchy script for an example of its use. You'll find that the actual listing function is incredibly simple, and that all of the work is done in the preprocessor which you don't have to touch. Just copy the preprocessor block of code and the LIA-specific variable declarations, and you can use it in any custom script.