@babylonjs/loaders 6.10.0 → 6.11.0
Sign up to get free protection for your applications and to get access to all the features.
- package/OBJ/index.js.map +1 -1
- package/OBJ/mtlFileLoader.js.map +1 -1
- package/OBJ/objFileLoader.js.map +1 -1
- package/OBJ/objLoadingOptions.js.map +1 -1
- package/OBJ/solidParser.js.map +1 -1
- package/STL/index.js.map +1 -1
- package/STL/stlFileLoader.js.map +1 -1
- package/glTF/1.0/glTFBinaryExtension.js.map +1 -1
- package/glTF/1.0/glTFLoader.js.map +1 -1
- package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/1.0/glTFLoaderUtils.js.map +1 -1
- package/glTF/1.0/glTFMaterialsCommonExtension.js.map +1 -1
- package/glTF/1.0/index.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_animation_pointer.data.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_animation_pointer.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_anisotropy.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
- package/glTF/2.0/Extensions/index.js.map +1 -1
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/2.0/glTFLoaderAnimation.js.map +1 -1
- package/glTF/2.0/glTFLoaderExtension.js.map +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/2.0/index.js.map +1 -1
- package/glTF/glTFFileLoader.js.map +1 -1
- package/glTF/glTFValidation.js.map +1 -1
- package/glTF/index.js.map +1 -1
- package/index.js.map +1 -1
- package/legacy/legacy-glTF.d.ts +2 -2
- package/legacy/legacy-glTF.js.map +1 -1
- package/legacy/legacy-glTF1.d.ts +1 -1
- package/legacy/legacy-glTF1.js.map +1 -1
- package/legacy/legacy-glTF1FileLoader.js.map +1 -1
- package/legacy/legacy-glTF2.d.ts +1 -1
- package/legacy/legacy-glTF2.js.map +1 -1
- package/legacy/legacy-glTF2FileLoader.js.map +1 -1
- package/legacy/legacy-glTFFileLoader.js.map +1 -1
- package/legacy/legacy-objFileLoader.d.ts +1 -1
- package/legacy/legacy-objFileLoader.js.map +1 -1
- package/legacy/legacy-stlFileLoader.d.ts +1 -1
- package/legacy/legacy-stlFileLoader.js.map +1 -1
- package/legacy/legacy.d.ts +1 -1
- package/legacy/legacy.js.map +1 -1
- package/package.json +5 -5
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_materials_variants.js","sourceRoot":"","sources":["../../../../../../lts/loaders/generated/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,uCAAyB;AAMxC,MAAM,IAAI,GAAG,wBAAwB,CAAC;AAYtC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,sBAAsB;IAe/B;;OAEG;IACH,YAAY,MAAkB;QAjB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAexB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,gBAAgB;IACT,OAAO;QACT,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,oBAAoB,CAAC,QAAc;QAC7C,MAAM,iBAAiB,GAAG,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;QAC/D,IAAI,CAAC,iBAAiB,EAAE;YACpB,OAAO,EAAE,CAAC;SACb;QAED,OAAO,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IACnD,CAAC;IAED;;;;OAIG;IACI,oBAAoB,CAAC,QAAc;QACtC,OAAO,sBAAsB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IACjE,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,aAAa,CAAC,QAAc,EAAE,WAA8B;QACtE,MAAM,iBAAiB,GAAG,IAAI,CAAC,qBAAqB,C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EAAE,CAAC,IAAI,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\n\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\nimport type { Node } from \"core/node\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport type { INode, IMeshPrimitive, IMesh } from \"../glTFLoaderInterfaces\";\r\nimport type { IKHRMaterialVariants_Mapping, IKHRMaterialVariants_Variant, IKHRMaterialVariants_Variants } from \"babylonjs-gltf2interface\";\r\n\r\nconst NAME = \"KHR_materials_variants\";\r\n\r\ninterface IVariantsMap {\r\n [key: string]: Array<{ mesh: AbstractMesh; material: Nullable<Material> }>;\r\n}\r\n\r\ninterface IExtensionMetadata {\r\n lastSelected: Nullable<string | Array<string>>;\r\n original: Array<{ mesh: AbstractMesh; material: Nullable<Material> }>;\r\n variants: IVariantsMap;\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_variants/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_variants 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 private _variants?: Array<IKHRMaterialVariants_Variant>;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * Gets the list of available variant names for this asset.\r\n * @param rootMesh The glTF root mesh\r\n * @returns the list of all the variant names for this model\r\n */\r\n public static GetAvailableVariants(rootMesh: Mesh): string[] {\r\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\r\n if (!extensionMetadata) {\r\n return [];\r\n }\r\n\r\n return Object.keys(extensionMetadata.variants);\r\n }\r\n\r\n /**\r\n * Gets the list of available variant names for this asset.\r\n * @param rootMesh The glTF root mesh\r\n * @returns the list of all the variant names for this model\r\n */\r\n public getAvailableVariants(rootMesh: Mesh): string[] {\r\n return KHR_materials_variants.GetAvailableVariants(rootMesh);\r\n }\r\n\r\n /**\r\n * Select a variant given a variant name or a list of variant names.\r\n * @param rootMesh The glTF root mesh\r\n * @param variantName The variant name(s) to select.\r\n */\r\n public static SelectVariant(rootMesh: Mesh, variantName: string | string[]): void {\r\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\r\n if (!extensionMetadata) {\r\n throw new Error(`Cannot select variant on a glTF mesh that does not have the ${NAME} extension`);\r\n }\r\n\r\n const select = (variantName: string): void => {\r\n const entries = extensionMetadata.variants[variantName];\r\n if (entries) {\r\n for (const entry of entries) {\r\n entry.mesh.material = entry.material;\r\n }\r\n }\r\n };\r\n\r\n if (variantName instanceof Array) {\r\n for (const name of variantName) {\r\n select(name);\r\n }\r\n } else {\r\n select(variantName);\r\n }\r\n\r\n extensionMetadata.lastSelected = variantName;\r\n }\r\n\r\n /**\r\n * Select a variant given a variant name or a list of variant names.\r\n * @param rootMesh The glTF root mesh\r\n * @param variantName The variant name(s) to select.\r\n */\r\n public selectVariant(rootMesh: Mesh, variantName: string | string[]): void {\r\n return KHR_materials_variants.SelectVariant(rootMesh, variantName);\r\n }\r\n\r\n /**\r\n * Reset back to the original before selecting a variant.\r\n * @param rootMesh The glTF root mesh\r\n */\r\n public static Reset(rootMesh: Mesh): void {\r\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\r\n if (!extensionMetadata) {\r\n throw new Error(`Cannot reset on a glTF mesh that does not have the ${NAME} extension`);\r\n }\r\n\r\n for (const entry of extensionMetadata.original) {\r\n entry.mesh.material = entry.material;\r\n }\r\n\r\n extensionMetadata.lastSelected = null;\r\n }\r\n\r\n /**\r\n * Reset back to the original before selecting a variant.\r\n * @param rootMesh The glTF root mesh\r\n */\r\n public reset(rootMesh: Mesh): void {\r\n return KHR_materials_variants.Reset(rootMesh);\r\n }\r\n\r\n /**\r\n * Gets the last selected variant name(s) or null if original.\r\n * @param rootMesh The glTF root mesh\r\n * @returns The selected variant name(s).\r\n */\r\n public static GetLastSelectedVariant(rootMesh: Mesh): Nullable<string | string[]> {\r\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\r\n if (!extensionMetadata) {\r\n throw new Error(`Cannot get the last selected variant on a glTF mesh that does not have the ${NAME} extension`);\r\n }\r\n\r\n return extensionMetadata.lastSelected;\r\n }\r\n\r\n /**\r\n * Gets the last selected variant name(s) or null if original.\r\n * @param rootMesh The glTF root mesh\r\n * @returns The selected variant name(s).\r\n */\r\n public getLastSelectedVariant(rootMesh: Mesh): Nullable<string | string[]> {\r\n return KHR_materials_variants.GetLastSelectedVariant(rootMesh);\r\n }\r\n\r\n private static _GetExtensionMetadata(rootMesh: Nullable<Mesh>): Nullable<IExtensionMetadata> {\r\n return rootMesh?._internalMetadata?.gltf?.[NAME] || null;\r\n }\r\n\r\n /** @internal */\r\n public onLoading(): void {\r\n const extensions = this._loader.gltf.extensions;\r\n if (extensions && extensions[this.name]) {\r\n const extension = extensions[this.name] as IKHRMaterialVariants_Variants;\r\n this._variants = extension.variants;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _loadMeshPrimitiveAsync(\r\n context: string,\r\n name: string,\r\n node: INode,\r\n mesh: IMesh,\r\n primitive: IMeshPrimitive,\r\n assign: (babylonMesh: AbstractMesh) => void\r\n ): Nullable<Promise<AbstractMesh>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRMaterialVariants_Mapping, AbstractMesh>(context, primitive, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n promises.push(\r\n this._loader._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, (babylonMesh) => {\r\n assign(babylonMesh);\r\n\r\n if (babylonMesh instanceof Mesh) {\r\n const babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);\r\n\r\n const root = this._loader.rootBabylonMesh;\r\n const metadata = root ? (root._internalMetadata = root._internalMetadata || {}) : {};\r\n const gltf = (metadata.gltf = metadata.gltf || {});\r\n const extensionMetadata: IExtensionMetadata = (gltf[NAME] = gltf[NAME] || { lastSelected: null, original: [], variants: {} });\r\n\r\n // Store the original material.\r\n extensionMetadata.original.push({ mesh: babylonMesh, material: babylonMesh.material });\r\n\r\n // For each mapping, look at the variants and make a new entry for them.\r\n for (let mappingIndex = 0; mappingIndex < extension.mappings.length; ++mappingIndex) {\r\n const mapping = extension.mappings[mappingIndex];\r\n const material = ArrayItem.Get(`${extensionContext}/mappings/${mappingIndex}/material`, this._loader.gltf.materials, mapping.material);\r\n promises.push(\r\n this._loader._loadMaterialAsync(`#/materials/${mapping.material}`, material, babylonMesh, babylonDrawMode, (babylonMaterial) => {\r\n for (let mappingVariantIndex = 0; mappingVariantIndex < mapping.variants.length; ++mappingVariantIndex) {\r\n const variantIndex = mapping.variants[mappingVariantIndex];\r\n const variant = ArrayItem.Get(`/extensions/${NAME}/variants/${variantIndex}`, this._variants, variantIndex);\r\n extensionMetadata.variants[variant.name] = extensionMetadata.variants[variant.name] || [];\r\n extensionMetadata.variants[variant.name].push({\r\n mesh: babylonMesh,\r\n material: babylonMaterial,\r\n });\r\n\r\n // Replace the target when original mesh is cloned\r\n babylonMesh.onClonedObservable.add((newOne: Node) => {\r\n const newMesh = newOne as Mesh;\r\n let metadata: Nullable<IExtensionMetadata> = null;\r\n let newRoot: Nullable<Node> = newMesh;\r\n\r\n // Find root to get medata\r\n do {\r\n newRoot = newRoot!.parent;\r\n if (!newRoot) {\r\n return;\r\n }\r\n metadata = KHR_materials_variants._GetExtensionMetadata(newRoot as Mesh);\r\n } while (metadata === null);\r\n\r\n // Need to clone the metadata on the root (first time only)\r\n if (root && metadata === KHR_materials_variants._GetExtensionMetadata(root)) {\r\n // Copy main metadata\r\n newRoot._internalMetadata = {};\r\n for (const key in root._internalMetadata) {\r\n newRoot._internalMetadata[key] = root._internalMetadata[key];\r\n }\r\n\r\n // Copy the gltf metadata\r\n newRoot._internalMetadata.gltf = [];\r\n for (const key in root._internalMetadata.gltf) {\r\n newRoot._internalMetadata.gltf[key] = root._internalMetadata.gltf[key];\r\n }\r\n\r\n // Duplicate the extension specific metadata\r\n newRoot._internalMetadata.gltf[NAME] = { lastSelected: null, original: [], variants: {} };\r\n for (const original of metadata.original) {\r\n newRoot._internalMetadata.gltf[NAME].original.push({\r\n mesh: original.mesh,\r\n material: original.material,\r\n });\r\n }\r\n for (const key in metadata.variants) {\r\n if (Object.prototype.hasOwnProperty.call(metadata.variants, key)) {\r\n newRoot._internalMetadata.gltf[NAME].variants[key] = [];\r\n for (const variantEntry of metadata.variants[key]) {\r\n newRoot._internalMetadata.gltf[NAME].variants[key].push({\r\n mesh: variantEntry.mesh,\r\n material: variantEntry.material,\r\n });\r\n }\r\n }\r\n }\r\n\r\n metadata = newRoot._internalMetadata.gltf[NAME];\r\n }\r\n\r\n // Relocate\r\n for (const target of metadata!.original) {\r\n if (target.mesh === babylonMesh) {\r\n target.mesh = newMesh;\r\n }\r\n }\r\n for (const target of metadata!.variants[variant.name]) {\r\n if (target.mesh === babylonMesh) {\r\n target.mesh = newMesh;\r\n }\r\n }\r\n });\r\n }\r\n })\r\n );\r\n }\r\n }\r\n })\r\n );\r\n return Promise.all(promises).then(([babylonMesh]) => {\r\n return babylonMesh;\r\n });\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_materials_variants(loader));\r\n"]}
|
1
|
+
{"version":3,"file":"KHR_materials_variants.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_variants.ts"],"names":[],"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IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;wDACpD,IAAI,EAAE,YAAY,CAAC,IAAI;wDACvB,QAAQ,EAAE,YAAY,CAAC,QAAQ;qDAClC,CAAC,CAAC;iDACN;6CACJ;yCACJ;wCAED,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;qCACnD;oCAED,WAAW;oCACX,KAAK,MAAM,MAAM,IAAI,QAAS,CAAC,QAAQ,EAAE;wCACrC,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW,EAAE;4CAC7B,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC;yCACzB;qCACJ;oCACD,KAAK,MAAM,MAAM,IAAI,QAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;wCACnD,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW,EAAE;4CAC7B,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC;yCACzB;qCACJ;gCACL,CAAC,CAAC,CAAC;6BACN;wBACL,CAAC,CAAC,CACL,CAAC;qBACL;iBACJ;YACL,CAAC,CAAC,CACL,CAAC;YACF,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE;gBAChD,OAAO,WAAW,CAAC;YACvB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\n\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\nimport type { Node } from \"core/node\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport type { INode, IMeshPrimitive, IMesh } from \"../glTFLoaderInterfaces\";\r\nimport type { IKHRMaterialVariants_Mapping, IKHRMaterialVariants_Variant, IKHRMaterialVariants_Variants } from \"babylonjs-gltf2interface\";\r\n\r\nconst NAME = \"KHR_materials_variants\";\r\n\r\ninterface IVariantsMap {\r\n [key: string]: Array<{ mesh: AbstractMesh; material: Nullable<Material> }>;\r\n}\r\n\r\ninterface IExtensionMetadata {\r\n lastSelected: Nullable<string | Array<string>>;\r\n original: Array<{ mesh: AbstractMesh; material: Nullable<Material> }>;\r\n variants: IVariantsMap;\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_variants/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_variants 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 private _variants?: Array<IKHRMaterialVariants_Variant>;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * Gets the list of available variant names for this asset.\r\n * @param rootMesh The glTF root mesh\r\n * @returns the list of all the variant names for this model\r\n */\r\n public static GetAvailableVariants(rootMesh: Mesh): string[] {\r\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\r\n if (!extensionMetadata) {\r\n return [];\r\n }\r\n\r\n return Object.keys(extensionMetadata.variants);\r\n }\r\n\r\n /**\r\n * Gets the list of available variant names for this asset.\r\n * @param rootMesh The glTF root mesh\r\n * @returns the list of all the variant names for this model\r\n */\r\n public getAvailableVariants(rootMesh: Mesh): string[] {\r\n return KHR_materials_variants.GetAvailableVariants(rootMesh);\r\n }\r\n\r\n /**\r\n * Select a variant given a variant name or a list of variant names.\r\n * @param rootMesh The glTF root mesh\r\n * @param variantName The variant name(s) to select.\r\n */\r\n public static SelectVariant(rootMesh: Mesh, variantName: string | string[]): void {\r\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\r\n if (!extensionMetadata) {\r\n throw new Error(`Cannot select variant on a glTF mesh that does not have the ${NAME} extension`);\r\n }\r\n\r\n const select = (variantName: string): void => {\r\n const entries = extensionMetadata.variants[variantName];\r\n if (entries) {\r\n for (const entry of entries) {\r\n entry.mesh.material = entry.material;\r\n }\r\n }\r\n };\r\n\r\n if (variantName instanceof Array) {\r\n for (const name of variantName) {\r\n select(name);\r\n }\r\n } else {\r\n select(variantName);\r\n }\r\n\r\n extensionMetadata.lastSelected = variantName;\r\n }\r\n\r\n /**\r\n * Select a variant given a variant name or a list of variant names.\r\n * @param rootMesh The glTF root mesh\r\n * @param variantName The variant name(s) to select.\r\n */\r\n public selectVariant(rootMesh: Mesh, variantName: string | string[]): void {\r\n return KHR_materials_variants.SelectVariant(rootMesh, variantName);\r\n }\r\n\r\n /**\r\n * Reset back to the original before selecting a variant.\r\n * @param rootMesh The glTF root mesh\r\n */\r\n public static Reset(rootMesh: Mesh): void {\r\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\r\n if (!extensionMetadata) {\r\n throw new Error(`Cannot reset on a glTF mesh that does not have the ${NAME} extension`);\r\n }\r\n\r\n for (const entry of extensionMetadata.original) {\r\n entry.mesh.material = entry.material;\r\n }\r\n\r\n extensionMetadata.lastSelected = null;\r\n }\r\n\r\n /**\r\n * Reset back to the original before selecting a variant.\r\n * @param rootMesh The glTF root mesh\r\n */\r\n public reset(rootMesh: Mesh): void {\r\n return KHR_materials_variants.Reset(rootMesh);\r\n }\r\n\r\n /**\r\n * Gets the last selected variant name(s) or null if original.\r\n * @param rootMesh The glTF root mesh\r\n * @returns The selected variant name(s).\r\n */\r\n public static GetLastSelectedVariant(rootMesh: Mesh): Nullable<string | string[]> {\r\n const extensionMetadata = this._GetExtensionMetadata(rootMesh);\r\n if (!extensionMetadata) {\r\n throw new Error(`Cannot get the last selected variant on a glTF mesh that does not have the ${NAME} extension`);\r\n }\r\n\r\n return extensionMetadata.lastSelected;\r\n }\r\n\r\n /**\r\n * Gets the last selected variant name(s) or null if original.\r\n * @param rootMesh The glTF root mesh\r\n * @returns The selected variant name(s).\r\n */\r\n public getLastSelectedVariant(rootMesh: Mesh): Nullable<string | string[]> {\r\n return KHR_materials_variants.GetLastSelectedVariant(rootMesh);\r\n }\r\n\r\n private static _GetExtensionMetadata(rootMesh: Nullable<Mesh>): Nullable<IExtensionMetadata> {\r\n return rootMesh?._internalMetadata?.gltf?.[NAME] || null;\r\n }\r\n\r\n /** @internal */\r\n public onLoading(): void {\r\n const extensions = this._loader.gltf.extensions;\r\n if (extensions && extensions[this.name]) {\r\n const extension = extensions[this.name] as IKHRMaterialVariants_Variants;\r\n this._variants = extension.variants;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _loadMeshPrimitiveAsync(\r\n context: string,\r\n name: string,\r\n node: INode,\r\n mesh: IMesh,\r\n primitive: IMeshPrimitive,\r\n assign: (babylonMesh: AbstractMesh) => void\r\n ): Nullable<Promise<AbstractMesh>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRMaterialVariants_Mapping, AbstractMesh>(context, primitive, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n promises.push(\r\n this._loader._loadMeshPrimitiveAsync(context, name, node, mesh, primitive, (babylonMesh) => {\r\n assign(babylonMesh);\r\n\r\n if (babylonMesh instanceof Mesh) {\r\n const babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);\r\n\r\n const root = this._loader.rootBabylonMesh;\r\n const metadata = root ? (root._internalMetadata = root._internalMetadata || {}) : {};\r\n const gltf = (metadata.gltf = metadata.gltf || {});\r\n const extensionMetadata: IExtensionMetadata = (gltf[NAME] = gltf[NAME] || { lastSelected: null, original: [], variants: {} });\r\n\r\n // Store the original material.\r\n extensionMetadata.original.push({ mesh: babylonMesh, material: babylonMesh.material });\r\n\r\n // For each mapping, look at the variants and make a new entry for them.\r\n for (let mappingIndex = 0; mappingIndex < extension.mappings.length; ++mappingIndex) {\r\n const mapping = extension.mappings[mappingIndex];\r\n const material = ArrayItem.Get(`${extensionContext}/mappings/${mappingIndex}/material`, this._loader.gltf.materials, mapping.material);\r\n promises.push(\r\n this._loader._loadMaterialAsync(`#/materials/${mapping.material}`, material, babylonMesh, babylonDrawMode, (babylonMaterial) => {\r\n for (let mappingVariantIndex = 0; mappingVariantIndex < mapping.variants.length; ++mappingVariantIndex) {\r\n const variantIndex = mapping.variants[mappingVariantIndex];\r\n const variant = ArrayItem.Get(`/extensions/${NAME}/variants/${variantIndex}`, this._variants, variantIndex);\r\n extensionMetadata.variants[variant.name] = extensionMetadata.variants[variant.name] || [];\r\n extensionMetadata.variants[variant.name].push({\r\n mesh: babylonMesh,\r\n material: babylonMaterial,\r\n });\r\n\r\n // Replace the target when original mesh is cloned\r\n babylonMesh.onClonedObservable.add((newOne: Node) => {\r\n const newMesh = newOne as Mesh;\r\n let metadata: Nullable<IExtensionMetadata> = null;\r\n let newRoot: Nullable<Node> = newMesh;\r\n\r\n // Find root to get medata\r\n do {\r\n newRoot = newRoot!.parent;\r\n if (!newRoot) {\r\n return;\r\n }\r\n metadata = KHR_materials_variants._GetExtensionMetadata(newRoot as Mesh);\r\n } while (metadata === null);\r\n\r\n // Need to clone the metadata on the root (first time only)\r\n if (root && metadata === KHR_materials_variants._GetExtensionMetadata(root)) {\r\n // Copy main metadata\r\n newRoot._internalMetadata = {};\r\n for (const key in root._internalMetadata) {\r\n newRoot._internalMetadata[key] = root._internalMetadata[key];\r\n }\r\n\r\n // Copy the gltf metadata\r\n newRoot._internalMetadata.gltf = [];\r\n for (const key in root._internalMetadata.gltf) {\r\n newRoot._internalMetadata.gltf[key] = root._internalMetadata.gltf[key];\r\n }\r\n\r\n // Duplicate the extension specific metadata\r\n newRoot._internalMetadata.gltf[NAME] = { lastSelected: null, original: [], variants: {} };\r\n for (const original of metadata.original) {\r\n newRoot._internalMetadata.gltf[NAME].original.push({\r\n mesh: original.mesh,\r\n material: original.material,\r\n });\r\n }\r\n for (const key in metadata.variants) {\r\n if (Object.prototype.hasOwnProperty.call(metadata.variants, key)) {\r\n newRoot._internalMetadata.gltf[NAME].variants[key] = [];\r\n for (const variantEntry of metadata.variants[key]) {\r\n newRoot._internalMetadata.gltf[NAME].variants[key].push({\r\n mesh: variantEntry.mesh,\r\n material: variantEntry.material,\r\n });\r\n }\r\n }\r\n }\r\n\r\n metadata = newRoot._internalMetadata.gltf[NAME];\r\n }\r\n\r\n // Relocate\r\n for (const target of metadata!.original) {\r\n if (target.mesh === babylonMesh) {\r\n target.mesh = newMesh;\r\n }\r\n }\r\n for (const target of metadata!.variants[variant.name]) {\r\n if (target.mesh === babylonMesh) {\r\n target.mesh = newMesh;\r\n }\r\n }\r\n });\r\n }\r\n })\r\n );\r\n }\r\n }\r\n })\r\n );\r\n return Promise.all(promises).then(([babylonMesh]) => {\r\n return babylonMesh;\r\n });\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_materials_variants(loader));\r\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_materials_volume.js","sourceRoot":"","sources":["../../../../../../
|
1
|
+
{"version":3,"file":"KHR_materials_volume.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_materials_volume.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,MAAM,IAAI,GAAG,sBAAsB,CAAC;AAEpC;;;GAGG;AACH,gEAAgE;AAChE,M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AAI,CAAC;QACtD,IAAI,SAAS,CAAC,gBAAgB,EAAE;YAC3B,SAAS,CAAC,gBAAiC,CAAC,YAAY,GAAG,IAAI,CAAC;YACjE,OAAO,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,OAAO,mBAAmB,EAAE,SAAS,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,CAAC,OAAoB,EAAE,EAAE;gBAC9H,eAAe,CAAC,UAAU,CAAC,gBAAgB,GAAG,OAAO,CAAC;gBACtD,eAAe,CAAC,UAAU,CAAC,oBAAoB,GAAG,IAAI,CAAC;YAC3D,CAAC,CAAC,CAAC;SACN;aAAM;YACH,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;SAC5B;IACL,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"core/types\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { IMaterial, ITextureInfo } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport type { IKHRMaterialsVolume } from \"babylonjs-gltf2interface\";\r\n\r\nconst NAME = \"KHR_materials_volume\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_volume/README.md)\r\n * @since 5.0.0\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_volume 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 /**\r\n * Defines a number that determines the order the extensions are applied.\r\n */\r\n public order = 173;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n if (this.enabled) {\r\n // We need to disable instance usage because the attenuation factor depends on the node scale of each individual mesh\r\n this._loader._disableInstancedMesh++;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n if (this.enabled) {\r\n this._loader._disableInstancedMesh--;\r\n }\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IKHRMaterialsVolume>(context, material, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n promises.push(this._loader.loadMaterialBasePropertiesAsync(context, material, babylonMaterial));\r\n promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));\r\n promises.push(this._loadVolumePropertiesAsync(extensionContext, material, babylonMaterial, extension));\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n private _loadVolumePropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material, extension: IKHRMaterialsVolume): Promise<void> {\r\n if (!(babylonMaterial instanceof PBRMaterial)) {\r\n throw new Error(`${context}: Material type not supported`);\r\n }\r\n\r\n // If transparency isn't enabled already, this extension shouldn't do anything.\r\n // i.e. it requires either the KHR_materials_transmission or KHR_materials_translucency extensions.\r\n if ((!babylonMaterial.subSurface.isRefractionEnabled && !babylonMaterial.subSurface.isTranslucencyEnabled) || !extension.thicknessFactor) {\r\n return Promise.resolve();\r\n }\r\n\r\n // IOR in this extension only affects interior.\r\n babylonMaterial.subSurface.volumeIndexOfRefraction = babylonMaterial.indexOfRefraction;\r\n const attenuationDistance = extension.attenuationDistance !== undefined ? extension.attenuationDistance : Number.MAX_VALUE;\r\n babylonMaterial.subSurface.tintColorAtDistance = attenuationDistance;\r\n if (extension.attenuationColor !== undefined && extension.attenuationColor.length == 3) {\r\n babylonMaterial.subSurface.tintColor.copyFromFloats(extension.attenuationColor[0], extension.attenuationColor[1], extension.attenuationColor[2]);\r\n }\r\n\r\n babylonMaterial.subSurface.minimumThickness = 0.0;\r\n babylonMaterial.subSurface.maximumThickness = extension.thicknessFactor;\r\n babylonMaterial.subSurface.useThicknessAsDepth = true;\r\n if (extension.thicknessTexture) {\r\n (extension.thicknessTexture as ITextureInfo).nonColorData = true;\r\n return this._loader.loadTextureInfoAsync(`${context}/thicknessTexture`, extension.thicknessTexture).then((texture: BaseTexture) => {\r\n babylonMaterial.subSurface.thicknessTexture = texture;\r\n babylonMaterial.subSurface.useGltfStyleTextures = true;\r\n });\r\n } else {\r\n return Promise.resolve();\r\n }\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_materials_volume(loader));\r\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_mesh_quantization.js","sourceRoot":"","sources":["../../../../../../
|
1
|
+
{"version":3,"file":"KHR_mesh_quantization.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_mesh_quantization.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,IAAI,GAAG,uBAAuB,CAAC;AAErC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,qBAAqB;IAW9B;;OAEG;IACH,YAAY,MAAkB;QAb9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAWxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IAED,gBAAgB;IACT,OAAO,KAAI,CAAC;CACtB;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\n\r\nconst NAME = \"KHR_mesh_quantization\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_mesh_quantization/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_mesh_quantization 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 /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this.enabled = loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {}\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_mesh_quantization(loader));\r\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_texture_basisu.js","sourceRoot":"","sources":["../../../../../../
|
1
|
+
{"version":3,"file":"KHR_texture_basisu.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_texture_basisu.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAMtD,MAAM,IAAI,GAAG,oBAAoB,CAAC;AAElC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,kBAAkB;IAS3B;;OAEG;IACH,YAAY,MAAkB;QAX9B,kCAAkC;QAClB,SAAI,GAAG,IAAI,CAAC;QAWxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IAED,gBAAgB;IACT,OAAO;QACT,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,iBAAiB,CAAC,OAAe,EAAE,OAAiB,EAAE,MAA6C;QACtG,OAAO,UAAU,CAAC,kBAAkB,CAAiC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,gBAAgB,EAAE,SAAS,EAAE,EAAE;YAC9H,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,OAAO,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;YAC5J,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,gBAAgB,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;YACtG,OAAO,IAAI,CAAC,OAAO,CAAC,mBAAmB,CACnC,OAAO,EACP,OAAO,EACP,KAAK,EACL,CAAC,cAAc,EAAE,EAAE;gBACf,MAAM,CAAC,cAAc,CAAC,CAAC;YAC3B,CAAC,EACD,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,qCAAqC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,EAC/F,CAAC,OAAO,CAAC,YAAY,CAAC,YAAY,CACrC,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\nimport type { ITexture } from \"../glTFLoaderInterfaces\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { IKHRTextureBasisU } from \"babylonjs-gltf2interface\";\r\n\r\nconst NAME = \"KHR_texture_basisu\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\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 /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\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(\r\n context,\r\n sampler,\r\n image,\r\n (babylonTexture) => {\r\n assign(babylonTexture);\r\n },\r\n texture._textureInfo.nonColorData ? { useRGBAIfASTCBC7NotAvailableWhenUASTC: true } : undefined,\r\n !texture._textureInfo.nonColorData\r\n );\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_texture_basisu(loader));\r\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_texture_transform.js","sourceRoot":"","sources":["../../../../../../
|
1
|
+
{"version":3,"file":"KHR_texture_transform.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_texture_transform.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,sDAAwC;AAI1D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,MAAM,IAAI,GAAG,uBAAuB,CAAC;AAErC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,qBAAqB;IAa9B;;OAEG;IACH,YAAY,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,gBAAgB;IACT,OAAO;QACT,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,oBAAoB,CAAC,OAAe,EAAE,WAAyB,EAAE,MAA6C;QACjH,OAAO,UAAU,CAAC,kBAAkB,CAAoC,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,gBAAgB,EAAE,SAAS,EAAE,EAAE;YACrI,OAAO,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,OAAO,EAAE,WAAW,EAAE,CAAC,cAAc,EAAE,EAAE;gBAC9E,IAAI,CAAC,CAAC,cAAc,YAAY,OAAO,CAAC,EAAE;oBACtC,MAAM,IAAI,KAAK,CAAC,GAAG,gBAAgB,8BAA8B,CAAC,CAAC;iBACtE;gBAED,IAAI,SAAS,CAAC,MAAM,EAAE;oBAClB,cAAc,CAAC,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;oBAC7C,cAAc,CAAC,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;iBAChD;gBAED,mCAAmC;gBACnC,cAAc,CAAC,eAAe,GAAG,CAAC,CAAC;gBACnC,cAAc,CAAC,eAAe,GAAG,CAAC,CAAC;gBAEnC,IAAI,SAAS,CAAC,QAAQ,EAAE;oBACpB,cAAc,CAAC,IAAI,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC;iBAC7C;gBAED,IAAI,SAAS,CAAC,KAAK,EAAE;oBACjB,cAAc,CAAC,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;oBAC3C,cAAc,CAAC,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;iBAC9C;gBAED,IAAI,SAAS,CAAC,QAAQ,IAAI,SAAS,EAAE;oBACjC,cAAc,CAAC,gBAAgB,GAAG,SAAS,CAAC,QAAQ,CAAC;iBACxD;gBAED,MAAM,CAAC,cAAc,CAAC,CAAC;YAC3B,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\n\r\nimport type { ITextureInfo } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport type { 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/main/extensions/2.0/Khronos/KHR_texture_transform/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\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 /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\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));\r\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_xmp_json_ld.js","sourceRoot":"","sources":["../../../../../../
|
1
|
+
{"version":3,"file":"KHR_xmp_json_ld.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/KHR_xmp_json_ld.ts"],"names":[],"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,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport type { IKHRXmpJsonLd_Gltf, IKHRXmpJsonLd_Node } from \"babylonjs-gltf2interface\";\r\n\r\nconst NAME = \"KHR_xmp_json_ld\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_xmp_json_ld/README.md)\r\n * @since 5.0.0\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_xmp_json_ld 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 /**\r\n * Defines a number that determines the order the extensions are applied.\r\n */\r\n public order = 100;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /**\r\n * Called after the loader state changes to LOADING.\r\n */\r\n public onLoading(): void {\r\n if (this._loader.rootBabylonMesh === null) {\r\n return;\r\n }\r\n\r\n const xmp_gltf = this._loader.gltf.extensions?.KHR_xmp_json_ld as IKHRXmpJsonLd_Gltf;\r\n const xmp_node = this._loader.gltf.asset?.extensions?.KHR_xmp_json_ld as IKHRXmpJsonLd_Node;\r\n if (xmp_gltf && xmp_node) {\r\n const packet = +xmp_node.packet;\r\n if (xmp_gltf.packets && packet < xmp_gltf.packets.length) {\r\n this._loader.rootBabylonMesh.metadata = this._loader.rootBabylonMesh.metadata || {};\r\n this._loader.rootBabylonMesh.metadata.xmp = xmp_gltf.packets[packet];\r\n }\r\n }\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new KHR_xmp_json_ld(loader));\r\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"MSFT_audio_emitter.js","sourceRoot":"","sources":["../../../../../../lts/loaders/generated/glTF/2.0/Extensions/MSFT_audio_emitter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,6CAA+B;AACjD,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAExC,OAAO,EAAE,cAAc,EAAE,qDAAuC;AAEhE,OAAO,EAAE,KAAK,EAAE,uCAAyB;AACzC,OAAO,EAAE,aAAa,EAAE,+CAAiC;AAIzD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAItD,MAAM,IAAI,GAAG,oBAAoB,CAAC;AAyBlC;;;GAGG;AACH,gEAAgE;AAChE,MAAM,OAAO,kBAAkB;IAe3B;;OAEG;IACH,YAAY,MAAkB;QAjB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAexB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,gBAAgB;IACT,OAAO;QACT,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;QAC5B,IAAI,CAAC,MAAc,GAAG,IAAI,CAAC;QAC3B,IAAI,CAAC,SAAiB,GAAG,IAAI,CAAC;IACnC,CAAC;IAED,gBAAgB;IACT,SAAS;QACZ,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;QAChD,IAAI,UAAU,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACrC,MAAM,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAsB,CAAC;YAE7D,IA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CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC;gBAC3D,uEAAuE;gBACvE,qBAAqB,CAAC,6BAA6B,CAAC,GAAG,CAAC,GAAG,EAAE;oBACzD,KAAK,CAAC,IAAI,EAAE,CAAC;gBACjB,CAAC,CAAC,CAAC;gBACH,qBAAqB,CAAC,+BAA+B,CAAC,GAAG,CAAC,GAAG,EAAE;oBAC3D,KAAK,CAAC,KAAK,EAAE,CAAC;gBAClB,CAAC,CAAC,CAAC;aACN;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Vector3 } from \"core/Maths/math.vector\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport type { AnimationGroup } from \"core/Animations/animationGroup\";\r\nimport { AnimationEvent } from \"core/Animations/animationEvent\";\r\nimport type { TransformNode } from \"core/Meshes/transformNode\";\r\nimport { Sound } from \"core/Audio/sound\";\r\nimport { WeightedSound } from \"core/Audio/weightedsound\";\r\n\r\nimport type { IArrayItem, IScene, INode, IAnimation } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\nimport type { IMSFTAudioEmitter_Clip, IMSFTAudioEmitter_Emitter, IMSFTAudioEmitter_EmittersReference, IMSFTAudioEmitter_AnimationEvent } from \"babylonjs-gltf2interface\";\r\nimport { IMSFTAudioEmitter_AnimationEventAction } from \"babylonjs-gltf2interface\";\r\n\r\nconst NAME = \"MSFT_audio_emitter\";\r\n\r\ninterface ILoaderClip extends IMSFTAudioEmitter_Clip, IArrayItem {\r\n _objectURL?: Promise<string>;\r\n}\r\n\r\ninterface ILoaderEmitter extends IMSFTAudioEmitter_Emitter, IArrayItem {\r\n _babylonData?: {\r\n sound?: WeightedSound;\r\n loaded: Promise<void>;\r\n };\r\n _babylonSounds: Sound[];\r\n}\r\n\r\ninterface IMSFTAudioEmitter {\r\n clips: ILoaderClip[];\r\n emitters: ILoaderEmitter[];\r\n}\r\n\r\ninterface ILoaderAnimationEvent extends IMSFTAudioEmitter_AnimationEvent, IArrayItem {}\r\n\r\ninterface ILoaderAnimationEvents {\r\n events: ILoaderAnimationEvent[];\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/najadojo/glTF/blob/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter/README.md)\r\n * !!! Experimental Extension Subject to Changes !!!\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class MSFT_audio_emitter 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 private _clips: Array<ILoaderClip>;\r\n private _emitters: Array<ILoaderEmitter>;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n (this._clips as any) = null;\r\n (this._emitters as any) = null;\r\n }\r\n\r\n /** @internal */\r\n public onLoading(): void {\r\n const extensions = this._loader.gltf.extensions;\r\n if (extensions && extensions[this.name]) {\r\n const extension = extensions[this.name] as IMSFTAudioEmitter;\r\n\r\n this._clips = extension.clips;\r\n this._emitters = extension.emitters;\r\n\r\n ArrayItem.Assign(this._clips);\r\n ArrayItem.Assign(this._emitters);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IMSFTAudioEmitter_EmittersReference>(context, scene, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n promises.push(this._loader.loadSceneAsync(context, scene));\r\n\r\n for (const emitterIndex of extension.emitters) {\r\n const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);\r\n if (\r\n emitter.refDistance != undefined ||\r\n emitter.maxDistance != undefined ||\r\n emitter.rolloffFactor != undefined ||\r\n emitter.distanceModel != undefined ||\r\n emitter.innerAngle != undefined ||\r\n emitter.outerAngle != undefined\r\n ) {\r\n throw new Error(`${extensionContext}: Direction or Distance properties are not allowed on emitters attached to a scene`);\r\n }\r\n\r\n promises.push(this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter));\r\n }\r\n\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\r\n return GLTFLoader.LoadExtensionAsync<IMSFTAudioEmitter_EmittersReference, TransformNode>(context, node, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n return this._loader\r\n .loadNodeAsync(extensionContext, node, (babylonMesh) => {\r\n for (const emitterIndex of extension.emitters) {\r\n const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);\r\n promises.push(\r\n this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter).then(() => {\r\n for (const sound of emitter._babylonSounds) {\r\n sound.attachToMesh(babylonMesh);\r\n if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {\r\n sound.setLocalDirectionToMesh(Vector3.Forward());\r\n sound.setDirectionalCone(\r\n 2 * Tools.ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle),\r\n 2 * Tools.ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle),\r\n 0\r\n );\r\n }\r\n }\r\n })\r\n );\r\n }\r\n\r\n assign(babylonMesh);\r\n })\r\n .then((babylonMesh) => {\r\n return Promise.all(promises).then(() => {\r\n return babylonMesh;\r\n });\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>> {\r\n return GLTFLoader.LoadExtensionAsync<ILoaderAnimationEvents, AnimationGroup>(context, animation, this.name, (extensionContext, extension) => {\r\n return this._loader.loadAnimationAsync(context, animation).then((babylonAnimationGroup) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n ArrayItem.Assign(extension.events);\r\n for (const event of extension.events) {\r\n promises.push(this._loadAnimationEventAsync(`${extensionContext}/events/${event.index}`, context, animation, event, babylonAnimationGroup));\r\n }\r\n\r\n return Promise.all(promises).then(() => {\r\n return babylonAnimationGroup;\r\n });\r\n });\r\n });\r\n }\r\n\r\n private _loadClipAsync(context: string, clip: ILoaderClip): Promise<string> {\r\n if (clip._objectURL) {\r\n return clip._objectURL;\r\n }\r\n\r\n let promise: Promise<ArrayBufferView>;\r\n if (clip.uri) {\r\n promise = this._loader.loadUriAsync(context, clip, clip.uri);\r\n } else {\r\n const bufferView = ArrayItem.Get(`${context}/bufferView`, this._loader.gltf.bufferViews, clip.bufferView);\r\n promise = this._loader.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView);\r\n }\r\n\r\n clip._objectURL = promise.then((data) => {\r\n return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));\r\n });\r\n\r\n return clip._objectURL;\r\n }\r\n\r\n private _loadEmitterAsync(context: string, emitter: ILoaderEmitter): Promise<void> {\r\n emitter._babylonSounds = emitter._babylonSounds || [];\r\n if (!emitter._babylonData) {\r\n const clipPromises = new Array<Promise<any>>();\r\n const name = emitter.name || `emitter${emitter.index}`;\r\n const options = {\r\n loop: false,\r\n autoplay: false,\r\n volume: emitter.volume == undefined ? 1 : emitter.volume,\r\n };\r\n\r\n for (let i = 0; i < emitter.clips.length; i++) {\r\n const clipContext = `/extensions/${this.name}/clips`;\r\n const clip = ArrayItem.Get(clipContext, this._clips, emitter.clips[i].clip);\r\n clipPromises.push(\r\n this._loadClipAsync(`${clipContext}/${emitter.clips[i].clip}`, clip).then((objectURL: string) => {\r\n const sound = (emitter._babylonSounds[i] = new Sound(name, objectURL, this._loader.babylonScene, null, options));\r\n sound.refDistance = emitter.refDistance || 1;\r\n sound.maxDistance = emitter.maxDistance || 256;\r\n sound.rolloffFactor = emitter.rolloffFactor || 1;\r\n sound.distanceModel = emitter.distanceModel || \"exponential\";\r\n })\r\n );\r\n }\r\n\r\n const promise = Promise.all(clipPromises).then(() => {\r\n const weights = emitter.clips.map((clip) => {\r\n return clip.weight || 1;\r\n });\r\n const weightedSound = new WeightedSound(emitter.loop || false, emitter._babylonSounds, weights);\r\n if (emitter.innerAngle) {\r\n weightedSound.directionalConeInnerAngle = 2 * Tools.ToDegrees(emitter.innerAngle);\r\n }\r\n if (emitter.outerAngle) {\r\n weightedSound.directionalConeOuterAngle = 2 * Tools.ToDegrees(emitter.outerAngle);\r\n }\r\n if (emitter.volume) {\r\n weightedSound.volume = emitter.volume;\r\n }\r\n emitter._babylonData!.sound = weightedSound;\r\n });\r\n\r\n emitter._babylonData = {\r\n loaded: promise,\r\n };\r\n }\r\n\r\n return emitter._babylonData.loaded;\r\n }\r\n\r\n private _getEventAction(\r\n context: string,\r\n sound: WeightedSound,\r\n action: IMSFTAudioEmitter_AnimationEventAction,\r\n time: number,\r\n startOffset?: number\r\n ): (currentFrame: number) => void {\r\n switch (action) {\r\n case IMSFTAudioEmitter_AnimationEventAction.play: {\r\n return (currentFrame: number) => {\r\n const frameOffset = (startOffset || 0) + (currentFrame - time);\r\n sound.play(frameOffset);\r\n };\r\n }\r\n case IMSFTAudioEmitter_AnimationEventAction.stop: {\r\n return () => {\r\n sound.stop();\r\n };\r\n }\r\n case IMSFTAudioEmitter_AnimationEventAction.pause: {\r\n return () => {\r\n sound.pause();\r\n };\r\n }\r\n default: {\r\n throw new Error(`${context}: Unsupported action ${action}`);\r\n }\r\n }\r\n }\r\n\r\n private _loadAnimationEventAsync(\r\n context: string,\r\n animationContext: string,\r\n animation: IAnimation,\r\n event: ILoaderAnimationEvent,\r\n babylonAnimationGroup: AnimationGroup\r\n ): Promise<void> {\r\n if (babylonAnimationGroup.targetedAnimations.length == 0) {\r\n return Promise.resolve();\r\n }\r\n const babylonAnimation = babylonAnimationGroup.targetedAnimations[0];\r\n const emitterIndex = event.emitter;\r\n const emitter = ArrayItem.Get(`/extensions/${this.name}/emitters`, this._emitters, emitterIndex);\r\n return this._loadEmitterAsync(context, emitter).then(() => {\r\n const sound = emitter._babylonData!.sound;\r\n if (sound) {\r\n const babylonAnimationEvent = new AnimationEvent(event.time, this._getEventAction(context, sound, event.action, event.time, event.startOffset));\r\n babylonAnimation.animation.addEvent(babylonAnimationEvent);\r\n // Make sure all started audio stops when this animation is terminated.\r\n babylonAnimationGroup.onAnimationGroupEndObservable.add(() => {\r\n sound.stop();\r\n });\r\n babylonAnimationGroup.onAnimationGroupPauseObservable.add(() => {\r\n sound.pause();\r\n });\r\n }\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new MSFT_audio_emitter(loader));\r\n"]}
|
1
|
+
{"version":3,"file":"MSFT_audio_emitter.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/MSFT_audio_emitter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,6CAA+B;AACjD,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAExC,OAAO,EAAE,cAAc,EAAE,qDAAuC;AAEhE,OAAO,EAAE,KAAK,EAAE,uCAAyB;AACzC,OAAO,EAAE,aAAa,EAAE,+CAAiC;AAIzD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAItD,MAAM,IAAI,GAAG,oBAAoB,CAAC;AAyBlC;;;GAGG;AACH,gEAAgE;AAChE,MAAM,OAAO,kBAAkB;IAe3B;;O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kB,CAAC,CAAC,CAAC,CAAC;QACrE,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC;QACnC,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,eAAe,IAAI,CAAC,IAAI,WAAW,EAAE,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QACjG,OAAO,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;YACtD,MAAM,KAAK,GAAG,OAAO,CAAC,YAAa,CAAC,KAAK,CAAC;YAC1C,IAAI,KAAK,EAAE;gBACP,MAAM,qBAAqB,GAAG,IAAI,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;gBAChJ,gBAAgB,CAAC,SAAS,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC;gBAC3D,uEAAuE;gBACvE,qBAAqB,CAAC,6BAA6B,CAAC,GAAG,CAAC,GAAG,EAAE;oBACzD,KAAK,CAAC,IAAI,EAAE,CAAC;gBACjB,CAAC,CAAC,CAAC;gBACH,qBAAqB,CAAC,+BAA+B,CAAC,GAAG,CAAC,GAAG,EAAE;oBAC3D,KAAK,CAAC,KAAK,EAAE,CAAC;gBAClB,CAAC,CAAC,CAAC;aACN;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Vector3 } from \"core/Maths/math.vector\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport type { AnimationGroup } from \"core/Animations/animationGroup\";\r\nimport { AnimationEvent } from \"core/Animations/animationEvent\";\r\nimport type { TransformNode } from \"core/Meshes/transformNode\";\r\nimport { Sound } from \"core/Audio/sound\";\r\nimport { WeightedSound } from \"core/Audio/weightedsound\";\r\n\r\nimport type { IArrayItem, IScene, INode, IAnimation } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\nimport type { IMSFTAudioEmitter_Clip, IMSFTAudioEmitter_Emitter, IMSFTAudioEmitter_EmittersReference, IMSFTAudioEmitter_AnimationEvent } from \"babylonjs-gltf2interface\";\r\nimport { IMSFTAudioEmitter_AnimationEventAction } from \"babylonjs-gltf2interface\";\r\n\r\nconst NAME = \"MSFT_audio_emitter\";\r\n\r\ninterface ILoaderClip extends IMSFTAudioEmitter_Clip, IArrayItem {\r\n _objectURL?: Promise<string>;\r\n}\r\n\r\ninterface ILoaderEmitter extends IMSFTAudioEmitter_Emitter, IArrayItem {\r\n _babylonData?: {\r\n sound?: WeightedSound;\r\n loaded: Promise<void>;\r\n };\r\n _babylonSounds: Sound[];\r\n}\r\n\r\ninterface IMSFTAudioEmitter {\r\n clips: ILoaderClip[];\r\n emitters: ILoaderEmitter[];\r\n}\r\n\r\ninterface ILoaderAnimationEvent extends IMSFTAudioEmitter_AnimationEvent, IArrayItem {}\r\n\r\ninterface ILoaderAnimationEvents {\r\n events: ILoaderAnimationEvent[];\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/najadojo/glTF/blob/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter/README.md)\r\n * !!! Experimental Extension Subject to Changes !!!\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class MSFT_audio_emitter 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 private _clips: Array<ILoaderClip>;\r\n private _emitters: Array<ILoaderEmitter>;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n (this._clips as any) = null;\r\n (this._emitters as any) = null;\r\n }\r\n\r\n /** @internal */\r\n public onLoading(): void {\r\n const extensions = this._loader.gltf.extensions;\r\n if (extensions && extensions[this.name]) {\r\n const extension = extensions[this.name] as IMSFTAudioEmitter;\r\n\r\n this._clips = extension.clips;\r\n this._emitters = extension.emitters;\r\n\r\n ArrayItem.Assign(this._clips);\r\n ArrayItem.Assign(this._emitters);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IMSFTAudioEmitter_EmittersReference>(context, scene, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n promises.push(this._loader.loadSceneAsync(context, scene));\r\n\r\n for (const emitterIndex of extension.emitters) {\r\n const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);\r\n if (\r\n emitter.refDistance != undefined ||\r\n emitter.maxDistance != undefined ||\r\n emitter.rolloffFactor != undefined ||\r\n emitter.distanceModel != undefined ||\r\n emitter.innerAngle != undefined ||\r\n emitter.outerAngle != undefined\r\n ) {\r\n throw new Error(`${extensionContext}: Direction or Distance properties are not allowed on emitters attached to a scene`);\r\n }\r\n\r\n promises.push(this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter));\r\n }\r\n\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\r\n return GLTFLoader.LoadExtensionAsync<IMSFTAudioEmitter_EmittersReference, TransformNode>(context, node, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n return this._loader\r\n .loadNodeAsync(extensionContext, node, (babylonMesh) => {\r\n for (const emitterIndex of extension.emitters) {\r\n const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);\r\n promises.push(\r\n this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter).then(() => {\r\n for (const sound of emitter._babylonSounds) {\r\n sound.attachToMesh(babylonMesh);\r\n if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {\r\n sound.setLocalDirectionToMesh(Vector3.Forward());\r\n sound.setDirectionalCone(\r\n 2 * Tools.ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle),\r\n 2 * Tools.ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle),\r\n 0\r\n );\r\n }\r\n }\r\n })\r\n );\r\n }\r\n\r\n assign(babylonMesh);\r\n })\r\n .then((babylonMesh) => {\r\n return Promise.all(promises).then(() => {\r\n return babylonMesh;\r\n });\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>> {\r\n return GLTFLoader.LoadExtensionAsync<ILoaderAnimationEvents, AnimationGroup>(context, animation, this.name, (extensionContext, extension) => {\r\n return this._loader.loadAnimationAsync(context, animation).then((babylonAnimationGroup) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n ArrayItem.Assign(extension.events);\r\n for (const event of extension.events) {\r\n promises.push(this._loadAnimationEventAsync(`${extensionContext}/events/${event.index}`, context, animation, event, babylonAnimationGroup));\r\n }\r\n\r\n return Promise.all(promises).then(() => {\r\n return babylonAnimationGroup;\r\n });\r\n });\r\n });\r\n }\r\n\r\n private _loadClipAsync(context: string, clip: ILoaderClip): Promise<string> {\r\n if (clip._objectURL) {\r\n return clip._objectURL;\r\n }\r\n\r\n let promise: Promise<ArrayBufferView>;\r\n if (clip.uri) {\r\n promise = this._loader.loadUriAsync(context, clip, clip.uri);\r\n } else {\r\n const bufferView = ArrayItem.Get(`${context}/bufferView`, this._loader.gltf.bufferViews, clip.bufferView);\r\n promise = this._loader.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView);\r\n }\r\n\r\n clip._objectURL = promise.then((data) => {\r\n return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));\r\n });\r\n\r\n return clip._objectURL;\r\n }\r\n\r\n private _loadEmitterAsync(context: string, emitter: ILoaderEmitter): Promise<void> {\r\n emitter._babylonSounds = emitter._babylonSounds || [];\r\n if (!emitter._babylonData) {\r\n const clipPromises = new Array<Promise<any>>();\r\n const name = emitter.name || `emitter${emitter.index}`;\r\n const options = {\r\n loop: false,\r\n autoplay: false,\r\n volume: emitter.volume == undefined ? 1 : emitter.volume,\r\n };\r\n\r\n for (let i = 0; i < emitter.clips.length; i++) {\r\n const clipContext = `/extensions/${this.name}/clips`;\r\n const clip = ArrayItem.Get(clipContext, this._clips, emitter.clips[i].clip);\r\n clipPromises.push(\r\n this._loadClipAsync(`${clipContext}/${emitter.clips[i].clip}`, clip).then((objectURL: string) => {\r\n const sound = (emitter._babylonSounds[i] = new Sound(name, objectURL, this._loader.babylonScene, null, options));\r\n sound.refDistance = emitter.refDistance || 1;\r\n sound.maxDistance = emitter.maxDistance || 256;\r\n sound.rolloffFactor = emitter.rolloffFactor || 1;\r\n sound.distanceModel = emitter.distanceModel || \"exponential\";\r\n })\r\n );\r\n }\r\n\r\n const promise = Promise.all(clipPromises).then(() => {\r\n const weights = emitter.clips.map((clip) => {\r\n return clip.weight || 1;\r\n });\r\n const weightedSound = new WeightedSound(emitter.loop || false, emitter._babylonSounds, weights);\r\n if (emitter.innerAngle) {\r\n weightedSound.directionalConeInnerAngle = 2 * Tools.ToDegrees(emitter.innerAngle);\r\n }\r\n if (emitter.outerAngle) {\r\n weightedSound.directionalConeOuterAngle = 2 * Tools.ToDegrees(emitter.outerAngle);\r\n }\r\n if (emitter.volume) {\r\n weightedSound.volume = emitter.volume;\r\n }\r\n emitter._babylonData!.sound = weightedSound;\r\n });\r\n\r\n emitter._babylonData = {\r\n loaded: promise,\r\n };\r\n }\r\n\r\n return emitter._babylonData.loaded;\r\n }\r\n\r\n private _getEventAction(\r\n context: string,\r\n sound: WeightedSound,\r\n action: IMSFTAudioEmitter_AnimationEventAction,\r\n time: number,\r\n startOffset?: number\r\n ): (currentFrame: number) => void {\r\n switch (action) {\r\n case IMSFTAudioEmitter_AnimationEventAction.play: {\r\n return (currentFrame: number) => {\r\n const frameOffset = (startOffset || 0) + (currentFrame - time);\r\n sound.play(frameOffset);\r\n };\r\n }\r\n case IMSFTAudioEmitter_AnimationEventAction.stop: {\r\n return () => {\r\n sound.stop();\r\n };\r\n }\r\n case IMSFTAudioEmitter_AnimationEventAction.pause: {\r\n return () => {\r\n sound.pause();\r\n };\r\n }\r\n default: {\r\n throw new Error(`${context}: Unsupported action ${action}`);\r\n }\r\n }\r\n }\r\n\r\n private _loadAnimationEventAsync(\r\n context: string,\r\n animationContext: string,\r\n animation: IAnimation,\r\n event: ILoaderAnimationEvent,\r\n babylonAnimationGroup: AnimationGroup\r\n ): Promise<void> {\r\n if (babylonAnimationGroup.targetedAnimations.length == 0) {\r\n return Promise.resolve();\r\n }\r\n const babylonAnimation = babylonAnimationGroup.targetedAnimations[0];\r\n const emitterIndex = event.emitter;\r\n const emitter = ArrayItem.Get(`/extensions/${this.name}/emitters`, this._emitters, emitterIndex);\r\n return this._loadEmitterAsync(context, emitter).then(() => {\r\n const sound = emitter._babylonData!.sound;\r\n if (sound) {\r\n const babylonAnimationEvent = new AnimationEvent(event.time, this._getEventAction(context, sound, event.action, event.time, event.startOffset));\r\n babylonAnimation.animation.addEvent(babylonAnimationEvent);\r\n // Make sure all started audio stops when this animation is terminated.\r\n babylonAnimationGroup.onAnimationGroupEndObservable.add(() => {\r\n sound.stop();\r\n });\r\n babylonAnimationGroup.onAnimationGroupPauseObservable.add(() => {\r\n sound.pause();\r\n });\r\n }\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new MSFT_audio_emitter(loader));\r\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"MSFT_lod.js","sourceRoot":"","sources":["../../../../../../lts/loaders/generated/glTF/2.0/Extensions/MSFT_lod.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,2CAA6B;AAClD,OAAO,EAAE,QAAQ,EAAE,yCAA2B;AAO9C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAGtD,MAAM,IAAI,GAAG,UAAU,CAAC;AAQxB;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,QAAQ;IAiDjB;;OAEG;IACH,YAAY,MAAkB;QAnD9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAO5B;;WAEG;QACI,UAAK,GAAG,GAAG,CAAC;QAEnB;;WAEG;QACI,kBAAa,GAAG,EAAE,CAAC;QAE1B;;;;WAIG;QACI,+BAA0B,GAAG,IAAI,UAAU,EAAU,CAAC;QAE7D;;;;WAIG;QACI,mCAA8B,GAAG,IAAI,UAAU,EAAU,CAAC;QAIzD,gBAAW,GAAG,IAAI,KAAK,EAAe,CAAC;QAEvC,kBAAa,GAAqB,IAAI,CAAC;QACvC,oBAAe,GAAG,IAAI,KAAK,EAAkB,CAAC;QAC9C,qBAAgB,GAAG,IAAI,KAAK,EAAuB,CAAC;QACpD,oBAAe,GAAG,IAAI,KAAK,EAAe,CAAC;QAE3C,sBAAiB,GAAqB,IAAI,CAAC;QAC3C,wBAAmB,GAAG,IAAI,KAAK,EAAkB,CAAC;QAClD,yBAAoB,GAAG,IAAI,KAAK,EAAuB,CAAC;QACxD,wBAAmB,GAAG,IAAI,KAAK,EAAe,CAAC;QAMnD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GA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AI,eAAe,EAAE;YACpC,eAAe,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC;SACvC;IACL,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Observable } from \"core/Misc/observable\";\r\nimport { Deferred } from \"core/Misc/deferred\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { TransformNode } from \"core/Meshes/transformNode\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { INode, IMaterial, IBuffer, IScene } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\nimport type { IProperty, IMSFTLOD } from \"babylonjs-gltf2interface\";\r\n\r\nconst NAME = \"MSFT_lod\";\r\n\r\ninterface IBufferInfo {\r\n start: number;\r\n end: number;\r\n loaded: Deferred<ArrayBufferView>;\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/MSFT_lod/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class MSFT_lod 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 /**\r\n * Defines a number that determines the order the extensions are applied.\r\n */\r\n public order = 100;\r\n\r\n /**\r\n * Maximum number of LODs to load, starting from the lowest LOD.\r\n */\r\n public maxLODsToLoad = 10;\r\n\r\n /**\r\n * Observable raised when all node LODs of one level are loaded.\r\n * The event data is the index of the loaded LOD starting from zero.\r\n * Dispose the loader to cancel the loading of the next level of LODs.\r\n */\r\n public onNodeLODsLoadedObservable = new Observable<number>();\r\n\r\n /**\r\n * Observable raised when all material LODs of one level are loaded.\r\n * The event data is the index of the loaded LOD starting from zero.\r\n * Dispose the loader to cancel the loading of the next level of LODs.\r\n */\r\n public onMaterialLODsLoadedObservable = new Observable<number>();\r\n\r\n private _loader: GLTFLoader;\r\n\r\n private _bufferLODs = new Array<IBufferInfo>();\r\n\r\n private _nodeIndexLOD: Nullable<number> = null;\r\n private _nodeSignalLODs = new Array<Deferred<void>>();\r\n private _nodePromiseLODs = new Array<Array<Promise<any>>>();\r\n private _nodeBufferLODs = new Array<IBufferInfo>();\r\n\r\n private _materialIndexLOD: Nullable<number> = null;\r\n private _materialSignalLODs = new Array<Deferred<void>>();\r\n private _materialPromiseLODs = new Array<Array<Promise<any>>>();\r\n private _materialBufferLODs = new Array<IBufferInfo>();\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n\r\n this._nodeIndexLOD = null;\r\n this._nodeSignalLODs.length = 0;\r\n this._nodePromiseLODs.length = 0;\r\n this._nodeBufferLODs.length = 0;\r\n\r\n this._materialIndexLOD = null;\r\n this._materialSignalLODs.length = 0;\r\n this._materialPromiseLODs.length = 0;\r\n this._materialBufferLODs.length = 0;\r\n\r\n this.onMaterialLODsLoadedObservable.clear();\r\n this.onNodeLODsLoadedObservable.clear();\r\n }\r\n\r\n /** @internal */\r\n public onReady(): void {\r\n for (let indexLOD = 0; indexLOD < this._nodePromiseLODs.length; indexLOD++) {\r\n const promise = Promise.all(this._nodePromiseLODs[indexLOD]).then(() => {\r\n if (indexLOD !== 0) {\r\n this._loader.endPerformanceCounter(`Node LOD ${indexLOD}`);\r\n this._loader.log(`Loaded node LOD ${indexLOD}`);\r\n }\r\n\r\n this.onNodeLODsLoadedObservable.notifyObservers(indexLOD);\r\n\r\n if (indexLOD !== this._nodePromiseLODs.length - 1) {\r\n this._loader.startPerformanceCounter(`Node LOD ${indexLOD + 1}`);\r\n this._loadBufferLOD(this._nodeBufferLODs, indexLOD + 1);\r\n if (this._nodeSignalLODs[indexLOD]) {\r\n this._nodeSignalLODs[indexLOD].resolve();\r\n }\r\n }\r\n });\r\n\r\n this._loader._completePromises.push(promise);\r\n }\r\n\r\n for (let indexLOD = 0; indexLOD < this._materialPromiseLODs.length; indexLOD++) {\r\n const promise = Promise.all(this._materialPromiseLODs[indexLOD]).then(() => {\r\n if (indexLOD !== 0) {\r\n this._loader.endPerformanceCounter(`Material LOD ${indexLOD}`);\r\n this._loader.log(`Loaded material LOD ${indexLOD}`);\r\n }\r\n\r\n this.onMaterialLODsLoadedObservable.notifyObservers(indexLOD);\r\n\r\n if (indexLOD !== this._materialPromiseLODs.length - 1) {\r\n this._loader.startPerformanceCounter(`Material LOD ${indexLOD + 1}`);\r\n this._loadBufferLOD(this._materialBufferLODs, indexLOD + 1);\r\n if (this._materialSignalLODs[indexLOD]) {\r\n this._materialSignalLODs[indexLOD].resolve();\r\n }\r\n }\r\n });\r\n\r\n this._loader._completePromises.push(promise);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {\r\n const promise = this._loader.loadSceneAsync(context, scene);\r\n this._loadBufferLOD(this._bufferLODs, 0);\r\n return promise;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\r\n return GLTFLoader.LoadExtensionAsync<IMSFTLOD, TransformNode>(context, node, this.name, (extensionContext, extension) => {\r\n let firstPromise: Promise<TransformNode>;\r\n\r\n const nodeLODs = this._getLODs(extensionContext, node, this._loader.gltf.nodes, extension.ids);\r\n this._loader.logOpen(`${extensionContext}`);\r\n\r\n for (let indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {\r\n const nodeLOD = nodeLODs[indexLOD];\r\n\r\n if (indexLOD !== 0) {\r\n this._nodeIndexLOD = indexLOD;\r\n this._nodeSignalLODs[indexLOD] = this._nodeSignalLODs[indexLOD] || new Deferred();\r\n }\r\n\r\n const assignWrap = (babylonTransformNode: TransformNode) => {\r\n assign(babylonTransformNode);\r\n babylonTransformNode.setEnabled(false);\r\n };\r\n\r\n const promise = this._loader.loadNodeAsync(`/nodes/${nodeLOD.index}`, nodeLOD, assignWrap).then((babylonMesh) => {\r\n if (indexLOD !== 0) {\r\n // TODO: should not rely on _babylonTransformNode\r\n const previousNodeLOD = nodeLODs[indexLOD - 1];\r\n if (previousNodeLOD._babylonTransformNode) {\r\n this._disposeTransformNode(previousNodeLOD._babylonTransformNode);\r\n delete previousNodeLOD._babylonTransformNode;\r\n }\r\n }\r\n\r\n babylonMesh.setEnabled(true);\r\n return babylonMesh;\r\n });\r\n\r\n this._nodePromiseLODs[indexLOD] = this._nodePromiseLODs[indexLOD] || [];\r\n\r\n if (indexLOD === 0) {\r\n firstPromise = promise;\r\n } else {\r\n this._nodeIndexLOD = null;\r\n this._nodePromiseLODs[indexLOD].push(promise);\r\n }\r\n }\r\n\r\n this._loader.logClose();\r\n return firstPromise!;\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _loadMaterialAsync(\r\n context: string,\r\n material: IMaterial,\r\n babylonMesh: Nullable<Mesh>,\r\n babylonDrawMode: number,\r\n assign: (babylonMaterial: Material) => void\r\n ): Nullable<Promise<Material>> {\r\n // Don't load material LODs if already loading a node LOD.\r\n if (this._nodeIndexLOD) {\r\n return null;\r\n }\r\n\r\n return GLTFLoader.LoadExtensionAsync<IMSFTLOD, Material>(context, material, this.name, (extensionContext, extension) => {\r\n let firstPromise: Promise<Material>;\r\n\r\n const materialLODs = this._getLODs(extensionContext, material, this._loader.gltf.materials, extension.ids);\r\n this._loader.logOpen(`${extensionContext}`);\r\n\r\n for (let indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {\r\n const materialLOD = materialLODs[indexLOD];\r\n\r\n if (indexLOD !== 0) {\r\n this._materialIndexLOD = indexLOD;\r\n }\r\n\r\n const promise = this._loader\r\n ._loadMaterialAsync(`/materials/${materialLOD.index}`, materialLOD, babylonMesh, babylonDrawMode, (babylonMaterial) => {\r\n if (indexLOD === 0) {\r\n assign(babylonMaterial);\r\n }\r\n })\r\n .then((babylonMaterial) => {\r\n if (indexLOD !== 0) {\r\n assign(babylonMaterial);\r\n\r\n // TODO: should not rely on _data\r\n const previousDataLOD = materialLODs[indexLOD - 1]._data!;\r\n if (previousDataLOD[babylonDrawMode]) {\r\n this._disposeMaterials([previousDataLOD[babylonDrawMode].babylonMaterial]);\r\n delete previousDataLOD[babylonDrawMode];\r\n }\r\n }\r\n\r\n return babylonMaterial;\r\n });\r\n\r\n this._materialPromiseLODs[indexLOD] = this._materialPromiseLODs[indexLOD] || [];\r\n\r\n if (indexLOD === 0) {\r\n firstPromise = promise;\r\n } else {\r\n this._materialIndexLOD = null;\r\n this._materialPromiseLODs[indexLOD].push(promise);\r\n }\r\n }\r\n\r\n this._loader.logClose();\r\n return firstPromise!;\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>> {\r\n // Defer the loading of uris if loading a node or material LOD.\r\n if (this._nodeIndexLOD !== null) {\r\n this._loader.log(`deferred`);\r\n const previousIndexLOD = this._nodeIndexLOD - 1;\r\n this._nodeSignalLODs[previousIndexLOD] = this._nodeSignalLODs[previousIndexLOD] || new Deferred<void>();\r\n return this._nodeSignalLODs[this._nodeIndexLOD - 1].promise.then(() => {\r\n return this._loader.loadUriAsync(context, property, uri);\r\n });\r\n } else if (this._materialIndexLOD !== null) {\r\n this._loader.log(`deferred`);\r\n const previousIndexLOD = this._materialIndexLOD - 1;\r\n this._materialSignalLODs[previousIndexLOD] = this._materialSignalLODs[previousIndexLOD] || new Deferred<void>();\r\n return this._materialSignalLODs[previousIndexLOD].promise.then(() => {\r\n return this._loader.loadUriAsync(context, property, uri);\r\n });\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadBufferAsync(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>> {\r\n if (this._loader.parent.useRangeRequests && !buffer.uri) {\r\n if (!this._loader.bin) {\r\n throw new Error(`${context}: Uri is missing or the binary glTF is missing its binary chunk`);\r\n }\r\n\r\n const loadAsync = (bufferLODs: Array<IBufferInfo>, indexLOD: number) => {\r\n const start = byteOffset;\r\n const end = start + byteLength - 1;\r\n let bufferLOD = bufferLODs[indexLOD];\r\n if (bufferLOD) {\r\n bufferLOD.start = Math.min(bufferLOD.start, start);\r\n bufferLOD.end = Math.max(bufferLOD.end, end);\r\n } else {\r\n bufferLOD = { start: start, end: end, loaded: new Deferred() };\r\n bufferLODs[indexLOD] = bufferLOD;\r\n }\r\n\r\n return bufferLOD.loaded.promise.then((data) => {\r\n return new Uint8Array(data.buffer, data.byteOffset + byteOffset - bufferLOD.start, byteLength);\r\n });\r\n };\r\n\r\n this._loader.log(`deferred`);\r\n\r\n if (this._nodeIndexLOD !== null) {\r\n return loadAsync(this._nodeBufferLODs, this._nodeIndexLOD);\r\n } else if (this._materialIndexLOD !== null) {\r\n return loadAsync(this._materialBufferLODs, this._materialIndexLOD);\r\n } else {\r\n return loadAsync(this._bufferLODs, 0);\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n private _loadBufferLOD(bufferLODs: Array<IBufferInfo>, indexLOD: number): void {\r\n const bufferLOD = bufferLODs[indexLOD];\r\n if (bufferLOD) {\r\n this._loader.log(`Loading buffer range [${bufferLOD.start}-${bufferLOD.end}]`);\r\n this._loader.bin!.readAsync(bufferLOD.start, bufferLOD.end - bufferLOD.start + 1).then(\r\n (data) => {\r\n bufferLOD.loaded.resolve(data);\r\n },\r\n (error) => {\r\n bufferLOD.loaded.reject(error);\r\n }\r\n );\r\n }\r\n }\r\n\r\n /**\r\n * Gets an array of LOD properties from lowest to highest.\r\n * @param context\r\n * @param property\r\n * @param array\r\n * @param ids\r\n */\r\n private _getLODs<T>(context: string, property: T, array: ArrayLike<T> | undefined, ids: number[]): T[] {\r\n if (this.maxLODsToLoad <= 0) {\r\n throw new Error(\"maxLODsToLoad must be greater than zero\");\r\n }\r\n\r\n const properties = new Array<T>();\r\n\r\n for (let i = ids.length - 1; i >= 0; i--) {\r\n properties.push(ArrayItem.Get(`${context}/ids/${ids[i]}`, array, ids[i]));\r\n if (properties.length === this.maxLODsToLoad) {\r\n return properties;\r\n }\r\n }\r\n\r\n properties.push(property);\r\n return properties;\r\n }\r\n\r\n private _disposeTransformNode(babylonTransformNode: TransformNode): void {\r\n const babylonMaterials = new Array<Material>();\r\n const babylonMaterial = (babylonTransformNode as Mesh).material;\r\n if (babylonMaterial) {\r\n babylonMaterials.push(babylonMaterial);\r\n }\r\n for (const babylonMesh of babylonTransformNode.getChildMeshes()) {\r\n if (babylonMesh.material) {\r\n babylonMaterials.push(babylonMesh.material);\r\n }\r\n }\r\n\r\n babylonTransformNode.dispose();\r\n\r\n const babylonMaterialsToDispose = babylonMaterials.filter((babylonMaterial) => this._loader.babylonScene.meshes.every((mesh) => mesh.material != babylonMaterial));\r\n this._disposeMaterials(babylonMaterialsToDispose);\r\n }\r\n\r\n private _disposeMaterials(babylonMaterials: Material[]): void {\r\n const babylonTextures: { [uniqueId: number]: BaseTexture } = {};\r\n\r\n for (const babylonMaterial of babylonMaterials) {\r\n for (const babylonTexture of babylonMaterial.getActiveTextures()) {\r\n babylonTextures[babylonTexture.uniqueId] = babylonTexture;\r\n }\r\n\r\n babylonMaterial.dispose();\r\n }\r\n\r\n for (const uniqueId in babylonTextures) {\r\n for (const babylonMaterial of this._loader.babylonScene.materials) {\r\n if (babylonMaterial.hasTexture(babylonTextures[uniqueId])) {\r\n delete babylonTextures[uniqueId];\r\n }\r\n }\r\n }\r\n\r\n for (const uniqueId in babylonTextures) {\r\n babylonTextures[uniqueId].dispose();\r\n }\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new MSFT_lod(loader));\r\n"]}
|
1
|
+
{"version":3,"file":"MSFT_lod.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/MSFT_lod.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,2CAA6B;AAClD,OAAO,EAAE,QAAQ,EAAE,yCAA2B;AAO9C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAGtD,MAAM,IAAI,GAAG,UAAU,CAAC;AAQxB;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,QAAQ;IAiDjB;;OAEG;IACH,YAAY,MAAkB;QAnD9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAO5B;;WAEG;QACI,UAAK,GAAG,GAAG,CAAC;QAEnB;;WAEG;QACI,kBAAa,GAAG,EAAE,CAAC;QAE1B;;;;WAIG;QACI,+BAA0B,GAAG,IAAI,UAAU,EAAU,CAAC;QAE7D;;;;WAIG;QACI,mCAA8B,GAAG,IAAI,UAAU,EAAU,CAAC;QAIzD,gBAAW,GAAG,IAAI,KAAK,EAAe,CAAC;QAEvC,kBAAa,GAAqB,IAAI,CAAC;QACvC,oBAAe,GAAG,IAAI,KAAK,EAAkB,CAAC;QAC9C,qBAAgB,GAAG,IAAI,KAAK,EAAuB,CAAC;QACpD,oBAAe,GAAG,IAAI,KAAK,EAAe,CAAC;QAE3C,sBAAiB,GAAqB,IAAI,CAAC;QAC3C,wBAAmB,GAAG,IAAI,KAAK,EAAkB,CAAC;QAClD,yBAAoB,GAAG,IAAI,KAAK,EAAuB,CAAC;QACxD,wBAAmB,GAAG,IAAI,KAAK,EAAe,CAAC;QAMnD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OA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pC,eAAe,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC;SACvC;IACL,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Observable } from \"core/Misc/observable\";\r\nimport { Deferred } from \"core/Misc/deferred\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport type { TransformNode } from \"core/Meshes/transformNode\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { INode, IMaterial, IBuffer, IScene } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\nimport type { IProperty, IMSFTLOD } from \"babylonjs-gltf2interface\";\r\n\r\nconst NAME = \"MSFT_lod\";\r\n\r\ninterface IBufferInfo {\r\n start: number;\r\n end: number;\r\n loaded: Deferred<ArrayBufferView>;\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/MSFT_lod/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class MSFT_lod 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 /**\r\n * Defines a number that determines the order the extensions are applied.\r\n */\r\n public order = 100;\r\n\r\n /**\r\n * Maximum number of LODs to load, starting from the lowest LOD.\r\n */\r\n public maxLODsToLoad = 10;\r\n\r\n /**\r\n * Observable raised when all node LODs of one level are loaded.\r\n * The event data is the index of the loaded LOD starting from zero.\r\n * Dispose the loader to cancel the loading of the next level of LODs.\r\n */\r\n public onNodeLODsLoadedObservable = new Observable<number>();\r\n\r\n /**\r\n * Observable raised when all material LODs of one level are loaded.\r\n * The event data is the index of the loaded LOD starting from zero.\r\n * Dispose the loader to cancel the loading of the next level of LODs.\r\n */\r\n public onMaterialLODsLoadedObservable = new Observable<number>();\r\n\r\n private _loader: GLTFLoader;\r\n\r\n private _bufferLODs = new Array<IBufferInfo>();\r\n\r\n private _nodeIndexLOD: Nullable<number> = null;\r\n private _nodeSignalLODs = new Array<Deferred<void>>();\r\n private _nodePromiseLODs = new Array<Array<Promise<any>>>();\r\n private _nodeBufferLODs = new Array<IBufferInfo>();\r\n\r\n private _materialIndexLOD: Nullable<number> = null;\r\n private _materialSignalLODs = new Array<Deferred<void>>();\r\n private _materialPromiseLODs = new Array<Array<Promise<any>>>();\r\n private _materialBufferLODs = new Array<IBufferInfo>();\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n\r\n this._nodeIndexLOD = null;\r\n this._nodeSignalLODs.length = 0;\r\n this._nodePromiseLODs.length = 0;\r\n this._nodeBufferLODs.length = 0;\r\n\r\n this._materialIndexLOD = null;\r\n this._materialSignalLODs.length = 0;\r\n this._materialPromiseLODs.length = 0;\r\n this._materialBufferLODs.length = 0;\r\n\r\n this.onMaterialLODsLoadedObservable.clear();\r\n this.onNodeLODsLoadedObservable.clear();\r\n }\r\n\r\n /** @internal */\r\n public onReady(): void {\r\n for (let indexLOD = 0; indexLOD < this._nodePromiseLODs.length; indexLOD++) {\r\n const promise = Promise.all(this._nodePromiseLODs[indexLOD]).then(() => {\r\n if (indexLOD !== 0) {\r\n this._loader.endPerformanceCounter(`Node LOD ${indexLOD}`);\r\n this._loader.log(`Loaded node LOD ${indexLOD}`);\r\n }\r\n\r\n this.onNodeLODsLoadedObservable.notifyObservers(indexLOD);\r\n\r\n if (indexLOD !== this._nodePromiseLODs.length - 1) {\r\n this._loader.startPerformanceCounter(`Node LOD ${indexLOD + 1}`);\r\n this._loadBufferLOD(this._nodeBufferLODs, indexLOD + 1);\r\n if (this._nodeSignalLODs[indexLOD]) {\r\n this._nodeSignalLODs[indexLOD].resolve();\r\n }\r\n }\r\n });\r\n\r\n this._loader._completePromises.push(promise);\r\n }\r\n\r\n for (let indexLOD = 0; indexLOD < this._materialPromiseLODs.length; indexLOD++) {\r\n const promise = Promise.all(this._materialPromiseLODs[indexLOD]).then(() => {\r\n if (indexLOD !== 0) {\r\n this._loader.endPerformanceCounter(`Material LOD ${indexLOD}`);\r\n this._loader.log(`Loaded material LOD ${indexLOD}`);\r\n }\r\n\r\n this.onMaterialLODsLoadedObservable.notifyObservers(indexLOD);\r\n\r\n if (indexLOD !== this._materialPromiseLODs.length - 1) {\r\n this._loader.startPerformanceCounter(`Material LOD ${indexLOD + 1}`);\r\n this._loadBufferLOD(this._materialBufferLODs, indexLOD + 1);\r\n if (this._materialSignalLODs[indexLOD]) {\r\n this._materialSignalLODs[indexLOD].resolve();\r\n }\r\n }\r\n });\r\n\r\n this._loader._completePromises.push(promise);\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {\r\n const promise = this._loader.loadSceneAsync(context, scene);\r\n this._loadBufferLOD(this._bufferLODs, 0);\r\n return promise;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\r\n return GLTFLoader.LoadExtensionAsync<IMSFTLOD, TransformNode>(context, node, this.name, (extensionContext, extension) => {\r\n let firstPromise: Promise<TransformNode>;\r\n\r\n const nodeLODs = this._getLODs(extensionContext, node, this._loader.gltf.nodes, extension.ids);\r\n this._loader.logOpen(`${extensionContext}`);\r\n\r\n for (let indexLOD = 0; indexLOD < nodeLODs.length; indexLOD++) {\r\n const nodeLOD = nodeLODs[indexLOD];\r\n\r\n if (indexLOD !== 0) {\r\n this._nodeIndexLOD = indexLOD;\r\n this._nodeSignalLODs[indexLOD] = this._nodeSignalLODs[indexLOD] || new Deferred();\r\n }\r\n\r\n const assignWrap = (babylonTransformNode: TransformNode) => {\r\n assign(babylonTransformNode);\r\n babylonTransformNode.setEnabled(false);\r\n };\r\n\r\n const promise = this._loader.loadNodeAsync(`/nodes/${nodeLOD.index}`, nodeLOD, assignWrap).then((babylonMesh) => {\r\n if (indexLOD !== 0) {\r\n // TODO: should not rely on _babylonTransformNode\r\n const previousNodeLOD = nodeLODs[indexLOD - 1];\r\n if (previousNodeLOD._babylonTransformNode) {\r\n this._disposeTransformNode(previousNodeLOD._babylonTransformNode);\r\n delete previousNodeLOD._babylonTransformNode;\r\n }\r\n }\r\n\r\n babylonMesh.setEnabled(true);\r\n return babylonMesh;\r\n });\r\n\r\n this._nodePromiseLODs[indexLOD] = this._nodePromiseLODs[indexLOD] || [];\r\n\r\n if (indexLOD === 0) {\r\n firstPromise = promise;\r\n } else {\r\n this._nodeIndexLOD = null;\r\n this._nodePromiseLODs[indexLOD].push(promise);\r\n }\r\n }\r\n\r\n this._loader.logClose();\r\n return firstPromise!;\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _loadMaterialAsync(\r\n context: string,\r\n material: IMaterial,\r\n babylonMesh: Nullable<Mesh>,\r\n babylonDrawMode: number,\r\n assign: (babylonMaterial: Material) => void\r\n ): Nullable<Promise<Material>> {\r\n // Don't load material LODs if already loading a node LOD.\r\n if (this._nodeIndexLOD) {\r\n return null;\r\n }\r\n\r\n return GLTFLoader.LoadExtensionAsync<IMSFTLOD, Material>(context, material, this.name, (extensionContext, extension) => {\r\n let firstPromise: Promise<Material>;\r\n\r\n const materialLODs = this._getLODs(extensionContext, material, this._loader.gltf.materials, extension.ids);\r\n this._loader.logOpen(`${extensionContext}`);\r\n\r\n for (let indexLOD = 0; indexLOD < materialLODs.length; indexLOD++) {\r\n const materialLOD = materialLODs[indexLOD];\r\n\r\n if (indexLOD !== 0) {\r\n this._materialIndexLOD = indexLOD;\r\n }\r\n\r\n const promise = this._loader\r\n ._loadMaterialAsync(`/materials/${materialLOD.index}`, materialLOD, babylonMesh, babylonDrawMode, (babylonMaterial) => {\r\n if (indexLOD === 0) {\r\n assign(babylonMaterial);\r\n }\r\n })\r\n .then((babylonMaterial) => {\r\n if (indexLOD !== 0) {\r\n assign(babylonMaterial);\r\n\r\n // TODO: should not rely on _data\r\n const previousDataLOD = materialLODs[indexLOD - 1]._data!;\r\n if (previousDataLOD[babylonDrawMode]) {\r\n this._disposeMaterials([previousDataLOD[babylonDrawMode].babylonMaterial]);\r\n delete previousDataLOD[babylonDrawMode];\r\n }\r\n }\r\n\r\n return babylonMaterial;\r\n });\r\n\r\n this._materialPromiseLODs[indexLOD] = this._materialPromiseLODs[indexLOD] || [];\r\n\r\n if (indexLOD === 0) {\r\n firstPromise = promise;\r\n } else {\r\n this._materialIndexLOD = null;\r\n this._materialPromiseLODs[indexLOD].push(promise);\r\n }\r\n }\r\n\r\n this._loader.logClose();\r\n return firstPromise!;\r\n });\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _loadUriAsync(context: string, property: IProperty, uri: string): Nullable<Promise<ArrayBufferView>> {\r\n // Defer the loading of uris if loading a node or material LOD.\r\n if (this._nodeIndexLOD !== null) {\r\n this._loader.log(`deferred`);\r\n const previousIndexLOD = this._nodeIndexLOD - 1;\r\n this._nodeSignalLODs[previousIndexLOD] = this._nodeSignalLODs[previousIndexLOD] || new Deferred<void>();\r\n return this._nodeSignalLODs[this._nodeIndexLOD - 1].promise.then(() => {\r\n return this._loader.loadUriAsync(context, property, uri);\r\n });\r\n } else if (this._materialIndexLOD !== null) {\r\n this._loader.log(`deferred`);\r\n const previousIndexLOD = this._materialIndexLOD - 1;\r\n this._materialSignalLODs[previousIndexLOD] = this._materialSignalLODs[previousIndexLOD] || new Deferred<void>();\r\n return this._materialSignalLODs[previousIndexLOD].promise.then(() => {\r\n return this._loader.loadUriAsync(context, property, uri);\r\n });\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public loadBufferAsync(context: string, buffer: IBuffer, byteOffset: number, byteLength: number): Nullable<Promise<ArrayBufferView>> {\r\n if (this._loader.parent.useRangeRequests && !buffer.uri) {\r\n if (!this._loader.bin) {\r\n throw new Error(`${context}: Uri is missing or the binary glTF is missing its binary chunk`);\r\n }\r\n\r\n const loadAsync = (bufferLODs: Array<IBufferInfo>, indexLOD: number) => {\r\n const start = byteOffset;\r\n const end = start + byteLength - 1;\r\n let bufferLOD = bufferLODs[indexLOD];\r\n if (bufferLOD) {\r\n bufferLOD.start = Math.min(bufferLOD.start, start);\r\n bufferLOD.end = Math.max(bufferLOD.end, end);\r\n } else {\r\n bufferLOD = { start: start, end: end, loaded: new Deferred() };\r\n bufferLODs[indexLOD] = bufferLOD;\r\n }\r\n\r\n return bufferLOD.loaded.promise.then((data) => {\r\n return new Uint8Array(data.buffer, data.byteOffset + byteOffset - bufferLOD.start, byteLength);\r\n });\r\n };\r\n\r\n this._loader.log(`deferred`);\r\n\r\n if (this._nodeIndexLOD !== null) {\r\n return loadAsync(this._nodeBufferLODs, this._nodeIndexLOD);\r\n } else if (this._materialIndexLOD !== null) {\r\n return loadAsync(this._materialBufferLODs, this._materialIndexLOD);\r\n } else {\r\n return loadAsync(this._bufferLODs, 0);\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n private _loadBufferLOD(bufferLODs: Array<IBufferInfo>, indexLOD: number): void {\r\n const bufferLOD = bufferLODs[indexLOD];\r\n if (bufferLOD) {\r\n this._loader.log(`Loading buffer range [${bufferLOD.start}-${bufferLOD.end}]`);\r\n this._loader.bin!.readAsync(bufferLOD.start, bufferLOD.end - bufferLOD.start + 1).then(\r\n (data) => {\r\n bufferLOD.loaded.resolve(data);\r\n },\r\n (error) => {\r\n bufferLOD.loaded.reject(error);\r\n }\r\n );\r\n }\r\n }\r\n\r\n /**\r\n * Gets an array of LOD properties from lowest to highest.\r\n * @param context\r\n * @param property\r\n * @param array\r\n * @param ids\r\n */\r\n private _getLODs<T>(context: string, property: T, array: ArrayLike<T> | undefined, ids: number[]): T[] {\r\n if (this.maxLODsToLoad <= 0) {\r\n throw new Error(\"maxLODsToLoad must be greater than zero\");\r\n }\r\n\r\n const properties = new Array<T>();\r\n\r\n for (let i = ids.length - 1; i >= 0; i--) {\r\n properties.push(ArrayItem.Get(`${context}/ids/${ids[i]}`, array, ids[i]));\r\n if (properties.length === this.maxLODsToLoad) {\r\n return properties;\r\n }\r\n }\r\n\r\n properties.push(property);\r\n return properties;\r\n }\r\n\r\n private _disposeTransformNode(babylonTransformNode: TransformNode): void {\r\n const babylonMaterials = new Array<Material>();\r\n const babylonMaterial = (babylonTransformNode as Mesh).material;\r\n if (babylonMaterial) {\r\n babylonMaterials.push(babylonMaterial);\r\n }\r\n for (const babylonMesh of babylonTransformNode.getChildMeshes()) {\r\n if (babylonMesh.material) {\r\n babylonMaterials.push(babylonMesh.material);\r\n }\r\n }\r\n\r\n babylonTransformNode.dispose();\r\n\r\n const babylonMaterialsToDispose = babylonMaterials.filter((babylonMaterial) => this._loader.babylonScene.meshes.every((mesh) => mesh.material != babylonMaterial));\r\n this._disposeMaterials(babylonMaterialsToDispose);\r\n }\r\n\r\n private _disposeMaterials(babylonMaterials: Material[]): void {\r\n const babylonTextures: { [uniqueId: number]: BaseTexture } = {};\r\n\r\n for (const babylonMaterial of babylonMaterials) {\r\n for (const babylonTexture of babylonMaterial.getActiveTextures()) {\r\n babylonTextures[babylonTexture.uniqueId] = babylonTexture;\r\n }\r\n\r\n babylonMaterial.dispose();\r\n }\r\n\r\n for (const uniqueId in babylonTextures) {\r\n for (const babylonMaterial of this._loader.babylonScene.materials) {\r\n if (babylonMaterial.hasTexture(babylonTextures[uniqueId])) {\r\n delete babylonTextures[uniqueId];\r\n }\r\n }\r\n }\r\n\r\n for (const uniqueId in babylonTextures) {\r\n babylonTextures[uniqueId].dispose();\r\n }\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new MSFT_lod(loader));\r\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"MSFT_minecraftMesh.js","sourceRoot":"","sources":["../../../../../../
|
1
|
+
{"version":3,"file":"MSFT_minecraftMesh.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/MSFT_minecraftMesh.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAI7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,IAAI,GAAG,oBAAoB,CAAC;AAElC,gBAAgB;AAChB,gEAAgE;AAChE,MAAM,OAAO,kBAAkB;IAS3B,gBAAgB;IAChB,YAAY,MAAkB;QAT9B,gBAAgB;QACA,SAAI,GAAG,IAAI,CAAC;QASxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,gBAAgB;IACT,OAAO;QACT,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED,gBAAgB;IACT,2BAA2B,CAAC,OAAe,EAAE,QAAmB,EAAE,eAAyB;QAC9F,OAAO,UAAU,CAAC,cAAc,CAAU,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,YAAY,EAAE,KAAK,EAAE,EAAE;YAC5F,IAAI,KAAK,EAAE;gBACP,IAAI,CAAC,CAAC,eAAe,YAAY,WAAW,CAAC,EAAE;oBAC3C,MAAM,IAAI,KAAK,CAAC,GAAG,YAAY,+BAA+B,CAAC,CAAC;iBACnE;gBAED,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,2BAA2B,CAAC,OAAO,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;gBAE7F,IAAI,eAAe,CAAC,iBAAiB,EAAE,EAAE;oBACrC,eAAe,CAAC,eAAe,GAAG,IAAI,CAAC;oBACvC,eAAe,CAAC,mBAAmB,GAAG,IAAI,CAAC;iBAC9C;gBAED,eAAe,CAAC,eAAe,GAAG,eAAe,CAAC,eAAe,CAAC;gBAClE,eAAe,CAAC,gBAAgB,GAAG,IAAI,CAAC;gBAExC,OAAO,OAAO,CAAC;aAClB;YAED,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\n\r\nimport type { IMaterial } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\n\r\nconst NAME = \"MSFT_minecraftMesh\";\r\n\r\n/** @internal */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class MSFT_minecraftMesh implements IGLTFLoaderExtension {\r\n /** @internal */\r\n public readonly name = NAME;\r\n\r\n /** @internal */\r\n public enabled: boolean;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /** @internal */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /** @internal */\r\n public loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtraAsync<boolean>(context, material, this.name, (extraContext, extra) => {\r\n if (extra) {\r\n if (!(babylonMaterial instanceof PBRMaterial)) {\r\n throw new Error(`${extraContext}: Material type not supported`);\r\n }\r\n\r\n const promise = this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);\r\n\r\n if (babylonMaterial.needAlphaBlending()) {\r\n babylonMaterial.forceDepthWrite = true;\r\n babylonMaterial.separateCullingPass = true;\r\n }\r\n\r\n babylonMaterial.backFaceCulling = babylonMaterial.forceDepthWrite;\r\n babylonMaterial.twoSidedLighting = true;\r\n\r\n return promise;\r\n }\r\n\r\n return null;\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new MSFT_minecraftMesh(loader));\r\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"MSFT_sRGBFactors.js","sourceRoot":"","sources":["../../../../../../
|
1
|
+
{"version":3,"file":"MSFT_sRGBFactors.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/MSFT_sRGBFactors.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAI7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,IAAI,GAAG,kBAAkB,CAAC;AAEhC,gBAAgB;AAChB,gEAAgE;AAChE,MAAM,OAAO,gBAAgB;IASzB,gBAAgB;IAChB,YAAY,MAAkB;QAT9B,gBAAgB;QACA,SAAI,GAAG,IAAI,CAAC;QASxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,gBAAgB;IACT,OAAO;QACT,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED,gBAAgB;IACT,2BAA2B,CAAC,OAAe,EAAE,QAAmB,EAAE,eAAyB;QAC9F,OAAO,UAAU,CAAC,cAAc,CAAU,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,YAAY,EAAE,KAAK,EAAE,EAAE;YAC5F,IAAI,KAAK,EAAE;gBACP,IAAI,CAAC,CAAC,eAAe,YAAY,WAAW,CAAC,EAAE;oBAC3C,MAAM,IAAI,KAAK,CAAC,GAAG,YAAY,+BAA+B,CAAC,CAAC;iBACnE;gBAED,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,2BAA2B,CAAC,OAAO,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;gBAE7F,MAAM,uBAAuB,GAAG,eAAe,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,CAAC,uBAAuB,CAAC;gBAC/F,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE;oBAChC,eAAe,CAAC,WAAW,CAAC,kBAAkB,CAAC,eAAe,CAAC,WAAW,EAAE,uBAAuB,CAAC,CAAC;iBACxG;gBAED,IAAI,CAAC,eAAe,CAAC,mBAAmB,EAAE;oBACtC,eAAe,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,eAAe,CAAC,iBAAiB,EAAE,uBAAuB,CAAC,CAAC;iBACpH;gBAED,OAAO,OAAO,CAAC;aAClB;YAED,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\n\r\nimport type { IMaterial } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\n\r\nconst NAME = \"MSFT_sRGBFactors\";\r\n\r\n/** @internal */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class MSFT_sRGBFactors implements IGLTFLoaderExtension {\r\n /** @internal */\r\n public readonly name = NAME;\r\n\r\n /** @internal */\r\n public enabled: boolean;\r\n\r\n private _loader: GLTFLoader;\r\n\r\n /** @internal */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n }\r\n\r\n /** @internal */\r\n public loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtraAsync<boolean>(context, material, this.name, (extraContext, extra) => {\r\n if (extra) {\r\n if (!(babylonMaterial instanceof PBRMaterial)) {\r\n throw new Error(`${extraContext}: Material type not supported`);\r\n }\r\n\r\n const promise = this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial);\r\n\r\n const useExactSrgbConversions = babylonMaterial.getScene().getEngine().useExactSrgbConversions;\r\n if (!babylonMaterial.albedoTexture) {\r\n babylonMaterial.albedoColor.toLinearSpaceToRef(babylonMaterial.albedoColor, useExactSrgbConversions);\r\n }\r\n\r\n if (!babylonMaterial.reflectivityTexture) {\r\n babylonMaterial.reflectivityColor.toLinearSpaceToRef(babylonMaterial.reflectivityColor, useExactSrgbConversions);\r\n }\r\n\r\n return promise;\r\n }\r\n\r\n return null;\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new MSFT_sRGBFactors(loader));\r\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,uCAAuC,CAAC;AACtD,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC","sourcesContent":["export * from \"./EXT_lights_image_based\";\r\nexport * from \"./EXT_mesh_gpu_instancing\";\r\nexport * from \"./EXT_meshopt_compression\";\r\nexport * from \"./EXT_texture_webp\";\r\nexport * from \"./KHR_draco_mesh_compression\";\r\nexport * from \"./KHR_lights_punctual\";\r\nexport * from \"./KHR_materials_pbrSpecularGlossiness\";\r\nexport * from \"./KHR_materials_unlit\";\r\nexport * from \"./KHR_materials_clearcoat\";\r\nexport * from \"./KHR_materials_iridescence\";\r\nexport * from \"./KHR_materials_anisotropy\";\r\nexport * from \"./KHR_materials_emissive_strength\";\r\nexport * from \"./KHR_materials_sheen\";\r\nexport * from \"./KHR_materials_specular\";\r\nexport * from \"./KHR_materials_ior\";\r\nexport * from \"./KHR_materials_variants\";\r\nexport * from \"./KHR_materials_transmission\";\r\nexport * from \"./KHR_materials_translucency\";\r\nexport * from \"./KHR_materials_volume\";\r\nexport * from \"./KHR_mesh_quantization\";\r\nexport * from \"./KHR_texture_basisu\";\r\nexport * from \"./KHR_texture_transform\";\r\nexport * from \"./KHR_xmp_json_ld\";\r\nexport * from \"./KHR_animation_pointer\";\r\nexport * from \"./MSFT_audio_emitter\";\r\nexport * from \"./MSFT_lod\";\r\nexport * from \"./MSFT_minecraftMesh\";\r\nexport * from \"./MSFT_sRGBFactors\";\r\nexport * from \"./ExtrasAsMetadata\";\r\n"]}
|