@babylonjs/serializers 5.0.0-alpha.60 → 5.0.0-alpha.64

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.
@@ -333,6 +333,13 @@ export declare class _Exporter {
333
333
  * @param binaryWriter Buffer to write binary data to
334
334
  */
335
335
  private createSceneAsync;
336
+ /**
337
+ * Getting the nodes and materials that would be exported.
338
+ * @param nodes Babylon transform nodes
339
+ * @returns Array of nodes which would be exported.
340
+ * @returns Set of materials which would be exported.
341
+ */
342
+ private getExportNodes;
336
343
  /**
337
344
  * Creates a mapping of Node unique id to node index and handles animations
338
345
  * @param babylonScene Babylon Scene
@@ -1,5 +1,5 @@
1
1
  import { __spreadArray } from "tslib";
2
- import { Vector2, Vector3, Vector4, Quaternion, Matrix } from "@babylonjs/core/Maths/math.vector.js";
2
+ import { Vector2, Vector3, Vector4, Quaternion } from "@babylonjs/core/Maths/math.vector.js";
3
3
  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";
@@ -12,7 +12,6 @@ import { _GLTFMaterialExporter } from "./glTFMaterialExporter.js";
12
12
  import { _GLTFUtilities } from "./glTFUtilities.js";
13
13
  import { GLTFData } from "./glTFData.js";
14
14
  import { _GLTFAnimation } from "./glTFAnimation.js";
15
- import { Epsilon } from '@babylonjs/core/Maths/math.constants.js';
16
15
  /**
17
16
  * Converts Babylon Scene into glTF 2.0.
18
17
  * @hidden
@@ -1272,7 +1271,7 @@ var _Exporter = /** @class */ (function () {
1272
1271
  var attribute = attributeData_2[_d];
1273
1272
  var attributeKind = attribute.kind;
1274
1273
  if ((attributeKind === VertexBuffer.UVKind || attributeKind === VertexBuffer.UV2Kind) && !this._options.exportUnusedUVs) {
1275
- if (glTFMaterial && !this._glTFMaterialExporter._hasTexturesPresent(glTFMaterial)) {
1274
+ if (!glTFMaterial || !this._glTFMaterialExporter._hasTexturesPresent(glTFMaterial)) {
1276
1275
  continue;
1277
1276
  }
1278
1277
  }
@@ -1360,13 +1359,8 @@ var _Exporter = /** @class */ (function () {
1360
1359
  }
1361
1360
  // Transform
1362
1361
  var matrix = node.getWorldMatrix();
1363
- var matrixToLeftHanded = Matrix.Compose(this._convertToRightHandedSystem ? new Vector3(-1, 1, 1) : Vector3.One(), Quaternion.Identity(), Vector3.Zero());
1364
- var matrixProduct = matrix.multiply(matrixToLeftHanded);
1365
- var matrixIdentity = Matrix.IdentityReadOnly;
1366
- for (var i = 0; i < 16; i++) {
1367
- if (Math.abs(matrixProduct.m[i] - matrixIdentity.m[i]) > Epsilon) {
1368
- return false;
1369
- }
1362
+ if (matrix.determinant() === 1) {
1363
+ return false;
1370
1364
  }
1371
1365
  // Geometry
1372
1366
  if ((node instanceof Mesh && node.geometry !== null) ||
@@ -1418,8 +1412,9 @@ var _Exporter = /** @class */ (function () {
1418
1412
  });
1419
1413
  }
1420
1414
  });
1421
- return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(babylonScene.materials, "image/png" /* PNG */, true).then(function () {
1422
- return _this.createNodeMapAndAnimationsAsync(babylonScene, nodes, binaryWriter).then(function (nodeMap) {
1415
+ var _a = this.getExportNodes(nodes), exportNodes = _a[0], exportMaterials = _a[1];
1416
+ return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(exportMaterials, "image/png" /* PNG */, true).then(function () {
1417
+ return _this.createNodeMapAndAnimationsAsync(babylonScene, exportNodes, binaryWriter).then(function (nodeMap) {
1423
1418
  return _this.createSkinsAsync(babylonScene, nodeMap, binaryWriter).then(function (skinMap) {
1424
1419
  _this._nodeMap = nodeMap;
1425
1420
  _this._totalByteLength = binaryWriter.getByteOffset();
@@ -1484,6 +1479,41 @@ var _Exporter = /** @class */ (function () {
1484
1479
  });
1485
1480
  });
1486
1481
  };
1482
+ /**
1483
+ * Getting the nodes and materials that would be exported.
1484
+ * @param nodes Babylon transform nodes
1485
+ * @returns Array of nodes which would be exported.
1486
+ * @returns Set of materials which would be exported.
1487
+ */
1488
+ _Exporter.prototype.getExportNodes = function (nodes) {
1489
+ var exportNodes = [];
1490
+ var exportMaterials = new Set();
1491
+ for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
1492
+ var babylonNode = nodes_2[_i];
1493
+ if (!this._options.shouldExportNode || this._options.shouldExportNode(babylonNode)) {
1494
+ exportNodes.push(babylonNode);
1495
+ if (babylonNode.getClassName() === "Mesh") {
1496
+ var mesh = babylonNode;
1497
+ if (mesh.material) {
1498
+ exportMaterials.add(mesh.material);
1499
+ }
1500
+ }
1501
+ else {
1502
+ var meshes = babylonNode.getChildMeshes(false);
1503
+ for (var _a = 0, meshes_1 = meshes; _a < meshes_1.length; _a++) {
1504
+ var mesh = meshes_1[_a];
1505
+ if (mesh.material) {
1506
+ exportMaterials.add(mesh.material);
1507
+ }
1508
+ }
1509
+ }
1510
+ }
1511
+ else {
1512
+ "Excluding node " + babylonNode.name;
1513
+ }
1514
+ }
1515
+ return [exportNodes, exportMaterials];
1516
+ };
1487
1517
  /**
1488
1518
  * Creates a mapping of Node unique id to node index and handles animations
1489
1519
  * @param babylonScene Babylon Scene
@@ -1503,41 +1533,35 @@ var _Exporter = /** @class */ (function () {
1503
1533
  };
1504
1534
  var idleGLTFAnimations = [];
1505
1535
  var _loop_1 = function (babylonNode) {
1506
- if (!this_1._options.shouldExportNode || this_1._options.shouldExportNode(babylonNode)) {
1507
- promiseChain = promiseChain.then(function () {
1508
- var convertToRightHandedSystem = _this._convertToRightHandedSystemMap[babylonNode.uniqueId];
1509
- return _this.createNodeAsync(babylonNode, binaryWriter, convertToRightHandedSystem, nodeMap).then(function (node) {
1510
- var promise = _this._extensionsPostExportNodeAsync("createNodeAsync", node, babylonNode, nodeMap);
1511
- if (promise == null) {
1512
- Tools.Warn("Not exporting node " + babylonNode.name);
1513
- return Promise.resolve();
1514
- }
1515
- else {
1516
- return promise.then(function (node) {
1517
- if (!node) {
1518
- return;
1519
- }
1520
- _this._nodes.push(node);
1521
- nodeIndex = _this._nodes.length - 1;
1522
- nodeMap[babylonNode.uniqueId] = nodeIndex;
1523
- if (!babylonScene.animationGroups.length) {
1524
- _GLTFAnimation._CreateMorphTargetAnimationFromMorphTargetAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, _this._nodes, binaryWriter, _this._bufferViews, _this._accessors, convertToRightHandedSystem, _this._animationSampleRate);
1525
- if (babylonNode.animations.length) {
1526
- _GLTFAnimation._CreateNodeAnimationFromNodeAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, _this._nodes, binaryWriter, _this._bufferViews, _this._accessors, convertToRightHandedSystem, _this._animationSampleRate);
1527
- }
1536
+ promiseChain = promiseChain.then(function () {
1537
+ var convertToRightHandedSystem = _this._convertToRightHandedSystemMap[babylonNode.uniqueId];
1538
+ return _this.createNodeAsync(babylonNode, binaryWriter, convertToRightHandedSystem, nodeMap).then(function (node) {
1539
+ var promise = _this._extensionsPostExportNodeAsync("createNodeAsync", node, babylonNode, nodeMap);
1540
+ if (promise == null) {
1541
+ Tools.Warn("Not exporting node " + babylonNode.name);
1542
+ return Promise.resolve();
1543
+ }
1544
+ else {
1545
+ return promise.then(function (node) {
1546
+ if (!node) {
1547
+ return;
1548
+ }
1549
+ _this._nodes.push(node);
1550
+ nodeIndex = _this._nodes.length - 1;
1551
+ nodeMap[babylonNode.uniqueId] = nodeIndex;
1552
+ if (!babylonScene.animationGroups.length) {
1553
+ _GLTFAnimation._CreateMorphTargetAnimationFromMorphTargetAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, _this._nodes, binaryWriter, _this._bufferViews, _this._accessors, convertToRightHandedSystem, _this._animationSampleRate);
1554
+ if (babylonNode.animations.length) {
1555
+ _GLTFAnimation._CreateNodeAnimationFromNodeAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, _this._nodes, binaryWriter, _this._bufferViews, _this._accessors, convertToRightHandedSystem, _this._animationSampleRate);
1528
1556
  }
1529
- });
1530
- }
1531
- });
1557
+ }
1558
+ });
1559
+ }
1532
1560
  });
1533
- }
1534
- else {
1535
- "Excluding node " + babylonNode.name;
1536
- }
1561
+ });
1537
1562
  };
1538
- var this_1 = this;
1539
- for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
1540
- var babylonNode = nodes_2[_i];
1563
+ for (var _i = 0, nodes_3 = nodes; _i < nodes_3.length; _i++) {
1564
+ var babylonNode = nodes_3[_i];
1541
1565
  _loop_1(babylonNode);
1542
1566
  }
1543
1567
  return promiseChain.then(function () {