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,516 @@
1
+ 
2
+ import { PostProcessParam } from './../PostProcess/PostProcessParam';
3
+ import OutlineNode from 'three/examples/jsm/tsl/display/OutlineNode.js';
4
+ import { CSS2DRenderer } from "three/examples/jsm/Addons.js";
5
+ import BloomNode from "three/examples/jsm/tsl/display/BloomNode.js";
6
+ import DenoiseNode from "three/examples/jsm/tsl/display/DenoiseNode.js";
7
+ import DepthOfFieldNode from "three/examples/jsm/tsl/display/DepthOfFieldNode.js";
8
+ import GTAONode from "three/examples/jsm/tsl/display/GTAONode.js";
9
+ import { WebGPURendererParameters } from "three/src/renderers/webgpu/WebGPURenderer.js";
10
+ import { blendColor, oscSine, ShaderNodeObject, time, uniform } from "three/tsl";
11
+ import { WebGPURenderer, PostProcessing, PassNode, Color, Node } from "three/webgpu";
12
+ import { BloomParam } from "../PostProcess/Param/Bloom";
13
+ import { GTAOParam } from "../PostProcess/Param/GTAO";
14
+ import { ToneMappingParams, ToneMappingOptions } from "../PostProcess/Param/ToneMapping";
15
+ import { WebGPUPostProcessFactory } from "../PostProcess/WebGPUPostProcessFactory";
16
+ import { ThreeJsApp } from "../ThreeJsApp";
17
+ import SSRNode from "three/examples/jsm/tsl/display/SSRNode.js";
18
+ import { SSRParam } from "../PostProcess/Param/SSR";
19
+ import { DefaultOutlineParams, OutlineParams } from '../PostProcess/Param/Outline';
20
+ import { Object3D } from 'three/src/Three.WebGPU.Nodes.js';
21
+ import { DOFParam } from '../PostProcess/Param/DOF';
22
+ import FXAANode from 'three/examples/jsm/tsl/display/FXAANode.js';
23
+ import { SMAANode } from 'three/examples/jsm/tsl/display/SMAANode.js';
24
+
25
+
26
+ export class Viewport
27
+ {
28
+ get canvas(): HTMLElement
29
+ {
30
+ if (!this._canvas)
31
+ {
32
+ throw Error("Canvas is not initialized");
33
+ }
34
+ return this._canvas;
35
+ }
36
+ get renderer(): WebGPURenderer
37
+ {
38
+ if (!this._renderer)
39
+ {
40
+ throw Error("Renderer is not initialized");
41
+ }
42
+ return this._renderer;
43
+ }
44
+ get app(): ThreeJsApp
45
+ {
46
+ if (!this._app)
47
+ {
48
+ throw Error("App is not initialized");
49
+ }
50
+ return this._app;
51
+ }
52
+
53
+ private _renderer: WebGPURenderer | null = null;
54
+ private labelRenderer: CSS2DRenderer | null = null;
55
+
56
+ protected _app: ThreeJsApp | null = null;
57
+ private resizeObserver: ResizeObserver | null = null;
58
+ private _canvas: HTMLElement | null = null;
59
+ private isRenderStateDirty: boolean = true;
60
+
61
+ private postProcessParam: PostProcessParam = {};
62
+ private postProcessing: PostProcessing | null = null;
63
+ private scenePass: ShaderNodeObject<PassNode> | null = null;
64
+ private bloomPass: ShaderNodeObject<BloomNode> | null = null;
65
+ private dofPass: ShaderNodeObject<DepthOfFieldNode> | null = null;
66
+ private GTAOPass: ShaderNodeObject<GTAONode> | null = null;
67
+ private denoiseGTAOPass: ShaderNodeObject<DenoiseNode> | null = null;
68
+ // private denoiseOutlinePass: ShaderNodeObject<DenoiseNode> | null = null;
69
+ private ssrPass: ShaderNodeObject<SSRNode> | null = null;
70
+ private outlinePass: ShaderNodeObject<OutlineNode> | null = null;
71
+ // private motionBlurPass: ShaderNodeObject<Node> | null = null;
72
+ private fxaaPass: ShaderNodeObject<FXAANode> | null = null;
73
+ private smaaPass: ShaderNodeObject<SMAANode> | null = null;
74
+
75
+ private outlineObjects: Object3D[] = [];
76
+ constructor(app: ThreeJsApp, elementId: string, rendererParam: WebGPURendererParameters = { antialias: true }, postProcessParam: PostProcessParam = {})
77
+ {
78
+ this.postProcessParam = postProcessParam
79
+ this._app = app;
80
+ let element = document.getElementById(elementId);
81
+ if (!element)
82
+ {
83
+ throw Error(`Can not find domElement which id is ${elementId}`);
84
+ }
85
+ this._renderer = new WebGPURenderer(rendererParam);
86
+ this._renderer.setPixelRatio(window.devicePixelRatio);
87
+ this._renderer.setSize(element.clientWidth, element.clientHeight);
88
+ this._renderer.shadowMap.enabled = true;
89
+ this.labelRenderer = new CSS2DRenderer();
90
+ this.labelRenderer.setSize(element.clientWidth, element.clientHeight);
91
+ this.labelRenderer.domElement.style.pointerEvents = 'none';
92
+ this.labelRenderer.domElement.style.position = 'absolute';
93
+ this.labelRenderer.domElement.style.top = '0px';
94
+ this.labelRenderer.domElement.className = 'scene-labelRenderer';
95
+
96
+ element.appendChild(this.labelRenderer.domElement);
97
+ element.appendChild(this._renderer.domElement);
98
+ this._canvas = element;
99
+
100
+ this.resizeObserver = new ResizeObserver((entries) =>
101
+ {
102
+ for (let entry of entries)
103
+ {
104
+ if (entry.contentBoxSize)
105
+ {
106
+ this.onWindowResize();
107
+ }
108
+ }
109
+ });
110
+ this.resizeObserver.observe(this._canvas);
111
+
112
+ this.setupPostProcess();
113
+ }
114
+
115
+ init()
116
+ {
117
+
118
+ }
119
+
120
+ setupPostProcess()
121
+ {
122
+ if (this.postProcessParam.toneMapping)
123
+ {
124
+ let toneMapping = ToneMappingOptions.get(this.postProcessParam.toneMapping.toneMapping);
125
+ if (toneMapping)
126
+ {
127
+ this.renderer.toneMapping = toneMapping;
128
+ }
129
+ this.renderer.toneMappingExposure = this.postProcessParam.toneMapping.exposure;
130
+ }
131
+ if (!(Object.keys(this.postProcessParam).some(key => ['bloom', 'dof', 'gtao', 'ssr', "outline"].includes(key))))
132
+ {
133
+ this.destroyPostProcess();
134
+ return
135
+ }
136
+ if (!this.postProcessing)
137
+ {
138
+ this.postProcessing = new PostProcessing(this.renderer);
139
+ }
140
+
141
+ if (!this.scenePass)
142
+ {
143
+ this.scenePass = WebGPUPostProcessFactory.constructScenePass(this.app.world.scene, this.app.camera);
144
+ }
145
+ let finalNode = this.scenePass.getTextureNode('output');
146
+
147
+ // bloom
148
+ if (this.postProcessParam.bloom)
149
+ {
150
+ if (!this.bloomPass)
151
+ {
152
+ this.bloomPass = WebGPUPostProcessFactory.constructBloomPass(this.scenePass, this.postProcessParam.bloom);
153
+ }
154
+ else
155
+ {
156
+ WebGPUPostProcessFactory.updateBloomPass(this.bloomPass, this.postProcessParam.bloom);
157
+ }
158
+ finalNode = finalNode.add(this.bloomPass);
159
+ }
160
+ else
161
+ {
162
+ if (this.bloomPass)
163
+ {
164
+ this.bloomPass.dispose();
165
+ this.bloomPass = null;
166
+ }
167
+ }
168
+ // DOF
169
+ if (this.postProcessParam.dof)
170
+ {
171
+ if (!this.dofPass)
172
+ {
173
+ this.dofPass = WebGPUPostProcessFactory.constructDOFPass(this.scenePass, this.postProcessParam.dof);
174
+ }
175
+ else
176
+ {
177
+ WebGPUPostProcessFactory.updateDOFPass(this.dofPass, this.postProcessParam.dof);
178
+ }
179
+ finalNode = this.dofPass;
180
+ }
181
+ else
182
+ {
183
+ if (this.dofPass)
184
+ {
185
+ this.dofPass.dispose();
186
+ this.dofPass = null;
187
+ }
188
+ }
189
+
190
+ // motion blur
191
+ // if (this.postProcessParam.motionBlur)
192
+ // {
193
+ // if (!this.motionBlurPass)
194
+ // {
195
+ // this.motionBlurPass = WebGPUPostProcessFactory.constructMotionBlurPass(finalNode, this.scenePass, this.postProcessParam.motionBlur);
196
+ // }
197
+ // const vignette = screenUV.distance(.5).remap(.6, 1).mul(2).clamp().oneMinus();
198
+ // finalNode = mix(this.motionBlurPass, this.scenePass.getTextureNode("velocity"), 0).mul(vignette);
199
+ // }
200
+ // else
201
+ // {
202
+ // if (this.motionBlurPass)
203
+ // {
204
+ // this.motionBlurPass.dispose();
205
+ // this.motionBlurPass = null;
206
+ // }
207
+ // }
208
+
209
+ // ssr
210
+ if (this.postProcessParam.ssr)
211
+ {
212
+ if (!this.ssrPass)
213
+ {
214
+ this.ssrPass = WebGPUPostProcessFactory.constructSSRPass(this.scenePass, this.postProcessParam.ssr);
215
+ }
216
+ else
217
+ {
218
+ WebGPUPostProcessFactory.updateSSRPass(this.ssrPass, this.postProcessParam.ssr);
219
+ }
220
+ finalNode = blendColor(finalNode, this.ssrPass)
221
+ }
222
+ // GTAO
223
+ if (this.postProcessParam.gtao)
224
+ {
225
+ if (!this.GTAOPass)
226
+ {
227
+ this.GTAOPass = WebGPUPostProcessFactory.constructGTAOPass(this.scenePass, this.postProcessParam.gtao);
228
+ }
229
+ else
230
+ {
231
+ WebGPUPostProcessFactory.updateGTAOPass(this.GTAOPass, this.postProcessParam.gtao);
232
+ }
233
+ if (this.postProcessParam.gtao.denoised)
234
+ {
235
+ if (!this.denoiseGTAOPass)
236
+ {
237
+ this.denoiseGTAOPass = WebGPUPostProcessFactory.constructGTAODenoisePass(this.scenePass, this.GTAOPass, this.postProcessParam.gtao);
238
+ }
239
+ else
240
+ {
241
+ WebGPUPostProcessFactory.updateGTAOPass(this.GTAOPass, this.postProcessParam.gtao);
242
+ }
243
+ finalNode = this.denoiseGTAOPass.mul(finalNode);
244
+ }
245
+ else
246
+ {
247
+ finalNode = this.GTAOPass.getTextureNode().mul(finalNode);
248
+ if (this.denoiseGTAOPass)
249
+ {
250
+ this.denoiseGTAOPass.dispose();
251
+ this.denoiseGTAOPass = null;
252
+ }
253
+ }
254
+ }
255
+ else
256
+ {
257
+ if (this.GTAOPass)
258
+ {
259
+ this.GTAOPass.dispose();
260
+ this.GTAOPass = null;
261
+ }
262
+ if (this.denoiseGTAOPass)
263
+ {
264
+ this.denoiseGTAOPass.dispose();
265
+ this.denoiseGTAOPass = null;
266
+ }
267
+ }
268
+ // outline
269
+ if (this.postProcessParam.outline)
270
+ {
271
+ if (!this.outlinePass)
272
+ {
273
+ this.outlinePass = WebGPUPostProcessFactory.constructOutlinePass(this.app.world.scene, this.scenePass.camera, this.outlineObjects, this.postProcessParam.outline);
274
+ }
275
+ else
276
+ {
277
+ WebGPUPostProcessFactory.updateOutlinePass(this.outlinePass, this.outlineObjects, this.postProcessParam.outline);
278
+ }
279
+ const { visibleEdge, hiddenEdge } = this.outlinePass;
280
+ const pulsePeriod = uniform(this.postProcessParam.outline.pulsePeriod);
281
+ const period = time.div(pulsePeriod).mul(2);
282
+ const osc = oscSine(period).mul(.5).add(.5);
283
+
284
+ const outlineColor = visibleEdge.mul(uniform(new Color(this.postProcessParam.outline.visibleEdgeColor))).add(hiddenEdge.mul(uniform(new Color(this.postProcessParam.outline.hiddenEdgeColor)))).mul(this.postProcessParam.outline.edgeStrength);
285
+ const outlinePulse = pulsePeriod.greaterThan(0).select(outlineColor.mul(osc), outlineColor);
286
+
287
+ // if(!this.denoiseOutlinePass)
288
+ // {
289
+ // this.denoiseOutlinePass = WebGPUPostProcessFactory.constructDenoisePass(this.scenePass, outlinePulse, DefaultDenoiseParam);
290
+ // }
291
+ // outlinePulse = this.denoiseOutlinePass.mul(outlinePulse)
292
+ // finalNode = this.denoiseOutlinePass.mul(outlinePulse).add(finalNode);
293
+ finalNode = outlinePulse.add(finalNode);
294
+ // finalNode = this.denoiseOutlinePass.mul(outlinePulse).add(finalNode);
295
+ }
296
+ else
297
+ {
298
+ if (this.outlinePass)
299
+ {
300
+ this.outlinePass.dispose();
301
+ this.outlinePass = null;
302
+ }
303
+ }
304
+
305
+ if (this.postProcessParam.aa)
306
+ {
307
+ if (this.postProcessParam.aa === "fxaa")
308
+ {
309
+ this.fxaaPass = WebGPUPostProcessFactory.constructFXAAPass(finalNode)
310
+ finalNode = this.fxaaPass;
311
+ }
312
+ if (this.postProcessParam.aa === "smaa")
313
+ {
314
+ this.smaaPass = WebGPUPostProcessFactory.constructSMAAPass(finalNode)
315
+ finalNode = this.smaaPass;
316
+ }
317
+ }
318
+ else
319
+ {
320
+ if (this.fxaaPass)
321
+ {
322
+ this.fxaaPass.dispose();
323
+ this.fxaaPass = null;
324
+ }
325
+ if (this.smaaPass)
326
+ {
327
+ this.smaaPass.dispose();
328
+ this.smaaPass = null;
329
+ }
330
+ }
331
+ console.log(this.postProcessParam, "sssssssssssssssssssss")
332
+ this.postProcessing.outputNode = finalNode;
333
+ this.markRenderStateDirty()
334
+ }
335
+
336
+ updateToneMappingParam(params: ToneMappingParams)
337
+ {
338
+ this.postProcessParam.toneMapping = params;
339
+ this.setupPostProcess();
340
+ this.markRenderStateDirty();
341
+ }
342
+
343
+ updateBloomPass(params: BloomParam)
344
+ {
345
+ this.postProcessParam.bloom = params;
346
+ this.setupPostProcess();
347
+ }
348
+
349
+ updateGTAOParam(params: GTAOParam | null)
350
+ {
351
+ this.postProcessParam.gtao = params;
352
+ this.setupPostProcess();
353
+ }
354
+
355
+ updateDOFParam(params: DOFParam | null)
356
+ {
357
+ this.postProcessParam.dof = params;
358
+ this.setupPostProcess();
359
+ }
360
+
361
+ updateSSRParam(params: SSRParam | null)
362
+ {
363
+ this.postProcessParam.ssr = params;
364
+ this.setupPostProcess();
365
+ }
366
+
367
+ updateOutlineParam(params: OutlineParams | null)
368
+ {
369
+ this.postProcessParam.outline = params
370
+ this.setupPostProcess();
371
+ }
372
+
373
+ addOutlineObject(obj: Object3D)
374
+ {
375
+ if(!this.outlineObjects.includes(obj))
376
+ {
377
+ this.outlineObjects.push(obj);
378
+ }
379
+
380
+ if (!this.postProcessParam.outline)
381
+ {
382
+ this.postProcessParam.outline = DefaultOutlineParams
383
+ this.setupPostProcess();
384
+ }
385
+ else
386
+ {
387
+ this.markRenderStateDirty();
388
+ }
389
+ }
390
+
391
+ removeOutlineObject(obj: Object3D)
392
+ {
393
+ if (!this.postProcessParam.outline)
394
+ {
395
+ this.outlineObjects = [];
396
+ return
397
+ }
398
+ const index = this.outlineObjects.indexOf(obj);
399
+ if(index > -1)
400
+ {
401
+ this.outlineObjects.splice(index, 1);
402
+ }
403
+ this.markRenderStateDirty();
404
+ }
405
+
406
+ destroyPostProcess()
407
+ {
408
+ if (this.bloomPass)
409
+ {
410
+ this.bloomPass.dispose()
411
+ this.bloomPass = null;
412
+ }
413
+ if (this.dofPass)
414
+ {
415
+ this.dofPass.dispose()
416
+ this.dofPass = null;
417
+ }
418
+ if (this.GTAOPass)
419
+ {
420
+ this.GTAOPass.dispose()
421
+ this.GTAOPass = null;
422
+ }
423
+ if (this.denoiseGTAOPass)
424
+ {
425
+ this.denoiseGTAOPass.dispose()
426
+ this.denoiseGTAOPass = null;
427
+ }
428
+ if (this.ssrPass)
429
+ {
430
+ this.ssrPass.dispose()
431
+ this.ssrPass = null;
432
+ }
433
+ if (this.outlinePass)
434
+ {
435
+ this.outlinePass.dispose()
436
+ this.outlinePass = null;
437
+ }
438
+ this.outlineObjects = [];
439
+ if (this.scenePass)
440
+ {
441
+ this.scenePass.dispose()
442
+ this.scenePass = null;
443
+ }
444
+ if (this.postProcessing)
445
+ {
446
+ this.postProcessing.dispose();
447
+ this.postProcessing = null;
448
+ }
449
+ }
450
+
451
+ onWindowResize()
452
+ {
453
+ console.log("resize")
454
+ let ele = this._canvas;
455
+ if (!ele)
456
+ {
457
+ return;
458
+ }
459
+ this.app.onWindowResize(ele.clientWidth, ele.clientHeight);
460
+ this.renderer.setSize(ele.clientWidth, ele.clientHeight);
461
+ if(this.labelRenderer)
462
+ this.labelRenderer.setSize(ele.clientWidth, ele.clientHeight);
463
+ this.markRenderStateDirty();
464
+ }
465
+
466
+ markRenderStateDirty()
467
+ {
468
+ this.isRenderStateDirty = true;
469
+ }
470
+
471
+ render()
472
+ {
473
+ if(!this.isRenderStateDirty)
474
+ {
475
+ return
476
+ }
477
+ if (this.postProcessing)
478
+ {
479
+ this.postProcessing.render();
480
+ }
481
+ else
482
+ { //console.log("render renderer");
483
+ this.renderer.render(this.app.world.scene, this.app.camera);
484
+ }
485
+ this.isRenderStateDirty = false;
486
+ }
487
+
488
+ destroy()
489
+ {
490
+ this.destroyPostProcess();
491
+ this.renderer.setAnimationLoop(null);
492
+ if (this.resizeObserver)
493
+ {
494
+ this.resizeObserver.disconnect();
495
+ this.resizeObserver = null;
496
+ }
497
+ if (this.labelRenderer)
498
+ {
499
+ this.labelRenderer.domElement.remove();
500
+ this.labelRenderer = null;
501
+ }
502
+ if (this._renderer)
503
+ {
504
+ this.renderer.domElement.remove();
505
+ this._renderer.dispose();
506
+ this._renderer = null;
507
+ }
508
+
509
+
510
+ this.postProcessing?.dispose();
511
+ this._canvas = null;
512
+ this._app = null;
513
+ this._renderer = null;
514
+ this.outlineObjects = [];
515
+ }
516
+ }
@@ -0,0 +1,59 @@
1
+ import {Scene} from "three";
2
+ import {ThreeJsApp} from "../ThreeJsApp.ts";
3
+ import { Viewport } from "./Viewport.ts";
4
+ import { Controller } from "./Controller.ts";
5
+ import { Actor } from "../Object/Actor.ts";
6
+
7
+ export class World
8
+ {
9
+ get scene():Scene
10
+ {
11
+ return this._scene;
12
+ }
13
+ get viewport(): Viewport
14
+ {
15
+ return this.app.viewport
16
+ }
17
+ get controller(): Controller
18
+ {
19
+ return this.app.controller
20
+ }
21
+ protected _scene:Scene
22
+ protected app:ThreeJsApp
23
+ protected actors:Set<Actor> = new Set()
24
+ constructor(app:ThreeJsApp,)
25
+ {
26
+ this.app = app
27
+ this._scene = new Scene();
28
+ }
29
+
30
+ init()
31
+ {
32
+
33
+ }
34
+
35
+ tick(deltaTime:number)
36
+ {
37
+ this.actors.forEach((elem)=>{
38
+ elem.tick(deltaTime)
39
+ })
40
+ }
41
+
42
+ addActor(actor:Actor)
43
+ {
44
+ if(!actor.rootComponent.threeObject)
45
+ {
46
+ throw Error("actor.threeObject is null")
47
+ }
48
+ actor.removeFromParent();
49
+ this.scene.add(actor.rootComponent.threeObject)
50
+ this.actors.add(actor)
51
+ actor.onAddedToWorld(this)
52
+ this.viewport.markRenderStateDirty()
53
+ }
54
+
55
+ destroy()
56
+ {
57
+
58
+ }
59
+ }