Load multiple URN in a same Viewer

匆匆过客 提交于 2019-12-12 04:07:16

问题


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

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