1

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*

2 Answers 2

1

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));
Sign up to request clarification or add additional context in comments.

Comments

0

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.

4 Comments

setThemingColor does not work for objects that already have a color in my case . Did you experiance such scenario ?
For me it has always worked as expected. You could also try to add a custom material with color to any object in the model
oh okey i will try again , I did that but didnt work may be i did it wrong.. thank you
Hello , will you be able to provide me a proper example of this ? i mean how to add a custom material with color . Thanks in advance

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.