minerender 2.1.0-alpha.141 → 2.1.0-alpha.143

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.
package/dist/bundle.js CHANGED
@@ -4852,7 +4852,7 @@ var MineRender = (() => {
4852
4852
  }
4853
4853
  throw new Error(`THREE.TextureUtils: Unknown texture type ${type}.`);
4854
4854
  }
4855
- var REVISION, MOUSE, TOUCH, CullFaceNone, CullFaceBack, CullFaceFront, PCFShadowMap, PCFSoftShadowMap, VSMShadowMap, FrontSide, BackSide, DoubleSide, NoBlending, NormalBlending, AdditiveBlending, SubtractiveBlending, MultiplyBlending, CustomBlending, AddEquation, SubtractEquation, ReverseSubtractEquation, MinEquation, MaxEquation, ZeroFactor, OneFactor, SrcColorFactor, OneMinusSrcColorFactor, SrcAlphaFactor, OneMinusSrcAlphaFactor, DstAlphaFactor, OneMinusDstAlphaFactor, DstColorFactor, OneMinusDstColorFactor, SrcAlphaSaturateFactor, ConstantColorFactor, OneMinusConstantColorFactor, ConstantAlphaFactor, OneMinusConstantAlphaFactor, NeverDepth, AlwaysDepth, LessDepth, LessEqualDepth, EqualDepth, GreaterEqualDepth, GreaterDepth, NotEqualDepth, MultiplyOperation, MixOperation, AddOperation, NoToneMapping, LinearToneMapping, ReinhardToneMapping, CineonToneMapping, ACESFilmicToneMapping, CustomToneMapping, AgXToneMapping, NeutralToneMapping, UVMapping, CubeReflectionMapping, CubeRefractionMapping, EquirectangularReflectionMapping, EquirectangularRefractionMapping, CubeUVReflectionMapping, RepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping, NearestFilter, NearestMipmapNearestFilter, NearestMipmapLinearFilter, LinearFilter, LinearMipmapNearestFilter, LinearMipmapLinearFilter, UnsignedByteType, ByteType, ShortType, UnsignedShortType, IntType, UnsignedIntType, FloatType, HalfFloatType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedInt248Type, UnsignedInt5999Type, UnsignedInt101111Type, AlphaFormat, RGBFormat, RGBAFormat, DepthFormat, DepthStencilFormat, RedFormat, RedIntegerFormat, RGFormat, RGIntegerFormat, RGBAIntegerFormat, RGB_S3TC_DXT1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGB_PVRTC_4BPPV1_Format, RGB_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_PVRTC_2BPPV1_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGBA_ETC2_EAC_Format, R11_EAC_Format, SIGNED_R11_EAC_Format, RG11_EAC_Format, SIGNED_RG11_EAC_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_BPTC_Format, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RED_RGTC1_Format, SIGNED_RED_RGTC1_Format, RED_GREEN_RGTC2_Format, SIGNED_RED_GREEN_RGTC2_Format, InterpolateDiscrete, InterpolateLinear, InterpolateSmooth, InterpolateBezier, ZeroCurvatureEnding, ZeroSlopeEnding, WrapAroundEnding, TrianglesDrawMode, TriangleStripDrawMode, TriangleFanDrawMode, BasicDepthPacking, TangentSpaceNormalMap, ObjectSpaceNormalMap, NoColorSpace, SRGBColorSpace, LinearSRGBColorSpace, LinearTransfer, SRGBTransfer, KeepStencilOp, AlwaysStencilFunc, NeverCompare, LessCompare, EqualCompare, LessEqualCompare, GreaterCompare, NotEqualCompare, GreaterEqualCompare, AlwaysCompare, StaticDrawUsage, GLSL3, WebGLCoordinateSystem, WebGPUCoordinateSystem, _cache, _setConsoleFunction, ReversedDepthFuncs, EventDispatcher, _lut, _seed, DEG2RAD, RAD2DEG, MathUtils, _Vector2, Vector2, Quaternion, _Vector3, Vector3, _vector$c, _quaternion$5, _Matrix3, Matrix3, _m3, LINEAR_REC709_TO_XYZ, XYZ_TO_LINEAR_REC709, ColorManagement, _canvas, ImageUtils, _sourceId, TextureSource, _textureId, _tempVec3, Texture, _Vector4, Vector4, RenderTarget, WebGLRenderTarget, DataArrayTexture, Data3DTexture, _Matrix4, Matrix4, _v1$7, _m1$2, _zero, _one, _x, _y, _z, _matrix$2, _quaternion$4, Euler, Layers, _object3DId, _v1$6, _q1, _m1$1, _target, _position$4, _scale$3, _quaternion$3, _xAxis, _yAxis, _zAxis, _addedEvent, _removedEvent, _childaddedEvent, _childremovedEvent, Object3D, Group, _moveEvent, WebXRController, _colorKeywords, _hslA, _hslB, Color, _color, Scene, _v0$2, _v1$5, _v2$4, _v3$2, _vab, _vac, _vbc, _vap, _vbp, _vcp, _v40, _v41, _v42, Triangle, Box3, _points, _vector$b, _box$4, _v0$1, _v1$4, _v2$3, _f0, _f1, _f2, _center, _extents, _triangleNormal, _testAxis, _vector$a, _vector2$1, _id$2, BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute, Float32BufferAttribute, _box$3, _v1$3, _v2$2, Sphere, _id$1, _m1, _obj, _offset, _box$2, _boxMorphTargets, _vector$9, BufferGeometry, InterleavedBuffer, _vector$8, InterleavedBufferAttribute, _vector1, _vector2, _normalMatrix, Plane, _materialId, Material, _vector$7, _segCenter, _segDir, _diff, Ray, MeshBasicMaterial, _inverseMatrix$3, _ray$3, _sphere$6, _sphereHitAt, _vA, _vB, _vC, _tempA, _morphA, _intersectionPoint, _intersectionPointWorld, Mesh, DataTexture, InstancedBufferAttribute, _instanceLocalMatrix, _instanceWorldMatrix, _instanceIntersects, _box3, _identity, _mesh$1, _sphere$4, InstancedMesh, _sphere$3, _defaultSpriteCenter, _vector$6, Frustum, LineBasicMaterial, _vStart, _vEnd, _inverseMatrix$1, _ray$1, _sphere$1, _intersectPointOnRay, _intersectPointOnSegment, Line, _start, _end, LineSegments, CompressedTexture, CubeTexture, CanvasTexture, DepthTexture, CubeDepthTexture, ExternalTexture, BoxGeometry, _v0, _v1$1, _normal, _triangle, EdgesGeometry, PlaneGeometry, UniformsUtils, default_vertex, default_fragment, ShaderMaterial, RawShaderMaterial, MeshStandardMaterial, MeshDepthMaterial, MeshDistanceMaterial, Interpolant, CubicInterpolant, LinearInterpolant, DiscreteInterpolant, BezierInterpolant, KeyframeTrack, BooleanKeyframeTrack, ColorKeyframeTrack, NumberKeyframeTrack, QuaternionLinearInterpolant, QuaternionKeyframeTrack, StringKeyframeTrack, VectorKeyframeTrack, LoadingManager, DefaultLoadingManager, Loader, _position$2, _quaternion$2, _scale$2, Camera, _v3$1, _minTarget, _maxTarget, PerspectiveCamera, OrthographicCamera, fov, aspect, CubeCamera, ArrayCamera, _RESERVED_CHARS_RE, _reservedRe, _wordChar, _wordCharOrDot, _directoryRe, _nodeRe, _objectRe, _propertyRe, _trackRe, _supportedObjectNames, Composite, PropertyBinding, _controlInterpolantsResultBuffer, Uniform, _matrix, Raycaster, Spherical, _Matrix2, Matrix2, _vector$4, Box2, GridHelper, AxesHelper, Controls;
4855
+ var REVISION, MOUSE, TOUCH, CullFaceNone, CullFaceBack, CullFaceFront, PCFShadowMap, PCFSoftShadowMap, VSMShadowMap, FrontSide, BackSide, DoubleSide, NoBlending, NormalBlending, AdditiveBlending, SubtractiveBlending, MultiplyBlending, CustomBlending, AddEquation, SubtractEquation, ReverseSubtractEquation, MinEquation, MaxEquation, ZeroFactor, OneFactor, SrcColorFactor, OneMinusSrcColorFactor, SrcAlphaFactor, OneMinusSrcAlphaFactor, DstAlphaFactor, OneMinusDstAlphaFactor, DstColorFactor, OneMinusDstColorFactor, SrcAlphaSaturateFactor, ConstantColorFactor, OneMinusConstantColorFactor, ConstantAlphaFactor, OneMinusConstantAlphaFactor, NeverDepth, AlwaysDepth, LessDepth, LessEqualDepth, EqualDepth, GreaterEqualDepth, GreaterDepth, NotEqualDepth, MultiplyOperation, MixOperation, AddOperation, NoToneMapping, LinearToneMapping, ReinhardToneMapping, CineonToneMapping, ACESFilmicToneMapping, CustomToneMapping, AgXToneMapping, NeutralToneMapping, UVMapping, CubeReflectionMapping, CubeRefractionMapping, EquirectangularReflectionMapping, EquirectangularRefractionMapping, CubeUVReflectionMapping, RepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping, NearestFilter, NearestMipmapNearestFilter, NearestMipmapLinearFilter, LinearFilter, LinearMipmapNearestFilter, LinearMipmapLinearFilter, UnsignedByteType, ByteType, ShortType, UnsignedShortType, IntType, UnsignedIntType, FloatType, HalfFloatType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedInt248Type, UnsignedInt5999Type, UnsignedInt101111Type, AlphaFormat, RGBFormat, RGBAFormat, DepthFormat, DepthStencilFormat, RedFormat, RedIntegerFormat, RGFormat, RGIntegerFormat, RGBAIntegerFormat, RGB_S3TC_DXT1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGB_PVRTC_4BPPV1_Format, RGB_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_PVRTC_2BPPV1_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGBA_ETC2_EAC_Format, R11_EAC_Format, SIGNED_R11_EAC_Format, RG11_EAC_Format, SIGNED_RG11_EAC_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_BPTC_Format, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RED_RGTC1_Format, SIGNED_RED_RGTC1_Format, RED_GREEN_RGTC2_Format, SIGNED_RED_GREEN_RGTC2_Format, InterpolateDiscrete, InterpolateLinear, InterpolateSmooth, InterpolateBezier, ZeroCurvatureEnding, ZeroSlopeEnding, WrapAroundEnding, TrianglesDrawMode, TriangleStripDrawMode, TriangleFanDrawMode, BasicDepthPacking, TangentSpaceNormalMap, ObjectSpaceNormalMap, NoColorSpace, SRGBColorSpace, LinearSRGBColorSpace, LinearTransfer, SRGBTransfer, KeepStencilOp, AlwaysStencilFunc, NeverCompare, LessCompare, EqualCompare, LessEqualCompare, GreaterCompare, NotEqualCompare, GreaterEqualCompare, AlwaysCompare, StaticDrawUsage, DynamicDrawUsage, GLSL3, WebGLCoordinateSystem, WebGPUCoordinateSystem, _cache, _setConsoleFunction, ReversedDepthFuncs, EventDispatcher, _lut, _seed, DEG2RAD, RAD2DEG, MathUtils, _Vector2, Vector2, Quaternion, _Vector3, Vector3, _vector$c, _quaternion$5, _Matrix3, Matrix3, _m3, LINEAR_REC709_TO_XYZ, XYZ_TO_LINEAR_REC709, ColorManagement, _canvas, ImageUtils, _sourceId, TextureSource, _textureId, _tempVec3, Texture, _Vector4, Vector4, RenderTarget, WebGLRenderTarget, DataArrayTexture, Data3DTexture, _Matrix4, Matrix4, _v1$7, _m1$2, _zero, _one, _x, _y, _z, _matrix$2, _quaternion$4, Euler, Layers, _object3DId, _v1$6, _q1, _m1$1, _target, _position$4, _scale$3, _quaternion$3, _xAxis, _yAxis, _zAxis, _addedEvent, _removedEvent, _childaddedEvent, _childremovedEvent, Object3D, Group, _moveEvent, WebXRController, _colorKeywords, _hslA, _hslB, Color, _color, Scene, _v0$2, _v1$5, _v2$4, _v3$2, _vab, _vac, _vbc, _vap, _vbp, _vcp, _v40, _v41, _v42, Triangle, Box3, _points, _vector$b, _box$4, _v0$1, _v1$4, _v2$3, _f0, _f1, _f2, _center, _extents, _triangleNormal, _testAxis, _vector$a, _vector2$1, _id$2, BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute, Float32BufferAttribute, _box$3, _v1$3, _v2$2, Sphere, _id$1, _m1, _obj, _offset, _box$2, _boxMorphTargets, _vector$9, BufferGeometry, InterleavedBuffer, _vector$8, InterleavedBufferAttribute, _vector1, _vector2, _normalMatrix, Plane, _materialId, Material, _vector$7, _segCenter, _segDir, _diff, Ray, MeshBasicMaterial, _inverseMatrix$3, _ray$3, _sphere$6, _sphereHitAt, _vA, _vB, _vC, _tempA, _morphA, _intersectionPoint, _intersectionPointWorld, Mesh, DataTexture, InstancedBufferAttribute, _instanceLocalMatrix, _instanceWorldMatrix, _instanceIntersects, _box3, _identity, _mesh$1, _sphere$4, InstancedMesh, _sphere$3, _defaultSpriteCenter, _vector$6, Frustum, LineBasicMaterial, _vStart, _vEnd, _inverseMatrix$1, _ray$1, _sphere$1, _intersectPointOnRay, _intersectPointOnSegment, Line, _start, _end, LineSegments, CompressedTexture, CubeTexture, CanvasTexture, DepthTexture, CubeDepthTexture, ExternalTexture, BoxGeometry, _v0, _v1$1, _normal, _triangle, EdgesGeometry, PlaneGeometry, UniformsUtils, default_vertex, default_fragment, ShaderMaterial, RawShaderMaterial, MeshStandardMaterial, MeshDepthMaterial, MeshDistanceMaterial, Interpolant, CubicInterpolant, LinearInterpolant, DiscreteInterpolant, BezierInterpolant, KeyframeTrack, BooleanKeyframeTrack, ColorKeyframeTrack, NumberKeyframeTrack, QuaternionLinearInterpolant, QuaternionKeyframeTrack, StringKeyframeTrack, VectorKeyframeTrack, LoadingManager, DefaultLoadingManager, Loader, _position$2, _quaternion$2, _scale$2, Camera, _v3$1, _minTarget, _maxTarget, PerspectiveCamera, OrthographicCamera, fov, aspect, CubeCamera, ArrayCamera, _RESERVED_CHARS_RE, _reservedRe, _wordChar, _wordCharOrDot, _directoryRe, _nodeRe, _objectRe, _propertyRe, _trackRe, _supportedObjectNames, Composite, PropertyBinding, _controlInterpolantsResultBuffer, Uniform, _matrix, Raycaster, Spherical, _Matrix2, Matrix2, _vector$4, Box2, GridHelper, AxesHelper, Controls;
4856
4856
  var init_three_core = __esm({
4857
4857
  "../../node_modules/three/build/three.core.js"() {
4858
4858
  init_dirname();
@@ -5018,6 +5018,7 @@ var MineRender = (() => {
5018
5018
  GreaterEqualCompare = 518;
5019
5019
  AlwaysCompare = 519;
5020
5020
  StaticDrawUsage = 35044;
5021
+ DynamicDrawUsage = 35048;
5021
5022
  GLSL3 = "300 es";
5022
5023
  WebGLCoordinateSystem = 2e3;
5023
5024
  WebGPUCoordinateSystem = 2001;
@@ -34067,8 +34068,6 @@ void main() {
34067
34068
  });
34068
34069
  }
34069
34070
  function yieldToEventLoop() {
34070
- const scheduler = globalThis.scheduler;
34071
- if (scheduler?.yield) return scheduler.yield();
34072
34071
  return new Promise((resolve) => {
34073
34072
  if (typeof MessageChannel !== "undefined") {
34074
34073
  const channel = new MessageChannel();
@@ -103866,6 +103865,7 @@ gl_FragDepth=readDepth(vUv);
103866
103865
  // src/world/MineRenderWorld.ts
103867
103866
  init_log();
103868
103867
  var log21 = logger("MineRenderWorld");
103868
+ var YIELD_INTERVAL_MS = 8;
103869
103869
  var MineRenderWorld = class {
103870
103870
  constructor(scene, options = {}) {
103871
103871
  this._chunks = /* @__PURE__ */ new Map();
@@ -103979,7 +103979,7 @@ gl_FragDepth=readDepth(vUv);
103979
103979
  failures.set(chunk, error2);
103980
103980
  if (this._chunks.get(`${chunk.x}_${chunk.y}_${chunk.z}`) === chunk) this.pendingBiomes.set(chunk, void 0);
103981
103981
  }
103982
- if (performance.now() - sliceStart > 8) {
103982
+ if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {
103983
103983
  await yieldToEventLoop();
103984
103984
  sliceStart = performance.now();
103985
103985
  }
@@ -104134,7 +104134,7 @@ gl_FragDepth=readDepth(vUv);
104134
104134
  )));
104135
104135
  for (const pos of positions) changes.set(`${pos.x},${pos.y},${pos.z}`, pos);
104136
104136
  }
104137
- if (performance.now() - sliceStart > 8) {
104137
+ if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {
104138
104138
  await yieldToEventLoop();
104139
104139
  sliceStart = performance.now();
104140
104140
  }
@@ -104142,6 +104142,62 @@ gl_FragDepth=readDepth(vUv);
104142
104142
  }
104143
104143
  /** Replaces a chunk column's blocks, biomes, and saved light and, with `renderEntities`, its supported saved mobs. */
104144
104144
  async placeChunk(chunk, executor) {
104145
+ return this.placeColumn(chunk, executor);
104146
+ }
104147
+ /**
104148
+ * Replaces parsed columns in input order, then refreshes neighboring geometry once.
104149
+ * Duplicate coordinates retain their order. A failed column stops placement; queued refreshes finish before rejection.
104150
+ */
104151
+ async placeChunks(chunks) {
104152
+ const columns = [];
104153
+ for (const chunk of chunks) {
104154
+ const { x: x4, z: z4 } = chunk ?? {};
104155
+ if (![x4, z4].every(Number.isSafeInteger)) {
104156
+ throw new RangeError("Chunk column coordinates must be safe integers");
104157
+ }
104158
+ const sections = Array.from(chunk.sections, (section) => {
104159
+ const { y: y5 } = section ?? {};
104160
+ if (!Number.isSafeInteger(y5)) throw new RangeError("Chunk section coordinates must be safe integers");
104161
+ return { ...section, y: y5 };
104162
+ });
104163
+ columns.push({ ...chunk, x: x4, z: z4, sections });
104164
+ }
104165
+ if (!columns.length) return;
104166
+ await this.culling;
104167
+ let failed = false, failure, sliceStart = performance.now();
104168
+ try {
104169
+ for (const column of columns) {
104170
+ await this.placeColumn(column, void 0, true);
104171
+ if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {
104172
+ await yieldToEventLoop();
104173
+ sliceStart = performance.now();
104174
+ }
104175
+ }
104176
+ } catch (error2) {
104177
+ failed = true;
104178
+ failure = error2;
104179
+ } finally {
104180
+ try {
104181
+ const failures = await this.refreshBiomes(true);
104182
+ if (failures.size) log21.warn("Failed to refresh biome colors", failures.values().next().value);
104183
+ } catch (error2) {
104184
+ if (!failed) {
104185
+ failed = true;
104186
+ failure = error2;
104187
+ }
104188
+ }
104189
+ try {
104190
+ await this.updateCulling([]);
104191
+ } catch (error2) {
104192
+ if (!failed) {
104193
+ failed = true;
104194
+ failure = error2;
104195
+ }
104196
+ }
104197
+ }
104198
+ if (failed) throw failure;
104199
+ }
104200
+ async placeColumn(chunk, executor, deferCulling = false) {
104145
104201
  if (![chunk.x, chunk.z].every(Number.isSafeInteger)) {
104146
104202
  throw new RangeError("Chunk column coordinates must be safe integers");
104147
104203
  }
@@ -104203,7 +104259,7 @@ gl_FragDepth=readDepth(vUv);
104203
104259
  } finally {
104204
104260
  this.markSectionChanged(target);
104205
104261
  }
104206
- if (performance.now() - sliceStart > 8) {
104262
+ if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {
104207
104263
  await yieldToEventLoop();
104208
104264
  sliceStart = performance.now();
104209
104265
  }
@@ -104226,9 +104282,12 @@ gl_FragDepth=readDepth(vUv);
104226
104282
  await placeEntities?.();
104227
104283
  } finally {
104228
104284
  this.markBiomesChanged(chunk.x, chunk.z, void 0, false);
104229
- const failures = await this.refreshBiomes();
104230
- if (failures.size) log21.warn("Failed to refresh biome colors", failures.values().next().value);
104231
- await this.updateCulling([...changes.values()]);
104285
+ if (deferCulling) await this.updateCulling([...changes.values()], true);
104286
+ else {
104287
+ const failures = await this.refreshBiomes();
104288
+ if (failures.size) log21.warn("Failed to refresh biome colors", failures.values().next().value);
104289
+ await this.updateCulling([...changes.values()]);
104290
+ }
104232
104291
  }
104233
104292
  }
104234
104293
  /**
@@ -104258,7 +104317,7 @@ gl_FragDepth=readDepth(vUv);
104258
104317
  for (const { x: x4, z: z4 } of columns.values()) {
104259
104318
  this.entities?.clearColumn(x4, z4);
104260
104319
  await this.clearChunkColumn(x4, z4);
104261
- if (performance.now() - sliceStart > 8) {
104320
+ if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {
104262
104321
  await yieldToEventLoop();
104263
104322
  sliceStart = performance.now();
104264
104323
  }
@@ -104397,15 +104456,25 @@ gl_FragDepth=readDepth(vUv);
104397
104456
  for (const [index, mask] of masks) await chunk.setCullMaskIndex(index, mask);
104398
104457
  await chunk.refreshLight(indices === "all" ? void 0 : indices);
104399
104458
  chunk.refreshAmbientOcclusion(this._ambientOcclusion);
104400
- if ((this._ambientOcclusion || this.ambientOcclusionPending) && performance.now() - sliceStart > 8) {
104459
+ if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {
104401
104460
  await yieldToEventLoop();
104402
104461
  sliceStart = performance.now();
104403
104462
  }
104404
104463
  }
104405
- const builds = await Promise.allSettled([...batch.keys()].map(async (chunk) => {
104406
- await chunk.rebuildSectionMesh();
104407
- batch.delete(chunk);
104408
- }));
104464
+ const pending = [];
104465
+ for (const chunk of [...batch.keys()]) {
104466
+ const build = (async () => {
104467
+ await chunk.rebuildSectionMesh();
104468
+ batch.delete(chunk);
104469
+ })();
104470
+ void build.catch(() => void 0);
104471
+ pending.push(build);
104472
+ if (performance.now() - sliceStart > YIELD_INTERVAL_MS) {
104473
+ await yieldToEventLoop();
104474
+ sliceStart = performance.now();
104475
+ }
104476
+ }
104477
+ const builds = await Promise.allSettled(pending);
104409
104478
  const failure = builds.find((result) => result.status === "rejected");
104410
104479
  if (failure?.status === "rejected") throw failure.reason;
104411
104480
  } catch (error2) {
@@ -104863,6 +104932,9 @@ gl_FragDepth=readDepth(vUv);
104863
104932
  var SectionWorker = _SectionWorker;
104864
104933
 
104865
104934
  // src/world/SectionMesh.ts
104935
+ var BLOCK_SIZE = 16;
104936
+ var QUAD_VERTICES = 4;
104937
+ var QUAD_INDICES = 6;
104866
104938
  var templateCache = /* @__PURE__ */ new WeakMap();
104867
104939
  var WATER_TINT = new Color(4159204).toArray();
104868
104940
  function toInput(entries, maxAtlasSize, fluids, lighting) {
@@ -104899,8 +104971,8 @@ gl_FragDepth=readDepth(vUv);
104899
104971
  if (!data) {
104900
104972
  const indices = template.geometry.getIndex();
104901
104973
  const position = template.geometry.getAttribute("position");
104902
- const quads = indices.count / 6;
104903
- if (indices.count % 6 !== 0 || position.count !== quads * 4) {
104974
+ const quads = indices.count / QUAD_INDICES;
104975
+ if (indices.count % QUAD_INDICES !== 0 || position.count !== quads * QUAD_VERTICES) {
104904
104976
  throw new RangeError("Section template geometry must hold four vertices and six indices per quad");
104905
104977
  }
104906
104978
  data = {
@@ -104910,8 +104982,8 @@ gl_FragDepth=readDepth(vUv);
104910
104982
  uvs: new Float32Array(quads * 8),
104911
104983
  uvBounds: new Float32Array(quads * 16),
104912
104984
  colors: new Float32Array(quads * 12),
104913
- shade: new Float32Array(quads * 4),
104914
- indices: new Uint16Array(quads * 6),
104985
+ shade: new Float32Array(quads * QUAD_VERTICES),
104986
+ indices: new Uint16Array(quads * QUAD_INDICES),
104915
104987
  cullFaces: new Uint8Array(template.cullFaces),
104916
104988
  biomeTint: template.biomeTint ? new Uint8Array(template.biomeTint) : void 0,
104917
104989
  atlas: 0,
@@ -104923,7 +104995,7 @@ gl_FragDepth=readDepth(vUv);
104923
104995
  const bounds = template.geometry.getAttribute("uvBounds");
104924
104996
  const color3 = template.geometry.getAttribute("color");
104925
104997
  const shade = template.geometry.getAttribute("shade");
104926
- for (let vertex2 = 0; vertex2 < quads * 4; vertex2++) {
104998
+ for (let vertex2 = 0; vertex2 < quads * QUAD_VERTICES; vertex2++) {
104927
104999
  data.positions.set([position.getX(vertex2), position.getY(vertex2), position.getZ(vertex2)], vertex2 * 3);
104928
105000
  data.normals.set([normal.getX(vertex2), normal.getY(vertex2), normal.getZ(vertex2)], vertex2 * 3);
104929
105001
  data.uvs.set([uv.getX(vertex2), uv.getY(vertex2)], vertex2 * 2);
@@ -104936,7 +105008,7 @@ gl_FragDepth=readDepth(vUv);
104936
105008
  data.colors.set([color3?.getX(vertex2) ?? 1, color3?.getY(vertex2) ?? 1, color3?.getZ(vertex2) ?? 1], vertex2 * 3);
104937
105009
  data.shade[vertex2] = shade?.getX(vertex2) ?? 1;
104938
105010
  }
104939
- for (let i5 = 0; i5 < data.indices.length; i5++) data.indices[i5] = indices.getX(i5) - 4 * Math.floor(i5 / 6);
105011
+ for (let i5 = 0; i5 < data.indices.length; i5++) data.indices[i5] = indices.getX(i5) - QUAD_VERTICES * Math.floor(i5 / QUAD_INDICES);
104940
105012
  templateCache.set(template, data);
104941
105013
  }
104942
105014
  id = input.templateData.length;
@@ -104969,6 +105041,54 @@ gl_FragDepth=readDepth(vUv);
104969
105041
  }
104970
105042
  return { input, atlases: atlases2 };
104971
105043
  }
105044
+ function sortTransparentQuads(mesh) {
105045
+ const index = mesh.geometry.getIndex();
105046
+ if (index.count <= QUAD_INDICES) return;
105047
+ index.setUsage(DynamicDrawUsage);
105048
+ const count = index.count / QUAD_INDICES;
105049
+ let source, centers, depths, order;
105050
+ const view = new Matrix4(), localCamera = new Vector3(), key = new Vector3(), previous = new Vector3();
105051
+ let previousOrthographic;
105052
+ mesh.onBeforeRender = (_renderer, _scene, camera) => {
105053
+ localCamera.setFromMatrixPosition(camera.matrixWorld).applyMatrix4(view.copy(mesh.matrixWorld).invert());
105054
+ const orthographic = !!camera.isOrthographicCamera;
105055
+ if (orthographic) {
105056
+ view.multiplyMatrices(camera.matrixWorldInverse, mesh.matrixWorld);
105057
+ key.set(view.elements[2], view.elements[6], view.elements[10]);
105058
+ } else {
105059
+ key.copy(localCamera).divideScalar(BLOCK_SIZE).floor();
105060
+ }
105061
+ if (orthographic === previousOrthographic && key.equals(previous)) return;
105062
+ previous.copy(key);
105063
+ previousOrthographic = orthographic;
105064
+ if (!centers) {
105065
+ source = new Uint32Array(index.array);
105066
+ centers = new Float32Array(count * 3);
105067
+ depths = new Float32Array(count);
105068
+ order = Uint32Array.from({ length: count }, (_4, quad) => quad);
105069
+ const positions = mesh.geometry.getAttribute("position");
105070
+ for (let quad = 0; quad < count; quad++) {
105071
+ for (let axis = 0; axis < 3; axis++) {
105072
+ let center = 0;
105073
+ for (let corner = 0; corner < QUAD_VERTICES; corner++) center += positions.getComponent(quad * QUAD_VERTICES + corner, axis);
105074
+ centers[quad * 3 + axis] = center / QUAD_VERTICES;
105075
+ }
105076
+ }
105077
+ }
105078
+ for (let quad = 0; quad < count; quad++) {
105079
+ const x4 = centers[quad * 3], y5 = centers[quad * 3 + 1], z4 = centers[quad * 3 + 2];
105080
+ depths[quad] = orthographic ? key.x * x4 + key.y * y5 + key.z * z4 : -((x4 - localCamera.x) ** 2 + (y5 - localCamera.y) ** 2 + (z4 - localCamera.z) ** 2);
105081
+ }
105082
+ order.sort((a4, b4) => depths[a4] - depths[b4] || a4 - b4);
105083
+ if (!order.some((quad, offset) => index.array[offset * QUAD_INDICES] !== source[quad * QUAD_INDICES])) return;
105084
+ for (let offset = 0; offset < count; offset++) {
105085
+ for (let indexOffset = 0; indexOffset < QUAD_INDICES; indexOffset++) {
105086
+ index.array[offset * QUAD_INDICES + indexOffset] = source[order[offset] * QUAD_INDICES + indexOffset];
105087
+ }
105088
+ }
105089
+ index.needsUpdate = true;
105090
+ };
105091
+ }
104972
105092
  var SectionMesh = class _SectionMesh extends Group {
104973
105093
  constructor() {
104974
105094
  super(...arguments);
@@ -104978,7 +105098,11 @@ gl_FragDepth=readDepth(vUv);
104978
105098
  /** Returns the owning section cell for a triangle hit on this mesh's merged geometry. */
104979
105099
  getBlockIndex(hit) {
104980
105100
  if (hit.faceIndex === void 0 || hit.faceIndex === null) return void 0;
104981
- return this.blockIndices.get(hit.object)?.[Math.floor(hit.faceIndex / 2)];
105101
+ const mesh = hit.object;
105102
+ const owners = this.blockIndices.get(mesh);
105103
+ if (!owners) return void 0;
105104
+ const vertex2 = mesh.geometry.getIndex().getX(hit.faceIndex * 3);
105105
+ return owners[Math.floor(vertex2 / QUAD_VERTICES)];
104982
105106
  }
104983
105107
  /** Builds section-local meshes from visible quads. `maxAtlasSize` limits each atlas dimension in pixels. */
104984
105108
  static build(entries, maxAtlasSize = 2048, fluids, lighting) {
@@ -105014,13 +105138,14 @@ gl_FragDepth=readDepth(vUv);
105014
105138
  const material = Materials.createShadedCanvasMaterial(canvas, transparent, false, true);
105015
105139
  material.side = FrontSide;
105016
105140
  if (page.layer === 2) {
105141
+ material.depthWrite = !material.transparent;
105017
105142
  material.side = DoubleSide;
105018
105143
  material.forceSinglePass = true;
105019
- material.depthWrite = !material.transparent;
105020
105144
  }
105021
105145
  material.vertexColors = true;
105022
105146
  const texture = material.uniforms?.map?.value ?? material.map;
105023
105147
  const mesh = new Mesh(geometry, material);
105148
+ if (transparent) sortTransparentQuads(mesh);
105024
105149
  section.add(mesh);
105025
105150
  section.blockIndices.set(mesh, page.blockIndices);
105026
105151
  const unsubscribe = [];
@@ -105841,6 +105966,7 @@ gl_FragDepth=readDepth(vUv);
105841
105966
  init_dirname();
105842
105967
  init_buffer2();
105843
105968
  init_process2();
105969
+ var MAX_PREFETCHED_COLUMNS = 4;
105844
105970
  var WorldStreamer = class {
105845
105971
  constructor(world, source, options = {}) {
105846
105972
  this.world = world;
@@ -105850,6 +105976,7 @@ gl_FragDepth=readDepth(vUv);
105850
105976
  this.missing = /* @__PURE__ */ new Map();
105851
105977
  this.failed = /* @__PURE__ */ new Map();
105852
105978
  this.desired = [];
105979
+ this.reads = /* @__PURE__ */ new Map();
105853
105980
  this.disposed = false;
105854
105981
  this.loadRadius = options.loadRadius ?? 2;
105855
105982
  this.unloadRadius = options.unloadRadius ?? Math.min(32, this.loadRadius + 1);
@@ -105894,6 +106021,12 @@ gl_FragDepth=readDepth(vUv);
105894
106021
  if (this.loading && !this.within(this.loading.position, this.loadRadius)) {
105895
106022
  this.loading.controller.abort();
105896
106023
  }
106024
+ for (const [key, read] of this.reads) {
106025
+ if (!this.within(read.position, this.loadRadius)) {
106026
+ read.controller.abort();
106027
+ if (read.ready) this.reads.delete(key);
106028
+ }
106029
+ }
105897
106030
  }
105898
106031
  return this.running ?? (this.running = Promise.resolve().then(() => this.drain()));
105899
106032
  }
@@ -105914,8 +106047,11 @@ gl_FragDepth=readDepth(vUv);
105914
106047
  this.desired = [];
105915
106048
  this.center = void 0;
105916
106049
  this.loading?.controller.abort();
106050
+ for (const read of this.reads.values()) read.controller.abort();
105917
106051
  return this.disposal ?? (this.disposal = Promise.resolve().then(async () => {
105918
106052
  await this.running?.catch(() => void 0);
106053
+ await Promise.all([...this.reads.values()].map((read) => read.promise));
106054
+ this.reads.clear();
105919
106055
  try {
105920
106056
  await this.unloadMany([...this.owned.values()]);
105921
106057
  } finally {
@@ -105941,6 +106077,10 @@ gl_FragDepth=readDepth(vUv);
105941
106077
  await this.unloadMany(obsolete);
105942
106078
  continue;
105943
106079
  }
106080
+ if (this.world.placeChunks) {
106081
+ if (await this.placeReadyChunks()) continue;
106082
+ return;
106083
+ }
105944
106084
  const position = this.desired.find((position2) => this.needsLoad(position2));
105945
106085
  if (!position) return;
105946
106086
  let chunk;
@@ -105963,26 +106103,105 @@ gl_FragDepth=readDepth(vUv);
105963
106103
  continue;
105964
106104
  }
105965
106105
  this.owned.set(this.key(position), position);
106106
+ await this.placeOwnedColumns([position], () => this.world.placeChunk(chunk));
106107
+ }
106108
+ } finally {
106109
+ for (const [key, read] of this.reads) {
106110
+ read.controller.abort();
106111
+ if (read.ready) this.reads.delete(key);
106112
+ }
106113
+ this.running = void 0;
106114
+ }
106115
+ }
106116
+ fillReadSlots() {
106117
+ while (!this.disposed && this.reads.size < MAX_PREFETCHED_COLUMNS) {
106118
+ const position = this.desired.find((position2) => this.needsLoad(position2) && !this.reads.has(this.key(position2)));
106119
+ if (!position) return;
106120
+ const key = this.key(position);
106121
+ const read = {
106122
+ position,
106123
+ controller: new AbortController(),
106124
+ promise: Promise.resolve(),
106125
+ ready: false,
106126
+ failed: false
106127
+ };
106128
+ this.reads.set(key, read);
106129
+ read.promise = (async () => {
105966
106130
  try {
105967
- await this.world.placeChunk(chunk);
105968
- this.loaded.set(this.key(position), position);
106131
+ read.chunk = await this.source.getChunk(position.x, position.z, read.controller.signal);
106132
+ if (read.chunk) this.validateChunk(read.chunk, position);
105969
106133
  } catch (error2) {
105970
- try {
105971
- await this.unloadMany([position]);
105972
- } catch (cleanupError) {
105973
- const failure = error2 instanceof Error ? error2 : new Error(String(error2));
105974
- try {
105975
- Object.defineProperty(failure, "cause", { value: cleanupError, configurable: true });
105976
- } catch {
105977
- throw Object.assign(new Error(failure.message), { cause: cleanupError });
105978
- }
105979
- throw failure;
106134
+ read.failed = true;
106135
+ read.error = error2;
106136
+ } finally {
106137
+ read.ready = true;
106138
+ if (read.controller.signal.aborted || this.disposed || !this.within(position, this.loadRadius)) {
106139
+ this.reads.delete(key);
105980
106140
  }
105981
- throw error2;
106141
+ }
106142
+ })();
106143
+ }
106144
+ }
106145
+ /** Places only the ready prefix, so later source reads cannot delay the nearest ready column. */
106146
+ async placeReadyChunks() {
106147
+ this.fillReadSlots();
106148
+ const position = this.desired.find((position2) => this.needsLoad(position2));
106149
+ if (!position) {
106150
+ if (!this.reads.size) return false;
106151
+ await Promise.all([...this.reads.values()].map((read) => read.promise));
106152
+ return true;
106153
+ }
106154
+ const head = this.reads.get(this.key(position));
106155
+ if (!head) {
106156
+ for (let index = this.desired.length - 1; index >= 0; index--) {
106157
+ const key = this.key(this.desired[index]);
106158
+ if (this.reads.get(key)?.ready) {
106159
+ this.reads.delete(key);
106160
+ return true;
105982
106161
  }
105983
106162
  }
105984
- } finally {
105985
- this.running = void 0;
106163
+ await Promise.race([...this.reads.values()].map((read) => read.promise));
106164
+ return true;
106165
+ }
106166
+ if (!head.ready) {
106167
+ await head.promise;
106168
+ return true;
106169
+ }
106170
+ const chunks = [], positions = [];
106171
+ for (const desired of this.desired) {
106172
+ if (!this.needsLoad(desired)) continue;
106173
+ const key = this.key(desired), read = this.reads.get(key);
106174
+ if (!read?.ready) break;
106175
+ this.reads.delete(key);
106176
+ if (read.failed) this.failed.set(key, { ...desired, error: read.error });
106177
+ else if (!read.chunk) this.missing.set(key, desired);
106178
+ else {
106179
+ chunks.push(read.chunk);
106180
+ positions.push(desired);
106181
+ }
106182
+ }
106183
+ if (!chunks.length) return true;
106184
+ for (const position2 of positions) this.owned.set(this.key(position2), position2);
106185
+ await this.placeOwnedColumns(positions, () => this.world.placeChunks(chunks));
106186
+ return true;
106187
+ }
106188
+ async placeOwnedColumns(positions, place) {
106189
+ try {
106190
+ await place();
106191
+ for (const position of positions) this.loaded.set(this.key(position), position);
106192
+ } catch (error2) {
106193
+ try {
106194
+ await this.unloadMany(positions);
106195
+ } catch (cleanupError) {
106196
+ const failure = error2 instanceof Error ? error2 : new Error(String(error2));
106197
+ try {
106198
+ Object.defineProperty(failure, "cause", { value: cleanupError, configurable: true });
106199
+ } catch {
106200
+ throw Object.assign(new Error(failure.message), { cause: cleanupError });
106201
+ }
106202
+ throw failure;
106203
+ }
106204
+ throw error2;
105986
106205
  }
105987
106206
  }
105988
106207
  needsLoad(position) {