Skip to content

Commit f680b02

Browse files
committed
fix: picker sees through highlighted items (fix #737)
Fragments puts highlight materials in extra slots of `mesh.material` and tags the highlighted item's `geometry.groups` entry with `materialIndex >= 1`. Swapping to a length-1 `[_idMaterial]` array made three skip those groups, so clicking a highlighted item read back the element behind instead of toggling the selection off. Pad the swap array to the original length, every slot pointing at the override material.
1 parent 09f81ea commit f680b02

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

packages/core/src/core/FastModelPicker/src/fast-model-picker.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,18 @@ export class FastModelPicker implements Disposable {
435435
// groups when the mesh's material is `Material[]`; with a single
436436
// `Material` it falls back to drawing the whole indexed
437437
// geometry, which would make hidden items pickable.
438-
child.material = [this._idMaterial];
438+
//
439+
// Length must match the original. Fragments puts highlight
440+
// materials in extra slots of `mesh.material` and tags the
441+
// highlighted item's group with `materialIndex >= 1`. A
442+
// length-1 swap array would make three skip those groups,
443+
// so a click on a highlighted item would see through it to
444+
// whatever's behind. Filling every slot with `_idMaterial`
445+
// keeps every group pickable while still honouring per-item
446+
// visibility (hidden items remain absent from `groups`).
447+
const original = child.material;
448+
const len = Array.isArray(original) ? original.length : 1;
449+
child.material = new Array(len).fill(this._idMaterial);
439450
any = true;
440451
});
441452

@@ -659,8 +670,12 @@ export class FastModelPicker implements Disposable {
659670
// Wrap in an array so three honours `geometry.groups` (per-item
660671
// visibility ranges). With a single Material, three draws the
661672
// whole indexed geometry and the depth/normal at the cursor
662-
// would reflect a hidden item.
663-
child.material = [material];
673+
// would reflect a hidden item. Length must match the original
674+
// so highlight groups (materialIndex >= 1) also draw — see the
675+
// longer note in `applyIdMaterial`.
676+
const original = child.material;
677+
const len = Array.isArray(original) ? original.length : 1;
678+
child.material = new Array(len).fill(material);
664679
});
665680
}
666681

0 commit comments

Comments
 (0)