@onerjs/serializers 8.29.3 → 8.29.5

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.
@@ -42,6 +42,7 @@ export declare class GLTFExporter {
42
42
  private readonly _extensions;
43
43
  readonly _bufferManager: BufferManager;
44
44
  private readonly _shouldExportNodeMap;
45
+ private readonly _shouldExportMaterialMap;
45
46
  private readonly _nodeMap;
46
47
  readonly _materialMap: Map<Material, number>;
47
48
  private readonly _camerasMap;
@@ -93,6 +94,7 @@ export declare class GLTFExporter {
93
94
  private _exportAndAssignSkeletons;
94
95
  private _exportSceneAsync;
95
96
  private _shouldExportNode;
97
+ private _shouldExportMaterial;
96
98
  private _exportNodesAsync;
97
99
  private _collectBuffers;
98
100
  private _exportBuffers;
@@ -275,6 +275,7 @@ export class GLTFExporter {
275
275
  this._extensions = {};
276
276
  this._bufferManager = new BufferManager();
277
277
  this._shouldExportNodeMap = new Map();
278
+ this._shouldExportMaterialMap = new Map();
278
279
  // Babylon node -> glTF node index
279
280
  this._nodeMap = new Map();
280
281
  // Babylon material -> glTF material index
@@ -292,6 +293,7 @@ export class GLTFExporter {
292
293
  this._options = {
293
294
  shouldExportNode: () => true,
294
295
  shouldExportAnimation: () => true,
296
+ shouldExportMaterial: () => true,
295
297
  metadataSelector: (metadata) => metadata?.gltf?.extras,
296
298
  animationSampleRate: 1 / 60,
297
299
  exportWithoutWaitingForScene: false,
@@ -722,6 +724,12 @@ export class GLTFExporter {
722
724
  }
723
725
  return result;
724
726
  }
727
+ _shouldExportMaterial(material) {
728
+ if (!this._shouldExportMaterialMap.has(material)) {
729
+ this._shouldExportMaterialMap.set(material, this._options.shouldExportMaterial(material));
730
+ }
731
+ return !!this._shouldExportMaterialMap.get(material);
732
+ }
725
733
  async _exportNodesAsync(babylonRootNodes, state) {
726
734
  const nodes = new Array();
727
735
  this._exportBuffers(babylonRootNodes, state);
@@ -1145,6 +1153,9 @@ export class GLTFExporter {
1145
1153
  if (materialIndex === undefined) {
1146
1154
  const hasUVs = vertexBuffers && Object.keys(vertexBuffers).some((kind) => kind.startsWith("uv"));
1147
1155
  babylonMaterial = babylonMaterial instanceof MultiMaterial ? babylonMaterial.subMaterials[subMesh.materialIndex] : babylonMaterial;
1156
+ if (!this._shouldExportMaterial(babylonMaterial)) {
1157
+ return;
1158
+ }
1148
1159
  if (babylonMaterial instanceof PBRBaseMaterial) {
1149
1160
  materialIndex = await this._materialExporter.exportPBRMaterialAsync(babylonMaterial, hasUVs);
1150
1161
  }