lythreeframe 1.0.0

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.
Files changed (68) hide show
  1. package/lythreeFrame/exporter.ts +36 -0
  2. package/lythreeFrame/src/AssetManagement/AssetDefines.ts +8 -0
  3. package/lythreeFrame/src/AssetManagement/AssetManager.ts +286 -0
  4. package/lythreeFrame/src/AssetManagement/AssetPointer/AssetPointer.ts +41 -0
  5. package/lythreeFrame/src/AssetManagement/Task/Task.ts +24 -0
  6. package/lythreeFrame/src/Container/SmartPointer.ts +54 -0
  7. package/lythreeFrame/src/Defines.ts +11 -0
  8. package/lythreeFrame/src/Delegate.ts +37 -0
  9. package/lythreeFrame/src/Factory/CameraFactory.ts +81 -0
  10. package/lythreeFrame/src/Factory/RendererFactory.ts +7 -0
  11. package/lythreeFrame/src/Frame/Controller.ts +261 -0
  12. package/lythreeFrame/src/Frame/Viewport.ts +516 -0
  13. package/lythreeFrame/src/Frame/World.ts +59 -0
  14. package/lythreeFrame/src/Frame.ts +511 -0
  15. package/lythreeFrame/src/Geometry/PlaneGeometry.ts +53 -0
  16. package/lythreeFrame/src/Geometry/TriangleGeometry.ts +50 -0
  17. package/lythreeFrame/src/Library/ContainerLibrary.ts +21 -0
  18. package/lythreeFrame/src/Library/MaterialLibrary.ts +288 -0
  19. package/lythreeFrame/src/Library/Math.ts +154 -0
  20. package/lythreeFrame/src/Library/ResourceLibrary.ts +21 -0
  21. package/lythreeFrame/src/Object/Actor.ts +571 -0
  22. package/lythreeFrame/src/Object/Actors/Camera/CameraActor.ts +11 -0
  23. package/lythreeFrame/src/Object/Actors/Light/DirectionalLightActor.ts +18 -0
  24. package/lythreeFrame/src/Object/Actors/Shape/BoxActor.ts +20 -0
  25. package/lythreeFrame/src/Object/Actors/Shape/CurveActor.ts +11 -0
  26. package/lythreeFrame/src/Object/Actors/Shape/PlaneActor.ts +27 -0
  27. package/lythreeFrame/src/Object/Actors/Shape/TubeActor.ts +37 -0
  28. package/lythreeFrame/src/Object/BaseObject.ts +45 -0
  29. package/lythreeFrame/src/Object/Components/2D/2DComponent.ts +64 -0
  30. package/lythreeFrame/src/Object/Components/Camera/CameraComponent.ts +113 -0
  31. package/lythreeFrame/src/Object/Components/Component.ts +67 -0
  32. package/lythreeFrame/src/Object/Components/Light/DirectionalLight/DirectionalLightComponent.ts +78 -0
  33. package/lythreeFrame/src/Object/Components/Light/LightComponent.ts +54 -0
  34. package/lythreeFrame/src/Object/Components/Mesh/InstanceMesh/InstanceMeshComponent.ts +39 -0
  35. package/lythreeFrame/src/Object/Components/Mesh/InstanceMesh/MultiInstanceMeshComponent.ts +115 -0
  36. package/lythreeFrame/src/Object/Components/Mesh/Line/CurveComponent.ts +221 -0
  37. package/lythreeFrame/src/Object/Components/Mesh/MeshComponent.ts +162 -0
  38. package/lythreeFrame/src/Object/Components/Mesh/Shape/BoxComponent.ts +17 -0
  39. package/lythreeFrame/src/Object/Components/Mesh/Shape/PlaneComponent.ts +10 -0
  40. package/lythreeFrame/src/Object/Components/Mesh/Shape/SphereComponent.ts +10 -0
  41. package/lythreeFrame/src/Object/Components/Mesh/Sprite/SpriteComponent.ts +32 -0
  42. package/lythreeFrame/src/Object/Components/SceneComponent.ts +809 -0
  43. package/lythreeFrame/src/Object/Controller/Controller.ts +764 -0
  44. package/lythreeFrame/src/Object/Pawn/CameraStatus.ts +262 -0
  45. package/lythreeFrame/src/Object/Pawn/FirstPerson.ts +230 -0
  46. package/lythreeFrame/src/Object/Pawn/Oribital.ts +276 -0
  47. package/lythreeFrame/src/Object/Pawn/PawnBase.ts +189 -0
  48. package/lythreeFrame/src/Object/Pawn/TopView.ts +205 -0
  49. package/lythreeFrame/src/Object/Pawn/TransformControl.ts +215 -0
  50. package/lythreeFrame/src/Object/Pawn/staticCamera.ts +80 -0
  51. package/lythreeFrame/src/Object/PawnV2/FirstPerson.ts +12 -0
  52. package/lythreeFrame/src/Object/PawnV2/Oribital.ts +45 -0
  53. package/lythreeFrame/src/Object/PawnV2/Pawn.ts +50 -0
  54. package/lythreeFrame/src/Object/PawnV2/TransformControl.ts +201 -0
  55. package/lythreeFrame/src/PostProcess/Param/Bloom.ts +12 -0
  56. package/lythreeFrame/src/PostProcess/Param/DOF.ts +14 -0
  57. package/lythreeFrame/src/PostProcess/Param/Denoise.ts +14 -0
  58. package/lythreeFrame/src/PostProcess/Param/GTAO.ts +21 -0
  59. package/lythreeFrame/src/PostProcess/Param/LensFlare.ts +11 -0
  60. package/lythreeFrame/src/PostProcess/Param/MotionBlur.ts +8 -0
  61. package/lythreeFrame/src/PostProcess/Param/Outline.ts +20 -0
  62. package/lythreeFrame/src/PostProcess/Param/SSR.ts +11 -0
  63. package/lythreeFrame/src/PostProcess/Param/ToneMapping.ts +31 -0
  64. package/lythreeFrame/src/PostProcess/PostProcessParam.ts +26 -0
  65. package/lythreeFrame/src/PostProcess/WebGPUPostProcessFactory.ts +217 -0
  66. package/lythreeFrame/src/Shader/Postprocess/ColorShader.ts +49 -0
  67. package/lythreeFrame/src/ThreeJsApp.ts +124 -0
  68. package/package.json +21 -0
