@babylonjs/serializers 5.6.1 → 5.8.1

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.
@@ -0,0 +1,26 @@
1
+ import type { INode } from "babylonjs-gltf2interface";
2
+ import type { IGLTFExporterExtensionV2 } from "../glTFExporterExtension";
3
+ import { _Exporter, _BinaryWriter } from "../glTFExporter";
4
+ import type { Nullable } from "@babylonjs/core/types.js";
5
+ import type { Node } from "@babylonjs/core/node.js";
6
+ /**
7
+ * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_mesh_gpu_instancing/README.md)
8
+ */
9
+ export declare class EXT_mesh_gpu_instancing implements IGLTFExporterExtensionV2 {
10
+ /** Name of this extension */
11
+ readonly name = "EXT_mesh_gpu_instancing";
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
+ postExportNodeAsync?(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: {
23
+ [key: number]: number;
24
+ }, binaryWriter?: _BinaryWriter): Promise<Nullable<INode>>;
25
+ private _buildAccessor;
26
+ }
@@ -0,0 +1,133 @@
1
+ import { _Exporter } from "../glTFExporter.js";
2
+ import { Mesh } from "@babylonjs/core/Meshes.js";
3
+ import { TmpVectors, Quaternion, Vector3 } from "@babylonjs/core/Maths/math.vector.js";
4
+ import { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
5
+ var NAME = "EXT_mesh_gpu_instancing";
6
+ /**
7
+ * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_mesh_gpu_instancing/README.md)
8
+ */
9
+ // eslint-disable-next-line @typescript-eslint/naming-convention
10
+ var EXT_mesh_gpu_instancing = /** @class */ (function () {
11
+ function EXT_mesh_gpu_instancing(exporter) {
12
+ /** Name of this extension */
13
+ this.name = NAME;
14
+ /** Defines whether this extension is enabled */
15
+ this.enabled = true;
16
+ /** Defines whether this extension is required */
17
+ this.required = false;
18
+ this._wasUsed = false;
19
+ this._exporter = exporter;
20
+ }
21
+ EXT_mesh_gpu_instancing.prototype.dispose = function () { };
22
+ Object.defineProperty(EXT_mesh_gpu_instancing.prototype, "wasUsed", {
23
+ /** @hidden */
24
+ get: function () {
25
+ return this._wasUsed;
26
+ },
27
+ enumerable: false,
28
+ configurable: true
29
+ });
30
+ EXT_mesh_gpu_instancing.prototype.postExportNodeAsync = function (context, node, babylonNode, nodeMap, binaryWriter) {
31
+ var _this = this;
32
+ return new Promise(function (resolve) {
33
+ if (node && babylonNode instanceof Mesh) {
34
+ if (babylonNode.hasThinInstances && binaryWriter) {
35
+ _this._wasUsed = true;
36
+ var noTranslation = Vector3.Zero();
37
+ var noRotation = Quaternion.Identity();
38
+ var noScale = Vector3.One();
39
+ // retreive all the instance world matrix
40
+ var matrix = babylonNode.thinInstanceGetWorldMatrices();
41
+ var iwt = TmpVectors.Vector3[2];
42
+ var iwr = TmpVectors.Quaternion[1];
43
+ var iws = TmpVectors.Vector3[3];
44
+ var hasAnyInstanceWorldTranslation = false;
45
+ var hasAnyInstanceWorldRotation = false;
46
+ var hasAnyInstanceWorldScale = false;
47
+ // prepare temp buffers
48
+ var translationBuffer = new Float32Array(babylonNode.thinInstanceCount * 3);
49
+ var rotationBuffer = new Float32Array(babylonNode.thinInstanceCount * 4);
50
+ var scaleBuffer = new Float32Array(babylonNode.thinInstanceCount * 3);
51
+ var i = 0;
52
+ for (var _i = 0, matrix_1 = matrix; _i < matrix_1.length; _i++) {
53
+ var m = matrix_1[_i];
54
+ m.decompose(iws, iwr, iwt);
55
+ // fill the temp buffer
56
+ translationBuffer.set(iwt.asArray(), i * 3);
57
+ rotationBuffer.set(iwr.normalize().asArray(), i * 4); // ensure the quaternion is normalized
58
+ scaleBuffer.set(iws.asArray(), i * 3);
59
+ // this is where we decide if there is any transformation
60
+ hasAnyInstanceWorldTranslation = hasAnyInstanceWorldTranslation || !iwt.equalsWithEpsilon(noTranslation);
61
+ hasAnyInstanceWorldRotation = hasAnyInstanceWorldRotation || !iwr.equalsWithEpsilon(noRotation);
62
+ hasAnyInstanceWorldScale = hasAnyInstanceWorldScale || !iws.equalsWithEpsilon(noScale);
63
+ i++;
64
+ }
65
+ var extension = {
66
+ attributes: {},
67
+ };
68
+ // do we need to write TRANSLATION ?
69
+ if (hasAnyInstanceWorldTranslation) {
70
+ extension.attributes["TRANSLATION"] = _this._buildAccessor(translationBuffer, "VEC3" /* VEC3 */, babylonNode.thinInstanceCount, binaryWriter, 5126 /* FLOAT */);
71
+ }
72
+ // do we need to write ROTATION ?
73
+ if (hasAnyInstanceWorldRotation) {
74
+ var componentType = 5126 /* FLOAT */; // we decided to stay on FLOAT for now see https://github.com/BabylonJS/Babylon.js/pull/12495
75
+ extension.attributes["ROTATION"] = _this._buildAccessor(rotationBuffer, "VEC4" /* VEC4 */, babylonNode.thinInstanceCount, binaryWriter, componentType);
76
+ }
77
+ // do we need to write SCALE ?
78
+ if (hasAnyInstanceWorldScale) {
79
+ extension.attributes["SCALE"] = _this._buildAccessor(scaleBuffer, "VEC3" /* VEC3 */, babylonNode.thinInstanceCount, binaryWriter, 5126 /* FLOAT */);
80
+ }
81
+ /* eslint-enable @typescript-eslint/naming-convention*/
82
+ node.extensions = node.extensions || {};
83
+ node.extensions[NAME] = extension;
84
+ }
85
+ }
86
+ resolve(node);
87
+ });
88
+ };
89
+ EXT_mesh_gpu_instancing.prototype._buildAccessor = function (buffer, type, count, binaryWriter, componentType) {
90
+ // write the buffer
91
+ var bufferOffset = binaryWriter.getByteOffset();
92
+ switch (componentType) {
93
+ case 5126 /* FLOAT */: {
94
+ for (var i = 0; i != buffer.length; i++) {
95
+ binaryWriter.setFloat32(buffer[i]);
96
+ }
97
+ break;
98
+ }
99
+ case 5120 /* BYTE */: {
100
+ for (var i = 0; i != buffer.length; i++) {
101
+ binaryWriter.setByte(buffer[i] * 127);
102
+ }
103
+ break;
104
+ }
105
+ case 5122 /* SHORT */: {
106
+ for (var i = 0; i != buffer.length; i++) {
107
+ binaryWriter.setInt16(buffer[i] * 32767);
108
+ }
109
+ break;
110
+ }
111
+ }
112
+ // build the buffer view
113
+ var bv = { buffer: 0, byteOffset: bufferOffset, byteLength: buffer.length * VertexBuffer.GetTypeByteLength(componentType) };
114
+ var bufferViewIndex = this._exporter._bufferViews.length;
115
+ this._exporter._bufferViews.push(bv);
116
+ // finally build the accessor
117
+ var accessorIndex = this._exporter._accessors.length;
118
+ var accessor = {
119
+ bufferView: bufferViewIndex,
120
+ componentType: componentType,
121
+ count: count,
122
+ type: type,
123
+ normalized: componentType == 5120 /* BYTE */ || componentType == 5122 /* SHORT */,
124
+ };
125
+ this._exporter._accessors.push(accessor);
126
+ return accessorIndex;
127
+ };
128
+ return EXT_mesh_gpu_instancing;
129
+ }());
130
+ export { EXT_mesh_gpu_instancing };
131
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
132
+ _Exporter.RegisterExtension(NAME, function (exporter) { return new EXT_mesh_gpu_instancing(exporter); });
133
+ //# sourceMappingURL=EXT_mesh_gpu_instancing.js.map
@@ -0,0 +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,kCAAoB;AACnC,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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,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\";\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"]}
@@ -8,3 +8,4 @@ export * from "./KHR_materials_ior";
8
8
  export * from "./KHR_materials_specular";
