0

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?

JGeerWM
  • 810
  • 10
  • 16

1 Answers1

4

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.

Eason Kang
  • 6,155
  • 1
  • 7
  • 24
  • Thank you for the confirmation about using model.selector.select( dbIds, selectionType). We've been advised against using viewer.impl functionality in the past, since this is considered internal and not for public use. Is there an advantage for using viewer.impl.selector? – JGeerWM May 31 '18 at 13:00
  • Actually ‘Viewer3D.select’ is calling ‘Viewer3D.impl.selector.setSelcetion()’ as I know, though it’s formally recommended **not** to use internal APIs, sometimes it’ just ok for some unexposed functions. The ‘viewer.iml.selector’ has been exposed since v2.x with my memories, so I think it’s reliable personally. – Eason Kang Jun 05 '18 at 02:18