@@ -157,7 +157,7 @@
|
|
157
157
|
handler: IPointerEventHandler;
|
158
158
|
};
|
159
159
|
|
160
|
-
if (e.obj === prevGrabbed && e.handler) {
|
160
|
+
if (e && e.obj === prevGrabbed && e.handler) {
|
161
161
|
e.handler.onPointerUp?.call(e.handler, opts);
|
162
162
|
this.pressedByID.delete(key);
|
163
163
|
}
|
@@ -168,8 +168,7 @@
|
|
168
168
|
const controllerRcOpts = new RaycastOptions();
|
169
169
|
this._selectUpdateFn ??= (_ctrl: WebXRController) => {
|
170
170
|
controllerRcOpts.ray = _ctrl.getRay();
|
171
|
-
const rc = this.performRaycast(controllerRcOpts);
|
172
|
-
if (!rc) return;
|
171
|
+
const rc = this.performRaycast(controllerRcOpts) ?? [];
|
173
172
|
const opts = new PointerEventData(this.context.input);
|
174
173
|
opts.inputSource = _ctrl;
|
175
174
|
opts.pointerId = _ctrl.input?.handedness === "right" ? 0 : 1;
|
@@ -177,7 +176,7 @@
|
|
177
176
|
opts.isUp = _ctrl.selectionUp;
|
178
177
|
opts.isPressed = _ctrl.selectionPressed;
|
179
178
|
opts.isClicked = false;
|
180
|
-
this.handleIntersections(rc, opts);
|
179
|
+
this.handleIntersections(opts.pointerId, rc, opts);
|
181
180
|
};
|
182
181
|
|
183
182
|
WebXRController.addEventListener(ControllerEvents.SelectStart, this._selectStartFn);
|
@@ -261,24 +260,8 @@
|
|
261
260
|
this.dispatchEvent(new CustomEvent(EventSystemEvents.BeforeHandleInput, { detail: evt }))
|
262
261
|
|
263
262
|
// handle hit objects
|
264
|
-
|
265
|
-
// pointer has not hit any object to handle
|
263
|
+
this.handleIntersections(id, hits, data)
|
266
264
|
|
267
|
-
// thus is not hovering over anything
|
268
|
-
const hoveredData = this.hoveredByID.get(id);
|
269
|
-
if (hoveredData) {
|
270
|
-
this.triggerOnExit(hoveredData.obj, hoveredData.data);
|
271
|
-
}
|
272
|
-
this.hoveredByID.delete(id);
|
273
|
-
|
274
|
-
// if it was up, it means it doesn't should notify things that it down on before
|
275
|
-
if (data.isUp) {
|
276
|
-
const pressedData = this.pressedByID.get(id);
|
277
|
-
pressedData?.handlers.forEach(h => h.onPointerUp?.call(h, data));
|
278
|
-
this.pressedByID.delete(id);
|
279
|
-
}
|
280
|
-
}
|
281
|
-
|
282
265
|
this.dispatchEvent(new CustomEvent<AfterHandleInputEvent>(EventSystemEvents.AfterHandleInput, { detail: evt }))
|
283
266
|
}
|
284
267
|
|
@@ -363,23 +346,38 @@
|
|
363
346
|
return this._sortedHits;
|
364
347
|
}
|
365
348
|
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
if (this.handleEventOnObject(object, args)) {
|
380
|
-
return true;
|
349
|
+
private handleIntersections(id:number, hits: THREE.Intersection[], args: PointerEventData): boolean {
|
350
|
+
if (hits?.length) {
|
351
|
+
hits = this.sortCandidates(hits);
|
352
|
+
for (const hit of hits) {
|
353
|
+
const { object } = hit;
|
354
|
+
args.point = hit.point;
|
355
|
+
args.normal = hit.normal;
|
356
|
+
args.face = hit.face;
|
357
|
+
args.distance = hit.distance;
|
358
|
+
args.instanceId = hit.instanceId;
|
359
|
+
if (this.handleEventOnObject(object, args)) {
|
360
|
+
return true;
|
361
|
+
}
|
381
362
|
}
|
382
363
|
}
|
364
|
+
|
365
|
+
// pointer has not hit any object to handle
|
366
|
+
|
367
|
+
// thus is not hovering over anything
|
368
|
+
const hoveredData = this.hoveredByID.get(id);
|
369
|
+
if (hoveredData) {
|
370
|
+
this.triggerOnExit(hoveredData.obj, hoveredData.data);
|
371
|
+
}
|
372
|
+
this.hoveredByID.delete(id);
|
373
|
+
|
374
|
+
// if it was up, it means it doesn't should notify things that it down on before
|
375
|
+
if (args.isUp) {
|
376
|
+
const pressedData = this.pressedByID.get(id);
|
377
|
+
pressedData?.handlers.forEach(h => h.onPointerUp?.call(h, args));
|
378
|
+
this.pressedByID.delete(id);
|
379
|
+
}
|
380
|
+
|
383
381
|
return false;
|
384
382
|
}
|