@onerjs/serializers 8.53.5 → 8.53.6
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/3mf.js +666 -270
- package/3MF/core/model/3mf.js.map +1 -1
- package/3MF/core/model/3mf.opc.js +142 -62
- package/3MF/core/model/3mf.opc.js.map +1 -1
- 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/core/xml/xml.interfaces.d.ts +52 -11
- package/3MF/core/xml/xml.interfaces.js +24 -8
- package/3MF/core/xml/xml.interfaces.js.map +1 -1
- 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/objSerializer.d.ts +2 -1
- package/OBJ/objSerializer.js +3 -2
- package/OBJ/objSerializer.js.map +1 -1
- 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 +3 -3
- 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
|
@@ -1,180 +1,8 @@
|
|
|
1
|
-
import { GLTFExporter } from "../glTFExporter.js";
|
|
2
|
-
import { PBRBaseMaterial } from "@onerjs/core/Materials/PBR/pbrBaseMaterial.js";
|
|
3
|
-
import { OpenPBRMaterial } from "@onerjs/core/Materials/PBR/openpbrMaterial.js";
|
|
4
|
-
import { MergeTexturesAsync, CreateRGBAConfiguration, CreateTextureInput, CreateConstantInput } from "@onerjs/core/Materials/Textures/textureMerger.js";
|
|
5
|
-
const NAME = "KHR_materials_anisotropy";
|
|
6
|
-
// Convert OpenPBR anisotropy values to glTF-compatible values
|
|
7
|
-
function OpenpbrAnisotropyStrengthToGltf(baseRoughness, anisotropy) {
|
|
8
|
-
const baseAlpha = baseRoughness * baseRoughness;
|
|
9
|
-
const roughnessT = baseAlpha * Math.sqrt(2.0 / (1.0 + (1 - anisotropy) * (1 - anisotropy)));
|
|
10
|
-
const roughnessB = (1 - anisotropy) * roughnessT;
|
|
11
|
-
const newBaseRoughness = Math.sqrt(roughnessB);
|
|
12
|
-
const newAnisotropyStrength = Math.min(Math.sqrt((roughnessT - baseAlpha) / Math.max(1.0 - baseAlpha, 0.0001)), 1.0);
|
|
13
|
-
return { newBaseRoughness, newAnisotropyStrength };
|
|
14
|
-
}
|
|
15
1
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @param babylonMaterial Source OpenPBR material
|
|
19
|
-
* @returns A unique ID string for the merged anisotropy textures
|
|
20
|
-
* @internal
|
|
2
|
+
* Re-exports the pure implementation and applies the runtime registration side effect.
|
|
3
|
+
* Import "./KHR_materials_anisotropy.pure" for tree-shakeable, side-effect-free usage.
|
|
21
4
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const strengthId = anisoStrengthTexture && anisoStrengthTexture.getInternalTexture() ? anisoStrengthTexture.getInternalTexture().uniqueId : "NoStrength";
|
|
26
|
-
const tangentId = tangentTexture && tangentTexture.getInternalTexture() ? tangentTexture.getInternalTexture().uniqueId : "NoTangent";
|
|
27
|
-
return `${strengthId}_${tangentId}`;
|
|
28
|
-
}
|
|
29
|
-
// In your postExportMaterialAsync method:
|
|
30
|
-
async function CreateMergedAnisotropyTexture(babylonMaterial) {
|
|
31
|
-
const scene = babylonMaterial.getScene();
|
|
32
|
-
const anisoStrengthTexture = babylonMaterial.specularRoughnessAnisotropyTexture;
|
|
33
|
-
const tangentTexture = babylonMaterial.geometryTangentTexture;
|
|
34
|
-
// If we don't have any textures, we don't need to generate anything.
|
|
35
|
-
if (!(anisoStrengthTexture || tangentTexture)) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
return await MergeTexturesAsync("AnisotropyTexture", CreateRGBAConfiguration(tangentTexture ? CreateTextureInput(tangentTexture, 0) : CreateConstantInput(1.0), // tangent x from red channel
|
|
39
|
-
tangentTexture ? CreateTextureInput(tangentTexture, 1) : CreateConstantInput(0.0), // tangent y from green channel
|
|
40
|
-
anisoStrengthTexture ? CreateTextureInput(anisoStrengthTexture, 0) : CreateConstantInput(1.0) // Anisotropy from red channel
|
|
41
|
-
), scene);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* @internal
|
|
45
|
-
*/
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
47
|
-
export class KHR_materials_anisotropy {
|
|
48
|
-
constructor(exporter) {
|
|
49
|
-
/** Name of this extension */
|
|
50
|
-
this.name = NAME;
|
|
51
|
-
/** Defines whether this extension is enabled */
|
|
52
|
-
this.enabled = true;
|
|
53
|
-
/** Defines whether this extension is required */
|
|
54
|
-
this.required = false;
|
|
55
|
-
this._wasUsed = false;
|
|
56
|
-
this._anisoTexturesMap = {};
|
|
57
|
-
this._exporter = exporter;
|
|
58
|
-
}
|
|
59
|
-
dispose() { }
|
|
60
|
-
/** @internal */
|
|
61
|
-
get wasUsed() {
|
|
62
|
-
return this._wasUsed;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* After exporting a material, deal with the additional textures
|
|
66
|
-
* @param context GLTF context of the material
|
|
67
|
-
* @param node exported GLTF node
|
|
68
|
-
* @param babylonMaterial corresponding babylon material
|
|
69
|
-
* @returns array of additional textures to export
|
|
70
|
-
*/
|
|
71
|
-
async postExportMaterialAdditionalTexturesAsync(context, node, babylonMaterial) {
|
|
72
|
-
const additionalTextures = [];
|
|
73
|
-
if (babylonMaterial instanceof PBRBaseMaterial) {
|
|
74
|
-
if (babylonMaterial.anisotropy.isEnabled && !babylonMaterial.anisotropy.legacy) {
|
|
75
|
-
if (babylonMaterial.anisotropy.texture) {
|
|
76
|
-
additionalTextures.push(babylonMaterial.anisotropy.texture);
|
|
77
|
-
}
|
|
78
|
-
return additionalTextures;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
else if (babylonMaterial instanceof OpenPBRMaterial) {
|
|
82
|
-
if (babylonMaterial.specularRoughnessAnisotropy > 0) {
|
|
83
|
-
const texId = GetAnisoTextureId(babylonMaterial);
|
|
84
|
-
if (this._anisoTexturesMap[texId]) {
|
|
85
|
-
additionalTextures.push(this._anisoTexturesMap[texId]);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
const anisoTexture = await CreateMergedAnisotropyTexture(babylonMaterial);
|
|
89
|
-
if (anisoTexture) {
|
|
90
|
-
additionalTextures.push(anisoTexture);
|
|
91
|
-
this._anisoTexturesMap[texId] = anisoTexture;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return additionalTextures;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return [];
|
|
98
|
-
}
|
|
99
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
100
|
-
postExportMaterialAsync(context, node, babylonMaterial) {
|
|
101
|
-
return new Promise((resolve) => {
|
|
102
|
-
var _a;
|
|
103
|
-
if (babylonMaterial instanceof PBRBaseMaterial) {
|
|
104
|
-
if (!babylonMaterial.anisotropy.isEnabled || babylonMaterial.anisotropy.legacy) {
|
|
105
|
-
resolve(node);
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
this._wasUsed = true;
|
|
109
|
-
node.extensions = node.extensions || {};
|
|
110
|
-
const anisotropyTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.anisotropy.texture);
|
|
111
|
-
const anisotropyInfo = {
|
|
112
|
-
anisotropyStrength: babylonMaterial.anisotropy.intensity,
|
|
113
|
-
anisotropyRotation: babylonMaterial.anisotropy.angle,
|
|
114
|
-
anisotropyTexture: anisotropyTextureInfo ?? undefined,
|
|
115
|
-
};
|
|
116
|
-
if (anisotropyInfo.anisotropyTexture !== null) {
|
|
117
|
-
this._exporter._materialNeedsUVsSet.add(babylonMaterial);
|
|
118
|
-
}
|
|
119
|
-
node.extensions[NAME] = anisotropyInfo;
|
|
120
|
-
}
|
|
121
|
-
else if (babylonMaterial instanceof OpenPBRMaterial) {
|
|
122
|
-
if (babylonMaterial.specularRoughnessAnisotropy > 0) {
|
|
123
|
-
this._wasUsed = true;
|
|
124
|
-
node.extensions = node.extensions || {};
|
|
125
|
-
// Check if we can convert from OpenPBR anisotropy to glTF anisotropy
|
|
126
|
-
// Conversion involves both specular roughness and anisotropic roughness changes so,
|
|
127
|
-
// if there are textures for either, we can't reliably convert due to there potentially
|
|
128
|
-
// being different mappings between the textures.
|
|
129
|
-
let roughnessTexture = babylonMaterial.specularRoughnessTexture;
|
|
130
|
-
if (babylonMaterial._useRoughnessFromMetallicTextureGreen) {
|
|
131
|
-
roughnessTexture = babylonMaterial.baseMetalnessTexture;
|
|
132
|
-
}
|
|
133
|
-
const mergedAnisoTexture = this._anisoTexturesMap[babylonMaterial.id];
|
|
134
|
-
// If no textures are being used, we'll always output glTF-style anisotropy.
|
|
135
|
-
// If using OpenPBR anisotropy, convert the constants. Otherwise, just export what we have.
|
|
136
|
-
if (!roughnessTexture && !mergedAnisoTexture) {
|
|
137
|
-
// Convert constants
|
|
138
|
-
let newBaseRoughness = babylonMaterial.specularRoughness;
|
|
139
|
-
let newAnisotropyStrength = babylonMaterial.specularRoughnessAnisotropy;
|
|
140
|
-
if (!babylonMaterial._useGltfStyleAnisotropy) {
|
|
141
|
-
const newParams = OpenpbrAnisotropyStrengthToGltf(babylonMaterial.specularRoughness, babylonMaterial.specularRoughnessAnisotropy);
|
|
142
|
-
newBaseRoughness = newParams.newBaseRoughness;
|
|
143
|
-
newAnisotropyStrength = newParams.newAnisotropyStrength;
|
|
144
|
-
}
|
|
145
|
-
if (node.pbrMetallicRoughness) {
|
|
146
|
-
node.pbrMetallicRoughness.roughnessFactor = newBaseRoughness;
|
|
147
|
-
}
|
|
148
|
-
const anisotropyInfo = {
|
|
149
|
-
anisotropyStrength: newAnisotropyStrength,
|
|
150
|
-
anisotropyRotation: babylonMaterial.geometryTangentAngle + Math.PI * 0.5,
|
|
151
|
-
anisotropyTexture: undefined,
|
|
152
|
-
};
|
|
153
|
-
node.extensions[NAME] = anisotropyInfo;
|
|
154
|
-
return resolve(node);
|
|
155
|
-
}
|
|
156
|
-
const mergedAnisoTextureInfo = mergedAnisoTexture ? this._exporter._materialExporter.getTextureInfo(mergedAnisoTexture) : null;
|
|
157
|
-
const anisotropyInfo = {
|
|
158
|
-
anisotropyStrength: babylonMaterial.specularRoughnessAnisotropy,
|
|
159
|
-
anisotropyRotation: babylonMaterial.geometryTangentAngle,
|
|
160
|
-
anisotropyTexture: mergedAnisoTextureInfo ? mergedAnisoTextureInfo : undefined,
|
|
161
|
-
extensions: {},
|
|
162
|
-
};
|
|
163
|
-
if (!babylonMaterial._useGltfStyleAnisotropy) {
|
|
164
|
-
// Enable OpenPBR extension on this material.
|
|
165
|
-
node.extensions["KHR_materials_openpbr"] = {};
|
|
166
|
-
(_a = this._exporter._glTF).extensionsUsed || (_a.extensionsUsed = []);
|
|
167
|
-
if (this._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr") === -1) {
|
|
168
|
-
this._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr");
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
this._exporter._materialNeedsUVsSet.add(babylonMaterial);
|
|
172
|
-
node.extensions[NAME] = anisotropyInfo;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
resolve(node);
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_anisotropy(exporter));
|
|
5
|
+
export * from "./KHR_materials_anisotropy.pure.js";
|
|
6
|
+
import { RegisterKHR_materials_anisotropy } from "./KHR_materials_anisotropy.pure.js";
|
|
7
|
+
RegisterKHR_materials_anisotropy();
|
|
180
8
|
//# sourceMappingURL=KHR_materials_anisotropy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_materials_anisotropy.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_anisotropy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAErE,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAErE,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAE7I,MAAM,IAAI,GAAG,0BAA0B,CAAC;AAExC,8DAA8D;AAC9D,SAAS,+BAA+B,CAAC,aAAqB,EAAE,UAAkB;IAC9E,MAAM,SAAS,GAAG,aAAa,GAAG,aAAa,CAAC;IAChD,MAAM,UAAU,GAAG,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IAC5F,MAAM,UAAU,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,UAAU,CAAC;IACjD,MAAM,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC/C,MAAM,qBAAqB,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,SAAS,EAAE,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAErH,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,CAAC;AACvD,CAAC;AAED;;;;;;GAMG;AACH,SAAS,iBAAiB,CAAC,eAAgC;IACvD,MAAM,oBAAoB,GAA0B,eAAe,CAAC,kCAAkC,CAAC;IACvG,MAA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D,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,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import { type IMaterial, type IKHRMaterialsAnisotropy } from \"babylonjs-gltf2interface\";\r\nimport { type IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport { type Material } from \"core/Materials/material\";\r\nimport { type Nullable } from \"core/types\";\r\nimport { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport { type BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { OpenPBRMaterial } from \"core/Materials/PBR/openpbrMaterial\";\r\nimport { type ProceduralTexture } from \"core/Materials/Textures/Procedurals/proceduralTexture\";\r\nimport { MergeTexturesAsync, CreateRGBAConfiguration, CreateTextureInput, CreateConstantInput } from \"core/Materials/Textures/textureMerger\";\r\n\r\nconst NAME = \"KHR_materials_anisotropy\";\r\n\r\n// Convert OpenPBR anisotropy values to glTF-compatible values\r\nfunction OpenpbrAnisotropyStrengthToGltf(baseRoughness: number, anisotropy: number) {\r\n const baseAlpha = baseRoughness * baseRoughness;\r\n const roughnessT = baseAlpha * Math.sqrt(2.0 / (1.0 + (1 - anisotropy) * (1 - anisotropy)));\r\n const roughnessB = (1 - anisotropy) * roughnessT;\r\n const newBaseRoughness = Math.sqrt(roughnessB);\r\n const newAnisotropyStrength = Math.min(Math.sqrt((roughnessT - baseAlpha) / Math.max(1.0 - baseAlpha, 0.0001)), 1.0);\r\n\r\n return { newBaseRoughness, newAnisotropyStrength };\r\n}\r\n\r\n/**\r\n * Generate a unique ID for the merged anisotropy textures based on the internal texture data.\r\n * This is used for caching merged textures.\r\n * @param babylonMaterial Source OpenPBR material\r\n * @returns A unique ID string for the merged anisotropy textures\r\n * @internal\r\n */\r\nfunction GetAnisoTextureId(babylonMaterial: OpenPBRMaterial): string {\r\n const anisoStrengthTexture: Nullable<BaseTexture> = babylonMaterial.specularRoughnessAnisotropyTexture;\r\n const tangentTexture = babylonMaterial.geometryTangentTexture;\r\n const strengthId = anisoStrengthTexture && anisoStrengthTexture.getInternalTexture() ? anisoStrengthTexture!.getInternalTexture()!.uniqueId : \"NoStrength\";\r\n const tangentId = tangentTexture && tangentTexture.getInternalTexture() ? tangentTexture!.getInternalTexture()!.uniqueId : \"NoTangent\";\r\n return `${strengthId}_${tangentId}`;\r\n}\r\n\r\n// In your postExportMaterialAsync method:\r\nasync function CreateMergedAnisotropyTexture(babylonMaterial: OpenPBRMaterial): Promise<Nullable<ProceduralTexture>> {\r\n const scene = babylonMaterial.getScene();\r\n\r\n const anisoStrengthTexture: Nullable<BaseTexture> = babylonMaterial.specularRoughnessAnisotropyTexture;\r\n const tangentTexture = babylonMaterial.geometryTangentTexture;\r\n\r\n // If we don't have any textures, we don't need to generate anything.\r\n if (!(anisoStrengthTexture || tangentTexture)) {\r\n return null;\r\n }\r\n\r\n return await MergeTexturesAsync(\r\n \"AnisotropyTexture\",\r\n CreateRGBAConfiguration(\r\n tangentTexture ? CreateTextureInput(tangentTexture, 0) : CreateConstantInput(1.0), // tangent x from red channel\r\n tangentTexture ? CreateTextureInput(tangentTexture, 1) : CreateConstantInput(0.0), // tangent y from green channel\r\n anisoStrengthTexture ? CreateTextureInput(anisoStrengthTexture, 0) : CreateConstantInput(1.0) // Anisotropy from red channel\r\n ),\r\n scene\r\n );\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_anisotropy 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 private _anisoTexturesMap: Record<string, ProceduralTexture> = {};\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 the 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 if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (babylonMaterial.anisotropy.isEnabled && !babylonMaterial.anisotropy.legacy) {\r\n if (babylonMaterial.anisotropy.texture) {\r\n additionalTextures.push(babylonMaterial.anisotropy.texture);\r\n }\r\n return additionalTextures;\r\n }\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.specularRoughnessAnisotropy > 0) {\r\n const texId = GetAnisoTextureId(babylonMaterial);\r\n if (this._anisoTexturesMap[texId]) {\r\n additionalTextures.push(this._anisoTexturesMap[texId]);\r\n } else {\r\n const anisoTexture = await CreateMergedAnisotropyTexture(babylonMaterial);\r\n if (anisoTexture) {\r\n additionalTextures.push(anisoTexture);\r\n this._anisoTexturesMap[texId] = anisoTexture;\r\n }\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 if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (!babylonMaterial.anisotropy.isEnabled || babylonMaterial.anisotropy.legacy) {\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 anisotropyTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.anisotropy.texture);\r\n\r\n const anisotropyInfo: IKHRMaterialsAnisotropy = {\r\n anisotropyStrength: babylonMaterial.anisotropy.intensity,\r\n anisotropyRotation: babylonMaterial.anisotropy.angle,\r\n anisotropyTexture: anisotropyTextureInfo ?? undefined,\r\n };\r\n\r\n if (anisotropyInfo.anisotropyTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = anisotropyInfo;\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.specularRoughnessAnisotropy > 0) {\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n // Check if we can convert from OpenPBR anisotropy to glTF anisotropy\r\n // Conversion involves both specular roughness and anisotropic roughness changes so,\r\n // if there are textures for either, we can't reliably convert due to there potentially\r\n // being different mappings between the textures.\r\n let roughnessTexture: Nullable<BaseTexture> = babylonMaterial.specularRoughnessTexture;\r\n if (babylonMaterial._useRoughnessFromMetallicTextureGreen) {\r\n roughnessTexture = babylonMaterial.baseMetalnessTexture;\r\n }\r\n const mergedAnisoTexture = this._anisoTexturesMap[babylonMaterial.id];\r\n\r\n // If no textures are being used, we'll always output glTF-style anisotropy.\r\n // If using OpenPBR anisotropy, convert the constants. Otherwise, just export what we have.\r\n if (!roughnessTexture && !mergedAnisoTexture) {\r\n // Convert constants\r\n let newBaseRoughness = babylonMaterial.specularRoughness;\r\n let newAnisotropyStrength = babylonMaterial.specularRoughnessAnisotropy;\r\n if (!babylonMaterial._useGltfStyleAnisotropy) {\r\n const newParams = OpenpbrAnisotropyStrengthToGltf(babylonMaterial.specularRoughness, babylonMaterial.specularRoughnessAnisotropy);\r\n newBaseRoughness = newParams.newBaseRoughness;\r\n newAnisotropyStrength = newParams.newAnisotropyStrength;\r\n }\r\n if (node.pbrMetallicRoughness) {\r\n node.pbrMetallicRoughness.roughnessFactor = newBaseRoughness;\r\n }\r\n const anisotropyInfo: IKHRMaterialsAnisotropy = {\r\n anisotropyStrength: newAnisotropyStrength,\r\n anisotropyRotation: babylonMaterial.geometryTangentAngle + Math.PI * 0.5,\r\n anisotropyTexture: undefined,\r\n };\r\n node.extensions[NAME] = anisotropyInfo;\r\n return resolve(node);\r\n }\r\n\r\n const mergedAnisoTextureInfo = mergedAnisoTexture ? this._exporter._materialExporter.getTextureInfo(mergedAnisoTexture) : null;\r\n\r\n const anisotropyInfo: IKHRMaterialsAnisotropy = {\r\n anisotropyStrength: babylonMaterial.specularRoughnessAnisotropy,\r\n anisotropyRotation: babylonMaterial.geometryTangentAngle,\r\n anisotropyTexture: mergedAnisoTextureInfo ? mergedAnisoTextureInfo : undefined,\r\n extensions: {},\r\n };\r\n\r\n if (!babylonMaterial._useGltfStyleAnisotropy) {\r\n // Enable OpenPBR extension on this material.\r\n node.extensions![\"KHR_materials_openpbr\"] = {};\r\n this._exporter._glTF.extensionsUsed ||= [];\r\n if (this._exporter._glTF.extensionsUsed.indexOf(\"KHR_materials_openpbr\") === -1) {\r\n this._exporter._glTF.extensionsUsed.push(\"KHR_materials_openpbr\");\r\n }\r\n }\r\n\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n\r\n node.extensions[NAME] = anisotropyInfo;\r\n }\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_anisotropy(exporter));\r\n"]}
|
|
1
|
+
{"version":3,"file":"KHR_materials_anisotropy.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_anisotropy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,iCAAiC,CAAC;AAEhD,OAAO,EAAE,gCAAgC,EAAE,MAAM,iCAAiC,CAAC;AACnF,gCAAgC,EAAE,CAAC","sourcesContent":["/**\r\n * Re-exports the pure implementation and applies the runtime registration side effect.\r\n * Import \"./KHR_materials_anisotropy.pure\" for tree-shakeable, side-effect-free usage.\r\n */\r\nexport * from \"./KHR_materials_anisotropy.pure\";\r\n\r\nimport { RegisterKHR_materials_anisotropy } from \"./KHR_materials_anisotropy.pure\";\r\nRegisterKHR_materials_anisotropy();\r\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
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 "@onerjs/core/Materials/material.js";
|
|
5
|
+
import { type BaseTexture } from "@onerjs/core/Materials/Textures/baseTexture.js";
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare class KHR_materials_anisotropy implements IGLTFExporterExtensionV2 {
|
|
10
|
+
/** Name of this extension */
|
|
11
|
+
readonly name = "KHR_materials_anisotropy";
|
|
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
|
+
private _anisoTexturesMap;
|
|
19
|
+
constructor(exporter: GLTFExporter);
|
|
20
|
+
dispose(): void;
|
|
21
|
+
/** @internal */
|
|
22
|
+
get wasUsed(): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* After exporting a material, deal with the 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
|
+
postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Registers the KHR_materials_anisotropy glTF serializer extension with the {@link GLTFExporter}.
|
|
35
|
+
* Safe to call multiple times; only the first call has an effect.
|
|
36
|
+
*/
|
|
37
|
+
export declare function RegisterKHR_materials_anisotropy(): void;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { GLTFExporter } from "../glTFExporter.js";
|
|
2
|
+
import { PBRBaseMaterial } from "@onerjs/core/Materials/PBR/pbrBaseMaterial.pure.js";
|
|
3
|
+
import { OpenPBRMaterial } from "@onerjs/core/Materials/PBR/openpbrMaterial.pure.js";
|
|
4
|
+
import { MergeTexturesAsync, CreateRGBAConfiguration, CreateTextureInput, CreateConstantInput } from "@onerjs/core/Materials/Textures/textureMerger.js";
|
|
5
|
+
const NAME = "KHR_materials_anisotropy";
|
|
6
|
+
// Convert OpenPBR anisotropy values to glTF-compatible values
|
|
7
|
+
function OpenpbrAnisotropyStrengthToGltf(baseRoughness, anisotropy) {
|
|
8
|
+
const baseAlpha = baseRoughness * baseRoughness;
|
|
9
|
+
const roughnessT = baseAlpha * Math.sqrt(2.0 / (1.0 + (1 - anisotropy) * (1 - anisotropy)));
|
|
10
|
+
const roughnessB = (1 - anisotropy) * roughnessT;
|
|
11
|
+
const newBaseRoughness = Math.sqrt(roughnessB);
|
|
12
|
+
const newAnisotropyStrength = Math.min(Math.sqrt((roughnessT - baseAlpha) / Math.max(1.0 - baseAlpha, 0.0001)), 1.0);
|
|
13
|
+
return { newBaseRoughness, newAnisotropyStrength };
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Generate a unique ID for the merged anisotropy textures based on the internal texture data.
|
|
17
|
+
* This is used for caching merged textures.
|
|
18
|
+
* @param babylonMaterial Source OpenPBR material
|
|
19
|
+
* @returns A unique ID string for the merged anisotropy textures
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
function GetAnisoTextureId(babylonMaterial) {
|
|
23
|
+
const anisoStrengthTexture = babylonMaterial.specularRoughnessAnisotropyTexture;
|
|
24
|
+
const tangentTexture = babylonMaterial.geometryTangentTexture;
|
|
25
|
+
const strengthId = anisoStrengthTexture && anisoStrengthTexture.getInternalTexture() ? anisoStrengthTexture.getInternalTexture().uniqueId : "NoStrength";
|
|
26
|
+
const tangentId = tangentTexture && tangentTexture.getInternalTexture() ? tangentTexture.getInternalTexture().uniqueId : "NoTangent";
|
|
27
|
+
return `${strengthId}_${tangentId}`;
|
|
28
|
+
}
|
|
29
|
+
// In your postExportMaterialAsync method:
|
|
30
|
+
async function CreateMergedAnisotropyTexture(babylonMaterial) {
|
|
31
|
+
const scene = babylonMaterial.getScene();
|
|
32
|
+
const anisoStrengthTexture = babylonMaterial.specularRoughnessAnisotropyTexture;
|
|
33
|
+
const tangentTexture = babylonMaterial.geometryTangentTexture;
|
|
34
|
+
// If we don't have any textures, we don't need to generate anything.
|
|
35
|
+
if (!(anisoStrengthTexture || tangentTexture)) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return await MergeTexturesAsync("AnisotropyTexture", CreateRGBAConfiguration(tangentTexture ? CreateTextureInput(tangentTexture, 0) : CreateConstantInput(1.0), // tangent x from red channel
|
|
39
|
+
tangentTexture ? CreateTextureInput(tangentTexture, 1) : CreateConstantInput(0.0), // tangent y from green channel
|
|
40
|
+
anisoStrengthTexture ? CreateTextureInput(anisoStrengthTexture, 0) : CreateConstantInput(1.0) // Anisotropy from red channel
|
|
41
|
+
), scene);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
47
|
+
export class KHR_materials_anisotropy {
|
|
48
|
+
constructor(exporter) {
|
|
49
|
+
/** Name of this extension */
|
|
50
|
+
this.name = NAME;
|
|
51
|
+
/** Defines whether this extension is enabled */
|
|
52
|
+
this.enabled = true;
|
|
53
|
+
/** Defines whether this extension is required */
|
|
54
|
+
this.required = false;
|
|
55
|
+
this._wasUsed = false;
|
|
56
|
+
this._anisoTexturesMap = {};
|
|
57
|
+
this._exporter = exporter;
|
|
58
|
+
}
|
|
59
|
+
dispose() { }
|
|
60
|
+
/** @internal */
|
|
61
|
+
get wasUsed() {
|
|
62
|
+
return this._wasUsed;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* After exporting a material, deal with the additional textures
|
|
66
|
+
* @param context GLTF context of the material
|
|
67
|
+
* @param node exported GLTF node
|
|
68
|
+
* @param babylonMaterial corresponding babylon material
|
|
69
|
+
* @returns array of additional textures to export
|
|
70
|
+
*/
|
|
71
|
+
async postExportMaterialAdditionalTexturesAsync(context, node, babylonMaterial) {
|
|
72
|
+
const additionalTextures = [];
|
|
73
|
+
if (babylonMaterial instanceof PBRBaseMaterial) {
|
|
74
|
+
if (babylonMaterial.anisotropy.isEnabled && !babylonMaterial.anisotropy.legacy) {
|
|
75
|
+
if (babylonMaterial.anisotropy.texture) {
|
|
76
|
+
additionalTextures.push(babylonMaterial.anisotropy.texture);
|
|
77
|
+
}
|
|
78
|
+
return additionalTextures;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if (babylonMaterial instanceof OpenPBRMaterial) {
|
|
82
|
+
if (babylonMaterial.specularRoughnessAnisotropy > 0) {
|
|
83
|
+
const texId = GetAnisoTextureId(babylonMaterial);
|
|
84
|
+
if (this._anisoTexturesMap[texId]) {
|
|
85
|
+
additionalTextures.push(this._anisoTexturesMap[texId]);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const anisoTexture = await CreateMergedAnisotropyTexture(babylonMaterial);
|
|
89
|
+
if (anisoTexture) {
|
|
90
|
+
additionalTextures.push(anisoTexture);
|
|
91
|
+
this._anisoTexturesMap[texId] = anisoTexture;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return additionalTextures;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
100
|
+
postExportMaterialAsync(context, node, babylonMaterial) {
|
|
101
|
+
return new Promise((resolve) => {
|
|
102
|
+
var _a;
|
|
103
|
+
if (babylonMaterial instanceof PBRBaseMaterial) {
|
|
104
|
+
if (!babylonMaterial.anisotropy.isEnabled || babylonMaterial.anisotropy.legacy) {
|
|
105
|
+
resolve(node);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
this._wasUsed = true;
|
|
109
|
+
node.extensions = node.extensions || {};
|
|
110
|
+
const anisotropyTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.anisotropy.texture);
|
|
111
|
+
const anisotropyInfo = {
|
|
112
|
+
anisotropyStrength: babylonMaterial.anisotropy.intensity,
|
|
113
|
+
anisotropyRotation: babylonMaterial.anisotropy.angle,
|
|
114
|
+
anisotropyTexture: anisotropyTextureInfo ?? undefined,
|
|
115
|
+
};
|
|
116
|
+
if (anisotropyInfo.anisotropyTexture !== null) {
|
|
117
|
+
this._exporter._materialNeedsUVsSet.add(babylonMaterial);
|
|
118
|
+
}
|
|
119
|
+
node.extensions[NAME] = anisotropyInfo;
|
|
120
|
+
}
|
|
121
|
+
else if (babylonMaterial instanceof OpenPBRMaterial) {
|
|
122
|
+
if (babylonMaterial.specularRoughnessAnisotropy > 0) {
|
|
123
|
+
this._wasUsed = true;
|
|
124
|
+
node.extensions = node.extensions || {};
|
|
125
|
+
// Check if we can convert from OpenPBR anisotropy to glTF anisotropy
|
|
126
|
+
// Conversion involves both specular roughness and anisotropic roughness changes so,
|
|
127
|
+
// if there are textures for either, we can't reliably convert due to there potentially
|
|
128
|
+
// being different mappings between the textures.
|
|
129
|
+
let roughnessTexture = babylonMaterial.specularRoughnessTexture;
|
|
130
|
+
if (babylonMaterial._useRoughnessFromMetallicTextureGreen) {
|
|
131
|
+
roughnessTexture = babylonMaterial.baseMetalnessTexture;
|
|
132
|
+
}
|
|
133
|
+
const mergedAnisoTexture = this._anisoTexturesMap[babylonMaterial.id];
|
|
134
|
+
// If no textures are being used, we'll always output glTF-style anisotropy.
|
|
135
|
+
// If using OpenPBR anisotropy, convert the constants. Otherwise, just export what we have.
|
|
136
|
+
if (!roughnessTexture && !mergedAnisoTexture) {
|
|
137
|
+
// Convert constants
|
|
138
|
+
let newBaseRoughness = babylonMaterial.specularRoughness;
|
|
139
|
+
let newAnisotropyStrength = babylonMaterial.specularRoughnessAnisotropy;
|
|
140
|
+
if (!babylonMaterial._useGltfStyleAnisotropy) {
|
|
141
|
+
const newParams = OpenpbrAnisotropyStrengthToGltf(babylonMaterial.specularRoughness, babylonMaterial.specularRoughnessAnisotropy);
|
|
142
|
+
newBaseRoughness = newParams.newBaseRoughness;
|
|
143
|
+
newAnisotropyStrength = newParams.newAnisotropyStrength;
|
|
144
|
+
}
|
|
145
|
+
if (node.pbrMetallicRoughness) {
|
|
146
|
+
node.pbrMetallicRoughness.roughnessFactor = newBaseRoughness;
|
|
147
|
+
}
|
|
148
|
+
const anisotropyInfo = {
|
|
149
|
+
anisotropyStrength: newAnisotropyStrength,
|
|
150
|
+
anisotropyRotation: babylonMaterial.geometryTangentAngle + Math.PI * 0.5,
|
|
151
|
+
anisotropyTexture: undefined,
|
|
152
|
+
};
|
|
153
|
+
node.extensions[NAME] = anisotropyInfo;
|
|
154
|
+
return resolve(node);
|
|
155
|
+
}
|
|
156
|
+
const mergedAnisoTextureInfo = mergedAnisoTexture ? this._exporter._materialExporter.getTextureInfo(mergedAnisoTexture) : null;
|
|
157
|
+
const anisotropyInfo = {
|
|
158
|
+
anisotropyStrength: babylonMaterial.specularRoughnessAnisotropy,
|
|
159
|
+
anisotropyRotation: babylonMaterial.geometryTangentAngle,
|
|
160
|
+
anisotropyTexture: mergedAnisoTextureInfo ? mergedAnisoTextureInfo : undefined,
|
|
161
|
+
extensions: {},
|
|
162
|
+
};
|
|
163
|
+
if (!babylonMaterial._useGltfStyleAnisotropy) {
|
|
164
|
+
// Enable OpenPBR extension on this material.
|
|
165
|
+
node.extensions["KHR_materials_openpbr"] = {};
|
|
166
|
+
(_a = this._exporter._glTF).extensionsUsed || (_a.extensionsUsed = []);
|
|
167
|
+
if (this._exporter._glTF.extensionsUsed.indexOf("KHR_materials_openpbr") === -1) {
|
|
168
|
+
this._exporter._glTF.extensionsUsed.push("KHR_materials_openpbr");
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
this._exporter._materialNeedsUVsSet.add(babylonMaterial);
|
|
172
|
+
node.extensions[NAME] = anisotropyInfo;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
resolve(node);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
let _Registered = false;
|
|
180
|
+
/**
|
|
181
|
+
* Registers the KHR_materials_anisotropy glTF serializer extension with the {@link GLTFExporter}.
|
|
182
|
+
* Safe to call multiple times; only the first call has an effect.
|
|
183
|
+
*/
|
|
184
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
185
|
+
export function RegisterKHR_materials_anisotropy() {
|
|
186
|
+
if (_Registered) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
_Registered = true;
|
|
190
|
+
GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_anisotropy(exporter));
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=KHR_materials_anisotropy.pure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KHR_materials_anisotropy.pure.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_anisotropy.pure.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAE1E,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,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C","sourcesContent":["import { type IMaterial, type IKHRMaterialsAnisotropy } from \"babylonjs-gltf2interface\";\r\nimport { type IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport { type Material } from \"core/Materials/material\";\r\nimport { type Nullable } from \"core/types\";\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 ProceduralTexture } from \"core/Materials/Textures/Procedurals/proceduralTexture\";\r\nimport { MergeTexturesAsync, CreateRGBAConfiguration, CreateTextureInput, CreateConstantInput } from \"core/Materials/Textures/textureMerger\";\r\n\r\nconst NAME = \"KHR_materials_anisotropy\";\r\n\r\n// Convert OpenPBR anisotropy values to glTF-compatible values\r\nfunction OpenpbrAnisotropyStrengthToGltf(baseRoughness: number, anisotropy: number) {\r\n const baseAlpha = baseRoughness * baseRoughness;\r\n const roughnessT = baseAlpha * Math.sqrt(2.0 / (1.0 + (1 - anisotropy) * (1 - anisotropy)));\r\n const roughnessB = (1 - anisotropy) * roughnessT;\r\n const newBaseRoughness = Math.sqrt(roughnessB);\r\n const newAnisotropyStrength = Math.min(Math.sqrt((roughnessT - baseAlpha) / Math.max(1.0 - baseAlpha, 0.0001)), 1.0);\r\n\r\n return { newBaseRoughness, newAnisotropyStrength };\r\n}\r\n\r\n/**\r\n * Generate a unique ID for the merged anisotropy textures based on the internal texture data.\r\n * This is used for caching merged textures.\r\n * @param babylonMaterial Source OpenPBR material\r\n * @returns A unique ID string for the merged anisotropy textures\r\n * @internal\r\n */\r\nfunction GetAnisoTextureId(babylonMaterial: OpenPBRMaterial): string {\r\n const anisoStrengthTexture: Nullable<BaseTexture> = babylonMaterial.specularRoughnessAnisotropyTexture;\r\n const tangentTexture = babylonMaterial.geometryTangentTexture;\r\n const strengthId = anisoStrengthTexture && anisoStrengthTexture.getInternalTexture() ? anisoStrengthTexture!.getInternalTexture()!.uniqueId : \"NoStrength\";\r\n const tangentId = tangentTexture && tangentTexture.getInternalTexture() ? tangentTexture!.getInternalTexture()!.uniqueId : \"NoTangent\";\r\n return `${strengthId}_${tangentId}`;\r\n}\r\n\r\n// In your postExportMaterialAsync method:\r\nasync function CreateMergedAnisotropyTexture(babylonMaterial: OpenPBRMaterial): Promise<Nullable<ProceduralTexture>> {\r\n const scene = babylonMaterial.getScene();\r\n\r\n const anisoStrengthTexture: Nullable<BaseTexture> = babylonMaterial.specularRoughnessAnisotropyTexture;\r\n const tangentTexture = babylonMaterial.geometryTangentTexture;\r\n\r\n // If we don't have any textures, we don't need to generate anything.\r\n if (!(anisoStrengthTexture || tangentTexture)) {\r\n return null;\r\n }\r\n\r\n return await MergeTexturesAsync(\r\n \"AnisotropyTexture\",\r\n CreateRGBAConfiguration(\r\n tangentTexture ? CreateTextureInput(tangentTexture, 0) : CreateConstantInput(1.0), // tangent x from red channel\r\n tangentTexture ? CreateTextureInput(tangentTexture, 1) : CreateConstantInput(0.0), // tangent y from green channel\r\n anisoStrengthTexture ? CreateTextureInput(anisoStrengthTexture, 0) : CreateConstantInput(1.0) // Anisotropy from red channel\r\n ),\r\n scene\r\n );\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_anisotropy 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 private _anisoTexturesMap: Record<string, ProceduralTexture> = {};\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 the 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 if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (babylonMaterial.anisotropy.isEnabled && !babylonMaterial.anisotropy.legacy) {\r\n if (babylonMaterial.anisotropy.texture) {\r\n additionalTextures.push(babylonMaterial.anisotropy.texture);\r\n }\r\n return additionalTextures;\r\n }\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.specularRoughnessAnisotropy > 0) {\r\n const texId = GetAnisoTextureId(babylonMaterial);\r\n if (this._anisoTexturesMap[texId]) {\r\n additionalTextures.push(this._anisoTexturesMap[texId]);\r\n } else {\r\n const anisoTexture = await CreateMergedAnisotropyTexture(babylonMaterial);\r\n if (anisoTexture) {\r\n additionalTextures.push(anisoTexture);\r\n this._anisoTexturesMap[texId] = anisoTexture;\r\n }\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 if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (!babylonMaterial.anisotropy.isEnabled || babylonMaterial.anisotropy.legacy) {\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 anisotropyTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.anisotropy.texture);\r\n\r\n const anisotropyInfo: IKHRMaterialsAnisotropy = {\r\n anisotropyStrength: babylonMaterial.anisotropy.intensity,\r\n anisotropyRotation: babylonMaterial.anisotropy.angle,\r\n anisotropyTexture: anisotropyTextureInfo ?? undefined,\r\n };\r\n\r\n if (anisotropyInfo.anisotropyTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = anisotropyInfo;\r\n } else if (babylonMaterial instanceof OpenPBRMaterial) {\r\n if (babylonMaterial.specularRoughnessAnisotropy > 0) {\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n // Check if we can convert from OpenPBR anisotropy to glTF anisotropy\r\n // Conversion involves both specular roughness and anisotropic roughness changes so,\r\n // if there are textures for either, we can't reliably convert due to there potentially\r\n // being different mappings between the textures.\r\n let roughnessTexture: Nullable<BaseTexture> = babylonMaterial.specularRoughnessTexture;\r\n if (babylonMaterial._useRoughnessFromMetallicTextureGreen) {\r\n roughnessTexture = babylonMaterial.baseMetalnessTexture;\r\n }\r\n const mergedAnisoTexture = this._anisoTexturesMap[babylonMaterial.id];\r\n\r\n // If no textures are being used, we'll always output glTF-style anisotropy.\r\n // If using OpenPBR anisotropy, convert the constants. Otherwise, just export what we have.\r\n if (!roughnessTexture && !mergedAnisoTexture) {\r\n // Convert constants\r\n let newBaseRoughness = babylonMaterial.specularRoughness;\r\n let newAnisotropyStrength = babylonMaterial.specularRoughnessAnisotropy;\r\n if (!babylonMaterial._useGltfStyleAnisotropy) {\r\n const newParams = OpenpbrAnisotropyStrengthToGltf(babylonMaterial.specularRoughness, babylonMaterial.specularRoughnessAnisotropy);\r\n newBaseRoughness = newParams.newBaseRoughness;\r\n newAnisotropyStrength = newParams.newAnisotropyStrength;\r\n }\r\n if (node.pbrMetallicRoughness) {\r\n node.pbrMetallicRoughness.roughnessFactor = newBaseRoughness;\r\n }\r\n const anisotropyInfo: IKHRMaterialsAnisotropy = {\r\n anisotropyStrength: newAnisotropyStrength,\r\n anisotropyRotation: babylonMaterial.geometryTangentAngle + Math.PI * 0.5,\r\n anisotropyTexture: undefined,\r\n };\r\n node.extensions[NAME] = anisotropyInfo;\r\n return resolve(node);\r\n }\r\n\r\n const mergedAnisoTextureInfo = mergedAnisoTexture ? this._exporter._materialExporter.getTextureInfo(mergedAnisoTexture) : null;\r\n\r\n const anisotropyInfo: IKHRMaterialsAnisotropy = {\r\n anisotropyStrength: babylonMaterial.specularRoughnessAnisotropy,\r\n anisotropyRotation: babylonMaterial.geometryTangentAngle,\r\n anisotropyTexture: mergedAnisoTextureInfo ? mergedAnisoTextureInfo : undefined,\r\n extensions: {},\r\n };\r\n\r\n if (!babylonMaterial._useGltfStyleAnisotropy) {\r\n // Enable OpenPBR extension on this material.\r\n node.extensions![\"KHR_materials_openpbr\"] = {};\r\n this._exporter._glTF.extensionsUsed ||= [];\r\n if (this._exporter._glTF.extensionsUsed.indexOf(\"KHR_materials_openpbr\") === -1) {\r\n this._exporter._glTF.extensionsUsed.push(\"KHR_materials_openpbr\");\r\n }\r\n }\r\n\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n\r\n node.extensions[NAME] = anisotropyInfo;\r\n }\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_anisotropy 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_anisotropy(): 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_anisotropy(exporter));\r\n}\r\n"]}
|
|
@@ -1,32 +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 "@onerjs/core/Materials/material.js";
|
|
5
|
-
import { type BaseTexture } from "@onerjs/core/Materials/Textures/baseTexture.js";
|
|
6
1
|
/**
|
|
7
|
-
*
|
|
2
|
+
* Re-exports the pure implementation and applies the runtime registration side effect.
|
|
3
|
+
* Import "./KHR_materials_clearcoat.pure" for tree-shakeable, side-effect-free usage.
|
|
8
4
|
*/
|
|
9
|
-
export
|
|
10
|
-
/** Name of this extension */
|
|
11
|
-
readonly name = "KHR_materials_clearcoat";
|
|
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
|
-
/**
|
|
20
|
-
* Cache that holds temporary merged textures created during export
|
|
21
|
-
*/
|
|
22
|
-
private _mergedTexturesMap;
|
|
23
|
-
/**
|
|
24
|
-
* Cache that holds internal textures of merged textures created during export
|
|
25
|
-
*/
|
|
26
|
-
private _cachedInternalTexturesMap;
|
|
27
|
-
dispose(): void;
|
|
28
|
-
/** @internal */
|
|
29
|
-
get wasUsed(): boolean;
|
|
30
|
-
postExportMaterialAdditionalTexturesAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<BaseTexture[]>;
|
|
31
|
-
postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
|
|
32
|
-
}
|
|
5
|
+
export * from "./KHR_materials_clearcoat.pure.js";
|