I want draw polygon in three.js with intersection points.
for that I am using below function.
first I add sphere at first point at first intersecting point with raycaster.
after each clicked new sphere created at intersecting point and line created between that and previous point.
now I want to close polygon when I clicked first point or clicked around that point.
how can I achieve that.
is raycaster params works with mesh to detect mesh around mouse position?
function checkIntersectionclick() {
var raycaster = new THREE.Raycaster();
raycaster.params.Mesh.threshold = 5
raycaster.params.Points.threshold = 5
raycaster.setFromCamera(mouse, camera);
var intersectionclick = raycaster.intersectObjects(addedObject, true);
if (intersectionclick.length > 0) {
var sphere = new THREE.Mesh(geometrySphere, materialSphere);
sphere.name = "point"
if (!p1 && !p2) {
p1 = intersectionclick[0].point
} else if (p1 && !p2) {
p2 = intersectionclick[0].point
// multipleRays(p1, p2)
var path = new THREE.LineCurve3(p1, p2);
var Tubegeometry = new THREE.TubeGeometry(path, 20, .5, 8, false);
var line = new THREE.Mesh(Tubegeometry, linematerial);
line.name = "dimensionLine"
line.renderOrder = 1
scene.add(line)
p1 = p2
p2 = null
}
addedObject.push(sphere)
sphere.position.copy(intersectionclick[0].point)
scene.add(sphere)
sphere.renderOrder = 2
}
}