Autodesk Forge Viewer API V7.*对齐多个2D DWG模型 [英] Autodesk forge viewer api v7.* align multiple 2d dwg models

查看:186
本文介绍了Autodesk Forge Viewer API V7.*对齐多个2D DWG模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用Autodesk Forge Viewer v7.*.在这个项目中,我必须展示来自上传到BIM360的 .dwg 文件的多个2d模型.我可以加载每个模型,并且它们彼此堆叠,但是它们的对齐方式似乎是完全错误的.我已经尝试过各种 loadOptions ,还尝试过后适应模型的总体转换,但是它们的对齐方式看起来还是随机的.这是代码的一部分:

I am using the Autodesk Forge viewer v7.* in a project. In this project I have to show multiple 2d models derriving from .dwg files uploaded to BIM360. I can load in each model and they are stacked on top of each other, but their alignment seems to be totally wrong. I have tried all sorts of loadOptions and also tried to post adapt the total transformation of the model, but their alignment remains to look random. Here is a part of the code:

onDocumentLoaded = (doc, id, resolve, reject) => {
    // A document contains references to 3D and 2D geometries.
    let geometries = doc.getRoot().search({ 'type': 'geometry' })
    if (geometries.length === 0) {
      console.error('Document contains no geometries.')
      return
    }

    // Choose any of the avialable geometries
    let initGeom = geometries[0]


    let ops = {
      placementTransform: new window.THREE.Matrix4(),
      modelSpace: true,
      globalOffset: { x: 0, y: 0, z: 0 },
      applyRefPoint: true,
      isAEC: true, // to align the models,
    }

    // Load the chosen geometry
    let svfUrl = doc.getViewablePath(initGeom)
    this.viewerApp.loadModel(svfUrl, ops, (model) => this.onModelLoaded(model, id, resolve, reject), (error) => reject(error))
  }

如您所见,我尝试了一些loadoptions,但是在加载2d模型时它们似乎都不重要.它们确实会对3d(.ifc,.rvt,.nwd)模型产生影响.

As you see, I tried a few loadoptions, but they all do not seem to matter when loading 2d models. they do have an impact on 3d (.ifc, .rvt, .nwd) models.

在加载模型之后,我还尝试更新转换:

I also tried to update the transformation after the model has been loaded:

transformModel = (viewer, model, transform) => {

    let translation = new window.THREE.Vector3();
    let rotation = new window.THREE.Quaternion();
    let scale = new window.THREE.Vector3();
    transform.decompose(translation, rotation, scale);

    function transformFragProxy(fragId) {

      var fragProxy = viewer.impl.getFragmentProxy(
        model,
        fragId);

      fragProxy.getAnimTransform();


      fragProxy.position = translation;

      fragProxy.scale = scale;

      fragProxy.quaternion._x = rotation.x;
      fragProxy.quaternion._y = rotation.y;
      fragProxy.quaternion._z = rotation.z;
      fragProxy.quaternion._w = rotation.w;

      fragProxy.updateAnimTransform();
    }

    var fragCount = model.getFragmentList().fragments.fragId2dbId.length;
    //fragIds range from 0 to fragCount-1
    for (var fragId = 0; fragId < fragCount; ++fragId) {

      transformFragProxy(fragId);
    }
  }

onModelLoaded = (model, id, resolve) => {

    if (!model.isLoadDone()) {
      // wait for loading complete, 2d models are not completely loaded even though onModelLoaded is called
      setTimeout(this.onModelLoaded, 0.1, model, id, resolve)
    } else {
      // done loading
      // force transformation
      this.transformModel(this.viewerApp, model, new window.THREE.Matrix4());
      this.viewerApp.impl.sceneUpdated(true);
      // .. rest op code here
    }

  }

推荐答案

如果所有其他方法均失败,请尝试使用 placementTransform 选项手动应用翻译:

If all else fails try apply translation manually using the placementTransform option:

const mat4 = new THREE.Matrix4()
mat4.makeTranslation(10,10,10)
//...
NOP_VIEWER.loadDocumentNode(document, geometry, {
   placementTransform: mat4, 
   keepCurrentModels: true
})

这篇关于Autodesk Forge Viewer API V7.*对齐多个2D DWG模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