babylonjs-serializers 5.8.0 → 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.
@@ -286,6 +286,155 @@ function __classPrivateFieldSet(receiver, state, value, kind, f) {
286
286
  }
287
287
 
288
288
 
289
+ /***/ }),
290
+
291
+ /***/ "../../../lts/serializers/dist/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js":
292
+ /*!************************************************************************************!*\
293
+ !*** ../../../lts/serializers/dist/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js ***!
294
+ \************************************************************************************/
295
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
296
+
297
+ __webpack_require__.r(__webpack_exports__);
298
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
299
+ /* harmony export */ "EXT_mesh_gpu_instancing": () => (/* binding */ EXT_mesh_gpu_instancing)
300
+ /* harmony export */ });
301
+ /* harmony import */ var _glTFExporter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../glTFExporter */ "../../../lts/serializers/dist/glTF/2.0/glTFExporter.js");
302
+ /* harmony import */ var core_Meshes__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! core/Buffers/buffer */ "core/Maths/math.vector");
303
+ /* harmony import */ var core_Meshes__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(core_Meshes__WEBPACK_IMPORTED_MODULE_1__);
304
+
305
+
306
+
307
+
308
+ var NAME = "EXT_mesh_gpu_instancing";
309
+ /**
310
+ * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_mesh_gpu_instancing/README.md)
311
+ */
312
+ // eslint-disable-next-line @typescript-eslint/naming-convention
313
+ var EXT_mesh_gpu_instancing = /** @class */ (function () {
314
+ function EXT_mesh_gpu_instancing(exporter) {
315
+ /** Name of this extension */
316
+ this.name = NAME;
317
+ /** Defines whether this extension is enabled */
318
+ this.enabled = true;
319
+ /** Defines whether this extension is required */
320
+ this.required = false;
321
+ this._wasUsed = false;
322
+ this._exporter = exporter;
323
+ }
324
+ EXT_mesh_gpu_instancing.prototype.dispose = function () { };
325
+ Object.defineProperty(EXT_mesh_gpu_instancing.prototype, "wasUsed", {
326
+ /** @hidden */
327
+ get: function () {
328
+ return this._wasUsed;
329
+ },
330
+ enumerable: false,
331
+ configurable: true
332
+ });
333
+ EXT_mesh_gpu_instancing.prototype.postExportNodeAsync = function (context, node, babylonNode, nodeMap, binaryWriter) {
334
+ var _this = this;
335
+ return new Promise(function (resolve) {
336
+ if (node && babylonNode instanceof core_Meshes__WEBPACK_IMPORTED_MODULE_1__.Mesh) {
337
+ if (babylonNode.hasThinInstances && binaryWriter) {
338
+ _this._wasUsed = true;
339
+ var noTranslation = core_Meshes__WEBPACK_IMPORTED_MODULE_1__.Vector3.Zero();
340
+ var noRotation = core_Meshes__WEBPACK_IMPORTED_MODULE_1__.Quaternion.Identity();
341
+ var noScale = core_Meshes__WEBPACK_IMPORTED_MODULE_1__.Vector3.One();
342
+ // retreive all the instance world matrix
343
+ var matrix = babylonNode.thinInstanceGetWorldMatrices();
344
+ var iwt = core_Meshes__WEBPACK_IMPORTED_MODULE_1__.TmpVectors.Vector3[2];
345
+ var iwr = core_Meshes__WEBPACK_IMPORTED_MODULE_1__.TmpVectors.Quaternion[1];
346
+ var iws = core_Meshes__WEBPACK_IMPORTED_MODULE_1__.TmpVectors.Vector3[3];
347
+ var hasAnyInstanceWorldTranslation = false;
348
+ var hasAnyInstanceWorldRotation = false;
349
+ var hasAnyInstanceWorldScale = false;
350
+ // prepare temp buffers
351
+ var translationBuffer = new Float32Array(babylonNode.thinInstanceCount * 3);
352
+ var rotationBuffer = new Float32Array(babylonNode.thinInstanceCount * 4);
353
+ var scaleBuffer = new Float32Array(babylonNode.thinInstanceCount * 3);
354
+ var i = 0;
355
+ for (var _i = 0, matrix_1 = matrix; _i < matrix_1.length; _i++) {
356
+ var m = matrix_1[_i];
357
+ m.decompose(iws, iwr, iwt);
358
+ // fill the temp buffer
359
+ translationBuffer.set(iwt.asArray(), i * 3);
360
+ rotationBuffer.set(iwr.normalize().asArray(), i * 4); // ensure the quaternion is normalized
361
+ scaleBuffer.set(iws.asArray(), i * 3);
362
+ // this is where we decide if there is any transformation
363
+ hasAnyInstanceWorldTranslation = hasAnyInstanceWorldTranslation || !iwt.equalsWithEpsilon(noTranslation);
364
+ hasAnyInstanceWorldRotation = hasAnyInstanceWorldRotation || !iwr.equalsWithEpsilon(noRotation);
365
+ hasAnyInstanceWorldScale = hasAnyInstanceWorldScale || !iws.equalsWithEpsilon(noScale);
366
+ i++;
367
+ }
368
+ var extension = {
369
+ attributes: {},
370
+ };
371
+ // do we need to write TRANSLATION ?
372
+ if (hasAnyInstanceWorldTranslation) {
373
+ extension.attributes["TRANSLATION"] = _this._buildAccessor(translationBuffer, "VEC3" /* VEC3 */, babylonNode.thinInstanceCount, binaryWriter, 5126 /* FLOAT */);
374
+ }
375
+ // do we need to write ROTATION ?
376
+ if (hasAnyInstanceWorldRotation) {
377
+ var componentType = 5126 /* FLOAT */; // we decided to stay on FLOAT for now see https://github.com/BabylonJS/Babylon.js/pull/12495
378
+ extension.attributes["ROTATION"] = _this._buildAccessor(rotationBuffer, "VEC4" /* VEC4 */, babylonNode.thinInstanceCount, binaryWriter, componentType);
379
+ }
380
+ // do we need to write SCALE ?
381
+ if (hasAnyInstanceWorldScale) {
382
+ extension.attributes["SCALE"] = _this._buildAccessor(scaleBuffer, "VEC3" /* VEC3 */, babylonNode.thinInstanceCount, binaryWriter, 5126 /* FLOAT */);
383
+ }
384
+ /* eslint-enable @typescript-eslint/naming-convention*/
385
+ node.extensions = node.extensions || {};
386
+ node.extensions[NAME] = extension;
387
+ }
388
+ }
389
+ resolve(node);
390
+ });
391
+ };
392
+ EXT_mesh_gpu_instancing.prototype._buildAccessor = function (buffer, type, count, binaryWriter, componentType) {
393
+ // write the buffer
394
+ var bufferOffset = binaryWriter.getByteOffset();
395
+ switch (componentType) {
396
+ case 5126 /* FLOAT */: {
397
+ for (var i = 0; i != buffer.length; i++) {
398
+ binaryWriter.setFloat32(buffer[i]);
399
+ }
400
+ break;
401
+ }
402
+ case 5120 /* BYTE */: {
403
+ for (var i = 0; i != buffer.length; i++) {
404
+ binaryWriter.setByte(buffer[i] * 127);
405
+ }
406
+ break;
407
+ }
408
+ case 5122 /* SHORT */: {
409
+ for (var i = 0; i != buffer.length; i++) {
410
+ binaryWriter.setInt16(buffer[i] * 32767);
411
+ }
412
+ break;
413
+ }
414
+ }
415
+ // build the buffer view
416
+ var bv = { buffer: 0, byteOffset: bufferOffset, byteLength: buffer.length * core_Meshes__WEBPACK_IMPORTED_MODULE_1__.VertexBuffer.GetTypeByteLength(componentType) };
417
+ var bufferViewIndex = this._exporter._bufferViews.length;
418
+ this._exporter._bufferViews.push(bv);
419
+ // finally build the accessor
420
+ var accessorIndex = this._exporter._accessors.length;
421
+ var accessor = {
422
+ bufferView: bufferViewIndex,
423
+ componentType: componentType,
424
+ count: count,
425
+ type: type,
426
+ normalized: componentType == 5120 /* BYTE */ || componentType == 5122 /* SHORT */,
427
+ };
428
+ this._exporter._accessors.push(accessor);
429
+ return accessorIndex;
430
+ };
431
+ return EXT_mesh_gpu_instancing;
432
+ }());
433
+
434
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
435
+ _glTFExporter__WEBPACK_IMPORTED_MODULE_0__._Exporter.RegisterExtension(NAME, function (exporter) { return new EXT_mesh_gpu_instancing(exporter); });
436
+
437
+
289
438
  /***/ }),
