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?