@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,255 +1,255 @@
|
|
1
|
-
import { GLTFLoader, ArrayItem } from "../glTFLoader
|
2
|
-
import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
|
3
|
-
var NAME = "KHR_materials_variants";
|
4
|
-
/**
|
5
|
-
* [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_variants/README.md)
|
6
|
-
*/
|
7
|
-
var KHR_materials_variants = /** @class */ (function () {
|
8
|
-
/**
|
9
|
-
* @param loader
|
10
|
-
* @hidden
|
11
|
-
*/
|
12
|
-
function KHR_materials_variants(loader) {
|
13
|
-
/**
|
14
|
-
* The name of this extension.
|
15
|
-
*/
|
16
|
-
this.name = NAME;
|
17
|
-
this._loader = loader;
|
18
|
-
this.enabled = this._loader.isExtensionUsed(NAME);
|
19
|
-
}
|
20
|
-
/** @hidden */
|
21
|
-
KHR_materials_variants.prototype.dispose = function () {
|
22
|
-
this._loader = null;
|
23
|
-
};
|
24
|
-
/**
|
25
|
-
* Gets the list of available variant names for this asset.
|
26
|
-
* @param rootMesh The glTF root mesh
|
27
|
-
* @returns the list of all the variant names for this model
|
28
|
-
*/
|
29
|
-
KHR_materials_variants.GetAvailableVariants = function (rootMesh) {
|
30
|
-
var extensionMetadata = this._GetExtensionMetadata(rootMesh);
|
31
|
-
if (!extensionMetadata) {
|
32
|
-
return [];
|
33
|
-
}
|
34
|
-
return Object.keys(extensionMetadata.variants);
|
35
|
-
};
|
36
|
-
/**
|
37
|
-
* Gets the list of available variant names for this asset.
|
38
|
-
* @param rootMesh The glTF root mesh
|
39
|
-
* @returns the list of all the variant names for this model
|
40
|
-
*/
|
41
|
-
KHR_materials_variants.prototype.getAvailableVariants = function (rootMesh) {
|
42
|
-
return KHR_materials_variants.GetAvailableVariants(rootMesh);
|
43
|
-
};
|
44
|
-
/**
|
45
|
-
* Select a variant given a variant name or a list of variant names.
|
46
|
-
* @param rootMesh The glTF root mesh
|
47
|
-
* @param variantName The variant name(s) to select.
|
48
|
-
*/
|
49
|
-
KHR_materials_variants.SelectVariant = function (rootMesh, variantName) {
|
50
|
-
var extensionMetadata = this._GetExtensionMetadata(rootMesh);
|
51
|
-
if (!extensionMetadata) {
|
52
|
-
throw new Error("Cannot select variant on a glTF mesh that does not have the ".concat(NAME, " extension"));
|
53
|
-
}
|
54
|
-
var select = function (variantName) {
|
55
|
-
var entries = extensionMetadata.variants[variantName];
|
56
|
-
if (entries) {
|
57
|
-
for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
|
58
|
-
var entry = entries_1[_i];
|
59
|
-
entry.mesh.material = entry.material;
|
60
|
-
}
|
61
|
-
}
|
62
|
-
};
|
63
|
-
if (variantName instanceof Array) {
|
64
|
-
for (var _i = 0, variantName_1 = variantName; _i < variantName_1.length; _i++) {
|
65
|
-
var name_1 = variantName_1[_i];
|
66
|
-
select(name_1);
|
67
|
-
}
|
68
|
-
}
|
69
|
-
else {
|
70
|
-
select(variantName);
|
71
|
-
}
|
72
|
-
extensionMetadata.lastSelected = variantName;
|
73
|
-
};
|
74
|
-
/**
|
75
|
-
* Select a variant given a variant name or a list of variant names.
|
76
|
-
* @param rootMesh The glTF root mesh
|
77
|
-
* @param variantName The variant name(s) to select.
|
78
|
-
*/
|
79
|
-
KHR_materials_variants.prototype.selectVariant = function (rootMesh, variantName) {
|
80
|
-
return KHR_materials_variants.SelectVariant(rootMesh, variantName);
|
81
|
-
};
|
82
|
-
/**
|
83
|
-
* Reset back to the original before selecting a variant.
|
84
|
-
* @param rootMesh The glTF root mesh
|
85
|
-
*/
|
86
|
-
KHR_materials_variants.Reset = function (rootMesh) {
|
87
|
-
var extensionMetadata = this._GetExtensionMetadata(rootMesh);
|
88
|
-
if (!extensionMetadata) {
|
89
|
-
throw new Error("Cannot reset on a glTF mesh that does not have the ".concat(NAME, " extension"));
|
90
|
-
}
|
91
|
-
for (var _i = 0, _a = extensionMetadata.original; _i < _a.length; _i++) {
|
92
|
-
var entry = _a[_i];
|
93
|
-
entry.mesh.material = entry.material;
|
94
|
-
}
|
95
|
-
extensionMetadata.lastSelected = null;
|
96
|
-
};
|
97
|
-
/**
|
98
|
-
* Reset back to the original before selecting a variant.
|
99
|
-
* @param rootMesh The glTF root mesh
|
100
|
-
*/
|
101
|
-
KHR_materials_variants.prototype.reset = function (rootMesh) {
|
102
|
-
return KHR_materials_variants.Reset(rootMesh);
|
103
|
-
};
|
104
|
-
/**
|
105
|
-
* Gets the last selected variant name(s) or null if original.
|
106
|
-
* @param rootMesh The glTF root mesh
|
107
|
-
* @returns The selected variant name(s).
|
108
|
-
*/
|
109
|
-
KHR_materials_variants.GetLastSelectedVariant = function (rootMesh) {
|
110
|
-
var extensionMetadata = this._GetExtensionMetadata(rootMesh);
|
111
|
-
if (!extensionMetadata) {
|
112
|
-
throw new Error("Cannot get the last selected variant on a glTF mesh that does not have the ".concat(NAME, " extension"));
|
113
|
-
}
|
114
|
-
return extensionMetadata.lastSelected;
|
115
|
-
};
|
116
|
-
/**
|
117
|
-
* Gets the last selected variant name(s) or null if original.
|
118
|
-
* @param rootMesh The glTF root mesh
|
119
|
-
* @returns The selected variant name(s).
|
120
|
-
*/
|
121
|
-
KHR_materials_variants.prototype.getLastSelectedVariant = function (rootMesh) {
|
122
|
-
return KHR_materials_variants.GetLastSelectedVariant(rootMesh);
|
123
|
-
};
|
124
|
-
KHR_materials_variants._GetExtensionMetadata = function (rootMesh) {
|
125
|
-
var _a, _b;
|
126
|
-
return ((_b = (_a = rootMesh === null || rootMesh === void 0 ? void 0 : rootMesh.metadata) === null || _a === void 0 ? void 0 : _a.gltf) === null || _b === void 0 ? void 0 : _b[NAME]) || null;
|
127
|
-
};
|
128
|
-
/** @hidden */
|
129
|
-
KHR_materials_variants.prototype.onLoading = function () {
|
130
|
-
var extensions = this._loader.gltf.extensions;
|
131
|
-
if (extensions && extensions[this.name]) {
|
132
|
-
var extension = extensions[this.name];
|
133
|
-
this._variants = extension.variants;
|
134
|
-
}
|
135
|
-
};
|
136
|
-
/**
|
137
|
-
* @param context
|
138
|
-
* @param name
|
139
|
-
* @param node
|
140
|
-
* @param mesh
|
141
|
-
* @param primitive
|
142
|
-
* @param assign
|
143
|
-
* @hidden
|
144
|
-
*/
|
145
|
-
KHR_materials_variants.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
|
146
|
-
var _this = this;
|
147
|
-
return GLTFLoader.LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
|
148
|
-
var promises = new Array();
|
149
|
-
promises.push(_this._loader._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, function (babylonMesh) {
|
150
|
-
assign(babylonMesh);
|
151
|
-
if (babylonMesh instanceof Mesh) {
|
152
|
-
var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
|
153
|
-
var root_1 = _this._loader.rootBabylonMesh;
|
154
|
-
var metadata = root_1 ? (root_1.metadata = root_1.metadata || {}) : {};
|
155
|
-
var gltf = (metadata.gltf = metadata.gltf || {});
|
156
|
-
var extensionMetadata_1 = (gltf[NAME] = gltf[NAME] || { lastSelected: null, original: [], variants: {} });
|
157
|
-
// Store the original material.
|
158
|
-
extensionMetadata_1.original.push({ mesh: babylonMesh, material: babylonMesh.material });
|
159
|
-
var _loop_1 = function (mappingIndex) {
|
160
|
-
var mapping = extension.mappings[mappingIndex];
|
161
|
-
var material = ArrayItem.Get("".concat(extensionContext, "/mappings/").concat(mappingIndex, "/material"), _this._loader.gltf.materials, mapping.material);
|
162
|
-
promises.push(_this._loader._loadMaterialAsync("#/materials/".concat(mapping.material), material, babylonMesh, babylonDrawMode, function (babylonMaterial) {
|
163
|
-
var _loop_2 = function (mappingVariantIndex) {
|
164
|
-
var variantIndex = mapping.variants[mappingVariantIndex];
|
165
|
-
var variant = ArrayItem.Get("/extensions/".concat(NAME, "/variants/").concat(variantIndex), _this._variants, variantIndex);
|
166
|
-
extensionMetadata_1.variants[variant.name] = extensionMetadata_1.variants[variant.name] || [];
|
167
|
-
extensionMetadata_1.variants[variant.name].push({
|
168
|
-
mesh: babylonMesh,
|
169
|
-
material: babylonMaterial,
|
170
|
-
});
|
171
|
-
// Replace the target when original mesh is cloned
|
172
|
-
babylonMesh.onClonedObservable.add(function (newOne) {
|
173
|
-
var newMesh = newOne;
|
174
|
-
var metadata = null;
|
175
|
-
var newRoot = newMesh;
|
176
|
-
// Find root to get medata
|
177
|
-
do {
|
178
|
-
newRoot = newRoot.parent;
|
179
|
-
if (!newRoot) {
|
180
|
-
return;
|
181
|
-
}
|
182
|
-
metadata = KHR_materials_variants._GetExtensionMetadata(newRoot);
|
183
|
-
} while (metadata === null);
|
184
|
-
// Need to clone the metadata on the root (first time only)
|
185
|
-
if (root_1 && metadata === KHR_materials_variants._GetExtensionMetadata(root_1)) {
|
186
|
-
// Copy main metadata
|
187
|
-
newRoot.metadata = {};
|
188
|
-
for (var key in root_1.metadata) {
|
189
|
-
newRoot.metadata[key] = root_1.metadata[key];
|
190
|
-
}
|
191
|
-
// Copy the gltf metadata
|
192
|
-
newRoot.metadata.gltf = [];
|
193
|
-
for (var key in root_1.metadata.gltf) {
|
194
|
-
newRoot.metadata.gltf[key] = root_1.metadata.gltf[key];
|
195
|
-
}
|
196
|
-
// Duplicate the extension specific metadata
|
197
|
-
newRoot.metadata.gltf[NAME] = { lastSelected: null, original: [], variants: {} };
|
198
|
-
for (var _i = 0, _a = metadata.original; _i < _a.length; _i++) {
|
199
|
-
var original = _a[_i];
|
200
|
-
newRoot.metadata.gltf[NAME].original.push({
|
201
|
-
mesh: original.mesh,
|
202
|
-
material: original.material,
|
203
|
-
});
|
204
|
-
}
|
205
|
-
for (var key in metadata.variants) {
|
206
|
-
if (Object.prototype.hasOwnProperty.call(metadata.variants, key)) {
|
207
|
-
newRoot.metadata.gltf[NAME].variants[key] = [];
|
208
|
-
for (var _b = 0, _c = metadata.variants[key]; _b < _c.length; _b++) {
|
209
|
-
var variantEntry = _c[_b];
|
210
|
-
newRoot.metadata.gltf[NAME].variants[key].push({
|
211
|
-
mesh: variantEntry.mesh,
|
212
|
-
material: variantEntry.material,
|
213
|
-
});
|
214
|
-
}
|
215
|
-
}
|
216
|
-
}
|
217
|
-
metadata = newRoot.metadata.gltf[NAME];
|
218
|
-
}
|
219
|
-
// Relocate
|
220
|
-
for (var _d = 0, _e = metadata.original; _d < _e.length; _d++) {
|
221
|
-
var target = _e[_d];
|
222
|
-
if (target.mesh === babylonMesh) {
|
223
|
-
target.mesh = newMesh;
|
224
|
-
}
|
225
|
-
}
|
226
|
-
for (var _f = 0, _g = metadata.variants[variant.name]; _f < _g.length; _f++) {
|
227
|
-
var target = _g[_f];
|
228
|
-
if (target.mesh === babylonMesh) {
|
229
|
-
target.mesh = newMesh;
|
230
|
-
}
|
231
|
-
}
|
232
|
-
});
|
233
|
-
};
|
234
|
-
for (var mappingVariantIndex = 0; mappingVariantIndex < mapping.variants.length; ++mappingVariantIndex) {
|
235
|
-
_loop_2(mappingVariantIndex);
|
236
|
-
}
|
237
|
-
}));
|
238
|
-
};
|
239
|
-
// For each mapping, look at the variants and make a new entry for them.
|
240
|
-
for (var mappingIndex = 0; mappingIndex < extension.mappings.length; ++mappingIndex) {
|
241
|
-
_loop_1(mappingIndex);
|
242
|
-
}
|
243
|
-
}
|
244
|
-
}));
|
245
|
-
return Promise.all(promises).then(function (_a) {
|
246
|
-
var babylonMesh = _a[0];
|
247
|
-
return babylonMesh;
|
248
|
-
});
|
249
|
-
});
|
250
|
-
};
|
251
|
-
return KHR_materials_variants;
|
252
|
-
}());
|
253
|
-
export { KHR_materials_variants };
|
254
|
-
GLTFLoader.RegisterExtension(NAME, function (loader) { return new KHR_materials_variants(loader); });
|
1
|
+
import { GLTFLoader, ArrayItem } from "../glTFLoader";
|
2
|
+
import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
|
3
|
+
var NAME = "KHR_materials_variants";
|
4
|
+
/**
|
5
|
+
* [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_variants/README.md)
|
6
|
+
*/
|
7
|
+
var KHR_materials_variants = /** @class */ (function () {
|
8
|
+
/**
|
9
|
+
* @param loader
|
10
|
+
* @hidden
|
11
|
+
*/
|
12
|
+
function KHR_materials_variants(loader) {
|
13
|
+
/**
|
14
|
+
* The name of this extension.
|
15
|
+
*/
|
16
|
+
this.name = NAME;
|
17
|
+
this._loader = loader;
|
18
|
+
this.enabled = this._loader.isExtensionUsed(NAME);
|
19
|
+
}
|
20
|
+
/** @hidden */
|
21
|
+
KHR_materials_variants.prototype.dispose = function () {
|
22
|
+
this._loader = null;
|
23
|
+
};
|
24
|
+
/**
|
25
|
+
* Gets the list of available variant names for this asset.
|
26
|
+
* @param rootMesh The glTF root mesh
|
27
|
+
* @returns the list of all the variant names for this model
|
28
|
+
*/
|
29
|
+
KHR_materials_variants.GetAvailableVariants = function (rootMesh) {
|
30
|
+
var extensionMetadata = this._GetExtensionMetadata(rootMesh);
|
31
|
+
if (!extensionMetadata) {
|
32
|
+
return [];
|
33
|
+
}
|
34
|
+
return Object.keys(extensionMetadata.variants);
|
35
|
+
};
|
36
|
+
/**
|
37
|
+
* Gets the list of available variant names for this asset.
|
38
|
+
* @param rootMesh The glTF root mesh
|
39
|
+
* @returns the list of all the variant names for this model
|
40
|
+
*/
|
41
|
+
KHR_materials_variants.prototype.getAvailableVariants = function (rootMesh) {
|
42
|
+
return KHR_materials_variants.GetAvailableVariants(rootMesh);
|
43
|
+
};
|
44
|
+
/**
|
45
|
+
* Select a variant given a variant name or a list of variant names.
|
46
|
+
* @param rootMesh The glTF root mesh
|
47
|
+
* @param variantName The variant name(s) to select.
|
48
|
+
*/
|
49
|
+
KHR_materials_variants.SelectVariant = function (rootMesh, variantName) {
|
50
|
+
var extensionMetadata = this._GetExtensionMetadata(rootMesh);
|
51
|
+
if (!extensionMetadata) {
|
52
|
+
throw new Error("Cannot select variant on a glTF mesh that does not have the ".concat(NAME, " extension"));
|
53
|
+
}
|
54
|
+
var select = function (variantName) {
|
55
|
+
var entries = extensionMetadata.variants[variantName];
|
56
|
+
if (entries) {
|
57
|
+
for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
|
58
|
+
var entry = entries_1[_i];
|
59
|
+
entry.mesh.material = entry.material;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
};
|
63
|
+
if (variantName instanceof Array) {
|
64
|
+
for (var _i = 0, variantName_1 = variantName; _i < variantName_1.length; _i++) {
|
65
|
+
var name_1 = variantName_1[_i];
|
66
|
+
select(name_1);
|
67
|
+
}
|
68
|
+
}
|
69
|
+
else {
|
70
|
+
select(variantName);
|
71
|
+
}
|
72
|
+
extensionMetadata.lastSelected = variantName;
|
73
|
+
};
|
74
|
+
/**
|
75
|
+
* Select a variant given a variant name or a list of variant names.
|
76
|
+
* @param rootMesh The glTF root mesh
|
77
|
+
* @param variantName The variant name(s) to select.
|
78
|
+
*/
|
79
|
+
KHR_materials_variants.prototype.selectVariant = function (rootMesh, variantName) {
|
80
|
+
return KHR_materials_variants.SelectVariant(rootMesh, variantName);
|
81
|
+
};
|
82
|
+
/**
|
83
|
+
* Reset back to the original before selecting a variant.
|
84
|
+
* @param rootMesh The glTF root mesh
|
85
|
+
*/
|
86
|
+
KHR_materials_variants.Reset = function (rootMesh) {
|
87
|
+
var extensionMetadata = this._GetExtensionMetadata(rootMesh);
|
88
|
+
if (!extensionMetadata) {
|
89
|
+
throw new Error("Cannot reset on a glTF mesh that does not have the ".concat(NAME, " extension"));
|
90
|
+
}
|
91
|
+
for (var _i = 0, _a = extensionMetadata.original; _i < _a.length; _i++) {
|
92
|
+
var entry = _a[_i];
|
93
|
+
entry.mesh.material = entry.material;
|
94
|
+
}
|
95
|
+
extensionMetadata.lastSelected = null;
|
96
|
+
};
|
97
|
+
/**
|
98
|
+
* Reset back to the original before selecting a variant.
|
99
|
+
* @param rootMesh The glTF root mesh
|
100
|
+
*/
|
101
|
+
KHR_materials_variants.prototype.reset = function (rootMesh) {
|
102
|
+
return KHR_materials_variants.Reset(rootMesh);
|
103
|
+
};
|
104
|
+
/**
|
105
|
+
* Gets the last selected variant name(s) or null if original.
|
106
|
+
* @param rootMesh The glTF root mesh
|
107
|
+
* @returns The selected variant name(s).
|
108
|
+
*/
|
109
|
+
KHR_materials_variants.GetLastSelectedVariant = function (rootMesh) {
|
110
|
+
var extensionMetadata = this._GetExtensionMetadata(rootMesh);
|
111
|
+
if (!extensionMetadata) {
|
112
|
+
throw new Error("Cannot get the last selected variant on a glTF mesh that does not have the ".concat(NAME, " extension"));
|
113
|
+
}
|
114
|
+
return extensionMetadata.lastSelected;
|
115
|
+
};
|
116
|
+
/**
|
117
|
+
* Gets the last selected variant name(s) or null if original.
|
118
|
+
* @param rootMesh The glTF root mesh
|
119
|
+
* @returns The selected variant name(s).
|
120
|
+
*/
|
121
|
+
KHR_materials_variants.prototype.getLastSelectedVariant = function (rootMesh) {
|
122
|
+
return KHR_materials_variants.GetLastSelectedVariant(rootMesh);
|
123
|
+
};
|
124
|
+
KHR_materials_variants._GetExtensionMetadata = function (rootMesh) {
|
125
|
+
var _a, _b;
|
126
|
+
return ((_b = (_a = rootMesh === null || rootMesh === void 0 ? void 0 : rootMesh.metadata) === null || _a === void 0 ? void 0 : _a.gltf) === null || _b === void 0 ? void 0 : _b[NAME]) || null;
|
127
|
+
};
|
128
|
+
/** @hidden */
|
129
|
+
KHR_materials_variants.prototype.onLoading = function () {
|
130
|
+
var extensions = this._loader.gltf.extensions;
|
131
|
+
if (extensions && extensions[this.name]) {
|
132
|
+
var extension = extensions[this.name];
|
133
|
+
this._variants = extension.variants;
|
134
|
+
}
|
135
|
+
};
|
136
|
+
/**
|
137
|
+
* @param context
|
138
|
+
* @param name
|
139
|
+
* @param node
|
140
|
+
* @param mesh
|
141
|
+
* @param primitive
|
142
|
+
* @param assign
|
143
|
+
* @hidden
|
144
|
+
*/
|
145
|
+
KHR_materials_variants.prototype._loadMeshPrimitiveAsync = function (context, name, node, mesh, primitive, assign) {
|
146
|
+
var _this = this;
|
147
|
+
return GLTFLoader.LoadExtensionAsync(context, primitive, this.name, function (extensionContext, extension) {
|
148
|
+
var promises = new Array();
|
149
|
+
promises.push(_this._loader._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, function (babylonMesh) {
|
150
|
+
assign(babylonMesh);
|
151
|
+
if (babylonMesh instanceof Mesh) {
|
152
|
+
var babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
|
153
|
+
var root_1 = _this._loader.rootBabylonMesh;
|
154
|
+
var metadata = root_1 ? (root_1.metadata = root_1.metadata || {}) : {};
|
155
|
+
var gltf = (metadata.gltf = metadata.gltf || {});
|
156
|
+
var extensionMetadata_1 = (gltf[NAME] = gltf[NAME] || { lastSelected: null, original: [], variants: {} });
|
157
|
+
// Store the original material.
|
158
|
+
extensionMetadata_1.original.push({ mesh: babylonMesh, material: babylonMesh.material });
|
159
|
+
var _loop_1 = function (mappingIndex) {
|
160
|
+
var mapping = extension.mappings[mappingIndex];
|
161
|
+
var material = ArrayItem.Get("".concat(extensionContext, "/mappings/").concat(mappingIndex, "/material"), _this._loader.gltf.materials, mapping.material);
|
162
|
+
promises.push(_this._loader._loadMaterialAsync("#/materials/".concat(mapping.material), material, babylonMesh, babylonDrawMode, function (babylonMaterial) {
|
163
|
+
var _loop_2 = function (mappingVariantIndex) {
|
164
|
+
var variantIndex = mapping.variants[mappingVariantIndex];
|
165
|
+
var variant = ArrayItem.Get("/extensions/".concat(NAME, "/variants/").concat(variantIndex), _this._variants, variantIndex);
|
166
|
+
extensionMetadata_1.variants[variant.name] = extensionMetadata_1.variants[variant.name] || [];
|
167
|
+
extensionMetadata_1.variants[variant.name].push({
|
168
|
+
mesh: babylonMesh,
|
169
|
+
material: babylonMaterial,
|
170
|
+
});
|
171
|
+
// Replace the target when original mesh is cloned
|
172
|
+
babylonMesh.onClonedObservable.add(function (newOne) {
|
173
|
+
var newMesh = newOne;
|
174
|
+
var metadata = null;
|
175
|
+
var newRoot = newMesh;
|
176
|
+
// Find root to get medata
|
177
|
+
do {
|
178
|
+
newRoot = newRoot.parent;
|
179
|
+
if (!newRoot) {
|
180
|
+
return;
|
181
|
+
}
|
182
|
+
metadata = KHR_materials_variants._GetExtensionMetadata(newRoot);
|
183
|
+
} while (metadata === null);
|
184
|
+
// Need to clone the metadata on the root (first time only)
|
185
|
+
if (root_1 && metadata === KHR_materials_variants._GetExtensionMetadata(root_1)) {
|
186
|
+
// Copy main metadata
|
187
|
+
newRoot.metadata = {};
|
188
|
+
for (var key in root_1.metadata) {
|
189
|
+
newRoot.metadata[key] = root_1.metadata[key];
|
190
|
+
}
|
191
|
+
// Copy the gltf metadata
|
192
|
+
newRoot.metadata.gltf = [];
|
193
|
+
for (var key in root_1.metadata.gltf) {
|
194
|
+
newRoot.metadata.gltf[key] = root_1.metadata.gltf[key];
|
195
|
+
}
|
196
|
+
// Duplicate the extension specific metadata
|
197
|
+
newRoot.metadata.gltf[NAME] = { lastSelected: null, original: [], variants: {} };
|
198
|
+
for (var _i = 0, _a = metadata.original; _i < _a.length; _i++) {
|
199
|
+
var original = _a[_i];
|
200
|
+
newRoot.metadata.gltf[NAME].original.push({
|
201
|
+
mesh: original.mesh,
|
202
|
+
material: original.material,
|
203
|
+
});
|
204
|
+
}
|
205
|
+
for (var key in metadata.variants) {
|
206
|
+
if (Object.prototype.hasOwnProperty.call(metadata.variants, key)) {
|
207
|
+
newRoot.metadata.gltf[NAME].variants[key] = [];
|
208
|
+
for (var _b = 0, _c = metadata.variants[key]; _b < _c.length; _b++) {
|
209
|
+
var variantEntry = _c[_b];
|
210
|
+
newRoot.metadata.gltf[NAME].variants[key].push({
|
211
|
+
mesh: variantEntry.mesh,
|
212
|
+
material: variantEntry.material,
|
213
|
+
});
|
214
|
+
}
|
215
|
+
}
|
216
|
+
}
|
217
|
+
metadata = newRoot.metadata.gltf[NAME];
|
218
|
+
}
|
219
|
+
// Relocate
|
220
|
+
for (var _d = 0, _e = metadata.original; _d < _e.length; _d++) {
|
221
|
+
var target = _e[_d];
|
222
|
+
if (target.mesh === babylonMesh) {
|
223
|
+
target.mesh = newMesh;
|
224
|
+
}
|
225
|
+
}
|
226
|
+
for (var _f = 0, _g = metadata.variants[variant.name]; _f < _g.length; _f++) {
|
227
|
+
var target = _g[_f];
|
228
|
+
if (target.mesh === babylonMesh) {
|
229
|
+
target.mesh = newMesh;
|
230
|
+
}
|
231
|
+
}
|
232
|
+
});
|
233
|
+
};
|
234
|
+
for (var mappingVariantIndex = 0; mappingVariantIndex < mapping.variants.length; ++mappingVariantIndex) {
|
235
|
+
_loop_2(mappingVariantIndex);
|
236
|
+
}
|
237
|
+
}));
|
238
|
+
};
|
239
|
+
// For each mapping, look at the variants and make a new entry for them.
|
240
|
+
for (var mappingIndex = 0; mappingIndex < extension.mappings.length; ++mappingIndex) {
|
241
|
+
_loop_1(mappingIndex);
|
242
|
+
}
|
243
|
+
}
|
244
|
+
}));
|
245
|
+
return Promise.all(promises).then(function (_a) {
|
246
|
+
var babylonMesh = _a[0];
|
247
|
+
return babylonMesh;
|
248
|
+
});
|
249
|
+
});
|
250
|
+
};
|
251
|
+
return KHR_materials_variants;
|
252
|
+
}());
|
253
|
+
export { KHR_materials_variants };
|
254
|
+
GLTFLoader.RegisterExtension(NAME, function (loader) { return new KHR_materials_variants(loader); });
|
255
255
|
//# sourceMappingURL=KHR_materials_variants.js.map
|
@@ -1,39 +1,39 @@
|
|
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/tree/master/extensions/2.0/Khronos/KHR_materials_volume)
|
8
|
-
* @since 5.0.0
|
9
|
-
*/
|
10
|
-
export declare class KHR_materials_volume implements IGLTFLoaderExtension {
|
11
|
-
/**
|
12
|
-
* The name of this extension.
|
13
|
-
*/
|
14
|
-
readonly name = "KHR_materials_volume";
|
15
|
-
/**
|
16
|
-
* Defines whether this extension is enabled.
|
17
|
-
*/
|
18
|
-
enabled: boolean;
|
19
|
-
/**
|
20
|
-
* Defines a number that determines the order the extensions are applied.
|
21
|
-
*/
|
22
|
-
order: number;
|
23
|
-
private _loader;
|
24
|
-
/**
|
25
|
-
* @param loader
|
26
|
-
* @hidden
|
27
|
-
*/
|
28
|
-
constructor(loader: GLTFLoader);
|
29
|
-
/** @hidden */
|
30
|
-
dispose(): void;
|
31
|
-
/**
|
32
|
-
* @param context
|
33
|
-
* @param material
|
34
|
-
* @param babylonMaterial
|
35
|
-
* @hidden
|
36
|
-
*/
|
37
|
-
loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
|
38
|
-
private _loadVolumePropertiesAsync;
|
39
|
-
}
|
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/tree/master/extensions/2.0/Khronos/KHR_materials_volume)
|
8
|
+
* @since 5.0.0
|
9
|
+
*/
|
10
|
+
export declare class KHR_materials_volume implements IGLTFLoaderExtension {
|
11
|
+
/**
|
12
|
+
* The name of this extension.
|
13
|
+
*/
|
14
|
+
readonly name = "KHR_materials_volume";
|
15
|
+
/**
|
16
|
+
* Defines whether this extension is enabled.
|
17
|
+
*/
|
18
|
+
enabled: boolean;
|
19
|
+
/**
|
20
|
+
* Defines a number that determines the order the extensions are applied.
|
21
|
+
*/
|
22
|
+
order: number;
|
23
|
+
private _loader;
|
24
|
+
/**
|
25
|
+
* @param loader
|
26
|
+
* @hidden
|
27
|
+
*/
|
28
|
+
constructor(loader: GLTFLoader);
|
29
|
+
/** @hidden */
|
30
|
+
dispose(): void;
|
31
|
+
/**
|
32
|
+
* @param context
|
33
|
+
* @param material
|
34
|
+
* @param babylonMaterial
|
35
|
+
* @hidden
|
36
|
+
*/
|
37
|
+
loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
|
38
|
+
private _loadVolumePropertiesAsync;
|
39
|
+
}
|