@babylonjs/serializers 7.37.1 → 7.37.2

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 (70) hide show
  1. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +6 -7
  2. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +18 -12
  3. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
  4. package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +5 -6
  5. package/glTF/2.0/Extensions/KHR_lights_punctual.js +99 -109
  6. package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
  7. package/glTF/2.0/Extensions/KHR_materials_anisotropy.d.ts +2 -2
  8. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js +6 -6
  9. package/glTF/2.0/Extensions/KHR_materials_anisotropy.js.map +1 -1
  10. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +2 -2
  11. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +9 -9
  12. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
  13. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.d.ts +2 -2
  14. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js +7 -7
  15. package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js.map +1 -1
  16. package/glTF/2.0/Extensions/KHR_materials_dispersion.js +2 -2
  17. package/glTF/2.0/Extensions/KHR_materials_dispersion.js.map +1 -1
  18. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +2 -2
  19. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
  20. package/glTF/2.0/Extensions/KHR_materials_ior.js +2 -2
  21. package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
  22. package/glTF/2.0/Extensions/KHR_materials_iridescence.d.ts +2 -2
  23. package/glTF/2.0/Extensions/KHR_materials_iridescence.js +7 -7
  24. package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -1
  25. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +2 -2
  26. package/glTF/2.0/Extensions/KHR_materials_sheen.js +8 -8
  27. package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
  28. package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +2 -2
  29. package/glTF/2.0/Extensions/KHR_materials_specular.js +7 -7
  30. package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
  31. package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +2 -2
  32. package/glTF/2.0/Extensions/KHR_materials_transmission.js +6 -6
  33. package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
  34. package/glTF/2.0/Extensions/KHR_materials_unlit.js +2 -2
  35. package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
  36. package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +2 -2
  37. package/glTF/2.0/Extensions/KHR_materials_volume.js +6 -6
  38. package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
  39. package/glTF/2.0/Extensions/KHR_texture_transform.js +2 -2
  40. package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
  41. package/glTF/2.0/Extensions/index.d.ts +9 -9
  42. package/glTF/2.0/Extensions/index.js +9 -9
  43. package/glTF/2.0/Extensions/index.js.map +1 -1
  44. package/glTF/2.0/dataWriter.d.ts +18 -0
  45. package/glTF/2.0/dataWriter.js +65 -0
  46. package/glTF/2.0/dataWriter.js.map +1 -0
  47. package/glTF/2.0/glTFAnimation.d.ts +4 -10
  48. package/glTF/2.0/glTFAnimation.js +87 -19
  49. package/glTF/2.0/glTFAnimation.js.map +1 -1
  50. package/glTF/2.0/glTFData.d.ts +5 -3
  51. package/glTF/2.0/glTFData.js +35 -36
  52. package/glTF/2.0/glTFData.js.map +1 -1
  53. package/glTF/2.0/glTFExporter.d.ts +62 -363
  54. package/glTF/2.0/glTFExporter.js +867 -1579
  55. package/glTF/2.0/glTFExporter.js.map +1 -1
  56. package/glTF/2.0/glTFExporterExtension.d.ts +8 -9
  57. package/glTF/2.0/glTFExporterExtension.js.map +1 -1
  58. package/glTF/2.0/glTFMaterialExporter.d.ts +26 -126
  59. package/glTF/2.0/glTFMaterialExporter.js +276 -438
  60. package/glTF/2.0/glTFMaterialExporter.js.map +1 -1
  61. package/glTF/2.0/glTFMorphTargetsUtilities.d.ts +14 -0
  62. package/glTF/2.0/glTFMorphTargetsUtilities.js +105 -0
  63. package/glTF/2.0/glTFMorphTargetsUtilities.js.map +1 -0
  64. package/glTF/2.0/glTFSerializer.d.ts +10 -13
  65. package/glTF/2.0/glTFSerializer.js +25 -44
  66. package/glTF/2.0/glTFSerializer.js.map +1 -1
  67. package/glTF/2.0/glTFUtilities.d.ts +75 -43
  68. package/glTF/2.0/glTFUtilities.js +350 -103
  69. package/glTF/2.0/glTFUtilities.js.map +1 -1
  70. package/package.json +3 -3
@@ -1,7 +1,7 @@
1
1
  import type { INode } from "babylonjs-gltf2interface";
2
2
  import type { IGLTFExporterExtensionV2 } from "../glTFExporterExtension";
3
- import type { _BinaryWriter } from "../glTFExporter";
4
- import { _Exporter } from "../glTFExporter";
3
+ import type { DataWriter } from "../dataWriter";
4
+ import { GLTFExporter } from "../glTFExporter";
5
5
  import type { Nullable } from "@babylonjs/core/types.js";
6
6
  import type { Node } from "@babylonjs/core/node.js";
7
7
  import "@babylonjs/core/Meshes/thinInstanceMesh.js";
@@ -17,7 +17,7 @@ export declare class EXT_mesh_gpu_instancing implements IGLTFExporterExtensionV2
17
17
  required: boolean;
18
18
  private _exporter;
19
19
  private _wasUsed;
20
- constructor(exporter: _Exporter);
20
+ constructor(exporter: GLTFExporter);
21
21
  dispose(): void;
22
22
  /** @internal */
23
23
  get wasUsed(): boolean;
@@ -27,11 +27,10 @@ export declare class EXT_mesh_gpu_instancing implements IGLTFExporterExtensionV2
27
27
  * @param node the node exported
28
28
  * @param babylonNode the corresponding babylon node
29
29
  * @param nodeMap map from babylon node id to node index
30
- * @param binaryWriter binary writer
30
+ * @param convertToRightHanded true if we need to convert data from left hand to right hand system.
31
+ * @param dataWriter binary writer
31
32
  * @returns nullable promise, resolves with the node
32
33
  */
33
- postExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap: {
34
- [key: number]: number;
35
- }, binaryWriter: _BinaryWriter): Promise<Nullable<INode>>;
34
+ postExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap: Map<Node, number>, convertToRightHanded: boolean, dataWriter: DataWriter): Promise<Nullable<INode>>;
36
35
  private _buildAccessor;
37
36
  }
@@ -1,8 +1,9 @@
1
- import { _Exporter } from "../glTFExporter.js";
1
+ import { GLTFExporter } from "../glTFExporter.js";
2
2
  import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
3
3
  import "@babylonjs/core/Meshes/thinInstanceMesh.js";
4
4
  import { TmpVectors, Quaternion, Vector3 } from "@babylonjs/core/Maths/math.vector.js";
