Hi All, I’ve been really struggling to get the raycaster detecting meshes consistently.
I’m creating plane geometries on mouse click and drag, they should be detected so they’re not placed over each other, I add each plane geometry to the scene as well as an array and then the next time the mouse moves it checks if there’s already a mesh intersecting the mouse (the position of the detected plane is then rounded to a grid location so it’s not looking for the exact position but the grid position the mouse is within). Sometimes it detects the mesh is there and other times it doesn’t and creates another mesh over the top of the current one.
I’ve checked the scene and the array and swapped between them, and the meshes are in the scene according to the updated child length.
var canvasBounds = scene.rendererModelling.domElement.getBoundingClientRect(); input.mouse.pos.x = ( ( event.clientX - canvasBounds.left ) / ( canvasBounds.right - canvasBounds.left ) ) * 2 - 1; input.mouse.pos.y = - ( ( event.clientY - canvasBounds.top ) / ( canvasBounds.bottom - canvasBounds.top) ) * 2 + 1; //console.log("clicked") //console.log("GetPoint MouseX: ",input.mouse.pos.x,", GetPoint MouseY: ",input.mouse.pos.x) scene.raycaster.setFromCamera(input.mouse.pos,scene.cameraModelling) var groupTileIntersects = scene.raycaster.intersectObjects(scene.currentGroup.children, true)
I’ve also implemented and checked the canvas mouse position code suggested in an earlier thread to make sure it’s getting the correct position, and the new canvas position code is returning the same exact position as my previous code on each mouse move.
I’ve also inserted ‘scene.currentGroup.updateMatrixWorld()’ after the mesh is created to update the group it’s going into.
Every check I’ve made is saying that the new mesh is in the scene but the raycaster sometimes doesn’t see it, and other times it will.
…I’m stumped