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,20 @@
1
+ import { ColorRepresentation} from "three";
2
+
3
+ export interface OutlineParams
4
+ {
5
+ edgeStrength : number;
6
+ edgeGlow : number;
7
+ edgeThickness : number;
8
+ pulsePeriod : number;
9
+ visibleEdgeColor: ColorRepresentation;
10
+ hiddenEdgeColor : ColorRepresentation;
11
+ }
12
+
13
+ export const DefaultOutlineParams = {
14
+ edgeStrength : 3.0,
15
+ edgeGlow : 1.0,
16
+ edgeThickness : 1.0,
17
+ pulsePeriod : 0.0,
18
+ visibleEdgeColor: 0xffffff,
19
+ hiddenEdgeColor : 0xffffff ,
20
+ }
@@ -0,0 +1,11 @@
1
+ export interface SSRParam {
2
+ maxDistance: number;
3
+ opacity : number;
4
+ thickness : number;
5
+ }
6
+
7
+ export const DefaultSSRParam: SSRParam = {
8
+ maxDistance: 0.5,
9
+ opacity : 1,
10
+ thickness : 0.015,
11
+ };
@@ -0,0 +1,31 @@
1
+ import {
2
+ ACESFilmicToneMapping,
3
+ AgXToneMapping,
4
+ CineonToneMapping,
5
+ LinearToneMapping, NeutralToneMapping,
6
+ NoToneMapping,
7
+ ReinhardToneMapping
8
+ } from "three";
9
+
10
+ export interface ToneMappingParams
11
+ {
12
+ exposure:number,
13
+ toneMapping:string
14
+ }
15
+
16
+ export const DefaultToneMappingParams = {
17
+ exposure: 1.0,
18
+ toneMapping: 'AgX',
19
+ }
20
+
21
+ export const ToneMappingOptions = new Map([
22
+ ["None", NoToneMapping],
23
+ ["Linear", LinearToneMapping],
24
+ ["Reinhard", ReinhardToneMapping],
25
+ ["Cineon", CineonToneMapping],
26
+ ["ACESFilmic", ACESFilmicToneMapping],
27
+ ["AgX", AgXToneMapping],
28
+ ["Neutral", NeutralToneMapping]
29
+ ])
30
+
31
+
@@ -0,0 +1,26 @@
1
+ 
2
+ import { SSRParam } from './Param/SSR';
3
+ import {GTAOParam} from "./Param/GTAO.ts";
4
+ import {BloomParam} from "./Param/Bloom.ts";
5
+ import {ToneMappingParams} from "./Param/ToneMapping.ts";
6
+ import {DOFParam} from "./Param/DOF.ts";
7
+ import { OutlineParams } from './Param/Outline.ts';
8
+
9
+ export interface PostProcessParam
10
+ {
11
+ toneMapping?: ToneMappingParams,
12
+ bloom ?: BloomParam|null,
13
+ dof ?: DOFParam|null,
14
+ // motionBlur ?: MotionBlurParam,
15
+ ssr ?: SSRParam|null,
16
+ gtao ?: GTAOParam|null,
17
+ outline ?: OutlineParams|null,
18
+ aa ?: "fxaa"|"smaa"|null
19
+ }
20
+
21
+ export const DefaultPostProcessParam:PostProcessParam = {
22
+ toneMapping: {
23
+ exposure: 1,
24
+ toneMapping:"AgX"
25
+ }
26
+ }
@@ -0,0 +1,217 @@
1
+ import { OutlineParams } from './Param/Outline';
2
+ import { Scene, Camera, Object3D } from "three";
3
+ import BloomNode, { bloom } from "three/examples/jsm/tsl/display/BloomNode.js";
4
+ import DenoiseNode, { denoise } from "three/examples/jsm/tsl/display/DenoiseNode.js";
5
+ import DepthOfFieldNode, { dof } from "three/examples/jsm/tsl/display/DepthOfFieldNode.js";
6
+ import GTAONode, { ao } from "three/examples/jsm/tsl/display/GTAONode.js";
7
+ import { ShaderNodeObject, pass, mrt, output, uniform, metalness, transformedNormalView, NodeRepresentation, normalView, depth, velocity } from "three/tsl";
8
+ import { PassNode, Node } from "three/webgpu";
9
+ import { BloomParam } from "./Param/Bloom";
10
+ import { DOFParam } from "./Param/DOF";
11
+ import { GTAOParam } from "./Param/GTAO";
12
+
13
+ import SSRNode, { ssr } from "three/examples/jsm/tsl/display/SSRNode.js";
14
+ import { SSRParam } from "./Param/SSR";
15
+ import { LensFlareParam } from "./Param/LensFlare";
16
+ import LensflareNode, { lensflare } from "three/examples/jsm/tsl/display/LensflareNode.js";
17
+ import OutlineNode, { outline } from "three/examples/jsm/tsl/display/OutlineNode.js";
18
+ import { motionBlur } from 'three/examples/jsm/tsl/display/MotionBlur.js';
19
+ import { MotionBlurParam } from './Param/MotionBlur';
20
+ import { fxaa } from 'three/examples/jsm/tsl/display/FXAANode.js';
21
+ import { smaa } from 'three/examples/jsm/tsl/display/SMAANode.js';
22
+ import { DenoiseParam } from './Param/Denoise';
23
+
24
+ export class WebGPUPostProcessFactory
25
+ {
26
+ // scene pass
27
+ static constructScenePass(scene: Scene, camera: Camera): ShaderNodeObject<PassNode>
28
+ {
29
+ const scenePass = pass(scene, camera);
30
+ scenePass.setMRT(mrt({
31
+ output: output,
32
+ }));
33
+ return scenePass;
34
+ }
35
+
36
+ static updateScenePass(scenePass: ShaderNodeObject<PassNode>, outputNodes: { [name: string]: Node })
37
+ {
38
+
39
+ let oldMRT = scenePass.getMRT();
40
+ let newMRT = mrt(outputNodes)
41
+ if (oldMRT)
42
+ {
43
+ scenePass.setMRT(oldMRT.merge(newMRT));
44
+ }
45
+ else
46
+ {
47
+ scenePass.setMRT(newMRT);
48
+ }
49
+ console.log(scenePass.getMRT(), "MRTTTTTTT");
50
+ }
51
+
52
+ // bloom pass
53
+ static constructBloomPass(scenePass: ShaderNodeObject<PassNode>, params: BloomParam): ShaderNodeObject<BloomNode>
54
+ {
55
+ const scenePassColor = scenePass.getTextureNode('output');
56
+ const bloomPass = bloom(scenePassColor);
57
+ WebGPUPostProcessFactory.updateBloomPass(bloomPass, params);
58
+ return bloomPass;
59
+ }
60
+
61
+ static updateBloomPass(bloomPass: ShaderNodeObject<BloomNode>, params: BloomParam)
62
+ {
63
+ bloomPass.threshold.value = params.threshold;
64
+ bloomPass.strength.value = params.strength;
65
+ bloomPass.radius.value = params.radius;
66
+ }
67
+
68
+ // DOF pass
69
+ static constructDOFPass(scenePass: ShaderNodeObject<PassNode>, params: DOFParam): ShaderNodeObject<DepthOfFieldNode>
70
+ {
71
+ const scenePassColor = scenePass.getTextureNode('output');
72
+ const scenePassViewZ = scenePass.getViewZNode();
73
+ return dof(scenePassColor, scenePassViewZ, uniform(params.focus), uniform(params.aperture).mul(0.00001), uniform(params.maxblur));
74
+ }
75
+
76
+ static updateDOFPass(dofPass: ShaderNodeObject<DepthOfFieldNode>, params: DOFParam)
77
+ {
78
+ dofPass.focus.value = params.focus;
79
+ dofPass.aperture.value = params.aperture * 0.00001;
80
+ dofPass.maxblur.value = params.maxblur;
81
+ }
82
+
83
+ // motion blur
84
+ static constructMotionBlurPass(lastNode:NodeRepresentation, scenePass: ShaderNodeObject<PassNode>, param:MotionBlurParam): ShaderNodeObject<Node>
85
+ {
86
+ WebGPUPostProcessFactory.updateScenePass(scenePass, {velocity})
87
+ const scenePassVelocity = scenePass.getTextureNode( 'velocity' ).mul( param.blurAmount );
88
+ const scenePassColor = scenePass.getTextureNode('output');
89
+ const motionBlurPass = motionBlur( scenePassColor, scenePassVelocity );
90
+ return motionBlurPass
91
+ }
92
+
93
+ // ssr
94
+ static constructSSRPass(scenePass: ShaderNodeObject<PassNode>, param: SSRParam): ShaderNodeObject<SSRNode>
95
+ {
96
+ WebGPUPostProcessFactory.updateScenePass(scenePass, {
97
+ normal : transformedNormalView,
98
+ metalness: metalness,
99
+ })
100
+ const scenePassColor = scenePass.getTextureNode('output');
101
+ const scenePassNormal = scenePass.getTextureNode('normal');
102
+ const scenePassDepth = scenePass.getTextureNode('depth');
103
+ const scenePassMetalness = scenePass.getTextureNode('metalness');
104
+ const ssrPass = ssr(scenePassColor, scenePassDepth, scenePassNormal, scenePassMetalness, scenePass.camera)
105
+ ssrPass.resolutionScale = 1.0;
106
+ WebGPUPostProcessFactory.updateSSRPass(ssrPass, param);
107
+ return ssrPass;
108
+ }
109
+
110
+ static updateSSRPass(ssrPass: ShaderNodeObject<SSRNode>, params: SSRParam)
111
+ {
112
+ ssrPass.maxDistance.value = params.maxDistance;
113
+ ssrPass.opacity.value = params.opacity;
114
+ ssrPass.thickness.value = params.thickness;
115
+ }
116
+
117
+ // GTAO
118
+ static constructGTAOPass(scenePass: ShaderNodeObject<PassNode>, params: GTAOParam): ShaderNodeObject<GTAONode>
119
+ {
120
+ WebGPUPostProcessFactory.updateScenePass(scenePass, {
121
+ normal: transformedNormalView,
122
+ })
123
+ const scenePassNormal = scenePass.getTextureNode('normal');
124
+ const scenePassDepth = scenePass.getTextureNode('depth');
125
+ const aoPass = ao(scenePassDepth, scenePassNormal, scenePass.camera);
126
+ aoPass.resolutionScale = 0.5;
127
+ WebGPUPostProcessFactory.updateGTAOPass(aoPass, params);
128
+ return aoPass;
129
+ }
130
+
131
+ static updateGTAOPass(gtaoPass: ShaderNodeObject<GTAONode>, params: GTAOParam)
132
+ {
133
+ gtaoPass.distanceExponent.value = params.distanceExponent;
134
+ gtaoPass.distanceFallOff.value = params.distanceFallOff;
135
+ gtaoPass.radius.value = params.radius;
136
+ gtaoPass.scale.value = params.scale;
137
+ gtaoPass.thickness.value = params.thickness;
138
+ }
139
+
140
+ static constructDenoisePass(scenePass: ShaderNodeObject<PassNode>, inputNode: NodeRepresentation, params: DenoiseParam): ShaderNodeObject<DenoiseNode>
141
+ {
142
+ WebGPUPostProcessFactory.updateScenePass(scenePass, {
143
+ normal: transformedNormalView,
144
+ })
145
+ const scenePassNormal = scenePass.getTextureNode('normal');
146
+ const scenePassDepth = scenePass.getTextureNode('depth');
147
+ const denoisePass = denoise(inputNode, scenePassDepth, scenePassNormal, scenePass.camera);
148
+ WebGPUPostProcessFactory.updateDenoisePass(denoisePass, params);
149
+ return denoisePass
150
+
151
+ }
152
+ static updateDenoisePass(denoisePass: ShaderNodeObject<DenoiseNode>, params: DenoiseParam)
153
+ {
154
+ denoisePass.radius.value = params.denoiseRadius;
155
+ denoisePass.lumaPhi.value = params.lumaPhi;
156
+ denoisePass.depthPhi.value = params.depthPhi;
157
+ denoisePass.normalPhi.value = params.normalPhi;
158
+ }
159
+
160
+ static constructGTAODenoisePass(scenePass: ShaderNodeObject<PassNode>, gtaoPass: ShaderNodeObject<GTAONode>, params: GTAOParam): ShaderNodeObject<DenoiseNode>
161
+ {
162
+ return WebGPUPostProcessFactory.constructDenoisePass(scenePass, gtaoPass.getTextureNode(), params.denoiseParam);
163
+ }
164
+
165
+ static updateGTAODenoisePass(denoisePass: ShaderNodeObject<DenoiseNode>, params: GTAOParam)
166
+ {
167
+ WebGPUPostProcessFactory.updateDenoisePass(denoisePass, params.denoiseParam);
168
+ }
169
+
170
+ static constructLensFlarePass(inputNode: NodeRepresentation, params: LensFlareParam): ShaderNodeObject<LensflareNode>
171
+ {
172
+ const lensflarePass = lensflare(inputNode, {
173
+ threshold : uniform(params.threshold),
174
+ ghostAttenuationFactor: uniform(params.ghostAttenuationFactor),
175
+ ghostSpacing : uniform(params.ghostSpacing),
176
+ });
177
+ return lensflarePass;
178
+ }
179
+
180
+ static updateLensFlarPass(lensflarePass: ShaderNodeObject<LensflareNode>, params: LensFlareParam)
181
+ {
182
+ lensflarePass.thresholdNode.value = params.threshold
183
+ lensflarePass.ghostSpacingNode.value = params.ghostSpacing
184
+ lensflarePass.ghostAttenuationFactorNode.value = params.ghostAttenuationFactor
185
+ }
186
+
187
+ static constructOutlinePass(scene: Scene, camera: Camera, outlineObjects:Object3D[], param:OutlineParams): ShaderNodeObject<OutlineNode>
188
+ {
189
+ const outlinePass = outline( scene, camera, {
190
+ selectedObjects: outlineObjects,
191
+ edgeGlow : param.edgeGlow,
192
+ edgeThickness : param.edgeThickness
193
+ } );
194
+ return outlinePass;
195
+ }
196
+
197
+ static updateOutlinePass(outlinePass: ShaderNodeObject<OutlineNode>, outlineObjects:Object3D[],params: OutlineParams)
198
+ {
199
+ outlinePass.edgeGlowNode.value = params.edgeGlow
200
+ outlinePass.edgeThicknessNode.value = params.edgeThickness
201
+ outlinePass.selectedObjects = outlineObjects
202
+ }
203
+
204
+ // fxaa
205
+ static constructFXAAPass(inputNode: NodeRepresentation)
206
+ {
207
+ return fxaa(inputNode)
208
+ }
209
+
210
+ // smaa
211
+ static constructSMAAPass(inputNode: NodeRepresentation)
212
+ {
213
+ return smaa(inputNode)
214
+ }
215
+
216
+
217
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Brightness and contrast adjustment
3
+ * https://github.com/evanw/glfx.js
4
+ * brightness: -1 to 1 (-1 is solid black, 0 is no change, and 1 is solid white)
5
+ * contrast: -1 to 1 (-1 is solid gray, 0 is no change, and 1 is maximum contrast)
6
+ */
7
+
8
+ const ColorShader = {
9
+
10
+ name: 'ColorShader',
11
+
12
+ uniforms: {
13
+ 'tDiffuse' : {value: null},
14
+ 'brightness': {value: 0.0},
15
+ 'contrast' : {value: 0},
16
+ 'saturation': {value: 1},
17
+ 'exposure' : {value: 1.0} // 新增的曝光uniform
18
+ },
19
+
20
+ vertexShader: /* glsl */`
21
+ varying vec2 vUv;
22
+ void main() {
23
+ vUv = uv;
24
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
25
+ }`,
26
+
27
+ fragmentShader: /* glsl */`
28
+
29
+ uniform sampler2D tDiffuse;
30
+ uniform float brightness;
31
+ uniform float contrast;
32
+ uniform float saturation;
33
+ uniform float exposure; // 新增的曝光uniform
34
+ varying vec2 vUv;
35
+
36
+ void main() {
37
+ gl_FragColor = texture2D( tDiffuse, vUv );
38
+ gl_FragColor.rgb *= exposure;
39
+ gl_FragColor.rgb += brightness;
40
+
41
+ gl_FragColor.rgb = (gl_FragColor.rgb - 0.5) * (1.0 + contrast) + 0.5;
42
+ vec3 grey = vec3(0.2126 * gl_FragColor.r + 0.7152 * gl_FragColor.g + 0.0722 * gl_FragColor.b); // 计算亮度(灰度)
43
+ gl_FragColor.rgb = mix(grey, gl_FragColor.rgb, saturation);;
44
+
45
+ }`
46
+
47
+ };
48
+
49
+ export {ColorShader};
@@ -0,0 +1,124 @@
1
+ 
2
+ import { DefaultPostProcessParam, PostProcessParam } from './PostProcess/PostProcessParam';
3
+ import {World} from "./Frame/World.ts";
4
+ import {Viewport} from "./Frame/Viewport.ts";
5
+ import {Controller} from "./Frame/Controller.ts";
6
+ import { Clock, OrthographicCamera, PerspectiveCamera} from "three";
7
+ import {CameraFactory, CameraParam} from "./Factory/CameraFactory.ts";
8
+ import { WebGPURendererParameters } from 'three/src/renderers/webgpu/WebGPURenderer.js';
9
+
10
+ export interface AppParam
11
+ {
12
+ renderParam ?: WebGPURendererParameters,
13
+ cameraParam ?: CameraParam,
14
+ postProcessParam?: PostProcessParam,
15
+ }
16
+
17
+ export const DefaultRenderParam:WebGPURendererParameters = {
18
+ antialias: true,
19
+ }
20
+ export const DefaultCameraParam:CameraParam = {
21
+ near : 0.1,
22
+ far : 1000,
23
+ param: {
24
+ fov : 50,
25
+ aspect: 1,
26
+ }
27
+ }
28
+ export const DefaultAppParam:AppParam = {
29
+ renderParam : DefaultRenderParam,
30
+ cameraParam : DefaultCameraParam,
31
+ postProcessParam: DefaultPostProcessParam,
32
+ }
33
+ export class ThreeJsApp
34
+ {
35
+ get camera(): PerspectiveCamera | OrthographicCamera
36
+ {
37
+ return this._camera;
38
+ }
39
+ get clock(): Clock
40
+ {
41
+ return this._clock;
42
+ }
43
+ get world(): World
44
+ {
45
+ return this._world;
46
+ }
47
+ get viewport(): Viewport
48
+ {
49
+ return this._viewport;
50
+ }
51
+ get controller(): Controller
52
+ {
53
+ return this._controller;
54
+ }
55
+
56
+ get worldClass()
57
+ {
58
+ return World
59
+ }
60
+ get viewportClass()
61
+ {
62
+ return Viewport
63
+ }
64
+ get controllerClass()
65
+ {
66
+ return Controller
67
+ }
68
+ protected _clock : Clock
69
+ protected _camera: PerspectiveCamera | OrthographicCamera
70
+ protected _world : World;
71
+ protected _viewport: Viewport;
72
+ protected _controller: Controller;
73
+
74
+ constructor(elementId:string, appParam:AppParam = DefaultAppParam)
75
+ {
76
+ this._clock = new Clock()
77
+ this._camera = CameraFactory.createCamera(appParam.cameraParam ? appParam.cameraParam : DefaultCameraParam)
78
+ this._world = new this.worldClass(this);
79
+ this._viewport = new this.viewportClass(this, elementId, appParam.renderParam ? appParam.renderParam:DefaultRenderParam, appParam.postProcessParam? appParam.postProcessParam:DefaultPostProcessParam);
80
+ this._controller = new this.controllerClass(this);
81
+
82
+ this.viewport.renderer.setAnimationLoop(()=>{
83
+ this.tick();
84
+ });
85
+
86
+ this.init();
87
+ }
88
+
89
+ init()
90
+ {
91
+ this.controller.init();
92
+ this.world.init();
93
+ this.viewport.init();
94
+ }
95
+
96
+ tick()
97
+ {
98
+ const delta = this._clock.getDelta();
99
+ this._controller.tick(delta);
100
+ this.world.tick(delta);
101
+ this.viewport.render();
102
+ }
103
+
104
+
105
+
106
+ onWindowResize(width:number, height:number)
107
+ {
108
+ if(this.camera instanceof PerspectiveCamera)
109
+ {
110
+ this.camera.aspect = width / height;
111
+ }
112
+ // if(this.camera instanceof OrthographicCamera)
113
+ // {
114
+ // // to do
115
+ // }
116
+ this.camera.updateProjectionMatrix();
117
+ }
118
+ destroy()
119
+ {
120
+ this.world.destroy();
121
+ this.controller.destroy();
122
+ this.viewport.destroy();
123
+ }
124
+ }
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "lythreeframe",
3
+ "version": "1.0.0",
4
+ "description": "my custom three ",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "dependencies": {
10
+ "@types/three": "^0.173.0",
11
+ "gsap": "^3.12.7",
12
+ "three": "^0.173.0"
13
+ },
14
+ "devDependencies": {
15
+ "@types/node": "^22.13.8",
16
+ "globals": "^16.0.0",
17
+ "typescript": "~5.6.2"
18
+ },
19
+ "author": "noegip",
20
+ "license": "ISC"
21
+ }