Notifications
Clear all

[Closed] Fast object attach?

Does anyone know The Way to do a fast “combine” of multiple meshes in script? I want to take many nodes and make them one node. I’ve used attach <node> <node> in a loop and it’s very slow… almost as slow as doing it in the UI However, if you use the collapse utility and collapse multiple nodes into a single object, it is several orders of magnitude faster. This makes me think that the capability does exist within Max, it’s just a matter of figuring out how to tap it.

I’d even be down with a plugin function that had a fast attach… anyone have any ideas?

4 Replies

Oh, BTW, I don’t care about materials. I know that sorting through materials and doing the right thing can eat up a bunch of time. I just want a single material on the resultant node. My guess is this is why the collapse utility is so fast… because it ignores material stuff.

Read the “How To Make It Faster” chapter in the MAXScript Reference’s FAQs.
I am pretty sure there is an example concerning attaching – the magic trick is to disable the UNDO context, as attaching two objects always creates an undo record in memory, doing this 1000 times creates a HUGE amount of undo data that you probably don’t want. Without disabling undo, Max might even crash…
IIRC, the attach of 1000 objects was approx. 20 times faster with UNDO off than without…

Thanks for the reply Bobo.

Actually, I was already employing the methods in that tip. However, I was screwing up in a new and improved fashion. After trying a few different approaches to fixing it, I did get it down to attaching 500 nodes in .5 sec on a p4 3.0ghz. Not too shabby.

So, what I was doing wrong was I was copying the node in the attach clause.

SLOW:
e = editable_mesh()
for o in objects do attach e (snapshot o)

FAST:
e = editable_mesh()
for o in objects do 
(
n = snapshot o
  attach e n
)  

I should go back and re-test this, but I was surprised to see the order of magnitude speedup that I am seeing. Can you correlate the difference?

Both of these sound dangerouns if you are doing EXACTLY that.
(I assume you are not, as you cannot assign anything to the reserved global E).

Basically, you cannot create a mesh, then loop through all OBJECTS as the mesh would be there as the last node in the scene data base, and you would attach a snapshot of that mesh to itself in the last step of the loop. Once again, I assume your example was just pseudo-code.

Without running the code, I would expect the first one to be slightly faster, so I am also surprised. (I cannot run the code as I am very busy now, waiting for Max to finish some crazy calculations)