简体   繁体   中英

Autodesk Forge Viewer - Click Events on models created through SceneBuilder

I am working on adding geometry to the viewer using the new SceneBuilder extension (using this guide). I have been able to show the geometry in the viewer and also been able to add TextGeometry to the same dbId as some of the models.

The viewer is allowing me to click and isolate the geometry, but when I use viewer.getSelection(), it returns an empty array. I even added a click event listener to the Geometry itself, but no luck there as well.

Would any one know of a way to add a listener to this newly created fragment or geometry.

Did you set dbid to the mesh appended to the scene? Otherwise the selector wouldn't be able to pick up their dbids as it would for the document(original model)'s bubble:


    sceneBuilder.addNewModel({conserveMemory: false,
    modelNameOverride: 'My Model Name233'})
        .then(modelBuilder => {
            //...
            mesh = new THREE.Mesh(geom, phongMaterial);
            mesh.dbId=23333;
            modelBuilder.addMesh(mesh);

        })

Then you would be able to call the selector on the custom model to get the current selection - since we are getting selection status from the custom model as opposed to the one loaded by Viewer (exposed via viewer.model ):

modelBuilder.model.selector.getSelection() //[23333]

EDIT

Forgot to mention you may also subscribe to the AGGREGATE_SELECTION_CHANGED_EVEN since we are dealing with multiple models here:

NOP_VIEWER.addEventListener(Autodesk.Viewing.AGGREGATE_SELECTION_CHANGED_EVENT,e=>{
//...
})

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