如何在Forge Viewer中显示模型之前加载模型并更改材料 [英] How do can I load model and change materials before showing it in the Forge Viewer
问题描述
我希望能够在伪造查看器中显示模型,但是在模型显示之前,我需要更改其默认材质.当前,我注册了Autodesk.Viewing.GEOMETRY_LOADED_EVENT,当收到事件时,我隐藏了模型,更改了材质,然后显示了模型.除了默认模型在隐藏之前在查看器中显示一两秒钟外,此方法有效.如何防止这种情况发生?
I want to be able to show a model in the forge viewer but before the model shows I need to change the materials from its defaults. Currently I register the Autodesk.Viewing.GEOMETRY_LOADED_EVENT and when I receive the event I hide the model, change the materials and then show the model. This works except that the default model displays in the viewer for a second or two before I can hide it. How can I prevent that from happening?
初始化查看器后,这里是加载文档的代码.如果我尝试按照下面注释代码中所示隐藏模型,则查看器将返回此错误.隐藏它之前,我必须等待几何加载事件.
After initializing the viewer here is code that loads the document. If I try and hide the model as indicated in the commented code below the viewer returns this error. I have to wait for the geometry loaded event before I can hide it.
wgs.js?v = v3.3:17876未捕获的TypeError:无法读取未定义的属性'getGeometryList' 在RenderScene.getGeometryList(wgs.js?v = v3.3:17876) 在Viewer3DImpl.onLoadComplete(viewer3D.js?v = v3.3:32002)
wgs.js?v=v3.3:17876 Uncaught TypeError: Cannot read property 'getGeometryList' of undefined at RenderScene.getGeometryList (wgs.js?v=v3.3:17876) at Viewer3DImpl.onLoadComplete (viewer3D.js?v=v3.3:32002)
这是我正在运行的代码:
Here is the code I'm, running:
Autodesk.Viewing.Document.load(
documentId, (doc) => {
var geometryItems = Autodesk.Viewing.Document.getSubItemsWithProperties(doc.getRootItem(), { 'type': 'geometry' }, true);
if (geometryItems.length > 0) {
viewer.load(doc.getViewablePath(geometryItems[0]), null, (model) => {
// Document loaded
// Can't hide model here, viewer returns an error because geometry
// is not loaded
//viewer.hideModel(model.id);
resolve(model.id);
}); // show 1st view on this document...
}
},
function (errorMsg) { // onErrorCallback
console.log('Load Document returned error message: ' + errorMsg);
}
)
推荐答案
我只是显示一个预先罐头的jpg图像预览来代替伪造画布.
I would simply show a pre-canned jpg image preview in place of the forge canvas.
即. 1.隐藏样式为'display:none'的伪造画布 2.显示您的Preview-jpg代替伪造画布 3.等待TEXTURES_LOADED_EVENT事件,像这样...
ie. 1. Hide the forge canvas with style 'display:none' 2. Show your preview-jpg in place of the forge canvas 3. wait for TEXTURES_LOADED_EVENT event, like this...
- 隐藏样式为'display:block'的伪造画布
- 隐藏预览图.
这篇关于如何在Forge Viewer中显示模型之前加载模型并更改材料的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!