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.
@@ -2922,16 +2922,17 @@ var init_UVMapper = __esm({
2922
2922
  positions[textureKey] = [x, y];
2923
2923
  const [width, height] = sizes[textureKey];
2924
2924
  const sequence = frames[textureKey];
2925
- const drawFrame = (index) => {
2925
+ const getFrameData = (index) => {
2926
2926
  const columns = texture.width / width;
2927
- image.putData(texture.getSectionData(
2927
+ return texture.getSectionData(
2928
2928
  index % columns * width,
2929
2929
  Math.floor(index / columns) * height,
2930
2930
  width,
2931
2931
  height
2932
- ), x, y);
2932
+ );
2933
2933
  };
2934
- drawFrame(sequence?.[0].index ?? 0);
2934
+ const firstFrame = getFrameData(sequence?.[0].index ?? 0);
2935
+ image.putData(firstFrame, x, y);
2935
2936
  if (texture.hasTransparency) {
2936
2937
  hasTransparency = true;
2937
2938
  }
@@ -2939,13 +2940,28 @@ var init_UVMapper = __esm({
2939
2940
  hasAnimation = true;
2940
2941
  let t = 0;
2941
2942
  let f = 0;
2943
+ const interpolated = metaMap[textureKey]?.animation?.interpolate ? image.context.createImageData(width, height) : void 0;
2944
+ let currentFrame = firstFrame;
2945
+ let nextFrame = interpolated ? getFrameData(sequence[1].index) : firstFrame;
2942
2946
  animatorFunctions[textureKey] = () => {
2943
- if (++t < sequence[f].time) return false;
2944
- t = 0;
2945
- const previous = sequence[f].index;
2946
- f = (f + 1) % sequence.length;
2947
- if (sequence[f].index === previous) return false;
2948
- drawFrame(sequence[f].index);
2947
+ if (++t >= sequence[f].time) {
2948
+ t = 0;
2949
+ const previous = sequence[f].index;
2950
+ f = (f + 1) % sequence.length;
2951
+ if (interpolated) {
2952
+ currentFrame = nextFrame;
2953
+ nextFrame = getFrameData(sequence[(f + 1) % sequence.length].index);
2954
+ }
2955
+ if (sequence[f].index === previous) return false;
2956
+ image.putData(interpolated ? currentFrame : getFrameData(sequence[f].index), x, y);
2957
+ return true;
2958
+ }
2959
+ if (!interpolated || sequence[f].index === sequence[(f + 1) % sequence.length].index) return false;
2960
+ const progress = Math.floor(Math.fround(Math.fround(t / sequence[f].time) * 1e3)) / 1e3;
2961
+ for (let i = 0; i < interpolated.data.length; i++) {
2962
+ interpolated.data[i] = currentFrame.data[i] + (nextFrame.data[i] - currentFrame.data[i]) * progress;
2963
+ }
2964
+ image.putData(interpolated, x, y);
2949
2965
  return true;
2950
2966
  };
2951
2967
  }
@@ -3926,6 +3942,7 @@ var init_SceneObject = __esm({
3926
3942
  dispose() {
3927
3943
  this.disposeAndRemoveAllChildren();
3928
3944
  this.notifyDirty();
3945
+ super.dispose();
3929
3946
  }
3930
3947
  disposeAndRemoveAllChildren() {
3931
3948
  if (this.instanceMesh) {
@@ -4143,6 +4160,7 @@ var init_EntityObject = __esm({
4143
4160
  else matrix.makeRotationFromEuler(new import_three14.Euler(...op.rotate, "ZYX"));
4144
4161
  modelRoot.matrix.multiply(matrix);
4145
4162
  }
4163
+ modelRoot.matrixWorldNeedsUpdate = true;
4146
4164
  modelRoot.matrixAutoUpdate = false;
4147
4165
  } else if (this.options.flip ?? true) {
4148
4166
  modelRoot.scale.set(-1, -1, 1);
@@ -4240,7 +4258,7 @@ function mergeBufferGeometries(geometries, useGroups = false) {
4240
4258
  const attributes = {};
4241
4259
  const morphAttributes = {};
4242
4260
  const morphTargetsRelative = geometries[0].morphTargetsRelative;
4243
- const mergedGeometry = new import_three21.BufferGeometry();
4261
+ const mergedGeometry = new import_three20.BufferGeometry();
4244
4262
  let offset = 0;
4245
4263
  for (let i = 0; i < geometries.length; ++i) {
4246
4264
  const geometry = geometries[i];
@@ -4364,7 +4382,7 @@ function mergeBufferAttributes(attributes) {
4364
4382
  array.set(attributes[i].array, offset);
4365
4383
  offset += attributes[i].array.length;
4366
4384
  }
4367
- return new import_three21.BufferAttribute(array, itemSize, normalized);
4385
+ return new import_three20.BufferAttribute(array, itemSize, normalized);
4368
4386
  }
4369
4387
  function interleaveAttributes(attributes) {
4370
4388
  let TypedArray;
@@ -4380,7 +4398,7 @@ function interleaveAttributes(attributes) {
4380
4398
  arrayLength += attribute.array.length;
4381
4399
  stride += attribute.itemSize;
4382
4400
  }
4383
- const interleavedBuffer = new import_three21.InterleavedBuffer(new TypedArray(arrayLength), stride);
4401
+ const interleavedBuffer = new import_three20.InterleavedBuffer(new TypedArray(arrayLength), stride);
4384
4402
  let offset = 0;
4385
4403
  const res = [];
4386
4404
  const getters = ["getX", "getY", "getZ", "getW"];
@@ -4389,7 +4407,7 @@ function interleaveAttributes(attributes) {
4389
4407
  const attribute = attributes[j];
4390
4408
  const itemSize = attribute.itemSize;
4391
4409
  const count = attribute.count;
4392
- const iba = new import_three21.InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, attribute.normalized);
4410
+ const iba = new import_three20.InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, attribute.normalized);
4393
4411
  res.push(iba);
4394
4412
  offset += itemSize;
4395
4413
  for (let c = 0; c < count; c++) {
@@ -4473,13 +4491,13 @@ function mergeVertices(geometry, tolerance = 1e-4) {
4473
4491
  const name = attributeNames[i];
4474
4492
  const oldAttribute = geometry.getAttribute(name);
4475
4493
  const buffer = new oldAttribute.array.constructor(attrArrays[name]);
4476
- const attribute = new import_three21.BufferAttribute(buffer, oldAttribute.itemSize, oldAttribute.normalized);
4494
+ const attribute = new import_three20.BufferAttribute(buffer, oldAttribute.itemSize, oldAttribute.normalized);
4477
4495
  result.setAttribute(name, attribute);
4478
4496
  if (name in morphAttrsArrays) {
4479
4497
  for (let j = 0; j < morphAttrsArrays[name].length; j++) {
4480
4498
  const oldMorphAttribute = geometry.morphAttributes[name][j];
4481
4499
  const buffer2 = new oldMorphAttribute.array.constructor(morphAttrsArrays[name][j]);
4482
- const morphAttribute = new import_three21.BufferAttribute(buffer2, oldMorphAttribute.itemSize, oldMorphAttribute.normalized);
4500
+ const morphAttribute = new import_three20.BufferAttribute(buffer2, oldMorphAttribute.itemSize, oldMorphAttribute.normalized);
4483
4501
  result.morphAttributes[name][j] = morphAttribute;
4484
4502
  }
4485
4503
  }
@@ -4488,11 +4506,11 @@ function mergeVertices(geometry, tolerance = 1e-4) {
4488
4506
  return result;
4489
4507
  }
4490
4508
  function toTrianglesDrawMode(geometry, drawMode) {
4491
- if (drawMode === import_three21.TrianglesDrawMode) {
4509
+ if (drawMode === import_three20.TrianglesDrawMode) {
4492
4510
  console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles.");
4493
4511
  return geometry;
4494
4512
  }
4495
- if (drawMode === import_three21.TriangleFanDrawMode || drawMode === import_three21.TriangleStripDrawMode) {
4513
+ if (drawMode === import_three20.TriangleFanDrawMode || drawMode === import_three20.TriangleStripDrawMode) {
4496
4514
  let index = geometry.getIndex();
4497
4515
  if (index === null) {
4498
4516
  const indices = [];
@@ -4510,7 +4528,7 @@ function toTrianglesDrawMode(geometry, drawMode) {
4510
4528
  }
4511
4529
  const numberOfTriangles = index.count - 2;
4512
4530
  const newIndices = [];
4513
- if (drawMode === import_three21.TriangleFanDrawMode) {
4531
+ if (drawMode === import_three20.TriangleFanDrawMode) {
4514
4532
  for (let i = 1; i <= numberOfTriangles; i++) {
4515
4533
  newIndices.push(index.getX(0));
4516
4534
  newIndices.push(index.getX(i));
@@ -4546,15 +4564,15 @@ function computeMorphedAttributes(object) {
4546
4564
  console.error("THREE.BufferGeometryUtils: Geometry is not of type BufferGeometry.");
4547
4565
  return null;
4548
4566
  }
4549
- const _vA = new import_three21.Vector3();
4550
- const _vB = new import_three21.Vector3();
4551
- const _vC = new import_three21.Vector3();
4552
- const _tempA = new import_three21.Vector3();
4553
- const _tempB = new import_three21.Vector3();
4554
- const _tempC = new import_three21.Vector3();
4555
- const _morphA = new import_three21.Vector3();
4556
- const _morphB = new import_three21.Vector3();
4557
- const _morphC = new import_three21.Vector3();
4567
+ const _vA = new import_three20.Vector3();
4568
+ const _vB = new import_three20.Vector3();
4569
+ const _vC = new import_three20.Vector3();
4570
+ const _tempA = new import_three20.Vector3();
4571
+ const _tempB = new import_three20.Vector3();
4572
+ const _tempC = new import_three20.Vector3();
4573
+ const _morphA = new import_three20.Vector3();
4574
+ const _morphB = new import_three20.Vector3();
4575
+ const _morphC = new import_three20.Vector3();
4558
4576
  function _calculateMorphedAttributeData(object2, material2, attribute, morphAttribute, morphTargetsRelative2, a2, b2, c2, modifiedAttributeArray) {
4559
4577
  _vA.fromBufferAttribute(attribute, a2);
4560
4578
  _vB.fromBufferAttribute(attribute, b2);
@@ -4749,8 +4767,8 @@ function computeMorphedAttributes(object) {
4749
4767
  }
4750
4768
  }
4751
4769
  }
4752
- const morphedPositionAttribute = new import_three21.Float32BufferAttribute(modifiedPosition, 3);
4753
- const morphedNormalAttribute = new import_three21.Float32BufferAttribute(modifiedNormal, 3);
4770
+ const morphedPositionAttribute = new import_three20.Float32BufferAttribute(modifiedPosition, 3);
4771
+ const morphedNormalAttribute = new import_three20.Float32BufferAttribute(modifiedNormal, 3);
4754
4772
  return {
4755
4773
  positionAttribute,
4756
4774
  normalAttribute,
@@ -4758,24 +4776,24 @@ function computeMorphedAttributes(object) {
4758
4776
  morphedNormalAttribute
4759
4777
  };
4760
4778
  }
4761
- var import_three21;
4779
+ var import_three20;
4762
4780
  var init_BufferGeometryUtils = __esm({
4763
4781
  "src/three/BufferGeometryUtils.js"() {
4764
- import_three21 = require("three");
4782
+ import_three20 = require("three");
4765
4783
  }
4766
4784
  });
4767
4785
 
4768
4786
  // src/model/ModelCulling.ts
4769
- var import_three22, ModelCulling;
4787
+ var import_three21, ModelCulling;
4770
4788
  var init_ModelCulling = __esm({
4771
4789
  "src/model/ModelCulling.ts"() {
4772
- import_three22 = require("three");
4790
+ import_three21 = require("three");
4773
4791
  init_CubeFace();
4774
4792
  ModelCulling = class {
4775
4793
  static toLocalMask(worldMask, rotation) {
4776
4794
  let localMask = 0;
4777
4795
  for (const [localFace, offset] of CUBE_FACE_OFFSETS.entries()) {
4778
- const normal = new import_three22.Vector3(...offset).applyEuler(rotation);
4796
+ const normal = new import_three21.Vector3(...offset).applyEuler(rotation);
4779
4797
  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);
4780
4798
  if (worldFace < 0) return 0;
4781
4799
  if (worldMask & 1 << worldFace) localMask |= 1 << localFace;
@@ -4808,10 +4826,10 @@ var init_ModelCulling = __esm({
4808
4826
  });
4809
4827
 
4810
4828
  // src/model/SpecialItems.ts
4811
- var import_three23, SpecialItems;
4829
+ var import_three22, SpecialItems;
4812
4830
  var init_SpecialItems = __esm({
4813
4831
  "src/model/SpecialItems.ts"() {
4814
- import_three23 = require("three");
4832
+ import_three22 = require("three");
4815
4833
  init_AssetKey();
4816
4834
  init_Entities();
4817
4835
  SpecialItems = class {
@@ -4839,7 +4857,7 @@ var init_SpecialItems = __esm({
4839
4857
  case "minecraft:chest":
4840
4858
  case "chest": {
4841
4859
  const angle = -(special.openness ?? 0) * Math.PI / 2;
4842
- const chest = await load("chest", texture(special.texture, "chest"), new import_three23.Matrix4(), {
4860
+ const chest = await load("chest", texture(special.texture, "chest"), new import_three22.Matrix4(), {
4843
4861
  lid: [angle, 0, 0],
4844
4862
  lock: [angle, 0, 0]
4845
4863
  });
@@ -4848,11 +4866,11 @@ var init_SpecialItems = __esm({
4848
4866
  }
4849
4867
  case "minecraft:bed":
4850
4868
  case "bed": {
4851
- 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));
4869
+ 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));
4852
4870
  const key = texture(special.texture, "bed");
4853
4871
  return Promise.all([
4854
4872
  load("bed_head", key, transform),
4855
- load("bed_foot", key, new import_three23.Matrix4().makeTranslation(0, 0, -16).multiply(transform))
4873
+ load("bed_foot", key, new import_three22.Matrix4().makeTranslation(0, 0, -16).multiply(transform))
4856
4874
  ]);
4857
4875
  }
4858
4876
  case "minecraft:head":
@@ -4877,7 +4895,7 @@ var init_SpecialItems = __esm({
4877
4895
  return [await load(
4878
4896
  id,
4879
4897
  special.texture ? texture(special.texture, "") : void 0,
4880
- new import_three23.Matrix4().makeTranslation(8, 0, 8).multiply(new import_three23.Matrix4().makeScale(-1, -1, 1)),
4898
+ new import_three22.Matrix4().makeTranslation(8, 0, 8).multiply(new import_three22.Matrix4().makeScale(-1, -1, 1)),
4881
4899
  rotations
4882
4900
  )];
4883
4901
  }
@@ -5005,13 +5023,13 @@ var init_ItemTints = __esm({
5005
5023
  function isModelObject(obj) {
5006
5024
  return obj.isModelObject;
5007
5025
  }
5008
- var import_three24, import_ts_deepmerge5, p7, _ModelObject, ModelObject;
5026
+ var import_three23, import_ts_deepmerge5, p7, _ModelObject, ModelObject;
5009
5027
  var init_ModelObject = __esm({
5010
5028
  "src/model/scene/ModelObject.ts"() {
5011
5029
  init_SceneObject();
5012
5030
  init_Materials();
5013
5031
  init_UVMapper();
5014
- import_three24 = require("three");
5032
+ import_three23 = require("three");
5015
5033
  init_BufferGeometryUtils();
5016
5034
  init_model();
5017
5035
  import_ts_deepmerge5 = __toESM(require_dist());
@@ -5043,12 +5061,13 @@ var init_ModelObject = __esm({
5043
5061
  const special = this.originalModel.special;
5044
5062
  if (special) {
5045
5063
  const parts = await SpecialItems.getParts(special, this.originalModel.key?.root);
5046
- const transform = this.options.displayPosition ? DisplayTransforms.getMatrix(this.originalModel.display, this.options.displayPosition) : new import_three24.Matrix4();
5047
- transform.multiply(new import_three24.Matrix4().makeTranslation(-8, -8, -8));
5064
+ const transform = this.options.displayPosition ? DisplayTransforms.getMatrix(this.originalModel.display, this.options.displayPosition) : new import_three23.Matrix4();
5065
+ transform.multiply(new import_three23.Matrix4().makeTranslation(-8, -8, -8));
5048
5066
  try {
5049
5067
  for (const part of parts) {
5050
5068
  const object = new EntityObject(part.model, { flip: false, wireframe: this.options.wireframe });
5051
5069
  object.matrix.copy(transform).multiply(part.transform);
5070
+ object.matrixWorldNeedsUpdate = true;
5052
5071
  object.matrixAutoUpdate = false;
5053
5072
  this.add(object);
5054
5073
  await object.init();
@@ -5106,7 +5125,7 @@ var init_ModelObject = __esm({
5106
5125
  elGeo.clearGroups();
5107
5126
  }
5108
5127
  if (this.options.uvLockRotation) {
5109
- UVMapper.lockUvs(elGeo, el.faces, this.atlas, new import_three24.Euler(...this.options.uvLockRotation));
5128
+ UVMapper.lockUvs(elGeo, el.faces, this.atlas, new import_three23.Euler(...this.options.uvLockRotation));
5110
5129
  }
5111
5130
  if (this.options.tints) {
5112
5131
  const colors = new Float32Array(elGeo.getAttribute("position").count * 3).fill(1);
@@ -5115,19 +5134,19 @@ var init_ModelObject = __esm({
5115
5134
  if (tintIndex === void 0 || tintIndex < 0) continue;
5116
5135
  const tint = this.options.tints[tintIndex];
5117
5136
  if (tint === void 0) continue;
5118
- const color = new import_three24.Color(tint);
5137
+ const color = new import_three23.Color(tint);
5119
5138
  for (let vertex = 0; vertex < 4; vertex++) {
5120
5139
  color.toArray(colors, (faceIndex * 4 + vertex) * 3);
5121
5140
  }
5122
5141
  }
5123
- elGeo.setAttribute("color", new import_three24.BufferAttribute(colors, 3));
5142
+ elGeo.setAttribute("color", new import_three23.BufferAttribute(colors, 3));
5124
5143
  }
5125
- 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));
5126
- elGeo.applyMatrix4(new import_three24.Matrix4().makeTranslation(el.from[0], el.from[1], el.from[2]));
5144
+ 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));
5145
+ elGeo.applyMatrix4(new import_three23.Matrix4().makeTranslation(el.from[0], el.from[1], el.from[2]));
5127
5146
  if (el.rotation) {
5128
5147
  applyElementRotation(el.rotation, elGeo);
5129
5148
  }
5130
- elGeo.applyMatrix4(new import_three24.Matrix4().makeTranslation(-8, -8, -8));
5149
+ elGeo.applyMatrix4(new import_three23.Matrix4().makeTranslation(-8, -8, -8));
5131
5150
  if (displayTransform) DisplayTransforms.apply(elGeo, displayTransform);
5132
5151
  if (this.options.mergeMeshes) {
5133
5152
  allGeos.push(elGeo);
@@ -5149,7 +5168,7 @@ var init_ModelObject = __esm({
5149
5168
  if (allGeos.length > 0) {
5150
5169
  combinedGeo = mergeBufferGeometries(allGeos);
5151
5170
  } else {
5152
- combinedGeo = new import_three24.BoxGeometry(16, 16, 16);
5171
+ combinedGeo = new import_three23.BoxGeometry(16, 16, 16);
5153
5172
  if (displayTransform) DisplayTransforms.apply(combinedGeo, displayTransform);
5154
5173
  }
5155
5174
  combinedGeo.computeBoundingBox();
@@ -5261,7 +5280,7 @@ function ownHeight(sample) {
5261
5280
  return (level === 0 || level >= 8 ? 8 : 8 - level) / 9;
5262
5281
  }
5263
5282
  function createFluidGeometry(kind, sample) {
5264
- const geometry = new import_three29.BufferGeometry();
5283
+ const geometry = new import_three28.BufferGeometry();
5265
5284
  const positions = [], normals = [], uvs = [], indices = [];
5266
5285
  const self = sample(0, 0, 0);
5267
5286
  const height = (x, z) => {
@@ -5360,16 +5379,16 @@ function createFluidGeometry(kind, sample) {
5360
5379
  1
5361
5380
  );
5362
5381
  }
5363
- geometry.setAttribute("position", new import_three29.Float32BufferAttribute(positions, 3));
5364
- geometry.setAttribute("normal", new import_three29.Float32BufferAttribute(normals, 3));
5365
- geometry.setAttribute("uv", new import_three29.Float32BufferAttribute(uvs, 2));
5382
+ geometry.setAttribute("position", new import_three28.Float32BufferAttribute(positions, 3));
5383
+ geometry.setAttribute("normal", new import_three28.Float32BufferAttribute(normals, 3));
5384
+ geometry.setAttribute("uv", new import_three28.Float32BufferAttribute(uvs, 2));
5366
5385
  geometry.setIndex(indices);
5367
5386
  return geometry;
5368
5387
  }
5369
- var import_three29, fluidRules, HORIZONTAL, EPSILON;
5388
+ var import_three28, fluidRules, HORIZONTAL, EPSILON;
5370
5389
  var init_FluidGeometry = __esm({
5371
5390
  "src/model/fluid/FluidGeometry.ts"() {
5372
- import_three29 = require("three");
5391
+ import_three28 = require("three");
5373
5392
  init_fluidBlocks();
5374
5393
  fluidRules = fluidBlocks_default;
5375
5394
  HORIZONTAL = [[0, -1], [0, 1], [-1, 0], [1, 0]];
@@ -5398,10 +5417,10 @@ function sampleFluid(kind, sample) {
5398
5417
  }
5399
5418
  return { key: key.join(""), sample: (x, y, z) => cells[(y + 1) * 9 + (z + 1) * 3 + x + 1] };
5400
5419
  }
5401
- var import_three30, FluidModelObject;
5420
+ var import_three29, FluidModelObject;
5402
5421
  var init_FluidModelObject = __esm({
5403
5422
  "src/model/fluid/FluidModelObject.ts"() {
5404
- import_three30 = require("three");
5423
+ import_three29 = require("three");
5405
5424
  init_AssetKey();
5406
5425
  init_Materials();
5407
5426
  init_ModelObject();
@@ -5434,10 +5453,10 @@ var init_FluidModelObject = __esm({
5434
5453
  }
5435
5454
  }
5436
5455
  geometry.clearGroups();
5437
- const color = new import_three30.Color(this.options.tints?.[0] ?? (this.kind === "water" ? 4159204 : 16777215));
5456
+ const color = new import_three29.Color(this.options.tints?.[0] ?? (this.kind === "water" ? 4159204 : 16777215));
5438
5457
  const colors = new Float32Array(geometry.getAttribute("position").count * 3);
5439
5458
  for (let i = 0; i < colors.length; i += 3) color.toArray(colors, i);
5440
- geometry.setAttribute("color", new import_three30.BufferAttribute(colors, 3));
5459
+ geometry.setAttribute("color", new import_three29.BufferAttribute(colors, 3));
5441
5460
  geometry.computeBoundingBox();
5442
5461
  geometry.computeBoundingSphere();
5443
5462
  if (this.options.instanceMeshes) {
@@ -5451,7 +5470,7 @@ var init_FluidModelObject = __esm({
5451
5470
  super.applyTextures();
5452
5471
  this.iterateAllMeshes((mesh) => {
5453
5472
  const material = mesh.material;
5454
- material.side = import_three30.DoubleSide;
5473
+ material.side = import_three29.DoubleSide;
5455
5474
  material.forceSinglePass = true;
5456
5475
  material.depthWrite = !material.transparent;
5457
5476
  });
@@ -5938,11 +5957,19 @@ init_EntityObject();
5938
5957
  init_MineRenderError();
5939
5958
 
5940
5959
  // src/export/SceneExporter.ts
5941
- var import_three20 = require("three");
5960
+ var import_three19 = require("three");
5942
5961
 
5943
5962
  // ../../node_modules/three/examples/jsm/exporters/OBJExporter.js
5944
5963
  var import_three16 = require("three");
5945
5964
  var OBJExporter = class {
5965
+ /**
5966
+ * Parses the given 3D object and generates the OBJ output.
5967
+ *
5968
+ * If the 3D object is composed of multiple children and geometry, they are merged into a single mesh in the file.
5969
+ *
5970
+ * @param {Object3D} object - The 3D object to export.
5971
+ * @return {string} The exported OBJ.
5972
+ */
5946
5973
  parse(object) {
5947
5974
  let output = "";
5948
5975
  let indexVertex = 0;
@@ -6048,7 +6075,8 @@ var OBJExporter = class {
6048
6075
  vertex.applyMatrix4(points.matrixWorld);
6049
6076
  output += "v " + vertex.x + " " + vertex.y + " " + vertex.z;
6050
6077
  if (colors !== void 0) {
6051
- color.fromBufferAttribute(colors, i).convertLinearToSRGB();
6078
+ color.fromBufferAttribute(colors, i);
6079
+ import_three16.ColorManagement.workingToColorSpace(color, import_three16.SRGBColorSpace);
6052
6080
  output += " " + color.r + " " + color.g + " " + color.b;
6053
6081
  }
6054
6082
  output += "\n";
@@ -6079,6 +6107,16 @@ var OBJExporter = class {
6079
6107
  // ../../node_modules/three/examples/jsm/exporters/PLYExporter.js
6080
6108
  var import_three17 = require("three");
6081
6109
  var PLYExporter = class {
6110
+ /**
6111
+ * Parses the given 3D object and generates the PLY output.
6112
+ *
6113
+ * If the 3D object is composed of multiple children and geometry, they are merged into a single mesh in the file.
6114
+ *
6115
+ * @param {Object3D} object - The 3D object to export.
6116
+ * @param {PLYExporter~OnDone} onDone - A callback function that is executed when the export has finished.
6117
+ * @param {PLYExporter~Options} options - The export options.
6118
+ * @return {?(string|ArrayBuffer)} The exported PLY.
6119
+ */
6082
6120
  parse(object, onDone, options = {}) {
6083
6121
  function traverseMeshes(cb) {
6084
6122
  object.traverse(function(child) {
@@ -6095,14 +6133,23 @@ var PLYExporter = class {
6095
6133
  binary: false,
6096
6134
  excludeAttributes: [],
6097
6135
  // normal, uv, color, index
6098
- littleEndian: false
6136
+ littleEndian: false,
6137
+ customPropertyMapping: {}
6099
6138
  };
6100
6139
  options = Object.assign(defaultOptions, options);
6101
6140
  const excludeAttributes = options.excludeAttributes;
6141
+ const customPropertyMapping = options.customPropertyMapping;
6142
+ const customAttributeNames = Object.keys(customPropertyMapping);
6102
6143
  let includeIndices = true;
6103
6144
  let includeNormals = false;
6104
6145
  let includeColors = false;
6105
6146
  let includeUVs = false;
6147
+ let positionType = "float";
6148
+ let normalType = "float";
6149
+ let uvType = "float";
6150
+ let colorType = "uchar";
6151
+ const customTypes = {};
6152
+ for (const name of customAttributeNames) customTypes[name] = "float";
6106
6153
  let vertexCount = 0;
6107
6154
  let faceCount = 0;
6108
6155
  object.traverse(function(child) {
@@ -6119,9 +6166,23 @@ var PLYExporter = class {
6119
6166
  }
6120
6167
  vertexCount += vertices.count;
6121
6168
  faceCount += indices ? indices.count / 3 : vertices.count / 3;
6122
- if (normals !== void 0) includeNormals = true;
6123
- if (uvs !== void 0) includeUVs = true;
6124
- if (colors !== void 0) includeColors = true;
6169
+ positionType = getPlyType(vertices.array);
6170
+ if (normals !== void 0) {
6171
+ includeNormals = true;
6172
+ normalType = getPlyType(normals.array);
6173
+ }
6174
+ if (uvs !== void 0) {
6175
+ includeUVs = true;
6176
+ uvType = getPlyType(uvs.array);
6177
+ }
6178
+ if (colors !== void 0) {
6179
+ includeColors = true;
6180
+ colorType = getPlyType(colors.array);
6181
+ }
6182
+ for (const name of customAttributeNames) {
6183
+ const attr = geometry.getAttribute(name);
6184
+ if (attr !== void 0) customTypes[name] = getPlyType(attr.array);
6185
+ }
6125
6186
  } else if (child.isPoints) {
6126
6187
  const mesh = child;
6127
6188
  const geometry = mesh.geometry;
@@ -6129,8 +6190,19 @@ var PLYExporter = class {
6129
6190
  const normals = geometry.getAttribute("normal");
6130
6191
  const colors = geometry.getAttribute("color");
6131
6192
  vertexCount += vertices.count;
6132
- if (normals !== void 0) includeNormals = true;
6133
- if (colors !== void 0) includeColors = true;
6193
+ positionType = getPlyType(vertices.array);
6194
+ if (normals !== void 0) {
6195
+ includeNormals = true;
6196
+ normalType = getPlyType(normals.array);
6197
+ }
6198
+ if (colors !== void 0) {
6199
+ includeColors = true;
6200
+ colorType = getPlyType(colors.array);
6201
+ }
6202
+ for (const name of customAttributeNames) {
6203
+ const attr = geometry.getAttribute(name);
6204
+ if (attr !== void 0) customTypes[name] = getPlyType(attr.array);
6205
+ }
6134
6206
  includeIndices = false;
6135
6207
  }
6136
6208
  });
@@ -6149,18 +6221,33 @@ var PLYExporter = class {
6149
6221
  let header = `ply
6150
6222
  format ${options.binary ? options.littleEndian ? "binary_little_endian" : "binary_big_endian" : "ascii"} 1.0
6151
6223
  element vertex ${vertexCount}
6152
- property float x
6153
- property float y
6154
- property float z
6224
+ property ${positionType} x
6225
+ property ${positionType} y
6226
+ property ${positionType} z
6155
6227
  `;
6156
6228
  if (includeNormals === true) {
6157
- header += "property float nx\nproperty float ny\nproperty float nz\n";
6229
+ header += `property ${normalType} nx
6230
+ property ${normalType} ny
6231
+ property ${normalType} nz
6232
+ `;
6158
6233
  }
6159
6234
  if (includeUVs === true) {
6160
- header += "property float s\nproperty float t\n";
6235
+ header += `property ${uvType} s
6236
+ property ${uvType} t
6237
+ `;
6161
6238
  }
6162
6239
  if (includeColors === true) {
6163
- header += "property uchar red\nproperty uchar green\nproperty uchar blue\n";
6240
+ header += `property ${colorType} red
6241
+ property ${colorType} green
6242
+ property ${colorType} blue
6243
+ `;
6244
+ }
6245
+ for (const name of customAttributeNames) {
6246
+ const type = customTypes[name];
6247
+ for (const propName of customPropertyMapping[name]) {
6248
+ header += `property ${type} ${propName}
6249
+ `;
6250
+ }
6164
6251
  }
6165
6252
  if (includeIndices === true) {
6166
6253
  header += `element face ${faceCount}
@@ -6173,7 +6260,23 @@ property list uchar int vertex_index
6173
6260
  let result = null;
6174
6261
  if (options.binary === true) {
6175
6262
  const headerBin = new TextEncoder().encode(header);
6176
- const vertexListLength = vertexCount * (4 * 3 + (includeNormals ? 4 * 3 : 0) + (includeColors ? 3 : 0) + (includeUVs ? 4 * 2 : 0));
6263
+ const posWriter = getBinaryWriter(positionType);
6264
+ const normalWriter = includeNormals ? getBinaryWriter(normalType) : null;
6265
+ const uvWriter = includeUVs ? getBinaryWriter(uvType) : null;
6266
+ const colorWriter = includeColors ? getBinaryWriter(colorType) : null;
6267
+ const colorIsFloat = isFloatType(colorType);
6268
+ const colorScale = getColorScale(colorType);
6269
+ const customWriters = {};
6270
+ const customIsFloat = {};
6271
+ let customStride = 0;
6272
+ for (const name of customAttributeNames) {
6273
+ const type = customTypes[name];
6274
+ const writer = getBinaryWriter(type);
6275
+ customWriters[name] = writer;
6276
+ customIsFloat[name] = isFloatType(type);
6277
+ customStride += customPropertyMapping[name].length * writer.size;
6278
+ }
6279
+ const vertexListLength = vertexCount * (3 * posWriter.size + (includeNormals ? 3 * normalWriter.size : 0) + (includeUVs ? 2 * uvWriter.size : 0) + (includeColors ? 3 * colorWriter.size : 0) + customStride);
6177
6280
  const faceListLength = includeIndices ? faceCount * (indexByteCount * 3 + 1) : 0;
6178
6281
  const output = new DataView(new ArrayBuffer(headerBin.length + vertexListLength + faceListLength));
6179
6282
  new Uint8Array(output.buffer).set(headerBin, 0);
@@ -6190,60 +6293,76 @@ property list uchar int vertex_index
6190
6293
  for (let i = 0, l = vertices.count; i < l; i++) {
6191
6294
  vertex.fromBufferAttribute(vertices, i);
6192
6295
  vertex.applyMatrix4(mesh.matrixWorld);
6193
- output.setFloat32(vOffset, vertex.x, options.littleEndian);
6194
- vOffset += 4;
6195
- output.setFloat32(vOffset, vertex.y, options.littleEndian);
6196
- vOffset += 4;
6197
- output.setFloat32(vOffset, vertex.z, options.littleEndian);
6198
- vOffset += 4;
6296
+ posWriter.write(output, vOffset, vertex.x, options.littleEndian);
6297
+ vOffset += posWriter.size;
6298
+ posWriter.write(output, vOffset, vertex.y, options.littleEndian);
6299
+ vOffset += posWriter.size;
6300
+ posWriter.write(output, vOffset, vertex.z, options.littleEndian);
6301
+ vOffset += posWriter.size;
6199
6302
  if (includeNormals === true) {
6200
6303
  if (normals != null) {
6201
6304
  vertex.fromBufferAttribute(normals, i);
6202
6305
  vertex.applyMatrix3(normalMatrixWorld).normalize();
6203
- output.setFloat32(vOffset, vertex.x, options.littleEndian);
6204
- vOffset += 4;
6205
- output.setFloat32(vOffset, vertex.y, options.littleEndian);
6206
- vOffset += 4;
6207
- output.setFloat32(vOffset, vertex.z, options.littleEndian);
6208
- vOffset += 4;
6306
+ normalWriter.write(output, vOffset, vertex.x, options.littleEndian);
6307
+ vOffset += normalWriter.size;
6308
+ normalWriter.write(output, vOffset, vertex.y, options.littleEndian);
6309
+ vOffset += normalWriter.size;
6310
+ normalWriter.write(output, vOffset, vertex.z, options.littleEndian);
6311
+ vOffset += normalWriter.size;
6209
6312
  } else {
6210
- output.setFloat32(vOffset, 0, options.littleEndian);
6211
- vOffset += 4;
6212
- output.setFloat32(vOffset, 0, options.littleEndian);
6213
- vOffset += 4;
6214
- output.setFloat32(vOffset, 0, options.littleEndian);
6215
- vOffset += 4;
6313
+ normalWriter.write(output, vOffset, 0, options.littleEndian);
6314
+ vOffset += normalWriter.size;
6315
+ normalWriter.write(output, vOffset, 0, options.littleEndian);
6316
+ vOffset += normalWriter.size;
6317
+ normalWriter.write(output, vOffset, 0, options.littleEndian);
6318
+ vOffset += normalWriter.size;
6216
6319
  }
6217
6320
  }
6218
6321
  if (includeUVs === true) {
6219
6322
  if (uvs != null) {
6220
- output.setFloat32(vOffset, uvs.getX(i), options.littleEndian);
6221
- vOffset += 4;
6222
- output.setFloat32(vOffset, uvs.getY(i), options.littleEndian);
6223
- vOffset += 4;
6323
+ uvWriter.write(output, vOffset, uvs.getX(i), options.littleEndian);
6324
+ vOffset += uvWriter.size;
6325
+ uvWriter.write(output, vOffset, uvs.getY(i), options.littleEndian);
6326
+ vOffset += uvWriter.size;
6224
6327
  } else {
6225
- output.setFloat32(vOffset, 0, options.littleEndian);
6226
- vOffset += 4;
6227
- output.setFloat32(vOffset, 0, options.littleEndian);
6228
- vOffset += 4;
6328
+ uvWriter.write(output, vOffset, 0, options.littleEndian);
6329
+ vOffset += uvWriter.size;
6330
+ uvWriter.write(output, vOffset, 0, options.littleEndian);
6331
+ vOffset += uvWriter.size;
6229
6332
  }
6230
6333
  }
6231
6334
  if (includeColors === true) {
6232
6335
  if (colors != null) {
6233
- tempColor.fromBufferAttribute(colors, i).convertLinearToSRGB();
6234
- output.setUint8(vOffset, Math.floor(tempColor.r * 255));
6235
- vOffset += 1;
6236
- output.setUint8(vOffset, Math.floor(tempColor.g * 255));
6237
- vOffset += 1;
6238
- output.setUint8(vOffset, Math.floor(tempColor.b * 255));
6239
- vOffset += 1;
6336
+ tempColor.fromBufferAttribute(colors, i);
6337
+ import_three17.ColorManagement.workingToColorSpace(tempColor, import_three17.SRGBColorSpace);
6338
+ const r = colorIsFloat ? tempColor.r : Math.round(tempColor.r * colorScale);
6339
+ const g = colorIsFloat ? tempColor.g : Math.round(tempColor.g * colorScale);
6340
+ const b = colorIsFloat ? tempColor.b : Math.round(tempColor.b * colorScale);
6341
+ colorWriter.write(output, vOffset, r, options.littleEndian);
6342
+ vOffset += colorWriter.size;
6343
+ colorWriter.write(output, vOffset, g, options.littleEndian);
6344
+ vOffset += colorWriter.size;
6345
+ colorWriter.write(output, vOffset, b, options.littleEndian);
6346
+ vOffset += colorWriter.size;
6240
6347
  } else {
6241
- output.setUint8(vOffset, 255);
6242
- vOffset += 1;
6243
- output.setUint8(vOffset, 255);
6244
- vOffset += 1;
6245
- output.setUint8(vOffset, 255);
6246
- vOffset += 1;
6348
+ const white = colorIsFloat ? 1 : colorScale;
6349
+ colorWriter.write(output, vOffset, white, options.littleEndian);
6350
+ vOffset += colorWriter.size;
6351
+ colorWriter.write(output, vOffset, white, options.littleEndian);
6352
+ vOffset += colorWriter.size;
6353
+ colorWriter.write(output, vOffset, white, options.littleEndian);
6354
+ vOffset += colorWriter.size;
6355
+ }
6356
+ }
6357
+ for (const name of customAttributeNames) {
6358
+ const writer = customWriters[name];
6359
+ const propCount = customPropertyMapping[name].length;
6360
+ const attr = geometry.getAttribute(name);
6361
+ const isFloat = customIsFloat[name];
6362
+ for (let c = 0; c < propCount; c++) {
6363
+ const raw = attr != null ? getAttributeComponent(attr, i, c) : 0;
6364
+ writer.write(output, vOffset, isFloat ? raw : Math.round(raw), options.littleEndian);
6365
+ vOffset += writer.size;
6247
6366
  }
6248
6367
  }
6249
6368
  }
@@ -6279,6 +6398,14 @@ property list uchar int vertex_index
6279
6398
  let writtenVertices = 0;
6280
6399
  let vertexList = "";
6281
6400
  let faceList = "";
6401
+ const positionIsFloat = isFloatType(positionType);
6402
+ const normalIsFloat = isFloatType(normalType);
6403
+ const uvIsFloat = isFloatType(uvType);
6404
+ const colorIsFloat = isFloatType(colorType);
6405
+ const colorScale = getColorScale(colorType);
6406
+ const customIsFloat = {};
6407
+ for (const name of customAttributeNames) customIsFloat[name] = isFloatType(customTypes[name]);
6408
+ const encode = (v, isFloat) => isFloat ? v : Math.round(v);
6282
6409
  traverseMeshes(function(mesh, geometry) {
6283
6410
  const vertices = geometry.getAttribute("position");
6284
6411
  const normals = geometry.getAttribute("normal");
@@ -6289,29 +6416,43 @@ property list uchar int vertex_index
6289
6416
  for (let i = 0, l = vertices.count; i < l; i++) {
6290
6417
  vertex.fromBufferAttribute(vertices, i);
6291
6418
  vertex.applyMatrix4(mesh.matrixWorld);
6292
- let line = vertex.x + " " + vertex.y + " " + vertex.z;
6419
+ let line = encode(vertex.x, positionIsFloat) + " " + encode(vertex.y, positionIsFloat) + " " + encode(vertex.z, positionIsFloat);
6293
6420
  if (includeNormals === true) {
6294
6421
  if (normals != null) {
6295
6422
  vertex.fromBufferAttribute(normals, i);
6296
6423
  vertex.applyMatrix3(normalMatrixWorld).normalize();
6297
- line += " " + vertex.x + " " + vertex.y + " " + vertex.z;
6424
+ line += " " + encode(vertex.x, normalIsFloat) + " " + encode(vertex.y, normalIsFloat) + " " + encode(vertex.z, normalIsFloat);
6298
6425
  } else {
6299
6426
  line += " 0 0 0";
6300
6427
  }
6301
6428
  }
6302
6429
  if (includeUVs === true) {
6303
6430
  if (uvs != null) {
6304
- line += " " + uvs.getX(i) + " " + uvs.getY(i);
6431
+ line += " " + encode(uvs.getX(i), uvIsFloat) + " " + encode(uvs.getY(i), uvIsFloat);
6305
6432
  } else {
6306
6433
  line += " 0 0";
6307
6434
  }
6308
6435
  }
6309
6436
  if (includeColors === true) {
6310
6437
  if (colors != null) {
6311
- tempColor.fromBufferAttribute(colors, i).convertLinearToSRGB();
6312
- line += " " + Math.floor(tempColor.r * 255) + " " + Math.floor(tempColor.g * 255) + " " + Math.floor(tempColor.b * 255);
6438
+ tempColor.fromBufferAttribute(colors, i);
6439
+ import_three17.ColorManagement.workingToColorSpace(tempColor, import_three17.SRGBColorSpace);
6440
+ const r = colorIsFloat ? tempColor.r : Math.round(tempColor.r * colorScale);
6441
+ const g = colorIsFloat ? tempColor.g : Math.round(tempColor.g * colorScale);
6442
+ const b = colorIsFloat ? tempColor.b : Math.round(tempColor.b * colorScale);
6443
+ line += ` ${r} ${g} ${b}`;
6313
6444
  } else {
6314
- line += " 255 255 255";
6445
+ const white = colorIsFloat ? 1 : colorScale;
6446
+ line += ` ${white} ${white} ${white}`;
6447
+ }
6448
+ }
6449
+ for (const name of customAttributeNames) {
6450
+ const propCount = customPropertyMapping[name].length;
6451
+ const attr = geometry.getAttribute(name);
6452
+ const isFloat = customIsFloat[name];
6453
+ for (let c = 0; c < propCount; c++) {
6454
+ const raw = attr != null ? getAttributeComponent(attr, i, c) : 0;
6455
+ line += " " + encode(raw, isFloat);
6315
6456
  }
6316
6457
  }
6317
6458
  vertexList += line + "\n";
@@ -6341,70 +6482,65 @@ property list uchar int vertex_index
6341
6482
  return result;
6342
6483
  }
6343
6484
  };
6344
-
6345
- // ../../node_modules/three/examples/jsm/exporters/GLTFExporter.js
6346
- var import_three19 = require("three");
6347
-
6348
- // ../../node_modules/three/examples/jsm/utils/TextureUtils.js
6349
- var import_three18 = require("three");
6350
- var _renderer;
6351
- var fullscreenQuadGeometry;
6352
- var fullscreenQuadMaterial;
6353
- var fullscreenQuad;
6354
- function decompress(texture, maxTextureSize = Infinity, renderer = null) {
6355
- if (!fullscreenQuadGeometry) fullscreenQuadGeometry = new import_three18.PlaneGeometry(2, 2, 1, 1);
6356
- if (!fullscreenQuadMaterial) fullscreenQuadMaterial = new import_three18.ShaderMaterial({
6357
- uniforms: { blitTexture: new import_three18.Uniform(texture) },
6358
- vertexShader: `
6359
- varying vec2 vUv;
6360
- void main(){
6361
- vUv = uv;
6362
- gl_Position = vec4(position.xy * 1.0,0.,.999999);
6363
- }`,
6364
- fragmentShader: `
6365
- uniform sampler2D blitTexture;
6366
- varying vec2 vUv;
6367
-
6368
- void main(){
6369
- gl_FragColor = vec4(vUv.xy, 0, 1);
6370
-
6371
- #ifdef IS_SRGB
6372
- gl_FragColor = LinearTosRGB( texture2D( blitTexture, vUv) );
6373
- #else
6374
- gl_FragColor = texture2D( blitTexture, vUv);
6375
- #endif
6376
- }`
6377
- });
6378
- fullscreenQuadMaterial.uniforms.blitTexture.value = texture;
6379
- fullscreenQuadMaterial.defines.IS_SRGB = texture.colorSpace == import_three18.SRGBColorSpace;
6380
- fullscreenQuadMaterial.needsUpdate = true;
6381
- if (!fullscreenQuad) {
6382
- fullscreenQuad = new import_three18.Mesh(fullscreenQuadGeometry, fullscreenQuadMaterial);
6383
- fullscreenQuad.frustrumCulled = false;
6384
- }
6385
- const _camera = new import_three18.PerspectiveCamera();
6386
- const _scene = new import_three18.Scene();
6387
- _scene.add(fullscreenQuad);
6388
- if (!renderer) {
6389
- renderer = _renderer = new import_three18.WebGLRenderer({ antialias: false });
6390
- }
6391
- renderer.setSize(Math.min(texture.image.width, maxTextureSize), Math.min(texture.image.height, maxTextureSize));
6392
- renderer.clear();
6393
- renderer.render(_scene, _camera);
6394
- const readableTexture = new import_three18.Texture(renderer.domElement);
6395
- readableTexture.minFilter = texture.minFilter;
6396
- readableTexture.magFilter = texture.magFilter;
6397
- readableTexture.wrapS = texture.wrapS;
6398
- readableTexture.wrapT = texture.wrapT;
6399
- readableTexture.name = texture.name;
6400
- if (_renderer) {
6401
- _renderer.dispose();
6402
- _renderer = null;
6403
- }
6404
- return readableTexture;
6485
+ function getPlyType(array) {
6486
+ if (array instanceof Int8Array) return "char";
6487
+ if (array instanceof Uint8Array || array instanceof Uint8ClampedArray) return "uchar";
6488
+ if (array instanceof Int16Array) return "short";
6489
+ if (array instanceof Uint16Array) return "ushort";
6490
+ if (array instanceof Int32Array) return "int";
6491
+ if (array instanceof Uint32Array) return "uint";
6492
+ if (array instanceof Float32Array) return "float";
6493
+ if (array instanceof Float64Array) return "double";
6494
+ return "float";
6495
+ }
6496
+ function getBinaryWriter(type) {
6497
+ switch (type) {
6498
+ case "char":
6499
+ return { write: (dv, at, v) => dv.setInt8(at, v), size: 1 };
6500
+ case "uchar":
6501
+ return { write: (dv, at, v) => dv.setUint8(at, v), size: 1 };
6502
+ case "short":
6503
+ return { write: (dv, at, v, le) => dv.setInt16(at, v, le), size: 2 };
6504
+ case "ushort":
6505
+ return { write: (dv, at, v, le) => dv.setUint16(at, v, le), size: 2 };
6506
+ case "int":
6507
+ return { write: (dv, at, v, le) => dv.setInt32(at, v, le), size: 4 };
6508
+ case "uint":
6509
+ return { write: (dv, at, v, le) => dv.setUint32(at, v, le), size: 4 };
6510
+ case "float":
6511
+ return { write: (dv, at, v, le) => dv.setFloat32(at, v, le), size: 4 };
6512
+ case "double":
6513
+ return { write: (dv, at, v, le) => dv.setFloat64(at, v, le), size: 8 };
6514
+ }
6515
+ }
6516
+ function isFloatType(type) {
6517
+ return type === "float" || type === "double";
6518
+ }
6519
+ function getAttributeComponent(attr, i, c) {
6520
+ switch (c) {
6521
+ case 0:
6522
+ return attr.getX(i);
6523
+ case 1:
6524
+ return attr.getY(i);
6525
+ case 2:
6526
+ return attr.getZ(i);
6527
+ case 3:
6528
+ return attr.getW(i);
6529
+ }
6530
+ }
6531
+ function getColorScale(type) {
6532
+ switch (type) {
6533
+ case "uchar":
6534
+ return 255;
6535
+ case "ushort":
6536
+ return 65535;
6537
+ default:
6538
+ return 1;
6539
+ }
6405
6540
  }
6406
6541
 
6407
6542
  // ../../node_modules/three/examples/jsm/exporters/GLTFExporter.js
6543
+ var import_three18 = require("three");
6408
6544
  var KHR_mesh_quantization_ExtraAttrTypes = {
6409
6545
  POSITION: [
6410
6546
  "byte",
@@ -6434,7 +6570,11 @@ var KHR_mesh_quantization_ExtraAttrTypes = {
6434
6570
  ]
6435
6571
  };
6436
6572
  var GLTFExporter = class {
6573
+ /**
6574
+ * Constructs a new glTF exporter.
6575
+ */
6437
6576
  constructor() {
6577
+ this.textureUtils = null;
6438
6578
  this.pluginCallbacks = [];
6439
6579
  this.register(function(writer) {
6440
6580
  return new GLTFLightExtension(writer);
@@ -6457,6 +6597,9 @@ var GLTFExporter = class {
6457
6597
  this.register(function(writer) {
6458
6598
  return new GLTFMaterialsClearcoatExtension(writer);
6459
6599
  });
6600
+ this.register(function(writer) {
6601
+ return new GLTFMaterialsDispersionExtension(writer);
6602
+ });
6460
6603
  this.register(function(writer) {
6461
6604
  return new GLTFMaterialsIridescenceExtension(writer);
6462
6605
  });
@@ -6469,16 +6612,33 @@ var GLTFExporter = class {
6469
6612
  this.register(function(writer) {
6470
6613
  return new GLTFMaterialsEmissiveStrengthExtension(writer);
6471
6614
  });
6615
+ this.register(function(writer) {
6616
+ return new GLTFMaterialsBumpExtension(writer);
6617
+ });
6472
6618
  this.register(function(writer) {
6473
6619
  return new GLTFMeshGpuInstancing(writer);
6474
6620
  });
6475
6621
  }
6622
+ /**
6623
+ * Registers a plugin callback. This API is internally used to implement the various
6624
+ * glTF extensions but can also used by third-party code to add additional logic
6625
+ * to the exporter.
6626
+ *
6627
+ * @param {function(writer:GLTFWriter)} callback - The callback function to register.
6628
+ * @return {GLTFExporter} A reference to this exporter.
6629
+ */
6476
6630
  register(callback) {
6477
6631
  if (this.pluginCallbacks.indexOf(callback) === -1) {
6478
6632
  this.pluginCallbacks.push(callback);
6479
6633
  }
6480
6634
  return this;
6481
6635
  }
6636
+ /**
6637
+ * Unregisters a plugin callback.
6638
+ *
6639
+ * @param {Function} callback - The callback function to unregister.
6640
+ * @return {GLTFExporter} A reference to this exporter.
6641
+ */
6482
6642
  unregister(callback) {
6483
6643
  if (this.pluginCallbacks.indexOf(callback) !== -1) {
6484
6644
  this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(callback), 1);
@@ -6486,11 +6646,25 @@ var GLTFExporter = class {
6486
6646
  return this;
6487
6647
  }
6488
6648
  /**
6489
- * Parse scenes and generate GLTF output
6490
- * @param {Scene or [THREE.Scenes]} input Scene or Array of THREE.Scenes
6491
- * @param {Function} onDone Callback on completed
6492
- * @param {Function} onError Callback on errors
6493
- * @param {Object} options options
6649
+ * Sets the texture utils for this exporter. Only relevant when compressed textures have to be exported.
6650
+ *
6651
+ * Depending on whether you use {@link WebGLRenderer} or {@link WebGPURenderer}, you must inject the
6652
+ * corresponding texture utils {@link module:WebGLTextureUtils} or {@link module:WebGPUTextureUtils}.
6653
+ *
6654
+ * @param {WebGLTextureUtils|WebGPUTextureUtils} utils - The texture utils.
6655
+ * @return {GLTFExporter} A reference to this exporter.
6656
+ */
6657
+ setTextureUtils(utils) {
6658
+ this.textureUtils = utils;
6659
+ return this;
6660
+ }
6661
+ /**
6662
+ * Parses the given scenes and generates the glTF output.
6663
+ *
6664
+ * @param {Scene|Array<Scene>} input - A scene or an array of scenes.
6665
+ * @param {GLTFExporter~OnDone} onDone - A callback function that is executed when the export has finished.
6666
+ * @param {GLTFExporter~OnError} onError - A callback function that is executed when an error happens.
6667
+ * @param {GLTFExporter~Options} options - options
6494
6668
  */
6495
6669
  parse(input, onDone, onError, options) {
6496
6670
  const writer = new GLTFWriter();
@@ -6499,8 +6673,16 @@ var GLTFExporter = class {
6499
6673
  plugins.push(this.pluginCallbacks[i](writer));
6500
6674
  }
6501
6675
  writer.setPlugins(plugins);
6502
- writer.write(input, onDone, options).catch(onError);
6676
+ writer.setTextureUtils(this.textureUtils);
6677
+ writer.writeAsync(input, onDone, options).catch(onError);
6503
6678
  }
6679
+ /**
6680
+ * Async version of {@link GLTFExporter#parse}.
6681
+ *
6682
+ * @param {Scene|Array<Scene>} input - A scene or an array of scenes.
6683
+ * @param {GLTFExporter~Options} options - options.
6684
+ * @return {Promise<ArrayBuffer|string>} A Promise that resolved with the exported glTF data.
6685
+ */
6504
6686
  parseAsync(input, options) {
6505
6687
  const scope = this;
6506
6688
  return new Promise(function(resolve, reject) {
@@ -6537,22 +6719,22 @@ var WEBGL_CONSTANTS = {
6537
6719
  };
6538
6720
  var KHR_MESH_QUANTIZATION = "KHR_mesh_quantization";
6539
6721
  var THREE_TO_WEBGL = {};
6540
- THREE_TO_WEBGL[import_three19.NearestFilter] = WEBGL_CONSTANTS.NEAREST;
6541
- THREE_TO_WEBGL[import_three19.NearestMipmapNearestFilter] = WEBGL_CONSTANTS.NEAREST_MIPMAP_NEAREST;
6542
- THREE_TO_WEBGL[import_three19.NearestMipmapLinearFilter] = WEBGL_CONSTANTS.NEAREST_MIPMAP_LINEAR;
6543
- THREE_TO_WEBGL[import_three19.LinearFilter] = WEBGL_CONSTANTS.LINEAR;
6544
- THREE_TO_WEBGL[import_three19.LinearMipmapNearestFilter] = WEBGL_CONSTANTS.LINEAR_MIPMAP_NEAREST;
6545
- THREE_TO_WEBGL[import_three19.LinearMipmapLinearFilter] = WEBGL_CONSTANTS.LINEAR_MIPMAP_LINEAR;
6546
- THREE_TO_WEBGL[import_three19.ClampToEdgeWrapping] = WEBGL_CONSTANTS.CLAMP_TO_EDGE;
6547
- THREE_TO_WEBGL[import_three19.RepeatWrapping] = WEBGL_CONSTANTS.REPEAT;
6548
- THREE_TO_WEBGL[import_three19.MirroredRepeatWrapping] = WEBGL_CONSTANTS.MIRRORED_REPEAT;
6722
+ THREE_TO_WEBGL[import_three18.NearestFilter] = WEBGL_CONSTANTS.NEAREST;
6723
+ THREE_TO_WEBGL[import_three18.NearestMipmapNearestFilter] = WEBGL_CONSTANTS.NEAREST_MIPMAP_NEAREST;
6724
+ THREE_TO_WEBGL[import_three18.NearestMipmapLinearFilter] = WEBGL_CONSTANTS.NEAREST_MIPMAP_LINEAR;
6725
+ THREE_TO_WEBGL[import_three18.LinearFilter] = WEBGL_CONSTANTS.LINEAR;
6726
+ THREE_TO_WEBGL[import_three18.LinearMipmapNearestFilter] = WEBGL_CONSTANTS.LINEAR_MIPMAP_NEAREST;
6727
+ THREE_TO_WEBGL[import_three18.LinearMipmapLinearFilter] = WEBGL_CONSTANTS.LINEAR_MIPMAP_LINEAR;
6728
+ THREE_TO_WEBGL[import_three18.ClampToEdgeWrapping] = WEBGL_CONSTANTS.CLAMP_TO_EDGE;
6729
+ THREE_TO_WEBGL[import_three18.RepeatWrapping] = WEBGL_CONSTANTS.REPEAT;
6730
+ THREE_TO_WEBGL[import_three18.MirroredRepeatWrapping] = WEBGL_CONSTANTS.MIRRORED_REPEAT;
6549
6731
  var PATH_PROPERTIES = {
6550
6732
  scale: "scale",
6551
6733
  position: "translation",
6552
6734
  quaternion: "rotation",
6553
6735
  morphTargetInfluences: "weights"
6554
6736
  };
6555
- var DEFAULT_SPECULAR_COLOR = new import_three19.Color();
6737
+ var DEFAULT_SPECULAR_COLOR = new import_three18.Color();
6556
6738
  var GLB_HEADER_BYTES = 12;
6557
6739
  var GLB_HEADER_MAGIC = 1179937895;
6558
6740
  var GLB_VERSION = 2;
@@ -6586,7 +6768,7 @@ function getMinMax(attribute, start, count) {
6586
6768
  else if (a === 2) value = attribute.getZ(i);
6587
6769
  else if (a === 3) value = attribute.getW(i);
6588
6770
  if (attribute.normalized === true) {
6589
- value = import_three19.MathUtils.normalize(value, attribute.array);
6771
+ value = import_three18.MathUtils.normalize(value, attribute.array);
6590
6772
  }
6591
6773
  }
6592
6774
  output.min[a] = Math.min(output.min[a], value);
@@ -6619,19 +6801,20 @@ function getCanvas() {
6619
6801
  return document.createElement("canvas");
6620
6802
  }
6621
6803
  function getToBlobPromise(canvas, mimeType) {
6622
- if (canvas.toBlob !== void 0) {
6804
+ if (typeof OffscreenCanvas !== "undefined" && canvas instanceof OffscreenCanvas) {
6805
+ let quality;
6806
+ if (mimeType === "image/jpeg") {
6807
+ quality = 0.92;
6808
+ } else if (mimeType === "image/webp") {
6809
+ quality = 0.8;
6810
+ }
6811
+ return canvas.convertToBlob({
6812
+ type: mimeType,
6813
+ quality
6814
+ });
6815
+ } else {
6623
6816
  return new Promise((resolve) => canvas.toBlob(resolve, mimeType));
6624
6817
  }
6625
- let quality;
6626
- if (mimeType === "image/jpeg") {
6627
- quality = 0.92;
6628
- } else if (mimeType === "image/webp") {
6629
- quality = 0.8;
6630
- }
6631
- return canvas.convertToBlob({
6632
- type: mimeType,
6633
- quality
6634
- });
6635
6818
  }
6636
6819
  var GLTFWriter = class {
6637
6820
  constructor() {
@@ -6650,7 +6833,7 @@ var GLTFWriter = class {
6650
6833
  this.json = {
6651
6834
  asset: {
6652
6835
  version: "2.0",
6653
- generator: "THREE.GLTFExporter"
6836
+ generator: "THREE.GLTFExporter r" + import_three18.REVISION
6654
6837
  }
6655
6838
  };
6656
6839
  this.cache = {
@@ -6659,19 +6842,25 @@ var GLTFWriter = class {
6659
6842
  attributesNormalized: /* @__PURE__ */ new Map(),
6660
6843
  materials: /* @__PURE__ */ new Map(),
6661
6844
  textures: /* @__PURE__ */ new Map(),
6662
- images: /* @__PURE__ */ new Map()
6845
+ images: /* @__PURE__ */ new Map(),
6846
+ normalMaps: /* @__PURE__ */ new Map()
6663
6847
  };
6848
+ this.textureUtils = null;
6664
6849
  }
6665
6850
  setPlugins(plugins) {
6666
6851
  this.plugins = plugins;
6667
6852
  }
6853
+ setTextureUtils(utils) {
6854
+ this.textureUtils = utils;
6855
+ }
6668
6856
  /**
6669
6857
  * Parse scenes and generate GLTF output
6670
- * @param {Scene or [THREE.Scenes]} input Scene or Array of THREE.Scenes
6671
- * @param {Function} onDone Callback on completed
6672
- * @param {Object} options options
6858
+ *
6859
+ * @param {Scene|Array<Scene>} input Scene or Array of THREE.Scenes
6860
+ * @param {Function} onDone Callback on completed
6861
+ * @param {Object} options options
6673
6862
  */
6674
- async write(input, onDone, options = {}) {
6863
+ async writeAsync(input, onDone, options = {}) {
6675
6864
  this.options = Object.assign({
6676
6865
  // default options
6677
6866
  binary: false,
@@ -6679,12 +6868,13 @@ var GLTFWriter = class {
6679
6868
  onlyVisible: true,
6680
6869
  maxTextureSize: Infinity,
6681
6870
  animations: [],
6682
- includeCustomExtensions: false
6871
+ includeCustomExtensions: false,
6872
+ copyright: null
6683
6873
  }, options);
6684
6874
  if (this.options.animations.length > 0) {
6685
6875
  this.options.trs = true;
6686
6876
  }
6687
- this.processInput(input);
6877
+ await this.processInputAsync(input);
6688
6878
  await Promise.all(this.pending);
6689
6879
  const writer = this;
6690
6880
  const buffers = writer.buffers;
@@ -6698,6 +6888,7 @@ var GLTFWriter = class {
6698
6888
  if (extensionsUsedList.length > 0) json.extensionsUsed = extensionsUsedList;
6699
6889
  if (extensionsRequiredList.length > 0) json.extensionsRequired = extensionsRequiredList;
6700
6890
  if (json.buffers && json.buffers.length > 0) json.buffers[0].byteLength = blob.size;
6891
+ if (options.copyright) json.asset.copyright = options.copyright;
6701
6892
  if (options.binary === true) {
6702
6893
  const reader = new FileReader();
6703
6894
  reader.readAsArrayBuffer(blob);
@@ -6746,7 +6937,7 @@ var GLTFWriter = class {
6746
6937
  /**
6747
6938
  * Serializes a userData.
6748
6939
  *
6749
- * @param {THREE.Object3D|THREE.Material} object
6940
+ * @param {THREE.Object3D|THREE.Material|THREE.BufferGeometry|THREE.AnimationClip} object
6750
6941
  * @param {Object} objectDef
6751
6942
  */
6752
6943
  serializeUserData(object, objectDef) {
@@ -6770,8 +6961,10 @@ var GLTFWriter = class {
6770
6961
  }
6771
6962
  /**
6772
6963
  * Returns ids for buffer attributes.
6773
- * @param {Object} object
6774
- * @return {Integer}
6964
+ *
6965
+ * @param {Object} attribute
6966
+ * @param {boolean} [isRelativeCopy=false]
6967
+ * @return {number} An integer
6775
6968
  */
6776
6969
  getUID(attribute, isRelativeCopy = false) {
6777
6970
  if (this.uids.has(attribute) === false) {
@@ -6787,12 +6980,12 @@ var GLTFWriter = class {
6787
6980
  * Checks if normal attribute values are normalized.
6788
6981
  *
6789
6982
  * @param {BufferAttribute} normal
6790
- * @returns {Boolean}
6983
+ * @returns {boolean}
6791
6984
  */
6792
6985
  isNormalizedNormalAttribute(normal) {
6793
6986
  const cache = this.cache;
6794
6987
  if (cache.attributesNormalized.has(normal)) return false;
6795
- const v = new import_three19.Vector3();
6988
+ const v = new import_three18.Vector3();
6796
6989
  for (let i = 0, il = normal.count; i < il; i++) {
6797
6990
  if (Math.abs(v.fromBufferAttribute(normal, i).length() - 1) > 5e-4) return false;
6798
6991
  }
@@ -6809,7 +7002,7 @@ var GLTFWriter = class {
6809
7002
  const cache = this.cache;
6810
7003
  if (cache.attributesNormalized.has(normal)) return cache.attributesNormalized.get(normal);
6811
7004
  const attribute = normal.clone();
6812
- const v = new import_three19.Vector3();
7005
+ const v = new import_three18.Vector3();
6813
7006
  for (let i = 0, il = attribute.count; i < il; i++) {
6814
7007
  v.fromBufferAttribute(attribute, i);
6815
7008
  if (v.x === 0 && v.y === 0 && v.z === 0) {
@@ -6850,10 +7043,10 @@ var GLTFWriter = class {
6850
7043
  this.extensionsUsed["KHR_texture_transform"] = true;
6851
7044
  }
6852
7045
  }
6853
- buildMetalRoughTexture(metalnessMap, roughnessMap) {
7046
+ async buildMetalRoughTextureAsync(metalnessMap, roughnessMap) {
6854
7047
  if (metalnessMap === roughnessMap) return metalnessMap;
6855
7048
  function getEncodingConversion(map) {
6856
- if (map.colorSpace === import_three19.SRGBColorSpace) {
7049
+ if (map.colorSpace === import_three18.SRGBColorSpace) {
6857
7050
  return function SRGBToLinear(c) {
6858
7051
  return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
6859
7052
  };
@@ -6862,12 +7055,11 @@ var GLTFWriter = class {
6862
7055
  return c;
6863
7056
  };
6864
7057
  }
6865
- console.warn("THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures.");
6866
- if (metalnessMap instanceof import_three19.CompressedTexture) {
6867
- metalnessMap = decompress(metalnessMap);
7058
+ if (metalnessMap instanceof import_three18.CompressedTexture) {
7059
+ metalnessMap = await this.decompressTextureAsync(metalnessMap);
6868
7060
  }
6869
- if (roughnessMap instanceof import_three19.CompressedTexture) {
6870
- roughnessMap = decompress(roughnessMap);
7061
+ if (roughnessMap instanceof import_three18.CompressedTexture) {
7062
+ roughnessMap = await this.decompressTextureAsync(roughnessMap);
6871
7063
  }
6872
7064
  const metalness = metalnessMap ? metalnessMap.image : null;
6873
7065
  const roughness = roughnessMap ? roughnessMap.image : null;
@@ -6876,7 +7068,9 @@ var GLTFWriter = class {
6876
7068
  const canvas = getCanvas();
6877
7069
  canvas.width = width;
6878
7070
  canvas.height = height;
6879
- const context = canvas.getContext("2d");
7071
+ const context = canvas.getContext("2d", {
7072
+ willReadFrequently: true
7073
+ });
6880
7074
  context.fillStyle = "#00ffff";
6881
7075
  context.fillRect(0, 0, width, height);
6882
7076
  const composite = context.getImageData(0, 0, width, height);
@@ -6899,18 +7093,60 @@ var GLTFWriter = class {
6899
7093
  context.putImageData(composite, 0, 0);
6900
7094
  const reference = metalnessMap || roughnessMap;
6901
7095
  const texture = reference.clone();
6902
- texture.source = new import_three19.Source(canvas);
6903
- texture.colorSpace = import_three19.NoColorSpace;
7096
+ texture.source = new import_three18.TextureSource(canvas);
7097
+ texture.colorSpace = import_three18.NoColorSpace;
6904
7098
  texture.channel = (metalnessMap || roughnessMap).channel;
6905
7099
  if (metalnessMap && roughnessMap && metalnessMap.channel !== roughnessMap.channel) {
6906
7100
  console.warn("THREE.GLTFExporter: UV channels for metalnessMap and roughnessMap textures must match.");
6907
7101
  }
7102
+ console.warn("THREE.GLTFExporter: Merged metalnessMap and roughnessMap textures.");
6908
7103
  return texture;
6909
7104
  }
7105
+ /**
7106
+ * Builds a copy of the given normal map with the red and/or green channels
7107
+ * inverted (`color = 255 - color`). This is used to bake the sign of
7108
+ * `material.normalScale` and the tangent-space convention into the texture,
7109
+ * since glTF only supports OpenGL-style normal maps with a univariate,
7110
+ * positive scale.
7111
+ *
7112
+ * @param {THREE.Texture} normalMap The source normal map.
7113
+ * @param {boolean} flipX Whether to invert the red channel (normal X).
7114
+ * @param {boolean} flipY Whether to invert the green channel (normal Y).
7115
+ * @return {Promise<THREE.Texture>} The derived normal map texture.
7116
+ */
7117
+ async buildNormalMapTextureAsync(normalMap, flipX, flipY) {
7118
+ if (normalMap instanceof import_three18.CompressedTexture) {
7119
+ normalMap = await this.decompressTextureAsync(normalMap);
7120
+ }
7121
+ const image = normalMap.image;
7122
+ const canvas = getCanvas();
7123
+ canvas.width = image.width;
7124
+ canvas.height = image.height;
7125
+ const context = canvas.getContext("2d", {
7126
+ willReadFrequently: true
7127
+ });
7128
+ context.drawImage(image, 0, 0, canvas.width, canvas.height);
7129
+ const imageData = context.getImageData(0, 0, canvas.width, canvas.height);
7130
+ const data = imageData.data;
7131
+ for (let i = 0; i < data.length; i += 4) {
7132
+ if (flipX) data[i + 0] = 255 - data[i + 0];
7133
+ if (flipY) data[i + 1] = 255 - data[i + 1];
7134
+ }
7135
+ context.putImageData(imageData, 0, 0);
7136
+ const texture = normalMap.clone();
7137
+ texture.source = new import_three18.TextureSource(canvas);
7138
+ return texture;
7139
+ }
7140
+ async decompressTextureAsync(texture, maxTextureSize = Infinity) {
7141
+ if (this.textureUtils === null) {
7142
+ throw new Error("THREE.GLTFExporter: setTextureUtils() must be called to process compressed textures.");
7143
+ }
7144
+ return await this.textureUtils.decompress(texture, maxTextureSize);
7145
+ }
6910
7146
  /**
6911
7147
  * Process a buffer to append to the default one.
6912
- * @param {ArrayBuffer} buffer
6913
- * @return {Integer}
7148
+ * @param {ArrayBuffer} buffer
7149
+ * @return {0}
6914
7150
  */
6915
7151
  processBuffer(buffer) {
6916
7152
  const json = this.json;
@@ -6921,11 +7157,11 @@ var GLTFWriter = class {
6921
7157
  }
6922
7158
  /**
6923
7159
  * Process and generate a BufferView
6924
- * @param {BufferAttribute} attribute
6925
- * @param {number} componentType
6926
- * @param {number} start
6927
- * @param {number} count
6928
- * @param {number} target (Optional) Target usage of the BufferView
7160
+ * @param {BufferAttribute} attribute
7161
+ * @param {number} componentType
7162
+ * @param {number} start
7163
+ * @param {number} count
7164
+ * @param {number} [target] Target usage of the BufferView
6929
7165
  * @return {Object}
6930
7166
  */
6931
7167
  processBufferView(attribute, componentType, start, count, target) {
@@ -6944,7 +7180,11 @@ var GLTFWriter = class {
6944
7180
  default:
6945
7181
  componentSize = 4;
6946
7182
  }
6947
- const byteLength = getPaddedBufferSize(count * attribute.itemSize * componentSize);
7183
+ let byteStride = attribute.itemSize * componentSize;
7184
+ if (target === WEBGL_CONSTANTS.ARRAY_BUFFER) {
7185
+ byteStride = Math.ceil(byteStride / 4) * 4;
7186
+ }
7187
+ const byteLength = getPaddedBufferSize(count * byteStride);
6948
7188
  const dataView = new DataView(new ArrayBuffer(byteLength));
6949
7189
  let offset = 0;
6950
7190
  for (let i = start; i < start + count; i++) {
@@ -6958,7 +7198,7 @@ var GLTFWriter = class {
6958
7198
  else if (a === 2) value = attribute.getZ(i);
6959
7199
  else if (a === 3) value = attribute.getW(i);
6960
7200
  if (attribute.normalized === true) {
6961
- value = import_three19.MathUtils.normalize(value, attribute.array);
7201
+ value = import_three18.MathUtils.normalize(value, attribute.array);
6962
7202
  }
6963
7203
  }
6964
7204
  if (componentType === WEBGL_CONSTANTS.FLOAT) {
@@ -6978,6 +7218,9 @@ var GLTFWriter = class {
6978
7218
  }
6979
7219
  offset += componentSize;
6980
7220
  }
7221
+ if (offset % byteStride !== 0) {
7222
+ offset += byteStride - offset % byteStride;
7223
+ }
6981
7224
  }
6982
7225
  const bufferViewDef = {
6983
7226
  buffer: this.processBuffer(dataView.buffer),
@@ -6986,7 +7229,7 @@ var GLTFWriter = class {
6986
7229
  };
6987
7230
  if (target !== void 0) bufferViewDef.target = target;
6988
7231
  if (target === WEBGL_CONSTANTS.ARRAY_BUFFER) {
6989
- bufferViewDef.byteStride = attribute.itemSize * componentSize;
7232
+ bufferViewDef.byteStride = byteStride;
6990
7233
  }
6991
7234
  this.byteOffset += byteLength;
6992
7235
  json.bufferViews.push(bufferViewDef);
@@ -6999,7 +7242,7 @@ var GLTFWriter = class {
6999
7242
  /**
7000
7243
  * Process and generate a BufferView from an image Blob.
7001
7244
  * @param {Blob} blob
7002
- * @return {Promise<Integer>}
7245
+ * @return {Promise<number>} An integer
7003
7246
  */
7004
7247
  processBufferViewImage(blob) {
7005
7248
  const writer = this;
@@ -7022,11 +7265,11 @@ var GLTFWriter = class {
7022
7265
  }
7023
7266
  /**
7024
7267
  * Process attribute to generate an accessor
7025
- * @param {BufferAttribute} attribute Attribute to process
7026
- * @param {THREE.BufferGeometry} geometry (Optional) Geometry used for truncated draw range
7027
- * @param {Integer} start (Optional)
7028
- * @param {Integer} count (Optional)
7029
- * @return {Integer|null} Index of the processed accessor on the "accessors" array
7268
+ * @param {BufferAttribute} attribute Attribute to process
7269
+ * @param {?BufferGeometry} [geometry] Geometry used for truncated draw range
7270
+ * @param {number} [start=0]
7271
+ * @param {number} [count=Infinity]
7272
+ * @return {?number} Index of the processed accessor on the "accessors" array
7030
7273
  */
7031
7274
  processAccessor(attribute, geometry, start, count) {
7032
7275
  const json = this.json;
@@ -7080,11 +7323,11 @@ var GLTFWriter = class {
7080
7323
  }
7081
7324
  /**
7082
7325
  * Process image
7083
- * @param {Image} image to process
7084
- * @param {Integer} format of the image (RGBAFormat)
7085
- * @param {Boolean} flipY before writing out the image
7086
- * @param {String} mimeType export format
7087
- * @return {Integer} Index of the processed texture in the "images" array
7326
+ * @param {Image} image to process
7327
+ * @param {number} format Identifier of the format (RGBAFormat)
7328
+ * @param {boolean} flipY before writing out the image
7329
+ * @param {string} mimeType export format
7330
+ * @return {number} Index of the processed texture in the "images" array
7088
7331
  */
7089
7332
  processImage(image, format, flipY, mimeType = "image/png") {
7090
7333
  if (image !== null) {
@@ -7102,13 +7345,15 @@ var GLTFWriter = class {
7102
7345
  const canvas = getCanvas();
7103
7346
  canvas.width = Math.min(image.width, options.maxTextureSize);
7104
7347
  canvas.height = Math.min(image.height, options.maxTextureSize);
7105
- const ctx = canvas.getContext("2d");
7348
+ const ctx = canvas.getContext("2d", {
7349
+ willReadFrequently: true
7350
+ });
7106
7351
  if (flipY === true) {
7107
7352
  ctx.translate(0, canvas.height);
7108
7353
  ctx.scale(1, -1);
7109
7354
  }
7110
7355
  if (image.data !== void 0) {
7111
- if (format !== import_three19.RGBAFormat) {
7356
+ if (format !== import_three18.RGBAFormat) {
7112
7357
  console.error("GLTFExporter: Only RGBAFormat is supported.", format);
7113
7358
  }
7114
7359
  if (image.width > options.maxTextureSize || image.height > options.maxTextureSize) {
@@ -7123,7 +7368,11 @@ var GLTFWriter = class {
7123
7368
  }
7124
7369
  ctx.putImageData(new ImageData(data, image.width, image.height), 0, 0);
7125
7370
  } else {
7126
- ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
7371
+ 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) {
7372
+ ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
7373
+ } else {
7374
+ throw new Error("THREE.GLTFExporter: Invalid image type. Use HTMLImageElement, HTMLCanvasElement, ImageBitmap or OffscreenCanvas.");
7375
+ }
7127
7376
  }
7128
7377
  if (options.binary === true) {
7129
7378
  pending.push(
@@ -7132,15 +7381,7 @@ var GLTFWriter = class {
7132
7381
  })
7133
7382
  );
7134
7383
  } else {
7135
- if (canvas.toDataURL !== void 0) {
7136
- imageDef.uri = canvas.toDataURL(mimeType);
7137
- } else {
7138
- pending.push(
7139
- getToBlobPromise(canvas, mimeType).then((blob) => new FileReader().readAsDataURL(blob)).then((dataURL) => {
7140
- imageDef.uri = dataURL;
7141
- })
7142
- );
7143
- }
7384
+ imageDef.uri = import_three18.ImageUtils.getDataURL(canvas, mimeType);
7144
7385
  }
7145
7386
  const index = json.images.push(imageDef) - 1;
7146
7387
  cachedImages[key] = index;
@@ -7151,8 +7392,8 @@ var GLTFWriter = class {
7151
7392
  }
7152
7393
  /**
7153
7394
  * Process sampler
7154
- * @param {Texture} map Texture to process
7155
- * @return {Integer} Index of the processed texture in the "samplers" array
7395
+ * @param {Texture} map Texture to process
7396
+ * @return {number} Index of the processed texture in the "samplers" array
7156
7397
  */
7157
7398
  processSampler(map) {
7158
7399
  const json = this.json;
@@ -7167,28 +7408,37 @@ var GLTFWriter = class {
7167
7408
  }
7168
7409
  /**
7169
7410
  * Process texture
7170
- * @param {Texture} map Map to process
7171
- * @return {Integer} Index of the processed texture in the "textures" array
7411
+ * @param {Texture} map Map to process
7412
+ * @return {Promise<number>} Index of the processed texture in the "textures" array
7172
7413
  */
7173
- processTexture(map) {
7414
+ async processTextureAsync(map) {
7174
7415
  const writer = this;
7175
7416
  const options = writer.options;
7176
7417
  const cache = this.cache;
7177
7418
  const json = this.json;
7178
7419
  if (cache.textures.has(map)) return cache.textures.get(map);
7179
7420
  if (!json.textures) json.textures = [];
7180
- if (map instanceof import_three19.CompressedTexture) {
7181
- map = decompress(map, options.maxTextureSize);
7421
+ if (map instanceof import_three18.CompressedTexture) {
7422
+ map = await this.decompressTextureAsync(map, options.maxTextureSize);
7182
7423
  }
7183
- let mimeType = map.userData.mimeType;
7184
- if (mimeType === "image/webp") mimeType = "image/png";
7424
+ const mimeType = map.userData.mimeType;
7425
+ const imageIndex = this.processImage(map.image, map.format, map.flipY, mimeType);
7185
7426
  const textureDef = {
7186
- sampler: this.processSampler(map),
7187
- source: this.processImage(map.image, map.format, map.flipY, mimeType)
7427
+ sampler: this.processSampler(map)
7188
7428
  };
7429
+ if (mimeType === "image/webp") {
7430
+ textureDef.extensions = textureDef.extensions || {};
7431
+ textureDef.extensions["EXT_texture_webp"] = {
7432
+ source: imageIndex
7433
+ };
7434
+ this.extensionsUsed["EXT_texture_webp"] = true;
7435
+ this.extensionsRequired["EXT_texture_webp"] = true;
7436
+ } else {
7437
+ textureDef.source = imageIndex;
7438
+ }
7189
7439
  if (map.name) textureDef.name = map.name;
7190
- this._invokeAll(function(ext) {
7191
- ext.writeTexture && ext.writeTexture(map, textureDef);
7440
+ await this._invokeAllAsync(async function(ext) {
7441
+ ext.writeTexture && await ext.writeTexture(map, textureDef);
7192
7442
  });
7193
7443
  const index = json.textures.push(textureDef) - 1;
7194
7444
  cache.textures.set(map, index);
@@ -7196,13 +7446,16 @@ var GLTFWriter = class {
7196
7446
  }
7197
7447
  /**
7198
7448
  * Process material
7199
- * @param {THREE.Material} material Material to process
7200
- * @return {Integer|null} Index of the processed material in the "materials" array
7449
+ * @param {THREE.Material} material Material to process
7450
+ * @param {THREE.BufferGeometry} [geometry] Geometry the material is used with.
7451
+ * @return {Promise<?number>} Index of the processed material in the "materials" array
7201
7452
  */
7202
- processMaterial(material) {
7453
+ async processMaterialAsync(material, geometry) {
7203
7454
  const cache = this.cache;
7204
7455
  const json = this.json;
7205
- if (cache.materials.has(material)) return cache.materials.get(material);
7456
+ const hasTangent = geometry !== void 0 && geometry.hasAttribute("tangent");
7457
+ const cacheKey = material.normalMap ? material.uuid + ":" + hasTangent : material.uuid;
7458
+ if (cache.materials.has(cacheKey)) return cache.materials.get(cacheKey);
7206
7459
  if (material.isShaderMaterial) {
7207
7460
  console.warn("GLTFExporter: THREE.ShaderMaterial not supported.");
7208
7461
  return null;
@@ -7220,21 +7473,21 @@ var GLTFWriter = class {
7220
7473
  materialDef.pbrMetallicRoughness.metallicFactor = material.metalness;
7221
7474
  materialDef.pbrMetallicRoughness.roughnessFactor = material.roughness;
7222
7475
  } else {
7223
- materialDef.pbrMetallicRoughness.metallicFactor = 0.5;
7224
- materialDef.pbrMetallicRoughness.roughnessFactor = 0.5;
7476
+ materialDef.pbrMetallicRoughness.metallicFactor = 0;
7477
+ materialDef.pbrMetallicRoughness.roughnessFactor = 1;
7225
7478
  }
7226
7479
  if (material.metalnessMap || material.roughnessMap) {
7227
- const metalRoughTexture = this.buildMetalRoughTexture(material.metalnessMap, material.roughnessMap);
7480
+ const metalRoughTexture = await this.buildMetalRoughTextureAsync(material.metalnessMap, material.roughnessMap);
7228
7481
  const metalRoughMapDef = {
7229
- index: this.processTexture(metalRoughTexture),
7230
- channel: metalRoughTexture.channel
7482
+ index: await this.processTextureAsync(metalRoughTexture),
7483
+ texCoord: metalRoughTexture.channel
7231
7484
  };
7232
7485
  this.applyTextureTransform(metalRoughMapDef, metalRoughTexture);
7233
7486
  materialDef.pbrMetallicRoughness.metallicRoughnessTexture = metalRoughMapDef;
7234
7487
  }
7235
7488
  if (material.map) {
7236
7489
  const baseColorMapDef = {
7237
- index: this.processTexture(material.map),
7490
+ index: await this.processTextureAsync(material.map),
7238
7491
  texCoord: material.map.channel
7239
7492
  };
7240
7493
  this.applyTextureTransform(baseColorMapDef, material.map);
@@ -7248,7 +7501,7 @@ var GLTFWriter = class {
7248
7501
  }
7249
7502
  if (material.emissiveMap) {
7250
7503
  const emissiveMapDef = {
7251
- index: this.processTexture(material.emissiveMap),
7504
+ index: await this.processTextureAsync(material.emissiveMap),
7252
7505
  texCoord: material.emissiveMap.channel
7253
7506
  };
7254
7507
  this.applyTextureTransform(emissiveMapDef, material.emissiveMap);
@@ -7256,19 +7509,32 @@ var GLTFWriter = class {
7256
7509
  }
7257
7510
  }
7258
7511
  if (material.normalMap) {
7512
+ const normalScale = material.normalScale;
7513
+ const flipX = normalScale.x < 0;
7514
+ const flipY = hasTangent ? normalScale.y < 0 : normalScale.y > 0;
7515
+ let normalMap = material.normalMap;
7516
+ if (flipX || flipY) {
7517
+ if (cache.normalMaps.has(material.normalMap) === false) cache.normalMaps.set(material.normalMap, {});
7518
+ const cachedVariants = cache.normalMaps.get(material.normalMap);
7519
+ const cacheKey2 = `${flipX}:${flipY}`;
7520
+ if (cachedVariants[cacheKey2] === void 0) {
7521
+ cachedVariants[cacheKey2] = await this.buildNormalMapTextureAsync(material.normalMap, flipX, flipY);
7522
+ }
7523
+ normalMap = cachedVariants[cacheKey2];
7524
+ }
7259
7525
  const normalMapDef = {
7260
- index: this.processTexture(material.normalMap),
7526
+ index: await this.processTextureAsync(normalMap),
7261
7527
  texCoord: material.normalMap.channel
7262
7528
  };
7263
- if (material.normalScale && material.normalScale.x !== 1) {
7264
- normalMapDef.scale = material.normalScale.x;
7529
+ if (Math.abs(normalScale.x) !== 1) {
7530
+ normalMapDef.scale = Math.abs(normalScale.x);
7265
7531
  }
7266
7532
  this.applyTextureTransform(normalMapDef, material.normalMap);
7267
7533
  materialDef.normalTexture = normalMapDef;
7268
7534
  }
7269
7535
  if (material.aoMap) {
7270
7536
  const occlusionMapDef = {
7271
- index: this.processTexture(material.aoMap),
7537
+ index: await this.processTextureAsync(material.aoMap),
7272
7538
  texCoord: material.aoMap.channel
7273
7539
  };
7274
7540
  if (material.aoMapIntensity !== 1) {
@@ -7285,22 +7551,22 @@ var GLTFWriter = class {
7285
7551
  materialDef.alphaCutoff = material.alphaTest;
7286
7552
  }
7287
7553
  }
7288
- if (material.side === import_three19.DoubleSide) materialDef.doubleSided = true;
7554
+ if (material.side === import_three18.DoubleSide) materialDef.doubleSided = true;
7289
7555
  if (material.name !== "") materialDef.name = material.name;
7290
7556
  this.serializeUserData(material, materialDef);
7291
- this._invokeAll(function(ext) {
7292
- ext.writeMaterial && ext.writeMaterial(material, materialDef);
7557
+ await this._invokeAllAsync(async function(ext) {
7558
+ ext.writeMaterialAsync && await ext.writeMaterialAsync(material, materialDef);
7293
7559
  });
7294
7560
  const index = json.materials.push(materialDef) - 1;
7295
- cache.materials.set(material, index);
7561
+ cache.materials.set(cacheKey, index);
7296
7562
  return index;
7297
7563
  }
7298
7564
  /**
7299
7565
  * Process mesh
7300
- * @param {THREE.Mesh} mesh Mesh to process
7301
- * @return {Integer|null} Index of the processed mesh in the "meshes" array
7566
+ * @param {THREE.Mesh} mesh Mesh to process
7567
+ * @return {Promise<?number>} Index of the processed mesh in the "meshes" array
7302
7568
  */
7303
- processMesh(mesh) {
7569
+ async processMeshAsync(mesh) {
7304
7570
  const cache = this.cache;
7305
7571
  const json = this.json;
7306
7572
  const meshCacheKeyParts = [mesh.geometry.uuid];
@@ -7350,7 +7616,7 @@ var GLTFWriter = class {
7350
7616
  const attribute = geometry.attributes[attributeName];
7351
7617
  attributeName = nameConversion[attributeName] || attributeName.toUpperCase();
7352
7618
  const validVertexAttributes = /^(POSITION|NORMAL|TANGENT|TEXCOORD_\d+|COLOR_\d+|JOINTS_\d+|WEIGHTS_\d+)$/;
7353
- if (!validVertexAttributes.test(attributeName)) attributeName = "_" + attributeName;
7619
+ if (!validVertexAttributes.test(attributeName) && !attributeName.startsWith("_")) attributeName = "_" + attributeName;
7354
7620
  if (cache.attributes.has(this.getUID(attribute))) {
7355
7621
  attributes[attributeName] = cache.attributes.get(this.getUID(attribute));
7356
7622
  continue;
@@ -7359,7 +7625,10 @@ var GLTFWriter = class {
7359
7625
  const array = attribute.array;
7360
7626
  if (attributeName === "JOINTS_0" && !(array instanceof Uint16Array) && !(array instanceof Uint8Array)) {
7361
7627
  console.warn('GLTFExporter: Attribute "skinIndex" converted to type UNSIGNED_SHORT.');
7362
- modifiedAttribute = new import_three19.BufferAttribute(new Uint16Array(array), attribute.itemSize, attribute.normalized);
7628
+ modifiedAttribute = GLTFExporter.Utils.toTypedBufferAttribute(attribute, Uint16Array);
7629
+ } else if ((array instanceof Uint32Array || array instanceof Int32Array) && !attributeName.startsWith("_")) {
7630
+ console.warn(`GLTFExporter: Attribute "${attributeName}" converted to type FLOAT.`);
7631
+ modifiedAttribute = GLTFExporter.Utils.toTypedBufferAttribute(attribute, Float32Array);
7363
7632
  }
7364
7633
  const accessor = this.processAccessor(modifiedAttribute || attribute, geometry);
7365
7634
  if (accessor !== null) {
@@ -7425,6 +7694,15 @@ var GLTFWriter = class {
7425
7694
  }
7426
7695
  const isMultiMaterial = Array.isArray(mesh.material);
7427
7696
  if (isMultiMaterial && geometry.groups.length === 0) return null;
7697
+ let didForceIndices = false;
7698
+ if (isMultiMaterial && geometry.index === null) {
7699
+ const indices = [];
7700
+ for (let i = 0, il = geometry.attributes.position.count; i < il; i++) {
7701
+ indices[i] = i;
7702
+ }
7703
+ geometry.setIndex(indices);
7704
+ didForceIndices = true;
7705
+ }
7428
7706
  const materials = isMultiMaterial ? mesh.material : [mesh.material];
7429
7707
  const groups = isMultiMaterial ? geometry.groups : [{ materialIndex: 0, start: void 0, count: void 0 }];
7430
7708
  for (let i = 0, il = groups.length; i < il; i++) {
@@ -7447,13 +7725,16 @@ var GLTFWriter = class {
7447
7725
  }
7448
7726
  if (primitive.indices === null) delete primitive.indices;
7449
7727
  }
7450
- const material = this.processMaterial(materials[groups[i].materialIndex]);
7728
+ const material = await this.processMaterialAsync(materials[groups[i].materialIndex], geometry);
7451
7729
  if (material !== null) primitive.material = material;
7452
7730
  primitives.push(primitive);
7453
7731
  }
7732
+ if (didForceIndices === true) {
7733
+ geometry.setIndex(null);
7734
+ }
7454
7735
  meshDef.primitives = primitives;
7455
7736
  if (!json.meshes) json.meshes = [];
7456
- this._invokeAll(function(ext) {
7737
+ await this._invokeAllAsync(function(ext) {
7457
7738
  ext.writeMesh && ext.writeMesh(mesh, meshDef);
7458
7739
  });
7459
7740
  const index = json.meshes.push(meshDef) - 1;
@@ -7499,8 +7780,8 @@ var GLTFWriter = class {
7499
7780
  }
7500
7781
  /**
7501
7782
  * Process camera
7502
- * @param {THREE.Camera} camera Camera to process
7503
- * @return {Integer} Index of the processed mesh in the "camera" array
7783
+ * @param {THREE.Camera} camera Camera to process
7784
+ * @return {number} Index of the processed mesh in the "camera" array
7504
7785
  */
7505
7786
  processCamera(camera) {
7506
7787
  const json = this.json;
@@ -7519,7 +7800,7 @@ var GLTFWriter = class {
7519
7800
  } else {
7520
7801
  cameraDef.perspective = {
7521
7802
  aspectRatio: camera.aspect,
7522
- yfov: import_three19.MathUtils.degToRad(camera.fov),
7803
+ yfov: import_three18.MathUtils.degToRad(camera.fov),
7523
7804
  zfar: camera.far <= 0 ? 1e-3 : camera.far,
7524
7805
  znear: camera.near < 0 ? 0 : camera.near
7525
7806
  };
@@ -7535,7 +7816,7 @@ var GLTFWriter = class {
7535
7816
  *
7536
7817
  * @param {THREE.AnimationClip} clip
7537
7818
  * @param {THREE.Object3D} root
7538
- * @return {number|null}
7819
+ * @return {?number}
7539
7820
  */
7540
7821
  processAnimation(clip, root) {
7541
7822
  const json = this.json;
@@ -7547,8 +7828,8 @@ var GLTFWriter = class {
7547
7828
  const samplers = [];
7548
7829
  for (let i = 0; i < tracks.length; ++i) {
7549
7830
  const track = tracks[i];
7550
- const trackBinding = import_three19.PropertyBinding.parseTrackName(track.name);
7551
- let trackNode = import_three19.PropertyBinding.findNode(root, trackBinding.nodeName);
7831
+ const trackBinding = import_three18.PropertyBinding.parseTrackName(track.name);
7832
+ let trackNode = import_three18.PropertyBinding.findNode(root, trackBinding.nodeName);
7552
7833
  const trackProperty = PATH_PROPERTIES[trackBinding.propertyName];
7553
7834
  if (trackBinding.objectName === "bones") {
7554
7835
  if (trackNode.isSkinnedMesh === true) {
@@ -7559,7 +7840,7 @@ var GLTFWriter = class {
7559
7840
  }
7560
7841
  if (!trackNode || !trackProperty) {
7561
7842
  console.warn('THREE.GLTFExporter: Could not export animation track "%s".', track.name);
7562
- return null;
7843
+ continue;
7563
7844
  }
7564
7845
  const inputItemSize = 1;
7565
7846
  let outputItemSize = track.values.length / track.times.length;
@@ -7570,14 +7851,14 @@ var GLTFWriter = class {
7570
7851
  if (track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline === true) {
7571
7852
  interpolation = "CUBICSPLINE";
7572
7853
  outputItemSize /= 3;
7573
- } else if (track.getInterpolation() === import_three19.InterpolateDiscrete) {
7854
+ } else if (track.getInterpolation() === import_three18.InterpolateDiscrete) {
7574
7855
  interpolation = "STEP";
7575
7856
  } else {
7576
7857
  interpolation = "LINEAR";
7577
7858
  }
7578
7859
  samplers.push({
7579
- input: this.processAccessor(new import_three19.BufferAttribute(track.times, inputItemSize)),
7580
- output: this.processAccessor(new import_three19.BufferAttribute(track.values, outputItemSize)),
7860
+ input: this.processAccessor(new import_three18.BufferAttribute(track.times, inputItemSize)),
7861
+ output: this.processAccessor(new import_three18.BufferAttribute(track.values, outputItemSize)),
7581
7862
  interpolation
7582
7863
  });
7583
7864
  channels.push({
@@ -7588,16 +7869,18 @@ var GLTFWriter = class {
7588
7869
  }
7589
7870
  });
7590
7871
  }
7591
- json.animations.push({
7872
+ const animationDef = {
7592
7873
  name: clip.name || "clip_" + json.animations.length,
7593
7874
  samplers,
7594
7875
  channels
7595
- });
7876
+ };
7877
+ this.serializeUserData(clip, animationDef);
7878
+ json.animations.push(animationDef);
7596
7879
  return json.animations.length - 1;
7597
7880
  }
7598
7881
  /**
7599
7882
  * @param {THREE.Object3D} object
7600
- * @return {number|null}
7883
+ * @return {?number}
7601
7884
  */
7602
7885
  processSkin(object) {
7603
7886
  const json = this.json;
@@ -7609,7 +7892,7 @@ var GLTFWriter = class {
7609
7892
  if (rootJoint === void 0) return null;
7610
7893
  const joints = [];
7611
7894
  const inverseBindMatrices = new Float32Array(skeleton.bones.length * 16);
7612
- const temporaryBoneInverse = new import_three19.Matrix4();
7895
+ const temporaryBoneInverse = new import_three18.Matrix4();
7613
7896
  for (let i = 0; i < skeleton.bones.length; ++i) {
7614
7897
  joints.push(nodeMap.get(skeleton.bones[i]));
7615
7898
  temporaryBoneInverse.copy(skeleton.boneInverses[i]);
@@ -7617,7 +7900,7 @@ var GLTFWriter = class {
7617
7900
  }
7618
7901
  if (json.skins === void 0) json.skins = [];
7619
7902
  json.skins.push({
7620
- inverseBindMatrices: this.processAccessor(new import_three19.BufferAttribute(inverseBindMatrices, 16)),
7903
+ inverseBindMatrices: this.processAccessor(new import_three18.BufferAttribute(inverseBindMatrices, 16)),
7621
7904
  joints,
7622
7905
  skeleton: nodeMap.get(rootJoint)
7623
7906
  });
@@ -7626,14 +7909,17 @@ var GLTFWriter = class {
7626
7909
  }
7627
7910
  /**
7628
7911
  * Process Object3D node
7629
- * @param {THREE.Object3D} node Object3D to processNode
7630
- * @return {Integer} Index of the node in the nodes list
7912
+ * @param {THREE.Object3D} object Object3D to processNodeAsync
7913
+ * @return {Promise<number>} Index of the node in the nodes list
7631
7914
  */
7632
- processNode(object) {
7915
+ async processNodeAsync(object) {
7633
7916
  const json = this.json;
7634
7917
  const options = this.options;
7635
7918
  const nodeMap = this.nodeMap;
7636
7919
  if (!json.nodes) json.nodes = [];
7920
+ if (object.pivot !== null) {
7921
+ return await this._processNodeWithPivotAsync(object);
7922
+ }
7637
7923
  const nodeDef = {};
7638
7924
  if (options.trs) {
7639
7925
  const rotation = object.quaternion.toArray();
@@ -7659,35 +7945,98 @@ var GLTFWriter = class {
7659
7945
  if (object.name !== "") nodeDef.name = String(object.name);
7660
7946
  this.serializeUserData(object, nodeDef);
7661
7947
  if (object.isMesh || object.isLine || object.isPoints) {
7662
- const meshIndex = this.processMesh(object);
7948
+ const meshIndex = await this.processMeshAsync(object);
7663
7949
  if (meshIndex !== null) nodeDef.mesh = meshIndex;
7664
7950
  } else if (object.isCamera) {
7665
7951
  nodeDef.camera = this.processCamera(object);
7666
7952
  }
7667
7953
  if (object.isSkinnedMesh) this.skins.push(object);
7954
+ const nodeIndex = json.nodes.push(nodeDef) - 1;
7955
+ nodeMap.set(object, nodeIndex);
7668
7956
  if (object.children.length > 0) {
7669
7957
  const children = [];
7670
7958
  for (let i = 0, l = object.children.length; i < l; i++) {
7671
7959
  const child = object.children[i];
7672
7960
  if (child.visible || options.onlyVisible === false) {
7673
- const nodeIndex2 = this.processNode(child);
7674
- if (nodeIndex2 !== null) children.push(nodeIndex2);
7961
+ const childNodeIndex = await this.processNodeAsync(child);
7962
+ if (childNodeIndex !== null) children.push(childNodeIndex);
7675
7963
  }
7676
7964
  }
7677
7965
  if (children.length > 0) nodeDef.children = children;
7678
7966
  }
7679
- this._invokeAll(function(ext) {
7967
+ await this._invokeAllAsync(function(ext) {
7680
7968
  ext.writeNode && ext.writeNode(object, nodeDef);
7681
7969
  });
7682
- const nodeIndex = json.nodes.push(nodeDef) - 1;
7683
- nodeMap.set(object, nodeIndex);
7684
7970
  return nodeIndex;
7685
7971
  }
7972
+ /**
7973
+ * Process Object3D node with pivot using container approach
7974
+ * @param {THREE.Object3D} object Object3D with pivot
7975
+ * @return {Promise<number>} Index of the container node
7976
+ */
7977
+ async _processNodeWithPivotAsync(object) {
7978
+ const json = this.json;
7979
+ const options = this.options;
7980
+ const nodeMap = this.nodeMap;
7981
+ const pivot = object.pivot;
7982
+ const containerDef = {};
7983
+ const rotation = object.quaternion.toArray();
7984
+ const position = [
7985
+ object.position.x + pivot.x,
7986
+ object.position.y + pivot.y,
7987
+ object.position.z + pivot.z
7988
+ ];
7989
+ const scale = object.scale.toArray();
7990
+ if (!equalArray(rotation, [0, 0, 0, 1])) {
7991
+ containerDef.rotation = rotation;
7992
+ }
7993
+ if (!equalArray(position, [0, 0, 0])) {
7994
+ containerDef.translation = position;
7995
+ }
7996
+ if (!equalArray(scale, [1, 1, 1])) {
7997
+ containerDef.scale = scale;
7998
+ }
7999
+ containerDef.extras = { pivot: pivot.toArray() };
8000
+ if (object.name !== "") containerDef.name = String(object.name);
8001
+ this.serializeUserData(object, containerDef);
8002
+ const containerIndex = json.nodes.push(containerDef) - 1;
8003
+ nodeMap.set(object, containerIndex);
8004
+ const childDef = {};
8005
+ const childPosition = [-pivot.x, -pivot.y, -pivot.z];
8006
+ if (!equalArray(childPosition, [0, 0, 0])) {
8007
+ childDef.translation = childPosition;
8008
+ }
8009
+ if (object.isMesh || object.isLine || object.isPoints) {
8010
+ const meshIndex = await this.processMeshAsync(object);
8011
+ if (meshIndex !== null) childDef.mesh = meshIndex;
8012
+ } else if (object.isCamera) {
8013
+ childDef.camera = this.processCamera(object);
8014
+ }
8015
+ if (object.isSkinnedMesh) this.skins.push(object);
8016
+ const childIndex = json.nodes.push(childDef) - 1;
8017
+ const containerChildren = [childIndex];
8018
+ if (object.children.length > 0) {
8019
+ const grandchildren = [];
8020
+ for (let i = 0, l = object.children.length; i < l; i++) {
8021
+ const child = object.children[i];
8022
+ if (child.visible || options.onlyVisible === false) {
8023
+ const childNodeIndex = await this.processNodeAsync(child);
8024
+ if (childNodeIndex !== null) grandchildren.push(childNodeIndex);
8025
+ }
8026
+ }
8027
+ if (grandchildren.length > 0) childDef.children = grandchildren;
8028
+ }
8029
+ containerDef.children = containerChildren;
8030
+ await this._invokeAllAsync(function(ext) {
8031
+ ext.writeNode && ext.writeNode(object, containerDef);
8032
+ });
8033
+ return containerIndex;
8034
+ }
7686
8035
  /**
7687
8036
  * Process Scene
7688
- * @param {Scene} node Scene to process
8037
+ * @param {Scene} scene Scene to process
7689
8038
  */
7690
- processScene(scene) {
8039
+ async processSceneAsync(scene) {
7691
8040
  const json = this.json;
7692
8041
  const options = this.options;
7693
8042
  if (!json.scenes) {
@@ -7701,7 +8050,7 @@ var GLTFWriter = class {
7701
8050
  for (let i = 0, l = scene.children.length; i < l; i++) {
7702
8051
  const child = scene.children[i];
7703
8052
  if (child.visible || options.onlyVisible === false) {
7704
- const nodeIndex = this.processNode(child);
8053
+ const nodeIndex = await this.processNodeAsync(child);
7705
8054
  if (nodeIndex !== null) nodes.push(nodeIndex);
7706
8055
  }
7707
8056
  }
@@ -7710,47 +8059,58 @@ var GLTFWriter = class {
7710
8059
  }
7711
8060
  /**
7712
8061
  * Creates a Scene to hold a list of objects and parse it
7713
- * @param {Array} objects List of objects to process
8062
+ * @param {Array<THREE.Object3D>} objects List of objects to process
7714
8063
  */
7715
- processObjects(objects) {
7716
- const scene = new import_three19.Scene();
8064
+ async processObjectsAsync(objects) {
8065
+ const scene = new import_three18.Scene();
7717
8066
  scene.name = "AuxScene";
7718
8067
  for (let i = 0; i < objects.length; i++) {
7719
8068
  scene.children.push(objects[i]);
7720
8069
  }
7721
- this.processScene(scene);
8070
+ await this.processSceneAsync(scene);
7722
8071
  }
7723
8072
  /**
7724
8073
  * @param {THREE.Object3D|Array<THREE.Object3D>} input
7725
8074
  */
7726
- processInput(input) {
8075
+ async processInputAsync(input) {
7727
8076
  const options = this.options;
7728
8077
  input = input instanceof Array ? input : [input];
7729
- this._invokeAll(function(ext) {
8078
+ await this._invokeAllAsync(function(ext) {
7730
8079
  ext.beforeParse && ext.beforeParse(input);
7731
8080
  });
7732
8081
  const objectsWithoutScene = [];
7733
8082
  for (let i = 0; i < input.length; i++) {
7734
- if (input[i] instanceof import_three19.Scene) {
7735
- this.processScene(input[i]);
8083
+ if (input[i] instanceof import_three18.Scene) {
8084
+ await this.processSceneAsync(input[i]);
7736
8085
  } else {
7737
8086
  objectsWithoutScene.push(input[i]);
7738
8087
  }
7739
8088
  }
7740
- if (objectsWithoutScene.length > 0) this.processObjects(objectsWithoutScene);
8089
+ if (objectsWithoutScene.length > 0) {
8090
+ await this.processObjectsAsync(objectsWithoutScene);
8091
+ }
7741
8092
  for (let i = 0; i < this.skins.length; ++i) {
7742
8093
  this.processSkin(this.skins[i]);
7743
8094
  }
7744
- for (let i = 0; i < options.animations.length; ++i) {
7745
- this.processAnimation(options.animations[i], input[0]);
8095
+ if (input.length === 1) {
8096
+ for (let i = 0; i < options.animations.length; ++i) {
8097
+ this.processAnimation(options.animations[i], input[0]);
8098
+ }
8099
+ } else {
8100
+ for (let i = 0; i < input.length; i++) {
8101
+ const animations = options.animations[i] || [];
8102
+ for (let j = 0; j < animations.length; ++j) {
8103
+ this.processAnimation(animations[j], input[i]);
8104
+ }
8105
+ }
7746
8106
  }
7747
- this._invokeAll(function(ext) {
8107
+ await this._invokeAllAsync(function(ext) {
7748
8108
  ext.afterParse && ext.afterParse(input);
7749
8109
  });
7750
8110
  }
7751
- _invokeAll(func) {
8111
+ async _invokeAllAsync(func) {
7752
8112
  for (let i = 0, il = this.plugins.length; i < il; i++) {
7753
- func(this.plugins[i]);
8113
+ await func(this.plugins[i]);
7754
8114
  }
7755
8115
  }
7756
8116
  };
@@ -7806,7 +8166,7 @@ var GLTFMaterialsUnlitExtension = class {
7806
8166
  this.writer = writer;
7807
8167
  this.name = "KHR_materials_unlit";
7808
8168
  }
7809
- writeMaterial(material, materialDef) {
8169
+ async writeMaterialAsync(material, materialDef) {
7810
8170
  if (!material.isMeshBasicMaterial) return;
7811
8171
  const writer = this.writer;
7812
8172
  const extensionsUsed = writer.extensionsUsed;
@@ -7822,7 +8182,7 @@ var GLTFMaterialsClearcoatExtension = class {
7822
8182
  this.writer = writer;
7823
8183
  this.name = "KHR_materials_clearcoat";
7824
8184
  }
7825
- writeMaterial(material, materialDef) {
8185
+ async writeMaterialAsync(material, materialDef) {
7826
8186
  if (!material.isMeshPhysicalMaterial || material.clearcoat === 0) return;
7827
8187
  const writer = this.writer;
7828
8188
  const extensionsUsed = writer.extensionsUsed;
@@ -7830,7 +8190,7 @@ var GLTFMaterialsClearcoatExtension = class {
7830
8190
  extensionDef.clearcoatFactor = material.clearcoat;
7831
8191
  if (material.clearcoatMap) {
7832
8192
  const clearcoatMapDef = {
7833
- index: writer.processTexture(material.clearcoatMap),
8193
+ index: await writer.processTextureAsync(material.clearcoatMap),
7834
8194
  texCoord: material.clearcoatMap.channel
7835
8195
  };
7836
8196
  writer.applyTextureTransform(clearcoatMapDef, material.clearcoatMap);
@@ -7839,7 +8199,7 @@ var GLTFMaterialsClearcoatExtension = class {
7839
8199
  extensionDef.clearcoatRoughnessFactor = material.clearcoatRoughness;
7840
8200
  if (material.clearcoatRoughnessMap) {
7841
8201
  const clearcoatRoughnessMapDef = {
7842
- index: writer.processTexture(material.clearcoatRoughnessMap),
8202
+ index: await writer.processTextureAsync(material.clearcoatRoughnessMap),
7843
8203
  texCoord: material.clearcoatRoughnessMap.channel
7844
8204
  };
7845
8205
  writer.applyTextureTransform(clearcoatRoughnessMapDef, material.clearcoatRoughnessMap);
@@ -7847,9 +8207,10 @@ var GLTFMaterialsClearcoatExtension = class {
7847
8207
  }
7848
8208
  if (material.clearcoatNormalMap) {
7849
8209
  const clearcoatNormalMapDef = {
7850
- index: writer.processTexture(material.clearcoatNormalMap),
8210
+ index: await writer.processTextureAsync(material.clearcoatNormalMap),
7851
8211
  texCoord: material.clearcoatNormalMap.channel
7852
8212
  };
8213
+ if (material.clearcoatNormalScale.x !== 1) clearcoatNormalMapDef.scale = material.clearcoatNormalScale.x;
7853
8214
  writer.applyTextureTransform(clearcoatNormalMapDef, material.clearcoatNormalMap);
7854
8215
  extensionDef.clearcoatNormalTexture = clearcoatNormalMapDef;
7855
8216
  }
@@ -7858,12 +8219,28 @@ var GLTFMaterialsClearcoatExtension = class {
7858
8219
  extensionsUsed[this.name] = true;
7859
8220
  }
7860
8221
  };
8222
+ var GLTFMaterialsDispersionExtension = class {
8223
+ constructor(writer) {
8224
+ this.writer = writer;
8225
+ this.name = "KHR_materials_dispersion";
8226
+ }
8227
+ async writeMaterialAsync(material, materialDef) {
8228
+ if (!material.isMeshPhysicalMaterial || material.dispersion === 0) return;
8229
+ const writer = this.writer;
8230
+ const extensionsUsed = writer.extensionsUsed;
8231
+ const extensionDef = {};
8232
+ extensionDef.dispersion = material.dispersion;
8233
+ materialDef.extensions = materialDef.extensions || {};
8234
+ materialDef.extensions[this.name] = extensionDef;
8235
+ extensionsUsed[this.name] = true;
8236
+ }
8237
+ };
7861
8238
  var GLTFMaterialsIridescenceExtension = class {
7862
8239
  constructor(writer) {
7863
8240
  this.writer = writer;
7864
8241
  this.name = "KHR_materials_iridescence";
7865
8242
  }
7866
- writeMaterial(material, materialDef) {
8243
+ async writeMaterialAsync(material, materialDef) {
7867
8244
  if (!material.isMeshPhysicalMaterial || material.iridescence === 0) return;
7868
8245
  const writer = this.writer;
7869
8246
  const extensionsUsed = writer.extensionsUsed;
@@ -7871,7 +8248,7 @@ var GLTFMaterialsIridescenceExtension = class {
7871
8248
  extensionDef.iridescenceFactor = material.iridescence;
7872
8249
  if (material.iridescenceMap) {
7873
8250
  const iridescenceMapDef = {
7874
- index: writer.processTexture(material.iridescenceMap),
8251
+ index: await writer.processTextureAsync(material.iridescenceMap),
7875
8252
  texCoord: material.iridescenceMap.channel
7876
8253
  };
7877
8254
  writer.applyTextureTransform(iridescenceMapDef, material.iridescenceMap);
@@ -7882,7 +8259,7 @@ var GLTFMaterialsIridescenceExtension = class {
7882
8259
  extensionDef.iridescenceThicknessMaximum = material.iridescenceThicknessRange[1];
7883
8260
  if (material.iridescenceThicknessMap) {
7884
8261
  const iridescenceThicknessMapDef = {
7885
- index: writer.processTexture(material.iridescenceThicknessMap),
8262
+ index: await writer.processTextureAsync(material.iridescenceThicknessMap),
7886
8263
  texCoord: material.iridescenceThicknessMap.channel
7887
8264
  };
7888
8265
  writer.applyTextureTransform(iridescenceThicknessMapDef, material.iridescenceThicknessMap);
@@ -7898,7 +8275,7 @@ var GLTFMaterialsTransmissionExtension = class {
7898
8275
  this.writer = writer;
7899
8276
  this.name = "KHR_materials_transmission";
7900
8277
  }
7901
- writeMaterial(material, materialDef) {
8278
+ async writeMaterialAsync(material, materialDef) {
7902
8279
  if (!material.isMeshPhysicalMaterial || material.transmission === 0) return;
7903
8280
  const writer = this.writer;
7904
8281
  const extensionsUsed = writer.extensionsUsed;
@@ -7906,7 +8283,7 @@ var GLTFMaterialsTransmissionExtension = class {
7906
8283
  extensionDef.transmissionFactor = material.transmission;
7907
8284
  if (material.transmissionMap) {
7908
8285
  const transmissionMapDef = {
7909
- index: writer.processTexture(material.transmissionMap),
8286
+ index: await writer.processTextureAsync(material.transmissionMap),
7910
8287
  texCoord: material.transmissionMap.channel
7911
8288
  };
7912
8289
  writer.applyTextureTransform(transmissionMapDef, material.transmissionMap);
@@ -7922,7 +8299,7 @@ var GLTFMaterialsVolumeExtension = class {
7922
8299
  this.writer = writer;
7923
8300
  this.name = "KHR_materials_volume";
7924
8301
  }
7925
- writeMaterial(material, materialDef) {
8302
+ async writeMaterialAsync(material, materialDef) {
7926
8303
  if (!material.isMeshPhysicalMaterial || material.transmission === 0) return;
7927
8304
  const writer = this.writer;
7928
8305
  const extensionsUsed = writer.extensionsUsed;
@@ -7930,13 +8307,15 @@ var GLTFMaterialsVolumeExtension = class {
7930
8307
  extensionDef.thicknessFactor = material.thickness;
7931
8308
  if (material.thicknessMap) {
7932
8309
  const thicknessMapDef = {
7933
- index: writer.processTexture(material.thicknessMap),
8310
+ index: await writer.processTextureAsync(material.thicknessMap),
7934
8311
  texCoord: material.thicknessMap.channel
7935
8312
  };
7936
8313
  writer.applyTextureTransform(thicknessMapDef, material.thicknessMap);
7937
8314
  extensionDef.thicknessTexture = thicknessMapDef;
7938
8315
  }
7939
- extensionDef.attenuationDistance = material.attenuationDistance;
8316
+ if (material.attenuationDistance !== Infinity) {
8317
+ extensionDef.attenuationDistance = material.attenuationDistance;
8318
+ }
7940
8319
  extensionDef.attenuationColor = material.attenuationColor.toArray();
7941
8320
  materialDef.extensions = materialDef.extensions || {};
7942
8321
  materialDef.extensions[this.name] = extensionDef;
@@ -7948,7 +8327,7 @@ var GLTFMaterialsIorExtension = class {
7948
8327
  this.writer = writer;
7949
8328
  this.name = "KHR_materials_ior";
7950
8329
  }
7951
- writeMaterial(material, materialDef) {
8330
+ async writeMaterialAsync(material, materialDef) {
7952
8331
  if (!material.isMeshPhysicalMaterial || material.ior === 1.5) return;
7953
8332
  const writer = this.writer;
7954
8333
  const extensionsUsed = writer.extensionsUsed;
@@ -7964,14 +8343,14 @@ var GLTFMaterialsSpecularExtension = class {
7964
8343
  this.writer = writer;
7965
8344
  this.name = "KHR_materials_specular";
7966
8345
  }
7967
- writeMaterial(material, materialDef) {
7968
- if (!material.isMeshPhysicalMaterial || material.specularIntensity === 1 && material.specularColor.equals(DEFAULT_SPECULAR_COLOR) && !material.specularIntensityMap && !material.specularColorTexture) return;
8346
+ async writeMaterialAsync(material, materialDef) {
8347
+ if (!material.isMeshPhysicalMaterial || material.specularIntensity === 1 && material.specularColor.equals(DEFAULT_SPECULAR_COLOR) && !material.specularIntensityMap && !material.specularColorMap) return;
7969
8348
  const writer = this.writer;
7970
8349
  const extensionsUsed = writer.extensionsUsed;
7971
8350
  const extensionDef = {};
7972
8351
  if (material.specularIntensityMap) {
7973
8352
  const specularIntensityMapDef = {
7974
- index: writer.processTexture(material.specularIntensityMap),
8353
+ index: await writer.processTextureAsync(material.specularIntensityMap),
7975
8354
  texCoord: material.specularIntensityMap.channel
7976
8355
  };
7977
8356
  writer.applyTextureTransform(specularIntensityMapDef, material.specularIntensityMap);
@@ -7979,7 +8358,7 @@ var GLTFMaterialsSpecularExtension = class {
7979
8358
  }
7980
8359
  if (material.specularColorMap) {
7981
8360
  const specularColorMapDef = {
7982
- index: writer.processTexture(material.specularColorMap),
8361
+ index: await writer.processTextureAsync(material.specularColorMap),
7983
8362
  texCoord: material.specularColorMap.channel
7984
8363
  };
7985
8364
  writer.applyTextureTransform(specularColorMapDef, material.specularColorMap);
@@ -7997,14 +8376,14 @@ var GLTFMaterialsSheenExtension = class {
7997
8376
  this.writer = writer;
7998
8377
  this.name = "KHR_materials_sheen";
7999
8378
  }
8000
- writeMaterial(material, materialDef) {
8379
+ async writeMaterialAsync(material, materialDef) {
8001
8380
  if (!material.isMeshPhysicalMaterial || material.sheen == 0) return;
8002
8381
  const writer = this.writer;
8003
8382
  const extensionsUsed = writer.extensionsUsed;
8004
8383
  const extensionDef = {};
8005
8384
  if (material.sheenRoughnessMap) {
8006
8385
  const sheenRoughnessMapDef = {
8007
- index: writer.processTexture(material.sheenRoughnessMap),
8386
+ index: await writer.processTextureAsync(material.sheenRoughnessMap),
8008
8387
  texCoord: material.sheenRoughnessMap.channel
8009
8388
  };
8010
8389
  writer.applyTextureTransform(sheenRoughnessMapDef, material.sheenRoughnessMap);
@@ -8012,7 +8391,7 @@ var GLTFMaterialsSheenExtension = class {
8012
8391
  }
8013
8392
  if (material.sheenColorMap) {
8014
8393
  const sheenColorMapDef = {
8015
- index: writer.processTexture(material.sheenColorMap),
8394
+ index: await writer.processTextureAsync(material.sheenColorMap),
8016
8395
  texCoord: material.sheenColorMap.channel
8017
8396
  };
8018
8397
  writer.applyTextureTransform(sheenColorMapDef, material.sheenColorMap);
@@ -8030,13 +8409,13 @@ var GLTFMaterialsAnisotropyExtension = class {
8030
8409
  this.writer = writer;
8031
8410
  this.name = "KHR_materials_anisotropy";
8032
8411
  }
8033
- writeMaterial(material, materialDef) {
8412
+ async writeMaterialAsync(material, materialDef) {
8034
8413
  if (!material.isMeshPhysicalMaterial || material.anisotropy == 0) return;
8035
8414
  const writer = this.writer;
8036
8415
  const extensionsUsed = writer.extensionsUsed;
8037
8416
  const extensionDef = {};
8038
8417
  if (material.anisotropyMap) {
8039
- const anisotropyMapDef = { index: writer.processTexture(material.anisotropyMap) };
8418
+ const anisotropyMapDef = { index: await writer.processTextureAsync(material.anisotropyMap) };
8040
8419
  writer.applyTextureTransform(anisotropyMapDef, material.anisotropyMap);
8041
8420
  extensionDef.anisotropyTexture = anisotropyMapDef;
8042
8421
  }
@@ -8052,7 +8431,7 @@ var GLTFMaterialsEmissiveStrengthExtension = class {
8052
8431
  this.writer = writer;
8053
8432
  this.name = "KHR_materials_emissive_strength";
8054
8433
  }
8055
- writeMaterial(material, materialDef) {
8434
+ async writeMaterialAsync(material, materialDef) {
8056
8435
  if (!material.isMeshStandardMaterial || material.emissiveIntensity === 1) return;
8057
8436
  const writer = this.writer;
8058
8437
  const extensionsUsed = writer.extensionsUsed;
@@ -8063,6 +8442,30 @@ var GLTFMaterialsEmissiveStrengthExtension = class {
8063
8442
  extensionsUsed[this.name] = true;
8064
8443
  }
8065
8444
  };
8445
+ var GLTFMaterialsBumpExtension = class {
8446
+ constructor(writer) {
8447
+ this.writer = writer;
8448
+ this.name = "EXT_materials_bump";
8449
+ }
8450
+ async writeMaterialAsync(material, materialDef) {
8451
+ if (!material.isMeshStandardMaterial || material.bumpScale === 1 && !material.bumpMap) return;
8452
+ const writer = this.writer;
8453
+ const extensionsUsed = writer.extensionsUsed;
8454
+ const extensionDef = {};
8455
+ if (material.bumpMap) {
8456
+ const bumpMapDef = {
8457
+ index: await writer.processTextureAsync(material.bumpMap),
8458
+ texCoord: material.bumpMap.channel
8459
+ };
8460
+ writer.applyTextureTransform(bumpMapDef, material.bumpMap);
8461
+ extensionDef.bumpTexture = bumpMapDef;
8462
+ }
8463
+ extensionDef.bumpFactor = material.bumpScale;
8464
+ materialDef.extensions = materialDef.extensions || {};
8465
+ materialDef.extensions[this.name] = extensionDef;
8466
+ extensionsUsed[this.name] = true;
8467
+ }
8468
+ };
8066
8469
  var GLTFMeshGpuInstancing = class {
8067
8470
  constructor(writer) {
8068
8471
  this.writer = writer;
@@ -8075,10 +8478,10 @@ var GLTFMeshGpuInstancing = class {
8075
8478
  const translationAttr = new Float32Array(mesh.count * 3);
8076
8479
  const rotationAttr = new Float32Array(mesh.count * 4);
8077
8480
  const scaleAttr = new Float32Array(mesh.count * 3);
8078
- const matrix = new import_three19.Matrix4();
8079
- const position = new import_three19.Vector3();
8080
- const quaternion = new import_three19.Quaternion();
8081
- const scale = new import_three19.Vector3();
8481
+ const matrix = new import_three18.Matrix4();
8482
+ const position = new import_three18.Vector3();
8483
+ const quaternion = new import_three18.Quaternion();
8484
+ const scale = new import_three18.Vector3();
8082
8485
  for (let i = 0; i < mesh.count; i++) {
8083
8486
  mesh.getMatrixAt(i, matrix);
8084
8487
  matrix.decompose(position, quaternion, scale);
@@ -8087,9 +8490,9 @@ var GLTFMeshGpuInstancing = class {
8087
8490
  scale.toArray(scaleAttr, i * 3);
8088
8491
  }
8089
8492
  const attributes = {
8090
- TRANSLATION: writer.processAccessor(new import_three19.BufferAttribute(translationAttr, 3)),
8091
- ROTATION: writer.processAccessor(new import_three19.BufferAttribute(rotationAttr, 4)),
8092
- SCALE: writer.processAccessor(new import_three19.BufferAttribute(scaleAttr, 3))
8493
+ TRANSLATION: writer.processAccessor(new import_three18.BufferAttribute(translationAttr, 3)),
8494
+ ROTATION: writer.processAccessor(new import_three18.BufferAttribute(rotationAttr, 4)),
8495
+ SCALE: writer.processAccessor(new import_three18.BufferAttribute(scaleAttr, 3))
8093
8496
  };
8094
8497
  if (mesh.instanceColor)
8095
8498
  attributes._COLOR_0 = writer.processAccessor(mesh.instanceColor);
@@ -8154,8 +8557,8 @@ GLTFExporter.Utils = {
8154
8557
  const sourceTracks = clip.tracks;
8155
8558
  for (let i = 0; i < sourceTracks.length; ++i) {
8156
8559
  let sourceTrack = sourceTracks[i];
8157
- const sourceTrackBinding = import_three19.PropertyBinding.parseTrackName(sourceTrack.name);
8158
- const sourceTrackNode = import_three19.PropertyBinding.findNode(root, sourceTrackBinding.nodeName);
8560
+ const sourceTrackBinding = import_three18.PropertyBinding.parseTrackName(sourceTrack.name);
8561
+ const sourceTrackNode = import_three18.PropertyBinding.findNode(root, sourceTrackBinding.nodeName);
8159
8562
  if (sourceTrackBinding.propertyName !== "morphTargetInfluences" || sourceTrackBinding.propertyIndex === void 0) {
8160
8563
  tracks.push(sourceTrack);
8161
8564
  continue;
@@ -8166,7 +8569,7 @@ GLTFExporter.Utils = {
8166
8569
  }
8167
8570
  console.warn("THREE.GLTFExporter: Morph target interpolation mode not yet supported. Using LINEAR instead.");
8168
8571
  sourceTrack = sourceTrack.clone();
8169
- sourceTrack.setInterpolation(import_three19.InterpolateLinear);
8572
+ sourceTrack.setInterpolation(import_three18.InterpolateLinear);
8170
8573
  }
8171
8574
  const targetCount = sourceTrackNode.morphTargetInfluences.length;
8172
8575
  const targetIndex = sourceTrackNode.morphTargetDictionary[sourceTrackBinding.propertyIndex];
@@ -8198,6 +8601,19 @@ GLTFExporter.Utils = {
8198
8601
  }
8199
8602
  clip.tracks = tracks;
8200
8603
  return clip;
8604
+ },
8605
+ toTypedBufferAttribute: function(srcAttribute, TypedArray) {
8606
+ const dstAttribute = new import_three18.BufferAttribute(new TypedArray(srcAttribute.count * srcAttribute.itemSize), srcAttribute.itemSize, false);
8607
+ if (!srcAttribute.normalized && !srcAttribute.isInterleavedBufferAttribute) {
8608
+ dstAttribute.array.set(srcAttribute.array);
8609
+ return dstAttribute;
8610
+ }
8611
+ for (let i = 0, il = srcAttribute.count; i < il; i++) {
8612
+ for (let j = 0; j < srcAttribute.itemSize; j++) {
8613
+ dstAttribute.setComponent(i, j, srcAttribute.getComponent(i, j));
8614
+ }
8615
+ }
8616
+ return dstAttribute;
8201
8617
  }
8202
8618
  };
8203
8619
 
@@ -8249,10 +8665,10 @@ var SceneExporter = class {
8249
8665
  }
8250
8666
  };
8251
8667
  function localMatrix(object) {
8252
- return object.matrixAutoUpdate ? new import_three20.Matrix4().compose(object.position, object.quaternion, object.scale) : object.matrix.clone();
8668
+ return object.matrixAutoUpdate ? new import_three19.Matrix4().compose(object.position, object.quaternion, object.scale) : object.matrix.clone();
8253
8669
  }
8254
8670
  function createSnapshot(root, gltf, bakeColors = false) {
8255
- const scene = new import_three20.Scene();
8671
+ const scene = new import_three19.Scene();
8256
8672
  const geometries = [];
8257
8673
  const materials = [];
8258
8674
  const textures = [];
@@ -8270,7 +8686,7 @@ function createSnapshot(root, gltf, bakeColors = false) {
8270
8686
  if (!uniforms.map?.value?.isTexture || !uniforms.SHADE || !uniforms.BRIGHTNESS || !uniforms.EMISSIVE) {
8271
8687
  throw new MineRenderError("glTF export does not support this custom ShaderMaterial");
8272
8688
  }
8273
- material = new import_three20.MeshBasicMaterial({
8689
+ material = new import_three19.MeshBasicMaterial({
8274
8690
  map: uniforms.map.value,
8275
8691
  vertexColors: source.vertexColors,
8276
8692
  transparent: source.transparent,
@@ -8280,7 +8696,7 @@ function createSnapshot(root, gltf, bakeColors = false) {
8280
8696
  });
8281
8697
  material.name = source.name;
8282
8698
  } else if (shader.isShaderMaterial) {
8283
- material = new import_three20.MeshBasicMaterial({ vertexColors: source.vertexColors });
8699
+ material = new import_three19.MeshBasicMaterial({ vertexColors: source.vertexColors });
8284
8700
  material.name = source.name;
8285
8701
  } else {
8286
8702
  const copySource = Object.create(source);
@@ -8334,11 +8750,11 @@ function createSnapshot(root, gltf, bakeColors = false) {
8334
8750
  const material = copyMaterial(sourceMaterial, geometry);
8335
8751
  if (!sourceMaterial.vertexColors) geometry.deleteAttribute("color");
8336
8752
  if (bakeColors || instanceColor) {
8337
- const tint = (material.color ?? new import_three20.Color()).clone();
8753
+ const tint = (material.color ?? new import_three19.Color()).clone();
8338
8754
  if (instanceColor) tint.multiply(instanceColor);
8339
8755
  if (bakeColors) {
8340
8756
  const original = geometry.getAttribute("color");
8341
- const colors = new import_three20.Float32BufferAttribute(new Float32Array(geometry.getAttribute("position").count * 3), 3);
8757
+ const colors = new import_three19.Float32BufferAttribute(new Float32Array(geometry.getAttribute("position").count * 3), 3);
8342
8758
  for (let i = 0; i < colors.count; i++) {
8343
8759
  colors.setXYZ(i, (original?.getX(i) ?? 1) * tint.r, (original?.getY(i) ?? 1) * tint.g, (original?.getZ(i) ?? 1) * tint.b);
8344
8760
  }
@@ -8347,7 +8763,7 @@ function createSnapshot(root, gltf, bakeColors = false) {
8347
8763
  material.color.copy(tint);
8348
8764
  }
8349
8765
  }
8350
- const copy = new import_three20.Mesh(geometry, material);
8766
+ const copy = new import_three19.Mesh(geometry, material);
8351
8767
  copy.name = mesh.name;
8352
8768
  copy.renderOrder = mesh.renderOrder;
8353
8769
  scene.add(copy);
@@ -8361,9 +8777,9 @@ function createSnapshot(root, gltf, bakeColors = false) {
8361
8777
  const instanced = mesh;
8362
8778
  if (instanced.isInstancedMesh) {
8363
8779
  for (let i = 0; i < instanced.count; i++) {
8364
- const matrix = new import_three20.Matrix4();
8780
+ const matrix = new import_three19.Matrix4();
8365
8781
  instanced.getMatrixAt(i, matrix);
8366
- const color = instanced.instanceColor ? new import_three20.Color().fromBufferAttribute(instanced.instanceColor, i) : void 0;
8782
+ const color = instanced.instanceColor ? new import_three19.Color().fromBufferAttribute(instanced.instanceColor, i) : void 0;
8367
8783
  addMesh(mesh, world.clone().multiply(matrix), color);
8368
8784
  }
8369
8785
  } else {
@@ -8375,7 +8791,7 @@ function createSnapshot(root, gltf, bakeColors = false) {
8375
8791
  try {
8376
8792
  const ancestors = [];
8377
8793
  for (let parent = root.parent; parent; parent = parent.parent) ancestors.unshift(parent);
8378
- const world = new import_three20.Matrix4();
8794
+ const world = new import_three19.Matrix4();
8379
8795
  for (const ancestor of ancestors) {
8380
8796
  if (!ancestor.visible) return { scene, dispose };
8381
8797
  world.multiply(localMatrix(ancestor));
@@ -8389,7 +8805,7 @@ function createSnapshot(root, gltf, bakeColors = false) {
8389
8805
  }
8390
8806
  function selectAlphaMode(material, geometry) {
8391
8807
  const texture = material.map;
8392
- 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;
8808
+ 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;
8393
8809
  const uv = geometry.getAttribute(texture.channel === 0 ? "uv" : `uv${texture.channel}`);
8394
8810
  const colors = geometry.getAttribute("color");
8395
8811
  if (!uv || material.vertexColors && colors?.itemSize === 4) return;
@@ -8426,7 +8842,7 @@ function selectAlphaMode(material, geometry) {
8426
8842
  }
8427
8843
  function copyDataTexture(source) {
8428
8844
  const image = source.image;
8429
- if (source.format !== import_three20.RGBAFormat || source.type !== import_three20.UnsignedByteType) {
8845
+ if (!image.data || source.format !== import_three19.RGBAFormat || source.type !== import_three19.UnsignedByteType) {
8430
8846
  throw new MineRenderError("glTF export requires RGBA unsigned-byte data textures");
8431
8847
  }
8432
8848
  const canvas = createCanvas(image.width, image.height);
@@ -8437,8 +8853,8 @@ function copyDataTexture(source) {
8437
8853
  context.putImageData(pixels, 0, 0);
8438
8854
  const copySource = Object.create(source);
8439
8855
  copySource.userData = {};
8440
- copySource.source = new import_three20.Source(canvas);
8441
- return new import_three20.Texture().copy(copySource);
8856
+ copySource.source = new import_three19.TextureSource(canvas);
8857
+ return new import_three19.Texture().copy(copySource);
8442
8858
  }
8443
8859
 
8444
8860
  // src/gui/GuiHelper.ts
@@ -8508,7 +8924,7 @@ var GuiHelper = class {
8508
8924
  };
8509
8925
 
8510
8926
  // src/gui/scene/GuiObject.ts
8511
- var import_three25 = require("three");
8927
+ var import_three24 = require("three");
8512
8928
  init_AssetKey();
8513
8929
  init_ModelTextures();
8514
8930
  init_Models();
@@ -8524,7 +8940,7 @@ var GuiObject = class extends SceneObject {
8524
8940
  this.textureLayers = textureLayers;
8525
8941
  this.isGuiObject = true;
8526
8942
  /** Local bounds in GUI pixels, with y growing down from the origin. */
8527
- this.bounds = new import_three25.Box2();
8943
+ this.bounds = new import_three24.Box2();
8528
8944
  this.geometries = /* @__PURE__ */ new Set();
8529
8945
  this.ownedMaterials = /* @__PURE__ */ new Set();
8530
8946
  this.initialized = false;
@@ -8542,17 +8958,17 @@ var GuiObject = class extends SceneObject {
8542
8958
  item.scale.set(width2 / 16, height2 / 16, width2 / 16);
8543
8959
  item.updateWorldMatrix(true, true);
8544
8960
  const inverse = this.matrixWorld.clone().invert();
8545
- const bounds = new import_three25.Box3();
8961
+ const bounds = new import_three24.Box3();
8546
8962
  item.iterateAllMeshes((mesh2) => {
8547
8963
  mesh2.geometry.computeBoundingBox();
8548
- bounds.union(mesh2.geometry.boundingBox.clone().applyMatrix4(new import_three25.Matrix4().multiplyMatrices(inverse, mesh2.matrixWorld)));
8964
+ bounds.union(mesh2.geometry.boundingBox.clone().applyMatrix4(new import_three24.Matrix4().multiplyMatrices(inverse, mesh2.matrixWorld)));
8549
8965
  });
8550
8966
  item.position.z = depth - bounds.min.z;
8551
8967
  depth += bounds.max.z - bounds.min.z + 0.01;
8552
- this.bounds.expandByPoint(new import_three25.Vector2(x, y));
8553
- this.bounds.expandByPoint(new import_three25.Vector2(x + width2, y + height2));
8554
- this.bounds.expandByPoint(new import_three25.Vector2(bounds.min.x, -bounds.max.y));
8555
- this.bounds.expandByPoint(new import_three25.Vector2(bounds.max.x, -bounds.min.y));
8968
+ this.bounds.expandByPoint(new import_three24.Vector2(x, y));
8969
+ this.bounds.expandByPoint(new import_three24.Vector2(x + width2, y + height2));
8970
+ this.bounds.expandByPoint(new import_three24.Vector2(bounds.min.x, -bounds.max.y));
8971
+ this.bounds.expandByPoint(new import_three24.Vector2(bounds.max.x, -bounds.min.y));
8556
8972
  continue;
8557
8973
  }
8558
8974
  const key = typeof layer.texture === "string" ? AssetKey.parse("textures", layer.texture) : layer.texture;
@@ -8560,7 +8976,7 @@ var GuiObject = class extends SceneObject {
8560
8976
  const image = material.map.image;
8561
8977
  const [cropX, cropY, cropWidth, cropHeight] = layer.crop ?? [0, 0, image.width, image.height];
8562
8978
  const [width, height] = layer.size ?? [cropWidth, cropHeight];
8563
- const geometry = new import_three25.PlaneGeometry(width, height);
8979
+ const geometry = new import_three24.PlaneGeometry(width, height);
8564
8980
  this.geometries.add(geometry);
8565
8981
  const uv = geometry.getAttribute("uv");
8566
8982
  for (let i = 0; i < uv.count; i++) {
@@ -8570,13 +8986,13 @@ var GuiObject = class extends SceneObject {
8570
8986
  1 - (cropY + (1 - uv.getY(i)) * cropHeight) / image.height
8571
8987
  );
8572
8988
  }
8573
- const mesh = new import_three25.Mesh(geometry, material);
8989
+ const mesh = new import_three24.Mesh(geometry, material);
8574
8990
  mesh.name = `mesh:${layer.name ?? index}`;
8575
8991
  mesh.position.set(x + width / 2, -y - height / 2, depth);
8576
8992
  mesh.renderOrder = index;
8577
8993
  this.add(mesh);
8578
- this.bounds.expandByPoint(new import_three25.Vector2(x, y));
8579
- this.bounds.expandByPoint(new import_three25.Vector2(x + width, y + height));
8994
+ this.bounds.expandByPoint(new import_three24.Vector2(x, y));
8995
+ this.bounds.expandByPoint(new import_three24.Vector2(x + width, y + height));
8580
8996
  depth += 0.01;
8581
8997
  }
8582
8998
  for (const child of this.children) child.position.z -= depth - 0.01;
@@ -8651,7 +9067,7 @@ function isGuiObject(obj) {
8651
9067
  init_image();
8652
9068
 
8653
9069
  // src/inspector/SceneInspector.ts
8654
- var import_three26 = require("three");
9070
+ var import_three25 = require("three");
8655
9071
  init_SceneObject();
8656
9072
  init_util();
8657
9073
  init_log();
@@ -8661,11 +9077,11 @@ var help = "<span>Ctrl/Cmd+Click to Select<br/></span><br/>";
8661
9077
  var SceneInspector = class {
8662
9078
  constructor(renderer) {
8663
9079
  this.renderer = renderer;
8664
- this.mouse = new import_three26.Vector2();
9080
+ this.mouse = new import_three25.Vector2();
8665
9081
  this.listeners = new AbortController();
8666
9082
  this.objectInfoContainer = document.createElement("div");
8667
9083
  this.objectControlsContainer = document.createElement("div");
8668
- this.raycaster = new import_three26.Raycaster();
9084
+ this.raycaster = new import_three25.Raycaster();
8669
9085
  this.init();
8670
9086
  }
8671
9087
  init() {
@@ -9068,7 +9484,7 @@ init_ModelMerger();
9068
9484
  init_SpecialItems();
9069
9485
 
9070
9486
  // src/model/block/BlockStateResolver.ts
9071
- var import_three28 = require("three");
9487
+ var import_three27 = require("three");
9072
9488
  init_BlockStates();
9073
9489
  init_MineRenderError();
9074
9490
  init_util();
@@ -9146,7 +9562,7 @@ var BlockStateResolver = class {
9146
9562
  return variants[variants.length - 1];
9147
9563
  }
9148
9564
  static rotation(variant) {
9149
- const rotation = new import_three28.Euler();
9565
+ const rotation = new import_three27.Euler();
9150
9566
  if (typeof variant.x !== "undefined") {
9151
9567
  rotation.x = toRadians(clampRotationDegrees(variant.x));
9152
9568
  }
@@ -9238,7 +9654,7 @@ init_SceneObject();
9238
9654
  init_ModelObject();
9239
9655
  init_Models();
9240
9656
  var import_ts_deepmerge6 = __toESM(require_dist());
9241
- var import_three31 = require("three");
9657
+ var import_three30 = require("three");
9242
9658
  init_MineRenderError();
9243
9659
  init_InstanceReference();
9244
9660
  init_AssetKey();
@@ -9260,7 +9676,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
9260
9676
  this._models = [];
9261
9677
  this._cullMask = 0;
9262
9678
  this._entities = [];
9263
- this._entityPlacement = new import_three31.Matrix4();
9679
+ this._entityPlacement = new import_three30.Matrix4();
9264
9680
  this._entityGeneration = 0;
9265
9681
  this.options = (0, import_ts_deepmerge6.default)({}, _BlockObject.DEFAULT_OPTIONS, options ?? {});
9266
9682
  }
@@ -9356,7 +9772,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
9356
9772
  return true;
9357
9773
  }
9358
9774
  placeEntities() {
9359
- const matrix = new import_three31.Matrix4().makeTranslation(this.position.x - 8, this.position.y - 8, this.position.z - 8).multiply(this._entityPlacement);
9775
+ const matrix = new import_three30.Matrix4().makeTranslation(this.position.x - 8, this.position.y - 8, this.position.z - 8).multiply(this._entityPlacement);
9360
9776
  for (const entity of this._entities) {
9361
9777
  matrix.decompose(entity.position, entity.quaternion, entity.scale);
9362
9778
  }
@@ -9378,12 +9794,12 @@ var _BlockObject = class _BlockObject extends SceneObject {
9378
9794
  getModelCullMask(model, worldMask) {
9379
9795
  const object = isInstanceReference(model) ? model.instanceable : model;
9380
9796
  if (object.options.displayPosition) return 0;
9381
- const position = new import_three31.Vector3();
9382
- const rotation = new import_three31.Quaternion();
9383
- const scale = new import_three31.Vector3();
9797
+ const position = new import_three30.Vector3();
9798
+ const rotation = new import_three30.Quaternion();
9799
+ const scale = new import_three30.Vector3();
9384
9800
  this.getModelMatrix(model).decompose(position, rotation, scale);
9385
- if (position.distanceToSquared(this.position) > 1e-10 || scale.distanceToSquared(new import_three31.Vector3(1, 1, 1)) > 1e-10) return 0;
9386
- return ModelCulling.toLocalMask(worldMask, new import_three31.Euler().setFromQuaternion(rotation));
9801
+ if (position.distanceToSquared(this.position) > 1e-10 || scale.distanceToSquared(new import_three30.Vector3(1, 1, 1)) > 1e-10) return 0;
9802
+ return ModelCulling.toLocalMask(worldMask, new import_three30.Euler().setFromQuaternion(rotation));
9387
9803
  }
9388
9804
  async setCullMask(worldMask) {
9389
9805
  worldMask &= 63;
@@ -9407,6 +9823,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
9407
9823
  replacement.setMatrix(matrix);
9408
9824
  } else {
9409
9825
  replacement.matrix.copy(matrix);
9826
+ replacement.matrixWorldNeedsUpdate = true;
9410
9827
  matrix.decompose(replacement.position, replacement.quaternion, replacement.scale);
9411
9828
  replacement.matrixAutoUpdate = object.matrixAutoUpdate;
9412
9829
  replacement.visible = object.visible;
@@ -9448,7 +9865,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
9448
9865
  () => new FluidModelObject2(kind, surface.sample, this.blockState.key, this.options)
9449
9866
  );
9450
9867
  const previous = this._fluidModel;
9451
- const matrix = previous ? this.getModelMatrix(previous) : new import_three31.Matrix4().makeTranslation(...this.position.toArray());
9868
+ const matrix = previous ? this.getModelMatrix(previous) : new import_three30.Matrix4().makeTranslation(...this.position.toArray());
9452
9869
  if (isInstanceReference(replacement)) replacement.setMatrix(matrix);
9453
9870
  else matrix.decompose(replacement.position, replacement.quaternion, replacement.scale);
9454
9871
  this._models = this._models.filter((model) => model !== previous);
@@ -9590,7 +10007,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
9590
10007
  setPositionRotationScaleAt(index, position, rotation, scale) {
9591
10008
  super.setPositionRotationScaleAt(index, position, rotation, scale);
9592
10009
  }
9593
- getMatrixAt(index, matrix = new import_three31.Matrix4()) {
10010
+ getMatrixAt(index, matrix = new import_three30.Matrix4()) {
9594
10011
  if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
9595
10012
  const child = this._models[0];
9596
10013
  if (child && isModelObject(child)) {
@@ -11466,7 +11883,7 @@ init_ModelObject();
11466
11883
  init_nbt();
11467
11884
 
11468
11885
  // src/renderer/MineRenderScene.ts
11469
- var import_three33 = require("three");
11886
+ var import_three32 = require("three");
11470
11887
  init_SceneObject();
11471
11888
  var import_ts_deepmerge8 = __toESM(require_dist());
11472
11889
  init_ModelObject();
@@ -12199,7 +12616,7 @@ var import_ts_deepmerge7 = __toESM(require_dist());
12199
12616
  init_util();
12200
12617
 
12201
12618
  // src/skin/SkinTextures.ts
12202
- var import_three32 = require("three");
12619
+ var import_three31 = require("three");
12203
12620
  init_Caching();
12204
12621
  init_CacheKey();
12205
12622
  init_MineRenderError();
@@ -12283,11 +12700,11 @@ var SkinTextures = class {
12283
12700
  });
12284
12701
  }
12285
12702
  static createMaterial(pixels, width, height, transparent = true) {
12286
- const texture = Textures.initTextureProps(new import_three32.DataTexture(pixels, width, height));
12287
- texture.colorSpace = import_three32.SRGBColorSpace;
12703
+ const texture = Textures.initTextureProps(new import_three31.DataTexture(pixels, width, height));
12704
+ texture.colorSpace = import_three31.SRGBColorSpace;
12288
12705
  texture.flipY = true;
12289
12706
  texture.needsUpdate = true;
12290
- return new import_three32.MeshBasicMaterial({ map: texture, transparent, side: transparent ? import_three32.DoubleSide : import_three32.FrontSide, alphaTest: transparent ? 0.1 : 0 });
12707
+ return new import_three31.MeshBasicMaterial({ map: texture, transparent, side: transparent ? import_three31.DoubleSide : import_three31.FrontSide, alphaTest: transparent ? 0.1 : 0 });
12291
12708
  }
12292
12709
  static isSlim(image, scale) {
12293
12710
  for (const [x, y] of [[46, 52], [54, 20]]) {
@@ -12517,7 +12934,7 @@ var SkinObject = class extends SceneObject {
12517
12934
  // src/renderer/MineRenderScene.ts
12518
12935
  init_EntityObject();
12519
12936
  init_ItemTints();
12520
- var _MineRenderScene = class _MineRenderScene extends import_three33.Scene {
12937
+ var _MineRenderScene = class _MineRenderScene extends import_three32.Scene {
12521
12938
  constructor(options) {
12522
12939
  super();
12523
12940
  this.isMineRenderScene = true;
@@ -12560,12 +12977,13 @@ var _MineRenderScene = class _MineRenderScene extends import_three33.Scene {
12560
12977
  }
12561
12978
  updateObjectRegistration(object, attached) {
12562
12979
  if (this.observedObjects.has(object) === attached) return;
12980
+ const observable = object;
12563
12981
  if (attached) {
12564
12982
  this.observedObjects.add(object);
12565
- object.addEventListener("change", this.onObjectChange);
12983
+ observable.addEventListener("change", this.onObjectChange);
12566
12984
  } else {
12567
12985
  this.observedObjects.delete(object);
12568
- object.removeEventListener("change", this.onObjectChange);
12986
+ observable.removeEventListener("change", this.onObjectChange);
12569
12987
  }
12570
12988
  const change = attached ? 1 : -1;
12571
12989
  this.stats.objectCount += change;
@@ -12645,7 +13063,7 @@ function isMineRenderScene(obj) {
12645
13063
  }
12646
13064
 
12647
13065
  // src/renderer/Renderer.ts
12648
- var import_three35 = require("three");
13066
+ var import_three34 = require("three");
12649
13067
  var import_ts_deepmerge9 = __toESM(require_dist());
12650
13068
  var import_stats = __toESM(require("stats.js"));
12651
13069
  var import_postprocessing = require("postprocessing");
@@ -12654,11 +13072,11 @@ init_Model();
12654
13072
  init_three();
12655
13073
 
12656
13074
  // src/three/OrbitControls.js
12657
- var import_three34 = require("three");
13075
+ var import_three33 = require("three");
12658
13076
  var _changeEvent = { type: "change" };
12659
13077
  var _startEvent = { type: "start" };
12660
13078
  var _endEvent = { type: "end" };
12661
- var OrbitControls = class extends import_three34.EventDispatcher {
13079
+ var OrbitControls = class extends import_three33.EventDispatcher {
12662
13080
  constructor(object, domElement) {
12663
13081
  super();
12664
13082
  if (domElement === void 0) console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.');
@@ -12667,7 +13085,7 @@ var OrbitControls = class extends import_three34.EventDispatcher {
12667
13085
  this.domElement = domElement;
12668
13086
  this.domElement.style.touchAction = "none";
12669
13087
  this.enabled = true;
12670
- this.target = new import_three34.Vector3();
13088
+ this.target = new import_three33.Vector3();
12671
13089
  this.minDistance = 0;
12672
13090
  this.maxDistance = Infinity;
12673
13091
  this.minZoom = 0;
@@ -12689,8 +13107,8 @@ var OrbitControls = class extends import_three34.EventDispatcher {
12689
13107
  this.autoRotate = false;
12690
13108
  this.autoRotateSpeed = 2;
12691
13109
  this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" };
12692
- this.mouseButtons = { LEFT: import_three34.MOUSE.ROTATE, MIDDLE: import_three34.MOUSE.DOLLY, RIGHT: import_three34.MOUSE.PAN };
12693
- this.touches = { ONE: import_three34.TOUCH.ROTATE, TWO: import_three34.TOUCH.DOLLY_PAN };
13110
+ this.mouseButtons = { LEFT: import_three33.MOUSE.ROTATE, MIDDLE: import_three33.MOUSE.DOLLY, RIGHT: import_three33.MOUSE.PAN };
13111
+ this.touches = { ONE: import_three33.TOUCH.ROTATE, TWO: import_three33.TOUCH.DOLLY_PAN };
12694
13112
  this.target0 = this.target.clone();
12695
13113
  this.position0 = this.object.position.clone();
12696
13114
  this.zoom0 = this.object.zoom;
@@ -12719,11 +13137,11 @@ var OrbitControls = class extends import_three34.EventDispatcher {
12719
13137
  state = STATE.NONE;
12720
13138
  };
12721
13139
  this.update = function() {
12722
- const offset = new import_three34.Vector3();
12723
- const quat = new import_three34.Quaternion().setFromUnitVectors(object.up, new import_three34.Vector3(0, 1, 0));
13140
+ const offset = new import_three33.Vector3();
13141
+ const quat = new import_three33.Quaternion().setFromUnitVectors(object.up, new import_three33.Vector3(0, 1, 0));
12724
13142
  const quatInverse = quat.clone().invert();
12725
- const lastPosition = new import_three34.Vector3();
12726
- const lastQuaternion = new import_three34.Quaternion();
13143
+ const lastPosition = new import_three33.Vector3();
13144
+ const lastQuaternion = new import_three33.Quaternion();
12727
13145
  const twoPI = 2 * Math.PI;
12728
13146
  return function update() {
12729
13147
  const position = scope.object.position;
@@ -12809,20 +13227,20 @@ var OrbitControls = class extends import_three34.EventDispatcher {
12809
13227
  };
12810
13228
  let state = STATE.NONE;
12811
13229
  const EPS = 1e-6;
12812
- const spherical = new import_three34.Spherical();
12813
- const sphericalDelta = new import_three34.Spherical();
13230
+ const spherical = new import_three33.Spherical();
13231
+ const sphericalDelta = new import_three33.Spherical();
12814
13232
  let scale = 1;
12815
- const panOffset = new import_three34.Vector3();
13233
+ const panOffset = new import_three33.Vector3();
12816
13234
  let zoomChanged = false;
12817
- const rotateStart = new import_three34.Vector2();
12818
- const rotateEnd = new import_three34.Vector2();
12819
- const rotateDelta = new import_three34.Vector2();
12820
- const panStart = new import_three34.Vector2();
12821
- const panEnd = new import_three34.Vector2();
12822
- const panDelta = new import_three34.Vector2();
12823
- const dollyStart = new import_three34.Vector2();
12824
- const dollyEnd = new import_three34.Vector2();
12825
- const dollyDelta = new import_three34.Vector2();
13235
+ const rotateStart = new import_three33.Vector2();
13236
+ const rotateEnd = new import_three33.Vector2();
13237
+ const rotateDelta = new import_three33.Vector2();
13238
+ const panStart = new import_three33.Vector2();
13239
+ const panEnd = new import_three33.Vector2();
13240
+ const panDelta = new import_three33.Vector2();
13241
+ const dollyStart = new import_three33.Vector2();
13242
+ const dollyEnd = new import_three33.Vector2();
13243
+ const dollyDelta = new import_three33.Vector2();
12826
13244
  const pointers = [];
12827
13245
  const pointerPositions = {};
12828
13246
  function getAutoRotationAngle() {
@@ -12838,7 +13256,7 @@ var OrbitControls = class extends import_three34.EventDispatcher {
12838
13256
  sphericalDelta.phi -= angle;
12839
13257
  }
12840
13258
  const panLeft = function() {
12841
- const v = new import_three34.Vector3();
13259
+ const v = new import_three33.Vector3();
12842
13260
  return function panLeft2(distance, objectMatrix) {
12843
13261
  v.setFromMatrixColumn(objectMatrix, 0);
12844
13262
  v.multiplyScalar(-distance);
@@ -12846,7 +13264,7 @@ var OrbitControls = class extends import_three34.EventDispatcher {
12846
13264
  };
12847
13265
  }();
12848
13266
  const panUp = function() {
12849
- const v = new import_three34.Vector3();
13267
+ const v = new import_three33.Vector3();
12850
13268
  return function panUp2(distance, objectMatrix) {
12851
13269
  if (scope.screenSpacePanning === true) {
12852
13270
  v.setFromMatrixColumn(objectMatrix, 1);
@@ -12859,7 +13277,7 @@ var OrbitControls = class extends import_three34.EventDispatcher {
12859
13277
  };
12860
13278
  }();
12861
13279
  const pan = function() {
12862
- const offset = new import_three34.Vector3();
13280
+ const offset = new import_three33.Vector3();
12863
13281
  return function pan2(deltaX, deltaY) {
12864
13282
  const element = scope.domElement;
12865
13283
  if (scope.object.isPerspectiveCamera) {
@@ -13108,12 +13526,12 @@ var OrbitControls = class extends import_three34.EventDispatcher {
13108
13526
  mouseAction = -1;
13109
13527
  }
13110
13528
  switch (mouseAction) {
13111
- case import_three34.MOUSE.DOLLY:
13529
+ case import_three33.MOUSE.DOLLY:
13112
13530
  if (scope.enableZoom === false) return;
13113
13531
  handleMouseDownDolly(event);
13114
13532
  state = STATE.DOLLY;
13115
13533
  break;
13116
- case import_three34.MOUSE.ROTATE:
13534
+ case import_three33.MOUSE.ROTATE:
13117
13535
  if (event.ctrlKey || event.metaKey || event.shiftKey) {
13118
13536
  if (scope.enablePan === false) return;
13119
13537
  handleMouseDownPan(event);
@@ -13124,7 +13542,7 @@ var OrbitControls = class extends import_three34.EventDispatcher {
13124
13542
  state = STATE.ROTATE;
13125
13543
  }
13126
13544
  break;
13127
- case import_three34.MOUSE.PAN:
13545
+ case import_three33.MOUSE.PAN:
13128
13546
  if (event.ctrlKey || event.metaKey || event.shiftKey) {
13129
13547
  if (scope.enableRotate === false) return;
13130
13548
  handleMouseDownRotate(event);
@@ -13180,12 +13598,12 @@ var OrbitControls = class extends import_three34.EventDispatcher {
13180
13598
  switch (pointers.length) {
13181
13599
  case 1:
13182
13600
  switch (scope.touches.ONE) {
13183
- case import_three34.TOUCH.ROTATE:
13601
+ case import_three33.TOUCH.ROTATE:
13184
13602
  if (scope.enableRotate === false) return;
13185
13603
  handleTouchStartRotate();
13186
13604
  state = STATE.TOUCH_ROTATE;
13187
13605
  break;
13188
- case import_three34.TOUCH.PAN:
13606
+ case import_three33.TOUCH.PAN:
13189
13607
  if (scope.enablePan === false) return;
13190
13608
  handleTouchStartPan();
13191
13609
  state = STATE.TOUCH_PAN;
@@ -13196,12 +13614,12 @@ var OrbitControls = class extends import_three34.EventDispatcher {
13196
13614
  break;
13197
13615
  case 2:
13198
13616
  switch (scope.touches.TWO) {
13199
- case import_three34.TOUCH.DOLLY_PAN:
13617
+ case import_three33.TOUCH.DOLLY_PAN:
13200
13618
  if (scope.enableZoom === false && scope.enablePan === false) return;
13201
13619
  handleTouchStartDollyPan();
13202
13620
  state = STATE.TOUCH_DOLLY_PAN;
13203
13621
  break;
13204
- case import_three34.TOUCH.DOLLY_ROTATE:
13622
+ case import_three33.TOUCH.DOLLY_ROTATE:
13205
13623
  if (scope.enableZoom === false && scope.enableRotate === false) return;
13206
13624
  handleTouchStartDollyRotate();
13207
13625
  state = STATE.TOUCH_DOLLY_ROTATE;
@@ -13268,7 +13686,7 @@ var OrbitControls = class extends import_three34.EventDispatcher {
13268
13686
  function trackPointer(event) {
13269
13687
  let position = pointerPositions[event.pointerId];
13270
13688
  if (position === void 0) {
13271
- position = new import_three34.Vector2();
13689
+ position = new import_three33.Vector2();
13272
13690
  pointerPositions[event.pointerId] = position;
13273
13691
  }
13274
13692
  position.set(event.pageX, event.pageY);
@@ -13288,10 +13706,10 @@ var MapControls = class extends OrbitControls {
13288
13706
  constructor(object, domElement) {
13289
13707
  super(object, domElement);
13290
13708
  this.screenSpacePanning = false;
13291
- this.mouseButtons.LEFT = import_three34.MOUSE.PAN;
13292
- this.mouseButtons.RIGHT = import_three34.MOUSE.ROTATE;
13293
- this.touches.ONE = import_three34.TOUCH.PAN;
13294
- this.touches.TWO = import_three34.TOUCH.DOLLY_ROTATE;
13709
+ this.mouseButtons.LEFT = import_three33.MOUSE.PAN;
13710
+ this.mouseButtons.RIGHT = import_three33.MOUSE.ROTATE;
13711
+ this.touches.ONE = import_three33.TOUCH.PAN;
13712
+ this.touches.TWO = import_three33.TOUCH.DOLLY_ROTATE;
13295
13713
  }
13296
13714
  };
13297
13715
 
@@ -13342,14 +13760,14 @@ var _Renderer = class _Renderer {
13342
13760
  switch (this.options.camera.type) {
13343
13761
  case "perspective":
13344
13762
  default:
13345
- return new import_three35.PerspectiveCamera(
13763
+ return new import_three34.PerspectiveCamera(
13346
13764
  this.options.camera.perspective.fov,
13347
13765
  this.options.camera.perspective.aspect ?? this.viewWidth / this.viewHeight,
13348
13766
  this.options.camera.near,
13349
13767
  this.options.camera.far
13350
13768
  );
13351
13769
  case "orthographic":
13352
- return new import_three35.OrthographicCamera(
13770
+ return new import_three34.OrthographicCamera(
13353
13771
  this.options.camera.orthographic.left ?? this.viewWidth / -2,
13354
13772
  this.options.camera.orthographic.right ?? this.viewWidth / 2,
13355
13773
  this.options.camera.orthographic.top ?? this.viewHeight / 2,
@@ -13360,7 +13778,7 @@ var _Renderer = class _Renderer {
13360
13778
  }
13361
13779
  }
13362
13780
  createRenderer() {
13363
- const renderer = new import_three35.WebGLRenderer({
13781
+ const renderer = new import_three34.WebGLRenderer({
13364
13782
  antialias: this.options.render.antialias,
13365
13783
  alpha: true,
13366
13784
  powerPreference: "high-performance",
@@ -13368,8 +13786,8 @@ var _Renderer = class _Renderer {
13368
13786
  });
13369
13787
  renderer.setClearColor(0, 0);
13370
13788
  renderer.shadowMap.enabled = true;
13371
- renderer.shadowMap.type = import_three35.PCFSoftShadowMap;
13372
- renderer.outputColorSpace = import_three35.SRGBColorSpace;
13789
+ renderer.shadowMap.type = import_three34.PCFShadowMap;
13790
+ renderer.outputColorSpace = import_three34.SRGBColorSpace;
13373
13791
  renderer.setPixelRatio(this.options.render.pixelRatio ?? 1);
13374
13792
  renderer.setSize(this.viewWidth, this.viewHeight);
13375
13793
  return renderer;
@@ -13404,20 +13822,20 @@ var _Renderer = class _Renderer {
13404
13822
  window["__THREE_DEVTOOLS__"].dispatchEvent(new CustomEvent("observe", { detail: this.scene }));
13405
13823
  }
13406
13824
  if (this.options.debug.grid) {
13407
- const gridHelper = new import_three35.GridHelper(128, 16);
13825
+ const gridHelper = new import_three34.GridHelper(128, 16);
13408
13826
  this._debugHelpers.push(gridHelper);
13409
13827
  this.scene.add(gridHelper);
13410
- const gridHelper2 = new import_three35.GridHelper(128, 16);
13828
+ const gridHelper2 = new import_three34.GridHelper(128, 16);
13411
13829
  this._debugHelpers.push(gridHelper2);
13412
13830
  gridHelper2.rotation.x = 90 * (Math.PI / 180);
13413
13831
  this.scene.add(gridHelper2);
13414
- const gridHelper3 = new import_three35.GridHelper(128, 16);
13832
+ const gridHelper3 = new import_three34.GridHelper(128, 16);
13415
13833
  this._debugHelpers.push(gridHelper3);
13416
13834
  gridHelper3.rotation.z = 90 * (Math.PI / 180);
13417
13835
  this.scene.add(gridHelper3);
13418
13836
  }
13419
13837
  if (this.options.debug.axes) {
13420
- const axesHelper = new import_three35.AxesHelper(64);
13838
+ const axesHelper = new import_three34.AxesHelper(64);
13421
13839
  this._debugHelpers.push(axesHelper);
13422
13840
  this.scene.add(axesHelper);
13423
13841
  }
@@ -13676,8 +14094,8 @@ _Renderer.DEFAULT_OPTIONS = (0, import_ts_deepmerge9.default)({}, {
13676
14094
  top: void 0,
13677
14095
  bottom: void 0
13678
14096
  },
13679
- position: new import_three35.Vector3(50, 50, 50),
13680
- lookingAt: new import_three35.Vector3(0, 0, 0)
14097
+ position: new import_three34.Vector3(50, 50, 50),
14098
+ lookingAt: new import_three34.Vector3(0, 0, 0)
13681
14099
  },
13682
14100
  render: {
13683
14101
  fpsLimit: 60,
@@ -14142,12 +14560,12 @@ var AnvilParser = class {
14142
14560
  };
14143
14561
 
14144
14562
  // src/world/Chunk.ts
14145
- var import_three40 = require("three");
14563
+ var import_three39 = require("three");
14146
14564
  init_BlockStates();
14147
14565
  init_AssetKey();
14148
14566
 
14149
14567
  // src/world/MineRenderWorld.ts
14150
- var import_three38 = require("three");
14568
+ var import_three37 = require("three");
14151
14569
  init_Model();
14152
14570
  init_BatchedExecutor();
14153
14571
  init_AssetKey();
@@ -14155,7 +14573,7 @@ init_BlockStates();
14155
14573
  init_CubeFace();
14156
14574
 
14157
14575
  // src/world/SectionModels.ts
14158
- var import_three37 = require("three");
14576
+ var import_three36 = require("three");
14159
14577
  init_AssetKey();
14160
14578
  init_Models();
14161
14579
  init_CubeFace();
@@ -14221,12 +14639,12 @@ var SectionModels = class {
14221
14639
  });
14222
14640
  await object.init();
14223
14641
  const geometry = object.children[0].geometry;
14224
- geometry.applyMatrix4(new import_three37.Matrix4().makeRotationFromEuler(rotation));
14642
+ geometry.applyMatrix4(new import_three36.Matrix4().makeRotationFromEuler(rotation));
14225
14643
  object.clear();
14226
14644
  const cullFaces = CUBE_FACES.map((face) => {
14227
14645
  const local = CUBE_FACES.findIndex((name) => name === atlas.model.elements[0].faces[face]?.cullface);
14228
14646
  if (local < 0) return 0;
14229
- const normal = new import_three37.Vector3(...CUBE_FACE_OFFSETS[local]).applyEuler(rotation);
14647
+ const normal = new import_three36.Vector3(...CUBE_FACE_OFFSETS[local]).applyEuler(rotation);
14230
14648
  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);
14231
14649
  return 1 << world;
14232
14650
  });
@@ -14256,20 +14674,20 @@ var MineRenderWorld = class {
14256
14674
  }
14257
14675
  getBlockAt(posOrX, y, z) {
14258
14676
  if (typeof posOrX == "number") {
14259
- return this.getBlockAt(new import_three38.Vector3(posOrX, y, z));
14677
+ return this.getBlockAt(new import_three37.Vector3(posOrX, y, z));
14260
14678
  }
14261
14679
  if (isTripleArray(posOrX)) {
14262
- return this.getBlockAt(new import_three38.Vector3(posOrX[0], posOrX[1], posOrX[2]));
14680
+ return this.getBlockAt(new import_three37.Vector3(posOrX[0], posOrX[1], posOrX[2]));
14263
14681
  }
14264
14682
  this.validatePosBounds(posOrX);
14265
14683
  return this.getChunkAt(posOrX)?.getBlockAt(posOrX);
14266
14684
  }
14267
14685
  async setBlockAt(posOrX, yOrBlock, z, block) {
14268
14686
  if (typeof posOrX == "number") {
14269
- return this.setBlockAt(new import_three38.Vector3(posOrX, yOrBlock, z), block);
14687
+ return this.setBlockAt(new import_three37.Vector3(posOrX, yOrBlock, z), block);
14270
14688
  }
14271
14689
  if (isTripleArray(posOrX)) {
14272
- return this.setBlockAt(new import_three38.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
14690
+ return this.setBlockAt(new import_three37.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
14273
14691
  }
14274
14692
  return this.placeBlock(posOrX, yOrBlock);
14275
14693
  }
@@ -14280,10 +14698,10 @@ var MineRenderWorld = class {
14280
14698
  }
14281
14699
  async setBlockVisibleAt(posOrX, yOrVisible, z, visible) {
14282
14700
  if (typeof posOrX === "number") {
14283
- return this.setBlockVisibleAt(new import_three38.Vector3(posOrX, yOrVisible, z), visible);
14701
+ return this.setBlockVisibleAt(new import_three37.Vector3(posOrX, yOrVisible, z), visible);
14284
14702
  }
14285
14703
  if (isTripleArray(posOrX)) {
14286
- return this.setBlockVisibleAt(new import_three38.Vector3(...posOrX), yOrVisible);
14704
+ return this.setBlockVisibleAt(new import_three37.Vector3(...posOrX), yOrVisible);
14287
14705
  }
14288
14706
  this.validatePosBounds(posOrX);
14289
14707
  await this.getChunkAt(posOrX)?.setBlockVisibleAt(posOrX, yOrVisible);
@@ -14300,7 +14718,7 @@ var MineRenderWorld = class {
14300
14718
  const collect = async (positions2) => {
14301
14719
  for (const pos of positions2) changes.set(pos.toArray().join(","), pos);
14302
14720
  };
14303
- const place = (block) => this.placeBlock(new import_three38.Vector3(...block.position), block, collect);
14721
+ const place = (block) => this.placeBlock(new import_three37.Vector3(...block.position), block, collect);
14304
14722
  const keys = /* @__PURE__ */ new Map();
14305
14723
  for (const block of multiblock.blocks) {
14306
14724
  if (Chunk.isAir(block)) continue;
@@ -14378,13 +14796,13 @@ var MineRenderWorld = class {
14378
14796
  for (const pos of positions) {
14379
14797
  this.pendingCulling.set(pos.toArray().join(","), pos.clone());
14380
14798
  for (const offset of CUBE_FACE_OFFSETS) {
14381
- const neighbor = pos.clone().add(new import_three38.Vector3(...offset));
14799
+ const neighbor = pos.clone().add(new import_three37.Vector3(...offset));
14382
14800
  this.pendingCulling.set(neighbor.toArray().join(","), neighbor);
14383
14801
  }
14384
14802
  for (let y = -1; y <= 1; y++) {
14385
14803
  for (let z = -1; z <= 1; z++) {
14386
14804
  for (let x = -1; x <= 1; x++) {
14387
- const neighbor = pos.clone().add(new import_three38.Vector3(x, y, z));
14805
+ const neighbor = pos.clone().add(new import_three37.Vector3(x, y, z));
14388
14806
  if (this.getBlockAt(neighbor)?.object?.fluidKind) {
14389
14807
  this.pendingCulling.set(neighbor.toArray().join(","), neighbor);
14390
14808
  }
@@ -14408,7 +14826,7 @@ var MineRenderWorld = class {
14408
14826
  }
14409
14827
  if (block.object?.fluidKind) {
14410
14828
  await block.object.updateFluid((x, y, z) => {
14411
- const neighbor = pos.clone().add(new import_three38.Vector3(x, y, z));
14829
+ const neighbor = pos.clone().add(new import_three37.Vector3(x, y, z));
14412
14830
  const section = this.getChunkAt(neighbor);
14413
14831
  const object = section?.isBlockVisibleAt(neighbor) ? section.getBlockAt(neighbor)?.object : void 0;
14414
14832
  return {
@@ -14420,7 +14838,7 @@ var MineRenderWorld = class {
14420
14838
  }
14421
14839
  let mask = 0;
14422
14840
  for (const [face, offset] of CUBE_FACE_OFFSETS.entries()) {
14423
- const neighbor = pos.clone().add(new import_three38.Vector3(...offset));
14841
+ const neighbor = pos.clone().add(new import_three37.Vector3(...offset));
14424
14842
  if (this.getChunkAt(neighbor)?.isOccludingAt(neighbor)) {
14425
14843
  mask |= 1 << face;
14426
14844
  }
@@ -14454,14 +14872,14 @@ var MineRenderWorld = class {
14454
14872
  return this._chunks.get(this.worldPosToChunkKey(pos));
14455
14873
  }
14456
14874
  static worldToScenePosition(pos) {
14457
- return new import_three38.Vector3(
14875
+ return new import_three37.Vector3(
14458
14876
  pos.x * 16,
14459
14877
  pos.y * 16,
14460
14878
  pos.z * 16
14461
14879
  );
14462
14880
  }
14463
14881
  static sceneToWorldPosition(pos) {
14464
- return new import_three38.Vector3(
14882
+ return new import_three37.Vector3(
14465
14883
  pos.x / 16,
14466
14884
  pos.y / 16,
14467
14885
  pos.z / 16
@@ -14484,10 +14902,10 @@ var MineRenderWorld = class {
14484
14902
  init_Model();
14485
14903
 
14486
14904
  // src/world/SectionMesh.ts
14487
- var import_three39 = require("three");
14905
+ var import_three38 = require("three");
14488
14906
  init_CanvasCompat();
14489
14907
  init_Materials();
14490
- var SectionMesh = class _SectionMesh extends import_three39.Group {
14908
+ var SectionMesh = class _SectionMesh extends import_three38.Group {
14491
14909
  constructor() {
14492
14910
  super(...arguments);
14493
14911
  this.ownedMeshes = [];
@@ -14560,18 +14978,18 @@ var SectionMesh = class _SectionMesh extends import_three39.Group {
14560
14978
  for (let corner = 0; corner < 6; corner++) indices.push(start + sourceIndices.getX(face * 6 + corner) - face * 4);
14561
14979
  }
14562
14980
  }
14563
- const geometry = new import_three39.BufferGeometry();
14564
- geometry.setAttribute("position", new import_three39.Float32BufferAttribute(positions, 3));
14565
- geometry.setAttribute("normal", new import_three39.Float32BufferAttribute(normals, 3));
14566
- geometry.setAttribute("uv", new import_three39.Float32BufferAttribute(uvs, 2));
14567
- geometry.setAttribute("color", new import_three39.Float32BufferAttribute(colors, 3));
14981
+ const geometry = new import_three38.BufferGeometry();
14982
+ geometry.setAttribute("position", new import_three38.Float32BufferAttribute(positions, 3));
14983
+ geometry.setAttribute("normal", new import_three38.Float32BufferAttribute(normals, 3));
14984
+ geometry.setAttribute("uv", new import_three38.Float32BufferAttribute(uvs, 2));
14985
+ geometry.setAttribute("color", new import_three38.Float32BufferAttribute(colors, 3));
14568
14986
  geometry.setIndex(indices);
14569
14987
  geometry.computeBoundingBox();
14570
14988
  geometry.computeBoundingSphere();
14571
14989
  const material = Materials.createShadedCanvasMaterial(canvas, false);
14572
14990
  material.vertexColors = true;
14573
14991
  const texture = material.uniforms?.map?.value ?? material.map;
14574
- const mesh = new import_three39.Mesh(geometry, material);
14992
+ const mesh = new import_three38.Mesh(geometry, material);
14575
14993
  section.add(mesh);
14576
14994
  section.ownedMeshes.push({ mesh, texture });
14577
14995
  }
@@ -14585,6 +15003,7 @@ var SectionMesh = class _SectionMesh extends import_three39.Group {
14585
15003
  texture?.dispose();
14586
15004
  }
14587
15005
  this.removeFromParent();
15006
+ super.dispose();
14588
15007
  }
14589
15008
  };
14590
15009
 
@@ -14606,10 +15025,10 @@ var Chunk = class _Chunk {
14606
15025
  }
14607
15026
  getBlockAt(posOrX, y, z) {
14608
15027
  if (typeof posOrX == "number") {
14609
- return this.getBlockAt(new import_three40.Vector3(posOrX, y, z));
15028
+ return this.getBlockAt(new import_three39.Vector3(posOrX, y, z));
14610
15029
  }
14611
15030
  if (isTripleArray(posOrX)) {
14612
- return this.getBlockAt(new import_three40.Vector3(posOrX[0], posOrX[1], posOrX[2]));
15031
+ return this.getBlockAt(new import_three39.Vector3(posOrX[0], posOrX[1], posOrX[2]));
14613
15032
  }
14614
15033
  const pos = this.worldPosToChunkPos(posOrX);
14615
15034
  const index = _Chunk.chunkPosToBlockIndex(pos);
@@ -14617,10 +15036,10 @@ var Chunk = class _Chunk {
14617
15036
  }
14618
15037
  async setBlockAt(posOrX, yOrBlock, z, block) {
14619
15038
  if (typeof posOrX == "number") {
14620
- return this.setBlockAt(new import_three40.Vector3(posOrX, yOrBlock, z), block);
15039
+ return this.setBlockAt(new import_three39.Vector3(posOrX, yOrBlock, z), block);
14621
15040
  }
14622
15041
  if (isTripleArray(posOrX)) {
14623
- return this.setBlockAt(new import_three40.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
15042
+ return this.setBlockAt(new import_three39.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
14624
15043
  }
14625
15044
  const worldPos = posOrX;
14626
15045
  const pos = this.worldPosToChunkPos(worldPos);
@@ -14732,7 +15151,7 @@ var Chunk = class _Chunk {
14732
15151
  }
14733
15152
  async clear(onBlocksChanged = this.onBlocksChanged) {
14734
15153
  const positions = [...this.renderedBlocks.keys()].map((index) => this.chunkPosToWorldPos(
14735
- new import_three40.Vector3(index % 16, Math.floor(index / 256), Math.floor(index / 16) % 16)
15154
+ new import_three39.Vector3(index % 16, Math.floor(index / 256), Math.floor(index / 16) % 16)
14736
15155
  ));
14737
15156
  for (const info of this.renderedBlocks.values()) info.object?.removeFromScene();
14738
15157
  this.sectionBlocks.clear();
@@ -14757,14 +15176,14 @@ var Chunk = class _Chunk {
14757
15176
  return pos.y * 16 * 16 + pos.z * 16 + pos.x;
14758
15177
  }
14759
15178
  worldPosToChunkPos(pos) {
14760
- return new import_three40.Vector3(
15179
+ return new import_three39.Vector3(
14761
15180
  pos.x - this.x * 16,
14762
15181
  pos.y - this.y * 16,
14763
15182
  pos.z - this.z * 16
14764
15183
  );
14765
15184
  }
14766
15185
  chunkPosToWorldPos(pos) {
14767
- return new import_three40.Vector3(
15186
+ return new import_three39.Vector3(
14768
15187
  this.x * 16 + pos.x,
14769
15188
  this.y * 16 + pos.y,
14770
15189
  this.z * 16 + pos.z