bg2e-js 2.0.1 → 2.0.2
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 +11001 -0
- package/dist/bg2e-js.js.map +1 -0
- package/package.json +17 -6
- package/app/AppController.d.ts +0 -37
- package/app/AppController.js +0 -32
- package/app/Canvas.d.ts +0 -42
- package/app/Canvas.js +0 -98
- package/app/EventBase.js +0 -8
- package/app/KeyboardEvent.js +0 -51
- package/app/MainLoop.d.ts +0 -245
- package/app/MainLoop.js +0 -251
- package/app/MouseEvent.js +0 -77
- package/app/TouchEvent.js +0 -15
- package/base/Color.js +0 -131
- package/base/Environment.js +0 -78
- package/base/Light.js +0 -176
- package/base/Material.js +0 -619
- package/base/PolyList.js +0 -336
- package/base/Texture.js +0 -545
- package/db/Bg2LoaderPlugin.js +0 -113
- package/db/DBPluginApi.js +0 -40
- package/db/Loader.js +0 -91
- package/db/LoaderPlugin.js +0 -26
- package/db/MtlParser.js +0 -7
- package/db/ObjLoaderPlugin.js +0 -51
- package/db/ObjParser.js +0 -233
- package/db/ObjWriterPlugin.js +0 -18
- package/db/VitscnjLoaderPlugin.js +0 -87
- package/db/Writer.js +0 -49
- package/db/WriterPlugin.js +0 -20
- package/debug/DebugRenderer.js +0 -138
- package/debug/WebGLTextureViewer.js +0 -67
- package/manipulation/SelectionBuffer.js +0 -65
- package/manipulation/SelectionHighlight.js +0 -69
- package/manipulation/SelectionIdAssignVisitor.js +0 -86
- package/manipulation/SelectionManager.js +0 -134
- package/manipulation/SelectionMode.js +0 -6
- package/math/Mat3.js +0 -248
- package/math/Mat4.js +0 -694
- package/math/MatrixStrategy.js +0 -23
- package/math/Quat.js +0 -60
- package/math/Vec.js +0 -728
- package/math/constants.js +0 -44
- package/math/functions.js +0 -104
- package/math/index.js +0 -74
- package/phsics/joint.js +0 -124
- package/primitives/arrow.js +0 -58
- package/primitives/cone.js +0 -137
- package/primitives/cube.js +0 -59
- package/primitives/cylinder.js +0 -215
- package/primitives/index.js +0 -13
- package/primitives/plane.js +0 -31
- package/primitives/sphere.js +0 -808
- package/render/BRDFIntegrationMap.js +0 -4
- package/render/Environment.js +0 -105
- package/render/EnvironmentRenderer.js +0 -12
- package/render/FrameBuffer.js +0 -26
- package/render/MaterialRenderer.js +0 -28
- package/render/Pipeline.js +0 -83
- package/render/PolyListRenderer.js +0 -42
- package/render/RenderBuffer.js +0 -189
- package/render/RenderQueue.js +0 -162
- package/render/RenderState.js +0 -82
- package/render/Renderer.js +0 -202
- package/render/SceneAppController.js +0 -208
- package/render/SceneRenderer.js +0 -310
- package/render/Shader.js +0 -21
- package/render/ShadowRenderer.js +0 -159
- package/render/SkyCube.js +0 -77
- package/render/SkySphere.js +0 -94
- package/render/TextureMergerRenderer.js +0 -58
- package/render/TextureRenderer.js +0 -29
- package/render/webgl/FrameBuffer.js +0 -9
- package/render/webgl/MaterialRenderer.js +0 -99
- package/render/webgl/Pipeline.js +0 -82
- package/render/webgl/PolyListRenderer.js +0 -224
- package/render/webgl/RenderBuffer.js +0 -244
- package/render/webgl/Renderer.js +0 -239
- package/render/webgl/SceneRenderer.js +0 -43
- package/render/webgl/ShaderProgram.js +0 -350
- package/render/webgl/ShadowRenderer.js +0 -6
- package/render/webgl/SkyCube.js +0 -15
- package/render/webgl/SkySphere.js +0 -14
- package/render/webgl/State.js +0 -149
- package/render/webgl/TextureRenderer.js +0 -167
- package/render/webgl/VertexBuffer.js +0 -128
- package/scene/Camera.js +0 -378
- package/scene/Chain.js +0 -43
- package/scene/ChainJoint.js +0 -55
- package/scene/Component.js +0 -146
- package/scene/ComponentMap.js +0 -99
- package/scene/Drawable.js +0 -130
- package/scene/EnvironmentComponent.js +0 -123
- package/scene/FindNodeVisitor.js +0 -55
- package/scene/LightComponent.js +0 -146
- package/scene/MatrixState.js +0 -39
- package/scene/Node.js +0 -300
- package/scene/NodeVisitor.js +0 -12
- package/scene/OrbitCameraController.js +0 -407
- package/scene/SmoothOrbitCameraController.js +0 -92
- package/scene/Transform.js +0 -74
- package/scene/index.js +0 -24
- package/shaders/BasicDiffuseColorShader.js +0 -91
- package/shaders/BasicPBRLightShader.js +0 -238
- package/shaders/DebugRenderShader.js +0 -79
- package/shaders/DepthRenderShader.js +0 -69
- package/shaders/IrradianceMapCubeShader.js +0 -99
- package/shaders/PBRLightIBLShader.js +0 -380
- package/shaders/PickSelectionShader.js +0 -75
- package/shaders/PresentDebugFramebufferShader.js +0 -90
- package/shaders/PresentTextureShader.js +0 -73
- package/shaders/SelectionHighlightShader.js +0 -98
- package/shaders/ShaderFunction.js +0 -72
- package/shaders/SkyCubeShader.js +0 -78
- package/shaders/SkySphereShader.js +0 -77
- package/shaders/SpecularMapCubeShader.js +0 -145
- package/shaders/TextureMergerShader.js +0 -127
- package/shaders/webgl_shader_lib.js +0 -187
- package/tools/BinaryResourceProvider.js +0 -15
- package/tools/ImageResourceProvider.js +0 -65
- package/tools/MaterialModifier.js +0 -228
- package/tools/Resource.js +0 -177
- package/tools/ResourceProvider.js +0 -56
- package/tools/TextResourceProvider.js +0 -24
- package/tools/TextureCache.js +0 -44
- package/tools/TextureResourceDatabase.js +0 -87
- package/tools/UserAgent.js +0 -294
- package/tools/VideoResourceProvider.js +0 -51
- package/tools/WriteStrategy.js +0 -22
- package/tools/base64.js +0 -15
- package/tools/crypto.js +0 -15
- package/tools/endiantess.js +0 -15
- package/tools/image.js +0 -15
- package/tools/index.js +0 -33
- package/tools/processType.js +0 -56
package/base/Texture.js
DELETED
|
@@ -1,545 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import Vec from '../math/Vec';
|
|
3
|
-
import Resource from '../tools/Resource';
|
|
4
|
-
import { generateImageHash } from '../tools/image';
|
|
5
|
-
import Color from './Color';
|
|
6
|
-
import Canvas from '../app/Canvas';
|
|
7
|
-
|
|
8
|
-
export const TextureDataType = Object.freeze({
|
|
9
|
-
NONE: 0,
|
|
10
|
-
IMAGE: 1,
|
|
11
|
-
IMAGE_DATA: 2,
|
|
12
|
-
CUBEMAP: 3,
|
|
13
|
-
CUBEMAP_DATA: 4,
|
|
14
|
-
VIDEO: 5,
|
|
15
|
-
PROCEDURAL: 6,
|
|
16
|
-
RENDER_TARGET: 7
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
export const TextureWrap = Object.freeze({
|
|
20
|
-
REPEAT: 0,
|
|
21
|
-
CLAMP: 1,
|
|
22
|
-
MIRRORED_REPEAT: 2
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
export const TextureFilter = Object.freeze({
|
|
26
|
-
NEAREST_MIPMAP_NEAREST: 0,
|
|
27
|
-
LINEAR_MIPMAP_NEAREST: 1,
|
|
28
|
-
NEAREST_MIPMAP_LINEAR: 2,
|
|
29
|
-
LINEAR_MIPMAP_LINEAR: 3,
|
|
30
|
-
NEAREST: 4,
|
|
31
|
-
LINEAR: 5
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
export const TextureTarget = Object.freeze({
|
|
35
|
-
TEXTURE_2D: 0,
|
|
36
|
-
CUBE_MAP: 1
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
export const ProceduralTextureFunction = Object.freeze({
|
|
40
|
-
PLAIN_COLOR: 0,
|
|
41
|
-
RANDOM_NOISE: 1,
|
|
42
|
-
DYNAMIC_CUBEMAP: 2,
|
|
43
|
-
FROM_BASE64: 3,
|
|
44
|
-
CANVAS_2D: 4
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
export const TextureRenderTargetAttachment = Object.freeze({
|
|
48
|
-
COLOR_ATTACHMENT_0: 0,
|
|
49
|
-
COLOR_ATTACHMENT_1: 1,
|
|
50
|
-
COLOR_ATTACHMENT_2: 2,
|
|
51
|
-
COLOR_ATTACHMENT_3: 3,
|
|
52
|
-
COLOR_ATTACHMENT_4: 4,
|
|
53
|
-
COLOR_ATTACHMENT_5: 5,
|
|
54
|
-
COLOR_ATTACHMENT_6: 6,
|
|
55
|
-
COLOR_ATTACHMENT_7: 7,
|
|
56
|
-
COLOR_ATTACHMENT_8: 8,
|
|
57
|
-
COLOR_ATTACHMENT_9: 9,
|
|
58
|
-
COLOR_ATTACHMENT_10: 10,
|
|
59
|
-
COLOR_ATTACHMENT_11: 11,
|
|
60
|
-
COLOR_ATTACHMENT_12: 12,
|
|
61
|
-
COLOR_ATTACHMENT_13: 13,
|
|
62
|
-
COLOR_ATTACHMENT_14: 14,
|
|
63
|
-
COLOR_ATTACHMENT_15: 15,
|
|
64
|
-
DEPTH_ATTACHMENT: 100,
|
|
65
|
-
STENCIL_ATTACHMENT: 200
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
export const TextureComponentFormat = Object.freeze({
|
|
69
|
-
UNSIGNED_BYTE: 0,
|
|
70
|
-
FLOAT32: 1
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
export const TextureChannel = Object.freeze({
|
|
74
|
-
R: 1,
|
|
75
|
-
G: 2,
|
|
76
|
-
B: 3,
|
|
77
|
-
A: 4
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
export const TextureDataTypeName = Object.freeze({
|
|
81
|
-
0: "NONE",
|
|
82
|
-
1: "IMAGE",
|
|
83
|
-
2: "IMAGE_DATA",
|
|
84
|
-
3: "CUBEMAP",
|
|
85
|
-
4: "CUBEMAP_DATA",
|
|
86
|
-
5: "VIDEO",
|
|
87
|
-
6: "PROCEDURAL",
|
|
88
|
-
7: "RENDER_TARGET"
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
export const TextureWrapName = Object.freeze({
|
|
92
|
-
0: "REPEAT",
|
|
93
|
-
1: "CLAMP",
|
|
94
|
-
2: "MIRRORED_REPEAT"
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
export const TextureFilterName = Object.freeze({
|
|
98
|
-
0: "NEAREST_MIPMAP_NEAREST",
|
|
99
|
-
1: "LINEAR_MIPMAP_NEAREST",
|
|
100
|
-
2: "NEAREST_MIPMAP_LINEAR",
|
|
101
|
-
3: "LINEAR_MIPMAP_LINEAR",
|
|
102
|
-
4: "NEAREST",
|
|
103
|
-
5: "LINEAR"
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
export const TextureTargetName = Object.freeze({
|
|
107
|
-
0: "TEXTURE_2D",
|
|
108
|
-
1: "CUBE_MAP"
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
export const ProceduralTextureFunctionName = Object.freeze({
|
|
112
|
-
0: "PLAIN_COLOR",
|
|
113
|
-
1: "RANDOM_NOISE",
|
|
114
|
-
2: "DYNAMIC_CUBEMAP",
|
|
115
|
-
3: "FROM_BASE64",
|
|
116
|
-
4: "CANVAS_2D"
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
export const TextureRenderTargetAttachmentNames = Object.freeze({
|
|
120
|
-
0: "COLOR_ATTACHMENT_0",
|
|
121
|
-
1: "COLOR_ATTACHMENT_1",
|
|
122
|
-
2: "COLOR_ATTACHMENT_2",
|
|
123
|
-
3: "COLOR_ATTACHMENT_3",
|
|
124
|
-
4: "COLOR_ATTACHMENT_4",
|
|
125
|
-
5: "COLOR_ATTACHMENT_5",
|
|
126
|
-
6: "COLOR_ATTACHMENT_6",
|
|
127
|
-
7: "COLOR_ATTACHMENT_7",
|
|
128
|
-
8: "COLOR_ATTACHMENT_8",
|
|
129
|
-
9: "COLOR_ATTACHMENT_9",
|
|
130
|
-
10: "COLOR_ATTACHMENT_10",
|
|
131
|
-
11: "COLOR_ATTACHMENT_11",
|
|
132
|
-
12: "COLOR_ATTACHMENT_12",
|
|
133
|
-
13: "COLOR_ATTACHMENT_13",
|
|
134
|
-
14: "COLOR_ATTACHMENT_14",
|
|
135
|
-
15: "COLOR_ATTACHMENT_15",
|
|
136
|
-
100: "DEPTH_ATTACHMENT",
|
|
137
|
-
200: "STENCIL_ATTACHMENT"
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
export const TextureComponentFormatNames = Object.freeze({
|
|
141
|
-
0: "UNSIGNED_BYTE",
|
|
142
|
-
1: "FLOAT32"
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
export const TextureChannelNames = Object.freeze({
|
|
146
|
-
1: "R",
|
|
147
|
-
2: "G",
|
|
148
|
-
3: "B",
|
|
149
|
-
4: "A"
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
const g_loadedImages = {};
|
|
153
|
-
let g_resource = null;
|
|
154
|
-
const g_loadPromises = {};
|
|
155
|
-
const loadImageFromFile = async fileUrl => {
|
|
156
|
-
if (!g_resource) {
|
|
157
|
-
g_resource = new Resource();
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (g_loadPromises[fileUrl]) {
|
|
161
|
-
console.log(`Image already loaded or loading: ${fileUrl}`);
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
console.log(`Loading image: ${fileUrl}`);
|
|
165
|
-
g_loadPromises[fileUrl] = new Promise(async (resolve, reject) => {
|
|
166
|
-
const image = await g_resource.load(fileUrl);
|
|
167
|
-
// Flip image Y coord
|
|
168
|
-
const canvas = document.createElement("canvas");
|
|
169
|
-
canvas.width = image.naturalWidth;
|
|
170
|
-
canvas.height = image.naturalHeight;
|
|
171
|
-
|
|
172
|
-
const ctx = canvas.getContext('2d');
|
|
173
|
-
ctx.fillStyle = '#00000000';
|
|
174
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
175
|
-
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
176
|
-
ctx.scale(1, -1);
|
|
177
|
-
ctx.drawImage(image, 0, 0, canvas.width, -canvas.height);
|
|
178
|
-
const flipImage = new Image();
|
|
179
|
-
const loadFlipImage = () => {
|
|
180
|
-
return new Promise(resolve => {
|
|
181
|
-
flipImage.onload = () => {
|
|
182
|
-
flipImage._hash = generateImageHash(flipImage);
|
|
183
|
-
resolve();
|
|
184
|
-
}
|
|
185
|
-
flipImage.src = canvas.toDataURL();
|
|
186
|
-
})
|
|
187
|
-
}
|
|
188
|
-
await loadFlipImage();
|
|
189
|
-
|
|
190
|
-
resolve(flipImage);
|
|
191
|
-
})
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return g_loadPromises[fileUrl];
|
|
195
|
-
}
|
|
196
|
-
const loadBase64Image = async base64Img => {
|
|
197
|
-
const loadImage = () => {
|
|
198
|
-
return new Promise(resolve => {
|
|
199
|
-
const image = new Image();
|
|
200
|
-
image.onload = () => {
|
|
201
|
-
resolve(image);
|
|
202
|
-
}
|
|
203
|
-
image.src = base64Img;
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const image = await loadImage();
|
|
208
|
-
|
|
209
|
-
// Flip image Y coord
|
|
210
|
-
const canvas = document.createElement("canvas");
|
|
211
|
-
canvas.width = image.naturalWidth;
|
|
212
|
-
canvas.height = image.naturalHeight;
|
|
213
|
-
|
|
214
|
-
const ctx = canvas.getContext('2d');
|
|
215
|
-
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
216
|
-
ctx.scale(1, -1);
|
|
217
|
-
ctx.drawImage(image, 0, 0, canvas.width, -canvas.height);
|
|
218
|
-
const flipImage = new Image();
|
|
219
|
-
const loadFlipImage = () => {
|
|
220
|
-
return new Promise(resolve => {
|
|
221
|
-
flipImage.onload = () => {
|
|
222
|
-
flipImage._hash = generateImageHash(flipImage);
|
|
223
|
-
resolve();
|
|
224
|
-
}
|
|
225
|
-
flipImage.src = canvas.toDataURL("image/png");
|
|
226
|
-
})
|
|
227
|
-
}
|
|
228
|
-
await loadFlipImage();
|
|
229
|
-
|
|
230
|
-
return flipImage;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export default class Texture {
|
|
234
|
-
constructor(canvas = null) {
|
|
235
|
-
this._canvas = canvas || Canvas.FirstCanvas();
|
|
236
|
-
|
|
237
|
-
// This flag allows to the renderer to know if the texture object
|
|
238
|
-
// has been updated. In this case, the renderer texture must to
|
|
239
|
-
// be regenerated.
|
|
240
|
-
this._dirty = true;
|
|
241
|
-
|
|
242
|
-
this._dataType = TextureDataType.NONE;
|
|
243
|
-
this._wrapModeX = TextureWrap.REPEAT;
|
|
244
|
-
this._wrapModeY = TextureWrap.REPEAT;
|
|
245
|
-
this._magFilter = TextureFilter.LINEAR;
|
|
246
|
-
this._minFilter = TextureFilter.LINEAR;
|
|
247
|
-
this._target = TextureTarget.TEXTURE_2D;
|
|
248
|
-
this._size = new Vec(64, 64);
|
|
249
|
-
this._fileName = "";
|
|
250
|
-
this._proceduralFunction = ProceduralTextureFunction.PLAIN_COLOR;
|
|
251
|
-
this._proceduralParameters = {};
|
|
252
|
-
this._renderTargetAttachment = TextureRenderTargetAttachment.COLOR_ATTACHMENT_0;
|
|
253
|
-
this._componentFormat = TextureComponentFormat.UNSIGNED_BYTE;
|
|
254
|
-
|
|
255
|
-
// This attribute is generated from the previous attributes, for example,
|
|
256
|
-
// calling loadImageData() after setting the fileName attribute
|
|
257
|
-
this._imageData = null;
|
|
258
|
-
|
|
259
|
-
// Reference counter, to know if a texture can be purged
|
|
260
|
-
this._references = 0;
|
|
261
|
-
|
|
262
|
-
// Object name, form debugging purposes
|
|
263
|
-
this._name = "";
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
get canvas() {
|
|
267
|
-
return this._canvas;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
get references() {
|
|
271
|
-
return this._references;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
incReferences() {
|
|
275
|
-
this._references++;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
decReferences() {
|
|
279
|
-
this._references--;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
clone() {
|
|
283
|
-
const copy = new Texture(this.canvas);
|
|
284
|
-
copy.assign(this);
|
|
285
|
-
return copy;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
assign(other) {
|
|
289
|
-
this._dataType = other._dataType;
|
|
290
|
-
this._wrapModeX = other._wrapModeX;
|
|
291
|
-
this._wrapModeY = other._wrapModeY;
|
|
292
|
-
this._magFilter = other._magFilter;
|
|
293
|
-
this._minFilter = other._minFilter;
|
|
294
|
-
this._target = other._target;
|
|
295
|
-
this._size = new Vec(other._size);
|
|
296
|
-
this._fileName = other._fileName;
|
|
297
|
-
this._proceduralFunction = other._proceduralFunction;
|
|
298
|
-
this._proceduralParameters = other._proceduralParameters;
|
|
299
|
-
this._imageData = other._imageData;
|
|
300
|
-
this._renderTargetAttachment = other._renderTargetAttachment;
|
|
301
|
-
this._componentFormat = other._componentFormat;
|
|
302
|
-
|
|
303
|
-
this._dirty = true;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
get dirty() {
|
|
307
|
-
return this._dirty;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
setUpdated(updated = true) {
|
|
311
|
-
this._dirty = !updated;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
get dataType() { return this._dataType; }
|
|
315
|
-
set dataType(v) {
|
|
316
|
-
this._dataType = v;
|
|
317
|
-
if (!this.isPowerOfTwo) {
|
|
318
|
-
this.wrapModeXY = TextureWrap.CLAMP;
|
|
319
|
-
}
|
|
320
|
-
this.magFilter = TextureFilter.LINEAR;
|
|
321
|
-
this.minFilter = TextureFilter.LINEAR;
|
|
322
|
-
this._dirty = true;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
get isPowerOfTwo() {
|
|
326
|
-
const pot = (n) => n!==0 && (n & (n - 1)) === 0;
|
|
327
|
-
return pot(this.size[0]) && pot(this.size[1]);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
get wrapModeX() { return this._wrapModeX; }
|
|
331
|
-
set wrapModeX(v) { this._wrapModeX = v; this._dirty = true; }
|
|
332
|
-
get wrapModeY() { return this._wrapModeY; }
|
|
333
|
-
set wrapModeY(v) { this._wrapModeY = v; this._dirty = true; }
|
|
334
|
-
set wrapModeXY(xy) {
|
|
335
|
-
this.wrapModeX = xy;
|
|
336
|
-
this.wrapModeY = xy;
|
|
337
|
-
this._dirty = true;
|
|
338
|
-
}
|
|
339
|
-
get magFilter() { return this._magFilter; }
|
|
340
|
-
set magFilter(v) {
|
|
341
|
-
if (v === TextureFilter.LINEAR || v === TextureFilter.NEAREST) {
|
|
342
|
-
this._magFilter = v;
|
|
343
|
-
this._dirty = true;
|
|
344
|
-
}
|
|
345
|
-
else {
|
|
346
|
-
console.warn(`Unsupported texture magnification filter: ${TextureFilterName[v]}. Command ignored.`);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
get minFilter() { return this._minFilter; }
|
|
350
|
-
set minFilter(v) { this._minFilter = v; this._dirty = true; }
|
|
351
|
-
get target() { return this._target; }
|
|
352
|
-
set target(v) { this._target = v; this._dirty = true; }
|
|
353
|
-
get size() { return this._size; }
|
|
354
|
-
set size(v) {
|
|
355
|
-
if (!v.length) {
|
|
356
|
-
throw new Error("Invalid parameter specified setting texture size.");
|
|
357
|
-
}
|
|
358
|
-
this._size = new Vec(v[0],v[1]);
|
|
359
|
-
this._dirty = true;
|
|
360
|
-
}
|
|
361
|
-
get fileName() { return this._fileName; }
|
|
362
|
-
set fileName(v) { this._fileName = v; this._dirty = true; this._imageData = null; this._name = v; }
|
|
363
|
-
get proceduralFunction() { return this._proceduralFunction; }
|
|
364
|
-
set proceduralFunction(v) { this._proceduralFunction = v; this._dirty = true; }
|
|
365
|
-
get proceduralParameters() { return this._proceduralParameters; }
|
|
366
|
-
set proceduralParameters(v) {
|
|
367
|
-
if (typeof(v) !== 'object' || !v) {
|
|
368
|
-
throw new Error("Invalid parameter specified setting procedural texture parameters.");
|
|
369
|
-
}
|
|
370
|
-
this._proceduralParameters = v;
|
|
371
|
-
this._dirty = true;
|
|
372
|
-
}
|
|
373
|
-
get renderTargetAttachment() { return this._renderTargetAttachment; }
|
|
374
|
-
set renderTargetAttachment(att) { this._renderTargetAttachment = att; this._dirty = true; }
|
|
375
|
-
get componentFormat() { return this._componentFormat; }
|
|
376
|
-
set componentFormat(fmt) { this._componentFormat = fmt; this._dirty = true; }
|
|
377
|
-
|
|
378
|
-
get mipmapRequired() {
|
|
379
|
-
return this._minFilter === TextureFilter.NEAREST_MIPMAP_NEAREST ||
|
|
380
|
-
this._minFilter === TextureFilter.LINEAR_MIPMAP_NEAREST ||
|
|
381
|
-
this._minFilter === TextureFilter.NEAREST_MIPMAP_LINEAR ||
|
|
382
|
-
this._minFilter === TextureFilter.LINEAR_MIPMAP_LINEAR ||
|
|
383
|
-
this._magFilter === TextureFilter.NEAREST_MIPMAP_NEAREST ||
|
|
384
|
-
this._magFilter === TextureFilter.LINEAR_MIPMAP_NEAREST ||
|
|
385
|
-
this._magFilter === TextureFilter.NEAREST_MIPMAP_LINEAR ||
|
|
386
|
-
this._magFilter === TextureFilter.LINEAR_MIPMAP_LINEAR;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
// If imageData === undefined it's because the function loadImageData() has not been called
|
|
390
|
-
get imageData() {
|
|
391
|
-
return this._imageData;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
// The this._renderer variable is initialized by the texture renderer
|
|
395
|
-
get renderer() {
|
|
396
|
-
return this._renderer;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
get name() {
|
|
400
|
-
return this._name;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
set name(n) {
|
|
404
|
-
this._name = n;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
destroy() {
|
|
408
|
-
if (this.renderer) {
|
|
409
|
-
this.renderer.destroy();
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
async deserialize(sceneData) {
|
|
414
|
-
this._dataType = sceneData.dataType !== undefined ? TextureDataType[sceneData.dataType] : TextureDataType.NONE;
|
|
415
|
-
this._wrapModeX = sceneData.wrapModeX !== undefined ? TextureWrap[sceneData.wrapModeX] : TextureWrap.REPEAT;
|
|
416
|
-
this._wrapModeY = sceneData.wrapModeY !== undefined ? TextureWrap[sceneData.wrapModeY] : TextureWrap.REPEAT;
|
|
417
|
-
this._magFilter = sceneData.magFilter !== undefined ? TextureFilter[sceneData.magFilter] : TextureFilter.LINEAR;
|
|
418
|
-
this._minFilter = sceneData.minFilter !== undefined ? TextureFilter[sceneData.minFilter] : TextureFilter.LINEAR;
|
|
419
|
-
this._target = sceneData.target !== undefined ? TextureTarget[sceneData.target] : TextureTarget.TEXTURE_2D;
|
|
420
|
-
this._size = sceneData.size?.length === 2 ? new Vec(sceneData.size[0], sceneData.size[1]) : new Vec(64, 64);
|
|
421
|
-
this._fileName = sceneData.fileName !== undefined ? sceneData.fileName : "";
|
|
422
|
-
this._proceduralFunction = sceneData.proceduralFunction !== undefined ? ProceduralTextureFunction[sceneData.proceduralFunction] : ProceduralTextureFunction.PLAIN_COLOR;
|
|
423
|
-
this._proceduralParameters = sceneData.proceduralParameters !== undefined ? sceneData.proceduralParameters : {};
|
|
424
|
-
this._renderTargetAttachment = sceneData.renderTargetAttachment !== undefined ? sceneData.renderTargetAttachment : TextureRenderTargetAttachment.COLOR_ATTACHMENT_0;
|
|
425
|
-
this._componentFormat = sceneData.componentFormat !== undefined ? sceneData.componentFormat : TextureComponentFormat.UNSIGNED_BYTE;
|
|
426
|
-
this._name = sceneData.name !== undefined ? sceneData.name : this._name;
|
|
427
|
-
this._dirty = true;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
async serialize(sceneData) {
|
|
431
|
-
sceneData.dataType = TextureDataTypeName[this.dataType];
|
|
432
|
-
sceneData.wrapModeX = TextureWrapName[this.wrapModeX];
|
|
433
|
-
sceneData.wrapModeY = TextureWrapName[this.wrapModeY];
|
|
434
|
-
sceneData.magFilter = TextureFilterName[this.magFilter];
|
|
435
|
-
sceneData.minFilter = TextureFilterName[this.minFilter];
|
|
436
|
-
sceneData.target = TextureTargetName[this.target];
|
|
437
|
-
sceneData.size = this.size;
|
|
438
|
-
sceneData.fileName = this.fileName;
|
|
439
|
-
sceneData.proceduralFunction = ProceduralTextureFunctionName[this.proceduralFunction];
|
|
440
|
-
sceneData.proceduralParameters = this.proceduralParameters;
|
|
441
|
-
sceneData.renderTargetAttachment = TextureRenderTargetAttachmentNames[this.renderTargetAttachment];
|
|
442
|
-
sceneData.componentFormat = TextureComponentFormatNames[this.componentFormat];
|
|
443
|
-
sceneData.name = this._name;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
async loadImageData(refresh = false) {
|
|
447
|
-
if (this.fileName) {
|
|
448
|
-
if (g_loadedImages[this.fileName] && refresh) {
|
|
449
|
-
delete g_loadedImages[this.fileName];
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
let loadPromise = g_loadedImages[this.fileName];
|
|
453
|
-
if (!loadPromise) {
|
|
454
|
-
loadPromise = loadImageFromFile(this.fileName);
|
|
455
|
-
g_loadedImages[this.fileName] = loadPromise;
|
|
456
|
-
}
|
|
457
|
-
else {
|
|
458
|
-
console.debug(`Texture: loadImageData(): image already loaded or is loading: ${this.fileName}`)
|
|
459
|
-
}
|
|
460
|
-
this._imageData = await loadPromise;
|
|
461
|
-
|
|
462
|
-
this._size = new Vec(this._imageData.width, this._imageData.height);
|
|
463
|
-
|
|
464
|
-
this._dirty = true;
|
|
465
|
-
}
|
|
466
|
-
else if (this.dataType === TextureDataType.RENDER_TARGET) {
|
|
467
|
-
// This object will store data to determine if the
|
|
468
|
-
// texture must to be resized, and other information
|
|
469
|
-
// from the framebuffer
|
|
470
|
-
this._imageData = {
|
|
471
|
-
currentSize: new Vec(this.size)
|
|
472
|
-
};
|
|
473
|
-
this._dirty = true;
|
|
474
|
-
}
|
|
475
|
-
else if (this.proceduralFunction === ProceduralTextureFunction.PLAIN_COLOR) {
|
|
476
|
-
if (this._imageData && refresh === false) {
|
|
477
|
-
return;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
if ((!Array.isArray(this.proceduralParameters) && !(this.proceduralParameters instanceof Vec)) || this.proceduralParameters.length<3) {
|
|
481
|
-
throw new Error("Error generating procedural plain color texture. invalid 'proceduralParameters' set.")
|
|
482
|
-
}
|
|
483
|
-
const color = new Color(this.proceduralParameters);
|
|
484
|
-
const canvas = document.createElement('canvas');
|
|
485
|
-
canvas.width = this.size.x;
|
|
486
|
-
canvas.height = this.size.y;
|
|
487
|
-
const ctx = canvas.getContext('2d');
|
|
488
|
-
ctx.fillStyle = color.hexColor;
|
|
489
|
-
ctx.fillRect(0, 0, this.size.x, this.size.y);
|
|
490
|
-
|
|
491
|
-
const loadProceduralImage = () => {
|
|
492
|
-
return new Promise(resolve => {
|
|
493
|
-
this._imageData = new Image();
|
|
494
|
-
this._imageData.onload = () => {
|
|
495
|
-
resolve();
|
|
496
|
-
}
|
|
497
|
-
this._imageData.src = canvas.toDataURL("image/png");
|
|
498
|
-
//document.body.appendChild(canvas);
|
|
499
|
-
})
|
|
500
|
-
}
|
|
501
|
-
await loadProceduralImage();
|
|
502
|
-
|
|
503
|
-
this._dirty = true;
|
|
504
|
-
}
|
|
505
|
-
else if (this.proceduralFunction === ProceduralTextureFunction.FROM_BASE64) {
|
|
506
|
-
if (this._imageData && refresh === false) {
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
if (!/;base64/i.test(this.proceduralParameters?.imageData)) {
|
|
511
|
-
throw new Error("Error generating procedural texture from base64 string. Invalid base64 image");
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
this._imageData = await loadBase64Image(this.proceduralParameters.imageData);
|
|
515
|
-
this._size = new Vec(this._imageData.width, this._imageData.height);
|
|
516
|
-
this._dirty = true;
|
|
517
|
-
}
|
|
518
|
-
else if (this.proceduralFunction == ProceduralTextureFunction.CANVAS_2D) {
|
|
519
|
-
if (this._imageData && refresh === false) {
|
|
520
|
-
return;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
const canvas = this.proceduralParameters?.canvas;
|
|
524
|
-
if (!/canvas/i.test(canvas?.tagName)) {
|
|
525
|
-
throw new Error("Error generating procedural texture from HTML canvas. Invalid 'canvas' parameter.");
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
const imageData = canvas.toDataURL();
|
|
529
|
-
this._imageData = await loadBase64Image(imageData);
|
|
530
|
-
this._size = new Vec(this._imageData.width, this._imageData.height);
|
|
531
|
-
this._dirty = true;
|
|
532
|
-
}
|
|
533
|
-
else {
|
|
534
|
-
// TODO: load other classes of procedural image data
|
|
535
|
-
throw new Error("Texture: loadImageData(): not implemented");
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
async updateImageData() {
|
|
540
|
-
// TODO: improve this function. It is possible to optimize the
|
|
541
|
-
// texture refresh in some cases
|
|
542
|
-
this.loadImageData(true);
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
};
|
package/db/Bg2LoaderPlugin.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import LoaderPlugin from "./LoaderPlugin";
|
|
2
|
-
import { ResourceType, getFileName, removeExtension, removeFileName } from "./../tools/Resource";
|
|
3
|
-
import Resource from "../tools/Resource";
|
|
4
|
-
import PolyList from "../base/PolyList";
|
|
5
|
-
import Drawable from "../scene/Drawable";
|
|
6
|
-
import Node from "../scene/Node";
|
|
7
|
-
import Material from "../base/Material";
|
|
8
|
-
import { deserializeComponent } from "../scene/Component";
|
|
9
|
-
|
|
10
|
-
import Bg2ioWrapper from 'bg2io/Bg2ioBrowser';
|
|
11
|
-
|
|
12
|
-
let g_bg2Wrapper = null;
|
|
13
|
-
|
|
14
|
-
const bg2ioFactory = async (path) => {
|
|
15
|
-
if (g_bg2Wrapper === null) {
|
|
16
|
-
const params = path ? { wasmPath: path } : {};
|
|
17
|
-
g_bg2Wrapper = await Bg2ioWrapper(params);
|
|
18
|
-
}
|
|
19
|
-
return g_bg2Wrapper;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const createPolyList = (jsonData,loader) => {
|
|
23
|
-
const result = jsonData.polyLists.map(plData => {
|
|
24
|
-
const plist = new PolyList();
|
|
25
|
-
const materialData = jsonData.materials.find(m => m.name === plData.matName);
|
|
26
|
-
plist.name = plData.name
|
|
27
|
-
plist.visible = plData.visible;
|
|
28
|
-
if (materialData) {
|
|
29
|
-
plist.groupName = materialData.groupName || "";
|
|
30
|
-
plist.enableCullFace = materialData.cullFace;
|
|
31
|
-
}
|
|
32
|
-
plist.vertex = plData.vertex;
|
|
33
|
-
plist.normal = plData.normal;
|
|
34
|
-
plist.texCoord0 = plData.texCoord0
|
|
35
|
-
plist.texCoord1 = plData.texCoord1
|
|
36
|
-
plist.texCoord2 = plData.texCoord2
|
|
37
|
-
plist.index = plData.index;
|
|
38
|
-
return { plist, materialData };
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const createDrawable = async (jsonData,filePath,loader) => {
|
|
45
|
-
const name = removeExtension(getFileName(filePath));
|
|
46
|
-
const relativePath = removeFileName(filePath);
|
|
47
|
-
const drawable = new Drawable(name);
|
|
48
|
-
for (const item of createPolyList(jsonData)) {
|
|
49
|
-
const mat = new Material(loader.canvas);
|
|
50
|
-
await mat.deserialize(item.materialData, relativePath);
|
|
51
|
-
drawable.addPolyList(item.plist, mat);
|
|
52
|
-
}
|
|
53
|
-
//createPolyList(jsonData).forEach(item => {
|
|
54
|
-
// const mat = new Material();
|
|
55
|
-
// mat.deserialize(item.materialData, relativePath);
|
|
56
|
-
// drawable.addPolyList(item.plist, mat);
|
|
57
|
-
//});
|
|
58
|
-
return drawable;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const createNode = async (jsonData,filePath,loader) => {
|
|
62
|
-
const name = removeExtension(getFileName(filePath));
|
|
63
|
-
const drawable = await createDrawable(jsonData,filePath,loader);
|
|
64
|
-
const node = new Node(name);
|
|
65
|
-
node.addChild(drawable);
|
|
66
|
-
for (const compData of jsonData.components) {
|
|
67
|
-
try {
|
|
68
|
-
const comp = await deserializeComponent(compData,loader);
|
|
69
|
-
node.addComponent(comp);
|
|
70
|
-
}
|
|
71
|
-
catch (err) {
|
|
72
|
-
console.warn(err.message);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
console.log(jsonData);
|
|
76
|
-
return node;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export default class Bg2LoaderPlugin extends LoaderPlugin {
|
|
80
|
-
constructor( { bg2ioPath = null } = {}) {
|
|
81
|
-
super();
|
|
82
|
-
this._bg2ioPath = bg2ioPath;
|
|
83
|
-
this._resource = new Resource();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
get supportedExtensions() { return ["bg2","vwglb"]; }
|
|
87
|
-
|
|
88
|
-
get resourceTypes() {
|
|
89
|
-
return [
|
|
90
|
-
ResourceType.PolyList,
|
|
91
|
-
ResourceType.Drawable,
|
|
92
|
-
ResourceType.Node
|
|
93
|
-
];
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async load(path,resourceType,loader) {
|
|
97
|
-
const bg2io = await bg2ioFactory(this._bg2ioPath);
|
|
98
|
-
|
|
99
|
-
const buffer = await this._resource.load(path);
|
|
100
|
-
const jsonData = bg2io.loadBg2FileAsJson(buffer);
|
|
101
|
-
|
|
102
|
-
switch (resourceType) {
|
|
103
|
-
case ResourceType.PolyList:
|
|
104
|
-
return createPolyList(jsonData,loader).map(item => item.plist);
|
|
105
|
-
case ResourceType.Drawable:
|
|
106
|
-
return createDrawable(jsonData,path,loader);
|
|
107
|
-
case ResourceType.Node:
|
|
108
|
-
return await createNode(jsonData,path,loader);
|
|
109
|
-
default:
|
|
110
|
-
throw new Error(`Bg2LoaderPlugin.load() unexpected resource type received: ${resourceType}`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
package/db/DBPluginApi.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { getExtension, ResourceType } from '../tools/Resource';
|
|
2
|
-
|
|
3
|
-
export const PluginOperationType = {
|
|
4
|
-
Read: "read",
|
|
5
|
-
Write: "write"
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export const createPluginDatabase = (operationType) => {
|
|
9
|
-
return {
|
|
10
|
-
operationType,
|
|
11
|
-
plugins: {}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const registerPluginInDatabase = (pluginInstance, pluginDatabase) => {
|
|
16
|
-
pluginInstance.resourceTypes.forEach(type => {
|
|
17
|
-
pluginDatabase.plugins[type] = pluginDatabase.plugins[type] || [];
|
|
18
|
-
pluginDatabase.plugins[type].push(pluginInstance);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const getPluginFromDatabase = function(path, type, pluginDatabase) {
|
|
23
|
-
const ext = getExtension(path);
|
|
24
|
-
const extCheck = new RegExp(ext, "i");
|
|
25
|
-
const errMsg = `Could not find a plugin to ${pluginDatabase.operationType} file '${path}' of type '${type}'.`;
|
|
26
|
-
|
|
27
|
-
const plugins = pluginDatabase.plugins[type];
|
|
28
|
-
if (!plugins) {
|
|
29
|
-
throw new Error(errMsg);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
for (const plugin of plugins) {
|
|
33
|
-
if (plugin.supportedExtensions.find(e => extCheck.test(e))) {
|
|
34
|
-
return plugin;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
throw new Error(errMsg);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|