how to raycast on a gaussian splat mesh?
addSplatMesh(url, options = {}) {
const splatAsset = new pc.Asset('gsplat', 'gsplat', { url: url });
this.stage.rendererManager.app.assets.add(splatAsset);
splatAsset.ready((asset) => {
this.splatMesh = new pc.Entity();
this.splatMesh.name = 'splatMesh'; // Add a name for debugging
this.splatMesh.addComponent('gsplat', {
asset: asset
});
this.splatMesh.setLocalPosition(-1.5, 0.05, 0);
this.splatMesh.setLocalEulerAngles(0, 0, 0);
this.splatMesh.setLocalScale(0.7, 0.7, 0.7);
// this.splatMesh.addComponent("collision", { type: "mesh" });
this.splatMesh.addComponent("rigidbody", { type: "static" });
this.splatMesh.userData = {
parent: this
}
this.stage.rendererManager.app.root.addChild(this.splatMesh);
});
this.stage.rendererManager.app.assets.load(splatAsset);
}
this is how i added the mesh, but im not getting any hit
Hi @Nikhil_Shaji and welcome!
I think you still need to assign the correct mesh asset to the mesh collision component. (Right now, the collision component is commented out by the way).
Unfortunately, I didn’t find a good example to share here.
Hi Albertos,
I did try without commenting it, but nothing seems to be working.
onClick(event) {
const camera = this.stage.rendererManager.app.root.findByName('camera').camera;
const from = camera.screenToWorld(event.x, event.y, 0);
const to = camera.screenToWorld(event.x, event.y, 1000);
const result = this.stage.rendererManager.app.systems.rigidbody.raycastFirst(from, to);
console.log('result: ', result);
}
the result is always null.
You still need to assign a mesh asset to it. Maybe you can give it a try with primitive collision first.
I’m actually need an accurate raycast method, not just picking objects but require the point of intersection. Not sure the mesh method will work for my case.
Raycast is not working on gSplat meshes. I only works if you place a hidden mesh inside it
Yes, that’s why I mentioned that you need to assign a mesh asset to the collision component. Not sure how you can create a mesh for a Gaussian Splat, but that’s a different question.
Hey @Nikhil_Shaji
This sample shows how to pick a Gaussian Splat element
PlayCanvas Examples
2 Likes