0

I am currently looking at trying to get a very simple solution working as a proof of concept before going any further with forge. I have gone through the basic application quick start guide and the basic extension guide and the viewer it self works perfectly with a file I created using Autodesk pipe 3D (tried both as a dwg file and a dwfx).

All I am trying to do is change the colour of the model, all the guides I could find all use similar methods but they all require you to get the list of FragIDs to apply a material

 var it = viewer.model.getData().instanceTree;

 var allDbIds = Object.keys(it.nodeAccess.dbIdToIndex);
 for (var i=0; i<allDbIds.length; i++) {
     var dbid = allDbIds[i];
     var fragIds = []
     try {
       it.enumNodeFragments(dbid, function(fragId){
       fragIds.push(fragId)
     })
    }catch(error) {  
    console.error(error);
    }


 fragIds.forEach(function(fragId) {
    //code to actually change colour
 })

It manages to get the dbid fine and brings back many however when it tries to get the frag ids it doesnt bring back anything. It does not break it just brings back nothing but am having trouble finding where to actually look in to why or where to even start

wolfman1001
  • 171
  • 1
  • 13

1 Answers1

0

First thing would be to define the fragIds array outside of the for loop, so it's not getting overridden at each iteration.

You can use the following code to set a specific material to a fragId:

fragIds.forEach((fragId) => {

  model.getFragmentList().setMaterial(
    fragId, material)
})

Take a look at this thread for more info how the topic:

Forge Viewer THREE.MeshLambertMaterial

Felipe
  • 4,325
  • 1
  • 14
  • 19