I'm only getting errors with setParameter()

I’m more than 1h searching and trying the right parameter value to insert in a code…
first I found one for my opacities:
this.entity.model.meshInstances[0].setParameter(“material_opacity”, 0.5);

ok, and now I tried all of the following for diffuse and I only get errors:
this.entity.model.meshInstances[0].setParameter(“material_diffuse”, new pc.Color(1,1,1));
this.entity.model.meshInstances[0].setParameter(“material_diffuse”, pc.Color(1,1,1));
this.entity.model.meshInstances[0].setParameter(“material_diffuse”, Color(1,1,1));
this.entity.model.meshInstances[0].setParameter(“material_diffuse”, new Color(1,1,1));
this.entity.model.meshInstances[0].setParameter(“material_diffuse”, (1,1,1));
this.entity.model.meshInstances[0].setParameter(“material_diffuse”, 1,1,1);

I search a lot on the docs but half of the things I found (like the “material_opacity”) is inside of some tutorial…
Then, for changing diffuse for example, I found “material.diffuse.set” but this changes the original material and this is not what I need :frowning:

I tried “material_diffuse” cause of this doc page:
https://developer.playcanvas.com/en/api/pc.StandardMaterial.html#opacity
But it seems that there is nothing “really useful” there cause pc.Color diffuse doesn’t work and there is a huge lack of examples for me to be able to compare what I could be doing wrong…

Is there anyone that could help me, pls? Does “material_diffuse” even exists like “material_opacity”? It wouldn’t make sense if it doens’t…

These parameters are not really documented on purpose because they are not considered public API yet. You can use them but they might change without notice. Now having said that the material_diffuse parameter expects an array. So this should work:

this.entity.model.meshInstances[0].setParameter('material_diffuse', [1,1,1]);

The ‘proper’ way to change the diffuse color for now is to do it on the material like so:

material.diffuse = new pc.Color(1,1,1);
material.update();

This will change the color of the material anywhere that material is used. If you only want to change the color on specific models and not others then you better clone that material and assign it to the model first.

2 Likes

It worked nicely :slight_smile:
How could I imagine that could be an array, using brackets instead of parentheses…
If this little example was in that page I wouldn’t be struggled and bothered anyone.

Cloning the material wouldn’t be ideal in my case because I’m building a turned-based game like The Risk… so, there are dozens of models and 4 base colors, changing the color identity of them frequently on each turn should be easy…

Again, thank you @vaios!
That was what I needed! :grin: