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.
- package/lythreeFrame/exporter.ts +36 -0
- package/lythreeFrame/src/AssetManagement/AssetDefines.ts +8 -0
- package/lythreeFrame/src/AssetManagement/AssetManager.ts +286 -0
- package/lythreeFrame/src/AssetManagement/AssetPointer/AssetPointer.ts +41 -0
- package/lythreeFrame/src/AssetManagement/Task/Task.ts +24 -0
- package/lythreeFrame/src/Container/SmartPointer.ts +54 -0
- package/lythreeFrame/src/Defines.ts +11 -0
- package/lythreeFrame/src/Delegate.ts +37 -0
- package/lythreeFrame/src/Factory/CameraFactory.ts +81 -0
- package/lythreeFrame/src/Factory/RendererFactory.ts +7 -0
- package/lythreeFrame/src/Frame/Controller.ts +261 -0
- package/lythreeFrame/src/Frame/Viewport.ts +516 -0
- package/lythreeFrame/src/Frame/World.ts +59 -0
- package/lythreeFrame/src/Frame.ts +511 -0
- package/lythreeFrame/src/Geometry/PlaneGeometry.ts +53 -0
- package/lythreeFrame/src/Geometry/TriangleGeometry.ts +50 -0
- package/lythreeFrame/src/Library/ContainerLibrary.ts +21 -0
- package/lythreeFrame/src/Library/MaterialLibrary.ts +288 -0
- package/lythreeFrame/src/Library/Math.ts +154 -0
- package/lythreeFrame/src/Library/ResourceLibrary.ts +21 -0
- package/lythreeFrame/src/Object/Actor.ts +571 -0
- package/lythreeFrame/src/Object/Actors/Camera/CameraActor.ts +11 -0
- package/lythreeFrame/src/Object/Actors/Light/DirectionalLightActor.ts +18 -0
- package/lythreeFrame/src/Object/Actors/Shape/BoxActor.ts +20 -0
- package/lythreeFrame/src/Object/Actors/Shape/CurveActor.ts +11 -0
- package/lythreeFrame/src/Object/Actors/Shape/PlaneActor.ts +27 -0
- package/lythreeFrame/src/Object/Actors/Shape/TubeActor.ts +37 -0
- package/lythreeFrame/src/Object/BaseObject.ts +45 -0
- package/lythreeFrame/src/Object/Components/2D/2DComponent.ts +64 -0
- package/lythreeFrame/src/Object/Components/Camera/CameraComponent.ts +113 -0
- package/lythreeFrame/src/Object/Components/Component.ts +67 -0
- package/lythreeFrame/src/Object/Components/Light/DirectionalLight/DirectionalLightComponent.ts +78 -0
- package/lythreeFrame/src/Object/Components/Light/LightComponent.ts +54 -0
- package/lythreeFrame/src/Object/Components/Mesh/InstanceMesh/InstanceMeshComponent.ts +39 -0
- package/lythreeFrame/src/Object/Components/Mesh/InstanceMesh/MultiInstanceMeshComponent.ts +115 -0
- package/lythreeFrame/src/Object/Components/Mesh/Line/CurveComponent.ts +221 -0
- package/lythreeFrame/src/Object/Components/Mesh/MeshComponent.ts +162 -0
- package/lythreeFrame/src/Object/Components/Mesh/Shape/BoxComponent.ts +17 -0
- package/lythreeFrame/src/Object/Components/Mesh/Shape/PlaneComponent.ts +10 -0
- package/lythreeFrame/src/Object/Components/Mesh/Shape/SphereComponent.ts +10 -0
- package/lythreeFrame/src/Object/Components/Mesh/Sprite/SpriteComponent.ts +32 -0
- package/lythreeFrame/src/Object/Components/SceneComponent.ts +809 -0
- package/lythreeFrame/src/Object/Controller/Controller.ts +764 -0
- package/lythreeFrame/src/Object/Pawn/CameraStatus.ts +262 -0
- package/lythreeFrame/src/Object/Pawn/FirstPerson.ts +230 -0
- package/lythreeFrame/src/Object/Pawn/Oribital.ts +276 -0
- package/lythreeFrame/src/Object/Pawn/PawnBase.ts +189 -0
- package/lythreeFrame/src/Object/Pawn/TopView.ts +205 -0
- package/lythreeFrame/src/Object/Pawn/TransformControl.ts +215 -0
- package/lythreeFrame/src/Object/Pawn/staticCamera.ts +80 -0
- package/lythreeFrame/src/Object/PawnV2/FirstPerson.ts +12 -0
- package/lythreeFrame/src/Object/PawnV2/Oribital.ts +45 -0
- package/lythreeFrame/src/Object/PawnV2/Pawn.ts +50 -0
- package/lythreeFrame/src/Object/PawnV2/TransformControl.ts +201 -0
- package/lythreeFrame/src/PostProcess/Param/Bloom.ts +12 -0
- package/lythreeFrame/src/PostProcess/Param/DOF.ts +14 -0
- package/lythreeFrame/src/PostProcess/Param/Denoise.ts +14 -0
- package/lythreeFrame/src/PostProcess/Param/GTAO.ts +21 -0
- package/lythreeFrame/src/PostProcess/Param/LensFlare.ts +11 -0
- package/lythreeFrame/src/PostProcess/Param/MotionBlur.ts +8 -0
- package/lythreeFrame/src/PostProcess/Param/Outline.ts +20 -0
- package/lythreeFrame/src/PostProcess/Param/SSR.ts +11 -0
- package/lythreeFrame/src/PostProcess/Param/ToneMapping.ts +31 -0
- package/lythreeFrame/src/PostProcess/PostProcessParam.ts +26 -0
- package/lythreeFrame/src/PostProcess/WebGPUPostProcessFactory.ts +217 -0
- package/lythreeFrame/src/Shader/Postprocess/ColorShader.ts +49 -0
- package/lythreeFrame/src/ThreeJsApp.ts +124 -0
- package/package.json +21 -0
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
// import {LYController} from './Object/Controller/Controller';
|
|
2
|
+
// import {Actor} from './Object/Actor';
|
|
3
|
+
|
|
4
|
+
// import {
|
|
5
|
+
// ACESFilmicToneMapping,
|
|
6
|
+
// Clock, FloatType,
|
|
7
|
+
// Mesh,
|
|
8
|
+
// PCFSoftShadowMap,
|
|
9
|
+
// RGBAFormat,
|
|
10
|
+
// Scene,
|
|
11
|
+
// SRGBColorSpace,
|
|
12
|
+
// Vector2,
|
|
13
|
+
// WebGLRenderer,
|
|
14
|
+
// WebGLRenderTarget,
|
|
15
|
+
// } from 'three';
|
|
16
|
+
// import {EffectComposer} from 'three/examples/jsm/postprocessing/EffectComposer';
|
|
17
|
+
// import {Octree} from "three/addons/math/Octree.js";
|
|
18
|
+
// import Stats from "three/addons/libs/stats.module.js";
|
|
19
|
+
// import {LYAssetManager} from "./AssetManagement/AssetManager.ts";
|
|
20
|
+
// import {CSS2DRenderer} from "three/examples/jsm/renderers/CSS2DRenderer";
|
|
21
|
+
|
|
22
|
+
// export class LYThreeApp
|
|
23
|
+
// {
|
|
24
|
+
// public world: LYThreeWorld;
|
|
25
|
+
// private assetManager: LYAssetManager | null
|
|
26
|
+
// constructor(elementName: string, bShowFPS: boolean)
|
|
27
|
+
// {
|
|
28
|
+
// this.world = new LYThreeWorld(this, elementName, bShowFPS);
|
|
29
|
+
// this.assetManager = LYAssetManager.Get()
|
|
30
|
+
// }
|
|
31
|
+
|
|
32
|
+
// get AssetManager(): LYAssetManager| null
|
|
33
|
+
// {
|
|
34
|
+
// return this.assetManager
|
|
35
|
+
// }
|
|
36
|
+
|
|
37
|
+
// get World(): LYThreeWorld
|
|
38
|
+
// {
|
|
39
|
+
// return this.world;
|
|
40
|
+
// }
|
|
41
|
+
|
|
42
|
+
// setTickEnabled(bEnabled: boolean): void
|
|
43
|
+
// {
|
|
44
|
+
// this.world.setTickEnabled(bEnabled);
|
|
45
|
+
// }
|
|
46
|
+
|
|
47
|
+
// destroy()
|
|
48
|
+
// {
|
|
49
|
+
// this.world.destroy()
|
|
50
|
+
// this.world = null
|
|
51
|
+
|
|
52
|
+
// this.AssetManager.clearAssets();
|
|
53
|
+
// this.assetManager = null
|
|
54
|
+
// }
|
|
55
|
+
// }
|
|
56
|
+
|
|
57
|
+
// export class LYThreeWorld
|
|
58
|
+
// {
|
|
59
|
+
|
|
60
|
+
// private _scene: Scene|null;
|
|
61
|
+
// protected objsInWorld: any[];
|
|
62
|
+
// protected elementId: string;
|
|
63
|
+
// protected bTickEnabled: boolean = true;
|
|
64
|
+
// private _renderer: WebGLRenderer | null;
|
|
65
|
+
// protected composer: EffectComposer;
|
|
66
|
+
// protected labelRenderer: CSS2DRenderer | null;
|
|
67
|
+
// protected controller: LYController | null;
|
|
68
|
+
// protected tickFuncs: any[] = [];
|
|
69
|
+
// protected clock: any;
|
|
70
|
+
|
|
71
|
+
// get App(): LYThreeApp
|
|
72
|
+
// {
|
|
73
|
+
// return this._app;
|
|
74
|
+
// }
|
|
75
|
+
// private _app: LYThreeApp;
|
|
76
|
+
|
|
77
|
+
// protected octree: Octree;
|
|
78
|
+
// protected bRenderStateDirty: boolean;
|
|
79
|
+
// protected stats: any;
|
|
80
|
+
// protected octreeHelper: any;
|
|
81
|
+
// protected bShowFPS: boolean = false
|
|
82
|
+
|
|
83
|
+
// private animationFrameHandle : any
|
|
84
|
+
// constructor(app: LYThreeApp, elementId: string, bShowFPS: boolean)
|
|
85
|
+
// {
|
|
86
|
+
// this.bShowFPS = bShowFPS;
|
|
87
|
+
// this._scene = new Scene();
|
|
88
|
+
// // const bgcolor = new Color(0x216c9d);
|
|
89
|
+
// // this.scene.background = bgcolor;
|
|
90
|
+
// // this.scene.fog = new Fog(bgcolor, 50, 300);
|
|
91
|
+
// this.objsInWorld = []
|
|
92
|
+
// this.elementId = elementId
|
|
93
|
+
// this._renderer = new WebGLRenderer({
|
|
94
|
+
// antialias: true,
|
|
95
|
+
// logarithmicDepthBuffer: true,
|
|
96
|
+
// });
|
|
97
|
+
|
|
98
|
+
// let ele = this.OuterElement;
|
|
99
|
+
// this._renderer.setPixelRatio(Math.max(1.1, window.devicePixelRatio));
|
|
100
|
+
// this._renderer.setSize(ele.clientWidth, ele.clientHeight);
|
|
101
|
+
// this._renderer.shadowMap.type = PCFSoftShadowMap
|
|
102
|
+
// this._renderer.shadowMap.enabled = true
|
|
103
|
+
// this._renderer.outputColorSpace = SRGBColorSpace;
|
|
104
|
+
// this._renderer.toneMapping = ACESFilmicToneMapping;
|
|
105
|
+
// this._renderer.domElement.className = 'scene-renderer';
|
|
106
|
+
// document.getElementById(elementId).appendChild(this._renderer.domElement)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
// this.labelRenderer = new CSS2DRenderer();
|
|
110
|
+
// this.labelRenderer.setSize(ele.clientWidth, ele.clientHeight);
|
|
111
|
+
// this.labelRenderer.domElement.style.pointerEvents = 'none';
|
|
112
|
+
// this.labelRenderer.domElement.style.position = 'absolute';
|
|
113
|
+
// this.labelRenderer.domElement.style.top = '0px';
|
|
114
|
+
// this.labelRenderer.domElement.className = 'scene-labelRenderer';
|
|
115
|
+
// document.getElementById(elementId).appendChild(this.labelRenderer.domElement)
|
|
116
|
+
|
|
117
|
+
// let instance = this;
|
|
118
|
+
// this.controller = new LYController(instance);
|
|
119
|
+
// this.controller.init()
|
|
120
|
+
|
|
121
|
+
// this.clock = new Clock();
|
|
122
|
+
// this._app = app;
|
|
123
|
+
|
|
124
|
+
// this.octree = null
|
|
125
|
+
// this.bRenderStateDirty = false
|
|
126
|
+
|
|
127
|
+
// this.composer = null
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
// if (this.bShowFPS)
|
|
131
|
+
// {
|
|
132
|
+
// console.log("create fps")
|
|
133
|
+
// // 创建性能监视器
|
|
134
|
+
// this.stats = new Stats()
|
|
135
|
+
|
|
136
|
+
// // 设置监视器面板,传入面板id(0: fps, 1: ms, 2: mb)
|
|
137
|
+
// this.stats.setMode(0)
|
|
138
|
+
|
|
139
|
+
// // 设置监视器位置
|
|
140
|
+
// this.stats.domElement.style.position = 'absolute'
|
|
141
|
+
// this.stats.domElement.style.left = '90%'
|
|
142
|
+
// this.stats.domElement.style.top = '90%'
|
|
143
|
+
// this.stats.domElement.className = 'stats'
|
|
144
|
+
|
|
145
|
+
// // 将监视器添加到页面中
|
|
146
|
+
// ele.appendChild(this.stats.domElement)
|
|
147
|
+
// }
|
|
148
|
+
// this.Controller?.onCameraChanged.add(()=>{
|
|
149
|
+
// if(!this.composer )
|
|
150
|
+
// {
|
|
151
|
+
// return
|
|
152
|
+
// }
|
|
153
|
+
// if(!this.Controller?.Camera)
|
|
154
|
+
// {
|
|
155
|
+
// return
|
|
156
|
+
// }
|
|
157
|
+
|
|
158
|
+
// for(let i in this.composer.passes)
|
|
159
|
+
// {
|
|
160
|
+
// const pass = this.composer.passes[i]
|
|
161
|
+
// if(pass.hasOwnProperty("camera"))
|
|
162
|
+
// {
|
|
163
|
+
// pass["camera"] = this.Controller.Camera
|
|
164
|
+
// continue
|
|
165
|
+
// }
|
|
166
|
+
// if(pass.hasOwnProperty("renderCamera"))
|
|
167
|
+
// {
|
|
168
|
+
// pass["renderCamera"] = this.Controller.Camera
|
|
169
|
+
// continue
|
|
170
|
+
// }
|
|
171
|
+
|
|
172
|
+
// }
|
|
173
|
+
// })
|
|
174
|
+
|
|
175
|
+
// this.tick();
|
|
176
|
+
// }
|
|
177
|
+
|
|
178
|
+
// get AssetManager(): LYAssetManager| null
|
|
179
|
+
// {
|
|
180
|
+
// return this._app.AssetManager;
|
|
181
|
+
// }
|
|
182
|
+
|
|
183
|
+
// get scene()
|
|
184
|
+
// {
|
|
185
|
+
// return this._scene;
|
|
186
|
+
// }
|
|
187
|
+
|
|
188
|
+
// setTickEnabled(bEnabled = true)
|
|
189
|
+
// {
|
|
190
|
+
// if(!this.bTickEnabled && bEnabled)
|
|
191
|
+
// {
|
|
192
|
+
// this.bTickEnabled = true
|
|
193
|
+
// this.tick()
|
|
194
|
+
// return;
|
|
195
|
+
// }
|
|
196
|
+
// this.bTickEnabled = bEnabled
|
|
197
|
+
// }
|
|
198
|
+
|
|
199
|
+
// get renderer(): WebGLRenderer|null
|
|
200
|
+
// {
|
|
201
|
+
// return this._renderer;
|
|
202
|
+
// }
|
|
203
|
+
|
|
204
|
+
// setLocalClippingEnabled(bEnabled:boolean)
|
|
205
|
+
// {
|
|
206
|
+
// if(!this.renderer)
|
|
207
|
+
// {
|
|
208
|
+
// return
|
|
209
|
+
// }
|
|
210
|
+
// if(bEnabled)
|
|
211
|
+
// {
|
|
212
|
+
// this.renderer.clippingPlanes = Object.freeze( [] );
|
|
213
|
+
// this.renderer.localClippingEnabled = true;
|
|
214
|
+
// }
|
|
215
|
+
// else
|
|
216
|
+
// {
|
|
217
|
+
// this.renderer.localClippingEnabled = false;
|
|
218
|
+
// }
|
|
219
|
+
// }
|
|
220
|
+
|
|
221
|
+
// get Element()
|
|
222
|
+
// {
|
|
223
|
+
// return this._renderer.domElement
|
|
224
|
+
// }
|
|
225
|
+
|
|
226
|
+
// get OuterElement()
|
|
227
|
+
// {
|
|
228
|
+
// return document.getElementById(this.elementId);
|
|
229
|
+
// }
|
|
230
|
+
|
|
231
|
+
// get Controller()
|
|
232
|
+
// {
|
|
233
|
+
// return this.controller;
|
|
234
|
+
// }
|
|
235
|
+
|
|
236
|
+
// get Composer()
|
|
237
|
+
// {
|
|
238
|
+
// return this.composer;
|
|
239
|
+
// }
|
|
240
|
+
|
|
241
|
+
// createComposer()
|
|
242
|
+
// {
|
|
243
|
+
// if(this.composer)
|
|
244
|
+
// {
|
|
245
|
+
// return
|
|
246
|
+
// }
|
|
247
|
+
// const renderer = this._renderer
|
|
248
|
+
// if(!renderer)
|
|
249
|
+
// {
|
|
250
|
+
// return
|
|
251
|
+
// }
|
|
252
|
+
// //添加后期渲染
|
|
253
|
+
// let size = new Vector2()
|
|
254
|
+
// renderer.getDrawingBufferSize(size)
|
|
255
|
+
// const renderTarget = new WebGLRenderTarget(size.width, size.height, {
|
|
256
|
+
// samples : 32,
|
|
257
|
+
// format : RGBAFormat,
|
|
258
|
+
// type : FloatType,
|
|
259
|
+
// colorSpace: SRGBColorSpace
|
|
260
|
+
// }
|
|
261
|
+
// )
|
|
262
|
+
// this.composer = new EffectComposer(renderer, renderTarget);
|
|
263
|
+
// let ele = this.OuterElement;
|
|
264
|
+
// this.composer.setPixelRatio(Math.max(1.1, window.devicePixelRatio));
|
|
265
|
+
// this.composer.setSize(ele.clientWidth, ele.clientHeight);
|
|
266
|
+
// }
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
// // onCameraChanged(newCamera)
|
|
270
|
+
// // {
|
|
271
|
+
// // if (!this.composer)
|
|
272
|
+
// // {
|
|
273
|
+
// // return;
|
|
274
|
+
// // }
|
|
275
|
+
// //
|
|
276
|
+
// // this.composer.passes.forEach((pass) =>
|
|
277
|
+
// // {
|
|
278
|
+
// // pass.camera = newCamera;
|
|
279
|
+
// // })
|
|
280
|
+
// // }
|
|
281
|
+
|
|
282
|
+
// buildOctree(group)
|
|
283
|
+
// {
|
|
284
|
+
// if (this.octreeHelper)
|
|
285
|
+
// {
|
|
286
|
+
// this._scene.remove(this.octreeHelper)
|
|
287
|
+
// this.octreeHelper = null
|
|
288
|
+
// }
|
|
289
|
+
// this.octree = new Octree();
|
|
290
|
+
// if (group)
|
|
291
|
+
// {
|
|
292
|
+
// this.octree.fromGraphNode(group)
|
|
293
|
+
// }
|
|
294
|
+
// // this.#octreeHelper = new OctreeHelper( this.#octree );
|
|
295
|
+
// // this.scene.add( this.#octreeHelper );
|
|
296
|
+
// this.markRenderStateDirty();
|
|
297
|
+
// }
|
|
298
|
+
|
|
299
|
+
// get Octree()
|
|
300
|
+
// {
|
|
301
|
+
// return this.octree
|
|
302
|
+
// }
|
|
303
|
+
|
|
304
|
+
// addActor(Obj:Actor)
|
|
305
|
+
// {
|
|
306
|
+
// if (Obj instanceof Actor)
|
|
307
|
+
// {
|
|
308
|
+
// this.objsInWorld.push(Obj)
|
|
309
|
+
// this.scene.add(Obj.RootComponent.threeObject)
|
|
310
|
+
// Obj.onAddedToWorld(this);
|
|
311
|
+
// this.markRenderStateDirty();
|
|
312
|
+
// } else
|
|
313
|
+
// {
|
|
314
|
+
// console.log("Trying to add obj in scene whitch is not a LYBaseActor");
|
|
315
|
+
// console.log(Obj)
|
|
316
|
+
// }
|
|
317
|
+
// }
|
|
318
|
+
|
|
319
|
+
// removeActor(Obj)
|
|
320
|
+
// {
|
|
321
|
+
// if (Obj instanceof Actor)
|
|
322
|
+
// {
|
|
323
|
+
// let index = this.objsInWorld.indexOf(Obj);
|
|
324
|
+
// if (index !== -1)
|
|
325
|
+
// {
|
|
326
|
+
// this.objsInWorld.splice(index, 1);
|
|
327
|
+
// }
|
|
328
|
+
|
|
329
|
+
// Obj.onRemovedFromWorld();
|
|
330
|
+
// } else
|
|
331
|
+
// {
|
|
332
|
+
// console.log("Trying to remove obj from scene whitch is not a LYBaseActor");
|
|
333
|
+
// }
|
|
334
|
+
// }
|
|
335
|
+
|
|
336
|
+
// getSceneObjectCount()
|
|
337
|
+
// {
|
|
338
|
+
|
|
339
|
+
// }
|
|
340
|
+
|
|
341
|
+
// markRenderStateDirty()
|
|
342
|
+
// {
|
|
343
|
+
// this.bRenderStateDirty = true;
|
|
344
|
+
// }
|
|
345
|
+
|
|
346
|
+
// /* Should not be called directly*/
|
|
347
|
+
// getObjChildren(obj, layer = 0)
|
|
348
|
+
// {
|
|
349
|
+
// if (obj.isObject3D)
|
|
350
|
+
// {
|
|
351
|
+
// let space = ''
|
|
352
|
+
// for (let i = 0; i < layer; ++i)
|
|
353
|
+
// {
|
|
354
|
+
// space += ' '
|
|
355
|
+
// }
|
|
356
|
+
|
|
357
|
+
// if (obj.children.length > 0)
|
|
358
|
+
// {
|
|
359
|
+
|
|
360
|
+
// for (let index in obj.children)
|
|
361
|
+
// {
|
|
362
|
+
// this.getObjChildren(obj.children[index], layer + 1);
|
|
363
|
+
// }
|
|
364
|
+
// }
|
|
365
|
+
// }
|
|
366
|
+
|
|
367
|
+
// }
|
|
368
|
+
|
|
369
|
+
// getObjsInWorld()
|
|
370
|
+
// {
|
|
371
|
+
// return this.objsInWorld
|
|
372
|
+
// }
|
|
373
|
+
|
|
374
|
+
// tick()
|
|
375
|
+
// {
|
|
376
|
+
// let instance = this;
|
|
377
|
+
|
|
378
|
+
// if (!this.bTickEnabled) {
|
|
379
|
+
// return;
|
|
380
|
+
// }
|
|
381
|
+
// // tick logic
|
|
382
|
+
// const delta = this.clock.getDelta() // 获取自上次调用的时间
|
|
383
|
+
|
|
384
|
+
// for (let i = 0; i < this.objsInWorld.length; ++i)
|
|
385
|
+
// {
|
|
386
|
+
// this.objsInWorld[i].tick(delta)
|
|
387
|
+
// }
|
|
388
|
+
|
|
389
|
+
// for (let i = 0; i < this.tickFuncs.length; ++i)
|
|
390
|
+
// {
|
|
391
|
+
// this.tickFuncs[i](delta)
|
|
392
|
+
// }
|
|
393
|
+
// this.Controller.tick(delta)
|
|
394
|
+
// // tick render
|
|
395
|
+
// if (this.bRenderStateDirty)
|
|
396
|
+
// {
|
|
397
|
+
// if(this.controller.Camera)
|
|
398
|
+
// {
|
|
399
|
+
// this.labelRenderer.render(this._scene, this.controller.Camera);
|
|
400
|
+
|
|
401
|
+
// if (this.composer)
|
|
402
|
+
// {
|
|
403
|
+
// this.composer.render(delta);
|
|
404
|
+
// }
|
|
405
|
+
// else
|
|
406
|
+
// {
|
|
407
|
+
// this._renderer.render(this._scene, this.controller.Camera);
|
|
408
|
+
// }
|
|
409
|
+
// this.bRenderStateDirty = false
|
|
410
|
+
// }
|
|
411
|
+
// }
|
|
412
|
+
|
|
413
|
+
// if (this.stats)
|
|
414
|
+
// {
|
|
415
|
+
// this.stats.update()
|
|
416
|
+
// }
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
// this.animationFrameHandle = window.requestAnimationFrame(
|
|
420
|
+
// () =>
|
|
421
|
+
// {
|
|
422
|
+
// instance.tick();
|
|
423
|
+
// }
|
|
424
|
+
// );
|
|
425
|
+
// }
|
|
426
|
+
|
|
427
|
+
// onLoadGLTFFinished(loadedActor, levelName)
|
|
428
|
+
// {
|
|
429
|
+
|
|
430
|
+
// }
|
|
431
|
+
|
|
432
|
+
// postProcess()
|
|
433
|
+
// {
|
|
434
|
+
|
|
435
|
+
// }
|
|
436
|
+
|
|
437
|
+
// addTickFunc(newFunc)
|
|
438
|
+
// {
|
|
439
|
+
// let index = this.tickFuncs.indexOf(newFunc)
|
|
440
|
+
// if (index >= 0)
|
|
441
|
+
// {
|
|
442
|
+
// return
|
|
443
|
+
// }
|
|
444
|
+
// this.tickFuncs.push(newFunc);
|
|
445
|
+
// }
|
|
446
|
+
|
|
447
|
+
// removeTickFunc(target)
|
|
448
|
+
// {
|
|
449
|
+
// let index = this.tickFuncs.indexOf(target)
|
|
450
|
+
// if (index >= 0)
|
|
451
|
+
// {
|
|
452
|
+
// this.tickFuncs.splice(index, 1)
|
|
453
|
+
// }
|
|
454
|
+
// }
|
|
455
|
+
|
|
456
|
+
// destroy()
|
|
457
|
+
// {
|
|
458
|
+
// console.log("World is destroying")
|
|
459
|
+
// this.tickFuncs = []
|
|
460
|
+
// window.cancelAnimationFrame(this.animationFrameHandle)
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
// this._scene?.traverse((elem) =>
|
|
464
|
+
// {
|
|
465
|
+
// if (elem instanceof Mesh)
|
|
466
|
+
// {
|
|
467
|
+
// if (elem.material)
|
|
468
|
+
// {
|
|
469
|
+
// let arr = elem.material instanceof Array ? elem.material : [elem.material]
|
|
470
|
+
|
|
471
|
+
// arr.forEach((mat) =>
|
|
472
|
+
// {
|
|
473
|
+
// mat.dispose()
|
|
474
|
+
// mat = null
|
|
475
|
+
// })
|
|
476
|
+
// }
|
|
477
|
+
// if (elem.geometry)
|
|
478
|
+
// {
|
|
479
|
+
// elem.geometry.dispose()
|
|
480
|
+
|
|
481
|
+
// }
|
|
482
|
+
// }
|
|
483
|
+
// })
|
|
484
|
+
// // for (let i in this.objsInWorld)
|
|
485
|
+
// // {
|
|
486
|
+
// // this.objsInWorld[i].destroy();
|
|
487
|
+
// // }
|
|
488
|
+
// //
|
|
489
|
+
// this._scene.clear()
|
|
490
|
+
// this._scene = null
|
|
491
|
+
// this.controller?.destroy()
|
|
492
|
+
// this.controller = null;
|
|
493
|
+
|
|
494
|
+
// this._renderer.forceContextLoss();
|
|
495
|
+
// this._renderer.context = null;
|
|
496
|
+
// this._renderer.domElement = null;
|
|
497
|
+
// this._renderer.dispose()
|
|
498
|
+
|
|
499
|
+
// this.labelRenderer.context = null;
|
|
500
|
+
// this.labelRenderer.domElement = null;
|
|
501
|
+
// this.labelRenderer = null;
|
|
502
|
+
// this.composer?.dispose()
|
|
503
|
+
// this.composer = null;
|
|
504
|
+
// }
|
|
505
|
+
|
|
506
|
+
// renderAsImage() {
|
|
507
|
+
// let image = new Image();
|
|
508
|
+
// this.renderer.render(this._scene, this.controller.Camera); //此处renderer为three.js里的渲染器,scene为场景 camera为相机
|
|
509
|
+
// return this.renderer.domElement.toDataURL('image/jpeg');
|
|
510
|
+
// }
|
|
511
|
+
// }
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// 创建顶点位置数组
|
|
2
|
+
import {
|
|
3
|
+
BufferAttribute,
|
|
4
|
+
BufferGeometry,
|
|
5
|
+
Float32BufferAttribute,
|
|
6
|
+
Uint16BufferAttribute,
|
|
7
|
+
} from 'three';
|
|
8
|
+
|
|
9
|
+
function createPlaneGeometryFaceUp():BufferGeometry
|
|
10
|
+
{
|
|
11
|
+
const vertices = [
|
|
12
|
+
-0.5,
|
|
13
|
+
0,
|
|
14
|
+
-0.5, // 顶点1
|
|
15
|
+
0.5,
|
|
16
|
+
0,
|
|
17
|
+
-0.5, // 顶点2
|
|
18
|
+
0.5,
|
|
19
|
+
0,
|
|
20
|
+
0.5, // 顶点3
|
|
21
|
+
-0.5,
|
|
22
|
+
0,
|
|
23
|
+
0.5, // 顶点4
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
// 创建法线数组,所有法线都朝向Y轴正方向
|
|
27
|
+
const normals = [0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0];
|
|
28
|
+
|
|
29
|
+
// 创建索引数组,用于确定顶点如何连接成三角形
|
|
30
|
+
const indices = [0, 2, 1, 2, 0, 3];
|
|
31
|
+
const uvs = new Float32Array([
|
|
32
|
+
0,
|
|
33
|
+
0, //图片左下角
|
|
34
|
+
1,
|
|
35
|
+
0, //图片右下角
|
|
36
|
+
1,
|
|
37
|
+
1, //图片右上角
|
|
38
|
+
0,
|
|
39
|
+
1, //图片左上角
|
|
40
|
+
]);
|
|
41
|
+
// 创建BufferPlaneGeometryFaceUp
|
|
42
|
+
const PlaneGeometryFaceUp = new BufferGeometry();
|
|
43
|
+
const positionAttribute = new Float32BufferAttribute(vertices, 3);
|
|
44
|
+
const normalAttribute = new Float32BufferAttribute(normals, 3);
|
|
45
|
+
const indexAttribute = new Uint16BufferAttribute(indices, 1);
|
|
46
|
+
PlaneGeometryFaceUp.attributes.uv = new BufferAttribute(uvs, 2);
|
|
47
|
+
PlaneGeometryFaceUp.setAttribute('position', positionAttribute);
|
|
48
|
+
PlaneGeometryFaceUp.setAttribute('normal', normalAttribute);
|
|
49
|
+
PlaneGeometryFaceUp.setIndex(indexAttribute);
|
|
50
|
+
return PlaneGeometryFaceUp
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { createPlaneGeometryFaceUp };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// 创建顶点位置数组
|
|
2
|
+
import {
|
|
3
|
+
BufferAttribute,
|
|
4
|
+
BufferGeometry,
|
|
5
|
+
Float32BufferAttribute,
|
|
6
|
+
Uint16BufferAttribute,
|
|
7
|
+
} from 'three';
|
|
8
|
+
|
|
9
|
+
function createArrowHeadGeometry():BufferGeometry
|
|
10
|
+
{
|
|
11
|
+
const vertices = [
|
|
12
|
+
-0.5,
|
|
13
|
+
0,
|
|
14
|
+
0, // 顶点1
|
|
15
|
+
0,
|
|
16
|
+
0,
|
|
17
|
+
0.5, // 顶点2
|
|
18
|
+
0.5,
|
|
19
|
+
0,
|
|
20
|
+
0, // 顶点3
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
// 创建法线数组,所有法线都朝向Y轴正方向
|
|
24
|
+
const normals = [0, 1, 0, 0, 1, 0, 0, 1, 0];
|
|
25
|
+
|
|
26
|
+
// 创建索引数组,用于确定顶点如何连接成三角形
|
|
27
|
+
const indices = [0, 1, 2];
|
|
28
|
+
const uvs = new Float32Array([
|
|
29
|
+
0,
|
|
30
|
+
0, //图片左下角
|
|
31
|
+
1,
|
|
32
|
+
0, //图片右下角
|
|
33
|
+
1,
|
|
34
|
+
1, //图片右上角
|
|
35
|
+
0,
|
|
36
|
+
1, //图片左上角
|
|
37
|
+
]);
|
|
38
|
+
// 创建BufferPlaneGeometryFaceUp
|
|
39
|
+
const PlaneGeometryFaceUp = new BufferGeometry();
|
|
40
|
+
const positionAttribute = new Float32BufferAttribute(vertices, 3);
|
|
41
|
+
const normalAttribute = new Float32BufferAttribute(normals, 3);
|
|
42
|
+
const indexAttribute = new Uint16BufferAttribute(indices, 1);
|
|
43
|
+
PlaneGeometryFaceUp.attributes.uv = new BufferAttribute(uvs, 2);
|
|
44
|
+
PlaneGeometryFaceUp.setAttribute('position', positionAttribute);
|
|
45
|
+
PlaneGeometryFaceUp.setAttribute('normal', normalAttribute);
|
|
46
|
+
PlaneGeometryFaceUp.setIndex(indexAttribute);
|
|
47
|
+
return PlaneGeometryFaceUp
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { createArrowHeadGeometry };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class LYContainerLibrary
|
|
2
|
+
{
|
|
3
|
+
static AreUnorderedArrayEqual(arr1: any[], arr2: any[]): boolean {
|
|
4
|
+
// 首先检查数组长度是否相同
|
|
5
|
+
if (arr1.length !== arr2.length) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// 对两个数组进行排序,然后比较每一个元素
|
|
10
|
+
const sortedArr1 = [...arr1].sort();
|
|
11
|
+
const sortedArr2 = [...arr2].sort();
|
|
12
|
+
|
|
13
|
+
for (let i = 0; i < sortedArr1.length; i++) {
|
|
14
|
+
if (sortedArr1[i] !== sortedArr2[i]) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
}
|