@babylonjs/serializers 5.0.0-rc.6 → 5.0.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.
Files changed (74) hide show
  1. package/OBJ/index.d.ts +1 -1
  2. package/OBJ/index.js +1 -1
  3. package/OBJ/objSerializer.d.ts +21 -21
  4. package/OBJ/objSerializer.js +174 -174
  5. package/OBJ/objSerializer.js.map +1 -1
  6. package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +41 -41
  7. package/glTF/2.0/Extensions/KHR_lights_punctual.js +189 -189
  8. package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
  9. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +24 -24
  10. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +90 -90
  11. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
  12. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +24 -24
  13. package/glTF/2.0/Extensions/KHR_materials_sheen.js +73 -73
  14. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
  15. package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +20 -20
  16. package/glTF/2.0/Extensions/KHR_materials_unlit.js +51 -51
  17. package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
  18. package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +30 -30
  19. package/glTF/2.0/Extensions/KHR_texture_transform.js +137 -137
  20. package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
  21. package/glTF/2.0/Extensions/index.d.ts +5 -5
  22. package/glTF/2.0/Extensions/index.js +5 -5
  23. package/glTF/2.0/glTFAnimation.d.ts +206 -205
  24. package/glTF/2.0/glTFAnimation.js +852 -852
  25. package/glTF/2.0/glTFAnimation.js.map +1 -1
  26. package/glTF/2.0/glTFData.d.ts +19 -19
  27. package/glTF/2.0/glTFData.js +52 -52
  28. package/glTF/2.0/glTFExporter.d.ts +456 -455
  29. package/glTF/2.0/glTFExporter.js +1975 -1972
  30. package/glTF/2.0/glTFExporter.js.map +1 -1
  31. package/glTF/2.0/glTFExporterExtension.d.ts +74 -74
  32. package/glTF/2.0/glTFExporterExtension.js +3 -3
  33. package/glTF/2.0/glTFExporterExtension.js.map +1 -1
  34. package/glTF/2.0/glTFMaterialExporter.d.ts +208 -207
  35. package/glTF/2.0/glTFMaterialExporter.js +1114 -1110
  36. package/glTF/2.0/glTFMaterialExporter.js.map +1 -1
  37. package/glTF/2.0/glTFSerializer.d.ts +60 -60
  38. package/glTF/2.0/glTFSerializer.js +62 -62
  39. package/glTF/2.0/glTFSerializer.js.map +1 -1
  40. package/glTF/2.0/glTFUtilities.d.ts +99 -97
  41. package/glTF/2.0/glTFUtilities.js +196 -196
  42. package/glTF/2.0/glTFUtilities.js.map +1 -1
  43. package/glTF/2.0/index.d.ts +8 -8
  44. package/glTF/2.0/index.js +9 -8
  45. package/glTF/2.0/index.js.map +1 -1
  46. package/glTF/2.0/shaders/textureTransform.fragment.d.ts +5 -5
  47. package/glTF/2.0/shaders/textureTransform.fragment.js +8 -8
  48. package/glTF/glTFFileExporter.d.ts +20 -20
  49. package/glTF/glTFFileExporter.js +3 -3
  50. package/glTF/index.d.ts +2 -2
  51. package/glTF/index.js +3 -2
  52. package/glTF/index.js.map +1 -1
  53. package/index.d.ts +3 -3
  54. package/index.js +4 -3
  55. package/index.js.map +1 -1
  56. package/legacy/legacy-glTF2Serializer.d.ts +2 -2
  57. package/legacy/legacy-glTF2Serializer.js +44 -43
  58. package/legacy/legacy-glTF2Serializer.js.map +1 -1
  59. package/legacy/legacy-objSerializer.d.ts +1 -1
  60. package/legacy/legacy-objSerializer.js +13 -12
  61. package/legacy/legacy-objSerializer.js.map +1 -1
  62. package/legacy/legacy-stlSerializer.d.ts +1 -1
  63. package/legacy/legacy-stlSerializer.js +13 -12
  64. package/legacy/legacy-stlSerializer.js.map +1 -1
  65. package/legacy/legacy.d.ts +4 -4
  66. package/legacy/legacy.js +6 -5
  67. package/legacy/legacy.js.map +1 -1
  68. package/license.md +71 -0
  69. package/package.json +25 -6
  70. package/stl/index.d.ts +1 -1
  71. package/stl/index.js +1 -1
  72. package/stl/stlSerializer.d.ts +17 -17
  73. package/stl/stlSerializer.js +107 -107
  74. package/stl/stlSerializer.js.map +1 -1
