简体   繁体   English

Revit 共享坐标到 Forge 查看器

[英]Revit shared coordinates to Forge viewer

What is the correct process for getting a transform between Forge coordinates and Revit's shared coordinates?在 Forge 坐标和 Revit 的共享坐标之间进行转换的正确过程是什么? I know there is globalOffset, but does it reference the Revit project internal coordinate system or shared coordinates?我知道有 globalOffset,但它参考的是 Revit 项目内部坐标系还是共享坐标?

Update Jun 11th, 2021 2021 年 6 月 11 日更新

Now my MultipleModelUtil.js supports the alignments I shared below.现在我的MultipleModelUtil.js支持我在下面分享的对齐方式。 Also, we can easily tell Forge Viewer to use By shared coordinates to aggregate models.此外,我们可以轻松地告诉 Forge Viewer 使用共享坐标来聚合模型。 Here is the code snippet, and you can check out here to know supported alignments这是代码片段,您可以在此处查看以了解支持的对齐方式

const util = new MultipleModelUtil( viewer );

util.options = {
  alignment: MultipleModelAlignmentType.ShareCoordinates
};

const models = [
  { name: '1.rvt', urn: 'urn:dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLlNpaHgxOTVuUVJDMHIyWXZUSVRuZFE_dmVyc2lvbj0x' },
  { name: '2.rvt', urn: 'urn:dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLldVRHJ4ajZ6UTBPLTRrbWZrZ3ZoLUE_dmVyc2lvbj0x' },
  { name: '3.rvt', urn: 'urn:dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLjRyZW5HRTNUU25xNHhYaW5xdWtyaWc_dmVyc2lvbj0x' }
];

util.processModels( models );

================== ===================

First, Forge Viewer supports 3 kinds of Revit link methods as the below, and you can take a look at the 3rd one (By shared coordinates).首先,Forge Viewer 支持 Revit 链接方式如下 3 种,大家可以看看第 3 种(通过共享坐标)。

  1. Origin to origin : Apply the globalOffset of the 1st model to others. Origin to origin : 将第一个globalOffset的 globalOffset 应用到其他人。 Check MultipleModelUtil/MultipleModelUtil.js for the demo检查MultipleModelUtil/MultipleModelUtil.js以获取演示
  2. Center to center : the default way of the viewer. Center to center :查看器的默认方式。
  3. By shared coordinates : set up applyRefpoint: true and make the globalOffset to the refPoint .通过共享坐标:设置 applyRefpoint: true 并将globalOffset设置为refPoint This method is the one you are looking for.此方法是您正在寻找的方法。

The refPoint is the Revit survey point location inside Revit internal coordinate system. refPoint是 Revit 内部坐标系内的 Revit 测量点位置。 It's accessible with the AecModelData .它可以通过AecModelData访问。 Meanwhile, you can take advantage of the AggregatedView to use this aligning option.同时,您可以利用AggregatedView来使用此对齐选项。 Here is an example of telling how to use AggregatedView: https://gist.github.com/yiskang/c404af571ba4d631b5929c777503891e这是一个说明如何使用 AggregatedView 的示例: https://gist.github.com/yiskang/c404af571ba4d631b5929c777503891e

If you want to use this logic with the Viewer class directly, here is a code snippet for you:如果您想直接将此逻辑与查看器 class 一起使用,这里有一个代码片段:

let globalOffset = null;

const aecModelData = bubbleNode.getAecModelData();
const tf = aecModelData && aecModelData.refPointTransformation; // Matrix4x3 as array[12]
const refPoint = tf ? { x: tf[9], y: tf[10], z: 0.0 } : { x: 0, y: 0, z: 0 };

// Check if the current globalOffset is sufficiently close to the refPoint to avoid inaccuracies.
const MaxDistSqr = 4.0e6;
const distSqr    = globalOffset && THREE.Vector3.prototype.distanceToSquared.call(refPoint, globalOffset);
if (!globalOffset || distSqr > MaxDistSqr) {
    globalOffset = new THREE.Vector3().copy(refPoint);
}

viewer.loadDocumentNode(doc, bubbleNode, { applyRefpoint: true, globalOffset: globalOffset, keepCurrentModels: true });

The bubbleNode can be either of the following: bubbleNode可以是以下任意一种:

bubbleNode = doc.getRoot().getDefaultGeometry()

//Or

const viewables = viewerDocument.getRoot().search({'type':'geometry'});
bubbleNode = viewables[0];

To get AecModelData , please refer to my gist: https://gist.github.com/yiskang/c404af571ba4d631b5929c777503891e#file-index-html-L67要获取AecModelData ,请参考我的要点: https://gist.github.com/yiskang/c404af571ba4d631b5929c777503871e#file-index-html-L

// Call this line before using AecModelData
await doc.downloadAecModelData();

// doc.downloadAecModelData(() => resolve(doc));

See here for details of the AecModelData: https://forge.autodesk.com/blog/consume-aec-data-which-are-model-derivative-api有关 AecModelData 的详细信息,请参见此处: https://forge.autodesk.com/blog/consume-aec-data-which-are-model-derivative-api

I've also found success feeding the refPointTransformation into a matrix4.我还发现成功地将refPointTransformation馈送到 matrix4 中。

This way, the orientation of the model is also taken into account.这样,模型的方向也被考虑在内。 (This is based off Eason's Answer ). (这是基于Eason 的回答)。

const bubbleNode = doc.getRoot().getDefaultGeometry();
await doc.downloadAecModelData();
const aecModelData = bubbleNode.getAecModelData();
const tf = aecModelData && aecModelData.refPointTransformation;
const matrix4 = new THREE.Matrix4()
  .makeBasis(
    new THREE.Vector3(tf[0], tf[1], tf[2]),
    new THREE.Vector3(tf[3], tf[4], tf[5]),
    new THREE.Vector3(tf[6], tf[7], tf[8])
  )
  .setPosition(new THREE.Vector3(tf[9], tf[10], tf[11]))

viewer.loadDocumentNode(doc, viewables, {
  placementTransform: matrix4,
  keepCurrentModels: true,
  globalOffset: {
    "x": 0,
    "y": 0,
    "z": 0
  },
  applyRefpoint: true,
  applyScaling: 'ft',
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM