`LineElement` origin & normal

Is it possible to have the LineElement type expose it’s origin and normal?

The CircleElement for example has both of these.

Use case is I want user selection of an edge of a loaded model to be used to derive input for a direction vector that is used elsewhere (e.g. to set a camera direction)

Hello @zak,

The LineElement object does not really have an origin, per se. Unless you are counting the first point of the edge to be the origin. If you’re okay with that, you can iterate through the lines.element retrieved from the MeshData object to get the raw points (object coordinates) of the edge. And I’m presuming that you have a known edge id/index (and node id for that matter).

Now to get the transformed (world coordinates) of the points, you will need to get the net matrix of the node. You can then subtract one point from another and normalize it to get the direction vector of the edge (if the edge has only has two points).

Here’s a code snippet to get the object and world coordinates of the edge points:

async function getLinePoints(nodeId, edgeIndex){
	let data = await hwv.model.getNodeMeshData(nodeId);
	let lines = data.lines.element(edgeIndex);
	let lineIterator = lines.iterate();
	let mat = hwv.model.getNodeNetMatrix(nodeId);
	let rawPointsAr = [];
	let transformedPointsAr = [];
	
	for (let j = 0; j < lines.vertexCount; j++) {
		let rawpoint = lineIterator.next();
		let p = new Communicator.Point3(
			rawpoint.position[0],
			rawpoint.position[1],
			rawpoint.position[2]
		);
		rawPointsAr.push(p);
		transformedPointsAr.push(mat.transform(p));
	}

	console.log("raw points: " + JSON.stringify(rawPointsAr));
	console.log("transformed points: " + JSON.stringify(transformedPointsAr));
}

Thanks,
Tino

Thanks, it is good to know there is a workaround, but could we have it added to to the public api? This would be consistent with the existing CircleElement which has an origin and normal.

A CircleElement has a natural, mathematically-defined center point and normal. For a LineElement, a point of origin in a bit more arbitrary and context-dependent. For a two point line, I suppose the origin can be the second point and not necesarily the first (or even the middle point). Also, a LineElement can have more than two points defining the edge such as a curving polyline.

Thanks Tino, the context I was missing was that LineElement represents a polyline, not a single two point line. Cheers.