babylonjs-serializers 5.8.0 → 5.9.0

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