lythreeframe 1.0.5 → 1.0.7

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