Is there a preferred way to cull the hierarchy of everything but meshes and produce a single merged mesh?
I have been converting a number of large files containing scenes comprised of thousands of separate pieces -- I've tried a couple approaches to create a single mesh from many (thousands) of separate meshes. My goal is to jettison the hierarchy/mode tree data and transformation history, creating a single mesh that performs as well as possible.
I settled on an approach that attaches even and odd meshes iteratively until only a single mesh remains, a method advocated separately by several people in different forums. The below code works, but the problem here is that some of my source files have nodes that can't be attached (they're not meshes) but aren't deleted by this 'delete everything but meshes' loop:
for i in objects where classOf i != geometryClass do delete i
My question: am I going about this wrong? Is there a preferred way to cull the hierarchy of everything but meshes and produce a single merged mesh?
Here's a summary of the two approaches I've tried:
- Collapse Stack is the obvious built-in function for discarding the complex hierarchy tree that slows 3DS down. It's a production-oriented feature to decrease the CPU load, especially when sending heavy files to rendering, when working in an asset sharing environment or exporting models to other formats or olders versions of 3DS. The problem here for me was time and memory -- the process was really slow, and ate up all 64GB of RAM on the systems I was using, so Windows was swapping quite a bit and slowing things down even further.
- Attach mesh is an alternative to collapse stack, and it can be much faster and require less memory. My simplest form of the attach script is below: it imports, ungroups, deletes non-geometry and runs the attach process by matching even and odd pairs until there's only one mesh left, then exports it.
undo off files = getFiles "C:\\test\*.fbx" theClasses = exporterPlugin.classes for f in files do ( resetMaxFile #noprompt ImportFile (f) #noPrompt select objects if selection.count > 0 do ( currentname = f + "-md.fbx" print currentname -- Ungroup all groups = for o in helpers where isGroupHead o collect o while groups.count > 0 do ( ungroup groups[groups.count] ; groups.count = groups.count-1 ) -- Cull everything but geometry for i in objects where classOf i != geometryClass do delete i while selection.count > 1 do ( selcount = selection.count for i = selcount to 2 by -2 do ( meshop.attach selection[i] selection[i-1] ) ) update selection exportFile (currentname) #noPrompt using:theClasses ) )