How do can I load model and change materials before showing it in the Forge Viewer

主宰稳场 提交于 2019-12-25 00:18:03

问题


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 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);
  }
)

回答1:


I would simply show a pre-canned jpg image preview in place of the forge canvas.

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...

https://github.com/wallabyway/forge-pdf-report/blob/6babb6d7332b6cdb983f57e7d140ff59a5136705/docs/index.html#L44

  1. Hide the forge canvas with style 'display:block'
  2. Hide your preview-jpg.


来源:https://stackoverflow.com/questions/51558587/how-do-can-i-load-model-and-change-materials-before-showing-it-in-the-forge-view

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