如何在Froge查看器中复制“截面剪切形式”修订?

发布于 2025-01-29 13:23:55 字数 1339 浏览 2 评论 0原文

我正在研究一个可以从Forge Viewer中从Revit切割的部分框的应用程序。我使用以下代码在Revit API中获得了最大点和最小框的最大点和最小框:

BoundingBoxXYZ currentSectionBox = view3D.GetSectionBox();

double[] minPt = new double[] { 
  currentSectionBox.Transform.Origin.X + currentSectionBox.Min[0],
  currentSectionBox.Transform.Origin.Y + currentSectionBox.Min[1],
  currentSectionBox.Transform.Origin.Z + currentSectionBox.Min[2]
};

double[] maxPt = new double[] { 
  currentSectionBox.Transform.Origin.X + currentSectionBox.Max[0],
  currentSectionBox.Transform.Origin.Y + currentSectionBox.Max[1],
  currentSectionBox.Transform.Origin.Z + currentSectionBox.Max[2]
};

它可以通过此代码在Revit中复制:

...
// View3D is the current opened 3d view in revit

View3D.SetSectionBox(new BoundingBoxXYZ() {
  Max = new XYZ(maxPt[0], maxPt[1], maxPt[2]), 
  Min = new XYZ(minPt[0], minPt[1], minPt[2]) 
});

到目前为止,,我使用了相同的最大值和最小值指向Forge Viewer 。我希望看到相同的结果,但事实并非如此。我的代码中有什么问题,还是我只是误解了一些概念?

let offset = this.Viewer3D.model.getData().globalOffset
offset = new THREE.Vector3(offset.x, offset.y, offset.y)

const sectionBoxPosition = new THREE.Box3(minPt.sub(offset), maxPt.sub(offset))
  
this.Viewer3D.loadExtension('Autodesk.Section').then(function (Section) {
  Section.setSectionBox(sectionBoxPosition)
})

I'm working on an app that can reproduce the section box cut from revit in forge viewer. I've got the max point and min point of section box using the code below in revit api:

BoundingBoxXYZ currentSectionBox = view3D.GetSectionBox();

double[] minPt = new double[] { 
  currentSectionBox.Transform.Origin.X + currentSectionBox.Min[0],
  currentSectionBox.Transform.Origin.Y + currentSectionBox.Min[1],
  currentSectionBox.Transform.Origin.Z + currentSectionBox.Min[2]
};

double[] maxPt = new double[] { 
  currentSectionBox.Transform.Origin.X + currentSectionBox.Max[0],
  currentSectionBox.Transform.Origin.Y + currentSectionBox.Max[1],
  currentSectionBox.Transform.Origin.Z + currentSectionBox.Max[2]
};

And it can be reproduced by this code same in the revit:

...
// View3D is the current opened 3d view in revit

View3D.SetSectionBox(new BoundingBoxXYZ() {
  Max = new XYZ(maxPt[0], maxPt[1], maxPt[2]), 
  Min = new XYZ(minPt[0], minPt[1], minPt[2]) 
});

So far so good, then I used the same max and min point in forge viewer. I expected to see the same result in revit, but it didn't. Is anything wrong in my code or I just misunderstand some concept about it?

let offset = this.Viewer3D.model.getData().globalOffset
offset = new THREE.Vector3(offset.x, offset.y, offset.y)

const sectionBoxPosition = new THREE.Box3(minPt.sub(offset), maxPt.sub(offset))
  
this.Viewer3D.loadExtension('Autodesk.Section').then(function (Section) {
  Section.setSectionBox(sectionBoxPosition)
})

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟凡古楼 2025-02-05 13:23:55

您过去应用全局偏移的方式看起来不正确。

我建议您使用viewer.model.getModeltoviewertransform()进行以下计算,以获取正确的模型来转换查看器。有时,除全球偏移量外,模型还有其他转换。

