Home > database >  Three.JS Object Material CleanUp
Three.JS Object Material CleanUp

Time:12-11

Newbie trying to understand what's a standard practice for you experts. I'm loading a GLTF model with multiple objects that change per the user's input. (Change being different material like color or shininess/metalness setting, etc.) I have a color picker that the user chooses from that currently creates a new material each time the user makes a selection of a different swatch from the color picker.

In terms of standard practice - should I just be creating the meshbasicmaterial once, and then changing it (i.e. setting a new color, changing the value of shininess etc.?) Should I be creating the meshbasicmaterial every time I want to change the color, etc.? If I'm creating a new meshbasicmaterial every time, should I be disposing of the previous one prior to creating the new? Or, maybe you do something completely different?

Any advice is greatly appreciated.

Thank you.

CodePudding user response:

should I just be creating the meshbasicmaterial once, and then changing it (i.e. setting a new color, changing the value of shininess etc.?)

Yes. There is no need to create materials over and over again just because a property value changes.

If you don't need a material instance anymore (for whatever reasons), always call dispose() on the object to potentially free internal resources like the respective shader program.

  • Related