minerender 2.1.0-alpha.66 → 2.1.0-alpha.68

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.
@@ -4036,6 +4036,7 @@ var init_SceneObject = __esm({
4036
4036
  dispose() {
4037
4037
  this.disposeAndRemoveAllChildren();
4038
4038
  this.notifyDirty();
4039
+ super.dispose();
4039
4040
  }
4040
4041
  disposeAndRemoveAllChildren() {
4041
4042
  if (this.instanceMesh) {
@@ -4249,6 +4250,7 @@ var init_EntityObject = __esm({
4249
4250
  else matrix.makeRotationFromEuler(new import_three14.Euler(...op.rotate, "ZYX"));
4250
4251
  modelRoot.matrix.multiply(matrix);
4251
4252
  }
4253
+ modelRoot.matrixWorldNeedsUpdate = true;
4252
4254
  modelRoot.matrixAutoUpdate = false;
4253
4255
  } else if (this.options.flip ?? true) {
4254
4256
  modelRoot.scale.set(-1, -1, 1);
@@ -5156,6 +5158,7 @@ var init_ModelObject = __esm({
5156
5158
  for (const part of parts) {
5157
5159
  const object = new EntityObject(part.model, { flip: false, wireframe: this.options.wireframe });
5158
5160
  object.matrix.copy(transform).multiply(part.transform);
5161
+ object.matrixWorldNeedsUpdate = true;
5159
5162
  object.matrixAutoUpdate = false;
5160
5163
  this.add(object);
5161
5164
  await object.init();
@@ -5689,6 +5692,7 @@ __export(index_node_exports, {
5689
5692
  computeTangents: () => computeTangents,
5690
5693
  createCanvas: () => createCanvas2,
5691
5694
  createFluidGeometry: () => createFluidGeometry,
5695
+ createGuiTextureGeometry: () => createGuiTextureGeometry,
5692
5696
  createImage: () => createImage,
5693
5697
  entityAnimationTime: () => entityAnimationTime,
5694
5698
  estimateBytesUsed: () => estimateBytesUsed,
@@ -6004,11 +6008,19 @@ init_EntityObject();
6004
6008
  init_MineRenderError();
6005
6009
 
6006
6010
  // src/export/SceneExporter.ts
6007
- var import_three20 = require("three");
6011
+ var import_three19 = require("three");
6008
6012
 
6009
6013
  // ../../node_modules/three/examples/jsm/exporters/OBJExporter.js
6010
6014
  var import_three16 = require("three");
6011
6015
  var OBJExporter = class {
6016
+ /**
6017
+ * Parses the given 3D object and generates the OBJ output.
6018
+ *
6019
+ * If the 3D object is composed of multiple children and geometry, they are merged into a single mesh in the file.
6020
+ *
6021
+ * @param {Object3D} object - The 3D object to export.
6022
+ * @return {string} The exported OBJ.
6023
+ */
6012
6024
  parse(object) {
6013
6025
  let output = "";
6014
6026
  let indexVertex = 0;
@@ -6114,7 +6126,8 @@ var OBJExporter = class {
6114
6126
  vertex.applyMatrix4(points.matrixWorld);
6115
6127
  output += "v " + vertex.x + " " + vertex.y + " " + vertex.z;
6116
6128
  if (colors !== void 0) {
6117
- color.fromBufferAttribute(colors, i).convertLinearToSRGB();
6129
+ color.fromBufferAttribute(colors, i);
6130
+ import_three16.ColorManagement.workingToColorSpace(color, import_three16.SRGBColorSpace);
6118
6131
  output += " " + color.r + " " + color.g + " " + color.b;
6119
6132
  }
6120
6133
  output += "\n";
@@ -6145,6 +6158,16 @@ var OBJExporter = class {
6145
6158
  // ../../node_modules/three/examples/jsm/exporters/PLYExporter.js
6146
6159
  var import_three17 = require("three");
6147
6160
  var PLYExporter = class {
6161
+ /**
6162
+ * Parses the given 3D object and generates the PLY output.
6163
+ *
6164
+ * If the 3D object is composed of multiple children and geometry, they are merged into a single mesh in the file.
6165
+ *
6166
+ * @param {Object3D} object - The 3D object to export.
6167
+ * @param {PLYExporter~OnDone} onDone - A callback function that is executed when the export has finished.
6168
+ * @param {PLYExporter~Options} options - The export options.
6169
+ * @return {?(string|ArrayBuffer)} The exported PLY.
6170
+ */
6148
6171
  parse(object, onDone, options = {}) {
6149
6172
  function traverseMeshes(cb) {
6150
6173
  object.traverse(function(child) {
@@ -6161,14 +6184,23 @@ var PLYExporter = class {
6161
6184
  binary: false,
6162
6185
  excludeAttributes: [],
6163
6186
  // normal, uv, color, index
6164
- littleEndian: false
6187
+ littleEndian: false,
6188
+ customPropertyMapping: {}
6165
6189
  };
6166
6190
  options = Object.assign(defaultOptions, options);
6167
6191
  const excludeAttributes = options.excludeAttributes;
6192
+ const customPropertyMapping = options.customPropertyMapping;
6193
+ const customAttributeNames = Object.keys(customPropertyMapping);
6168
6194
  let includeIndices = true;
6169
6195
  let includeNormals = false;
6170
6196
  let includeColors = false;
6171
6197
  let includeUVs = false;
6198
+ let positionType = "float";
6199
+ let normalType = "float";
6200
+ let uvType = "float";
6201
+ let colorType = "uchar";
6202
+ const customTypes = {};
6203
+ for (const name of customAttributeNames) customTypes[name] = "float";
6172
6204
  let vertexCount = 0;
6173
6205
  let faceCount = 0;
6174
6206
  object.traverse(function(child) {
@@ -6185,9 +6217,23 @@ var PLYExporter = class {
6185
6217
  }
6186
6218
  vertexCount += vertices.count;
6187
6219
  faceCount += indices ? indices.count / 3 : vertices.count / 3;
6188
- if (normals !== void 0) includeNormals = true;
6189
- if (uvs !== void 0) includeUVs = true;
6190
- if (colors !== void 0) includeColors = true;
6220
+ positionType = getPlyType(vertices.array);
6221
+ if (normals !== void 0) {
6222
+ includeNormals = true;
6223
+ normalType = getPlyType(normals.array);
6224
+ }
6225
+ if (uvs !== void 0) {
6226
+ includeUVs = true;
6227
+ uvType = getPlyType(uvs.array);
6228
+ }
6229
+ if (colors !== void 0) {
6230
+ includeColors = true;
6231
+ colorType = getPlyType(colors.array);
6232
+ }
6233
+ for (const name of customAttributeNames) {
6234
+ const attr = geometry.getAttribute(name);
6235
+ if (attr !== void 0) customTypes[name] = getPlyType(attr.array);
6236
+ }
6191
6237
  } else if (child.isPoints) {
6192
6238
  const mesh = child;
6193
6239
  const geometry = mesh.geometry;
@@ -6195,8 +6241,19 @@ var PLYExporter = class {
6195
6241
  const normals = geometry.getAttribute("normal");
6196
6242
  const colors = geometry.getAttribute("color");
6197
6243
  vertexCount += vertices.count;
6198
- if (normals !== void 0) includeNormals = true;
6199
- if (colors !== void 0) includeColors = true;
6244
+ positionType = getPlyType(vertices.array);
6245
+ if (normals !== void 0) {
6246
+ includeNormals = true;
6247
+ normalType = getPlyType(normals.array);
6248
+ }
6249
+ if (colors !== void 0) {
6250
+ includeColors = true;
6251
+ colorType = getPlyType(colors.array);
6252
+ }
6253
+ for (const name of customAttributeNames) {
6254
+ const attr = geometry.getAttribute(name);
6255
+ if (attr !== void 0) customTypes[name] = getPlyType(attr.array);
6256
+ }
6200
6257
  includeIndices = false;
6201
6258
  }
6202
6259
  });
@@ -6215,18 +6272,33 @@ var PLYExporter = class {
6215
6272
  let header = `ply
6216
6273
  format ${options.binary ? options.littleEndian ? "binary_little_endian" : "binary_big_endian" : "ascii"} 1.0
6217
6274
  element vertex ${vertexCount}
6218
- property float x
6219
- property float y
6220
- property float z
6275
+ property ${positionType} x
6276
+ property ${positionType} y
6277
+ property ${positionType} z
6221
6278
  `;
6222
6279
  if (includeNormals === true) {
6223
- header += "property float nx\nproperty float ny\nproperty float nz\n";
6280
+ header += `property ${normalType} nx
6281
+ property ${normalType} ny
6282
+ property ${normalType} nz
6283
+ `;
6224
6284
  }
6225
6285
  if (includeUVs === true) {
6226
- header += "property float s\nproperty float t\n";
6286
+ header += `property ${uvType} s
6287
+ property ${uvType} t
6288
+ `;
6227
6289
  }
6228
6290
  if (includeColors === true) {
6229
- header += "property uchar red\nproperty uchar green\nproperty uchar blue\n";
6291
+ header += `property ${colorType} red
6292
+ property ${colorType} green
6293
+ property ${colorType} blue
6294
+ `;
6295
+ }
6296
+ for (const name of customAttributeNames) {
6297
+ const type = customTypes[name];
6298
+ for (const propName of customPropertyMapping[name]) {
6299
+ header += `property ${type} ${propName}
6300
+ `;
6301
+ }
6230
6302
  }
6231
6303
  if (includeIndices === true) {
6232
6304
  header += `element face ${faceCount}
@@ -6239,7 +6311,23 @@ property list uchar int vertex_index
6239
6311
  let result = null;
6240
6312
  if (options.binary === true) {
6241
6313
  const headerBin = new TextEncoder().encode(header);
6242
- const vertexListLength = vertexCount * (4 * 3 + (includeNormals ? 4 * 3 : 0) + (includeColors ? 3 : 0) + (includeUVs ? 4 * 2 : 0));
6314
+ const posWriter = getBinaryWriter(positionType);
6315
+ const normalWriter = includeNormals ? getBinaryWriter(normalType) : null;
6316
+ const uvWriter = includeUVs ? getBinaryWriter(uvType) : null;
6317
+ const colorWriter = includeColors ? getBinaryWriter(colorType) : null;
6318
+ const colorIsFloat = isFloatType(colorType);
6319
+ const colorScale = getColorScale(colorType);
6320
+ const customWriters = {};
6321
+ const customIsFloat = {};
6322
+ let customStride = 0;
6323
+ for (const name of customAttributeNames) {
6324
+ const type = customTypes[name];
6325
+ const writer = getBinaryWriter(type);
6326
+ customWriters[name] = writer;
6327
+ customIsFloat[name] = isFloatType(type);
6328
+ customStride += customPropertyMapping[name].length * writer.size;
6329
+ }
6330
+ const vertexListLength = vertexCount * (3 * posWriter.size + (includeNormals ? 3 * normalWriter.size : 0) + (includeUVs ? 2 * uvWriter.size : 0) + (includeColors ? 3 * colorWriter.size : 0) + customStride);
6243
6331
  const faceListLength = includeIndices ? faceCount * (indexByteCount * 3 + 1) : 0;
6244
6332
  const output = new DataView(new ArrayBuffer(headerBin.length + vertexListLength + faceListLength));
6245
6333
  new Uint8Array(output.buffer).set(headerBin, 0);
@@ -6256,60 +6344,76 @@ property list uchar int vertex_index
6256
6344
  for (let i = 0, l = vertices.count; i < l; i++) {
6257
6345
  vertex.fromBufferAttribute(vertices, i);
6258
6346
  vertex.applyMatrix4(mesh.matrixWorld);
6259
- output.setFloat32(vOffset, vertex.x, options.littleEndian);
6260
- vOffset += 4;
6261
- output.setFloat32(vOffset, vertex.y, options.littleEndian);
6262
- vOffset += 4;
6263
- output.setFloat32(vOffset, vertex.z, options.littleEndian);
6264
- vOffset += 4;
6347
+ posWriter.write(output, vOffset, vertex.x, options.littleEndian);
6348
+ vOffset += posWriter.size;
6349
+ posWriter.write(output, vOffset, vertex.y, options.littleEndian);
6350
+ vOffset += posWriter.size;
6351
+ posWriter.write(output, vOffset, vertex.z, options.littleEndian);
6352
+ vOffset += posWriter.size;
6265
6353
  if (includeNormals === true) {
6266
6354
  if (normals != null) {
6267
6355
  vertex.fromBufferAttribute(normals, i);
6268
6356
  vertex.applyMatrix3(normalMatrixWorld).normalize();
6269
- output.setFloat32(vOffset, vertex.x, options.littleEndian);
6270
- vOffset += 4;
6271
- output.setFloat32(vOffset, vertex.y, options.littleEndian);
6272
- vOffset += 4;
6273
- output.setFloat32(vOffset, vertex.z, options.littleEndian);
6274
- vOffset += 4;
6357
+ normalWriter.write(output, vOffset, vertex.x, options.littleEndian);
6358
+ vOffset += normalWriter.size;
6359
+ normalWriter.write(output, vOffset, vertex.y, options.littleEndian);
6360
+ vOffset += normalWriter.size;
6361
+ normalWriter.write(output, vOffset, vertex.z, options.littleEndian);
6362
+ vOffset += normalWriter.size;
6275
6363
  } else {
6276
- output.setFloat32(vOffset, 0, options.littleEndian);
6277
- vOffset += 4;
6278
- output.setFloat32(vOffset, 0, options.littleEndian);
6279
- vOffset += 4;
6280
- output.setFloat32(vOffset, 0, options.littleEndian);
6281
- vOffset += 4;
6364
+ normalWriter.write(output, vOffset, 0, options.littleEndian);
6365
+ vOffset += normalWriter.size;
6366
+ normalWriter.write(output, vOffset, 0, options.littleEndian);
6367
+ vOffset += normalWriter.size;
6368
+ normalWriter.write(output, vOffset, 0, options.littleEndian);
6369
+ vOffset += normalWriter.size;
6282
6370
  }
6283
6371
  }
6284
6372
  if (includeUVs === true) {
6285
6373
  if (uvs != null) {
6286
- output.setFloat32(vOffset, uvs.getX(i), options.littleEndian);
6287
- vOffset += 4;
6288
- output.setFloat32(vOffset, uvs.getY(i), options.littleEndian);
6289
- vOffset += 4;
6374
+ uvWriter.write(output, vOffset, uvs.getX(i), options.littleEndian);
6375
+ vOffset += uvWriter.size;
6376
+ uvWriter.write(output, vOffset, uvs.getY(i), options.littleEndian);
6377
+ vOffset += uvWriter.size;
6290
6378
  } else {
6291
- output.setFloat32(vOffset, 0, options.littleEndian);
6292
- vOffset += 4;
6293
- output.setFloat32(vOffset, 0, options.littleEndian);
6294
- vOffset += 4;
6379
+ uvWriter.write(output, vOffset, 0, options.littleEndian);
6380
+ vOffset += uvWriter.size;
6381
+ uvWriter.write(output, vOffset, 0, options.littleEndian);
6382
+ vOffset += uvWriter.size;
6295
6383
  }
6296
6384
  }
6297
6385
  if (includeColors === true) {
6298
6386
  if (colors != null) {
6299
- tempColor.fromBufferAttribute(colors, i).convertLinearToSRGB();
6300
- output.setUint8(vOffset, Math.floor(tempColor.r * 255));
6301
- vOffset += 1;
6302
- output.setUint8(vOffset, Math.floor(tempColor.g * 255));
6303
- vOffset += 1;
6304
- output.setUint8(vOffset, Math.floor(tempColor.b * 255));
6305
- vOffset += 1;
6387
+ tempColor.fromBufferAttribute(colors, i);
6388
+ import_three17.ColorManagement.workingToColorSpace(tempColor, import_three17.SRGBColorSpace);
6389
+ const r = colorIsFloat ? tempColor.r : Math.round(tempColor.r * colorScale);
6390
+ const g = colorIsFloat ? tempColor.g : Math.round(tempColor.g * colorScale);
6391
+ const b = colorIsFloat ? tempColor.b : Math.round(tempColor.b * colorScale);
6392
+ colorWriter.write(output, vOffset, r, options.littleEndian);
6393
+ vOffset += colorWriter.size;
6394
+ colorWriter.write(output, vOffset, g, options.littleEndian);
6395
+ vOffset += colorWriter.size;
6396
+ colorWriter.write(output, vOffset, b, options.littleEndian);
6397
+ vOffset += colorWriter.size;
6306
6398
  } else {
6307
- output.setUint8(vOffset, 255);
6308
- vOffset += 1;
6309
- output.setUint8(vOffset, 255);
6310
- vOffset += 1;
6311
- output.setUint8(vOffset, 255);
6312
- vOffset += 1;
6399
+ const white = colorIsFloat ? 1 : colorScale;
6400
+ colorWriter.write(output, vOffset, white, options.littleEndian);
6401
+ vOffset += colorWriter.size;
6402
+ colorWriter.write(output, vOffset, white, options.littleEndian);
6403
+ vOffset += colorWriter.size;
6404
+ colorWriter.write(output, vOffset, white, options.littleEndian);
6405
+ vOffset += colorWriter.size;
6406
+ }
6407
+ }
6408
+ for (const name of customAttributeNames) {
6409
+ const writer = customWriters[name];
6410
+ const propCount = customPropertyMapping[name].length;
6411
+ const attr = geometry.getAttribute(name);
6412
+ const isFloat = customIsFloat[name];
6413
+ for (let c = 0; c < propCount; c++) {
6414
+ const raw = attr != null ? getAttributeComponent(attr, i, c) : 0;
6415
+ writer.write(output, vOffset, isFloat ? raw : Math.round(raw), options.littleEndian);
6416
+ vOffset += writer.size;
6313
6417
  }
6314
6418
  }
6315
6419
  }
@@ -6345,6 +6449,14 @@ property list uchar int vertex_index
6345
6449
  let writtenVertices = 0;
6346
6450
  let vertexList = "";
6347
6451
  let faceList = "";
6452
+ const positionIsFloat = isFloatType(positionType);
6453
+ const normalIsFloat = isFloatType(normalType);
6454
+ const uvIsFloat = isFloatType(uvType);
6455
+ const colorIsFloat = isFloatType(colorType);
6456
+ const colorScale = getColorScale(colorType);
6457
+ const customIsFloat = {};
6458
+ for (const name of customAttributeNames) customIsFloat[name] = isFloatType(customTypes[name]);
6459
+ const encode = (v, isFloat) => isFloat ? v : Math.round(v);
6348
6460
  traverseMeshes(function(mesh, geometry) {
6349
6461
  const vertices = geometry.getAttribute("position");
6350
6462
  const normals = geometry.getAttribute("normal");
@@ -6355,29 +6467,43 @@ property list uchar int vertex_index
6355
6467
  for (let i = 0, l = vertices.count; i < l; i++) {
6356
6468
  vertex.fromBufferAttribute(vertices, i);
6357
6469
  vertex.applyMatrix4(mesh.matrixWorld);
6358
- let line = vertex.x + " " + vertex.y + " " + vertex.z;
6470
+ let line = encode(vertex.x, positionIsFloat) + " " + encode(vertex.y, positionIsFloat) + " " + encode(vertex.z, positionIsFloat);
6359
6471
  if (includeNormals === true) {
6360
6472
  if (normals != null) {
6361
6473
  vertex.fromBufferAttribute(normals, i);
6362
6474
  vertex.applyMatrix3(normalMatrixWorld).normalize();
6363
- line += " " + vertex.x + " " + vertex.y + " " + vertex.z;
6475
+ line += " " + encode(vertex.x, normalIsFloat) + " " + encode(vertex.y, normalIsFloat) + " " + encode(vertex.z, normalIsFloat);
6364
6476
  } else {
6365
6477
  line += " 0 0 0";
6366
6478
  }
6367
6479
  }
6368
6480
  if (includeUVs === true) {
6369
6481
  if (uvs != null) {
6370
- line += " " + uvs.getX(i) + " " + uvs.getY(i);
6482
+ line += " " + encode(uvs.getX(i), uvIsFloat) + " " + encode(uvs.getY(i), uvIsFloat);
6371
6483
  } else {
6372
6484
  line += " 0 0";
6373
6485
  }
6374
6486
  }
6375
6487
  if (includeColors === true) {
6376
6488
  if (colors != null) {
6377
- tempColor.fromBufferAttribute(colors, i).convertLinearToSRGB();
6378
- line += " " + Math.floor(tempColor.r * 255) + " " + Math.floor(tempColor.g * 255) + " " + Math.floor(tempColor.b * 255);
6489
+ tempColor.fromBufferAttribute(colors, i);
6490
+ import_three17.ColorManagement.workingToColorSpace(tempColor, import_three17.SRGBColorSpace);
6491
+ const r = colorIsFloat ? tempColor.r : Math.round(tempColor.r * colorScale);
6492
+ const g = colorIsFloat ? tempColor.g : Math.round(tempColor.g * colorScale);
6493
+ const b = colorIsFloat ? tempColor.b : Math.round(tempColor.b * colorScale);
6494
+ line += ` ${r} ${g} ${b}`;
6379
6495
  } else {
6380
- line += " 255 255 255";
6496
+ const white = colorIsFloat ? 1 : colorScale;
6497
+ line += ` ${white} ${white} ${white}`;
6498
+ }
6499
+ }
6500
+ for (const name of customAttributeNames) {
6501
+ const propCount = customPropertyMapping[name].length;
6502
+ const attr = geometry.getAttribute(name);
6503
+ const isFloat = customIsFloat[name];
6504
+ for (let c = 0; c < propCount; c++) {
6505
+ const raw = attr != null ? getAttributeComponent(attr, i, c) : 0;
6506
+ line += " " + encode(raw, isFloat);
6381
6507
  }
6382
6508
  }
6383
6509
  vertexList += line + "\n";
@@ -6407,70 +6533,65 @@ property list uchar int vertex_index
6407
6533
  return result;
6408
6534
  }
6409
6535
  };
6410
-
6411
- // ../../node_modules/three/examples/jsm/exporters/GLTFExporter.js
6412
- var import_three19 = require("three");
6413
-
6414
- // ../../node_modules/three/examples/jsm/utils/TextureUtils.js
6415
- var import_three18 = require("three");
6416
- var _renderer;
6417
- var fullscreenQuadGeometry;
6418
- var fullscreenQuadMaterial;
6419
- var fullscreenQuad;
6420
- function decompress(texture, maxTextureSize = Infinity, renderer = null) {
6421
- if (!fullscreenQuadGeometry) fullscreenQuadGeometry = new import_three18.PlaneGeometry(2, 2, 1, 1);
6422
- if (!fullscreenQuadMaterial) fullscreenQuadMaterial = new import_three18.ShaderMaterial({
6423
- uniforms: { blitTexture: new import_three18.Uniform(texture) },
6424
- vertexShader: `
6425
- varying vec2 vUv;
6426
- void main(){
6427
- vUv = uv;
6428
- gl_Position = vec4(position.xy * 1.0,0.,.999999);
6429
- }`,
6430
- fragmentShader: `
6431
- uniform sampler2D blitTexture;
6432
- varying vec2 vUv;
6433
-
6434
- void main(){
6435
- gl_FragColor = vec4(vUv.xy, 0, 1);
6436
-
6437
- #ifdef IS_SRGB
6438
- gl_FragColor = LinearTosRGB( texture2D( blitTexture, vUv) );
6439
- #else
6440
- gl_FragColor = texture2D( blitTexture, vUv);
6441
- #endif
6442
- }`
6443
- });
6444
- fullscreenQuadMaterial.uniforms.blitTexture.value = texture;
6445
- fullscreenQuadMaterial.defines.IS_SRGB = texture.colorSpace == import_three18.SRGBColorSpace;
6446
- fullscreenQuadMaterial.needsUpdate = true;
6447
- if (!fullscreenQuad) {
6448
- fullscreenQuad = new import_three18.Mesh(fullscreenQuadGeometry, fullscreenQuadMaterial);
6449
- fullscreenQuad.frustrumCulled = false;
6450
- }
6451
- const _camera = new import_three18.PerspectiveCamera();
6452
- const _scene = new import_three18.Scene();
6453
- _scene.add(fullscreenQuad);
6454
- if (!renderer) {
6455
- renderer = _renderer = new import_three18.WebGLRenderer({ antialias: false });
6456
- }
6457
- renderer.setSize(Math.min(texture.image.width, maxTextureSize), Math.min(texture.image.height, maxTextureSize));
6458
- renderer.clear();
6459
- renderer.render(_scene, _camera);
6460
- const readableTexture = new import_three18.Texture(renderer.domElement);
6461
- readableTexture.minFilter = texture.minFilter;
6462
- readableTexture.magFilter = texture.magFilter;
6463
- readableTexture.wrapS = texture.wrapS;
6464
- readableTexture.wrapT = texture.wrapT;
6465
- readableTexture.name = texture.name;
6466
- if (_renderer) {
6467
- _renderer.dispose();
6468
- _renderer = null;
6469
- }
6470
- return readableTexture;
6536
+ function getPlyType(array) {
6537
+ if (array instanceof Int8Array) return "char";
6538
+ if (array instanceof Uint8Array || array instanceof Uint8ClampedArray) return "uchar";
6539
+ if (array instanceof Int16Array) return "short";
6540
+ if (array instanceof Uint16Array) return "ushort";
6541
+ if (array instanceof Int32Array) return "int";
6542
+ if (array instanceof Uint32Array) return "uint";
6543
+ if (array instanceof Float32Array) return "float";
6544
+ if (array instanceof Float64Array) return "double";
6545
+ return "float";
6546
+ }
6547
+ function getBinaryWriter(type) {
6548
+ switch (type) {
6549
+ case "char":
6550
+ return { write: (dv, at, v) => dv.setInt8(at, v), size: 1 };
6551
+ case "uchar":
6552
+ return { write: (dv, at, v) => dv.setUint8(at, v), size: 1 };
6553
+ case "short":
6554
+ return { write: (dv, at, v, le) => dv.setInt16(at, v, le), size: 2 };
6555
+ case "ushort":
6556
+ return { write: (dv, at, v, le) => dv.setUint16(at, v, le), size: 2 };
6557
+ case "int":
6558
+ return { write: (dv, at, v, le) => dv.setInt32(at, v, le), size: 4 };
6559
+ case "uint":
6560
+ return { write: (dv, at, v, le) => dv.setUint32(at, v, le), size: 4 };
6561
+ case "float":
6562
+ return { write: (dv, at, v, le) => dv.setFloat32(at, v, le), size: 4 };
6563
+ case "double":
6564
+ return { write: (dv, at, v, le) => dv.setFloat64(at, v, le), size: 8 };
6565
+ }
6566
+ }
6567
+ function isFloatType(type) {
6568
+ return type === "float" || type === "double";
6569
+ }
6570
+ function getAttributeComponent(attr, i, c) {
6571
+ switch (c) {
6572
+ case 0:
6573
+ return attr.getX(i);
6574
+ case 1:
6575
+ return attr.getY(i);
6576
+ case 2:
6577
+ return attr.getZ(i);
6578
+ case 3:
6579
+ return attr.getW(i);
6580
+ }
6581
+ }
6582
+ function getColorScale(type) {
6583
+ switch (type) {
6584
+ case "uchar":
6585
+ return 255;
6586
+ case "ushort":
6587
+ return 65535;
6588
+ default:
6589
+ return 1;
6590
+ }
6471
6591
  }
6472
6592
 
6473
6593
  // ../../node_modules/three/examples/jsm/exporters/GLTFExporter.js
6594
+ var import_three18 = require("three");
6474
6595
  var KHR_mesh_quantization_ExtraAttrTypes = {
6475
6596
  POSITION: [
6476
6597
  "byte",
@@ -6500,7 +6621,11 @@ var KHR_mesh_quantization_ExtraAttrTypes = {
6500
6621
  ]
6501
6622
  };
6502
6623
  var GLTFExporter = class {
6624
+ /**
6625
+ * Constructs a new glTF exporter.
6626
+ */
6503
6627
  constructor() {
6628
+ this.textureUtils = null;
6504
6629
  this.pluginCallbacks = [];
6505
6630
  this.register(function(writer) {
6506
6631
  return new GLTFLightExtension(writer);
@@ -6523,6 +6648,9 @@ var GLTFExporter = class {
6523
6648
  this.register(function(writer) {
6524
6649
  return new GLTFMaterialsClearcoatExtension(writer);
6525
6650
  });
6651
+ this.register(function(writer) {
6652
+ return new GLTFMaterialsDispersionExtension(writer);
6653
+ });
6526
6654
  this.register(function(writer) {
6527
6655
  return new GLTFMaterialsIridescenceExtension(writer);
6528
6656
  });
@@ -6535,16 +6663,33 @@ var GLTFExporter = class {
6535
6663
  this.register(function(writer) {
6536
6664
  return new GLTFMaterialsEmissiveStrengthExtension(writer);
6537
6665
  });
6666
+ this.register(function(writer) {
6667
+ return new GLTFMaterialsBumpExtension(writer);
6668
+ });
6538
6669
  this.register(function(writer) {
6539
6670
  return new GLTFMeshGpuInstancing(writer);
6540
6671
  });
6541
6672
  }
6673
+ /**
6674
+ * Registers a plugin callback. This API is internally used to implement the various
6675
+ * glTF extensions but can also used by third-party code to add additional logic
6676
+ * to the exporter.
6677
+ *
6678
+ * @param {function(writer:GLTFWriter)} callback - The callback function to register.
6679
+ * @return {GLTFExporter} A reference to this exporter.
6680
+ */
6542
6681
  register(callback) {
6543
6682
  if (this.pluginCallbacks.indexOf(callback) === -1) {
6544
6683
  this.pluginCallbacks.push(callback);
6545
6684
  }
6546
6685
  return this;
6547
6686
  }
6687
+ /**
6688
+ * Unregisters a plugin callback.
6689
+ *
6690
+ * @param {Function} callback - The callback function to unregister.
6691
+ * @return {GLTFExporter} A reference to this exporter.
6692
+ */
6548
6693
  unregister(callback) {
6549
6694
  if (this.pluginCallbacks.indexOf(callback) !== -1) {
6550
6695
  this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(callback), 1);
@@ -6552,11 +6697,25 @@ var GLTFExporter = class {
6552
6697
  return this;
6553
6698
  }
6554
6699
  /**
6555
- * Parse scenes and generate GLTF output
6556
- * @param {Scene or [THREE.Scenes]} input Scene or Array of THREE.Scenes
6557
- * @param {Function} onDone Callback on completed
6558
- * @param {Function} onError Callback on errors
6559
- * @param {Object} options options
6700
+ * Sets the texture utils for this exporter. Only relevant when compressed textures have to be exported.
6701
+ *
6702
+ * Depending on whether you use {@link WebGLRenderer} or {@link WebGPURenderer}, you must inject the
6703
+ * corresponding texture utils {@link module:WebGLTextureUtils} or {@link module:WebGPUTextureUtils}.
6704
+ *
6705
+ * @param {WebGLTextureUtils|WebGPUTextureUtils} utils - The texture utils.
6706
+ * @return {GLTFExporter} A reference to this exporter.
6707
+ */
6708
+ setTextureUtils(utils) {
6709
+ this.textureUtils = utils;
6710
+ return this;
6711
+ }
6712
+ /**
6713
+ * Parses the given scenes and generates the glTF output.
6714
+ *
6715
+ * @param {Scene|Array<Scene>} input - A scene or an array of scenes.
6716
+ * @param {GLTFExporter~OnDone} onDone - A callback function that is executed when the export has finished.
6717
+ * @param {GLTFExporter~OnError} onError - A callback function that is executed when an error happens.
6718
+ * @param {GLTFExporter~Options} options - options
6560
6719
  */
6561
6720
  parse(input, onDone, onError, options) {
6562
6721
  const writer = new GLTFWriter();
@@ -6565,8 +6724,16 @@ var GLTFExporter = class {
6565
6724
  plugins.push(this.pluginCallbacks[i](writer));
6566
6725
  }
6567
6726
  writer.setPlugins(plugins);
6568
- writer.write(input, onDone, options).catch(onError);
6727
+ writer.setTextureUtils(this.textureUtils);
6728
+ writer.writeAsync(input, onDone, options).catch(onError);
6569
6729
  }
6730
+ /**
6731
+ * Async version of {@link GLTFExporter#parse}.
6732
+ *
6733
+ * @param {Scene|Array<Scene>} input - A scene or an array of scenes.
6734
+ * @param {GLTFExporter~Options} options - options.
6735
+ * @return {Promise<ArrayBuffer|string>} A Promise that resolved with the exported glTF data.
6736
+ */
6570
6737
  parseAsync(input, options) {
6571
6738
  const scope = this;
6572
6739
  return new Promise(function(resolve, reject) {
@@ -6603,22 +6770,22 @@ var WEBGL_CONSTANTS = {
6603
6770
  };
6604
6771
  var KHR_MESH_QUANTIZATION = "KHR_mesh_quantization";
6605
6772
  var THREE_TO_WEBGL = {};
6606
- THREE_TO_WEBGL[import_three19.NearestFilter] = WEBGL_CONSTANTS.NEAREST;
6607
- THREE_TO_WEBGL[import_three19.NearestMipmapNearestFilter] = WEBGL_CONSTANTS.NEAREST_MIPMAP_NEAREST;
6608
- THREE_TO_WEBGL[import_three19.NearestMipmapLinearFilter] = WEBGL_CONSTANTS.NEAREST_MIPMAP_LINEAR;
6609
- THREE_TO_WEBGL[import_three19.LinearFilter] = WEBGL_CONSTANTS.LINEAR;
6610
- THREE_TO_WEBGL[import_three19.LinearMipmapNearestFilter] = WEBGL_CONSTANTS.LINEAR_MIPMAP_NEAREST;
6611
- THREE_TO_WEBGL[import_three19.LinearMipmapLinearFilter] = WEBGL_CONSTANTS.LINEAR_MIPMAP_LINEAR;
6612
- THREE_TO_WEBGL[import_three19.ClampToEdgeWrapping] = WEBGL_CONSTANTS.CLAMP_TO_EDGE;
6613
- THREE_TO_WEBGL[import_three19.RepeatWrapping] = WEBGL_CONSTANTS.REPEAT;
6614
- THREE_TO_WEBGL[import_three19.MirroredRepeatWrapping] = WEBGL_CONSTANTS.MIRRORED_REPEAT;
6773
+ THREE_TO_WEBGL[import_three18.NearestFilter] = WEBGL_CONSTANTS.NEAREST;
6774
+ THREE_TO_WEBGL[import_three18.NearestMipmapNearestFilter] = WEBGL_CONSTANTS.NEAREST_MIPMAP_NEAREST;
6775
+ THREE_TO_WEBGL[import_three18.NearestMipmapLinearFilter] = WEBGL_CONSTANTS.NEAREST_MIPMAP_LINEAR;
6776
+ THREE_TO_WEBGL[import_three18.LinearFilter] = WEBGL_CONSTANTS.LINEAR;
6777
+ THREE_TO_WEBGL[import_three18.LinearMipmapNearestFilter] = WEBGL_CONSTANTS.LINEAR_MIPMAP_NEAREST;
6778
+ THREE_TO_WEBGL[import_three18.LinearMipmapLinearFilter] = WEBGL_CONSTANTS.LINEAR_MIPMAP_LINEAR;
6779
+ THREE_TO_WEBGL[import_three18.ClampToEdgeWrapping] = WEBGL_CONSTANTS.CLAMP_TO_EDGE;
6780
+ THREE_TO_WEBGL[import_three18.RepeatWrapping] = WEBGL_CONSTANTS.REPEAT;
6781
+ THREE_TO_WEBGL[import_three18.MirroredRepeatWrapping] = WEBGL_CONSTANTS.MIRRORED_REPEAT;
6615
6782
  var PATH_PROPERTIES = {
6616
6783
  scale: "scale",
6617
6784
  position: "translation",
6618
6785
  quaternion: "rotation",
6619
6786
  morphTargetInfluences: "weights"
6620
6787
  };
6621
- var DEFAULT_SPECULAR_COLOR = new import_three19.Color();
6788
+ var DEFAULT_SPECULAR_COLOR = new import_three18.Color();
6622
6789
  var GLB_HEADER_BYTES = 12;
6623
6790
  var GLB_HEADER_MAGIC = 1179937895;
6624
6791
  var GLB_VERSION = 2;
@@ -6652,7 +6819,7 @@ function getMinMax(attribute, start, count) {
6652
6819
  else if (a === 2) value = attribute.getZ(i);
6653
6820
  else if (a === 3) value = attribute.getW(i);
6654
6821
  if (attribute.normalized === true) {
6655
- value = import_three19.MathUtils.normalize(value, attribute.array);
6822
+ value = import_three18.MathUtils.normalize(value, attribute.array);
6656
6823
  }
6657
6824
  }
6658
6825
  output.min[a] = Math.min(output.min[a], value);
@@ -6685,19 +6852,20 @@ function getCanvas() {
6685
6852
  return document.createElement("canvas");
6686
6853
  }
6687
6854
  function getToBlobPromise(canvas, mimeType) {
6688
- if (canvas.toBlob !== void 0) {
6855
+ if (typeof OffscreenCanvas !== "undefined" && canvas instanceof OffscreenCanvas) {
6856
+ let quality;
6857
+ if (mimeType === "image/jpeg") {
6858
+ quality = 0.92;
6859
+ } else if (mimeType === "image/webp") {
6860
+ quality = 0.8;
6861
+ }
6862
+ return canvas.convertToBlob({
6863
+ type: mimeType,
6864
+ quality
6865
+ });
6866
+ } else {
6689
6867
  return new Promise((resolve) => canvas.toBlob(resolve, mimeType));
6690
6868
  }
6691
- let quality;
6692
- if (mimeType === "image/jpeg") {
6693
- quality = 0.92;
6694
- } else if (mimeType === "image/webp") {
6695
- quality = 0.8;
6696
- }
6697
- return canvas.convertToBlob({
6698
- type: mimeType,
6699
- quality
6700
- });
6701
6869
  }
6702
6870
  var GLTFWriter = class {
6703
6871
  constructor() {
@@ -6716,7 +6884,7 @@ var GLTFWriter = class {
6716
6884
  this.json = {
6717
6885
  asset: {
6718
6886
  version: "2.0",
6719
- generator: "THREE.GLTFExporter"
6887
+ generator: "THREE.GLTFExporter r" + import_three18.REVISION
6720
6888
  }
6721
6889
  };
6722
6890
  this.cache = {
@@ -6725,19 +6893,25 @@ var GLTFWriter = class {
6725
6893
  attributesNormalized: /* @__PURE__ */ new Map(),
6726
6894
  materials: /* @__PURE__ */ new Map(),
6727
6895
  textures: /* @__PURE__ */ new Map(),
6728
- images: /* @__PURE__ */ new Map()
6896
+ images: /* @__PURE__ */ new Map(),
6897
+ normalMaps: /* @__PURE__ */ new Map()
6729
6898
  };
6899
+ this.textureUtils = null;
6730
6900
  }
6731
6901
  setPlugins(plugins) {
6732
6902
  this.plugins = plugins;
6733
6903
  }
6904
+ setTextureUtils(utils) {
6905
+ this.textureUtils = utils;
6906
+ }
6734
6907
  /**
6735
6908
  * Parse scenes and generate GLTF output
6736
- * @param {Scene or [THREE.Scenes]} input Scene or Array of THREE.Scenes
6737
- * @param {Function} onDone Callback on completed
6738
- * @param {Object} options options
6909
+ *
6910
+ * @param {Scene|Array<Scene>} input Scene or Array of THREE.Scenes
6911
+ * @param {Function} onDone Callback on completed
6912
+ * @param {Object} options options
6739
6913
  */
6740
- async write(input, onDone, options = {}) {
6914
+ async writeAsync(input, onDone, options = {}) {
6741
6915
  this.options = Object.assign({
6742
6916
  // default options
6743
6917
  binary: false,
@@ -6745,12 +6919,13 @@ var GLTFWriter = class {
6745
6919
  onlyVisible: true,
6746
6920
  maxTextureSize: Infinity,
6747
6921
  animations: [],
6748
- includeCustomExtensions: false
6922
+ includeCustomExtensions: false,
6923
+ copyright: null
6749
6924
  }, options);
6750
6925
  if (this.options.animations.length > 0) {
6751
6926
  this.options.trs = true;
6752
6927
  }
6753
- this.processInput(input);
6928
+ await this.processInputAsync(input);
6754
6929
  await Promise.all(this.pending);
6755
6930
  const writer = this;
6756
6931
  const buffers = writer.buffers;
@@ -6764,6 +6939,7 @@ var GLTFWriter = class {
6764
6939
  if (extensionsUsedList.length > 0) json.extensionsUsed = extensionsUsedList;
6765
6940
  if (extensionsRequiredList.length > 0) json.extensionsRequired = extensionsRequiredList;
6766
6941
  if (json.buffers && json.buffers.length > 0) json.buffers[0].byteLength = blob.size;
6942
+ if (options.copyright) json.asset.copyright = options.copyright;
6767
6943
  if (options.binary === true) {
6768
6944
  const reader = new FileReader();
6769
6945
  reader.readAsArrayBuffer(blob);
@@ -6812,7 +6988,7 @@ var GLTFWriter = class {
6812
6988
  /**
6813
6989
  * Serializes a userData.
6814
6990
  *
6815
- * @param {THREE.Object3D|THREE.Material} object
6991
+ * @param {THREE.Object3D|THREE.Material|THREE.BufferGeometry|THREE.AnimationClip} object
6816
6992
  * @param {Object} objectDef
6817
6993
  */
6818
6994
  serializeUserData(object, objectDef) {
@@ -6836,8 +7012,10 @@ var GLTFWriter = class {
6836
7012
  }
6837
7013
  /**
6838
7014
  * Returns ids for buffer attributes.
6839
- * @param {Object} object
6840
- * @return {Integer}
7015
+ *
7016
+ * @param {Object} attribute
7017
+ * @param {boolean} [isRelativeCopy=false]
7018
+ * @return {number} An integer
6841
7019
  */
6842
7020
  getUID(attribute, isRelativeCopy = false) {
6843
7021
  if (this.uids.has(attribute) === false) {
@@ -6853,12 +7031,12 @@ var GLTFWriter = class {
6853
7031
  * Checks if normal attribute values are normalized.
6854
7032
  *
6855
7033
  * @param {BufferAttribute} normal
6856
- * @returns {Boolean}
7034
+ * @returns {boolean}
6857
7035
  */
6858
7036
  isNormalizedNormalAttribute(normal) {
6859
7037
  const cache = this.cache;
6860
7038
  if (cache.attributesNormalized.has(normal)) return false;
6861
- const v = new import_three19.Vector3();
7039
+ const v = new import_three18.Vector3();
6862
7040
  for (let i = 0, il = normal.count; i < il; i++) {
6863
7041
  if (Math.abs(v.fromBufferAttribute(normal, i).length() - 1) > 5e-4) return false;
6864
7042
  }
@@ -6875,7 +7053,7 @@ var GLTFWriter = class {
6875
7053
  const cache = this.cache;
6876
7054
  if (cache.attributesNormalized.has(normal)) return cache.attributesNormalized.get(normal);
6877
7055
  const attribute = normal.clone();
6878
- const v = new import_three19.Vector3();
7056
+ const v = new import_three18.Vector3();
6879
7057
  for (let i = 0, il = attribute.count; i < il; i++) {
6880
7058
  v.fromBufferAttribute(attribute, i);
6881
7059
  if (v.x === 0 && v.y === 0 && v.z === 0) {
@@ -6916,10 +7094,10 @@ var GLTFWriter = class {
6916
7094
  this.extensionsUsed["KHR_texture_transform"] = true;
6917
7095
  }
6918
7096
  }
6919
- buildMetalRoughTexture(metalnessMap, roughnessMap) {
7097
+ async buildMetalRoughTextureAsync(metalnessMap, roughnessMap) {
6920
7098
  if (metalnessMap === roughnessMap) return metalnessMap;
6921
7099
  function getEncodingConversion(map) {
6922
- if (map.colorSpace === import_three19.SRGBColorSpace) {
7100
+ if (map.colorSpace === import_three18.SRGBColorSpace) {
6923
7101
  return function SRGBToLinear(c) {
6924
7102
  return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
6925
7103
  };
@@ -6928,12 +7106,11 @@ var GLTFWriter = class {
6928
7106
  return c;
6929
7107
  };
6930
7108
  }
6931
- console.warn("THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures.");
6932
- if (metalnessMap instanceof import_three19.CompressedTexture) {
6933
- metalnessMap = decompress(metalnessMap);
7109
+ if (metalnessMap instanceof import_three18.CompressedTexture) {
7110
+ metalnessMap = await this.decompressTextureAsync(metalnessMap);
6934
7111
  }
6935
- if (roughnessMap instanceof import_three19.CompressedTexture) {
6936
- roughnessMap = decompress(roughnessMap);
7112
+ if (roughnessMap instanceof import_three18.CompressedTexture) {
7113
+ roughnessMap = await this.decompressTextureAsync(roughnessMap);
6937
7114
  }
6938
7115
  const metalness = metalnessMap ? metalnessMap.image : null;
6939
7116
  const roughness = roughnessMap ? roughnessMap.image : null;
@@ -6942,7 +7119,9 @@ var GLTFWriter = class {
6942
7119
  const canvas = getCanvas();
6943
7120
  canvas.width = width;
6944
7121
  canvas.height = height;
6945
- const context = canvas.getContext("2d");
7122
+ const context = canvas.getContext("2d", {
7123
+ willReadFrequently: true
7124
+ });
6946
7125
  context.fillStyle = "#00ffff";
6947
7126
  context.fillRect(0, 0, width, height);
6948
7127
  const composite = context.getImageData(0, 0, width, height);
@@ -6965,18 +7144,60 @@ var GLTFWriter = class {
6965
7144
  context.putImageData(composite, 0, 0);
6966
7145
  const reference = metalnessMap || roughnessMap;
6967
7146
  const texture = reference.clone();
6968
- texture.source = new import_three19.Source(canvas);
6969
- texture.colorSpace = import_three19.NoColorSpace;
7147
+ texture.source = new import_three18.TextureSource(canvas);
7148
+ texture.colorSpace = import_three18.NoColorSpace;
6970
7149
  texture.channel = (metalnessMap || roughnessMap).channel;
6971
7150
  if (metalnessMap && roughnessMap && metalnessMap.channel !== roughnessMap.channel) {
6972
7151
  console.warn("THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match.");
6973
7152
  }
7153
+ console.warn("THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures.");
7154
+ return texture;
7155
+ }
7156
+ /**
7157
+ * Builds a copy of the given normal map with the red and/or green channels
7158
+ * inverted (`color = 255 - color`). This is used to bake the sign of
7159
+ * `material.normalScale` and the tangent-space convention into the texture,
7160
+ * since glTF only supports OpenGL-style normal maps with a univariate,
7161
+ * positive scale.
7162
+ *
7163
+ * @param {THREE.Texture} normalMap The source normal map.
7164
+ * @param {boolean} flipX Whether to invert the red channel (normal X).
7165
+ * @param {boolean} flipY Whether to invert the green channel (normal Y).
7166
+ * @return {Promise<THREE.Texture>} The derived normal map texture.
7167
+ */
7168
+ async buildNormalMapTextureAsync(normalMap, flipX, flipY) {
7169
+ if (normalMap instanceof import_three18.CompressedTexture) {
7170
+ normalMap = await this.decompressTextureAsync(normalMap);
7171
+ }
7172
+ const image = normalMap.image;
7173
+ const canvas = getCanvas();
7174
+ canvas.width = image.width;
7175
+ canvas.height = image.height;
7176
+ const context = canvas.getContext("2d", {
7177
+ willReadFrequently: true
7178
+ });
7179
+ context.drawImage(image, 0, 0, canvas.width, canvas.height);
7180
+ const imageData = context.getImageData(0, 0, canvas.width, canvas.height);
7181
+ const data = imageData.data;
7182
+ for (let i = 0; i < data.length; i += 4) {
7183
+ if (flipX) data[i + 0] = 255 - data[i + 0];
7184
+ if (flipY) data[i + 1] = 255 - data[i + 1];
7185
+ }
7186
+ context.putImageData(imageData, 0, 0);
7187
+ const texture = normalMap.clone();
7188
+ texture.source = new import_three18.TextureSource(canvas);
6974
7189
  return texture;
6975
7190
  }
7191
+ async decompressTextureAsync(texture, maxTextureSize = Infinity) {
7192
+ if (this.textureUtils === null) {
7193
+ throw new Error("THREE.GLTFExporter: setTextureUtils() must be called to process compressed textures.");
7194
+ }
7195
+ return await this.textureUtils.decompress(texture, maxTextureSize);
7196
+ }
6976
7197
  /**
6977
7198
  * Process a buffer to append to the default one.
6978
- * @param {ArrayBuffer} buffer
6979
- * @return {Integer}
7199
+ * @param {ArrayBuffer} buffer
7200
+ * @return {0}
6980
7201
  */
6981
7202
  processBuffer(buffer) {
6982
7203
  const json = this.json;
@@ -6987,11 +7208,11 @@ var GLTFWriter = class {
6987
7208
  }
6988
7209
  /**
6989
7210
  * Process and generate a BufferView
6990
- * @param {BufferAttribute} attribute
6991
- * @param {number} componentType
6992
- * @param {number} start
6993
- * @param {number} count
6994
- * @param {number} target (Optional) Target usage of the BufferView
7211
+ * @param {BufferAttribute} attribute
7212
+ * @param {number} componentType
7213
+ * @param {number} start
7214
+ * @param {number} count
7215
+ * @param {number} [target] Target usage of the BufferView
6995
7216
  * @return {Object}
6996
7217
  */
6997
7218
  processBufferView(attribute, componentType, start, count, target) {
@@ -7010,7 +7231,11 @@ var GLTFWriter = class {
7010
7231
  default:
7011
7232
  componentSize = 4;
7012
7233
  }
7013
- const byteLength = getPaddedBufferSize(count * attribute.itemSize * componentSize);
7234
+ let byteStride = attribute.itemSize * componentSize;
7235
+ if (target === WEBGL_CONSTANTS.ARRAY_BUFFER) {
7236
+ byteStride = Math.ceil(byteStride / 4) * 4;
7237
+ }
7238
+ const byteLength = getPaddedBufferSize(count * byteStride);
7014
7239
  const dataView = new DataView(new ArrayBuffer(byteLength));
7015
7240
  let offset = 0;
7016
7241
  for (let i = start; i < start + count; i++) {
@@ -7024,7 +7249,7 @@ var GLTFWriter = class {
7024
7249
  else if (a === 2) value = attribute.getZ(i);
7025
7250
  else if (a === 3) value = attribute.getW(i);
7026
7251
  if (attribute.normalized === true) {
7027
- value = import_three19.MathUtils.normalize(value, attribute.array);
7252
+ value = import_three18.MathUtils.normalize(value, attribute.array);
7028
7253
  }
7029
7254
  }
7030
7255
  if (componentType === WEBGL_CONSTANTS.FLOAT) {
@@ -7044,6 +7269,9 @@ var GLTFWriter = class {
7044
7269
  }
7045
7270
  offset += componentSize;
7046
7271
  }
7272
+ if (offset % byteStride !== 0) {
7273
+ offset += byteStride - offset % byteStride;
7274
+ }
7047
7275
  }
7048
7276
  const bufferViewDef = {
7049
7277
  buffer: this.processBuffer(dataView.buffer),
@@ -7052,7 +7280,7 @@ var GLTFWriter = class {
7052
7280
  };
7053
7281
  if (target !== void 0) bufferViewDef.target = target;
7054
7282
  if (target === WEBGL_CONSTANTS.ARRAY_BUFFER) {
7055
- bufferViewDef.byteStride = attribute.itemSize * componentSize;
7283
+ bufferViewDef.byteStride = byteStride;
7056
7284
  }
7057
7285
  this.byteOffset += byteLength;
7058
7286
  json.bufferViews.push(bufferViewDef);
@@ -7065,7 +7293,7 @@ var GLTFWriter = class {
7065
7293
  /**
7066
7294
  * Process and generate a BufferView from an image Blob.
7067
7295
  * @param {Blob} blob
7068
- * @return {Promise<Integer>}
7296
+ * @return {Promise<number>} An integer
7069
7297
  */
7070
7298
  processBufferViewImage(blob) {
7071
7299
  const writer = this;
@@ -7088,11 +7316,11 @@ var GLTFWriter = class {
7088
7316
  }
7089
7317
  /**
7090
7318
  * Process attribute to generate an accessor
7091
- * @param {BufferAttribute} attribute Attribute to process
7092
- * @param {THREE.BufferGeometry} geometry (Optional) Geometry used for truncated draw range
7093
- * @param {Integer} start (Optional)
7094
- * @param {Integer} count (Optional)
7095
- * @return {Integer|null} Index of the processed accessor on the "accessors" array
7319
+ * @param {BufferAttribute} attribute Attribute to process
7320
+ * @param {?BufferGeometry} [geometry] Geometry used for truncated draw range
7321
+ * @param {number} [start=0]
7322
+ * @param {number} [count=Infinity]
7323
+ * @return {?number} Index of the processed accessor on the "accessors" array
7096
7324
  */
7097
7325
  processAccessor(attribute, geometry, start, count) {
7098
7326
  const json = this.json;
@@ -7146,11 +7374,11 @@ var GLTFWriter = class {
7146
7374
  }
7147
7375
  /**
7148
7376
  * Process image
7149
- * @param {Image} image to process
7150
- * @param {Integer} format of the image (RGBAFormat)
7151
- * @param {Boolean} flipY before writing out the image
7152
- * @param {String} mimeType export format
7153
- * @return {Integer} Index of the processed texture in the "images" array
7377
+ * @param {Image} image to process
7378
+ * @param {number} format Identifier of the format (RGBAFormat)
7379
+ * @param {boolean} flipY before writing out the image
7380
+ * @param {string} mimeType export format
7381
+ * @return {number} Index of the processed texture in the "images" array
7154
7382
  */
7155
7383
  processImage(image, format, flipY, mimeType = "image/png") {
7156
7384
  if (image !== null) {
@@ -7168,13 +7396,15 @@ var GLTFWriter = class {
7168
7396
  const canvas = getCanvas();
7169
7397
  canvas.width = Math.min(image.width, options.maxTextureSize);
7170
7398
  canvas.height = Math.min(image.height, options.maxTextureSize);
7171
- const ctx = canvas.getContext("2d");
7399
+ const ctx = canvas.getContext("2d", {
7400
+ willReadFrequently: true
7401
+ });
7172
7402
  if (flipY === true) {
7173
7403
  ctx.translate(0, canvas.height);
7174
7404
  ctx.scale(1, -1);
7175
7405
  }
7176
7406
  if (image.data !== void 0) {
7177
- if (format !== import_three19.RGBAFormat) {
7407
+ if (format !== import_three18.RGBAFormat) {
7178
7408
  console.error("GLTFExporter: Only RGBAFormat is supported.", format);
7179
7409
  }
7180
7410
  if (image.width > options.maxTextureSize || image.height > options.maxTextureSize) {
@@ -7189,7 +7419,11 @@ var GLTFWriter = class {
7189
7419
  }
7190
7420
  ctx.putImageData(new ImageData(data, image.width, image.height), 0, 0);
7191
7421
  } else {
7192
- ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
7422
+ if (typeof HTMLImageElement !== "undefined" && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== "undefined" && image instanceof HTMLCanvasElement || typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap || typeof OffscreenCanvas !== "undefined" && image instanceof OffscreenCanvas) {
7423
+ ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
7424
+ } else {
7425
+ throw new Error("THREE.GLTFExporter: Invalid image type. Use HTMLImageElement, HTMLCanvasElement, ImageBitmap or OffscreenCanvas.");
7426
+ }
7193
7427
  }
7194
7428
  if (options.binary === true) {
7195
7429
  pending.push(
@@ -7198,15 +7432,7 @@ var GLTFWriter = class {
7198
7432
  })
7199
7433
  );
7200
7434
  } else {
7201
- if (canvas.toDataURL !== void 0) {
7202
- imageDef.uri = canvas.toDataURL(mimeType);
7203
- } else {
7204
- pending.push(
7205
- getToBlobPromise(canvas, mimeType).then((blob) => new FileReader().readAsDataURL(blob)).then((dataURL) => {
7206
- imageDef.uri = dataURL;
7207
- })
7208
- );
7209
- }
7435
+ imageDef.uri = import_three18.ImageUtils.getDataURL(canvas, mimeType);
7210
7436
  }
7211
7437
  const index = json.images.push(imageDef) - 1;
7212
7438
  cachedImages[key] = index;
@@ -7217,8 +7443,8 @@ var GLTFWriter = class {
7217
7443
  }
7218
7444
  /**
7219
7445
  * Process sampler
7220
- * @param {Texture} map Texture to process
7221
- * @return {Integer} Index of the processed texture in the "samplers" array
7446
+ * @param {Texture} map Texture to process
7447
+ * @return {number} Index of the processed texture in the "samplers" array
7222
7448
  */
7223
7449
  processSampler(map) {
7224
7450
  const json = this.json;
@@ -7233,28 +7459,37 @@ var GLTFWriter = class {
7233
7459
  }
7234
7460
  /**
7235
7461
  * Process texture
7236
- * @param {Texture} map Map to process
7237
- * @return {Integer} Index of the processed texture in the "textures" array
7462
+ * @param {Texture} map Map to process
7463
+ * @return {Promise<number>} Index of the processed texture in the "textures" array
7238
7464
  */
7239
- processTexture(map) {
7465
+ async processTextureAsync(map) {
7240
7466
  const writer = this;
7241
7467
  const options = writer.options;
7242
7468
  const cache = this.cache;
7243
7469
  const json = this.json;
7244
7470
  if (cache.textures.has(map)) return cache.textures.get(map);
7245
7471
  if (!json.textures) json.textures = [];
7246
- if (map instanceof import_three19.CompressedTexture) {
7247
- map = decompress(map, options.maxTextureSize);
7472
+ if (map instanceof import_three18.CompressedTexture) {
7473
+ map = await this.decompressTextureAsync(map, options.maxTextureSize);
7248
7474
  }
7249
- let mimeType = map.userData.mimeType;
7250
- if (mimeType === "image/webp") mimeType = "image/png";
7475
+ const mimeType = map.userData.mimeType;
7476
+ const imageIndex = this.processImage(map.image, map.format, map.flipY, mimeType);
7251
7477
  const textureDef = {
7252
- sampler: this.processSampler(map),
7253
- source: this.processImage(map.image, map.format, map.flipY, mimeType)
7478
+ sampler: this.processSampler(map)
7254
7479
  };
7480
+ if (mimeType === "image/webp") {
7481
+ textureDef.extensions = textureDef.extensions || {};
7482
+ textureDef.extensions["EXT_texture_webp"] = {
7483
+ source: imageIndex
7484
+ };
7485
+ this.extensionsUsed["EXT_texture_webp"] = true;
7486
+ this.extensionsRequired["EXT_texture_webp"] = true;
7487
+ } else {
7488
+ textureDef.source = imageIndex;
7489
+ }
7255
7490
  if (map.name) textureDef.name = map.name;
7256
- this._invokeAll(function(ext) {
7257
- ext.writeTexture && ext.writeTexture(map, textureDef);
7491
+ await this._invokeAllAsync(async function(ext) {
7492
+ ext.writeTexture && await ext.writeTexture(map, textureDef);
7258
7493
  });
7259
7494
  const index = json.textures.push(textureDef) - 1;
7260
7495
  cache.textures.set(map, index);
@@ -7262,13 +7497,16 @@ var GLTFWriter = class {
7262
7497
  }
7263
7498
  /**
7264
7499
  * Process material
7265
- * @param {THREE.Material} material Material to process
7266
- * @return {Integer|null} Index of the processed material in the "materials" array
7500
+ * @param {THREE.Material} material Material to process
7501
+ * @param {THREE.BufferGeometry} [geometry] Geometry the material is used with.
7502
+ * @return {Promise<?number>} Index of the processed material in the "materials" array
7267
7503
  */
7268
- processMaterial(material) {
7504
+ async processMaterialAsync(material, geometry) {
7269
7505
  const cache = this.cache;
7270
7506
  const json = this.json;
7271
- if (cache.materials.has(material)) return cache.materials.get(material);
7507
+ const hasTangent = geometry !== void 0 && geometry.hasAttribute("tangent");
7508
+ const cacheKey = material.normalMap ? material.uuid + ":" + hasTangent : material.uuid;
7509
+ if (cache.materials.has(cacheKey)) return cache.materials.get(cacheKey);
7272
7510
  if (material.isShaderMaterial) {
7273
7511
  console.warn("GLTFExporter: THREE.ShaderMaterial not supported.");
7274
7512
  return null;
@@ -7286,21 +7524,21 @@ var GLTFWriter = class {
7286
7524
  materialDef.pbrMetallicRoughness.metallicFactor = material.metalness;
7287
7525
  materialDef.pbrMetallicRoughness.roughnessFactor = material.roughness;
7288
7526
  } else {
7289
- materialDef.pbrMetallicRoughness.metallicFactor = 0.5;
7290
- materialDef.pbrMetallicRoughness.roughnessFactor = 0.5;
7527
+ materialDef.pbrMetallicRoughness.metallicFactor = 0;
7528
+ materialDef.pbrMetallicRoughness.roughnessFactor = 1;
7291
7529
  }
7292
7530
  if (material.metalnessMap || material.roughnessMap) {
7293
- const metalRoughTexture = this.buildMetalRoughTexture(material.metalnessMap, material.roughnessMap);
7531
+ const metalRoughTexture = await this.buildMetalRoughTextureAsync(material.metalnessMap, material.roughnessMap);
7294
7532
  const metalRoughMapDef = {
7295
- index: this.processTexture(metalRoughTexture),
7296
- channel: metalRoughTexture.channel
7533
+ index: await this.processTextureAsync(metalRoughTexture),
7534
+ texCoord: metalRoughTexture.channel
7297
7535
  };
7298
7536
  this.applyTextureTransform(metalRoughMapDef, metalRoughTexture);
7299
7537
  materialDef.pbrMetallicRoughness.metallicRoughnessTexture = metalRoughMapDef;
7300
7538
  }
7301
7539
  if (material.map) {
7302
7540
  const baseColorMapDef = {
7303
- index: this.processTexture(material.map),
7541
+ index: await this.processTextureAsync(material.map),
7304
7542
  texCoord: material.map.channel
7305
7543
  };
7306
7544
  this.applyTextureTransform(baseColorMapDef, material.map);
@@ -7314,7 +7552,7 @@ var GLTFWriter = class {
7314
7552
  }
7315
7553
  if (material.emissiveMap) {
7316
7554
  const emissiveMapDef = {
7317
- index: this.processTexture(material.emissiveMap),
7555
+ index: await this.processTextureAsync(material.emissiveMap),
7318
7556
  texCoord: material.emissiveMap.channel
7319
7557
  };
7320
7558
  this.applyTextureTransform(emissiveMapDef, material.emissiveMap);
@@ -7322,19 +7560,32 @@ var GLTFWriter = class {
7322
7560
  }
7323
7561
  }
7324
7562
  if (material.normalMap) {
7563
+ const normalScale = material.normalScale;
7564
+ const flipX = normalScale.x < 0;
7565
+ const flipY = hasTangent ? normalScale.y < 0 : normalScale.y > 0;
7566
+ let normalMap = material.normalMap;
7567
+ if (flipX || flipY) {
7568
+ if (cache.normalMaps.has(material.normalMap) === false) cache.normalMaps.set(material.normalMap, {});
7569
+ const cachedVariants = cache.normalMaps.get(material.normalMap);
7570
+ const cacheKey2 = `${flipX}:${flipY}`;
7571
+ if (cachedVariants[cacheKey2] === void 0) {
7572
+ cachedVariants[cacheKey2] = await this.buildNormalMapTextureAsync(material.normalMap, flipX, flipY);
7573
+ }
7574
+ normalMap = cachedVariants[cacheKey2];
7575
+ }
7325
7576
  const normalMapDef = {
7326
- index: this.processTexture(material.normalMap),
7577
+ index: await this.processTextureAsync(normalMap),
7327
7578
  texCoord: material.normalMap.channel
7328
7579
  };
7329
- if (material.normalScale && material.normalScale.x !== 1) {
7330
- normalMapDef.scale = material.normalScale.x;
7580
+ if (Math.abs(normalScale.x) !== 1) {
7581
+ normalMapDef.scale = Math.abs(normalScale.x);
7331
7582
  }
7332
7583
  this.applyTextureTransform(normalMapDef, material.normalMap);
7333
7584
  materialDef.normalTexture = normalMapDef;
7334
7585
  }
7335
7586
  if (material.aoMap) {
7336
7587
  const occlusionMapDef = {
7337
- index: this.processTexture(material.aoMap),
7588
+ index: await this.processTextureAsync(material.aoMap),
7338
7589
  texCoord: material.aoMap.channel
7339
7590
  };
7340
7591
  if (material.aoMapIntensity !== 1) {
@@ -7351,22 +7602,22 @@ var GLTFWriter = class {
7351
7602
  materialDef.alphaCutoff = material.alphaTest;
7352
7603
  }
7353
7604
  }
7354
- if (material.side === import_three19.DoubleSide) materialDef.doubleSided = true;
7605
+ if (material.side === import_three18.DoubleSide) materialDef.doubleSided = true;
7355
7606
  if (material.name !== "") materialDef.name = material.name;
7356
7607
  this.serializeUserData(material, materialDef);
7357
- this._invokeAll(function(ext) {
7358
- ext.writeMaterial && ext.writeMaterial(material, materialDef);
7608
+ await this._invokeAllAsync(async function(ext) {
7609
+ ext.writeMaterialAsync && await ext.writeMaterialAsync(material, materialDef);
7359
7610
  });
7360
7611
  const index = json.materials.push(materialDef) - 1;
7361
- cache.materials.set(material, index);
7612
+ cache.materials.set(cacheKey, index);
7362
7613
  return index;
7363
7614
  }
7364
7615
  /**
7365
7616
  * Process mesh
7366
- * @param {THREE.Mesh} mesh Mesh to process
7367
- * @return {Integer|null} Index of the processed mesh in the "meshes" array
7617
+ * @param {THREE.Mesh} mesh Mesh to process
7618
+ * @return {Promise<?number>} Index of the processed mesh in the "meshes" array
7368
7619
  */
7369
- processMesh(mesh) {
7620
+ async processMeshAsync(mesh) {
7370
7621
  const cache = this.cache;
7371
7622
  const json = this.json;
7372
7623
  const meshCacheKeyParts = [mesh.geometry.uuid];
@@ -7416,7 +7667,7 @@ var GLTFWriter = class {
7416
7667
  const attribute = geometry.attributes[attributeName];
7417
7668
  attributeName = nameConversion[attributeName] || attributeName.toUpperCase();
7418
7669
  const validVertexAttributes = /^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/;
7419
- if (!validVertexAttributes.test(attributeName)) attributeName = "_" + attributeName;
7670
+ if (!validVertexAttributes.test(attributeName) && !attributeName.startsWith("_")) attributeName = "_" + attributeName;
7420
7671
  if (cache.attributes.has(this.getUID(attribute))) {
7421
7672
  attributes[attributeName] = cache.attributes.get(this.getUID(attribute));
7422
7673
  continue;
@@ -7425,7 +7676,10 @@ var GLTFWriter = class {
7425
7676
  const array = attribute.array;
7426
7677
  if (attributeName === "JOINTS_0" && !(array instanceof Uint16Array) && !(array instanceof Uint8Array)) {
7427
7678
  console.warn('GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.');
7428
- modifiedAttribute = new import_three19.BufferAttribute(new Uint16Array(array), attribute.itemSize, attribute.normalized);
7679
+ modifiedAttribute = GLTFExporter.Utils.toTypedBufferAttribute(attribute, Uint16Array);
7680
+ } else if ((array instanceof Uint32Array || array instanceof Int32Array) && !attributeName.startsWith("_")) {
7681
+ console.warn(`GLTFExporter: Attribute "${attributeName}" converted to type FLOAT.`);
7682
+ modifiedAttribute = GLTFExporter.Utils.toTypedBufferAttribute(attribute, Float32Array);
7429
7683
  }
7430
7684
  const accessor = this.processAccessor(modifiedAttribute || attribute, geometry);
7431
7685
  if (accessor !== null) {
@@ -7491,6 +7745,15 @@ var GLTFWriter = class {
7491
7745
  }
7492
7746
  const isMultiMaterial = Array.isArray(mesh.material);
7493
7747
  if (isMultiMaterial && geometry.groups.length === 0) return null;
7748
+ let didForceIndices = false;
7749
+ if (isMultiMaterial && geometry.index === null) {
7750
+ const indices = [];
7751
+ for (let i = 0, il = geometry.attributes.position.count; i < il; i++) {
7752
+ indices[i] = i;
7753
+ }
7754
+ geometry.setIndex(indices);
7755
+ didForceIndices = true;
7756
+ }
7494
7757
  const materials = isMultiMaterial ? mesh.material : [mesh.material];
7495
7758
  const groups = isMultiMaterial ? geometry.groups : [{ materialIndex: 0, start: void 0, count: void 0 }];
7496
7759
  for (let i = 0, il = groups.length; i < il; i++) {
@@ -7513,13 +7776,16 @@ var GLTFWriter = class {
7513
7776
  }
7514
7777
  if (primitive.indices === null) delete primitive.indices;
7515
7778
  }
7516
- const material = this.processMaterial(materials[groups[i].materialIndex]);
7779
+ const material = await this.processMaterialAsync(materials[groups[i].materialIndex], geometry);
7517
7780
  if (material !== null) primitive.material = material;
7518
7781
  primitives.push(primitive);
7519
7782
  }
7783
+ if (didForceIndices === true) {
7784
+ geometry.setIndex(null);
7785
+ }
7520
7786
  meshDef.primitives = primitives;
7521
7787
  if (!json.meshes) json.meshes = [];
7522
- this._invokeAll(function(ext) {
7788
+ await this._invokeAllAsync(function(ext) {
7523
7789
  ext.writeMesh && ext.writeMesh(mesh, meshDef);
7524
7790
  });
7525
7791
  const index = json.meshes.push(meshDef) - 1;
@@ -7565,8 +7831,8 @@ var GLTFWriter = class {
7565
7831
  }
7566
7832
  /**
7567
7833
  * Process camera
7568
- * @param {THREE.Camera} camera Camera to process
7569
- * @return {Integer} Index of the processed mesh in the "camera" array
7834
+ * @param {THREE.Camera} camera Camera to process
7835
+ * @return {number} Index of the processed mesh in the "camera" array
7570
7836
  */
7571
7837
  processCamera(camera) {
7572
7838
  const json = this.json;
@@ -7585,7 +7851,7 @@ var GLTFWriter = class {
7585
7851
  } else {
7586
7852
  cameraDef.perspective = {
7587
7853
  aspectRatio: camera.aspect,
7588
- yfov: import_three19.MathUtils.degToRad(camera.fov),
7854
+ yfov: import_three18.MathUtils.degToRad(camera.fov),
7589
7855
  zfar: camera.far <= 0 ? 1e-3 : camera.far,
7590
7856
  znear: camera.near < 0 ? 0 : camera.near
7591
7857
  };
@@ -7601,7 +7867,7 @@ var GLTFWriter = class {
7601
7867
  *
7602
7868
  * @param {THREE.AnimationClip} clip
7603
7869
  * @param {THREE.Object3D} root
7604
- * @return {number|null}
7870
+ * @return {?number}
7605
7871
  */
7606
7872
  processAnimation(clip, root) {
7607
7873
  const json = this.json;
@@ -7613,8 +7879,8 @@ var GLTFWriter = class {
7613
7879
  const samplers = [];
7614
7880
  for (let i = 0; i < tracks.length; ++i) {
7615
7881
  const track = tracks[i];
7616
- const trackBinding = import_three19.PropertyBinding.parseTrackName(track.name);
7617
- let trackNode = import_three19.PropertyBinding.findNode(root, trackBinding.nodeName);
7882
+ const trackBinding = import_three18.PropertyBinding.parseTrackName(track.name);
7883
+ let trackNode = import_three18.PropertyBinding.findNode(root, trackBinding.nodeName);
7618
7884
  const trackProperty = PATH_PROPERTIES[trackBinding.propertyName];
7619
7885
  if (trackBinding.objectName === "bones") {
7620
7886
  if (trackNode.isSkinnedMesh === true) {
@@ -7625,7 +7891,7 @@ var GLTFWriter = class {
7625
7891
  }
7626
7892
  if (!trackNode || !trackProperty) {
7627
7893
  console.warn('THREE.GLTFExporter: Could not export animation track "%s".', track.name);
7628
- return null;
7894
+ continue;
7629
7895
  }
7630
7896
  const inputItemSize = 1;
7631
7897
  let outputItemSize = track.values.length / track.times.length;
@@ -7636,14 +7902,14 @@ var GLTFWriter = class {
7636
7902
  if (track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline === true) {
7637
7903
  interpolation = "CUBICSPLINE";
7638
7904
  outputItemSize /= 3;
7639
- } else if (track.getInterpolation() === import_three19.InterpolateDiscrete) {
7905
+ } else if (track.getInterpolation() === import_three18.InterpolateDiscrete) {
7640
7906
  interpolation = "STEP";
7641
7907
  } else {
7642
7908
  interpolation = "LINEAR";
7643
7909
  }
7644
7910
  samplers.push({
7645
- input: this.processAccessor(new import_three19.BufferAttribute(track.times, inputItemSize)),
7646
- output: this.processAccessor(new import_three19.BufferAttribute(track.values, outputItemSize)),
7911
+ input: this.processAccessor(new import_three18.BufferAttribute(track.times, inputItemSize)),
7912
+ output: this.processAccessor(new import_three18.BufferAttribute(track.values, outputItemSize)),
7647
7913
  interpolation
7648
7914
  });
7649
7915
  channels.push({
@@ -7654,16 +7920,18 @@ var GLTFWriter = class {
7654
7920
  }
7655
7921
  });
7656
7922
  }
7657
- json.animations.push({
7923
+ const animationDef = {
7658
7924
  name: clip.name || "clip_" + json.animations.length,
7659
7925
  samplers,
7660
7926
  channels
7661
- });
7927
+ };
7928
+ this.serializeUserData(clip, animationDef);
7929
+ json.animations.push(animationDef);
7662
7930
  return json.animations.length - 1;
7663
7931
  }
7664
7932
  /**
7665
7933
  * @param {THREE.Object3D} object
7666
- * @return {number|null}
7934
+ * @return {?number}
7667
7935
  */
7668
7936
  processSkin(object) {
7669
7937
  const json = this.json;
@@ -7675,7 +7943,7 @@ var GLTFWriter = class {
7675
7943
  if (rootJoint === void 0) return null;
7676
7944
  const joints = [];
7677
7945
  const inverseBindMatrices = new Float32Array(skeleton.bones.length * 16);
7678
- const temporaryBoneInverse = new import_three19.Matrix4();
7946
+ const temporaryBoneInverse = new import_three18.Matrix4();
7679
7947
  for (let i = 0; i < skeleton.bones.length; ++i) {
7680
7948
  joints.push(nodeMap.get(skeleton.bones[i]));
7681
7949
  temporaryBoneInverse.copy(skeleton.boneInverses[i]);
@@ -7683,7 +7951,7 @@ var GLTFWriter = class {
7683
7951
  }
7684
7952
  if (json.skins === void 0) json.skins = [];
7685
7953
  json.skins.push({
7686
- inverseBindMatrices: this.processAccessor(new import_three19.BufferAttribute(inverseBindMatrices, 16)),
7954
+ inverseBindMatrices: this.processAccessor(new import_three18.BufferAttribute(inverseBindMatrices, 16)),
7687
7955
  joints,
7688
7956
  skeleton: nodeMap.get(rootJoint)
7689
7957
  });
@@ -7692,14 +7960,17 @@ var GLTFWriter = class {
7692
7960
  }
7693
7961
  /**
7694
7962
  * Process Object3D node
7695
- * @param {THREE.Object3D} node Object3D to processNode
7696
- * @return {Integer} Index of the node in the nodes list
7963
+ * @param {THREE.Object3D} object Object3D to processNodeAsync
7964
+ * @return {Promise<number>} Index of the node in the nodes list
7697
7965
  */
7698
- processNode(object) {
7966
+ async processNodeAsync(object) {
7699
7967
  const json = this.json;
7700
7968
  const options = this.options;
7701
7969
  const nodeMap = this.nodeMap;
7702
7970
  if (!json.nodes) json.nodes = [];
7971
+ if (object.pivot !== null) {
7972
+ return await this._processNodeWithPivotAsync(object);
7973
+ }
7703
7974
  const nodeDef = {};
7704
7975
  if (options.trs) {
7705
7976
  const rotation = object.quaternion.toArray();
@@ -7725,35 +7996,98 @@ var GLTFWriter = class {
7725
7996
  if (object.name !== "") nodeDef.name = String(object.name);
7726
7997
  this.serializeUserData(object, nodeDef);
7727
7998
  if (object.isMesh || object.isLine || object.isPoints) {
7728
- const meshIndex = this.processMesh(object);
7999
+ const meshIndex = await this.processMeshAsync(object);
7729
8000
  if (meshIndex !== null) nodeDef.mesh = meshIndex;
7730
8001
  } else if (object.isCamera) {
7731
8002
  nodeDef.camera = this.processCamera(object);
7732
8003
  }
7733
8004
  if (object.isSkinnedMesh) this.skins.push(object);
8005
+ const nodeIndex = json.nodes.push(nodeDef) - 1;
8006
+ nodeMap.set(object, nodeIndex);
7734
8007
  if (object.children.length > 0) {
7735
8008
  const children = [];
7736
8009
  for (let i = 0, l = object.children.length; i < l; i++) {
7737
8010
  const child = object.children[i];
7738
8011
  if (child.visible || options.onlyVisible === false) {
7739
- const nodeIndex2 = this.processNode(child);
7740
- if (nodeIndex2 !== null) children.push(nodeIndex2);
8012
+ const childNodeIndex = await this.processNodeAsync(child);
8013
+ if (childNodeIndex !== null) children.push(childNodeIndex);
7741
8014
  }
7742
8015
  }
7743
8016
  if (children.length > 0) nodeDef.children = children;
7744
8017
  }
7745
- this._invokeAll(function(ext) {
8018
+ await this._invokeAllAsync(function(ext) {
7746
8019
  ext.writeNode && ext.writeNode(object, nodeDef);
7747
8020
  });
7748
- const nodeIndex = json.nodes.push(nodeDef) - 1;
7749
- nodeMap.set(object, nodeIndex);
7750
8021
  return nodeIndex;
7751
8022
  }
8023
+ /**
8024
+ * Process Object3D node with pivot using container approach
8025
+ * @param {THREE.Object3D} object Object3D with pivot
8026
+ * @return {Promise<number>} Index of the container node
8027
+ */
8028
+ async _processNodeWithPivotAsync(object) {
8029
+ const json = this.json;
8030
+ const options = this.options;
8031
+ const nodeMap = this.nodeMap;
8032
+ const pivot = object.pivot;
8033
+ const containerDef = {};
8034
+ const rotation = object.quaternion.toArray();
8035
+ const position = [
8036
+ object.position.x + pivot.x,
8037
+ object.position.y + pivot.y,
8038
+ object.position.z + pivot.z
8039
+ ];
8040
+ const scale = object.scale.toArray();
8041
+ if (!equalArray(rotation, [0, 0, 0, 1])) {
8042
+ containerDef.rotation = rotation;
8043
+ }
8044
+ if (!equalArray(position, [0, 0, 0])) {
8045
+ containerDef.translation = position;
8046
+ }
8047
+ if (!equalArray(scale, [1, 1, 1])) {
8048
+ containerDef.scale = scale;
8049
+ }
8050
+ containerDef.extras = { pivot: pivot.toArray() };
8051
+ if (object.name !== "") containerDef.name = String(object.name);
8052
+ this.serializeUserData(object, containerDef);
8053
+ const containerIndex = json.nodes.push(containerDef) - 1;
8054
+ nodeMap.set(object, containerIndex);
8055
+ const childDef = {};
8056
+ const childPosition = [-pivot.x, -pivot.y, -pivot.z];
8057
+ if (!equalArray(childPosition, [0, 0, 0])) {
8058
+ childDef.translation = childPosition;
8059
+ }
8060
+ if (object.isMesh || object.isLine || object.isPoints) {
8061
+ const meshIndex = await this.processMeshAsync(object);
8062
+ if (meshIndex !== null) childDef.mesh = meshIndex;
8063
+ } else if (object.isCamera) {
8064
+ childDef.camera = this.processCamera(object);
8065
+ }
8066
+ if (object.isSkinnedMesh) this.skins.push(object);
8067
+ const childIndex = json.nodes.push(childDef) - 1;
8068
+ const containerChildren = [childIndex];
8069
+ if (object.children.length > 0) {
8070
+ const grandchildren = [];
8071
+ for (let i = 0, l = object.children.length; i < l; i++) {
8072
+ const child = object.children[i];
8073
+ if (child.visible || options.onlyVisible === false) {
8074
+ const childNodeIndex = await this.processNodeAsync(child);
8075
+ if (childNodeIndex !== null) grandchildren.push(childNodeIndex);
8076
+ }
8077
+ }
8078
+ if (grandchildren.length > 0) childDef.children = grandchildren;
8079
+ }
8080
+ containerDef.children = containerChildren;
8081
+ await this._invokeAllAsync(function(ext) {
8082
+ ext.writeNode && ext.writeNode(object, containerDef);
8083
+ });
8084
+ return containerIndex;
8085
+ }
7752
8086
  /**
7753
8087
  * Process Scene
7754
- * @param {Scene} node Scene to process
8088
+ * @param {Scene} scene Scene to process
7755
8089
  */
7756
- processScene(scene) {
8090
+ async processSceneAsync(scene) {
7757
8091
  const json = this.json;
7758
8092
  const options = this.options;
7759
8093
  if (!json.scenes) {
@@ -7767,7 +8101,7 @@ var GLTFWriter = class {
7767
8101
  for (let i = 0, l = scene.children.length; i < l; i++) {
7768
8102
  const child = scene.children[i];
7769
8103
  if (child.visible || options.onlyVisible === false) {
7770
- const nodeIndex = this.processNode(child);
8104
+ const nodeIndex = await this.processNodeAsync(child);
7771
8105
  if (nodeIndex !== null) nodes.push(nodeIndex);
7772
8106
  }
7773
8107
  }
@@ -7776,47 +8110,58 @@ var GLTFWriter = class {
7776
8110
  }
7777
8111
  /**
7778
8112
  * Creates a Scene to hold a list of objects and parse it
7779
- * @param {Array} objects List of objects to process
8113
+ * @param {Array<THREE.Object3D>} objects List of objects to process
7780
8114
  */
7781
- processObjects(objects) {
7782
- const scene = new import_three19.Scene();
8115
+ async processObjectsAsync(objects) {
8116
+ const scene = new import_three18.Scene();
7783
8117
  scene.name = "AuxScene";
7784
8118
  for (let i = 0; i < objects.length; i++) {
7785
8119
  scene.children.push(objects[i]);
7786
8120
  }
7787
- this.processScene(scene);
8121
+ await this.processSceneAsync(scene);
7788
8122
  }
7789
8123
  /**
7790
8124
  * @param {THREE.Object3D|Array<THREE.Object3D>} input
7791
8125
  */
7792
- processInput(input) {
8126
+ async processInputAsync(input) {
7793
8127
  const options = this.options;
7794
8128
  input = input instanceof Array ? input : [input];
7795
- this._invokeAll(function(ext) {
8129
+ await this._invokeAllAsync(function(ext) {
7796
8130
  ext.beforeParse && ext.beforeParse(input);
7797
8131
  });
7798
8132
  const objectsWithoutScene = [];
7799
8133
  for (let i = 0; i < input.length; i++) {
7800
- if (input[i] instanceof import_three19.Scene) {
7801
- this.processScene(input[i]);
8134
+ if (input[i] instanceof import_three18.Scene) {
8135
+ await this.processSceneAsync(input[i]);
7802
8136
  } else {
7803
8137
  objectsWithoutScene.push(input[i]);
7804
8138
  }
7805
8139
  }
7806
- if (objectsWithoutScene.length > 0) this.processObjects(objectsWithoutScene);
8140
+ if (objectsWithoutScene.length > 0) {
8141
+ await this.processObjectsAsync(objectsWithoutScene);
8142
+ }
7807
8143
  for (let i = 0; i < this.skins.length; ++i) {
7808
8144
  this.processSkin(this.skins[i]);
7809
8145
  }
7810
- for (let i = 0; i < options.animations.length; ++i) {
7811
- this.processAnimation(options.animations[i], input[0]);
8146
+ if (input.length === 1) {
8147
+ for (let i = 0; i < options.animations.length; ++i) {
8148
+ this.processAnimation(options.animations[i], input[0]);
8149
+ }
8150
+ } else {
8151
+ for (let i = 0; i < input.length; i++) {
8152
+ const animations = options.animations[i] || [];
8153
+ for (let j = 0; j < animations.length; ++j) {
8154
+ this.processAnimation(animations[j], input[i]);
8155
+ }
8156
+ }
7812
8157
  }
7813
- this._invokeAll(function(ext) {
8158
+ await this._invokeAllAsync(function(ext) {
7814
8159
  ext.afterParse && ext.afterParse(input);
7815
8160
  });
7816
8161
  }
7817
- _invokeAll(func) {
8162
+ async _invokeAllAsync(func) {
7818
8163
  for (let i = 0, il = this.plugins.length; i < il; i++) {
7819
- func(this.plugins[i]);
8164
+ await func(this.plugins[i]);
7820
8165
  }
7821
8166
  }
7822
8167
  };
@@ -7872,7 +8217,7 @@ var GLTFMaterialsUnlitExtension = class {
7872
8217
  this.writer = writer;
7873
8218
  this.name = "KHR_materials_unlit";
7874
8219
  }
7875
- writeMaterial(material, materialDef) {
8220
+ async writeMaterialAsync(material, materialDef) {
7876
8221
  if (!material.isMeshBasicMaterial) return;
7877
8222
  const writer = this.writer;
7878
8223
  const extensionsUsed = writer.extensionsUsed;
@@ -7888,7 +8233,7 @@ var GLTFMaterialsClearcoatExtension = class {
7888
8233
  this.writer = writer;
7889
8234
  this.name = "KHR_materials_clearcoat";
7890
8235
  }
7891
- writeMaterial(material, materialDef) {
8236
+ async writeMaterialAsync(material, materialDef) {
7892
8237
  if (!material.isMeshPhysicalMaterial || material.clearcoat === 0) return;
7893
8238
  const writer = this.writer;
7894
8239
  const extensionsUsed = writer.extensionsUsed;
@@ -7896,7 +8241,7 @@ var GLTFMaterialsClearcoatExtension = class {
7896
8241
  extensionDef.clearcoatFactor = material.clearcoat;
7897
8242
  if (material.clearcoatMap) {
7898
8243
  const clearcoatMapDef = {
7899
- index: writer.processTexture(material.clearcoatMap),
8244
+ index: await writer.processTextureAsync(material.clearcoatMap),
7900
8245
  texCoord: material.clearcoatMap.channel
7901
8246
  };
7902
8247
  writer.applyTextureTransform(clearcoatMapDef, material.clearcoatMap);
@@ -7905,7 +8250,7 @@ var GLTFMaterialsClearcoatExtension = class {
7905
8250
  extensionDef.clearcoatRoughnessFactor = material.clearcoatRoughness;
7906
8251
  if (material.clearcoatRoughnessMap) {
7907
8252
  const clearcoatRoughnessMapDef = {
7908
- index: writer.processTexture(material.clearcoatRoughnessMap),
8253
+ index: await writer.processTextureAsync(material.clearcoatRoughnessMap),
7909
8254
  texCoord: material.clearcoatRoughnessMap.channel
7910
8255
  };
7911
8256
  writer.applyTextureTransform(clearcoatRoughnessMapDef, material.clearcoatRoughnessMap);
@@ -7913,9 +8258,10 @@ var GLTFMaterialsClearcoatExtension = class {
7913
8258
  }
7914
8259
  if (material.clearcoatNormalMap) {
7915
8260
  const clearcoatNormalMapDef = {
7916
- index: writer.processTexture(material.clearcoatNormalMap),
8261
+ index: await writer.processTextureAsync(material.clearcoatNormalMap),
7917
8262
  texCoord: material.clearcoatNormalMap.channel
7918
8263
  };
8264
+ if (material.clearcoatNormalScale.x !== 1) clearcoatNormalMapDef.scale = material.clearcoatNormalScale.x;
7919
8265
  writer.applyTextureTransform(clearcoatNormalMapDef, material.clearcoatNormalMap);
7920
8266
  extensionDef.clearcoatNormalTexture = clearcoatNormalMapDef;
7921
8267
  }
@@ -7924,12 +8270,28 @@ var GLTFMaterialsClearcoatExtension = class {
7924
8270
  extensionsUsed[this.name] = true;
7925
8271
  }
7926
8272
  };
8273
+ var GLTFMaterialsDispersionExtension = class {
8274
+ constructor(writer) {
8275
+ this.writer = writer;
8276
+ this.name = "KHR_materials_dispersion";
8277
+ }
8278
+ async writeMaterialAsync(material, materialDef) {
8279
+ if (!material.isMeshPhysicalMaterial || material.dispersion === 0) return;
8280
+ const writer = this.writer;
8281
+ const extensionsUsed = writer.extensionsUsed;
8282
+ const extensionDef = {};
8283
+ extensionDef.dispersion = material.dispersion;
8284
+ materialDef.extensions = materialDef.extensions || {};
8285
+ materialDef.extensions[this.name] = extensionDef;
8286
+ extensionsUsed[this.name] = true;
8287
+ }
8288
+ };
7927
8289
  var GLTFMaterialsIridescenceExtension = class {
7928
8290
  constructor(writer) {
7929
8291
  this.writer = writer;
7930
8292
  this.name = "KHR_materials_iridescence";
7931
8293
  }
7932
- writeMaterial(material, materialDef) {
8294
+ async writeMaterialAsync(material, materialDef) {
7933
8295
  if (!material.isMeshPhysicalMaterial || material.iridescence === 0) return;
7934
8296
  const writer = this.writer;
7935
8297
  const extensionsUsed = writer.extensionsUsed;
@@ -7937,7 +8299,7 @@ var GLTFMaterialsIridescenceExtension = class {
7937
8299
  extensionDef.iridescenceFactor = material.iridescence;
7938
8300
  if (material.iridescenceMap) {
7939
8301
  const iridescenceMapDef = {
7940
- index: writer.processTexture(material.iridescenceMap),
8302
+ index: await writer.processTextureAsync(material.iridescenceMap),
7941
8303
  texCoord: material.iridescenceMap.channel
7942
8304
  };
7943
8305
  writer.applyTextureTransform(iridescenceMapDef, material.iridescenceMap);
@@ -7948,7 +8310,7 @@ var GLTFMaterialsIridescenceExtension = class {
7948
8310
  extensionDef.iridescenceThicknessMaximum = material.iridescenceThicknessRange[1];
7949
8311
  if (material.iridescenceThicknessMap) {
7950
8312
  const iridescenceThicknessMapDef = {
7951
- index: writer.processTexture(material.iridescenceThicknessMap),
8313
+ index: await writer.processTextureAsync(material.iridescenceThicknessMap),
7952
8314
  texCoord: material.iridescenceThicknessMap.channel
7953
8315
  };
7954
8316
  writer.applyTextureTransform(iridescenceThicknessMapDef, material.iridescenceThicknessMap);
@@ -7964,7 +8326,7 @@ var GLTFMaterialsTransmissionExtension = class {
7964
8326
  this.writer = writer;
7965
8327
  this.name = "KHR_materials_transmission";
7966
8328
  }
7967
- writeMaterial(material, materialDef) {
8329
+ async writeMaterialAsync(material, materialDef) {
7968
8330
  if (!material.isMeshPhysicalMaterial || material.transmission === 0) return;
7969
8331
  const writer = this.writer;
7970
8332
  const extensionsUsed = writer.extensionsUsed;
@@ -7972,7 +8334,7 @@ var GLTFMaterialsTransmissionExtension = class {
7972
8334
  extensionDef.transmissionFactor = material.transmission;
7973
8335
  if (material.transmissionMap) {
7974
8336
  const transmissionMapDef = {
7975
- index: writer.processTexture(material.transmissionMap),
8337
+ index: await writer.processTextureAsync(material.transmissionMap),
7976
8338
  texCoord: material.transmissionMap.channel
7977
8339
  };
7978
8340
  writer.applyTextureTransform(transmissionMapDef, material.transmissionMap);
@@ -7988,7 +8350,7 @@ var GLTFMaterialsVolumeExtension = class {
7988
8350
  this.writer = writer;
7989
8351
  this.name = "KHR_materials_volume";
7990
8352
  }
7991
- writeMaterial(material, materialDef) {
8353
+ async writeMaterialAsync(material, materialDef) {
7992
8354
  if (!material.isMeshPhysicalMaterial || material.transmission === 0) return;
7993
8355
  const writer = this.writer;
7994
8356
  const extensionsUsed = writer.extensionsUsed;
@@ -7996,13 +8358,15 @@ var GLTFMaterialsVolumeExtension = class {
7996
8358
  extensionDef.thicknessFactor = material.thickness;
7997
8359
  if (material.thicknessMap) {
7998
8360
  const thicknessMapDef = {
7999
- index: writer.processTexture(material.thicknessMap),
8361
+ index: await writer.processTextureAsync(material.thicknessMap),
8000
8362
  texCoord: material.thicknessMap.channel
8001
8363
  };
8002
8364
  writer.applyTextureTransform(thicknessMapDef, material.thicknessMap);
8003
8365
  extensionDef.thicknessTexture = thicknessMapDef;
8004
8366
  }
8005
- extensionDef.attenuationDistance = material.attenuationDistance;
8367
+ if (material.attenuationDistance !== Infinity) {
8368
+ extensionDef.attenuationDistance = material.attenuationDistance;
8369
+ }
8006
8370
  extensionDef.attenuationColor = material.attenuationColor.toArray();
8007
8371
  materialDef.extensions = materialDef.extensions || {};
8008
8372
  materialDef.extensions[this.name] = extensionDef;
@@ -8014,7 +8378,7 @@ var GLTFMaterialsIorExtension = class {
8014
8378
  this.writer = writer;
8015
8379
  this.name = "KHR_materials_ior";
8016
8380
  }
8017
- writeMaterial(material, materialDef) {
8381
+ async writeMaterialAsync(material, materialDef) {
8018
8382
  if (!material.isMeshPhysicalMaterial || material.ior === 1.5) return;
8019
8383
  const writer = this.writer;
8020
8384
  const extensionsUsed = writer.extensionsUsed;
@@ -8030,14 +8394,14 @@ var GLTFMaterialsSpecularExtension = class {
8030
8394
  this.writer = writer;
8031
8395
  this.name = "KHR_materials_specular";
8032
8396
  }
8033
- writeMaterial(material, materialDef) {
8034
- if (!material.isMeshPhysicalMaterial || material.specularIntensity === 1 && material.specularColor.equals(DEFAULT_SPECULAR_COLOR) && !material.specularIntensityMap && !material.specularColorTexture) return;
8397
+ async writeMaterialAsync(material, materialDef) {
8398
+ if (!material.isMeshPhysicalMaterial || material.specularIntensity === 1 && material.specularColor.equals(DEFAULT_SPECULAR_COLOR) && !material.specularIntensityMap && !material.specularColorMap) return;
8035
8399
  const writer = this.writer;
8036
8400
  const extensionsUsed = writer.extensionsUsed;
8037
8401
  const extensionDef = {};
8038
8402
  if (material.specularIntensityMap) {
8039
8403
  const specularIntensityMapDef = {
8040
- index: writer.processTexture(material.specularIntensityMap),
8404
+ index: await writer.processTextureAsync(material.specularIntensityMap),
8041
8405
  texCoord: material.specularIntensityMap.channel
8042
8406
  };
8043
8407
  writer.applyTextureTransform(specularIntensityMapDef, material.specularIntensityMap);
@@ -8045,7 +8409,7 @@ var GLTFMaterialsSpecularExtension = class {
8045
8409
  }
8046
8410
  if (material.specularColorMap) {
8047
8411
  const specularColorMapDef = {
8048
- index: writer.processTexture(material.specularColorMap),
8412
+ index: await writer.processTextureAsync(material.specularColorMap),
8049
8413
  texCoord: material.specularColorMap.channel
8050
8414
  };
8051
8415
  writer.applyTextureTransform(specularColorMapDef, material.specularColorMap);
@@ -8063,14 +8427,14 @@ var GLTFMaterialsSheenExtension = class {
8063
8427
  this.writer = writer;
8064
8428
  this.name = "KHR_materials_sheen";
8065
8429
  }
8066
- writeMaterial(material, materialDef) {
8430
+ async writeMaterialAsync(material, materialDef) {
8067
8431
  if (!material.isMeshPhysicalMaterial || material.sheen == 0) return;
8068
8432
  const writer = this.writer;
8069
8433
  const extensionsUsed = writer.extensionsUsed;
8070
8434
  const extensionDef = {};
8071
8435
  if (material.sheenRoughnessMap) {
8072
8436
  const sheenRoughnessMapDef = {
8073
- index: writer.processTexture(material.sheenRoughnessMap),
8437
+ index: await writer.processTextureAsync(material.sheenRoughnessMap),
8074
8438
  texCoord: material.sheenRoughnessMap.channel
8075
8439
  };
8076
8440
  writer.applyTextureTransform(sheenRoughnessMapDef, material.sheenRoughnessMap);
@@ -8078,7 +8442,7 @@ var GLTFMaterialsSheenExtension = class {
8078
8442
  }
8079
8443
  if (material.sheenColorMap) {
8080
8444
  const sheenColorMapDef = {
8081
- index: writer.processTexture(material.sheenColorMap),
8445
+ index: await writer.processTextureAsync(material.sheenColorMap),
8082
8446
  texCoord: material.sheenColorMap.channel
8083
8447
  };
8084
8448
  writer.applyTextureTransform(sheenColorMapDef, material.sheenColorMap);
@@ -8096,13 +8460,13 @@ var GLTFMaterialsAnisotropyExtension = class {
8096
8460
  this.writer = writer;
8097
8461
  this.name = "KHR_materials_anisotropy";
8098
8462
  }
8099
- writeMaterial(material, materialDef) {
8463
+ async writeMaterialAsync(material, materialDef) {
8100
8464
  if (!material.isMeshPhysicalMaterial || material.anisotropy == 0) return;
8101
8465
  const writer = this.writer;
8102
8466
  const extensionsUsed = writer.extensionsUsed;
8103
8467
  const extensionDef = {};
8104
8468
  if (material.anisotropyMap) {
8105
- const anisotropyMapDef = { index: writer.processTexture(material.anisotropyMap) };
8469
+ const anisotropyMapDef = { index: await writer.processTextureAsync(material.anisotropyMap) };
8106
8470
  writer.applyTextureTransform(anisotropyMapDef, material.anisotropyMap);
8107
8471
  extensionDef.anisotropyTexture = anisotropyMapDef;
8108
8472
  }
@@ -8118,7 +8482,7 @@ var GLTFMaterialsEmissiveStrengthExtension = class {
8118
8482
  this.writer = writer;
8119
8483
  this.name = "KHR_materials_emissive_strength";
8120
8484
  }
8121
- writeMaterial(material, materialDef) {
8485
+ async writeMaterialAsync(material, materialDef) {
8122
8486
  if (!material.isMeshStandardMaterial || material.emissiveIntensity === 1) return;
8123
8487
  const writer = this.writer;
8124
8488
  const extensionsUsed = writer.extensionsUsed;
@@ -8129,6 +8493,30 @@ var GLTFMaterialsEmissiveStrengthExtension = class {
8129
8493
  extensionsUsed[this.name] = true;
8130
8494
  }
8131
8495
  };
8496
+ var GLTFMaterialsBumpExtension = class {
8497
+ constructor(writer) {
8498
+ this.writer = writer;
8499
+ this.name = "EXT_materials_bump";
8500
+ }
8501
+ async writeMaterialAsync(material, materialDef) {
8502
+ if (!material.isMeshStandardMaterial || material.bumpScale === 1 && !material.bumpMap) return;
8503
+ const writer = this.writer;
8504
+ const extensionsUsed = writer.extensionsUsed;
8505
+ const extensionDef = {};
8506
+ if (material.bumpMap) {
8507
+ const bumpMapDef = {
8508
+ index: await writer.processTextureAsync(material.bumpMap),
8509
+ texCoord: material.bumpMap.channel
8510
+ };
8511
+ writer.applyTextureTransform(bumpMapDef, material.bumpMap);
8512
+ extensionDef.bumpTexture = bumpMapDef;
8513
+ }
8514
+ extensionDef.bumpFactor = material.bumpScale;
8515
+ materialDef.extensions = materialDef.extensions || {};
8516
+ materialDef.extensions[this.name] = extensionDef;
8517
+ extensionsUsed[this.name] = true;
8518
+ }
8519
+ };
8132
8520
  var GLTFMeshGpuInstancing = class {
8133
8521
  constructor(writer) {
8134
8522
  this.writer = writer;
@@ -8141,10 +8529,10 @@ var GLTFMeshGpuInstancing = class {
8141
8529
  const translationAttr = new Float32Array(mesh.count * 3);
8142
8530
  const rotationAttr = new Float32Array(mesh.count * 4);
8143
8531
  const scaleAttr = new Float32Array(mesh.count * 3);
8144
- const matrix = new import_three19.Matrix4();
8145
- const position = new import_three19.Vector3();
8146
- const quaternion = new import_three19.Quaternion();
8147
- const scale = new import_three19.Vector3();
8532
+ const matrix = new import_three18.Matrix4();
8533
+ const position = new import_three18.Vector3();
8534
+ const quaternion = new import_three18.Quaternion();
8535
+ const scale = new import_three18.Vector3();
8148
8536
  for (let i = 0; i < mesh.count; i++) {
8149
8537
  mesh.getMatrixAt(i, matrix);
8150
8538
  matrix.decompose(position, quaternion, scale);
@@ -8153,9 +8541,9 @@ var GLTFMeshGpuInstancing = class {
8153
8541
  scale.toArray(scaleAttr, i * 3);
8154
8542
  }
8155
8543
  const attributes = {
8156
- TRANSLATION: writer.processAccessor(new import_three19.BufferAttribute(translationAttr, 3)),
8157
- ROTATION: writer.processAccessor(new import_three19.BufferAttribute(rotationAttr, 4)),
8158
- SCALE: writer.processAccessor(new import_three19.BufferAttribute(scaleAttr, 3))
8544
+ TRANSLATION: writer.processAccessor(new import_three18.BufferAttribute(translationAttr, 3)),
8545
+ ROTATION: writer.processAccessor(new import_three18.BufferAttribute(rotationAttr, 4)),
8546
+ SCALE: writer.processAccessor(new import_three18.BufferAttribute(scaleAttr, 3))
8159
8547
  };
8160
8548
  if (mesh.instanceColor)
8161
8549
  attributes._COLOR_0 = writer.processAccessor(mesh.instanceColor);
@@ -8220,8 +8608,8 @@ GLTFExporter.Utils = {
8220
8608
  const sourceTracks = clip.tracks;
8221
8609
  for (let i = 0; i < sourceTracks.length; ++i) {
8222
8610
  let sourceTrack = sourceTracks[i];
8223
- const sourceTrackBinding = import_three19.PropertyBinding.parseTrackName(sourceTrack.name);
8224
- const sourceTrackNode = import_three19.PropertyBinding.findNode(root, sourceTrackBinding.nodeName);
8611
+ const sourceTrackBinding = import_three18.PropertyBinding.parseTrackName(sourceTrack.name);
8612
+ const sourceTrackNode = import_three18.PropertyBinding.findNode(root, sourceTrackBinding.nodeName);
8225
8613
  if (sourceTrackBinding.propertyName !== "morphTargetInfluences" || sourceTrackBinding.propertyIndex === void 0) {
8226
8614
  tracks.push(sourceTrack);
8227
8615
  continue;
@@ -8232,7 +8620,7 @@ GLTFExporter.Utils = {
8232
8620
  }
8233
8621
  console.warn("THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead.");
8234
8622
  sourceTrack = sourceTrack.clone();
8235
- sourceTrack.setInterpolation(import_three19.InterpolateLinear);
8623
+ sourceTrack.setInterpolation(import_three18.InterpolateLinear);
8236
8624
  }
8237
8625
  const targetCount = sourceTrackNode.morphTargetInfluences.length;
8238
8626
  const targetIndex = sourceTrackNode.morphTargetDictionary[sourceTrackBinding.propertyIndex];
@@ -8264,6 +8652,19 @@ GLTFExporter.Utils = {
8264
8652
  }
8265
8653
  clip.tracks = tracks;
8266
8654
  return clip;
8655
+ },
8656
+ toTypedBufferAttribute: function(srcAttribute, TypedArray) {
8657
+ const dstAttribute = new import_three18.BufferAttribute(new TypedArray(srcAttribute.count * srcAttribute.itemSize), srcAttribute.itemSize, false);
8658
+ if (!srcAttribute.normalized && !srcAttribute.isInterleavedBufferAttribute) {
8659
+ dstAttribute.array.set(srcAttribute.array);
8660
+ return dstAttribute;
8661
+ }
8662
+ for (let i = 0, il = srcAttribute.count; i < il; i++) {
8663
+ for (let j = 0; j < srcAttribute.itemSize; j++) {
8664
+ dstAttribute.setComponent(i, j, srcAttribute.getComponent(i, j));
8665
+ }
8666
+ }
8667
+ return dstAttribute;
8267
8668
  }
8268
8669
  };
8269
8670
 
@@ -8315,10 +8716,10 @@ var SceneExporter = class {
8315
8716
  }
8316
8717
  };
8317
8718
  function localMatrix(object) {
8318
- return object.matrixAutoUpdate ? new import_three20.Matrix4().compose(object.position, object.quaternion, object.scale) : object.matrix.clone();
8719
+ return object.matrixAutoUpdate ? new import_three19.Matrix4().compose(object.position, object.quaternion, object.scale) : object.matrix.clone();
8319
8720
  }
8320
8721
  function createSnapshot(root, gltf, bakeColors = false) {
8321
- const scene = new import_three20.Scene();
8722
+ const scene = new import_three19.Scene();
8322
8723
  const geometries = [];
8323
8724
  const materials = [];
8324
8725
  const textures = [];
@@ -8336,7 +8737,7 @@ function createSnapshot(root, gltf, bakeColors = false) {
8336
8737
  if (!uniforms.map?.value?.isTexture || !uniforms.SHADE || !uniforms.BRIGHTNESS || !uniforms.EMISSIVE) {
8337
8738
  throw new MineRenderError("glTF export does not support this custom ShaderMaterial");
8338
8739
  }
8339
- material = new import_three20.MeshBasicMaterial({
8740
+ material = new import_three19.MeshBasicMaterial({
8340
8741
  map: uniforms.map.value,
8341
8742
  vertexColors: source.vertexColors,
8342
8743
  transparent: source.transparent,
@@ -8346,7 +8747,7 @@ function createSnapshot(root, gltf, bakeColors = false) {
8346
8747
  });
8347
8748
  material.name = source.name;
8348
8749
  } else if (shader.isShaderMaterial) {
8349
- material = new import_three20.MeshBasicMaterial({ vertexColors: source.vertexColors });
8750
+ material = new import_three19.MeshBasicMaterial({ vertexColors: source.vertexColors });
8350
8751
  material.name = source.name;
8351
8752
  } else {
8352
8753
  const copySource = Object.create(source);
@@ -8400,11 +8801,11 @@ function createSnapshot(root, gltf, bakeColors = false) {
8400
8801
  const material = copyMaterial(sourceMaterial, geometry);
8401
8802
  if (!sourceMaterial.vertexColors) geometry.deleteAttribute("color");
8402
8803
  if (bakeColors || instanceColor) {
8403
- const tint = (material.color ?? new import_three20.Color()).clone();
8804
+ const tint = (material.color ?? new import_three19.Color()).clone();
8404
8805
  if (instanceColor) tint.multiply(instanceColor);
8405
8806
  if (bakeColors) {
8406
8807
  const original = geometry.getAttribute("color");
8407
- const colors = new import_three20.Float32BufferAttribute(new Float32Array(geometry.getAttribute("position").count * 3), 3);
8808
+ const colors = new import_three19.Float32BufferAttribute(new Float32Array(geometry.getAttribute("position").count * 3), 3);
8408
8809
  for (let i = 0; i < colors.count; i++) {
8409
8810
  colors.setXYZ(i, (original?.getX(i) ?? 1) * tint.r, (original?.getY(i) ?? 1) * tint.g, (original?.getZ(i) ?? 1) * tint.b);
8410
8811
  }
@@ -8413,7 +8814,7 @@ function createSnapshot(root, gltf, bakeColors = false) {
8413
8814
  material.color.copy(tint);
8414
8815
  }
8415
8816
  }
8416
- const copy = new import_three20.Mesh(geometry, material);
8817
+ const copy = new import_three19.Mesh(geometry, material);
8417
8818
  copy.name = mesh.name;
8418
8819
  copy.renderOrder = mesh.renderOrder;
8419
8820
  scene.add(copy);
@@ -8427,9 +8828,9 @@ function createSnapshot(root, gltf, bakeColors = false) {
8427
8828
  const instanced = mesh;
8428
8829
  if (instanced.isInstancedMesh) {
8429
8830
  for (let i = 0; i < instanced.count; i++) {
8430
- const matrix = new import_three20.Matrix4();
8831
+ const matrix = new import_three19.Matrix4();
8431
8832
  instanced.getMatrixAt(i, matrix);
8432
- const color = instanced.instanceColor ? new import_three20.Color().fromBufferAttribute(instanced.instanceColor, i) : void 0;
8833
+ const color = instanced.instanceColor ? new import_three19.Color().fromBufferAttribute(instanced.instanceColor, i) : void 0;
8433
8834
  addMesh(mesh, world.clone().multiply(matrix), color);
8434
8835
  }
8435
8836
  } else {
@@ -8441,7 +8842,7 @@ function createSnapshot(root, gltf, bakeColors = false) {
8441
8842
  try {
8442
8843
  const ancestors = [];
8443
8844
  for (let parent = root.parent; parent; parent = parent.parent) ancestors.unshift(parent);
8444
- const world = new import_three20.Matrix4();
8845
+ const world = new import_three19.Matrix4();
8445
8846
  for (const ancestor of ancestors) {
8446
8847
  if (!ancestor.visible) return { scene, dispose };
8447
8848
  world.multiply(localMatrix(ancestor));
@@ -8455,7 +8856,7 @@ function createSnapshot(root, gltf, bakeColors = false) {
8455
8856
  }
8456
8857
  function selectAlphaMode(material, geometry) {
8457
8858
  const texture = material.map;
8458
- if (material.type !== "MeshBasicMaterial" || !material.transparent || !material.depthWrite || material.opacity !== 1 || material.alphaMap || !texture?.isDataTexture || texture.format !== import_three20.RGBAFormat || texture.type !== import_three20.UnsignedByteType || texture.wrapS !== import_three20.ClampToEdgeWrapping || texture.wrapT !== import_three20.ClampToEdgeWrapping || texture.magFilter !== import_three20.NearestFilter || texture.minFilter !== import_three20.NearestFilter || texture.anisotropy > 1 || texture.offset.x !== 0 || texture.offset.y !== 0 || texture.repeat.x !== 1 || texture.repeat.y !== 1 || texture.rotation !== 0 || !texture.matrixAutoUpdate && !texture.matrix.elements.every((value, i) => value === (i % 4 === 0 ? 1 : 0))) return;
8859
+ if (material.type !== "MeshBasicMaterial" || !material.transparent || !material.depthWrite || material.opacity !== 1 || material.alphaMap || !texture?.isDataTexture || texture.format !== import_three19.RGBAFormat || texture.type !== import_three19.UnsignedByteType || texture.wrapS !== import_three19.ClampToEdgeWrapping || texture.wrapT !== import_three19.ClampToEdgeWrapping || texture.magFilter !== import_three19.NearestFilter || texture.minFilter !== import_three19.NearestFilter || texture.anisotropy > 1 || texture.offset.x !== 0 || texture.offset.y !== 0 || texture.repeat.x !== 1 || texture.repeat.y !== 1 || texture.rotation !== 0 || !texture.matrixAutoUpdate && !texture.matrix.elements.every((value, i) => value === (i % 4 === 0 ? 1 : 0))) return;
8459
8860
  const uv = geometry.getAttribute(texture.channel === 0 ? "uv" : `uv${texture.channel}`);
8460
8861
  const colors = geometry.getAttribute("color");
8461
8862
  if (!uv || material.vertexColors && colors?.itemSize === 4) return;
@@ -8492,7 +8893,7 @@ function selectAlphaMode(material, geometry) {
8492
8893
  }
8493
8894
  function copyDataTexture(source) {
8494
8895
  const image = source.image;
8495
- if (source.format !== import_three20.RGBAFormat || source.type !== import_three20.UnsignedByteType) {
8896
+ if (!image.data || source.format !== import_three19.RGBAFormat || source.type !== import_three19.UnsignedByteType) {
8496
8897
  throw new MineRenderError("glTF export requires RGBA unsigned-byte data textures");
8497
8898
  }
8498
8899
  const canvas = createCanvas2(image.width, image.height);
@@ -8503,8 +8904,8 @@ function copyDataTexture(source) {
8503
8904
  context.putImageData(pixels, 0, 0);
8504
8905
  const copySource = Object.create(source);
8505
8906
  copySource.userData = {};
8506
- copySource.source = new import_three20.Source(canvas);
8507
- return new import_three20.Texture().copy(copySource);
8907
+ copySource.source = new import_three19.TextureSource(canvas);
8908
+ return new import_three19.Texture().copy(copySource);
8508
8909
  }
8509
8910
 
8510
8911
  // src/gui/GuiHelper.ts
@@ -8573,6 +8974,85 @@ var GuiHelper = class {
8573
8974
  }
8574
8975
  };
8575
8976
 
8977
+ // src/gui/GuiTextureGeometry.ts
8978
+ var import_three20 = require("three");
8979
+ function createGuiTextureGeometry(width, height, imageWidth, imageHeight, crop, scaling) {
8980
+ if (crop || !scaling || scaling.type === "stretch") {
8981
+ const [x, y, w, h] = crop ?? [0, 0, imageWidth, imageHeight];
8982
+ const geometry = new import_three20.PlaneGeometry(width, height);
8983
+ const uv = geometry.getAttribute("uv");
8984
+ for (let i = 0; i < uv.count; i++) {
8985
+ uv.setXY(
8986
+ i,
8987
+ (x + uv.getX(i) * w) / imageWidth,
8988
+ 1 - (y + (1 - uv.getY(i)) * h) / imageHeight
8989
+ );
8990
+ }
8991
+ return geometry;
8992
+ }
8993
+ const sw = scaling.width, sh = scaling.height;
8994
+ if (![sw, sh].every((value) => Number.isInteger(value) && value > 0)) {
8995
+ throw new Error("GUI sprite dimensions must be positive integers");
8996
+ }
8997
+ if (![width, height].every((value) => Number.isFinite(value) && value >= 0)) {
8998
+ throw new Error("GUI output dimensions must be finite and nonnegative");
8999
+ }
9000
+ const positions = [], uvs = [], normals = [], indices = [];
9001
+ function quad(x, y, w, h, u, v, uw, vh) {
9002
+ if (w <= 0 || h <= 0) return;
9003
+ const index = positions.length / 3;
9004
+ const left = x - width / 2, top = height / 2 - y;
9005
+ positions.push(left, top, 0, left + w, top, 0, left, top - h, 0, left + w, top - h, 0);
9006
+ uvs.push(
9007
+ u / sw,
9008
+ 1 - v / sh,
9009
+ (u + uw) / sw,
9010
+ 1 - v / sh,
9011
+ u / sw,
9012
+ 1 - (v + vh) / sh,
9013
+ (u + uw) / sw,
9014
+ 1 - (v + vh) / sh
9015
+ );
9016
+ normals.push(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1);
9017
+ indices.push(index, index + 2, index + 1, index + 2, index + 3, index + 1);
9018
+ }
9019
+ function tile(x, y, w, h, u, v, tw, th) {
9020
+ for (let dy = 0; dy < h; dy += th) {
9021
+ for (let dx = 0; dx < w; dx += tw) {
9022
+ const cw = Math.min(tw, w - dx), ch = Math.min(th, h - dy);
9023
+ quad(x + dx, y + dy, cw, ch, u, v, cw, ch);
9024
+ }
9025
+ }
9026
+ }
9027
+ if (scaling.type === "tile") {
9028
+ tile(0, 0, width, height, 0, 0, sw, sh);
9029
+ } else {
9030
+ let segments = function(size, sourceSize, start, end) {
9031
+ if (size === sourceSize) return [[0, size, 0, sourceSize]];
9032
+ start = Math.min(start, Math.floor(size / 2));
9033
+ end = Math.min(end, Math.floor(size / 2));
9034
+ return [
9035
+ [0, start, 0, start],
9036
+ [start, size - start - end, start, sourceSize - start - end],
9037
+ [size - end, end, sourceSize - end, end]
9038
+ ];
9039
+ };
9040
+ const border = typeof scaling.border === "number" ? { left: scaling.border, top: scaling.border, right: scaling.border, bottom: scaling.border } : scaling.border;
9041
+ if (!border || typeof scaling.border === "number" && scaling.border <= 0 || ![border.left, border.top, border.right, border.bottom].every((value) => Number.isInteger(value) && value >= 0) || border.left + border.right >= sw || border.top + border.bottom >= sh) {
9042
+ throw new Error("GUI nine-slice borders must be nonnegative integers with a nonempty center");
9043
+ }
9044
+ const columns = segments(width, sw, border.left, border.right);
9045
+ const rows = segments(height, sh, border.top, border.bottom);
9046
+ for (const [y, h, v, vh] of rows) {
9047
+ for (const [x, w, u, uw] of columns) {
9048
+ if (w <= 0 || h <= 0) continue;
9049
+ (scaling.stretch_inner ? quad : tile)(x, y, w, h, u, v, uw, vh);
9050
+ }
9051
+ }
9052
+ }
9053
+ return new import_three20.BufferGeometry().setAttribute("position", new import_three20.Float32BufferAttribute(positions, 3)).setAttribute("normal", new import_three20.Float32BufferAttribute(normals, 3)).setAttribute("uv", new import_three20.Float32BufferAttribute(uvs, 2)).setIndex(indices);
9054
+ }
9055
+
8576
9056
  // src/gui/scene/GuiObject.ts
8577
9057
  var import_three25 = require("three");
8578
9058
  init_AssetKey();
@@ -8624,18 +9104,10 @@ var GuiObject = class extends SceneObject {
8624
9104
  const key = typeof layer.texture === "string" ? AssetKey.parse("textures", layer.texture) : layer.texture;
8625
9105
  const material = await this.loadMaterial(key);
8626
9106
  const image = material.map.image;
8627
- const [cropX, cropY, cropWidth, cropHeight] = layer.crop ?? [0, 0, image.width, image.height];
8628
- const [width, height] = layer.size ?? [cropWidth, cropHeight];
8629
- const geometry = new import_three25.PlaneGeometry(width, height);
9107
+ const scaling = layer.crop ? void 0 : (await ModelTextures.getMeta(key))?.gui?.scaling;
9108
+ const [width, height] = layer.size ?? (layer.crop ? layer.crop.slice(2) : scaling && scaling.type !== "stretch" ? [scaling.width, scaling.height] : [image.width, image.height]);
9109
+ const geometry = createGuiTextureGeometry(width, height, image.width, image.height, layer.crop, scaling);
8630
9110
  this.geometries.add(geometry);
8631
- const uv = geometry.getAttribute("uv");
8632
- for (let i = 0; i < uv.count; i++) {
8633
- uv.setXY(
8634
- i,
8635
- (cropX + uv.getX(i) * cropWidth) / image.width,
8636
- 1 - (cropY + (1 - uv.getY(i)) * cropHeight) / image.height
8637
- );
8638
- }
8639
9111
  const mesh = new import_three25.Mesh(geometry, material);
8640
9112
  mesh.name = `mesh:${layer.name ?? index}`;
8641
9113
  mesh.position.set(x + width / 2, -y - height / 2, depth);
@@ -9478,6 +9950,7 @@ var BlockObject = class _BlockObject extends SceneObject {
9478
9950
  replacement.setMatrix(matrix);
9479
9951
  } else {
9480
9952
  replacement.matrix.copy(matrix);
9953
+ replacement.matrixWorldNeedsUpdate = true;
9481
9954
  matrix.decompose(replacement.position, replacement.quaternion, replacement.scale);
9482
9955
  replacement.matrixAutoUpdate = object.matrixAutoUpdate;
9483
9956
  replacement.visible = object.visible;
@@ -12630,12 +13103,13 @@ var MineRenderScene = class _MineRenderScene extends import_three33.Scene {
12630
13103
  }
12631
13104
  updateObjectRegistration(object, attached) {
12632
13105
  if (this.observedObjects.has(object) === attached) return;
13106
+ const observable = object;
12633
13107
  if (attached) {
12634
13108
  this.observedObjects.add(object);
12635
- object.addEventListener("change", this.onObjectChange);
13109
+ observable.addEventListener("change", this.onObjectChange);
12636
13110
  } else {
12637
13111
  this.observedObjects.delete(object);
12638
- object.removeEventListener("change", this.onObjectChange);
13112
+ observable.removeEventListener("change", this.onObjectChange);
12639
13113
  }
12640
13114
  const change = attached ? 1 : -1;
12641
13115
  this.stats.objectCount += change;
@@ -13476,7 +13950,7 @@ var Renderer = class _Renderer {
13476
13950
  });
13477
13951
  renderer.setClearColor(0, 0);
13478
13952
  renderer.shadowMap.enabled = true;
13479
- renderer.shadowMap.type = import_three35.PCFSoftShadowMap;
13953
+ renderer.shadowMap.type = import_three35.PCFShadowMap;
13480
13954
  renderer.outputColorSpace = import_three35.SRGBColorSpace;
13481
13955
  renderer.setPixelRatio(this.options.render.pixelRatio ?? 1);
13482
13956
  renderer.setSize(this.viewWidth, this.viewHeight);
@@ -14654,6 +15128,7 @@ var SectionMesh = class _SectionMesh extends import_three39.Group {
14654
15128
  texture?.dispose();
14655
15129
  }
14656
15130
  this.removeFromParent();
15131
+ super.dispose();
14657
15132
  }
14658
15133
  };
14659
15134
 
@@ -14958,6 +15433,7 @@ var Chunk = class _Chunk {
14958
15433
  computeTangents,
14959
15434
  createCanvas,
14960
15435
  createFluidGeometry,
15436
+ createGuiTextureGeometry,
14961
15437
  createImage,
14962
15438
  entityAnimationTime,
14963
15439
  estimateBytesUsed,