[Closed] Import/merge slows down drastically when importing multiple models
I’m trying to import a bunch of .max files into a single scene. I’m working in C#, and I have the following code running for each file:
var mergeParams = new MergeParams(true, true, false, DuplicateNodeNameActions.MERGE_DUPS_MERGE, null, DuplicateMaterialNameActions.MERGE_DUP_MTL_RENAME, NodeReparentActions.MERGE_REPARENT_ALWAYS);
IInterface17.MergeFromFile(fileName, mergeParams.MergeAll, mergeParams.SelMerged, mergeParams.Refresh, mergeParams.DupAction, mergeParams.MrgList, mergeParams.DupMtlAction, mergeParams.ReparentAction);
(MergeParams is a struct I wrote to hold the parameters needed.)
For the first few models, it works fine. It takes 2-3 seconds each. By the 4th or 5th model, it’s taking 30 seconds to import each model. By the last model, it’s taking up to 60 seconds. That means the total import time for 30 models is around 25 minutes.
My main questions are:
- Why does it slow down so much when importing multiple models vs one model?
- Is there something I can be doing in this code to speed it up? (I’ve tried playing with selmerged and reparentaction – the rest need to be the way they are.)
- Is there a different way to merge in files through code that’s faster? I’m happy to do this through MaxScript, for instance, if that’s going to be faster. I just need it to be able to merge in different models that might have the same node or material names, and I don’t want the new models to overwrite the old ones.
- Is it slowing down because it needs to accomplish some operation between each model? How can I give it time to do so, or instruct it to do so? (This is on any async method, and I’ve tried doing a Task.Delay() in between models, to no avail.)
I’m pretty much stuck – nothing I do seems to affect the time it takes, and I can’t see inside the engine code to see what it’s doing. Any help is appreciated!
Oh, and if you’re wondering, the merge parameters are described in detail here:
That’s for the duplicate node name actions – the others are linked in the left bar.
What if you change the order in which models are merged? Does it affect the timings?
I’d start from comparing the timings to mergeMaxFile to see if there’s a difference at all
most likely, if there is any problem, it is a logical one… or a system related. In any case, it doesn’t matter and work the same for any programming language that the import method is written in …
I suggest doing the same experiment, but using MaxScript … and then we will see further