Hi, I have created the TubeBufferGeometry. The code is following:
var curve = new THREE.CatmullRomCurve3( pointArray, false, "centripetal");
var geometry = new THREE.TubeBufferGeometry( curve, curveSegments, tubeRadius, radiusSegments, closed );
In the Raycaster.intersectObject(), I can get the following results.
distance – distance between the origin of the ray and the intersection
point – point of intersection, in world coordinates
face – intersected face
faceIndex – index of the intersected face
object – the intersected object
uv - U,V coordinates at point of intersection
Now I can get the intersected point position in TubeBufferGeometry when moving the mouse.
How can I find the nearest point in the pointArray to the intersected point?
Should I change the coordination of the intersected point into world vector?
// point: intersection point
var nearestPoint = null;
var nearestIndex = -1;
var nearestDistance = Infinity;
for ( var i = 0, n = pointArray.length; i ++ ) {
var currPoint = pointArray[ i ];
var dist = currPoint.distanceTo( point );
if ( dist < nearestDistance ) {
nearestDistance = dist;
nearestPoint = currPoint;
nearestIndex = i;
}
}
You’re welcome. Probably, but it will depend on the number of segments. You could infere it from the tube geometry code.
If the tube is generated with constant segment length (as opposed to constant number of segments per point) then the relation will be too complex.
Thanks prisoner. I found the faceIndex at the end of path is 11000. But the count of color in the TubeBuffferGeometry is only 6925. The length of the color is 20775 = 6925*3. How can I know how many faces in the Geometry? Is it the number tubularSegments 1384 * radialSegments 4 ?
path — Curve - A path that inherits from the Curve base class
tubularSegments — Integer - The number of segments that make up the tube, default is 64
radius — Float - The radius of the tube, default is 1
radialSegments — Integer - The number of segments that make up the cross-section, default is 8
closed — Boolean Is the tube open or closed, default is false
Here, the tubularSegments is set as the real point number. But it seems there is no attribute of tubularSegments in the TubeBufferGeometry. The Raycaster only return the faceIndex.