Mike, you are mistaken. I put a gist together to show how to do this: https://gist.github.com/mramato/2b6becee077c664bf25d You can just copy and paste the code into Sandcastle. Here are the relevant bits and explanations.
The below function will retrieve the given Model primitive for any valid entity instance. Since the Entity API does not have any support for node/mesh/material manipulation you can safely change the values under the hood without the Entity API interfering.
function getModelForEntity(entity) {
var primitives = viewer.scene.primitives;
for (var i = 0; i < primitives.length; i++) {
var primitive = primitives.get(i);
if (primitive instanceof Cesium.Model && primitive.id === entity) {
return primitive;
}
}
};
We can use this function to look up the primitive and color it. In my example, I used a primitive that has a material named ‘Red’ (the fact that the name is a color is coincidental)
var model = getModelForEntity(entity);
if (model) {
var material = model.getMaterial(‘Red’);
material.setValue(‘diffuse’, Cesium.Cartesian4.fromColor(Cesium.Color.fromRandom()));
}
When this code runs, the box model changes to the new random color.
I also through in a simple mouse-over example to show how that would work. You don’t actually need the Entity in this case, but it’s available to you if you want to color based on other entity information. The one caveat to this approach is that if you change models on the fly, you have to re-apply the color yourself, Cesium or the Entity API won’t track any of the changes you make automatically. If an Entity always has the same model though, you’re golden.
Eventually we’ll expose this all via Entity API and CZML, but for now this approach should work well, you just need to know the name of the model material you want to color.
Let me know if you’re still having problems.
Thanks,
Matt