9
9
  export * from "./KHR_materials_volume";
10
10
  export * from "./KHR_materials_transmission";
11
+ export * from "./EXT_mesh_gpu_instancing";
@@ -8,4 +8,5 @@ export * from "./KHR_materials_ior.js";
8
8
  export * from "./KHR_materials_specular.js";
9
9
  export * from "./KHR_materials_volume.js";
10
10
  export * from "./KHR_materials_transmission.js";
11
+ export * from "./EXT_mesh_gpu_instancing.js";
11
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../lts/serializers/generated/glTF/2.0/Extensions/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC","sourcesContent":["export * from \"./KHR_texture_transform\";\r\nexport * from \"./KHR_lights_punctual\";\r\nexport * from \"./KHR_materials_clearcoat\";\r\nexport * from \"./KHR_materials_iridescence\";\r\nexport * from \"./KHR_materials_sheen\";\r\nexport * from \"./KHR_materials_unlit\";\r\nexport * from \"./KHR_materials_ior\";\r\nexport * from \"./KHR_materials_specular\";\r\nexport * from \"./KHR_materials_volume\";\r\nexport * from \"./KHR_materials_transmission\";\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../lts/serializers/generated/glTF/2.0/Extensions/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC","sourcesContent":["export * from \"./KHR_texture_transform\";\r\nexport * from \"./KHR_lights_punctual\";\r\nexport * from \"./KHR_materials_clearcoat\";\r\nexport * from \"./KHR_materials_iridescence\";\r\nexport * from \"./KHR_materials_sheen\";\r\nexport * from \"./KHR_materials_unlit\";\r\nexport * from \"./KHR_materials_ior\";\r\nexport * from \"./KHR_materials_specular\";\r\nexport * from \"./KHR_materials_volume\";\r\nexport * from \"./KHR_materials_transmission\";\r\nexport * from \"./EXT_mesh_gpu_instancing\";\r\n"]}
@@ -132,7 +132,7 @@ export declare class _Exporter {
132
132
  _extensionsPostExportMeshPrimitiveAsync(context: string, meshPrimitive: IMeshPrimitive, babylonSubMesh: SubMesh, binaryWriter: _BinaryWriter): Promise<Nullable<IMeshPrimitive>>;
133
133
  _extensionsPostExportNodeAsync(context: string, node: Nullable<INode>, babylonNode: Node, nodeMap?: {
134
134
  [key: number]: number;
135
- }): Promise<Nullable<INode>>;
135
+ }, binaryWriter?: _BinaryWriter): Promise<Nullable<INode>>;
136
136
  _extensionsPostExportMaterialAsync(context: string, material: Nullable<IMaterial>, babylonMaterial: Material): Promise<Nullable<IMaterial>>;
