Unable to use Mesh.material.emissiveColor in TS

In advance, I just started to learn TS and Babylon JS, also my English is not good that mean I can only read by translation, so this may be my mistake (Because this problem seems easy to be discovered by other people).

When I use “Mesh.material.emissiveColor” in TS, I got a message that material had no emissiveColor.

So I tried to use this API with native JS, and I found that using this API was completely feasible.

Next, I tried to edit “babylon.module.d.ts” to add emissiveColor property to Meterila. And, compile TS. There were no any problems.

It seems that “babylon.module.d.ts” does not completely contain APIs?

Hello and welcome!

emissiveColor does not exist on all materials. So it really depends on the kind of material you are using
Can you share your code maybe?

In JS, it is ok to dynamically create a new property so it could be ok from the compiler standpoint but it will not work for babylon.js

Thanks.I already know how to solve this problem.And, this error was caused by TS.
In TS, when something has written a type, TS will use this type and not care about the real situation.So,even if I write code like this:

......
mesh: Mesh;
scene: Scene;
mesh.material = new StandardMaterial('m',scene);
//mesh.material.emissiveColor is err

The “mesh.material” is still “Material” type.:dizzy_face:
So I changed it like this:

var lol = mesh.material as StandardMaterial;
lol.emissiveColor = new Color3(1, 1, 1);

It’s worked.
I don’t know if static languages are all like this, but TS really makes me feel bad for hours. I don’t like static languages anymore.:frowning_face:

hahaha, you will like it more when it will help you fix bugs :slight_smile:

At least it is what happened to me :smiley:

(box.material as StandardMaterial).emissiveColor = Babylon.Color3.White();
1 Like