0

I have some color codes returned from an API dynamically. I want to use those code as values for setThemingcolor method in my viewer app. How can I do that?

I tried,

let color = new THREE.Color( 0xff0000 );
window.viewer.setThemingColor(workorder.resource.data.autodeskid,color)

But it's not working. The doc states to use vector4 with (r,g,b,i) values. But is there a way I could directly use the hexadecimal color code in it.

Please do help. Thanks in advance.

Edit:

The suggested answer helps and I have tried that already, but what I was expecting is something from the Autodesk viewer API point of view from the community. It helps as a quick hack but I was expecting the reason behind the single format support for color from the team. Anyway, thanks for the suggestion. But I'm keeping this open just to get few more inputs on this.

mariappan .gameo
  • 171
  • 1
  • 1
  • 15

2 Answers2

0

I'm afraid not, the function does expect a Vector4 (RBG+Transparency). Maybe convert HEX to RGB?

Augusto Goncalves
  • 8,493
  • 2
  • 17
  • 44
0

If you look at the three.js sourcecode namely lines 40,77 and 233, we see that if we input a hex string ie: let color = new THREE.Color("#ff0000"); into the constructor we should be fine. Also directly inputting the hex should be fine. I think the problem might be that the setThemingColor expects a Vec4 and not a color object. Since setThemingColor does indeed expect a vec4 we can create one on the fly:

let color = new THREE.Color( 0xff0000 );
let outputColor = new THREE.Vector4(color.r , color.g, color.b, 1);
window.viewer.setThemingColor(workorder.resource.data.autodeskid,outputColor)