137
137
  _extensionsPostExportMaterialAdditionalTextures(context: string, material: IMaterial, babylonMaterial: Material): BaseTexture[];
138
138
  _extensionsPostExportTextures(context: string, textureInfo: ITextureInfo, babylonTexture: BaseTexture): void;
@@ -149,6 +149,7 @@ export declare class _Exporter {
149
149
  */
150
150
  constructor(babylonScene?: Nullable<Scene>, options?: IExportOptions);
151
151
  dispose(): void;
152
+ get options(): IExportOptions;
152
153
  /**
153
154
  * Registers a glTF exporter extension
154
155
  * @param name Name of the extension to export
@@ -453,4 +454,16 @@ export declare class _BinaryWriter {
453
454
  * @param byteOffset If defined, specifies where to set the value as an offset.
454
455
  */
455
456
  setUInt32(entry: number, byteOffset?: number): void;
457
+ /**
458
+ * Stores an Int16 in the array buffer
459
+ * @param entry
460
+ * @param byteOffset If defined, specifies where to set the value as an offset.
461
+ */
462
+ setInt16(entry: number, byteOffset?: number): void;
463
+ /**
464
+ * Stores a byte in the array buffer
465
+ * @param entry
466
+ * @param byteOffset If defined, specifies where to set the value as an offset.
467
+ */
468
+ setByte(entry: number, byteOffset?: number): void;
456
469
  }
