Home  >  Q&A  >  body text

javascript - How to change the color of widgets through API?

How to change the color of a component in Forge Viewer?

巴扎黑巴扎黑2663 days ago1159

reply all(1)I'll reply

  • 習慣沉默

    習慣沉默2017-07-05 11:01:19

    Yes, you can set it through the viewer.setThemingColor() function. The parameter it accepts is a THREE.Vector4. Forge Viewer uses (x, y, z) of THREE.Vector4 to represent the three primary colors (r, g, b), w represents the opacity alpha, note that each parameter is between 0 Between 1 and 1, the color codes of the three primary colors must be divided by 255. The calling example is as follows:

    // 变成红色
    var color = new THREE.Vector4( 255/255, 0, 0, 1 );
    
    viewer.setThemingColor( 2498, color);

    Screenshot of the result, the original green space turned red:

    If you want to restore the color of the component, you can call viewer.clearThemingColors() This function will clear the color settings. The results are as follows:

    reply
    0
  • Cancelreply