Skip to content

Commit

Permalink
fix(pickfire): fix undefined values (Orillusion#416)
Browse files Browse the repository at this point in the history
1. assign values with input event
2. simplify event.data with {worldPos, screenUv, meshID, worldNormal}
  • Loading branch information
lslzl3000 authored Jul 15, 2024
1 parent c79e287 commit 5548467
Showing 1 changed file with 21 additions and 30 deletions.
51 changes: 21 additions & 30 deletions src/io/PickFire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,10 @@ export class PickFire extends CEventDispatcher {
let target = this.findNearestObj(this._interestList, this._view.camera);
this._lastDownTarget = target;
if (target) {
Object.assign(this._downEvent, e);
this._downEvent.type = PointerEvent3D.PICK_DOWN;
this._downEvent.target = target.object3D;
this._downEvent.ctrlKey = e.ctrlKey;
this._downEvent.metaKey = e.metaKey;
this._downEvent.altKey = e.altKey;
this._downEvent.shiftKey = e.shiftKey;
this._downEvent.data = { pick: target, pickInfo: this.getPickInfo(), mouseCode: this._mouseCode };
this._downEvent.data = this.getPickInfo();
this.dispatchEvent(this._downEvent);

if (target.object3D.containEventListener(PointerEvent3D.PICK_DOWN)) {
Expand All @@ -125,13 +123,12 @@ export class PickFire extends CEventDispatcher {
this.pick(this._view.camera);
let target = this.findNearestObj(this._interestList, this._view.camera);
if (target) {
Object.assign(this._upEvent, e);
this._upEvent.type = PointerEvent3D.PICK_UP;
this._upEvent.target = target.object3D;
this._upEvent.ctrlKey = e.ctrlKey;
this._upEvent.metaKey = e.metaKey;
this._upEvent.altKey = e.altKey;
this._upEvent.shiftKey = e.shiftKey;
this._upEvent.data = { pick: target, pickInfo: this.getPickInfo(), mouseCode: this._mouseCode };
this._upEvent.data = this.getPickInfo();
this.dispatchEvent(this._upEvent);

if (target.object3D.containEventListener(PointerEvent3D.PICK_UP)) {
target.object3D.dispatchEvent(this._upEvent);
}
Expand All @@ -156,38 +153,34 @@ export class PickFire extends CEventDispatcher {
this.pick(this._view.camera);
let target = this.findNearestObj(this._interestList, this._view.camera);
if (target) {
Object.assign(this._mouseMove, e);
this._mouseMove.type = PointerEvent3D.PICK_MOVE;
this._mouseMove.target = target.object3D;
this._mouseMove.ctrlKey = e.ctrlKey;
this._mouseMove.metaKey = e.metaKey;
this._mouseMove.altKey = e.altKey;
this._mouseMove.shiftKey = e.shiftKey;
this._mouseMove.data = { pick: target, pickInfo: this.getPickInfo(), mouseCode: this._mouseCode };
this._mouseMove.data = this.getPickInfo();
this.dispatchEvent(this._mouseMove);

if (target.object3D.containEventListener(PointerEvent3D.PICK_MOVE)) {
target.object3D.dispatchEvent(this._mouseMove);
}
}

if (target != this._lastFocus) {
if (this._lastFocus && this._lastFocus.object3D) {
Object.assign(this._outEvent, e);
this._outEvent.type = PointerEvent3D.PICK_OUT;
this._outEvent.target = this._lastFocus.object3D;
this._outEvent.data = { pick: this._lastFocus, pickInfo: this.getPickInfo(), mouseCode: this._mouseCode };
this._outEvent.ctrlKey = e.ctrlKey;
this._outEvent.metaKey = e.metaKey;
this._outEvent.altKey = e.altKey;
this._outEvent.shiftKey = e.shiftKey;
this._outEvent.data = this.getPickInfo();
this.dispatchEvent(this._outEvent);

if (this._lastFocus.object3D.containEventListener(PointerEvent3D.PICK_OUT)) {
this._lastFocus.object3D.dispatchEvent(this._outEvent);
}
}
if (target) {
Object.assign(this._overEvent, e);
this._overEvent.type = PointerEvent3D.PICK_OVER;
this._overEvent.target = target.object3D;
this._overEvent.ctrlKey = e.ctrlKey;
this._overEvent.metaKey = e.metaKey;
this._overEvent.altKey = e.altKey;
this._overEvent.shiftKey = e.shiftKey;
this._overEvent.data = { pick: target, pickInfo: this.getPickInfo(), mouseCode: this._mouseCode };
this._overEvent.data = this.getPickInfo();
this.dispatchEvent(this._overEvent);
if (target.object3D.containEventListener(PointerEvent3D.PICK_OVER)) {
target.object3D.dispatchEvent(this._overEvent);
Expand All @@ -204,12 +197,10 @@ export class PickFire extends CEventDispatcher {
let target = this.findNearestObj(this._interestList, this._view.camera);
if (target) {
let info = Engine3D.setting.pick.mode == `pixel` ? this.getPickInfo() : null;
Object.assign(this._pickEvent, e);
this._pickEvent.type = PointerEvent3D.PICK_CLICK;
this._pickEvent.target = target.object3D;
this._pickEvent.ctrlKey = e.ctrlKey;
this._pickEvent.metaKey = e.metaKey;
this._pickEvent.altKey = e.altKey;
this._pickEvent.shiftKey = e.shiftKey;
this._pickEvent.data = { pick: target, pickInfo: info, mouseCode: this._mouseCode };
this._pickEvent.data = info;
this.dispatchEvent(this._pickEvent);

if (target === this._lastDownTarget && target.object3D.containEventListener(PointerEvent3D.PICK_CLICK)) {
Expand Down

0 comments on commit 5548467

Please sign in to comment.