I used The code which remove the mesh after each click and
I Create a variable to store the reference to the previous mesh but nothing change
here is the code used
let previousMesh=true;
window.addEventListener('click', handleClick);function handleClick() {
// Remove previous mesh if it exists
if (!previousMesh) {
scene.remove(previousMesh);
}
// Create a new mesh
const geometry = new THREE.BoxGeometry(5, 6, 1);
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00,wireframe:true });
const mesh = new THREE.Mesh(geometry, material);
// Add the new mesh to the scene
scene.add(mesh);
// Update the reference to the previous mesh
previousMesh = mesh;
}