@babylonjs/loaders 5.0.0-rc.5 → 5.0.0-rc.9
Sign up to get free protection for your applications and to get access to all the features.
- package/OBJ/index.d.ts +4 -4
- package/OBJ/index.js +4 -4
- package/OBJ/mtlFileLoader.d.ts +41 -41
- package/OBJ/mtlFileLoader.js +232 -232
- package/OBJ/objFileLoader.d.ts +126 -126
- package/OBJ/objFileLoader.js +296 -296
- package/OBJ/objLoadingOptions.d.ts +43 -43
- package/OBJ/objLoadingOptions.js +1 -1
- package/OBJ/solidParser.d.ts +154 -154
- package/OBJ/solidParser.js +693 -693
- package/STL/index.d.ts +1 -1
- package/STL/index.js +1 -1
- package/STL/stlFileLoader.d.ts +64 -64
- package/STL/stlFileLoader.js +233 -233
- package/glTF/1.0/glTFBinaryExtension.d.ts +13 -13
- package/glTF/1.0/glTFBinaryExtension.js +60 -60
- package/glTF/1.0/glTFLoader.d.ts +136 -136
- package/glTF/1.0/glTFLoader.js +1815 -1815
- package/glTF/1.0/glTFLoaderInterfaces.d.ts +412 -412
- package/glTF/1.0/glTFLoaderInterfaces.js +95 -95
- package/glTF/1.0/glTFLoaderUtils.d.ts +62 -62
- package/glTF/1.0/glTFLoaderUtils.js +250 -250
- package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +10 -10
- package/glTF/1.0/glTFMaterialsCommonExtension.js +129 -129
- package/glTF/1.0/index.d.ts +5 -5
- package/glTF/1.0/index.js +5 -5
- package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +43 -43
- package/glTF/2.0/Extensions/EXT_lights_image_based.js +117 -117
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +36 -36
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +88 -88
- package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +34 -34
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js +49 -49
- package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +29 -29
- package/glTF/2.0/Extensions/EXT_texture_webp.js +40 -40
- package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +50 -50
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js +73 -73
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +39 -39
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +112 -112
- package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +36 -36
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +89 -89
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +39 -39
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +94 -94
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +38 -38
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +53 -53
- package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +42 -42
- package/glTF/2.0/Extensions/KHR_materials_ior.js +62 -62
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +38 -38
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +80 -80
- package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +39 -39
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +84 -84
- package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +38 -38
- package/glTF/2.0/Extensions/KHR_materials_specular.js +74 -74
- package/glTF/2.0/Extensions/KHR_materials_translucency.d.ts +39 -39
- package/glTF/2.0/Extensions/KHR_materials_translucency.js +83 -83
- package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +38 -38
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +288 -288
- package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +38 -38
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +73 -73
- package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +87 -87
- package/glTF/2.0/Extensions/KHR_materials_variants.js +254 -254
- package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +39 -39
- package/glTF/2.0/Extensions/KHR_materials_volume.js +85 -85
- package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +22 -22
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js +23 -23
- package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +29 -29
- package/glTF/2.0/Extensions/KHR_texture_basisu.js +40 -40
- package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +33 -33
- package/glTF/2.0/Extensions/KHR_texture_transform.js +61 -61
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +32 -32
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +49 -49
- package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +54 -54
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js +240 -240
- package/glTF/2.0/Extensions/MSFT_lod.d.ts +109 -109
- package/glTF/2.0/Extensions/MSFT_lod.js +369 -369
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +14 -14
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +36 -36
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +14 -14
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +36 -36
- package/glTF/2.0/Extensions/index.d.ts +26 -26
- package/glTF/2.0/Extensions/index.js +26 -26
- package/glTF/2.0/glTFLoader.d.ts +405 -405
- package/glTF/2.0/glTFLoader.js +2366 -2366
- package/glTF/2.0/glTFLoaderExtension.d.ts +152 -152
- package/glTF/2.0/glTFLoaderExtension.js +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.d.ts +211 -211
- package/glTF/2.0/glTFLoaderInterfaces.js +1 -1
- package/glTF/2.0/index.d.ts +4 -4
- package/glTF/2.0/index.js +4 -4
- package/glTF/glTFFileLoader.d.ts +433 -433
- package/glTF/glTFFileLoader.js +927 -927
- package/glTF/glTFValidation.d.ts +29 -29
- package/glTF/glTFValidation.js +123 -123
- package/glTF/index.d.ts +5 -5
- package/glTF/index.js +5 -5
- package/index.d.ts +3 -3
- package/index.js +3 -3
- package/legacy/legacy-glTF.d.ts +2 -2
- package/legacy/legacy-glTF.js +18 -18
- package/legacy/legacy-glTF1.d.ts +2 -2
- package/legacy/legacy-glTF1.js +14 -14
- package/legacy/legacy-glTF1FileLoader.d.ts +2 -2
- package/legacy/legacy-glTF1FileLoader.js +3 -3
- package/legacy/legacy-glTF2.d.ts +2 -2
- package/legacy/legacy-glTF2.js +32 -32
- package/legacy/legacy-glTF2FileLoader.d.ts +2 -2
- package/legacy/legacy-glTF2FileLoader.js +3 -3
- package/legacy/legacy-glTFFileLoader.d.ts +3 -3
- package/legacy/legacy-glTFFileLoader.js +4 -4
- package/legacy/legacy-objFileLoader.d.ts +1 -1
- package/legacy/legacy-objFileLoader.js +12 -12
- package/legacy/legacy-stlFileLoader.d.ts +1 -1
- package/legacy/legacy-stlFileLoader.js +12 -12
- package/legacy/legacy.d.ts +6 -6
- package/legacy/legacy.js +7 -7
- package/package.json +3 -3
@@ -1,38 +1,38 @@
|
|
1
|
-
import { Nullable } from "@babylonjs/core/types.js";
|
2
|
-
import { Material } from "@babylonjs/core/Materials/material.js";
|
3
|
-
import { IMaterial } from "../glTFLoaderInterfaces";
|
4
|
-
import { IGLTFLoaderExtension } from "../glTFLoaderExtension";
|
5
|
-
import { GLTFLoader } from "../glTFLoader";
|
6
|
-
/**
|
7
|
-
* [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_transmission/README.md)
|
8
|
-
*/
|
9
|
-
export declare class KHR_materials_transmission implements IGLTFLoaderExtension {
|
10
|
-
/**
|
11
|
-
* The name of this extension.
|
12
|
-
*/
|
13
|
-
readonly name = "KHR_materials_transmission";
|
14
|
-
/**
|
15
|
-
* Defines whether this extension is enabled.
|
16
|
-
*/
|
17
|
-
enabled: boolean;
|
18
|
-
/**
|
19
|
-
* Defines a number that determines the order the extensions are applied.
|
20
|
-
*/
|
21
|
-
order: number;
|
22
|
-
private _loader;
|
23
|
-
/**
|
24
|
-
* @param loader
|
25
|
-
* @hidden
|
26
|
-
*/
|
27
|
-
constructor(loader: GLTFLoader);
|
28
|
-
/** @hidden */
|
29
|
-
dispose(): void;
|
30
|
-
/**
|
31
|
-
* @param context
|
32
|
-
* @param material
|
33
|
-
* @param babylonMaterial
|
34
|
-
* @hidden
|
35
|
-
*/
|
36
|
-
loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
|
37
|
-
private _loadTransparentPropertiesAsync;
|
38
|
-
}
|
1
|
+
import { Nullable } from "@babylonjs/core/types.js";
|
2
|
+
import { Material } from "@babylonjs/core/Materials/material.js";
|
3
|
+
import { IMaterial } from "../glTFLoaderInterfaces";
|
4
|
+
import { IGLTFLoaderExtension } from "../glTFLoaderExtension";
|
5
|
+
import { GLTFLoader } from "../glTFLoader";
|
6
|
+
/**
|
7
|
+
* [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_transmission/README.md)
|
8
|
+
*/
|
9
|
+
export declare class KHR_materials_transmission implements IGLTFLoaderExtension {
|
10
|
+
/**
|
11
|
+
* The name of this extension.
|
12
|
+
*/
|
13
|
+
readonly name = "KHR_materials_transmission";
|
14
|
+
/**
|
15
|
+
* Defines whether this extension is enabled.
|
16
|
+
*/
|
17
|
+
enabled: boolean;
|
18
|
+
/**
|
19
|
+
* Defines a number that determines the order the extensions are applied.
|
20
|
+
*/
|
21
|
+
order: number;
|
22
|
+
private _loader;
|
23
|
+
/**
|
24
|
+
* @param loader
|
25
|
+
* @hidden
|
26
|
+
*/
|
27
|
+
constructor(loader: GLTFLoader);
|
28
|
+
/** @hidden */
|
29
|
+
dispose(): void;
|
30
|
+
/**
|
31
|
+
* @param context
|
32
|
+
* @param material
|
33
|
+
* @param babylonMaterial
|
34
|
+
* @hidden
|
35
|
+
*/
|
36
|
+
loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
|
37
|
+
private _loadTransparentPropertiesAsync;
|
38
|
+
}
|
@@ -1,289 +1,289 @@
|
|
1
|
-
import { __assign } from "tslib";
|
2
|
-
import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
|
3
|
-
import { GLTFLoader } from "../glTFLoader
|
4
|
-
import { RenderTargetTexture } from "@babylonjs/core/Materials/Textures/renderTargetTexture.js";
|
5
|
-
import { Observable } from "@babylonjs/core/Misc/observable.js";
|
6
|
-
import { Constants } from "@babylonjs/core/Engines/constants.js";
|
7
|
-
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
8
|
-
/**
|
9
|
-
* A class to handle setting up the rendering of opaque objects to be shown through transmissive objects.
|
10
|
-
*/
|
11
|
-
var TransmissionHelper = /** @class */ (function () {
|
12
|
-
/**
|
13
|
-
* constructor
|
14
|
-
* @param options Defines the options we want to customize the helper
|
15
|
-
* @param scene The scene to add the material to
|
16
|
-
*/
|
17
|
-
function TransmissionHelper(options, scene) {
|
18
|
-
var _this = this;
|
19
|
-
this._opaqueRenderTarget = null;
|
20
|
-
this._opaqueMeshesCache = [];
|
21
|
-
this._transparentMeshesCache = [];
|
22
|
-
this._materialObservers = {};
|
23
|
-
this._options = __assign(__assign({}, TransmissionHelper._GetDefaultOptions()), options);
|
24
|
-
this._scene = scene;
|
25
|
-
this._scene._transmissionHelper = this;
|
26
|
-
this.onErrorObservable = new Observable();
|
27
|
-
this._scene.onDisposeObservable.addOnce(function () {
|
28
|
-
_this.dispose();
|
29
|
-
});
|
30
|
-
this._parseScene();
|
31
|
-
this._setupRenderTargets();
|
32
|
-
}
|
33
|
-
/**
|
34
|
-
* Creates the default options for the helper.
|
35
|
-
*/
|
36
|
-
TransmissionHelper._GetDefaultOptions = function () {
|
37
|
-
return {
|
38
|
-
renderSize: 1024,
|
39
|
-
samples: 4,
|
40
|
-
lodGenerationScale: 1,
|
41
|
-
lodGenerationOffset: -4,
|
42
|
-
renderTargetTextureType: Constants.TEXTURETYPE_HALF_FLOAT,
|
43
|
-
generateMipmaps: true,
|
44
|
-
};
|
45
|
-
};
|
46
|
-
/**
|
47
|
-
* Updates the background according to the new options
|
48
|
-
* @param options
|
49
|
-
*/
|
50
|
-
TransmissionHelper.prototype.updateOptions = function (options) {
|
51
|
-
var _this = this;
|
52
|
-
// First check if any options are actually being changed. If not, exit.
|
53
|
-
var newValues = Object.keys(options).filter(function (key) { return _this._options[key] !== options[key]; });
|
54
|
-
if (!newValues.length) {
|
55
|
-
return;
|
56
|
-
}
|
57
|
-
var newOptions = __assign(__assign({}, this._options), options);
|
58
|
-
var oldOptions = this._options;
|
59
|
-
this._options = newOptions;
|
60
|
-
// If size changes, recreate everything
|
61
|
-
if (newOptions.renderSize !== oldOptions.renderSize ||
|
62
|
-
newOptions.renderTargetTextureType !== oldOptions.renderTargetTextureType ||
|
63
|
-
newOptions.generateMipmaps !== oldOptions.generateMipmaps ||
|
64
|
-
!this._opaqueRenderTarget) {
|
65
|
-
this._setupRenderTargets();
|
66
|
-
}
|
67
|
-
else {
|
68
|
-
this._opaqueRenderTarget.samples = newOptions.samples;
|
69
|
-
this._opaqueRenderTarget.lodGenerationScale = newOptions.lodGenerationScale;
|
70
|
-
this._opaqueRenderTarget.lodGenerationOffset = newOptions.lodGenerationOffset;
|
71
|
-
}
|
72
|
-
};
|
73
|
-
TransmissionHelper.prototype.getOpaqueTarget = function () {
|
74
|
-
return this._opaqueRenderTarget;
|
75
|
-
};
|
76
|
-
TransmissionHelper.prototype._shouldRenderAsTransmission = function (material) {
|
77
|
-
if (!material) {
|
78
|
-
return false;
|
79
|
-
}
|
80
|
-
if (material instanceof PBRMaterial && material.subSurface.isRefractionEnabled) {
|
81
|
-
return true;
|
82
|
-
}
|
83
|
-
return false;
|
84
|
-
};
|
85
|
-
TransmissionHelper.prototype._addMesh = function (mesh) {
|
86
|
-
var _this = this;
|
87
|
-
this._materialObservers[mesh.uniqueId] = mesh.onMaterialChangedObservable.add(this._onMeshMaterialChanged.bind(this));
|
88
|
-
// we need to defer the processing because _addMesh may be called as part as an instance mesh creation, in which case some
|
89
|
-
// internal properties are not setup yet, like _sourceMesh (needed when doing mesh.material below)
|
90
|
-
Tools.SetImmediate(function () {
|
91
|
-
if (_this._shouldRenderAsTransmission(mesh.material)) {
|
92
|
-
mesh.material.refractionTexture = _this._opaqueRenderTarget;
|
93
|
-
_this._transparentMeshesCache.push(mesh);
|
94
|
-
}
|
95
|
-
else {
|
96
|
-
_this._opaqueMeshesCache.push(mesh);
|
97
|
-
}
|
98
|
-
});
|
99
|
-
};
|
100
|
-
TransmissionHelper.prototype._removeMesh = function (mesh) {
|
101
|
-
mesh.onMaterialChangedObservable.remove(this._materialObservers[mesh.uniqueId]);
|
102
|
-
delete this._materialObservers[mesh.uniqueId];
|
103
|
-
var idx = this._transparentMeshesCache.indexOf(mesh);
|
104
|
-
if (idx !== -1) {
|
105
|
-
this._transparentMeshesCache.splice(idx, 1);
|
106
|
-
}
|
107
|
-
idx = this._opaqueMeshesCache.indexOf(mesh);
|
108
|
-
if (idx !== -1) {
|
109
|
-
this._opaqueMeshesCache.splice(idx, 1);
|
110
|
-
}
|
111
|
-
};
|
112
|
-
TransmissionHelper.prototype._parseScene = function () {
|
113
|
-
this._scene.meshes.forEach(this._addMesh.bind(this));
|
114
|
-
// Listen for when a mesh is added to the scene and add it to our cache lists.
|
115
|
-
this._scene.onNewMeshAddedObservable.add(this._addMesh.bind(this));
|
116
|
-
// Listen for when a mesh is removed from to the scene and remove it from our cache lists.
|
117
|
-
this._scene.onMeshRemovedObservable.add(this._removeMesh.bind(this));
|
118
|
-
};
|
119
|
-
// When one of the meshes in the scene has its material changed, make sure that it's in the correct cache list.
|
120
|
-
TransmissionHelper.prototype._onMeshMaterialChanged = function (mesh) {
|
121
|
-
var transparentIdx = this._transparentMeshesCache.indexOf(mesh);
|
122
|
-
var opaqueIdx = this._opaqueMeshesCache.indexOf(mesh);
|
123
|
-
// If the material is transparent, make sure that it's added to the transparent list and removed from the opaque list
|
124
|
-
var useTransmission = this._shouldRenderAsTransmission(mesh.material);
|
125
|
-
if (useTransmission) {
|
126
|
-
if (mesh.material instanceof PBRMaterial) {
|
127
|
-
mesh.material.subSurface.refractionTexture = this._opaqueRenderTarget;
|
128
|
-
}
|
129
|
-
if (opaqueIdx !== -1) {
|
130
|
-
this._opaqueMeshesCache.splice(opaqueIdx, 1);
|
131
|
-
this._transparentMeshesCache.push(mesh);
|
132
|
-
}
|
133
|
-
else if (transparentIdx === -1) {
|
134
|
-
this._transparentMeshesCache.push(mesh);
|
135
|
-
}
|
136
|
-
// If the material is opaque, make sure that it's added to the opaque list and removed from the transparent list
|
137
|
-
}
|
138
|
-
else {
|
139
|
-
if (transparentIdx !== -1) {
|
140
|
-
this._transparentMeshesCache.splice(transparentIdx, 1);
|
141
|
-
this._opaqueMeshesCache.push(mesh);
|
142
|
-
}
|
143
|
-
else if (opaqueIdx === -1) {
|
144
|
-
this._opaqueMeshesCache.push(mesh);
|
145
|
-
}
|
146
|
-
}
|
147
|
-
};
|
148
|
-
/**
|
149
|
-
* Setup the render targets according to the specified options.
|
150
|
-
*/
|
151
|
-
TransmissionHelper.prototype._setupRenderTargets = function () {
|
152
|
-
var _this = this;
|
153
|
-
var _a, _b;
|
154
|
-
if (this._opaqueRenderTarget) {
|
155
|
-
this._opaqueRenderTarget.dispose();
|
156
|
-
}
|
157
|
-
this._opaqueRenderTarget = new RenderTargetTexture("opaqueSceneTexture", this._options.renderSize, this._scene, this._options.generateMipmaps, undefined, this._options.renderTargetTextureType);
|
158
|
-
this._opaqueRenderTarget.ignoreCameraViewport = true;
|
159
|
-
this._opaqueRenderTarget.renderList = this._opaqueMeshesCache;
|
160
|
-
this._opaqueRenderTarget.clearColor = (_b = (_a = this._options.clearColor) === null || _a === void 0 ? void 0 : _a.clone()) !== null && _b !== void 0 ? _b : this._scene.clearColor.clone();
|
161
|
-
this._opaqueRenderTarget.gammaSpace = false;
|
162
|
-
this._opaqueRenderTarget.lodGenerationScale = this._options.lodGenerationScale;
|
163
|
-
this._opaqueRenderTarget.lodGenerationOffset = this._options.lodGenerationOffset;
|
164
|
-
this._opaqueRenderTarget.samples = this._options.samples;
|
165
|
-
var sceneImageProcessingapplyByPostProcess;
|
166
|
-
var saveSceneEnvIntensity;
|
167
|
-
this._opaqueRenderTarget.onBeforeBindObservable.add(function (opaqueRenderTarget) {
|
168
|
-
saveSceneEnvIntensity = _this._scene.environmentIntensity;
|
169
|
-
_this._scene.environmentIntensity = 1.0;
|
170
|
-
sceneImageProcessingapplyByPostProcess = _this._scene.imageProcessingConfiguration.applyByPostProcess;
|
171
|
-
if (!_this._options.clearColor) {
|
172
|
-
_this._scene.clearColor.toLinearSpaceToRef(opaqueRenderTarget.clearColor);
|
173
|
-
}
|
174
|
-
else {
|
175
|
-
opaqueRenderTarget.clearColor.copyFrom(_this._options.clearColor);
|
176
|
-
}
|
177
|
-
// we do not use the applyByPostProcess setter to avoid flagging all the materials as "image processing dirty"!
|
178
|
-
_this._scene.imageProcessingConfiguration._applyByPostProcess = true;
|
179
|
-
});
|
180
|
-
this._opaqueRenderTarget.onAfterUnbindObservable.add(function () {
|
181
|
-
_this._scene.environmentIntensity = saveSceneEnvIntensity;
|
182
|
-
_this._scene.imageProcessingConfiguration._applyByPostProcess = sceneImageProcessingapplyByPostProcess;
|
183
|
-
});
|
184
|
-
this._transparentMeshesCache.forEach(function (mesh) {
|
185
|
-
if (_this._shouldRenderAsTransmission(mesh.material)) {
|
186
|
-
mesh.material.refractionTexture = _this._opaqueRenderTarget;
|
187
|
-
}
|
188
|
-
});
|
189
|
-
};
|
190
|
-
/**
|
191
|
-
* Dispose all the elements created by the Helper.
|
192
|
-
*/
|
193
|
-
TransmissionHelper.prototype.dispose = function () {
|
194
|
-
this._scene._transmissionHelper = undefined;
|
195
|
-
if (this._opaqueRenderTarget) {
|
196
|
-
this._opaqueRenderTarget.dispose();
|
197
|
-
this._opaqueRenderTarget = null;
|
198
|
-
}
|
199
|
-
this._transparentMeshesCache = [];
|
200
|
-
this._opaqueMeshesCache = [];
|
201
|
-
};
|
202
|
-
return TransmissionHelper;
|
203
|
-
}());
|
204
|
-
var NAME = "KHR_materials_transmission";
|
205
|
-
/**
|
206
|
-
* [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_transmission/README.md)
|
207
|
-
*/
|
208
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
209
|
-
var KHR_materials_transmission = /** @class */ (function () {
|
210
|
-
/**
|
211
|
-
* @param loader
|
212
|
-
* @hidden
|
213
|
-
*/
|
214
|
-
function KHR_materials_transmission(loader) {
|
215
|
-
/**
|
216
|
-
* The name of this extension.
|
217
|
-
*/
|
218
|
-
this.name = NAME;
|
219
|
-
/**
|
220
|
-
* Defines a number that determines the order the extensions are applied.
|
221
|
-
*/
|
222
|
-
this.order = 175;
|
223
|
-
this._loader = loader;
|
224
|
-
this.enabled = this._loader.isExtensionUsed(NAME);
|
225
|
-
if (this.enabled) {
|
226
|
-
loader.parent.transparencyAsCoverage = true;
|
227
|
-
}
|
228
|
-
}
|
229
|
-
/** @hidden */
|
230
|
-
KHR_materials_transmission.prototype.dispose = function () {
|
231
|
-
this._loader = null;
|
232
|
-
};
|
233
|
-
/**
|
234
|
-
* @param context
|
235
|
-
* @param material
|
236
|
-
* @param babylonMaterial
|
237
|
-
* @hidden
|
238
|
-
*/
|
239
|
-
KHR_materials_transmission.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
|
240
|
-
var _this = this;
|
241
|
-
return GLTFLoader.LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
|
242
|
-
var promises = new Array();
|
243
|
-
promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
|
244
|
-
promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
|
245
|
-
promises.push(_this._loadTransparentPropertiesAsync(extensionContext, material, babylonMaterial, extension));
|
246
|
-
return Promise.all(promises).then(function () { });
|
247
|
-
});
|
248
|
-
};
|
249
|
-
KHR_materials_transmission.prototype._loadTransparentPropertiesAsync = function (context, material, babylonMaterial, extension) {
|
250
|
-
if (!(babylonMaterial instanceof PBRMaterial)) {
|
251
|
-
throw new Error("".concat(context, ": Material type not supported"));
|
252
|
-
}
|
253
|
-
var pbrMaterial = babylonMaterial;
|
254
|
-
// Enables "refraction" texture which represents transmitted light.
|
255
|
-
pbrMaterial.subSurface.isRefractionEnabled = true;
|
256
|
-
// Since this extension models thin-surface transmission only, we must make IOR = 1.0
|
257
|
-
pbrMaterial.subSurface.volumeIndexOfRefraction = 1.0;
|
258
|
-
// Albedo colour will tint transmission.
|
259
|
-
pbrMaterial.subSurface.useAlbedoToTintRefraction = true;
|
260
|
-
if (extension.transmissionFactor !== undefined) {
|
261
|
-
pbrMaterial.subSurface.refractionIntensity = extension.transmissionFactor;
|
262
|
-
var scene = pbrMaterial.getScene();
|
263
|
-
if (pbrMaterial.subSurface.refractionIntensity && !scene._transmissionHelper) {
|
264
|
-
new TransmissionHelper({}, pbrMaterial.getScene());
|
265
|
-
}
|
266
|
-
}
|
267
|
-
else {
|
268
|
-
pbrMaterial.subSurface.refractionIntensity = 0.0;
|
269
|
-
pbrMaterial.subSurface.isRefractionEnabled = false;
|
270
|
-
return Promise.resolve();
|
271
|
-
}
|
272
|
-
pbrMaterial.subSurface.minimumThickness = 0.0;
|
273
|
-
pbrMaterial.subSurface.maximumThickness = 0.0;
|
274
|
-
if (extension.transmissionTexture) {
|
275
|
-
extension.transmissionTexture.nonColorData = true;
|
276
|
-
return this._loader.loadTextureInfoAsync("".concat(context, "/transmissionTexture"), extension.transmissionTexture, undefined).then(function (texture) {
|
277
|
-
pbrMaterial.subSurface.refractionIntensityTexture = texture;
|
278
|
-
pbrMaterial.subSurface.useGltfStyleTextures = true;
|
279
|
-
});
|
280
|
-
}
|
281
|
-
else {
|
282
|
-
return Promise.resolve();
|
283
|
-
}
|
284
|
-
};
|
285
|
-
return KHR_materials_transmission;
|
286
|
-
}());
|
287
|
-
export { KHR_materials_transmission };
|
288
|
-
GLTFLoader.RegisterExtension(NAME, function (loader) { return new KHR_materials_transmission(loader); });
|
1
|
+
import { __assign } from "tslib";
|
2
|
+
import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
|
3
|
+
import { GLTFLoader } from "../glTFLoader";
|
4
|
+
import { RenderTargetTexture } from "@babylonjs/core/Materials/Textures/renderTargetTexture.js";
|
5
|
+
import { Observable } from "@babylonjs/core/Misc/observable.js";
|
6
|
+
import { Constants } from "@babylonjs/core/Engines/constants.js";
|
7
|
+
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
8
|
+
/**
|
9
|
+
* A class to handle setting up the rendering of opaque objects to be shown through transmissive objects.
|
10
|
+
*/
|
11
|
+
var TransmissionHelper = /** @class */ (function () {
|
12
|
+
/**
|
13
|
+
* constructor
|
14
|
+
* @param options Defines the options we want to customize the helper
|
15
|
+
* @param scene The scene to add the material to
|
16
|
+
*/
|
17
|
+
function TransmissionHelper(options, scene) {
|
18
|
+
var _this = this;
|
19
|
+
this._opaqueRenderTarget = null;
|
20
|
+
this._opaqueMeshesCache = [];
|
21
|
+
this._transparentMeshesCache = [];
|
22
|
+
this._materialObservers = {};
|
23
|
+
this._options = __assign(__assign({}, TransmissionHelper._GetDefaultOptions()), options);
|
24
|
+
this._scene = scene;
|
25
|
+
this._scene._transmissionHelper = this;
|
26
|
+
this.onErrorObservable = new Observable();
|
27
|
+
this._scene.onDisposeObservable.addOnce(function () {
|
28
|
+
_this.dispose();
|
29
|
+
});
|
30
|
+
this._parseScene();
|
31
|
+
this._setupRenderTargets();
|
32
|
+
}
|
33
|
+
/**
|
34
|
+
* Creates the default options for the helper.
|
35
|
+
*/
|
36
|
+
TransmissionHelper._GetDefaultOptions = function () {
|
37
|
+
return {
|
38
|
+
renderSize: 1024,
|
39
|
+
samples: 4,
|
40
|
+
lodGenerationScale: 1,
|
41
|
+
lodGenerationOffset: -4,
|
42
|
+
renderTargetTextureType: Constants.TEXTURETYPE_HALF_FLOAT,
|
43
|
+
generateMipmaps: true,
|
44
|
+
};
|
45
|
+
};
|
46
|
+
/**
|
47
|
+
* Updates the background according to the new options
|
48
|
+
* @param options
|
49
|
+
*/
|
50
|
+
TransmissionHelper.prototype.updateOptions = function (options) {
|
51
|
+
var _this = this;
|
52
|
+
// First check if any options are actually being changed. If not, exit.
|
53
|
+
var newValues = Object.keys(options).filter(function (key) { return _this._options[key] !== options[key]; });
|
54
|
+
if (!newValues.length) {
|
55
|
+
return;
|
56
|
+
}
|
57
|
+
var newOptions = __assign(__assign({}, this._options), options);
|
58
|
+
var oldOptions = this._options;
|
59
|
+
this._options = newOptions;
|
60
|
+
// If size changes, recreate everything
|
61
|
+
if (newOptions.renderSize !== oldOptions.renderSize ||
|
62
|
+
newOptions.renderTargetTextureType !== oldOptions.renderTargetTextureType ||
|
63
|
+
newOptions.generateMipmaps !== oldOptions.generateMipmaps ||
|
64
|
+
!this._opaqueRenderTarget) {
|
65
|
+
this._setupRenderTargets();
|
66
|
+
}
|
67
|
+
else {
|
68
|
+
this._opaqueRenderTarget.samples = newOptions.samples;
|
69
|
+
this._opaqueRenderTarget.lodGenerationScale = newOptions.lodGenerationScale;
|
70
|
+
this._opaqueRenderTarget.lodGenerationOffset = newOptions.lodGenerationOffset;
|
71
|
+
}
|
72
|
+
};
|
73
|
+
TransmissionHelper.prototype.getOpaqueTarget = function () {
|
74
|
+
return this._opaqueRenderTarget;
|
75
|
+
};
|
76
|
+
TransmissionHelper.prototype._shouldRenderAsTransmission = function (material) {
|
77
|
+
if (!material) {
|
78
|
+
return false;
|
79
|
+
}
|
80
|
+
if (material instanceof PBRMaterial && material.subSurface.isRefractionEnabled) {
|
81
|
+
return true;
|
82
|
+
}
|
83
|
+
return false;
|
84
|
+
};
|
85
|
+
TransmissionHelper.prototype._addMesh = function (mesh) {
|
86
|
+
var _this = this;
|
87
|
+
this._materialObservers[mesh.uniqueId] = mesh.onMaterialChangedObservable.add(this._onMeshMaterialChanged.bind(this));
|
88
|
+
// we need to defer the processing because _addMesh may be called as part as an instance mesh creation, in which case some
|
89
|
+
// internal properties are not setup yet, like _sourceMesh (needed when doing mesh.material below)
|
90
|
+
Tools.SetImmediate(function () {
|
91
|
+
if (_this._shouldRenderAsTransmission(mesh.material)) {
|
92
|
+
mesh.material.refractionTexture = _this._opaqueRenderTarget;
|
93
|
+
_this._transparentMeshesCache.push(mesh);
|
94
|
+
}
|
95
|
+
else {
|
96
|
+
_this._opaqueMeshesCache.push(mesh);
|
97
|
+
}
|
98
|
+
});
|
99
|
+
};
|
100
|
+
TransmissionHelper.prototype._removeMesh = function (mesh) {
|
101
|
+
mesh.onMaterialChangedObservable.remove(this._materialObservers[mesh.uniqueId]);
|
102
|
+
delete this._materialObservers[mesh.uniqueId];
|
103
|
+
var idx = this._transparentMeshesCache.indexOf(mesh);
|
104
|
+
if (idx !== -1) {
|
105
|
+
this._transparentMeshesCache.splice(idx, 1);
|
106
|
+
}
|
107
|
+
idx = this._opaqueMeshesCache.indexOf(mesh);
|
108
|
+
if (idx !== -1) {
|
109
|
+
this._opaqueMeshesCache.splice(idx, 1);
|
110
|
+
}
|
111
|
+
};
|
112
|
+
TransmissionHelper.prototype._parseScene = function () {
|
113
|
+
this._scene.meshes.forEach(this._addMesh.bind(this));
|
114
|
+
// Listen for when a mesh is added to the scene and add it to our cache lists.
|
115
|
+
this._scene.onNewMeshAddedObservable.add(this._addMesh.bind(this));
|
116
|
+
// Listen for when a mesh is removed from to the scene and remove it from our cache lists.
|
117
|
+
this._scene.onMeshRemovedObservable.add(this._removeMesh.bind(this));
|
118
|
+
};
|
119
|
+
// When one of the meshes in the scene has its material changed, make sure that it's in the correct cache list.
|
120
|
+
TransmissionHelper.prototype._onMeshMaterialChanged = function (mesh) {
|
121
|
+
var transparentIdx = this._transparentMeshesCache.indexOf(mesh);
|
122
|
+
var opaqueIdx = this._opaqueMeshesCache.indexOf(mesh);
|
123
|
+
// If the material is transparent, make sure that it's added to the transparent list and removed from the opaque list
|
124
|
+
var useTransmission = this._shouldRenderAsTransmission(mesh.material);
|
125
|
+
if (useTransmission) {
|
126
|
+
if (mesh.material instanceof PBRMaterial) {
|
127
|
+
mesh.material.subSurface.refractionTexture = this._opaqueRenderTarget;
|
128
|
+
}
|
129
|
+
if (opaqueIdx !== -1) {
|
130
|
+
this._opaqueMeshesCache.splice(opaqueIdx, 1);
|
131
|
+
this._transparentMeshesCache.push(mesh);
|
132
|
+
}
|
133
|
+
else if (transparentIdx === -1) {
|
134
|
+
this._transparentMeshesCache.push(mesh);
|
135
|
+
}
|
136
|
+
// If the material is opaque, make sure that it's added to the opaque list and removed from the transparent list
|
137
|
+
}
|
138
|
+
else {
|
139
|
+
if (transparentIdx !== -1) {
|
140
|
+
this._transparentMeshesCache.splice(transparentIdx, 1);
|
141
|
+
this._opaqueMeshesCache.push(mesh);
|
142
|
+
}
|
143
|
+
else if (opaqueIdx === -1) {
|
144
|
+
this._opaqueMeshesCache.push(mesh);
|
145
|
+
}
|
146
|
+
}
|
147
|
+
};
|
148
|
+
/**
|
149
|
+
* Setup the render targets according to the specified options.
|
150
|
+
*/
|
151
|
+
TransmissionHelper.prototype._setupRenderTargets = function () {
|
152
|
+
var _this = this;
|
153
|
+
var _a, _b;
|
154
|
+
if (this._opaqueRenderTarget) {
|
155
|
+
this._opaqueRenderTarget.dispose();
|
156
|
+
}
|
157
|
+
this._opaqueRenderTarget = new RenderTargetTexture("opaqueSceneTexture", this._options.renderSize, this._scene, this._options.generateMipmaps, undefined, this._options.renderTargetTextureType);
|
158
|
+
this._opaqueRenderTarget.ignoreCameraViewport = true;
|
159
|
+
this._opaqueRenderTarget.renderList = this._opaqueMeshesCache;
|
160
|
+
this._opaqueRenderTarget.clearColor = (_b = (_a = this._options.clearColor) === null || _a === void 0 ? void 0 : _a.clone()) !== null && _b !== void 0 ? _b : this._scene.clearColor.clone();
|
161
|
+
this._opaqueRenderTarget.gammaSpace = false;
|
162
|
+
this._opaqueRenderTarget.lodGenerationScale = this._options.lodGenerationScale;
|
163
|
+
this._opaqueRenderTarget.lodGenerationOffset = this._options.lodGenerationOffset;
|
164
|
+
this._opaqueRenderTarget.samples = this._options.samples;
|
165
|
+
var sceneImageProcessingapplyByPostProcess;
|
166
|
+
var saveSceneEnvIntensity;
|
167
|
+
this._opaqueRenderTarget.onBeforeBindObservable.add(function (opaqueRenderTarget) {
|
168
|
+
saveSceneEnvIntensity = _this._scene.environmentIntensity;
|
169
|
+
_this._scene.environmentIntensity = 1.0;
|
170
|
+
sceneImageProcessingapplyByPostProcess = _this._scene.imageProcessingConfiguration.applyByPostProcess;
|
171
|
+
if (!_this._options.clearColor) {
|
172
|
+
_this._scene.clearColor.toLinearSpaceToRef(opaqueRenderTarget.clearColor);
|
173
|
+
}
|
174
|
+
else {
|
175
|
+
opaqueRenderTarget.clearColor.copyFrom(_this._options.clearColor);
|
176
|
+
}
|
177
|
+
// we do not use the applyByPostProcess setter to avoid flagging all the materials as "image processing dirty"!
|
178
|
+
_this._scene.imageProcessingConfiguration._applyByPostProcess = true;
|
179
|
+
});
|
180
|
+
this._opaqueRenderTarget.onAfterUnbindObservable.add(function () {
|
181
|
+
_this._scene.environmentIntensity = saveSceneEnvIntensity;
|
182
|
+
_this._scene.imageProcessingConfiguration._applyByPostProcess = sceneImageProcessingapplyByPostProcess;
|
183
|
+
});
|
184
|
+
this._transparentMeshesCache.forEach(function (mesh) {
|
185
|
+
if (_this._shouldRenderAsTransmission(mesh.material)) {
|
186
|
+
mesh.material.refractionTexture = _this._opaqueRenderTarget;
|
187
|
+
}
|
188
|
+
});
|
189
|
+
};
|
190
|
+
/**
|
191
|
+
* Dispose all the elements created by the Helper.
|
192
|
+
*/
|
193
|
+
TransmissionHelper.prototype.dispose = function () {
|
194
|
+
this._scene._transmissionHelper = undefined;
|
195
|
+
if (this._opaqueRenderTarget) {
|
196
|
+
this._opaqueRenderTarget.dispose();
|
197
|
+
this._opaqueRenderTarget = null;
|
198
|
+
}
|
199
|
+
this._transparentMeshesCache = [];
|
200
|
+
this._opaqueMeshesCache = [];
|
201
|
+
};
|
202
|
+
return TransmissionHelper;
|
203
|
+
}());
|
204
|
+
var NAME = "KHR_materials_transmission";
|
205
|
+
/**
|
206
|
+
* [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_transmission/README.md)
|
207
|
+
*/
|
208
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
209
|
+
var KHR_materials_transmission = /** @class */ (function () {
|
210
|
+
/**
|
211
|
+
* @param loader
|
212
|
+
* @hidden
|
213
|
+
*/
|
214
|
+
function KHR_materials_transmission(loader) {
|
215
|
+
/**
|
216
|
+
* The name of this extension.
|
217
|
+
*/
|
218
|
+
this.name = NAME;
|
219
|
+
/**
|
220
|
+
* Defines a number that determines the order the extensions are applied.
|
221
|
+
*/
|
222
|
+
this.order = 175;
|
223
|
+
this._loader = loader;
|
224
|
+
this.enabled = this._loader.isExtensionUsed(NAME);
|
225
|
+
if (this.enabled) {
|
226
|
+
loader.parent.transparencyAsCoverage = true;
|
227
|
+
}
|
228
|
+
}
|
229
|
+
/** @hidden */
|
230
|
+
KHR_materials_transmission.prototype.dispose = function () {
|
231
|
+
this._loader = null;
|
232
|
+
};
|
233
|
+
/**
|
234
|
+
* @param context
|
235
|
+
* @param material
|
236
|
+
* @param babylonMaterial
|
237
|
+
* @hidden
|
238
|
+
*/
|
239
|
+
KHR_materials_transmission.prototype.loadMaterialPropertiesAsync = function (context, material, babylonMaterial) {
|
240
|
+
var _this = this;
|
241
|
+
return GLTFLoader.LoadExtensionAsync(context, material, this.name, function (extensionContext, extension) {
|
242
|
+
var promises = new Array();
|
243
|
+
promises.push(_this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));
|
244
|
+
promises.push(_this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
|
245
|
+
promises.push(_this._loadTransparentPropertiesAsync(extensionContext, material, babylonMaterial, extension));
|
246
|
+
return Promise.all(promises).then(function () { });
|
247
|
+
});
|
248
|
+
};
|
249
|
+
KHR_materials_transmission.prototype._loadTransparentPropertiesAsync = function (context, material, babylonMaterial, extension) {
|
250
|
+
if (!(babylonMaterial instanceof PBRMaterial)) {
|
251
|
+
throw new Error("".concat(context, ": Material type not supported"));
|
252
|
+
}
|
253
|
+
var pbrMaterial = babylonMaterial;
|
254
|
+
// Enables "refraction" texture which represents transmitted light.
|
255
|
+
pbrMaterial.subSurface.isRefractionEnabled = true;
|
256
|
+
// Since this extension models thin-surface transmission only, we must make IOR = 1.0
|
257
|
+
pbrMaterial.subSurface.volumeIndexOfRefraction = 1.0;
|
258
|
+
// Albedo colour will tint transmission.
|
259
|
+
pbrMaterial.subSurface.useAlbedoToTintRefraction = true;
|
260
|
+
if (extension.transmissionFactor !== undefined) {
|
261
|
+
pbrMaterial.subSurface.refractionIntensity = extension.transmissionFactor;
|
262
|
+
var scene = pbrMaterial.getScene();
|
263
|
+
if (pbrMaterial.subSurface.refractionIntensity && !scene._transmissionHelper) {
|
264
|
+
new TransmissionHelper({}, pbrMaterial.getScene());
|
265
|
+
}
|
266
|
+
}
|
267
|
+
else {
|
268
|
+
pbrMaterial.subSurface.refractionIntensity = 0.0;
|
269
|
+
pbrMaterial.subSurface.isRefractionEnabled = false;
|
270
|
+
return Promise.resolve();
|
271
|
+
}
|
272
|
+
pbrMaterial.subSurface.minimumThickness = 0.0;
|
273
|
+
pbrMaterial.subSurface.maximumThickness = 0.0;
|
274
|
+
if (extension.transmissionTexture) {
|
275
|
+
extension.transmissionTexture.nonColorData = true;
|
276
|
+
return this._loader.loadTextureInfoAsync("".concat(context, "/transmissionTexture"), extension.transmissionTexture, undefined).then(function (texture) {
|
277
|
+
pbrMaterial.subSurface.refractionIntensityTexture = texture;
|
278
|
+
pbrMaterial.subSurface.useGltfStyleTextures = true;
|
279
|
+
});
|
280
|
+
}
|
281
|
+
else {
|
282
|
+
return Promise.resolve();
|
283
|
+
}
|
284
|
+
};
|
285
|
+
return KHR_materials_transmission;
|
286
|
+
}());
|
287
|
+
export { KHR_materials_transmission };
|
288
|
+
GLTFLoader.RegisterExtension(NAME, function (loader) { return new KHR_materials_transmission(loader); });
|
289
289
|
//# sourceMappingURL=KHR_materials_transmission.js.map
|