@@ -1,190 +1,190 @@
1
- import { Vector3, Quaternion, TmpVectors, Matrix } from "@babylonjs/core/Maths/math.vector.js";
2
- import { Color3 } from "@babylonjs/core/Maths/math.color.js";
3
- import { Light } from "@babylonjs/core/Lights/light.js";
4
- import { DirectionalLight } from "@babylonjs/core/Lights/directionalLight.js";
5
- import { ShadowLight } from "@babylonjs/core/Lights/shadowLight.js";
6
- import { _Exporter } from "../glTFExporter.js";
7
- import { Logger } from "@babylonjs/core/Misc/logger.js";
8
- import { _GLTFUtilities } from "../glTFUtilities.js";
9
- var NAME = "KHR_lights_punctual";
10
- /**
11
- * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
12
- */
13
- // eslint-disable-next-line @typescript-eslint/naming-convention
14
- var KHR_lights_punctual = /** @class */ (function () {
15
- /**
16
- * @param exporter
17
- * @hidden
18
- */
19
- function KHR_lights_punctual(exporter) {
20
- /** The name of this extension. */
21
- this.name = NAME;
22
- /** Defines whether this extension is enabled. */
23
- this.enabled = true;
24
- /** Defines whether this extension is required */
25
- this.required = false;
26
- this._exporter = exporter;
27
- }
28
- /** @hidden */
29
- KHR_lights_punctual.prototype.dispose = function () {
30
- this._lights = null;
31
- };
32
- Object.defineProperty(KHR_lights_punctual.prototype, "wasUsed", {
33
- /** @hidden */
34
- get: function () {
35
- return !!this._lights;
36
- },
37
- enumerable: false,
38
- configurable: true
39
- });
40
- /** @hidden */
41
- KHR_lights_punctual.prototype.onExporting = function () {
42
- this._exporter._glTF.extensions[NAME] = this._lights;
43
- };
44
- /**
45
- * Define this method to modify the default behavior when exporting a node
46
- * @param context The context when exporting the node
47
- * @param node glTF node
48
- * @param babylonNode BabylonJS node
49
- * @param nodeMap Node mapping of unique id to glTF node index
50
- * @returns nullable INode promise
51
- */
52
- KHR_lights_punctual.prototype.postExportNodeAsync = function (context, node, babylonNode, nodeMap) {
53
- var _this = this;
54
- return new Promise(function (resolve) {
55
- if (node && babylonNode instanceof ShadowLight) {
56
- var babylonLight = babylonNode;
57
- var light = void 0;
58
- var lightType = babylonLight.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT
59
- ? "point" /* POINT */
60
- : babylonLight.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT
61
- ? "directional" /* DIRECTIONAL */
62
- : babylonLight.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT
63
- ? "spot" /* SPOT */
64
- : null;
65
- if (lightType == null) {
66
- Logger.Warn("".concat(context, ": Light ").concat(babylonLight.name, " is not supported in ").concat(NAME));
67
- }
68
- else {
69
- var lightPosition = babylonLight.position.clone();
70
- var convertToRightHandedSystem = _this._exporter._convertToRightHandedSystemMap[babylonNode.uniqueId];
71
- if (!lightPosition.equals(Vector3.Zero())) {
72
- if (convertToRightHandedSystem) {
73
- _GLTFUtilities._GetRightHandedPositionVector3FromRef(lightPosition);
74
- }
75
- node.translation = lightPosition.asArray();
76
- }
77
- if (lightType !== "point" /* POINT */) {
78
- var localAxis = babylonLight.direction;
79
- var yaw = -Math.atan2(localAxis.z * (_this._exporter._babylonScene.useRightHandedSystem ? -1 : 1), localAxis.x) + Math.PI / 2;
80
- var len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);
81
- var pitch = -Math.atan2(localAxis.y, len);
82
- var lightRotationQuaternion = Quaternion.RotationYawPitchRoll(yaw, pitch, 0);
83
- if (convertToRightHandedSystem) {
84
- _GLTFUtilities._GetRightHandedQuaternionFromRef(lightRotationQuaternion);
85
- }
86
- if (!lightRotationQuaternion.equals(Quaternion.Identity())) {
87
- node.rotation = lightRotationQuaternion.asArray();
88
- }
89
- }
90
- if (babylonLight.falloffType !== Light.FALLOFF_GLTF) {
91
- Logger.Warn("".concat(context, ": Light falloff for ").concat(babylonLight.name, " does not match the ").concat(NAME, " specification!"));
92
- }
93
- light = {
94
- type: lightType,
95
- };
96
- if (!babylonLight.diffuse.equals(Color3.White())) {
97
- light.color = babylonLight.diffuse.asArray();
98
- }
99
- if (babylonLight.intensity !== 1.0) {
100
- light.intensity = babylonLight.intensity;
101
- }
102
- if (babylonLight.range !== Number.MAX_VALUE) {
103
- light.range = babylonLight.range;
104
- }
105
- if (lightType === "spot" /* SPOT */) {
106
- var babylonSpotLight = babylonLight;
107
- if (babylonSpotLight.angle !== Math.PI / 2.0) {
108
- if (light.spot == null) {
109
- light.spot = {};
110
- }
111
- light.spot.outerConeAngle = babylonSpotLight.angle / 2.0;
112
- }
113
- if (babylonSpotLight.innerAngle !== 0) {
114
- if (light.spot == null) {
115
- light.spot = {};
116
- }
117
- light.spot.innerConeAngle = babylonSpotLight.innerAngle / 2.0;
118
- }
119
- }
120
- if (_this._lights == null) {
121
- _this._lights = {
122
- lights: [],
123
- };
124
- }
125
- _this._lights.lights.push(light);
126
- var lightReference = {
127
- light: _this._lights.lights.length - 1,
128
- };
129
- // Avoid duplicating the Light's parent node if possible.
130
- var parentBabylonNode = babylonNode.parent;
131
- if (parentBabylonNode && parentBabylonNode.getChildren().length == 1) {
132
- var parentNode = _this._exporter._nodes[nodeMap[parentBabylonNode.uniqueId]];
133
- if (parentNode) {
134
- var parentNodeLocalMatrix = TmpVectors.Matrix[0];
135
- var parentInvertNodeLocalMatrix = TmpVectors.Matrix[1];
136
- var parentNodeLocalTranslation = parentNode.translation
137
- ? new Vector3(parentNode.translation[0], parentNode.translation[1], parentNode.translation[2])
138
- : Vector3.Zero();
139
- var parentNodeLocalRotation = parentNode.rotation
140
- ? new Quaternion(parentNode.rotation[0], parentNode.rotation[1], parentNode.rotation[2], parentNode.rotation[3])
141
- : Quaternion.Identity();
142
- var parentNodeLocalScale = parentNode.scale ? new Vector3(parentNode.scale[0], parentNode.scale[1], parentNode.scale[2]) : Vector3.One();
143
- Matrix.ComposeToRef(parentNodeLocalScale, parentNodeLocalRotation, parentNodeLocalTranslation, parentNodeLocalMatrix);
144
- parentNodeLocalMatrix.invertToRef(parentInvertNodeLocalMatrix);
145
- // Convert light local matrix to local matrix relative to grandparent, facing -Z
146
- var lightLocalMatrix = TmpVectors.Matrix[2];
147
- var nodeLocalTranslation = node.translation ? new Vector3(node.translation[0], node.translation[1], node.translation[2]) : Vector3.Zero();
148
- // Undo directional light positional offset
149
- if (babylonLight instanceof DirectionalLight) {
150
- nodeLocalTranslation.subtractInPlace(_this._exporter._babylonScene.useRightHandedSystem
151
- ? babylonLight.direction
152
- : _GLTFUtilities._GetRightHandedPositionVector3(babylonLight.direction));
153
- }
154
- var nodeLocalRotation = _this._exporter._babylonScene.useRightHandedSystem ? Quaternion.Identity() : new Quaternion(0, 1, 0, 0);
155
- if (node.rotation) {
156
- nodeLocalRotation.multiplyInPlace(new Quaternion(node.rotation[0], node.rotation[1], node.rotation[2], node.rotation[3]));
157
- }
158
- var nodeLocalScale = node.scale ? new Vector3(node.scale[0], node.scale[1], node.scale[2]) : Vector3.One();
159
- Matrix.ComposeToRef(nodeLocalScale, nodeLocalRotation, nodeLocalTranslation, lightLocalMatrix);
160
- lightLocalMatrix.multiplyToRef(parentInvertNodeLocalMatrix, lightLocalMatrix);
161
- var parentNewScale = TmpVectors.Vector3[0];
162
- var parentNewRotationQuaternion = TmpVectors.Quaternion[0];
163
- var parentNewTranslation = TmpVectors.Vector3[1];
164
- lightLocalMatrix.decompose(parentNewScale, parentNewRotationQuaternion, parentNewTranslation);
165
- parentNode.scale = parentNewScale.asArray();
166
- parentNode.rotation = parentNewRotationQuaternion.asArray();
167
- parentNode.translation = parentNewTranslation.asArray();
168
- if (parentNode.extensions == null) {
169
- parentNode.extensions = {};
170
- }
171
- parentNode.extensions[NAME] = lightReference;
172
- // Do not export the original node
173
- resolve(null);
174
- return;
175
- }
176
- }
177
- if (node.extensions == null) {
178
- node.extensions = {};
179
- }
180
- node.extensions[NAME] = lightReference;
181
- }
182
- }
183
- resolve(node);
184
- });
185
- };
186
- return KHR_lights_punctual;
187
- }());
188
- export { KHR_lights_punctual };
189
- _Exporter.RegisterExtension(NAME, function (exporter) { return new KHR_lights_punctual(exporter); });
1
+ import { Vector3, Quaternion, TmpVectors, Matrix } from "@babylonjs/core/Maths/math.vector.js";
2
+ import { Color3 } from "@babylonjs/core/Maths/math.color.js";
3
+ import { Light } from "@babylonjs/core/Lights/light.js";
4
+ import { DirectionalLight } from "@babylonjs/core/Lights/directionalLight.js";
5
+ import { ShadowLight } from "@babylonjs/core/Lights/shadowLight.js";
6
+ import { _Exporter } from "../glTFExporter.js";
7
+ import { Logger } from "@babylonjs/core/Misc/logger.js";
8
+ import { _GLTFUtilities } from "../glTFUtilities.js";
9
+ var NAME = "KHR_lights_punctual";
10
+ /**
11
+ * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
12
+ */
13
+ // eslint-disable-next-line @typescript-eslint/naming-convention
14
+ var KHR_lights_punctual = /** @class */ (function () {
15
+ /**
16
+ * @param exporter
17
+ * @hidden
18
+ */
19
+ function KHR_lights_punctual(exporter) {
20
+ /** The name of this extension. */
21
+ this.name = NAME;
22
+ /** Defines whether this extension is enabled. */
23
+ this.enabled = true;
24
+ /** Defines whether this extension is required */
25
+ this.required = false;
26
+ this._exporter = exporter;
27
+ }
28
+ /** @hidden */
29
+ KHR_lights_punctual.prototype.dispose = function () {
30
+ this._lights = null;
31
+ };
32
+ Object.defineProperty(KHR_lights_punctual.prototype, "wasUsed", {
33
+ /** @hidden */
34
+ get: function () {
35
+ return !!this._lights;
36
+ },
37
+ enumerable: false,
38
+ configurable: true
39
+ });
40
+ /** @hidden */
41
+ KHR_lights_punctual.prototype.onExporting = function () {
42
+ this._exporter._glTF.extensions[NAME] = this._lights;
43
+ };
44
+ /**
45
+ * Define this method to modify the default behavior when exporting a node
46
+ * @param context The context when exporting the node
47
+ * @param node glTF node
48
+ * @param babylonNode BabylonJS node
49
+ * @param nodeMap Node mapping of unique id to glTF node index
50
+ * @returns nullable INode promise
51
+ */
52
+ KHR_lights_punctual.prototype.postExportNodeAsync = function (context, node, babylonNode, nodeMap) {
53
+ var _this = this;
54
+ return new Promise(function (resolve) {
55
+ if (node && babylonNode instanceof ShadowLight) {
56
+ var babylonLight = babylonNode;
57
+ var light = void 0;
58
+ var lightType = babylonLight.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT
59
+ ? "point" /* POINT */
60
+ : babylonLight.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT
61
+ ? "directional" /* DIRECTIONAL */
62
+ : babylonLight.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT
63
+ ? "spot" /* SPOT */
64
+ : null;
65
+ if (lightType == null) {
66
+ Logger.Warn("".concat(context, ": Light ").concat(babylonLight.name, " is not supported in ").concat(NAME));
67
+ }
68
+ else {
69
+ var lightPosition = babylonLight.position.clone();
70
+ var convertToRightHandedSystem = _this._exporter._convertToRightHandedSystemMap[babylonNode.uniqueId];
71
+ if (!lightPosition.equals(Vector3.Zero())) {
72
+ if (convertToRightHandedSystem) {
73
+ _GLTFUtilities._GetRightHandedPositionVector3FromRef(lightPosition);
74
+ }
75
+ node.translation = lightPosition.asArray();
76
+ }
77
+ if (lightType !== "point" /* POINT */) {
78
+ var localAxis = babylonLight.direction;
79
+ var yaw = -Math.atan2(localAxis.z * (_this._exporter._babylonScene.useRightHandedSystem ? -1 : 1), localAxis.x) + Math.PI / 2;
80
+ var len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);
81
+ var pitch = -Math.atan2(localAxis.y, len);
82
+ var lightRotationQuaternion = Quaternion.RotationYawPitchRoll(yaw, pitch, 0);
83
+ if (convertToRightHandedSystem) {
84
+ _GLTFUtilities._GetRightHandedQuaternionFromRef(lightRotationQuaternion);
85
+ }
86
+ if (!lightRotationQuaternion.equals(Quaternion.Identity())) {
87
+ node.rotation = lightRotationQuaternion.asArray();
88
+ }
89
+ }
90
+ if (babylonLight.falloffType !== Light.FALLOFF_GLTF) {
91
+ Logger.Warn("".concat(context, ": Light falloff for ").concat(babylonLight.name, " does not match the ").concat(NAME, " specification!"));
92
+ }
93
+ light = {
94
+ type: lightType,
95
+ };
96
+ if (!babylonLight.diffuse.equals(Color3.White())) {
97
+ light.color = babylonLight.diffuse.asArray();
98
+ }
99
+ if (babylonLight.intensity !== 1.0) {
100
+ light.intensity = babylonLight.intensity;
101
+ }
102
+ if (babylonLight.range !== Number.MAX_VALUE) {
103
+ light.range = babylonLight.range;
104
+ }
105
+ if (lightType === "spot" /* SPOT */) {
106
+ var babylonSpotLight = babylonLight;
107
+ if (babylonSpotLight.angle !== Math.PI / 2.0) {
108
+ if (light.spot == null) {
109
+ light.spot = {};
110
+ }
111
+ light.spot.outerConeAngle = babylonSpotLight.angle / 2.0;
112
+ }
113
+ if (babylonSpotLight.innerAngle !== 0) {
114
+ if (light.spot == null) {
115
+ light.spot = {};
116
+ }
117
+ light.spot.innerConeAngle = babylonSpotLight.innerAngle / 2.0;
118
+ }
119
+ }
120
+ if (_this._lights == null) {
121
+ _this._lights = {
122
+ lights: [],
123
+ };
124
+ }
125
+ _this._lights.lights.push(light);
126
+ var lightReference = {
127
+ light: _this._lights.lights.length - 1,
128
+ };
129
+ // Avoid duplicating the Light's parent node if possible.
130
+ var parentBabylonNode = babylonNode.parent;
131
+ if (parentBabylonNode && parentBabylonNode.getChildren().length == 1) {
132
+ var parentNode = _this._exporter._nodes[nodeMap[parentBabylonNode.uniqueId]];
133
+ if (parentNode) {
134
+ var parentNodeLocalMatrix = TmpVectors.Matrix[0];
135
+ var parentInvertNodeLocalMatrix = TmpVectors.Matrix[1];
136
+ var parentNodeLocalTranslation = parentNode.translation
137
+ ? new Vector3(parentNode.translation[0], parentNode.translation[1], parentNode.translation[2])
138
+ : Vector3.Zero();
139
+ var parentNodeLocalRotation = parentNode.rotation
140
+ ? new Quaternion(parentNode.rotation[0], parentNode.rotation[1], parentNode.rotation[2], parentNode.rotation[3])
141
+ : Quaternion.Identity();
142
+ var parentNodeLocalScale = parentNode.scale ? new Vector3(parentNode.scale[0], parentNode.scale[1], parentNode.scale[2]) : Vector3.One();
143
+ Matrix.ComposeToRef(parentNodeLocalScale, parentNodeLocalRotation, parentNodeLocalTranslation, parentNodeLocalMatrix);
144
+ parentNodeLocalMatrix.invertToRef(parentInvertNodeLocalMatrix);
145
+ // Convert light local matrix to local matrix relative to grandparent, facing -Z
146
+ var lightLocalMatrix = TmpVectors.Matrix[2];
147
+ var nodeLocalTranslation = node.translation ? new Vector3(node.translation[0], node.translation[1], node.translation[2]) : Vector3.Zero();
148
+ // Undo directional light positional offset
149
+ if (babylonLight instanceof DirectionalLight) {
150
+ nodeLocalTranslation.subtractInPlace(_this._exporter._babylonScene.useRightHandedSystem
151
+ ? babylonLight.direction
152
+ : _GLTFUtilities._GetRightHandedPositionVector3(babylonLight.direction));
153
+ }
154
+ var nodeLocalRotation = _this._exporter._babylonScene.useRightHandedSystem ? Quaternion.Identity() : new Quaternion(0, 1, 0, 0);
155
+ if (node.rotation) {
156
+ nodeLocalRotation.multiplyInPlace(new Quaternion(node.rotation[0], node.rotation[1], node.rotation[2], node.rotation[3]));
157
+ }
158
+ var nodeLocalScale = node.scale ? new Vector3(node.scale[0], node.scale[1], node.scale[2]) : Vector3.One();
159
+ Matrix.ComposeToRef(nodeLocalScale, nodeLocalRotation, nodeLocalTranslation, lightLocalMatrix);
160
+ lightLocalMatrix.multiplyToRef(parentInvertNodeLocalMatrix, lightLocalMatrix);
161
+ var parentNewScale = TmpVectors.Vector3[0];
162
+ var parentNewRotationQuaternion = TmpVectors.Quaternion[0];
163
+ var parentNewTranslation = TmpVectors.Vector3[1];
164
+ lightLocalMatrix.decompose(parentNewScale, parentNewRotationQuaternion, parentNewTranslation);
165
+ parentNode.scale = parentNewScale.asArray();
166
+ parentNode.rotation = parentNewRotationQuaternion.asArray();
167
+ parentNode.translation = parentNewTranslation.asArray();
168
+ if (parentNode.extensions == null) {
169
+ parentNode.extensions = {};
170
+ }
171
+ parentNode.extensions[NAME] = lightReference;
172
+ // Do not export the original node
173
+ resolve(null);
174
+ return;
175
+ }
176
+ }
177
+ if (node.extensions == null) {
178
+ node.extensions = {};
179
+ }
180
+ node.extensions[NAME] = lightReference;
181
+ }
182
+ }
183
+ resolve(node);
184
+ });
185
+ };
186
+ return KHR_lights_punctual;
187
+ }());
188
+ export { KHR_lights_punctual };
189
+ _Exporter.RegisterExtension(NAME, function (exporter) { return new KHR_lights_punctual(exporter); });
190
190
  //# sourceMappingURL=KHR_lights_punctual.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"KHR_lights_punctual.js","sourceRoot":"","sources":["../../../../../../../lts/serializers/generated/glTF/2.0/Extensions/KHR_lights_punctual.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,6CAA+B;AACjF,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,KAAK,EAAE,wCAA0B;AAC1C,OAAO,EAAE,gBAAgB,EAAE,mDAAqC;AAEhE,OAAO,EAAE,WAAW,EAAE,8CAAgC;AAGtD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,uCAAyB;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,IAAM,IAAI,GAAG,qBAAqB,CAAC;AAEnC;;GAEG;AACH,gEAAgE;AAChE;IAeI;;;OAGG;IACH,6BAAY,QAAmB;QAlB/B,kCAAkC;QAClB,SAAI,GAAG,IAAI,CAAC;QAE5B,iDAAiD;QAC1C,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,KAAK,CAAC;QAYpB,IAAI,CAAC,SAAS,GAAG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;gCAC/B,UAAU,CAAC,UAAU,GAAG,EAAE,CAAC;6BAC9B;4BACD,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;4BAE7C,kCAAkC;4BAClC,OAAO,CAAC,IAAI,CAAC,CAAC;4BACd,OAAO;yBACV;qBACJ;oBAED,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,EAAE;wBACzB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;qBACxB;oBAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;iBAC1C;aACJ;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;IACL,0BAAC;AAAD,CAAC,AApMD,IAoMC;;AAED,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,QAAQ,IAAK,OAAA,IAAI,mBAAmB,CAAC,QAAQ,CAAC,EAAjC,CAAiC,CAAC,CAAC","sourcesContent":["import { SpotLight } from \"core/Lights/spotLight\";\r\nimport { Nullable } from \"core/types\";\r\nimport { Vector3, Quaternion, TmpVectors, Matrix } from \"core/Maths/math.vector\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { Light } from \"core/Lights/light\";\r\nimport { DirectionalLight } from \"core/Lights/directionalLight\";\r\nimport { Node } from \"core/node\";\r\nimport { ShadowLight } from \"core/Lights/shadowLight\";\r\nimport { INode, IKHRLightsPunctual_LightType, IKHRLightsPunctual_LightReference, IKHRLightsPunctual_Light, IKHRLightsPunctual } from \"babylonjs-gltf2interface\";\r\nimport { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { _GLTFUtilities } from \"../glTFUtilities\";\r\n\r\nconst NAME = \"KHR_lights_punctual\";\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: _Exporter;\r\n\r\n private _lights: IKHRLightsPunctual;\r\n\r\n /**\r\n * @param exporter\r\n * @hidden\r\n */\r\n constructor(exporter: _Exporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n /** @hidden */\r\n public dispose() {\r\n (this._lights as any) = null;\r\n }\r\n\r\n /** @hidden */\r\n public get wasUsed() {\r\n return !!this._lights;\r\n }\r\n\r\n /** @hidden */\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 unique id to glTF node index\r\n * @returns nullable INode promise\r\n */\r\n public postExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: { [key: number]: number }): Promise<Nullable<INode>> {\r\n return new Promise((resolve) => {\r\n if (node && babylonNode instanceof ShadowLight) {\r\n const babylonLight: ShadowLight = babylonNode;\r\n let light: IKHRLightsPunctual_Light;\r\n\r\n const lightType =\r\n babylonLight.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT\r\n ? IKHRLightsPunctual_LightType.POINT\r\n : babylonLight.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT\r\n ? IKHRLightsPunctual_LightType.DIRECTIONAL\r\n : babylonLight.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT\r\n ? IKHRLightsPunctual_LightType.SPOT\r\n : null;\r\n if (lightType == null) {\r\n Logger.Warn(`${context}: Light ${babylonLight.name} is not supported in ${NAME}`);\r\n } else {\r\n const lightPosition = babylonLight.position.clone();\r\n const convertToRightHandedSystem = this._exporter._convertToRightHandedSystemMap[babylonNode.uniqueId];\r\n if (!lightPosition.equals(Vector3.Zero())) {\r\n if (convertToRightHandedSystem) {\r\n _GLTFUtilities._GetRightHandedPositionVector3FromRef(lightPosition);\r\n }\r\n node.translation = lightPosition.asArray();\r\n }\r\n if (lightType !== IKHRLightsPunctual_LightType.POINT) {\r\n const localAxis = babylonLight.direction;\r\n const yaw = -Math.atan2(localAxis.z * (this._exporter._babylonScene.useRightHandedSystem ? -1 : 1), localAxis.x) + Math.PI / 2;\r\n const len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);\r\n const pitch = -Math.atan2(localAxis.y, len);\r\n const lightRotationQuaternion = Quaternion.RotationYawPitchRoll(yaw, pitch, 0);\r\n if (convertToRightHandedSystem) {\r\n _GLTFUtilities._GetRightHandedQuaternionFromRef(lightRotationQuaternion);\r\n }\r\n if (!lightRotationQuaternion.equals(Quaternion.Identity())) {\r\n node.rotation = lightRotationQuaternion.asArray();\r\n }\r\n }\r\n\r\n if (babylonLight.falloffType !== Light.FALLOFF_GLTF) {\r\n Logger.Warn(`${context}: Light falloff for ${babylonLight.name} does not match the ${NAME} specification!`);\r\n }\r\n light = {\r\n type: lightType,\r\n };\r\n if (!babylonLight.diffuse.equals(Color3.White())) {\r\n light.color = babylonLight.diffuse.asArray();\r\n }\r\n if (babylonLight.intensity !== 1.0) {\r\n light.intensity = babylonLight.intensity;\r\n }\r\n if (babylonLight.range !== Number.MAX_VALUE) {\r\n light.range = babylonLight.range;\r\n }\r\n\r\n if (lightType === IKHRLightsPunctual_LightType.SPOT) {\r\n const babylonSpotLight = babylonLight as SpotLight;\r\n if (babylonSpotLight.angle !== Math.PI / 2.0) {\r\n if (light.spot == null) {\r\n light.spot = {};\r\n }\r\n light.spot.outerConeAngle = babylonSpotLight.angle / 2.0;\r\n }\r\n if (babylonSpotLight.innerAngle !== 0) {\r\n if (light.spot == null) {\r\n light.spot = {};\r\n }\r\n light.spot.innerConeAngle = babylonSpotLight.innerAngle / 2.0;\r\n }\r\n }\r\n\r\n if (this._lights == null) {\r\n this._lights = {\r\n lights: [],\r\n };\r\n }\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 // Avoid duplicating the Light's parent node if possible.\r\n const parentBabylonNode = babylonNode.parent;\r\n if (parentBabylonNode && parentBabylonNode.getChildren().length == 1) {\r\n const parentNode = this._exporter._nodes[nodeMap![parentBabylonNode.uniqueId]];\r\n if (parentNode) {\r\n const parentNodeLocalMatrix = TmpVectors.Matrix[0];\r\n const parentInvertNodeLocalMatrix = TmpVectors.Matrix[1];\r\n const parentNodeLocalTranslation = parentNode.translation\r\n ? new Vector3(parentNode.translation[0], parentNode.translation[1], parentNode.translation[2])\r\n : Vector3.Zero();\r\n const parentNodeLocalRotation = parentNode.rotation\r\n ? new Quaternion(parentNode.rotation[0], parentNode.rotation[1], parentNode.rotation[2], parentNode.rotation[3])\r\n : Quaternion.Identity();\r\n const parentNodeLocalScale = parentNode.scale ? new Vector3(parentNode.scale[0], parentNode.scale[1], parentNode.scale[2]) : Vector3.One();\r\n\r\n Matrix.ComposeToRef(parentNodeLocalScale, parentNodeLocalRotation, parentNodeLocalTranslation, parentNodeLocalMatrix);\r\n parentNodeLocalMatrix.invertToRef(parentInvertNodeLocalMatrix);\r\n\r\n // Convert light local matrix to local matrix relative to grandparent, facing -Z\r\n const lightLocalMatrix = TmpVectors.Matrix[2];\r\n const nodeLocalTranslation = node.translation ? new Vector3(node.translation[0], node.translation[1], node.translation[2]) : Vector3.Zero();\r\n\r\n // Undo directional light positional offset\r\n if (babylonLight instanceof DirectionalLight) {\r\n nodeLocalTranslation.subtractInPlace(\r\n this._exporter._babylonScene.useRightHandedSystem\r\n ? babylonLight.direction\r\n : _GLTFUtilities._GetRightHandedPositionVector3(babylonLight.direction)\r\n );\r\n }\r\n const nodeLocalRotation = this._exporter._babylonScene.useRightHandedSystem ? Quaternion.Identity() : new Quaternion(0, 1, 0, 0);\r\n if (node.rotation) {\r\n nodeLocalRotation.multiplyInPlace(new Quaternion(node.rotation[0], node.rotation[1], node.rotation[2], node.rotation[3]));\r\n }\r\n const nodeLocalScale = node.scale ? new Vector3(node.scale[0], node.scale[1], node.scale[2]) : Vector3.One();\r\n\r\n Matrix.ComposeToRef(nodeLocalScale, nodeLocalRotation, nodeLocalTranslation, lightLocalMatrix);\r\n lightLocalMatrix.multiplyToRef(parentInvertNodeLocalMatrix, lightLocalMatrix);\r\n const parentNewScale = TmpVectors.Vector3[0];\r\n const parentNewRotationQuaternion = TmpVectors.Quaternion[0];\r\n const parentNewTranslation = TmpVectors.Vector3[1];\r\n\r\n lightLocalMatrix.decompose(parentNewScale, parentNewRotationQuaternion, parentNewTranslation);\r\n parentNode.scale = parentNewScale.asArray();\r\n parentNode.rotation = parentNewRotationQuaternion.asArray();\r\n parentNode.translation = parentNewTranslation.asArray();\r\n\r\n if (parentNode.extensions == null) {\r\n parentNode.extensions = {};\r\n }\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 if (node.extensions == null) {\r\n node.extensions = {};\r\n }\r\n\r\n node.extensions[NAME] = lightReference;\r\n }\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_lights_punctual(exporter));\r\n"]}
