please How to make spline working only in green area
here is the code
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, 0.5);
vector.unproject(camera);
const dir = vector.sub(camera.position).normalize();
const distance = -camera.position.z / dir.z;
const pos = camera.position.clone().add(dir.multiplyScalar(distance));
vertices.push(pos);
console.log(pos.x,pos.y,pos.z)
const customGeometry = new THREE.BufferGeometry().setFromPoints(vertices);
points.geometry.dispose(), points.geometry = customGeometry;
if (vertices.length >= 3) {
const curve = new THREE.CatmullRomCurve3(vertices);
const po = curve.getPoints(150);
const geometry = new THREE.BufferGeometry().setFromPoints(po);
const material = new THREE.LineBasicMaterial({ color: 0xff0000 });
curveObject.geometry.dispose(), curveObject.geometry = geometry, curveObject.material = material;
}
}
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(0, 0, 5);
scene.add(camera);
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
scene.add(points);
scene.add(curveObject);
window.addEventListener('click', handleClick);
const geometry = new THREE.PlaneGeometry( 5,5,10, 10 );
const material = new THREE.MeshBasicMaterial( {color:'green', side: THREE.DoubleSide,wireframe:true} );
const plane = new THREE.Mesh( geometry, material );
scene.add( plane );
}