@@ -87,8 +87,8 @@ var _Exporter = /** @class */ (function () {
87
87
  _Exporter.prototype._extensionsPostExportMeshPrimitiveAsync = function (context, meshPrimitive, babylonSubMesh, binaryWriter) {
88
88
  return this._applyExtensions(meshPrimitive, function (extension, node) { return extension.postExportMeshPrimitiveAsync && extension.postExportMeshPrimitiveAsync(context, node, babylonSubMesh, binaryWriter); });
89
89
  };
90
- _Exporter.prototype._extensionsPostExportNodeAsync = function (context, node, babylonNode, nodeMap) {
91
- return this._applyExtensions(node, function (extension, node) { return extension.postExportNodeAsync && extension.postExportNodeAsync(context, node, babylonNode, nodeMap); });
90
+ _Exporter.prototype._extensionsPostExportNodeAsync = function (context, node, babylonNode, nodeMap, binaryWriter) {
91
+ return this._applyExtensions(node, function (extension, node) { return extension.postExportNodeAsync && extension.postExportNodeAsync(context, node, babylonNode, nodeMap, binaryWriter); });
92
92
  };
93
93
  _Exporter.prototype._extensionsPostExportMaterialAsync = function (context, material, babylonMaterial) {
94
94
  return this._applyExtensions(material, function (extension, node) { return extension.postExportMaterialAsync && extension.postExportMaterialAsync(context, node, babylonMaterial); });
@@ -165,6 +165,13 @@ var _Exporter = /** @class */ (function () {
165
165
  extension.dispose();
166
166
  }
167
167
  };
168
+ Object.defineProperty(_Exporter.prototype, "options", {
169
+ get: function () {
170
+ return this._options;
171
+ },
172
+ enumerable: false,
173
+ configurable: true
174
+ });
168
175
  /**
169
176
  * Registers a glTF exporter extension
170
177
  * @param name Name of the extension to export
@@ -1624,7 +1631,7 @@ var _Exporter = /** @class */ (function () {
1624
1631
  promiseChain = promiseChain.then(function () {
1625
1632
  var convertToRightHandedSystem = _this._convertToRightHandedSystemMap[babylonNode.uniqueId];
1626
1633
  return _this._createNodeAsync(babylonNode, binaryWriter, convertToRightHandedSystem).then(function (node) {
1627
- var promise = _this._extensionsPostExportNodeAsync("createNodeAsync", node, babylonNode, nodeMap);
1634
+ var promise = _this._extensionsPostExportNodeAsync("createNodeAsync", node, babylonNode, nodeMap, binaryWriter);
1628
1635
  if (promise == null) {
1629
1636
  Tools.Warn("Not exporting node ".concat(babylonNode.name));
1630
1637
  return Promise.resolve();
@@ -1973,6 +1980,50 @@ var _BinaryWriter = /** @class */ (function () {
1973
1980
  this._byteOffset += 4;
1974
1981
  }
1975
1982
  };
1983
+ /**
1984
+ * Stores an Int16 in the array buffer
1985
+ * @param entry
1986
+ * @param byteOffset If defined, specifies where to set the value as an offset.
1987
+ */
1988
+ _BinaryWriter.prototype.setInt16 = function (entry, byteOffset) {
1989
+ if (byteOffset != null) {
1990
+ if (byteOffset < this._byteOffset) {
1991
+ this._dataView.setInt16(byteOffset, entry, true);
1992
+ }
1993
+ else {
1994
+ Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
1995
+ }
1996
+ }
1997
+ else {
1998
+ if (this._byteOffset + 2 > this._arrayBuffer.byteLength) {
1999
+ this._resizeBuffer(this._arrayBuffer.byteLength * 2);
2000
+ }
2001
+ this._dataView.setInt16(this._byteOffset, entry, true);
2002
+ this._byteOffset += 2;
2003
+ }
2004
+ };
2005
+ /**
2006
+ * Stores a byte in the array buffer
2007
+ * @param entry
2008
+ * @param byteOffset If defined, specifies where to set the value as an offset.
2009
+ */
2010
+ _BinaryWriter.prototype.setByte = function (entry, byteOffset) {
2011
+ if (byteOffset != null) {
2012
+ if (byteOffset < this._byteOffset) {
2013
+ this._dataView.setInt8(byteOffset, entry);
2014
+ }
2015
+ else {
2016
+ Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
2017
+ }
2018
+ }
2019
+ else {
2020
+ if (this._byteOffset + 1 > this._arrayBuffer.byteLength) {
2021
+ this._resizeBuffer(this._arrayBuffer.byteLength * 2);
2022
+ }
2023
+ this._dataView.setInt8(this._byteOffset, entry);
2024
+ this._byteOffset++;
2025
+ }
2026
+ };
1976
2027
  return _BinaryWriter;
1977
2028
  }());
1978
2029
  export { _BinaryWriter };