Hi!
Not sure about THREE.LineSegments()
with THREE.Geometry()
, but, if you work with THREE.BufferGeometry()
, then .intersectObject()
method returns an array of objects and one of properties of those objects is .index
, that represents the index of the neares vertex of the intersected line segment (if I got it correctly, though the documentation doesn’t say about it).
Thus, when you know the index of one point of a line segment, you can find the index of the other point just like that:
suppose idx
is the index you found by intersection
let idxNear = idx % 2 === 0 ? idx + 1: idx - 1;
So, you know indices of vertices, you can obtain their coordinates from line.geometry.attributes.position
with .fromBufferAttribute()
method of THREE.Vector3()
.
Just a related fiddle, where you can see how to find the indices of points in a line segment:
https://jsfiddle.net/prisoner849/hu6jjj4p/
One more example of interaction with points (an indexed THREE.BufferGeometry()
):
http://jsfiddle.net/prisoner849/go0dfwo5/