bg2e-js 2.3.11 → 2.3.13
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/dist/bg2e-js.js +356 -326
- package/dist/bg2e-js.js.map +1 -1
- package/package.json +56 -56
- package/src/app/AppController.ts +39 -39
- package/src/app/Bg2KeyboardEvent.ts +54 -54
- package/src/app/Bg2MouseEvent.ts +82 -82
- package/src/app/Bg2TouchEvent.ts +18 -18
- package/src/app/Canvas.ts +108 -108
- package/src/app/EventBase.ts +10 -10
- package/src/app/MainLoop.ts +273 -273
- package/src/app/index.ts +24 -24
- package/src/base/Color.ts +134 -134
- package/src/base/Environment.ts +183 -183
- package/src/base/Light.ts +192 -192
- package/src/base/Material.ts +620 -620
- package/src/base/PolyList.ts +365 -365
- package/src/base/Texture.ts +620 -620
- package/src/base/index.ts +81 -81
- package/src/db/Bg2LoaderPlugin.ts +143 -143
- package/src/db/DBPluginApi.ts +48 -48
- package/src/db/Loader.ts +116 -116
- package/src/db/LoaderPlugin.ts +34 -34
- package/src/db/MtlParser.ts +7 -7
- package/src/db/ObjLoaderPlugin.ts +54 -54
- package/src/db/ObjParser.ts +252 -252
- package/src/db/ObjWriterPlugin.ts +18 -18
- package/src/db/VitscnjLoaderPlugin.ts +112 -112
- package/src/db/Writer.ts +52 -52
- package/src/db/WriterPlugin.ts +22 -22
- package/src/db/index.ts +44 -44
- package/src/debug/DebugRenderer.ts +173 -173
- package/src/debug/WebGLTextureViewer.ts +75 -75
- package/src/debug/index.ts +6 -6
- package/src/index.html +11 -11
- package/src/index.ts +33 -33
- package/src/manipulation/SelectionBuffer.ts +81 -81
- package/src/manipulation/SelectionHighlight.ts +105 -84
- package/src/manipulation/SelectionIdAssignVisitor.ts +96 -96
- package/src/manipulation/SelectionManager.ts +196 -188
- package/src/manipulation/SelectionMode.ts +6 -6
- package/src/math/Mat3.ts +259 -259
- package/src/math/Mat4.ts +710 -710
- package/src/math/MatrixStrategy.ts +25 -25
- package/src/math/Quat.ts +65 -65
- package/src/math/Vec.ts +753 -753
- package/src/math/constants.ts +46 -46
- package/src/math/functions.ts +103 -103
- package/src/math/index.ts +74 -74
- package/src/phsics/joint.ts +137 -137
- package/src/primitives/arrow.ts +57 -57
- package/src/primitives/cone.ts +138 -138
- package/src/primitives/cube.ts +60 -60
- package/src/primitives/cylinder.ts +216 -216
- package/src/primitives/index.ts +13 -13
- package/src/primitives/plane.ts +31 -31
- package/src/primitives/sphere.ts +809 -809
- package/src/react/useBg2e.ts +69 -69
- package/src/render/BRDFIntegrationMap.ts +4 -4
- package/src/render/Environment.ts +135 -135
- package/src/render/FrameBuffer.ts +35 -35
- package/src/render/MaterialRenderer.ts +34 -34
- package/src/render/Pipeline.ts +108 -108
- package/src/render/PolyListRenderer.ts +47 -47
- package/src/render/RenderBuffer.ts +197 -197
- package/src/render/RenderQueue.ts +198 -198
- package/src/render/RenderState.ts +116 -116
- package/src/render/Renderer.ts +248 -248
- package/src/render/SceneAppController.ts +250 -250
- package/src/render/SceneRenderer.ts +387 -387
- package/src/render/Shader.ts +32 -32
- package/src/render/ShadowRenderer.ts +176 -176
- package/src/render/SkyCube.ts +105 -105
- package/src/render/SkySphere.ts +117 -117
- package/src/render/TextureMergerRenderer.ts +70 -70
- package/src/render/TextureRenderer.ts +34 -34
- package/src/render/index.ts +67 -67
- package/src/render/webgl/FrameBuffer.ts +9 -9
- package/src/render/webgl/MaterialRenderer.ts +112 -112
- package/src/render/webgl/Pipeline.ts +88 -88
- package/src/render/webgl/PolyListRenderer.ts +260 -260
- package/src/render/webgl/RenderBuffer.ts +226 -226
- package/src/render/webgl/Renderer.ts +262 -262
- package/src/render/webgl/SceneRenderer.ts +67 -67
- package/src/render/webgl/ShaderProgram.ts +424 -424
- package/src/render/webgl/ShadowRenderer.ts +6 -6
- package/src/render/webgl/SkyCube.ts +15 -15
- package/src/render/webgl/SkySphere.ts +15 -15
- package/src/render/webgl/State.ts +152 -152
- package/src/render/webgl/TextureRenderer.ts +167 -167
- package/src/render/webgl/VertexBuffer.ts +137 -137
- package/src/render/webgl/index.ts +35 -35
- package/src/scene/Camera.ts +458 -458
- package/src/scene/Chain.ts +44 -44
- package/src/scene/ChainJoint.ts +58 -58
- package/src/scene/Component.ts +177 -177
- package/src/scene/ComponentMap.ts +106 -106
- package/src/scene/Drawable.ts +154 -154
- package/src/scene/EnvironmentComponent.ts +141 -141
- package/src/scene/FindNodeVisitor.ts +59 -59
- package/src/scene/LightComponent.ts +154 -154
- package/src/scene/MatrixState.ts +46 -46
- package/src/scene/Node.ts +328 -328
- package/src/scene/NodeVisitor.ts +15 -15
- package/src/scene/OrbitCameraController.ts +450 -450
- package/src/scene/SmoothOrbitCameraController.ts +99 -99
- package/src/scene/Transform.ts +73 -73
- package/src/scene/index.ts +60 -60
- package/src/shaders/BasicDiffuseColorShader.ts +111 -111
- package/src/shaders/BasicPBRLightShader.ts +276 -276
- package/src/shaders/DebugRenderShader.ts +97 -97
- package/src/shaders/DepthRenderShader.ts +127 -127
- package/src/shaders/IrradianceMapCubeShader.ts +115 -115
- package/src/shaders/PBRLightIBLShader.ts +486 -486
- package/src/shaders/PickSelectionShader.ts +101 -101
- package/src/shaders/PresentDebugFramebufferShader.ts +118 -118
- package/src/shaders/PresentTextureShader.ts +99 -99
- package/src/shaders/SelectionHighlightShader.ts +143 -127
- package/src/shaders/ShaderFunction.ts +318 -318
- package/src/shaders/SkyCubeShader.ts +93 -93
- package/src/shaders/SkySphereShader.ts +102 -102
- package/src/shaders/SpecularMapCubeShader.ts +164 -164
- package/src/shaders/TextureMergerShader.ts +171 -171
- package/src/shaders/index.ts +36 -36
- package/src/shaders/webgl/color_correction.glsl +47 -47
- package/src/shaders/webgl/constants.glsl +6 -6
- package/src/shaders/webgl/index.ts +70 -70
- package/src/shaders/webgl/normal_map.glsl +9 -9
- package/src/shaders/webgl/pbr.glsl +173 -173
- package/src/shaders/webgl/uniforms.glsl +91 -91
- package/src/shaders/webgl_shader_lib.ts +213 -213
- package/src/tools/BinaryResourceProvider.ts +14 -14
- package/src/tools/ImageResourceProvider.ts +66 -66
- package/src/tools/MaterialModifier.ts +446 -446
- package/src/tools/Resource.ts +203 -203
- package/src/tools/ResourceProvider.ts +69 -69
- package/src/tools/TextResourceProvider.ts +24 -24
- package/src/tools/TextureCache.ts +51 -51
- package/src/tools/TextureResourceDatabase.ts +100 -100
- package/src/tools/UserAgent.ts +362 -362
- package/src/tools/VideoResourceProvider.ts +50 -50
- package/src/tools/WriteStrategy.ts +22 -22
- package/src/tools/base64.ts +11 -11
- package/src/tools/crypto.ts +19 -19
- package/src/tools/endiantess.ts +13 -13
- package/src/tools/image.ts +18 -18
- package/src/tools/index.ts +41 -41
- package/src/tools/processType.ts +39 -39
- package/src/vite-env.d.ts +12 -12
package/src/db/Loader.ts
CHANGED
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
|
|
2
|
-
import { isAbsolute, jointUrl, ResourceType } from '../tools/Resource';
|
|
3
|
-
import {
|
|
4
|
-
PluginOperationType,
|
|
5
|
-
createPluginDatabase,
|
|
6
|
-
registerPluginInDatabase,
|
|
7
|
-
getPluginFromDatabase
|
|
8
|
-
} from './DBPluginApi';
|
|
9
|
-
import Canvas from '../app/Canvas';
|
|
10
|
-
import LoaderPlugin from './LoaderPlugin';
|
|
11
|
-
import PolyList from '../base/PolyList';
|
|
12
|
-
import Texture from '../base/Texture';
|
|
13
|
-
|
|
14
|
-
const g_loadPluginDatabase = createPluginDatabase(PluginOperationType.Read);
|
|
15
|
-
|
|
16
|
-
type ResourceCache = {
|
|
17
|
-
[ResourceType.PolyList]: Record<string, PolyList>;
|
|
18
|
-
[ResourceType.Drawable]: Record<string, any>;
|
|
19
|
-
[ResourceType.Node]: Record<string, any>;
|
|
20
|
-
[ResourceType.Texture]: Record<string, Texture>;
|
|
21
|
-
[ResourceType.Material]: Record<string, any>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const registerLoaderPlugin = (pluginInstance: LoaderPlugin): void => {
|
|
25
|
-
pluginInstance.dependencies.forEach(dep => registerPluginInDatabase(dep, g_loadPluginDatabase));
|
|
26
|
-
registerPluginInDatabase(pluginInstance, g_loadPluginDatabase);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const getLoaderPlugin = (path: string, type: ResourceType): LoaderPlugin => {
|
|
30
|
-
return getPluginFromDatabase(path, type, g_loadPluginDatabase);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const getClearedCache = (): ResourceCache => {
|
|
34
|
-
return {
|
|
35
|
-
[ResourceType.PolyList]: {},
|
|
36
|
-
[ResourceType.Drawable]: {},
|
|
37
|
-
[ResourceType.Node]: {},
|
|
38
|
-
[ResourceType.Texture]: {},
|
|
39
|
-
[ResourceType.Material]: {}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export default class Loader {
|
|
44
|
-
private _canvas: Canvas;
|
|
45
|
-
private _cache: ResourceCache;
|
|
46
|
-
private _currentPath: string;
|
|
47
|
-
|
|
48
|
-
constructor(canvas?: Canvas | null) {
|
|
49
|
-
this._canvas = canvas || Canvas.FirstCanvas();
|
|
50
|
-
this._cache = getClearedCache();
|
|
51
|
-
this._currentPath = "";
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
get canvas(): Canvas {
|
|
55
|
-
return this._canvas;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
get currentPath(): string {
|
|
59
|
-
return this._currentPath;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
set currentPath(p: string) {
|
|
63
|
-
this._currentPath = p;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
clearCache(): void {
|
|
67
|
-
this._cache = getClearedCache();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
findCache(path: string, type: ResourceType): any {
|
|
71
|
-
return this._cache[type] && this._cache[type][path];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async loadResource(path: string, type: ResourceType): Promise<any> {
|
|
75
|
-
if (!isAbsolute(path) && this.currentPath !== "") {
|
|
76
|
-
path = jointUrl(this.currentPath, path);
|
|
77
|
-
}
|
|
78
|
-
let result = this.findCache(path, type);
|
|
79
|
-
if (!result) {
|
|
80
|
-
const plugin = getLoaderPlugin(path, type);
|
|
81
|
-
result = await plugin.load(path, type, this);
|
|
82
|
-
}
|
|
83
|
-
return result;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async loadResourceBuffer(buffer: ArrayBuffer, format: string, dependencies: string[], type: ResourceType): Promise<any> {
|
|
87
|
-
const plugin = getLoaderPlugin(`file.${ format }`, type);
|
|
88
|
-
const result = await plugin.loadBuffer(buffer, format, dependencies, type, this);
|
|
89
|
-
return result;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async loadPolyList(path: string): Promise<PolyList> {
|
|
93
|
-
return await this.loadResource(path, ResourceType.PolyList);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async loadDrawable(path: string): Promise<any> {
|
|
97
|
-
return await this.loadResource(path, ResourceType.Drawable);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async loadDrawableBuffer(buffer: ArrayBuffer, format: string, dependencies: string[]): Promise<any> {
|
|
101
|
-
return await this.loadResourceBuffer(buffer, format, dependencies, ResourceType.Drawable);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async loadNode(path: string): Promise<any> {
|
|
105
|
-
return await this.loadResource(path, ResourceType.Node);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
async loadTexture(path: string): Promise<Texture> {
|
|
109
|
-
return await this.loadResource(path, ResourceType.Texture);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async loadMaterial(path: string): Promise<any> {
|
|
113
|
-
return await this.loadResource(path, ResourceType.Material);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
1
|
+
|
|
2
|
+
import { isAbsolute, jointUrl, ResourceType } from '../tools/Resource';
|
|
3
|
+
import {
|
|
4
|
+
PluginOperationType,
|
|
5
|
+
createPluginDatabase,
|
|
6
|
+
registerPluginInDatabase,
|
|
7
|
+
getPluginFromDatabase
|
|
8
|
+
} from './DBPluginApi';
|
|
9
|
+
import Canvas from '../app/Canvas';
|
|
10
|
+
import LoaderPlugin from './LoaderPlugin';
|
|
11
|
+
import PolyList from '../base/PolyList';
|
|
12
|
+
import Texture from '../base/Texture';
|
|
13
|
+
|
|
14
|
+
const g_loadPluginDatabase = createPluginDatabase(PluginOperationType.Read);
|
|
15
|
+
|
|
16
|
+
type ResourceCache = {
|
|
17
|
+
[ResourceType.PolyList]: Record<string, PolyList>;
|
|
18
|
+
[ResourceType.Drawable]: Record<string, any>;
|
|
19
|
+
[ResourceType.Node]: Record<string, any>;
|
|
20
|
+
[ResourceType.Texture]: Record<string, Texture>;
|
|
21
|
+
[ResourceType.Material]: Record<string, any>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const registerLoaderPlugin = (pluginInstance: LoaderPlugin): void => {
|
|
25
|
+
pluginInstance.dependencies.forEach(dep => registerPluginInDatabase(dep, g_loadPluginDatabase));
|
|
26
|
+
registerPluginInDatabase(pluginInstance, g_loadPluginDatabase);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const getLoaderPlugin = (path: string, type: ResourceType): LoaderPlugin => {
|
|
30
|
+
return getPluginFromDatabase(path, type, g_loadPluginDatabase);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const getClearedCache = (): ResourceCache => {
|
|
34
|
+
return {
|
|
35
|
+
[ResourceType.PolyList]: {},
|
|
36
|
+
[ResourceType.Drawable]: {},
|
|
37
|
+
[ResourceType.Node]: {},
|
|
38
|
+
[ResourceType.Texture]: {},
|
|
39
|
+
[ResourceType.Material]: {}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default class Loader {
|
|
44
|
+
private _canvas: Canvas;
|
|
45
|
+
private _cache: ResourceCache;
|
|
46
|
+
private _currentPath: string;
|
|
47
|
+
|
|
48
|
+
constructor(canvas?: Canvas | null) {
|
|
49
|
+
this._canvas = canvas || Canvas.FirstCanvas();
|
|
50
|
+
this._cache = getClearedCache();
|
|
51
|
+
this._currentPath = "";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get canvas(): Canvas {
|
|
55
|
+
return this._canvas;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get currentPath(): string {
|
|
59
|
+
return this._currentPath;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
set currentPath(p: string) {
|
|
63
|
+
this._currentPath = p;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
clearCache(): void {
|
|
67
|
+
this._cache = getClearedCache();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
findCache(path: string, type: ResourceType): any {
|
|
71
|
+
return this._cache[type] && this._cache[type][path];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async loadResource(path: string, type: ResourceType): Promise<any> {
|
|
75
|
+
if (!isAbsolute(path) && this.currentPath !== "") {
|
|
76
|
+
path = jointUrl(this.currentPath, path);
|
|
77
|
+
}
|
|
78
|
+
let result = this.findCache(path, type);
|
|
79
|
+
if (!result) {
|
|
80
|
+
const plugin = getLoaderPlugin(path, type);
|
|
81
|
+
result = await plugin.load(path, type, this);
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async loadResourceBuffer(buffer: ArrayBuffer, format: string, dependencies: string[], type: ResourceType): Promise<any> {
|
|
87
|
+
const plugin = getLoaderPlugin(`file.${ format }`, type);
|
|
88
|
+
const result = await plugin.loadBuffer(buffer, format, dependencies, type, this);
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async loadPolyList(path: string): Promise<PolyList> {
|
|
93
|
+
return await this.loadResource(path, ResourceType.PolyList);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async loadDrawable(path: string): Promise<any> {
|
|
97
|
+
return await this.loadResource(path, ResourceType.Drawable);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async loadDrawableBuffer(buffer: ArrayBuffer, format: string, dependencies: string[]): Promise<any> {
|
|
101
|
+
return await this.loadResourceBuffer(buffer, format, dependencies, ResourceType.Drawable);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async loadNode(path: string): Promise<any> {
|
|
105
|
+
return await this.loadResource(path, ResourceType.Node);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async loadTexture(path: string): Promise<Texture> {
|
|
109
|
+
return await this.loadResource(path, ResourceType.Texture);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async loadMaterial(path: string): Promise<any> {
|
|
113
|
+
return await this.loadResource(path, ResourceType.Material);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
package/src/db/LoaderPlugin.ts
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { ResourceType } from "../tools/Resource.js";
|
|
2
|
-
|
|
3
|
-
export default class LoaderPlugin {
|
|
4
|
-
// Returns an array of valid file extensions for this plugin
|
|
5
|
-
// example: ["obj","dae"]
|
|
6
|
-
get supportedExtensions(): string[] {
|
|
7
|
-
throw new Error("LoaderPlugin.supportedExtensions: attribute not implemented");
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// Returns the resource types that the loader plugin can handle
|
|
11
|
-
// example: [ ResourceType.PolyList, ResourceType.Scene ]
|
|
12
|
-
get resourceTypes(): ResourceType[] {
|
|
13
|
-
throw new Error("LoaderPlugin.resourceTypes: attribute not implemented");
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Returns the resource loaded with the path. The resource type must be one
|
|
17
|
-
// of the specified in the resourceTypes attribute
|
|
18
|
-
async load(path: string, type: ResourceType, loader: any): Promise<any> {
|
|
19
|
-
throw new Error("LoaderPlugin.load(): method not implemented");
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async loadBuffer(buffer: ArrayBuffer, format: string, dependencies: string[], type: ResourceType, loader: any): Promise<any> {
|
|
23
|
-
throw new Error("LoaderPlugin.loadBuffer(): method not implemented");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Returns an array of LoaderPlugin objects that are necessary for this plugin to work.
|
|
27
|
-
get dependencies(): LoaderPlugin[] {
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async write(path: string, data: any, type: ResourceType, writer: any): Promise<any> {
|
|
32
|
-
throw new Error("LoaderPlugin.write(): method not implemented");
|
|
33
|
-
}
|
|
34
|
-
}
|
|
1
|
+
import { ResourceType } from "../tools/Resource.js";
|
|
2
|
+
|
|
3
|
+
export default class LoaderPlugin {
|
|
4
|
+
// Returns an array of valid file extensions for this plugin
|
|
5
|
+
// example: ["obj","dae"]
|
|
6
|
+
get supportedExtensions(): string[] {
|
|
7
|
+
throw new Error("LoaderPlugin.supportedExtensions: attribute not implemented");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Returns the resource types that the loader plugin can handle
|
|
11
|
+
// example: [ ResourceType.PolyList, ResourceType.Scene ]
|
|
12
|
+
get resourceTypes(): ResourceType[] {
|
|
13
|
+
throw new Error("LoaderPlugin.resourceTypes: attribute not implemented");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Returns the resource loaded with the path. The resource type must be one
|
|
17
|
+
// of the specified in the resourceTypes attribute
|
|
18
|
+
async load(path: string, type: ResourceType, loader: any): Promise<any> {
|
|
19
|
+
throw new Error("LoaderPlugin.load(): method not implemented");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async loadBuffer(buffer: ArrayBuffer, format: string, dependencies: string[], type: ResourceType, loader: any): Promise<any> {
|
|
23
|
+
throw new Error("LoaderPlugin.loadBuffer(): method not implemented");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Returns an array of LoaderPlugin objects that are necessary for this plugin to work.
|
|
27
|
+
get dependencies(): LoaderPlugin[] {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async write(path: string, data: any, type: ResourceType, writer: any): Promise<any> {
|
|
32
|
+
throw new Error("LoaderPlugin.write(): method not implemented");
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/db/MtlParser.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export default class MtlParser {
|
|
4
|
-
constructor(mtlText: string) {
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
}
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export default class MtlParser {
|
|
4
|
+
constructor(mtlText: string) {
|
|
5
|
+
|
|
6
|
+
}
|
|
7
|
+
}
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import LoaderPlugin from './LoaderPlugin';
|
|
2
|
-
import Resource, { getFileName, removeExtension, removeFileName, ResourceType } from './../tools/Resource';
|
|
3
|
-
import ObjParser from './ObjParser';
|
|
4
|
-
import Drawable from '../scene/Drawable';
|
|
5
|
-
import Material from '../base/Material';
|
|
6
|
-
import PolyList from '../base/PolyList';
|
|
7
|
-
import Loader from './Loader';
|
|
8
|
-
|
|
9
|
-
const buildDrawable = (polyListArray: PolyList[], mtlData: any, filePath: string): Drawable => {
|
|
10
|
-
const name = removeExtension(getFileName(filePath));
|
|
11
|
-
const drawable = new Drawable(name);
|
|
12
|
-
|
|
13
|
-
polyListArray.forEach((plist: PolyList) => {
|
|
14
|
-
// TODO: set mtl data
|
|
15
|
-
const mat = new Material();
|
|
16
|
-
drawable.addPolyList(plist,mat);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
return drawable;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default class ObjLoaderPlugin extends LoaderPlugin {
|
|
23
|
-
private _resource: Resource;
|
|
24
|
-
|
|
25
|
-
constructor() {
|
|
26
|
-
super();
|
|
27
|
-
this._resource = new Resource();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get supportedExtensions(): string[] { return ['obj']; }
|
|
31
|
-
|
|
32
|
-
get resourceTypes(): ResourceType[] {
|
|
33
|
-
return [
|
|
34
|
-
ResourceType.PolyList,
|
|
35
|
-
ResourceType.Drawable
|
|
36
|
-
];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async load(path: string, resourceType: ResourceType, loader: Loader): Promise<PolyList[] | Drawable> {
|
|
40
|
-
const objText = await this._resource.load(path);
|
|
41
|
-
const parser = new ObjParser(objText);
|
|
42
|
-
|
|
43
|
-
// TODO: load material from mtl file
|
|
44
|
-
// const relativePath = removeFileName(filePath);
|
|
45
|
-
|
|
46
|
-
switch (resourceType) {
|
|
47
|
-
case ResourceType.PolyList:
|
|
48
|
-
return parser.polyListArray;
|
|
49
|
-
case ResourceType.Drawable:
|
|
50
|
-
return buildDrawable(parser.polyListArray, null, path);
|
|
51
|
-
default:
|
|
52
|
-
throw new Error(`ObjLoaderPlugin.load() unexpected resource type received: ${resourceType}`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
1
|
+
import LoaderPlugin from './LoaderPlugin';
|
|
2
|
+
import Resource, { getFileName, removeExtension, removeFileName, ResourceType } from './../tools/Resource';
|
|
3
|
+
import ObjParser from './ObjParser';
|
|
4
|
+
import Drawable from '../scene/Drawable';
|
|
5
|
+
import Material from '../base/Material';
|
|
6
|
+
import PolyList from '../base/PolyList';
|
|
7
|
+
import Loader from './Loader';
|
|
8
|
+
|
|
9
|
+
const buildDrawable = (polyListArray: PolyList[], mtlData: any, filePath: string): Drawable => {
|
|
10
|
+
const name = removeExtension(getFileName(filePath));
|
|
11
|
+
const drawable = new Drawable(name);
|
|
12
|
+
|
|
13
|
+
polyListArray.forEach((plist: PolyList) => {
|
|
14
|
+
// TODO: set mtl data
|
|
15
|
+
const mat = new Material();
|
|
16
|
+
drawable.addPolyList(plist,mat);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return drawable;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default class ObjLoaderPlugin extends LoaderPlugin {
|
|
23
|
+
private _resource: Resource;
|
|
24
|
+
|
|
25
|
+
constructor() {
|
|
26
|
+
super();
|
|
27
|
+
this._resource = new Resource();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get supportedExtensions(): string[] { return ['obj']; }
|
|
31
|
+
|
|
32
|
+
get resourceTypes(): ResourceType[] {
|
|
33
|
+
return [
|
|
34
|
+
ResourceType.PolyList,
|
|
35
|
+
ResourceType.Drawable
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async load(path: string, resourceType: ResourceType, loader: Loader): Promise<PolyList[] | Drawable> {
|
|
40
|
+
const objText = await this._resource.load(path);
|
|
41
|
+
const parser = new ObjParser(objText);
|
|
42
|
+
|
|
43
|
+
// TODO: load material from mtl file
|
|
44
|
+
// const relativePath = removeFileName(filePath);
|
|
45
|
+
|
|
46
|
+
switch (resourceType) {
|
|
47
|
+
case ResourceType.PolyList:
|
|
48
|
+
return parser.polyListArray;
|
|
49
|
+
case ResourceType.Drawable:
|
|
50
|
+
return buildDrawable(parser.polyListArray, null, path);
|
|
51
|
+
default:
|
|
52
|
+
throw new Error(`ObjLoaderPlugin.load() unexpected resource type received: ${resourceType}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
55
|
}
|