@onerjs/loaders 8.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/OBJ/index.d.ts +4 -0
- package/OBJ/index.js +5 -0
- package/OBJ/index.js.map +1 -0
- package/OBJ/mtlFileLoader.d.ts +41 -0
- package/OBJ/mtlFileLoader.js +231 -0
- package/OBJ/mtlFileLoader.js.map +1 -0
- package/OBJ/objFileLoader.d.ts +136 -0
- package/OBJ/objFileLoader.js +318 -0
- package/OBJ/objFileLoader.js.map +1 -0
- package/OBJ/objFileLoader.metadata.d.ts +4 -0
- package/OBJ/objFileLoader.metadata.js +5 -0
- package/OBJ/objFileLoader.metadata.js.map +1 -0
- package/OBJ/objLoadingOptions.d.ts +47 -0
- package/OBJ/objLoadingOptions.js +2 -0
- package/OBJ/objLoadingOptions.js.map +1 -0
- package/OBJ/solidParser.d.ts +174 -0
- package/OBJ/solidParser.js +862 -0
- package/OBJ/solidParser.js.map +1 -0
- package/SPLAT/index.d.ts +2 -0
- package/SPLAT/index.js +4 -0
- package/SPLAT/index.js.map +1 -0
- package/SPLAT/splatFileLoader.d.ts +88 -0
- package/SPLAT/splatFileLoader.js +562 -0
- package/SPLAT/splatFileLoader.js.map +1 -0
- package/SPLAT/splatFileLoader.metadata.d.ts +14 -0
- package/SPLAT/splatFileLoader.metadata.js +12 -0
- package/SPLAT/splatFileLoader.metadata.js.map +1 -0
- package/SPLAT/splatLoadingOptions.d.ts +13 -0
- package/SPLAT/splatLoadingOptions.js +2 -0
- package/SPLAT/splatLoadingOptions.js.map +1 -0
- package/STL/index.d.ts +1 -0
- package/STL/index.js +2 -0
- package/STL/index.js.map +1 -0
- package/STL/stlFileLoader.d.ts +78 -0
- package/STL/stlFileLoader.js +239 -0
- package/STL/stlFileLoader.js.map +1 -0
- package/STL/stlFileLoader.metadata.d.ts +8 -0
- package/STL/stlFileLoader.metadata.js +8 -0
- package/STL/stlFileLoader.metadata.js.map +1 -0
- package/bvh/bvhFileLoader.d.ts +69 -0
- package/bvh/bvhFileLoader.js +133 -0
- package/bvh/bvhFileLoader.js.map +1 -0
- package/bvh/bvhFileLoader.metadata.d.ts +8 -0
- package/bvh/bvhFileLoader.metadata.js +8 -0
- package/bvh/bvhFileLoader.metadata.js.map +1 -0
- package/bvh/bvhLoader.d.ts +14 -0
- package/bvh/bvhLoader.js +329 -0
- package/bvh/bvhLoader.js.map +1 -0
- package/bvh/bvhLoadingOptions.d.ts +9 -0
- package/bvh/bvhLoadingOptions.js +2 -0
- package/bvh/bvhLoadingOptions.js.map +1 -0
- package/bvh/index.d.ts +2 -0
- package/bvh/index.js +4 -0
- package/bvh/index.js.map +1 -0
- package/bvh/license.md +21 -0
- package/dynamic.d.ts +5 -0
- package/dynamic.js +57 -0
- package/dynamic.js.map +1 -0
- package/glTF/1.0/glTFBinaryExtension.d.ts +16 -0
- package/glTF/1.0/glTFBinaryExtension.js +65 -0
- package/glTF/1.0/glTFBinaryExtension.js.map +1 -0
- package/glTF/1.0/glTFLoader.d.ts +144 -0
- package/glTF/1.0/glTFLoader.js +1841 -0
- package/glTF/1.0/glTFLoader.js.map +1 -0
- package/glTF/1.0/glTFLoaderInterfaces.d.ts +412 -0
- package/glTF/1.0/glTFLoaderInterfaces.js +96 -0
- package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -0
- package/glTF/1.0/glTFLoaderUtils.d.ts +71 -0
- package/glTF/1.0/glTFLoaderUtils.js +255 -0
- package/glTF/1.0/glTFLoaderUtils.js.map +1 -0
- package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +13 -0
- package/glTF/1.0/glTFMaterialsCommonExtension.js +131 -0
- package/glTF/1.0/glTFMaterialsCommonExtension.js.map +1 -0
- package/glTF/1.0/index.d.ts +5 -0
- package/glTF/1.0/index.js +6 -0
- package/glTF/1.0/index.js.map +1 -0
- package/glTF/2.0/Extensions/EXT_lights_ies.d.ts +41 -0
- package/glTF/2.0/Extensions/EXT_lights_ies.js +84 -0
- package/glTF/2.0/Extensions/EXT_lights_ies.js.map +1 -0
- package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +48 -0
- package/glTF/2.0/Extensions/EXT_lights_image_based.js +116 -0
- package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -0
- package/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.d.ts +43 -0
- package/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.js +69 -0
- package/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.js.map +1 -0
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +39 -0
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +82 -0
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -0
- package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +39 -0
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js +51 -0
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -0
- package/glTF/2.0/Extensions/EXT_texture_avif.d.ts +34 -0
- package/glTF/2.0/Extensions/EXT_texture_avif.js +39 -0
- package/glTF/2.0/Extensions/EXT_texture_avif.js.map +1 -0
- package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +33 -0
- package/glTF/2.0/Extensions/EXT_texture_webp.js +38 -0
- package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -0
- package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +48 -0
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js +63 -0
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_animation_pointer.d.ts +47 -0
- package/glTF/2.0/Extensions/KHR_animation_pointer.data.d.ts +1 -0
- package/glTF/2.0/Extensions/KHR_animation_pointer.data.js +239 -0
- package/glTF/2.0/Extensions/KHR_animation_pointer.data.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_animation_pointer.js +78 -0
- package/glTF/2.0/Extensions/KHR_animation_pointer.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +47 -0
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +93 -0
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_interactivity/declarationMapper.d.ts +352 -0
- package/glTF/2.0/Extensions/KHR_interactivity/declarationMapper.js +1700 -0
- package/glTF/2.0/Extensions/KHR_interactivity/declarationMapper.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_interactivity/flowGraphGLTFDataProvider.d.ts +33 -0
- package/glTF/2.0/Extensions/KHR_interactivity/flowGraphGLTFDataProvider.js +20 -0
- package/glTF/2.0/Extensions/KHR_interactivity/flowGraphGLTFDataProvider.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_interactivity/index.d.ts +3 -0
- package/glTF/2.0/Extensions/KHR_interactivity/index.js +4 -0
- package/glTF/2.0/Extensions/KHR_interactivity/index.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_interactivity/interactivityGraphParser.d.ts +70 -0
- package/glTF/2.0/Extensions/KHR_interactivity/interactivityGraphParser.js +450 -0
- package/glTF/2.0/Extensions/KHR_interactivity/interactivityGraphParser.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_interactivity.d.ts +38 -0
- package/glTF/2.0/Extensions/KHR_interactivity.js +151 -0
- package/glTF/2.0/Extensions/KHR_interactivity.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +41 -0
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +92 -0
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_anisotropy.d.ts +42 -0
- package/glTF/2.0/Extensions/KHR_materials_anisotropy.js +61 -0
- package/glTF/2.0/Extensions/KHR_materials_anisotropy.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +43 -0
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +94 -0
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.d.ts +43 -0
- package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js +95 -0
- package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_dispersion.d.ts +43 -0
- package/glTF/2.0/Extensions/KHR_materials_dispersion.js +60 -0
- package/glTF/2.0/Extensions/KHR_materials_dispersion.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +42 -0
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +52 -0
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +46 -0
- package/glTF/2.0/Extensions/KHR_materials_ior.js +62 -0
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_iridescence.d.ts +42 -0
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js +71 -0
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +42 -0
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +81 -0
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +43 -0
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +85 -0
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +42 -0
- package/glTF/2.0/Extensions/KHR_materials_specular.js +85 -0
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +42 -0
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +306 -0
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +42 -0
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +73 -0
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +112 -0
- package/glTF/2.0/Extensions/KHR_materials_variants.js +263 -0
- package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +43 -0
- package/glTF/2.0/Extensions/KHR_materials_volume.js +86 -0
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +29 -0
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js +23 -0
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_node_hoverability.d.ts +31 -0
- package/glTF/2.0/Extensions/KHR_node_hoverability.js +190 -0
- package/glTF/2.0/Extensions/KHR_node_hoverability.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_node_selectability.d.ts +30 -0
- package/glTF/2.0/Extensions/KHR_node_selectability.js +124 -0
- package/glTF/2.0/Extensions/KHR_node_selectability.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_node_visibility.d.ts +30 -0
- package/glTF/2.0/Extensions/KHR_node_visibility.js +69 -0
- package/glTF/2.0/Extensions/KHR_node_visibility.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +33 -0
- package/glTF/2.0/Extensions/KHR_texture_basisu.js +38 -0
- package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +37 -0
- package/glTF/2.0/Extensions/KHR_texture_transform.js +59 -0
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +39 -0
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +48 -0
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -0
- package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +56 -0
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js +227 -0
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -0
- package/glTF/2.0/Extensions/MSFT_lod.d.ts +104 -0
- package/glTF/2.0/Extensions/MSFT_lod.js +338 -0
- package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -0
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +27 -0
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +41 -0
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -0
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +27 -0
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +42 -0
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -0
- package/glTF/2.0/Extensions/dynamic.d.ts +4 -0
- package/glTF/2.0/Extensions/dynamic.js +156 -0
- package/glTF/2.0/Extensions/dynamic.js.map +1 -0
- package/glTF/2.0/Extensions/gltfPathToObjectConverter.d.ts +45 -0
- package/glTF/2.0/Extensions/gltfPathToObjectConverter.js +101 -0
- package/glTF/2.0/Extensions/gltfPathToObjectConverter.js.map +1 -0
- package/glTF/2.0/Extensions/index.d.ts +39 -0
- package/glTF/2.0/Extensions/index.js +41 -0
- package/glTF/2.0/Extensions/index.js.map +1 -0
- package/glTF/2.0/Extensions/objectModelMapping.d.ts +289 -0
- package/glTF/2.0/Extensions/objectModelMapping.js +828 -0
- package/glTF/2.0/Extensions/objectModelMapping.js.map +1 -0
- package/glTF/2.0/glTFLoader.d.ts +429 -0
- package/glTF/2.0/glTFLoader.js +2408 -0
- package/glTF/2.0/glTFLoader.js.map +1 -0
- package/glTF/2.0/glTFLoaderAnimation.d.ts +42 -0
- package/glTF/2.0/glTFLoaderAnimation.js +80 -0
- package/glTF/2.0/glTFLoaderAnimation.js.map +1 -0
- package/glTF/2.0/glTFLoaderExtension.d.ts +165 -0
- package/glTF/2.0/glTFLoaderExtension.js +2 -0
- package/glTF/2.0/glTFLoaderExtension.js.map +1 -0
- package/glTF/2.0/glTFLoaderExtensionRegistry.d.ts +25 -0
- package/glTF/2.0/glTFLoaderExtensionRegistry.js +33 -0
- package/glTF/2.0/glTFLoaderExtensionRegistry.js.map +1 -0
- package/glTF/2.0/glTFLoaderInterfaces.d.ts +257 -0
- package/glTF/2.0/glTFLoaderInterfaces.js +2 -0
- package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -0
- package/glTF/2.0/index.d.ts +6 -0
- package/glTF/2.0/index.js +8 -0
- package/glTF/2.0/index.js.map +1 -0
- package/glTF/glTFFileLoader.d.ts +516 -0
- package/glTF/glTFFileLoader.js +968 -0
- package/glTF/glTFFileLoader.js.map +1 -0
- package/glTF/glTFFileLoader.metadata.d.ts +15 -0
- package/glTF/glTFFileLoader.metadata.js +18 -0
- package/glTF/glTFFileLoader.metadata.js.map +1 -0
- package/glTF/glTFValidation.d.ts +29 -0
- package/glTF/glTFValidation.js +126 -0
- package/glTF/glTFValidation.js.map +1 -0
- package/glTF/index.d.ts +5 -0
- package/glTF/index.js +7 -0
- package/glTF/index.js.map +1 -0
- package/index.d.ts +5 -0
- package/index.js +7 -0
- package/index.js.map +1 -0
- package/legacy/legacy-bvhFileLoader.d.ts +1 -0
- package/legacy/legacy-bvhFileLoader.js +16 -0
- package/legacy/legacy-bvhFileLoader.js.map +1 -0
- package/legacy/legacy-glTF.d.ts +2 -0
- package/legacy/legacy-glTF.js +19 -0
- package/legacy/legacy-glTF.js.map +1 -0
- package/legacy/legacy-glTF1.d.ts +2 -0
- package/legacy/legacy-glTF1.js +16 -0
- package/legacy/legacy-glTF1.js.map +1 -0
- package/legacy/legacy-glTF1FileLoader.d.ts +2 -0
- package/legacy/legacy-glTF1FileLoader.js +4 -0
- package/legacy/legacy-glTF1FileLoader.js.map +1 -0
- package/legacy/legacy-glTF2.d.ts +2 -0
- package/legacy/legacy-glTF2.js +35 -0
- package/legacy/legacy-glTF2.js.map +1 -0
- package/legacy/legacy-glTF2FileLoader.d.ts +2 -0
- package/legacy/legacy-glTF2FileLoader.js +4 -0
- package/legacy/legacy-glTF2FileLoader.js.map +1 -0
- package/legacy/legacy-glTFFileLoader.d.ts +3 -0
- package/legacy/legacy-glTFFileLoader.js +5 -0
- package/legacy/legacy-glTFFileLoader.js.map +1 -0
- package/legacy/legacy-objFileLoader.d.ts +1 -0
- package/legacy/legacy-objFileLoader.js +16 -0
- package/legacy/legacy-objFileLoader.js.map +1 -0
- package/legacy/legacy-stlFileLoader.d.ts +1 -0
- package/legacy/legacy-stlFileLoader.js +16 -0
- package/legacy/legacy-stlFileLoader.js.map +1 -0
- package/legacy/legacy.d.ts +7 -0
- package/legacy/legacy.js +10 -0
- package/legacy/legacy.js.map +1 -0
- package/license.md +71 -0
- package/package.json +49 -0
- package/readme.md +23 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Nullable } from "@babylonjs/core/types.js";
|
|
2
|
+
import type { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
|
|
3
|
+
import type { IScene } from "../glTFLoaderInterfaces.js";
|
|
4
|
+
import type { IGLTFLoaderExtension } from "../glTFLoaderExtension.js";
|
|
5
|
+
import { GLTFLoader } from "../glTFLoader.js";
|
|
6
|
+
declare module "../../glTFFileLoader.js" {
|
|
7
|
+
interface GLTFLoaderExtensionOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Defines options for the EXT_lights_image_based extension.
|
|
10
|
+
*/
|
|
11
|
+
["EXT_lights_image_based"]: {};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
declare module "babylonjs-gltf2interface" {
|
|
15
|
+
/** @internal */
|
|
16
|
+
interface IEXTLightsImageBased_LightImageBased {
|
|
17
|
+
_babylonTexture?: BaseTexture;
|
|
18
|
+
_loaded?: Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
|
|
23
|
+
*/
|
|
24
|
+
export declare class EXT_lights_image_based implements IGLTFLoaderExtension {
|
|
25
|
+
/**
|
|
26
|
+
* The name of this extension.
|
|
27
|
+
*/
|
|
28
|
+
readonly name = "EXT_lights_image_based";
|
|
29
|
+
/**
|
|
30
|
+
* Defines whether this extension is enabled.
|
|
31
|
+
*/
|
|
32
|
+
enabled: boolean;
|
|
33
|
+
private _loader;
|
|
34
|
+
private _lights?;
|
|
35
|
+
/**
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
constructor(loader: GLTFLoader);
|
|
39
|
+
/** @internal */
|
|
40
|
+
dispose(): void;
|
|
41
|
+
/** @internal */
|
|
42
|
+
onLoading(): void;
|
|
43
|
+
/**
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>>;
|
|
47
|
+
private _loadLightAsync;
|
|
48
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { SphericalHarmonics, SphericalPolynomial } from "@babylonjs/core/Maths/sphericalPolynomial.js";
|
|
2
|
+
import { Quaternion, Matrix } from "@babylonjs/core/Maths/math.vector.js";
|
|
3
|
+
import { RawCubeTexture } from "@babylonjs/core/Materials/Textures/rawCubeTexture.js";
|
|
4
|
+
import { GLTFLoader, ArrayItem } from "../glTFLoader.js";
|
|
5
|
+
import { registerGLTFExtension, unregisterGLTFExtension } from "../glTFLoaderExtensionRegistry.js";
|
|
6
|
+
const NAME = "EXT_lights_image_based";
|
|
7
|
+
/**
|
|
8
|
+
* [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_lights_image_based/README.md)
|
|
9
|
+
*/
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
11
|
+
export class EXT_lights_image_based {
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
constructor(loader) {
|
|
16
|
+
/**
|
|
17
|
+
* The name of this extension.
|
|
18
|
+
*/
|
|
19
|
+
this.name = NAME;
|
|
20
|
+
this._loader = loader;
|
|
21
|
+
this.enabled = this._loader.isExtensionUsed(NAME);
|
|
22
|
+
}
|
|
23
|
+
/** @internal */
|
|
24
|
+
dispose() {
|
|
25
|
+
this._loader = null;
|
|
26
|
+
delete this._lights;
|
|
27
|
+
}
|
|
28
|
+
/** @internal */
|
|
29
|
+
onLoading() {
|
|
30
|
+
const extensions = this._loader.gltf.extensions;
|
|
31
|
+
if (extensions && extensions[this.name]) {
|
|
32
|
+
const extension = extensions[this.name];
|
|
33
|
+
this._lights = extension.lights;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
40
|
+
loadSceneAsync(context, scene) {
|
|
41
|
+
return GLTFLoader.LoadExtensionAsync(context, scene, this.name, async (extensionContext, extension) => {
|
|
42
|
+
this._loader._allMaterialsDirtyRequired = true;
|
|
43
|
+
const promises = new Array();
|
|
44
|
+
promises.push(this._loader.loadSceneAsync(context, scene));
|
|
45
|
+
this._loader.logOpen(`${extensionContext}`);
|
|
46
|
+
const light = ArrayItem.Get(`${extensionContext}/light`, this._lights, extension.light);
|
|
47
|
+
promises.push(
|
|
48
|
+
// eslint-disable-next-line github/no-then
|
|
49
|
+
this._loadLightAsync(`/extensions/${this.name}/lights/${extension.light}`, light).then((texture) => {
|
|
50
|
+
this._loader.babylonScene.environmentTexture = texture;
|
|
51
|
+
}));
|
|
52
|
+
this._loader.logClose();
|
|
53
|
+
// eslint-disable-next-line github/no-then
|
|
54
|
+
return await Promise.all(promises).then(() => { });
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax
|
|
58
|
+
_loadLightAsync(context, light) {
|
|
59
|
+
if (!light._loaded) {
|
|
60
|
+
const promises = new Array();
|
|
61
|
+
this._loader.logOpen(`${context}`);
|
|
62
|
+
const imageData = new Array(light.specularImages.length);
|
|
63
|
+
for (let mipmap = 0; mipmap < light.specularImages.length; mipmap++) {
|
|
64
|
+
const faces = light.specularImages[mipmap];
|
|
65
|
+
imageData[mipmap] = new Array(faces.length);
|
|
66
|
+
for (let face = 0; face < faces.length; face++) {
|
|
67
|
+
const specularImageContext = `${context}/specularImages/${mipmap}/${face}`;
|
|
68
|
+
this._loader.logOpen(`${specularImageContext}`);
|
|
69
|
+
const index = faces[face];
|
|
70
|
+
const image = ArrayItem.Get(specularImageContext, this._loader.gltf.images, index);
|
|
71
|
+
promises.push(
|
|
72
|
+
// eslint-disable-next-line github/no-then
|
|
73
|
+
this._loader.loadImageAsync(`/images/${index}`, image).then((data) => {
|
|
74
|
+
imageData[mipmap][face] = data;
|
|
75
|
+
}));
|
|
76
|
+
this._loader.logClose();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
this._loader.logClose();
|
|
80
|
+
// eslint-disable-next-line github/no-then
|
|
81
|
+
light._loaded = Promise.all(promises).then(async () => {
|
|
82
|
+
const babylonTexture = new RawCubeTexture(this._loader.babylonScene, null, light.specularImageSize);
|
|
83
|
+
babylonTexture.name = light.name || "environment";
|
|
84
|
+
light._babylonTexture = babylonTexture;
|
|
85
|
+
if (light.intensity != undefined) {
|
|
86
|
+
babylonTexture.level = light.intensity;
|
|
87
|
+
}
|
|
88
|
+
if (light.rotation) {
|
|
89
|
+
let rotation = Quaternion.FromArray(light.rotation);
|
|
90
|
+
// Invert the rotation so that positive rotation is counter-clockwise.
|
|
91
|
+
if (!this._loader.babylonScene.useRightHandedSystem) {
|
|
92
|
+
rotation = Quaternion.Inverse(rotation);
|
|
93
|
+
}
|
|
94
|
+
Matrix.FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());
|
|
95
|
+
}
|
|
96
|
+
if (!light.irradianceCoefficients) {
|
|
97
|
+
throw new Error(`${context}: Irradiance coefficients are missing`);
|
|
98
|
+
}
|
|
99
|
+
const sphericalHarmonics = SphericalHarmonics.FromArray(light.irradianceCoefficients);
|
|
100
|
+
sphericalHarmonics.scaleInPlace(light.intensity);
|
|
101
|
+
sphericalHarmonics.convertIrradianceToLambertianRadiance();
|
|
102
|
+
const sphericalPolynomial = SphericalPolynomial.FromHarmonics(sphericalHarmonics);
|
|
103
|
+
// Compute the lod generation scale to fit exactly to the number of levels available.
|
|
104
|
+
const lodGenerationScale = (imageData.length - 1) / Math.log2(light.specularImageSize);
|
|
105
|
+
return await babylonTexture.updateRGBDAsync(imageData, sphericalPolynomial, lodGenerationScale);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
// eslint-disable-next-line github/no-then
|
|
109
|
+
return light._loaded.then(() => {
|
|
110
|
+
return light._babylonTexture;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
unregisterGLTFExtension(NAME);
|
|
115
|
+
registerGLTFExtension(NAME, true, (loader) => new EXT_lights_image_based(loader));
|
|
116
|
+
//# sourceMappingURL=EXT_lights_image_based.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EXT_lights_image_based.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/EXT_lights_image_based.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,qDAAuC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,6CAA+B;AAE5D,OAAO,EAAE,cAAc,EAAE,6DAA+C;AAKxE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG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,CAAC;IACP,CAAC;CACJ;AAED,uBAAuB,CAAC,IAAI,CAAC,CAAC;AAC9B,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { SphericalHarmonics, SphericalPolynomial } from \"core/Maths/sphericalPolynomial\";\r\nimport { Quaternion, Matrix } from \"core/Maths/math.vector\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { RawCubeTexture } from \"core/Materials/Textures/rawCubeTexture\";\r\n\r\nimport type { IEXTLightsImageBased_LightReferenceImageBased, IEXTLightsImageBased_LightImageBased, IEXTLightsImageBased } from \"babylonjs-gltf2interface\";\r\nimport type { IScene } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"EXT_lights_image_based\";\r\n\r\ndeclare module \"../../glTFFileLoader\" {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n export interface GLTFLoaderExtensionOptions {\r\n /**\r\n * Defines options for the EXT_lights_image_based extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"EXT_lights_image_based\"]: {};\r\n }\r\n}\r\n\r\ndeclare module \"babylonjs-gltf2interface\" {\r\n /** @internal */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n interface IEXTLightsImageBased_LightImageBased {\r\n _babylonTexture?: BaseTexture;\r\n _loaded?: Promise<void>;\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_lights_image_based/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class EXT_lights_image_based 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 _lights?: IEXTLightsImageBased_LightImageBased[];\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 delete this._lights;\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 IEXTLightsImageBased;\r\n this._lights = extension.lights;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n // eslint-disable-next-line no-restricted-syntax\r\n public loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IEXTLightsImageBased_LightReferenceImageBased>(context, scene, this.name, async (extensionContext, extension) => {\r\n this._loader._allMaterialsDirtyRequired = true;\r\n\r\n const promises = new Array<Promise<any>>();\r\n\r\n promises.push(this._loader.loadSceneAsync(context, scene));\r\n\r\n this._loader.logOpen(`${extensionContext}`);\r\n\r\n const light = ArrayItem.Get(`${extensionContext}/light`, this._lights, extension.light);\r\n promises.push(\r\n // eslint-disable-next-line github/no-then\r\n this._loadLightAsync(`/extensions/${this.name}/lights/${extension.light}`, light).then((texture) => {\r\n this._loader.babylonScene.environmentTexture = texture;\r\n })\r\n );\r\n\r\n this._loader.logClose();\r\n\r\n // eslint-disable-next-line github/no-then\r\n return await Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\r\n private _loadLightAsync(context: string, light: IEXTLightsImageBased_LightImageBased): Promise<BaseTexture> {\r\n if (!light._loaded) {\r\n const promises = new Array<Promise<any>>();\r\n\r\n this._loader.logOpen(`${context}`);\r\n\r\n const imageData = new Array<Array<ArrayBufferView>>(light.specularImages.length);\r\n for (let mipmap = 0; mipmap < light.specularImages.length; mipmap++) {\r\n const faces = light.specularImages[mipmap];\r\n imageData[mipmap] = new Array<ArrayBufferView>(faces.length);\r\n for (let face = 0; face < faces.length; face++) {\r\n const specularImageContext = `${context}/specularImages/${mipmap}/${face}`;\r\n this._loader.logOpen(`${specularImageContext}`);\r\n\r\n const index = faces[face];\r\n const image = ArrayItem.Get(specularImageContext, this._loader.gltf.images, index);\r\n promises.push(\r\n // eslint-disable-next-line github/no-then\r\n this._loader.loadImageAsync(`/images/${index}`, image).then((data) => {\r\n imageData[mipmap][face] = data;\r\n })\r\n );\r\n\r\n this._loader.logClose();\r\n }\r\n }\r\n\r\n this._loader.logClose();\r\n\r\n // eslint-disable-next-line github/no-then\r\n light._loaded = Promise.all(promises).then(async () => {\r\n const babylonTexture = new RawCubeTexture(this._loader.babylonScene, null, light.specularImageSize);\r\n babylonTexture.name = light.name || \"environment\";\r\n light._babylonTexture = babylonTexture;\r\n\r\n if (light.intensity != undefined) {\r\n babylonTexture.level = light.intensity;\r\n }\r\n\r\n if (light.rotation) {\r\n let rotation = Quaternion.FromArray(light.rotation);\r\n\r\n // Invert the rotation so that positive rotation is counter-clockwise.\r\n if (!this._loader.babylonScene.useRightHandedSystem) {\r\n rotation = Quaternion.Inverse(rotation);\r\n }\r\n\r\n Matrix.FromQuaternionToRef(rotation, babylonTexture.getReflectionTextureMatrix());\r\n }\r\n\r\n if (!light.irradianceCoefficients) {\r\n throw new Error(`${context}: Irradiance coefficients are missing`);\r\n }\r\n\r\n const sphericalHarmonics = SphericalHarmonics.FromArray(light.irradianceCoefficients);\r\n sphericalHarmonics.scaleInPlace(light.intensity);\r\n\r\n sphericalHarmonics.convertIrradianceToLambertianRadiance();\r\n const sphericalPolynomial = SphericalPolynomial.FromHarmonics(sphericalHarmonics);\r\n\r\n // Compute the lod generation scale to fit exactly to the number of levels available.\r\n const lodGenerationScale = (imageData.length - 1) / Math.log2(light.specularImageSize);\r\n return await babylonTexture.updateRGBDAsync(imageData, sphericalPolynomial, lodGenerationScale);\r\n });\r\n }\r\n\r\n // eslint-disable-next-line github/no-then\r\n return light._loaded.then(() => {\r\n return light._babylonTexture!;\r\n });\r\n }\r\n}\r\n\r\nunregisterGLTFExtension(NAME);\r\nregisterGLTFExtension(NAME, true, (loader) => new EXT_lights_image_based(loader));\r\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Nullable } from "@babylonjs/core/types.js";
|
|
2
|
+
import type { Material } from "@babylonjs/core/Materials/material.js";
|
|
3
|
+
import type { IMaterial } from "../glTFLoaderInterfaces.js";
|
|
4
|
+
import type { IGLTFLoaderExtension } from "../glTFLoaderExtension.js";
|
|
5
|
+
import { GLTFLoader } from "../glTFLoader.js";
|
|
6
|
+
declare module "../../glTFFileLoader.js" {
|
|
7
|
+
interface GLTFLoaderExtensionOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Defines options for the EXT_materials_diffuse_roughness extension.
|
|
10
|
+
*/
|
|
11
|
+
["EXT_materials_diffuse_roughness"]: {};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* [Specification](https://github.com/KhronosGroup/glTF/blob/fdee35425ae560ea378092e38977216d63a094ec/extensions/2.0/Khronos/EXT_materials_diffuse_roughness/README.md)
|
|
16
|
+
* @experimental
|
|
17
|
+
*/
|
|
18
|
+
export declare class EXT_materials_diffuse_roughness implements IGLTFLoaderExtension {
|
|
19
|
+
/**
|
|
20
|
+
* The name of this extension.
|
|
21
|
+
*/
|
|
22
|
+
readonly name = "EXT_materials_diffuse_roughness";
|
|
23
|
+
/**
|
|
24
|
+
* Defines whether this extension is enabled.
|
|
25
|
+
*/
|
|
26
|
+
enabled: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Defines a number that determines the order the extensions are applied.
|
|
29
|
+
*/
|
|
30
|
+
order: number;
|
|
31
|
+
private _loader;
|
|
32
|
+
/**
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
constructor(loader: GLTFLoader);
|
|
36
|
+
/** @internal */
|
|
37
|
+
dispose(): void;
|
|
38
|
+
/**
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>>;
|
|
42
|
+
private _loadDiffuseRoughnessPropertiesAsync;
|
|
43
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
|
|
2
|
+
import { GLTFLoader } from "../glTFLoader.js";
|
|
3
|
+
import { registerGLTFExtension, unregisterGLTFExtension } from "../glTFLoaderExtensionRegistry.js";
|
|
4
|
+
import { Constants } from "@babylonjs/core/Engines/constants.js";
|
|
5
|
+
const NAME = "EXT_materials_diffuse_roughness";
|
|
6
|
+
/**
|
|
7
|
+
* [Specification](https://github.com/KhronosGroup/glTF/blob/fdee35425ae560ea378092e38977216d63a094ec/extensions/2.0/Khronos/EXT_materials_diffuse_roughness/README.md)
|
|
8
|
+
* @experimental
|
|
9
|
+
*/
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
11
|
+
export class EXT_materials_diffuse_roughness {
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
constructor(loader) {
|
|
16
|
+
/**
|
|
17
|
+
* The name of this extension.
|
|
18
|
+
*/
|
|
19
|
+
this.name = NAME;
|
|
20
|
+
/**
|
|
21
|
+
* Defines a number that determines the order the extensions are applied.
|
|
22
|
+
*/
|
|
23
|
+
this.order = 190;
|
|
24
|
+
this._loader = loader;
|
|
25
|
+
this.enabled = this._loader.isExtensionUsed(NAME);
|
|
26
|
+
}
|
|
27
|
+
/** @internal */
|
|
28
|
+
dispose() {
|
|
29
|
+
this._loader = null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax
|
|
35
|
+
loadMaterialPropertiesAsync(context, material, babylonMaterial) {
|
|
36
|
+
return GLTFLoader.LoadExtensionAsync(context, material, this.name, async (extensionContext, extension) => {
|
|
37
|
+
const promises = new Array();
|
|
38
|
+
promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));
|
|
39
|
+
promises.push(this._loadDiffuseRoughnessPropertiesAsync(extensionContext, extension, babylonMaterial));
|
|
40
|
+
// eslint-disable-next-line github/no-then
|
|
41
|
+
return await Promise.all(promises).then(() => { });
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax
|
|
45
|
+
_loadDiffuseRoughnessPropertiesAsync(context, properties, babylonMaterial) {
|
|
46
|
+
if (!(babylonMaterial instanceof PBRMaterial)) {
|
|
47
|
+
throw new Error(`${context}: Material type not supported`);
|
|
48
|
+
}
|
|
49
|
+
const promises = new Array();
|
|
50
|
+
babylonMaterial.brdf.baseDiffuseModel = Constants.MATERIAL_DIFFUSE_MODEL_E_OREN_NAYAR;
|
|
51
|
+
if (properties.diffuseRoughnessFactor != undefined) {
|
|
52
|
+
babylonMaterial.baseDiffuseRoughness = properties.diffuseRoughnessFactor;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
babylonMaterial.baseDiffuseRoughness = 0;
|
|
56
|
+
}
|
|
57
|
+
if (properties.diffuseRoughnessTexture) {
|
|
58
|
+
promises.push(this._loader.loadTextureInfoAsync(`${context}/diffuseRoughnessTexture`, properties.diffuseRoughnessTexture, (texture) => {
|
|
59
|
+
texture.name = `${babylonMaterial.name} (Diffuse Roughness)`;
|
|
60
|
+
babylonMaterial.baseDiffuseRoughnessTexture = texture;
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
// eslint-disable-next-line github/no-then
|
|
64
|
+
return Promise.all(promises).then(() => { });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
unregisterGLTFExtension(NAME);
|
|
68
|
+
registerGLTFExtension(NAME, true, (loader) => new EXT_materials_diffuse_roughness(loader));
|
|
69
|
+
//# sourceMappingURL=EXT_materials_diffuse_roughness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EXT_materials_diffuse_roughness.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAK7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,6CAA+B;AAEnD,MAAM,IAAI,GAAG,iCAAiC,CAAC;AAa/C;;;GAGG;AACH,gEAAgE;AAChE,MAAM,OAAO,+BAA+B;IAkBxC;;OAEG;IACH,YAAY,MAAkB;QApB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAO5B;;WAEG;QACI,UAAK,GAAG,GAAG,CAAC;QAQf,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;IACH,2FAA2F;IACpF,2BAA2B,CAAC,OAAe,EAAE,QAAmB,EAAE,eAAyB;QAC9F,OAAO,UAAU,CAAC,kBAAkB,CAAgC,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,EAA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7D,eAAe,CAAC,2BAA2B,GAAG,OAAO,CAAC;YAC1D,CAAC,CAAC,CACL,CAAC;QACN,CAAC;QAED,0CAA0C;QAC1C,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAChD,CAAC;CACJ;AAED,uBAAuB,CAAC,IAAI,CAAC,CAAC;AAC9B,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,+BAA+B,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { Material } from \"core/Materials/material\";\r\n\r\nimport type { IMaterial } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader } from \"../glTFLoader\";\r\nimport type { IEXTMaterialsDiffuseRoughness } from \"babylonjs-gltf2interface\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\nimport { Constants } from \"core/Engines/constants\";\r\n\r\nconst NAME = \"EXT_materials_diffuse_roughness\";\r\n\r\ndeclare module \"../../glTFFileLoader\" {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n export interface GLTFLoaderExtensionOptions {\r\n /**\r\n * Defines options for the EXT_materials_diffuse_roughness extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"EXT_materials_diffuse_roughness\"]: {};\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/fdee35425ae560ea378092e38977216d63a094ec/extensions/2.0/Khronos/EXT_materials_diffuse_roughness/README.md)\r\n * @experimental\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class EXT_materials_diffuse_roughness 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 = 190;\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 // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\r\n public loadMaterialPropertiesAsync(context: string, material: IMaterial, babylonMaterial: Material): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IEXTMaterialsDiffuseRoughness>(context, material, this.name, async (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n promises.push(this._loader.loadMaterialPropertiesAsync(context, material, babylonMaterial));\r\n promises.push(this._loadDiffuseRoughnessPropertiesAsync(extensionContext, extension, babylonMaterial));\r\n // eslint-disable-next-line github/no-then\r\n return await Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/promise-function-async, no-restricted-syntax\r\n private _loadDiffuseRoughnessPropertiesAsync(context: string, properties: IEXTMaterialsDiffuseRoughness, babylonMaterial: Material): Promise<void> {\r\n if (!(babylonMaterial instanceof PBRMaterial)) {\r\n throw new Error(`${context}: Material type not supported`);\r\n }\r\n\r\n const promises = new Array<Promise<any>>();\r\n\r\n babylonMaterial.brdf.baseDiffuseModel = Constants.MATERIAL_DIFFUSE_MODEL_E_OREN_NAYAR;\r\n\r\n if (properties.diffuseRoughnessFactor != undefined) {\r\n babylonMaterial.baseDiffuseRoughness = properties.diffuseRoughnessFactor;\r\n } else {\r\n babylonMaterial.baseDiffuseRoughness = 0;\r\n }\r\n\r\n if (properties.diffuseRoughnessTexture) {\r\n promises.push(\r\n this._loader.loadTextureInfoAsync(`${context}/diffuseRoughnessTexture`, properties.diffuseRoughnessTexture, (texture) => {\r\n texture.name = `${babylonMaterial.name} (Diffuse Roughness)`;\r\n babylonMaterial.baseDiffuseRoughnessTexture = texture;\r\n })\r\n );\r\n }\r\n\r\n // eslint-disable-next-line github/no-then\r\n return Promise.all(promises).then(() => {});\r\n }\r\n}\r\n\r\nunregisterGLTFExtension(NAME);\r\nregisterGLTFExtension(NAME, true, (loader) => new EXT_materials_diffuse_roughness(loader));\r\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { TransformNode } from "@babylonjs/core/Meshes/transformNode.js";
|
|
2
|
+
import type { Nullable } from "@babylonjs/core/types.js";
|
|
3
|
+
import { GLTFLoader } from "../glTFLoader.js";
|
|
4
|
+
import type { IGLTFLoaderExtension } from "../glTFLoaderExtension.js";
|
|
5
|
+
import type { INode } from "../glTFLoaderInterfaces.js";
|
|
6
|
+
import "@babylonjs/core/Meshes/thinInstanceMesh.js";
|
|
7
|
+
declare module "../../glTFFileLoader.js" {
|
|
8
|
+
interface GLTFLoaderExtensionOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Defines options for the EXT_mesh_gpu_instancing extension.
|
|
11
|
+
*/
|
|
12
|
+
["EXT_mesh_gpu_instancing"]: {};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_mesh_gpu_instancing/README.md)
|
|
17
|
+
* [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)
|
|
18
|
+
*/
|
|
19
|
+
export declare class EXT_mesh_gpu_instancing implements IGLTFLoaderExtension {
|
|
20
|
+
/**
|
|
21
|
+
* The name of this extension.
|
|
22
|
+
*/
|
|
23
|
+
readonly name = "EXT_mesh_gpu_instancing";
|
|
24
|
+
/**
|
|
25
|
+
* Defines whether this extension is enabled.
|
|
26
|
+
*/
|
|
27
|
+
enabled: boolean;
|
|
28
|
+
private _loader;
|
|
29
|
+
/**
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
constructor(loader: GLTFLoader);
|
|
33
|
+
/** @internal */
|
|
34
|
+
dispose(): void;
|
|
35
|
+
/**
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Vector3, Quaternion, Matrix, TmpVectors } from "@babylonjs/core/Maths/math.vector.js";
|
|
2
|
+
import { GLTFLoader, ArrayItem } from "../glTFLoader.js";
|
|
3
|
+
import { registerGLTFExtension, unregisterGLTFExtension } from "../glTFLoaderExtensionRegistry.js";
|
|
4
|
+
import "@babylonjs/core/Meshes/thinInstanceMesh.js";
|
|
5
|
+
const NAME = "EXT_mesh_gpu_instancing";
|
|
6
|
+
/**
|
|
7
|
+
* [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_mesh_gpu_instancing/README.md)
|
|
8
|
+
* [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)
|
|
9
|
+
*/
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
11
|
+
export class EXT_mesh_gpu_instancing {
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
constructor(loader) {
|
|
16
|
+
/**
|
|
17
|
+
* The name of this extension.
|
|
18
|
+
*/
|
|
19
|
+
this.name = NAME;
|
|
20
|
+
this._loader = loader;
|
|
21
|
+
this.enabled = this._loader.isExtensionUsed(NAME);
|
|
22
|
+
}
|
|
23
|
+
/** @internal */
|
|
24
|
+
dispose() {
|
|
25
|
+
this._loader = null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
31
|
+
loadNodeAsync(context, node, assign) {
|
|
32
|
+
return GLTFLoader.LoadExtensionAsync(context, node, this.name, async (extensionContext, extension) => {
|
|
33
|
+
this._loader._disableInstancedMesh++;
|
|
34
|
+
const promise = this._loader.loadNodeAsync(`/nodes/${node.index}`, node, assign);
|
|
35
|
+
this._loader._disableInstancedMesh--;
|
|
36
|
+
if (!node._primitiveBabylonMeshes) {
|
|
37
|
+
return await promise;
|
|
38
|
+
}
|
|
39
|
+
const promises = new Array();
|
|
40
|
+
let instanceCount = 0;
|
|
41
|
+
const loadAttribute = (attribute) => {
|
|
42
|
+
if (extension.attributes[attribute] == undefined) {
|
|
43
|
+
promises.push(Promise.resolve(null));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const accessor = ArrayItem.Get(`${extensionContext}/attributes/${attribute}`, this._loader.gltf.accessors, extension.attributes[attribute]);
|
|
47
|
+
promises.push(this._loader._loadFloatAccessorAsync(`/accessors/${accessor.bufferView}`, accessor));
|
|
48
|
+
if (instanceCount === 0) {
|
|
49
|
+
instanceCount = accessor.count;
|
|
50
|
+
}
|
|
51
|
+
else if (instanceCount !== accessor.count) {
|
|
52
|
+
throw new Error(`${extensionContext}/attributes: Instance buffer accessors do not have the same count.`);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
loadAttribute("TRANSLATION");
|
|
56
|
+
loadAttribute("ROTATION");
|
|
57
|
+
loadAttribute("SCALE");
|
|
58
|
+
// eslint-disable-next-line github/no-then
|
|
59
|
+
return await promise.then(async (babylonTransformNode) => {
|
|
60
|
+
const [translationBuffer, rotationBuffer, scaleBuffer] = await Promise.all(promises);
|
|
61
|
+
const matrices = new Float32Array(instanceCount * 16);
|
|
62
|
+
TmpVectors.Vector3[0].copyFromFloats(0, 0, 0); // translation
|
|
63
|
+
TmpVectors.Quaternion[0].copyFromFloats(0, 0, 0, 1); // rotation
|
|
64
|
+
TmpVectors.Vector3[1].copyFromFloats(1, 1, 1); // scale
|
|
65
|
+
for (let i = 0; i < instanceCount; ++i) {
|
|
66
|
+
translationBuffer && Vector3.FromArrayToRef(translationBuffer, i * 3, TmpVectors.Vector3[0]);
|
|
67
|
+
rotationBuffer && Quaternion.FromArrayToRef(rotationBuffer, i * 4, TmpVectors.Quaternion[0]);
|
|
68
|
+
scaleBuffer && Vector3.FromArrayToRef(scaleBuffer, i * 3, TmpVectors.Vector3[1]);
|
|
69
|
+
Matrix.ComposeToRef(TmpVectors.Vector3[1], TmpVectors.Quaternion[0], TmpVectors.Vector3[0], TmpVectors.Matrix[0]);
|
|
70
|
+
TmpVectors.Matrix[0].copyToArray(matrices, i * 16);
|
|
71
|
+
}
|
|
72
|
+
for (const babylonMesh of node._primitiveBabylonMeshes) {
|
|
73
|
+
babylonMesh.thinInstanceSetBuffer("matrix", matrices, 16, true);
|
|
74
|
+
}
|
|
75
|
+
return babylonTransformNode;
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
unregisterGLTFExtension(NAME);
|
|
81
|
+
registerGLTFExtension(NAME, true, (loader) => new EXT_mesh_gpu_instancing(loader));
|
|
82
|
+
//# sourceMappingURL=EXT_mesh_gpu_instancing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EXT_mesh_gpu_instancing.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,6CAA+B;AAIjF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAItD,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,oDAAsC;AAEtC,MAAM,IAAI,GAAG,yBAAyB,CAAC;AAavC;;;GAGG;AACH,gEAAgE;AAChE,MAAM,OAAO,uBAAuB;I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import { Vector3, Quaternion, Matrix, TmpVectors } from \"core/Maths/math.vector\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport type { TransformNode } from \"core/Meshes/transformNode\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport type { INode } from \"../glTFLoaderInterfaces\";\r\nimport type { IEXTMeshGpuInstancing } from \"babylonjs-gltf2interface\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nimport \"core/Meshes/thinInstanceMesh\";\r\n\r\nconst NAME = \"EXT_mesh_gpu_instancing\";\r\n\r\ndeclare module \"../../glTFFileLoader\" {\r\n // eslint-disable-next-line jsdoc/require-jsdoc, @typescript-eslint/naming-convention\r\n export interface GLTFLoaderExtensionOptions {\r\n /**\r\n * Defines options for the EXT_mesh_gpu_instancing extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"EXT_mesh_gpu_instancing\"]: {};\r\n }\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_mesh_gpu_instancing/README.md)\r\n * [Playground Sample](https://playground.babylonjs.com/#QFIGLW#9)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class EXT_mesh_gpu_instancing 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 // eslint-disable-next-line no-restricted-syntax\r\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\r\n return GLTFLoader.LoadExtensionAsync<IEXTMeshGpuInstancing, TransformNode>(context, node, this.name, async (extensionContext, extension) => {\r\n this._loader._disableInstancedMesh++;\r\n\r\n const promise = this._loader.loadNodeAsync(`/nodes/${node.index}`, node, assign);\r\n\r\n this._loader._disableInstancedMesh--;\r\n\r\n if (!node._primitiveBabylonMeshes) {\r\n return await promise;\r\n }\r\n\r\n const promises = new Array<Promise<Nullable<Float32Array>>>();\r\n let instanceCount = 0;\r\n\r\n const loadAttribute = (attribute: string) => {\r\n if (extension.attributes[attribute] == undefined) {\r\n promises.push(Promise.resolve(null));\r\n return;\r\n }\r\n\r\n const accessor = ArrayItem.Get(`${extensionContext}/attributes/${attribute}`, this._loader.gltf.accessors, extension.attributes[attribute]);\r\n promises.push(this._loader._loadFloatAccessorAsync(`/accessors/${accessor.bufferView}`, accessor));\r\n\r\n if (instanceCount === 0) {\r\n instanceCount = accessor.count;\r\n } else if (instanceCount !== accessor.count) {\r\n throw new Error(`${extensionContext}/attributes: Instance buffer accessors do not have the same count.`);\r\n }\r\n };\r\n\r\n loadAttribute(\"TRANSLATION\");\r\n loadAttribute(\"ROTATION\");\r\n loadAttribute(\"SCALE\");\r\n\r\n // eslint-disable-next-line github/no-then\r\n return await promise.then(async (babylonTransformNode) => {\r\n const [translationBuffer, rotationBuffer, scaleBuffer] = await Promise.all(promises);\r\n const matrices = new Float32Array(instanceCount * 16);\r\n TmpVectors.Vector3[0].copyFromFloats(0, 0, 0); // translation\r\n TmpVectors.Quaternion[0].copyFromFloats(0, 0, 0, 1); // rotation\r\n TmpVectors.Vector3[1].copyFromFloats(1, 1, 1); // scale\r\n for (let i = 0; i < instanceCount; ++i) {\r\n translationBuffer && Vector3.FromArrayToRef(translationBuffer, i * 3, TmpVectors.Vector3[0]);\r\n rotationBuffer && Quaternion.FromArrayToRef(rotationBuffer, i * 4, TmpVectors.Quaternion[0]);\r\n scaleBuffer && Vector3.FromArrayToRef(scaleBuffer, i * 3, TmpVectors.Vector3[1]);\r\n\r\n Matrix.ComposeToRef(TmpVectors.Vector3[1], TmpVectors.Quaternion[0], TmpVectors.Vector3[0], TmpVectors.Matrix[0]);\r\n\r\n TmpVectors.Matrix[0].copyToArray(matrices, i * 16);\r\n }\r\n for (const babylonMesh of node._primitiveBabylonMeshes!) {\r\n (babylonMesh as Mesh).thinInstanceSetBuffer(\"matrix\", matrices, 16, true);\r\n }\r\n return babylonTransformNode;\r\n });\r\n });\r\n }\r\n}\r\n\r\nunregisterGLTFExtension(NAME);\r\nregisterGLTFExtension(NAME, true, (loader) => new EXT_mesh_gpu_instancing(loader));\r\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Nullable } from "@babylonjs/core/types.js";
|
|
2
|
+
import type { IGLTFLoaderExtension } from "../glTFLoaderExtension.js";
|
|
3
|
+
import { GLTFLoader } from "../glTFLoader.js";
|
|
4
|
+
import type { IBufferView } from "../glTFLoaderInterfaces.js";
|
|
5
|
+
declare module "../../glTFFileLoader.js" {
|
|
6
|
+
interface GLTFLoaderExtensionOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Defines options for the EXT_meshopt_compression extension.
|
|
9
|
+
*/
|
|
10
|
+
["EXT_meshopt_compression"]: {};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_meshopt_compression/README.md)
|
|
15
|
+
*
|
|
16
|
+
* This extension uses a WebAssembly decoder module from https://github.com/zeux/meshoptimizer/tree/master/js
|
|
17
|
+
* @since 5.0.0
|
|
18
|
+
*/
|
|
19
|
+
export declare class EXT_meshopt_compression implements IGLTFLoaderExtension {
|
|
20
|
+
/**
|
|
21
|
+
* The name of this extension.
|
|
22
|
+
*/
|
|
23
|
+
readonly name = "EXT_meshopt_compression";
|
|
24
|
+
/**
|
|
25
|
+
* Defines whether this extension is enabled.
|
|
26
|
+
*/
|
|
27
|
+
enabled: boolean;
|
|
28
|
+
private _loader;
|
|
29
|
+
/**
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
constructor(loader: GLTFLoader);
|
|
33
|
+
/** @internal */
|
|
34
|
+
dispose(): void;
|
|
35
|
+
/**
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
loadBufferViewAsync(context: string, bufferView: IBufferView): Nullable<Promise<ArrayBufferView>>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ArrayItem, GLTFLoader } from "../glTFLoader.js";
|
|
2
|
+
import { MeshoptCompression } from "@babylonjs/core/Meshes/Compression/meshoptCompression.js";
|
|
3
|
+
import { registerGLTFExtension, unregisterGLTFExtension } from "../glTFLoaderExtensionRegistry.js";
|
|
4
|
+
const NAME = "EXT_meshopt_compression";
|
|
5
|
+
/**
|
|
6
|
+
* [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_meshopt_compression/README.md)
|
|
7
|
+
*
|
|
8
|
+
* This extension uses a WebAssembly decoder module from https://github.com/zeux/meshoptimizer/tree/master/js
|
|
9
|
+
* @since 5.0.0
|
|
10
|
+
*/
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
12
|
+
export class EXT_meshopt_compression {
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
constructor(loader) {
|
|
17
|
+
/**
|
|
18
|
+
* The name of this extension.
|
|
19
|
+
*/
|
|
20
|
+
this.name = NAME;
|
|
21
|
+
this.enabled = loader.isExtensionUsed(NAME);
|
|
22
|
+
this._loader = loader;
|
|
23
|
+
}
|
|
24
|
+
/** @internal */
|
|
25
|
+
dispose() {
|
|
26
|
+
this._loader = null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
32
|
+
loadBufferViewAsync(context, bufferView) {
|
|
33
|
+
return GLTFLoader.LoadExtensionAsync(context, bufferView, this.name, async (extensionContext, extension) => {
|
|
34
|
+
const bufferViewMeshopt = bufferView;
|
|
35
|
+
if (bufferViewMeshopt._meshOptData) {
|
|
36
|
+
return await bufferViewMeshopt._meshOptData;
|
|
37
|
+
}
|
|
38
|
+
const buffer = ArrayItem.Get(`${context}/buffer`, this._loader.gltf.buffers, extension.buffer);
|
|
39
|
+
bufferViewMeshopt._meshOptData = this._loader
|
|
40
|
+
.loadBufferAsync(`/buffers/${buffer.index}`, buffer, extension.byteOffset || 0, extension.byteLength)
|
|
41
|
+
// eslint-disable-next-line github/no-then
|
|
42
|
+
.then(async (buffer) => {
|
|
43
|
+
return await MeshoptCompression.Default.decodeGltfBufferAsync(buffer, extension.count, extension.byteStride, extension.mode, extension.filter);
|
|
44
|
+
});
|
|
45
|
+
return await bufferViewMeshopt._meshOptData;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
unregisterGLTFExtension(NAME);
|
|
50
|
+
registerGLTFExtension(NAME, true, (loader) => new EXT_meshopt_compression(loader));
|
|
51
|
+
//# sourceMappingURL=EXT_meshopt_compression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EXT_meshopt_compression.js","sourceRoot":"","sources":["../../../../../../dev/loaders/src/glTF/2.0/Extensions/EXT_meshopt_compression.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,EAAE,kBAAkB,EAAE,iEAAmD;AAChF,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEhG,MAAM,IAAI,GAAG,yBAAyB,CAAC;AAiBvC;;;;;GAKG;AACH,gEAAgE;AAChE,MAAM,OAAO,u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AAO,MAAM,iBAAiB,CAAC,YAAY,CAAC;QAChD,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,uBAAuB,CAAC,IAAI,CAAC,CAAC;AAC9B,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,uBAAuB,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { ArrayItem, GLTFLoader } from \"../glTFLoader\";\r\nimport type { IBufferView } from \"../glTFLoaderInterfaces\";\r\nimport type { IEXTMeshoptCompression } from \"babylonjs-gltf2interface\";\r\nimport { MeshoptCompression } from \"core/Meshes/Compression/meshoptCompression\";\r\nimport { registerGLTFExtension, unregisterGLTFExtension } from \"../glTFLoaderExtensionRegistry\";\r\n\r\nconst NAME = \"EXT_meshopt_compression\";\r\n\r\ndeclare module \"../../glTFFileLoader\" {\r\n // eslint-disable-next-line jsdoc/require-jsdoc, @typescript-eslint/naming-convention\r\n export interface GLTFLoaderExtensionOptions {\r\n /**\r\n * Defines options for the EXT_meshopt_compression extension.\r\n */\r\n // NOTE: Don't use NAME here as it will break the UMD type declarations.\r\n [\"EXT_meshopt_compression\"]: {};\r\n }\r\n}\r\n\r\ninterface IBufferViewMeshopt extends IBufferView {\r\n _meshOptData?: Promise<ArrayBufferView>;\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_meshopt_compression/README.md)\r\n *\r\n * This extension uses a WebAssembly decoder module from https://github.com/zeux/meshoptimizer/tree/master/js\r\n * @since 5.0.0\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class EXT_meshopt_compression 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.enabled = loader.isExtensionUsed(NAME);\r\n this._loader = loader;\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 // eslint-disable-next-line no-restricted-syntax\r\n public loadBufferViewAsync(context: string, bufferView: IBufferView): Nullable<Promise<ArrayBufferView>> {\r\n return GLTFLoader.LoadExtensionAsync<IEXTMeshoptCompression, ArrayBufferView>(context, bufferView, this.name, async (extensionContext, extension) => {\r\n const bufferViewMeshopt = bufferView as IBufferViewMeshopt;\r\n if (bufferViewMeshopt._meshOptData) {\r\n return await bufferViewMeshopt._meshOptData;\r\n }\r\n\r\n const buffer = ArrayItem.Get(`${context}/buffer`, this._loader.gltf.buffers, extension.buffer);\r\n bufferViewMeshopt._meshOptData = this._loader\r\n .loadBufferAsync(`/buffers/${buffer.index}`, buffer, extension.byteOffset || 0, extension.byteLength)\r\n // eslint-disable-next-line github/no-then\r\n .then(async (buffer) => {\r\n return await MeshoptCompression.Default.decodeGltfBufferAsync(buffer as Uint8Array, extension.count, extension.byteStride, extension.mode, extension.filter);\r\n });\r\n\r\n return await bufferViewMeshopt._meshOptData;\r\n });\r\n }\r\n}\r\n\r\nunregisterGLTFExtension(NAME);\r\nregisterGLTFExtension(NAME, true, (loader) => new EXT_meshopt_compression(loader));\r\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { IGLTFLoaderExtension } from "../glTFLoaderExtension.js";
|
|
2
|
+
import { GLTFLoader } from "../glTFLoader.js";
|
|
3
|
+
import type { ITexture } from "../glTFLoaderInterfaces.js";
|
|
4
|
+
import type { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
|
|
5
|
+
import type { Nullable } from "@babylonjs/core/types.js";
|
|
6
|
+
declare module "../../glTFFileLoader.js" {
|
|
7
|
+
interface GLTFLoaderExtensionOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Defines options for the EXT_texture_avif extension.
|
|
10
|
+
*/
|
|
11
|
+
["EXT_texture_avif"]: {};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* [glTF PR](https://github.com/KhronosGroup/glTF/pull/2235)
|
|
16
|
+
* [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_texture_avif/README.md)
|
|
17
|
+
*/
|
|
18
|
+
export declare class EXT_texture_avif implements IGLTFLoaderExtension {
|
|
19
|
+
/** The name of this extension. */
|
|
20
|
+
readonly name = "EXT_texture_avif";
|
|
21
|
+
/** Defines whether this extension is enabled. */
|
|
22
|
+
enabled: boolean;
|
|
23
|
+
private _loader;
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
constructor(loader: GLTFLoader);
|
|
28
|
+
/** @internal */
|
|
29
|
+
dispose(): void;
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
_loadTextureAsync(context: string, texture: ITexture, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>>;
|
|
34
|
+
}
|