@babylonjs/serializers 9.13.0 → 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
|
@@ -1,145 +1,8 @@
|
|
|
1
|
-
import { Vector3, Quaternion, TmpVectors } from "@babylonjs/core/Maths/math.vector.js";
|
|
2
|
-
import { Light } from "@babylonjs/core/Lights/light.js";
|
|
3
|
-
import { ShadowLight } from "@babylonjs/core/Lights/shadowLight.js";
|
|
4
|
-
import { GLTFExporter } from "../glTFExporter.js";
|
|
5
|
-
import { Logger } from "@babylonjs/core/Misc/logger.js";
|
|
6
|
-
import { ConvertToRightHandedPosition, OmitDefaultValues, CollapseChildIntoParent, IsChildCollapsible } from "../glTFUtilities.js";
|
|
7
|
-
const NAME = "KHR_lights_punctual";
|
|
8
|
-
const DEFAULTS = {
|
|
9
|
-
name: "",
|
|
10
|
-
color: [1, 1, 1],
|
|
11
|
-
intensity: 1,
|
|
12
|
-
range: Number.MAX_VALUE,
|
|
13
|
-
};
|
|
14
|
-
const SPOTDEFAULTS = {
|
|
15
|
-
innerConeAngle: 0,
|
|
16
|
-
outerConeAngle: Math.PI / 4.0,
|
|
17
|
-
};
|
|
18
|
-
const LIGHTDIRECTION = Vector3.Backward();
|
|
19
1
|
/**
|
|
20
|
-
*
|
|
2
|
+
* Re-exports the pure implementation and applies the runtime registration side effect.
|
|
3
|
+
* Import "./KHR_lights_punctual.pure" for tree-shakeable, side-effect-free usage.
|
|
21
4
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* @internal
|
|
26
|
-
*/
|
|
27
|
-
constructor(exporter) {
|
|
28
|
-
/** The name of this extension. */
|
|
29
|
-
this.name = NAME;
|
|
30
|
-
/** Defines whether this extension is enabled. */
|
|
31
|
-
this.enabled = true;
|
|
32
|
-
/** Defines whether this extension is required */
|
|
33
|
-
this.required = false;
|
|
34
|
-
this._exporter = exporter;
|
|
35
|
-
}
|
|
36
|
-
/** @internal */
|
|
37
|
-
dispose() {
|
|
38
|
-
this._lights = null;
|
|
39
|
-
}
|
|
40
|
-
/** @internal */
|
|
41
|
-
get wasUsed() {
|
|
42
|
-
return !!this._lights;
|
|
43
|
-
}
|
|
44
|
-
/** @internal */
|
|
45
|
-
onExporting() {
|
|
46
|
-
this._exporter._glTF.extensions[NAME] = this._lights;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Define this method to modify the default behavior when exporting a node
|
|
50
|
-
* @param context The context when exporting the node
|
|
51
|
-
* @param node glTF node
|
|
52
|
-
* @param babylonNode BabylonJS node
|
|
53
|
-
* @param nodeMap Node mapping of babylon node to glTF node index
|
|
54
|
-
* @param convertToRightHanded Flag to convert the values to right-handed
|
|
55
|
-
* @returns nullable INode promise
|
|
56
|
-
*/
|
|
57
|
-
async postExportNodeAsync(context, node, babylonNode, nodeMap, convertToRightHanded) {
|
|
58
|
-
return await new Promise((resolve) => {
|
|
59
|
-
if (!(babylonNode instanceof Light)) {
|
|
60
|
-
resolve(node);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
const lightType = babylonNode.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT
|
|
64
|
-
? "point" /* KHRLightsPunctual_LightType.POINT */
|
|
65
|
-
: babylonNode.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT
|
|
66
|
-
? "directional" /* KHRLightsPunctual_LightType.DIRECTIONAL */
|
|
67
|
-
: babylonNode.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT
|
|
68
|
-
? "spot" /* KHRLightsPunctual_LightType.SPOT */
|
|
69
|
-
: null;
|
|
70
|
-
if (!lightType || !(babylonNode instanceof ShadowLight)) {
|
|
71
|
-
Logger.Warn(`${context}: Light ${babylonNode.name} is not supported in ${NAME}`);
|
|
72
|
-
resolve(node);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
if (babylonNode.falloffType !== Light.FALLOFF_GLTF) {
|
|
76
|
-
Logger.Warn(`${context}: Light falloff for ${babylonNode.name} does not match the ${NAME} specification!`);
|
|
77
|
-
}
|
|
78
|
-
// Set the node's translation and rotation here, since lights are not handled in exportNodeAsync
|
|
79
|
-
if (!babylonNode.position.equalsToFloats(0, 0, 0)) {
|
|
80
|
-
const translation = TmpVectors.Vector3[0].copyFrom(babylonNode.position);
|
|
81
|
-
if (convertToRightHanded) {
|
|
82
|
-
ConvertToRightHandedPosition(translation);
|
|
83
|
-
}
|
|
84
|
-
node.translation = translation.asArray();
|
|
85
|
-
}
|
|
86
|
-
// Represent the Babylon light's direction as a quaternion
|
|
87
|
-
// relative to glTF lights' forward direction, (0, 0, -1).
|
|
88
|
-
if (lightType !== "point" /* KHRLightsPunctual_LightType.POINT */) {
|
|
89
|
-
const direction = babylonNode.direction.normalizeToRef(TmpVectors.Vector3[0]);
|
|
90
|
-
if (convertToRightHanded) {
|
|
91
|
-
ConvertToRightHandedPosition(direction);
|
|
92
|
-
}
|
|
93
|
-
const lightRotationQuaternion = Quaternion.FromUnitVectorsToRef(LIGHTDIRECTION, direction, TmpVectors.Quaternion[0]);
|
|
94
|
-
if (!Quaternion.IsIdentity(lightRotationQuaternion)) {
|
|
95
|
-
node.rotation = lightRotationQuaternion.asArray();
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const light = {
|
|
99
|
-
type: lightType,
|
|
100
|
-
name: babylonNode.name,
|
|
101
|
-
color: babylonNode.diffuse.asArray(),
|
|
102
|
-
intensity: babylonNode.intensity,
|
|
103
|
-
range: babylonNode.range,
|
|
104
|
-
};
|
|
105
|
-
OmitDefaultValues(light, DEFAULTS);
|
|
106
|
-
// Separately handle the required 'spot' field for spot lights
|
|
107
|
-
if (lightType === "spot" /* KHRLightsPunctual_LightType.SPOT */) {
|
|
108
|
-
const babylonSpotLight = babylonNode;
|
|
109
|
-
light.spot = {
|
|
110
|
-
innerConeAngle: babylonSpotLight.innerAngle / 2.0,
|
|
111
|
-
outerConeAngle: babylonSpotLight.angle / 2.0,
|
|
112
|
-
};
|
|
113
|
-
OmitDefaultValues(light.spot, SPOTDEFAULTS);
|
|
114
|
-
}
|
|
115
|
-
this._lights || (this._lights = {
|
|
116
|
-
lights: [],
|
|
117
|
-
});
|
|
118
|
-
this._lights.lights.push(light);
|
|
119
|
-
const lightReference = {
|
|
120
|
-
light: this._lights.lights.length - 1,
|
|
121
|
-
};
|
|
122
|
-
// Assign the light to its parent node, if possible, to condense the glTF
|
|
123
|
-
// Why and when: the glTF loader generates a new parent TransformNode for each light node, which we should undo on export
|
|
124
|
-
const parentBabylonNode = babylonNode.parent;
|
|
125
|
-
if (parentBabylonNode && IsChildCollapsible(babylonNode, parentBabylonNode)) {
|
|
126
|
-
const parentNodeIndex = nodeMap.get(parentBabylonNode);
|
|
127
|
-
if (parentNodeIndex) {
|
|
128
|
-
// Combine the light's transformation with the parent's
|
|
129
|
-
const parentNode = this._exporter._nodes[parentNodeIndex];
|
|
130
|
-
CollapseChildIntoParent(node, parentNode);
|
|
131
|
-
parentNode.extensions || (parentNode.extensions = {});
|
|
132
|
-
parentNode.extensions[NAME] = lightReference;
|
|
133
|
-
// Do not export the original node
|
|
134
|
-
resolve(null);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
node.extensions || (node.extensions = {});
|
|
139
|
-
node.extensions[NAME] = lightReference;
|
|
140
|
-
resolve(node);
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_lights_punctual(exporter));
|
|
5
|
+
export * from "./KHR_lights_punctual.pure.js";
|
|
6
|
+
import { RegisterKHR_lights_punctual } from "./KHR_lights_punctual.pure.js";
|
|
7
|
+
RegisterKHR_lights_punctual();
|
|
145
8
|
//# sourceMappingURL=KHR_lights_punctual.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_lights_punctual.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_lights_punctual.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEhI,MAAM,IAAI,GAAG,qBAAqB,CAAC;AACnC,MAAM,QAAQ,GAA2C;IACrD,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAChB,SAAS,EAAE,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC,SAAS;CAC1B,CAAC;AACF,MAAM,YAAY,GAAkD;IAChE,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG;CAChC,CAAC;AACF,MAAM,cAAc,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;AAE1C;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,m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AC;oBAC1D,uBAAuB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;oBAC1C,UAAU,CAAC,UAAU,KAArB,UAAU,CAAC,UAAU,GAAK,EAAE,EAAC;oBAC7B,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;oBAE7C,kCAAkC;oBAClC,OAAO,CAAC,IAAI,CAAC,CAAC;oBACd,OAAO;gBACX,CAAC;YACL,CAAC;YAED,IAAI,CAAC,UAAU,KAAf,IAAI,CAAC,UAAU,GAAK,EAAE,EAAC;YACvB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;YACvC,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,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import { type SpotLight } from \"core/Lights/spotLight\";\r\nimport { type Nullable } from \"core/types\";\r\nimport { Vector3, Quaternion, TmpVectors } from \"core/Maths/math.vector\";\r\nimport { Light } from \"core/Lights/light\";\r\nimport { type Node } from \"core/node\";\r\nimport { ShadowLight } from \"core/Lights/shadowLight\";\r\nimport { type INode, type IKHRLightsPunctual_LightReference, type IKHRLightsPunctual_Light, type IKHRLightsPunctual, KHRLightsPunctual_LightType } from \"babylonjs-gltf2interface\";\r\nimport { type IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { ConvertToRightHandedPosition, OmitDefaultValues, CollapseChildIntoParent, IsChildCollapsible } from \"../glTFUtilities\";\r\n\r\nconst NAME = \"KHR_lights_punctual\";\r\nconst DEFAULTS: Omit<IKHRLightsPunctual_Light, \"type\"> = {\r\n name: \"\",\r\n color: [1, 1, 1],\r\n intensity: 1,\r\n range: Number.MAX_VALUE,\r\n};\r\nconst SPOTDEFAULTS: NonNullable<IKHRLightsPunctual_Light[\"spot\"]> = {\r\n innerConeAngle: 0,\r\n outerConeAngle: Math.PI / 4.0,\r\n};\r\nconst LIGHTDIRECTION = Vector3.Backward();\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_lights_punctual implements IGLTFExporterExtensionV2 {\r\n /** The name of this extension. */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled. */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n /** Reference to the glTF exporter */\r\n private _exporter: GLTFExporter;\r\n\r\n private _lights: IKHRLightsPunctual;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(exporter: GLTFExporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._lights as any) = null;\r\n }\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return !!this._lights;\r\n }\r\n\r\n /** @internal */\r\n public onExporting(): void {\r\n this._exporter._glTF.extensions![NAME] = this._lights;\r\n }\r\n /**\r\n * Define this method to modify the default behavior when exporting a node\r\n * @param context The context when exporting the node\r\n * @param node glTF node\r\n * @param babylonNode BabylonJS node\r\n * @param nodeMap Node mapping of babylon node to glTF node index\r\n * @param convertToRightHanded Flag to convert the values to right-handed\r\n * @returns nullable INode promise\r\n */\r\n public async postExportNodeAsync(context: string, node: INode, babylonNode: Node, nodeMap: Map<Node, number>, convertToRightHanded: boolean): Promise<Nullable<INode>> {\r\n return await new Promise((resolve) => {\r\n if (!(babylonNode instanceof Light)) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n const lightType =\r\n babylonNode.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT\r\n ? KHRLightsPunctual_LightType.POINT\r\n : babylonNode.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT\r\n ? KHRLightsPunctual_LightType.DIRECTIONAL\r\n : babylonNode.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT\r\n ? KHRLightsPunctual_LightType.SPOT\r\n : null;\r\n if (!lightType || !(babylonNode instanceof ShadowLight)) {\r\n Logger.Warn(`${context}: Light ${babylonNode.name} is not supported in ${NAME}`);\r\n resolve(node);\r\n return;\r\n }\r\n\r\n if (babylonNode.falloffType !== Light.FALLOFF_GLTF) {\r\n Logger.Warn(`${context}: Light falloff for ${babylonNode.name} does not match the ${NAME} specification!`);\r\n }\r\n\r\n // Set the node's translation and rotation here, since lights are not handled in exportNodeAsync\r\n if (!babylonNode.position.equalsToFloats(0, 0, 0)) {\r\n const translation = TmpVectors.Vector3[0].copyFrom(babylonNode.position);\r\n if (convertToRightHanded) {\r\n ConvertToRightHandedPosition(translation);\r\n }\r\n node.translation = translation.asArray();\r\n }\r\n\r\n // Represent the Babylon light's direction as a quaternion\r\n // relative to glTF lights' forward direction, (0, 0, -1).\r\n if (lightType !== KHRLightsPunctual_LightType.POINT) {\r\n const direction = babylonNode.direction.normalizeToRef(TmpVectors.Vector3[0]);\r\n if (convertToRightHanded) {\r\n ConvertToRightHandedPosition(direction);\r\n }\r\n\r\n const lightRotationQuaternion = Quaternion.FromUnitVectorsToRef(LIGHTDIRECTION, direction, TmpVectors.Quaternion[0]);\r\n if (!Quaternion.IsIdentity(lightRotationQuaternion)) {\r\n node.rotation = lightRotationQuaternion.asArray();\r\n }\r\n }\r\n\r\n const light: IKHRLightsPunctual_Light = {\r\n type: lightType,\r\n name: babylonNode.name,\r\n color: babylonNode.diffuse.asArray(),\r\n intensity: babylonNode.intensity,\r\n range: babylonNode.range,\r\n };\r\n OmitDefaultValues(light, DEFAULTS);\r\n\r\n // Separately handle the required 'spot' field for spot lights\r\n if (lightType === KHRLightsPunctual_LightType.SPOT) {\r\n const babylonSpotLight = babylonNode as SpotLight;\r\n light.spot = {\r\n innerConeAngle: babylonSpotLight.innerAngle / 2.0,\r\n outerConeAngle: babylonSpotLight.angle / 2.0,\r\n };\r\n OmitDefaultValues(light.spot, SPOTDEFAULTS);\r\n }\r\n\r\n this._lights ||= {\r\n lights: [],\r\n };\r\n this._lights.lights.push(light);\r\n\r\n const lightReference: IKHRLightsPunctual_LightReference = {\r\n light: this._lights.lights.length - 1,\r\n };\r\n\r\n // Assign the light to its parent node, if possible, to condense the glTF\r\n // Why and when: the glTF loader generates a new parent TransformNode for each light node, which we should undo on export\r\n const parentBabylonNode = babylonNode.parent;\r\n\r\n if (parentBabylonNode && IsChildCollapsible(babylonNode, parentBabylonNode)) {\r\n const parentNodeIndex = nodeMap.get(parentBabylonNode);\r\n if (parentNodeIndex) {\r\n // Combine the light's transformation with the parent's\r\n const parentNode = this._exporter._nodes[parentNodeIndex];\r\n CollapseChildIntoParent(node, parentNode);\r\n parentNode.extensions ||= {};\r\n parentNode.extensions[NAME] = lightReference;\r\n\r\n // Do not export the original node\r\n resolve(null);\r\n return;\r\n }\r\n }\r\n\r\n node.extensions ||= {};\r\n node.extensions[NAME] = lightReference;\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_lights_punctual(exporter));\r\n"]}
|
|
1
|
+
{"version":3,"file":"KHR_lights_punctual.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_lights_punctual.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,4BAA4B,CAAC;AAE3C,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AACzE,2BAA2B,EAAE,CAAC","sourcesContent":["/**\r\n * Re-exports the pure implementation and applies the runtime registration side effect.\r\n * Import \"./KHR_lights_punctual.pure\" for tree-shakeable, side-effect-free usage.\r\n */\r\nexport * from \"./KHR_lights_punctual.pure\";\r\n\r\nimport { RegisterKHR_lights_punctual } from \"./KHR_lights_punctual.pure\";\r\nRegisterKHR_lights_punctual();\r\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Nullable } from "@babylonjs/core/types.js";
|
|
2
|
+
import { type Node } from "@babylonjs/core/node.js";
|
|
3
|
+
import { type INode } from "babylonjs-gltf2interface";
|
|
4
|
+
import { type IGLTFExporterExtensionV2 } from "../glTFExporterExtension.js";
|
|
5
|
+
import { GLTFExporter } from "../glTFExporter.js";
|
|
6
|
+
/**
|
|
7
|
+
* [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
|
|
8
|
+
*/
|
|
9
|
+
export declare class KHR_lights_punctual implements IGLTFExporterExtensionV2 {
|
|
10
|
+
/** The name of this extension. */
|
|
11
|
+
readonly name = "KHR_lights_punctual";
|
|
12
|
+
/** Defines whether this extension is enabled. */
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
/** Defines whether this extension is required */
|
|
15
|
+
required: boolean;
|
|
16
|
+
/** Reference to the glTF exporter */
|
|
17
|
+
private _exporter;
|
|
18
|
+
private _lights;
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
constructor(exporter: GLTFExporter);
|
|
23
|
+
/** @internal */
|
|
24
|
+
dispose(): void;
|
|
25
|
+
/** @internal */
|
|
26
|
+
get wasUsed(): boolean;
|
|
27
|
+
/** @internal */
|
|
28
|
+
onExporting(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Define this method to modify the default behavior when exporting a node
|
|
31
|
+
* @param context The context when exporting the node
|
|
32
|
+
* @param node glTF node
|
|
33
|
+
* @param babylonNode BabylonJS node
|
|
34
|
+
* @param nodeMap Node mapping of babylon node to glTF node index
|
|
35
|
+
* @param convertToRightHanded Flag to convert the values to right-handed
|
|
36
|
+
* @returns nullable INode promise
|
|
37
|
+
*/
|
|
38
|
+
postExportNodeAsync(context: string, node: INode, babylonNode: Node, nodeMap: Map<Node, number>, convertToRightHanded: boolean): Promise<Nullable<INode>>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Registers the KHR_lights_punctual glTF serializer extension with the {@link GLTFExporter}.
|
|
42
|
+
* Safe to call multiple times; only the first call has an effect.
|
|
43
|
+
*/
|
|
44
|
+
export declare function RegisterKHR_lights_punctual(): void;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { Vector3, Quaternion, TmpVectors } from "@babylonjs/core/Maths/math.vector.pure.js";
|
|
2
|
+
import { Light } from "@babylonjs/core/Lights/light.js";
|
|
3
|
+
import { ShadowLight } from "@babylonjs/core/Lights/shadowLight.js";
|
|
4
|
+
import { GLTFExporter } from "../glTFExporter.js";
|
|
5
|
+
import { Logger } from "@babylonjs/core/Misc/logger.js";
|
|
6
|
+
import { ConvertToRightHandedPosition, OmitDefaultValues, CollapseChildIntoParent, IsChildCollapsible } from "../glTFUtilities.js";
|
|
7
|
+
const NAME = "KHR_lights_punctual";
|
|
8
|
+
const DEFAULTS = {
|
|
9
|
+
name: "",
|
|
10
|
+
color: [1, 1, 1],
|
|
11
|
+
intensity: 1,
|
|
12
|
+
range: Number.MAX_VALUE,
|
|
13
|
+
};
|
|
14
|
+
const SPOTDEFAULTS = {
|
|
15
|
+
innerConeAngle: 0,
|
|
16
|
+
outerConeAngle: Math.PI / 4.0,
|
|
17
|
+
};
|
|
18
|
+
const LIGHTDIRECTION = /*#__PURE__*/ Vector3.Backward();
|
|
19
|
+
/**
|
|
20
|
+
* [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
|
|
21
|
+
*/
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
23
|
+
export class KHR_lights_punctual {
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
constructor(exporter) {
|
|
28
|
+
/** The name of this extension. */
|
|
29
|
+
this.name = NAME;
|
|
30
|
+
/** Defines whether this extension is enabled. */
|
|
31
|
+
this.enabled = true;
|
|
32
|
+
/** Defines whether this extension is required */
|
|
33
|
+
this.required = false;
|
|
34
|
+
this._exporter = exporter;
|
|
35
|
+
}
|
|
36
|
+
/** @internal */
|
|
37
|
+
dispose() {
|
|
38
|
+
this._lights = null;
|
|
39
|
+
}
|
|
40
|
+
/** @internal */
|
|
41
|
+
get wasUsed() {
|
|
42
|
+
return !!this._lights;
|
|
43
|
+
}
|
|
44
|
+
/** @internal */
|
|
45
|
+
onExporting() {
|
|
46
|
+
this._exporter._glTF.extensions[NAME] = this._lights;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Define this method to modify the default behavior when exporting a node
|
|
50
|
+
* @param context The context when exporting the node
|
|
51
|
+
* @param node glTF node
|
|
52
|
+
* @param babylonNode BabylonJS node
|
|
53
|
+
* @param nodeMap Node mapping of babylon node to glTF node index
|
|
54
|
+
* @param convertToRightHanded Flag to convert the values to right-handed
|
|
55
|
+
* @returns nullable INode promise
|
|
56
|
+
*/
|
|
57
|
+
async postExportNodeAsync(context, node, babylonNode, nodeMap, convertToRightHanded) {
|
|
58
|
+
return await new Promise((resolve) => {
|
|
59
|
+
if (!(babylonNode instanceof Light)) {
|
|
60
|
+
resolve(node);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const lightType = babylonNode.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT
|
|
64
|
+
? "point" /* KHRLightsPunctual_LightType.POINT */
|
|
65
|
+
: babylonNode.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT
|
|
66
|
+
? "directional" /* KHRLightsPunctual_LightType.DIRECTIONAL */
|
|
67
|
+
: babylonNode.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT
|
|
68
|
+
? "spot" /* KHRLightsPunctual_LightType.SPOT */
|
|
69
|
+
: null;
|
|
70
|
+
if (!lightType || !(babylonNode instanceof ShadowLight)) {
|
|
71
|
+
Logger.Warn(`${context}: Light ${babylonNode.name} is not supported in ${NAME}`);
|
|
72
|
+
resolve(node);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (babylonNode.falloffType !== Light.FALLOFF_GLTF) {
|
|
76
|
+
Logger.Warn(`${context}: Light falloff for ${babylonNode.name} does not match the ${NAME} specification!`);
|
|
77
|
+
}
|
|
78
|
+
// Set the node's translation and rotation here, since lights are not handled in exportNodeAsync
|
|
79
|
+
if (!babylonNode.position.equalsToFloats(0, 0, 0)) {
|
|
80
|
+
const translation = TmpVectors.Vector3[0].copyFrom(babylonNode.position);
|
|
81
|
+
if (convertToRightHanded) {
|
|
82
|
+
ConvertToRightHandedPosition(translation);
|
|
83
|
+
}
|
|
84
|
+
node.translation = translation.asArray();
|
|
85
|
+
}
|
|
86
|
+
// Represent the Babylon light's direction as a quaternion
|
|
87
|
+
// relative to glTF lights' forward direction, (0, 0, -1).
|
|
88
|
+
if (lightType !== "point" /* KHRLightsPunctual_LightType.POINT */) {
|
|
89
|
+
const direction = babylonNode.direction.normalizeToRef(TmpVectors.Vector3[0]);
|
|
90
|
+
if (convertToRightHanded) {
|
|
91
|
+
ConvertToRightHandedPosition(direction);
|
|
92
|
+
}
|
|
93
|
+
const lightRotationQuaternion = Quaternion.FromUnitVectorsToRef(LIGHTDIRECTION, direction, TmpVectors.Quaternion[0]);
|
|
94
|
+
if (!Quaternion.IsIdentity(lightRotationQuaternion)) {
|
|
95
|
+
node.rotation = lightRotationQuaternion.asArray();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const light = {
|
|
99
|
+
type: lightType,
|
|
100
|
+
name: babylonNode.name,
|
|
101
|
+
color: babylonNode.diffuse.asArray(),
|
|
102
|
+
intensity: babylonNode.intensity,
|
|
103
|
+
range: babylonNode.range,
|
|
104
|
+
};
|
|
105
|
+
OmitDefaultValues(light, DEFAULTS);
|
|
106
|
+
// Separately handle the required 'spot' field for spot lights
|
|
107
|
+
if (lightType === "spot" /* KHRLightsPunctual_LightType.SPOT */) {
|
|
108
|
+
const babylonSpotLight = babylonNode;
|
|
109
|
+
light.spot = {
|
|
110
|
+
innerConeAngle: babylonSpotLight.innerAngle / 2.0,
|
|
111
|
+
outerConeAngle: babylonSpotLight.angle / 2.0,
|
|
112
|
+
};
|
|
113
|
+
OmitDefaultValues(light.spot, SPOTDEFAULTS);
|
|
114
|
+
}
|
|
115
|
+
this._lights || (this._lights = {
|
|
116
|
+
lights: [],
|
|
117
|
+
});
|
|
118
|
+
this._lights.lights.push(light);
|
|
119
|
+
const lightReference = {
|
|
120
|
+
light: this._lights.lights.length - 1,
|
|
121
|
+
};
|
|
122
|
+
// Assign the light to its parent node, if possible, to condense the glTF
|
|
123
|
+
// Why and when: the glTF loader generates a new parent TransformNode for each light node, which we should undo on export
|
|
124
|
+
const parentBabylonNode = babylonNode.parent;
|
|
125
|
+
if (parentBabylonNode && IsChildCollapsible(babylonNode, parentBabylonNode)) {
|
|
126
|
+
const parentNodeIndex = nodeMap.get(parentBabylonNode);
|
|
127
|
+
if (parentNodeIndex) {
|
|
128
|
+
// Combine the light's transformation with the parent's
|
|
129
|
+
const parentNode = this._exporter._nodes[parentNodeIndex];
|
|
130
|
+
CollapseChildIntoParent(node, parentNode);
|
|
131
|
+
parentNode.extensions || (parentNode.extensions = {});
|
|
132
|
+
parentNode.extensions[NAME] = lightReference;
|
|
133
|
+
// Do not export the original node
|
|
134
|
+
resolve(null);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
node.extensions || (node.extensions = {});
|
|
139
|
+
node.extensions[NAME] = lightReference;
|
|
140
|
+
resolve(node);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
let _Registered = false;
|
|
145
|
+
/**
|
|
146
|
+
* Registers the KHR_lights_punctual glTF serializer extension with the {@link GLTFExporter}.
|
|
147
|
+
* Safe to call multiple times; only the first call has an effect.
|
|
148
|
+
*/
|
|
149
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
150
|
+
export function RegisterKHR_lights_punctual() {
|
|
151
|
+
if (_Registered) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
_Registered = true;
|
|
155
|
+
GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_lights_punctual(exporter));
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=KHR_lights_punctual.pure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KHR_lights_punctual.pure.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_lights_punctual.pure.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEhI,MAAM,IAAI,GAAG,qBAAqB,CAAC;AACnC,MAAM,QAAQ,GAA2C;IACrD,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAChB,SAAS,EAAE,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC,SAAS;CAC1B,CAAC;AACF,MAAM,YAAY,GAAkD;IAChE,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG;CAChC,CAAC;AACF,MAAM,cAAc,GAAG,aAAa,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;AAExD;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,mBAAmB;IAe5B;;OAEG;IACH,YAAY,QAAsB;QAjBlC,kCAAkC;QAClB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1C,UAAU,CAAC,UAAU,KAArB,UAAU,CAAC,UAAU,GAAK,EAAE,EAAC;oBAC7B,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;oBAE7C,kCAAkC;oBAClC,OAAO,CAAC,IAAI,CAAC,CAAC;oBACd,OAAO;gBACX,CAAC;YACL,CAAC;YAED,IAAI,CAAC,UAAU,KAAf,IAAI,CAAC,UAAU,GAAK,EAAE,EAAC;YACvB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;YACvC,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,2BAA2B;IACvC,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,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC1F,CAAC","sourcesContent":["import { type SpotLight } from \"core/Lights/spotLight\";\r\nimport { type Nullable } from \"core/types\";\r\nimport { Vector3, Quaternion, TmpVectors } from \"core/Maths/math.vector.pure\";\r\nimport { Light } from \"core/Lights/light\";\r\nimport { type Node } from \"core/node\";\r\nimport { ShadowLight } from \"core/Lights/shadowLight\";\r\nimport { type INode, type IKHRLightsPunctual_LightReference, type IKHRLightsPunctual_Light, type IKHRLightsPunctual, KHRLightsPunctual_LightType } from \"babylonjs-gltf2interface\";\r\nimport { type IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { ConvertToRightHandedPosition, OmitDefaultValues, CollapseChildIntoParent, IsChildCollapsible } from \"../glTFUtilities\";\r\n\r\nconst NAME = \"KHR_lights_punctual\";\r\nconst DEFAULTS: Omit<IKHRLightsPunctual_Light, \"type\"> = {\r\n name: \"\",\r\n color: [1, 1, 1],\r\n intensity: 1,\r\n range: Number.MAX_VALUE,\r\n};\r\nconst SPOTDEFAULTS: NonNullable<IKHRLightsPunctual_Light[\"spot\"]> = {\r\n innerConeAngle: 0,\r\n outerConeAngle: Math.PI / 4.0,\r\n};\r\nconst LIGHTDIRECTION = /*#__PURE__*/ Vector3.Backward();\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_lights_punctual implements IGLTFExporterExtensionV2 {\r\n /** The name of this extension. */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled. */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n /** Reference to the glTF exporter */\r\n private _exporter: GLTFExporter;\r\n\r\n private _lights: IKHRLightsPunctual;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(exporter: GLTFExporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._lights as any) = null;\r\n }\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return !!this._lights;\r\n }\r\n\r\n /** @internal */\r\n public onExporting(): void {\r\n this._exporter._glTF.extensions![NAME] = this._lights;\r\n }\r\n /**\r\n * Define this method to modify the default behavior when exporting a node\r\n * @param context The context when exporting the node\r\n * @param node glTF node\r\n * @param babylonNode BabylonJS node\r\n * @param nodeMap Node mapping of babylon node to glTF node index\r\n * @param convertToRightHanded Flag to convert the values to right-handed\r\n * @returns nullable INode promise\r\n */\r\n public async postExportNodeAsync(context: string, node: INode, babylonNode: Node, nodeMap: Map<Node, number>, convertToRightHanded: boolean): Promise<Nullable<INode>> {\r\n return await new Promise((resolve) => {\r\n if (!(babylonNode instanceof Light)) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n const lightType =\r\n babylonNode.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT\r\n ? KHRLightsPunctual_LightType.POINT\r\n : babylonNode.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT\r\n ? KHRLightsPunctual_LightType.DIRECTIONAL\r\n : babylonNode.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT\r\n ? KHRLightsPunctual_LightType.SPOT\r\n : null;\r\n if (!lightType || !(babylonNode instanceof ShadowLight)) {\r\n Logger.Warn(`${context}: Light ${babylonNode.name} is not supported in ${NAME}`);\r\n resolve(node);\r\n return;\r\n }\r\n\r\n if (babylonNode.falloffType !== Light.FALLOFF_GLTF) {\r\n Logger.Warn(`${context}: Light falloff for ${babylonNode.name} does not match the ${NAME} specification!`);\r\n }\r\n\r\n // Set the node's translation and rotation here, since lights are not handled in exportNodeAsync\r\n if (!babylonNode.position.equalsToFloats(0, 0, 0)) {\r\n const translation = TmpVectors.Vector3[0].copyFrom(babylonNode.position);\r\n if (convertToRightHanded) {\r\n ConvertToRightHandedPosition(translation);\r\n }\r\n node.translation = translation.asArray();\r\n }\r\n\r\n // Represent the Babylon light's direction as a quaternion\r\n // relative to glTF lights' forward direction, (0, 0, -1).\r\n if (lightType !== KHRLightsPunctual_LightType.POINT) {\r\n const direction = babylonNode.direction.normalizeToRef(TmpVectors.Vector3[0]);\r\n if (convertToRightHanded) {\r\n ConvertToRightHandedPosition(direction);\r\n }\r\n\r\n const lightRotationQuaternion = Quaternion.FromUnitVectorsToRef(LIGHTDIRECTION, direction, TmpVectors.Quaternion[0]);\r\n if (!Quaternion.IsIdentity(lightRotationQuaternion)) {\r\n node.rotation = lightRotationQuaternion.asArray();\r\n }\r\n }\r\n\r\n const light: IKHRLightsPunctual_Light = {\r\n type: lightType,\r\n name: babylonNode.name,\r\n color: babylonNode.diffuse.asArray(),\r\n intensity: babylonNode.intensity,\r\n range: babylonNode.range,\r\n };\r\n OmitDefaultValues(light, DEFAULTS);\r\n\r\n // Separately handle the required 'spot' field for spot lights\r\n if (lightType === KHRLightsPunctual_LightType.SPOT) {\r\n const babylonSpotLight = babylonNode as SpotLight;\r\n light.spot = {\r\n innerConeAngle: babylonSpotLight.innerAngle / 2.0,\r\n outerConeAngle: babylonSpotLight.angle / 2.0,\r\n };\r\n OmitDefaultValues(light.spot, SPOTDEFAULTS);\r\n }\r\n\r\n this._lights ||= {\r\n lights: [],\r\n };\r\n this._lights.lights.push(light);\r\n\r\n const lightReference: IKHRLightsPunctual_LightReference = {\r\n light: this._lights.lights.length - 1,\r\n };\r\n\r\n // Assign the light to its parent node, if possible, to condense the glTF\r\n // Why and when: the glTF loader generates a new parent TransformNode for each light node, which we should undo on export\r\n const parentBabylonNode = babylonNode.parent;\r\n\r\n if (parentBabylonNode && IsChildCollapsible(babylonNode, parentBabylonNode)) {\r\n const parentNodeIndex = nodeMap.get(parentBabylonNode);\r\n if (parentNodeIndex) {\r\n // Combine the light's transformation with the parent's\r\n const parentNode = this._exporter._nodes[parentNodeIndex];\r\n CollapseChildIntoParent(node, parentNode);\r\n parentNode.extensions ||= {};\r\n parentNode.extensions[NAME] = lightReference;\r\n\r\n // Do not export the original node\r\n resolve(null);\r\n return;\r\n }\r\n }\r\n\r\n node.extensions ||= {};\r\n node.extensions[NAME] = lightReference;\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nlet _Registered = false;\r\n/**\r\n * Registers the KHR_lights_punctual 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_lights_punctual(): void {\r\n if (_Registered) {\r\n return;\r\n }\r\n _Registered = true;\r\n\r\n GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_lights_punctual(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 "@babylonjs/core/Materials/material.js";
|
|
5
|
-
import { type BaseTexture } from "@babylonjs/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_anisotropy.pure" for tree-shakeable, side-effect-free usage.
|
|
8
4
|
*/
|
|
9
|
-
export
|
|
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
|
-
}
|
|
5
|
+
export * from "./KHR_materials_anisotropy.pure.js";
|
|
@@ -1,180 +1,8 @@
|
|
|
1
|
-
import { GLTFExporter } from "../glTFExporter.js";
|
|
2
|
-
import { PBRBaseMaterial } from "@babylonjs/core/Materials/PBR/pbrBaseMaterial.js";
|
|
3
|
-
import { OpenPBRMaterial } from "@babylonjs/core/Materials/PBR/openpbrMaterial.js";
|
|
4
|
-
import { MergeTexturesAsync, CreateRGBAConfiguration, CreateTextureInput, CreateConstantInput } from "@babylonjs/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
|