问题
How to load multiple URN or and array of URN in a viewer and also use the GlobalOffest of the 1st URN to load the 2nd URN in same viewer
回答1:
It's simple, the basic scenario is from this official blog's loadModel function.
You can load 2nd model while Autodesk.Viewing.GEOMETRY_LOADED_EVENT
was fired and apply 1st model's GlobalOffest to the 2nd model in my experience. Here is the example for this case:
function _onGeometryLoaded( event ) {
if( urns.length <= 0 ) {
viewer.removeEventListener(
Autodesk.Viewing.GEOMETRY_LOADED_EVENT,
_onGeometryLoaded
);
return;
}
viewer.loadModel( urns[0], { globalOffset: event.model.getData().globalOffset } );
urns.splice( 0, 1 );
}
viewer.addEventListener(
Autodesk.Viewing.GEOMETRY_LOADED_EVENT,
_onGeometryLoaded
);
viewer.loadModel( urns[0] );
urns.splice( 0, 1 );
If you use viewer.start()
to load the first model on the viewer initialization, those codes will be changed into:
function _onGeometryLoaded( event ) {
if( urns.length <= 0 ) {
viewer.removeEventListener(
Autodesk.Viewing.GEOMETRY_LOADED_EVENT,
_onGeometryLoaded
);
return;
}
viewer.loadModel( urns[0], { globalOffset: event.model.getData().globalOffset } );
urns.splice( 0, 1 );
}
viewer.addEventListener(
Autodesk.Viewing.GEOMETRY_LOADED_EVENT,
_onGeometryLoaded
);
// Change here
viewer.start( urns[0], options, onSuccessCallback, onErrorCallback );
urns.splice( 0, 1 );
来源:https://stackoverflow.com/questions/46127967/load-multiple-urn-in-a-same-viewer