1
+ {"version":3,"file":"KHR_lights_punctual.js","sourceRoot":"","sources":["../../../../../../../lts/serializers/generated/glTF/2.0/Extensions/KHR_lights_punctual.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,6CAA+B;AACjF,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,KAAK,EAAE,wCAA0B;AAC1C,OAAO,EA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C,CAAC,CAAC,CAAC;4BAC7C,IAAM,2BAA2B,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;4BAC7D,IAAM,oBAAoB,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;4BAEnD,gBAAgB,CAAC,SAAS,CAAC,cAAc,EAAE,2BAA2B,EAAE,oBAAoB,CAAC,CAAC;4BAC9F,UAAU,CAAC,KAAK,GAAG,cAAc,CAAC,OAAO,EAAE,CAAC;4BAC5C,UAAU,CAAC,QAAQ,GAAG,2BAA2B,CAAC,OAAO,EAAE,CAAC;4BAC5D,UAAU,CAAC,WAAW,GAAG,oBAAoB,CAAC,OAAO,EAAE,CAAC;4BAExD,IAAI,UAAU,CAAC,UAAU,IAAI,IAAI,EAAE;gCAC/B,UAAU,CAAC,UAAU,GAAG,EAAE,CAAC;6BAC9B;4BACD,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;4BAE7C,kCAAkC;4BAClC,OAAO,CAAC,IAAI,CAAC,CAAC;4BACd,OAAO;yBACV;qBACJ;oBAED,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,EAAE;wBACzB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;qBACxB;oBAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;iBAC1C;aACJ;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;IACL,0BAAC;AAAD,CAAC,AApMD,IAoMC;;AAED,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,QAAQ,IAAK,OAAA,IAAI,mBAAmB,CAAC,QAAQ,CAAC,EAAjC,CAAiC,CAAC,CAAC","sourcesContent":["import type { SpotLight } from \"core/Lights/spotLight\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { Vector3, Quaternion, TmpVectors, Matrix } from \"core/Maths/math.vector\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { Light } from \"core/Lights/light\";\r\nimport { DirectionalLight } from \"core/Lights/directionalLight\";\r\nimport type { Node } from \"core/node\";\r\nimport { ShadowLight } from \"core/Lights/shadowLight\";\r\nimport type { INode, IKHRLightsPunctual_LightReference, IKHRLightsPunctual_Light, IKHRLightsPunctual } from \"babylonjs-gltf2interface\";\r\nimport { IKHRLightsPunctual_LightType } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { _GLTFUtilities } from \"../glTFUtilities\";\r\n\r\nconst NAME = \"KHR_lights_punctual\";\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: _Exporter;\r\n\r\n private _lights: IKHRLightsPunctual;\r\n\r\n /**\r\n * @param exporter\r\n * @hidden\r\n */\r\n constructor(exporter: _Exporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n /** @hidden */\r\n public dispose() {\r\n (this._lights as any) = null;\r\n }\r\n\r\n /** @hidden */\r\n public get wasUsed() {\r\n return !!this._lights;\r\n }\r\n\r\n /** @hidden */\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 unique id to glTF node index\r\n * @returns nullable INode promise\r\n */\r\n public postExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: { [key: number]: number }): Promise<Nullable<INode>> {\r\n return new Promise((resolve) => {\r\n if (node && babylonNode instanceof ShadowLight) {\r\n const babylonLight: ShadowLight = babylonNode;\r\n let light: IKHRLightsPunctual_Light;\r\n\r\n const lightType =\r\n babylonLight.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT\r\n ? IKHRLightsPunctual_LightType.POINT\r\n : babylonLight.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT\r\n ? IKHRLightsPunctual_LightType.DIRECTIONAL\r\n : babylonLight.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT\r\n ? IKHRLightsPunctual_LightType.SPOT\r\n : null;\r\n if (lightType == null) {\r\n Logger.Warn(`${context}: Light ${babylonLight.name} is not supported in ${NAME}`);\r\n } else {\r\n const lightPosition = babylonLight.position.clone();\r\n const convertToRightHandedSystem = this._exporter._convertToRightHandedSystemMap[babylonNode.uniqueId];\r\n if (!lightPosition.equals(Vector3.Zero())) {\r\n if (convertToRightHandedSystem) {\r\n _GLTFUtilities._GetRightHandedPositionVector3FromRef(lightPosition);\r\n }\r\n node.translation = lightPosition.asArray();\r\n }\r\n if (lightType !== IKHRLightsPunctual_LightType.POINT) {\r\n const localAxis = babylonLight.direction;\r\n const yaw = -Math.atan2(localAxis.z * (this._exporter._babylonScene.useRightHandedSystem ? -1 : 1), localAxis.x) + Math.PI / 2;\r\n const len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);\r\n const pitch = -Math.atan2(localAxis.y, len);\r\n const lightRotationQuaternion = Quaternion.RotationYawPitchRoll(yaw, pitch, 0);\r\n if (convertToRightHandedSystem) {\r\n _GLTFUtilities._GetRightHandedQuaternionFromRef(lightRotationQuaternion);\r\n }\r\n if (!lightRotationQuaternion.equals(Quaternion.Identity())) {\r\n node.rotation = lightRotationQuaternion.asArray();\r\n }\r\n }\r\n\r\n if (babylonLight.falloffType !== Light.FALLOFF_GLTF) {\r\n Logger.Warn(`${context}: Light falloff for ${babylonLight.name} does not match the ${NAME} specification!`);\r\n }\r\n light = {\r\n type: lightType,\r\n };\r\n if (!babylonLight.diffuse.equals(Color3.White())) {\r\n light.color = babylonLight.diffuse.asArray();\r\n }\r\n if (babylonLight.intensity !== 1.0) {\r\n light.intensity = babylonLight.intensity;\r\n }\r\n if (babylonLight.range !== Number.MAX_VALUE) {\r\n light.range = babylonLight.range;\r\n }\r\n\r\n if (lightType === IKHRLightsPunctual_LightType.SPOT) {\r\n const babylonSpotLight = babylonLight as SpotLight;\r\n if (babylonSpotLight.angle !== Math.PI / 2.0) {\r\n if (light.spot == null) {\r\n light.spot = {};\r\n }\r\n light.spot.outerConeAngle = babylonSpotLight.angle / 2.0;\r\n }\r\n if (babylonSpotLight.innerAngle !== 0) {\r\n if (light.spot == null) {\r\n light.spot = {};\r\n }\r\n light.spot.innerConeAngle = babylonSpotLight.innerAngle / 2.0;\r\n }\r\n }\r\n\r\n if (this._lights == null) {\r\n this._lights = {\r\n lights: [],\r\n };\r\n }\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 // Avoid duplicating the Light's parent node if possible.\r\n const parentBabylonNode = babylonNode.parent;\r\n if (parentBabylonNode && parentBabylonNode.getChildren().length == 1) {\r\n const parentNode = this._exporter._nodes[nodeMap![parentBabylonNode.uniqueId]];\r\n if (parentNode) {\r\n const parentNodeLocalMatrix = TmpVectors.Matrix[0];\r\n const parentInvertNodeLocalMatrix = TmpVectors.Matrix[1];\r\n const parentNodeLocalTranslation = parentNode.translation\r\n ? new Vector3(parentNode.translation[0], parentNode.translation[1], parentNode.translation[2])\r\n : Vector3.Zero();\r\n const parentNodeLocalRotation = parentNode.rotation\r\n ? new Quaternion(parentNode.rotation[0], parentNode.rotation[1], parentNode.rotation[2], parentNode.rotation[3])\r\n : Quaternion.Identity();\r\n const parentNodeLocalScale = parentNode.scale ? new Vector3(parentNode.scale[0], parentNode.scale[1], parentNode.scale[2]) : Vector3.One();\r\n\r\n Matrix.ComposeToRef(parentNodeLocalScale, parentNodeLocalRotation, parentNodeLocalTranslation, parentNodeLocalMatrix);\r\n parentNodeLocalMatrix.invertToRef(parentInvertNodeLocalMatrix);\r\n\r\n // Convert light local matrix to local matrix relative to grandparent, facing -Z\r\n const lightLocalMatrix = TmpVectors.Matrix[2];\r\n const nodeLocalTranslation = node.translation ? new Vector3(node.translation[0], node.translation[1], node.translation[2]) : Vector3.Zero();\r\n\r\n // Undo directional light positional offset\r\n if (babylonLight instanceof DirectionalLight) {\r\n nodeLocalTranslation.subtractInPlace(\r\n this._exporter._babylonScene.useRightHandedSystem\r\n ? babylonLight.direction\r\n : _GLTFUtilities._GetRightHandedPositionVector3(babylonLight.direction)\r\n );\r\n }\r\n const nodeLocalRotation = this._exporter._babylonScene.useRightHandedSystem ? Quaternion.Identity() : new Quaternion(0, 1, 0, 0);\r\n if (node.rotation) {\r\n nodeLocalRotation.multiplyInPlace(new Quaternion(node.rotation[0], node.rotation[1], node.rotation[2], node.rotation[3]));\r\n }\r\n const nodeLocalScale = node.scale ? new Vector3(node.scale[0], node.scale[1], node.scale[2]) : Vector3.One();\r\n\r\n Matrix.ComposeToRef(nodeLocalScale, nodeLocalRotation, nodeLocalTranslation, lightLocalMatrix);\r\n lightLocalMatrix.multiplyToRef(parentInvertNodeLocalMatrix, lightLocalMatrix);\r\n const parentNewScale = TmpVectors.Vector3[0];\r\n const parentNewRotationQuaternion = TmpVectors.Quaternion[0];\r\n const parentNewTranslation = TmpVectors.Vector3[1];\r\n\r\n lightLocalMatrix.decompose(parentNewScale, parentNewRotationQuaternion, parentNewTranslation);\r\n parentNode.scale = parentNewScale.asArray();\r\n parentNode.rotation = parentNewRotationQuaternion.asArray();\r\n parentNode.translation = parentNewTranslation.asArray();\r\n\r\n if (parentNode.extensions == null) {\r\n parentNode.extensions = {};\r\n }\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 if (node.extensions == null) {\r\n node.extensions = {};\r\n }\r\n\r\n node.extensions[NAME] = lightReference;\r\n }\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_lights_punctual(exporter));\r\n"]}
@@ -1,24 +1,24 @@
1
- import { IMaterial } from "babylonjs-gltf2interface";
2
- import { IGLTFExporterExtensionV2 } from "../glTFExporterExtension";
3
- import { _Exporter } from "../glTFExporter";
4
- import { Material } from "@babylonjs/core/Materials/material.js";
5
- import { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
6
- /**
7
- * @hidden
8
- */
9
- export declare class KHR_materials_clearcoat implements IGLTFExporterExtensionV2 {
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: _Exporter);
19
- dispose(): void;
20
- /** @hidden */
21
- get wasUsed(): boolean;
22
- postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
23
- postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
24
- }
1
+ import type { IMaterial } from "babylonjs-gltf2interface";
2
+ import type { IGLTFExporterExtensionV2 } from "../glTFExporterExtension";
3
+ import { _Exporter } from "../glTFExporter";
4
+ import type { Material } from "@babylonjs/core/Materials/material.js";
5
+ import type { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
6
+ /**
7
+ * @hidden
8
+ */
9
+ export declare class KHR_materials_clearcoat implements IGLTFExporterExtensionV2 {
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: _Exporter);
19
+ dispose(): void;
20
+ /** @hidden */
21
+ get wasUsed(): boolean;
22
+ postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
23
+ postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
24
+ }