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,36 @@
|
|
|
1
|
+
// Loading functionality
|
|
2
|
+
export {LYLoadTask} from "./src/AssetManagement/Task/Task";
|
|
3
|
+
export {LYAssetManager} from "./src/AssetManagement/AssetManager";
|
|
4
|
+
|
|
5
|
+
// Tools
|
|
6
|
+
export {LYMaterialLibrary} from "./src/Library/MaterialLibrary";
|
|
7
|
+
export {AttachmentRules} from "./src/Defines";
|
|
8
|
+
export {Delegate as LYDelegate} from "./src/Delegate";
|
|
9
|
+
|
|
10
|
+
// FrameRoot
|
|
11
|
+
export {ThreeJsApp} from "./src/ThreeJsApp";
|
|
12
|
+
export {Controller} from "./src/Frame/Controller";
|
|
13
|
+
|
|
14
|
+
// Actors
|
|
15
|
+
export {Actor} from "./src/Object/Actor";
|
|
16
|
+
export {DirectionalLightActor} from "./src/Object/Actors/Light/DirectionalLightActor";
|
|
17
|
+
export {BoxActor} from "./src/Object/Actors/Shape/BoxActor";
|
|
18
|
+
export {PlaneActor} from "./src/Object/Actors/Shape/PlaneActor";
|
|
19
|
+
|
|
20
|
+
// Components
|
|
21
|
+
export {SceneComponent} from "./src/Object/Components/SceneComponent";
|
|
22
|
+
export {MeshComponent} from "./src/Object/Components/Mesh/MeshComponent";
|
|
23
|
+
export {BoxComponent} from "./src/Object/Components/Mesh/Shape/BoxComponent";
|
|
24
|
+
export {PlaneComponent} from "./src/Object/Components/Mesh/Shape/PlaneComponent";
|
|
25
|
+
export {SphereComponent} from "./src/Object/Components/Mesh/Shape/SphereComponent";
|
|
26
|
+
|
|
27
|
+
export {DirectionalLightComponent} from "./src/Object/Components/Light/DirectionalLight/DirectionalLightComponent";
|
|
28
|
+
export {LabelComponent} from "./src/Object/Components/2D/2DComponent";
|
|
29
|
+
|
|
30
|
+
// Pawn
|
|
31
|
+
export {Orbital} from "./src/Object/PawnV2/Oribital";
|
|
32
|
+
export {FirstPerson} from "./src/Object/PawnV2/FirstPerson";
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
// Shader
|
|
36
|
+
export {ColorShader} from "./src/Shader/Postprocess/ColorShader";
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import {BufferGeometry, FileLoader, LoadingManager, Material, Mesh, Texture,} from 'three';
|
|
2
|
+
import {MeshComponent} from "../Object/Components/Mesh/MeshComponent";
|
|
3
|
+
import {SceneComponent} from "../Object/Components/SceneComponent.ts";
|
|
4
|
+
import {LYLoadTask} from "./Task/Task.ts";
|
|
5
|
+
import {TAssetPointer} from "./AssetPointer/AssetPointer.ts";
|
|
6
|
+
import { DRACOLoader, GLTF, GLTFLoader } from 'three/examples/jsm/Addons.js';
|
|
7
|
+
|
|
8
|
+
// this class should be a singleton
|
|
9
|
+
export class LYAssetManager
|
|
10
|
+
{
|
|
11
|
+
protected assetPointer:Map<string, TAssetPointer<BufferGeometry | Texture | Material>> = new Map();
|
|
12
|
+
protected readonly dracoLoader:DRACOLoader;
|
|
13
|
+
protected readonly gltfLoader:GLTFLoader;
|
|
14
|
+
protected readonly loadingManager:LoadingManager;
|
|
15
|
+
|
|
16
|
+
constructor()
|
|
17
|
+
{
|
|
18
|
+
this.dracoLoader = new DRACOLoader();
|
|
19
|
+
this.dracoLoader.setDecoderPath(`./SceneResource/draco/`);
|
|
20
|
+
this.dracoLoader.setDecoderConfig({type:"js"});
|
|
21
|
+
this.dracoLoader.preload();
|
|
22
|
+
|
|
23
|
+
this.loadingManager = new LoadingManager();
|
|
24
|
+
|
|
25
|
+
this.gltfLoader = new GLTFLoader(this.loadingManager);
|
|
26
|
+
this.gltfLoader.setDRACOLoader(this.dracoLoader);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get LoadingManager():LoadingManager
|
|
30
|
+
{
|
|
31
|
+
return this.loadingManager;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static Get()
|
|
35
|
+
{
|
|
36
|
+
return assetManager;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static ClearAssets()
|
|
40
|
+
{
|
|
41
|
+
assetManager.clearAssets();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
convertThreeObjectToLYObject(parentLYComponent:SceneComponent, threejsObject:any):SceneComponent | null
|
|
45
|
+
{
|
|
46
|
+
let location = threejsObject.position.clone();
|
|
47
|
+
let rotation = threejsObject.rotation.clone();
|
|
48
|
+
let scale = threejsObject.scale.clone();
|
|
49
|
+
|
|
50
|
+
let newComp = null;
|
|
51
|
+
let children = threejsObject.children;
|
|
52
|
+
threejsObject.children = [];
|
|
53
|
+
if (threejsObject.type === "Group" || threejsObject.type === "Object3D")
|
|
54
|
+
{
|
|
55
|
+
newComp = new SceneComponent(threejsObject);
|
|
56
|
+
}
|
|
57
|
+
else if (threejsObject.isMesh)
|
|
58
|
+
{
|
|
59
|
+
let obj = threejsObject as Mesh;
|
|
60
|
+
newComp = new MeshComponent(obj);
|
|
61
|
+
// assetManager.#collectMatAndGeoInMesh(threejsObject)
|
|
62
|
+
threejsObject.layers.set(0);
|
|
63
|
+
}
|
|
64
|
+
else
|
|
65
|
+
{
|
|
66
|
+
newComp = new SceneComponent(threejsObject);
|
|
67
|
+
}
|
|
68
|
+
if (newComp === null)
|
|
69
|
+
{
|
|
70
|
+
threejsObject.children = children;
|
|
71
|
+
//threejsObject.parent = parent
|
|
72
|
+
console.log("Unprocess", threejsObject);
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
parentLYComponent.addChildComponent(newComp);
|
|
76
|
+
|
|
77
|
+
newComp.setPosition(location);
|
|
78
|
+
newComp.setRotation(rotation);
|
|
79
|
+
newComp.setScale(scale);
|
|
80
|
+
for (let i = 0; i < children.length; ++i)
|
|
81
|
+
{
|
|
82
|
+
this.convertThreeObjectToLYObject(newComp, children[i]);
|
|
83
|
+
}
|
|
84
|
+
return threejsObject.userData.LYObject;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private collectResourcesAndReferences(gltf:GLTF)
|
|
88
|
+
{
|
|
89
|
+
function countResource(map:Map<any, number>, resource:any)
|
|
90
|
+
{
|
|
91
|
+
if (!map.has(resource))
|
|
92
|
+
{
|
|
93
|
+
map.set(resource, 1);
|
|
94
|
+
}
|
|
95
|
+
else
|
|
96
|
+
{
|
|
97
|
+
map.set(resource, map.get(resource)! + 1);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const resources = {
|
|
102
|
+
geometries:new Map<BufferGeometry, number>(),
|
|
103
|
+
materials :new Map<Material, number>(),
|
|
104
|
+
textures :new Map<Texture, number>()
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
gltf.scene.traverse((child:any) =>
|
|
109
|
+
{
|
|
110
|
+
if (child.geometry && child.geometry instanceof BufferGeometry)
|
|
111
|
+
{
|
|
112
|
+
countResource(resources.geometries, child.geometry);
|
|
113
|
+
}
|
|
114
|
+
if (child.material)
|
|
115
|
+
{
|
|
116
|
+
const mats = Array.isArray(child.material) ? child.material : [child.material];
|
|
117
|
+
mats.forEach((mat:Material|null) =>
|
|
118
|
+
{
|
|
119
|
+
if (mat)
|
|
120
|
+
{
|
|
121
|
+
countResource(resources.materials, mat);
|
|
122
|
+
Object.entries(mat).forEach(([key, value]) =>
|
|
123
|
+
{
|
|
124
|
+
if (value instanceof Texture)
|
|
125
|
+
{
|
|
126
|
+
countResource(resources.textures, value);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
function createPointer(manager:LYAssetManager, map:Map<BufferGeometry | Material | Texture, number>)
|
|
136
|
+
{
|
|
137
|
+
map.forEach((value, key:BufferGeometry | Material | Texture) =>
|
|
138
|
+
{
|
|
139
|
+
manager.addAsset(key, value);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
createPointer(this, resources.geometries);
|
|
144
|
+
createPointer(this, resources.materials);
|
|
145
|
+
createPointer(this, resources.textures);
|
|
146
|
+
|
|
147
|
+
// console.log('Geometries:', Array.from(resources.geometries.entries()));
|
|
148
|
+
// console.log('Materials:', Array.from(resources.materials.entries()));
|
|
149
|
+
// console.log('Textures:', Array.from(resources.textures.entries()));
|
|
150
|
+
// console.log('assetPointer:', this.assetPointer);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
public checkMeshResource(mesh:Mesh)
|
|
154
|
+
{
|
|
155
|
+
if(mesh.geometry)
|
|
156
|
+
{
|
|
157
|
+
if(!mesh.geometry.userData["assetPointer"])
|
|
158
|
+
{
|
|
159
|
+
this.addAsset(mesh.geometry)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if(mesh.material)
|
|
164
|
+
{
|
|
165
|
+
const mats = Array.isArray(mesh.material) ? mesh.material : [mesh.material];
|
|
166
|
+
mats.forEach((material) => {
|
|
167
|
+
if (material)
|
|
168
|
+
{
|
|
169
|
+
if(!material.userData["assetPointer"])
|
|
170
|
+
{
|
|
171
|
+
this.addAsset(material)
|
|
172
|
+
}
|
|
173
|
+
Object.entries(material).forEach(([key, value]) => {
|
|
174
|
+
if (value instanceof Texture)
|
|
175
|
+
{
|
|
176
|
+
if(!value.userData["assetPointer"])
|
|
177
|
+
{
|
|
178
|
+
this.addAsset(value)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
loadMultiGLTFAsGroup(tasks:LYLoadTask[], onProgress:((url:string, loaded:number, total:number) => void) | null = null, onAllFinished:(() => void) | null = null)
|
|
188
|
+
{
|
|
189
|
+
this.loadingManager.onLoad = onAllFinished ? () =>
|
|
190
|
+
{
|
|
191
|
+
this.loadingManager.onLoad = () =>
|
|
192
|
+
{
|
|
193
|
+
};
|
|
194
|
+
onAllFinished();
|
|
195
|
+
} : () =>
|
|
196
|
+
{
|
|
197
|
+
this.loadingManager.onLoad = () =>
|
|
198
|
+
{
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
this.loadingManager.onProgress = onProgress ? (url, loaded, total) =>
|
|
202
|
+
{
|
|
203
|
+
onProgress(url, loaded, total);
|
|
204
|
+
} : () =>
|
|
205
|
+
{
|
|
206
|
+
};
|
|
207
|
+
tasks.forEach(
|
|
208
|
+
(task) =>
|
|
209
|
+
{
|
|
210
|
+
task.Paths.forEach(
|
|
211
|
+
(path) =>
|
|
212
|
+
{
|
|
213
|
+
const onGlbLoaded = (glb:GLTF) =>
|
|
214
|
+
{
|
|
215
|
+
task.onLoadingFinished(glb);
|
|
216
|
+
this.collectResourcesAndReferences(glb);
|
|
217
|
+
};
|
|
218
|
+
try
|
|
219
|
+
{
|
|
220
|
+
this.gltfLoader.load(path, (glb:GLTF) =>
|
|
221
|
+
{
|
|
222
|
+
onGlbLoaded(glb);
|
|
223
|
+
});
|
|
224
|
+
} catch (e)
|
|
225
|
+
{
|
|
226
|
+
console.error(e, path);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
loadFile(filepath = '', onLoadFinished:(data:any)=>void)
|
|
234
|
+
{
|
|
235
|
+
const loader = new FileLoader();
|
|
236
|
+
loader.load(filepath, (data) =>
|
|
237
|
+
{
|
|
238
|
+
onLoadFinished(data);
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
addAsset(asset:BufferGeometry | Material | Texture, referenceCount:number = 1)
|
|
243
|
+
{
|
|
244
|
+
let pointer:TAssetPointer<BufferGeometry | Material | Texture> | null = null;
|
|
245
|
+
if (!asset.userData["assetPointer"])
|
|
246
|
+
{
|
|
247
|
+
pointer = new TAssetPointer(asset, referenceCount);
|
|
248
|
+
asset.userData["assetPointer"] = pointer;
|
|
249
|
+
}
|
|
250
|
+
else
|
|
251
|
+
{
|
|
252
|
+
pointer = asset.userData["assetPointer"] as TAssetPointer<BufferGeometry | Material | Texture>;
|
|
253
|
+
pointer.addRef(referenceCount);
|
|
254
|
+
}
|
|
255
|
+
if (pointer)
|
|
256
|
+
{
|
|
257
|
+
this.assetPointer.set(pointer.uuid, pointer);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
releaseAsset(asset:BufferGeometry | Material | Texture)
|
|
262
|
+
{
|
|
263
|
+
// let uuid = asset.uuid
|
|
264
|
+
let p = asset.userData["assetPointer"] as TAssetPointer<BufferGeometry | Material | Texture>;
|
|
265
|
+
if (p)
|
|
266
|
+
{
|
|
267
|
+
p.release();
|
|
268
|
+
}
|
|
269
|
+
else
|
|
270
|
+
{
|
|
271
|
+
asset.dispose();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
clearAssets()
|
|
276
|
+
{
|
|
277
|
+
let pointers = Array.from(this.assetPointer.values());
|
|
278
|
+
pointers.forEach((p) =>
|
|
279
|
+
{
|
|
280
|
+
p.forceRelease();
|
|
281
|
+
});
|
|
282
|
+
this.assetPointer.clear();
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
let assetManager = new LYAssetManager();
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
import {BufferGeometry, Material, Texture} from "three";
|
|
3
|
+
import {TSmartPointer} from "../../Container/SmartPointer.ts";
|
|
4
|
+
|
|
5
|
+
export class TAssetPointer<T extends BufferGeometry|Texture|Material> extends TSmartPointer<T>
|
|
6
|
+
{
|
|
7
|
+
get uuid():string
|
|
8
|
+
{
|
|
9
|
+
return this._uuid;
|
|
10
|
+
}
|
|
11
|
+
private readonly _uuid:string
|
|
12
|
+
constructor(value: T, referenceCount:number = 1)
|
|
13
|
+
{
|
|
14
|
+
super(value,referenceCount);
|
|
15
|
+
this._uuid = value.uuid
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
override release():void
|
|
19
|
+
{
|
|
20
|
+
if (this.value !== null)
|
|
21
|
+
{
|
|
22
|
+
this.referenceCount--;
|
|
23
|
+
|
|
24
|
+
if (this.referenceCount === 0)
|
|
25
|
+
{
|
|
26
|
+
this.value.dispose();
|
|
27
|
+
this.value = null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
forceRelease()
|
|
33
|
+
{
|
|
34
|
+
if (this.value !== null)
|
|
35
|
+
{
|
|
36
|
+
this.value.dispose();
|
|
37
|
+
this.value = null
|
|
38
|
+
this.referenceCount = 0
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class LYLoadTask
|
|
2
|
+
{
|
|
3
|
+
private readonly paths : string[]
|
|
4
|
+
private readonly onLoaded : (loaded:any)=>void | null
|
|
5
|
+
|
|
6
|
+
constructor(paths:string[], onLoaded:(loaded:any)=>void )
|
|
7
|
+
{
|
|
8
|
+
this.paths = paths;
|
|
9
|
+
this.onLoaded = onLoaded;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
get Paths()
|
|
13
|
+
{
|
|
14
|
+
return this.paths
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
onLoadingFinished(loaded:any)
|
|
18
|
+
{
|
|
19
|
+
if (this.onLoaded)
|
|
20
|
+
{
|
|
21
|
+
this.onLoaded(loaded)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
|
|
2
|
+
export class TSmartPointer<T>
|
|
3
|
+
{
|
|
4
|
+
protected referenceCount:number = 1;
|
|
5
|
+
protected value:T | null = null;
|
|
6
|
+
|
|
7
|
+
constructor(value:T, referenceCount:number = 1)
|
|
8
|
+
{
|
|
9
|
+
this.value = value;
|
|
10
|
+
this.referenceCount = referenceCount;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
getRefCount():number
|
|
14
|
+
{
|
|
15
|
+
return this.referenceCount;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
addRef(count:number = 1):void
|
|
19
|
+
{
|
|
20
|
+
if (this.value !== null)
|
|
21
|
+
{
|
|
22
|
+
this.referenceCount+=count;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
release():void
|
|
27
|
+
{
|
|
28
|
+
if (this.value !== null)
|
|
29
|
+
{
|
|
30
|
+
this.referenceCount--;
|
|
31
|
+
console.log(`Reference count decreased to: ${this.referenceCount}`);
|
|
32
|
+
|
|
33
|
+
if (this.referenceCount === 0)
|
|
34
|
+
{
|
|
35
|
+
console.log("No more references. Deleting object.");
|
|
36
|
+
this.value = null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
forceRelease()
|
|
42
|
+
{
|
|
43
|
+
if (this.value !== null)
|
|
44
|
+
{
|
|
45
|
+
this.value = null
|
|
46
|
+
this.referenceCount = 0
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
getValue():T | null
|
|
51
|
+
{
|
|
52
|
+
return this.value;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export class Delegate<T extends any[]>
|
|
2
|
+
{
|
|
3
|
+
private functions:Array<(...args:T) => void>;
|
|
4
|
+
|
|
5
|
+
constructor()
|
|
6
|
+
{
|
|
7
|
+
this.functions = [];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
broadcast(...args:T):void
|
|
11
|
+
{
|
|
12
|
+
this.functions.forEach((func) => func(...args));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
add(func:(...args:T) => void):void
|
|
16
|
+
{
|
|
17
|
+
this.functions.push(func);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
remove(func:(...args:T) => void):void
|
|
21
|
+
{
|
|
22
|
+
const index = this.functions.indexOf(func);
|
|
23
|
+
if (index >= 0)
|
|
24
|
+
{
|
|
25
|
+
this.functions.splice(index, 1);
|
|
26
|
+
}
|
|
27
|
+
else
|
|
28
|
+
{
|
|
29
|
+
console.warn("function not found");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
clear():void
|
|
34
|
+
{
|
|
35
|
+
this.functions = [];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {OrthographicCamera, PerspectiveCamera} from "three";
|
|
2
|
+
|
|
3
|
+
export interface CameraParam
|
|
4
|
+
{
|
|
5
|
+
near:number,
|
|
6
|
+
far:number,
|
|
7
|
+
param:PerspectiveCameraParam | OrthographicCameraParam
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface PerspectiveCameraParam
|
|
11
|
+
{
|
|
12
|
+
fov:number,
|
|
13
|
+
aspect:number,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface OrthographicCameraParam
|
|
17
|
+
{
|
|
18
|
+
left:number,
|
|
19
|
+
right:number,
|
|
20
|
+
top:number,
|
|
21
|
+
bottom:number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class CameraFactory
|
|
25
|
+
{
|
|
26
|
+
static createCamera(param:CameraParam)
|
|
27
|
+
{
|
|
28
|
+
let cam:PerspectiveCamera | OrthographicCamera | null = null;
|
|
29
|
+
if ("fov" in param.param && "aspect" in param.param)
|
|
30
|
+
{
|
|
31
|
+
cam = new PerspectiveCamera(param.param.fov, param.param.aspect, param.near, param.far);
|
|
32
|
+
}
|
|
33
|
+
if ("left" in param.param && "right" in param.param && "top" in param.param && "bottom" in param.param)
|
|
34
|
+
{
|
|
35
|
+
cam = new OrthographicCamera(param.param.left, param.param.right, param.param.top, param.param.bottom, param.near, param.far);
|
|
36
|
+
}
|
|
37
|
+
if (!cam)
|
|
38
|
+
{
|
|
39
|
+
console.error("create camera failed");
|
|
40
|
+
debugger
|
|
41
|
+
throw Error("create camera failed");
|
|
42
|
+
}
|
|
43
|
+
return cam
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static updataCamera(param:CameraParam, camera:PerspectiveCamera | OrthographicCamera)
|
|
47
|
+
{
|
|
48
|
+
if ("fov" in param.param && "aspect" in param.param)
|
|
49
|
+
{
|
|
50
|
+
if (camera instanceof PerspectiveCamera)
|
|
51
|
+
{
|
|
52
|
+
camera.near = param.near;
|
|
53
|
+
camera.far = param.far;
|
|
54
|
+
camera.fov = param.param.fov;
|
|
55
|
+
camera.aspect = param.param.aspect;
|
|
56
|
+
return camera
|
|
57
|
+
}
|
|
58
|
+
else
|
|
59
|
+
{
|
|
60
|
+
return new PerspectiveCamera(param.param.fov, param.param.aspect, param.near, param.far);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if ("left" in param.param && "right" in param.param && "top" in param.param && "bottom" in param.param)
|
|
64
|
+
{
|
|
65
|
+
if (camera instanceof OrthographicCamera)
|
|
66
|
+
{
|
|
67
|
+
camera.near = param.near;
|
|
68
|
+
camera.far = param.far;
|
|
69
|
+
camera.left = param.param.left;
|
|
70
|
+
camera.right = param.param.right;
|
|
71
|
+
camera.top = param.param.top;
|
|
72
|
+
camera.bottom = param.param.bottom;
|
|
73
|
+
return camera
|
|
74
|
+
}
|
|
75
|
+
else
|
|
76
|
+
{
|
|
77
|
+
return new OrthographicCamera(param.param.left, param.param.right, param.param.top, param.param.bottom, param.near, param.far);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|