5
5
  import { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
6
+ import { ConvertToRightHandedPosition, ConvertToRightHandedRotation } from "../glTFUtilities.js";
6
7
  const NAME = "EXT_mesh_gpu_instancing";
7
8
  /**
8
9
  * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_mesh_gpu_instancing/README.md)
@@ -30,13 +31,14 @@ export class EXT_mesh_gpu_instancing {
30
31
  * @param node the node exported
31
32
  * @param babylonNode the corresponding babylon node
32
33
  * @param nodeMap map from babylon node id to node index
33
- * @param binaryWriter binary writer
34
+ * @param convertToRightHanded true if we need to convert data from left hand to right hand system.
35
+ * @param dataWriter binary writer
34
36
  * @returns nullable promise, resolves with the node
35
37
  */
36
- postExportNodeAsync(context, node, babylonNode, nodeMap, binaryWriter) {
38
+ postExportNodeAsync(context, node, babylonNode, nodeMap, convertToRightHanded, dataWriter) {
37
39
  return new Promise((resolve) => {
38
40
  if (node && babylonNode instanceof Mesh) {
39
- if (babylonNode.hasThinInstances && binaryWriter) {
41
+ if (babylonNode.hasThinInstances && this._exporter) {
40
42
  this._wasUsed = true;
41
43
  const noTranslation = Vector3.Zero();
42
44
  const noRotation = Quaternion.Identity();
@@ -56,6 +58,10 @@ export class EXT_mesh_gpu_instancing {
56
58
  let i = 0;
57
59
  for (const m of matrix) {
58
60
  m.decompose(iws, iwr, iwt);
61
+ if (convertToRightHanded) {
62
+ ConvertToRightHandedPosition(iwt);
63
+ ConvertToRightHandedRotation(iwr);
64
+ }
59
65
  // fill the temp buffer
60
66
  translationBuffer.set(iwt.asArray(), i * 3);
61
67
  rotationBuffer.set(iwr.normalize().asArray(), i * 4); // ensure the quaternion is normalized
@@ -71,16 +77,16 @@ export class EXT_mesh_gpu_instancing {
71
77
  };
72
78
  // do we need to write TRANSLATION ?
73
79
  if (hasAnyInstanceWorldTranslation) {
74
- extension.attributes["TRANSLATION"] = this._buildAccessor(translationBuffer, "VEC3" /* AccessorType.VEC3 */, babylonNode.thinInstanceCount, binaryWriter, 5126 /* AccessorComponentType.FLOAT */);
80
+ extension.attributes["TRANSLATION"] = this._buildAccessor(translationBuffer, "VEC3" /* AccessorType.VEC3 */, babylonNode.thinInstanceCount, dataWriter, 5126 /* AccessorComponentType.FLOAT */);
75
81
  }
76
82
  // do we need to write ROTATION ?
77
83
  if (hasAnyInstanceWorldRotation) {
78
84
  const componentType = 5126 /* AccessorComponentType.FLOAT */; // we decided to stay on FLOAT for now see https://github.com/BabylonJS/Babylon.js/pull/12495
79
- extension.attributes["ROTATION"] = this._buildAccessor(rotationBuffer, "VEC4" /* AccessorType.VEC4 */, babylonNode.thinInstanceCount, binaryWriter, componentType);
85
+ extension.attributes["ROTATION"] = this._buildAccessor(rotationBuffer, "VEC4" /* AccessorType.VEC4 */, babylonNode.thinInstanceCount, dataWriter, componentType);
80
86
  }
81
87
  // do we need to write SCALE ?
82
88
  if (hasAnyInstanceWorldScale) {
83
- extension.attributes["SCALE"] = this._buildAccessor(scaleBuffer, "VEC3" /* AccessorType.VEC3 */, babylonNode.thinInstanceCount, binaryWriter, 5126 /* AccessorComponentType.FLOAT */);
89
+ extension.attributes["SCALE"] = this._buildAccessor(scaleBuffer, "VEC3" /* AccessorType.VEC3 */, babylonNode.thinInstanceCount, dataWriter, 5126 /* AccessorComponentType.FLOAT */);
84
90
  }
85
91
  /* eslint-enable @typescript-eslint/naming-convention*/
86
92
  node.extensions = node.extensions || {};
@@ -92,23 +98,23 @@ export class EXT_mesh_gpu_instancing {
92
98
  }
93
99
  _buildAccessor(buffer, type, count, binaryWriter, componentType) {
94
100
  // write the buffer
95
- const bufferOffset = binaryWriter.getByteOffset();
101
+ const bufferOffset = binaryWriter.byteOffset;
96
102
  switch (componentType) {
97
103
  case 5126 /* AccessorComponentType.FLOAT */: {
98
104
  for (let i = 0; i != buffer.length; i++) {
99
- binaryWriter.setFloat32(buffer[i]);
105
+ binaryWriter.writeFloat32(buffer[i]);
100
106
  }
101
107
  break;
102
108
  }
103
109
  case 5120 /* AccessorComponentType.BYTE */: {
104
110
  for (let i = 0; i != buffer.length; i++) {
105
- binaryWriter.setByte(buffer[i] * 127);
111
+ binaryWriter.writeInt8(buffer[i] * 127);
106
112
  }
107
113
  break;
108
114
  }
109
115
  case 5122 /* AccessorComponentType.SHORT */: {
110
116
  for (let i = 0; i != buffer.length; i++) {
111
- binaryWriter.setInt16(buffer[i] * 32767);
117
+ binaryWriter.writeInt16(buffer[i] * 32767);
112
118
  }
113
119
  break;
114
120
  }
@@ -131,5 +137,5 @@ export class EXT_mesh_gpu_instancing {
131
137
  }
132
138
  }
133
139
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
134
- _Exporter.RegisterExtension(NAME, (exporter) => new EXT_mesh_gpu_instancing(exporter));
140
+ GLTFExporter.RegisterExtension(NAME, (exporter) => new EXT_mesh_gpu_instancing(exporter));
135
141
  //# sourceMappingURL=EXT_mesh_gpu_instancing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EXT_mesh_gpu_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ErC,6BAA6B;QAC7B,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC;QACvD,MAAM,QAAQ,GAAc;YACxB,UAAU,EAAE,eAAe;YAC3B,aAAa,EAAE,aAAa;YAC5B,KAAK,EAAE,KAAK;YACZ,IAAI,EAAE,IAAI;YACV,UAAU,EAAE,aAAa,yCAA8B,IAAI,aAAa,0CAA+B;SAC1G,CAAC;QACF,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzC,OAAO,aAAa,CAAC;IACzB,CAAC;CACJ;AAED,6DAA6D;AAC7D,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,uBAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IBufferView, IAccessor, INode, IEXTMeshGpuInstancing } from \"babylonjs-gltf2interface\";\r\nimport { AccessorType, AccessorComponentType } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport type { _BinaryWriter } from \"../glTFExporter\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { Node } from \"core/node\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\nimport \"core/Meshes/thinInstanceMesh\";\r\nimport { TmpVectors, Quaternion, Vector3 } from \"core/Maths/math.vector\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\n\r\nconst NAME = \"EXT_mesh_gpu_instancing\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_mesh_gpu_instancing/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class EXT_mesh_gpu_instancing implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: _Exporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: _Exporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n /**\r\n * After node is exported\r\n * @param context the GLTF context when loading the asset\r\n * @param node the node exported\r\n * @param babylonNode the corresponding babylon node\r\n * @param nodeMap map from babylon node id to node index\r\n * @param binaryWriter binary writer\r\n * @returns nullable promise, resolves with the node\r\n */\r\n public postExportNodeAsync(\r\n context: string,\r\n node: Nullable<INode>,\r\n babylonNode: Node,\r\n nodeMap: { [key: number]: number },\r\n binaryWriter: _BinaryWriter\r\n ): Promise<Nullable<INode>> {\r\n return new Promise((resolve) => {\r\n if (node && babylonNode instanceof Mesh) {\r\n if (babylonNode.hasThinInstances && binaryWriter) {\r\n this._wasUsed = true;\r\n\r\n const noTranslation = Vector3.Zero();\r\n const noRotation = Quaternion.Identity();\r\n const noScale = Vector3.One();\r\n\r\n // retrieve all the instance world matrix\r\n const matrix = babylonNode.thinInstanceGetWorldMatrices();\r\n\r\n const iwt = TmpVectors.Vector3[2];\r\n const iwr = TmpVectors.Quaternion[1];\r\n const iws = TmpVectors.Vector3[3];\r\n\r\n let hasAnyInstanceWorldTranslation = false;\r\n let hasAnyInstanceWorldRotation = false;\r\n let hasAnyInstanceWorldScale = false;\r\n\r\n // prepare temp buffers\r\n const translationBuffer = new Float32Array(babylonNode.thinInstanceCount * 3);\r\n const rotationBuffer = new Float32Array(babylonNode.thinInstanceCount * 4);\r\n const scaleBuffer = new Float32Array(babylonNode.thinInstanceCount * 3);\r\n\r\n let i = 0;\r\n for (const m of matrix) {\r\n m.decompose(iws, iwr, iwt);\r\n\r\n // fill the temp buffer\r\n translationBuffer.set(iwt.asArray(), i * 3);\r\n rotationBuffer.set(iwr.normalize().asArray(), i * 4); // ensure the quaternion is normalized\r\n scaleBuffer.set(iws.asArray(), i * 3);\r\n\r\n // this is where we decide if there is any transformation\r\n hasAnyInstanceWorldTranslation = hasAnyInstanceWorldTranslation || !iwt.equalsWithEpsilon(noTranslation);\r\n hasAnyInstanceWorldRotation = hasAnyInstanceWorldRotation || !iwr.equalsWithEpsilon(noRotation);\r\n hasAnyInstanceWorldScale = hasAnyInstanceWorldScale || !iws.equalsWithEpsilon(noScale);\r\n\r\n i++;\r\n }\r\n\r\n const extension: IEXTMeshGpuInstancing = {\r\n attributes: {},\r\n };\r\n\r\n // do we need to write TRANSLATION ?\r\n if (hasAnyInstanceWorldTranslation) {\r\n extension.attributes[\"TRANSLATION\"] = this._buildAccessor(\r\n translationBuffer,\r\n AccessorType.VEC3,\r\n babylonNode.thinInstanceCount,\r\n binaryWriter,\r\n AccessorComponentType.FLOAT\r\n );\r\n }\r\n // do we need to write ROTATION ?\r\n if (hasAnyInstanceWorldRotation) {\r\n const componentType = AccessorComponentType.FLOAT; // we decided to stay on FLOAT for now see https://github.com/BabylonJS/Babylon.js/pull/12495\r\n extension.attributes[\"ROTATION\"] = this._buildAccessor(rotationBuffer, AccessorType.VEC4, babylonNode.thinInstanceCount, binaryWriter, componentType);\r\n }\r\n // do we need to write SCALE ?\r\n if (hasAnyInstanceWorldScale) {\r\n extension.attributes[\"SCALE\"] = this._buildAccessor(\r\n scaleBuffer,\r\n AccessorType.VEC3,\r\n babylonNode.thinInstanceCount,\r\n binaryWriter,\r\n AccessorComponentType.FLOAT\r\n );\r\n }\r\n\r\n /* eslint-enable @typescript-eslint/naming-convention*/\r\n node.extensions = node.extensions || {};\r\n node.extensions[NAME] = extension;\r\n }\r\n }\r\n resolve(node);\r\n });\r\n }\r\n\r\n private _buildAccessor(buffer: Float32Array, type: AccessorType, count: number, binaryWriter: _BinaryWriter, componentType: AccessorComponentType): number {\r\n // write the buffer\r\n const bufferOffset = binaryWriter.getByteOffset();\r\n switch (componentType) {\r\n case AccessorComponentType.FLOAT: {\r\n for (let i = 0; i != buffer.length; i++) {\r\n binaryWriter.setFloat32(buffer[i]);\r\n }\r\n break;\r\n }\r\n case AccessorComponentType.BYTE: {\r\n for (let i = 0; i != buffer.length; i++) {\r\n binaryWriter.setByte(buffer[i] * 127);\r\n }\r\n break;\r\n }\r\n case AccessorComponentType.SHORT: {\r\n for (let i = 0; i != buffer.length; i++) {\r\n binaryWriter.setInt16(buffer[i] * 32767);\r\n }\r\n\r\n break;\r\n }\r\n }\r\n // build the buffer view\r\n const bv: IBufferView = { buffer: 0, byteOffset: bufferOffset, byteLength: buffer.length * VertexBuffer.GetTypeByteLength(componentType) };\r\n const bufferViewIndex = this._exporter._bufferViews.length;\r\n this._exporter._bufferViews.push(bv);\r\n\r\n // finally build the accessor\r\n const accessorIndex = this._exporter._accessors.length;\r\n const accessor: IAccessor = {\r\n bufferView: bufferViewIndex,\r\n componentType: componentType,\r\n count: count,\r\n type: type,\r\n normalized: componentType == AccessorComponentType.BYTE || componentType == AccessorComponentType.SHORT,\r\n };\r\n this._exporter._accessors.push(accessor);\r\n return accessorIndex;\r\n }\r\n}\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\n_Exporter.RegisterExtension(NAME, (exporter) => new EXT_mesh_gpu_instancing(exporter));\r\n"]}
1
+ {"version":3,"file":"EXT_mesh_gpu_instancing.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAAE,IAAI,EAAE,uCAAyB;AACxC,oDAAsC;AACtC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,6CAA+B;AACzE,OAAO,EAAE,YAAY,EAAE,0CAA4B;AACnD,OAAO,EAAE,4BAA4B,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAE9F,MAAM,IAAI,GAAG,yBAAyB,CAA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,IAAI,EAAE,IAAI;YACV,UAAU,EAAE,aAAa,yCAA8B,IAAI,aAAa,0CAA+B;SAC1G,CAAC;QACF,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzC,OAAO,aAAa,CAAC;IACzB,CAAC;CACJ;AAED,6DAA6D;AAC7D,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,uBAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IBufferView, IAccessor, INode, IEXTMeshGpuInstancing } from \"babylonjs-gltf2interface\";\r\nimport { AccessorType, AccessorComponentType } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport type { DataWriter } from \"../dataWriter\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { Node } from \"core/node\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\nimport \"core/Meshes/thinInstanceMesh\";\r\nimport { TmpVectors, Quaternion, Vector3 } from \"core/Maths/math.vector\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\nimport { ConvertToRightHandedPosition, ConvertToRightHandedRotation } from \"../glTFUtilities\";\r\n\r\nconst NAME = \"EXT_mesh_gpu_instancing\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_mesh_gpu_instancing/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class EXT_mesh_gpu_instancing implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: GLTFExporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: GLTFExporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n /**\r\n * After node is exported\r\n * @param context the GLTF context when loading the asset\r\n * @param node the node exported\r\n * @param babylonNode the corresponding babylon node\r\n * @param nodeMap map from babylon node id to node index\r\n * @param convertToRightHanded true if we need to convert data from left hand to right hand system.\r\n * @param dataWriter binary writer\r\n * @returns nullable promise, resolves with the node\r\n */\r\n public postExportNodeAsync(\r\n context: string,\r\n node: Nullable<INode>,\r\n babylonNode: Node,\r\n nodeMap: Map<Node, number>,\r\n convertToRightHanded: boolean,\r\n dataWriter: DataWriter\r\n ): Promise<Nullable<INode>> {\r\n return new Promise((resolve) => {\r\n if (node && babylonNode instanceof Mesh) {\r\n if (babylonNode.hasThinInstances && this._exporter) {\r\n this._wasUsed = true;\r\n\r\n const noTranslation = Vector3.Zero();\r\n const noRotation = Quaternion.Identity();\r\n const noScale = Vector3.One();\r\n\r\n // retrieve all the instance world matrix\r\n const matrix = babylonNode.thinInstanceGetWorldMatrices();\r\n\r\n const iwt = TmpVectors.Vector3[2];\r\n const iwr = TmpVectors.Quaternion[1];\r\n const iws = TmpVectors.Vector3[3];\r\n\r\n let hasAnyInstanceWorldTranslation = false;\r\n let hasAnyInstanceWorldRotation = false;\r\n let hasAnyInstanceWorldScale = false;\r\n\r\n // prepare temp buffers\r\n const translationBuffer = new Float32Array(babylonNode.thinInstanceCount * 3);\r\n const rotationBuffer = new Float32Array(babylonNode.thinInstanceCount * 4);\r\n const scaleBuffer = new Float32Array(babylonNode.thinInstanceCount * 3);\r\n\r\n let i = 0;\r\n for (const m of matrix) {\r\n m.decompose(iws, iwr, iwt);\r\n\r\n if (convertToRightHanded) {\r\n ConvertToRightHandedPosition(iwt);\r\n ConvertToRightHandedRotation(iwr);\r\n }\r\n\r\n // fill the temp buffer\r\n translationBuffer.set(iwt.asArray(), i * 3);\r\n rotationBuffer.set(iwr.normalize().asArray(), i * 4); // ensure the quaternion is normalized\r\n scaleBuffer.set(iws.asArray(), i * 3);\r\n\r\n // this is where we decide if there is any transformation\r\n hasAnyInstanceWorldTranslation = hasAnyInstanceWorldTranslation || !iwt.equalsWithEpsilon(noTranslation);\r\n hasAnyInstanceWorldRotation = hasAnyInstanceWorldRotation || !iwr.equalsWithEpsilon(noRotation);\r\n hasAnyInstanceWorldScale = hasAnyInstanceWorldScale || !iws.equalsWithEpsilon(noScale);\r\n\r\n i++;\r\n }\r\n\r\n const extension: IEXTMeshGpuInstancing = {\r\n attributes: {},\r\n };\r\n\r\n // do we need to write TRANSLATION ?\r\n if (hasAnyInstanceWorldTranslation) {\r\n extension.attributes[\"TRANSLATION\"] = this._buildAccessor(\r\n translationBuffer,\r\n AccessorType.VEC3,\r\n babylonNode.thinInstanceCount,\r\n dataWriter,\r\n AccessorComponentType.FLOAT\r\n );\r\n }\r\n // do we need to write ROTATION ?\r\n if (hasAnyInstanceWorldRotation) {\r\n const componentType = AccessorComponentType.FLOAT; // we decided to stay on FLOAT for now see https://github.com/BabylonJS/Babylon.js/pull/12495\r\n extension.attributes[\"ROTATION\"] = this._buildAccessor(rotationBuffer, AccessorType.VEC4, babylonNode.thinInstanceCount, dataWriter, componentType);\r\n }\r\n // do we need to write SCALE ?\r\n if (hasAnyInstanceWorldScale) {\r\n extension.attributes[\"SCALE\"] = this._buildAccessor(scaleBuffer, AccessorType.VEC3, babylonNode.thinInstanceCount, dataWriter, AccessorComponentType.FLOAT);\r\n }\r\n\r\n /* eslint-enable @typescript-eslint/naming-convention*/\r\n node.extensions = node.extensions || {};\r\n node.extensions[NAME] = extension;\r\n }\r\n }\r\n resolve(node);\r\n });\r\n }\r\n\r\n private _buildAccessor(buffer: Float32Array, type: AccessorType, count: number, binaryWriter: DataWriter, componentType: AccessorComponentType): number {\r\n // write the buffer\r\n const bufferOffset = binaryWriter.byteOffset;\r\n switch (componentType) {\r\n case AccessorComponentType.FLOAT: {\r\n for (let i = 0; i != buffer.length; i++) {\r\n binaryWriter.writeFloat32(buffer[i]);\r\n }\r\n break;\r\n }\r\n case AccessorComponentType.BYTE: {\r\n for (let i = 0; i != buffer.length; i++) {\r\n binaryWriter.writeInt8(buffer[i] * 127);\r\n }\r\n break;\r\n }\r\n case AccessorComponentType.SHORT: {\r\n for (let i = 0; i != buffer.length; i++) {\r\n binaryWriter.writeInt16(buffer[i] * 32767);\r\n }\r\n\r\n break;\r\n }\r\n }\r\n // build the buffer view\r\n const bv: IBufferView = { buffer: 0, byteOffset: bufferOffset, byteLength: buffer.length * VertexBuffer.GetTypeByteLength(componentType) };\r\n const bufferViewIndex = this._exporter._bufferViews.length;\r\n this._exporter._bufferViews.push(bv);\r\n\r\n // finally build the accessor\r\n const accessorIndex = this._exporter._accessors.length;\r\n const accessor: IAccessor = {\r\n bufferView: bufferViewIndex,\r\n componentType: componentType,\r\n count: count,\r\n type: type,\r\n normalized: componentType == AccessorComponentType.BYTE || componentType == AccessorComponentType.SHORT,\r\n };\r\n this._exporter._accessors.push(accessor);\r\n return accessorIndex;\r\n }\r\n}\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new EXT_mesh_gpu_instancing(exporter));\r\n"]}
@@ -2,7 +2,7 @@ import type { Nullable } from "@babylonjs/core/types.js";
2
2
  import type { Node } from "@babylonjs/core/node.js";
3
3
  import type { INode } from "babylonjs-gltf2interface";
4
4
  import type { IGLTFExporterExtensionV2 } from "../glTFExporterExtension";
5
- import { _Exporter } from "../glTFExporter";
5
+ import { GLTFExporter } from "../glTFExporter";
6
6
  /**
7
7
  * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
8
8
  */
@@ -19,7 +19,7 @@ export declare class KHR_lights_punctual implements IGLTFExporterExtensionV2 {
19
19
  /**
20
20
  * @internal
21
21
  */
22
- constructor(exporter: _Exporter);
22
+ constructor(exporter: GLTFExporter);
23
23
  /** @internal */
24
24
  dispose(): void;
25
25
  /** @internal */
@@ -31,10 +31,9 @@ export declare class KHR_lights_punctual implements IGLTFExporterExtensionV2 {
31
31
  * @param context The context when exporting the node
32
32
  * @param node glTF node
33
33
  * @param babylonNode BabylonJS node
34
- * @param nodeMap Node mapping of unique id to glTF node index
34
+ * @param nodeMap Node mapping of babylon node to glTF node index
35
+ * @param convertToRightHanded Flag to convert the values to right-handed
35
36
  * @returns nullable INode promise
36
37
  */
37
- postExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap: {
38
- [key: number]: number;
39
- }): Promise<Nullable<INode>>;
38
+ postExportNodeAsync(context: string, node: INode, babylonNode: Node, nodeMap: Map<Node, number>, convertToRightHanded: boolean): Promise<Nullable<INode>>;
40
39
  }
@@ -1,10 +1,21 @@
1
- import { Vector3, Quaternion, TmpVectors, Matrix } from "@babylonjs/core/Maths/math.vector.js";
2
- import { Color3 } from "@babylonjs/core/Maths/math.color.js";
1
+ import { Vector3, Quaternion, TmpVectors } from "@babylonjs/core/Maths/math.vector.js";
3
2
  import { Light } from "@babylonjs/core/Lights/light.js";
4
3
  import { ShadowLight } from "@babylonjs/core/Lights/shadowLight.js";
5
- import { _Exporter } from "../glTFExporter.js";
4
+ import { GLTFExporter } from "../glTFExporter.js";
6
5
  import { Logger } from "@babylonjs/core/Misc/logger.js";
6
+ import { ConvertToRightHandedPosition, OmitDefaultValues, CollapseParentNode, IsParentAddedByImporter } from "../glTFUtilities.js";
7
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();
8
19
  /**
9
20
  * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
10
21
  */
@@ -39,120 +50,99 @@ export class KHR_lights_punctual {
39
50
  * @param context The context when exporting the node
40
51
  * @param node glTF node
41
52
  * @param babylonNode BabylonJS node
42
- * @param nodeMap Node mapping of unique id to glTF node index
53
+ * @param nodeMap Node mapping of babylon node to glTF node index
54
+ * @param convertToRightHanded Flag to convert the values to right-handed
43
55
  * @returns nullable INode promise
44
56
  */
45
- postExportNodeAsync(context, node, babylonNode, nodeMap) {
57
+ postExportNodeAsync(context, node, babylonNode, nodeMap, convertToRightHanded) {
46
58
  return new Promise((resolve) => {
47
- if (node && babylonNode instanceof ShadowLight) {
48
- let light;
49
- const lightType = babylonNode.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT
50
- ? "point" /* KHRLightsPunctual_LightType.POINT */
51
- : babylonNode.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT
52
- ? "directional" /* KHRLightsPunctual_LightType.DIRECTIONAL */
53
- : babylonNode.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT
54
- ? "spot" /* KHRLightsPunctual_LightType.SPOT */
55
- : null;
56
- if (lightType == null) {
57
- Logger.Warn(`${context}: Light ${babylonNode.name} is not supported in ${NAME}`);
59
+ if (!(babylonNode instanceof ShadowLight)) {
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) {
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
+ // Babylon lights have "constant" rotation and variable direction, while
87
+ // glTF lights have variable rotation and constant direction. Therefore,
88
+ // compute a quaternion that aligns the Babylon light's direction with glTF's constant one.
89
+ if (lightType !== "point" /* KHRLightsPunctual_LightType.POINT */) {
90
+ const direction = babylonNode.direction.normalizeToRef(TmpVectors.Vector3[0]);
91
+ if (convertToRightHanded) {
92
+ ConvertToRightHandedPosition(direction);
93
+ }
94
+ const angle = Math.acos(Vector3.Dot(LIGHTDIRECTION, direction));
95
+ const axis = Vector3.Cross(LIGHTDIRECTION, direction);
96
+ const lightRotationQuaternion = Quaternion.RotationAxisToRef(axis, angle, TmpVectors.Quaternion[0]);
97
+ if (!Quaternion.IsIdentity(lightRotationQuaternion)) {
98
+ node.rotation = lightRotationQuaternion.asArray();
58
99
  }
59
- else {
60
- if (!babylonNode.position.equalsToFloats(0, 0, 0)) {
61
- node.translation = babylonNode.position.asArray();
62
- }
63
- if (lightType !== "point" /* KHRLightsPunctual_LightType.POINT */) {
64
- const localAxis = babylonNode.direction;
65
- const yaw = -Math.atan2(localAxis.z, localAxis.x) + Math.PI / 2;
66
- const len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);
67
- const pitch = -Math.atan2(localAxis.y, len);
68
- const lightRotationQuaternion = Quaternion.RotationYawPitchRoll(yaw + Math.PI, pitch, 0);
69
- if (!Quaternion.IsIdentity(lightRotationQuaternion)) {
70
- node.rotation = lightRotationQuaternion.asArray();
71
- }
72
- }
73
- if (babylonNode.falloffType !== Light.FALLOFF_GLTF) {
74
- Logger.Warn(`${context}: Light falloff for ${babylonNode.name} does not match the ${NAME} specification!`);
75
- }
76
- light = {
77
- type: lightType,
78
- };
79
- if (!babylonNode.diffuse.equals(Color3.White())) {
80
- light.color = babylonNode.diffuse.asArray();
81
- }
82
- if (babylonNode.intensity !== 1.0) {
83
- light.intensity = babylonNode.intensity;
84
- }
85
- if (babylonNode.range !== Number.MAX_VALUE) {
86
- light.range = babylonNode.range;
87
- }
88
- if (lightType === "spot" /* KHRLightsPunctual_LightType.SPOT */) {
89
- const babylonSpotLight = babylonNode;
90
- if (babylonSpotLight.angle !== Math.PI / 2.0) {
91
- if (light.spot == null) {
92
- light.spot = {};
93
- }
94
- light.spot.outerConeAngle = babylonSpotLight.angle / 2.0;
95
- }
96
- if (babylonSpotLight.innerAngle !== 0) {
97
- if (light.spot == null) {
98
- light.spot = {};
99
- }
100
- light.spot.innerConeAngle = babylonSpotLight.innerAngle / 2.0;
101
- }
102
- }
103
- this._lights || (this._lights = {
104
- lights: [],
105
- });
106
- this._lights.lights.push(light);
107
- const lightReference = {
108
- light: this._lights.lights.length - 1,
109
- };
110
- // Avoid duplicating the Light's parent node if possible.
111
- const parentBabylonNode = babylonNode.parent;
112
- if (parentBabylonNode && parentBabylonNode.getChildren().length == 1) {
113
- const parentNode = this._exporter._nodes[nodeMap[parentBabylonNode.uniqueId]];
114
- if (parentNode) {
115
- const parentTranslation = Vector3.FromArrayToRef(parentNode.translation || [0, 0, 0], 0, TmpVectors.Vector3[0]);
116
- const parentRotation = Quaternion.FromArrayToRef(parentNode.rotation || [0, 0, 0, 1], 0, TmpVectors.Quaternion[0]);
117
- const parentScale = Vector3.FromArrayToRef(parentNode.scale || [1, 1, 1], 0, TmpVectors.Vector3[1]);
118
- const parentMatrix = Matrix.ComposeToRef(parentScale, parentRotation, parentTranslation, TmpVectors.Matrix[0]);
119
- const translation = Vector3.FromArrayToRef(node.translation || [0, 0, 0], 0, TmpVectors.Vector3[2]);
120
- const rotation = Quaternion.FromArrayToRef(node.rotation || [0, 0, 0, 1], 0, TmpVectors.Quaternion[1]);
121
- const matrix = Matrix.ComposeToRef(Vector3.OneReadOnly, rotation, translation, TmpVectors.Matrix[1]);
122
- parentMatrix.multiplyToRef(matrix, matrix);
123
- matrix.decompose(parentScale, parentRotation, parentTranslation);
124
- if (parentTranslation.equalsToFloats(0, 0, 0)) {
125
- delete parentNode.translation;
126
- }
127
- else {
128
- parentNode.translation = parentTranslation.asArray();
129
- }
130
- if (Quaternion.IsIdentity(parentRotation)) {
131
- delete parentNode.rotation;
132
- }
133
- else {
134
- parentNode.rotation = parentRotation.asArray();
135
- }
136
- if (parentScale.equalsToFloats(1, 1, 1)) {
137
- delete parentNode.scale;
138
- }
139
- else {
140
- parentNode.scale = parentScale.asArray();
141
- }
142
- parentNode.extensions || (parentNode.extensions = {});
143
- parentNode.extensions[NAME] = lightReference;
144
- // Do not export the original node
145
- resolve(null);
146
- return;
147
- }
148
- }
149
- node.extensions || (node.extensions = {});
150
- node.extensions[NAME] = lightReference;
100
+ }
101
+ const light = {
102
+ type: lightType,
103
+ name: babylonNode.name,
104
+ color: babylonNode.diffuse.asArray(),
105
+ intensity: babylonNode.intensity,
106
+ range: babylonNode.range,
107
+ };
108
+ OmitDefaultValues(light, DEFAULTS);
109
+ // Separately handle the required 'spot' field for spot lights
110
+ if (lightType === "spot" /* KHRLightsPunctual_LightType.SPOT */) {
111
+ const babylonSpotLight = babylonNode;
112
+ light.spot = {
113
+ innerConeAngle: babylonSpotLight.innerAngle / 2.0,
114
+ outerConeAngle: babylonSpotLight.angle / 2.0,
115
+ };
116
+ OmitDefaultValues(light.spot, SPOTDEFAULTS);
117
+ }
118
+ this._lights || (this._lights = {
119
+ lights: [],
120
+ });
121
+ this._lights.lights.push(light);
122
+ const lightReference = {
123
+ light: this._lights.lights.length - 1,
124
+ };
125
+ // Assign the light to its parent node, if possible, to condense the glTF
126
+ // Why and when: the glTF loader generates a new parent TransformNode for each light node, which we should undo on export
127
+ const parentBabylonNode = babylonNode.parent;
128
+ if (parentBabylonNode && IsParentAddedByImporter(babylonNode, parentBabylonNode)) {
129
+ const parentNodeIndex = nodeMap.get(parentBabylonNode);
130
+ if (parentNodeIndex) {
131
+ // Combine the light's transformation with the parent's
132
+ const parentNode = this._exporter._nodes[parentNodeIndex];
133
+ CollapseParentNode(node, parentNode);
134
+ parentNode.extensions || (parentNode.extensions = {});
135
+ parentNode.extensions[NAME] = lightReference;
136
+ // Do not export the original node
137
+ resolve(null);
138
+ return;
151
139
  }
152
140
  }
141
+ node.extensions || (node.extensions = {});
142
+ node.extensions[NAME] = lightReference;
153
143
  resolve(node);
154
144
  });
155
145
  }
156
146
  }
157
- _Exporter.RegisterExtension(NAME, (exporter) => new KHR_lights_punctual(exporter));
147
+ GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_lights_punctual(exporter));
158
148
  //# 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,EAAE,6CAA+B;AACjF,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,KAAK,EAAE,wCAA0B;AAE1C,OAAO,EAAE,WAAW,EAAE,8CAAgC;AAItD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,uCAAyB;AAG1C,MAAM,IAAI,GAAG,qBAAqB,CAAC;AAEnC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,mBAAmB;IAe5B;;OAEG;IACH,YAAY,QAAmB;QAjB/B,kCAAkC;QAClB,SAAI,GAAG,IAAI,CAAC;QAE5B,iDAAiD;QAC1C,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,KAAK,CAAC;QA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KAAf,IAAI,CAAC,UAAU,GAAK,EAAE,EAAC;oBACvB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;gBAC3C,CAAC;YACL,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,SAAS,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, Matrix } from \"core/Maths/math.vector\";\r\nimport { Color3 } from \"core/Maths/math.color\";\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, IKHRLightsPunctual_LightReference, IKHRLightsPunctual_Light, IKHRLightsPunctual } from \"babylonjs-gltf2interface\";\r\nimport { KHRLightsPunctual_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 * @internal\r\n */\r\n constructor(exporter: _Exporter) {\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 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 let light: IKHRLightsPunctual_Light;\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 == null) {\r\n Logger.Warn(`${context}: Light ${babylonNode.name} is not supported in ${NAME}`);\r\n } else {\r\n if (!babylonNode.position.equalsToFloats(0, 0, 0)) {\r\n node.translation = babylonNode.position.asArray();\r\n }\r\n if (lightType !== KHRLightsPunctual_LightType.POINT) {\r\n const localAxis = babylonNode.direction;\r\n const yaw = -Math.atan2(localAxis.z, 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 + Math.PI, pitch, 0);\r\n if (!Quaternion.IsIdentity(lightRotationQuaternion)) {\r\n node.rotation = lightRotationQuaternion.asArray();\r\n }\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 light = {\r\n type: lightType,\r\n };\r\n if (!babylonNode.diffuse.equals(Color3.White())) {\r\n light.color = babylonNode.diffuse.asArray();\r\n }\r\n if (babylonNode.intensity !== 1.0) {\r\n light.intensity = babylonNode.intensity;\r\n }\r\n if (babylonNode.range !== Number.MAX_VALUE) {\r\n light.range = babylonNode.range;\r\n }\r\n\r\n if (lightType === KHRLightsPunctual_LightType.SPOT) {\r\n const babylonSpotLight = babylonNode 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 this._lights ||= {\r\n lights: [],\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 parentTranslation = Vector3.FromArrayToRef(parentNode.translation || [0, 0, 0], 0, TmpVectors.Vector3[0]);\r\n const parentRotation = Quaternion.FromArrayToRef(parentNode.rotation || [0, 0, 0, 1], 0, TmpVectors.Quaternion[0]);\r\n const parentScale = Vector3.FromArrayToRef(parentNode.scale || [1, 1, 1], 0, TmpVectors.Vector3[1]);\r\n const parentMatrix = Matrix.ComposeToRef(parentScale, parentRotation, parentTranslation, TmpVectors.Matrix[0]);\r\n\r\n const translation = Vector3.FromArrayToRef(node.translation || [0, 0, 0], 0, TmpVectors.Vector3[2]);\r\n const rotation = Quaternion.FromArrayToRef(node.rotation || [0, 0, 0, 1], 0, TmpVectors.Quaternion[1]);\r\n const matrix = Matrix.ComposeToRef(Vector3.OneReadOnly, rotation, translation, TmpVectors.Matrix[1]);\r\n\r\n parentMatrix.multiplyToRef(matrix, matrix);\r\n matrix.decompose(parentScale, parentRotation, parentTranslation);\r\n\r\n if (parentTranslation.equalsToFloats(0, 0, 0)) {\r\n delete parentNode.translation;\r\n } else {\r\n parentNode.translation = parentTranslation.asArray();\r\n }\r\n\r\n if (Quaternion.IsIdentity(parentRotation)) {\r\n delete parentNode.rotation;\r\n } else {\r\n parentNode.rotation = parentRotation.asArray();\r\n }\r\n\r\n if (parentScale.equalsToFloats(1, 1, 1)) {\r\n delete parentNode.scale;\r\n } else {\r\n parentNode.scale = parentScale.asArray();\r\n }\r\n\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 }\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":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_lights_punctual.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,6CAA+B;AACzE,OAAO,EAAE,KAAK,EAAE,wCAA0B;AAE1C,OAAO,EAAE,WAAW,EAAE,8CAAgC;AAItD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,MA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AE,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, IKHRLightsPunctual_LightReference, IKHRLightsPunctual_Light, IKHRLightsPunctual } from \"babylonjs-gltf2interface\";\r\nimport { 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, CollapseParentNode, IsParentAddedByImporter } 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 postExportNodeAsync(context: string, node: INode, babylonNode: Node, nodeMap: Map<Node, number>, convertToRightHanded: boolean): Promise<Nullable<INode>> {\r\n return new Promise((resolve) => {\r\n if (!(babylonNode instanceof ShadowLight)) {\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) {\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 // Babylon lights have \"constant\" rotation and variable direction, while\r\n // glTF lights have variable rotation and constant direction. Therefore,\r\n // compute a quaternion that aligns the Babylon light's direction with glTF's constant one.\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 const angle = Math.acos(Vector3.Dot(LIGHTDIRECTION, direction));\r\n const axis = Vector3.Cross(LIGHTDIRECTION, direction);\r\n const lightRotationQuaternion = Quaternion.RotationAxisToRef(axis, angle, 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 && IsParentAddedByImporter(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 CollapseParentNode(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,6 +1,6 @@
1
1
  import type { IMaterial } from "babylonjs-gltf2interface";
2
2
  import type { IGLTFExporterExtensionV2 } from "../glTFExporterExtension";
3
- import { _Exporter } from "../glTFExporter";
3
+ import { GLTFExporter } from "../glTFExporter";
4
4
  import type { Material } from "@babylonjs/core/Materials/material.js";
5
5
  import type { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
6
6
  /**
@@ -15,7 +15,7 @@ export declare class KHR_materials_anisotropy implements IGLTFExporterExtensionV
15
15
  required: boolean;
16
16
  private _exporter;
17
17
  private _wasUsed;
18
- constructor(exporter: _Exporter);
18
+ constructor(exporter: GLTFExporter);
19
19
  dispose(): void;
20
20
  /** @internal */
21
21
  get wasUsed(): boolean;
@@ -1,4 +1,4 @@
1
- import { _Exporter } from "../glTFExporter.js";
1
+ import { GLTFExporter } from "../glTFExporter.js";
2
2
  import { PBRBaseMaterial } from "@babylonjs/core/Materials/PBR/pbrBaseMaterial.js";
3
3
  const NAME = "KHR_materials_anisotropy";
4
4
  /**
@@ -42,20 +42,20 @@ export class KHR_materials_anisotropy {
42
42
  }
43
43
  this._wasUsed = true;
44
44
  node.extensions = node.extensions || {};
45
- const anisotropyTextureInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.anisotropy.texture);
45
+ const anisotropyTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.anisotropy.texture);
46
46
  const anisotropyInfo = {
47
47
  anisotropyStrength: babylonMaterial.anisotropy.intensity,
48
48
  anisotropyRotation: babylonMaterial.anisotropy.angle,
49
49
  anisotropyTexture: anisotropyTextureInfo ?? undefined,
50
- hasTextures: () => {
51
- return anisotropyInfo.anisotropyTexture !== null;
52
- },
53
50
  };
51
+ if (anisotropyInfo.anisotropyTexture !== null) {
52
+ this._exporter._materialNeedsUVsSet.add(babylonMaterial);
53
+ }
54
54
  node.extensions[NAME] = anisotropyInfo;
55
55
  }
56
56
  resolve(node);
57
57
  });
58
58
  }
59
59
  }
60
- _Exporter.RegisterExtension(NAME, (exporter) => new KHR_materials_anisotropy(exporter));
60
+ GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_anisotropy(exporter));
61
61
  //# sourceMappingURL=KHR_materials_anisotropy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"KHR_materials_anisotropy.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_anisotropy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,yDAA2C;AAGrE,MAAM,IAAI,GAAG,0BAA0B,CAAC;AAExC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,wBAAwB;IAcjC,YAAY,QAAmB;QAb/B,6BAA6B;QACb,SAAI,GAAG,IAAI,CAAC;QAE5B,gDAAgD;QACzC,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,KAAK,CAAC;QAIhB,aAAQ,GAAG,KAAK,CAAC;QAGrB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAEM,OAAO,KAAI,CAAC;IAEnB,gBAAgB;IAChB,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAEM,oCAAoC,CAAE,OAAe,EAAE,IAAe,EAAE,eAAyB;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C;gBAEF,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;YAC3C,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsAnisotropy } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\n\r\nconst NAME = \"KHR_materials_anisotropy\";\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_anisotropy implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: _Exporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: _Exporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] {\r\n const additionalTextures: BaseTexture[] = [];\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (babylonMaterial.anisotropy.isEnabled && !babylonMaterial.anisotropy.legacy) {\r\n if (babylonMaterial.anisotropy.texture) {\r\n additionalTextures.push(babylonMaterial.anisotropy.texture);\r\n }\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (!babylonMaterial.anisotropy.isEnabled || babylonMaterial.anisotropy.legacy) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n const anisotropyTextureInfo = this._exporter._glTFMaterialExporter._getTextureInfo(babylonMaterial.anisotropy.texture);\r\n\r\n const anisotropyInfo: IKHRMaterialsAnisotropy = {\r\n anisotropyStrength: babylonMaterial.anisotropy.intensity,\r\n anisotropyRotation: babylonMaterial.anisotropy.angle,\r\n anisotropyTexture: anisotropyTextureInfo ?? undefined,\r\n hasTextures: () => {\r\n return anisotropyInfo.anisotropyTexture !== null;\r\n },\r\n };\r\n\r\n node.extensions[NAME] = anisotropyInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_materials_anisotropy(exporter));\r\n"]}
1
+ {"version":3,"file":"KHR_materials_anisotropy.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_anisotropy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,yDAA2C;AAGrE,MAAM,IAAI,GAAG,0BAA0B,CAAC;AAExC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,wBAAwB;IAcjC,YAAY,QAAsB;QAblC,6BAA6B;QACb,SAAI,GAAG,IAAI,CAAC;QAE5B,gDAAgD;QACzC,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,KAAK,CAAC;QAIhB,aAAQ,GAAG,KAAK,CAAC;QAGrB,IAAI,CAAC,SAAS,GAAG,QAAQ,C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e,CAAC,UAAU,CAAC,KAAK;oBACpD,iBAAiB,EAAE,qBAAqB,IAAI,SAAS;iBACxD,CAAC;gBAEF,IAAI,cAAc,CAAC,iBAAiB,KAAK,IAAI,EAAE,CAAC;oBAC5C,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;gBAC7D,CAAC;gBAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;YAC3C,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsAnisotropy } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\n\r\nconst NAME = \"KHR_materials_anisotropy\";\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_anisotropy implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: GLTFExporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: GLTFExporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] {\r\n const additionalTextures: BaseTexture[] = [];\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (babylonMaterial.anisotropy.isEnabled && !babylonMaterial.anisotropy.legacy) {\r\n if (babylonMaterial.anisotropy.texture) {\r\n additionalTextures.push(babylonMaterial.anisotropy.texture);\r\n }\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return [];\r\n }\r\n\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (!babylonMaterial.anisotropy.isEnabled || babylonMaterial.anisotropy.legacy) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n const anisotropyTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.anisotropy.texture);\r\n\r\n const anisotropyInfo: IKHRMaterialsAnisotropy = {\r\n anisotropyStrength: babylonMaterial.anisotropy.intensity,\r\n anisotropyRotation: babylonMaterial.anisotropy.angle,\r\n anisotropyTexture: anisotropyTextureInfo ?? undefined,\r\n };\r\n\r\n if (anisotropyInfo.anisotropyTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = anisotropyInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_anisotropy(exporter));\r\n"]}