如何在伪造查看器中获取真实世界的测量值 [2D 计划] [英] How to acquire real world measurements in forge viewer [2D plan]

查看:32
本文介绍了如何在伪造查看器中获取真实世界的测量值 [2D 计划]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堵墙,我将坐标从墙上放入边缘"类.Edge 具有属性 start 和 end,它们表示墙的一条边的起点和终点.由于这是伪造坐标,我不知道我的墙到底有多长.有一个测量工具可以做到这一点,但我如何以编程方式使用它来确定边缘的长度.

I have a wall from which I put the coordinates into "Edge" classes. Edge has the properties start and end which represent start and end point of one edge of the wall. Due to this being in forge coordinates, I do not know how long my wall really is. There is a measurement tool which can do this but how do I use it programatically to determine the length of my edges.

实际结果:Forge 坐标中的边
预期结果:m 中的边

Actual Result: Edges in Forge coordinates
Expected Result: Edges in m

  const vertexbuffer = new Autodesk.Viewing.Private.VertexBufferReader(geometry);
  let event = new VertexBufferEvent();
  vertexbuffer.enumGeomsForObject(dbid, event);
  parts.push(new Part(event.getCollection(), dbid));

<小时>

  /**
   * This event is called when Autodesk.VertexBufferReader finds a line.
   * Line coordinates are saved as an Edge
   * @param x0
   * @param y0
   * @param x1
   * @param y1
   * @param viewport_id
   */
  handle(x0, y0, x1, y1) {
    let start = new Point(x0, y0, 0);
    let end = new Point(x1, y1, 0)
    let edge = new Edge(start, end)
    this.edgeCollection.push(edge);
  }

  onLineSegment(x0, y0, x1, y1, viewport_id) {
    this.handle(x0, y0, x1, y1)
  }

  getCollection() {
    return this.edgeCollection
  }

注意:我不想在 propertydb 中获取 length 属性

Note: I am not looking to acquire the length property in the propertydb

推荐答案

您可能需要将 viewer.model.getUnitScale() 应用于模型的长度信息.

You probably need to apply the viewer.model.getUnitScale() to the length information on the model.

编辑

getUnitScale 返回模型距离单位的比例因子,以米为单位.

getUnitScale returns the scale factor of model's distance unit to meters.

你应该使用 model.getInstanceTree().getNodeBox() 作为边界框,在你的情况下,如果你传递 dbId 1 应该返回边界框整个模型.当您的模型在 mm 中时,您乘以 bu .getUnitScale 以转换为 m.

And you should be using model.getInstanceTree().getNodeBox() for the bounding box, in your case, if you pass dbId 1 should return the bounding box of the entire model. As you model is in mm, then you multiply bu .getUnitScale to convert to m.

var f = new Float32Array(6)
viewer.model.getInstanceTree().getNodeBox(1, f)

编辑 2

对于 2D 图纸,您需要额外的转换.对于 onLineSegment,您可以使用以下内容:

For 2D sheets you need an extra transformation. For the onLineSegment you can use something like:

GeometryCallback.prototype.onLineSegment = function (x1, y1, x2, y2, vpId) {
    var vpXform = this.viewer.model.getPageToModelTransform(vpId);

    var pt1 = new THREE.Vector3().set(x1, y1, 0).applyMatrix4(vpXform);
    var pt2 = new THREE.Vector3().set(x2, y2, 0).applyMatrix4(vpXform);

    var dist = pt1.distanceTo(pt2) * this.viewer.model.getUnitScale();

    console.log(dist); // this should be in meters
};

这篇关于如何在伪造查看器中获取真实世界的测量值 [2D 计划]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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