简体   繁体   中英

Set color of elements before they render in Autodesk Forge viewer

We load the models using Forge Viewer where all the elements are of the same color. We need to be able to set the color of these elements dynamically before Forge Viewer displays them. It's also acceptable, although not ideal, to change the color of the element right after it gets rendered.

Currently it looks like in order to change the colors reliably we need to wait until the whole model is loaded, since we don't know in the middle of the load which elements got the chance to render and which didn't. This means we can't really display the model until it's fully loaded since we'll be showing users wrong colors.

Is there a way to set colors of elements using forge db ids before they get rendered?

you may have chance to access the objects data before they are loaded visibly in the viewer such as OBJECT_TREE_CREATED_EVENT.

   viewer.addEventListener(
    Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT,
    i=>{
      console.log('OBJECT_TREE_CREATED_EVENT')
      viewer.setThemingColor(5425,new THREE.Vector4(1,0,0,1))

    }

In addition, if your scenario is to a group of objects, or override the existing materials, the best is to create custom material and apply the material to the objects. better performance than setThemingColor in my demo.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM