Search code examples
cssautodesk-forgeautodeskforgeautodesk-viewer

How to add custom background in Autodesk forge?


Is this possible? I want to load an image for the background.

Currently I got this:

viewer.setLightPreset(4);
viewer.setQualityLevel(false, false);
viewer.setGhosting(true);
viewer.setGroundShadow(true);
viewer.setGroundReflection(true);
viewer.setEnvMapBackground(false);
viewer.setProgressiveRendering(true);

But neither of these makes it possible to add a image for the background. If this is not within the API, would it be possible to change the background color? (not the load background color, but the viewer background color)


Solution

  • There is no API available for changing the viewer background image. But a workaround could be applied in this case, please refer the answer here.

    However, you can change the background color via the viewer.setBackgroundColor. Here is an example for change background into red color:

    viewer.setBackgroundColor( 255, 0, 0, 255, 255, 255 )
    

    The first 3 arguments are for the top clear color of the WebGLRenderer. The others stand for the bottom clear color of the WebGLRenderer. But there is no documentation that describes what top and bottom clear color is.

    ===== Update =====

    After some research, I found that:

    • If you want to change the background color into pure colors, you can set both top and bottom clear color up with the same value. e.g.

      // Change whole background color into red.
      viewer.setBackgroundColor( 255, 0, 0, 255, 0, 0 )
      
    • If you want to change the background color in the color gradient style, you can set the top clear color and the bottom clear color with different value. e.g.

      // Change background color in a color gradient style, top color is red, bottom color is white.
      viewer.setBackgroundColor( 255, 0, 0, 255, 255, 255 )