Hi All,
I’m attempting to replicate this effect (colour change on mouse hover) for glTF files and by using the “EntityModelColor.js”.
In my case it seems to work but I have come across the situation where an object(s) stays selected (as depicted in the image below) even after the mouse cursor position is away from it, which is not desirable. Might you know what this is caused by?
Below is the section of the JavaScript code used for the selection which is a slightly modified version the original “EntityModelColor.js”.
//Change color on mouse over. This relies on the fact that given a primitive,
//you can retrieve an associted en
var lastColor;
var lastPick;
var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function(movement) {
var primitive;
var pickedObject = viewer.scene.pick(movement.endPosition);
if (pickedObject) {
primitive = pickedObject.primitive;
if (pickedObject !== lastPick && primitive instanceof Cesium.Model) {
//We don’t use the entity here, but if you need to color based on
//some entity property, you can get to that data it here.
var entity = primitive.id;
var material = primitive.getMaterial(‘Material_0’);
//var material = primitive.getMaterial(‘Red’); - original line
lastColor = material.getValue(‘diffuse’).clone();
//material.setValue(‘diffuse’, Cesium.Cartesian4.fromColor(Cesium.Color.BLUE));
material.setValue(‘diffuse’, Cesium.Cartesian4.fromColor(Cesium.Color.YELLOW));
lastPick = pickedObject;
}
} else if (lastPick) {
primitive = lastPick.primitive;
var material = primitive.getMaterial(‘Material_0’);
//var material = primitive.getMaterial(‘Red’); - original line
material.setValue(‘diffuse’, lastColor);
lastPick = undefined;
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
``
Thanks
Kabiro