【问题标题】:Autodesk Forge Viewer open multiple views togetherAutodesk Forge Viewer 同时打开多个视图
【发布时间】:2021-06-20 21:43:40
【问题描述】:

我试图在一个 Forge 查看器中打开一个模型的多个视图,但每次它只打开一个视图但两次。我想知道是否可以打开多个视图,或者我只能同时打开不同的模型。

为了打开,我使用此代码

const svf_path =
      "/storage/" + decodeURIComponent(props.search.split("&&")[1]);

    Autodesk.Viewing.endpoint.getItemApi = (endpoint, derivativeUrn, api) => {
      return svf_path;
    };

Autodesk.Viewing.Initializer(options, async () => {
      if (props.checked_3D_views.length >= 2) {
       
      const path = svf_path.split("/");
      const [dest, svf_dir] = [path[2], path[3]];
      const url = `/api/viewer/dest/${dest}/svf/${svf_dir}/manifest`;

 Autodesk.Viewing.Initializer(options, async () => {
      const response = await fetch(url);
      const manifest = await response.json();

const viewer_start = new Promise((resolve, reject) => {
            const model = props.loc_viewer.impl.modelQueue().getModels()[0];
            props.loc_viewer.impl.unloadModel(model);
            const viewerDocument = new Autodesk.Viewing.Document(manifest);
            const viewables = viewerDocument
              .getRoot()
              .search(Autodesk.Viewing.BubbleNode.MODEL_NODE);

            const views = [];

            props.checked_3D_views.map(x => {
              views.push(
                viewables.filter(viewable => viewable.data.name === x.name),
              );
            });

views.forEach((view, index) => {
              resolve(
                props.loc_viewer.loadDocumentNode(viewerDocument, view[0], {
                  globalOffset: {x: 0, y: 0, z: 0},
                }),
              );
            });
          });
          viewer_start.then(() => {
            set_bool(true);
          });
        });

我也尝试同时打开不同的模型,它工作正常,但我不能打开两个以上。 如果有人熟悉此类问题,请向我解释如何做到这一点。

【问题讨论】:

    标签: autodesk-forge autodesk-viewer autodesk-model-derivative


    【解决方案1】:

    您需要将 keepCurrentModels 设置为 true,就像对 placementTransform 所做的那样

    async function addViewable(viewer, urn, xform, offset) {
        return new Promise(function (resolve, reject) {
            function onDocumentLoadSuccess(doc) {
                const viewable = doc.getRoot().getDefaultGeometry();
                const options = {
                    preserveView: true,
                    keepCurrentModels: true //!<<<< You need to set this option to true as you did for the placementTransform 
                };
                if (xform) {
                    options.placementTransform = xform;
                }
                if (offset) {
                    options.globalOffset = offset;
                }
                viewer.loadDocumentNode(doc, viewable, options)
                    .then(resolve)
                    .catch(reject);
            }
            function onDocumentLoadFailure(code) {
                reject(`Could not load document (${code}).`);
            }
            Autodesk.Viewing.Document.load('urn:' + urn, onDocumentLoadSuccess, onDocumentLoadFailure);
        });
    }
    

    参考:https://forge.autodesk.com/blog/multi-model-refresher

    【讨论】:

    • 感谢您的回答。但不幸的是,它对我不起作用。我无法通过骨灰盒打开多个视图,因为它们具有相同的骨灰盒。
    • 我需要一些关于如何返回多个端点的建议。
    • 这样可以返回两个端点Autodesk.Viewing.endpoint.getItemApi = ( endpoint, derivativeUrn, api, ) =&gt; { if (svf_path_2 !== null) { Autodesk.Viewing.endpoint.getItemApi = ( endpoint, derivativeUrn, api, ) =&gt; { return svf_path_2; }; } return svf_path_1; };
    猜你喜欢
    • 2020-04-06
    • 2019-04-02
    • 2022-01-02
    • 2020-05-06
    • 2020-10-09
    • 2021-05-13
    • 2020-05-15
    • 2020-09-25
    • 2021-01-16
    相关资源
    最近更新 更多