【问题标题】:Set instanceTree to a custom node in Forge 3D viewer在 Forge 3D 查看器中将 instanceTree 设置为自定义节点
【发布时间】:2018-10-28 14:40:50
【问题描述】:

假设我正在处理一个 3D 文件,该文件是一个建筑模型和一个结构模型的组合。 实例树或模型浏览器如下所示

root/
    Arch/
        Level 01/
        Level 02/
        ...
    Str/
        Level 01/
        Level 02/
        ...

我只想显示级别 01。
所以我:

  1. 按照查看器教程中的步骤进行操作
  2. Autodesk.Viewing.GEOMETRY_LOADED_EVENTAutodesk.Viewing.OBJECT_TREE_CREATED_EVENT 添加一个事件监听器
  3. 当 2 被触发时,我使用 article 中的代码仅显示没有重影的 Level 01。

我对这种方法有 2 个问题

  1. 我必须等到整个模型加载完毕才能过滤关卡
  2. 过滤关卡后,如果我点击模型浏览器,我仍然可以看到整个模型结构(但除了关卡 01 之外的所有内容都隐藏了)。如何将实例树设置为仅包含以下内容?

    root/
        Arch/
           Level 01/
        Str/
           Level 01/
    

编辑
我应该在什么时候覆盖 shouldInclude() 函数?
我已经尝试过这个并设置了一个断点,但它似乎永远不会被调用......我也尝试过移动它但徒劳无功。

const start = Date.now();
Autodesk.Viewing.UI.ModelStructurePanel.shouldInclude = (node) => {
  Logger.log(node);
  return true;
};
Autodesk.Viewing.Initializer(options, () => {
  Logger.log(`Viewer initialized in ${Date.now() - start}ms`);
  const config = {};
  // prettier-ignore
  Autodesk.Viewing.theExtensionManager.registerExtension('MyAwesomeExtension', MyAwesomeExtension);
  viewerApp = new Autodesk.Viewing.ViewingApplication('MyViewerDiv');
  viewerApp.registerViewer(viewerApp.k3D, Autodesk.Viewing.Private.GuiViewer3D, config);
  loadDocumentStart = Date.now();
  // prettier-ignore
  viewerApp.loadDocument(documentId, onDocumentLoadSuccess, onDocumentLoadFailure);
});

【问题讨论】:

    标签: autodesk-forge autodesk-viewer


    【解决方案1】:

    关于 #1:对象树存储在文件的内部数据库中 - 出于性能原因 - 仅在实际几何图形之后加载

    关于 #2:您可以继承 ModelStructurePanel 类并添加您自己的行为,例如,通过覆盖 ModelStructurePanel#shouldInclude 方法。

    【讨论】:

    • 我明白了,所以解决方案是通过 Model Derivative API 获取模型结构,如此处所述link,然后覆盖 shouldInclude 方法。
    • 是的,我认为这种方法应该涵盖您的用例。干杯!
    【解决方案2】:

    由于我无法理解如何使用ModelStructurePanel,因此我覆盖了Autodesk.Viewing.ViewingApplication.selectItem,仅修改传递给loadDocumentNodestartWithDocumentNodeoptions,如下所示:

    const options = {
        ids: leafIDs.length > 0 ? leafIDs : null, // changed this line
        acmSessionId: this.myDocument.acmSessionId,
        loadOptions,
        useConsolidation: this.options.useConsolidation,
        consolidationMemoryLimit: this.options.consolidationMemoryLimit || 100 * 1024 * 1024, // 100 MB
      };
    

    leafIDs 是要显示的 objectID 数组。我能够通过以下方式构建它:

    1. 使用GET :urn/metadata/:guid查询ModelDerivativeAPI
    2. 遍历树以查找我感兴趣的 ID。

    可能有一种更优雅的方法可以做到这一点,但这是迄今为止我能做到的最好的方法。

    【讨论】:

      猜你喜欢
      • 2018-03-23
      • 2018-01-30
      • 2022-12-14
      • 2019-03-27
      • 2021-07-14
      • 2021-01-10
      • 2021-09-02
      • 2018-12-31
      • 2018-09-12
      相关资源
      最近更新 更多