@@ -0,0 +1,809 @@
1
+ import {Actor} from "../Actor.ts";
2
+ import {Box3, Euler, Group, Matrix4, Object3D, Quaternion, Vector3} from "three";
3
+ import {Component} from "./Component.ts";
4
+ import { World } from "../../Frame/World.ts";
5
+ import { AttachmentRules } from "@threeframe/src/Defines.ts";
6
+
7
+ export class SceneComponent extends Component
8
+ {
9
+ set parentActor(value:Actor | null)
10
+ {
11
+ this.childrenComponents.forEach((elem) =>
12
+ {
13
+ elem.parentActor = value;
14
+ });
15
+ super.parentActor = value;
16
+ }
17
+
18
+ get parentActor():Actor | null
19
+ {
20
+ return super.parentActor;
21
+ }
22
+
23
+ protected bCanHover:boolean = false;
24
+ protected bCanClick:boolean = false;
25
+ protected world:World | null = null;
26
+
27
+ constructor(newThreeObject:Object3D)
28
+ {
29
+ super(newThreeObject);
30
+ this._name = "SceneComponent"
31
+ }
32
+
33
+ createDefaultThreeObject()
34
+ {
35
+ this.threeObject = new Group();
36
+ }
37
+
38
+ get isVisible():boolean
39
+ {
40
+ if(!this.threeObject)
41
+ {
42
+ return false
43
+ }
44
+ return this.threeObject.visible;
45
+ }
46
+
47
+ setVisible(bVisible:boolean)
48
+ {
49
+ if (!this.threeObject)
50
+ {
51
+ throw Error("threeObject is invalid")
52
+ }
53
+ this.threeObject.visible = bVisible;
54
+ if (this.world)
55
+ {
56
+ this.world.viewport.markRenderStateDirty();
57
+ }
58
+ }
59
+
60
+ setLayers(layer:number):void
61
+ {
62
+ if (!this.threeObject)
63
+ {
64
+ throw Error("threeObject is invalid")
65
+ }
66
+ this.threeObject.layers.set(layer);
67
+ let childComps = this.childrenComponents;
68
+ childComps.forEach((elem) =>
69
+ {
70
+ elem.setLayers(layer);
71
+ });
72
+ }
73
+
74
+ getBoundsCenterPositionWS():Vector3
75
+ {
76
+ let ret = new Vector3();
77
+ this.getBounds().getCenter(ret);
78
+ return this.getWorldPosition();
79
+ }
80
+
81
+ getBoundsTopCenterPositionWS():Vector3
82
+ {
83
+ let ret = new Vector3();
84
+ let bounds = this.getBounds();
85
+ bounds.getCenter(ret);
86
+ ret.y = bounds.max.y;
87
+ return ret;
88
+ }
89
+
90
+ getBoundsBottomCenterPositionWS():Vector3
91
+ {
92
+ let ret = new Vector3();
93
+ let bounds = this.getBounds();
94
+ bounds.getCenter(ret);
95
+ ret.y = bounds.min.y;
96
+ return ret;
97
+ }
98
+
99
+ getBounds():Box3
100
+ {
101
+ if (!this.threeObject)
102
+ {
103
+ throw Error("threeObject is invalid")
104
+ }
105
+ let ret = new Box3();
106
+ ret.setFromObject(this.threeObject, false);
107
+ if (ret.isEmpty())
108
+ {
109
+ ret.min = ret.max = this.getWorldPosition();
110
+ }
111
+ return ret;
112
+ }
113
+
114
+ get parentComponent():SceneComponent | null
115
+ {
116
+ if (!this.threeObject)
117
+ {
118
+ throw Error("threeObject is invalid")
119
+ }
120
+ let target = this.threeObject?.parent?.userData.LYObject
121
+ if(!target)
122
+ {
123
+ return null
124
+ }
125
+ if(!(target instanceof SceneComponent))
126
+ {
127
+ return null
128
+ }
129
+ if(target.parentActor !== this.parentActor)
130
+ {
131
+ return null
132
+ }
133
+ return target as SceneComponent;
134
+ }
135
+
136
+ get childrenComponents()
137
+ {
138
+ if (!this.threeObject)
139
+ {
140
+ throw Error("threeObject is invalid")
141
+ }
142
+ let childrens = [];
143
+
144
+ for (let i = 0; i < this.threeObject.children.length; ++i)
145
+ {
146
+ if (!this.threeObject.children[i].userData.LYObject)
147
+ {
148
+ console.warn("One of children component has no parentActor", this.threeObject.children[i].userData.LYObject, this.threeObject.children[i]);
149
+ continue;
150
+ }
151
+ if (this.threeObject.children[i].userData.LYObject.parentActor === this.parentActor)
152
+ {
153
+ childrens.push(this.threeObject.children[i].userData.LYObject);
154
+ }
155
+ }
156
+
157
+ return childrens;
158
+ }
159
+
160
+ onAddedToWorld(world:World)
161
+ {
162
+ this.world = world;
163
+ let childrens = this.childrenComponents;
164
+ for (let i = 0; i < childrens.length; ++i)
165
+ {
166
+ childrens[i].onAddedToWorld(this.world);
167
+ }
168
+ }
169
+
170
+ destroy()
171
+ {
172
+ this.isHoverEnabled = false;
173
+ this.isClickEnabled = false;
174
+ this.detachFromParentActor();
175
+ this.detachFromParentComponent();
176
+ this.destroyChildren();
177
+ this.destroyObject();
178
+ if (this.world)
179
+ {
180
+ this.world.viewport.markRenderStateDirty();
181
+ }
182
+ }
183
+
184
+ destroyObject()
185
+ {
186
+ if (!this.threeObject)
187
+ {
188
+ return;
189
+ }
190
+ if (this.threeObject.parent)
191
+ {
192
+ this.threeObject.parent.remove(this.threeObject);
193
+ }
194
+
195
+ super.destroyObject();
196
+ }
197
+
198
+ // Local Transforms
199
+ // // Position
200
+ getPosition()
201
+ {
202
+ if (!this.threeObject)
203
+ {
204
+ throw Error("threeObject is invalid")
205
+ }
206
+ if (this.threeObject.matrixAutoUpdate)
207
+ {
208
+ return this.threeObject.position.clone();
209
+ }
210
+ else
211
+ {
212
+ const position = new Vector3();
213
+ const quaternion = new Quaternion();
214
+ const scale = new Vector3();
215
+ this.threeObject.matrix.decompose(position, quaternion, scale);
216
+ return position;
217
+ }
218
+ }
219
+
220
+ setPosition(position:Vector3):void;
221
+ setPosition(x:number, y:number, z:number):void;
222
+ setPosition(...args:[Vector3] | [number, number, number]):void
223
+ {
224
+ if (!this.threeObject)
225
+ {
226
+ throw Error("threeObject is invalid")
227
+ }
228
+
229
+ let newPosition:Vector3 | null = null;
230
+
231
+ if (args.length === 1 && args[0] instanceof Vector3)
232
+ {
233
+ newPosition = new Vector3().copy(args[0]);
234
+ }
235
+ else if (args.length === 3 &&
236
+ typeof args[0] === "number" &&
237
+ typeof args[1] === "number" &&
238
+ typeof args[2] === "number")
239
+ {
240
+ newPosition = new Vector3(args[0], args[1], args[2]);
241
+ }
242
+
243
+ if (!newPosition)
244
+ {
245
+ return;
246
+ }
247
+
248
+ this.threeObject.position.copy(newPosition);
249
+
250
+ if (!this.threeObject.matrixAutoUpdate)
251
+ {
252
+ this.threeObject.matrix.setPosition(newPosition.x, newPosition.y, newPosition.z);
253
+ }
254
+
255
+ this.threeObject.updateMatrix();
256
+ this.threeObject.updateMatrixWorld(true);
257
+
258
+ if (this.world)
259
+ {
260
+ this.world.viewport.markRenderStateDirty();
261
+ }
262
+ }
263
+
264
+ // // Rotation
265
+ getRotation()
266
+ {
267
+ if (!this.threeObject)
268
+ {
269
+ throw Error("threeObject is invalid")
270
+ }
271
+ if (this.threeObject.matrixAutoUpdate)
272
+ {
273
+ return this.threeObject.rotation.clone();
274
+ }
275
+ else
276
+ {
277
+ const position = new Vector3();
278
+ const quaternion = new Quaternion();
279
+ const scale = new Vector3();
280
+ this.threeObject.matrix.decompose(position, quaternion, scale);
281
+ return new Euler().setFromQuaternion(quaternion);
282
+ }
283
+ }
284
+
285
+ setRotation(rotation:Euler):void;
286
+ setRotation(x:number, y:number, z:number):void;
287
+ setRotation(...args:[Euler]|[x:number, y:number, z:number])
288
+ {
289
+ if (!this.threeObject)
290
+ {
291
+ throw Error("threeObject is invalid")
292
+ }
293
+ let newRotation:Euler | null = null;
294
+ if (args[0] instanceof Euler)
295
+ {
296
+ newRotation = new Euler().copy(args[0]);
297
+ }
298
+ if (typeof (args[0]) === "number" && typeof (args[1]) === "number" && typeof (args[2]) === "number")
299
+ {
300
+ newRotation = new Euler(args[0], args[1], args[2]);
301
+ }
302
+ if (!newRotation)
303
+ {
304
+ return;
305
+ }
306
+ this.threeObject.rotation.copy(newRotation);
307
+
308
+ this.threeObject.updateMatrix();
309
+ this.threeObject.updateMatrixWorld(true);
310
+ if (this.world)
311
+ {
312
+ this.world.viewport.markRenderStateDirty();
313
+ }
314
+ }
315
+
316
+ // // quat
317
+ getQuaternion()
318
+ {
319
+ if (!this.threeObject)
320
+ {
321
+ throw Error("threeObject is invalid")
322
+ }
323
+ if (this.threeObject.matrixAutoUpdate)
324
+ {
325
+ return this.threeObject.quaternion.clone();
326
+ }
327
+ else
328
+ {
329
+ const position = new Vector3();
330
+ const quaternion = new Quaternion();
331
+ const scale = new Vector3();
332
+ this.threeObject.matrix.decompose(position, quaternion, scale);
333
+ return quaternion;
334
+ }
335
+ }
336
+
337
+ setQuaternion(quat:Quaternion):void;
338
+ setQuaternion(x:number, y:number, z:number, w:number):void;
339
+ setQuaternion(...args:[Quaternion]|[x:number, y:number, z:number, w:number])
340
+ {
341
+ if (!this.threeObject)
342
+ {
343
+ throw Error("threeObject is invalid")
344
+ }
345
+ let newQuat:Quaternion | null = null;
346
+ if (args[0] instanceof Quaternion)
347
+ {
348
+ newQuat = new Quaternion().copy(args[0]);
349
+ }
350
+ if (typeof args[0] === "number" && typeof args[1] === "number" && typeof args[2] === "number" && typeof args[3] === "number")
351
+ {
352
+ newQuat = new Quaternion(args[0], args[1], args[2], args[3]);
353
+ }
354
+ if (!newQuat)
355
+ {
356
+ console.error("setQuaternion failed,param is invalid", args);
357
+ return;
358
+ }
359
+ this.threeObject.quaternion.copy(newQuat);
360
+
361
+ if (!this.threeObject.matrixAutoUpdate)
362
+ {
363
+ const position = new Vector3();
364
+ const quaternion = new Quaternion();
365
+ const scale = new Vector3();
366
+ this.threeObject.matrix.decompose(position, quaternion, scale);
367
+ this.threeObject.matrix.compose(position, newQuat, scale);
368
+ }
369
+ if (this.world)
370
+ {
371
+ this.world.viewport.markRenderStateDirty();
372
+ }
373
+
374
+ this.threeObject.updateMatrix();
375
+ this.threeObject.updateMatrixWorld(true);
376
+
377
+ }
378
+
379
+ // // Scale
380
+ getScale()
381
+ {
382
+ if (!this.threeObject)
383
+ {
384
+ throw Error("threeObject is invalid")
385
+ }
386
+ if (this.threeObject.matrixAutoUpdate)
387
+ {
388
+ return this.threeObject.scale.clone();
389
+ }
390
+ else
391
+ {
392
+ const position = new Vector3();
393
+ const quaternion = new Quaternion();
394
+ const scale = new Vector3();
395
+ this.threeObject.matrix.decompose(position, quaternion, scale);
396
+ return scale;
397
+ }
398
+ }
399
+
400
+ setScale(position:Vector3):void;
401
+ setScale(x:number, y:number, z:number):void;
402
+ setScale(...args:[Vector3] | [number, number, number]):void
403
+ {
404
+ if (!this.threeObject)
405
+ {
406
+ throw Error("threeObject is invalid")
407
+ }
408
+
409
+ let newScale:Vector3 | null = null;
410
+ if (args[0] instanceof Vector3)
411
+ {
412
+ newScale = new Vector3().copy(args[0]);
413
+ }
414
+
415
+ if (typeof (args[0]) === "number" && typeof (args[1]) === "number" && typeof (args[2]) === "number")
416
+ {
417
+ newScale = new Vector3(args[0], args[1], args[2]);
418
+ }
419
+ if (!newScale)
420
+ {
421
+ return;
422
+ }
423
+ this.threeObject.scale.copy(newScale);
424
+ // if(!this.threeObject.matrixAutoUpdate)
425
+ // {
426
+ // const position = new Vector3();
427
+ // const quaternion = new Quaternion()
428
+ // const scale = new Vector3();
429
+ // this.threeObject.matrix.decompose(position, quaternion, scale)
430
+ // this.threeObject.matrix.compose(position, quaternion, new Vector3(param1, param2, param3))
431
+ // }
432
+ this.threeObject.updateMatrix();
433
+ this.threeObject.updateMatrixWorld(true);
434
+
435
+ if (this.world)
436
+ {
437
+ this.world.viewport.markRenderStateDirty();
438
+ }
439
+ }
440
+
441
+ // matrix
442
+ getMatrix():Matrix4
443
+ {
444
+ if (!this.threeObject)
445
+ {
446
+ throw Error("threeObject is invalid")
447
+ }
448
+ return this.threeObject.matrix;
449
+ }
450
+
451
+ setMatrix(matrix:Matrix4)
452
+ {
453
+ if (!this.threeObject)
454
+ {
455
+ throw Error("threeObject is invalid")
456
+ }
457
+ // this.threeObject.matrix.copy(matrix)
458
+ matrix.decompose(this.threeObject.position, this.threeObject.quaternion, this.threeObject.scale);
459
+ this.threeObject.updateMatrix();
460
+ this.threeObject.updateMatrixWorld(true);
461
+ this.world?.viewport.markRenderStateDirty();
462
+ }
463
+
464
+ // World Transform
465
+ // // WorldPosition
466
+ getWorldPosition()
467
+ {
468
+ if (!this.threeObject)
469
+ {
470
+ throw Error("threeObject is invalid")
471
+ }
472
+ let location = new Vector3();
473
+ this.threeObject.getWorldPosition(location);
474
+ return location;
475
+ }
476
+
477
+
478
+ // // rotation(euler)
479
+ getWorldRotation()
480
+ {
481
+ if (!this.threeObject)
482
+ {
483
+ throw Error("threeObject is invalid")
484
+ }
485
+ let rotation = new Quaternion();
486
+ this.threeObject.getWorldQuaternion(rotation);
487
+ return new Euler().setFromQuaternion(rotation);
488
+ }
489
+
490
+
491
+ // // rotation(quat)
492
+ getWorldQuaternion()
493
+ {
494
+ if (!this.threeObject)
495
+ {
496
+ throw Error("threeObject is invalid")
497
+ }
498
+ let rotation = new Quaternion();
499
+ this.threeObject.getWorldQuaternion(rotation);
500
+ return rotation;
501
+ }
502
+
503
+ // // Scale
504
+ getWorldScale()
505
+ {
506
+ if (!this.threeObject)
507
+ {
508
+ throw Error("threeObject is invalid")
509
+ }
510
+ let scale = new Vector3();
511
+ this.threeObject.getWorldScale(scale);
512
+ return scale;
513
+ }
514
+
515
+ // // Matrix
516
+ getWorldMatrix()
517
+ {
518
+ if (!this.threeObject)
519
+ {
520
+ throw Error("threeObject is invalid")
521
+ }
522
+ this.threeObject.updateMatrixWorld(true);
523
+ return this.threeObject.matrixWorld.clone();
524
+ }
525
+
526
+ setWorldMatrix(newMatrix:Matrix4)
527
+ {
528
+ if (!this.threeObject)
529
+ {
530
+ throw Error("threeObject is invalid")
531
+ }
532
+ if (this.threeObject.parent)
533
+ {
534
+ this.threeObject.parent.updateMatrixWorld(true);
535
+ // 计算父对象的逆世界矩阵
536
+ const parentInverseWorldMatrix = this.threeObject.parent.matrixWorld.clone().invert();
537
+ // 计算物体的本地矩阵
538
+ const cLocalMatrix = new Matrix4().multiplyMatrices(parentInverseWorldMatrix, newMatrix);
539
+
540
+ // 更新物体的本地矩阵
541
+ this.setMatrix(cLocalMatrix);
542
+ // this.threeObject.matrix.copy(cLocalMatrix);
543
+ // this.threeObject.matrixAutoUpdate = false;
544
+ // this.threeObject.matrix.decompose(this.threeObject.position, this.threeObject.quaternion, this.threeObject.scale);
545
+
546
+ }
547
+ else
548
+ {
549
+ this.setMatrix(newMatrix);
550
+
551
+ // // 没有父对象时直接设置世界矩阵为本地矩阵
552
+ // this.threeObject.matrix.copy(newMatrix);
553
+ // this.threeObject.matrixAutoUpdate = false;
554
+
555
+ }
556
+
557
+ // 更新世界矩阵
558
+ this.threeObject.updateMatrixWorld(true);
559
+
560
+ if (this.world)
561
+ {
562
+ // 强制场景重新渲染
563
+ this.world.viewport.markRenderStateDirty();
564
+ }
565
+
566
+
567
+ }
568
+
569
+ getWorldForwardDirection()
570
+ {
571
+ if (!this.threeObject)
572
+ {
573
+ throw Error("threeObject is invalid")
574
+ }
575
+ let ret = new Vector3();
576
+ this.threeObject.getWorldDirection(ret);
577
+ return ret;
578
+ }
579
+
580
+ getWorldUpDirection()
581
+ {
582
+ if (!this.threeObject)
583
+ {
584
+ throw Error("threeObject is invalid")
585
+ }
586
+ let ret = new Vector3(0, 1, 0);
587
+ ret.applyQuaternion(this.getWorldQuaternion());
588
+ return ret;
589
+ }
590
+
591
+ getWorldRightDirection()
592
+ {
593
+ if (!this.threeObject)
594
+ {
595
+ throw Error("threeObject is invalid")
596
+ }
597
+ let ret = new Vector3(1, 0, 0);
598
+ ret.applyQuaternion(this.getWorldQuaternion());
599
+ return ret;
600
+ }
601
+
602
+ worldToLocal(vec:Vector3):Vector3
603
+ {
604
+ if (!this.threeObject)
605
+ {
606
+ throw Error("threeObject is invalid")
607
+ }
608
+ return this.threeObject.worldToLocal(vec);
609
+ }
610
+
611
+ localToWorld(vec:Vector3):Vector3
612
+ {
613
+ if (!this.threeObject)
614
+ {
615
+ throw Error("threeObject is invalid")
616
+ }
617
+ return this.threeObject.localToWorld(vec);
618
+ }
619
+
620
+ // Attachment
621
+ // // to another component
622
+ // this function will not set newComponent's parentActor
623
+ attachComponent(newComponent:SceneComponent)
624
+ {
625
+ if (!this.threeObject)
626
+ {
627
+ throw Error("threeObject is invalid")
628
+ }
629
+ if (!newComponent.threeObject)
630
+ {
631
+ throw Error("newComponent threeObject is invalid")
632
+ }
633
+ this.threeObject.add(newComponent.threeObject);
634
+ if (this.world)
635
+ {
636
+ newComponent.onAddedToWorld(this.world);
637
+ }
638
+ }
639
+
640
+ detachComponent(target:SceneComponent)
641
+ {
642
+ if (!this.threeObject)
643
+ {
644
+ throw Error("threeObject is invalid")
645
+ }
646
+ if (!target.threeObject)
647
+ {
648
+ throw Error("target threeObject is invalid")
649
+ }
650
+ this.threeObject.remove(target.threeObject);
651
+ }
652
+
653
+ // newComponent's parentActor will be the same as this
654
+ addChildComponent(newComponent:SceneComponent, attachmentRule:AttachmentRules = AttachmentRules.KeepRelative)
655
+ {
656
+ if (!this.threeObject)
657
+ {
658
+ throw Error("threeObject is invalid")
659
+ }
660
+ if (!newComponent.threeObject)
661
+ {
662
+ throw Error("newComponent threeObject is invalid")
663
+ }
664
+ newComponent.parentActor = this.parentActor;
665
+
666
+ if(attachmentRule = AttachmentRules.KeepWorld)
667
+ {
668
+ let worldMatrix = newComponent.getWorldMatrix();
669
+ this.threeObject.add(newComponent.threeObject);
670
+ newComponent.setWorldMatrix(worldMatrix);
671
+ }
672
+ else
673
+ {
674
+ this.threeObject.add(newComponent.threeObject);
675
+ }
676
+
677
+ if (this.world)
678
+ {
679
+ newComponent.onAddedToWorld(this.world);
680
+ }
681
+
682
+ this.threeObject.updateMatrix();
683
+ this.threeObject.updateMatrixWorld(true);
684
+ }
685
+
686
+ removeChildComponent(targetComponent:SceneComponent)
687
+ {
688
+ if (!this.threeObject)
689
+ {
690
+ throw Error("threeObject is invalid")
691
+ }
692
+ if (!targetComponent.threeObject)
693
+ {
694
+ throw Error("targetComponent threeObject is invalid")
695
+ }
696
+ this.threeObject.remove(targetComponent.threeObject);
697
+ targetComponent.destroy();
698
+ }
699
+
700
+
701
+ detachFromParentComponent()
702
+ {
703
+ if (this.parentComponent)
704
+ {
705
+ this.parentComponent.removeChildComponent(this);
706
+ }
707
+ }
708
+
709
+ detachFromParentActor()
710
+ {
711
+ if (this.parentActor)
712
+ {
713
+ this.parentActor = null;
714
+ }
715
+
716
+ }
717
+
718
+ destroyChildren()
719
+ {
720
+ if (!this.threeObject)
721
+ {
722
+ return;
723
+ }
724
+ for (let i = 0; i < this.threeObject.children.length; ++i)
725
+ {
726
+ this.threeObject.children[i].userData.LYObject.destroy();
727
+ }
728
+ }
729
+
730
+ /* horver */
731
+ set isHoverEnabled(bCanHorver:boolean)
732
+ {
733
+ this.bCanHover = bCanHorver;
734
+
735
+ let children = this.childrenComponents;
736
+ for (let i = 0; i < children.length; ++i)
737
+ {
738
+ children[i].isHoverEnabled = this.bCanHover;
739
+ }
740
+ }
741
+
742
+ get isHoverEnabled()
743
+ {
744
+ return this.bCanHover;
745
+ }
746
+
747
+ // click
748
+ set isClickEnabled(bCanClick:boolean)
749
+ {
750
+ this.bCanClick = bCanClick;
751
+
752
+ let children = this.childrenComponents;
753
+ for (let i = 0; i < children.length; ++i)
754
+ {
755
+ children[i].isClickEnabled = this.bCanClick;
756
+ }
757
+ }
758
+
759
+ get isClickEnabled()
760
+ {
761
+ return this.bCanClick;
762
+ }
763
+
764
+ onHorveringBegin()
765
+ {
766
+ if (!this.isHoverEnabled)
767
+ {
768
+ return;
769
+ }
770
+ if (this.parentActor)
771
+ {
772
+ let comp = this;
773
+ this.parentActor.onComponentHorveringBegin(comp);
774
+ }
775
+ }
776
+
777
+ onHorveringEnd()
778
+ {
779
+ if (!this.isHoverEnabled)
780
+ {
781
+ return;
782
+ }
783
+ if (this.parentActor)
784
+ {
785
+ let comp = this;
786
+ this.parentActor.onComponentHorveringEnd(comp);
787
+ }
788
+ }
789
+
790
+ /* click */
791
+ onClicked()
792
+ {
793
+ if (this.parentActor)
794
+ {
795
+ let comp = this;
796
+ this.parentActor.onComponentClicked(comp);
797
+ }
798
+ }
799
+
800
+ onDoubleClicked()
801
+ {
802
+ if (this.parentActor)
803
+ {
804
+ let comp = this;
805
+ this.parentActor.onComponentDoubleClicked(comp);
806
+ }
807
+ }
808
+
809
+ }