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
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import ShaderFunction from "./ShaderFunction";
|
|
3
|
-
|
|
4
|
-
export const fresnelSchlick = new ShaderFunction('vec3', 'fresnelSchlick', 'float cosTheta, vec3 F0', `{
|
|
5
|
-
return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
|
|
6
|
-
}`);
|
|
7
|
-
|
|
8
|
-
export const fresnelSchlickRoughness = new ShaderFunction('vec3', 'fresnelSchlickRoughness', 'float cosTheta, vec3 F0, float roughness', `{
|
|
9
|
-
return F0 + (max(vec3(1.0 - roughness), F0) - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
|
|
10
|
-
}`);
|
|
11
|
-
|
|
12
|
-
export const distributionGGX = new ShaderFunction('float', 'distributionGGX', 'vec3 N, vec3 H, float roughness', `{
|
|
13
|
-
float a = roughness * roughness;
|
|
14
|
-
float a2 = a * a;
|
|
15
|
-
float NdotH = max(dot(N, H), 0.0);
|
|
16
|
-
float NdotH2 = NdotH * NdotH;
|
|
17
|
-
|
|
18
|
-
float num = a2;
|
|
19
|
-
float denom = NdotH2 * (a2 - 1.0) + 1.0;
|
|
20
|
-
denom = ${Math.PI} * denom * denom;
|
|
21
|
-
|
|
22
|
-
return num / denom;
|
|
23
|
-
}`);
|
|
24
|
-
|
|
25
|
-
export const geometrySchlickGGX = new ShaderFunction('float', 'geometrySchlickGGX', 'float NdotV, float roughness', `{
|
|
26
|
-
float r = (roughness + 1.0);
|
|
27
|
-
float k = (r * r) / 8.0;
|
|
28
|
-
|
|
29
|
-
float num = NdotV;
|
|
30
|
-
float denom = NdotV * (1.0 - k) + k;
|
|
31
|
-
|
|
32
|
-
return num / denom;
|
|
33
|
-
}`)
|
|
34
|
-
|
|
35
|
-
export const geometrySmith = new ShaderFunction('float', 'geometrySmith', 'vec3 N, vec3 V, vec3 L, float roughness', `{
|
|
36
|
-
float NdotV = max(dot(N,V), 0.0);
|
|
37
|
-
float NdotL = max(dot(N,L), 0.0);
|
|
38
|
-
float ggx2 = geometrySchlickGGX(NdotV, roughness);
|
|
39
|
-
float ggx1 = geometrySchlickGGX(NdotL, roughness);
|
|
40
|
-
|
|
41
|
-
return ggx1 * ggx2;
|
|
42
|
-
}`, [geometrySchlickGGX]);
|
|
43
|
-
|
|
44
|
-
export const pbrPointLight = new ShaderFunction('vec3', 'pbrPointLight',
|
|
45
|
-
'vec3 lightPos, vec3 lightColor, vec3 fragPos, vec3 fragNorm, vec3 viewPos, vec3 albedo, float roughness, float metallic, vec3 fresnel',
|
|
46
|
-
`{
|
|
47
|
-
vec3 F0 = vec3(0.04);
|
|
48
|
-
F0 = mix(F0, albedo, metallic);
|
|
49
|
-
|
|
50
|
-
vec3 L = normalize(lightPos - fragPos);
|
|
51
|
-
vec3 H = normalize(viewPos + L);
|
|
52
|
-
|
|
53
|
-
float distance = length(lightPos - fragPos);
|
|
54
|
-
float attenuation = 1.0 / (distance * distance);
|
|
55
|
-
vec3 radiance = lightColor * attenuation;
|
|
56
|
-
|
|
57
|
-
vec3 F = fresnelSchlick(max(dot(H, viewPos), 0.0), F0) * fresnel;
|
|
58
|
-
|
|
59
|
-
float NDF = distributionGGX(fragNorm, H, roughness);
|
|
60
|
-
float G = geometrySmith(fragNorm, viewPos, L, roughness);
|
|
61
|
-
|
|
62
|
-
vec3 numerator = NDF * G * F;
|
|
63
|
-
float denom = 4.0 * max(dot(fragNorm,viewPos), 0.0) * max(dot(fragNorm,L), 0.0) + 0.0001;
|
|
64
|
-
vec3 specular = numerator / denom;
|
|
65
|
-
|
|
66
|
-
vec3 kS = F;
|
|
67
|
-
vec3 kD = vec3(1.0) - kS;
|
|
68
|
-
|
|
69
|
-
kD *= 1.0 - metallic;
|
|
70
|
-
|
|
71
|
-
float NdotL = max(dot(fragNorm,L), 0.0);
|
|
72
|
-
return (kD * albedo / ${Math.PI} + specular) * radiance * NdotL;
|
|
73
|
-
}`, [fresnelSchlick, distributionGGX, geometrySmith]);
|
|
74
|
-
|
|
75
|
-
export const pbrDirectionalLight = new ShaderFunction('vec3', 'pbrDirectionalLight',
|
|
76
|
-
'vec3 lightDir, vec3 lightColor, vec3 fragPos, vec3 fragNorm, vec3 viewPos, vec3 albedo, float roughness, float metallic, vec3 fresnel, vec3 shadowColor',
|
|
77
|
-
`{
|
|
78
|
-
vec3 F0 = vec3(0.04);
|
|
79
|
-
F0 = mix(F0, albedo, metallic);
|
|
80
|
-
|
|
81
|
-
vec3 L = normalize(lightDir);
|
|
82
|
-
vec3 H = normalize(viewPos + L);
|
|
83
|
-
|
|
84
|
-
vec3 F = fresnelSchlickRoughness(max(dot(H, viewPos), 0.0), F0, roughness);
|
|
85
|
-
|
|
86
|
-
float NDF = distributionGGX(fragNorm, H, roughness);
|
|
87
|
-
float G = geometrySmith(fragNorm, viewPos, L, roughness);
|
|
88
|
-
|
|
89
|
-
vec3 numerator = NDF * G * F;
|
|
90
|
-
float denom = 4.0 * max(dot(fragNorm,viewPos), 0.4) * max(dot(fragNorm,L), 0.4);
|
|
91
|
-
vec3 specular = numerator / max(denom, 0.0001);
|
|
92
|
-
|
|
93
|
-
vec3 kS = F;
|
|
94
|
-
vec3 kD = vec3(1.0) - kS;
|
|
95
|
-
|
|
96
|
-
kD *= 1.0 - metallic;
|
|
97
|
-
|
|
98
|
-
float NdotL = max(dot(fragNorm,L), 0.0);
|
|
99
|
-
return (kD * albedo / ${Math.PI} + specular * fresnel * shadowColor) * lightColor * shadowColor * NdotL;
|
|
100
|
-
}`, [fresnelSchlick, distributionGGX, geometrySmith, fresnelSchlickRoughness]);
|
|
101
|
-
|
|
102
|
-
export const getPrefilteredColor = new ShaderFunction('vec3', 'getPrefilteredColor', 'float roughness, vec3 refVec, samplerCube irrMap, samplerCube specMap, samplerCube envMap',
|
|
103
|
-
`{
|
|
104
|
-
vec3 specMap0 = textureCube(envMap, refVec).rgb;
|
|
105
|
-
vec3 specMap1 = textureCube(specMap, refVec).rgb;
|
|
106
|
-
vec3 specMap2 = textureCube(irrMap, refVec).rgb;
|
|
107
|
-
|
|
108
|
-
if (roughness<0.7) {
|
|
109
|
-
return mix(specMap0, specMap1, (log(roughness) + 5.0) / 5.0);
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
return mix(specMap1, specMap2, roughness);
|
|
113
|
-
}
|
|
114
|
-
}`);
|
|
115
|
-
|
|
116
|
-
export const pbrAmbientLight = new ShaderFunction('vec3', 'pbrAmbientLight', 'vec3 fragPos, vec3 N, vec3 V, vec3 albedo, float metallic, float roughness, samplerCube irradianceMap, samplerCube specularMap, samplerCube envMap, sampler2D brdfMap, vec3 fresnel, vec3 shadowColor',
|
|
117
|
-
`{
|
|
118
|
-
vec3 F0 = vec3(0.04);
|
|
119
|
-
F0 = mix(F0, albedo, metallic);
|
|
120
|
-
vec3 kS = fresnelSchlickRoughness(max(dot(N,V), 0.0), F0, roughness) * fresnel;
|
|
121
|
-
vec3 kD = 1.0 - kS;
|
|
122
|
-
vec3 irradiance = textureCube(irradianceMap, N).rgb;
|
|
123
|
-
vec3 diffuse = irradiance * albedo;
|
|
124
|
-
|
|
125
|
-
vec3 R = reflect(-V, N);
|
|
126
|
-
vec3 prefilteredColor = getPrefilteredColor(roughness, R, irradianceMap, specularMap, envMap);
|
|
127
|
-
float NdotV = min(max(dot(N,V), 0.0), 0.95);
|
|
128
|
-
vec2 envBRDF = texture2D(brdfMap, vec2(NdotV,roughness)).xy;
|
|
129
|
-
vec3 indirectSpecular = prefilteredColor * (kS * envBRDF.x + envBRDF.y);
|
|
130
|
-
|
|
131
|
-
return kD * diffuse + indirectSpecular * max(shadowColor, vec3(0.5, 0.5, 0.5));
|
|
132
|
-
}`, [fresnelSchlickRoughness, getPrefilteredColor]);
|
|
133
|
-
|
|
134
|
-
export const applyConvolution = new ShaderFunction('vec4', 'applyConvolution', 'sampler2D texture, vec2 texCoord, vec2 texSize, float[9] convMatrix, float radius',
|
|
135
|
-
`
|
|
136
|
-
{
|
|
137
|
-
vec2 onePixel = vec2(1.0,1.0) / texSize * radius;
|
|
138
|
-
vec4 colorSum =
|
|
139
|
-
texture2D(texture, texCoord + onePixel * vec2(-1, -1)) * convMatrix[0] +
|
|
140
|
-
texture2D(texture, texCoord + onePixel * vec2( 0, -1)) * convMatrix[1] +
|
|
141
|
-
texture2D(texture, texCoord + onePixel * vec2( 1, -1)) * convMatrix[2] +
|
|
142
|
-
texture2D(texture, texCoord + onePixel * vec2(-1, 0)) * convMatrix[3] +
|
|
143
|
-
texture2D(texture, texCoord + onePixel * vec2( 0, 0)) * convMatrix[4] +
|
|
144
|
-
texture2D(texture, texCoord + onePixel * vec2( 1, 0)) * convMatrix[5] +
|
|
145
|
-
texture2D(texture, texCoord + onePixel * vec2(-1, 1)) * convMatrix[6] +
|
|
146
|
-
texture2D(texture, texCoord + onePixel * vec2( 0, 1)) * convMatrix[7] +
|
|
147
|
-
texture2D(texture, texCoord + onePixel * vec2( 1, 1)) * convMatrix[8];
|
|
148
|
-
float kernelWeight =
|
|
149
|
-
convMatrix[0] +
|
|
150
|
-
convMatrix[1] +
|
|
151
|
-
convMatrix[2] +
|
|
152
|
-
convMatrix[3] +
|
|
153
|
-
convMatrix[4] +
|
|
154
|
-
convMatrix[5] +
|
|
155
|
-
convMatrix[6] +
|
|
156
|
-
convMatrix[7] +
|
|
157
|
-
convMatrix[8];
|
|
158
|
-
if (kernelWeight <= 0.0) {
|
|
159
|
-
kernelWeight = 1.0;
|
|
160
|
-
}
|
|
161
|
-
return vec4((colorSum / kernelWeight).rgb, 1.0);
|
|
162
|
-
}
|
|
163
|
-
`, []);
|
|
164
|
-
|
|
165
|
-
export const getShadowColor = new ShaderFunction('vec3', 'getShadowColor', 'vec4 positionFromLightPov, sampler2D shadowMap, float shadowBias, float shadowStrength',
|
|
166
|
-
`
|
|
167
|
-
{
|
|
168
|
-
// The vertex location rendered from the light source is almost in
|
|
169
|
-
// normalized device coordinates (NDC), but the perspective division
|
|
170
|
-
// has not been performed yet. We need to divide by w to get the
|
|
171
|
-
// vertex location in range [-1, +1]
|
|
172
|
-
vec3 shadowCoord = positionFromLightPov.xyz / positionFromLightPov.w;
|
|
173
|
-
|
|
174
|
-
// Convert from NDC to texture coordinates
|
|
175
|
-
shadowCoord = shadowCoord * 0.5 + 0.5;
|
|
176
|
-
|
|
177
|
-
if (shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 &&
|
|
178
|
-
shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0)
|
|
179
|
-
{
|
|
180
|
-
float shadowDepth = texture2D(shadowMap, shadowCoord.xy).r;
|
|
181
|
-
if (shadowCoord.z > shadowDepth + shadowBias) {
|
|
182
|
-
return vec3(1.0 - shadowStrength);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return vec3(1.0);
|
|
186
|
-
}
|
|
187
|
-
`, []);
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import ResourceProvider from "./ResourceProvider.js";
|
|
3
|
-
|
|
4
|
-
export default class BinaryResourceProvider extends ResourceProvider {
|
|
5
|
-
async load(url) {
|
|
6
|
-
const response = await fetch(url);
|
|
7
|
-
if (response.ok) {
|
|
8
|
-
const binaryData = await response.arrayBuffer();
|
|
9
|
-
return binaryData;
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
throw new Error(`Resource not found at '${ url }'`);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import ResourceProvider from "./ResourceProvider.js";
|
|
3
|
-
import { generateUUID } from "./crypto.js";
|
|
4
|
-
|
|
5
|
-
// In this array we keep a reference to the images being loaded to
|
|
6
|
-
// prevent them from being deleted from memory
|
|
7
|
-
const g_preventImageDump = [];
|
|
8
|
-
|
|
9
|
-
const beginLoadImage = (img) => {
|
|
10
|
-
if (g_preventImageDump.indexOf(img) === -1) {
|
|
11
|
-
g_preventImageDump.push(img);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const endLoadImage = (img) => {
|
|
16
|
-
const i = g_preventImageDump.indexOf(img);
|
|
17
|
-
if (i !== -1) {
|
|
18
|
-
g_preventImageDump.splice(i, 1);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const loadImage = (url,preventCache = false) => {
|
|
23
|
-
return new Promise((resolve,reject) => {
|
|
24
|
-
const img = new Image();
|
|
25
|
-
beginLoadImage(img);
|
|
26
|
-
img.crossOrigin = "";
|
|
27
|
-
img.addEventListener("load", evt => {
|
|
28
|
-
endLoadImage(evt.target);
|
|
29
|
-
resolve(evt.target);
|
|
30
|
-
});
|
|
31
|
-
img.addEventListener("error", evt => {
|
|
32
|
-
endLoadImage(evt.target);
|
|
33
|
-
reject(new Error(`Error loading image '${ url }'.`));
|
|
34
|
-
});
|
|
35
|
-
img.addEventListener("abort", evt => {
|
|
36
|
-
endLoadImage(evt.target);
|
|
37
|
-
reject(new Error(`Image load aborted '${ url }'.`));
|
|
38
|
-
});
|
|
39
|
-
img.src = url + (preventCache ? `?${generateUUID()}` : "");
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export default class ImageResourceProvider extends ResourceProvider {
|
|
44
|
-
async load(url) {
|
|
45
|
-
const img = await loadImage(url, false);
|
|
46
|
-
return img;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async write(url,img) {
|
|
50
|
-
let data = null;
|
|
51
|
-
if (img instanceof Image) {
|
|
52
|
-
// TODO: convert to Uint8Array data
|
|
53
|
-
}
|
|
54
|
-
else if (typeof(img) === "string" && /base64/i.test(img)) {
|
|
55
|
-
// Convert base64 image into Uint8Array data
|
|
56
|
-
}
|
|
57
|
-
else if (typeof(img) === "string") {
|
|
58
|
-
// Path: copy image
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
throw new Error("Unsupported image type specified for write");
|
|
62
|
-
}
|
|
63
|
-
return await this.writeStrategy.writeData(url,data);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
deserializeColorTexture,
|
|
3
|
-
deserializeVector,
|
|
4
|
-
deserializeValueTexture
|
|
5
|
-
} from "../base/Material";
|
|
6
|
-
import Texture from "../base/Texture";
|
|
7
|
-
|
|
8
|
-
const checkImageData = (texture) => {
|
|
9
|
-
return texture instanceof Texture ? texture.loadImageData() : Promise.resolve();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default class MaterialModifier {
|
|
13
|
-
constructor(jsonData = null) {
|
|
14
|
-
if (jsonData) {
|
|
15
|
-
if (jsonData['class'] && jsonData['class'] !== "PBRMaterial") {
|
|
16
|
-
console.warn(`Could not apply material modifier because of class "${jsonData['class']}". Check the valid material types in bg2 engine v2`);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if (jsonData.alphaCutoff !== undefined) {
|
|
20
|
-
this.alphaCutoff = jsonData.alphaCutoff;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (jsonData.castShadows !== undefined) {
|
|
24
|
-
this.castShadows = jsonData.castShadows;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (jsonData.diffuse !== undefined) {
|
|
28
|
-
this.diffuse = jsonData.diffuse;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (jsonData.diffuseScale !== undefined) {
|
|
32
|
-
this.diffuseScale = jsonData.diffuseScale;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (jsonData.fresnel !== undefined) {
|
|
36
|
-
this.fresnel = jsonData.fresnel;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (jsonData.isTransparent !== undefined) {
|
|
40
|
-
this.isTransparent = jsonData.isTransparent;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (jsonData.lightEmission !== undefined) {
|
|
44
|
-
this.lightEmission = jsonData.lightEmission;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (jsonData.lightEmissionChannel !== undefined) {
|
|
48
|
-
this.lightEmissionChannel = jsonData.lightEmissionChannel;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (jsonData.lightEmissionScale !== undefined) {
|
|
52
|
-
this.lightEmissionScale = jsonData.lightEmissionScale;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (jsonData.metallic !== undefined) {
|
|
56
|
-
this.metallic = jsonData.metallic;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (jsonData.metallicChannel !== undefined) {
|
|
60
|
-
this.metallicChannel = jsonData.metallicChannel;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (jsonData.metallicScale !== undefined) {
|
|
64
|
-
this.metallicScale = jsonData.metallicScale;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (jsonData.normal !== undefined) {
|
|
68
|
-
this.normal = jsonData.normal;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (jsonData.normalScale !== undefined) {
|
|
72
|
-
this.normalScale = jsonData.normalScale;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (jsonData.roughness !== undefined) {
|
|
76
|
-
this.roughness = jsonData.roughness;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (jsonData.roughnessChannel !== undefined) {
|
|
80
|
-
this.roughnessChannel = jsonData.roughnessChannel;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (jsonData.roughnessScale !== undefined) {
|
|
84
|
-
this.roughnessScale = jsonData.roughnessScale;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (jsonData.unlit !== undefined) {
|
|
88
|
-
this.unlit = jsonData.unlit;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
get alphaCutoff() { return this._alphaCutoff; }
|
|
95
|
-
set alphaCutoff(v) { this._alphaCutoff = v; }
|
|
96
|
-
|
|
97
|
-
get castShadows() { return this._castShadows; }
|
|
98
|
-
set castShadows(v) { this._castShadows = v; }
|
|
99
|
-
|
|
100
|
-
get diffuse() { return this._diffuse; }
|
|
101
|
-
set diffuse(v) { this._diffuse = v; }
|
|
102
|
-
|
|
103
|
-
get diffuseScale() { return this._diffuseScale; }
|
|
104
|
-
set diffuseScale(v) { this._diffuseScale = v; }
|
|
105
|
-
|
|
106
|
-
get fresnel() { return this._fresnel; }
|
|
107
|
-
set fresnel(v) { this._fresnel = v; }
|
|
108
|
-
|
|
109
|
-
get isTransparent() { return this._isTransparent; }
|
|
110
|
-
set isTransparent(v) { this._isTransparent = v; }
|
|
111
|
-
|
|
112
|
-
get lightEmission() { return this._lightEmission; }
|
|
113
|
-
set lightEmission(v) { this._lightEmission = v; }
|
|
114
|
-
|
|
115
|
-
get lightEmissionChannel() { return this._lightEmissionChannel; }
|
|
116
|
-
set lightEmissionChannel(v) { this._lightEmissionChannel = v; }
|
|
117
|
-
|
|
118
|
-
get lightEmissionScale() { return this._lightEmissionScale; }
|
|
119
|
-
set lightEmissionScale(v) { this._lightEmissionScale = v; }
|
|
120
|
-
|
|
121
|
-
get metallic() { return this._metallic; }
|
|
122
|
-
set metallic(v) { this._metallic = v; }
|
|
123
|
-
|
|
124
|
-
get metallicChannel() { return this._metallicChannel; }
|
|
125
|
-
set metallicChannel(v) { this._metallicChannel = v; }
|
|
126
|
-
|
|
127
|
-
get metallicScale() { return this._metallicScale; }
|
|
128
|
-
set metallicScale(v) { this._metallicScale = v; }
|
|
129
|
-
|
|
130
|
-
get normal() { return this._normal; }
|
|
131
|
-
set normal(v) { this._normal = v; }
|
|
132
|
-
|
|
133
|
-
get normalScale() { return this._normalScale; }
|
|
134
|
-
set normalScale(v) { this._normalScale = v; }
|
|
135
|
-
|
|
136
|
-
get roughness() { return this._roughness; }
|
|
137
|
-
set roughness(v) { this._roughness = v; }
|
|
138
|
-
|
|
139
|
-
get roughnessChannel() { return this._roughnessChannel; }
|
|
140
|
-
set roughnessChannel(v) { this._roughnessChannel = v; }
|
|
141
|
-
|
|
142
|
-
get roughnessScale() { return this._roughnessScale; }
|
|
143
|
-
set roughnessScale(v) { this._roughnessScale = v; }
|
|
144
|
-
|
|
145
|
-
get unlit() { return this._unlit; }
|
|
146
|
-
set unlit(v) { this._unlit = v; }
|
|
147
|
-
|
|
148
|
-
async applyModifier(material, relativePath = "") {
|
|
149
|
-
const promises = [];
|
|
150
|
-
if (this.alphaCutoff !== undefined) {
|
|
151
|
-
material.alphaCutoff = this.alphaCutoff;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (this.castShadows !== undefined) {
|
|
155
|
-
material.castShadows = this.castShadows;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (this.diffuse !== undefined) {
|
|
159
|
-
material.diffuse = deserializeColorTexture(this.diffuse, relativePath);
|
|
160
|
-
promises.push(checkImageData(material.diffuse));
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (this.diffuseScale !== undefined) {
|
|
164
|
-
material.diffuseScale = deserializeVector(this.diffuseScale);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (this.fresnel !== undefined) {
|
|
168
|
-
material.fresnel = deserializeVector(this.fresnel);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (this.isTransparent !== undefined) {
|
|
172
|
-
material.isTransparent = this.isTransparent;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (this.lightEmission !== undefined) {
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (this.lightEmissionChannel !== undefined) {
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (this.lightEmissionScale !== undefined) {
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (this.metallic !== undefined) {
|
|
188
|
-
material.metallic = deserializeValueTexture(this.metallic, relativePath);
|
|
189
|
-
promises.push(checkImageData(material.metallic));
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (this.metallicChannel !== undefined) {
|
|
193
|
-
material.metallicChannel = this.metallicChannel;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (this.metallicScale !== undefined) {
|
|
197
|
-
material.metallicScale = deserializeVector(this.metallicScale);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if (this.normal !== undefined) {
|
|
201
|
-
material.normal = deserializeColorTexture(this.normal, relativePath);
|
|
202
|
-
promises.push(checkImageData(material.normal));
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (this.normalScale !== undefined) {
|
|
206
|
-
material.normalScale = deserializeVector(this.normalScale);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (this.roughness !== undefined) {
|
|
210
|
-
material.roughness = deserializeValueTexture(this.roughness, relativePath);
|
|
211
|
-
promises.push(checkImageData(material.roughness));
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (this.roughnessChannel !== undefined) {
|
|
215
|
-
material.roughnessChannel = this.roughnessChannel;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (this.roughnessScale !== undefined) {
|
|
219
|
-
material.roughnessScale = deserializeVector(this.roughnessScale);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (this.unlit !== undefined) {
|
|
223
|
-
material.unlit = this.unlit;
|
|
224
|
-
}
|
|
225
|
-
await Promise.allSettled(promises);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
}
|
package/tools/Resource.js
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import ImageResourceProvider from "./ImageResourceProvider.js";
|
|
3
|
-
import VideoResourceProvider from "./VideoResourceProvider.js";
|
|
4
|
-
import BinaryResourceProvider from "./BinaryResourceProvider.js";
|
|
5
|
-
import TextResourceProvider from "./TextResourceProvider.js";
|
|
6
|
-
|
|
7
|
-
export const ResourceType = {
|
|
8
|
-
PolyList: 'PolyList', // Array of meshes
|
|
9
|
-
Drawable: 'Drawable',
|
|
10
|
-
Node: 'Node',
|
|
11
|
-
Texture: 'Texture',
|
|
12
|
-
Material: 'Material'
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const getExtension = (url) => {
|
|
16
|
-
const reResult = /\.([a-z0-9]+)$/i.exec(url);
|
|
17
|
-
if (reResult) {
|
|
18
|
-
return reResult[1];
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
return "";
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const getFileName = (url) => {
|
|
26
|
-
const reResult = /(.+)\/(.+)$/.exec(url);
|
|
27
|
-
if (reResult) {
|
|
28
|
-
return reResult[2];
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
return url;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export const removeExtension = (url) => {
|
|
36
|
-
const reResult = /(.+)\.(.+)$/.exec(url);
|
|
37
|
-
if (reResult) {
|
|
38
|
-
return reResult[1];
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
return url;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export const removeFileName = (url) => {
|
|
46
|
-
const i = url.lastIndexOf('/');
|
|
47
|
-
if (i != -1) {
|
|
48
|
-
return url.substring(0,i + 1);
|
|
49
|
-
}
|
|
50
|
-
return url;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export const isAbsolute = (url) => {
|
|
54
|
-
return /^http|^\//i.test(url);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export const jointUrl = (base,append) => {
|
|
58
|
-
if (base[base.length - 1] !== '/' && append[0] !== '/') {
|
|
59
|
-
return `${base}/${append}`;
|
|
60
|
-
}
|
|
61
|
-
else if ((base[base.length - 1] === '/' && append[0] !== '/') ||
|
|
62
|
-
(base[base.length - 1] !== '/' && append[0] === '/')) {
|
|
63
|
-
return `${base}${append}`;
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
return `${base}${append.slice(1)}`;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export const isFormat = (url,formats) => formats.some(fmt => (new RegExp(`\.${fmt}`,'i')).test(url));
|
|
71
|
-
|
|
72
|
-
export const addFormats = (fmts, dst) => {
|
|
73
|
-
if (!Array.isArray(fmts)) {
|
|
74
|
-
fmts = [fmts]
|
|
75
|
-
}
|
|
76
|
-
fmts.forEach(fmt => {
|
|
77
|
-
if (dst.indexOf(fmt) === -1) {
|
|
78
|
-
dst.push(fmt);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const g_validImageFormats = [
|
|
85
|
-
"jpg",
|
|
86
|
-
"jpeg",
|
|
87
|
-
"gif",
|
|
88
|
-
"png"
|
|
89
|
-
];
|
|
90
|
-
|
|
91
|
-
export const isValidImage = (url) => isFormat(url,g_validImageFormats);
|
|
92
|
-
|
|
93
|
-
export const addImageFormats = (fmts) => {
|
|
94
|
-
addFormats(fmts, g_validImageFormats);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export const getValidImageFormats = () => g_validImageFormats;
|
|
98
|
-
|
|
99
|
-
const g_validVideoFormats = [
|
|
100
|
-
"mp4",
|
|
101
|
-
"m4v"
|
|
102
|
-
];
|
|
103
|
-
|
|
104
|
-
export const isValidVideo = (url) => isFormat(url,g_validVideoFormats);
|
|
105
|
-
|
|
106
|
-
export const addVideoFormats = (fmts) => {
|
|
107
|
-
addFormats(fmts, g_validVideoFormats);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export const getValidVideoFormats = () => g_validVideoFormats;
|
|
111
|
-
|
|
112
|
-
const g_validBinaryFormats = [
|
|
113
|
-
"vwglb",
|
|
114
|
-
"bg2"
|
|
115
|
-
];
|
|
116
|
-
|
|
117
|
-
export const isValidBinary = (url) => isFormat(url, g_validBinaryFormats);
|
|
118
|
-
|
|
119
|
-
export const addBinaryFormats = (fmts) => {
|
|
120
|
-
addFormats(fmts, g_validBinaryFormats);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export const getValidBinaryFormats = () => g_validBinaryFormats;
|
|
124
|
-
|
|
125
|
-
export default class Resource {
|
|
126
|
-
|
|
127
|
-
constructor({
|
|
128
|
-
imageProvider = null,
|
|
129
|
-
videoProvider = null,
|
|
130
|
-
binaryProvider = null,
|
|
131
|
-
textProvider = null,
|
|
132
|
-
writeStrategy = null
|
|
133
|
-
} = {}) {
|
|
134
|
-
this._imageProvider = imageProvider || new ImageResourceProvider();
|
|
135
|
-
this._videoProvider = videoProvider || new VideoResourceProvider();
|
|
136
|
-
this._binaryProvider = binaryProvider || new BinaryResourceProvider();
|
|
137
|
-
this._textProvider = textProvider || new TextResourceProvider();
|
|
138
|
-
this.writeStrategy = writeStrategy;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
set writeStrategy(ws) {
|
|
142
|
-
this._writeStrategy = ws;
|
|
143
|
-
|
|
144
|
-
this._imageProvider.writeStrategy = ws;
|
|
145
|
-
this._videoProvider.writeStrategy = ws;
|
|
146
|
-
this._binaryProvider.writeStrategy = ws;
|
|
147
|
-
this._textProvider.writeStrategy = ws;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
get writeStrategy() {
|
|
151
|
-
return this._writeStrategy;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
getProvider(url) {
|
|
155
|
-
switch (true) {
|
|
156
|
-
case isValidImage(url):
|
|
157
|
-
return this._imageProvider;
|
|
158
|
-
case isValidVideo(url):
|
|
159
|
-
return this._videoProvider;
|
|
160
|
-
case isValidBinary(url):
|
|
161
|
-
return this._binaryProvider;
|
|
162
|
-
default:
|
|
163
|
-
return this._textProvider;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async load(url) {
|
|
168
|
-
const provider = this.getProvider(url);
|
|
169
|
-
const data = await provider.load(url);
|
|
170
|
-
return data;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
async write(url,data) {
|
|
174
|
-
const provider = this.getProvider(url);
|
|
175
|
-
return await provider.write(url,data);
|
|
176
|
-
}
|
|
177
|
-
}
|