Forge Viewer Select in a multi-model context

倖福魔咒の 提交于 2019-12-20 06:24:18

问题


We have extensions that currently leverage viewer.select() with a list of dbIds from the model.

Our customers would like to see secondary models in the same viewer, and we’re giving them the ability to load reference models after the first model has been loaded.

We’re running into a problem with multiple models, however, where the viewer is selecting from one of the models other than the first model loaded when we call viewer.select().

It seems like we may want to stop using viewer.select() but instead start using model.selector.select() after keeping a reference to the first model loaded. This would mean changing quite a bit of code.

Is there a way to set the context of viewer.select() so that it always uses the first model we load?


回答1:


Before Forge Viewer v3.3, Viewer3D#select( dbIds, selectionType) didn't be exposed for the multi-model use case unfortunately. The 2nd argument of Viewer3D#select has been changed to Viewer3D#select( dbIds, model ). So, the below code snippets will changed to:

var scene = viewer.impl.modelQueue();
var models = scene.getModels();

var targetIndex = ...;
var targetModel = models[targetIndex];
var selectionType = ...;

// Method 1:
viewer.impl.selector.setSelection( dbIds, targetModel, selectionType );

// Method 2:
model.selector.select( dbIds, selectionType );

// Method 3: (After Forge Viewer v4)
viewer.select( dbIds, targetModel );

// Method 4: (After Forge Viewer v4)
var selections = [
    {
       model: targetModel,
       ids: dbIds
    }
];
viewer.impl.selector.setAggregateSelection( selections );

==== Update End ====

Unfortunately, Viewer3D#select didn't be exposed for the multi-model use case. However, there are few ways to select items via the API in multi-model environment:

var scene = viewer.impl.modelQueue();
var models = scene.getModels();

var targetIndex = ...;
var targetModel = models[targetIndex];
var selectionType = ...;

// Method 1:
viewer.impl.selector.setSelection( dbIds, targetModel, selectionType );

// Method 2:
model.selector.select( dbIds, selectionType );

// Method 3: (After Forge Viewer v4)
var selections = [
    {
       model: targetModel,
       ids: dbIds
    }
];
viewer.impl.selector.setAggregateSelection( selections );

Or, you can write your own Viewer class which extends Autodesk.Viewing.Viewer3D or Autodesk.Viewing.Private.GuiViewer3D to private a select function that supports passing model argument.



来源:https://stackoverflow.com/questions/50614588/forge-viewer-select-in-a-multi-model-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!