This script provides a maxscript function for exploding meshes into shadow-casting sub-objects.
The function is very basic. It only checks face normals relative to the average of face centers. The mesh pivot is set to that position, and faces are checked against the pivot to make sure they're pointing away from the pivot. Faces that fail the check are moved to another sub-object and the process repeats until there are no faces to remove. The last chunk of faces may be concave instead of convex, and so the pivot is placed opposite the centroid across the mesh body.
version 1.2: Fixed issue with non-convex single-element portion being shadowed inside out if the shape was any type of box. The final parts in the chunking system will now simply be exploded into faces rather than doing a lot of extra work.
version 1.1: Fixex issue with non-convex multi-element last portion in the chunking system.
version 1.0: The function does not check for self-shadowing, only pivot-oriented shadow errors
To run the script:
If mesh node children of the aurorabase already have trimesh modifiers applied, the script will check for "shadow 0". If shadow is disabled, the mesh will be skipped.
If mesh node chidlren are able to properly cast their own shadows, the "shadow 1" property will be retained, otherwise it will be disabled.
Mesh node children without a trimesh modifier will be given one with the proper shadow 1 or 0 property
Mesh nodes which cannot cast their own shadows will be cloned, chunked into elements, and then the builder will process each chunk.
Chunk pivots will be set to their average face center. Any faces on the chunk which cannot cast a proper shadow will be sub-chunked and the process will repeat.
The last faces may be concave, so the pivot will be moved opposite the average face center across the mesh.
All shadow chunks are named with a unique index per parent, and then all are parented to the aurorabase.
A somewhat detailed list of what the script did will be dumped to the maxscript listener window.
Warnings:
The script does NOT process nested children. Use child nesting for things like transparency only. All other objects should be parented to the aurorabase before processing.
If you're working with an animated series of parts, the parts will need to be parented to the aurorabase first. After processing the parts will need to be restructured to match your original animation tree. In this case you will also want to make sure all the shadow objects are parented to the proper moving nodes.
This script cannot work with transformed parts in animation frame zero. The resulting shadow casting objects will be in the wrong positions and orientations. Unless you cannot erase the zero-frame animation for some reason, you need to reset transform on each part for which you intend to have a shadow created.
Attachment | Size |
---|---|
![]() | 2.56 KB |
![]() | 7.26 KB |
If you want to automatically select your produced shadow objects so you can move them or mass-assign a material, run the script by typing:
select(buildshadows selection[1])
This works like a charm! I use this script, if my shadow boxes on the DLA Solace set are t0o messy (like on the vallenwood trees). I then get nice working shadows. The script creates quiet a few (sub-) mesh parts (depends on the source mesh, of course). At the end of this process I attached them all (and weld the verts) and all is fine.
Just pay attention: The Aurora(-trimesh-)modifier of the original mesh(es) gets lost.
Anyways: THANKS FOR SHARING!