Notifications
Clear all

[Closed] Scene efficiency: Applying materials

 em3

what is the difference between:

Selecting all like objects and applying a material


   mat1 = currentmateriallibrary[1]
   thecol = for o in objects where matchpattern o.name pattern:"something" collect o
   select thecol
   $.material = mat1
   

and loop through each, assign a material…

mat1 = currentmateriallibrary[1]
  thecol = for o in objects where matchpattern o.name pattern:"something" collect o
  for i in thecol do i.material = mat1

Example: I have 26,000 pieces of Ibeam steel in my scene. Am I creating 26,000 instances of that material in my scene by doing it the second way?

Thanks,

Dave

3 Replies

Same thing happens for both ways, material is instanced, so you’re not creating 26000 materials

Although you could do it like this, maybe it’s faster:

for o in objects where matchpattern o.name pattern:"something" do o.material = currentmateriallibrary[1]
 em3

great, thanks artur!

the applying a material to collection of objects is a little faster than to applying it to every object from the list. in first case the system sends a little less notification messages.
the situation might change if some script uses material change events (#nodePreMaterial, #nodePostMaterial, NodeEventCallback materialStructured (materialOtherEvent), etc.). it makes the second method (applying per node) more memory used up.