lythreeframe 1.2.61 → 1.2.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -125,6 +125,30 @@ exports.AttachmentRules = void 0;
125
125
  AttachmentRules[AttachmentRules["KeepRelative"] = 2] = "KeepRelative";
126
126
  })(exports.AttachmentRules || (exports.AttachmentRules = {}));
127
127
 
128
+ class Delegate {
129
+ constructor() {
130
+ this.functions = [];
131
+ }
132
+ broadcast(...args) {
133
+ this.functions.forEach((func) => func(...args));
134
+ }
135
+ add(func) {
136
+ this.functions.push(func);
137
+ }
138
+ remove(func) {
139
+ const index = this.functions.indexOf(func);
140
+ if (index >= 0) {
141
+ this.functions.splice(index, 1);
142
+ }
143
+ else {
144
+ console.warn("function not found");
145
+ }
146
+ }
147
+ clear() {
148
+ this.functions = [];
149
+ }
150
+ }
151
+
128
152
  class SceneComponent extends Component {
129
153
  set parentActor(value) {
130
154
  this.childrenComponents.forEach((elem) => {
@@ -135,6 +159,11 @@ class SceneComponent extends Component {
135
159
  get parentActor() {
136
160
  return this._parentActor;
137
161
  }
162
+ // Delegate getters
163
+ get onHoverBeginDelegate() { return this._onHoverBeginDelegate; }
164
+ get onHoverEndDelegate() { return this._onHoverEndDelegate; }
165
+ get onClickDelegate() { return this._onClickDelegate; }
166
+ get onDoubleClickDelegate() { return this._onDoubleClickDelegate; }
138
167
  get world() {
139
168
  return this.app.world;
140
169
  }
@@ -142,6 +171,11 @@ class SceneComponent extends Component {
142
171
  super(uuid);
143
172
  this.bCanHover = false;
144
173
  this.bCanClick = false;
174
+ // Component 级别事件 Delegates
175
+ this._onHoverBeginDelegate = new Delegate();
176
+ this._onHoverEndDelegate = new Delegate();
177
+ this._onClickDelegate = new Delegate();
178
+ this._onDoubleClickDelegate = new Delegate();
145
179
  this.app = app;
146
180
  this.name = "SceneComponent";
147
181
  }
@@ -310,12 +344,15 @@ class SceneComponent extends Component {
310
344
  }
311
345
  }
312
346
  setPosition(...args) {
347
+ var _a;
313
348
  if (!this.obj) {
314
349
  throw Error("threeObject is invalid");
315
350
  }
316
351
  let newPosition = null;
317
- if (args.length === 1 && args[0] instanceof webgpu.Vector3) {
318
- newPosition = new webgpu.Vector3().copy(args[0]);
352
+ // 使用 isVector3 属性检查,避免多个 Three.js 实例导致 instanceof 失败
353
+ if (args.length === 1 && ((_a = args[0]) === null || _a === void 0 ? void 0 : _a.isVector3)) {
354
+ const vec = args[0];
355
+ newPosition = new webgpu.Vector3(vec.x, vec.y, vec.z);
319
356
  }
320
357
  else if (args.length === 3 &&
321
358
  typeof args[0] === "number" &&
@@ -353,14 +390,17 @@ class SceneComponent extends Component {
353
390
  }
354
391
  }
355
392
  setRotation(...args) {
393
+ var _a;
356
394
  if (!this.obj) {
357
395
  throw Error("threeObject is invalid");
358
396
  }
359
397
  let newRotation = null;
360
- if (args[0] instanceof webgpu.Euler) {
361
- newRotation = new webgpu.Euler().copy(args[0]);
398
+ // 使用 isEuler 属性检查,避免多个 Three.js 实例导致 instanceof 失败
399
+ if ((_a = args[0]) === null || _a === void 0 ? void 0 : _a.isEuler) {
400
+ const euler = args[0];
401
+ newRotation = new webgpu.Euler(euler.x, euler.y, euler.z, euler.order);
362
402
  }
363
- if (typeof (args[0]) === "number" && typeof (args[1]) === "number" && typeof (args[2]) === "number") {
403
+ else if (typeof (args[0]) === "number" && typeof (args[1]) === "number" && typeof (args[2]) === "number") {
364
404
  newRotation = new webgpu.Euler(args[0], args[1], args[2]);
365
405
  }
366
406
  if (!newRotation) {
@@ -390,14 +430,17 @@ class SceneComponent extends Component {
390
430
  }
391
431
  }
392
432
  setQuaternion(...args) {
433
+ var _a;
393
434
  if (!this.obj) {
394
435
  throw Error("threeObject is invalid");
395
436
  }
396
437
  let newQuat = null;
397
- if (args[0] instanceof webgpu.Quaternion) {
398
- newQuat = new webgpu.Quaternion().copy(args[0]);
438
+ // 使用 isQuaternion 属性检查,避免多个 Three.js 实例导致 instanceof 失败
439
+ if ((_a = args[0]) === null || _a === void 0 ? void 0 : _a.isQuaternion) {
440
+ const q = args[0];
441
+ newQuat = new webgpu.Quaternion(q.x, q.y, q.z, q.w);
399
442
  }
400
- if (typeof args[0] === "number" && typeof args[1] === "number" && typeof args[2] === "number" && typeof args[3] === "number") {
443
+ else if (typeof args[0] === "number" && typeof args[1] === "number" && typeof args[2] === "number" && typeof args[3] === "number") {
401
444
  newQuat = new webgpu.Quaternion(args[0], args[1], args[2], args[3]);
402
445
  }
403
446
  if (!newQuat) {
@@ -435,14 +478,17 @@ class SceneComponent extends Component {
435
478
  }
436
479
  }
437
480
  setScale(...args) {
481
+ var _a;
438
482
  if (!this.obj) {
439
483
  throw Error("threeObject is invalid");
440
484
  }
441
485
  let newScale = null;
442
- if (args[0] instanceof webgpu.Vector3) {
443
- newScale = new webgpu.Vector3().copy(args[0]);
486
+ // 使用 isVector3 属性检查,避免多个 Three.js 实例导致 instanceof 失败
487
+ if ((_a = args[0]) === null || _a === void 0 ? void 0 : _a.isVector3) {
488
+ const vec = args[0];
489
+ newScale = new webgpu.Vector3(vec.x, vec.y, vec.z);
444
490
  }
445
- if (typeof (args[0]) === "number" && typeof (args[1]) === "number" && typeof (args[2]) === "number") {
491
+ else if (typeof (args[0]) === "number" && typeof (args[1]) === "number" && typeof (args[2]) === "number") {
446
492
  newScale = new webgpu.Vector3(args[0], args[1], args[2]);
447
493
  }
448
494
  if (!newScale) {
@@ -698,38 +744,17 @@ class SceneComponent extends Component {
698
744
  return this.bCanClick;
699
745
  }
700
746
  onHorveringBegin() {
701
- if (!this.isHoverEnabled) {
702
- return;
703
- }
704
- if (this.parentActor) {
705
- let comp = this;
706
- this.parentActor.onComponentHorveringBegin(comp);
707
- }
747
+ this._onHoverBeginDelegate.broadcast();
708
748
  }
709
749
  onHorveringEnd() {
710
- if (!this.isHoverEnabled) {
711
- return;
712
- }
713
- if (this.parentActor) {
714
- let comp = this;
715
- this.parentActor.onComponentHorveringEnd(comp);
716
- }
750
+ this._onHoverEndDelegate.broadcast();
717
751
  }
718
752
  /* click */
719
753
  onClicked() {
720
- if (!this.isClickEnabled) {
721
- return;
722
- }
723
- if (this.parentActor) {
724
- let comp = this;
725
- this.parentActor.onComponentClicked(comp);
726
- }
754
+ this._onClickDelegate.broadcast();
727
755
  }
728
756
  onDoubleClicked() {
729
- if (this.parentActor) {
730
- let comp = this;
731
- this.parentActor.onComponentDoubleClicked(comp);
732
- }
757
+ this._onDoubleClickDelegate.broadcast();
733
758
  }
734
759
  }
735
760
 
@@ -1289,30 +1314,6 @@ exports.AssetType = void 0;
1289
1314
  AssetType[AssetType["undefined"] = -1] = "undefined";
1290
1315
  })(exports.AssetType || (exports.AssetType = {}));
1291
1316
 
1292
- class Delegate {
1293
- constructor() {
1294
- this.functions = [];
1295
- }
1296
- broadcast(...args) {
1297
- this.functions.forEach((func) => func(...args));
1298
- }
1299
- add(func) {
1300
- this.functions.push(func);
1301
- }
1302
- remove(func) {
1303
- const index = this.functions.indexOf(func);
1304
- if (index >= 0) {
1305
- this.functions.splice(index, 1);
1306
- }
1307
- else {
1308
- console.warn("function not found");
1309
- }
1310
- }
1311
- clear() {
1312
- this.functions = [];
1313
- }
1314
- }
1315
-
1316
1317
  const DefaultPostProcessParam = {
1317
1318
  steps: []
1318
1319
  };
@@ -2088,7 +2089,8 @@ class Orbital extends Pawn {
2088
2089
  focusTo(targetPos, targetQuat, distance, time, onGoing = null, onFinished = null) {
2089
2090
  this.stopFocusing();
2090
2091
  let finalQuat = null;
2091
- if (targetQuat instanceof webgpu.Euler) {
2092
+ // 使用 isEuler 属性检查,避免多个 Three.js 实例导致 instanceof 失败
2093
+ if (targetQuat === null || targetQuat === void 0 ? void 0 : targetQuat.isEuler) {
2092
2094
  finalQuat = new webgpu.Quaternion().setFromEuler(targetQuat);
2093
2095
  }
2094
2096
  else {
@@ -2178,34 +2180,51 @@ class Controller {
2178
2180
  get world() { return this._app.world; }
2179
2181
  get viewPort() { return this._app.viewport; }
2180
2182
  get app() { return this._app; }
2181
- get onClickNothingDelegate() { return this._onClickNothingDelegate; }
2182
- get onComponentClickDelegate() { return this._onComponentClickDelegate; }
2183
- get onComponentDoubleClickDelegate() { return this._onComponentDoubleClickDelegate; }
2184
- get onComponentHoverBeginDelegate() { return this._onComponentHoverBeginDelegate; }
2185
- get onComponentHoverEndDelegate() { return this._onComponentHoverEndDelegate; }
2186
- get onComponentPointerDownDelegate() { return this._onComponentPointerDownDelegate; }
2187
2183
  get pawn() {
2188
2184
  if (!this._pawn)
2189
2185
  throw Error("pawn is null");
2190
2186
  return this._pawn;
2191
2187
  }
2188
+ // Component level delegate getters
2189
+ get onComponentClickDelegate() { return this._onComponentClickDelegate; }
2190
+ get onComponentDoubleClickDelegate() { return this._onComponentDoubleClickDelegate; }
2191
+ get onComponentHoverBeginDelegate() { return this._onComponentHoverBeginDelegate; }
2192
+ get onComponentHoverEndDelegate() { return this._onComponentHoverEndDelegate; }
2193
+ get onComponentPointerDownDelegate() { return this._onComponentPointerDownDelegate; }
2194
+ // Actor level delegate getters
2195
+ get onActorClickDelegate() { return this._onActorClickDelegate; }
2196
+ get onActorDoubleClickDelegate() { return this._onActorDoubleClickDelegate; }
2197
+ get onActorHoverBeginDelegate() { return this._onActorHoverBeginDelegate; }
2198
+ get onActorHoverEndDelegate() { return this._onActorHoverEndDelegate; }
2199
+ get onClickNothingDelegate() { return this._onClickNothingDelegate; }
2192
2200
  constructor(app) {
2193
2201
  this._pawn = null;
2202
+ // Component level state
2203
+ this.hoveringComponent = null;
2204
+ // Actor level state
2205
+ this.hoveringActor = null;
2206
+ // Click state
2194
2207
  this.prepareClickComponent = null;
2195
2208
  this.prepareClickHit = null;
2196
2209
  this.prepareClickModifiers = { ctrlKey: false, shiftKey: false, altKey: false };
2197
- this.hoveringComponent = null;
2198
2210
  this._pointButtonIsDown = new Set();
2199
- this._onClickNothingDelegate = new Delegate();
2211
+ // Component level delegates
2200
2212
  this._onComponentClickDelegate = new Delegate();
2201
2213
  this._onComponentDoubleClickDelegate = new Delegate();
2202
2214
  this._onComponentHoverBeginDelegate = new Delegate();
2203
2215
  this._onComponentHoverEndDelegate = new Delegate();
2204
2216
  this._onComponentPointerDownDelegate = new Delegate();
2217
+ // Actor level delegates
2218
+ this._onActorClickDelegate = new Delegate();
2219
+ this._onActorDoubleClickDelegate = new Delegate();
2220
+ this._onActorHoverBeginDelegate = new Delegate();
2221
+ this._onActorHoverEndDelegate = new Delegate();
2222
+ // Other delegates
2223
+ this._onClickNothingDelegate = new Delegate();
2205
2224
  // Pointer state
2206
2225
  this.pointerPosition = new webgpu.Vector2();
2207
2226
  this.pointerLeftDownPosition = new webgpu.Vector2();
2208
- // Reusable objects to avoid GC pressure
2227
+ // Reusable objects
2209
2228
  this._tempVec2 = new webgpu.Vector2();
2210
2229
  this._raycastVec2 = new webgpu.Vector2();
2211
2230
  // Double click detection
@@ -2244,7 +2263,7 @@ class Controller {
2244
2263
  }
2245
2264
  destroy() {
2246
2265
  this.clearClickTimer();
2247
- this.clearHoveringComponent();
2266
+ this.clearHovering();
2248
2267
  const canvas = this.viewPort.canvas;
2249
2268
  if (canvas) {
2250
2269
  canvas.removeEventListener("pointerenter", this.onPointerEnter);
@@ -2255,7 +2274,9 @@ class Controller {
2255
2274
  this.pawn.destroy();
2256
2275
  this._pawn = null;
2257
2276
  }
2277
+ // ==================== Pointer Events ====================
2258
2278
  onPointerMoveEvent(event) {
2279
+ var _a, _b;
2259
2280
  const canvas = this.viewPort.canvas;
2260
2281
  if (!canvas)
2261
2282
  throw Error("canvas is null");
@@ -2264,47 +2285,48 @@ class Controller {
2264
2285
  if (this._pointButtonIsDown.size > 0)
2265
2286
  return;
2266
2287
  const hits = this.getHitResultUnderCursor();
2267
- const component = hits === null || hits === void 0 ? void 0 : hits.component;
2288
+ const component = (_a = hits === null || hits === void 0 ? void 0 : hits.component) !== null && _a !== void 0 ? _a : null;
2289
+ const actor = (_b = component === null || component === void 0 ? void 0 : component.parentActor) !== null && _b !== void 0 ? _b : null;
2290
+ // Component 级别 hover 检测
2268
2291
  if (component !== this.hoveringComponent) {
2269
- this.clearHoveringComponent();
2270
- if (component instanceof SceneComponent && component.isHoverEnabled && hits) {
2271
- this.fireHoverEvent(component, hits.hit, true);
2292
+ if (this.hoveringComponent) {
2293
+ this.fireComponentHoverEnd(this.hoveringComponent);
2294
+ }
2295
+ if (component && component.isHoverEnabled && hits) {
2296
+ this.fireComponentHoverBegin(component, hits.hit);
2272
2297
  }
2273
2298
  }
2274
- }
2275
- clearHoveringComponent() {
2276
- if (this.hoveringComponent) {
2277
- this.fireHoverEvent(this.hoveringComponent, null, false);
2299
+ // Actor 级别 hover 检测(独立于 Component)
2300
+ if (actor !== this.hoveringActor) {
2301
+ if (this.hoveringActor && this.hoveringComponent) {
2302
+ this.fireActorHoverEnd(this.hoveringActor, this.hoveringComponent);
2303
+ }
2304
+ if (actor && component && actor.isHoverEnabled && hits) {
2305
+ this.fireActorHoverBegin(actor, component, hits.hit);
2306
+ }
2278
2307
  }
2308
+ this.hoveringComponent = component;
2309
+ this.hoveringActor = actor;
2279
2310
  }
2280
- fireHoverEvent(component, hit, isBegin) {
2281
- const event = { component, hit, handled: false };
2282
- if (isBegin) {
2283
- this._onComponentHoverBeginDelegate.broadcast(event);
2284
- if (!event.handled) {
2285
- component.onHorveringBegin();
2286
- }
2287
- this.hoveringComponent = component;
2311
+ clearHovering() {
2312
+ if (this.hoveringComponent) {
2313
+ this.fireComponentHoverEnd(this.hoveringComponent);
2288
2314
  }
2289
- else {
2290
- this._onComponentHoverEndDelegate.broadcast(event);
2291
- if (!event.handled) {
2292
- component.onHorveringEnd();
2293
- }
2294
- this.hoveringComponent = null;
2315
+ if (this.hoveringActor && this.hoveringComponent) {
2316
+ this.fireActorHoverEnd(this.hoveringActor, this.hoveringComponent);
2295
2317
  }
2318
+ this.hoveringComponent = null;
2319
+ this.hoveringActor = null;
2296
2320
  }
2297
2321
  onPointerUpEvent(event) {
2298
2322
  this._pointButtonIsDown.delete(event.button);
2299
2323
  if (event.button !== 0)
2300
2324
  return;
2301
- // Check if pointer moved too much (drag instead of click)
2302
2325
  const pointerOffset = this._tempVec2.subVectors(this.pointerLeftDownPosition, this.pointerPosition).length();
2303
2326
  if (pointerOffset > 0.005) {
2304
2327
  this.clearClickTimer();
2305
2328
  return;
2306
2329
  }
2307
- // 保存修饰键状态
2308
2330
  this.prepareClickModifiers = {
2309
2331
  ctrlKey: event.ctrlKey,
2310
2332
  shiftKey: event.shiftKey,
@@ -2326,7 +2348,7 @@ class Controller {
2326
2348
  this.leftClickTimer = window.setTimeout(() => {
2327
2349
  this.leftClickTimer = null;
2328
2350
  if (this.prepareClickComponent && this.prepareClickHit) {
2329
- this.fireClickEvent(this.prepareClickComponent, this.prepareClickHit, false, this.prepareClickModifiers);
2351
+ this.fireClickEvents(this.prepareClickComponent, this.prepareClickHit, false);
2330
2352
  this.prepareClickComponent = null;
2331
2353
  this.prepareClickHit = null;
2332
2354
  }
@@ -2339,7 +2361,7 @@ class Controller {
2339
2361
  handleDoubleClick() {
2340
2362
  this.clearClickTimer();
2341
2363
  if (this.prepareClickComponent && this.prepareClickHit) {
2342
- this.fireClickEvent(this.prepareClickComponent, this.prepareClickHit, true, this.prepareClickModifiers);
2364
+ this.fireClickEvents(this.prepareClickComponent, this.prepareClickHit, true);
2343
2365
  }
2344
2366
  else {
2345
2367
  this._onClickNothingDelegate.broadcast();
@@ -2347,8 +2369,40 @@ class Controller {
2347
2369
  this.prepareClickComponent = null;
2348
2370
  this.prepareClickHit = null;
2349
2371
  }
2350
- fireClickEvent(component, hit, isDoubleClick, modifiers) {
2351
- const event = Object.assign({ component, hit, handled: false }, modifiers);
2372
+ onPointerDownEvent(event) {
2373
+ this._pointButtonIsDown.add(event.button);
2374
+ if (event.button === 0) {
2375
+ this.pointerLeftDownPosition.copy(this.pointerPosition);
2376
+ }
2377
+ const hit = this.getHitResultUnderCursor();
2378
+ const component = hit === null || hit === void 0 ? void 0 : hit.component;
2379
+ if (component instanceof SceneComponent && hit) {
2380
+ this.firePointerDownEvent(component, hit.hit, event.button);
2381
+ }
2382
+ }
2383
+ onPointerEnterEvent(_event) {
2384
+ this.addCorePointerListeners();
2385
+ }
2386
+ onPointerLeaveEvent(_event) {
2387
+ this.removeCorePointerListeners();
2388
+ }
2389
+ // ==================== Component Level Events ====================
2390
+ fireComponentHoverBegin(component, hit) {
2391
+ const event = { component, hit, handled: false };
2392
+ this._onComponentHoverBeginDelegate.broadcast(event);
2393
+ if (!event.handled) {
2394
+ component.onHorveringBegin();
2395
+ }
2396
+ }
2397
+ fireComponentHoverEnd(component) {
2398
+ const event = { component, hit: null, handled: false };
2399
+ this._onComponentHoverEndDelegate.broadcast(event);
2400
+ if (!event.handled) {
2401
+ component.onHorveringEnd();
2402
+ }
2403
+ }
2404
+ fireComponentClick(component, hit, isDoubleClick) {
2405
+ const event = Object.assign({ component, hit, handled: false }, this.prepareClickModifiers);
2352
2406
  if (isDoubleClick) {
2353
2407
  this._onComponentDoubleClickDelegate.broadcast(event);
2354
2408
  if (!event.handled) {
@@ -2362,33 +2416,56 @@ class Controller {
2362
2416
  }
2363
2417
  }
2364
2418
  }
2365
- clearClickTimer() {
2366
- if (this.leftClickTimer) {
2367
- window.clearTimeout(this.leftClickTimer);
2368
- this.leftClickTimer = null;
2369
- }
2419
+ firePointerDownEvent(component, hit, button) {
2420
+ const event = { component, hit, button, handled: false };
2421
+ this._onComponentPointerDownDelegate.broadcast(event);
2370
2422
  }
2371
- onPointerDownEvent(event) {
2372
- this._pointButtonIsDown.add(event.button);
2373
- if (event.button === 0) {
2374
- this.pointerLeftDownPosition.copy(this.pointerPosition);
2423
+ // ==================== Actor Level Events ====================
2424
+ fireActorHoverBegin(actor, component, hit) {
2425
+ const event = { actor, component, hit, handled: false };
2426
+ this._onActorHoverBeginDelegate.broadcast(event);
2427
+ if (!event.handled) {
2428
+ actor.onActorHoverBegin(component);
2375
2429
  }
2376
- // 广播组件按下事件
2377
- const hit = this.getHitResultUnderCursor();
2378
- const component = hit === null || hit === void 0 ? void 0 : hit.component;
2379
- if (component instanceof SceneComponent && hit) {
2380
- this.firePointerDownEvent(component, hit.hit, event.button);
2430
+ }
2431
+ fireActorHoverEnd(actor, component) {
2432
+ const event = { actor, component, hit: null, handled: false };
2433
+ this._onActorHoverEndDelegate.broadcast(event);
2434
+ if (!event.handled) {
2435
+ actor.onActorHoverEnd(component);
2381
2436
  }
2382
2437
  }
2383
- firePointerDownEvent(component, hit, button) {
2384
- const event = { component, hit, button, handled: false };
2385
- this._onComponentPointerDownDelegate.broadcast(event);
2438
+ fireActorClick(actor, component, hit, isDoubleClick) {
2439
+ const event = Object.assign({ actor, component, hit, handled: false }, this.prepareClickModifiers);
2440
+ if (isDoubleClick) {
2441
+ this._onActorDoubleClickDelegate.broadcast(event);
2442
+ if (!event.handled) {
2443
+ actor.onActorDoubleClick(component);
2444
+ }
2445
+ }
2446
+ else {
2447
+ this._onActorClickDelegate.broadcast(event);
2448
+ if (!event.handled) {
2449
+ actor.onActorClick(component);
2450
+ }
2451
+ }
2386
2452
  }
2387
- onPointerEnterEvent(_event) {
2388
- this.addCorePointerListeners();
2453
+ // ==================== Combined Events ====================
2454
+ fireClickEvents(component, hit, isDoubleClick) {
2455
+ // Component level
2456
+ this.fireComponentClick(component, hit, isDoubleClick);
2457
+ // Actor level
2458
+ const actor = component.parentActor;
2459
+ if (actor && actor.isClickEnabled) {
2460
+ this.fireActorClick(actor, component, hit, isDoubleClick);
2461
+ }
2389
2462
  }
2390
- onPointerLeaveEvent(_event) {
2391
- this.removeCorePointerListeners();
2463
+ // ==================== Utility ====================
2464
+ clearClickTimer() {
2465
+ if (this.leftClickTimer) {
2466
+ window.clearTimeout(this.leftClickTimer);
2467
+ this.leftClickTimer = null;
2468
+ }
2392
2469
  }
2393
2470
  addCorePointerListeners() {
2394
2471
  const canvas = this.viewPort.canvas;
@@ -2424,17 +2501,14 @@ class Controller {
2424
2501
  this._raycastVec2.set(x, y);
2425
2502
  this.raycaster.setFromCamera(this._raycastVec2, this.camera);
2426
2503
  const hits = this.raycaster.intersectObjects(this.world.scene.children, true);
2427
- let out = [];
2504
+ const out = [];
2428
2505
  for (const hit of hits) {
2429
2506
  if (hit.object.userData["rayIgnored"])
2430
2507
  continue;
2431
2508
  const component = hit.object.userData["LYObject"];
2432
2509
  if (!component)
2433
2510
  continue;
2434
- out.push({
2435
- component: component,
2436
- hit: hit
2437
- });
2511
+ out.push({ component, hit });
2438
2512
  }
2439
2513
  return out;
2440
2514
  }
@@ -2627,15 +2701,21 @@ class Actor extends BaseObject {
2627
2701
  this.app.world.removeTickableActor(this);
2628
2702
  }
2629
2703
  }
2704
+ // Delegate getters
2705
+ get onHoverBeginDelegate() { return this._onHoverBeginDelegate; }
2706
+ get onHoverEndDelegate() { return this._onHoverEndDelegate; }
2707
+ get onClickDelegate() { return this._onClickDelegate; }
2708
+ get onDoubleClickDelegate() { return this._onDoubleClickDelegate; }
2630
2709
  constructor(app, uuid) {
2631
2710
  super(uuid);
2632
2711
  this._name = "Actor";
2633
2712
  this._rootComponent = null;
2634
2713
  this._world = null;
2635
- this.onClickedEvent = [];
2636
- this.onDoubleClickedEvent = [];
2637
- this.onHoverBeginEvent = [];
2638
- this.onHoverEndEvent = [];
2714
+ // Actor 级别事件 Delegates
2715
+ this._onHoverBeginDelegate = new Delegate();
2716
+ this._onHoverEndDelegate = new Delegate();
2717
+ this._onClickDelegate = new Delegate();
2718
+ this._onDoubleClickDelegate = new Delegate();
2639
2719
  this.app = app;
2640
2720
  this.rootComponent = this.constructRootComponent();
2641
2721
  this.rootComponent.parentActor = this;
@@ -2890,80 +2970,18 @@ class Actor extends BaseObject {
2890
2970
  set isClickEnabled(bCanHorver) {
2891
2971
  this.rootComponent.isClickEnabled = bCanHorver;
2892
2972
  }
2893
- // hovering begin
2894
- addHoveringBeginEvent(newFunc) {
2895
- this.onHoverBeginEvent.push(newFunc);
2973
+ // ==================== Actor Events ====================
2974
+ onActorHoverBegin(component) {
2975
+ this._onHoverBeginDelegate.broadcast(component);
2896
2976
  }
2897
- removeHoveringBeginEvent(target) {
2898
- let index = this.onHoverBeginEvent.indexOf(target);
2899
- if (index >= 0) {
2900
- this.onHoverBeginEvent.splice(index, 1);
2901
- }
2977
+ onActorHoverEnd(component) {
2978
+ this._onHoverEndDelegate.broadcast(component);
2902
2979
  }
2903
- clearHoveringBeginEvent() {
2904
- this.onHoverBeginEvent = [];
2905
- }
2906
- onComponentHorveringBegin(component) {
2907
- for (let i = 0; i < this.onHoverBeginEvent.length; ++i) {
2908
- this.onHoverBeginEvent[i](component);
2909
- }
2910
- }
2911
- // hovering end
2912
- addHoveringEndEvent(newFunc) {
2913
- this.onHoverEndEvent.push(newFunc);
2914
- }
2915
- removeHoveringEndEvent(target) {
2916
- let index = this.onHoverEndEvent.indexOf(target);
2917
- if (index >= 0) {
2918
- this.onHoverEndEvent.splice(index, 1);
2919
- }
2920
- }
2921
- clearHoveringEndEvent() {
2922
- this.onHoverEndEvent = [];
2923
- }
2924
- onComponentHorveringEnd(component) {
2925
- // console.log("onComponentHorveringEnd", this)
2926
- for (let i = 0; i < this.onHoverEndEvent.length; ++i) {
2927
- this.onHoverEndEvent[i](component);
2928
- }
2929
- }
2930
- //click
2931
- addClickEvent(newFunc) {
2932
- this.onClickedEvent.push(newFunc);
2933
- }
2934
- removeClickEvent(target) {
2935
- let index = this.onClickedEvent.indexOf(target);
2936
- if (index >= 0) {
2937
- this.onClickedEvent.splice(index, 1);
2938
- }
2939
- }
2940
- clearClickEvent() {
2941
- this.onClickedEvent = [];
2942
- }
2943
- onComponentClicked(component) {
2944
- //console.log("onComponentClicked", this.Name, component)
2945
- for (let i = 0; i < this.onClickedEvent.length; ++i) {
2946
- this.onClickedEvent[i](component);
2947
- }
2948
- }
2949
- // double click
2950
- addDoubleClickEvent(newFunc) {
2951
- this.onDoubleClickedEvent.push(newFunc);
2952
- }
2953
- removeDoubleClickEvent(target) {
2954
- let index = this.onClickedEvent.indexOf(target);
2955
- if (index >= 0) {
2956
- this.onDoubleClickedEvent.splice(index, 1);
2957
- }
2958
- }
2959
- onComponentDoubleClicked(component) {
2960
- //console.log("onComponentClicked", this.Name, component)
2961
- for (let i = 0; i < this.onDoubleClickedEvent.length; ++i) {
2962
- this.onDoubleClickedEvent[i](component);
2963
- }
2980
+ onActorClick(component) {
2981
+ this._onClickDelegate.broadcast(component);
2964
2982
  }
2965
- clearDoubleClickEvent() {
2966
- this.onDoubleClickedEvent = [];
2983
+ onActorDoubleClick(component) {
2984
+ this._onDoubleClickDelegate.broadcast(component);
2967
2985
  }
2968
2986
  }
2969
2987