three.js: Undefinend values in planeBufferGeometry causes raycaster to return empty
Description of the problem
I create a planeBufferGeometry and fill it like so:
var positions = new Float32Array(grid.elevations.length * 3).fill(undefined);
for(stuff){
positions[i * 3 + 0] = xpos ;
positions[i * 3 + 1] = ypos;
positions[i * 3 + 2] = (isNaN(zpos)) ? undefined : zpos;
}
var geometry = new THREE.PlaneBufferGeometry();
geometry.addAttribute('position', new THREE.BufferAttribute(positions, 3));
var terrainMesh = new THREE.Mesh(geometry, material);
terrainMesh.name = myMesh;
scene.add(terrainMesh)
then raycast using:
raycaster.setFromCamera(mouse, camera);
var intersects = raycaster.intersectObject(scene.getObjectByName('myMesh'));
intersects is always empty. If I do this:
vertices[i * 3 + 2] = (isNaN(zpos)) ? -1: zpos;
I get a result;
Currently I’m thinking best work around is making a second planeBufferGeometry and assign the undefined values a -1. Then handle if(z = -1) . This position array can get rather large though and having another one is not ideal.
Three.js version
- Dev
- [ X] r84
- …
Browser
- All of them
- Chrome
- Firefox
- Internet Explorer
OS
- All of them
- Windows
- macOS
- Linux
- Android
- iOS
Hardware Requirements (graphics card, VR Device, …)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 19 (8 by maintainers)
@kpetrow what I am saying is that if you are (obviously) not happy with what 3js puts into boundingSphere/Box, you could do this:
instead of relying on geometry.computeBoundingSphere/Box calls. this will allow you to bypass the checks that you are saying are in the way of finding intersections, right?