How to obtain edges for Communicator.Selection.FaceEntity ?

I selected SelectionItem through pickFromPoint and successfully obtained the faceEntity. I wanted to obtain the edges corresponding to this polygon through faceEntity, but I couldn’t find the corresponding method

Hello @1012683648,

The FaceEntity object does not provide an API to retrieve edges. However, you can get the mesh data of the node and iterate through the points of the selected face element. The returned points construct the individual triangles of the face. So if you want just the perimeter edges, you will have to do additional processing of these points.

Below is an example:

hwv.setCallbacks({
  selectionArray: async function (selections) {
      if (selections.length > 0) {
          for (const selectionEvent of selections) {
            var selection = selectionEvent.getSelection();
            var nodeid = selection.getNodeId();
			console.log("Selected Node: " + nodeid);
			if (selection.getFaceEntity() !== null) {
				var faceIndex = selection.getFaceEntity().getCadFaceIndex();
				console.log("face index: " + faceIndex);
				let data = await hwv.model.getNodeMeshData(nodeid);
				let face = data.faces.element(faceIndex);
				let vertexIterator = face.iterate();
				for (let j = 0; j < face.vertexCount; j += 3) {
					let points = []; //will contain three points representing a single triangle            
					for (let k = 0; k < 3; k++) {
						let rawpoint = vertexIterator.next();
						let p = new Communicator.Point3(rawpoint.position[0], rawpoint.position[1], rawpoint.position[2]);
						points.push(p);
					}
					
					console.log("points" + JSON.stringify(points));
				}
			}
          }
      }
  },
});

Thanks,
Tino

1 Like