@babylonjs/serializers 5.12.1 → 5.13.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.
@@ -1,6 +1,7 @@
1
1
  import type { INode } from "babylonjs-gltf2interface";
2
2
  import type { IGLTFExporterExtensionV2 } from "../glTFExporterExtension";
3
- import { _Exporter, _BinaryWriter } from "../glTFExporter";
3
+ import type { _BinaryWriter } from "../glTFExporter";
4
+ import { _Exporter } from "../glTFExporter";
4
5
  import type { Nullable } from "@babylonjs/core/types.js";
5
6
  import type { Node } from "@babylonjs/core/node.js";
6
7
  import "@babylonjs/core/Meshes/thinInstanceMesh.js";
@@ -1 +1 @@
1
- {"version":3,"file":"EXT_mesh_gpu_instancing.js","sourceRoot":"","sources":["../../../../../../../lts/serializers/generated/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAiB,MAAM,iBAAiB,CAAC;AAG3D,OAAO,EAAE,IAAI,EAAE,uCAAyB;AACxC,oDAAsC;AACtC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,6CAA+B;AACzE,OAAO,EAAE,YAAY,EAAE,0CAA4B;AAEnD,IAAM,IAAI,GAAG,yBAAyB,CAAC;AAEvC;;GAEG;AACH,gEAAgE;AAChE;IAcI,iCAAY,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,yCAAO,GAAd,cAAkB,CAAC;IAGnB,sBAAW,4CAAO;QADlB,cAAc;aACd;YACI,OAAO,IAAI,CAAC,QAAQ,CAAC;QACzB,CAAC;;;OAAA;IAEM,qDAAmB,GAA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AC5C;gBAED,MAAM;aACT;SACJ;QACD,wBAAwB;QACxB,IAAM,EAAE,GAAgB,EAAE,MAAM,EAAE,CAAC,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,GAAG,YAAY,CAAC,iBAAiB,CAAC,aAAa,CAAC,EAAE,CAAC;QAC3I,IAAM,eAAe,GAAG,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,MAAM,CAAC;QAC3D,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAErC,6BAA6B;QAC7B,IAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC;QACvD,IAAM,QAAQ,GAAc;YACxB,UAAU,EAAE,eAAe;YAC3B,aAAa,EAAE,aAAa;YAC5B,KAAK,EAAE,KAAK;YACZ,IAAI,EAAE,IAAI;YACV,UAAU,EAAE,aAAa,mBAA8B,IAAI,aAAa,oBAA+B;SAC1G,CAAC;QACF,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzC,OAAO,aAAa,CAAC;IACzB,CAAC;IACL,8BAAC;AAAD,CAAC,AA1JD,IA0JC;;AAED,6DAA6D;AAC7D,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,QAAQ,IAAK,OAAA,IAAI,uBAAuB,CAAC,QAAQ,CAAC,EAArC,CAAqC,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 { _Exporter, _BinaryWriter } 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 /** @hidden */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\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 // retreive 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":["../../../../../../../lts/serializers/generated/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,IAAI,EAAE,uCAAyB;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SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzC,OAAO,aAAa,CAAC;IACzB,CAAC;IACL,8BAAC;AAAD,CAAC,AA1JD,IA0JC;;AAED,6DAA6D;AAC7D,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,QAAQ,IAAK,OAAA,IAAI,uBAAuB,CAAC,QAAQ,CAAC,EAArC,CAAqC,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 /** @hidden */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\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 // retreive 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"]}
@@ -4,7 +4,6 @@ import { Color3, Color4 } from "@babylonjs/core/Maths/math.color.js";
4
4
  import { Tools } from "@babylonjs/core/Misc/tools.js";
5
5
  import { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
6
6
  import { TransformNode } from "@babylonjs/core/Meshes/transformNode.js";
7
- import { AbstractMesh } from "@babylonjs/core/Meshes/abstractMesh.js";
8
7
  import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
9
8
  import { LinesMesh } from "@babylonjs/core/Meshes/linesMesh.js";
10
9
  import { InstancedMesh } from "@babylonjs/core/Meshes/instancedMesh.js";
@@ -1013,8 +1012,8 @@ var _Exporter = /** @class */ (function () {
1013
1012
  if (!babylonCamera.position.equalsToFloats(0, 0, 0)) {
1014
1013
  node.translation = convertToRightHandedSystem ? _GLTFUtilities._GetRightHandedPositionVector3(babylonCamera.position).asArray() : babylonCamera.position.asArray();
1015
1014
  }
1016
- var rotationQuaternion = babylonCamera.absoluteRotation;
1017
- if (!Quaternion.IsIdentity(rotationQuaternion)) {
1015
+ var rotationQuaternion = babylonCamera.rotationQuaternion; // we target the local transformation if one.
1016
+ if (rotationQuaternion && !Quaternion.IsIdentity(rotationQuaternion)) {
1018
1017
  if (convertToRightHandedSystem) {
1019
1018
  _GLTFUtilities._GetRightHandedQuaternionFromRef(rotationQuaternion);
1020
1019
  }
@@ -1588,8 +1587,9 @@ var _Exporter = /** @class */ (function () {
1588
1587
  var babylonNode = nodes_2[_i];
1589
1588
  if (!this._options.shouldExportNode || this._options.shouldExportNode(babylonNode)) {
1590
1589
  exportNodes.push(babylonNode);
1591
- if (babylonNode instanceof AbstractMesh) {
1592
- var material = babylonNode.material || babylonNode.getScene().defaultMaterial;
1590
+ var babylonMesh = babylonNode;
1591
+ if (babylonMesh.subMeshes && babylonMesh.subMeshes.length > 0) {
1592
+ var material = babylonMesh.material || babylonMesh.getScene().defaultMaterial;
1593
1593
  if (material instanceof MultiMaterial) {
1594
1594
  for (var _a = 0, _b = material.subMaterials; _a < _b.length; _a++) {
1595
1595
  var subMaterial = _b[_a];