Coloring Models

Hi

In version 1.3 we made "hack" that allowed us to color gltf Models using this technique :

var tempColor = new Cesium.Cartesian4();
Cesium.Cartesian4.fromColor(new Cesium.Color.fromCssColorString(this.Color), tempColor);
var obj = this.Model._gltf.materials;
this.Model['colored'] = true;
for (var mat in obj) {
     if (obj.hasOwnProperty(mat)) { console.log("ambient",this.Model.getMaterial(obj[mat].name).getValue('ambient'));
this.Model.getMaterial(obj[mat].name).setValue('emission', tempColor);
this.Model.getMaterial(obj[mat].name).setValue('diffuse', tempColor);
                
     }
}

Note the usage of "this.Model._gltf.materials" We know not to use _ properties but doing this allowed us to modify the materials on the fly and actually add a colored "shader".

The problem being since caching was added to the models this technique no longer seems to work the same way.

We tried doing "this.Model._cachedGltf._gltf.materials" and doing the rest, but it no longer seemed to work the same way.

Any advice on a proper way to color models?

Hi,

I would expect “model.gltf” to provide access to the original glTF object:

https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Scene/Model.js#L432

Is it undefined? Is model.releaseGltfJson true (it shouldn’t be unless it was explicitly set)?

Patrick