@babylonjs/loaders 5.0.0-beta.4 → 5.0.0-beta.8
Sign up to get free protection for your applications and to get access to all the features.
- package/OBJ/objFileLoader.js +2 -2
- package/OBJ/objFileLoader.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_lights_image_based.js +8 -8
- package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +4 -4
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js +2 -2
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_texture_webp.js +2 -2
- package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +27 -7
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +7 -7
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +1 -1
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_ior.js +1 -1
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +5 -5
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +5 -5
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_specular.js +5 -5
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_translucency.js +2 -2
- package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +2 -2
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +3 -3
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_variants.js +6 -6
- package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.js +2 -2
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_basisu.js +2 -2
- package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.js +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js +13 -13
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.d.ts +0 -1
- package/glTF/2.0/Extensions/MSFT_lod.js +17 -54
- package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +1 -1
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +1 -1
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
- package/glTF/2.0/glTFLoader.d.ts +4 -2
- package/glTF/2.0/glTFLoader.js +258 -193
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.d.ts +0 -3
- package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/glTFFileLoader.d.ts +4 -0
- package/glTF/glTFFileLoader.js +17 -13
- package/glTF/glTFFileLoader.js.map +1 -1
- package/glTF/glTFValidation.js +1 -1
- package/glTF/glTFValidation.js.map +1 -1
- package/package.json +3 -3
@@ -46,7 +46,7 @@ var KHR_materials_variants = /** @class */ (function () {
|
|
46
46
|
KHR_materials_variants.SelectVariant = function (rootMesh, variantName) {
|
47
47
|
var extensionMetadata = this._GetExtensionMetadata(rootMesh);
|
48
48
|
if (!extensionMetadata) {
|
49
|
-
throw new Error("Cannot select variant on a glTF mesh that does not have the "
|
49
|
+
throw new Error("Cannot select variant on a glTF mesh that does not have the ".concat(NAME, " extension"));
|
50
50
|
}
|
51
51
|
var select = function (variantName) {
|
52
52
|
var entries = extensionMetadata.variants[variantName];
|
@@ -83,7 +83,7 @@ var KHR_materials_variants = /** @class */ (function () {
|
|
83
83
|
KHR_materials_variants.Reset = function (rootMesh) {
|
84
84
|
var extensionMetadata = this._GetExtensionMetadata(rootMesh);
|
85
85
|
if (!extensionMetadata) {
|
86
|
-
throw new Error("Cannot reset on a glTF mesh that does not have the "
|
86
|
+
throw new Error("Cannot reset on a glTF mesh that does not have the ".concat(NAME, " extension"));
|
87
87
|
}
|
88
88
|
for (var _i = 0, _a = extensionMetadata.original; _i < _a.length; _i++) {
|
89
89
|
var entry = _a[_i];
|
@@ -106,7 +106,7 @@ var KHR_materials_variants = /** @class */ (function () {
|
|
106
106
|
KHR_materials_variants.GetLastSelectedVariant = function (rootMesh) {
|
107
107
|
var extensionMetadata = this._GetExtensionMetadata(rootMesh);
|
108
108
|
if (!extensionMetadata) {
|
109
|
-
throw new Error("Cannot get the last selected variant on a glTF mesh that does not have the "
|
109
|
+
throw new Error("Cannot get the last selected variant on a glTF mesh that does not have the ".concat(NAME, " extension"));
|
110
110
|
}
|
111
111
|
return extensionMetadata.lastSelected;
|
112
112
|
};
|
@@ -147,11 +147,11 @@ var KHR_materials_variants = /** @class */ (function () {
|
|
147
147
|
extensionMetadata_1.original.push({ mesh: babylonMesh, material: babylonMesh.material });
|
148
148
|
var _loop_1 = function (mappingIndex) {
|
149
149
|
var mapping = extension.mappings[mappingIndex];
|
150
|
-
var material = ArrayItem.Get(extensionContext
|
151
|
-
promises.push(_this._loader._loadMaterialAsync("#/materials/"
|
150
|
+
var material = ArrayItem.Get("".concat(extensionContext, "/mappings/").concat(mappingIndex, "/material"), _this._loader.gltf.materials, mapping.material);
|
151
|
+
promises.push(_this._loader._loadMaterialAsync("#/materials/".concat(mapping.material), material, babylonMesh, babylonDrawMode, function (babylonMaterial) {
|
152
152
|
var _loop_2 = function (mappingVariantIndex) {
|
153
153
|
var variantIndex = mapping.variants[mappingVariantIndex];
|
154
|
-
var variant = ArrayItem.Get("/extensions/"
|
154
|
+
var variant = ArrayItem.Get("/extensions/".concat(NAME, "/variants/").concat(variantIndex), _this._variants, variantIndex);
|
155
155
|
extensionMetadata_1.variants[variant.name] = extensionMetadata_1.variants[variant.name] || [];
|
156
156
|
extensionMetadata_1.variants[variant.name].push({
|
157
157
|
mesh: babylonMesh,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_materials_variants.js","sourceRoot":"","sources":["../../../../../sourceES6/loaders/src/glTF/2.0/Extensions/KHR_materials_variants.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAMnD,IAAM,IAAI,GAAG,wBAAwB,CAAC;AAYtC;;GAEG;AACH;IAeI,cAAc;IACd,gCAAY,MAAkB;QAf9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAaxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,cAAc;IACP,wCAAO,GAAd;QACK,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACW,2CAAoB,GAAlC,UAAmC,QAAc;QAC7C,IAAM,iBAAiB,GAAG,IAAI,CAAC,qBAAqB,C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IAAI,MAAM,SAAA;wCACX,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW,EAAE;4CAC7B,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC;yCACzB;qCACJ;gCACL,CAAC,CAAC,CAAC;;4BAzEP,KAAK,IAAI,mBAAmB,GAAG,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,mBAAmB;wCAA7F,mBAAmB;6BA0E3B;wBACL,CAAC,CAAC,CAAC,CAAC;;oBAhFR,wEAAwE;oBACxE,KAAK,IAAI,YAAY,GAAG,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,YAAY;gCAA1E,YAAY;qBAgFpB;iBACJ;YACL,CAAC,CAAC,CAAC,CAAC;YACJ,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,UAAC,EAAa;oBAAZ,WAAW,QAAA;gBAC3C,OAAO,WAAW,CAAC;YACvB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IACL,6BAAC;AAAD,CAAC,AAjQD,IAiQC;;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,MAAM,IAAK,OAAA,IAAI,sBAAsB,CAAC,MAAM,CAAC,EAAlC,CAAkC,CAAC,CAAC","sourcesContent":["import { Nullable } from \"@babylonjs/core/types\";\nimport { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\n\nimport { Material } from '@babylonjs/core/Materials/material';\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\nimport { Node } from '@babylonjs/core/node';\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\nimport { INode, IMeshPrimitive, IMesh } from '../glTFLoaderInterfaces';\nimport { IKHRMaterialVariants_Mapping, IKHRMaterialVariants_Variant, IKHRMaterialVariants_Variants } from 'babylonjs-gltf2interface';\n\nconst NAME = \"KHR_materials_variants\";\n\ninterface IVariantsMap {\n [key: string]: Array<{ mesh: AbstractMesh, material: Nullable<Material> }>;\n}\n\ninterface IExtensionMetadata {\n lastSelected: Nullable<string | Array<string>>;\n original: Array<{ mesh: AbstractMesh, material: Nullable<Material> }>;\n variants: IVariantsMap;\n}\n\n/**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_variants/README.md)\n */\nexport class KHR_materials_variants implements IGLTFLoaderExtension {\n /**\n * The name of this extension.\n */\n public readonly name = NAME;\n\n /**\n * Defines whether this extension is enabled.\n */\n public enabled: boolean;\n\n private _loader: GLTFLoader;\n\n private _variants?: Array<IKHRMaterialVariants_Variant>;\n\n /** @hidden */\n constructor(loader: GLTFLoader) {\n this._loader = loader;\n this.enabled = this._loader.isExtensionUsed(NAME);\n }\n\n /** @hidden */\n public dispose() {\n (this._loader as any) = null;\n }\n\n /**\n * Gets the list of available variant names for this asset.\n * @param rootMesh The glTF root mesh\n * @returns the list of all the variant names for this model\n */\n public static GetAvailableVariants(rootMesh: Mesh): string[] {\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\n if (!extensionMetadata) {\n return [];\n }\n\n return Object.keys(extensionMetadata.variants);\n }\n\n /**\n * Gets the list of available variant names for this asset.\n * @param rootMesh The glTF root mesh\n * @returns the list of all the variant names for this model\n */\n public getAvailableVariants(rootMesh: Mesh): string[] {\n return KHR_materials_variants.GetAvailableVariants(rootMesh);\n }\n\n /**\n * Select a variant given a variant name or a list of variant names.\n * @param rootMesh The glTF root mesh\n * @param variantName The variant name(s) to select.\n */\n public static SelectVariant(rootMesh: Mesh, variantName: string | string[]): void {\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\n if (!extensionMetadata) {\n throw new Error(`Cannot select variant on a glTF mesh that does not have the ${NAME} extension`);\n }\n\n const select = (variantName: string): void => {\n const entries = extensionMetadata.variants[variantName];\n if (entries) {\n for (const entry of entries) {\n entry.mesh.material = entry.material;\n }\n }\n };\n\n if (variantName instanceof Array) {\n for (const name of variantName) {\n select(name);\n }\n } else {\n select(variantName);\n }\n\n extensionMetadata.lastSelected = variantName;\n }\n\n /**\n * Select a variant given a variant name or a list of variant names.\n * @param rootMesh The glTF root mesh\n * @param variantName The variant name(s) to select.\n */\n public selectVariant(rootMesh: Mesh, variantName: string | string[]): void {\n return KHR_materials_variants.SelectVariant(rootMesh, variantName);\n }\n\n /**\n * Reset back to the original before selecting a variant.\n * @param rootMesh The glTF root mesh\n */\n public static Reset(rootMesh: Mesh): void {\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\n if (!extensionMetadata) {\n throw new Error(`Cannot reset on a glTF mesh that does not have the ${NAME} extension`);\n }\n\n for (const entry of extensionMetadata.original) {\n entry.mesh.material = entry.material;\n }\n\n extensionMetadata.lastSelected = null;\n }\n\n /**\n * Reset back to the original before selecting a variant.\n * @param rootMesh The glTF root mesh\n */\n public reset(rootMesh: Mesh): void {\n return KHR_materials_variants.Reset(rootMesh);\n }\n\n /**\n * Gets the last selected variant name(s) or null if original.\n * @param rootMesh The glTF root mesh\n * @returns The selected variant name(s).\n */\n public static GetLastSelectedVariant(rootMesh: Mesh): Nullable<string | string[]> {\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\n if (!extensionMetadata) {\n throw new Error(`Cannot get the last selected variant on a glTF mesh that does not have the ${NAME} extension`);\n }\n\n return extensionMetadata.lastSelected;\n }\n\n /**\n * Gets the last selected variant name(s) or null if original.\n * @param rootMesh The glTF root mesh\n * @returns The selected variant name(s).\n */\n public getLastSelectedVariant(rootMesh: Mesh): Nullable<string | string[]> {\n return KHR_materials_variants.GetLastSelectedVariant(rootMesh);\n }\n\n private static _GetExtensionMetadata(rootMesh: Nullable<Mesh>): Nullable<IExtensionMetadata> {\n return rootMesh?.metadata?.gltf?.[NAME] || null;\n }\n\n /** @hidden */\n public onLoading(): void {\n const extensions = this._loader.gltf.extensions;\n if (extensions && extensions[this.name]) {\n const extension = extensions[this.name] as IKHRMaterialVariants_Variants;\n this._variants = extension.variants;\n }\n }\n\n /** @hidden */\n public _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Nullable<Promise<AbstractMesh>> {\n return GLTFLoader.LoadExtensionAsync<IKHRMaterialVariants_Mapping, AbstractMesh>(context, primitive, this.name, (extensionContext, extension) => {\n const promises = new Array<Promise<any>>();\n promises.push(this._loader._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, (babylonMesh) => {\n assign(babylonMesh);\n\n if (babylonMesh instanceof Mesh) {\n const babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);\n\n const root = this._loader.rootBabylonMesh;\n const metadata = (root ? root.metadata = root.metadata || {} : {});\n const gltf = (metadata.gltf = metadata.gltf || {});\n const extensionMetadata: IExtensionMetadata = (gltf[NAME] = gltf[NAME] || { lastSelected: null, original: [], variants: {} });\n\n // Store the original material.\n extensionMetadata.original.push({ mesh: babylonMesh, material: babylonMesh.material });\n\n // For each mapping, look at the variants and make a new entry for them.\n for (let mappingIndex = 0; mappingIndex < extension.mappings.length; ++mappingIndex) {\n const mapping = extension.mappings[mappingIndex];\n const material = ArrayItem.Get(`${extensionContext}/mappings/${mappingIndex}/material`, this._loader.gltf.materials, mapping.material);\n promises.push(this._loader._loadMaterialAsync(`#/materials/${mapping.material}`, material, babylonMesh, babylonDrawMode, (babylonMaterial) => {\n for (let mappingVariantIndex = 0; mappingVariantIndex < mapping.variants.length; ++mappingVariantIndex) {\n const variantIndex = mapping.variants[mappingVariantIndex];\n const variant = ArrayItem.Get(`/extensions/${NAME}/variants/${variantIndex}`, this._variants, variantIndex);\n extensionMetadata.variants[variant.name] = extensionMetadata.variants[variant.name] || [];\n extensionMetadata.variants[variant.name].push({\n mesh: babylonMesh,\n material: babylonMaterial\n });\n\n // Replace the target when original mesh is cloned\n babylonMesh.onClonedObservable.add((newOne: Node) => {\n const newMesh = newOne as Mesh;\n let metadata: Nullable<IExtensionMetadata> = null;\n let newRoot: Nullable<Node> = newMesh;\n\n // Find root to get medata\n do {\n newRoot = newRoot!.parent;\n if (!newRoot) {\n return;\n }\n metadata = KHR_materials_variants._GetExtensionMetadata(newRoot as Mesh);\n }\n while (metadata === null);\n\n // Need to clone the metadata on the root (first time only)\n if (root && metadata === KHR_materials_variants._GetExtensionMetadata(root)) {\n // Copy main metadata\n newRoot.metadata = {};\n for (var key in root.metadata) {\n newRoot.metadata[key] = root.metadata[key];\n }\n\n // Copy the gltf metadata\n newRoot.metadata.gltf = [];\n for (var key in root.metadata.gltf) {\n newRoot.metadata.gltf[key] = root.metadata.gltf[key];\n }\n\n // Duplicate the extension specific metadata\n newRoot.metadata.gltf[NAME] = { lastSelected: null, original: [], variants: {} };\n for (var original of metadata.original) {\n newRoot.metadata.gltf[NAME].original.push({\n mesh: original.mesh,\n material: original.material\n });\n }\n for (var key in metadata.variants) {\n if (metadata.variants.hasOwnProperty(key)) {\n newRoot.metadata.gltf[NAME].variants[key] = [];\n for (var variantEntry of metadata.variants[key]) {\n newRoot.metadata.gltf[NAME].variants[key].push({\n mesh: variantEntry.mesh,\n material: variantEntry.material\n });\n }\n }\n }\n\n metadata = newRoot.metadata.gltf[NAME];\n }\n\n // Relocate\n for (var target of metadata!.original) {\n if (target.mesh === babylonMesh) {\n target.mesh = newMesh;\n }\n }\n for (var target of metadata!.variants[variant.name]) {\n if (target.mesh === babylonMesh) {\n target.mesh = newMesh;\n }\n }\n });\n }\n }));\n }\n }\n }));\n return Promise.all(promises).then(([babylonMesh]) => {\n return babylonMesh;\n });\n });\n }\n}\n\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_materials_variants(loader));\n"]}
|
1
|
+
{"version":3,"file":"KHR_materials_variants.js","sourceRoot":"","sources":["../../../../../sourceES6/loaders/src/glTF/2.0/Extensions/KHR_materials_variants.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,SAAS,E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;IACL,6BAAC;AAAD,CAAC,AAjQD,IAiQC;;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,MAAM,IAAK,OAAA,IAAI,sBAAsB,CAAC,MAAM,CAAC,EAAlC,CAAkC,CAAC,CAAC","sourcesContent":["import { Nullable } from \"@babylonjs/core/types\";\nimport { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\n\nimport { Material } from '@babylonjs/core/Materials/material';\nimport { Mesh } from '@babylonjs/core/Meshes/mesh';\nimport { Node } from '@babylonjs/core/node';\nimport { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';\nimport { INode, IMeshPrimitive, IMesh } from '../glTFLoaderInterfaces';\nimport { IKHRMaterialVariants_Mapping, IKHRMaterialVariants_Variant, IKHRMaterialVariants_Variants } from 'babylonjs-gltf2interface';\n\nconst NAME = \"KHR_materials_variants\";\n\ninterface IVariantsMap {\n [key: string]: Array<{ mesh: AbstractMesh, material: Nullable<Material> }>;\n}\n\ninterface IExtensionMetadata {\n lastSelected: Nullable<string | Array<string>>;\n original: Array<{ mesh: AbstractMesh, material: Nullable<Material> }>;\n variants: IVariantsMap;\n}\n\n/**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_variants/README.md)\n */\nexport class KHR_materials_variants implements IGLTFLoaderExtension {\n /**\n * The name of this extension.\n */\n public readonly name = NAME;\n\n /**\n * Defines whether this extension is enabled.\n */\n public enabled: boolean;\n\n private _loader: GLTFLoader;\n\n private _variants?: Array<IKHRMaterialVariants_Variant>;\n\n /** @hidden */\n constructor(loader: GLTFLoader) {\n this._loader = loader;\n this.enabled = this._loader.isExtensionUsed(NAME);\n }\n\n /** @hidden */\n public dispose() {\n (this._loader as any) = null;\n }\n\n /**\n * Gets the list of available variant names for this asset.\n * @param rootMesh The glTF root mesh\n * @returns the list of all the variant names for this model\n */\n public static GetAvailableVariants(rootMesh: Mesh): string[] {\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\n if (!extensionMetadata) {\n return [];\n }\n\n return Object.keys(extensionMetadata.variants);\n }\n\n /**\n * Gets the list of available variant names for this asset.\n * @param rootMesh The glTF root mesh\n * @returns the list of all the variant names for this model\n */\n public getAvailableVariants(rootMesh: Mesh): string[] {\n return KHR_materials_variants.GetAvailableVariants(rootMesh);\n }\n\n /**\n * Select a variant given a variant name or a list of variant names.\n * @param rootMesh The glTF root mesh\n * @param variantName The variant name(s) to select.\n */\n public static SelectVariant(rootMesh: Mesh, variantName: string | string[]): void {\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\n if (!extensionMetadata) {\n throw new Error(`Cannot select variant on a glTF mesh that does not have the ${NAME} extension`);\n }\n\n const select = (variantName: string): void => {\n const entries = extensionMetadata.variants[variantName];\n if (entries) {\n for (const entry of entries) {\n entry.mesh.material = entry.material;\n }\n }\n };\n\n if (variantName instanceof Array) {\n for (const name of variantName) {\n select(name);\n }\n } else {\n select(variantName);\n }\n\n extensionMetadata.lastSelected = variantName;\n }\n\n /**\n * Select a variant given a variant name or a list of variant names.\n * @param rootMesh The glTF root mesh\n * @param variantName The variant name(s) to select.\n */\n public selectVariant(rootMesh: Mesh, variantName: string | string[]): void {\n return KHR_materials_variants.SelectVariant(rootMesh, variantName);\n }\n\n /**\n * Reset back to the original before selecting a variant.\n * @param rootMesh The glTF root mesh\n */\n public static Reset(rootMesh: Mesh): void {\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\n if (!extensionMetadata) {\n throw new Error(`Cannot reset on a glTF mesh that does not have the ${NAME} extension`);\n }\n\n for (const entry of extensionMetadata.original) {\n entry.mesh.material = entry.material;\n }\n\n extensionMetadata.lastSelected = null;\n }\n\n /**\n * Reset back to the original before selecting a variant.\n * @param rootMesh The glTF root mesh\n */\n public reset(rootMesh: Mesh): void {\n return KHR_materials_variants.Reset(rootMesh);\n }\n\n /**\n * Gets the last selected variant name(s) or null if original.\n * @param rootMesh The glTF root mesh\n * @returns The selected variant name(s).\n */\n public static GetLastSelectedVariant(rootMesh: Mesh): Nullable<string | string[]> {\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\n if (!extensionMetadata) {\n throw new Error(`Cannot get the last selected variant on a glTF mesh that does not have the ${NAME} extension`);\n }\n\n return extensionMetadata.lastSelected;\n }\n\n /**\n * Gets the last selected variant name(s) or null if original.\n * @param rootMesh The glTF root mesh\n * @returns The selected variant name(s).\n */\n public getLastSelectedVariant(rootMesh: Mesh): Nullable<string | string[]> {\n return KHR_materials_variants.GetLastSelectedVariant(rootMesh);\n }\n\n private static _GetExtensionMetadata(rootMesh: Nullable<Mesh>): Nullable<IExtensionMetadata> {\n return rootMesh?.metadata?.gltf?.[NAME] || null;\n }\n\n /** @hidden */\n public onLoading(): void {\n const extensions = this._loader.gltf.extensions;\n if (extensions && extensions[this.name]) {\n const extension = extensions[this.name] as IKHRMaterialVariants_Variants;\n this._variants = extension.variants;\n }\n }\n\n /** @hidden */\n public _loadMeshPrimitiveAsync(context: string, name: string, node: INode, mesh: IMesh, primitive: IMeshPrimitive, assign: (babylonMesh: AbstractMesh) => void): Nullable<Promise<AbstractMesh>> {\n return GLTFLoader.LoadExtensionAsync<IKHRMaterialVariants_Mapping, AbstractMesh>(context, primitive, this.name, (extensionContext, extension) => {\n const promises = new Array<Promise<any>>();\n promises.push(this._loader._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, (babylonMesh) => {\n assign(babylonMesh);\n\n if (babylonMesh instanceof Mesh) {\n const babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);\n\n const root = this._loader.rootBabylonMesh;\n const metadata = (root ? root.metadata = root.metadata || {} : {});\n const gltf = (metadata.gltf = metadata.gltf || {});\n const extensionMetadata: IExtensionMetadata = (gltf[NAME] = gltf[NAME] || { lastSelected: null, original: [], variants: {} });\n\n // Store the original material.\n extensionMetadata.original.push({ mesh: babylonMesh, material: babylonMesh.material });\n\n // For each mapping, look at the variants and make a new entry for them.\n for (let mappingIndex = 0; mappingIndex < extension.mappings.length; ++mappingIndex) {\n const mapping = extension.mappings[mappingIndex];\n const material = ArrayItem.Get(`${extensionContext}/mappings/${mappingIndex}/material`, this._loader.gltf.materials, mapping.material);\n promises.push(this._loader._loadMaterialAsync(`#/materials/${mapping.material}`, material, babylonMesh, babylonDrawMode, (babylonMaterial) => {\n for (let mappingVariantIndex = 0; mappingVariantIndex < mapping.variants.length; ++mappingVariantIndex) {\n const variantIndex = mapping.variants[mappingVariantIndex];\n const variant = ArrayItem.Get(`/extensions/${NAME}/variants/${variantIndex}`, this._variants, variantIndex);\n extensionMetadata.variants[variant.name] = extensionMetadata.variants[variant.name] || [];\n extensionMetadata.variants[variant.name].push({\n mesh: babylonMesh,\n material: babylonMaterial\n });\n\n // Replace the target when original mesh is cloned\n babylonMesh.onClonedObservable.add((newOne: Node) => {\n const newMesh = newOne as Mesh;\n let metadata: Nullable<IExtensionMetadata> = null;\n let newRoot: Nullable<Node> = newMesh;\n\n // Find root to get medata\n do {\n newRoot = newRoot!.parent;\n if (!newRoot) {\n return;\n }\n metadata = KHR_materials_variants._GetExtensionMetadata(newRoot as Mesh);\n }\n while (metadata === null);\n\n // Need to clone the metadata on the root (first time only)\n if (root && metadata === KHR_materials_variants._GetExtensionMetadata(root)) {\n // Copy main metadata\n newRoot.metadata = {};\n for (var key in root.metadata) {\n newRoot.metadata[key] = root.metadata[key];\n }\n\n // Copy the gltf metadata\n newRoot.metadata.gltf = [];\n for (var key in root.metadata.gltf) {\n newRoot.metadata.gltf[key] = root.metadata.gltf[key];\n }\n\n // Duplicate the extension specific metadata\n newRoot.metadata.gltf[NAME] = { lastSelected: null, original: [], variants: {} };\n for (var original of metadata.original) {\n newRoot.metadata.gltf[NAME].original.push({\n mesh: original.mesh,\n material: original.material\n });\n }\n for (var key in metadata.variants) {\n if (metadata.variants.hasOwnProperty(key)) {\n newRoot.metadata.gltf[NAME].variants[key] = [];\n for (var variantEntry of metadata.variants[key]) {\n newRoot.metadata.gltf[NAME].variants[key].push({\n mesh: variantEntry.mesh,\n material: variantEntry.material\n });\n }\n }\n }\n\n metadata = newRoot.metadata.gltf[NAME];\n }\n\n // Relocate\n for (var target of metadata!.original) {\n if (target.mesh === babylonMesh) {\n target.mesh = newMesh;\n }\n }\n for (var target of metadata!.variants[variant.name]) {\n if (target.mesh === babylonMesh) {\n target.mesh = newMesh;\n }\n }\n });\n }\n }));\n }\n }\n }));\n return Promise.all(promises).then(([babylonMesh]) => {\n return babylonMesh;\n });\n });\n }\n}\n\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_materials_variants(loader));\n"]}
|
@@ -43,7 +43,7 @@ var KHR_materials_volume = /** @class */ (function () {
|
|
43
43
|
};
|
44
44
|
KHR_materials_volume.prototype._loadVolumePropertiesAsync = function (context, material, babylonMaterial, extension) {
|
45
45
|
if (!(babylonMaterial instanceof PBRMaterial)) {
|
46
|
-
throw new Error(context
|
46
|
+
throw new Error("".concat(context, ": Material type not supported"));
|
47
47
|
}
|
48
48
|
// If transparency isn't enabled already, this extension shouldn't do anything.
|
49
49
|
// i.e. it requires either the KHR_materials_transmission or KHR_materials_translucency extensions.
|
@@ -62,7 +62,7 @@ var KHR_materials_volume = /** @class */ (function () {
|
|
62
62
|
babylonMaterial.subSurface.useThicknessAsDepth = true;
|
63
63
|
if (extension.thicknessTexture) {
|
64
64
|
extension.thicknessTexture.nonColorData = true;
|
65
|
-
return this._loader.loadTextureInfoAsync(context
|
65
|
+
return this._loader.loadTextureInfoAsync("".concat(context, "/thicknessTexture"), extension.thicknessTexture)
|
66
66
|
.then(function (texture) {
|
67
67
|
babylonMaterial.subSurface.thicknessTexture = texture;
|
68
68
|
babylonMaterial.subSurface.useGltfStyleTextures = true;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_materials_volume.js","sourceRoot":"","sources":["../../../../../sourceES6/loaders/src/glTF/2.0/Extensions/KHR_materials_volume.ts"],"names":[],"mappings":"AACA,OAAO,EAA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AgB,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,CAAC,CAAC,CAAC;YACvG,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,cAAQ,CAAC,CAAC,CAAC;QACjD,CAAC,CAAC,CAAC;IACP,CAAC;IAEO,yDAA0B,GAAlC,UAAmC,OAAe,EAAE,QAAmB,EAAE,eAAyB,EAAE,SAAiC;QACjI,IAAI,CAAC,CAAC,eAAe,YAAY,WAAW,CAAC,EAAE;YAC3C,MAAM,IAAI,KAAK,
|
1
|
+
{"version":3,"file":"KHR_materials_volume.js","sourceRoot":"","sources":["../../../../../sourceES6/loaders/src/glTF/2.0/Extensions/KHR_materials_volume.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AAKxE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,IAAM,IAAI,GAAG,sBAAsB,CAAC;AASpC;;;GAGG;AACH;IAkBI,cAAc;IACd,8BAAY,MAAkB;QAlB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAO5B;;WAEG;QACI,UAAK,GAAG,GAAG,CAAC;QAMf,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,IAAI,CAAC,OAAO,EAAE;YACd,qHAAqH;YACrH,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC;SACxC;IACL,CAAC;IAED,cAAc;IACP,sCAAO,GAAd;QACI,IAAI,IAAI,CAAC,OAAO,EAAE;YACd,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC;SACxC;QACA,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED,cAAc;IACP,0DAA2B,GAAlC,UAAmC,OAAe,EAAE,QAAmB,EAAE,eAAyB;QAAlG,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ullable } from \"@babylonjs/core/types\";\nimport { PBRMaterial } from \"@babylonjs/core/Materials/PBR/pbrMaterial\";\nimport { Material } from \"@babylonjs/core/Materials/material\";\nimport { BaseTexture } from \"@babylonjs/core/Materials/Textures/baseTexture\";\nimport { IMaterial, ITextureInfo } from \"../glTFLoaderInterfaces\";\nimport { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\nimport { GLTFLoader } from \"../glTFLoader\";\n\nconst NAME = \"KHR_materials_volume\";\n\ninterface IMaterialsTransmission {\n attenuationColor?: number[];\n attenuationDistance?: number;\n thicknessTexture?: ITextureInfo;\n thicknessFactor?: number;\n}\n\n/**\n * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_volume)\n * @since 5.0.0\n */\nexport class KHR_materials_volume implements IGLTFLoaderExtension {\n /**\n * The name of this extension.\n */\n public readonly name = NAME;\n\n /**\n * Defines whether this extension is enabled.\n */\n public enabled: boolean;\n\n /**\n * Defines a number that determines the order the extensions are applied.\n */\n public order = 173;\n\n private _loader: GLTFLoader;\n\n /** @hidden */\n constructor(loader: GLTFLoader) {\n this._loader = loader;\n this.enabled = this._loader.isExtensionUsed(NAME);\n if (this.enabled) {\n // We need to disable instance usage because the attenuation factor depends on the node scale of each individual mesh\n this._loader._disableInstancedMesh++;\n }\n }\n\n /** @hidden */\n public dispose() {\n if (this.enabled) {\n this._loader._disableInstancedMesh--;\n }\n (this._loader as any) = null;\n }\n\n /** @hidden */\n public loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>> {\n return GLTFLoader.LoadExtensionAsync<IMaterialsTransmission>(context, material, this.name, (extensionContext, extension) => {\n const promises = new Array<Promise<any>>();\n promises.push(this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));\n promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));\n promises.push(this._loadVolumePropertiesAsync(extensionContext, material, babylonMaterial, extension));\n return Promise.all(promises).then(() => { });\n });\n }\n\n private _loadVolumePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material, extension: IMaterialsTransmission): Promise<void> {\n if (!(babylonMaterial instanceof PBRMaterial)) {\n throw new Error(`${context}: Material type not supported`);\n }\n\n // If transparency isn't enabled already, this extension shouldn't do anything.\n // i.e. it requires either the KHR_materials_transmission or KHR_materials_translucency extensions.\n if (!babylonMaterial.subSurface.isRefractionEnabled && !babylonMaterial.subSurface.isTranslucencyEnabled || !extension.thicknessFactor) {\n return Promise.resolve();\n }\n\n // IOR in this extension only affects interior.\n babylonMaterial.subSurface.volumeIndexOfRefraction = babylonMaterial.indexOfRefraction;\n const attenuationDistance = extension.attenuationDistance !== undefined ? extension.attenuationDistance : Number.MAX_VALUE;\n babylonMaterial.subSurface.tintColorAtDistance = attenuationDistance;\n if (extension.attenuationColor !== undefined && extension.attenuationColor.length == 3) {\n babylonMaterial.subSurface.tintColor.copyFromFloats(extension.attenuationColor[0], extension.attenuationColor[1], extension.attenuationColor[2]);\n }\n\n babylonMaterial.subSurface.minimumThickness = 0.0;\n babylonMaterial.subSurface.maximumThickness = extension.thicknessFactor;\n babylonMaterial.subSurface.useThicknessAsDepth = true;\n if (extension.thicknessTexture) {\n (extension.thicknessTexture as ITextureInfo).nonColorData = true;\n return this._loader.loadTextureInfoAsync(`${context}/thicknessTexture`, extension.thicknessTexture)\n .then((texture: BaseTexture) => {\n babylonMaterial.subSurface.thicknessTexture = texture;\n babylonMaterial.subSurface.useGltfStyleTextures = true;\n });\n } else {\n return Promise.resolve();\n }\n }\n}\n\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_materials_volume(loader));"]}
|
@@ -19,8 +19,8 @@ var KHR_texture_basisu = /** @class */ (function () {
|
|
19
19
|
KHR_texture_basisu.prototype._loadTextureAsync = function (context, texture, assign) {
|
20
20
|
var _this = this;
|
21
21
|
return GLTFLoader.LoadExtensionAsync(context, texture, this.name, function (extensionContext, extension) {
|
22
|
-
var sampler = (texture.sampler == undefined ? GLTFLoader.DefaultSampler : ArrayItem.Get(context
|
23
|
-
var image = ArrayItem.Get(extensionContext
|
22
|
+
var sampler = (texture.sampler == undefined ? GLTFLoader.DefaultSampler : ArrayItem.Get("".concat(context, "/sampler"), _this._loader.gltf.samplers, texture.sampler));
|
23
|
+
var image = ArrayItem.Get("".concat(extensionContext, "/source"), _this._loader.gltf.images, extension.source);
|
24
24
|
return _this._loader._createTextureAsync(context, sampler, image, function (babylonTexture) {
|
25
25
|
assign(babylonTexture);
|
26
26
|
}, texture._textureInfo.nonColorData ? { useRGBAIfASTCBC7NotAvailableWhenUASTC: true } : undefined, !texture._textureInfo.nonColorData);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_texture_basisu.js","sourceRoot":"","sources":["../../../../../sourceES6/loaders/src/glTF/2.0/Extensions/KHR_texture_basisu.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAMtD,IAAM,IAAI,GAAG,oBAAoB,CAAC;AAElC;;GAEG;AACH;IASI,cAAc;IACd,4BAAY,MAAkB;QAT9B,kCAAkC;QAClB,SAAI,GAAG,IAAI,CAAC;QASxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IAED,cAAc;IACP,oCAAO,GAAd;QACK,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED,cAAc;IACP,8CAAiB,GAAxB,UAAyB,OAAe,EAAE,OAAiB,EAAE,MAA6C;QAA1G,iBAQC;QAPG,OAAO,UAAU,CAAC,kBAAkB,CAAiC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE,UAAC,gBAAgB,EAAE,SAAS;YAC1H,IAAM,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,SAAS,CAAC,CAAC,CAAC,UAAU,CAA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OAAO,EAAE,KAAK,EAAE,UAAC,cAAc;gBAC5E,MAAM,CAAC,cAAc,CAAC,CAAC;YAC3B,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,qCAAqC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAC5I,CAAC,CAAC,CAAC;IACP,CAAC;IACL,yBAAC;AAAD,CAAC,AA9BD,IA8BC;;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,MAAM,IAAK,OAAA,IAAI,kBAAkB,CAAC,MAAM,CAAC,EAA9B,CAA8B,CAAC,CAAC","sourcesContent":["import { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\nimport { ITexture } from \"../glTFLoaderInterfaces\";\r\nimport { BaseTexture } from \"@babylonjs/core/Materials/Textures/baseTexture\";\r\nimport { Nullable } from \"@babylonjs/core/types\";\r\nimport { IKHRTextureBasisU } from 'babylonjs-gltf2interface';\r\n\r\nconst NAME = \"KHR_texture_basisu\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_basisu)\r\n */\r\nexport class KHR_texture_basisu implements IGLTFLoaderExtension {\r\n /** The name of this extension. */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled. */\r\n public enabled: boolean;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /** @hidden */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @hidden */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /** @hidden */\r\n public _loadTextureAsync(context: string, texture: ITexture, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRTextureBasisU, BaseTexture>(context, texture, this.name, (extensionContext, extension) => {\r\n const sampler = (texture.sampler == undefined ? GLTFLoader.DefaultSampler : ArrayItem.Get(`${context}/sampler`, this._loader.gltf.samplers, texture.sampler));\r\n const image = ArrayItem.Get(`${extensionContext}/source`, this._loader.gltf.images, extension.source);\r\n return this._loader._createTextureAsync(context, sampler, image, (babylonTexture) => {\r\n assign(babylonTexture);\r\n }, texture._textureInfo.nonColorData ? { useRGBAIfASTCBC7NotAvailableWhenUASTC: true } : undefined, !texture._textureInfo.nonColorData);\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_texture_basisu(loader));"]}
|
@@ -24,7 +24,7 @@ var KHR_texture_transform = /** @class */ (function () {
|
|
24
24
|
return GLTFLoader.LoadExtensionAsync(context, textureInfo, this.name, function (extensionContext, extension) {
|
25
25
|
return _this._loader.loadTextureInfoAsync(context, textureInfo, function (babylonTexture) {
|
26
26
|
if (!(babylonTexture instanceof Texture)) {
|
27
|
-
throw new Error(extensionContext
|
27
|
+
throw new Error("".concat(extensionContext, ": Texture type not supported"));
|
28
28
|
}
|
29
29
|
if (extension.offset) {
|
30
30
|
babylonTexture.uOffset = extension.offset[0];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_texture_transform.js","sourceRoot":"","sources":["../../../../../sourceES6/loaders/src/glTF/2.0/Extensions/KHR_texture_transform.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,4CAA4C,CAAC;AAIrE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,IAAM,IAAI,GAAG,uBAAuB,CAAC;AAErC;;GAEG;AACH;IAaI,cAAc;IACd,+BAAY,MAAkB;QAb9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAWxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,cAAc;IACP,uCAAO,GAAd;QACK,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED,cAAc;IACP,oDAAoB,GAA3B,UAA4B,OAAe,EAAE,WAAyB,EAAE,MAA6C;QAArH,iBAgCC;QA/BG,OAAO,UAAU,CAAC,kBAAkB,CAAoC,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,IAAI,EAAE,UAAC,gBAAgB,EAAE,SAAS;YACjI,OAAO,KAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,OAAO,EAAE,WAAW,EAAE,UAAC,cAAc;gBAC1E,IAAI,CAAC,CAAC,cAAc,YAAY,OAAO,CAAC,EAAE;oBACtC,MAAM,IAAI,KAAK,
|
1
|
+
{"version":3,"file":"KHR_texture_transform.js","sourceRoot":"","sources":["../../../../../sourceES6/loaders/src/glTF/2.0/Extensions/KHR_texture_transform.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,4CAA4C,CAAC;AAIrE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,IAAM,IAAI,GAAG,uBAAuB,CAAC;AAErC;;GAEG;AACH;IAaI,cAAc;IACd,+BAAY,MAAkB;QAb9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAWxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,cAAc;IACP,uCAAO,GAAd;QACK,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED,cAAc;IACP,oDAAoB,GAA3B,UAA4B,OAAe,EAAE,WAAyB,EAAE,MAA6C;QAArH,iBAgCC;QA/BG,OAAO,UAAU,CAAC,kBAAkB,CAAoC,OAAO,EAAE,WAAW,EAAE,IAAI,C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sourcesContent":["import { Nullable } from \"@babylonjs/core/types\";\r\nimport { BaseTexture } from \"@babylonjs/core/Materials/Textures/baseTexture\";\r\nimport { Texture } from \"@babylonjs/core/Materials/Textures/texture\";\r\n\r\nimport { ITextureInfo } from \"../glTFLoaderInterfaces\";\r\nimport { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport { IKHRTextureTransform } from 'babylonjs-gltf2interface';\r\n\r\nconst NAME = \"KHR_texture_transform\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform)\r\n */\r\nexport class KHR_texture_transform implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /** @hidden */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @hidden */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /** @hidden */\r\n public loadTextureInfoAsync(context: string, textureInfo: ITextureInfo, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRTextureTransform, BaseTexture>(context, textureInfo, this.name, (extensionContext, extension) => {\r\n return this._loader.loadTextureInfoAsync(context, textureInfo, (babylonTexture) => {\r\n if (!(babylonTexture instanceof Texture)) {\r\n throw new Error(`${extensionContext}: Texture type not supported`);\r\n }\r\n\r\n if (extension.offset) {\r\n babylonTexture.uOffset = extension.offset[0];\r\n babylonTexture.vOffset = extension.offset[1];\r\n }\r\n\r\n // Always rotate around the origin.\r\n babylonTexture.uRotationCenter = 0;\r\n babylonTexture.vRotationCenter = 0;\r\n\r\n if (extension.rotation) {\r\n babylonTexture.wAng = -extension.rotation;\r\n }\r\n\r\n if (extension.scale) {\r\n babylonTexture.uScale = extension.scale[0];\r\n babylonTexture.vScale = extension.scale[1];\r\n }\r\n\r\n if (extension.texCoord != undefined) {\r\n babylonTexture.coordinatesIndex = extension.texCoord;\r\n }\r\n\r\n assign(babylonTexture);\r\n });\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_texture_transform(loader));"]}
|
@@ -43,12 +43,12 @@ var MSFT_audio_emitter = /** @class */ (function () {
|
|
43
43
|
promises.push(_this._loader.loadSceneAsync(context, scene));
|
44
44
|
for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
|
45
45
|
var emitterIndex = _a[_i];
|
46
|
-
var emitter = ArrayItem.Get(extensionContext
|
46
|
+
var emitter = ArrayItem.Get("".concat(extensionContext, "/emitters"), _this._emitters, emitterIndex);
|
47
47
|
if (emitter.refDistance != undefined || emitter.maxDistance != undefined || emitter.rolloffFactor != undefined ||
|
48
48
|
emitter.distanceModel != undefined || emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
|
49
|
-
throw new Error(extensionContext
|
49
|
+
throw new Error("".concat(extensionContext, ": Direction or Distance properties are not allowed on emitters attached to a scene"));
|
50
50
|
}
|
51
|
-
promises.push(_this._loadEmitterAsync(extensionContext
|
51
|
+
promises.push(_this._loadEmitterAsync("".concat(extensionContext, "/emitters/").concat(emitter.index), emitter));
|
52
52
|
}
|
53
53
|
return Promise.all(promises).then(function () { });
|
54
54
|
});
|
@@ -60,8 +60,8 @@ var MSFT_audio_emitter = /** @class */ (function () {
|
|
60
60
|
var promises = new Array();
|
61
61
|
return _this._loader.loadNodeAsync(extensionContext, node, function (babylonMesh) {
|
62
62
|
var _loop_1 = function (emitterIndex) {
|
63
|
-
var emitter = ArrayItem.Get(extensionContext
|
64
|
-
promises.push(_this._loadEmitterAsync(extensionContext
|
63
|
+
var emitter = ArrayItem.Get("".concat(extensionContext, "/emitters"), _this._emitters, emitterIndex);
|
64
|
+
promises.push(_this._loadEmitterAsync("".concat(extensionContext, "/emitters/").concat(emitter.index), emitter).then(function () {
|
65
65
|
for (var _i = 0, _a = emitter._babylonSounds; _i < _a.length; _i++) {
|
66
66
|
var sound = _a[_i];
|
67
67
|
sound.attachToMesh(babylonMesh);
|
@@ -93,7 +93,7 @@ var MSFT_audio_emitter = /** @class */ (function () {
|
|
93
93
|
ArrayItem.Assign(extension.events);
|
94
94
|
for (var _i = 0, _a = extension.events; _i < _a.length; _i++) {
|
95
95
|
var event_1 = _a[_i];
|
96
|
-
promises.push(_this._loadAnimationEventAsync(extensionContext
|
96
|
+
promises.push(_this._loadAnimationEventAsync("".concat(extensionContext, "/events/").concat(event_1.index), context, animation, event_1, babylonAnimationGroup));
|
97
97
|
}
|
98
98
|
return Promise.all(promises).then(function () {
|
99
99
|
return babylonAnimationGroup;
|
@@ -110,8 +110,8 @@ var MSFT_audio_emitter = /** @class */ (function () {
|
|
110
110
|
promise = this._loader.loadUriAsync(context, clip, clip.uri);
|
111
111
|
}
|
112
112
|
else {
|
113
|
-
var bufferView = ArrayItem.Get(context
|
114
|
-
promise = this._loader.loadBufferViewAsync("/bufferViews/"
|
113
|
+
var bufferView = ArrayItem.Get("".concat(context, "/bufferView"), this._loader.gltf.bufferViews, clip.bufferView);
|
114
|
+
promise = this._loader.loadBufferViewAsync("/bufferViews/".concat(bufferView.index), bufferView);
|
115
115
|
}
|
116
116
|
clip._objectURL = promise.then(function (data) {
|
117
117
|
return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));
|
@@ -123,16 +123,16 @@ var MSFT_audio_emitter = /** @class */ (function () {
|
|
123
123
|
emitter._babylonSounds = emitter._babylonSounds || [];
|
124
124
|
if (!emitter._babylonData) {
|
125
125
|
var clipPromises = new Array();
|
126
|
-
var name_1 = emitter.name || "emitter"
|
126
|
+
var name_1 = emitter.name || "emitter".concat(emitter.index);
|
127
127
|
var options_1 = {
|
128
128
|
loop: false,
|
129
129
|
autoplay: false,
|
130
130
|
volume: emitter.volume == undefined ? 1 : emitter.volume,
|
131
131
|
};
|
132
132
|
var _loop_2 = function (i) {
|
133
|
-
var clipContext = "/extensions/"
|
133
|
+
var clipContext = "/extensions/".concat(this_1.name, "/clips");
|
134
134
|
var clip = ArrayItem.Get(clipContext, this_1._clips, emitter.clips[i].clip);
|
135
|
-
clipPromises.push(this_1._loadClipAsync(clipContext
|
135
|
+
clipPromises.push(this_1._loadClipAsync("".concat(clipContext, "/").concat(emitter.clips[i].clip), clip).then(function (objectURL) {
|
136
136
|
var sound = emitter._babylonSounds[i] = new Sound(name_1, objectURL, _this._loader.babylonScene, null, options_1);
|
137
137
|
sound.refDistance = emitter.refDistance || 1;
|
138
138
|
sound.maxDistance = emitter.maxDistance || 256;
|
@@ -183,7 +183,7 @@ var MSFT_audio_emitter = /** @class */ (function () {
|
|
183
183
|
};
|
184
184
|
}
|
185
185
|
default: {
|
186
|
-
throw new Error(context
|
186
|
+
throw new Error("".concat(context, ": Unsupported action ").concat(action));
|
187
187
|
}
|
188
188
|
}
|
189
189
|
};
|
@@ -194,7 +194,7 @@ var MSFT_audio_emitter = /** @class */ (function () {
|
|
194
194
|
}
|
195
195
|
var babylonAnimation = babylonAnimationGroup.targetedAnimations[0];
|
196
196
|
var emitterIndex = event.emitter;
|
197
|
-
var emitter = ArrayItem.Get("/extensions/"
|
197
|
+
var emitter = ArrayItem.Get("/extensions/".concat(this.name, "/emitters"), this._emitters, emitterIndex);
|
198
198
|
return this._loadEmitterAsync(context, emitter).then(function () {
|
199
199
|
var sound = emitter._babylonData.sound;
|
200
200
|
if (sound) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"MSFT_audio_emitter.js","sourceRoot":"","sources":["../../../../../sourceES6/loaders/src/glTF/2.0/Extensions/MSFT_audio_emitter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAEnD,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tD,KAAK,CAAC,KAAK,EAAE,CAAC;gBAClB,CAAC,CAAC,CAAC;aACN;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IACL,yBAAC;AAAD,CAAC,AA3ND,IA2NC;;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,MAAM,IAAK,OAAA,IAAI,kBAAkB,CAAC,MAAM,CAAC,EAA9B,CAA8B,CAAC,CAAC","sourcesContent":["import { Nullable } from \"@babylonjs/core/types\";\nimport { Vector3 } from \"@babylonjs/core/Maths/math.vector\";\nimport { Tools } from \"@babylonjs/core/Misc/tools\";\nimport { AnimationGroup } from \"@babylonjs/core/Animations/animationGroup\";\nimport { AnimationEvent } from \"@babylonjs/core/Animations/animationEvent\";\nimport { TransformNode } from \"@babylonjs/core/Meshes/transformNode\";\nimport { Sound } from \"@babylonjs/core/Audio/sound\";\nimport { WeightedSound } from \"@babylonjs/core/Audio/weightedsound\";\n\nimport { IArrayItem, IScene, INode, IAnimation } from \"../glTFLoaderInterfaces\";\nimport { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\nimport { IMSFTAudioEmitter_Clip, IMSFTAudioEmitter_Emitter, IMSFTAudioEmitter_EmittersReference, IMSFTAudioEmitter_AnimationEvent, IMSFTAudioEmitter_AnimationEventAction } from 'babylonjs-gltf2interface';\n\nconst NAME = \"MSFT_audio_emitter\";\n\ninterface ILoaderClip extends IMSFTAudioEmitter_Clip, IArrayItem {\n _objectURL?: Promise<string>;\n}\n\ninterface ILoaderEmitter extends IMSFTAudioEmitter_Emitter, IArrayItem {\n _babylonData?: {\n sound?: WeightedSound;\n loaded: Promise<void>;\n };\n _babylonSounds: Sound[];\n}\n\ninterface IMSFTAudioEmitter {\n clips: ILoaderClip[];\n emitters: ILoaderEmitter[];\n}\n\ninterface ILoaderAnimationEvent extends IMSFTAudioEmitter_AnimationEvent, IArrayItem {\n}\n\ninterface ILoaderAnimationEvents {\n events: ILoaderAnimationEvent[];\n}\n\n/**\n * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)\n */\nexport class MSFT_audio_emitter implements IGLTFLoaderExtension {\n /**\n * The name of this extension.\n */\n public readonly name = NAME;\n\n /**\n * Defines whether this extension is enabled.\n */\n public enabled: boolean;\n\n private _loader: GLTFLoader;\n private _clips: Array<ILoaderClip>;\n private _emitters: Array<ILoaderEmitter>;\n\n /** @hidden */\n constructor(loader: GLTFLoader) {\n this._loader = loader;\n this.enabled = this._loader.isExtensionUsed(NAME);\n }\n\n /** @hidden */\n public dispose() {\n (this._loader as any) = null;\n (this._clips as any) = null;\n (this._emitters as any) = null;\n }\n\n /** @hidden */\n public onLoading(): void {\n const extensions = this._loader.gltf.extensions;\n if (extensions && extensions[this.name]) {\n const extension = extensions[this.name] as IMSFTAudioEmitter;\n\n this._clips = extension.clips;\n this._emitters = extension.emitters;\n\n ArrayItem.Assign(this._clips);\n ArrayItem.Assign(this._emitters);\n }\n }\n\n /** @hidden */\n public loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {\n return GLTFLoader.LoadExtensionAsync<IMSFTAudioEmitter_EmittersReference>(context, scene, this.name, (extensionContext, extension) => {\n const promises = new Array<Promise<any>>();\n\n promises.push(this._loader.loadSceneAsync(context, scene));\n\n for (const emitterIndex of extension.emitters) {\n const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);\n if (emitter.refDistance != undefined || emitter.maxDistance != undefined || emitter.rolloffFactor != undefined ||\n emitter.distanceModel != undefined || emitter.innerAngle != undefined || emitter.outerAngle != undefined) {\n throw new Error(`${extensionContext}: Direction or Distance properties are not allowed on emitters attached to a scene`);\n }\n\n promises.push(this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter));\n }\n\n return Promise.all(promises).then(() => { });\n });\n }\n\n /** @hidden */\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\n return GLTFLoader.LoadExtensionAsync<IMSFTAudioEmitter_EmittersReference, TransformNode>(context, node, this.name, (extensionContext, extension) => {\n const promises = new Array<Promise<any>>();\n\n return this._loader.loadNodeAsync(extensionContext, node, (babylonMesh) => {\n for (const emitterIndex of extension.emitters) {\n const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);\n promises.push(this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter).then(() => {\n for (const sound of emitter._babylonSounds) {\n sound.attachToMesh(babylonMesh);\n if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {\n sound.setLocalDirectionToMesh(Vector3.Forward());\n sound.setDirectionalCone(\n 2 * Tools.ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle),\n 2 * Tools.ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle),\n 0);\n }\n }\n }));\n }\n\n assign(babylonMesh);\n }).then((babylonMesh) => {\n return Promise.all(promises).then(() => {\n return babylonMesh;\n });\n });\n });\n }\n\n /** @hidden */\n public loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>> {\n return GLTFLoader.LoadExtensionAsync<ILoaderAnimationEvents, AnimationGroup>(context, animation, this.name, (extensionContext, extension) => {\n return this._loader.loadAnimationAsync(context, animation).then((babylonAnimationGroup) => {\n const promises = new Array<Promise<any>>();\n\n ArrayItem.Assign(extension.events);\n for (const event of extension.events) {\n promises.push(this._loadAnimationEventAsync(`${extensionContext}/events/${event.index}`, context, animation, event, babylonAnimationGroup));\n }\n\n return Promise.all(promises).then(() => {\n return babylonAnimationGroup;\n });\n });\n });\n }\n\n private _loadClipAsync(context: string, clip: ILoaderClip): Promise<string> {\n if (clip._objectURL) {\n return clip._objectURL;\n }\n\n let promise: Promise<ArrayBufferView>;\n if (clip.uri) {\n promise = this._loader.loadUriAsync(context, clip, clip.uri);\n }\n else {\n const bufferView = ArrayItem.Get(`${context}/bufferView`, this._loader.gltf.bufferViews, clip.bufferView);\n promise = this._loader.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView);\n }\n\n clip._objectURL = promise.then((data) => {\n return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));\n });\n\n return clip._objectURL;\n }\n\n private _loadEmitterAsync(context: string, emitter: ILoaderEmitter): Promise<void> {\n emitter._babylonSounds = emitter._babylonSounds || [];\n if (!emitter._babylonData) {\n const clipPromises = new Array<Promise<any>>();\n const name = emitter.name || `emitter${emitter.index}`;\n const options = {\n loop: false,\n autoplay: false,\n volume: emitter.volume == undefined ? 1 : emitter.volume,\n };\n\n for (let i = 0; i < emitter.clips.length; i++) {\n const clipContext = `/extensions/${this.name}/clips`;\n const clip = ArrayItem.Get(clipContext, this._clips, emitter.clips[i].clip);\n clipPromises.push(this._loadClipAsync(`${clipContext}/${emitter.clips[i].clip}`, clip).then((objectURL: string) => {\n const sound = emitter._babylonSounds[i] = new Sound(name, objectURL, this._loader.babylonScene, null, options);\n sound.refDistance = emitter.refDistance || 1;\n sound.maxDistance = emitter.maxDistance || 256;\n sound.rolloffFactor = emitter.rolloffFactor || 1;\n sound.distanceModel = emitter.distanceModel || 'exponential';\n }));\n }\n\n const promise = Promise.all(clipPromises).then(() => {\n const weights = emitter.clips.map((clip) => { return clip.weight || 1; });\n const weightedSound = new WeightedSound(emitter.loop || false, emitter._babylonSounds, weights);\n if (emitter.innerAngle) { weightedSound.directionalConeInnerAngle = 2 * Tools.ToDegrees(emitter.innerAngle); }\n if (emitter.outerAngle) { weightedSound.directionalConeOuterAngle = 2 * Tools.ToDegrees(emitter.outerAngle); }\n if (emitter.volume) { weightedSound.volume = emitter.volume; }\n emitter._babylonData!.sound = weightedSound;\n });\n\n emitter._babylonData = {\n loaded: promise\n };\n }\n\n return emitter._babylonData.loaded;\n }\n\n private _getEventAction(context: string, sound: WeightedSound, action: IMSFTAudioEmitter_AnimationEventAction, time: number, startOffset?: number): (currentFrame: number) => void {\n switch (action) {\n case IMSFTAudioEmitter_AnimationEventAction.play: {\n return (currentFrame: number) => {\n const frameOffset = (startOffset || 0) + (currentFrame - time);\n sound.play(frameOffset);\n };\n }\n case IMSFTAudioEmitter_AnimationEventAction.stop: {\n return (currentFrame: number) => {\n sound.stop();\n };\n }\n case IMSFTAudioEmitter_AnimationEventAction.pause: {\n return (currentFrame: number) => {\n sound.pause();\n };\n }\n default: {\n throw new Error(`${context}: Unsupported action ${action}`);\n }\n }\n }\n\n private _loadAnimationEventAsync(context: string, animationContext: string, animation: IAnimation, event: ILoaderAnimationEvent, babylonAnimationGroup: AnimationGroup): Promise<void> {\n if (babylonAnimationGroup.targetedAnimations.length == 0) {\n return Promise.resolve();\n }\n const babylonAnimation = babylonAnimationGroup.targetedAnimations[0];\n const emitterIndex = event.emitter;\n const emitter = ArrayItem.Get(`/extensions/${this.name}/emitters`, this._emitters, emitterIndex);\n return this._loadEmitterAsync(context, emitter).then(() => {\n const sound = emitter._babylonData!.sound;\n if (sound) {\n var babylonAnimationEvent = new AnimationEvent(event.time, this._getEventAction(context, sound, event.action, event.time, event.startOffset));\n babylonAnimation.animation.addEvent(babylonAnimationEvent);\n // Make sure all started audio stops when this animation is terminated.\n babylonAnimationGroup.onAnimationGroupEndObservable.add(() => {\n sound.stop();\n });\n babylonAnimationGroup.onAnimationGroupPauseObservable.add(() => {\n sound.pause();\n });\n }\n });\n }\n}\n\nGLTFLoader.RegisterExtension(NAME, (loader) => new MSFT_audio_emitter(loader));"]}
|
1
|
+
{"version":3,"file":"MSFT_audio_emitter.js","sourceRoot":"","sources":["../../../../../sourceES6/loaders/src/glTF/2.0/Extensions/MSFT_audio_emitter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAEnD,OAAO,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAE3E,OAAO,EAAE,KAAK,EAAE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CAAC,GAAG,CAAC;oBACtD,KAAK,CAAC,KAAK,EAAE,CAAC;gBAClB,CAAC,CAAC,CAAC;aACN;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IACL,yBAAC;AAAD,CAAC,AA3ND,IA2NC;;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,MAAM,IAAK,OAAA,IAAI,kBAAkB,CAAC,MAAM,CAAC,EAA9B,CAA8B,CAAC,CAAC","sourcesContent":["import { Nullable } from \"@babylonjs/core/types\";\nimport { Vector3 } from \"@babylonjs/core/Maths/math.vector\";\nimport { Tools } from \"@babylonjs/core/Misc/tools\";\nimport { AnimationGroup } from \"@babylonjs/core/Animations/animationGroup\";\nimport { AnimationEvent } from \"@babylonjs/core/Animations/animationEvent\";\nimport { TransformNode } from \"@babylonjs/core/Meshes/transformNode\";\nimport { Sound } from \"@babylonjs/core/Audio/sound\";\nimport { WeightedSound } from \"@babylonjs/core/Audio/weightedsound\";\n\nimport { IArrayItem, IScene, INode, IAnimation } from \"../glTFLoaderInterfaces\";\nimport { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\nimport { IMSFTAudioEmitter_Clip, IMSFTAudioEmitter_Emitter, IMSFTAudioEmitter_EmittersReference, IMSFTAudioEmitter_AnimationEvent, IMSFTAudioEmitter_AnimationEventAction } from 'babylonjs-gltf2interface';\n\nconst NAME = \"MSFT_audio_emitter\";\n\ninterface ILoaderClip extends IMSFTAudioEmitter_Clip, IArrayItem {\n _objectURL?: Promise<string>;\n}\n\ninterface ILoaderEmitter extends IMSFTAudioEmitter_Emitter, IArrayItem {\n _babylonData?: {\n sound?: WeightedSound;\n loaded: Promise<void>;\n };\n _babylonSounds: Sound[];\n}\n\ninterface IMSFTAudioEmitter {\n clips: ILoaderClip[];\n emitters: ILoaderEmitter[];\n}\n\ninterface ILoaderAnimationEvent extends IMSFTAudioEmitter_AnimationEvent, IArrayItem {\n}\n\ninterface ILoaderAnimationEvents {\n events: ILoaderAnimationEvent[];\n}\n\n/**\n * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)\n */\nexport class MSFT_audio_emitter implements IGLTFLoaderExtension {\n /**\n * The name of this extension.\n */\n public readonly name = NAME;\n\n /**\n * Defines whether this extension is enabled.\n */\n public enabled: boolean;\n\n private _loader: GLTFLoader;\n private _clips: Array<ILoaderClip>;\n private _emitters: Array<ILoaderEmitter>;\n\n /** @hidden */\n constructor(loader: GLTFLoader) {\n this._loader = loader;\n this.enabled = this._loader.isExtensionUsed(NAME);\n }\n\n /** @hidden */\n public dispose() {\n (this._loader as any) = null;\n (this._clips as any) = null;\n (this._emitters as any) = null;\n }\n\n /** @hidden */\n public onLoading(): void {\n const extensions = this._loader.gltf.extensions;\n if (extensions && extensions[this.name]) {\n const extension = extensions[this.name] as IMSFTAudioEmitter;\n\n this._clips = extension.clips;\n this._emitters = extension.emitters;\n\n ArrayItem.Assign(this._clips);\n ArrayItem.Assign(this._emitters);\n }\n }\n\n /** @hidden */\n public loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {\n return GLTFLoader.LoadExtensionAsync<IMSFTAudioEmitter_EmittersReference>(context, scene, this.name, (extensionContext, extension) => {\n const promises = new Array<Promise<any>>();\n\n promises.push(this._loader.loadSceneAsync(context, scene));\n\n for (const emitterIndex of extension.emitters) {\n const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);\n if (emitter.refDistance != undefined || emitter.maxDistance != undefined || emitter.rolloffFactor != undefined ||\n emitter.distanceModel != undefined || emitter.innerAngle != undefined || emitter.outerAngle != undefined) {\n throw new Error(`${extensionContext}: Direction or Distance properties are not allowed on emitters attached to a scene`);\n }\n\n promises.push(this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter));\n }\n\n return Promise.all(promises).then(() => { });\n });\n }\n\n /** @hidden */\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\n return GLTFLoader.LoadExtensionAsync<IMSFTAudioEmitter_EmittersReference, TransformNode>(context, node, this.name, (extensionContext, extension) => {\n const promises = new Array<Promise<any>>();\n\n return this._loader.loadNodeAsync(extensionContext, node, (babylonMesh) => {\n for (const emitterIndex of extension.emitters) {\n const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);\n promises.push(this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter).then(() => {\n for (const sound of emitter._babylonSounds) {\n sound.attachToMesh(babylonMesh);\n if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {\n sound.setLocalDirectionToMesh(Vector3.Forward());\n sound.setDirectionalCone(\n 2 * Tools.ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle),\n 2 * Tools.ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle),\n 0);\n }\n }\n }));\n }\n\n assign(babylonMesh);\n }).then((babylonMesh) => {\n return Promise.all(promises).then(() => {\n return babylonMesh;\n });\n });\n });\n }\n\n /** @hidden */\n public loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>> {\n return GLTFLoader.LoadExtensionAsync<ILoaderAnimationEvents, AnimationGroup>(context, animation, this.name, (extensionContext, extension) => {\n return this._loader.loadAnimationAsync(context, animation).then((babylonAnimationGroup) => {\n const promises = new Array<Promise<any>>();\n\n ArrayItem.Assign(extension.events);\n for (const event of extension.events) {\n promises.push(this._loadAnimationEventAsync(`${extensionContext}/events/${event.index}`, context, animation, event, babylonAnimationGroup));\n }\n\n return Promise.all(promises).then(() => {\n return babylonAnimationGroup;\n });\n });\n });\n }\n\n private _loadClipAsync(context: string, clip: ILoaderClip): Promise<string> {\n if (clip._objectURL) {\n return clip._objectURL;\n }\n\n let promise: Promise<ArrayBufferView>;\n if (clip.uri) {\n promise = this._loader.loadUriAsync(context, clip, clip.uri);\n }\n else {\n const bufferView = ArrayItem.Get(`${context}/bufferView`, this._loader.gltf.bufferViews, clip.bufferView);\n promise = this._loader.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView);\n }\n\n clip._objectURL = promise.then((data) => {\n return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));\n });\n\n return clip._objectURL;\n }\n\n private _loadEmitterAsync(context: string, emitter: ILoaderEmitter): Promise<void> {\n emitter._babylonSounds = emitter._babylonSounds || [];\n if (!emitter._babylonData) {\n const clipPromises = new Array<Promise<any>>();\n const name = emitter.name || `emitter${emitter.index}`;\n const options = {\n loop: false,\n autoplay: false,\n volume: emitter.volume == undefined ? 1 : emitter.volume,\n };\n\n for (let i = 0; i < emitter.clips.length; i++) {\n const clipContext = `/extensions/${this.name}/clips`;\n const clip = ArrayItem.Get(clipContext, this._clips, emitter.clips[i].clip);\n clipPromises.push(this._loadClipAsync(`${clipContext}/${emitter.clips[i].clip}`, clip).then((objectURL: string) => {\n const sound = emitter._babylonSounds[i] = new Sound(name, objectURL, this._loader.babylonScene, null, options);\n sound.refDistance = emitter.refDistance || 1;\n sound.maxDistance = emitter.maxDistance || 256;\n sound.rolloffFactor = emitter.rolloffFactor || 1;\n sound.distanceModel = emitter.distanceModel || 'exponential';\n }));\n }\n\n const promise = Promise.all(clipPromises).then(() => {\n const weights = emitter.clips.map((clip) => { return clip.weight || 1; });\n const weightedSound = new WeightedSound(emitter.loop || false, emitter._babylonSounds, weights);\n if (emitter.innerAngle) { weightedSound.directionalConeInnerAngle = 2 * Tools.ToDegrees(emitter.innerAngle); }\n if (emitter.outerAngle) { weightedSound.directionalConeOuterAngle = 2 * Tools.ToDegrees(emitter.outerAngle); }\n if (emitter.volume) { weightedSound.volume = emitter.volume; }\n emitter._babylonData!.sound = weightedSound;\n });\n\n emitter._babylonData = {\n loaded: promise\n };\n }\n\n return emitter._babylonData.loaded;\n }\n\n private _getEventAction(context: string, sound: WeightedSound, action: IMSFTAudioEmitter_AnimationEventAction, time: number, startOffset?: number): (currentFrame: number) => void {\n switch (action) {\n case IMSFTAudioEmitter_AnimationEventAction.play: {\n return (currentFrame: number) => {\n const frameOffset = (startOffset || 0) + (currentFrame - time);\n sound.play(frameOffset);\n };\n }\n case IMSFTAudioEmitter_AnimationEventAction.stop: {\n return (currentFrame: number) => {\n sound.stop();\n };\n }\n case IMSFTAudioEmitter_AnimationEventAction.pause: {\n return (currentFrame: number) => {\n sound.pause();\n };\n }\n default: {\n throw new Error(`${context}: Unsupported action ${action}`);\n }\n }\n }\n\n private _loadAnimationEventAsync(context: string, animationContext: string, animation: IAnimation, event: ILoaderAnimationEvent, babylonAnimationGroup: AnimationGroup): Promise<void> {\n if (babylonAnimationGroup.targetedAnimations.length == 0) {\n return Promise.resolve();\n }\n const babylonAnimation = babylonAnimationGroup.targetedAnimations[0];\n const emitterIndex = event.emitter;\n const emitter = ArrayItem.Get(`/extensions/${this.name}/emitters`, this._emitters, emitterIndex);\n return this._loadEmitterAsync(context, emitter).then(() => {\n const sound = emitter._babylonData!.sound;\n if (sound) {\n var babylonAnimationEvent = new AnimationEvent(event.time, this._getEventAction(context, sound, event.action, event.time, event.startOffset));\n babylonAnimation.animation.addEvent(babylonAnimationEvent);\n // Make sure all started audio stops when this animation is terminated.\n babylonAnimationGroup.onAnimationGroupEndObservable.add(() => {\n sound.stop();\n });\n babylonAnimationGroup.onAnimationGroupPauseObservable.add(() => {\n sound.pause();\n });\n }\n });\n }\n}\n\nGLTFLoader.RegisterExtension(NAME, (loader) => new MSFT_audio_emitter(loader));"]}
|
@@ -65,7 +65,6 @@ export declare class MSFT_lod implements IGLTFLoaderExtension {
|
|
65
65
|
_loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>>;
|
66
66
|
/** @hidden */
|
67
67
|
loadBufferAsync(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>>;
|
68
|
-
private _isMesh;
|
69
68
|
private _loadBufferLOD;
|
70
69
|
/**
|
71
70
|
* Gets an array of LOD properties from lowest to highest.
|