问题描述
如何在查看器中加载多个URN或URN数组并使用第一个URN的GlobalOffest在同一查看器中加载第二个URN
How to load multiple URN or and array of URN in a viewerand also use the GlobalOffest of the 1st URN to load the 2nd URN in same viewer
推荐答案
很简单,基本方案来自此官方博客的 loadModel函数.
It's simple, the basic scenario is from this official blog's loadModel function.
根据我的经验,您可以在触发Autodesk.Viewing.GEOMETRY_LOADED_EVENT
的同时加载第二个模型,并将第一个模型的GlobalOffest应用于第二个模型.这是这种情况的示例:
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 );
如果您使用viewer.start()
在查看器初始化中加载第一个模型,则这些代码将更改为:
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 );
这篇关于在同一查看器中加载多个URN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!