0

Using the VertexBufferReader as proposed in Autodesk Forge Viewer : f2d get frag from dbid I got some kind of reader, which apparently can be used to read geometry from a specific dbId which is my objective.
My approach which is according to the answer on the other question is not working

   const d2f = oViewer2D.gui.model.getFragmentList().fragments.dbId2fragId; //acquire dbid to fragid reference
        const geometry = oViewer2D.gui.impl.getFragmentProxy(oViewer2D.gui.model, d2f[941]).frags.getGeometry(d2f[941]); //get geometry for fragment
        const reader = new Autodesk.Viewing.Private.VertexBufferReader(geometry); //create reader for geometry
        let obj = new CallbackObject(); //sample callbackobject for reader
        console.log(reader.enumGeomsForObject(940,obj)); //find geometry for dbid --> not working

class CallbackObject {
    constructor() {
    }

    onLineSegment(x0, y0, x1, y1, viewport_id) {
    }

    onCircularArc(centerX, centerY, startAngle, endAngle, radius, viewport_id) {
    }

    onEllipticalArc(centerX, centerY, startAngle, endAngle, major, minor, tilt, viewport_id) {
    }

    onTriangleVertex(x, y, viewport_id) {
    }
}

Goal: I have a custom drawn polygon and I want to find a part that intersects with it, but to do that I need the coordinates from the parts. Thank you!

Update: reading the geometry was quite tricky as my usecase also required the knowledge on which part belongs to which geometry. Below is a full example on how I got the geometry.

    /**
     * Use AutodeskVertexBufferReader to read geometry of parts which consist of concrete and save it in a map with id as a key
     *
     * @param concrete
     */
    async read(concrete) {
        const dbid2fragid = this.viewer.model.getFragmentList().fragments.dbId2fragId;
        let forgeparts = [];
        for (let dbid of concrete) {
            const geometry = this.viewer.impl
                .getFragmentProxy(this.viewer.model, dbid2fragid[dbid])
                .frags.getGeometry(dbid2fragid[dbid]);
            if (geometry === null) {
                continue
            }
            const properties = await this.getProperties(this.viewer, dbid)

            const name: string = properties["name"];
            if (!name.startsWith("Basic Wall") && !name.startsWith("Stue_STB_rech")) {
                continue
            }
            const vertexbuffer = new Autodesk.Viewing.Private.VertexBufferReader(geometry);
            let event = new VertexBufferEvent(this.viewer);
            vertexbuffer.enumGeomsForObject(dbid, event);
            //geoJSONS.push(event.getForgePointsGeoJSONCoordinates());
            let convexHullPoints = ConvexHull.makeHull(event.getForgePoints());
            console.log(properties);
            let relevantproperties = this.readPartProperties(properties);
            let onSameLevelCond = this.isInLevel(relevantproperties.level, relevantproperties.topLevel, this.viewer.currentView.levelName);
            if (!onSameLevelCond) {
                continue;
            }

            forgeparts.push(new Part(event.getforgeEdgeCollection(), convexHullPoints, relevantproperties));
        }
        return forgeparts
    }

Also this part is important to actually get the points

  handle(x0, y0, x1, y1) {
    let startforge = new Point(x0, y0, 0);
    let endforge = new Point(x1, y1, 0);

    if ( this.forgePoints.length === 0 ) {
      this.forgePoints.push(startforge);

    } else {
      let lastPoint = this.forgePoints[this.forgePoints.length-1]
      if (!lastPoint.equals(startforge)) {
        this.forgePoints.push(startforge);
      }
    }

    this.forgePoints.push(endforge);

    let edgeforge = new Edge(startforge, endforge);
    this.forgeEdgeCollection.push(edgeforge);
  }

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

Disclaimer:

  1. This code is 2.5 years old, so it might not work as expected, I very much hope that they have a proper solution on how to get geometry today.
  2. We discarded forge for reading and interacting with ifc data and used a real ifc reader and a homebuilt 3D tool as it was just too inconsistent for a real world usecase at that point in time.
Daniel Ignjat
  • 73
  • 1
  • 1
  • 7
  • Daniel, I do not see any document on this, but as I remember, my colleague Jamie has tested some scripts in https://github.com/jaimerosales/viewer-dwgoffset/blob/0bc36f01c2f93d58a4c91fc33e16ce336fe21f01/src/client/components/Viewer/Viewer-Helpers.js#L159 . Could you check if it helps? – Xiaodong Liang Jun 02 '18 at 02:35
  • Thank you very much, I realized that the callback object method for the `VertexBufferReader` are events, so I just get the x0,y0 and x1,y1 when I hit a line to get the vertices, which gets me some coordinates. I did not test any further if the coordinates correspond to the part, but I will see when i get to the part – Daniel Ignjat Jun 02 '18 at 15:10
  • @DanielIgnjat any progress on this looking for same requirement – Ronak Shetiya Nov 09 '20 at 15:14
  • @RonakShethia updated the question with the answer – Daniel Ignjat Nov 10 '20 at 16:35
  • thanks @DanielIgnjat for your immediate reply, I implemented same thing at my side but it says Point and Edge are not define, could u please tell me from what class are u getting this two things ? – Ronak Shetiya Nov 11 '20 at 05:15
  • just some classes that represent the geometry that i created – Daniel Ignjat Nov 13 '20 at 02:44

0 Answers0