@babylonjs/serializers 9.12.1 → 9.14.0
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/3MF/core/model/pure.d.ts +8 -0
- package/3MF/core/model/pure.js +9 -0
- package/3MF/core/model/pure.js.map +1 -0
- package/3MF/core/pure.d.ts +3 -0
- package/3MF/core/pure.js +5 -0
- package/3MF/core/pure.js.map +1 -0
- package/3MF/core/xml/pure.d.ts +7 -0
- package/3MF/core/xml/pure.js +8 -0
- package/3MF/core/xml/pure.js.map +1 -0
- package/3MF/pure.d.ts +4 -0
- package/3MF/pure.js +6 -0
- package/3MF/pure.js.map +1 -0
- package/BVH/pure.d.ts +2 -0
- package/BVH/pure.js +3 -0
- package/BVH/pure.js.map +1 -0
- package/OBJ/pure.d.ts +2 -0
- package/OBJ/pure.js +3 -0
- package/OBJ/pure.js.map +1 -0
- package/USDZ/pure.d.ts +2 -0
- package/USDZ/pure.js +4 -0
- package/USDZ/pure.js.map +1 -0
- package/glTF/2.0/Extensions/EXT_lights_area.d.ts +3 -37
- package/glTF/2.0/Extensions/EXT_lights_area.js +5 -130
- package/glTF/2.0/Extensions/EXT_lights_area.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_lights_area.pure.d.ts +44 -0
- package/glTF/2.0/Extensions/EXT_lights_area.pure.js +145 -0
- package/glTF/2.0/Extensions/EXT_lights_area.pure.js.map +1 -0
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +4 -38
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +6 -138
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.pure.d.ts +44 -0
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.pure.js +151 -0
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.pure.js.map +1 -0
- package/glTF/2.0/Extensions/EXT_texture_avif.d.ts +3 -15
- package/glTF/2.0/Extensions/EXT_texture_avif.js +5 -38
- package/glTF/2.0/Extensions/EXT_texture_avif.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_texture_avif.pure.d.ts +27 -0
- package/glTF/2.0/Extensions/EXT_texture_avif.pure.js +58 -0
- package/glTF/2.0/Extensions/EXT_texture_avif.pure.js.map +1 -0
- package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +3 -14
- package/glTF/2.0/Extensions/EXT_texture_webp.js +5 -37
- package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_texture_webp.pure.d.ts +26 -0
- package/glTF/2.0/Extensions/EXT_texture_webp.pure.js +57 -0
- package/glTF/2.0/Extensions/EXT_texture_webp.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +3 -30
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +5 -128
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.pure.d.ts +37 -0
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.pure.js +143 -0
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +3 -37
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +5 -142
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.pure.d.ts +44 -0
- package/glTF/2.0/Extensions/KHR_lights_punctual.pure.js +157 -0
- package/glTF/2.0/Extensions/KHR_lights_punctual.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_anisotropy.d.ts +3 -30
- package/glTF/2.0/Extensions/KHR_materials_anisotropy.js +5 -177
- package/glTF/2.0/Extensions/KHR_materials_anisotropy.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_anisotropy.pure.d.ts +37 -0
- package/glTF/2.0/Extensions/KHR_materials_anisotropy.pure.js +192 -0
- package/glTF/2.0/Extensions/KHR_materials_anisotropy.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +3 -30
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +5 -251
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.pure.d.ts +37 -0
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.pure.js +266 -0
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_coat.d.ts +3 -30
- package/glTF/2.0/Extensions/KHR_materials_coat.js +5 -380
- package/glTF/2.0/Extensions/KHR_materials_coat.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_coat.pure.d.ts +37 -0
- package/glTF/2.0/Extensions/KHR_materials_coat.pure.js +395 -0
- package/glTF/2.0/Extensions/KHR_materials_coat.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.d.ts +3 -22
- package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.js +5 -75
- package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.pure.d.ts +29 -0
- package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.pure.js +90 -0
- package/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.d.ts +3 -38
- package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js +5 -115
- package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.pure.d.ts +45 -0
- package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.pure.js +130 -0
- package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_dispersion.d.ts +3 -29
- package/glTF/2.0/Extensions/KHR_materials_dispersion.js +5 -60
- package/glTF/2.0/Extensions/KHR_materials_dispersion.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_dispersion.pure.d.ts +36 -0
- package/glTF/2.0/Extensions/KHR_materials_dispersion.pure.js +75 -0
- package/glTF/2.0/Extensions/KHR_materials_dispersion.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +3 -25
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +5 -54
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.pure.d.ts +32 -0
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.pure.js +69 -0
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_fuzz.d.ts +3 -30
- package/glTF/2.0/Extensions/KHR_materials_fuzz.js +5 -191
- package/glTF/2.0/Extensions/KHR_materials_fuzz.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_fuzz.pure.d.ts +37 -0
- package/glTF/2.0/Extensions/KHR_materials_fuzz.pure.js +206 -0
- package/glTF/2.0/Extensions/KHR_materials_fuzz.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +3 -27
- package/glTF/2.0/Extensions/KHR_materials_ior.js +5 -67
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_ior.pure.d.ts +34 -0
- package/glTF/2.0/Extensions/KHR_materials_ior.pure.js +81 -0
- package/glTF/2.0/Extensions/KHR_materials_ior.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_iridescence.d.ts +3 -22
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js +5 -100
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_iridescence.pure.d.ts +29 -0
- package/glTF/2.0/Extensions/KHR_materials_iridescence.pure.js +115 -0
- package/glTF/2.0/Extensions/KHR_materials_iridescence.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_openpbr.d.ts +3 -25
- package/glTF/2.0/Extensions/KHR_materials_openpbr.js +5 -41
- package/glTF/2.0/Extensions/KHR_materials_openpbr.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_openpbr.pure.d.ts +32 -0
- package/glTF/2.0/Extensions/KHR_materials_openpbr.pure.js +56 -0
- package/glTF/2.0/Extensions/KHR_materials_openpbr.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +3 -22
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +5 -63
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.pure.d.ts +29 -0
- package/glTF/2.0/Extensions/KHR_materials_sheen.pure.js +78 -0
- package/glTF/2.0/Extensions/KHR_materials_sheen.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +3 -39
- package/glTF/2.0/Extensions/KHR_materials_specular.js +5 -123
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_specular.pure.d.ts +46 -0
- package/glTF/2.0/Extensions/KHR_materials_specular.pure.js +138 -0
- package/glTF/2.0/Extensions/KHR_materials_specular.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +3 -38
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +5 -145
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.pure.d.ts +45 -0
- package/glTF/2.0/Extensions/KHR_materials_transmission.pure.js +160 -0
- package/glTF/2.0/Extensions/KHR_materials_transmission.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +3 -18
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +5 -43
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.pure.d.ts +25 -0
- package/glTF/2.0/Extensions/KHR_materials_unlit.pure.js +58 -0
- package/glTF/2.0/Extensions/KHR_materials_unlit.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +3 -38
- package/glTF/2.0/Extensions/KHR_materials_volume.js +5 -169
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.pure.d.ts +45 -0
- package/glTF/2.0/Extensions/KHR_materials_volume.pure.js +184 -0
- package/glTF/2.0/Extensions/KHR_materials_volume.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_volume_scatter.d.ts +3 -38
- package/glTF/2.0/Extensions/KHR_materials_volume_scatter.js +5 -130
- package/glTF/2.0/Extensions/KHR_materials_volume_scatter.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume_scatter.pure.d.ts +45 -0
- package/glTF/2.0/Extensions/KHR_materials_volume_scatter.pure.js +145 -0
- package/glTF/2.0/Extensions/KHR_materials_volume_scatter.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +3 -14
- package/glTF/2.0/Extensions/KHR_texture_basisu.js +5 -37
- package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_basisu.pure.d.ts +26 -0
- package/glTF/2.0/Extensions/KHR_texture_basisu.pure.js +57 -0
- package/glTF/2.0/Extensions/KHR_texture_basisu.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +3 -19
- package/glTF/2.0/Extensions/KHR_texture_transform.js +5 -90
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.pure.d.ts +26 -0
- package/glTF/2.0/Extensions/KHR_texture_transform.pure.js +105 -0
- package/glTF/2.0/Extensions/KHR_texture_transform.pure.js.map +1 -0
- package/glTF/2.0/Extensions/pure.d.ts +26 -0
- package/glTF/2.0/Extensions/pure.js +27 -0
- package/glTF/2.0/Extensions/pure.js.map +1 -0
- package/glTF/2.0/pure.d.ts +5 -0
- package/glTF/2.0/pure.js +7 -0
- package/glTF/2.0/pure.js.map +1 -0
- package/glTF/pure.d.ts +3 -0
- package/glTF/pure.js +5 -0
- package/glTF/pure.js.map +1 -0
- package/package.json +30 -4
- package/pure.d.ts +7 -0
- package/pure.js +9 -0
- package/pure.js.map +1 -0
- package/stl/pure.d.ts +2 -0
- package/stl/pure.js +3 -0
- package/stl/pure.js.map +1 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type IMaterial } from "babylonjs-gltf2interface";
|
|
2
|
+
import { type IGLTFExporterExtensionV2 } from "../glTFExporterExtension.js";
|
|
3
|
+
import { GLTFExporter } from "../glTFExporter.js";
|
|
4
|
+
import { type Material } from "@babylonjs/core/Materials/material.js";
|
|
5
|
+
import { type BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare class KHR_materials_diffuse_roughness implements IGLTFExporterExtensionV2 {
|
|
10
|
+
/** Name of this extension */
|
|
11
|
+
readonly name = "KHR_materials_diffuse_roughness";
|
|
12
|
+
/** Defines whether this extension is enabled */
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
/** Defines whether this extension is required */
|
|
15
|
+
required: boolean;
|
|
16
|
+
private _exporter;
|
|
17
|
+
private _wasUsed;
|
|
18
|
+
constructor(exporter: GLTFExporter);
|
|
19
|
+
dispose(): void;
|
|
20
|
+
/** @internal */
|
|
21
|
+
get wasUsed(): boolean;
|
|
22
|
+
postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]>;
|
|
23
|
+
postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Registers the KHR_materials_diffuse_roughness glTF serializer extension with the {@link GLTFExporter}.
|
|
27
|
+
* Safe to call multiple times; only the first call has an effect.
|
|
28
|
+
*/
|
|
29
|
+
export declare function RegisterKHR_materials_diffuse_roughness(): void;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { GLTFExporter } from "../glTFExporter.js";
|
|
2
|
+
import { PBRBaseMaterial } from "@babylonjs/core/Materials/PBR/pbrBaseMaterial.pure.js";
|
|
3
|
+
import { OpenPBRMaterial } from "@babylonjs/core/Materials/PBR/openpbrMaterial.pure.js";
|
|
4
|
+
const NAME = "KHR_materials_diffuse_roughness";
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
9
|
+
export class KHR_materials_diffuse_roughness {
|
|
10
|
+
constructor(exporter) {
|
|
11
|
+
/** Name of this extension */
|
|
12
|
+
this.name = NAME;
|
|
13
|
+
/** Defines whether this extension is enabled */
|
|
14
|
+
this.enabled = true;
|
|
15
|
+
/** Defines whether this extension is required */
|
|
16
|
+
this.required = false;
|
|
17
|
+
this._wasUsed = false;
|
|
18
|
+
this._exporter = exporter;
|
|
19
|
+
}
|
|
20
|
+
dispose() { }
|
|
21
|
+
/** @internal */
|
|
22
|
+
get wasUsed() {
|
|
23
|
+
return this._wasUsed;
|
|
24
|
+
}
|
|
25
|
+
async postExportMaterialAdditionalTexturesAsync(context, node, babylonMaterial) {
|
|
26
|
+
const additionalTextures = [];
|
|
27
|
+
if (babylonMaterial instanceof PBRBaseMaterial) {
|
|
28
|
+
if (babylonMaterial._baseDiffuseRoughness) {
|
|
29
|
+
if (babylonMaterial._baseDiffuseRoughnessTexture) {
|
|
30
|
+
additionalTextures.push(babylonMaterial._baseDiffuseRoughnessTexture);
|
|
31
|
+
}
|
|
32
|
+
return additionalTextures;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else if (babylonMaterial instanceof OpenPBRMaterial) {
|
|
36
|
+
if (babylonMaterial.baseDiffuseRoughness) {
|
|
37
|
+
if (babylonMaterial.baseDiffuseRoughnessTexture) {
|
|
38
|
+
additionalTextures.push(babylonMaterial.baseDiffuseRoughnessTexture);
|
|
39
|
+
}
|
|
40
|
+
return additionalTextures;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
46
|
+
postExportMaterialAsync(context, node, babylonMaterial) {
|
|
47
|
+
return new Promise((resolve) => {
|
|
48
|
+
let diffuseRoughnessFactor = null;
|
|
49
|
+
let diffuseRoughnessTexture = null;
|
|
50
|
+
if (babylonMaterial instanceof PBRBaseMaterial) {
|
|
51
|
+
diffuseRoughnessFactor = babylonMaterial._baseDiffuseRoughness;
|
|
52
|
+
diffuseRoughnessTexture = babylonMaterial._baseDiffuseRoughnessTexture;
|
|
53
|
+
}
|
|
54
|
+
else if (babylonMaterial instanceof OpenPBRMaterial) {
|
|
55
|
+
diffuseRoughnessFactor = babylonMaterial.baseDiffuseRoughness;
|
|
56
|
+
diffuseRoughnessTexture = babylonMaterial.baseDiffuseRoughnessTexture;
|
|
57
|
+
}
|
|
58
|
+
if (!diffuseRoughnessFactor) {
|
|
59
|
+
resolve(node);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
this._wasUsed = true;
|
|
63
|
+
node.extensions = node.extensions || {};
|
|
64
|
+
const diffuseRoughnessTextureInfo = this._exporter._materialExporter.getTextureInfo(diffuseRoughnessTexture);
|
|
65
|
+
const diffuseRoughnessInfo = {
|
|
66
|
+
diffuseRoughnessFactor: diffuseRoughnessFactor,
|
|
67
|
+
diffuseRoughnessTexture: diffuseRoughnessTextureInfo ?? undefined,
|
|
68
|
+
};
|
|
69
|
+
if (diffuseRoughnessInfo.diffuseRoughnessTexture !== null) {
|
|
70
|
+
this._exporter._materialNeedsUVsSet.add(babylonMaterial);
|
|
71
|
+
}
|
|
72
|
+
node.extensions[NAME] = diffuseRoughnessInfo;
|
|
73
|
+
resolve(node);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
let _Registered = false;
|
|
78
|
+
/**
|
|
79
|
+
* Registers the KHR_materials_diffuse_roughness glTF serializer extension with the {@link GLTFExporter}.
|
|
80
|
+
* Safe to call multiple times; only the first call has an effect.
|
|
81
|
+
*/
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
83
|
+
export function RegisterKHR_materials_diffuse_roughness() {
|
|
84
|
+
if (_Registered) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
_Registered = true;
|
|
88
|
+
GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_diffuse_roughness(exporter));
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=KHR_materials_diffuse_roughness.pure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KHR_materials_diffuse_roughness.pure.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_diffuse_roughness.pure.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAG1E,MAAM,IAAI,GAAG,iCAAiC,CAAC;AAE/C;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,+BAA+B;IAcxC,YAAY,QAAsB;QAblC,6BAA6B;QACb,SAAI,GAAG,IAAI,CAAC;QAE5B,gDAAgD;QACzC,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aA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ltf2interface\";\r\nimport { type IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport { type Material } from \"core/Materials/material\";\r\nimport { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial.pure\";\r\nimport { type BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { OpenPBRMaterial } from \"core/Materials/PBR/openpbrMaterial.pure\";\r\nimport { type Nullable } from \"core/types\";\r\n\r\nconst NAME = \"KHR_materials_diffuse_roughness\";\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_diffuse_roughness implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: GLTFExporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: GLTFExporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public async postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]> {\r\n const additionalTextures: BaseTexture[] = [];\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (babylonMaterial._baseDiffuseRoughness) {\r\n if (babylonMaterial._baseDiffuseRoughnessTexture) {\r\n additionalTextures.push(babylonMaterial._baseDiffuseRoughnessTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.baseDiffuseRoughness) {\r\n if (babylonMaterial.baseDiffuseRoughnessTexture) {\r\n additionalTextures.push(babylonMaterial.baseDiffuseRoughnessTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return [];\r\n }\r\n\r\n // eslint-disable-next-line no-restricted-syntax\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return new Promise((resolve) => {\r\n let diffuseRoughnessFactor: Nullable<number> = null;\r\n let diffuseRoughnessTexture: Nullable<BaseTexture> = null;\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n diffuseRoughnessFactor = babylonMaterial._baseDiffuseRoughness;\r\n diffuseRoughnessTexture = babylonMaterial._baseDiffuseRoughnessTexture;\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n diffuseRoughnessFactor = babylonMaterial.baseDiffuseRoughness;\r\n diffuseRoughnessTexture = babylonMaterial.baseDiffuseRoughnessTexture;\r\n }\r\n if (!diffuseRoughnessFactor) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n const diffuseRoughnessTextureInfo = this._exporter._materialExporter.getTextureInfo(diffuseRoughnessTexture);\r\n\r\n const diffuseRoughnessInfo: IKHRMaterialsDiffuseRoughness = {\r\n diffuseRoughnessFactor: diffuseRoughnessFactor,\r\n diffuseRoughnessTexture: diffuseRoughnessTextureInfo ?? undefined,\r\n };\r\n\r\n if (diffuseRoughnessInfo.diffuseRoughnessTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = diffuseRoughnessInfo;\r\n\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nlet _Registered = false;\r\n/**\r\n * Registers the KHR_materials_diffuse_roughness glTF serializer extension with the {@link GLTFExporter}.\r\n * Safe to call multiple times; only the first call has an effect.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function RegisterKHR_materials_diffuse_roughness(): void {\r\n if (_Registered) {\r\n return;\r\n }\r\n _Registered = true;\r\n\r\n GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_diffuse_roughness(exporter));\r\n}\r\n"]}
|
|
@@ -1,40 +1,5 @@
|
|
|
1
|
-
import { type IMaterial } from "babylonjs-gltf2interface";
|
|
2
|
-
import { type IGLTFExporterExtensionV2 } from "../glTFExporterExtension.js";
|
|
3
|
-
import { GLTFExporter } from "../glTFExporter.js";
|
|
4
|
-
import { type Material } from "@babylonjs/core/Materials/material.js";
|
|
5
|
-
import { type BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
|
|
6
1
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
2
|
+
* Re-exports the pure implementation and applies the runtime registration side effect.
|
|
3
|
+
* Import "./KHR_materials_diffuse_transmission.pure" for tree-shakeable, side-effect-free usage.
|
|
9
4
|
*/
|
|
10
|
-
export
|
|
11
|
-
/** Name of this extension */
|
|
12
|
-
readonly name = "KHR_materials_diffuse_transmission";
|
|
13
|
-
/** Defines whether this extension is enabled */
|
|
14
|
-
enabled: boolean;
|
|
15
|
-
/** Defines whether this extension is required */
|
|
16
|
-
required: boolean;
|
|
17
|
-
private _exporter;
|
|
18
|
-
private _wasUsed;
|
|
19
|
-
constructor(exporter: GLTFExporter);
|
|
20
|
-
dispose(): void;
|
|
21
|
-
/** @internal */
|
|
22
|
-
get wasUsed(): boolean;
|
|
23
|
-
/**
|
|
24
|
-
* After exporting a material, deal with additional textures
|
|
25
|
-
* @param context GLTF context of the material
|
|
26
|
-
* @param node exported GLTF node
|
|
27
|
-
* @param babylonMaterial corresponding babylon material
|
|
28
|
-
* @returns array of additional textures to export
|
|
29
|
-
*/
|
|
30
|
-
postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]>;
|
|
31
|
-
private _isExtensionEnabled;
|
|
32
|
-
/**
|
|
33
|
-
* After exporting a material
|
|
34
|
-
* @param context GLTF context of the material
|
|
35
|
-
* @param node exported GLTF node
|
|
36
|
-
* @param babylonMaterial corresponding babylon material
|
|
37
|
-
* @returns promise that resolves with the updated node
|
|
38
|
-
*/
|
|
39
|
-
postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
|
|
40
|
-
}
|
|
5
|
+
export * from "./KHR_materials_diffuse_transmission.pure.js";
|
|
@@ -1,118 +1,8 @@
|
|
|
1
|
-
import { GLTFExporter } from "../glTFExporter.js";
|
|
2
|
-
import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
|
|
3
|
-
import { Logger } from "@babylonjs/core/Misc/logger.js";
|
|
4
|
-
const NAME = "KHR_materials_diffuse_transmission";
|
|
5
1
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
2
|
+
* Re-exports the pure implementation and applies the runtime registration side effect.
|
|
3
|
+
* Import "./KHR_materials_diffuse_transmission.pure" for tree-shakeable, side-effect-free usage.
|
|
8
4
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// Check if translucency intensity texture is available or can be derived from thickness texture
|
|
13
|
-
if (subs.translucencyIntensityTexture) {
|
|
14
|
-
texture = subs.translucencyIntensityTexture;
|
|
15
|
-
}
|
|
16
|
-
else if (subs.thicknessTexture && subs.useMaskFromThicknessTexture) {
|
|
17
|
-
texture = subs.thicknessTexture;
|
|
18
|
-
}
|
|
19
|
-
if (texture && !subs.useGltfStyleTextures) {
|
|
20
|
-
Logger.Warn(`${context}: Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ${babylonMaterial.name}`, 1);
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
return texture;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1825)
|
|
27
|
-
* !!! Experimental Extension Subject to Changes !!!
|
|
28
|
-
*/
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
30
|
-
export class KHR_materials_diffuse_transmission {
|
|
31
|
-
constructor(exporter) {
|
|
32
|
-
/** Name of this extension */
|
|
33
|
-
this.name = NAME;
|
|
34
|
-
/** Defines whether this extension is enabled */
|
|
35
|
-
this.enabled = true;
|
|
36
|
-
/** Defines whether this extension is required */
|
|
37
|
-
this.required = false;
|
|
38
|
-
this._wasUsed = false;
|
|
39
|
-
this._exporter = exporter;
|
|
40
|
-
}
|
|
41
|
-
dispose() { }
|
|
42
|
-
/** @internal */
|
|
43
|
-
get wasUsed() {
|
|
44
|
-
return this._wasUsed;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* After exporting a material, deal with additional textures
|
|
48
|
-
* @param context GLTF context of the material
|
|
49
|
-
* @param node exported GLTF node
|
|
50
|
-
* @param babylonMaterial corresponding babylon material
|
|
51
|
-
* @returns array of additional textures to export
|
|
52
|
-
*/
|
|
53
|
-
async postExportMaterialAdditionalTexturesAsync(context, node, babylonMaterial) {
|
|
54
|
-
const additionalTextures = [];
|
|
55
|
-
if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {
|
|
56
|
-
const translucencyIntensityTexture = GetTranslucencyIntensityTexture(context, babylonMaterial);
|
|
57
|
-
if (translucencyIntensityTexture) {
|
|
58
|
-
additionalTextures.push(translucencyIntensityTexture);
|
|
59
|
-
}
|
|
60
|
-
if (babylonMaterial.subSurface.translucencyColorTexture) {
|
|
61
|
-
additionalTextures.push(babylonMaterial.subSurface.translucencyColorTexture);
|
|
62
|
-
}
|
|
63
|
-
return additionalTextures;
|
|
64
|
-
}
|
|
65
|
-
return additionalTextures;
|
|
66
|
-
}
|
|
67
|
-
_isExtensionEnabled(mat) {
|
|
68
|
-
// This extension must not be used on a material that also uses KHR_materials_unlit
|
|
69
|
-
if (mat.unlit) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
const subs = mat.subSurface;
|
|
73
|
-
if (!subs.isTranslucencyEnabled) {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
return (!mat.unlit &&
|
|
77
|
-
!subs.useAlbedoToTintTranslucency &&
|
|
78
|
-
subs.useGltfStyleTextures &&
|
|
79
|
-
subs.volumeIndexOfRefraction === 1 &&
|
|
80
|
-
subs.minimumThickness === 0 &&
|
|
81
|
-
subs.maximumThickness === 0);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* After exporting a material
|
|
85
|
-
* @param context GLTF context of the material
|
|
86
|
-
* @param node exported GLTF node
|
|
87
|
-
* @param babylonMaterial corresponding babylon material
|
|
88
|
-
* @returns promise that resolves with the updated node
|
|
89
|
-
*/
|
|
90
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
91
|
-
postExportMaterialAsync(context, node, babylonMaterial) {
|
|
92
|
-
return new Promise((resolve) => {
|
|
93
|
-
if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {
|
|
94
|
-
this._wasUsed = true;
|
|
95
|
-
const subs = babylonMaterial.subSurface;
|
|
96
|
-
const translucencyIntensityTexture = GetTranslucencyIntensityTexture(context, babylonMaterial);
|
|
97
|
-
const diffuseTransmissionFactor = subs.translucencyIntensity == 0 ? undefined : subs.translucencyIntensity;
|
|
98
|
-
const diffuseTransmissionTexture = this._exporter._materialExporter.getTextureInfo(translucencyIntensityTexture) ?? undefined;
|
|
99
|
-
const diffuseTransmissionColorFactor = !subs.translucencyColor || subs.translucencyColor.equalsFloats(1.0, 1.0, 1.0) ? undefined : subs.translucencyColor.asArray();
|
|
100
|
-
const diffuseTransmissionColorTexture = this._exporter._materialExporter.getTextureInfo(subs.translucencyColorTexture) ?? undefined;
|
|
101
|
-
const diffuseTransmissionInfo = {
|
|
102
|
-
diffuseTransmissionFactor,
|
|
103
|
-
diffuseTransmissionTexture,
|
|
104
|
-
diffuseTransmissionColorFactor,
|
|
105
|
-
diffuseTransmissionColorTexture,
|
|
106
|
-
};
|
|
107
|
-
if (diffuseTransmissionTexture || diffuseTransmissionColorTexture) {
|
|
108
|
-
this._exporter._materialNeedsUVsSet.add(babylonMaterial);
|
|
109
|
-
}
|
|
110
|
-
node.extensions = node.extensions || {};
|
|
111
|
-
node.extensions[NAME] = diffuseTransmissionInfo;
|
|
112
|
-
}
|
|
113
|
-
resolve(node);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_diffuse_transmission(exporter));
|
|
5
|
+
export * from "./KHR_materials_diffuse_transmission.pure.js";
|
|
6
|
+
import { RegisterKHR_materials_diffuse_transmission } from "./KHR_materials_diffuse_transmission.pure.js";
|
|
7
|
+
RegisterKHR_materials_diffuse_transmission();
|
|
118
8
|
//# sourceMappingURL=KHR_materials_diffuse_transmission.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_materials_diffuse_transmission.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAE7D,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,MAAM,IAAI,GAAG,oCAAoC,CAAC;AAElD;;;GAGG;AACH,SAAS,+BAA+B,CAAC,OAAe,EAAE,eAA4B;IAClF,MAAM,IAAI,GAAG,eAAe,CAAC,UAAU,CAAC;IACxC,IAAI,OAAO,GAAG,IAAI,CAAC;IAEnB,gGAAgG;IAChG,IAAI,IAAI,CAAC,4BAA4B,EAAE,CAAC;QACpC,OAAO,GAAG,IAAI,CAAC,4BAA4B,CAAC;IAChD,CAAC;SAAM,IAAI,IAAI,CAAC,gBAAgB,IAAI,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACnE,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC;IACpC,CAAC;IAED,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC;QACxC,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,sGAAsG,eAAe,CAAC,IAAI,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ACpK,MAAM,+BAA+B,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,cAAc,CAAC,IAAI,CAAC,wBAAwB,CAAC,IAAI,SAAS,CAAC;gBAEpI,MAAM,uBAAuB,GAAqC;oBAC9D,yBAAyB;oBACzB,0BAA0B;oBAC1B,8BAA8B;oBAC9B,+BAA+B;iBAClC,CAAC;gBAEF,IAAI,0BAA0B,IAAI,+BAA+B,EAAE,CAAC;oBAChE,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;gBAC7D,CAAC;gBAED,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC;gBACxC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,uBAAuB,CAAC;YACpD,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,kCAAkC,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import { type IMaterial, type IKHRMaterialsDiffuseTransmission } from \"babylonjs-gltf2interface\";\r\nimport { type IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport { type Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport { type BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { type Nullable } from \"core/types\";\r\n\r\nconst NAME = \"KHR_materials_diffuse_transmission\";\r\n\r\n/**\r\n * Get the appropriate translucency intensity texture for the material.\r\n * @internal\r\n */\r\nfunction GetTranslucencyIntensityTexture(context: string, babylonMaterial: PBRMaterial): Nullable<BaseTexture> {\r\n const subs = babylonMaterial.subSurface;\r\n let texture = null;\r\n\r\n // Check if translucency intensity texture is available or can be derived from thickness texture\r\n if (subs.translucencyIntensityTexture) {\r\n texture = subs.translucencyIntensityTexture;\r\n } else if (subs.thicknessTexture && subs.useMaskFromThicknessTexture) {\r\n texture = subs.thicknessTexture;\r\n }\r\n\r\n if (texture && !subs.useGltfStyleTextures) {\r\n Logger.Warn(`${context}: Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ${babylonMaterial.name}`, 1);\r\n return null;\r\n }\r\n\r\n return texture;\r\n}\r\n\r\n/**\r\n * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1825)\r\n * !!! Experimental Extension Subject to Changes !!!\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_diffuse_transmission implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: GLTFExporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: GLTFExporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n /**\r\n * After exporting a material, deal with additional textures\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns array of additional textures to export\r\n */\r\n public async postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]> {\r\n const additionalTextures: BaseTexture[] = [];\r\n\r\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\r\n const translucencyIntensityTexture = GetTranslucencyIntensityTexture(context, babylonMaterial);\r\n if (translucencyIntensityTexture) {\r\n additionalTextures.push(translucencyIntensityTexture);\r\n }\r\n if (babylonMaterial.subSurface.translucencyColorTexture) {\r\n additionalTextures.push(babylonMaterial.subSurface.translucencyColorTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n\r\n return additionalTextures;\r\n }\r\n\r\n private _isExtensionEnabled(mat: PBRMaterial): boolean {\r\n // This extension must not be used on a material that also uses KHR_materials_unlit\r\n if (mat.unlit) {\r\n return false;\r\n }\r\n const subs = mat.subSurface;\r\n if (!subs.isTranslucencyEnabled) {\r\n return false;\r\n }\r\n\r\n return (\r\n !mat.unlit &&\r\n !subs.useAlbedoToTintTranslucency &&\r\n subs.useGltfStyleTextures &&\r\n subs.volumeIndexOfRefraction === 1 &&\r\n subs.minimumThickness === 0 &&\r\n subs.maximumThickness === 0\r\n );\r\n }\r\n\r\n /**\r\n * After exporting a material\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns promise that resolves with the updated node\r\n */\r\n // eslint-disable-next-line no-restricted-syntax\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\r\n this._wasUsed = true;\r\n\r\n const subs = babylonMaterial.subSurface;\r\n const translucencyIntensityTexture = GetTranslucencyIntensityTexture(context, babylonMaterial);\r\n\r\n const diffuseTransmissionFactor = subs.translucencyIntensity == 0 ? undefined : subs.translucencyIntensity;\r\n const diffuseTransmissionTexture = this._exporter._materialExporter.getTextureInfo(translucencyIntensityTexture) ?? undefined;\r\n const diffuseTransmissionColorFactor = !subs.translucencyColor || subs.translucencyColor.equalsFloats(1.0, 1.0, 1.0) ? undefined : subs.translucencyColor.asArray();\r\n const diffuseTransmissionColorTexture = this._exporter._materialExporter.getTextureInfo(subs.translucencyColorTexture) ?? undefined;\r\n\r\n const diffuseTransmissionInfo: IKHRMaterialsDiffuseTransmission = {\r\n diffuseTransmissionFactor,\r\n diffuseTransmissionTexture,\r\n diffuseTransmissionColorFactor,\r\n diffuseTransmissionColorTexture,\r\n };\r\n\r\n if (diffuseTransmissionTexture || diffuseTransmissionColorTexture) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions = node.extensions || {};\r\n node.extensions[NAME] = diffuseTransmissionInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_diffuse_transmission(exporter));\r\n"]}
|
|
1
|
+
{"version":3,"file":"KHR_materials_diffuse_transmission.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,2CAA2C,CAAC;AAE1D,OAAO,EAAE,0CAA0C,EAAE,MAAM,2CAA2C,CAAC;AACvG,0CAA0C,EAAE,CAAC","sourcesContent":["/**\r\n * Re-exports the pure implementation and applies the runtime registration side effect.\r\n * Import \"./KHR_materials_diffuse_transmission.pure\" for tree-shakeable, side-effect-free usage.\r\n */\r\nexport * from \"./KHR_materials_diffuse_transmission.pure\";\r\n\r\nimport { RegisterKHR_materials_diffuse_transmission } from \"./KHR_materials_diffuse_transmission.pure\";\r\nRegisterKHR_materials_diffuse_transmission();\r\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type IMaterial } from "babylonjs-gltf2interface";
|
|
2
|
+
import { type IGLTFExporterExtensionV2 } from "../glTFExporterExtension.js";
|
|
3
|
+
import { GLTFExporter } from "../glTFExporter.js";
|
|
4
|
+
import { type Material } from "@babylonjs/core/Materials/material.js";
|
|
5
|
+
import { type BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
|
|
6
|
+
/**
|
|
7
|
+
* [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1825)
|
|
8
|
+
* !!! Experimental Extension Subject to Changes !!!
|
|
9
|
+
*/
|
|
10
|
+
export declare class KHR_materials_diffuse_transmission implements IGLTFExporterExtensionV2 {
|
|
11
|
+
/** Name of this extension */
|
|
12
|
+
readonly name = "KHR_materials_diffuse_transmission";
|
|
13
|
+
/** Defines whether this extension is enabled */
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
/** Defines whether this extension is required */
|
|
16
|
+
required: boolean;
|
|
17
|
+
private _exporter;
|
|
18
|
+
private _wasUsed;
|
|
19
|
+
constructor(exporter: GLTFExporter);
|
|
20
|
+
dispose(): void;
|
|
21
|
+
/** @internal */
|
|
22
|
+
get wasUsed(): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* After exporting a material, deal with additional textures
|
|
25
|
+
* @param context GLTF context of the material
|
|
26
|
+
* @param node exported GLTF node
|
|
27
|
+
* @param babylonMaterial corresponding babylon material
|
|
28
|
+
* @returns array of additional textures to export
|
|
29
|
+
*/
|
|
30
|
+
postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]>;
|
|
31
|
+
private _isExtensionEnabled;
|
|
32
|
+
/**
|
|
33
|
+
* After exporting a material
|
|
34
|
+
* @param context GLTF context of the material
|
|
35
|
+
* @param node exported GLTF node
|
|
36
|
+
* @param babylonMaterial corresponding babylon material
|
|
37
|
+
* @returns promise that resolves with the updated node
|
|
38
|
+
*/
|
|
39
|
+
postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Registers the KHR_materials_diffuse_transmission glTF serializer extension with the {@link GLTFExporter}.
|
|
43
|
+
* Safe to call multiple times; only the first call has an effect.
|
|
44
|
+
*/
|
|
45
|
+
export declare function RegisterKHR_materials_diffuse_transmission(): void;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { GLTFExporter } from "../glTFExporter.js";
|
|
2
|
+
import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.pure.js";
|
|
3
|
+
import { Logger } from "@babylonjs/core/Misc/logger.js";
|
|
4
|
+
const NAME = "KHR_materials_diffuse_transmission";
|
|
5
|
+
/**
|
|
6
|
+
* Get the appropriate translucency intensity texture for the material.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
function GetTranslucencyIntensityTexture(context, babylonMaterial) {
|
|
10
|
+
const subs = babylonMaterial.subSurface;
|
|
11
|
+
let texture = null;
|
|
12
|
+
// Check if translucency intensity texture is available or can be derived from thickness texture
|
|
13
|
+
if (subs.translucencyIntensityTexture) {
|
|
14
|
+
texture = subs.translucencyIntensityTexture;
|
|
15
|
+
}
|
|
16
|
+
else if (subs.thicknessTexture && subs.useMaskFromThicknessTexture) {
|
|
17
|
+
texture = subs.thicknessTexture;
|
|
18
|
+
}
|
|
19
|
+
if (texture && !subs.useGltfStyleTextures) {
|
|
20
|
+
Logger.Warn(`${context}: Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ${babylonMaterial.name}`, 1);
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return texture;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1825)
|
|
27
|
+
* !!! Experimental Extension Subject to Changes !!!
|
|
28
|
+
*/
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
30
|
+
export class KHR_materials_diffuse_transmission {
|
|
31
|
+
constructor(exporter) {
|
|
32
|
+
/** Name of this extension */
|
|
33
|
+
this.name = NAME;
|
|
34
|
+
/** Defines whether this extension is enabled */
|
|
35
|
+
this.enabled = true;
|
|
36
|
+
/** Defines whether this extension is required */
|
|
37
|
+
this.required = false;
|
|
38
|
+
this._wasUsed = false;
|
|
39
|
+
this._exporter = exporter;
|
|
40
|
+
}
|
|
41
|
+
dispose() { }
|
|
42
|
+
/** @internal */
|
|
43
|
+
get wasUsed() {
|
|
44
|
+
return this._wasUsed;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* After exporting a material, deal with additional textures
|
|
48
|
+
* @param context GLTF context of the material
|
|
49
|
+
* @param node exported GLTF node
|
|
50
|
+
* @param babylonMaterial corresponding babylon material
|
|
51
|
+
* @returns array of additional textures to export
|
|
52
|
+
*/
|
|
53
|
+
async postExportMaterialAdditionalTexturesAsync(context, node, babylonMaterial) {
|
|
54
|
+
const additionalTextures = [];
|
|
55
|
+
if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {
|
|
56
|
+
const translucencyIntensityTexture = GetTranslucencyIntensityTexture(context, babylonMaterial);
|
|
57
|
+
if (translucencyIntensityTexture) {
|
|
58
|
+
additionalTextures.push(translucencyIntensityTexture);
|
|
59
|
+
}
|
|
60
|
+
if (babylonMaterial.subSurface.translucencyColorTexture) {
|
|
61
|
+
additionalTextures.push(babylonMaterial.subSurface.translucencyColorTexture);
|
|
62
|
+
}
|
|
63
|
+
return additionalTextures;
|
|
64
|
+
}
|
|
65
|
+
return additionalTextures;
|
|
66
|
+
}
|
|
67
|
+
_isExtensionEnabled(mat) {
|
|
68
|
+
// This extension must not be used on a material that also uses KHR_materials_unlit
|
|
69
|
+
if (mat.unlit) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
const subs = mat.subSurface;
|
|
73
|
+
if (!subs.isTranslucencyEnabled) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return (!mat.unlit &&
|
|
77
|
+
!subs.useAlbedoToTintTranslucency &&
|
|
78
|
+
subs.useGltfStyleTextures &&
|
|
79
|
+
subs.volumeIndexOfRefraction === 1 &&
|
|
80
|
+
subs.minimumThickness === 0 &&
|
|
81
|
+
subs.maximumThickness === 0);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* After exporting a material
|
|
85
|
+
* @param context GLTF context of the material
|
|
86
|
+
* @param node exported GLTF node
|
|
87
|
+
* @param babylonMaterial corresponding babylon material
|
|
88
|
+
* @returns promise that resolves with the updated node
|
|
89
|
+
*/
|
|
90
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
91
|
+
postExportMaterialAsync(context, node, babylonMaterial) {
|
|
92
|
+
return new Promise((resolve) => {
|
|
93
|
+
if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {
|
|
94
|
+
this._wasUsed = true;
|
|
95
|
+
const subs = babylonMaterial.subSurface;
|
|
96
|
+
const translucencyIntensityTexture = GetTranslucencyIntensityTexture(context, babylonMaterial);
|
|
97
|
+
const diffuseTransmissionFactor = subs.translucencyIntensity == 0 ? undefined : subs.translucencyIntensity;
|
|
98
|
+
const diffuseTransmissionTexture = this._exporter._materialExporter.getTextureInfo(translucencyIntensityTexture) ?? undefined;
|
|
99
|
+
const diffuseTransmissionColorFactor = !subs.translucencyColor || subs.translucencyColor.equalsFloats(1.0, 1.0, 1.0) ? undefined : subs.translucencyColor.asArray();
|
|
100
|
+
const diffuseTransmissionColorTexture = this._exporter._materialExporter.getTextureInfo(subs.translucencyColorTexture) ?? undefined;
|
|
101
|
+
const diffuseTransmissionInfo = {
|
|
102
|
+
diffuseTransmissionFactor,
|
|
103
|
+
diffuseTransmissionTexture,
|
|
104
|
+
diffuseTransmissionColorFactor,
|
|
105
|
+
diffuseTransmissionColorTexture,
|
|
106
|
+
};
|
|
107
|
+
if (diffuseTransmissionTexture || diffuseTransmissionColorTexture) {
|
|
108
|
+
this._exporter._materialNeedsUVsSet.add(babylonMaterial);
|
|
109
|
+
}
|
|
110
|
+
node.extensions = node.extensions || {};
|
|
111
|
+
node.extensions[NAME] = diffuseTransmissionInfo;
|
|
112
|
+
}
|
|
113
|
+
resolve(node);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
let _Registered = false;
|
|
118
|
+
/**
|
|
119
|
+
* Registers the KHR_materials_diffuse_transmission glTF serializer extension with the {@link GLTFExporter}.
|
|
120
|
+
* Safe to call multiple times; only the first call has an effect.
|
|
121
|
+
*/
|
|
122
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
123
|
+
export function RegisterKHR_materials_diffuse_transmission() {
|
|
124
|
+
if (_Registered) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
_Registered = true;
|
|
128
|
+
GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_diffuse_transmission(exporter));
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=KHR_materials_diffuse_transmission.pure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KHR_materials_diffuse_transmission.pure.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.pure.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAElE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,MAAM,IAAI,GAAG,oCAAoC,CAAC;AAElD;;;GAGG;AACH,SAAS,+BAA+B,CAAC,OAAe,EAAE,eAA4B;IAClF,MAAM,IAAI,GAAG,eAAe,CAAC,UAAU,CAAC;IACxC,IAAI,OAAO,GAAG,IAAI,CAAC;IAEnB,gGAAgG;IAChG,IAAI,IAAI,CAAC,4BAA4B,EAAE,CAAC;QACpC,OAAO,GAAG,IAAI,CAAC,4BAA4B,CAAC;IAChD,CAAC;SAAM,IAAI,IAAI,CAAC,gBAAgB,IAAI,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACnE,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC;IACpC,CAAC;IAED,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC;QACxC,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,sGAAsG,eAAe,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;QACvJ,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC;AAED;;;GAGG;AACH,gEAAgE;AAChE,MAAM,OA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GAAqC;oBAC9D,yBAAyB;oBACzB,0BAA0B;oBAC1B,8BAA8B;oBAC9B,+BAA+B;iBAClC,CAAC;gBAEF,IAAI,0BAA0B,IAAI,+BAA+B,EAAE,CAAC;oBAChE,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;gBAC7D,CAAC;gBAED,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC;gBACxC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,uBAAuB,CAAC;YACpD,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB;;;GAGG;AACH,gEAAgE;AAChE,MAAM,UAAU,0CAA0C;IACtD,IAAI,WAAW,EAAE,CAAC;QACd,OAAO;IACX,CAAC;IACD,WAAW,GAAG,IAAI,CAAC;IAEnB,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,kCAAkC,CAAC,QAAQ,CAAC,CAAC,CAAC;AACzG,CAAC","sourcesContent":["import { type IMaterial, type IKHRMaterialsDiffuseTransmission } from \"babylonjs-gltf2interface\";\r\nimport { type IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport { type Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial.pure\";\r\nimport { type BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { type Nullable } from \"core/types\";\r\n\r\nconst NAME = \"KHR_materials_diffuse_transmission\";\r\n\r\n/**\r\n * Get the appropriate translucency intensity texture for the material.\r\n * @internal\r\n */\r\nfunction GetTranslucencyIntensityTexture(context: string, babylonMaterial: PBRMaterial): Nullable<BaseTexture> {\r\n const subs = babylonMaterial.subSurface;\r\n let texture = null;\r\n\r\n // Check if translucency intensity texture is available or can be derived from thickness texture\r\n if (subs.translucencyIntensityTexture) {\r\n texture = subs.translucencyIntensityTexture;\r\n } else if (subs.thicknessTexture && subs.useMaskFromThicknessTexture) {\r\n texture = subs.thicknessTexture;\r\n }\r\n\r\n if (texture && !subs.useGltfStyleTextures) {\r\n Logger.Warn(`${context}: Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ${babylonMaterial.name}`, 1);\r\n return null;\r\n }\r\n\r\n return texture;\r\n}\r\n\r\n/**\r\n * [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1825)\r\n * !!! Experimental Extension Subject to Changes !!!\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_diffuse_transmission implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: GLTFExporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: GLTFExporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n /**\r\n * After exporting a material, deal with additional textures\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns array of additional textures to export\r\n */\r\n public async postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]> {\r\n const additionalTextures: BaseTexture[] = [];\r\n\r\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\r\n const translucencyIntensityTexture = GetTranslucencyIntensityTexture(context, babylonMaterial);\r\n if (translucencyIntensityTexture) {\r\n additionalTextures.push(translucencyIntensityTexture);\r\n }\r\n if (babylonMaterial.subSurface.translucencyColorTexture) {\r\n additionalTextures.push(babylonMaterial.subSurface.translucencyColorTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n\r\n return additionalTextures;\r\n }\r\n\r\n private _isExtensionEnabled(mat: PBRMaterial): boolean {\r\n // This extension must not be used on a material that also uses KHR_materials_unlit\r\n if (mat.unlit) {\r\n return false;\r\n }\r\n const subs = mat.subSurface;\r\n if (!subs.isTranslucencyEnabled) {\r\n return false;\r\n }\r\n\r\n return (\r\n !mat.unlit &&\r\n !subs.useAlbedoToTintTranslucency &&\r\n subs.useGltfStyleTextures &&\r\n subs.volumeIndexOfRefraction === 1 &&\r\n subs.minimumThickness === 0 &&\r\n subs.maximumThickness === 0\r\n );\r\n }\r\n\r\n /**\r\n * After exporting a material\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns promise that resolves with the updated node\r\n */\r\n // eslint-disable-next-line no-restricted-syntax\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\r\n this._wasUsed = true;\r\n\r\n const subs = babylonMaterial.subSurface;\r\n const translucencyIntensityTexture = GetTranslucencyIntensityTexture(context, babylonMaterial);\r\n\r\n const diffuseTransmissionFactor = subs.translucencyIntensity == 0 ? undefined : subs.translucencyIntensity;\r\n const diffuseTransmissionTexture = this._exporter._materialExporter.getTextureInfo(translucencyIntensityTexture) ?? undefined;\r\n const diffuseTransmissionColorFactor = !subs.translucencyColor || subs.translucencyColor.equalsFloats(1.0, 1.0, 1.0) ? undefined : subs.translucencyColor.asArray();\r\n const diffuseTransmissionColorTexture = this._exporter._materialExporter.getTextureInfo(subs.translucencyColorTexture) ?? undefined;\r\n\r\n const diffuseTransmissionInfo: IKHRMaterialsDiffuseTransmission = {\r\n diffuseTransmissionFactor,\r\n diffuseTransmissionTexture,\r\n diffuseTransmissionColorFactor,\r\n diffuseTransmissionColorTexture,\r\n };\r\n\r\n if (diffuseTransmissionTexture || diffuseTransmissionColorTexture) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions = node.extensions || {};\r\n node.extensions[NAME] = diffuseTransmissionInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nlet _Registered = false;\r\n/**\r\n * Registers the KHR_materials_diffuse_transmission glTF serializer extension with the {@link GLTFExporter}.\r\n * Safe to call multiple times; only the first call has an effect.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function RegisterKHR_materials_diffuse_transmission(): void {\r\n if (_Registered) {\r\n return;\r\n }\r\n _Registered = true;\r\n\r\n GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_diffuse_transmission(exporter));\r\n}\r\n"]}
|
|
@@ -1,31 +1,5 @@
|
|
|
1
|
-
import { type IMaterial } from "babylonjs-gltf2interface";
|
|
2
|
-
import { type IGLTFExporterExtensionV2 } from "../glTFExporterExtension.js";
|
|
3
|
-
import { type Material } from "@babylonjs/core/Materials/material.js";
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* Re-exports the pure implementation and applies the runtime registration side effect.
|
|
3
|
+
* Import "./KHR_materials_dispersion.pure" for tree-shakeable, side-effect-free usage.
|
|
7
4
|
*/
|
|
8
|
-
export
|
|
9
|
-
/** Name of this extension */
|
|
10
|
-
readonly name = "KHR_materials_dispersion";
|
|
11
|
-
/** Defines whether this extension is enabled */
|
|
12
|
-
enabled: boolean;
|
|
13
|
-
/** Defines whether this extension is required */
|
|
14
|
-
required: boolean;
|
|
15
|
-
private _wasUsed;
|
|
16
|
-
/** Constructor */
|
|
17
|
-
constructor();
|
|
18
|
-
/** Dispose */
|
|
19
|
-
dispose(): void;
|
|
20
|
-
/** @internal */
|
|
21
|
-
get wasUsed(): boolean;
|
|
22
|
-
private _isExtensionEnabled;
|
|
23
|
-
/**
|
|
24
|
-
* After exporting a material
|
|
25
|
-
* @param context GLTF context of the material
|
|
26
|
-
* @param node exported GLTF node
|
|
27
|
-
* @param babylonMaterial corresponding babylon material
|
|
28
|
-
* @returns promise, resolves with the material
|
|
29
|
-
*/
|
|
30
|
-
postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
|
|
31
|
-
}
|
|
5
|
+
export * from "./KHR_materials_dispersion.pure.js";
|
|
@@ -1,63 +1,8 @@
|
|
|
1
|
-
import { GLTFExporter } from "../glTFExporter.js";
|
|
2
|
-
import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
|
|
3
|
-
const NAME = "KHR_materials_dispersion";
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* Re-exports the pure implementation and applies the runtime registration side effect.
|
|
3
|
+
* Import "./KHR_materials_dispersion.pure" for tree-shakeable, side-effect-free usage.
|
|
7
4
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
constructor() {
|
|
12
|
-
/** Name of this extension */
|
|
13
|
-
this.name = NAME;
|
|
14
|
-
/** Defines whether this extension is enabled */
|
|
15
|
-
this.enabled = true;
|
|
16
|
-
/** Defines whether this extension is required */
|
|
17
|
-
this.required = false;
|
|
18
|
-
this._wasUsed = false;
|
|
19
|
-
}
|
|
20
|
-
/** Dispose */
|
|
21
|
-
dispose() { }
|
|
22
|
-
/** @internal */
|
|
23
|
-
get wasUsed() {
|
|
24
|
-
return this._wasUsed;
|
|
25
|
-
}
|
|
26
|
-
_isExtensionEnabled(mat) {
|
|
27
|
-
// This extension must not be used on a material that also uses KHR_materials_unlit
|
|
28
|
-
if (mat.unlit) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
const subs = mat.subSurface;
|
|
32
|
-
// this extension requires refraction to be enabled.
|
|
33
|
-
if (!subs.isRefractionEnabled && !subs.isDispersionEnabled) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* After exporting a material
|
|
40
|
-
* @param context GLTF context of the material
|
|
41
|
-
* @param node exported GLTF node
|
|
42
|
-
* @param babylonMaterial corresponding babylon material
|
|
43
|
-
* @returns promise, resolves with the material
|
|
44
|
-
*/
|
|
45
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
46
|
-
postExportMaterialAsync(context, node, babylonMaterial) {
|
|
47
|
-
return new Promise((resolve) => {
|
|
48
|
-
if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {
|
|
49
|
-
this._wasUsed = true;
|
|
50
|
-
const subs = babylonMaterial.subSurface;
|
|
51
|
-
const dispersion = subs.dispersion;
|
|
52
|
-
const dispersionInfo = {
|
|
53
|
-
dispersion: dispersion,
|
|
54
|
-
};
|
|
55
|
-
node.extensions = node.extensions || {};
|
|
56
|
-
node.extensions[NAME] = dispersionInfo;
|
|
57
|
-
}
|
|
58
|
-
resolve(node);
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
GLTFExporter.RegisterExtension(NAME, () => new KHR_materials_dispersion());
|
|
5
|
+
export * from "./KHR_materials_dispersion.pure.js";
|
|
6
|
+
import { RegisterKHR_materials_dispersion } from "./KHR_materials_dispersion.pure.js";
|
|
7
|
+
RegisterKHR_materials_dispersion();
|
|
63
8
|
//# sourceMappingURL=KHR_materials_dispersion.js.map
|