Posted By

Philippe Leefsma
I write JavaScript for the future 3D World Wide Web, A.K.A Forge Platform
15 May 2017
Being able to aggregate, as we call it, multiple models in a single scene within the Forge viewer is really a recurring topic across all the Cloud Accelerators that my team and myself have been delivering all around the globe.
If your application doesn't handle multi-model scenarii yet, I bet there is a good chance that sooner or later it will require it... So in order to avoid painful refactoring at an advanced stage of your development, it is a good idea to start planning from the scratch.
I already wrote an article on that topic in the past: Model Aggregation Exposed, but today I'm proposing a base template class from which you can derive your viewer extensions that will abstract away some of the plumbing work for you.
When dealing with multi-model workflows, I can think basically about 3 kind of extensions:
In order to simplify the implementation of such "multi-model aware" extensions, I created a base class that my extensions can derive from. The base class acts as an interface which is responsible for setting up all the required event handlers and invoke predefined methods which can be implemented by the derived extension if this one is interested in dealing with that event. I found this gives a lot of structure and avoid code repetition in the extensions I am writing now.
For this to work properly you will need to have one of the extension managing the models: for example exposing controls to load, unload, activate models, and firing events when those actions happens. That is a topic I will present in a later post. Below is the code of the MultiModelExtensionBase.
My first extension supporting multi-models simultaneously is the Selection Filter: give a try at that live demo and load an extra model to the scene. The treeview will show another root entry where you can see each model structure and toggle the selectability of each component.