Skip to content

Commit 66f7c8a

Browse files
authored
Merge pull request #162 from google/ux-intersection-overriding
Support UX intersection check overriding.
2 parents 7d4916c + 712f6c8 commit 66f7c8a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/ux/UX.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,7 @@ export class UX {
125125
const id = controller.userData.id;
126126
this.initializeVariablesForId(id);
127127

128-
if (
129-
intersection.object === this.parent ||
130-
intersection.object === (this.parent as Partial<View>).mesh
131-
) {
128+
if (this.isRelevantIntersection(intersection)) {
132129
this.hovered[id] = true;
133130
this.selected[id] = controller.userData.selected;
134131
if (intersection.uv) {
@@ -159,6 +156,20 @@ export class UX {
159156
}
160157
}
161158

159+
/**
160+
* Checks if the intersection object belongs to this UX's attached Script.
161+
* Allow overriding this function for more complex objects with multiple
162+
* meshes.
163+
* @param intersection - The raycast intersection to check.
164+
* @returns True if the intersection is relevant to this UX's parent object.
165+
*/
166+
isRelevantIntersection(intersection: THREE.Intersection): boolean {
167+
return (
168+
intersection.object === this.parent ||
169+
intersection.object === (this.parent as Partial<View>).mesh
170+
);
171+
}
172+
162173
/**
163174
* Resets the hover and selection states for all controllers. This is
164175
* typically called at the beginning of each frame.

0 commit comments

Comments
 (0)