Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/dev/core/src/Collisions/gpuPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ export class GPUPicker {
this._meshUniqueIdToPickerId[mesh.uniqueId] = pickId;
nextFreeId++;

if (!mesh.isPickable || !mesh.isVisible) {
continue;
}

// Create a GaussianSplattingMaterial with picking plugin for GPU picking
const gsPickingMaterial = this._createGaussianSplattingPickingMaterial(scene, mesh);
const plugin = gsPickingMaterial.pluginManager!.getPlugin<GaussianSplattingGpuPickingMaterialPlugin>("GaussianSplatGpuPicking")!;
Expand Down Expand Up @@ -496,6 +500,11 @@ export class GPUPicker {
const plugin = gsPickingMaterial.pluginManager!.getPlugin<GaussianSplattingGpuPickingMaterialPlugin>("GaussianSplatGpuPicking")!;
plugin.isCompound = true;
plugin.partMeshIds = partMeshIds;
// Only active (included, visible, and pickable) parts should contribute to the depth buffer.
const activeParts = group.partEntries
.filter((e) => (e.proxy as AbstractMesh).isPickable && (e.proxy as AbstractMesh).isVisible)
.map((e) => (e.proxy as any).partIndex as number);
plugin.setPartActive(activeParts);
Comment thread
CedricGuillemet marked this conversation as resolved.

gsPickingMaterial.onBindObservable.add(() => {
this._meshRenderingCount++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class GaussianSplattingGpuPickingMaterialPlugin extends MaterialPluginBas
private _pickingColor: [number, number, number] = [0, 0, 0];
private _isCompound: boolean = false;
private _partPickingColors: number[] = [];
private _partVisibility: number[] = [];
private _maxPartCount: number;

/**
Expand Down Expand Up @@ -82,6 +83,21 @@ export class GaussianSplattingGpuPickingMaterialPlugin extends MaterialPluginBas
this._partPickingColors = colors;
}

/**
* Sets which parts are active (pickable) for the compound picking pass.
* Parts not in the set are discarded in the shader by overriding partVisibility to 0.
* @param activeParts Array of part indices that should be pickable.
*/
public setPartActive(activeParts: number[]): void {
const visibility = new Array(this._maxPartCount).fill(0.0);
for (const index of activeParts) {
if (index >= 0 && index < this._maxPartCount) {
visibility[index] = 1.0;
Comment thread
CedricGuillemet marked this conversation as resolved.
}
}
this._partVisibility = visibility;
}

/**
* @returns the class name
*/
Expand Down Expand Up @@ -154,8 +170,10 @@ uniform vec3 pickingColor;
`,
CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR: `
#if IS_COMPOUND
if (vColor.a < 0.001) discard;
finalColor = vec4(partPickingColors[int(vPartIndex + 0.5)], 1.0);
#else
if (vColor.a < 0.001) discard;
finalColor = vec4(pickingColor, 1.0);
#endif
`,
Expand Down Expand Up @@ -188,8 +206,10 @@ uniform pickingColor: vec3f;
`,
CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR: `
#if IS_COMPOUND
if (fragmentInputs.vColor.a < 0.001) { discard; }
finalColor = vec4f(uniforms.partPickingColors[i32(fragmentInputs.vPartIndex + 0.5)], 1.0);
#else
if (fragmentInputs.vColor.a < 0.001) { discard; }
finalColor = vec4f(uniforms.pickingColor, 1.0);
#endif
`,
Expand Down Expand Up @@ -228,6 +248,9 @@ uniform pickingColor: vec3f;

if (this._isCompound) {
effect.setArray3("partPickingColors", this._partPickingColors);
// default all visible when setPartActive hasn't been called
const visibility = this._partVisibility.length > 0 ? this._partVisibility : new Array(this._maxPartCount).fill(1.0);
Comment thread
CedricGuillemet marked this conversation as resolved.
effect.setArray("partVisibility", visibility);
} else {
effect.setFloat3("pickingColor", this._pickingColor[0], this._pickingColor[1], this._pickingColor[2]);
}
Expand Down
Loading