Can Render Material Color in runtime to dynamically loaded model

Can you post your code please?

Nevermind, I see your code here:

    this.entity.model.model = d,
    this.entity.model.meshInstances[0] = this.Mymaterial.resource,
    product = this.entity;
    var u = this.entity.model.meshInstances[0].material;
    u.opacity = 1,

This line is odd

this.entity.model.meshInstances[0] = this.Mymaterial.resource

Why is app setting a material to a meshInstance?

1 Like

Not working !

What’s not working? I didn’t post a fix to the code, just pointed out where the code I saw in your app that doesn’t look right.

Its working on 3d models page you can check

I still see the error on that page:
Check this out !

Shows the following error:

Are these errors expected at this stage of development?

Yes showing but the color and opacity is changing !


Its the code that i got from forum

Sorry, you need to be clearer about

  • what your problem is (if you are still getting problems)
  • what your error is
  • which project or webpage you are getting it
  • how to reproduce the error

We are creating Product configurator where we are importing models on runtime that’s working fine( and also creating material on runtime that’s also working fine( But when we are implementing that material on model here( Its not working. That’s the main problem.

Not showing any error on material.opacity and so on

that’s what i want !

Are you their ?

TypeError: Cannot set property ‘opacity’ of undefined
Not showing any thing !

You basically have the same problem that I mentioned in an earlier post: Can Render Material Color in runtime to dynamically loaded model

I’ve highlighted the line of code that needs to be fixed where you are incorrectly setting the material to the meshInstance in that post.

Refer to the meshInstance API about the property that I suspect that you should be setting to:

So how can we fixed that ?

 var model = this.entity.model;
//model.type = "box";
model.material.useMetalness = true;
model.material.opacity = 0 ;
 model.material.shininess =100;

I had replace that code with this but still not working !

Please appreciate that that both Leonidas and myself have voluntarily spent hours between us supporting this team and project, down to the line of code that is causing your issue and the correct API that they should be using.

The team, given this information should be able to solve this. If they are not able to, then consider hiring a freelancer to help review the code and consult.

Edit: Here’s a code example of changing materials on meshInstances

1 Like