good day everybody
I tried many ways to use the code to cancel drawing after getting several number of points but not working i don’t know how to do that
function handleClick(event) {
const x = (event.clientX / window.innerWidth) * 2 - 1;
const y = -(event.clientY / window.innerHeight) * 2 + 1;
const vector = new THREE.Vector3(x, y, y);
vector.unproject(camera);
const dir = vector.sub(camera.position).normalize();
const distance = -camera.position.y / dir.y;
const pos = camera.position.clone().add(dir.multiplyScalar(distance));
vertice.push(pos);
console.log(pos)
const customGeometry = new THREE.BufferGeometry().setFromPoints(vertice);
points.geometry.dispose(), points.geometry = customGeometry;
if (vertice.length >= 3) {
const curve = new THREE.CatmullRomCurve3(vertice);
const po = curve.getSpacedPoints(50);
const geometry = new THREE.BufferGeometry().setFromPoints(po);
const material = new THREE.LineBasicMaterial({ color: 0xff0000,size:5 });
curveObject.geometry.dispose(), curveObject.geometry = geometry, curveObject.material = material;
}
}
function init() {
scene.add(points);
scene.add(curveObject);
window.addEventListener('click', handleClick);
window.addEventListener('contextmenu', function(){
document.onclick=null;
});
anybody to fix this.
Thank you