将Revit级别和2D小地图添加到本地查看器的3D中

时间:2020-09-02 07:20:58

标签: autodesk-forge autodesk-viewer

在我们的项目中,我们使用本地查看器,虽然没有从请求中接收数据,但是我们将其保存在本地。

要从本地文件中获取数据,就不可能将其插入面板中。

然后调用doc.downloadAecModelData()返回null。

查看更多https://forge.autodesk.com/blog/add-revit-levels-and-2d-minimap-your-3d

Autodesk.Viewing.Initializer(options, async () => {


  const config3d = {
    useConsolidation: true,
    useADP: false,
    extensions: [
      "Autodesk.Viewing.MarkupsCore",
      "MarkupExtension",
      "Autodesk.AEC.LevelsExtension", 
      "Autodesk.AEC.Minimap3DExtension"
    ]
  };      


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

  const viewer = new Autodesk.Viewing.GuiViewer3D(init_div, config3d);

  Autodesk.Viewing.endpoint.getItemApi = (endpoint, derivativeUrn, api) => {
    return (
      "/storage/5bf49c73e2ac26b2756b642ae1b29037/aa1bb3d5baaa229e0c15e674adb7aceec1a0fb061e9c0288d9979f801fb6460d.svf/Resource" +
      decodeURIComponent(p.split("Resource")[1])
    );
  };
  const paths = svf_path.split("/");
  const [dest, svf_dir] = [paths[2], paths[3]];

  const url = http://localhost:3000/api/viewer/dest/${dest}/svf/${svf_dir}/manifest;
  const response = await fetch(url);
  const manifest = await response.json();
  const aec_url = /api/viewer/dest/${dest}/svf/${svf_dir}/aec;
  const response_aec = await fetch(aec_url);
  const aec = JSON.parse(await response_aec.json());
  // console.log(aec);
  const viewerDocument = new Autodesk.Viewing.Document(manifest);
  const a = await viewerDocument.downloadAecModelData();
  console.log(a);
  console.log(manifest);
  const viewable = viewerDocument.getRoot().getDefaultGeometry();
  viewable.data.aec_odel_data = aec;
  // console.log(viewable);

  await Autodesk.Viewing.Initializer(options, () => {
  
    // const aec = viewable.parent.children[1].data; //.urn//.split("Resource")[1];

    // for resize and use viewer outer useEffect
    props.set_loc_viewer(viewer);
    
    viewer.start();
    viewer.loadDocumentNode(viewerDocument, viewable, options);
  });

1 个答案:

答案 0 :(得分:0)

据我所知,文档加载后只能使用doc.downloadAecModelData(),如下所示: onDocumentLoadSuccess(doc: Autodesk.Viewing.Document) {doc.downloadAecModelData(); }