@babylonjs/viewer 5.0.0 → 5.0.3
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/configuration/configuration.d.ts +107 -107
- package/configuration/configuration.js +15 -15
- package/configuration/configurationCompatibility.d.ts +8 -8
- package/configuration/configurationCompatibility.js +65 -65
- package/configuration/configurationContainer.d.ts +10 -10
- package/configuration/configurationContainer.js +9 -9
- package/configuration/globals.d.ts +6 -6
- package/configuration/globals.js +17 -17
- package/configuration/index.d.ts +2 -2
- package/configuration/index.js +3 -3
- package/configuration/interfaces/cameraConfiguration.d.ts +31 -31
- package/configuration/interfaces/cameraConfiguration.js +1 -1
- package/configuration/interfaces/colorGradingConfiguration.d.ts +81 -81
- package/configuration/interfaces/colorGradingConfiguration.js +1 -1
- package/configuration/interfaces/defaultRenderingPipelineConfiguration.d.ts +20 -20
- package/configuration/interfaces/defaultRenderingPipelineConfiguration.js +1 -1
- package/configuration/interfaces/environmentMapConfiguration.d.ts +22 -22
- package/configuration/interfaces/environmentMapConfiguration.js +1 -1
- package/configuration/interfaces/groundConfiguration.d.ts +24 -24
- package/configuration/interfaces/groundConfiguration.js +1 -1
- package/configuration/interfaces/imageProcessingConfiguration.d.ts +43 -43
- package/configuration/interfaces/imageProcessingConfiguration.js +1 -1
- package/configuration/interfaces/index.d.ts +15 -15
- package/configuration/interfaces/index.js +15 -15
- package/configuration/interfaces/lightConfiguration.d.ts +60 -60
- package/configuration/interfaces/lightConfiguration.js +1 -1
- package/configuration/interfaces/modelAnimationConfiguration.d.ts +26 -26
- package/configuration/interfaces/modelAnimationConfiguration.js +1 -1
- package/configuration/interfaces/modelConfiguration.d.ts +65 -65
- package/configuration/interfaces/modelConfiguration.js +1 -1
- package/configuration/interfaces/observersConfiguration.d.ts +5 -5
- package/configuration/interfaces/observersConfiguration.js +1 -1
- package/configuration/interfaces/sceneConfiguration.d.ts +48 -48
- package/configuration/interfaces/sceneConfiguration.js +1 -1
- package/configuration/interfaces/sceneOptimizerConfiguration.d.ts +23 -23
- package/configuration/interfaces/sceneOptimizerConfiguration.js +1 -1
- package/configuration/interfaces/skyboxConfiguration.d.ts +21 -21
- package/configuration/interfaces/skyboxConfiguration.js +1 -1
- package/configuration/interfaces/templateConfiguration.d.ts +67 -67
- package/configuration/interfaces/templateConfiguration.js +1 -1
- package/configuration/interfaces/vrConfiguration.d.ts +16 -16
- package/configuration/interfaces/vrConfiguration.js +1 -1
- package/configuration/loader.d.ts +4 -4
- package/configuration/loader.js +16 -16
- package/configuration/mappers.d.ts +42 -42
- package/configuration/mappers.js +190 -190
- package/configuration/renderOnlyLoader.d.ts +33 -33
- package/configuration/renderOnlyLoader.js +161 -161
- package/configuration/types/default.d.ts +6 -6
- package/configuration/types/default.js +120 -120
- package/configuration/types/environmentMap.d.ts +5 -5
- package/configuration/types/environmentMap.js +13 -13
- package/configuration/types/extended.d.ts +6 -6
- package/configuration/types/extended.js +316 -316
- package/configuration/types/index.d.ts +13 -13
- package/configuration/types/index.js +49 -49
- package/configuration/types/minimal.d.ts +6 -6
- package/configuration/types/minimal.js +42 -42
- package/configuration/types/renderOnlyDefault.d.ts +30 -30
- package/configuration/types/renderOnlyDefault.js +30 -30
- package/configuration/types/shadowLight.d.ts +9 -9
- package/configuration/types/shadowLight.js +63 -63
- package/helper/index.d.ts +26 -26
- package/helper/index.js +62 -62
- package/index.d.ts +30 -30
- package/index.js +45 -45
- package/initializer.d.ts +11 -11
- package/initializer.js +34 -34
- package/interfaces.d.ts +5 -5
- package/interfaces.js +1 -1
- package/labs/environmentSerializer.d.ts +126 -126
- package/labs/environmentSerializer.js +190 -190
- package/labs/texture.d.ts +183 -183
- package/labs/texture.js +300 -300
- package/labs/viewerLabs.d.ts +51 -51
- package/labs/viewerLabs.js +133 -133
- package/loader/modelLoader.d.ts +47 -47
- package/loader/modelLoader.js +189 -189
- package/loader/plugins/applyMaterialConfig.d.ts +12 -12
- package/loader/plugins/applyMaterialConfig.js +15 -15
- package/loader/plugins/extendedMaterialLoaderPlugin.d.ts +9 -9
- package/loader/plugins/extendedMaterialLoaderPlugin.js +15 -15
- package/loader/plugins/index.d.ts +18 -18
- package/loader/plugins/index.js +42 -42
- package/loader/plugins/loaderPlugin.d.ts +24 -24
- package/loader/plugins/loaderPlugin.js +1 -1
- package/loader/plugins/msftLodLoaderPlugin.d.ts +12 -12
- package/loader/plugins/msftLodLoaderPlugin.js +20 -20
- package/loader/plugins/telemetryLoaderPlugin.d.ts +12 -12
- package/loader/plugins/telemetryLoaderPlugin.js +35 -35
- package/managers/observablesManager.d.ts +66 -66
- package/managers/observablesManager.js +34 -34
- package/managers/sceneManager.d.ts +243 -243
- package/managers/sceneManager.js +1388 -1388
- package/managers/telemetryManager.d.ts +57 -57
- package/managers/telemetryManager.js +113 -113
- package/model/modelAnimation.d.ts +215 -215
- package/model/modelAnimation.js +232 -232
- package/model/viewerModel.d.ts +228 -228
- package/model/viewerModel.js +669 -669
- package/optimizer/custom/extended.d.ts +11 -11
- package/optimizer/custom/extended.js +98 -98
- package/optimizer/custom/index.d.ts +8 -8
- package/optimizer/custom/index.js +24 -24
- package/package.json +5 -5
- package/renderOnlyIndex.d.ts +11 -11
- package/renderOnlyIndex.js +17 -17
- package/templating/eventManager.d.ts +35 -35
- package/templating/eventManager.js +65 -65
- package/templating/plugins/hdButtonPlugin.d.ts +9 -9
- package/templating/plugins/hdButtonPlugin.js +21 -21
- package/templating/plugins/printButton.d.ts +9 -9
- package/templating/plugins/printButton.js +40 -40
- package/templating/templateManager.d.ts +190 -190
- package/templating/templateManager.js +553 -553
- package/templating/viewerTemplatePlugin.d.ts +21 -21
- package/templating/viewerTemplatePlugin.js +68 -68
- package/viewer/defaultViewer.d.ts +122 -122
- package/viewer/defaultViewer.js +665 -665
- package/viewer/renderOnlyViewer.d.ts +8 -8
- package/viewer/renderOnlyViewer.js +43 -43
- package/viewer/viewer.d.ts +254 -254
- package/viewer/viewer.js +777 -777
- package/viewer/viewerManager.d.ts +55 -55
- package/viewer/viewerManager.js +87 -87
- package/viewer/viewerWithTemplate.d.ts +9 -9
- package/viewer/viewerWithTemplate.js +19 -19
|
@@ -1,191 +1,191 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
-
import { Vector3 } from "@babylonjs/core/Maths/math.js";
|
|
3
|
-
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
|
4
|
-
import { TextureCube } from "./texture.js";
|
|
5
|
-
/**
|
|
6
|
-
* A static class proving methods to aid parsing Spectre environment files
|
|
7
|
-
*/
|
|
8
|
-
var EnvironmentDeserializer = /** @class */ (function () {
|
|
9
|
-
function EnvironmentDeserializer() {
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Parses an arraybuffer into a new PBREnvironment object
|
|
13
|
-
* @param arrayBuffer The arraybuffer of the Spectre environment file
|
|
14
|
-
* @return a PBREnvironment object
|
|
15
|
-
*/
|
|
16
|
-
EnvironmentDeserializer.Parse = function (arrayBuffer) {
|
|
17
|
-
var environment = {
|
|
18
|
-
//irradiance
|
|
19
|
-
irradiancePolynomialCoefficients: {
|
|
20
|
-
x: new Vector3(0, 0, 0),
|
|
21
|
-
y: new Vector3(0, 0, 0),
|
|
22
|
-
z: new Vector3(0, 0, 0),
|
|
23
|
-
xx: new Vector3(0, 0, 0),
|
|
24
|
-
yy: new Vector3(0, 0, 0),
|
|
25
|
-
zz: new Vector3(0, 0, 0),
|
|
26
|
-
yz: new Vector3(0, 0, 0),
|
|
27
|
-
zx: new Vector3(0, 0, 0),
|
|
28
|
-
xy: new Vector3(0, 0, 0),
|
|
29
|
-
},
|
|
30
|
-
//specular
|
|
31
|
-
textureIntensityScale: 1.0,
|
|
32
|
-
};
|
|
33
|
-
//read .env
|
|
34
|
-
var littleEndian = false;
|
|
35
|
-
var magicBytes = [0x86, 0x16, 0x87, 0x96, 0xf6, 0xd6, 0x96, 0x36];
|
|
36
|
-
var dataView = new DataView(arrayBuffer);
|
|
37
|
-
var pos = 0;
|
|
38
|
-
for (var i = 0; i < magicBytes.length; i++) {
|
|
39
|
-
if (dataView.getUint8(pos++) !== magicBytes[i]) {
|
|
40
|
-
Tools.Error("Not a Spectre environment map");
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
var version = dataView.getUint16(pos, littleEndian);
|
|
44
|
-
pos += 2;
|
|
45
|
-
if (version !== 1) {
|
|
46
|
-
Tools.Warn('Unsupported Spectre environment map version "' + version + '"');
|
|
47
|
-
}
|
|
48
|
-
//read json descriptor - collect characters up to null terminator
|
|
49
|
-
var descriptorString = "";
|
|
50
|
-
var charCode = 0x00;
|
|
51
|
-
while ((charCode = dataView.getUint8(pos++))) {
|
|
52
|
-
descriptorString += String.fromCharCode(charCode);
|
|
53
|
-
}
|
|
54
|
-
var descriptor = JSON.parse(descriptorString);
|
|
55
|
-
var payloadPos = pos;
|
|
56
|
-
//irradiance
|
|
57
|
-
switch (descriptor.irradiance.type) {
|
|
58
|
-
case "irradiance_sh_coefficients_9": {
|
|
59
|
-
//irradiance
|
|
60
|
-
var harmonics = descriptor.irradiance;
|
|
61
|
-
EnvironmentDeserializer._ConvertSHIrradianceToLambertianRadiance(harmonics);
|
|
62
|
-
//harmonics now represent radiance
|
|
63
|
-
EnvironmentDeserializer._ConvertSHToSP(harmonics, environment.irradiancePolynomialCoefficients);
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
default:
|
|
67
|
-
Tools.Error("Unhandled MapType descriptor.irradiance.type (" + descriptor.irradiance.type + ")");
|
|
68
|
-
}
|
|
69
|
-
//specular
|
|
70
|
-
switch (descriptor.specular.type) {
|
|
71
|
-
case "cubemap_faces": {
|
|
72
|
-
var specularDescriptor = descriptor.specular;
|
|
73
|
-
var specularTexture = (environment.specularTexture = new TextureCube(6408 /* RGBA */, 5121 /* UNSIGNED_BYTE */));
|
|
74
|
-
environment.textureIntensityScale = specularDescriptor.multiplier != null ? specularDescriptor.multiplier : 1.0;
|
|
75
|
-
var mipmaps = specularDescriptor.mipmaps;
|
|
76
|
-
var imageType = specularDescriptor.imageType;
|
|
77
|
-
for (var l = 0; l < mipmaps.length; l++) {
|
|
78
|
-
var faceRanges = mipmaps[l];
|
|
79
|
-
specularTexture.source[l] = [];
|
|
80
|
-
for (var i = 0; i < 6; i++) {
|
|
81
|
-
var range = faceRanges[i];
|
|
82
|
-
var bytes = new Uint8Array(arrayBuffer, payloadPos + range.pos, range.length);
|
|
83
|
-
switch (imageType) {
|
|
84
|
-
case "png": {
|
|
85
|
-
//construct image element from bytes
|
|
86
|
-
var image = new Image();
|
|
87
|
-
var src = URL.createObjectURL(new Blob([bytes], { type: "image/png" }));
|
|
88
|
-
image.src = src;
|
|
89
|
-
specularTexture.source[l][i] = image;
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
default:
|
|
93
|
-
Tools.Error("Unhandled ImageType descriptor.specular.imageType (" + imageType + ")");
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
default:
|
|
100
|
-
Tools.Error("Unhandled MapType descriptor.specular.type (" + descriptor.specular.type + ")");
|
|
101
|
-
}
|
|
102
|
-
return environment;
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* Convert from irradiance to outgoing radiance for Lambertian BDRF, suitable for efficient shader evaluation.
|
|
106
|
-
* L = (1/pi) * E * rho
|
|
107
|
-
*
|
|
108
|
-
* This is done by an additional scale by 1/pi, so is a fairly trivial operation but important conceptually.
|
|
109
|
-
* @param harmonics Spherical harmonic coefficients (9)
|
|
110
|
-
*/
|
|
111
|
-
EnvironmentDeserializer._ConvertSHIrradianceToLambertianRadiance = function (harmonics) {
|
|
112
|
-
EnvironmentDeserializer._ScaleSH(harmonics, 1 / Math.PI);
|
|
113
|
-
// The resultant SH now represents outgoing radiance, so includes the Lambert 1/pi normalisation factor but without albedo (rho) applied
|
|
114
|
-
// (The pixel shader must apply albedo after texture fetches, etc).
|
|
115
|
-
};
|
|
116
|
-
/**
|
|
117
|
-
* Convert spherical harmonics to spherical polynomial coefficients
|
|
118
|
-
* @param harmonics Spherical harmonic coefficients (9)
|
|
119
|
-
* @param outPolynomialCoefficents Polynomial coefficients (9) object to store result
|
|
120
|
-
*/
|
|
121
|
-
EnvironmentDeserializer._ConvertSHToSP = function (harmonics, outPolynomialCoefficents) {
|
|
122
|
-
var rPi = 1 / Math.PI;
|
|
123
|
-
//x
|
|
124
|
-
outPolynomialCoefficents.x.x = 1.02333 * harmonics.l11[0] * rPi;
|
|
125
|
-
outPolynomialCoefficents.x.y = 1.02333 * harmonics.l11[1] * rPi;
|
|
126
|
-
outPolynomialCoefficents.x.z = 1.02333 * harmonics.l11[2] * rPi;
|
|
127
|
-
outPolynomialCoefficents.y.x = 1.02333 * harmonics.l1_1[0] * rPi;
|
|
128
|
-
outPolynomialCoefficents.y.y = 1.02333 * harmonics.l1_1[1] * rPi;
|
|
129
|
-
outPolynomialCoefficents.y.z = 1.02333 * harmonics.l1_1[2] * rPi;
|
|
130
|
-
outPolynomialCoefficents.z.x = 1.02333 * harmonics.l10[0] * rPi;
|
|
131
|
-
outPolynomialCoefficents.z.y = 1.02333 * harmonics.l10[1] * rPi;
|
|
132
|
-
outPolynomialCoefficents.z.z = 1.02333 * harmonics.l10[2] * rPi;
|
|
133
|
-
//xx
|
|
134
|
-
outPolynomialCoefficents.xx.x = (0.886277 * harmonics.l00[0] - 0.247708 * harmonics.l20[0] + 0.429043 * harmonics.l22[0]) * rPi;
|
|
135
|
-
outPolynomialCoefficents.xx.y = (0.886277 * harmonics.l00[1] - 0.247708 * harmonics.l20[1] + 0.429043 * harmonics.l22[1]) * rPi;
|
|
136
|
-
outPolynomialCoefficents.xx.z = (0.886277 * harmonics.l00[2] - 0.247708 * harmonics.l20[2] + 0.429043 * harmonics.l22[2]) * rPi;
|
|
137
|
-
outPolynomialCoefficents.yy.x = (0.886277 * harmonics.l00[0] - 0.247708 * harmonics.l20[0] - 0.429043 * harmonics.l22[0]) * rPi;
|
|
138
|
-
outPolynomialCoefficents.yy.y = (0.886277 * harmonics.l00[1] - 0.247708 * harmonics.l20[1] - 0.429043 * harmonics.l22[1]) * rPi;
|
|
139
|
-
outPolynomialCoefficents.yy.z = (0.886277 * harmonics.l00[2] - 0.247708 * harmonics.l20[2] - 0.429043 * harmonics.l22[2]) * rPi;
|
|
140
|
-
outPolynomialCoefficents.zz.x = (0.886277 * harmonics.l00[0] + 0.495417 * harmonics.l20[0]) * rPi;
|
|
141
|
-
outPolynomialCoefficents.zz.y = (0.886277 * harmonics.l00[1] + 0.495417 * harmonics.l20[1]) * rPi;
|
|
142
|
-
outPolynomialCoefficents.zz.z = (0.886277 * harmonics.l00[2] + 0.495417 * harmonics.l20[2]) * rPi;
|
|
143
|
-
//yz
|
|
144
|
-
outPolynomialCoefficents.yz.x = 0.858086 * harmonics.l2_1[0] * rPi;
|
|
145
|
-
outPolynomialCoefficents.yz.y = 0.858086 * harmonics.l2_1[1] * rPi;
|
|
146
|
-
outPolynomialCoefficents.yz.z = 0.858086 * harmonics.l2_1[2] * rPi;
|
|
147
|
-
outPolynomialCoefficents.zx.x = 0.858086 * harmonics.l21[0] * rPi;
|
|
148
|
-
outPolynomialCoefficents.zx.y = 0.858086 * harmonics.l21[1] * rPi;
|
|
149
|
-
outPolynomialCoefficents.zx.z = 0.858086 * harmonics.l21[2] * rPi;
|
|
150
|
-
outPolynomialCoefficents.xy.x = 0.858086 * harmonics.l2_2[0] * rPi;
|
|
151
|
-
outPolynomialCoefficents.xy.y = 0.858086 * harmonics.l2_2[1] * rPi;
|
|
152
|
-
outPolynomialCoefficents.xy.z = 0.858086 * harmonics.l2_2[2] * rPi;
|
|
153
|
-
};
|
|
154
|
-
/**
|
|
155
|
-
* Multiplies harmonic coefficients in place
|
|
156
|
-
* @param harmonics Spherical harmonic coefficients (9)
|
|
157
|
-
* @param scaleFactor Value to multiply by
|
|
158
|
-
*/
|
|
159
|
-
EnvironmentDeserializer._ScaleSH = function (harmonics, scaleFactor) {
|
|
160
|
-
harmonics.l00[0] *= scaleFactor;
|
|
161
|
-
harmonics.l00[1] *= scaleFactor;
|
|
162
|
-
harmonics.l00[2] *= scaleFactor;
|
|
163
|
-
harmonics.l1_1[0] *= scaleFactor;
|
|
164
|
-
harmonics.l1_1[1] *= scaleFactor;
|
|
165
|
-
harmonics.l1_1[2] *= scaleFactor;
|
|
166
|
-
harmonics.l10[0] *= scaleFactor;
|
|
167
|
-
harmonics.l10[1] *= scaleFactor;
|
|
168
|
-
harmonics.l10[2] *= scaleFactor;
|
|
169
|
-
harmonics.l11[0] *= scaleFactor;
|
|
170
|
-
harmonics.l11[1] *= scaleFactor;
|
|
171
|
-
harmonics.l11[2] *= scaleFactor;
|
|
172
|
-
harmonics.l2_2[0] *= scaleFactor;
|
|
173
|
-
harmonics.l2_2[1] *= scaleFactor;
|
|
174
|
-
harmonics.l2_2[2] *= scaleFactor;
|
|
175
|
-
harmonics.l2_1[0] *= scaleFactor;
|
|
176
|
-
harmonics.l2_1[1] *= scaleFactor;
|
|
177
|
-
harmonics.l2_1[2] *= scaleFactor;
|
|
178
|
-
harmonics.l20[0] *= scaleFactor;
|
|
179
|
-
harmonics.l20[1] *= scaleFactor;
|
|
180
|
-
harmonics.l20[2] *= scaleFactor;
|
|
181
|
-
harmonics.l21[0] *= scaleFactor;
|
|
182
|
-
harmonics.l21[1] *= scaleFactor;
|
|
183
|
-
harmonics.l21[2] *= scaleFactor;
|
|
184
|
-
harmonics.l22[0] *= scaleFactor;
|
|
185
|
-
harmonics.l22[1] *= scaleFactor;
|
|
186
|
-
harmonics.l22[2] *= scaleFactor;
|
|
187
|
-
};
|
|
188
|
-
return EnvironmentDeserializer;
|
|
189
|
-
}());
|
|
190
|
-
export { EnvironmentDeserializer };
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
+
import { Vector3 } from "@babylonjs/core/Maths/math.js";
|
|
3
|
+
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
|
4
|
+
import { TextureCube } from "./texture.js";
|
|
5
|
+
/**
|
|
6
|
+
* A static class proving methods to aid parsing Spectre environment files
|
|
7
|
+
*/
|
|
8
|
+
var EnvironmentDeserializer = /** @class */ (function () {
|
|
9
|
+
function EnvironmentDeserializer() {
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parses an arraybuffer into a new PBREnvironment object
|
|
13
|
+
* @param arrayBuffer The arraybuffer of the Spectre environment file
|
|
14
|
+
* @return a PBREnvironment object
|
|
15
|
+
*/
|
|
16
|
+
EnvironmentDeserializer.Parse = function (arrayBuffer) {
|
|
17
|
+
var environment = {
|
|
18
|
+
//irradiance
|
|
19
|
+
irradiancePolynomialCoefficients: {
|
|
20
|
+
x: new Vector3(0, 0, 0),
|
|
21
|
+
y: new Vector3(0, 0, 0),
|
|
22
|
+
z: new Vector3(0, 0, 0),
|
|
23
|
+
xx: new Vector3(0, 0, 0),
|
|
24
|
+
yy: new Vector3(0, 0, 0),
|
|
25
|
+
zz: new Vector3(0, 0, 0),
|
|
26
|
+
yz: new Vector3(0, 0, 0),
|
|
27
|
+
zx: new Vector3(0, 0, 0),
|
|
28
|
+
xy: new Vector3(0, 0, 0),
|
|
29
|
+
},
|
|
30
|
+
//specular
|
|
31
|
+
textureIntensityScale: 1.0,
|
|
32
|
+
};
|
|
33
|
+
//read .env
|
|
34
|
+
var littleEndian = false;
|
|
35
|
+
var magicBytes = [0x86, 0x16, 0x87, 0x96, 0xf6, 0xd6, 0x96, 0x36];
|
|
36
|
+
var dataView = new DataView(arrayBuffer);
|
|
37
|
+
var pos = 0;
|
|
38
|
+
for (var i = 0; i < magicBytes.length; i++) {
|
|
39
|
+
if (dataView.getUint8(pos++) !== magicBytes[i]) {
|
|
40
|
+
Tools.Error("Not a Spectre environment map");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
var version = dataView.getUint16(pos, littleEndian);
|
|
44
|
+
pos += 2;
|
|
45
|
+
if (version !== 1) {
|
|
46
|
+
Tools.Warn('Unsupported Spectre environment map version "' + version + '"');
|
|
47
|
+
}
|
|
48
|
+
//read json descriptor - collect characters up to null terminator
|
|
49
|
+
var descriptorString = "";
|
|
50
|
+
var charCode = 0x00;
|
|
51
|
+
while ((charCode = dataView.getUint8(pos++))) {
|
|
52
|
+
descriptorString += String.fromCharCode(charCode);
|
|
53
|
+
}
|
|
54
|
+
var descriptor = JSON.parse(descriptorString);
|
|
55
|
+
var payloadPos = pos;
|
|
56
|
+
//irradiance
|
|
57
|
+
switch (descriptor.irradiance.type) {
|
|
58
|
+
case "irradiance_sh_coefficients_9": {
|
|
59
|
+
//irradiance
|
|
60
|
+
var harmonics = descriptor.irradiance;
|
|
61
|
+
EnvironmentDeserializer._ConvertSHIrradianceToLambertianRadiance(harmonics);
|
|
62
|
+
//harmonics now represent radiance
|
|
63
|
+
EnvironmentDeserializer._ConvertSHToSP(harmonics, environment.irradiancePolynomialCoefficients);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
default:
|
|
67
|
+
Tools.Error("Unhandled MapType descriptor.irradiance.type (" + descriptor.irradiance.type + ")");
|
|
68
|
+
}
|
|
69
|
+
//specular
|
|
70
|
+
switch (descriptor.specular.type) {
|
|
71
|
+
case "cubemap_faces": {
|
|
72
|
+
var specularDescriptor = descriptor.specular;
|
|
73
|
+
var specularTexture = (environment.specularTexture = new TextureCube(6408 /* RGBA */, 5121 /* UNSIGNED_BYTE */));
|
|
74
|
+
environment.textureIntensityScale = specularDescriptor.multiplier != null ? specularDescriptor.multiplier : 1.0;
|
|
75
|
+
var mipmaps = specularDescriptor.mipmaps;
|
|
76
|
+
var imageType = specularDescriptor.imageType;
|
|
77
|
+
for (var l = 0; l < mipmaps.length; l++) {
|
|
78
|
+
var faceRanges = mipmaps[l];
|
|
79
|
+
specularTexture.source[l] = [];
|
|
80
|
+
for (var i = 0; i < 6; i++) {
|
|
81
|
+
var range = faceRanges[i];
|
|
82
|
+
var bytes = new Uint8Array(arrayBuffer, payloadPos + range.pos, range.length);
|
|
83
|
+
switch (imageType) {
|
|
84
|
+
case "png": {
|
|
85
|
+
//construct image element from bytes
|
|
86
|
+
var image = new Image();
|
|
87
|
+
var src = URL.createObjectURL(new Blob([bytes], { type: "image/png" }));
|
|
88
|
+
image.src = src;
|
|
89
|
+
specularTexture.source[l][i] = image;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
default:
|
|
93
|
+
Tools.Error("Unhandled ImageType descriptor.specular.imageType (" + imageType + ")");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
default:
|
|
100
|
+
Tools.Error("Unhandled MapType descriptor.specular.type (" + descriptor.specular.type + ")");
|
|
101
|
+
}
|
|
102
|
+
return environment;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Convert from irradiance to outgoing radiance for Lambertian BDRF, suitable for efficient shader evaluation.
|
|
106
|
+
* L = (1/pi) * E * rho
|
|
107
|
+
*
|
|
108
|
+
* This is done by an additional scale by 1/pi, so is a fairly trivial operation but important conceptually.
|
|
109
|
+
* @param harmonics Spherical harmonic coefficients (9)
|
|
110
|
+
*/
|
|
111
|
+
EnvironmentDeserializer._ConvertSHIrradianceToLambertianRadiance = function (harmonics) {
|
|
112
|
+
EnvironmentDeserializer._ScaleSH(harmonics, 1 / Math.PI);
|
|
113
|
+
// The resultant SH now represents outgoing radiance, so includes the Lambert 1/pi normalisation factor but without albedo (rho) applied
|
|
114
|
+
// (The pixel shader must apply albedo after texture fetches, etc).
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Convert spherical harmonics to spherical polynomial coefficients
|
|
118
|
+
* @param harmonics Spherical harmonic coefficients (9)
|
|
119
|
+
* @param outPolynomialCoefficents Polynomial coefficients (9) object to store result
|
|
120
|
+
*/
|
|
121
|
+
EnvironmentDeserializer._ConvertSHToSP = function (harmonics, outPolynomialCoefficents) {
|
|
122
|
+
var rPi = 1 / Math.PI;
|
|
123
|
+
//x
|
|
124
|
+
outPolynomialCoefficents.x.x = 1.02333 * harmonics.l11[0] * rPi;
|
|
125
|
+
outPolynomialCoefficents.x.y = 1.02333 * harmonics.l11[1] * rPi;
|
|
126
|
+
outPolynomialCoefficents.x.z = 1.02333 * harmonics.l11[2] * rPi;
|
|
127
|
+
outPolynomialCoefficents.y.x = 1.02333 * harmonics.l1_1[0] * rPi;
|
|
128
|
+
outPolynomialCoefficents.y.y = 1.02333 * harmonics.l1_1[1] * rPi;
|
|
129
|
+
outPolynomialCoefficents.y.z = 1.02333 * harmonics.l1_1[2] * rPi;
|
|
130
|
+
outPolynomialCoefficents.z.x = 1.02333 * harmonics.l10[0] * rPi;
|
|
131
|
+
outPolynomialCoefficents.z.y = 1.02333 * harmonics.l10[1] * rPi;
|
|
132
|
+
outPolynomialCoefficents.z.z = 1.02333 * harmonics.l10[2] * rPi;
|
|
133
|
+
//xx
|
|
134
|
+
outPolynomialCoefficents.xx.x = (0.886277 * harmonics.l00[0] - 0.247708 * harmonics.l20[0] + 0.429043 * harmonics.l22[0]) * rPi;
|
|
135
|
+
outPolynomialCoefficents.xx.y = (0.886277 * harmonics.l00[1] - 0.247708 * harmonics.l20[1] + 0.429043 * harmonics.l22[1]) * rPi;
|
|
136
|
+
outPolynomialCoefficents.xx.z = (0.886277 * harmonics.l00[2] - 0.247708 * harmonics.l20[2] + 0.429043 * harmonics.l22[2]) * rPi;
|
|
137
|
+
outPolynomialCoefficents.yy.x = (0.886277 * harmonics.l00[0] - 0.247708 * harmonics.l20[0] - 0.429043 * harmonics.l22[0]) * rPi;
|
|
138
|
+
outPolynomialCoefficents.yy.y = (0.886277 * harmonics.l00[1] - 0.247708 * harmonics.l20[1] - 0.429043 * harmonics.l22[1]) * rPi;
|
|
139
|
+
outPolynomialCoefficents.yy.z = (0.886277 * harmonics.l00[2] - 0.247708 * harmonics.l20[2] - 0.429043 * harmonics.l22[2]) * rPi;
|
|
140
|
+
outPolynomialCoefficents.zz.x = (0.886277 * harmonics.l00[0] + 0.495417 * harmonics.l20[0]) * rPi;
|
|
141
|
+
outPolynomialCoefficents.zz.y = (0.886277 * harmonics.l00[1] + 0.495417 * harmonics.l20[1]) * rPi;
|
|
142
|
+
outPolynomialCoefficents.zz.z = (0.886277 * harmonics.l00[2] + 0.495417 * harmonics.l20[2]) * rPi;
|
|
143
|
+
//yz
|
|
144
|
+
outPolynomialCoefficents.yz.x = 0.858086 * harmonics.l2_1[0] * rPi;
|
|
145
|
+
outPolynomialCoefficents.yz.y = 0.858086 * harmonics.l2_1[1] * rPi;
|
|
146
|
+
outPolynomialCoefficents.yz.z = 0.858086 * harmonics.l2_1[2] * rPi;
|
|
147
|
+
outPolynomialCoefficents.zx.x = 0.858086 * harmonics.l21[0] * rPi;
|
|
148
|
+
outPolynomialCoefficents.zx.y = 0.858086 * harmonics.l21[1] * rPi;
|
|
149
|
+
outPolynomialCoefficents.zx.z = 0.858086 * harmonics.l21[2] * rPi;
|
|
150
|
+
outPolynomialCoefficents.xy.x = 0.858086 * harmonics.l2_2[0] * rPi;
|
|
151
|
+
outPolynomialCoefficents.xy.y = 0.858086 * harmonics.l2_2[1] * rPi;
|
|
152
|
+
outPolynomialCoefficents.xy.z = 0.858086 * harmonics.l2_2[2] * rPi;
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Multiplies harmonic coefficients in place
|
|
156
|
+
* @param harmonics Spherical harmonic coefficients (9)
|
|
157
|
+
* @param scaleFactor Value to multiply by
|
|
158
|
+
*/
|
|
159
|
+
EnvironmentDeserializer._ScaleSH = function (harmonics, scaleFactor) {
|
|
160
|
+
harmonics.l00[0] *= scaleFactor;
|
|
161
|
+
harmonics.l00[1] *= scaleFactor;
|
|
162
|
+
harmonics.l00[2] *= scaleFactor;
|
|
163
|
+
harmonics.l1_1[0] *= scaleFactor;
|
|
164
|
+
harmonics.l1_1[1] *= scaleFactor;
|
|
165
|
+
harmonics.l1_1[2] *= scaleFactor;
|
|
166
|
+
harmonics.l10[0] *= scaleFactor;
|
|
167
|
+
harmonics.l10[1] *= scaleFactor;
|
|
168
|
+
harmonics.l10[2] *= scaleFactor;
|
|
169
|
+
harmonics.l11[0] *= scaleFactor;
|
|
170
|
+
harmonics.l11[1] *= scaleFactor;
|
|
171
|
+
harmonics.l11[2] *= scaleFactor;
|
|
172
|
+
harmonics.l2_2[0] *= scaleFactor;
|
|
173
|
+
harmonics.l2_2[1] *= scaleFactor;
|
|
174
|
+
harmonics.l2_2[2] *= scaleFactor;
|
|
175
|
+
harmonics.l2_1[0] *= scaleFactor;
|
|
176
|
+
harmonics.l2_1[1] *= scaleFactor;
|
|
177
|
+
harmonics.l2_1[2] *= scaleFactor;
|
|
178
|
+
harmonics.l20[0] *= scaleFactor;
|
|
179
|
+
harmonics.l20[1] *= scaleFactor;
|
|
180
|
+
harmonics.l20[2] *= scaleFactor;
|
|
181
|
+
harmonics.l21[0] *= scaleFactor;
|
|
182
|
+
harmonics.l21[1] *= scaleFactor;
|
|
183
|
+
harmonics.l21[2] *= scaleFactor;
|
|
184
|
+
harmonics.l22[0] *= scaleFactor;
|
|
185
|
+
harmonics.l22[1] *= scaleFactor;
|
|
186
|
+
harmonics.l22[2] *= scaleFactor;
|
|
187
|
+
};
|
|
188
|
+
return EnvironmentDeserializer;
|
|
189
|
+
}());
|
|
190
|
+
export { EnvironmentDeserializer };
|
|
191
191
|
//# sourceMappingURL=environmentSerializer.js.map
|