lythreeframe 1.2.60 → 1.2.62

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.
@@ -310,12 +310,15 @@ class SceneComponent extends Component {
310
310
  }
311
311
  }
312
312
  setPosition(...args) {
313
+ var _a;
313
314
  if (!this.obj) {
314
315
  throw Error("threeObject is invalid");
315
316
  }
316
317
  let newPosition = null;
317
- if (args.length === 1 && args[0] instanceof webgpu.Vector3) {
318
- newPosition = new webgpu.Vector3().copy(args[0]);
318
+ // 使用 isVector3 属性检查,避免多个 Three.js 实例导致 instanceof 失败
319
+ if (args.length === 1 && ((_a = args[0]) === null || _a === void 0 ? void 0 : _a.isVector3)) {
320
+ const vec = args[0];
321
+ newPosition = new webgpu.Vector3(vec.x, vec.y, vec.z);
319
322
  }
320
323
  else if (args.length === 3 &&
321
324
  typeof args[0] === "number" &&
@@ -353,14 +356,17 @@ class SceneComponent extends Component {
353
356
  }
354
357
  }
355
358
  setRotation(...args) {
359
+ var _a;
356
360
  if (!this.obj) {
357
361
  throw Error("threeObject is invalid");
358
362
  }
359
363
  let newRotation = null;
360
- if (args[0] instanceof webgpu.Euler) {
361
- newRotation = new webgpu.Euler().copy(args[0]);
364
+ // 使用 isEuler 属性检查,避免多个 Three.js 实例导致 instanceof 失败
365
+ if ((_a = args[0]) === null || _a === void 0 ? void 0 : _a.isEuler) {
366
+ const euler = args[0];
367
+ newRotation = new webgpu.Euler(euler.x, euler.y, euler.z, euler.order);
362
368
  }
363
- if (typeof (args[0]) === "number" && typeof (args[1]) === "number" && typeof (args[2]) === "number") {
369
+ else if (typeof (args[0]) === "number" && typeof (args[1]) === "number" && typeof (args[2]) === "number") {
364
370
  newRotation = new webgpu.Euler(args[0], args[1], args[2]);
365
371
  }
366
372
  if (!newRotation) {
@@ -390,14 +396,17 @@ class SceneComponent extends Component {
390
396
  }
391
397
  }
392
398
  setQuaternion(...args) {
399
+ var _a;
393
400
  if (!this.obj) {
394
401
  throw Error("threeObject is invalid");
395
402
  }
396
403
  let newQuat = null;
397
- if (args[0] instanceof webgpu.Quaternion) {
398
- newQuat = new webgpu.Quaternion().copy(args[0]);
404
+ // 使用 isQuaternion 属性检查,避免多个 Three.js 实例导致 instanceof 失败
405
+ if ((_a = args[0]) === null || _a === void 0 ? void 0 : _a.isQuaternion) {
406
+ const q = args[0];
407
+ newQuat = new webgpu.Quaternion(q.x, q.y, q.z, q.w);
399
408
  }
400
- if (typeof args[0] === "number" && typeof args[1] === "number" && typeof args[2] === "number" && typeof args[3] === "number") {
409
+ else if (typeof args[0] === "number" && typeof args[1] === "number" && typeof args[2] === "number" && typeof args[3] === "number") {
401
410
  newQuat = new webgpu.Quaternion(args[0], args[1], args[2], args[3]);
402
411
  }
403
412
  if (!newQuat) {
@@ -435,14 +444,17 @@ class SceneComponent extends Component {
435
444
  }
436
445
  }
437
446
  setScale(...args) {
447
+ var _a;
438
448
  if (!this.obj) {
439
449
  throw Error("threeObject is invalid");
440
450
  }
441
451
  let newScale = null;
442
- if (args[0] instanceof webgpu.Vector3) {
443
- newScale = new webgpu.Vector3().copy(args[0]);
452
+ // 使用 isVector3 属性检查,避免多个 Three.js 实例导致 instanceof 失败
453
+ if ((_a = args[0]) === null || _a === void 0 ? void 0 : _a.isVector3) {
454
+ const vec = args[0];
455
+ newScale = new webgpu.Vector3(vec.x, vec.y, vec.z);
444
456
  }
445
- if (typeof (args[0]) === "number" && typeof (args[1]) === "number" && typeof (args[2]) === "number") {
457
+ else if (typeof (args[0]) === "number" && typeof (args[1]) === "number" && typeof (args[2]) === "number") {
446
458
  newScale = new webgpu.Vector3(args[0], args[1], args[2]);
447
459
  }
448
460
  if (!newScale) {
@@ -2088,7 +2100,8 @@ class Orbital extends Pawn {
2088
2100
  focusTo(targetPos, targetQuat, distance, time, onGoing = null, onFinished = null) {
2089
2101
  this.stopFocusing();
2090
2102
  let finalQuat = null;
2091
- if (targetQuat instanceof webgpu.Euler) {
2103
+ // 使用 isEuler 属性检查,避免多个 Three.js 实例导致 instanceof 失败
2104
+ if (targetQuat === null || targetQuat === void 0 ? void 0 : targetQuat.isEuler) {
2092
2105
  finalQuat = new webgpu.Quaternion().setFromEuler(targetQuat);
2093
2106
  }
2094
2107
  else {
@@ -2264,11 +2277,11 @@ class Controller {
2264
2277
  if (this._pointButtonIsDown.size > 0)
2265
2278
  return;
2266
2279
  const hits = this.getHitResultUnderCursor();
2267
- const component = hits === null || hits === void 0 ? void 0 : hits.object.userData["LYObject"];
2280
+ const component = hits === null || hits === void 0 ? void 0 : hits.component;
2268
2281
  if (component !== this.hoveringComponent) {
2269
2282
  this.clearHoveringComponent();
2270
2283
  if (component instanceof SceneComponent && component.isHoverEnabled && hits) {
2271
- this.fireHoverEvent(component, hits, true);
2284
+ this.fireHoverEvent(component, hits.hit, true);
2272
2285
  }
2273
2286
  }
2274
2287
  }
@@ -2319,10 +2332,10 @@ class Controller {
2319
2332
  }
2320
2333
  handleFirstClick() {
2321
2334
  const hit = this.getHitResultUnderCursor();
2322
- const component = hit === null || hit === void 0 ? void 0 : hit.object.userData["LYObject"];
2335
+ const component = hit === null || hit === void 0 ? void 0 : hit.component;
2323
2336
  if (component instanceof SceneComponent && component.isClickEnabled && hit) {
2324
2337
  this.prepareClickComponent = component;
2325
- this.prepareClickHit = hit;
2338
+ this.prepareClickHit = hit.hit;
2326
2339
  this.leftClickTimer = window.setTimeout(() => {
2327
2340
  this.leftClickTimer = null;
2328
2341
  if (this.prepareClickComponent && this.prepareClickHit) {
@@ -2375,9 +2388,9 @@ class Controller {
2375
2388
  }
2376
2389
  // 广播组件按下事件
2377
2390
  const hit = this.getHitResultUnderCursor();
2378
- const component = hit === null || hit === void 0 ? void 0 : hit.object.userData["LYObject"];
2391
+ const component = hit === null || hit === void 0 ? void 0 : hit.component;
2379
2392
  if (component instanceof SceneComponent && hit) {
2380
- this.firePointerDownEvent(component, hit, event.button);
2393
+ this.firePointerDownEvent(component, hit.hit, event.button);
2381
2394
  }
2382
2395
  }
2383
2396
  firePointerDownEvent(component, hit, button) {
@@ -2414,12 +2427,7 @@ class Controller {
2414
2427
  this.raycaster.setFromCamera(this._raycastVec2, this.camera);
2415
2428
  const out = this.getAllHitResultFromScreenPoint(x, y);
2416
2429
  for (const hit of out) {
2417
- if (hit.object.userData["rayIgnored"])
2418
- continue;
2419
- const component = hit.object.userData["LYObject"];
2420
- if (!component)
2421
- continue;
2422
- if (!component.isHoverEnabled && !component.isClickEnabled)
2430
+ if (!hit.component.isHoverEnabled && !hit.component.isClickEnabled)
2423
2431
  continue;
2424
2432
  return hit;
2425
2433
  }
@@ -2428,7 +2436,20 @@ class Controller {
2428
2436
  getAllHitResultFromScreenPoint(x, y) {
2429
2437
  this._raycastVec2.set(x, y);
2430
2438
  this.raycaster.setFromCamera(this._raycastVec2, this.camera);
2431
- return this.raycaster.intersectObjects(this.world.scene.children, true);
2439
+ const hits = this.raycaster.intersectObjects(this.world.scene.children, true);
2440
+ let out = [];
2441
+ for (const hit of hits) {
2442
+ if (hit.object.userData["rayIgnored"])
2443
+ continue;
2444
+ const component = hit.object.userData["LYObject"];
2445
+ if (!component)
2446
+ continue;
2447
+ out.push({
2448
+ component: component,
2449
+ hit: hit
2450
+ });
2451
+ }
2452
+ return out;
2432
2453
  }
2433
2454
  focusTo(targetPos, targetQuat, distance, time, onGoing = null, onFinished = null) {
2434
2455
  this.pawn.focusTo(targetPos, targetQuat, distance, time, onGoing, onFinished);
@@ -308,12 +308,15 @@ class SceneComponent extends Component {
308
308
  }
309
309
  }
310
310
  setPosition(...args) {
311
+ var _a;
311
312
  if (!this.obj) {
312
313
  throw Error("threeObject is invalid");
313
314
  }
314
315
  let newPosition = null;
315
- if (args.length === 1 && args[0] instanceof Vector3) {
316
- newPosition = new Vector3().copy(args[0]);
316
+ // 使用 isVector3 属性检查,避免多个 Three.js 实例导致 instanceof 失败
317
+ if (args.length === 1 && ((_a = args[0]) === null || _a === void 0 ? void 0 : _a.isVector3)) {
318
+ const vec = args[0];
319
+ newPosition = new Vector3(vec.x, vec.y, vec.z);
317
320
  }
318
321
  else if (args.length === 3 &&
319
322
  typeof args[0] === "number" &&
@@ -351,14 +354,17 @@ class SceneComponent extends Component {
351
354
  }
352
355
  }
353
356
  setRotation(...args) {
357
+ var _a;
354
358
  if (!this.obj) {
355
359
  throw Error("threeObject is invalid");
356
360
  }
357
361
  let newRotation = null;
358
- if (args[0] instanceof Euler) {
359
- newRotation = new Euler().copy(args[0]);
362
+ // 使用 isEuler 属性检查,避免多个 Three.js 实例导致 instanceof 失败
363
+ if ((_a = args[0]) === null || _a === void 0 ? void 0 : _a.isEuler) {
364
+ const euler = args[0];
365
+ newRotation = new Euler(euler.x, euler.y, euler.z, euler.order);
360
366
  }
361
- if (typeof (args[0]) === "number" && typeof (args[1]) === "number" && typeof (args[2]) === "number") {
367
+ else if (typeof (args[0]) === "number" && typeof (args[1]) === "number" && typeof (args[2]) === "number") {
362
368
  newRotation = new Euler(args[0], args[1], args[2]);
363
369
  }
364
370
  if (!newRotation) {
@@ -388,14 +394,17 @@ class SceneComponent extends Component {
388
394
  }
389
395
  }
390
396
  setQuaternion(...args) {
397
+ var _a;
391
398
  if (!this.obj) {
392
399
  throw Error("threeObject is invalid");
393
400
  }
394
401
  let newQuat = null;
395
- if (args[0] instanceof Quaternion) {
396
- newQuat = new Quaternion().copy(args[0]);
402
+ // 使用 isQuaternion 属性检查,避免多个 Three.js 实例导致 instanceof 失败
403
+ if ((_a = args[0]) === null || _a === void 0 ? void 0 : _a.isQuaternion) {
404
+ const q = args[0];
405
+ newQuat = new Quaternion(q.x, q.y, q.z, q.w);
397
406
  }
398
- if (typeof args[0] === "number" && typeof args[1] === "number" && typeof args[2] === "number" && typeof args[3] === "number") {
407
+ else if (typeof args[0] === "number" && typeof args[1] === "number" && typeof args[2] === "number" && typeof args[3] === "number") {
399
408
  newQuat = new Quaternion(args[0], args[1], args[2], args[3]);
400
409
  }
401
410
  if (!newQuat) {
@@ -433,14 +442,17 @@ class SceneComponent extends Component {
433
442
  }
434
443
  }
435
444
  setScale(...args) {
445
+ var _a;
436
446
  if (!this.obj) {
437
447
  throw Error("threeObject is invalid");
438
448
  }
439
449
  let newScale = null;
440
- if (args[0] instanceof Vector3) {
441
- newScale = new Vector3().copy(args[0]);
450
+ // 使用 isVector3 属性检查,避免多个 Three.js 实例导致 instanceof 失败
451
+ if ((_a = args[0]) === null || _a === void 0 ? void 0 : _a.isVector3) {
452
+ const vec = args[0];
453
+ newScale = new Vector3(vec.x, vec.y, vec.z);
442
454
  }
443
- if (typeof (args[0]) === "number" && typeof (args[1]) === "number" && typeof (args[2]) === "number") {
455
+ else if (typeof (args[0]) === "number" && typeof (args[1]) === "number" && typeof (args[2]) === "number") {
444
456
  newScale = new Vector3(args[0], args[1], args[2]);
445
457
  }
446
458
  if (!newScale) {
@@ -2086,7 +2098,8 @@ class Orbital extends Pawn {
2086
2098
  focusTo(targetPos, targetQuat, distance, time, onGoing = null, onFinished = null) {
2087
2099
  this.stopFocusing();
2088
2100
  let finalQuat = null;
2089
- if (targetQuat instanceof Euler) {
2101
+ // 使用 isEuler 属性检查,避免多个 Three.js 实例导致 instanceof 失败
2102
+ if (targetQuat === null || targetQuat === void 0 ? void 0 : targetQuat.isEuler) {
2090
2103
  finalQuat = new Quaternion().setFromEuler(targetQuat);
2091
2104
  }
2092
2105
  else {
@@ -2262,11 +2275,11 @@ class Controller {
2262
2275
  if (this._pointButtonIsDown.size > 0)
2263
2276
  return;
2264
2277
  const hits = this.getHitResultUnderCursor();
2265
- const component = hits === null || hits === void 0 ? void 0 : hits.object.userData["LYObject"];
2278
+ const component = hits === null || hits === void 0 ? void 0 : hits.component;
2266
2279
  if (component !== this.hoveringComponent) {
2267
2280
  this.clearHoveringComponent();
2268
2281
  if (component instanceof SceneComponent && component.isHoverEnabled && hits) {
2269
- this.fireHoverEvent(component, hits, true);
2282
+ this.fireHoverEvent(component, hits.hit, true);
2270
2283
  }
2271
2284
  }
2272
2285
  }
@@ -2317,10 +2330,10 @@ class Controller {
2317
2330
  }
2318
2331
  handleFirstClick() {
2319
2332
  const hit = this.getHitResultUnderCursor();
2320
- const component = hit === null || hit === void 0 ? void 0 : hit.object.userData["LYObject"];
2333
+ const component = hit === null || hit === void 0 ? void 0 : hit.component;
2321
2334
  if (component instanceof SceneComponent && component.isClickEnabled && hit) {
2322
2335
  this.prepareClickComponent = component;
2323
- this.prepareClickHit = hit;
2336
+ this.prepareClickHit = hit.hit;
2324
2337
  this.leftClickTimer = window.setTimeout(() => {
2325
2338
  this.leftClickTimer = null;
2326
2339
  if (this.prepareClickComponent && this.prepareClickHit) {
@@ -2373,9 +2386,9 @@ class Controller {
2373
2386
  }
2374
2387
  // 广播组件按下事件
2375
2388
  const hit = this.getHitResultUnderCursor();
2376
- const component = hit === null || hit === void 0 ? void 0 : hit.object.userData["LYObject"];
2389
+ const component = hit === null || hit === void 0 ? void 0 : hit.component;
2377
2390
  if (component instanceof SceneComponent && hit) {
2378
- this.firePointerDownEvent(component, hit, event.button);
2391
+ this.firePointerDownEvent(component, hit.hit, event.button);
2379
2392
  }
2380
2393
  }
2381
2394
  firePointerDownEvent(component, hit, button) {
@@ -2412,12 +2425,7 @@ class Controller {
2412
2425
  this.raycaster.setFromCamera(this._raycastVec2, this.camera);
2413
2426
  const out = this.getAllHitResultFromScreenPoint(x, y);
2414
2427
  for (const hit of out) {
2415
- if (hit.object.userData["rayIgnored"])
2416
- continue;
2417
- const component = hit.object.userData["LYObject"];
2418
- if (!component)
2419
- continue;
2420
- if (!component.isHoverEnabled && !component.isClickEnabled)
2428
+ if (!hit.component.isHoverEnabled && !hit.component.isClickEnabled)
2421
2429
  continue;
2422
2430
  return hit;
2423
2431
  }
@@ -2426,7 +2434,20 @@ class Controller {
2426
2434
  getAllHitResultFromScreenPoint(x, y) {
2427
2435
  this._raycastVec2.set(x, y);
2428
2436
  this.raycaster.setFromCamera(this._raycastVec2, this.camera);
2429
- return this.raycaster.intersectObjects(this.world.scene.children, true);
2437
+ const hits = this.raycaster.intersectObjects(this.world.scene.children, true);
2438
+ let out = [];
2439
+ for (const hit of hits) {
2440
+ if (hit.object.userData["rayIgnored"])
2441
+ continue;
2442
+ const component = hit.object.userData["LYObject"];
2443
+ if (!component)
2444
+ continue;
2445
+ out.push({
2446
+ component: component,
2447
+ hit: hit
2448
+ });
2449
+ }
2450
+ return out;
2430
2451
  }
2431
2452
  focusTo(targetPos, targetQuat, distance, time, onGoing = null, onFinished = null) {
2432
2453
  this.pawn.focusTo(targetPos, targetQuat, distance, time, onGoing, onFinished);
@@ -5,6 +5,10 @@ import { Viewport } from "./Viewport";
5
5
  import { Pawn } from "../Object/PawnV2/Pawn";
6
6
  import { SceneComponent } from "../Object/Components/SceneComponent";
7
7
  import { Delegate } from "../Delegate";
8
+ export interface HitResult {
9
+ component: SceneComponent;
10
+ hit: Intersection;
11
+ }
8
12
  /** 组件交互事件基类 */
9
13
  export interface ComponentInteractionEvent {
10
14
  component: SceneComponent;
@@ -97,8 +101,8 @@ export declare class Controller {
97
101
  protected onPointerLeaveEvent(_event: MouseEvent): void;
98
102
  protected addCorePointerListeners(): void;
99
103
  protected removeCorePointerListeners(): void;
100
- getHitResultUnderCursor(): Intersection | null;
101
- getHitResultFromScreenPoint(x: number, y: number): Intersection | null;
102
- getAllHitResultFromScreenPoint(x: number, y: number): Intersection[];
104
+ getHitResultUnderCursor(): HitResult | null;
105
+ getHitResultFromScreenPoint(x: number, y: number): HitResult | null;
106
+ getAllHitResultFromScreenPoint(x: number, y: number): HitResult[];
103
107
  focusTo(targetPos: Vector3, targetQuat: Quaternion | Euler, distance: number, time: number, onGoing?: (() => void) | null, onFinished?: (() => void) | null): void;
104
108
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lythreeframe",
3
- "version": "1.2.60",
3
+ "version": "1.2.62",
4
4
  "description": "Three.js 封装",
5
5
  "main": "dist/bundle.cjs.js",
6
6
  "module": "dist/bundle.esm.js",