[Closed] Make .classes and getClassInstances faster?
Anyone know how to make this faster? Can be quite slow on big scenes.
for i in (material.classes) do (for ii in (getclassinstances i) do print (i as string +": "+ii as string))
Hey Jordan, this isn’t useful at all – but turning off printing generally makes things a lot faster.
ha, yeah you are right, that isnt useful!
Ive just added the printing stuff in for that example… should have been something like this:
myMats = (for i in (material.classes) collect (for ii in (getclassinstances i) collect ii))
it’s fast enough. and it can’t be faster staying with mxs. why do you think it’s slow? do you have numbers?
I get about 6 seconds on a medium sized scene.
Its part of a tool i use a lot and im just getting sick of waiting all that time!
Thought Id try to make it a bit faster.
any chance a recursive function to collect all materials by object will be faster?
I need to get all the materials (and by the way, its not just for materials, its for any superclass) in the entier scene, not jus tthe ones on obects and it seems getclassinstance is the most reliable way.
You can itterate the “scenematerials” array, then you’re sure you’re only get the materials assigned to objects. But you’ll have to take care of multi materials like multisub and blend etc. If thats what you need.
-Johan
Nah, not quite what im after. I want it to be more of a general bit of code so I can do things like this too:
myPosCtrls = (for i in (PositionController.classes) collect (for ii in (getclassinstances i) collect ii))
Maybe this can speed it up a bit, but haven’t checked it.
myPosCtrls = for pClass in PositionController.classes where (pInst = getClassInstances pClass ).count > 0 collect pInst
-Johan
there is no way to do it dramatically faster but there is how to do it most optimal way:
for c in (material.classes as array) collect (getclassinstances c)
no. the material.classes probably is not an array in c++. i think it’s operator []. so it evaluates on every loop iteration. casting to array we do it only once.
to be absolutely correct it has to be:
classes = material.classes
for c in classes do ...