Coloring Models Over Light Colored Map

We have used the following code for the past couple of years to color our models…

var tempColor = new Cesium.Cartesian4();
Cesium.Cartesian4.fromColor(hex2rgbaCesiumColor(this.FlightColor), tempColor);

var gltfMaterials = this.Model._cachedGltf._gltf.materials;
for (var obj in gltfMaterials) {
if (gltfMaterials.hasOwnProperty(obj)) {

   var material = this.Model.getMaterial(gltfMaterials[obj].name);
           
   if (material === undefined) {
      console.log("Unable to get material!");
      continue;
   }
               
   if (material.getValue('diffuse') !== undefined) {
      material.setValue('diffuse', tempColor);
   }
               
   if (material.getValue('emission') !== undefined) {
      material.setValue('emission', tempColor);
   }
       
}

}

``

Although this throws a bunch of “WebGL: INVALID_ENUM: bindTexture: invalid target” errors on the call “material.setValue(‘diffuse’, tempColor);” it does color the models over a satellite map. See below…

But when we change the map to one that is light colored the models are washed out to the point that it is hard to tell that they are colored at all. See below…

I know that the ‘diffuse’ property is supposed to be set using a mode material texture. But I can’t find an example anywhere of how to create a texture for this purpose. And on top of that how to set it to a specific color.

Does anyone know how I can color these models so that GL errors are not thrown and so that the models appear colored regardless of the background they are over?

I’m not sure what the best solution is here and I’m surprised it works at all.

I think it would be really cool to extend Model to support dynamic coloring though. I may be able to get something running quickly.

That would be great! I’m currently experimenting with this issue in Sandcastle. If you come up with something I’d love to see it!

I opened a PR for doing this: https://github.com/AnalyticalGraphicsInc/cesium/pull/4547

Hi Sean,

Sorry for my ignorance on the topic, but I’m not sure how this process works. I clicked the link in your post, and I see a conversation between you and Patrick. Where does this issue stand? It sounds like a change is being made… when do you think the code will be available?

Thanks for your help with this!

If all goes well the PR will be merged into master pretty soon and the code will be part of the 1.28 release next month. Since we are straddling the edge of the 1.27 release (tomorrow) it will not make it there.

Thanks, Sean!

Hi Rob,

Sean’s pull request was just merged so model coloring will be in Cesium 1.29 on January 2.

Patrick

That’s awesome! I can put that to immediate use!

Thank you, Patrick and Sean!