1

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.

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
  }

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

Daniel Ignjat
  • 73
  • 1
  • 1
  • 7
  • 1
    Welcome to Stack Overflow. Please show your latest non-working attempt at solving this problem. It is usually more instructive to see fixes to your code than to read someone else's solution. See https://stackoverflow.com/help/how-to-ask – Spangen Jul 05 '18 at 13:48

1 Answers1

0

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

EDIT

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

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)

EDIT 2

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
};
Augusto Goncalves
  • 8,493
  • 2
  • 17
  • 44
  • So using getUnitScale I get 0.001, and UnitString gives me 'mm'. I am unsure on how to apply that. I know that the bounding box of the building in the revit file is roughly 40m x 60m which is what I am looking for, Calculating the bounding box of the building in forge I get 223x150. For calculation I use the vertices of the building, which are in forge coordinates. How do I get these values in meter. – Daniel Ignjat Jul 10 '18 at 08:14
  • Thank you for the answer, but in my case I use vertices from Autodesk.VertexBufferReader to acquire the vertices and want to have e.g. the distance between 2 points in meters. The bounding box I stated was for explanatory reasons. My case is like I have Wall A with vertex1 and Wall O with vertex2 and want to know the distance between or how long is the wall by checking its vertices – Daniel Ignjat Jul 10 '18 at 13:59
  • if you can elaborate how you obtain the vertex, maybe I can help.... I tested just with `.getNodeBox` and the result is as expected – Augusto Goncalves Jul 10 '18 at 14:03
  • Wow that works, thank you! just one more question. The viewport_id used in this context. Is there a way to acquire it manually? – Daniel Ignjat Jul 11 '18 at 09:08
  • great it's working! remember to accept as solution when done :) about the `viewportId`, sorry don't see another way to access it... – Augusto Goncalves Jul 11 '18 at 11:53
  • 1
    viewer.model.getData().viewports is the way to go :D – Daniel Ignjat Jul 11 '18 at 12:26
  • the calculation for the viewport id is a boolean operation, so it can only be 0 or 1. and looking at the viewports array it has only 2 elements and the first one seems to be the forge viewport i guess while the seconds is the viewport used for transfornation. Just assumptions – Daniel Ignjat Jul 11 '18 at 15:43