minerender 2.1.0-alpha.65 → 2.1.0-alpha.67

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.
@@ -3008,16 +3008,17 @@ var init_UVMapper = __esm({
3008
3008
  positions[textureKey] = [x, y];
3009
3009
  const [width, height] = sizes[textureKey];
3010
3010
  const sequence = frames[textureKey];
3011
- const drawFrame = (index) => {
3011
+ const getFrameData = (index) => {
3012
3012
  const columns = texture.width / width;
3013
- image.putData(texture.getSectionData(
3013
+ return texture.getSectionData(
3014
3014
  index % columns * width,
3015
3015
  Math.floor(index / columns) * height,
3016
3016
  width,
3017
3017
  height
3018
- ), x, y);
3018
+ );
3019
3019
  };
3020
- drawFrame(sequence?.[0].index ?? 0);
3020
+ const firstFrame = getFrameData(sequence?.[0].index ?? 0);
3021
+ image.putData(firstFrame, x, y);
3021
3022
  if (texture.hasTransparency) {
3022
3023
  hasTransparency = true;
3023
3024
  }
@@ -3025,13 +3026,28 @@ var init_UVMapper = __esm({
3025
3026
  hasAnimation = true;
3026
3027
  let t = 0;
3027
3028
  let f = 0;
3029
+ const interpolated = metaMap[textureKey]?.animation?.interpolate ? image.context.createImageData(width, height) : void 0;
3030
+ let currentFrame = firstFrame;
3031
+ let nextFrame = interpolated ? getFrameData(sequence[1].index) : firstFrame;
3028
3032
  animatorFunctions[textureKey] = () => {
3029
- if (++t < sequence[f].time) return false;
3030
- t = 0;
3031
- const previous = sequence[f].index;
3032
- f = (f + 1) % sequence.length;
3033
- if (sequence[f].index === previous) return false;
3034
- drawFrame(sequence[f].index);
3033
+ if (++t >= sequence[f].time) {
3034
+ t = 0;
3035
+ const previous = sequence[f].index;
3036
+ f = (f + 1) % sequence.length;
3037
+ if (interpolated) {
3038
+ currentFrame = nextFrame;
3039
+ nextFrame = getFrameData(sequence[(f + 1) % sequence.length].index);
3040
+ }
3041
+ if (sequence[f].index === previous) return false;
3042
+ image.putData(interpolated ? currentFrame : getFrameData(sequence[f].index), x, y);
3043
+ return true;
3044
+ }
3045
+ if (!interpolated || sequence[f].index === sequence[(f + 1) % sequence.length].index) return false;
3046
+ const progress = Math.floor(Math.fround(Math.fround(t / sequence[f].time) * 1e3)) / 1e3;
3047
+ for (let i = 0; i < interpolated.data.length; i++) {
3048
+ interpolated.data[i] = currentFrame.data[i] + (nextFrame.data[i] - currentFrame.data[i]) * progress;
3049
+ }
3050
+ image.putData(interpolated, x, y);
3035
3051
  return true;
3036
3052
  };
3037
3053
  }
@@ -4020,6 +4036,7 @@ var init_SceneObject = __esm({
4020
4036
  dispose() {
4021
4037
  this.disposeAndRemoveAllChildren();
4022
4038
  this.notifyDirty();
4039
+ super.dispose();
4023
4040
  }
4024
4041
  disposeAndRemoveAllChildren() {
4025
4042
  if (this.instanceMesh) {
@@ -4233,6 +4250,7 @@ var init_EntityObject = __esm({
4233
4250
  else matrix.makeRotationFromEuler(new import_three14.Euler(...op.rotate, "ZYX"));
4234
4251
  modelRoot.matrix.multiply(matrix);
4235
4252
  }
4253
+ modelRoot.matrixWorldNeedsUpdate = true;
4236
4254
  modelRoot.matrixAutoUpdate = false;
4237
4255
  } else if (this.options.flip ?? true) {
4238
4256
  modelRoot.scale.set(-1, -1, 1);
@@ -4328,7 +4346,7 @@ function mergeBufferGeometries(geometries, useGroups = false) {
4328
4346
  const attributes = {};
4329
4347
  const morphAttributes = {};
4330
4348
  const morphTargetsRelative = geometries[0].morphTargetsRelative;
4331
- const mergedGeometry = new import_three21.BufferGeometry();
4349
+ const mergedGeometry = new import_three20.BufferGeometry();
4332
4350
  let offset = 0;
4333
4351
  for (let i = 0; i < geometries.length; ++i) {
4334
4352
  const geometry = geometries[i];
@@ -4452,7 +4470,7 @@ function mergeBufferAttributes(attributes) {
4452
4470
  array.set(attributes[i].array, offset);
4453
4471
  offset += attributes[i].array.length;
4454
4472
  }
4455
- return new import_three21.BufferAttribute(array, itemSize, normalized);
4473
+ return new import_three20.BufferAttribute(array, itemSize, normalized);
4456
4474
  }
4457
4475
  function interleaveAttributes(attributes) {
4458
4476
  let TypedArray;
@@ -4468,7 +4486,7 @@ function interleaveAttributes(attributes) {
4468
4486
  arrayLength += attribute.array.length;
4469
4487
  stride += attribute.itemSize;
4470
4488
  }
4471
- const interleavedBuffer = new import_three21.InterleavedBuffer(new TypedArray(arrayLength), stride);
4489
+ const interleavedBuffer = new import_three20.InterleavedBuffer(new TypedArray(arrayLength), stride);
4472
4490
  let offset = 0;
4473
4491
  const res = [];
4474
4492
  const getters = ["getX", "getY", "getZ", "getW"];
@@ -4477,7 +4495,7 @@ function interleaveAttributes(attributes) {
4477
4495
  const attribute = attributes[j];
4478
4496
  const itemSize = attribute.itemSize;
4479
4497
  const count = attribute.count;
4480
- const iba = new import_three21.InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, attribute.normalized);
4498
+ const iba = new import_three20.InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, attribute.normalized);
4481
4499
  res.push(iba);
4482
4500
  offset += itemSize;
4483
4501
  for (let c = 0; c < count; c++) {
@@ -4561,13 +4579,13 @@ function mergeVertices(geometry, tolerance = 1e-4) {
4561
4579
  const name = attributeNames[i];
4562
4580
  const oldAttribute = geometry.getAttribute(name);
4563
4581
  const buffer = new oldAttribute.array.constructor(attrArrays[name]);
4564
- const attribute = new import_three21.BufferAttribute(buffer, oldAttribute.itemSize, oldAttribute.normalized);
4582
+ const attribute = new import_three20.BufferAttribute(buffer, oldAttribute.itemSize, oldAttribute.normalized);
4565
4583
  result.setAttribute(name, attribute);
4566
4584
  if (name in morphAttrsArrays) {
4567
4585
  for (let j = 0; j < morphAttrsArrays[name].length; j++) {
4568
4586
  const oldMorphAttribute = geometry.morphAttributes[name][j];
4569
4587
  const buffer2 = new oldMorphAttribute.array.constructor(morphAttrsArrays[name][j]);
4570
- const morphAttribute = new import_three21.BufferAttribute(buffer2, oldMorphAttribute.itemSize, oldMorphAttribute.normalized);
4588
+ const morphAttribute = new import_three20.BufferAttribute(buffer2, oldMorphAttribute.itemSize, oldMorphAttribute.normalized);
4571
4589
  result.morphAttributes[name][j] = morphAttribute;
4572
4590
  }
4573
4591
  }
@@ -4576,11 +4594,11 @@ function mergeVertices(geometry, tolerance = 1e-4) {
4576
4594
  return result;
4577
4595
  }
4578
4596
  function toTrianglesDrawMode(geometry, drawMode) {
4579
- if (drawMode === import_three21.TrianglesDrawMode) {
4597
+ if (drawMode === import_three20.TrianglesDrawMode) {
4580
4598
  console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles.");
4581
4599
  return geometry;
4582
4600
  }
4583
- if (drawMode === import_three21.TriangleFanDrawMode || drawMode === import_three21.TriangleStripDrawMode) {
4601
+ if (drawMode === import_three20.TriangleFanDrawMode || drawMode === import_three20.TriangleStripDrawMode) {
4584
4602
  let index = geometry.getIndex();
4585
4603
  if (index === null) {
4586
4604
  const indices = [];
@@ -4598,7 +4616,7 @@ function toTrianglesDrawMode(geometry, drawMode) {
4598
4616
  }
4599
4617
  const numberOfTriangles = index.count - 2;
4600
4618
  const newIndices = [];
4601
- if (drawMode === import_three21.TriangleFanDrawMode) {
4619
+ if (drawMode === import_three20.TriangleFanDrawMode) {
4602
4620
  for (let i = 1; i <= numberOfTriangles; i++) {
4603
4621
  newIndices.push(index.getX(0));
4604
4622
  newIndices.push(index.getX(i));
@@ -4634,15 +4652,15 @@ function computeMorphedAttributes(object) {
4634
4652
  console.error("THREE.BufferGeometryUtils: Geometry is not of type BufferGeometry.");
4635
4653
  return null;
4636
4654
  }
4637
- const _vA = new import_three21.Vector3();
4638
- const _vB = new import_three21.Vector3();
4639
- const _vC = new import_three21.Vector3();
4640
- const _tempA = new import_three21.Vector3();
4641
- const _tempB = new import_three21.Vector3();
4642
- const _tempC = new import_three21.Vector3();
4643
- const _morphA = new import_three21.Vector3();
4644
- const _morphB = new import_three21.Vector3();
4645
- const _morphC = new import_three21.Vector3();
4655
+ const _vA = new import_three20.Vector3();
4656
+ const _vB = new import_three20.Vector3();
4657
+ const _vC = new import_three20.Vector3();
4658
+ const _tempA = new import_three20.Vector3();
4659
+ const _tempB = new import_three20.Vector3();
4660
+ const _tempC = new import_three20.Vector3();
4661
+ const _morphA = new import_three20.Vector3();
4662
+ const _morphB = new import_three20.Vector3();
4663
+ const _morphC = new import_three20.Vector3();
4646
4664
  function _calculateMorphedAttributeData(object2, material2, attribute, morphAttribute, morphTargetsRelative2, a2, b2, c2, modifiedAttributeArray) {
4647
4665
  _vA.fromBufferAttribute(attribute, a2);
4648
4666
  _vB.fromBufferAttribute(attribute, b2);
@@ -4837,8 +4855,8 @@ function computeMorphedAttributes(object) {
4837
4855
  }
4838
4856
  }
4839
4857
  }
4840
- const morphedPositionAttribute = new import_three21.Float32BufferAttribute(modifiedPosition, 3);
4841
- const morphedNormalAttribute = new import_three21.Float32BufferAttribute(modifiedNormal, 3);
4858
+ const morphedPositionAttribute = new import_three20.Float32BufferAttribute(modifiedPosition, 3);
4859
+ const morphedNormalAttribute = new import_three20.Float32BufferAttribute(modifiedNormal, 3);
4842
4860
  return {
4843
4861
  positionAttribute,
4844
4862
  normalAttribute,
@@ -4846,24 +4864,24 @@ function computeMorphedAttributes(object) {
4846
4864
  morphedNormalAttribute
4847
4865
  };
4848
4866
  }
4849
- var import_three21;
4867
+ var import_three20;
4850
4868
  var init_BufferGeometryUtils = __esm({
4851
4869
  "src/three/BufferGeometryUtils.js"() {
4852
- import_three21 = require("three");
4870
+ import_three20 = require("three");
4853
4871
  }
4854
4872
  });
4855
4873
 
4856
4874
  // src/model/ModelCulling.ts
4857
- var import_three22, ModelCulling;
4875
+ var import_three21, ModelCulling;
4858
4876
  var init_ModelCulling = __esm({
4859
4877
  "src/model/ModelCulling.ts"() {
4860
- import_three22 = require("three");
4878
+ import_three21 = require("three");
4861
4879
  init_CubeFace();
4862
4880
  ModelCulling = class {
4863
4881
  static toLocalMask(worldMask, rotation) {
4864
4882
  let localMask = 0;
4865
4883
  for (const [localFace, offset] of CUBE_FACE_OFFSETS.entries()) {
4866
- const normal = new import_three22.Vector3(...offset).applyEuler(rotation);
4884
+ const normal = new import_three21.Vector3(...offset).applyEuler(rotation);
4867
4885
  const worldFace = CUBE_FACE_OFFSETS.findIndex(([x, y, z]) => Math.abs(normal.x - x) < 1e-6 && Math.abs(normal.y - y) < 1e-6 && Math.abs(normal.z - z) < 1e-6);
4868
4886
  if (worldFace < 0) return 0;
4869
4887
  if (worldMask & 1 << worldFace) localMask |= 1 << localFace;
@@ -4896,10 +4914,10 @@ var init_ModelCulling = __esm({
4896
4914
  });
4897
4915
 
4898
4916
  // src/model/SpecialItems.ts
4899
- var import_three23, SpecialItems;
4917
+ var import_three22, SpecialItems;
4900
4918
  var init_SpecialItems = __esm({
4901
4919
  "src/model/SpecialItems.ts"() {
4902
- import_three23 = require("three");
4920
+ import_three22 = require("three");
4903
4921
  init_AssetKey();
4904
4922
  init_Entities();
4905
4923
  SpecialItems = class {
@@ -4927,7 +4945,7 @@ var init_SpecialItems = __esm({
4927
4945
  case "minecraft:chest":
4928
4946
  case "chest": {
4929
4947
  const angle = -(special.openness ?? 0) * Math.PI / 2;
4930
- const chest = await load("chest", texture(special.texture, "chest"), new import_three23.Matrix4(), {
4948
+ const chest = await load("chest", texture(special.texture, "chest"), new import_three22.Matrix4(), {
4931
4949
  lid: [angle, 0, 0],
4932
4950
  lock: [angle, 0, 0]
4933
4951
  });
@@ -4936,11 +4954,11 @@ var init_SpecialItems = __esm({
4936
4954
  }
4937
4955
  case "minecraft:bed":
4938
4956
  case "bed": {
4939
- const transform = new import_three23.Matrix4().makeTranslation(0, 9, 0).multiply(new import_three23.Matrix4().makeRotationX(Math.PI / 2)).multiply(new import_three23.Matrix4().makeTranslation(8, 8, 8)).multiply(new import_three23.Matrix4().makeRotationZ(Math.PI)).multiply(new import_three23.Matrix4().makeTranslation(-8, -8, -8));
4957
+ const transform = new import_three22.Matrix4().makeTranslation(0, 9, 0).multiply(new import_three22.Matrix4().makeRotationX(Math.PI / 2)).multiply(new import_three22.Matrix4().makeTranslation(8, 8, 8)).multiply(new import_three22.Matrix4().makeRotationZ(Math.PI)).multiply(new import_three22.Matrix4().makeTranslation(-8, -8, -8));
4940
4958
  const key = texture(special.texture, "bed");
4941
4959
  return Promise.all([
4942
4960
  load("bed_head", key, transform),
4943
- load("bed_foot", key, new import_three23.Matrix4().makeTranslation(0, 0, -16).multiply(transform))
4961
+ load("bed_foot", key, new import_three22.Matrix4().makeTranslation(0, 0, -16).multiply(transform))
4944
4962
  ]);
4945
4963
  }
4946
4964
  case "minecraft:head":
@@ -4965,7 +4983,7 @@ var init_SpecialItems = __esm({
4965
4983
  return [await load(
4966
4984
  id,
4967
4985
  special.texture ? texture(special.texture, "") : void 0,
4968
- new import_three23.Matrix4().makeTranslation(8, 0, 8).multiply(new import_three23.Matrix4().makeScale(-1, -1, 1)),
4986
+ new import_three22.Matrix4().makeTranslation(8, 0, 8).multiply(new import_three22.Matrix4().makeScale(-1, -1, 1)),
4969
4987
  rotations
4970
4988
  )];
4971
4989
  }
@@ -5093,13 +5111,13 @@ var init_ItemTints = __esm({
5093
5111
  function isModelObject(obj) {
5094
5112
  return obj.isModelObject;
5095
5113
  }
5096
- var import_three24, import_ts_deepmerge5, p7, ModelObject;
5114
+ var import_three23, import_ts_deepmerge5, p7, ModelObject;
5097
5115
  var init_ModelObject = __esm({
5098
5116
  "src/model/scene/ModelObject.ts"() {
5099
5117
  init_SceneObject();
5100
5118
  init_Materials();
5101
5119
  init_UVMapper();
5102
- import_three24 = require("three");
5120
+ import_three23 = require("three");
5103
5121
  init_BufferGeometryUtils();
5104
5122
  init_model();
5105
5123
  import_ts_deepmerge5 = __toESM(require_dist());
@@ -5134,12 +5152,13 @@ var init_ModelObject = __esm({
5134
5152
  const special = this.originalModel.special;
5135
5153
  if (special) {
5136
5154
  const parts = await SpecialItems.getParts(special, this.originalModel.key?.root);
5137
- const transform = this.options.displayPosition ? DisplayTransforms.getMatrix(this.originalModel.display, this.options.displayPosition) : new import_three24.Matrix4();
5138
- transform.multiply(new import_three24.Matrix4().makeTranslation(-8, -8, -8));
5155
+ const transform = this.options.displayPosition ? DisplayTransforms.getMatrix(this.originalModel.display, this.options.displayPosition) : new import_three23.Matrix4();
5156
+ transform.multiply(new import_three23.Matrix4().makeTranslation(-8, -8, -8));
5139
5157
  try {
5140
5158
  for (const part of parts) {
5141
5159
  const object = new EntityObject(part.model, { flip: false, wireframe: this.options.wireframe });
5142
5160
  object.matrix.copy(transform).multiply(part.transform);
5161
+ object.matrixWorldNeedsUpdate = true;
5143
5162
  object.matrixAutoUpdate = false;
5144
5163
  this.add(object);
5145
5164
  await object.init();
@@ -5197,7 +5216,7 @@ var init_ModelObject = __esm({
5197
5216
  elGeo.clearGroups();
5198
5217
  }
5199
5218
  if (this.options.uvLockRotation) {
5200
- UVMapper.lockUvs(elGeo, el.faces, this.atlas, new import_three24.Euler(...this.options.uvLockRotation));
5219
+ UVMapper.lockUvs(elGeo, el.faces, this.atlas, new import_three23.Euler(...this.options.uvLockRotation));
5201
5220
  }
5202
5221
  if (this.options.tints) {
5203
5222
  const colors = new Float32Array(elGeo.getAttribute("position").count * 3).fill(1);
@@ -5206,19 +5225,19 @@ var init_ModelObject = __esm({
5206
5225
  if (tintIndex === void 0 || tintIndex < 0) continue;
5207
5226
  const tint = this.options.tints[tintIndex];
5208
5227
  if (tint === void 0) continue;
5209
- const color = new import_three24.Color(tint);
5228
+ const color = new import_three23.Color(tint);
5210
5229
  for (let vertex = 0; vertex < 4; vertex++) {
5211
5230
  color.toArray(colors, (faceIndex * 4 + vertex) * 3);
5212
5231
  }
5213
5232
  }
5214
- elGeo.setAttribute("color", new import_three24.BufferAttribute(colors, 3));
5233
+ elGeo.setAttribute("color", new import_three23.BufferAttribute(colors, 3));
5215
5234
  }
5216
- elGeo.applyMatrix4(new import_three24.Matrix4().makeTranslation((el.to[0] - el.from[0]) / 2, (el.to[1] - el.from[1]) / 2, (el.to[2] - el.from[2]) / 2));
5217
- elGeo.applyMatrix4(new import_three24.Matrix4().makeTranslation(el.from[0], el.from[1], el.from[2]));
5235
+ elGeo.applyMatrix4(new import_three23.Matrix4().makeTranslation((el.to[0] - el.from[0]) / 2, (el.to[1] - el.from[1]) / 2, (el.to[2] - el.from[2]) / 2));
5236
+ elGeo.applyMatrix4(new import_three23.Matrix4().makeTranslation(el.from[0], el.from[1], el.from[2]));
5218
5237
  if (el.rotation) {
5219
5238
  applyElementRotation(el.rotation, elGeo);
5220
5239
  }
5221
- elGeo.applyMatrix4(new import_three24.Matrix4().makeTranslation(-8, -8, -8));
5240
+ elGeo.applyMatrix4(new import_three23.Matrix4().makeTranslation(-8, -8, -8));
5222
5241
  if (displayTransform) DisplayTransforms.apply(elGeo, displayTransform);
5223
5242
  if (this.options.mergeMeshes) {
5224
5243
  allGeos.push(elGeo);
@@ -5240,7 +5259,7 @@ var init_ModelObject = __esm({
5240
5259
  if (allGeos.length > 0) {
5241
5260
  combinedGeo = mergeBufferGeometries(allGeos);
5242
5261
  } else {
5243
- combinedGeo = new import_three24.BoxGeometry(16, 16, 16);
5262
+ combinedGeo = new import_three23.BoxGeometry(16, 16, 16);
5244
5263
  if (displayTransform) DisplayTransforms.apply(combinedGeo, displayTransform);
5245
5264
  }
5246
5265
  combinedGeo.computeBoundingBox();
@@ -5350,7 +5369,7 @@ function ownHeight(sample) {
5350
5369
  return (level === 0 || level >= 8 ? 8 : 8 - level) / 9;
5351
5370
  }
5352
5371
  function createFluidGeometry(kind, sample) {
5353
- const geometry = new import_three29.BufferGeometry();
5372
+ const geometry = new import_three28.BufferGeometry();
5354
5373
  const positions = [], normals = [], uvs = [], indices = [];
5355
5374
  const self = sample(0, 0, 0);
5356
5375
  const height = (x, z) => {
@@ -5449,16 +5468,16 @@ function createFluidGeometry(kind, sample) {
5449
5468
  1
5450
5469
  );
5451
5470
  }
5452
- geometry.setAttribute("position", new import_three29.Float32BufferAttribute(positions, 3));
5453
- geometry.setAttribute("normal", new import_three29.Float32BufferAttribute(normals, 3));
5454
- geometry.setAttribute("uv", new import_three29.Float32BufferAttribute(uvs, 2));
5471
+ geometry.setAttribute("position", new import_three28.Float32BufferAttribute(positions, 3));
5472
+ geometry.setAttribute("normal", new import_three28.Float32BufferAttribute(normals, 3));
5473
+ geometry.setAttribute("uv", new import_three28.Float32BufferAttribute(uvs, 2));
5455
5474
  geometry.setIndex(indices);
5456
5475
  return geometry;
5457
5476
  }
5458
- var import_three29, fluidRules, HORIZONTAL, EPSILON;
5477
+ var import_three28, fluidRules, HORIZONTAL, EPSILON;
5459
5478
  var init_FluidGeometry = __esm({
5460
5479
  "src/model/fluid/FluidGeometry.ts"() {
5461
- import_three29 = require("three");
5480
+ import_three28 = require("three");
5462
5481
  init_fluidBlocks();
5463
5482
  fluidRules = fluidBlocks_default;
5464
5483
  HORIZONTAL = [[0, -1], [0, 1], [-1, 0], [1, 0]];
@@ -5487,10 +5506,10 @@ function sampleFluid(kind, sample) {
5487
5506
  }
5488
5507
  return { key: key.join(""), sample: (x, y, z) => cells[(y + 1) * 9 + (z + 1) * 3 + x + 1] };
5489
5508
  }
5490
- var import_three30, FluidModelObject;
5509
+ var import_three29, FluidModelObject;
5491
5510
  var init_FluidModelObject = __esm({
5492
5511
  "src/model/fluid/FluidModelObject.ts"() {
5493
- import_three30 = require("three");
5512
+ import_three29 = require("three");
5494
5513
  init_AssetKey();
5495
5514
  init_Materials();
5496
5515
  init_ModelObject();
@@ -5523,10 +5542,10 @@ var init_FluidModelObject = __esm({
5523
5542
  }
5524
5543
  }
5525
5544
  geometry.clearGroups();
5526
- const color = new import_three30.Color(this.options.tints?.[0] ?? (this.kind === "water" ? 4159204 : 16777215));
5545
+ const color = new import_three29.Color(this.options.tints?.[0] ?? (this.kind === "water" ? 4159204 : 16777215));
5527
5546
  const colors = new Float32Array(geometry.getAttribute("position").count * 3);
5528
5547
  for (let i = 0; i < colors.length; i += 3) color.toArray(colors, i);
5529
- geometry.setAttribute("color", new import_three30.BufferAttribute(colors, 3));
5548
+ geometry.setAttribute("color", new import_three29.BufferAttribute(colors, 3));
5530
5549
  geometry.computeBoundingBox();
5531
5550
  geometry.computeBoundingSphere();
5532
5551
  if (this.options.instanceMeshes) {
@@ -5540,7 +5559,7 @@ var init_FluidModelObject = __esm({
5540
5559
  super.applyTextures();
5541
5560
  this.iterateAllMeshes((mesh) => {
5542
5561
  const material = mesh.material;
5543
- material.side = import_three30.DoubleSide;
5562
+ material.side = import_three29.DoubleSide;
5544
5563
  material.forceSinglePass = true;
5545
5564
  material.depthWrite = !material.transparent;
5546
5565
  });
@@ -5988,11 +6007,19 @@ init_EntityObject();
5988
6007
  init_MineRenderError();
5989
6008
 
5990
6009
  // src/export/SceneExporter.ts
5991
- var import_three20 = require("three");
6010
+ var import_three19 = require("three");
5992
6011
 
5993
6012
  // ../../node_modules/three/examples/jsm/exporters/OBJExporter.js
5994
6013
  var import_three16 = require("three");
5995
6014
  var OBJExporter = class {
6015
+ /**
6016
+ * Parses the given 3D object and generates the OBJ output.
6017
+ *
6018
+ * If the 3D object is composed of multiple children and geometry, they are merged into a single mesh in the file.
6019
+ *
6020
+ * @param {Object3D} object - The 3D object to export.
6021
+ * @return {string} The exported OBJ.
6022
+ */
5996
6023
  parse(object) {
5997
6024
  let output = "";
5998
6025
  let indexVertex = 0;
@@ -6098,7 +6125,8 @@ var OBJExporter = class {
6098
6125
  vertex.applyMatrix4(points.matrixWorld);
6099
6126
  output += "v " + vertex.x + " " + vertex.y + " " + vertex.z;
6100
6127
  if (colors !== void 0) {
6101
- color.fromBufferAttribute(colors, i).convertLinearToSRGB();
6128
+ color.fromBufferAttribute(colors, i);
6129
+ import_three16.ColorManagement.workingToColorSpace(color, import_three16.SRGBColorSpace);
6102
6130
  output += " " + color.r + " " + color.g + " " + color.b;
6103
6131
  }
6104
6132
  output += "\n";
@@ -6129,6 +6157,16 @@ var OBJExporter = class {
6129
6157
  // ../../node_modules/three/examples/jsm/exporters/PLYExporter.js
6130
6158
  var import_three17 = require("three");
6131
6159
  var PLYExporter = class {
6160
+ /**
6161
+ * Parses the given 3D object and generates the PLY output.
6162
+ *
6163
+ * If the 3D object is composed of multiple children and geometry, they are merged into a single mesh in the file.
6164
+ *
6165
+ * @param {Object3D} object - The 3D object to export.
6166
+ * @param {PLYExporter~OnDone} onDone - A callback function that is executed when the export has finished.
6167
+ * @param {PLYExporter~Options} options - The export options.
6168
+ * @return {?(string|ArrayBuffer)} The exported PLY.
6169
+ */
6132
6170
  parse(object, onDone, options = {}) {
6133
6171
  function traverseMeshes(cb) {
6134
6172
  object.traverse(function(child) {
@@ -6145,14 +6183,23 @@ var PLYExporter = class {
6145
6183
  binary: false,
6146
6184
  excludeAttributes: [],
6147
6185
  // normal, uv, color, index
6148
- littleEndian: false
6186
+ littleEndian: false,
6187
+ customPropertyMapping: {}
6149
6188
  };
6150
6189
  options = Object.assign(defaultOptions, options);
6151
6190
  const excludeAttributes = options.excludeAttributes;
6191
+ const customPropertyMapping = options.customPropertyMapping;
6192
+ const customAttributeNames = Object.keys(customPropertyMapping);
6152
6193
  let includeIndices = true;
6153
6194
  let includeNormals = false;
6154
6195
  let includeColors = false;
6155
6196
  let includeUVs = false;
6197
+ let positionType = "float";
6198
+ let normalType = "float";
6199
+ let uvType = "float";
6200
+ let colorType = "uchar";
6201
+ const customTypes = {};
6202
+ for (const name of customAttributeNames) customTypes[name] = "float";
6156
6203
  let vertexCount = 0;
6157
6204
  let faceCount = 0;
6158
6205
  object.traverse(function(child) {
@@ -6169,9 +6216,23 @@ var PLYExporter = class {
6169
6216
  }
6170
6217
  vertexCount += vertices.count;
6171
6218
  faceCount += indices ? indices.count / 3 : vertices.count / 3;
6172
- if (normals !== void 0) includeNormals = true;
6173
- if (uvs !== void 0) includeUVs = true;
6174
- if (colors !== void 0) includeColors = true;
6219
+ positionType = getPlyType(vertices.array);
6220
+ if (normals !== void 0) {
6221
+ includeNormals = true;
6222
+ normalType = getPlyType(normals.array);
6223
+ }
6224
+ if (uvs !== void 0) {
6225
+ includeUVs = true;
6226
+ uvType = getPlyType(uvs.array);
6227
+ }
6228
+ if (colors !== void 0) {
6229
+ includeColors = true;
6230
+ colorType = getPlyType(colors.array);
6231
+ }
6232
+ for (const name of customAttributeNames) {
6233
+ const attr = geometry.getAttribute(name);
6234
+ if (attr !== void 0) customTypes[name] = getPlyType(attr.array);
6235
+ }
6175
6236
  } else if (child.isPoints) {
6176
6237
  const mesh = child;
6177
6238
  const geometry = mesh.geometry;
@@ -6179,8 +6240,19 @@ var PLYExporter = class {
6179
6240
  const normals = geometry.getAttribute("normal");
6180
6241
  const colors = geometry.getAttribute("color");
6181
6242
  vertexCount += vertices.count;
6182
- if (normals !== void 0) includeNormals = true;
6183
- if (colors !== void 0) includeColors = true;
6243
+ positionType = getPlyType(vertices.array);
6244
+ if (normals !== void 0) {
6245
+ includeNormals = true;
6246
+ normalType = getPlyType(normals.array);
6247
+ }
6248
+ if (colors !== void 0) {
6249
+ includeColors = true;
6250
+ colorType = getPlyType(colors.array);
6251
+ }
6252
+ for (const name of customAttributeNames) {
6253
+ const attr = geometry.getAttribute(name);
6254
+ if (attr !== void 0) customTypes[name] = getPlyType(attr.array);
6255
+ }
6184
6256
  includeIndices = false;
6185
6257
  }
6186
6258
  });
@@ -6199,18 +6271,33 @@ var PLYExporter = class {
6199
6271
  let header = `ply
6200
6272
  format ${options.binary ? options.littleEndian ? "binary_little_endian" : "binary_big_endian" : "ascii"} 1.0
6201
6273
  element vertex ${vertexCount}
6202
- property float x
6203
- property float y
6204
- property float z
6274
+ property ${positionType} x
6275
+ property ${positionType} y
6276
+ property ${positionType} z
6205
6277
  `;
6206
6278
  if (includeNormals === true) {
6207
- header += "property float nx\nproperty float ny\nproperty float nz\n";
6279
+ header += `property ${normalType} nx
6280
+ property ${normalType} ny
6281
+ property ${normalType} nz
6282
+ `;
6208
6283
  }
6209
6284
  if (includeUVs === true) {
6210
- header += "property float s\nproperty float t\n";
6285
+ header += `property ${uvType} s
6286
+ property ${uvType} t
6287
+ `;
6211
6288
  }
6212
6289
  if (includeColors === true) {
6213
- header += "property uchar red\nproperty uchar green\nproperty uchar blue\n";
6290
+ header += `property ${colorType} red
6291
+ property ${colorType} green
6292
+ property ${colorType} blue
6293
+ `;
6294
+ }
6295
+ for (const name of customAttributeNames) {
6296
+ const type = customTypes[name];
6297
+ for (const propName of customPropertyMapping[name]) {
6298
+ header += `property ${type} ${propName}
6299
+ `;
6300
+ }
6214
6301
  }
6215
6302
  if (includeIndices === true) {
6216
6303
  header += `element face ${faceCount}
@@ -6223,7 +6310,23 @@ property list uchar int vertex_index
6223
6310
  let result = null;
6224
6311
  if (options.binary === true) {
6225
6312
  const headerBin = new TextEncoder().encode(header);
6226
- const vertexListLength = vertexCount * (4 * 3 + (includeNormals ? 4 * 3 : 0) + (includeColors ? 3 : 0) + (includeUVs ? 4 * 2 : 0));
6313
+ const posWriter = getBinaryWriter(positionType);
6314
+ const normalWriter = includeNormals ? getBinaryWriter(normalType) : null;
6315
+ const uvWriter = includeUVs ? getBinaryWriter(uvType) : null;
6316
+ const colorWriter = includeColors ? getBinaryWriter(colorType) : null;
6317
+ const colorIsFloat = isFloatType(colorType);
6318
+ const colorScale = getColorScale(colorType);
6319
+ const customWriters = {};
6320
+ const customIsFloat = {};
6321
+ let customStride = 0;
6322
+ for (const name of customAttributeNames) {
6323
+ const type = customTypes[name];
6324
+ const writer = getBinaryWriter(type);
6325
+ customWriters[name] = writer;
6326
+ customIsFloat[name] = isFloatType(type);
6327
+ customStride += customPropertyMapping[name].length * writer.size;
6328
+ }
6329
+ const vertexListLength = vertexCount * (3 * posWriter.size + (includeNormals ? 3 * normalWriter.size : 0) + (includeUVs ? 2 * uvWriter.size : 0) + (includeColors ? 3 * colorWriter.size : 0) + customStride);
6227
6330
  const faceListLength = includeIndices ? faceCount * (indexByteCount * 3 + 1) : 0;
6228
6331
  const output = new DataView(new ArrayBuffer(headerBin.length + vertexListLength + faceListLength));
6229
6332
  new Uint8Array(output.buffer).set(headerBin, 0);
@@ -6240,60 +6343,76 @@ property list uchar int vertex_index
6240
6343
  for (let i = 0, l = vertices.count; i < l; i++) {
6241
6344
  vertex.fromBufferAttribute(vertices, i);
6242
6345
  vertex.applyMatrix4(mesh.matrixWorld);
6243
- output.setFloat32(vOffset, vertex.x, options.littleEndian);
6244
- vOffset += 4;
6245
- output.setFloat32(vOffset, vertex.y, options.littleEndian);
6246
- vOffset += 4;
6247
- output.setFloat32(vOffset, vertex.z, options.littleEndian);
6248
- vOffset += 4;
6346
+ posWriter.write(output, vOffset, vertex.x, options.littleEndian);
6347
+ vOffset += posWriter.size;
6348
+ posWriter.write(output, vOffset, vertex.y, options.littleEndian);
6349
+ vOffset += posWriter.size;
6350
+ posWriter.write(output, vOffset, vertex.z, options.littleEndian);
6351
+ vOffset += posWriter.size;
6249
6352
  if (includeNormals === true) {
6250
6353
  if (normals != null) {
6251
6354
  vertex.fromBufferAttribute(normals, i);
6252
6355
  vertex.applyMatrix3(normalMatrixWorld).normalize();
6253
- output.setFloat32(vOffset, vertex.x, options.littleEndian);
6254
- vOffset += 4;
6255
- output.setFloat32(vOffset, vertex.y, options.littleEndian);
6256
- vOffset += 4;
6257
- output.setFloat32(vOffset, vertex.z, options.littleEndian);
6258
- vOffset += 4;
6356
+ normalWriter.write(output, vOffset, vertex.x, options.littleEndian);
6357
+ vOffset += normalWriter.size;
6358
+ normalWriter.write(output, vOffset, vertex.y, options.littleEndian);
6359
+ vOffset += normalWriter.size;
6360
+ normalWriter.write(output, vOffset, vertex.z, options.littleEndian);
6361
+ vOffset += normalWriter.size;
6259
6362
  } else {
6260
- output.setFloat32(vOffset, 0, options.littleEndian);
6261
- vOffset += 4;
6262
- output.setFloat32(vOffset, 0, options.littleEndian);
6263
- vOffset += 4;
6264
- output.setFloat32(vOffset, 0, options.littleEndian);
6265
- vOffset += 4;
6363
+ normalWriter.write(output, vOffset, 0, options.littleEndian);
6364
+ vOffset += normalWriter.size;
6365
+ normalWriter.write(output, vOffset, 0, options.littleEndian);
6366
+ vOffset += normalWriter.size;
6367
+ normalWriter.write(output, vOffset, 0, options.littleEndian);
6368
+ vOffset += normalWriter.size;
6266
6369
  }
6267
6370
  }
6268
6371
  if (includeUVs === true) {
6269
6372
  if (uvs != null) {
6270
- output.setFloat32(vOffset, uvs.getX(i), options.littleEndian);
6271
- vOffset += 4;
6272
- output.setFloat32(vOffset, uvs.getY(i), options.littleEndian);
6273
- vOffset += 4;
6373
+ uvWriter.write(output, vOffset, uvs.getX(i), options.littleEndian);
6374
+ vOffset += uvWriter.size;
6375
+ uvWriter.write(output, vOffset, uvs.getY(i), options.littleEndian);
6376
+ vOffset += uvWriter.size;
6274
6377
  } else {
6275
- output.setFloat32(vOffset, 0, options.littleEndian);
6276
- vOffset += 4;
6277
- output.setFloat32(vOffset, 0, options.littleEndian);
6278
- vOffset += 4;
6378
+ uvWriter.write(output, vOffset, 0, options.littleEndian);
6379
+ vOffset += uvWriter.size;
6380
+ uvWriter.write(output, vOffset, 0, options.littleEndian);
6381
+ vOffset += uvWriter.size;
6279
6382
  }
6280
6383
  }
6281
6384
  if (includeColors === true) {
6282
6385
  if (colors != null) {
6283
- tempColor.fromBufferAttribute(colors, i).convertLinearToSRGB();
6284
- output.setUint8(vOffset, Math.floor(tempColor.r * 255));
6285
- vOffset += 1;
6286
- output.setUint8(vOffset, Math.floor(tempColor.g * 255));
6287
- vOffset += 1;
6288
- output.setUint8(vOffset, Math.floor(tempColor.b * 255));
6289
- vOffset += 1;
6386
+ tempColor.fromBufferAttribute(colors, i);
6387
+ import_three17.ColorManagement.workingToColorSpace(tempColor, import_three17.SRGBColorSpace);
6388
+ const r = colorIsFloat ? tempColor.r : Math.round(tempColor.r * colorScale);
6389
+ const g = colorIsFloat ? tempColor.g : Math.round(tempColor.g * colorScale);
6390
+ const b = colorIsFloat ? tempColor.b : Math.round(tempColor.b * colorScale);
6391
+ colorWriter.write(output, vOffset, r, options.littleEndian);
6392
+ vOffset += colorWriter.size;
6393
+ colorWriter.write(output, vOffset, g, options.littleEndian);
6394
+ vOffset += colorWriter.size;
6395
+ colorWriter.write(output, vOffset, b, options.littleEndian);
6396
+ vOffset += colorWriter.size;
6290
6397
  } else {
6291
- output.setUint8(vOffset, 255);
6292
- vOffset += 1;
6293
- output.setUint8(vOffset, 255);
6294
- vOffset += 1;
6295
- output.setUint8(vOffset, 255);
6296
- vOffset += 1;
6398
+ const white = colorIsFloat ? 1 : colorScale;
6399
+ colorWriter.write(output, vOffset, white, options.littleEndian);
6400
+ vOffset += colorWriter.size;
6401
+ colorWriter.write(output, vOffset, white, options.littleEndian);
6402
+ vOffset += colorWriter.size;
6403
+ colorWriter.write(output, vOffset, white, options.littleEndian);
6404
+ vOffset += colorWriter.size;
6405
+ }
6406
+ }
6407
+ for (const name of customAttributeNames) {
6408
+ const writer = customWriters[name];
6409
+ const propCount = customPropertyMapping[name].length;
6410
+ const attr = geometry.getAttribute(name);
6411
+ const isFloat = customIsFloat[name];
6412
+ for (let c = 0; c < propCount; c++) {
6413
+ const raw = attr != null ? getAttributeComponent(attr, i, c) : 0;
6414
+ writer.write(output, vOffset, isFloat ? raw : Math.round(raw), options.littleEndian);
6415
+ vOffset += writer.size;
6297
6416
  }
6298
6417
  }
6299
6418
  }
@@ -6329,6 +6448,14 @@ property list uchar int vertex_index
6329
6448
  let writtenVertices = 0;
6330
6449
  let vertexList = "";
6331
6450
  let faceList = "";
6451
+ const positionIsFloat = isFloatType(positionType);
6452
+ const normalIsFloat = isFloatType(normalType);
6453
+ const uvIsFloat = isFloatType(uvType);
6454
+ const colorIsFloat = isFloatType(colorType);
6455
+ const colorScale = getColorScale(colorType);
6456
+ const customIsFloat = {};
6457
+ for (const name of customAttributeNames) customIsFloat[name] = isFloatType(customTypes[name]);
6458
+ const encode = (v, isFloat) => isFloat ? v : Math.round(v);
6332
6459
  traverseMeshes(function(mesh, geometry) {
6333
6460
  const vertices = geometry.getAttribute("position");
6334
6461
  const normals = geometry.getAttribute("normal");
@@ -6339,29 +6466,43 @@ property list uchar int vertex_index
6339
6466
  for (let i = 0, l = vertices.count; i < l; i++) {
6340
6467
  vertex.fromBufferAttribute(vertices, i);
6341
6468
  vertex.applyMatrix4(mesh.matrixWorld);
6342
- let line = vertex.x + " " + vertex.y + " " + vertex.z;
6469
+ let line = encode(vertex.x, positionIsFloat) + " " + encode(vertex.y, positionIsFloat) + " " + encode(vertex.z, positionIsFloat);
6343
6470
  if (includeNormals === true) {
6344
6471
  if (normals != null) {
6345
6472
  vertex.fromBufferAttribute(normals, i);
6346
6473
  vertex.applyMatrix3(normalMatrixWorld).normalize();
6347
- line += " " + vertex.x + " " + vertex.y + " " + vertex.z;
6474
+ line += " " + encode(vertex.x, normalIsFloat) + " " + encode(vertex.y, normalIsFloat) + " " + encode(vertex.z, normalIsFloat);
6348
6475
  } else {
6349
6476
  line += " 0 0 0";
6350
6477
  }
6351
6478
  }
6352
6479
  if (includeUVs === true) {
6353
6480
  if (uvs != null) {
6354
- line += " " + uvs.getX(i) + " " + uvs.getY(i);
6481
+ line += " " + encode(uvs.getX(i), uvIsFloat) + " " + encode(uvs.getY(i), uvIsFloat);
6355
6482
  } else {
6356
6483
  line += " 0 0";
6357
6484
  }
6358
6485
  }
6359
6486
  if (includeColors === true) {
6360
6487
  if (colors != null) {
6361
- tempColor.fromBufferAttribute(colors, i).convertLinearToSRGB();
6362
- line += " " + Math.floor(tempColor.r * 255) + " " + Math.floor(tempColor.g * 255) + " " + Math.floor(tempColor.b * 255);
6488
+ tempColor.fromBufferAttribute(colors, i);
6489
+ import_three17.ColorManagement.workingToColorSpace(tempColor, import_three17.SRGBColorSpace);
6490
+ const r = colorIsFloat ? tempColor.r : Math.round(tempColor.r * colorScale);
6491
+ const g = colorIsFloat ? tempColor.g : Math.round(tempColor.g * colorScale);
6492
+ const b = colorIsFloat ? tempColor.b : Math.round(tempColor.b * colorScale);
6493
+ line += ` ${r} ${g} ${b}`;
6363
6494
  } else {
6364
- line += " 255 255 255";
6495
+ const white = colorIsFloat ? 1 : colorScale;
6496
+ line += ` ${white} ${white} ${white}`;
6497
+ }
6498
+ }
6499
+ for (const name of customAttributeNames) {
6500
+ const propCount = customPropertyMapping[name].length;
6501
+ const attr = geometry.getAttribute(name);
6502
+ const isFloat = customIsFloat[name];
6503
+ for (let c = 0; c < propCount; c++) {
6504
+ const raw = attr != null ? getAttributeComponent(attr, i, c) : 0;
6505
+ line += " " + encode(raw, isFloat);
6365
6506
  }
6366
6507
  }
6367
6508
  vertexList += line + "\n";
@@ -6391,70 +6532,65 @@ property list uchar int vertex_index
6391
6532
  return result;
6392
6533
  }
6393
6534
  };
6394
-
6395
- // ../../node_modules/three/examples/jsm/exporters/GLTFExporter.js
6396
- var import_three19 = require("three");
6397
-
6398
- // ../../node_modules/three/examples/jsm/utils/TextureUtils.js
6399
- var import_three18 = require("three");
6400
- var _renderer;
6401
- var fullscreenQuadGeometry;
6402
- var fullscreenQuadMaterial;
6403
- var fullscreenQuad;
6404
- function decompress(texture, maxTextureSize = Infinity, renderer = null) {
6405
- if (!fullscreenQuadGeometry) fullscreenQuadGeometry = new import_three18.PlaneGeometry(2, 2, 1, 1);
6406
- if (!fullscreenQuadMaterial) fullscreenQuadMaterial = new import_three18.ShaderMaterial({
6407
- uniforms: { blitTexture: new import_three18.Uniform(texture) },
6408
- vertexShader: `
6409
- varying vec2 vUv;
6410
- void main(){
6411
- vUv = uv;
6412
- gl_Position = vec4(position.xy * 1.0,0.,.999999);
6413
- }`,
6414
- fragmentShader: `
6415
- uniform sampler2D blitTexture;
6416
- varying vec2 vUv;
6417
-
6418
- void main(){
6419
- gl_FragColor = vec4(vUv.xy, 0, 1);
6420
-
6421
- #ifdef IS_SRGB
6422
- gl_FragColor = LinearTosRGB( texture2D( blitTexture, vUv) );
6423
- #else
6424
- gl_FragColor = texture2D( blitTexture, vUv);
6425
- #endif
6426
- }`
6427
- });
6428
- fullscreenQuadMaterial.uniforms.blitTexture.value = texture;
6429
- fullscreenQuadMaterial.defines.IS_SRGB = texture.colorSpace == import_three18.SRGBColorSpace;
6430
- fullscreenQuadMaterial.needsUpdate = true;
6431
- if (!fullscreenQuad) {
6432
- fullscreenQuad = new import_three18.Mesh(fullscreenQuadGeometry, fullscreenQuadMaterial);
6433
- fullscreenQuad.frustrumCulled = false;
6434
- }
6435
- const _camera = new import_three18.PerspectiveCamera();
6436
- const _scene = new import_three18.Scene();
6437
- _scene.add(fullscreenQuad);
6438
- if (!renderer) {
6439
- renderer = _renderer = new import_three18.WebGLRenderer({ antialias: false });
6440
- }
6441
- renderer.setSize(Math.min(texture.image.width, maxTextureSize), Math.min(texture.image.height, maxTextureSize));
6442
- renderer.clear();
6443
- renderer.render(_scene, _camera);
6444
- const readableTexture = new import_three18.Texture(renderer.domElement);
6445
- readableTexture.minFilter = texture.minFilter;
6446
- readableTexture.magFilter = texture.magFilter;
6447
- readableTexture.wrapS = texture.wrapS;
6448
- readableTexture.wrapT = texture.wrapT;
6449
- readableTexture.name = texture.name;
6450
- if (_renderer) {
6451
- _renderer.dispose();
6452
- _renderer = null;
6453
- }
6454
- return readableTexture;
6535
+ function getPlyType(array) {
6536
+ if (array instanceof Int8Array) return "char";
6537
+ if (array instanceof Uint8Array || array instanceof Uint8ClampedArray) return "uchar";
6538
+ if (array instanceof Int16Array) return "short";
6539
+ if (array instanceof Uint16Array) return "ushort";
6540
+ if (array instanceof Int32Array) return "int";
6541
+ if (array instanceof Uint32Array) return "uint";
6542
+ if (array instanceof Float32Array) return "float";
6543
+ if (array instanceof Float64Array) return "double";
6544
+ return "float";
6545
+ }
6546
+ function getBinaryWriter(type) {
6547
+ switch (type) {
6548
+ case "char":
6549
+ return { write: (dv, at, v) => dv.setInt8(at, v), size: 1 };
6550
+ case "uchar":
6551
+ return { write: (dv, at, v) => dv.setUint8(at, v), size: 1 };
6552
+ case "short":
6553
+ return { write: (dv, at, v, le) => dv.setInt16(at, v, le), size: 2 };
6554
+ case "ushort":
6555
+ return { write: (dv, at, v, le) => dv.setUint16(at, v, le), size: 2 };
6556
+ case "int":
6557
+ return { write: (dv, at, v, le) => dv.setInt32(at, v, le), size: 4 };
6558
+ case "uint":
6559
+ return { write: (dv, at, v, le) => dv.setUint32(at, v, le), size: 4 };
6560
+ case "float":
6561
+ return { write: (dv, at, v, le) => dv.setFloat32(at, v, le), size: 4 };
6562
+ case "double":
6563
+ return { write: (dv, at, v, le) => dv.setFloat64(at, v, le), size: 8 };
6564
+ }
6565
+ }
6566
+ function isFloatType(type) {
6567
+ return type === "float" || type === "double";
6568
+ }
6569
+ function getAttributeComponent(attr, i, c) {
6570
+ switch (c) {
6571
+ case 0:
6572
+ return attr.getX(i);
6573
+ case 1:
6574
+ return attr.getY(i);
6575
+ case 2:
6576
+ return attr.getZ(i);
6577
+ case 3:
6578
+ return attr.getW(i);
6579
+ }
6580
+ }
6581
+ function getColorScale(type) {
6582
+ switch (type) {
6583
+ case "uchar":
6584
+ return 255;
6585
+ case "ushort":
6586
+ return 65535;
6587
+ default:
6588
+ return 1;
6589
+ }
6455
6590
  }
6456
6591
 
6457
6592
  // ../../node_modules/three/examples/jsm/exporters/GLTFExporter.js
6593
+ var import_three18 = require("three");
6458
6594
  var KHR_mesh_quantization_ExtraAttrTypes = {
6459
6595
  POSITION: [
6460
6596
  "byte",
@@ -6484,7 +6620,11 @@ var KHR_mesh_quantization_ExtraAttrTypes = {
6484
6620
  ]
6485
6621
  };
6486
6622
  var GLTFExporter = class {
6623
+ /**
6624
+ * Constructs a new glTF exporter.
6625
+ */
6487
6626
  constructor() {
6627
+ this.textureUtils = null;
6488
6628
  this.pluginCallbacks = [];
6489
6629
  this.register(function(writer) {
6490
6630
  return new GLTFLightExtension(writer);
@@ -6507,6 +6647,9 @@ var GLTFExporter = class {
6507
6647
  this.register(function(writer) {
6508
6648
  return new GLTFMaterialsClearcoatExtension(writer);
6509
6649
  });
6650
+ this.register(function(writer) {
6651
+ return new GLTFMaterialsDispersionExtension(writer);
6652
+ });
6510
6653
  this.register(function(writer) {
6511
6654
  return new GLTFMaterialsIridescenceExtension(writer);
6512
6655
  });
@@ -6519,16 +6662,33 @@ var GLTFExporter = class {
6519
6662
  this.register(function(writer) {
6520
6663
  return new GLTFMaterialsEmissiveStrengthExtension(writer);
6521
6664
  });
6665
+ this.register(function(writer) {
6666
+ return new GLTFMaterialsBumpExtension(writer);
6667
+ });
6522
6668
  this.register(function(writer) {
6523
6669
  return new GLTFMeshGpuInstancing(writer);
6524
6670
  });
6525
6671
  }
6672
+ /**
6673
+ * Registers a plugin callback. This API is internally used to implement the various
6674
+ * glTF extensions but can also used by third-party code to add additional logic
6675
+ * to the exporter.
6676
+ *
6677
+ * @param {function(writer:GLTFWriter)} callback - The callback function to register.
6678
+ * @return {GLTFExporter} A reference to this exporter.
6679
+ */
6526
6680
  register(callback) {
6527
6681
  if (this.pluginCallbacks.indexOf(callback) === -1) {
6528
6682
  this.pluginCallbacks.push(callback);
6529
6683
  }
6530
6684
  return this;
6531
6685
  }
6686
+ /**
6687
+ * Unregisters a plugin callback.
6688
+ *
6689
+ * @param {Function} callback - The callback function to unregister.
6690
+ * @return {GLTFExporter} A reference to this exporter.
6691
+ */
6532
6692
  unregister(callback) {
6533
6693
  if (this.pluginCallbacks.indexOf(callback) !== -1) {
6534
6694
  this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(callback), 1);
@@ -6536,11 +6696,25 @@ var GLTFExporter = class {
6536
6696
  return this;
6537
6697
  }
6538
6698
  /**
6539
- * Parse scenes and generate GLTF output
6540
- * @param {Scene or [THREE.Scenes]} input Scene or Array of THREE.Scenes
6541
- * @param {Function} onDone Callback on completed
6542
- * @param {Function} onError Callback on errors
6543
- * @param {Object} options options
6699
+ * Sets the texture utils for this exporter. Only relevant when compressed textures have to be exported.
6700
+ *
6701
+ * Depending on whether you use {@link WebGLRenderer} or {@link WebGPURenderer}, you must inject the
6702
+ * corresponding texture utils {@link module:WebGLTextureUtils} or {@link module:WebGPUTextureUtils}.
6703
+ *
6704
+ * @param {WebGLTextureUtils|WebGPUTextureUtils} utils - The texture utils.
6705
+ * @return {GLTFExporter} A reference to this exporter.
6706
+ */
6707
+ setTextureUtils(utils) {
6708
+ this.textureUtils = utils;
6709
+ return this;
6710
+ }
6711
+ /**
6712
+ * Parses the given scenes and generates the glTF output.
6713
+ *
6714
+ * @param {Scene|Array<Scene>} input - A scene or an array of scenes.
6715
+ * @param {GLTFExporter~OnDone} onDone - A callback function that is executed when the export has finished.
6716
+ * @param {GLTFExporter~OnError} onError - A callback function that is executed when an error happens.
6717
+ * @param {GLTFExporter~Options} options - options
6544
6718
  */
6545
6719
  parse(input, onDone, onError, options) {
6546
6720
  const writer = new GLTFWriter();
@@ -6549,8 +6723,16 @@ var GLTFExporter = class {
6549
6723
  plugins.push(this.pluginCallbacks[i](writer));
6550
6724
  }
6551
6725
  writer.setPlugins(plugins);
6552
- writer.write(input, onDone, options).catch(onError);
6726
+ writer.setTextureUtils(this.textureUtils);
6727
+ writer.writeAsync(input, onDone, options).catch(onError);
6553
6728
  }
6729
+ /**
6730
+ * Async version of {@link GLTFExporter#parse}.
6731
+ *
6732
+ * @param {Scene|Array<Scene>} input - A scene or an array of scenes.
6733
+ * @param {GLTFExporter~Options} options - options.
6734
+ * @return {Promise<ArrayBuffer|string>} A Promise that resolved with the exported glTF data.
6735
+ */
6554
6736
  parseAsync(input, options) {
6555
6737
  const scope = this;
6556
6738
  return new Promise(function(resolve, reject) {
@@ -6587,22 +6769,22 @@ var WEBGL_CONSTANTS = {
6587
6769
  };
6588
6770
  var KHR_MESH_QUANTIZATION = "KHR_mesh_quantization";
6589
6771
  var THREE_TO_WEBGL = {};
6590
- THREE_TO_WEBGL[import_three19.NearestFilter] = WEBGL_CONSTANTS.NEAREST;
6591
- THREE_TO_WEBGL[import_three19.NearestMipmapNearestFilter] = WEBGL_CONSTANTS.NEAREST_MIPMAP_NEAREST;
6592
- THREE_TO_WEBGL[import_three19.NearestMipmapLinearFilter] = WEBGL_CONSTANTS.NEAREST_MIPMAP_LINEAR;
6593
- THREE_TO_WEBGL[import_three19.LinearFilter] = WEBGL_CONSTANTS.LINEAR;
6594
- THREE_TO_WEBGL[import_three19.LinearMipmapNearestFilter] = WEBGL_CONSTANTS.LINEAR_MIPMAP_NEAREST;
6595
- THREE_TO_WEBGL[import_three19.LinearMipmapLinearFilter] = WEBGL_CONSTANTS.LINEAR_MIPMAP_LINEAR;
6596
- THREE_TO_WEBGL[import_three19.ClampToEdgeWrapping] = WEBGL_CONSTANTS.CLAMP_TO_EDGE;
6597
- THREE_TO_WEBGL[import_three19.RepeatWrapping] = WEBGL_CONSTANTS.REPEAT;
6598
- THREE_TO_WEBGL[import_three19.MirroredRepeatWrapping] = WEBGL_CONSTANTS.MIRRORED_REPEAT;
6772
+ THREE_TO_WEBGL[import_three18.NearestFilter] = WEBGL_CONSTANTS.NEAREST;
6773
+ THREE_TO_WEBGL[import_three18.NearestMipmapNearestFilter] = WEBGL_CONSTANTS.NEAREST_MIPMAP_NEAREST;
6774
+ THREE_TO_WEBGL[import_three18.NearestMipmapLinearFilter] = WEBGL_CONSTANTS.NEAREST_MIPMAP_LINEAR;
6775
+ THREE_TO_WEBGL[import_three18.LinearFilter] = WEBGL_CONSTANTS.LINEAR;
6776
+ THREE_TO_WEBGL[import_three18.LinearMipmapNearestFilter] = WEBGL_CONSTANTS.LINEAR_MIPMAP_NEAREST;
6777
+ THREE_TO_WEBGL[import_three18.LinearMipmapLinearFilter] = WEBGL_CONSTANTS.LINEAR_MIPMAP_LINEAR;
6778
+ THREE_TO_WEBGL[import_three18.ClampToEdgeWrapping] = WEBGL_CONSTANTS.CLAMP_TO_EDGE;
6779
+ THREE_TO_WEBGL[import_three18.RepeatWrapping] = WEBGL_CONSTANTS.REPEAT;
6780
+ THREE_TO_WEBGL[import_three18.MirroredRepeatWrapping] = WEBGL_CONSTANTS.MIRRORED_REPEAT;
6599
6781
  var PATH_PROPERTIES = {
6600
6782
  scale: "scale",
6601
6783
  position: "translation",
6602
6784
  quaternion: "rotation",
6603
6785
  morphTargetInfluences: "weights"
6604
6786
  };
6605
- var DEFAULT_SPECULAR_COLOR = new import_three19.Color();
6787
+ var DEFAULT_SPECULAR_COLOR = new import_three18.Color();
6606
6788
  var GLB_HEADER_BYTES = 12;
6607
6789
  var GLB_HEADER_MAGIC = 1179937895;
6608
6790
  var GLB_VERSION = 2;
@@ -6636,7 +6818,7 @@ function getMinMax(attribute, start, count) {
6636
6818
  else if (a === 2) value = attribute.getZ(i);
6637
6819
  else if (a === 3) value = attribute.getW(i);
6638
6820
  if (attribute.normalized === true) {
6639
- value = import_three19.MathUtils.normalize(value, attribute.array);
6821
+ value = import_three18.MathUtils.normalize(value, attribute.array);
6640
6822
  }
6641
6823
  }
6642
6824
  output.min[a] = Math.min(output.min[a], value);
@@ -6669,19 +6851,20 @@ function getCanvas() {
6669
6851
  return document.createElement("canvas");
6670
6852
  }
6671
6853
  function getToBlobPromise(canvas, mimeType) {
6672
- if (canvas.toBlob !== void 0) {
6854
+ if (typeof OffscreenCanvas !== "undefined" && canvas instanceof OffscreenCanvas) {
6855
+ let quality;
6856
+ if (mimeType === "image/jpeg") {
6857
+ quality = 0.92;
6858
+ } else if (mimeType === "image/webp") {
6859
+ quality = 0.8;
6860
+ }
6861
+ return canvas.convertToBlob({
6862
+ type: mimeType,
6863
+ quality
6864
+ });
6865
+ } else {
6673
6866
  return new Promise((resolve) => canvas.toBlob(resolve, mimeType));
6674
6867
  }
6675
- let quality;
6676
- if (mimeType === "image/jpeg") {
6677
- quality = 0.92;
6678
- } else if (mimeType === "image/webp") {
6679
- quality = 0.8;
6680
- }
6681
- return canvas.convertToBlob({
6682
- type: mimeType,
6683
- quality
6684
- });
6685
6868
  }
6686
6869
  var GLTFWriter = class {
6687
6870
  constructor() {
@@ -6700,7 +6883,7 @@ var GLTFWriter = class {
6700
6883
  this.json = {
6701
6884
  asset: {
6702
6885
  version: "2.0",
6703
- generator: "THREE.GLTFExporter"
6886
+ generator: "THREE.GLTFExporter r" + import_three18.REVISION
6704
6887
  }
6705
6888
  };
6706
6889
  this.cache = {
@@ -6709,19 +6892,25 @@ var GLTFWriter = class {
6709
6892
  attributesNormalized: /* @__PURE__ */ new Map(),
6710
6893
  materials: /* @__PURE__ */ new Map(),
6711
6894
  textures: /* @__PURE__ */ new Map(),
6712
- images: /* @__PURE__ */ new Map()
6895
+ images: /* @__PURE__ */ new Map(),
6896
+ normalMaps: /* @__PURE__ */ new Map()
6713
6897
  };
6898
+ this.textureUtils = null;
6714
6899
  }
6715
6900
  setPlugins(plugins) {
6716
6901
  this.plugins = plugins;
6717
6902
  }
6903
+ setTextureUtils(utils) {
6904
+ this.textureUtils = utils;
6905
+ }
6718
6906
  /**
6719
6907
  * Parse scenes and generate GLTF output
6720
- * @param {Scene or [THREE.Scenes]} input Scene or Array of THREE.Scenes
6721
- * @param {Function} onDone Callback on completed
6722
- * @param {Object} options options
6908
+ *
6909
+ * @param {Scene|Array<Scene>} input Scene or Array of THREE.Scenes
6910
+ * @param {Function} onDone Callback on completed
6911
+ * @param {Object} options options
6723
6912
  */
6724
- async write(input, onDone, options = {}) {
6913
+ async writeAsync(input, onDone, options = {}) {
6725
6914
  this.options = Object.assign({
6726
6915
  // default options
6727
6916
  binary: false,
@@ -6729,12 +6918,13 @@ var GLTFWriter = class {
6729
6918
  onlyVisible: true,
6730
6919
  maxTextureSize: Infinity,
6731
6920
  animations: [],
6732
- includeCustomExtensions: false
6921
+ includeCustomExtensions: false,
6922
+ copyright: null
6733
6923
  }, options);
6734
6924
  if (this.options.animations.length > 0) {
6735
6925
  this.options.trs = true;
6736
6926
  }
6737
- this.processInput(input);
6927
+ await this.processInputAsync(input);
6738
6928
  await Promise.all(this.pending);
6739
6929
  const writer = this;
6740
6930
  const buffers = writer.buffers;
@@ -6748,6 +6938,7 @@ var GLTFWriter = class {
6748
6938
  if (extensionsUsedList.length > 0) json.extensionsUsed = extensionsUsedList;
6749
6939
  if (extensionsRequiredList.length > 0) json.extensionsRequired = extensionsRequiredList;
6750
6940
  if (json.buffers && json.buffers.length > 0) json.buffers[0].byteLength = blob.size;
6941
+ if (options.copyright) json.asset.copyright = options.copyright;
6751
6942
  if (options.binary === true) {
6752
6943
  const reader = new FileReader();
6753
6944
  reader.readAsArrayBuffer(blob);
@@ -6796,7 +6987,7 @@ var GLTFWriter = class {
6796
6987
  /**
6797
6988
  * Serializes a userData.
6798
6989
  *
6799
- * @param {THREE.Object3D|THREE.Material} object
6990
+ * @param {THREE.Object3D|THREE.Material|THREE.BufferGeometry|THREE.AnimationClip} object
6800
6991
  * @param {Object} objectDef
6801
6992
  */
6802
6993
  serializeUserData(object, objectDef) {
@@ -6820,8 +7011,10 @@ var GLTFWriter = class {
6820
7011
  }
6821
7012
  /**
6822
7013
  * Returns ids for buffer attributes.
6823
- * @param {Object} object
6824
- * @return {Integer}
7014
+ *
7015
+ * @param {Object} attribute
7016
+ * @param {boolean} [isRelativeCopy=false]
7017
+ * @return {number} An integer
6825
7018
  */
6826
7019
  getUID(attribute, isRelativeCopy = false) {
6827
7020
  if (this.uids.has(attribute) === false) {
@@ -6837,12 +7030,12 @@ var GLTFWriter = class {
6837
7030
  * Checks if normal attribute values are normalized.
6838
7031
  *
6839
7032
  * @param {BufferAttribute} normal
6840
- * @returns {Boolean}
7033
+ * @returns {boolean}
6841
7034
  */
6842
7035
  isNormalizedNormalAttribute(normal) {
6843
7036
  const cache = this.cache;
6844
7037
  if (cache.attributesNormalized.has(normal)) return false;
6845
- const v = new import_three19.Vector3();
7038
+ const v = new import_three18.Vector3();
6846
7039
  for (let i = 0, il = normal.count; i < il; i++) {
6847
7040
  if (Math.abs(v.fromBufferAttribute(normal, i).length() - 1) > 5e-4) return false;
6848
7041
  }
@@ -6859,7 +7052,7 @@ var GLTFWriter = class {
6859
7052
  const cache = this.cache;
6860
7053
  if (cache.attributesNormalized.has(normal)) return cache.attributesNormalized.get(normal);
6861
7054
  const attribute = normal.clone();
6862
- const v = new import_three19.Vector3();
7055
+ const v = new import_three18.Vector3();
6863
7056
  for (let i = 0, il = attribute.count; i < il; i++) {
6864
7057
  v.fromBufferAttribute(attribute, i);
6865
7058
  if (v.x === 0 && v.y === 0 && v.z === 0) {
@@ -6900,10 +7093,10 @@ var GLTFWriter = class {
6900
7093
  this.extensionsUsed["KHR_texture_transform"] = true;
6901
7094
  }
6902
7095
  }
6903
- buildMetalRoughTexture(metalnessMap, roughnessMap) {
7096
+ async buildMetalRoughTextureAsync(metalnessMap, roughnessMap) {
6904
7097
  if (metalnessMap === roughnessMap) return metalnessMap;
6905
7098
  function getEncodingConversion(map) {
6906
- if (map.colorSpace === import_three19.SRGBColorSpace) {
7099
+ if (map.colorSpace === import_three18.SRGBColorSpace) {
6907
7100
  return function SRGBToLinear(c) {
6908
7101
  return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
6909
7102
  };
@@ -6912,12 +7105,11 @@ var GLTFWriter = class {
6912
7105
  return c;
6913
7106
  };
6914
7107
  }
6915
- console.warn("THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures.");
6916
- if (metalnessMap instanceof import_three19.CompressedTexture) {
6917
- metalnessMap = decompress(metalnessMap);
7108
+ if (metalnessMap instanceof import_three18.CompressedTexture) {
7109
+ metalnessMap = await this.decompressTextureAsync(metalnessMap);
6918
7110
  }
6919
- if (roughnessMap instanceof import_three19.CompressedTexture) {
6920
- roughnessMap = decompress(roughnessMap);
7111
+ if (roughnessMap instanceof import_three18.CompressedTexture) {
7112
+ roughnessMap = await this.decompressTextureAsync(roughnessMap);
6921
7113
  }
6922
7114
  const metalness = metalnessMap ? metalnessMap.image : null;
6923
7115
  const roughness = roughnessMap ? roughnessMap.image : null;
@@ -6926,7 +7118,9 @@ var GLTFWriter = class {
6926
7118
  const canvas = getCanvas();
6927
7119
  canvas.width = width;
6928
7120
  canvas.height = height;
6929
- const context = canvas.getContext("2d");
7121
+ const context = canvas.getContext("2d", {
7122
+ willReadFrequently: true
7123
+ });
6930
7124
  context.fillStyle = "#00ffff";
6931
7125
  context.fillRect(0, 0, width, height);
6932
7126
  const composite = context.getImageData(0, 0, width, height);
@@ -6949,18 +7143,60 @@ var GLTFWriter = class {
6949
7143
  context.putImageData(composite, 0, 0);
6950
7144
  const reference = metalnessMap || roughnessMap;
6951
7145
  const texture = reference.clone();
6952
- texture.source = new import_three19.Source(canvas);
6953
- texture.colorSpace = import_three19.NoColorSpace;
7146
+ texture.source = new import_three18.TextureSource(canvas);
7147
+ texture.colorSpace = import_three18.NoColorSpace;
6954
7148
  texture.channel = (metalnessMap || roughnessMap).channel;
6955
7149
  if (metalnessMap && roughnessMap && metalnessMap.channel !== roughnessMap.channel) {
6956
7150
  console.warn("THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match.");
6957
7151
  }
7152
+ console.warn("THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures.");
6958
7153
  return texture;
6959
7154
  }
7155
+ /**
7156
+ * Builds a copy of the given normal map with the red and/or green channels
7157
+ * inverted (`color = 255 - color`). This is used to bake the sign of
7158
+ * `material.normalScale` and the tangent-space convention into the texture,
7159
+ * since glTF only supports OpenGL-style normal maps with a univariate,
7160
+ * positive scale.
7161
+ *
7162
+ * @param {THREE.Texture} normalMap The source normal map.
7163
+ * @param {boolean} flipX Whether to invert the red channel (normal X).
7164
+ * @param {boolean} flipY Whether to invert the green channel (normal Y).
7165
+ * @return {Promise<THREE.Texture>} The derived normal map texture.
7166
+ */
7167
+ async buildNormalMapTextureAsync(normalMap, flipX, flipY) {
7168
+ if (normalMap instanceof import_three18.CompressedTexture) {
7169
+ normalMap = await this.decompressTextureAsync(normalMap);
7170
+ }
7171
+ const image = normalMap.image;
7172
+ const canvas = getCanvas();
7173
+ canvas.width = image.width;
7174
+ canvas.height = image.height;
7175
+ const context = canvas.getContext("2d", {
7176
+ willReadFrequently: true
7177
+ });
7178
+ context.drawImage(image, 0, 0, canvas.width, canvas.height);
7179
+ const imageData = context.getImageData(0, 0, canvas.width, canvas.height);
7180
+ const data = imageData.data;
7181
+ for (let i = 0; i < data.length; i += 4) {
7182
+ if (flipX) data[i + 0] = 255 - data[i + 0];
7183
+ if (flipY) data[i + 1] = 255 - data[i + 1];
7184
+ }
7185
+ context.putImageData(imageData, 0, 0);
7186
+ const texture = normalMap.clone();
7187
+ texture.source = new import_three18.TextureSource(canvas);
7188
+ return texture;
7189
+ }
7190
+ async decompressTextureAsync(texture, maxTextureSize = Infinity) {
7191
+ if (this.textureUtils === null) {
7192
+ throw new Error("THREE.GLTFExporter: setTextureUtils() must be called to process compressed textures.");
7193
+ }
7194
+ return await this.textureUtils.decompress(texture, maxTextureSize);
7195
+ }
6960
7196
  /**
6961
7197
  * Process a buffer to append to the default one.
6962
- * @param {ArrayBuffer} buffer
6963
- * @return {Integer}
7198
+ * @param {ArrayBuffer} buffer
7199
+ * @return {0}
6964
7200
  */
6965
7201
  processBuffer(buffer) {
6966
7202
  const json = this.json;
@@ -6971,11 +7207,11 @@ var GLTFWriter = class {
6971
7207
  }
6972
7208
  /**
6973
7209
  * Process and generate a BufferView
6974
- * @param {BufferAttribute} attribute
6975
- * @param {number} componentType
6976
- * @param {number} start
6977
- * @param {number} count
6978
- * @param {number} target (Optional) Target usage of the BufferView
7210
+ * @param {BufferAttribute} attribute
7211
+ * @param {number} componentType
7212
+ * @param {number} start
7213
+ * @param {number} count
7214
+ * @param {number} [target] Target usage of the BufferView
6979
7215
  * @return {Object}
6980
7216
  */
6981
7217
  processBufferView(attribute, componentType, start, count, target) {
@@ -6994,7 +7230,11 @@ var GLTFWriter = class {
6994
7230
  default:
6995
7231
  componentSize = 4;
6996
7232
  }
6997
- const byteLength = getPaddedBufferSize(count * attribute.itemSize * componentSize);
7233
+ let byteStride = attribute.itemSize * componentSize;
7234
+ if (target === WEBGL_CONSTANTS.ARRAY_BUFFER) {
7235
+ byteStride = Math.ceil(byteStride / 4) * 4;
7236
+ }
7237
+ const byteLength = getPaddedBufferSize(count * byteStride);
6998
7238
  const dataView = new DataView(new ArrayBuffer(byteLength));
6999
7239
  let offset = 0;
7000
7240
  for (let i = start; i < start + count; i++) {
@@ -7008,7 +7248,7 @@ var GLTFWriter = class {
7008
7248
  else if (a === 2) value = attribute.getZ(i);
7009
7249
  else if (a === 3) value = attribute.getW(i);
7010
7250
  if (attribute.normalized === true) {
7011
- value = import_three19.MathUtils.normalize(value, attribute.array);
7251
+ value = import_three18.MathUtils.normalize(value, attribute.array);
7012
7252
  }
7013
7253
  }
7014
7254
  if (componentType === WEBGL_CONSTANTS.FLOAT) {
@@ -7028,6 +7268,9 @@ var GLTFWriter = class {
7028
7268
  }
7029
7269
  offset += componentSize;
7030
7270
  }
7271
+ if (offset % byteStride !== 0) {
7272
+ offset += byteStride - offset % byteStride;
7273
+ }
7031
7274
  }
7032
7275
  const bufferViewDef = {
7033
7276
  buffer: this.processBuffer(dataView.buffer),
@@ -7036,7 +7279,7 @@ var GLTFWriter = class {
7036
7279
  };
7037
7280
  if (target !== void 0) bufferViewDef.target = target;
7038
7281
  if (target === WEBGL_CONSTANTS.ARRAY_BUFFER) {
7039
- bufferViewDef.byteStride = attribute.itemSize * componentSize;
7282
+ bufferViewDef.byteStride = byteStride;
7040
7283
  }
7041
7284
  this.byteOffset += byteLength;
7042
7285
  json.bufferViews.push(bufferViewDef);
@@ -7049,7 +7292,7 @@ var GLTFWriter = class {
7049
7292
  /**
7050
7293
  * Process and generate a BufferView from an image Blob.
7051
7294
  * @param {Blob} blob
7052
- * @return {Promise<Integer>}
7295
+ * @return {Promise<number>} An integer
7053
7296
  */
7054
7297
  processBufferViewImage(blob) {
7055
7298
  const writer = this;
@@ -7072,11 +7315,11 @@ var GLTFWriter = class {
7072
7315
  }
7073
7316
  /**
7074
7317
  * Process attribute to generate an accessor
7075
- * @param {BufferAttribute} attribute Attribute to process
7076
- * @param {THREE.BufferGeometry} geometry (Optional) Geometry used for truncated draw range
7077
- * @param {Integer} start (Optional)
7078
- * @param {Integer} count (Optional)
7079
- * @return {Integer|null} Index of the processed accessor on the "accessors" array
7318
+ * @param {BufferAttribute} attribute Attribute to process
7319
+ * @param {?BufferGeometry} [geometry] Geometry used for truncated draw range
7320
+ * @param {number} [start=0]
7321
+ * @param {number} [count=Infinity]
7322
+ * @return {?number} Index of the processed accessor on the "accessors" array
7080
7323
  */
7081
7324
  processAccessor(attribute, geometry, start, count) {
7082
7325
  const json = this.json;
@@ -7130,11 +7373,11 @@ var GLTFWriter = class {
7130
7373
  }
7131
7374
  /**
7132
7375
  * Process image
7133
- * @param {Image} image to process
7134
- * @param {Integer} format of the image (RGBAFormat)
7135
- * @param {Boolean} flipY before writing out the image
7136
- * @param {String} mimeType export format
7137
- * @return {Integer} Index of the processed texture in the "images" array
7376
+ * @param {Image} image to process
7377
+ * @param {number} format Identifier of the format (RGBAFormat)
7378
+ * @param {boolean} flipY before writing out the image
7379
+ * @param {string} mimeType export format
7380
+ * @return {number} Index of the processed texture in the "images" array
7138
7381
  */
7139
7382
  processImage(image, format, flipY, mimeType = "image/png") {
7140
7383
  if (image !== null) {
@@ -7152,13 +7395,15 @@ var GLTFWriter = class {
7152
7395
  const canvas = getCanvas();
7153
7396
  canvas.width = Math.min(image.width, options.maxTextureSize);
7154
7397
  canvas.height = Math.min(image.height, options.maxTextureSize);
7155
- const ctx = canvas.getContext("2d");
7398
+ const ctx = canvas.getContext("2d", {
7399
+ willReadFrequently: true
7400
+ });
7156
7401
  if (flipY === true) {
7157
7402
  ctx.translate(0, canvas.height);
7158
7403
  ctx.scale(1, -1);
7159
7404
  }
7160
7405
  if (image.data !== void 0) {
7161
- if (format !== import_three19.RGBAFormat) {
7406
+ if (format !== import_three18.RGBAFormat) {
7162
7407
  console.error("GLTFExporter: Only RGBAFormat is supported.", format);
7163
7408
  }
7164
7409
  if (image.width > options.maxTextureSize || image.height > options.maxTextureSize) {
@@ -7173,7 +7418,11 @@ var GLTFWriter = class {
7173
7418
  }
7174
7419
  ctx.putImageData(new ImageData(data, image.width, image.height), 0, 0);
7175
7420
  } else {
7176
- ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
7421
+ 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) {
7422
+ ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
7423
+ } else {
7424
+ throw new Error("THREE.GLTFExporter: Invalid image type. Use HTMLImageElement, HTMLCanvasElement, ImageBitmap or OffscreenCanvas.");
7425
+ }
7177
7426
  }
7178
7427
  if (options.binary === true) {
7179
7428
  pending.push(
@@ -7182,15 +7431,7 @@ var GLTFWriter = class {
7182
7431
  })
7183
7432
  );
7184
7433
  } else {
7185
- if (canvas.toDataURL !== void 0) {
7186
- imageDef.uri = canvas.toDataURL(mimeType);
7187
- } else {
7188
- pending.push(
7189
- getToBlobPromise(canvas, mimeType).then((blob) => new FileReader().readAsDataURL(blob)).then((dataURL) => {
7190
- imageDef.uri = dataURL;
7191
- })
7192
- );
7193
- }
7434
+ imageDef.uri = import_three18.ImageUtils.getDataURL(canvas, mimeType);
7194
7435
  }
7195
7436
  const index = json.images.push(imageDef) - 1;
7196
7437
  cachedImages[key] = index;
@@ -7201,8 +7442,8 @@ var GLTFWriter = class {
7201
7442
  }
7202
7443
  /**
7203
7444
  * Process sampler
7204
- * @param {Texture} map Texture to process
7205
- * @return {Integer} Index of the processed texture in the "samplers" array
7445
+ * @param {Texture} map Texture to process
7446
+ * @return {number} Index of the processed texture in the "samplers" array
7206
7447
  */
7207
7448
  processSampler(map) {
7208
7449
  const json = this.json;
@@ -7217,28 +7458,37 @@ var GLTFWriter = class {
7217
7458
  }
7218
7459
  /**
7219
7460
  * Process texture
7220
- * @param {Texture} map Map to process
7221
- * @return {Integer} Index of the processed texture in the "textures" array
7461
+ * @param {Texture} map Map to process
7462
+ * @return {Promise<number>} Index of the processed texture in the "textures" array
7222
7463
  */
7223
- processTexture(map) {
7464
+ async processTextureAsync(map) {
7224
7465
  const writer = this;
7225
7466
  const options = writer.options;
7226
7467
  const cache = this.cache;
7227
7468
  const json = this.json;
7228
7469
  if (cache.textures.has(map)) return cache.textures.get(map);
7229
7470
  if (!json.textures) json.textures = [];
7230
- if (map instanceof import_three19.CompressedTexture) {
7231
- map = decompress(map, options.maxTextureSize);
7471
+ if (map instanceof import_three18.CompressedTexture) {
7472
+ map = await this.decompressTextureAsync(map, options.maxTextureSize);
7232
7473
  }
7233
- let mimeType = map.userData.mimeType;
7234
- if (mimeType === "image/webp") mimeType = "image/png";
7474
+ const mimeType = map.userData.mimeType;
7475
+ const imageIndex = this.processImage(map.image, map.format, map.flipY, mimeType);
7235
7476
  const textureDef = {
7236
- sampler: this.processSampler(map),
7237
- source: this.processImage(map.image, map.format, map.flipY, mimeType)
7477
+ sampler: this.processSampler(map)
7238
7478
  };
7479
+ if (mimeType === "image/webp") {
7480
+ textureDef.extensions = textureDef.extensions || {};
7481
+ textureDef.extensions["EXT_texture_webp"] = {
7482
+ source: imageIndex
7483
+ };
7484
+ this.extensionsUsed["EXT_texture_webp"] = true;
7485
+ this.extensionsRequired["EXT_texture_webp"] = true;
7486
+ } else {
7487
+ textureDef.source = imageIndex;
7488
+ }
7239
7489
  if (map.name) textureDef.name = map.name;
7240
- this._invokeAll(function(ext) {
7241
- ext.writeTexture && ext.writeTexture(map, textureDef);
7490
+ await this._invokeAllAsync(async function(ext) {
7491
+ ext.writeTexture && await ext.writeTexture(map, textureDef);
7242
7492
  });
7243
7493
  const index = json.textures.push(textureDef) - 1;
7244
7494
  cache.textures.set(map, index);
@@ -7246,13 +7496,16 @@ var GLTFWriter = class {
7246
7496
  }
7247
7497
  /**
7248
7498
  * Process material
7249
- * @param {THREE.Material} material Material to process
7250
- * @return {Integer|null} Index of the processed material in the "materials" array
7499
+ * @param {THREE.Material} material Material to process
7500
+ * @param {THREE.BufferGeometry} [geometry] Geometry the material is used with.
7501
+ * @return {Promise<?number>} Index of the processed material in the "materials" array
7251
7502
  */
7252
- processMaterial(material) {
7503
+ async processMaterialAsync(material, geometry) {
7253
7504
  const cache = this.cache;
7254
7505
  const json = this.json;
7255
- if (cache.materials.has(material)) return cache.materials.get(material);
7506
+ const hasTangent = geometry !== void 0 && geometry.hasAttribute("tangent");
7507
+ const cacheKey = material.normalMap ? material.uuid + ":" + hasTangent : material.uuid;
7508
+ if (cache.materials.has(cacheKey)) return cache.materials.get(cacheKey);
7256
7509
  if (material.isShaderMaterial) {
7257
7510
  console.warn("GLTFExporter: THREE.ShaderMaterial not supported.");
7258
7511
  return null;
@@ -7270,21 +7523,21 @@ var GLTFWriter = class {
7270
7523
  materialDef.pbrMetallicRoughness.metallicFactor = material.metalness;
7271
7524
  materialDef.pbrMetallicRoughness.roughnessFactor = material.roughness;
7272
7525
  } else {
7273
- materialDef.pbrMetallicRoughness.metallicFactor = 0.5;
7274
- materialDef.pbrMetallicRoughness.roughnessFactor = 0.5;
7526
+ materialDef.pbrMetallicRoughness.metallicFactor = 0;
7527
+ materialDef.pbrMetallicRoughness.roughnessFactor = 1;
7275
7528
  }
7276
7529
  if (material.metalnessMap || material.roughnessMap) {
7277
- const metalRoughTexture = this.buildMetalRoughTexture(material.metalnessMap, material.roughnessMap);
7530
+ const metalRoughTexture = await this.buildMetalRoughTextureAsync(material.metalnessMap, material.roughnessMap);
7278
7531
  const metalRoughMapDef = {
7279
- index: this.processTexture(metalRoughTexture),
7280
- channel: metalRoughTexture.channel
7532
+ index: await this.processTextureAsync(metalRoughTexture),
7533
+ texCoord: metalRoughTexture.channel
7281
7534
  };
7282
7535
  this.applyTextureTransform(metalRoughMapDef, metalRoughTexture);
7283
7536
  materialDef.pbrMetallicRoughness.metallicRoughnessTexture = metalRoughMapDef;
7284
7537
  }
7285
7538
  if (material.map) {
7286
7539
  const baseColorMapDef = {
7287
- index: this.processTexture(material.map),
7540
+ index: await this.processTextureAsync(material.map),
7288
7541
  texCoord: material.map.channel
7289
7542
  };
7290
7543
  this.applyTextureTransform(baseColorMapDef, material.map);
@@ -7298,7 +7551,7 @@ var GLTFWriter = class {
7298
7551
  }
7299
7552
  if (material.emissiveMap) {
7300
7553
  const emissiveMapDef = {
7301
- index: this.processTexture(material.emissiveMap),
7554
+ index: await this.processTextureAsync(material.emissiveMap),
7302
7555
  texCoord: material.emissiveMap.channel
7303
7556
  };
7304
7557
  this.applyTextureTransform(emissiveMapDef, material.emissiveMap);
@@ -7306,19 +7559,32 @@ var GLTFWriter = class {
7306
7559
  }
7307
7560
  }
7308
7561
  if (material.normalMap) {
7562
+ const normalScale = material.normalScale;
7563
+ const flipX = normalScale.x < 0;
7564
+ const flipY = hasTangent ? normalScale.y < 0 : normalScale.y > 0;
7565
+ let normalMap = material.normalMap;
7566
+ if (flipX || flipY) {
7567
+ if (cache.normalMaps.has(material.normalMap) === false) cache.normalMaps.set(material.normalMap, {});
7568
+ const cachedVariants = cache.normalMaps.get(material.normalMap);
7569
+ const cacheKey2 = `${flipX}:${flipY}`;
7570
+ if (cachedVariants[cacheKey2] === void 0) {
7571
+ cachedVariants[cacheKey2] = await this.buildNormalMapTextureAsync(material.normalMap, flipX, flipY);
7572
+ }
7573
+ normalMap = cachedVariants[cacheKey2];
7574
+ }
7309
7575
  const normalMapDef = {
7310
- index: this.processTexture(material.normalMap),
7576
+ index: await this.processTextureAsync(normalMap),
7311
7577
  texCoord: material.normalMap.channel
7312
7578
  };
7313
- if (material.normalScale && material.normalScale.x !== 1) {
7314
- normalMapDef.scale = material.normalScale.x;
7579
+ if (Math.abs(normalScale.x) !== 1) {
7580
+ normalMapDef.scale = Math.abs(normalScale.x);
7315
7581
  }
7316
7582
  this.applyTextureTransform(normalMapDef, material.normalMap);
7317
7583
  materialDef.normalTexture = normalMapDef;
7318
7584
  }
7319
7585
  if (material.aoMap) {
7320
7586
  const occlusionMapDef = {
7321
- index: this.processTexture(material.aoMap),
7587
+ index: await this.processTextureAsync(material.aoMap),
7322
7588
  texCoord: material.aoMap.channel
7323
7589
  };
7324
7590
  if (material.aoMapIntensity !== 1) {
@@ -7335,22 +7601,22 @@ var GLTFWriter = class {
7335
7601
  materialDef.alphaCutoff = material.alphaTest;
7336
7602
  }
7337
7603
  }
7338
- if (material.side === import_three19.DoubleSide) materialDef.doubleSided = true;
7604
+ if (material.side === import_three18.DoubleSide) materialDef.doubleSided = true;
7339
7605
  if (material.name !== "") materialDef.name = material.name;
7340
7606
  this.serializeUserData(material, materialDef);
7341
- this._invokeAll(function(ext) {
7342
- ext.writeMaterial && ext.writeMaterial(material, materialDef);
7607
+ await this._invokeAllAsync(async function(ext) {
7608
+ ext.writeMaterialAsync && await ext.writeMaterialAsync(material, materialDef);
7343
7609
  });
7344
7610
  const index = json.materials.push(materialDef) - 1;
7345
- cache.materials.set(material, index);
7611
+ cache.materials.set(cacheKey, index);
7346
7612
  return index;
7347
7613
  }
7348
7614
  /**
7349
7615
  * Process mesh
7350
- * @param {THREE.Mesh} mesh Mesh to process
7351
- * @return {Integer|null} Index of the processed mesh in the "meshes" array
7616
+ * @param {THREE.Mesh} mesh Mesh to process
7617
+ * @return {Promise<?number>} Index of the processed mesh in the "meshes" array
7352
7618
  */
7353
- processMesh(mesh) {
7619
+ async processMeshAsync(mesh) {
7354
7620
  const cache = this.cache;
7355
7621
  const json = this.json;
7356
7622
  const meshCacheKeyParts = [mesh.geometry.uuid];
@@ -7400,7 +7666,7 @@ var GLTFWriter = class {
7400
7666
  const attribute = geometry.attributes[attributeName];
7401
7667
  attributeName = nameConversion[attributeName] || attributeName.toUpperCase();
7402
7668
  const validVertexAttributes = /^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/;
7403
- if (!validVertexAttributes.test(attributeName)) attributeName = "_" + attributeName;
7669
+ if (!validVertexAttributes.test(attributeName) && !attributeName.startsWith("_")) attributeName = "_" + attributeName;
7404
7670
  if (cache.attributes.has(this.getUID(attribute))) {
7405
7671
  attributes[attributeName] = cache.attributes.get(this.getUID(attribute));
7406
7672
  continue;
@@ -7409,7 +7675,10 @@ var GLTFWriter = class {
7409
7675
  const array = attribute.array;
7410
7676
  if (attributeName === "JOINTS_0" && !(array instanceof Uint16Array) && !(array instanceof Uint8Array)) {
7411
7677
  console.warn('GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.');
7412
- modifiedAttribute = new import_three19.BufferAttribute(new Uint16Array(array), attribute.itemSize, attribute.normalized);
7678
+ modifiedAttribute = GLTFExporter.Utils.toTypedBufferAttribute(attribute, Uint16Array);
7679
+ } else if ((array instanceof Uint32Array || array instanceof Int32Array) && !attributeName.startsWith("_")) {
7680
+ console.warn(`GLTFExporter: Attribute "${attributeName}" converted to type FLOAT.`);
7681
+ modifiedAttribute = GLTFExporter.Utils.toTypedBufferAttribute(attribute, Float32Array);
7413
7682
  }
7414
7683
  const accessor = this.processAccessor(modifiedAttribute || attribute, geometry);
7415
7684
  if (accessor !== null) {
@@ -7475,6 +7744,15 @@ var GLTFWriter = class {
7475
7744
  }
7476
7745
  const isMultiMaterial = Array.isArray(mesh.material);
7477
7746
  if (isMultiMaterial && geometry.groups.length === 0) return null;
7747
+ let didForceIndices = false;
7748
+ if (isMultiMaterial && geometry.index === null) {
7749
+ const indices = [];
7750
+ for (let i = 0, il = geometry.attributes.position.count; i < il; i++) {
7751
+ indices[i] = i;
7752
+ }
7753
+ geometry.setIndex(indices);
7754
+ didForceIndices = true;
7755
+ }
7478
7756
  const materials = isMultiMaterial ? mesh.material : [mesh.material];
7479
7757
  const groups = isMultiMaterial ? geometry.groups : [{ materialIndex: 0, start: void 0, count: void 0 }];
7480
7758
  for (let i = 0, il = groups.length; i < il; i++) {
@@ -7497,13 +7775,16 @@ var GLTFWriter = class {
7497
7775
  }
7498
7776
  if (primitive.indices === null) delete primitive.indices;
7499
7777
  }
7500
- const material = this.processMaterial(materials[groups[i].materialIndex]);
7778
+ const material = await this.processMaterialAsync(materials[groups[i].materialIndex], geometry);
7501
7779
  if (material !== null) primitive.material = material;
7502
7780
  primitives.push(primitive);
7503
7781
  }
7782
+ if (didForceIndices === true) {
7783
+ geometry.setIndex(null);
7784
+ }
7504
7785
  meshDef.primitives = primitives;
7505
7786
  if (!json.meshes) json.meshes = [];
7506
- this._invokeAll(function(ext) {
7787
+ await this._invokeAllAsync(function(ext) {
7507
7788
  ext.writeMesh && ext.writeMesh(mesh, meshDef);
7508
7789
  });
7509
7790
  const index = json.meshes.push(meshDef) - 1;
@@ -7549,8 +7830,8 @@ var GLTFWriter = class {
7549
7830
  }
7550
7831
  /**
7551
7832
  * Process camera
7552
- * @param {THREE.Camera} camera Camera to process
7553
- * @return {Integer} Index of the processed mesh in the "camera" array
7833
+ * @param {THREE.Camera} camera Camera to process
7834
+ * @return {number} Index of the processed mesh in the "camera" array
7554
7835
  */
7555
7836
  processCamera(camera) {
7556
7837
  const json = this.json;
@@ -7569,7 +7850,7 @@ var GLTFWriter = class {
7569
7850
  } else {
7570
7851
  cameraDef.perspective = {
7571
7852
  aspectRatio: camera.aspect,
7572
- yfov: import_three19.MathUtils.degToRad(camera.fov),
7853
+ yfov: import_three18.MathUtils.degToRad(camera.fov),
7573
7854
  zfar: camera.far <= 0 ? 1e-3 : camera.far,
7574
7855
  znear: camera.near < 0 ? 0 : camera.near
7575
7856
  };
@@ -7585,7 +7866,7 @@ var GLTFWriter = class {
7585
7866
  *
7586
7867
  * @param {THREE.AnimationClip} clip
7587
7868
  * @param {THREE.Object3D} root
7588
- * @return {number|null}
7869
+ * @return {?number}
7589
7870
  */
7590
7871
  processAnimation(clip, root) {
7591
7872
  const json = this.json;
@@ -7597,8 +7878,8 @@ var GLTFWriter = class {
7597
7878
  const samplers = [];
7598
7879
  for (let i = 0; i < tracks.length; ++i) {
7599
7880
  const track = tracks[i];
7600
- const trackBinding = import_three19.PropertyBinding.parseTrackName(track.name);
7601
- let trackNode = import_three19.PropertyBinding.findNode(root, trackBinding.nodeName);
7881
+ const trackBinding = import_three18.PropertyBinding.parseTrackName(track.name);
7882
+ let trackNode = import_three18.PropertyBinding.findNode(root, trackBinding.nodeName);
7602
7883
  const trackProperty = PATH_PROPERTIES[trackBinding.propertyName];
7603
7884
  if (trackBinding.objectName === "bones") {
7604
7885
  if (trackNode.isSkinnedMesh === true) {
@@ -7609,7 +7890,7 @@ var GLTFWriter = class {
7609
7890
  }
7610
7891
  if (!trackNode || !trackProperty) {
7611
7892
  console.warn('THREE.GLTFExporter: Could not export animation track "%s".', track.name);
7612
- return null;
7893
+ continue;
7613
7894
  }
7614
7895
  const inputItemSize = 1;
7615
7896
  let outputItemSize = track.values.length / track.times.length;
@@ -7620,14 +7901,14 @@ var GLTFWriter = class {
7620
7901
  if (track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline === true) {
7621
7902
  interpolation = "CUBICSPLINE";
7622
7903
  outputItemSize /= 3;
7623
- } else if (track.getInterpolation() === import_three19.InterpolateDiscrete) {
7904
+ } else if (track.getInterpolation() === import_three18.InterpolateDiscrete) {
7624
7905
  interpolation = "STEP";
7625
7906
  } else {
7626
7907
  interpolation = "LINEAR";
7627
7908
  }
7628
7909
  samplers.push({
7629
- input: this.processAccessor(new import_three19.BufferAttribute(track.times, inputItemSize)),
7630
- output: this.processAccessor(new import_three19.BufferAttribute(track.values, outputItemSize)),
7910
+ input: this.processAccessor(new import_three18.BufferAttribute(track.times, inputItemSize)),
7911
+ output: this.processAccessor(new import_three18.BufferAttribute(track.values, outputItemSize)),
7631
7912
  interpolation
7632
7913
  });
7633
7914
  channels.push({
@@ -7638,16 +7919,18 @@ var GLTFWriter = class {
7638
7919
  }
7639
7920
  });
7640
7921
  }
7641
- json.animations.push({
7922
+ const animationDef = {
7642
7923
  name: clip.name || "clip_" + json.animations.length,
7643
7924
  samplers,
7644
7925
  channels
7645
- });
7926
+ };
7927
+ this.serializeUserData(clip, animationDef);
7928
+ json.animations.push(animationDef);
7646
7929
  return json.animations.length - 1;
7647
7930
  }
7648
7931
  /**
7649
7932
  * @param {THREE.Object3D} object
7650
- * @return {number|null}
7933
+ * @return {?number}
7651
7934
  */
7652
7935
  processSkin(object) {
7653
7936
  const json = this.json;
@@ -7659,7 +7942,7 @@ var GLTFWriter = class {
7659
7942
  if (rootJoint === void 0) return null;
7660
7943
  const joints = [];
7661
7944
  const inverseBindMatrices = new Float32Array(skeleton.bones.length * 16);
7662
- const temporaryBoneInverse = new import_three19.Matrix4();
7945
+ const temporaryBoneInverse = new import_three18.Matrix4();
7663
7946
  for (let i = 0; i < skeleton.bones.length; ++i) {
7664
7947
  joints.push(nodeMap.get(skeleton.bones[i]));
7665
7948
  temporaryBoneInverse.copy(skeleton.boneInverses[i]);
@@ -7667,7 +7950,7 @@ var GLTFWriter = class {
7667
7950
  }
7668
7951
  if (json.skins === void 0) json.skins = [];
7669
7952
  json.skins.push({
7670
- inverseBindMatrices: this.processAccessor(new import_three19.BufferAttribute(inverseBindMatrices, 16)),
7953
+ inverseBindMatrices: this.processAccessor(new import_three18.BufferAttribute(inverseBindMatrices, 16)),
7671
7954
  joints,
7672
7955
  skeleton: nodeMap.get(rootJoint)
7673
7956
  });
@@ -7676,14 +7959,17 @@ var GLTFWriter = class {
7676
7959
  }
7677
7960
  /**
7678
7961
  * Process Object3D node
7679
- * @param {THREE.Object3D} node Object3D to processNode
7680
- * @return {Integer} Index of the node in the nodes list
7962
+ * @param {THREE.Object3D} object Object3D to processNodeAsync
7963
+ * @return {Promise<number>} Index of the node in the nodes list
7681
7964
  */
7682
- processNode(object) {
7965
+ async processNodeAsync(object) {
7683
7966
  const json = this.json;
7684
7967
  const options = this.options;
7685
7968
  const nodeMap = this.nodeMap;
7686
7969
  if (!json.nodes) json.nodes = [];
7970
+ if (object.pivot !== null) {
7971
+ return await this._processNodeWithPivotAsync(object);
7972
+ }
7687
7973
  const nodeDef = {};
7688
7974
  if (options.trs) {
7689
7975
  const rotation = object.quaternion.toArray();
@@ -7709,35 +7995,98 @@ var GLTFWriter = class {
7709
7995
  if (object.name !== "") nodeDef.name = String(object.name);
7710
7996
  this.serializeUserData(object, nodeDef);
7711
7997
  if (object.isMesh || object.isLine || object.isPoints) {
7712
- const meshIndex = this.processMesh(object);
7998
+ const meshIndex = await this.processMeshAsync(object);
7713
7999
  if (meshIndex !== null) nodeDef.mesh = meshIndex;
7714
8000
  } else if (object.isCamera) {
7715
8001
  nodeDef.camera = this.processCamera(object);
7716
8002
  }
7717
8003
  if (object.isSkinnedMesh) this.skins.push(object);
8004
+ const nodeIndex = json.nodes.push(nodeDef) - 1;
8005
+ nodeMap.set(object, nodeIndex);
7718
8006
  if (object.children.length > 0) {
7719
8007
  const children = [];
7720
8008
  for (let i = 0, l = object.children.length; i < l; i++) {
7721
8009
  const child = object.children[i];
7722
8010
  if (child.visible || options.onlyVisible === false) {
7723
- const nodeIndex2 = this.processNode(child);
7724
- if (nodeIndex2 !== null) children.push(nodeIndex2);
8011
+ const childNodeIndex = await this.processNodeAsync(child);
8012
+ if (childNodeIndex !== null) children.push(childNodeIndex);
7725
8013
  }
7726
8014
  }
7727
8015
  if (children.length > 0) nodeDef.children = children;
7728
8016
  }
7729
- this._invokeAll(function(ext) {
8017
+ await this._invokeAllAsync(function(ext) {
7730
8018
  ext.writeNode && ext.writeNode(object, nodeDef);
7731
8019
  });
7732
- const nodeIndex = json.nodes.push(nodeDef) - 1;
7733
- nodeMap.set(object, nodeIndex);
7734
8020
  return nodeIndex;
7735
8021
  }
8022
+ /**
8023
+ * Process Object3D node with pivot using container approach
8024
+ * @param {THREE.Object3D} object Object3D with pivot
8025
+ * @return {Promise<number>} Index of the container node
8026
+ */
8027
+ async _processNodeWithPivotAsync(object) {
8028
+ const json = this.json;
8029
+ const options = this.options;
8030
+ const nodeMap = this.nodeMap;
8031
+ const pivot = object.pivot;
8032
+ const containerDef = {};
8033
+ const rotation = object.quaternion.toArray();
8034
+ const position = [
8035
+ object.position.x + pivot.x,
8036
+ object.position.y + pivot.y,
8037
+ object.position.z + pivot.z
8038
+ ];
8039
+ const scale = object.scale.toArray();
8040
+ if (!equalArray(rotation, [0, 0, 0, 1])) {
8041
+ containerDef.rotation = rotation;
8042
+ }
8043
+ if (!equalArray(position, [0, 0, 0])) {
8044
+ containerDef.translation = position;
8045
+ }
8046
+ if (!equalArray(scale, [1, 1, 1])) {
8047
+ containerDef.scale = scale;
8048
+ }
8049
+ containerDef.extras = { pivot: pivot.toArray() };
8050
+ if (object.name !== "") containerDef.name = String(object.name);
8051
+ this.serializeUserData(object, containerDef);
8052
+ const containerIndex = json.nodes.push(containerDef) - 1;
8053
+ nodeMap.set(object, containerIndex);
8054
+ const childDef = {};
8055
+ const childPosition = [-pivot.x, -pivot.y, -pivot.z];
8056
+ if (!equalArray(childPosition, [0, 0, 0])) {
8057
+ childDef.translation = childPosition;
8058
+ }
8059
+ if (object.isMesh || object.isLine || object.isPoints) {
8060
+ const meshIndex = await this.processMeshAsync(object);
8061
+ if (meshIndex !== null) childDef.mesh = meshIndex;
8062
+ } else if (object.isCamera) {
8063
+ childDef.camera = this.processCamera(object);
8064
+ }
8065
+ if (object.isSkinnedMesh) this.skins.push(object);
8066
+ const childIndex = json.nodes.push(childDef) - 1;
8067
+ const containerChildren = [childIndex];
8068
+ if (object.children.length > 0) {
8069
+ const grandchildren = [];
8070
+ for (let i = 0, l = object.children.length; i < l; i++) {
8071
+ const child = object.children[i];
8072
+ if (child.visible || options.onlyVisible === false) {
8073
+ const childNodeIndex = await this.processNodeAsync(child);
8074
+ if (childNodeIndex !== null) grandchildren.push(childNodeIndex);
8075
+ }
8076
+ }
8077
+ if (grandchildren.length > 0) childDef.children = grandchildren;
8078
+ }
8079
+ containerDef.children = containerChildren;
8080
+ await this._invokeAllAsync(function(ext) {
8081
+ ext.writeNode && ext.writeNode(object, containerDef);
8082
+ });
8083
+ return containerIndex;
8084
+ }
7736
8085
  /**
7737
8086
  * Process Scene
7738
- * @param {Scene} node Scene to process
8087
+ * @param {Scene} scene Scene to process
7739
8088
  */
7740
- processScene(scene) {
8089
+ async processSceneAsync(scene) {
7741
8090
  const json = this.json;
7742
8091
  const options = this.options;
7743
8092
  if (!json.scenes) {
@@ -7751,7 +8100,7 @@ var GLTFWriter = class {
7751
8100
  for (let i = 0, l = scene.children.length; i < l; i++) {
7752
8101
  const child = scene.children[i];
7753
8102
  if (child.visible || options.onlyVisible === false) {
7754
- const nodeIndex = this.processNode(child);
8103
+ const nodeIndex = await this.processNodeAsync(child);
7755
8104
  if (nodeIndex !== null) nodes.push(nodeIndex);
7756
8105
  }
7757
8106
  }
@@ -7760,47 +8109,58 @@ var GLTFWriter = class {
7760
8109
  }
7761
8110
  /**
7762
8111
  * Creates a Scene to hold a list of objects and parse it
7763
- * @param {Array} objects List of objects to process
8112
+ * @param {Array<THREE.Object3D>} objects List of objects to process
7764
8113
  */
7765
- processObjects(objects) {
7766
- const scene = new import_three19.Scene();
8114
+ async processObjectsAsync(objects) {
8115
+ const scene = new import_three18.Scene();
7767
8116
  scene.name = "AuxScene";
7768
8117
  for (let i = 0; i < objects.length; i++) {
7769
8118
  scene.children.push(objects[i]);
7770
8119
  }
7771
- this.processScene(scene);
8120
+ await this.processSceneAsync(scene);
7772
8121
  }
7773
8122
  /**
7774
8123
  * @param {THREE.Object3D|Array<THREE.Object3D>} input
7775
8124
  */
7776
- processInput(input) {
8125
+ async processInputAsync(input) {
7777
8126
  const options = this.options;
7778
8127
  input = input instanceof Array ? input : [input];
7779
- this._invokeAll(function(ext) {
8128
+ await this._invokeAllAsync(function(ext) {
7780
8129
  ext.beforeParse && ext.beforeParse(input);
7781
8130
  });
7782
8131
  const objectsWithoutScene = [];
7783
8132
  for (let i = 0; i < input.length; i++) {
7784
- if (input[i] instanceof import_three19.Scene) {
7785
- this.processScene(input[i]);
8133
+ if (input[i] instanceof import_three18.Scene) {
8134
+ await this.processSceneAsync(input[i]);
7786
8135
  } else {
7787
8136
  objectsWithoutScene.push(input[i]);
7788
8137
  }
7789
8138
  }
7790
- if (objectsWithoutScene.length > 0) this.processObjects(objectsWithoutScene);
8139
+ if (objectsWithoutScene.length > 0) {
8140
+ await this.processObjectsAsync(objectsWithoutScene);
8141
+ }
7791
8142
  for (let i = 0; i < this.skins.length; ++i) {
7792
8143
  this.processSkin(this.skins[i]);
7793
8144
  }
7794
- for (let i = 0; i < options.animations.length; ++i) {
7795
- this.processAnimation(options.animations[i], input[0]);
8145
+ if (input.length === 1) {
8146
+ for (let i = 0; i < options.animations.length; ++i) {
8147
+ this.processAnimation(options.animations[i], input[0]);
8148
+ }
8149
+ } else {
8150
+ for (let i = 0; i < input.length; i++) {
8151
+ const animations = options.animations[i] || [];
8152
+ for (let j = 0; j < animations.length; ++j) {
8153
+ this.processAnimation(animations[j], input[i]);
8154
+ }
8155
+ }
7796
8156
  }
7797
- this._invokeAll(function(ext) {
8157
+ await this._invokeAllAsync(function(ext) {
7798
8158
  ext.afterParse && ext.afterParse(input);
7799
8159
  });
7800
8160
  }
7801
- _invokeAll(func) {
8161
+ async _invokeAllAsync(func) {
7802
8162
  for (let i = 0, il = this.plugins.length; i < il; i++) {
7803
- func(this.plugins[i]);
8163
+ await func(this.plugins[i]);
7804
8164
  }
7805
8165
  }
7806
8166
  };
@@ -7856,7 +8216,7 @@ var GLTFMaterialsUnlitExtension = class {
7856
8216
  this.writer = writer;
7857
8217
  this.name = "KHR_materials_unlit";
7858
8218
  }
7859
- writeMaterial(material, materialDef) {
8219
+ async writeMaterialAsync(material, materialDef) {
7860
8220
  if (!material.isMeshBasicMaterial) return;
7861
8221
  const writer = this.writer;
7862
8222
  const extensionsUsed = writer.extensionsUsed;
@@ -7872,7 +8232,7 @@ var GLTFMaterialsClearcoatExtension = class {
7872
8232
  this.writer = writer;
7873
8233
  this.name = "KHR_materials_clearcoat";
7874
8234
  }
7875
- writeMaterial(material, materialDef) {
8235
+ async writeMaterialAsync(material, materialDef) {
7876
8236
  if (!material.isMeshPhysicalMaterial || material.clearcoat === 0) return;
7877
8237
  const writer = this.writer;
7878
8238
  const extensionsUsed = writer.extensionsUsed;
@@ -7880,7 +8240,7 @@ var GLTFMaterialsClearcoatExtension = class {
7880
8240
  extensionDef.clearcoatFactor = material.clearcoat;
7881
8241
  if (material.clearcoatMap) {
7882
8242
  const clearcoatMapDef = {
7883
- index: writer.processTexture(material.clearcoatMap),
8243
+ index: await writer.processTextureAsync(material.clearcoatMap),
7884
8244
  texCoord: material.clearcoatMap.channel
7885
8245
  };
7886
8246
  writer.applyTextureTransform(clearcoatMapDef, material.clearcoatMap);
@@ -7889,7 +8249,7 @@ var GLTFMaterialsClearcoatExtension = class {
7889
8249
  extensionDef.clearcoatRoughnessFactor = material.clearcoatRoughness;
7890
8250
  if (material.clearcoatRoughnessMap) {
7891
8251
  const clearcoatRoughnessMapDef = {
7892
- index: writer.processTexture(material.clearcoatRoughnessMap),
8252
+ index: await writer.processTextureAsync(material.clearcoatRoughnessMap),
7893
8253
  texCoord: material.clearcoatRoughnessMap.channel
7894
8254
  };
7895
8255
  writer.applyTextureTransform(clearcoatRoughnessMapDef, material.clearcoatRoughnessMap);
@@ -7897,9 +8257,10 @@ var GLTFMaterialsClearcoatExtension = class {
7897
8257
  }
7898
8258
  if (material.clearcoatNormalMap) {
7899
8259
  const clearcoatNormalMapDef = {
7900
- index: writer.processTexture(material.clearcoatNormalMap),
8260
+ index: await writer.processTextureAsync(material.clearcoatNormalMap),
7901
8261
  texCoord: material.clearcoatNormalMap.channel
7902
8262
  };
8263
+ if (material.clearcoatNormalScale.x !== 1) clearcoatNormalMapDef.scale = material.clearcoatNormalScale.x;
7903
8264
  writer.applyTextureTransform(clearcoatNormalMapDef, material.clearcoatNormalMap);
7904
8265
  extensionDef.clearcoatNormalTexture = clearcoatNormalMapDef;
7905
8266
  }
@@ -7908,12 +8269,28 @@ var GLTFMaterialsClearcoatExtension = class {
7908
8269
  extensionsUsed[this.name] = true;
7909
8270
  }
7910
8271
  };
8272
+ var GLTFMaterialsDispersionExtension = class {
8273
+ constructor(writer) {
8274
+ this.writer = writer;
8275
+ this.name = "KHR_materials_dispersion";
8276
+ }
8277
+ async writeMaterialAsync(material, materialDef) {
8278
+ if (!material.isMeshPhysicalMaterial || material.dispersion === 0) return;
8279
+ const writer = this.writer;
8280
+ const extensionsUsed = writer.extensionsUsed;
8281
+ const extensionDef = {};
8282
+ extensionDef.dispersion = material.dispersion;
8283
+ materialDef.extensions = materialDef.extensions || {};
8284
+ materialDef.extensions[this.name] = extensionDef;
8285
+ extensionsUsed[this.name] = true;
8286
+ }
8287
+ };
7911
8288
  var GLTFMaterialsIridescenceExtension = class {
7912
8289
  constructor(writer) {
7913
8290
  this.writer = writer;
7914
8291
  this.name = "KHR_materials_iridescence";
7915
8292
  }
7916
- writeMaterial(material, materialDef) {
8293
+ async writeMaterialAsync(material, materialDef) {
7917
8294
  if (!material.isMeshPhysicalMaterial || material.iridescence === 0) return;
7918
8295
  const writer = this.writer;
7919
8296
  const extensionsUsed = writer.extensionsUsed;
@@ -7921,7 +8298,7 @@ var GLTFMaterialsIridescenceExtension = class {
7921
8298
  extensionDef.iridescenceFactor = material.iridescence;
7922
8299
  if (material.iridescenceMap) {
7923
8300
  const iridescenceMapDef = {
7924
- index: writer.processTexture(material.iridescenceMap),
8301
+ index: await writer.processTextureAsync(material.iridescenceMap),
7925
8302
  texCoord: material.iridescenceMap.channel
7926
8303
  };
7927
8304
  writer.applyTextureTransform(iridescenceMapDef, material.iridescenceMap);
@@ -7932,7 +8309,7 @@ var GLTFMaterialsIridescenceExtension = class {
7932
8309
  extensionDef.iridescenceThicknessMaximum = material.iridescenceThicknessRange[1];
7933
8310
  if (material.iridescenceThicknessMap) {
7934
8311
  const iridescenceThicknessMapDef = {
7935
- index: writer.processTexture(material.iridescenceThicknessMap),
8312
+ index: await writer.processTextureAsync(material.iridescenceThicknessMap),
7936
8313
  texCoord: material.iridescenceThicknessMap.channel
7937
8314
  };
7938
8315
  writer.applyTextureTransform(iridescenceThicknessMapDef, material.iridescenceThicknessMap);
@@ -7948,7 +8325,7 @@ var GLTFMaterialsTransmissionExtension = class {
7948
8325
  this.writer = writer;
7949
8326
  this.name = "KHR_materials_transmission";
7950
8327
  }
7951
- writeMaterial(material, materialDef) {
8328
+ async writeMaterialAsync(material, materialDef) {
7952
8329
  if (!material.isMeshPhysicalMaterial || material.transmission === 0) return;
7953
8330
  const writer = this.writer;
7954
8331
  const extensionsUsed = writer.extensionsUsed;
@@ -7956,7 +8333,7 @@ var GLTFMaterialsTransmissionExtension = class {
7956
8333
  extensionDef.transmissionFactor = material.transmission;
7957
8334
  if (material.transmissionMap) {
7958
8335
  const transmissionMapDef = {
7959
- index: writer.processTexture(material.transmissionMap),
8336
+ index: await writer.processTextureAsync(material.transmissionMap),
7960
8337
  texCoord: material.transmissionMap.channel
7961
8338
  };
7962
8339
  writer.applyTextureTransform(transmissionMapDef, material.transmissionMap);
@@ -7972,7 +8349,7 @@ var GLTFMaterialsVolumeExtension = class {
7972
8349
  this.writer = writer;
7973
8350
  this.name = "KHR_materials_volume";
7974
8351
  }
7975
- writeMaterial(material, materialDef) {
8352
+ async writeMaterialAsync(material, materialDef) {
7976
8353
  if (!material.isMeshPhysicalMaterial || material.transmission === 0) return;
7977
8354
  const writer = this.writer;
7978
8355
  const extensionsUsed = writer.extensionsUsed;
@@ -7980,13 +8357,15 @@ var GLTFMaterialsVolumeExtension = class {
7980
8357
  extensionDef.thicknessFactor = material.thickness;
7981
8358
  if (material.thicknessMap) {
7982
8359
  const thicknessMapDef = {
7983
- index: writer.processTexture(material.thicknessMap),
8360
+ index: await writer.processTextureAsync(material.thicknessMap),
7984
8361
  texCoord: material.thicknessMap.channel
7985
8362
  };
7986
8363
  writer.applyTextureTransform(thicknessMapDef, material.thicknessMap);
7987
8364
  extensionDef.thicknessTexture = thicknessMapDef;
7988
8365
  }
7989
- extensionDef.attenuationDistance = material.attenuationDistance;
8366
+ if (material.attenuationDistance !== Infinity) {
8367
+ extensionDef.attenuationDistance = material.attenuationDistance;
8368
+ }
7990
8369
  extensionDef.attenuationColor = material.attenuationColor.toArray();
7991
8370
  materialDef.extensions = materialDef.extensions || {};
7992
8371
  materialDef.extensions[this.name] = extensionDef;
@@ -7998,7 +8377,7 @@ var GLTFMaterialsIorExtension = class {
7998
8377
  this.writer = writer;
7999
8378
  this.name = "KHR_materials_ior";
8000
8379
  }
8001
- writeMaterial(material, materialDef) {
8380
+ async writeMaterialAsync(material, materialDef) {
8002
8381
  if (!material.isMeshPhysicalMaterial || material.ior === 1.5) return;
8003
8382
  const writer = this.writer;
8004
8383
  const extensionsUsed = writer.extensionsUsed;
@@ -8014,14 +8393,14 @@ var GLTFMaterialsSpecularExtension = class {
8014
8393
  this.writer = writer;
8015
8394
  this.name = "KHR_materials_specular";
8016
8395
  }
8017
- writeMaterial(material, materialDef) {
8018
- if (!material.isMeshPhysicalMaterial || material.specularIntensity === 1 && material.specularColor.equals(DEFAULT_SPECULAR_COLOR) && !material.specularIntensityMap && !material.specularColorTexture) return;
8396
+ async writeMaterialAsync(material, materialDef) {
8397
+ if (!material.isMeshPhysicalMaterial || material.specularIntensity === 1 && material.specularColor.equals(DEFAULT_SPECULAR_COLOR) && !material.specularIntensityMap && !material.specularColorMap) return;
8019
8398
  const writer = this.writer;
8020
8399
  const extensionsUsed = writer.extensionsUsed;
8021
8400
  const extensionDef = {};
8022
8401
  if (material.specularIntensityMap) {
8023
8402
  const specularIntensityMapDef = {
8024
- index: writer.processTexture(material.specularIntensityMap),
8403
+ index: await writer.processTextureAsync(material.specularIntensityMap),
8025
8404
  texCoord: material.specularIntensityMap.channel
8026
8405
  };
8027
8406
  writer.applyTextureTransform(specularIntensityMapDef, material.specularIntensityMap);
@@ -8029,7 +8408,7 @@ var GLTFMaterialsSpecularExtension = class {
8029
8408
  }
8030
8409
  if (material.specularColorMap) {
8031
8410
  const specularColorMapDef = {
8032
- index: writer.processTexture(material.specularColorMap),
8411
+ index: await writer.processTextureAsync(material.specularColorMap),
8033
8412
  texCoord: material.specularColorMap.channel
8034
8413
  };
8035
8414
  writer.applyTextureTransform(specularColorMapDef, material.specularColorMap);
@@ -8047,14 +8426,14 @@ var GLTFMaterialsSheenExtension = class {
8047
8426
  this.writer = writer;
8048
8427
  this.name = "KHR_materials_sheen";
8049
8428
  }
8050
- writeMaterial(material, materialDef) {
8429
+ async writeMaterialAsync(material, materialDef) {
8051
8430
  if (!material.isMeshPhysicalMaterial || material.sheen == 0) return;
8052
8431
  const writer = this.writer;
8053
8432
  const extensionsUsed = writer.extensionsUsed;
8054
8433
  const extensionDef = {};
8055
8434
  if (material.sheenRoughnessMap) {
8056
8435
  const sheenRoughnessMapDef = {
8057
- index: writer.processTexture(material.sheenRoughnessMap),
8436
+ index: await writer.processTextureAsync(material.sheenRoughnessMap),
8058
8437
  texCoord: material.sheenRoughnessMap.channel
8059
8438
  };
8060
8439
  writer.applyTextureTransform(sheenRoughnessMapDef, material.sheenRoughnessMap);
@@ -8062,7 +8441,7 @@ var GLTFMaterialsSheenExtension = class {
8062
8441
  }
8063
8442
  if (material.sheenColorMap) {
8064
8443
  const sheenColorMapDef = {
8065
- index: writer.processTexture(material.sheenColorMap),
8444
+ index: await writer.processTextureAsync(material.sheenColorMap),
8066
8445
  texCoord: material.sheenColorMap.channel
8067
8446
  };
8068
8447
  writer.applyTextureTransform(sheenColorMapDef, material.sheenColorMap);
@@ -8080,13 +8459,13 @@ var GLTFMaterialsAnisotropyExtension = class {
8080
8459
  this.writer = writer;
8081
8460
  this.name = "KHR_materials_anisotropy";
8082
8461
  }
8083
- writeMaterial(material, materialDef) {
8462
+ async writeMaterialAsync(material, materialDef) {
8084
8463
  if (!material.isMeshPhysicalMaterial || material.anisotropy == 0) return;
8085
8464
  const writer = this.writer;
8086
8465
  const extensionsUsed = writer.extensionsUsed;
8087
8466
  const extensionDef = {};
8088
8467
  if (material.anisotropyMap) {
8089
- const anisotropyMapDef = { index: writer.processTexture(material.anisotropyMap) };
8468
+ const anisotropyMapDef = { index: await writer.processTextureAsync(material.anisotropyMap) };
8090
8469
  writer.applyTextureTransform(anisotropyMapDef, material.anisotropyMap);
8091
8470
  extensionDef.anisotropyTexture = anisotropyMapDef;
8092
8471
  }
@@ -8102,7 +8481,7 @@ var GLTFMaterialsEmissiveStrengthExtension = class {
8102
8481
  this.writer = writer;
8103
8482
  this.name = "KHR_materials_emissive_strength";
8104
8483
  }
8105
- writeMaterial(material, materialDef) {
8484
+ async writeMaterialAsync(material, materialDef) {
8106
8485
  if (!material.isMeshStandardMaterial || material.emissiveIntensity === 1) return;
8107
8486
  const writer = this.writer;
8108
8487
  const extensionsUsed = writer.extensionsUsed;
@@ -8113,6 +8492,30 @@ var GLTFMaterialsEmissiveStrengthExtension = class {
8113
8492
  extensionsUsed[this.name] = true;
8114
8493
  }
8115
8494
  };
8495
+ var GLTFMaterialsBumpExtension = class {
8496
+ constructor(writer) {
8497
+ this.writer = writer;
8498
+ this.name = "EXT_materials_bump";
8499
+ }
8500
+ async writeMaterialAsync(material, materialDef) {
8501
+ if (!material.isMeshStandardMaterial || material.bumpScale === 1 && !material.bumpMap) return;
8502
+ const writer = this.writer;
8503
+ const extensionsUsed = writer.extensionsUsed;
8504
+ const extensionDef = {};
8505
+ if (material.bumpMap) {
8506
+ const bumpMapDef = {
8507
+ index: await writer.processTextureAsync(material.bumpMap),
8508
+ texCoord: material.bumpMap.channel
8509
+ };
8510
+ writer.applyTextureTransform(bumpMapDef, material.bumpMap);
8511
+ extensionDef.bumpTexture = bumpMapDef;
8512
+ }
8513
+ extensionDef.bumpFactor = material.bumpScale;
8514
+ materialDef.extensions = materialDef.extensions || {};
8515
+ materialDef.extensions[this.name] = extensionDef;
8516
+ extensionsUsed[this.name] = true;
8517
+ }
8518
+ };
8116
8519
  var GLTFMeshGpuInstancing = class {
8117
8520
  constructor(writer) {
8118
8521
  this.writer = writer;
@@ -8125,10 +8528,10 @@ var GLTFMeshGpuInstancing = class {
8125
8528
  const translationAttr = new Float32Array(mesh.count * 3);
8126
8529
  const rotationAttr = new Float32Array(mesh.count * 4);
8127
8530
  const scaleAttr = new Float32Array(mesh.count * 3);
8128
- const matrix = new import_three19.Matrix4();
8129
- const position = new import_three19.Vector3();
8130
- const quaternion = new import_three19.Quaternion();
8131
- const scale = new import_three19.Vector3();
8531
+ const matrix = new import_three18.Matrix4();
8532
+ const position = new import_three18.Vector3();
8533
+ const quaternion = new import_three18.Quaternion();
8534
+ const scale = new import_three18.Vector3();
8132
8535
  for (let i = 0; i < mesh.count; i++) {
8133
8536
  mesh.getMatrixAt(i, matrix);
8134
8537
  matrix.decompose(position, quaternion, scale);
@@ -8137,9 +8540,9 @@ var GLTFMeshGpuInstancing = class {
8137
8540
  scale.toArray(scaleAttr, i * 3);
8138
8541
  }
8139
8542
  const attributes = {
8140
- TRANSLATION: writer.processAccessor(new import_three19.BufferAttribute(translationAttr, 3)),
8141
- ROTATION: writer.processAccessor(new import_three19.BufferAttribute(rotationAttr, 4)),
8142
- SCALE: writer.processAccessor(new import_three19.BufferAttribute(scaleAttr, 3))
8543
+ TRANSLATION: writer.processAccessor(new import_three18.BufferAttribute(translationAttr, 3)),
8544
+ ROTATION: writer.processAccessor(new import_three18.BufferAttribute(rotationAttr, 4)),
8545
+ SCALE: writer.processAccessor(new import_three18.BufferAttribute(scaleAttr, 3))
8143
8546
  };
8144
8547
  if (mesh.instanceColor)
8145
8548
  attributes._COLOR_0 = writer.processAccessor(mesh.instanceColor);
@@ -8204,8 +8607,8 @@ GLTFExporter.Utils = {
8204
8607
  const sourceTracks = clip.tracks;
8205
8608
  for (let i = 0; i < sourceTracks.length; ++i) {
8206
8609
  let sourceTrack = sourceTracks[i];
8207
- const sourceTrackBinding = import_three19.PropertyBinding.parseTrackName(sourceTrack.name);
8208
- const sourceTrackNode = import_three19.PropertyBinding.findNode(root, sourceTrackBinding.nodeName);
8610
+ const sourceTrackBinding = import_three18.PropertyBinding.parseTrackName(sourceTrack.name);
8611
+ const sourceTrackNode = import_three18.PropertyBinding.findNode(root, sourceTrackBinding.nodeName);
8209
8612
  if (sourceTrackBinding.propertyName !== "morphTargetInfluences" || sourceTrackBinding.propertyIndex === void 0) {
8210
8613
  tracks.push(sourceTrack);
8211
8614
  continue;
@@ -8216,7 +8619,7 @@ GLTFExporter.Utils = {
8216
8619
  }
8217
8620
  console.warn("THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead.");
8218
8621
  sourceTrack = sourceTrack.clone();
8219
- sourceTrack.setInterpolation(import_three19.InterpolateLinear);
8622
+ sourceTrack.setInterpolation(import_three18.InterpolateLinear);
8220
8623
  }
8221
8624
  const targetCount = sourceTrackNode.morphTargetInfluences.length;
8222
8625
  const targetIndex = sourceTrackNode.morphTargetDictionary[sourceTrackBinding.propertyIndex];
@@ -8248,6 +8651,19 @@ GLTFExporter.Utils = {
8248
8651
  }
8249
8652
  clip.tracks = tracks;
8250
8653
  return clip;
8654
+ },
8655
+ toTypedBufferAttribute: function(srcAttribute, TypedArray) {
8656
+ const dstAttribute = new import_three18.BufferAttribute(new TypedArray(srcAttribute.count * srcAttribute.itemSize), srcAttribute.itemSize, false);
8657
+ if (!srcAttribute.normalized && !srcAttribute.isInterleavedBufferAttribute) {
8658
+ dstAttribute.array.set(srcAttribute.array);
8659
+ return dstAttribute;
8660
+ }
8661
+ for (let i = 0, il = srcAttribute.count; i < il; i++) {
8662
+ for (let j = 0; j < srcAttribute.itemSize; j++) {
8663
+ dstAttribute.setComponent(i, j, srcAttribute.getComponent(i, j));
8664
+ }
8665
+ }
8666
+ return dstAttribute;
8251
8667
  }
8252
8668
  };
8253
8669
 
@@ -8299,10 +8715,10 @@ var SceneExporter = class {
8299
8715
  }
8300
8716
  };
8301
8717
  function localMatrix(object) {
8302
- return object.matrixAutoUpdate ? new import_three20.Matrix4().compose(object.position, object.quaternion, object.scale) : object.matrix.clone();
8718
+ return object.matrixAutoUpdate ? new import_three19.Matrix4().compose(object.position, object.quaternion, object.scale) : object.matrix.clone();
8303
8719
  }
8304
8720
  function createSnapshot(root, gltf, bakeColors = false) {
8305
- const scene = new import_three20.Scene();
8721
+ const scene = new import_three19.Scene();
8306
8722
  const geometries = [];
8307
8723
  const materials = [];
8308
8724
  const textures = [];
@@ -8320,7 +8736,7 @@ function createSnapshot(root, gltf, bakeColors = false) {
8320
8736
  if (!uniforms.map?.value?.isTexture || !uniforms.SHADE || !uniforms.BRIGHTNESS || !uniforms.EMISSIVE) {
8321
8737
  throw new MineRenderError("glTF export does not support this custom ShaderMaterial");
8322
8738
  }
8323
- material = new import_three20.MeshBasicMaterial({
8739
+ material = new import_three19.MeshBasicMaterial({
8324
8740
  map: uniforms.map.value,
8325
8741
  vertexColors: source.vertexColors,
8326
8742
  transparent: source.transparent,
@@ -8330,7 +8746,7 @@ function createSnapshot(root, gltf, bakeColors = false) {
8330
8746
  });
8331
8747
  material.name = source.name;
8332
8748
  } else if (shader.isShaderMaterial) {
8333
- material = new import_three20.MeshBasicMaterial({ vertexColors: source.vertexColors });
8749
+ material = new import_three19.MeshBasicMaterial({ vertexColors: source.vertexColors });
8334
8750
  material.name = source.name;
8335
8751
  } else {
8336
8752
  const copySource = Object.create(source);
@@ -8384,11 +8800,11 @@ function createSnapshot(root, gltf, bakeColors = false) {
8384
8800
  const material = copyMaterial(sourceMaterial, geometry);
8385
8801
  if (!sourceMaterial.vertexColors) geometry.deleteAttribute("color");
8386
8802
  if (bakeColors || instanceColor) {
8387
- const tint = (material.color ?? new import_three20.Color()).clone();
8803
+ const tint = (material.color ?? new import_three19.Color()).clone();
8388
8804
  if (instanceColor) tint.multiply(instanceColor);
8389
8805
  if (bakeColors) {
8390
8806
  const original = geometry.getAttribute("color");
8391
- const colors = new import_three20.Float32BufferAttribute(new Float32Array(geometry.getAttribute("position").count * 3), 3);
8807
+ const colors = new import_three19.Float32BufferAttribute(new Float32Array(geometry.getAttribute("position").count * 3), 3);
8392
8808
  for (let i = 0; i < colors.count; i++) {
8393
8809
  colors.setXYZ(i, (original?.getX(i) ?? 1) * tint.r, (original?.getY(i) ?? 1) * tint.g, (original?.getZ(i) ?? 1) * tint.b);
8394
8810
  }
@@ -8397,7 +8813,7 @@ function createSnapshot(root, gltf, bakeColors = false) {
8397
8813
  material.color.copy(tint);
8398
8814
  }
8399
8815
  }
8400
- const copy = new import_three20.Mesh(geometry, material);
8816
+ const copy = new import_three19.Mesh(geometry, material);
8401
8817
  copy.name = mesh.name;
8402
8818
  copy.renderOrder = mesh.renderOrder;
8403
8819
  scene.add(copy);
@@ -8411,9 +8827,9 @@ function createSnapshot(root, gltf, bakeColors = false) {
8411
8827
  const instanced = mesh;
8412
8828
  if (instanced.isInstancedMesh) {
8413
8829
  for (let i = 0; i < instanced.count; i++) {
8414
- const matrix = new import_three20.Matrix4();
8830
+ const matrix = new import_three19.Matrix4();
8415
8831
  instanced.getMatrixAt(i, matrix);
8416
- const color = instanced.instanceColor ? new import_three20.Color().fromBufferAttribute(instanced.instanceColor, i) : void 0;
8832
+ const color = instanced.instanceColor ? new import_three19.Color().fromBufferAttribute(instanced.instanceColor, i) : void 0;
8417
8833
  addMesh(mesh, world.clone().multiply(matrix), color);
8418
8834
  }
8419
8835
  } else {
@@ -8425,7 +8841,7 @@ function createSnapshot(root, gltf, bakeColors = false) {
8425
8841
  try {
8426
8842
  const ancestors = [];
8427
8843
  for (let parent = root.parent; parent; parent = parent.parent) ancestors.unshift(parent);
8428
- const world = new import_three20.Matrix4();
8844
+ const world = new import_three19.Matrix4();
8429
8845
  for (const ancestor of ancestors) {
8430
8846
  if (!ancestor.visible) return { scene, dispose };
8431
8847
  world.multiply(localMatrix(ancestor));
@@ -8439,7 +8855,7 @@ function createSnapshot(root, gltf, bakeColors = false) {
8439
8855
  }
8440
8856
  function selectAlphaMode(material, geometry) {
8441
8857
  const texture = material.map;
8442
- 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;
8858
+ 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;
8443
8859
  const uv = geometry.getAttribute(texture.channel === 0 ? "uv" : `uv${texture.channel}`);
8444
8860
  const colors = geometry.getAttribute("color");
8445
8861
  if (!uv || material.vertexColors && colors?.itemSize === 4) return;
@@ -8476,7 +8892,7 @@ function selectAlphaMode(material, geometry) {
8476
8892
  }
8477
8893
  function copyDataTexture(source) {
8478
8894
  const image = source.image;
8479
- if (source.format !== import_three20.RGBAFormat || source.type !== import_three20.UnsignedByteType) {
8895
+ if (!image.data || source.format !== import_three19.RGBAFormat || source.type !== import_three19.UnsignedByteType) {
8480
8896
  throw new MineRenderError("glTF export requires RGBA unsigned-byte data textures");
8481
8897
  }
8482
8898
  const canvas = createCanvas2(image.width, image.height);
@@ -8487,8 +8903,8 @@ function copyDataTexture(source) {
8487
8903
  context.putImageData(pixels, 0, 0);
8488
8904
  const copySource = Object.create(source);
8489
8905
  copySource.userData = {};
8490
- copySource.source = new import_three20.Source(canvas);
8491
- return new import_three20.Texture().copy(copySource);
8906
+ copySource.source = new import_three19.TextureSource(canvas);
8907
+ return new import_three19.Texture().copy(copySource);
8492
8908
  }
8493
8909
 
8494
8910
  // src/gui/GuiHelper.ts
@@ -8558,7 +8974,7 @@ var GuiHelper = class {
8558
8974
  };
8559
8975
 
8560
8976
  // src/gui/scene/GuiObject.ts
8561
- var import_three25 = require("three");
8977
+ var import_three24 = require("three");
8562
8978
  init_AssetKey();
8563
8979
  init_ModelTextures();
8564
8980
  init_Models();
@@ -8574,7 +8990,7 @@ var GuiObject = class extends SceneObject {
8574
8990
  this.textureLayers = textureLayers;
8575
8991
  this.isGuiObject = true;
8576
8992
  /** Local bounds in GUI pixels, with y growing down from the origin. */
8577
- this.bounds = new import_three25.Box2();
8993
+ this.bounds = new import_three24.Box2();
8578
8994
  this.geometries = /* @__PURE__ */ new Set();
8579
8995
  this.ownedMaterials = /* @__PURE__ */ new Set();
8580
8996
  this.initialized = false;
@@ -8592,17 +9008,17 @@ var GuiObject = class extends SceneObject {
8592
9008
  item.scale.set(width2 / 16, height2 / 16, width2 / 16);
8593
9009
  item.updateWorldMatrix(true, true);
8594
9010
  const inverse = this.matrixWorld.clone().invert();
8595
- const bounds = new import_three25.Box3();
9011
+ const bounds = new import_three24.Box3();
8596
9012
  item.iterateAllMeshes((mesh2) => {
8597
9013
  mesh2.geometry.computeBoundingBox();
8598
- bounds.union(mesh2.geometry.boundingBox.clone().applyMatrix4(new import_three25.Matrix4().multiplyMatrices(inverse, mesh2.matrixWorld)));
9014
+ bounds.union(mesh2.geometry.boundingBox.clone().applyMatrix4(new import_three24.Matrix4().multiplyMatrices(inverse, mesh2.matrixWorld)));
8599
9015
  });
8600
9016
  item.position.z = depth - bounds.min.z;
8601
9017
  depth += bounds.max.z - bounds.min.z + 0.01;
8602
- this.bounds.expandByPoint(new import_three25.Vector2(x, y));
8603
- this.bounds.expandByPoint(new import_three25.Vector2(x + width2, y + height2));
8604
- this.bounds.expandByPoint(new import_three25.Vector2(bounds.min.x, -bounds.max.y));
8605
- this.bounds.expandByPoint(new import_three25.Vector2(bounds.max.x, -bounds.min.y));
9018
+ this.bounds.expandByPoint(new import_three24.Vector2(x, y));
9019
+ this.bounds.expandByPoint(new import_three24.Vector2(x + width2, y + height2));
9020
+ this.bounds.expandByPoint(new import_three24.Vector2(bounds.min.x, -bounds.max.y));
9021
+ this.bounds.expandByPoint(new import_three24.Vector2(bounds.max.x, -bounds.min.y));
8606
9022
  continue;
8607
9023
  }
8608
9024
  const key = typeof layer.texture === "string" ? AssetKey.parse("textures", layer.texture) : layer.texture;
@@ -8610,7 +9026,7 @@ var GuiObject = class extends SceneObject {
8610
9026
  const image = material.map.image;
8611
9027
  const [cropX, cropY, cropWidth, cropHeight] = layer.crop ?? [0, 0, image.width, image.height];
8612
9028
  const [width, height] = layer.size ?? [cropWidth, cropHeight];
8613
- const geometry = new import_three25.PlaneGeometry(width, height);
9029
+ const geometry = new import_three24.PlaneGeometry(width, height);
8614
9030
  this.geometries.add(geometry);
8615
9031
  const uv = geometry.getAttribute("uv");
8616
9032
  for (let i = 0; i < uv.count; i++) {
@@ -8620,13 +9036,13 @@ var GuiObject = class extends SceneObject {
8620
9036
  1 - (cropY + (1 - uv.getY(i)) * cropHeight) / image.height
8621
9037
  );
8622
9038
  }
8623
- const mesh = new import_three25.Mesh(geometry, material);
9039
+ const mesh = new import_three24.Mesh(geometry, material);
8624
9040
  mesh.name = `mesh:${layer.name ?? index}`;
8625
9041
  mesh.position.set(x + width / 2, -y - height / 2, depth);
8626
9042
  mesh.renderOrder = index;
8627
9043
  this.add(mesh);
8628
- this.bounds.expandByPoint(new import_three25.Vector2(x, y));
8629
- this.bounds.expandByPoint(new import_three25.Vector2(x + width, y + height));
9044
+ this.bounds.expandByPoint(new import_three24.Vector2(x, y));
9045
+ this.bounds.expandByPoint(new import_three24.Vector2(x + width, y + height));
8630
9046
  depth += 0.01;
8631
9047
  }
8632
9048
  for (const child of this.children) child.position.z -= depth - 0.01;
@@ -8701,7 +9117,7 @@ function isGuiObject(obj) {
8701
9117
  init_image();
8702
9118
 
8703
9119
  // src/inspector/SceneInspector.ts
8704
- var import_three26 = require("three");
9120
+ var import_three25 = require("three");
8705
9121
  init_SceneObject();
8706
9122
  init_util();
8707
9123
  init_log();
@@ -8711,11 +9127,11 @@ var help = "<span>Ctrl/Cmd+Click to Select<br/></span><br/>";
8711
9127
  var SceneInspector = class {
8712
9128
  constructor(renderer) {
8713
9129
  this.renderer = renderer;
8714
- this.mouse = new import_three26.Vector2();
9130
+ this.mouse = new import_three25.Vector2();
8715
9131
  this.listeners = new AbortController();
8716
9132
  this.objectInfoContainer = document.createElement("div");
8717
9133
  this.objectControlsContainer = document.createElement("div");
8718
- this.raycaster = new import_three26.Raycaster();
9134
+ this.raycaster = new import_three25.Raycaster();
8719
9135
  this.init();
8720
9136
  }
8721
9137
  init() {
@@ -9118,7 +9534,7 @@ init_ModelMerger();
9118
9534
  init_SpecialItems();
9119
9535
 
9120
9536
  // src/model/block/BlockStateResolver.ts
9121
- var import_three28 = require("three");
9537
+ var import_three27 = require("three");
9122
9538
  init_BlockStates();
9123
9539
  init_MineRenderError();
9124
9540
  init_util();
@@ -9196,7 +9612,7 @@ var BlockStateResolver = class {
9196
9612
  return variants[variants.length - 1];
9197
9613
  }
9198
9614
  static rotation(variant) {
9199
- const rotation = new import_three28.Euler();
9615
+ const rotation = new import_three27.Euler();
9200
9616
  if (typeof variant.x !== "undefined") {
9201
9617
  rotation.x = toRadians(clampRotationDegrees(variant.x));
9202
9618
  }
@@ -9288,7 +9704,7 @@ init_SceneObject();
9288
9704
  init_ModelObject();
9289
9705
  init_Models();
9290
9706
  var import_ts_deepmerge6 = __toESM(require_dist());
9291
- var import_three31 = require("three");
9707
+ var import_three30 = require("three");
9292
9708
  init_MineRenderError();
9293
9709
  init_InstanceReference();
9294
9710
  init_AssetKey();
@@ -9310,7 +9726,7 @@ var BlockObject = class _BlockObject extends SceneObject {
9310
9726
  this._models = [];
9311
9727
  this._cullMask = 0;
9312
9728
  this._entities = [];
9313
- this._entityPlacement = new import_three31.Matrix4();
9729
+ this._entityPlacement = new import_three30.Matrix4();
9314
9730
  this._entityGeneration = 0;
9315
9731
  this.options = (0, import_ts_deepmerge6.default)({}, _BlockObject.DEFAULT_OPTIONS, options ?? {});
9316
9732
  }
@@ -9411,7 +9827,7 @@ var BlockObject = class _BlockObject extends SceneObject {
9411
9827
  return true;
9412
9828
  }
9413
9829
  placeEntities() {
9414
- const matrix = new import_three31.Matrix4().makeTranslation(this.position.x - 8, this.position.y - 8, this.position.z - 8).multiply(this._entityPlacement);
9830
+ const matrix = new import_three30.Matrix4().makeTranslation(this.position.x - 8, this.position.y - 8, this.position.z - 8).multiply(this._entityPlacement);
9415
9831
  for (const entity of this._entities) {
9416
9832
  matrix.decompose(entity.position, entity.quaternion, entity.scale);
9417
9833
  }
@@ -9433,12 +9849,12 @@ var BlockObject = class _BlockObject extends SceneObject {
9433
9849
  getModelCullMask(model, worldMask) {
9434
9850
  const object = isInstanceReference(model) ? model.instanceable : model;
9435
9851
  if (object.options.displayPosition) return 0;
9436
- const position = new import_three31.Vector3();
9437
- const rotation = new import_three31.Quaternion();
9438
- const scale = new import_three31.Vector3();
9852
+ const position = new import_three30.Vector3();
9853
+ const rotation = new import_three30.Quaternion();
9854
+ const scale = new import_three30.Vector3();
9439
9855
  this.getModelMatrix(model).decompose(position, rotation, scale);
9440
- if (position.distanceToSquared(this.position) > 1e-10 || scale.distanceToSquared(new import_three31.Vector3(1, 1, 1)) > 1e-10) return 0;
9441
- return ModelCulling.toLocalMask(worldMask, new import_three31.Euler().setFromQuaternion(rotation));
9856
+ if (position.distanceToSquared(this.position) > 1e-10 || scale.distanceToSquared(new import_three30.Vector3(1, 1, 1)) > 1e-10) return 0;
9857
+ return ModelCulling.toLocalMask(worldMask, new import_three30.Euler().setFromQuaternion(rotation));
9442
9858
  }
9443
9859
  async setCullMask(worldMask) {
9444
9860
  worldMask &= 63;
@@ -9462,6 +9878,7 @@ var BlockObject = class _BlockObject extends SceneObject {
9462
9878
  replacement.setMatrix(matrix);
9463
9879
  } else {
9464
9880
  replacement.matrix.copy(matrix);
9881
+ replacement.matrixWorldNeedsUpdate = true;
9465
9882
  matrix.decompose(replacement.position, replacement.quaternion, replacement.scale);
9466
9883
  replacement.matrixAutoUpdate = object.matrixAutoUpdate;
9467
9884
  replacement.visible = object.visible;
@@ -9503,7 +9920,7 @@ var BlockObject = class _BlockObject extends SceneObject {
9503
9920
  () => new FluidModelObject2(kind, surface.sample, this.blockState.key, this.options)
9504
9921
  );
9505
9922
  const previous = this._fluidModel;
9506
- const matrix = previous ? this.getModelMatrix(previous) : new import_three31.Matrix4().makeTranslation(...this.position.toArray());
9923
+ const matrix = previous ? this.getModelMatrix(previous) : new import_three30.Matrix4().makeTranslation(...this.position.toArray());
9507
9924
  if (isInstanceReference(replacement)) replacement.setMatrix(matrix);
9508
9925
  else matrix.decompose(replacement.position, replacement.quaternion, replacement.scale);
9509
9926
  this._models = this._models.filter((model) => model !== previous);
@@ -9645,7 +10062,7 @@ var BlockObject = class _BlockObject extends SceneObject {
9645
10062
  setPositionRotationScaleAt(index, position, rotation, scale) {
9646
10063
  super.setPositionRotationScaleAt(index, position, rotation, scale);
9647
10064
  }
9648
- getMatrixAt(index, matrix = new import_three31.Matrix4()) {
10065
+ getMatrixAt(index, matrix = new import_three30.Matrix4()) {
9649
10066
  if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
9650
10067
  const child = this._models[0];
9651
10068
  if (child && isModelObject(child)) {
@@ -11517,7 +11934,7 @@ init_ModelObject();
11517
11934
  init_nbt();
11518
11935
 
11519
11936
  // src/renderer/MineRenderScene.ts
11520
- var import_three33 = require("three");
11937
+ var import_three32 = require("three");
11521
11938
  init_SceneObject();
11522
11939
  var import_ts_deepmerge8 = __toESM(require_dist());
11523
11940
  init_ModelObject();
@@ -12250,7 +12667,7 @@ var import_ts_deepmerge7 = __toESM(require_dist());
12250
12667
  init_util();
12251
12668
 
12252
12669
  // src/skin/SkinTextures.ts
12253
- var import_three32 = require("three");
12670
+ var import_three31 = require("three");
12254
12671
  init_Caching();
12255
12672
  init_CacheKey();
12256
12673
  init_MineRenderError();
@@ -12334,11 +12751,11 @@ var SkinTextures = class {
12334
12751
  });
12335
12752
  }
12336
12753
  static createMaterial(pixels, width, height, transparent = true) {
12337
- const texture = Textures.initTextureProps(new import_three32.DataTexture(pixels, width, height));
12338
- texture.colorSpace = import_three32.SRGBColorSpace;
12754
+ const texture = Textures.initTextureProps(new import_three31.DataTexture(pixels, width, height));
12755
+ texture.colorSpace = import_three31.SRGBColorSpace;
12339
12756
  texture.flipY = true;
12340
12757
  texture.needsUpdate = true;
12341
- return new import_three32.MeshBasicMaterial({ map: texture, transparent, side: transparent ? import_three32.DoubleSide : import_three32.FrontSide, alphaTest: transparent ? 0.1 : 0 });
12758
+ return new import_three31.MeshBasicMaterial({ map: texture, transparent, side: transparent ? import_three31.DoubleSide : import_three31.FrontSide, alphaTest: transparent ? 0.1 : 0 });
12342
12759
  }
12343
12760
  static isSlim(image, scale) {
12344
12761
  for (const [x, y] of [[46, 52], [54, 20]]) {
@@ -12568,7 +12985,7 @@ var SkinObject = class extends SceneObject {
12568
12985
  // src/renderer/MineRenderScene.ts
12569
12986
  init_EntityObject();
12570
12987
  init_ItemTints();
12571
- var MineRenderScene = class _MineRenderScene extends import_three33.Scene {
12988
+ var MineRenderScene = class _MineRenderScene extends import_three32.Scene {
12572
12989
  constructor(options) {
12573
12990
  super();
12574
12991
  this.isMineRenderScene = true;
@@ -12614,12 +13031,13 @@ var MineRenderScene = class _MineRenderScene extends import_three33.Scene {
12614
13031
  }
12615
13032
  updateObjectRegistration(object, attached) {
12616
13033
  if (this.observedObjects.has(object) === attached) return;
13034
+ const observable = object;
12617
13035
  if (attached) {
12618
13036
  this.observedObjects.add(object);
12619
- object.addEventListener("change", this.onObjectChange);
13037
+ observable.addEventListener("change", this.onObjectChange);
12620
13038
  } else {
12621
13039
  this.observedObjects.delete(object);
12622
- object.removeEventListener("change", this.onObjectChange);
13040
+ observable.removeEventListener("change", this.onObjectChange);
12623
13041
  }
12624
13042
  const change = attached ? 1 : -1;
12625
13043
  this.stats.objectCount += change;
@@ -12697,7 +13115,7 @@ function isMineRenderScene(obj) {
12697
13115
  }
12698
13116
 
12699
13117
  // src/renderer/Renderer.ts
12700
- var import_three35 = require("three");
13118
+ var import_three34 = require("three");
12701
13119
  var import_ts_deepmerge9 = __toESM(require_dist());
12702
13120
  var import_stats = __toESM(require("stats.js"));
12703
13121
  var import_postprocessing = require("postprocessing");
@@ -12706,11 +13124,11 @@ init_Model();
12706
13124
  init_three();
12707
13125
 
12708
13126
  // src/three/OrbitControls.js
12709
- var import_three34 = require("three");
13127
+ var import_three33 = require("three");
12710
13128
  var _changeEvent = { type: "change" };
12711
13129
  var _startEvent = { type: "start" };
12712
13130
  var _endEvent = { type: "end" };
12713
- var OrbitControls = class extends import_three34.EventDispatcher {
13131
+ var OrbitControls = class extends import_three33.EventDispatcher {
12714
13132
  constructor(object, domElement) {
12715
13133
  super();
12716
13134
  if (domElement === void 0) console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.');
@@ -12719,7 +13137,7 @@ var OrbitControls = class extends import_three34.EventDispatcher {
12719
13137
  this.domElement = domElement;
12720
13138
  this.domElement.style.touchAction = "none";
12721
13139
  this.enabled = true;
12722
- this.target = new import_three34.Vector3();
13140
+ this.target = new import_three33.Vector3();
12723
13141
  this.minDistance = 0;
12724
13142
  this.maxDistance = Infinity;
12725
13143
  this.minZoom = 0;
@@ -12741,8 +13159,8 @@ var OrbitControls = class extends import_three34.EventDispatcher {
12741
13159
  this.autoRotate = false;
12742
13160
  this.autoRotateSpeed = 2;
12743
13161
  this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" };
12744
- this.mouseButtons = { LEFT: import_three34.MOUSE.ROTATE, MIDDLE: import_three34.MOUSE.DOLLY, RIGHT: import_three34.MOUSE.PAN };
12745
- this.touches = { ONE: import_three34.TOUCH.ROTATE, TWO: import_three34.TOUCH.DOLLY_PAN };
13162
+ this.mouseButtons = { LEFT: import_three33.MOUSE.ROTATE, MIDDLE: import_three33.MOUSE.DOLLY, RIGHT: import_three33.MOUSE.PAN };
13163
+ this.touches = { ONE: import_three33.TOUCH.ROTATE, TWO: import_three33.TOUCH.DOLLY_PAN };
12746
13164
  this.target0 = this.target.clone();
12747
13165
  this.position0 = this.object.position.clone();
12748
13166
  this.zoom0 = this.object.zoom;
@@ -12771,11 +13189,11 @@ var OrbitControls = class extends import_three34.EventDispatcher {
12771
13189
  state = STATE.NONE;
12772
13190
  };
12773
13191
  this.update = function() {
12774
- const offset = new import_three34.Vector3();
12775
- const quat = new import_three34.Quaternion().setFromUnitVectors(object.up, new import_three34.Vector3(0, 1, 0));
13192
+ const offset = new import_three33.Vector3();
13193
+ const quat = new import_three33.Quaternion().setFromUnitVectors(object.up, new import_three33.Vector3(0, 1, 0));
12776
13194
  const quatInverse = quat.clone().invert();
12777
- const lastPosition = new import_three34.Vector3();
12778
- const lastQuaternion = new import_three34.Quaternion();
13195
+ const lastPosition = new import_three33.Vector3();
13196
+ const lastQuaternion = new import_three33.Quaternion();
12779
13197
  const twoPI = 2 * Math.PI;
12780
13198
  return function update() {
12781
13199
  const position = scope.object.position;
@@ -12861,20 +13279,20 @@ var OrbitControls = class extends import_three34.EventDispatcher {
12861
13279
  };
12862
13280
  let state = STATE.NONE;
12863
13281
  const EPS = 1e-6;
12864
- const spherical = new import_three34.Spherical();
12865
- const sphericalDelta = new import_three34.Spherical();
13282
+ const spherical = new import_three33.Spherical();
13283
+ const sphericalDelta = new import_three33.Spherical();
12866
13284
  let scale = 1;
12867
- const panOffset = new import_three34.Vector3();
13285
+ const panOffset = new import_three33.Vector3();
12868
13286
  let zoomChanged = false;
12869
- const rotateStart = new import_three34.Vector2();
12870
- const rotateEnd = new import_three34.Vector2();
12871
- const rotateDelta = new import_three34.Vector2();
12872
- const panStart = new import_three34.Vector2();
12873
- const panEnd = new import_three34.Vector2();
12874
- const panDelta = new import_three34.Vector2();
12875
- const dollyStart = new import_three34.Vector2();
12876
- const dollyEnd = new import_three34.Vector2();
12877
- const dollyDelta = new import_three34.Vector2();
13287
+ const rotateStart = new import_three33.Vector2();
13288
+ const rotateEnd = new import_three33.Vector2();
13289
+ const rotateDelta = new import_three33.Vector2();
13290
+ const panStart = new import_three33.Vector2();
13291
+ const panEnd = new import_three33.Vector2();
13292
+ const panDelta = new import_three33.Vector2();
13293
+ const dollyStart = new import_three33.Vector2();
13294
+ const dollyEnd = new import_three33.Vector2();
13295
+ const dollyDelta = new import_three33.Vector2();
12878
13296
  const pointers = [];
12879
13297
  const pointerPositions = {};
12880
13298
  function getAutoRotationAngle() {
@@ -12890,7 +13308,7 @@ var OrbitControls = class extends import_three34.EventDispatcher {
12890
13308
  sphericalDelta.phi -= angle;
12891
13309
  }
12892
13310
  const panLeft = function() {
12893
- const v = new import_three34.Vector3();
13311
+ const v = new import_three33.Vector3();
12894
13312
  return function panLeft2(distance, objectMatrix) {
12895
13313
  v.setFromMatrixColumn(objectMatrix, 0);
12896
13314
  v.multiplyScalar(-distance);
@@ -12898,7 +13316,7 @@ var OrbitControls = class extends import_three34.EventDispatcher {
12898
13316
  };
12899
13317
  }();
12900
13318
  const panUp = function() {
12901
- const v = new import_three34.Vector3();
13319
+ const v = new import_three33.Vector3();
12902
13320
  return function panUp2(distance, objectMatrix) {
12903
13321
  if (scope.screenSpacePanning === true) {
12904
13322
  v.setFromMatrixColumn(objectMatrix, 1);
@@ -12911,7 +13329,7 @@ var OrbitControls = class extends import_three34.EventDispatcher {
12911
13329
  };
12912
13330
  }();
12913
13331
  const pan = function() {
12914
- const offset = new import_three34.Vector3();
13332
+ const offset = new import_three33.Vector3();
12915
13333
  return function pan2(deltaX, deltaY) {
12916
13334
  const element = scope.domElement;
12917
13335
  if (scope.object.isPerspectiveCamera) {
@@ -13160,12 +13578,12 @@ var OrbitControls = class extends import_three34.EventDispatcher {
13160
13578
  mouseAction = -1;
13161
13579
  }
13162
13580
  switch (mouseAction) {
13163
- case import_three34.MOUSE.DOLLY:
13581
+ case import_three33.MOUSE.DOLLY:
13164
13582
  if (scope.enableZoom === false) return;
13165
13583
  handleMouseDownDolly(event);
13166
13584
  state = STATE.DOLLY;
13167
13585
  break;
13168
- case import_three34.MOUSE.ROTATE:
13586
+ case import_three33.MOUSE.ROTATE:
13169
13587
  if (event.ctrlKey || event.metaKey || event.shiftKey) {
13170
13588
  if (scope.enablePan === false) return;
13171
13589
  handleMouseDownPan(event);
@@ -13176,7 +13594,7 @@ var OrbitControls = class extends import_three34.EventDispatcher {
13176
13594
  state = STATE.ROTATE;
13177
13595
  }
13178
13596
  break;
13179
- case import_three34.MOUSE.PAN:
13597
+ case import_three33.MOUSE.PAN:
13180
13598
  if (event.ctrlKey || event.metaKey || event.shiftKey) {
13181
13599
  if (scope.enableRotate === false) return;
13182
13600
  handleMouseDownRotate(event);
@@ -13232,12 +13650,12 @@ var OrbitControls = class extends import_three34.EventDispatcher {
13232
13650
  switch (pointers.length) {
13233
13651
  case 1:
13234
13652
  switch (scope.touches.ONE) {
13235
- case import_three34.TOUCH.ROTATE:
13653
+ case import_three33.TOUCH.ROTATE:
13236
13654
  if (scope.enableRotate === false) return;
13237
13655
  handleTouchStartRotate();
13238
13656
  state = STATE.TOUCH_ROTATE;
13239
13657
  break;
13240
- case import_three34.TOUCH.PAN:
13658
+ case import_three33.TOUCH.PAN:
13241
13659
  if (scope.enablePan === false) return;
13242
13660
  handleTouchStartPan();
13243
13661
  state = STATE.TOUCH_PAN;
@@ -13248,12 +13666,12 @@ var OrbitControls = class extends import_three34.EventDispatcher {
13248
13666
  break;
13249
13667
  case 2:
13250
13668
  switch (scope.touches.TWO) {
13251
- case import_three34.TOUCH.DOLLY_PAN:
13669
+ case import_three33.TOUCH.DOLLY_PAN:
13252
13670
  if (scope.enableZoom === false && scope.enablePan === false) return;
13253
13671
  handleTouchStartDollyPan();
13254
13672
  state = STATE.TOUCH_DOLLY_PAN;
13255
13673
  break;
13256
- case import_three34.TOUCH.DOLLY_ROTATE:
13674
+ case import_three33.TOUCH.DOLLY_ROTATE:
13257
13675
  if (scope.enableZoom === false && scope.enableRotate === false) return;
13258
13676
  handleTouchStartDollyRotate();
13259
13677
  state = STATE.TOUCH_DOLLY_ROTATE;
@@ -13320,7 +13738,7 @@ var OrbitControls = class extends import_three34.EventDispatcher {
13320
13738
  function trackPointer(event) {
13321
13739
  let position = pointerPositions[event.pointerId];
13322
13740
  if (position === void 0) {
13323
- position = new import_three34.Vector2();
13741
+ position = new import_three33.Vector2();
13324
13742
  pointerPositions[event.pointerId] = position;
13325
13743
  }
13326
13744
  position.set(event.pageX, event.pageY);
@@ -13340,10 +13758,10 @@ var MapControls = class extends OrbitControls {
13340
13758
  constructor(object, domElement) {
13341
13759
  super(object, domElement);
13342
13760
  this.screenSpacePanning = false;
13343
- this.mouseButtons.LEFT = import_three34.MOUSE.PAN;
13344
- this.mouseButtons.RIGHT = import_three34.MOUSE.ROTATE;
13345
- this.touches.ONE = import_three34.TOUCH.PAN;
13346
- this.touches.TWO = import_three34.TOUCH.DOLLY_ROTATE;
13761
+ this.mouseButtons.LEFT = import_three33.MOUSE.PAN;
13762
+ this.mouseButtons.RIGHT = import_three33.MOUSE.ROTATE;
13763
+ this.touches.ONE = import_three33.TOUCH.PAN;
13764
+ this.touches.TWO = import_three33.TOUCH.DOLLY_ROTATE;
13347
13765
  }
13348
13766
  };
13349
13767
 
@@ -13402,8 +13820,8 @@ var Renderer = class _Renderer {
13402
13820
  top: void 0,
13403
13821
  bottom: void 0
13404
13822
  },
13405
- position: new import_three35.Vector3(50, 50, 50),
13406
- lookingAt: new import_three35.Vector3(0, 0, 0)
13823
+ position: new import_three34.Vector3(50, 50, 50),
13824
+ lookingAt: new import_three34.Vector3(0, 0, 0)
13407
13825
  },
13408
13826
  render: {
13409
13827
  fpsLimit: 60,
@@ -13434,14 +13852,14 @@ var Renderer = class _Renderer {
13434
13852
  switch (this.options.camera.type) {
13435
13853
  case "perspective":
13436
13854
  default:
13437
- return new import_three35.PerspectiveCamera(
13855
+ return new import_three34.PerspectiveCamera(
13438
13856
  this.options.camera.perspective.fov,
13439
13857
  this.options.camera.perspective.aspect ?? this.viewWidth / this.viewHeight,
13440
13858
  this.options.camera.near,
13441
13859
  this.options.camera.far
13442
13860
  );
13443
13861
  case "orthographic":
13444
- return new import_three35.OrthographicCamera(
13862
+ return new import_three34.OrthographicCamera(
13445
13863
  this.options.camera.orthographic.left ?? this.viewWidth / -2,
13446
13864
  this.options.camera.orthographic.right ?? this.viewWidth / 2,
13447
13865
  this.options.camera.orthographic.top ?? this.viewHeight / 2,
@@ -13452,7 +13870,7 @@ var Renderer = class _Renderer {
13452
13870
  }
13453
13871
  }
13454
13872
  createRenderer() {
13455
- const renderer = new import_three35.WebGLRenderer({
13873
+ const renderer = new import_three34.WebGLRenderer({
13456
13874
  antialias: this.options.render.antialias,
13457
13875
  alpha: true,
13458
13876
  powerPreference: "high-performance",
@@ -13460,8 +13878,8 @@ var Renderer = class _Renderer {
13460
13878
  });
13461
13879
  renderer.setClearColor(0, 0);
13462
13880
  renderer.shadowMap.enabled = true;
13463
- renderer.shadowMap.type = import_three35.PCFSoftShadowMap;
13464
- renderer.outputColorSpace = import_three35.SRGBColorSpace;
13881
+ renderer.shadowMap.type = import_three34.PCFShadowMap;
13882
+ renderer.outputColorSpace = import_three34.SRGBColorSpace;
13465
13883
  renderer.setPixelRatio(this.options.render.pixelRatio ?? 1);
13466
13884
  renderer.setSize(this.viewWidth, this.viewHeight);
13467
13885
  return renderer;
@@ -13496,20 +13914,20 @@ var Renderer = class _Renderer {
13496
13914
  window["__THREE_DEVTOOLS__"].dispatchEvent(new CustomEvent("observe", { detail: this.scene }));
13497
13915
  }
13498
13916
  if (this.options.debug.grid) {
13499
- const gridHelper = new import_three35.GridHelper(128, 16);
13917
+ const gridHelper = new import_three34.GridHelper(128, 16);
13500
13918
  this._debugHelpers.push(gridHelper);
13501
13919
  this.scene.add(gridHelper);
13502
- const gridHelper2 = new import_three35.GridHelper(128, 16);
13920
+ const gridHelper2 = new import_three34.GridHelper(128, 16);
13503
13921
  this._debugHelpers.push(gridHelper2);
13504
13922
  gridHelper2.rotation.x = 90 * (Math.PI / 180);
13505
13923
  this.scene.add(gridHelper2);
13506
- const gridHelper3 = new import_three35.GridHelper(128, 16);
13924
+ const gridHelper3 = new import_three34.GridHelper(128, 16);
13507
13925
  this._debugHelpers.push(gridHelper3);
13508
13926
  gridHelper3.rotation.z = 90 * (Math.PI / 180);
13509
13927
  this.scene.add(gridHelper3);
13510
13928
  }
13511
13929
  if (this.options.debug.axes) {
13512
- const axesHelper = new import_three35.AxesHelper(64);
13930
+ const axesHelper = new import_three34.AxesHelper(64);
13513
13931
  this._debugHelpers.push(axesHelper);
13514
13932
  this.scene.add(axesHelper);
13515
13933
  }
@@ -14195,12 +14613,12 @@ var AnvilParser = class {
14195
14613
  };
14196
14614
 
14197
14615
  // src/world/Chunk.ts
14198
- var import_three40 = require("three");
14616
+ var import_three39 = require("three");
14199
14617
  init_BlockStates();
14200
14618
  init_AssetKey();
14201
14619
 
14202
14620
  // src/world/MineRenderWorld.ts
14203
- var import_three38 = require("three");
14621
+ var import_three37 = require("three");
14204
14622
  init_Model();
14205
14623
  init_BatchedExecutor();
14206
14624
  init_AssetKey();
@@ -14208,7 +14626,7 @@ init_BlockStates();
14208
14626
  init_CubeFace();
14209
14627
 
14210
14628
  // src/world/SectionModels.ts
14211
- var import_three37 = require("three");
14629
+ var import_three36 = require("three");
14212
14630
  init_AssetKey();
14213
14631
  init_Models();
14214
14632
  init_CubeFace();
@@ -14274,12 +14692,12 @@ var SectionModels = class {
14274
14692
  });
14275
14693
  await object.init();
14276
14694
  const geometry = object.children[0].geometry;
14277
- geometry.applyMatrix4(new import_three37.Matrix4().makeRotationFromEuler(rotation));
14695
+ geometry.applyMatrix4(new import_three36.Matrix4().makeRotationFromEuler(rotation));
14278
14696
  object.clear();
14279
14697
  const cullFaces = CUBE_FACES.map((face) => {
14280
14698
  const local = CUBE_FACES.findIndex((name) => name === atlas.model.elements[0].faces[face]?.cullface);
14281
14699
  if (local < 0) return 0;
14282
- const normal = new import_three37.Vector3(...CUBE_FACE_OFFSETS[local]).applyEuler(rotation);
14700
+ const normal = new import_three36.Vector3(...CUBE_FACE_OFFSETS[local]).applyEuler(rotation);
14283
14701
  const world = CUBE_FACE_OFFSETS.findIndex(([x, y, z]) => Math.abs(normal.x - x) < 1e-6 && Math.abs(normal.y - y) < 1e-6 && Math.abs(normal.z - z) < 1e-6);
14284
14702
  return 1 << world;
14285
14703
  });
@@ -14309,20 +14727,20 @@ var MineRenderWorld = class {
14309
14727
  }
14310
14728
  getBlockAt(posOrX, y, z) {
14311
14729
  if (typeof posOrX == "number") {
14312
- return this.getBlockAt(new import_three38.Vector3(posOrX, y, z));
14730
+ return this.getBlockAt(new import_three37.Vector3(posOrX, y, z));
14313
14731
  }
14314
14732
  if (isTripleArray(posOrX)) {
14315
- return this.getBlockAt(new import_three38.Vector3(posOrX[0], posOrX[1], posOrX[2]));
14733
+ return this.getBlockAt(new import_three37.Vector3(posOrX[0], posOrX[1], posOrX[2]));
14316
14734
  }
14317
14735
  this.validatePosBounds(posOrX);
14318
14736
  return this.getChunkAt(posOrX)?.getBlockAt(posOrX);
14319
14737
  }
14320
14738
  async setBlockAt(posOrX, yOrBlock, z, block) {
14321
14739
  if (typeof posOrX == "number") {
14322
- return this.setBlockAt(new import_three38.Vector3(posOrX, yOrBlock, z), block);
14740
+ return this.setBlockAt(new import_three37.Vector3(posOrX, yOrBlock, z), block);
14323
14741
  }
14324
14742
  if (isTripleArray(posOrX)) {
14325
- return this.setBlockAt(new import_three38.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
14743
+ return this.setBlockAt(new import_three37.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
14326
14744
  }
14327
14745
  return this.placeBlock(posOrX, yOrBlock);
14328
14746
  }
@@ -14333,10 +14751,10 @@ var MineRenderWorld = class {
14333
14751
  }
14334
14752
  async setBlockVisibleAt(posOrX, yOrVisible, z, visible) {
14335
14753
  if (typeof posOrX === "number") {
14336
- return this.setBlockVisibleAt(new import_three38.Vector3(posOrX, yOrVisible, z), visible);
14754
+ return this.setBlockVisibleAt(new import_three37.Vector3(posOrX, yOrVisible, z), visible);
14337
14755
  }
14338
14756
  if (isTripleArray(posOrX)) {
14339
- return this.setBlockVisibleAt(new import_three38.Vector3(...posOrX), yOrVisible);
14757
+ return this.setBlockVisibleAt(new import_three37.Vector3(...posOrX), yOrVisible);
14340
14758
  }
14341
14759
  this.validatePosBounds(posOrX);
14342
14760
  await this.getChunkAt(posOrX)?.setBlockVisibleAt(posOrX, yOrVisible);
@@ -14353,7 +14771,7 @@ var MineRenderWorld = class {
14353
14771
  const collect = async (positions2) => {
14354
14772
  for (const pos of positions2) changes.set(pos.toArray().join(","), pos);
14355
14773
  };
14356
- const place = (block) => this.placeBlock(new import_three38.Vector3(...block.position), block, collect);
14774
+ const place = (block) => this.placeBlock(new import_three37.Vector3(...block.position), block, collect);
14357
14775
  const keys = /* @__PURE__ */ new Map();
14358
14776
  for (const block of multiblock.blocks) {
14359
14777
  if (Chunk.isAir(block)) continue;
@@ -14431,13 +14849,13 @@ var MineRenderWorld = class {
14431
14849
  for (const pos of positions) {
14432
14850
  this.pendingCulling.set(pos.toArray().join(","), pos.clone());
14433
14851
  for (const offset of CUBE_FACE_OFFSETS) {
14434
- const neighbor = pos.clone().add(new import_three38.Vector3(...offset));
14852
+ const neighbor = pos.clone().add(new import_three37.Vector3(...offset));
14435
14853
  this.pendingCulling.set(neighbor.toArray().join(","), neighbor);
14436
14854
  }
14437
14855
  for (let y = -1; y <= 1; y++) {
14438
14856
  for (let z = -1; z <= 1; z++) {
14439
14857
  for (let x = -1; x <= 1; x++) {
14440
- const neighbor = pos.clone().add(new import_three38.Vector3(x, y, z));
14858
+ const neighbor = pos.clone().add(new import_three37.Vector3(x, y, z));
14441
14859
  if (this.getBlockAt(neighbor)?.object?.fluidKind) {
14442
14860
  this.pendingCulling.set(neighbor.toArray().join(","), neighbor);
14443
14861
  }
@@ -14461,7 +14879,7 @@ var MineRenderWorld = class {
14461
14879
  }
14462
14880
  if (block.object?.fluidKind) {
14463
14881
  await block.object.updateFluid((x, y, z) => {
14464
- const neighbor = pos.clone().add(new import_three38.Vector3(x, y, z));
14882
+ const neighbor = pos.clone().add(new import_three37.Vector3(x, y, z));
14465
14883
  const section = this.getChunkAt(neighbor);
14466
14884
  const object = section?.isBlockVisibleAt(neighbor) ? section.getBlockAt(neighbor)?.object : void 0;
14467
14885
  return {
@@ -14473,7 +14891,7 @@ var MineRenderWorld = class {
14473
14891
  }
14474
14892
  let mask = 0;
14475
14893
  for (const [face, offset] of CUBE_FACE_OFFSETS.entries()) {
14476
- const neighbor = pos.clone().add(new import_three38.Vector3(...offset));
14894
+ const neighbor = pos.clone().add(new import_three37.Vector3(...offset));
14477
14895
  if (this.getChunkAt(neighbor)?.isOccludingAt(neighbor)) {
14478
14896
  mask |= 1 << face;
14479
14897
  }
@@ -14507,14 +14925,14 @@ var MineRenderWorld = class {
14507
14925
  return this._chunks.get(this.worldPosToChunkKey(pos));
14508
14926
  }
14509
14927
  static worldToScenePosition(pos) {
14510
- return new import_three38.Vector3(
14928
+ return new import_three37.Vector3(
14511
14929
  pos.x * 16,
14512
14930
  pos.y * 16,
14513
14931
  pos.z * 16
14514
14932
  );
14515
14933
  }
14516
14934
  static sceneToWorldPosition(pos) {
14517
- return new import_three38.Vector3(
14935
+ return new import_three37.Vector3(
14518
14936
  pos.x / 16,
14519
14937
  pos.y / 16,
14520
14938
  pos.z / 16
@@ -14537,10 +14955,10 @@ var MineRenderWorld = class {
14537
14955
  init_Model();
14538
14956
 
14539
14957
  // src/world/SectionMesh.ts
14540
- var import_three39 = require("three");
14958
+ var import_three38 = require("three");
14541
14959
  init_CanvasCompat();
14542
14960
  init_Materials();
14543
- var SectionMesh = class _SectionMesh extends import_three39.Group {
14961
+ var SectionMesh = class _SectionMesh extends import_three38.Group {
14544
14962
  constructor() {
14545
14963
  super(...arguments);
14546
14964
  this.ownedMeshes = [];
@@ -14613,18 +15031,18 @@ var SectionMesh = class _SectionMesh extends import_three39.Group {
14613
15031
  for (let corner = 0; corner < 6; corner++) indices.push(start + sourceIndices.getX(face * 6 + corner) - face * 4);
14614
15032
  }
14615
15033
  }
14616
- const geometry = new import_three39.BufferGeometry();
14617
- geometry.setAttribute("position", new import_three39.Float32BufferAttribute(positions, 3));
14618
- geometry.setAttribute("normal", new import_three39.Float32BufferAttribute(normals, 3));
14619
- geometry.setAttribute("uv", new import_three39.Float32BufferAttribute(uvs, 2));
14620
- geometry.setAttribute("color", new import_three39.Float32BufferAttribute(colors, 3));
15034
+ const geometry = new import_three38.BufferGeometry();
15035
+ geometry.setAttribute("position", new import_three38.Float32BufferAttribute(positions, 3));
15036
+ geometry.setAttribute("normal", new import_three38.Float32BufferAttribute(normals, 3));
15037
+ geometry.setAttribute("uv", new import_three38.Float32BufferAttribute(uvs, 2));
15038
+ geometry.setAttribute("color", new import_three38.Float32BufferAttribute(colors, 3));
14621
15039
  geometry.setIndex(indices);
14622
15040
  geometry.computeBoundingBox();
14623
15041
  geometry.computeBoundingSphere();
14624
15042
  const material = Materials.createShadedCanvasMaterial(canvas, false);
14625
15043
  material.vertexColors = true;
14626
15044
  const texture = material.uniforms?.map?.value ?? material.map;
14627
- const mesh = new import_three39.Mesh(geometry, material);
15045
+ const mesh = new import_three38.Mesh(geometry, material);
14628
15046
  section.add(mesh);
14629
15047
  section.ownedMeshes.push({ mesh, texture });
14630
15048
  }
@@ -14638,6 +15056,7 @@ var SectionMesh = class _SectionMesh extends import_three39.Group {
14638
15056
  texture?.dispose();
14639
15057
  }
14640
15058
  this.removeFromParent();
15059
+ super.dispose();
14641
15060
  }
14642
15061
  };
14643
15062
 
@@ -14659,10 +15078,10 @@ var Chunk = class _Chunk {
14659
15078
  }
14660
15079
  getBlockAt(posOrX, y, z) {
14661
15080
  if (typeof posOrX == "number") {
14662
- return this.getBlockAt(new import_three40.Vector3(posOrX, y, z));
15081
+ return this.getBlockAt(new import_three39.Vector3(posOrX, y, z));
14663
15082
  }
14664
15083
  if (isTripleArray(posOrX)) {
14665
- return this.getBlockAt(new import_three40.Vector3(posOrX[0], posOrX[1], posOrX[2]));
15084
+ return this.getBlockAt(new import_three39.Vector3(posOrX[0], posOrX[1], posOrX[2]));
14666
15085
  }
14667
15086
  const pos = this.worldPosToChunkPos(posOrX);
14668
15087
  const index = _Chunk.chunkPosToBlockIndex(pos);
@@ -14670,10 +15089,10 @@ var Chunk = class _Chunk {
14670
15089
  }
14671
15090
  async setBlockAt(posOrX, yOrBlock, z, block) {
14672
15091
  if (typeof posOrX == "number") {
14673
- return this.setBlockAt(new import_three40.Vector3(posOrX, yOrBlock, z), block);
15092
+ return this.setBlockAt(new import_three39.Vector3(posOrX, yOrBlock, z), block);
14674
15093
  }
14675
15094
  if (isTripleArray(posOrX)) {
14676
- return this.setBlockAt(new import_three40.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
15095
+ return this.setBlockAt(new import_three39.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
14677
15096
  }
14678
15097
  const worldPos = posOrX;
14679
15098
  const pos = this.worldPosToChunkPos(worldPos);
@@ -14785,7 +15204,7 @@ var Chunk = class _Chunk {
14785
15204
  }
14786
15205
  async clear(onBlocksChanged = this.onBlocksChanged) {
14787
15206
  const positions = [...this.renderedBlocks.keys()].map((index) => this.chunkPosToWorldPos(
14788
- new import_three40.Vector3(index % 16, Math.floor(index / 256), Math.floor(index / 16) % 16)
15207
+ new import_three39.Vector3(index % 16, Math.floor(index / 256), Math.floor(index / 16) % 16)
14789
15208
  ));
14790
15209
  for (const info of this.renderedBlocks.values()) info.object?.removeFromScene();
14791
15210
  this.sectionBlocks.clear();
@@ -14810,14 +15229,14 @@ var Chunk = class _Chunk {
14810
15229
  return pos.y * 16 * 16 + pos.z * 16 + pos.x;
14811
15230
  }
14812
15231
  worldPosToChunkPos(pos) {
14813
- return new import_three40.Vector3(
15232
+ return new import_three39.Vector3(
14814
15233
  pos.x - this.x * 16,
14815
15234
  pos.y - this.y * 16,
14816
15235
  pos.z - this.z * 16
14817
15236
  );
14818
15237
  }
14819
15238
  chunkPosToWorldPos(pos) {
14820
- return new import_three40.Vector3(
15239
+ return new import_three39.Vector3(
14821
15240
  this.x * 16 + pos.x,
14822
15241
  this.y * 16 + pos.y,
14823
15242
  this.z * 16 + pos.z