Reputation: 93
at object selection I'm using below code to change the selected object color ,
viewerApp.getCurrentViewer().impl.setSelectionColor(new THREE.Color(1, 0, 0));
It works fine , but how do I set the selection color to default ?
I tried both
viewerApp.getCurrentViewer().clearSelection();
and
viewerApp.getCurrentViewer().clearThemingColors();
but these methods doesn't seems to work.
Am I doing something wrong ? or what is the best practice to change color and revert it back to default ?
viewer version : 6*
Upvotes: 1
Views: 998
Reputation: 662
If the goal is to change the color of a selected element I would highly advice to use setThemingColor instead. This will set a theming color to the defined dbids, this can easily be cleared at any point. You could hook this up to a select event to have automatic clearing and reassigning of colors. You could handle this after initialising the viewer.
In v7:
viewerApp.getCurrentViewer().viewer.addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT, event=>{
viewerApp.getCurrentViewer().clearThemingColors();
event.dbIdArray.forEach(id =>
{
viewerApp.getCurrentViewer().setThemingColor(id, new THREE.Vector4(1,0,0,1)
})
}
)
However if you did want to have this approach you would have to find out what the default color is and use setSelectionColor
with this color to overwrite it:
Edit Thanks to Cyrille we now know ! so adjusted the color accordingly
viewerApp.getCurrentViewer().impl.setSelectionColor(new THREE.Color(0.4, 0.6, 1));
no clear function is defined.
Upvotes: 0
Reputation: 2659
This selection color is actually hardcoded and not saved in any configuration. You need to reset the color by specifying the original color, like this:
.impl.setSelectionColor(new THREE.Color(0.4, 0.6, 1));
Upvotes: 1