var boxMinFromRvt = new THREE.Vector3(-20.9539269351606, -128.710696355516, -43.8630604978775); //!<<< From Revit API's BoundingBoxXYZ.Min
var boxMaxFromRvt = new THREE.Vector3(73.7218284399634, 102.143481472216, 43.8630604978775); //!<<< From Revit API's BoundingBoxXYZ.Max

var boxTransformFromRvt = new Autodesk.Viewing.Private.LmvMatrix4(true).fromArray([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 7.49058457162347, -35.3016883690933, 16.5749846091418, 1]);  //!<<< From Revit API's BoundingBoxXYZ. Transform

var modelTransform = viewer.model.getModelToViewerTransform();

var minOffseted = boxMinFromRvt.clone().applyMatrix4(boxTransformFromRvt).applyMatrix4(modelTransform);
var maxOffseted = boxMaxFromRvt.clone().applyMatrix4(boxTransformFromRvt).applyMatrix4(modelTransform);

var box = new THREE.Box3(minOffseted, maxOffseted);
viewer.getExtension('Autodesk.Section').setSectionBox(box);

注意。 boxtransformfromrvt来自Revit SectionBox的boundingbox.transform如下所示。 (0,0,0,1)用于转换矩阵的w元素,因为三js的变换为4x4(xyzw),但是我们从revit中获得的是4x3。

var boxTransformFromRvt = [
  Transform.BasicX.X, Transform.BasicX.Y, Transform.BasicX.Z, 0,
  Transform.BasicY.X, Transform.BasicY.Y, Transform.BasicY.Z, 0,
  Transform.BasicZ.X, Transform.BasicZ.Y, Transform.BasicZ.Z, 0,
  Transform.BasicZ.X, Transform.BasicZ.Y, Transform.BasicZ.Z, 0,
  Transform.Origin.X, Transform.Origin.Y, Transform.Origin.Z, 1
]

这是我的测试的快照:

  • revit

  • 在Forge查看器中

The way you used to apply the global offset looks incorrect.

I would advise you to do the calculation like the below using viewer.model.getModelToViewerTransform() to get the correct model to transform in the viewer. Sometimes, there are other transforms made to the model except for the global offset.

var boxMinFromRvt = new THREE.Vector3(-20.9539269351606, -128.710696355516, -43.8630604978775); //!<<< From Revit API's BoundingBoxXYZ.Min
var boxMaxFromRvt = new THREE.Vector3(73.7218284399634, 102.143481472216, 43.8630604978775); //!<<< From Revit API's BoundingBoxXYZ.Max

var boxTransformFromRvt = new Autodesk.Viewing.Private.LmvMatrix4(true).fromArray([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 7.49058457162347, -35.3016883690933, 16.5749846091418, 1]);  //!<<< From Revit API's BoundingBoxXYZ. Transform

var modelTransform = viewer.model.getModelToViewerTransform();

var minOffseted = boxMinFromRvt.clone().applyMatrix4(boxTransformFromRvt).applyMatrix4(modelTransform);
var maxOffseted = boxMaxFromRvt.clone().applyMatrix4(boxTransformFromRvt).applyMatrix4(modelTransform);

var box = new THREE.Box3(minOffseted, maxOffseted);
viewer.getExtension('Autodesk.Section').setSectionBox(box);

Note. The boxTransformFromRvt is from Revit SectionBox's BoundingBox.Transform like below. The (0,0,0,1) is for w element of the transform matrix, as threejs' transform is 4x4 (xyzw), but what we get from Revit is 4x3.

var boxTransformFromRvt = [
  Transform.BasicX.X, Transform.BasicX.Y, Transform.BasicX.Z, 0,
  Transform.BasicY.X, Transform.BasicY.Y, Transform.BasicY.Z, 0,
  Transform.BasicZ.X, Transform.BasicZ.Y, Transform.BasicZ.Z, 0,
  Transform.BasicZ.X, Transform.BasicZ.Y, Transform.BasicZ.Z, 0,
  Transform.Origin.X, Transform.Origin.Y, Transform.Origin.Z, 1
]

Here are the snapshots of my tests:

  • In Revit
    enter image description here

  • In Forge Viewer
    enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文