Can Render Material Color in runtime to dynamically loaded model

Can you post your code please?

Nevermind, I see your code here:

    this.entity.addComponent("model"),
    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,
    u.diffuse.fromString("#000000"),
    u.update()

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
http://network.daruldev.com/Edit-3d-models/12

I still see the error on that page:

http://network.daruldev.com/Edit-materials/1
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 !

https://playcanvas.com/project/715052/overview/material-viewer

@yaustar

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(http://network.daruldev.com/Edit-3d-models/12) and also creating material on runtime that’s also working fine(http://network.daruldev.com/Edit-materials/1) But when we are implementing that material on model here(http://network.daruldev.com/Edit-product_variations/2) Its not working. That’s the main problem.

Not showing any error on material.opacity and so on

http://network.daruldev.com/Edit-product_variations/2
https://playcanvas.com/project/712735/overview/obj-loader-3

that’s what i want !

@yaustar
Are you their ?

TypeError: Cannot set property ‘opacity’ of undefined
Or
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:
https://developer.playcanvas.com/en/api/pc.MeshInstance.html#material

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;
 model.material.update();

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 https://developer.playcanvas.com/en/tutorials/switching-materials-at-runtime/

2 Likes