290
439
 
291
440
  /***/ "../../../lts/serializers/dist/glTF/2.0/Extensions/KHR_lights_punctual.js":
@@ -1383,6 +1532,7 @@ _glTFExporter__WEBPACK_IMPORTED_MODULE_1__._Exporter.RegisterExtension(NAME, fun
1383
1532
 
1384
1533
  __webpack_require__.r(__webpack_exports__);
1385
1534
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1535
+ /* harmony export */ "EXT_mesh_gpu_instancing": () => (/* reexport safe */ _EXT_mesh_gpu_instancing__WEBPACK_IMPORTED_MODULE_10__.EXT_mesh_gpu_instancing),
1386
1536
  /* harmony export */ "KHR_lights_punctual": () => (/* reexport safe */ _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_1__.KHR_lights_punctual),
1387
1537
  /* harmony export */ "KHR_materials_clearcoat": () => (/* reexport safe */ _KHR_materials_clearcoat__WEBPACK_IMPORTED_MODULE_2__.KHR_materials_clearcoat),
1388
1538
  /* harmony export */ "KHR_materials_ior": () => (/* reexport safe */ _KHR_materials_ior__WEBPACK_IMPORTED_MODULE_6__.KHR_materials_ior),
@@ -1404,6 +1554,8 @@ __webpack_require__.r(__webpack_exports__);
1404
1554
  /* harmony import */ var _KHR_materials_specular__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./KHR_materials_specular */ "../../../lts/serializers/dist/glTF/2.0/Extensions/KHR_materials_specular.js");
