Closed zsjssj closed 2 weeks ago
Ah, right now raycasting with a splat mesh doesn't work with three.js' raycaster, because raycasting against a splat mesh works differently (it returns intersections with splats, not three.js meshes).
Here is an example of how to use the raycaster that I made for this library specifically for raycasting against splats:
const viewer = new GaussianSplats3D.Viewer();
viewer.addSplatScene(path)
.then(() => {
viewer.start();
viewer.renderer.domElement.addEventListener('pointerdown', onMouseClick, false);
});
const onMouseClick = function(mouse) {
raycastSplatMesh(mouse.offsetX, mouse.offsetY);
}
const raycastSplatMesh = function() {
const renderDimensions = new THREE.Vector2();
const toNewFocalPoint = new THREE.Vector3();
const mousePos = new THREE.Vector3();
const outHits = [];
return function(x, y) {
viewer.getRenderDimensions(renderDimensions);
mousePos.set(x, y);
outHits.length = 0;
viewer.raycaster.setFromCameraAndScreenPosition(viewer.camera, mousePos, renderDimensions);
viewer.raycaster.intersectSplatMesh(viewer.splatMesh, outHits);
if (outHits && outHits.length > 0) {
console.log(outHits[0])
}
};
}();
This solves my problem, thank you.
Great, glad that fixed it!
I want to pick up intersection points using ray like follows
But I can only get intersection points in a invisible sphere at the origin like in the following image. And it is not possible to get intersect point outside the sphere area.![image](https://github.com/mkkellogg/GaussianSplats3D/assets/95166074/2a58a53d-6c20-4b0d-b2e9-d273cd0f2017)