SolidParticleSystem Picking(maybe a bug)

I think it is a bug but I’m not sure.
https://playground.babylonjs.com/#2FPT1A#453
If you try to pick a extrudeshape you’ll get an error.

I went through the source code. In solidParticleSystem.pickedParticle, faceId comes from the index of sps-mesh, while pickedBySubMesh may be splited becauseof multi materials of sps. I think faceId should subtract the submeshes’ faces before.

That’s how I “fix” it now.

sps.__proto__.pickedParticle = function(pickingInfo) {
    if (pickingInfo.hit) {
        const subMesh = pickingInfo.subMeshId;
        let faceId = pickingInfo.faceId;
        const picked = this.pickedBySubMesh;
        for (let i = 0; i < subMesh; i++) {
            faceId -= picked[i].length;
        }
        if (picked[subMesh] && picked[subMesh][faceId]) {
            return picked[subMesh][faceId];
        }
    }
    return null;
}

Pinging @jerome :wink:

The same with https://forum.babylonjs.com/t/multimaterial-solid-particle-system-breaks-picking/8784

1 Like