1405
1555
  /* harmony import */ var _KHR_materials_volume__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./KHR_materials_volume */ "../../../lts/serializers/dist/glTF/2.0/Extensions/KHR_materials_volume.js");
1406
1556
  /* harmony import */ var _KHR_materials_transmission__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./KHR_materials_transmission */ "../../../lts/serializers/dist/glTF/2.0/Extensions/KHR_materials_transmission.js");
1557
+ /* harmony import */ var _EXT_mesh_gpu_instancing__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./EXT_mesh_gpu_instancing */ "../../../lts/serializers/dist/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js");
1558
+
1407
1559
 
1408
1560
 
1409
1561
 
@@ -2460,8 +2612,8 @@ var _Exporter = /** @class */ (function () {
2460
2612
  _Exporter.prototype._extensionsPostExportMeshPrimitiveAsync = function (context, meshPrimitive, babylonSubMesh, binaryWriter) {
2461
2613
  return this._applyExtensions(meshPrimitive, function (extension, node) { return extension.postExportMeshPrimitiveAsync && extension.postExportMeshPrimitiveAsync(context, node, babylonSubMesh, binaryWriter); });
2462
2614
  };
2463
- _Exporter.prototype._extensionsPostExportNodeAsync = function (context, node, babylonNode, nodeMap) {
2464
- return this._applyExtensions(node, function (extension, node) { return extension.postExportNodeAsync && extension.postExportNodeAsync(context, node, babylonNode, nodeMap); });
2615
+ _Exporter.prototype._extensionsPostExportNodeAsync = function (context, node, babylonNode, nodeMap, binaryWriter) {
2616
+ return this._applyExtensions(node, function (extension, node) { return extension.postExportNodeAsync && extension.postExportNodeAsync(context, node, babylonNode, nodeMap, binaryWriter); });
2465
2617
  };
2466
2618
  _Exporter.prototype._extensionsPostExportMaterialAsync = function (context, material, babylonMaterial) {
2467
2619
  return this._applyExtensions(material, function (extension, node) { return extension.postExportMaterialAsync && extension.postExportMaterialAsync(context, node, babylonMaterial); });
@@ -2538,6 +2690,13 @@ var _Exporter = /** @class */ (function () {
2538
2690
  extension.dispose();
2539
2691
  }
2540
2692
  };
2693
+ Object.defineProperty(_Exporter.prototype, "options", {
2694
+ get: function () {
2695
+ return this._options;
2696
+ },
2697
+ enumerable: false,
2698
+ configurable: true
2699
+ });
2541
2700
  /**
2542
2701
  * Registers a glTF exporter extension
2543
2702
  * @param name Name of the extension to export
@@ -3997,7 +4156,7 @@ var _Exporter = /** @class */ (function () {
3997
4156
  promiseChain = promiseChain.then(function () {
3998
4157
  var convertToRightHandedSystem = _this._convertToRightHandedSystemMap[babylonNode.uniqueId];
3999
4158
  return _this._createNodeAsync(babylonNode, binaryWriter, convertToRightHandedSystem).then(function (node) {
4000
- var promise = _this._extensionsPostExportNodeAsync("createNodeAsync", node, babylonNode, nodeMap);
4159
+ var promise = _this._extensionsPostExportNodeAsync("createNodeAsync", node, babylonNode, nodeMap, binaryWriter);
4001
4160
  if (promise == null) {
4002
4161
  core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Tools.Warn("Not exporting node ".concat(babylonNode.name));
4003
4162
  return Promise.resolve();
@@ -4346,6 +4505,50 @@ var _BinaryWriter = /** @class */ (function () {
4346
4505
  this._byteOffset += 4;
4347
4506
  }
4348
4507
  };
4508
+ /**
4509
+ * Stores an Int16 in the array buffer
4510
+ * @param entry
4511
+ * @param byteOffset If defined, specifies where to set the value as an offset.
4512
+ */
4513
+ _BinaryWriter.prototype.setInt16 = function (entry, byteOffset) {
4514
+ if (byteOffset != null) {
4515
+ if (byteOffset < this._byteOffset) {
4516
+ this._dataView.setInt16(byteOffset, entry, true);
4517
+ }
4518
+ else {
4519
+ core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
4520
+ }
4521
+ }
4522
+ else {
4523
+ if (this._byteOffset + 2 > this._arrayBuffer.byteLength) {
4524
+ this._resizeBuffer(this._arrayBuffer.byteLength * 2);
4525
+ }
4526
+ this._dataView.setInt16(this._byteOffset, entry, true);
4527
+ this._byteOffset += 2;
4528
+ }
4529
+ };
4530
+ /**
4531
+ * Stores a byte in the array buffer
4532
+ * @param entry
4533
+ * @param byteOffset If defined, specifies where to set the value as an offset.
4534
+ */
4535
+ _BinaryWriter.prototype.setByte = function (entry, byteOffset) {
4536
+ if (byteOffset != null) {
4537
+ if (byteOffset < this._byteOffset) {
4538
+ this._dataView.setInt8(byteOffset, entry);
4539
+ }
4540
+ else {
4541
+ core_Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__.Tools.Error("BinaryWriter: byteoffset is greater than the current binary buffer length!");
4542
+ }
4543
+ }
4544
+ else {
4545
+ if (this._byteOffset + 1 > this._arrayBuffer.byteLength) {
4546
+ this._resizeBuffer(this._arrayBuffer.byteLength * 2);
4547
+ }
4548
+ this._dataView.setInt8(this._byteOffset, entry);
4549
+ this._byteOffset++;
4550
+ }
4551
+ };
4349
4552
  return _BinaryWriter;
4350
4553
  }());
4351
4554
 
@@ -5722,6 +5925,7 @@ var _GLTFUtilities = /** @class */ (function () {
5722
5925
 
5723
5926
  __webpack_require__.r(__webpack_exports__);
5724
5927
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
5928
+ /* harmony export */ "EXT_mesh_gpu_instancing": () => (/* reexport safe */ _Extensions_index__WEBPACK_IMPORTED_MODULE_7__.EXT_mesh_gpu_instancing),
5725
5929
  /* harmony export */ "GLTF2Export": () => (/* reexport safe */ _glTFSerializer__WEBPACK_IMPORTED_MODULE_5__.GLTF2Export),
5726
5930
  /* harmony export */ "GLTFData": () => (/* reexport safe */ _glTFData__WEBPACK_IMPORTED_MODULE_1__.GLTFData),
5727
5931
  /* harmony export */ "KHR_lights_punctual": () => (/* reexport safe */ _Extensions_index__WEBPACK_IMPORTED_MODULE_7__.KHR_lights_punctual),
@@ -5811,6 +6015,7 @@ var __IGLTFExporterExtension = 0; // I am here to allow dts to be created
5811
6015
 
5812
6016
  __webpack_require__.r(__webpack_exports__);
5813
6017
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
6018
+ /* harmony export */ "EXT_mesh_gpu_instancing": () => (/* reexport safe */ _glTF_2_0_index__WEBPACK_IMPORTED_MODULE_4__.EXT_mesh_gpu_instancing),
5814
6019
  /* harmony export */ "GLTF2Export": () => (/* reexport safe */ _glTF_2_0_index__WEBPACK_IMPORTED_MODULE_4__.GLTF2Export),
5815
6020
  /* harmony export */ "GLTFData": () => (/* reexport safe */ _glTF_2_0_index__WEBPACK_IMPORTED_MODULE_4__.GLTFData),
5816
6021
  /* harmony export */ "KHR_lights_punctual": () => (/* reexport safe */ _glTF_2_0_index__WEBPACK_IMPORTED_MODULE_4__.KHR_lights_punctual),