This could be a silly question, but: how do you get the current alpha value from the colour of a model that is used in one entity in the scene?
Let’s say that i have an entity in the scene whose model’s color is white, with a 0.5 alpha value. If i write this:
console.log(viewer.entities.values[0].model.color);
console.log(viewer.entities.values[0].model.color.alpha);
i would get as output “(1, 1, 1, 0.5)” for the first instruction, and “undefined” for the second.
Is viewer.entities.values[0].model.color not a Color type? How do i access the alpha value of this color?
Hi Elia,
The issue is that you’re accessing a property. You’re right that a Color has an alpha property.
console.log(Cesium.Color.WHITE.withAlpha(0.25).alpha); => 0.25
However, Color is itself a Property object (http://cesiumjs.org/Cesium/Build/Documentation/Property.html), which isn’t just a single value, but is an object that defines the value over time. In order to access a Property’s value, you need to call getValue(time)
. Confusingly, we have special behavior for Properties like this such that they’ll print their values when you call console.log, but you need to retrieve the value properly to access its values.
viewer.entities.values[0].model.color.getValue(Cesium.JulianDate.now()).alpha
will get you what you need.
Hope that helps,
That just made things a lot clearer to me. Thanks a bunch, Rachel!