minerender 2.1.0-alpha.1 → 2.1.0-alpha.4

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.
@@ -5430,24 +5430,54 @@ var _MineRenderScene = class _MineRenderScene extends import_three17.Scene {
5430
5430
  this.stats = new SceneStats();
5431
5431
  this.instanceManager = new InstanceManager();
5432
5432
  this.dirty = true;
5433
+ this.observedObjects = /* @__PURE__ */ new Set();
5434
+ this.onObjectChange = (event) => {
5435
+ if (event.target?.parent === this) {
5436
+ this.dirty = true;
5437
+ }
5438
+ };
5433
5439
  this.options = (0, import_ts_deepmerge9.default)({}, _MineRenderScene.DEFAULT_OPTIONS, options ?? {});
5434
5440
  }
5435
- add(...object) {
5436
- this.dirty = true;
5437
- this.stats.objectCount += object.length;
5438
- for (let obj of object) {
5439
- if (isSceneObject(obj)) {
5440
- this.stats.sceneObjectCount++;
5441
+ add(...objects) {
5442
+ for (const object of objects) {
5443
+ this.dirty = true;
5444
+ try {
5445
+ super.add(object);
5446
+ } finally {
5447
+ if (object?.isObject3D && object !== this) {
5448
+ this.updateObjectRegistration(object, object.parent === this);
5449
+ }
5441
5450
  }
5442
- obj.addEventListener("change", (event) => {
5443
- this.dirty = true;
5444
- });
5445
5451
  }
5446
- return super.add(...object);
5452
+ return this;
5447
5453
  }
5448
- remove(...object) {
5449
- this.dirty = true;
5450
- return super.remove(...object);
5454
+ remove(...objects) {
5455
+ for (const object of objects) {
5456
+ if (!this.children.includes(object)) continue;
5457
+ this.dirty = true;
5458
+ this.updateObjectRegistration(object, false);
5459
+ try {
5460
+ super.remove(object);
5461
+ } finally {
5462
+ this.updateObjectRegistration(object, object.parent === this);
5463
+ }
5464
+ }
5465
+ return this;
5466
+ }
5467
+ updateObjectRegistration(object, attached) {
5468
+ if (this.observedObjects.has(object) === attached) return;
5469
+ if (attached) {
5470
+ this.observedObjects.add(object);
5471
+ object.addEventListener("change", this.onObjectChange);
5472
+ } else {
5473
+ this.observedObjects.delete(object);
5474
+ object.removeEventListener("change", this.onObjectChange);
5475
+ }
5476
+ const change = attached ? 1 : -1;
5477
+ this.stats.objectCount += change;
5478
+ if (isSceneObject(object)) {
5479
+ this.stats.sceneObjectCount += change;
5480
+ }
5451
5481
  }
5452
5482
  async initAndAdd(...object) {
5453
5483
  this.dirty = true;
@@ -5509,1039 +5539,1133 @@ function isMineRenderScene(obj) {
5509
5539
  }
5510
5540
 
5511
5541
  // src/renderer/Renderer.ts
5512
- var import_three18 = require("three");
5542
+ var import_three19 = require("three");
5513
5543
  var import_ts_deepmerge10 = __toESM(require_dist());
5514
5544
  var import_stats = __toESM(require("stats.js"));
5515
5545
  var import_postprocessing = require("postprocessing");
5516
- var _Renderer = class _Renderer {
5517
- constructor(options) {
5518
- this._dirty = true;
5519
- this._animationTimer = void 0;
5520
- this._animationFrame = void 0;
5521
- this._resizeListener = void 0;
5522
- this.options = (0, import_ts_deepmerge10.default)({}, _Renderer.DEFAULT_OPTIONS, options ?? {});
5523
- this._animationLoop = this.animate.bind(this);
5524
- this._fpsTimer = this.options.render.fpsLimit > 0 ? 1e3 / this.options.render.fpsLimit : void 0;
5525
- this._scene = this.createScene();
5526
- this._camera = this.createCamera();
5527
- this._renderer = this.createRenderer();
5528
- this._composer = this.createComposer();
5529
- if (this.options.render.stats) {
5530
- this._stats = new import_stats.default();
5531
- document.body.appendChild(this._stats.dom);
5532
- }
5533
- this.init();
5534
- }
5535
- //<editor-fold desc="INIT">
5536
- createScene() {
5537
- return new MineRenderScene();
5538
- }
5539
- createCamera() {
5540
- switch (this.options.camera.type) {
5541
- case "perspective":
5542
- default:
5543
- return new import_three18.PerspectiveCamera(
5544
- this.options.camera.perspective.fov,
5545
- this.options.camera.perspective.aspect ?? this.viewWidth / this.viewHeight,
5546
- this.options.camera.near,
5547
- this.options.camera.far
5548
- );
5549
- case "orthographic":
5550
- return new import_three18.OrthographicCamera(
5551
- this.options.camera.orthographic.left ?? this.viewWidth / -2,
5552
- this.options.camera.orthographic.right ?? this.viewWidth / 2,
5553
- this.options.camera.orthographic.top ?? this.viewHeight / 2,
5554
- this.options.camera.orthographic.bottom ?? this.viewHeight / -2,
5555
- this.options.camera.near,
5556
- this.options.camera.far
5557
- );
5558
- }
5559
- }
5560
- createRenderer() {
5561
- const renderer = new import_three18.WebGLRenderer({
5562
- antialias: this.options.render.antialias,
5563
- alpha: true,
5564
- powerPreference: "high-performance",
5565
- depth: true
5566
- });
5567
- renderer.setClearColor(0, 0);
5568
- renderer.shadowMap.enabled = true;
5569
- renderer.shadowMap.type = import_three18.PCFSoftShadowMap;
5570
- renderer.outputEncoding = import_three18.LinearEncoding;
5571
- renderer.setSize(this.viewWidth, this.viewHeight);
5572
- return renderer;
5573
- }
5574
- createComposer() {
5575
- const composer = new import_postprocessing.EffectComposer(this.renderer);
5576
- if (!this.options.composer.enabled) return composer;
5577
- composer.setSize(this.viewWidth, this.viewHeight);
5578
- composer.addPass(new import_postprocessing.RenderPass(this.scene, this.camera));
5579
- return composer;
5580
- }
5581
- //</editor-fold>
5582
- init() {
5583
- if (typeof window["__THREE_DEVTOOLS__"] !== "undefined") {
5584
- window["__THREE_DEVTOOLS__"].dispatchEvent(new CustomEvent("observe", { detail: this.scene }));
5546
+
5547
+ // src/three/OrbitControls.js
5548
+ var import_three18 = require("three");
5549
+ var _changeEvent = { type: "change" };
5550
+ var _startEvent = { type: "start" };
5551
+ var _endEvent = { type: "end" };
5552
+ var OrbitControls = class extends import_three18.EventDispatcher {
5553
+ constructor(object, domElement) {
5554
+ super();
5555
+ if (domElement === void 0) console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.');
5556
+ if (domElement === document) console.error('THREE.OrbitControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.');
5557
+ this.object = object;
5558
+ this.domElement = domElement;
5559
+ this.domElement.style.touchAction = "none";
5560
+ this.enabled = true;
5561
+ this.target = new import_three18.Vector3();
5562
+ this.minDistance = 0;
5563
+ this.maxDistance = Infinity;
5564
+ this.minZoom = 0;
5565
+ this.maxZoom = Infinity;
5566
+ this.minPolarAngle = 0;
5567
+ this.maxPolarAngle = Math.PI;
5568
+ this.minAzimuthAngle = -Infinity;
5569
+ this.maxAzimuthAngle = Infinity;
5570
+ this.enableDamping = false;
5571
+ this.dampingFactor = 0.05;
5572
+ this.enableZoom = true;
5573
+ this.zoomSpeed = 1;
5574
+ this.enableRotate = true;
5575
+ this.rotateSpeed = 1;
5576
+ this.enablePan = true;
5577
+ this.panSpeed = 1;
5578
+ this.screenSpacePanning = true;
5579
+ this.keyPanSpeed = 7;
5580
+ this.autoRotate = false;
5581
+ this.autoRotateSpeed = 2;
5582
+ this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" };
5583
+ this.mouseButtons = { LEFT: import_three18.MOUSE.ROTATE, MIDDLE: import_three18.MOUSE.DOLLY, RIGHT: import_three18.MOUSE.PAN };
5584
+ this.touches = { ONE: import_three18.TOUCH.ROTATE, TWO: import_three18.TOUCH.DOLLY_PAN };
5585
+ this.target0 = this.target.clone();
5586
+ this.position0 = this.object.position.clone();
5587
+ this.zoom0 = this.object.zoom;
5588
+ this._domElementKeyEvents = null;
5589
+ this.getPolarAngle = function() {
5590
+ return spherical.phi;
5591
+ };
5592
+ this.getAzimuthalAngle = function() {
5593
+ return spherical.theta;
5594
+ };
5595
+ this.getDistance = function() {
5596
+ return this.object.position.distanceTo(this.target);
5597
+ };
5598
+ this.saveState = function() {
5599
+ scope.target0.copy(scope.target);
5600
+ scope.position0.copy(scope.object.position);
5601
+ scope.zoom0 = scope.object.zoom;
5602
+ };
5603
+ this.reset = function() {
5604
+ scope.target.copy(scope.target0);
5605
+ scope.object.position.copy(scope.position0);
5606
+ scope.object.zoom = scope.zoom0;
5607
+ scope.object.updateProjectionMatrix();
5608
+ scope.dispatchEvent(_changeEvent);
5609
+ scope.update();
5610
+ state = STATE.NONE;
5611
+ };
5612
+ this.update = function() {
5613
+ const offset = new import_three18.Vector3();
5614
+ const quat = new import_three18.Quaternion().setFromUnitVectors(object.up, new import_three18.Vector3(0, 1, 0));
5615
+ const quatInverse = quat.clone().invert();
5616
+ const lastPosition = new import_three18.Vector3();
5617
+ const lastQuaternion = new import_three18.Quaternion();
5618
+ const twoPI = 2 * Math.PI;
5619
+ return function update() {
5620
+ const position = scope.object.position;
5621
+ offset.copy(position).sub(scope.target);
5622
+ offset.applyQuaternion(quat);
5623
+ spherical.setFromVector3(offset);
5624
+ if (scope.autoRotate && state === STATE.NONE) {
5625
+ rotateLeft(getAutoRotationAngle());
5626
+ }
5627
+ if (scope.enableDamping) {
5628
+ spherical.theta += sphericalDelta.theta * scope.dampingFactor;
5629
+ spherical.phi += sphericalDelta.phi * scope.dampingFactor;
5630
+ } else {
5631
+ spherical.theta += sphericalDelta.theta;
5632
+ spherical.phi += sphericalDelta.phi;
5633
+ }
5634
+ let min = scope.minAzimuthAngle;
5635
+ let max = scope.maxAzimuthAngle;
5636
+ if (isFinite(min) && isFinite(max)) {
5637
+ if (min < -Math.PI) min += twoPI;
5638
+ else if (min > Math.PI) min -= twoPI;
5639
+ if (max < -Math.PI) max += twoPI;
5640
+ else if (max > Math.PI) max -= twoPI;
5641
+ if (min <= max) {
5642
+ spherical.theta = Math.max(min, Math.min(max, spherical.theta));
5643
+ } else {
5644
+ spherical.theta = spherical.theta > (min + max) / 2 ? Math.max(min, spherical.theta) : Math.min(max, spherical.theta);
5645
+ }
5646
+ }
5647
+ spherical.phi = Math.max(scope.minPolarAngle, Math.min(scope.maxPolarAngle, spherical.phi));
5648
+ spherical.makeSafe();
5649
+ spherical.radius *= scale;
5650
+ spherical.radius = Math.max(scope.minDistance, Math.min(scope.maxDistance, spherical.radius));
5651
+ if (scope.enableDamping === true) {
5652
+ scope.target.addScaledVector(panOffset, scope.dampingFactor);
5653
+ } else {
5654
+ scope.target.add(panOffset);
5655
+ }
5656
+ offset.setFromSpherical(spherical);
5657
+ offset.applyQuaternion(quatInverse);
5658
+ position.copy(scope.target).add(offset);
5659
+ scope.object.lookAt(scope.target);
5660
+ if (scope.enableDamping === true) {
5661
+ sphericalDelta.theta *= 1 - scope.dampingFactor;
5662
+ sphericalDelta.phi *= 1 - scope.dampingFactor;
5663
+ panOffset.multiplyScalar(1 - scope.dampingFactor);
5664
+ } else {
5665
+ sphericalDelta.set(0, 0, 0);
5666
+ panOffset.set(0, 0, 0);
5667
+ }
5668
+ scale = 1;
5669
+ if (zoomChanged || lastPosition.distanceToSquared(scope.object.position) > EPS || 8 * (1 - lastQuaternion.dot(scope.object.quaternion)) > EPS) {
5670
+ scope.dispatchEvent(_changeEvent);
5671
+ lastPosition.copy(scope.object.position);
5672
+ lastQuaternion.copy(scope.object.quaternion);
5673
+ zoomChanged = false;
5674
+ return true;
5675
+ }
5676
+ return false;
5677
+ };
5678
+ }();
5679
+ this.dispose = function() {
5680
+ scope.domElement.removeEventListener("contextmenu", onContextMenu);
5681
+ scope.domElement.removeEventListener("pointerdown", onPointerDown);
5682
+ scope.domElement.removeEventListener("pointercancel", onPointerCancel);
5683
+ scope.domElement.removeEventListener("wheel", onMouseWheel);
5684
+ scope.domElement.removeEventListener("pointermove", onPointerMove);
5685
+ scope.domElement.removeEventListener("pointerup", onPointerUp);
5686
+ if (scope._domElementKeyEvents !== null) {
5687
+ scope._domElementKeyEvents.removeEventListener("keydown", onKeyDown);
5688
+ }
5689
+ };
5690
+ const scope = this;
5691
+ const STATE = {
5692
+ NONE: -1,
5693
+ ROTATE: 0,
5694
+ DOLLY: 1,
5695
+ PAN: 2,
5696
+ TOUCH_ROTATE: 3,
5697
+ TOUCH_PAN: 4,
5698
+ TOUCH_DOLLY_PAN: 5,
5699
+ TOUCH_DOLLY_ROTATE: 6
5700
+ };
5701
+ let state = STATE.NONE;
5702
+ const EPS = 1e-6;
5703
+ const spherical = new import_three18.Spherical();
5704
+ const sphericalDelta = new import_three18.Spherical();
5705
+ let scale = 1;
5706
+ const panOffset = new import_three18.Vector3();
5707
+ let zoomChanged = false;
5708
+ const rotateStart = new import_three18.Vector2();
5709
+ const rotateEnd = new import_three18.Vector2();
5710
+ const rotateDelta = new import_three18.Vector2();
5711
+ const panStart = new import_three18.Vector2();
5712
+ const panEnd = new import_three18.Vector2();
5713
+ const panDelta = new import_three18.Vector2();
5714
+ const dollyStart = new import_three18.Vector2();
5715
+ const dollyEnd = new import_three18.Vector2();
5716
+ const dollyDelta = new import_three18.Vector2();
5717
+ const pointers = [];
5718
+ const pointerPositions = {};
5719
+ function getAutoRotationAngle() {
5720
+ return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
5585
5721
  }
5586
- if (this.options.debug.grid) {
5587
- const gridHelper = new import_three18.GridHelper(128, 16);
5588
- this.scene.add(gridHelper);
5589
- const gridHelper2 = new import_three18.GridHelper(128, 16);
5590
- gridHelper2.rotation.x = 90 * (Math.PI / 180);
5591
- this.scene.add(gridHelper2);
5592
- const gridHelper3 = new import_three18.GridHelper(128, 16);
5593
- gridHelper3.rotation.z = 90 * (Math.PI / 180);
5594
- this.scene.add(gridHelper3);
5722
+ function getZoomScale() {
5723
+ return Math.pow(0.95, scope.zoomSpeed);
5595
5724
  }
5596
- if (this.options.debug.axes) {
5597
- const axesHelper = new import_three18.AxesHelper(64);
5598
- this.scene.add(axesHelper);
5725
+ function rotateLeft(angle) {
5726
+ sphericalDelta.theta -= angle;
5599
5727
  }
5600
- if (this.options.camera.position) {
5601
- if (isVector3(this.options.camera.position)) {
5602
- this.camera.position.set(this.options.camera.position.x, this.options.camera.position.y, this.options.camera.position.z);
5603
- } else if (isTripleArray(this.options.camera.position)) {
5604
- this.camera.position.set(this.options.camera.position[0], this.options.camera.position[1], this.options.camera.position[2]);
5605
- }
5728
+ function rotateUp(angle) {
5729
+ sphericalDelta.phi -= angle;
5606
5730
  }
5607
- if (this.options.camera.lookingAt) {
5608
- if (isVector3(this.options.camera.lookingAt)) {
5609
- this.camera.lookAt(this.options.camera.lookingAt);
5610
- } else if (isTripleArray(this.options.camera.lookingAt)) {
5611
- this.camera.lookAt(this.options.camera.lookingAt[0], this.options.camera.lookingAt[1], this.options.camera.lookingAt[2]);
5731
+ const panLeft = function() {
5732
+ const v = new import_three18.Vector3();
5733
+ return function panLeft2(distance, objectMatrix) {
5734
+ v.setFromMatrixColumn(objectMatrix, 0);
5735
+ v.multiplyScalar(-distance);
5736
+ panOffset.add(v);
5737
+ };
5738
+ }();
5739
+ const panUp = function() {
5740
+ const v = new import_three18.Vector3();
5741
+ return function panUp2(distance, objectMatrix) {
5742
+ if (scope.screenSpacePanning === true) {
5743
+ v.setFromMatrixColumn(objectMatrix, 1);
5744
+ } else {
5745
+ v.setFromMatrixColumn(objectMatrix, 0);
5746
+ v.crossVectors(scope.object.up, v);
5747
+ }
5748
+ v.multiplyScalar(distance);
5749
+ panOffset.add(v);
5750
+ };
5751
+ }();
5752
+ const pan = function() {
5753
+ const offset = new import_three18.Vector3();
5754
+ return function pan2(deltaX, deltaY) {
5755
+ const element = scope.domElement;
5756
+ if (scope.object.isPerspectiveCamera) {
5757
+ const position = scope.object.position;
5758
+ offset.copy(position).sub(scope.target);
5759
+ let targetDistance = offset.length();
5760
+ targetDistance *= Math.tan(scope.object.fov / 2 * Math.PI / 180);
5761
+ panLeft(2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix);
5762
+ panUp(2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix);
5763
+ } else if (scope.object.isOrthographicCamera) {
5764
+ panLeft(deltaX * (scope.object.right - scope.object.left) / scope.object.zoom / element.clientWidth, scope.object.matrix);
5765
+ panUp(deltaY * (scope.object.top - scope.object.bottom) / scope.object.zoom / element.clientHeight, scope.object.matrix);
5766
+ } else {
5767
+ console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.");
5768
+ scope.enablePan = false;
5769
+ }
5770
+ };
5771
+ }();
5772
+ function dollyOut(dollyScale) {
5773
+ if (scope.object.isPerspectiveCamera) {
5774
+ scale /= dollyScale;
5775
+ } else if (scope.object.isOrthographicCamera) {
5776
+ scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom * dollyScale));
5777
+ scope.object.updateProjectionMatrix();
5778
+ zoomChanged = true;
5779
+ } else {
5780
+ console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
5781
+ scope.enableZoom = false;
5612
5782
  }
5613
5783
  }
5614
- if (this.options.render.autoResize) {
5615
- this._resizeListener = () => {
5616
- this.resize(this.viewWidth, this.viewHeight);
5617
- };
5618
- window.addEventListener("resize", this._resizeListener);
5784
+ function dollyIn(dollyScale) {
5785
+ if (scope.object.isPerspectiveCamera) {
5786
+ scale *= dollyScale;
5787
+ } else if (scope.object.isOrthographicCamera) {
5788
+ scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / dollyScale));
5789
+ scope.object.updateProjectionMatrix();
5790
+ zoomChanged = true;
5791
+ } else {
5792
+ console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
5793
+ scope.enableZoom = false;
5794
+ }
5619
5795
  }
5620
- }
5621
- get element() {
5622
- return this._element;
5623
- }
5624
- appendTo(element) {
5625
- this._element = element;
5626
- this._element.appendChild(this.renderer.domElement);
5627
- if (this.viewWidth == 0) {
5628
- console.warn("0 element width");
5796
+ function handleMouseDownRotate(event) {
5797
+ rotateStart.set(event.clientX, event.clientY);
5629
5798
  }
5630
- if (this.viewHeight == 0) {
5631
- console.warn("0 element height");
5799
+ function handleMouseDownDolly(event) {
5800
+ dollyStart.set(event.clientX, event.clientY);
5632
5801
  }
5633
- this.resize(this.viewWidth, this.viewHeight);
5634
- }
5635
- /**
5636
- * Register an EventDispatcher which may update the scene or renderer in order to redraw the scene
5637
- */
5638
- registerEventDispatcher(dispatcher, changeEvent2 = "change") {
5639
- dispatcher.addEventListener(changeEvent2, (event) => {
5640
- this._dirty = true;
5641
- });
5642
- }
5643
- resize(width, height) {
5644
- if (isPerspectiveCamera(this.camera)) {
5645
- this.camera.aspect = width / height;
5646
- this.camera.updateProjectionMatrix();
5647
- } else if (isOrthographicCamera(this.camera)) {
5648
- this.camera.left = width / -2;
5649
- this.camera.right = width / 2;
5650
- this.camera.top = height / 2;
5651
- this.camera.bottom = height / -2;
5652
- this.camera.updateProjectionMatrix();
5802
+ function handleMouseDownPan(event) {
5803
+ panStart.set(event.clientX, event.clientY);
5653
5804
  }
5654
- this.renderer.setSize(width, height);
5655
- this.composer.setSize(width, height);
5656
- }
5657
- //<editor-fold desc="RENDER">
5658
- get dirty() {
5659
- return this._dirty || this.scene.dirty;
5660
- }
5661
- set dirty(dirty) {
5662
- this._dirty = dirty;
5663
- this.scene.dirty = dirty;
5664
- }
5665
- start() {
5666
- stop();
5667
- this.renderer.setAnimationLoop(this._animationLoop);
5668
- }
5669
- stop() {
5670
- this.renderer.setAnimationLoop(null);
5671
- if (this._animationTimer)
5672
- clearTimeout(this._animationTimer);
5673
- this._animationTimer = void 0;
5674
- if (this._animationFrame)
5675
- cancelAnimationFrame(this._animationFrame);
5676
- this._animationFrame = void 0;
5677
- }
5678
- animate(t) {
5679
- if (this._stats) {
5680
- this._stats.begin();
5805
+ function handleMouseMoveRotate(event) {
5806
+ rotateEnd.set(event.clientX, event.clientY);
5807
+ rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed);
5808
+ const element = scope.domElement;
5809
+ rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight);
5810
+ rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight);
5811
+ rotateStart.copy(rotateEnd);
5812
+ scope.update();
5681
5813
  }
5682
- if (this.dirty || this.options.render.renderAlways) {
5683
- if (this.options.composer.enabled) {
5684
- this.composer.render();
5685
- } else {
5686
- this.renderer.render(this.scene, this.camera);
5814
+ function handleMouseMoveDolly(event) {
5815
+ dollyEnd.set(event.clientX, event.clientY);
5816
+ dollyDelta.subVectors(dollyEnd, dollyStart);
5817
+ if (dollyDelta.y > 0) {
5818
+ dollyOut(getZoomScale());
5819
+ } else if (dollyDelta.y < 0) {
5820
+ dollyIn(getZoomScale());
5687
5821
  }
5822
+ dollyStart.copy(dollyEnd);
5823
+ scope.update();
5688
5824
  }
5689
- this.dirty = false;
5690
- if (this._stats) {
5691
- this._stats.end();
5825
+ function handleMouseMovePan(event) {
5826
+ panEnd.set(event.clientX, event.clientY);
5827
+ panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
5828
+ pan(panDelta.x, panDelta.y);
5829
+ panStart.copy(panEnd);
5830
+ scope.update();
5692
5831
  }
5693
- }
5694
- //</editor-fold>
5695
- toImage() {
5696
- return this.renderer.domElement.toDataURL();
5697
- }
5698
- ///
5699
- get attachedToBody() {
5700
- return this.element === document.body;
5701
- }
5702
- get viewWidth() {
5703
- return this.attachedToBody ? window.innerWidth : this.element?.offsetWidth || 0;
5704
- }
5705
- get viewHeight() {
5706
- return this.attachedToBody ? window.innerHeight : this.element?.offsetHeight || 0;
5707
- }
5708
- get scene() {
5709
- return this._scene;
5710
- }
5711
- get camera() {
5712
- return this._camera;
5713
- }
5714
- get renderer() {
5715
- return this._renderer;
5716
- }
5717
- get composer() {
5718
- return this._composer;
5719
- }
5720
- ///
5721
- };
5722
- _Renderer.DEFAULT_OPTIONS = (0, import_ts_deepmerge10.default)({}, {
5723
- camera: {
5724
- type: "perspective",
5725
- near: 1,
5726
- far: 5e3,
5727
- perspective: {
5728
- aspect: void 0,
5729
- fov: 50
5730
- },
5731
- orthographic: {
5732
- left: void 0,
5733
- right: void 0,
5734
- top: void 0,
5735
- bottom: void 0
5736
- },
5737
- position: new import_three18.Vector3(50, 50, 50),
5738
- lookingAt: new import_three18.Vector3(0, 0, 0)
5739
- },
5740
- render: {
5741
- fpsLimit: 60,
5742
- stats: false,
5743
- antialias: true,
5744
- shade: true,
5745
- autoResize: true,
5746
- renderAlways: false
5747
- },
5748
- composer: {
5749
- enabled: true
5750
- },
5751
- debug: {
5752
- grid: false,
5753
- axes: false
5754
- }
5755
- });
5756
- var Renderer = _Renderer;
5757
-
5758
- // src/skin/Skins.ts
5759
- var Skins = class {
5760
- //<editor-fold desc="Skins">
5761
- static async fromUuidOrUsername(uuidOrUsername) {
5762
- if (uuidOrUsername.length === 32 || uuidOrUsername.length === 36) {
5763
- return this.fromUuid(uuidOrUsername);
5832
+ function handleMouseUp() {
5764
5833
  }
5765
- return this.fromUsername(uuidOrUsername);
5766
- }
5767
- static async fromUuid(uuid) {
5768
- return this.getSkinProxySkinUrl(uuid);
5769
- }
5770
- static async fromUsername(username) {
5771
- return this.usernameToUuid(username).then((uuid) => {
5772
- if (uuid) {
5773
- return this.fromUuid(uuid);
5774
- }
5775
- return void 0;
5776
- });
5777
- }
5778
- static async fromMineSkin(mineskinId) {
5779
- return this.getMineSkin(mineskinId).then((mineskin) => {
5780
- if (mineskin) {
5781
- return mineskin["data"]["texture"]["value"]["urls"]["skins"];
5834
+ function handleMouseWheel(event) {
5835
+ if (event.deltaY < 0) {
5836
+ dollyIn(getZoomScale());
5837
+ } else if (event.deltaY > 0) {
5838
+ dollyOut(getZoomScale());
5782
5839
  }
5783
- return void 0;
5784
- });
5785
- }
5786
- //</editor-fold>
5787
- //<editor-fold desc="Capes">
5788
- static async capeFromUuidOrUsername(uuidOrUsername) {
5789
- if (uuidOrUsername.length === 32 || uuidOrUsername.length === 36) {
5790
- return this.capeFromUuid(uuidOrUsername);
5840
+ scope.update();
5791
5841
  }
5792
- return this.capeFromUsername(uuidOrUsername);
5793
- }
5794
- static async capeFromUuid(uuid) {
5795
- return this.getSkinProxyCapeUrl(uuid);
5796
- }
5797
- static async capeFromUsername(username) {
5798
- return this.usernameToUuid(username).then((uuid) => {
5799
- if (uuid) {
5800
- return this.capeFromUuid(uuid);
5801
- }
5802
- return void 0;
5803
- });
5804
- }
5805
- static async capeFromCapesDev(uuid, capeType = "minecraft") {
5806
- return this.getCapesDev(uuid, capeType).then((cape) => {
5807
- if (cape) {
5808
- return cape?.stillImageUrl;
5809
- }
5810
- return void 0;
5811
- });
5812
- }
5813
- //</editor-fold>
5814
- //<editor-fold desc="Helpers">
5815
- static async usernameToUuid(username) {
5816
- return this.usernameToUuidSkinProxy(username);
5817
- }
5818
- static async usernameToUuidSkinProxy(username) {
5819
- return Requests.genericRequest({
5820
- baseURL: "https://minecraft-skin-proxy.inventive.workers.dev",
5821
- url: "/uuid/" + username
5822
- }).then((res) => {
5823
- if (res.status === 200) {
5824
- return res.data["id"];
5825
- }
5826
- return void 0;
5827
- }).catch((err) => {
5828
- console.warn(err);
5829
- return void 0;
5830
- });
5831
- }
5832
- static async usernameToUuidMineTools(username) {
5833
- return Requests.genericRequest({
5834
- baseURL: "https://api.minetools.eu",
5835
- url: "/uuid/" + username
5836
- }).then((res) => {
5837
- if (res.status === 200) {
5838
- return res.data["id"];
5839
- }
5840
- return void 0;
5841
- }).catch((err) => {
5842
- console.warn(err);
5843
- return void 0;
5844
- });
5845
- }
5846
- static async getProfileFromMinetools(uuid) {
5847
- return Requests.genericRequest({
5848
- baseURL: "https://api.minetools.eu",
5849
- url: "/profile/" + uuid
5850
- }).then((res) => {
5851
- if (res.status === 200) {
5852
- return res.data;
5853
- }
5854
- });
5855
- }
5856
- static async getMineSkin(mineskinId) {
5857
- return Requests.genericRequest({
5858
- baseURL: "https://api.mineskin.org",
5859
- url: "/get/uuid/" + mineskinId
5860
- }).then((res) => {
5861
- if (res.status === 200) {
5862
- return res.data;
5863
- }
5864
- return void 0;
5865
- }).catch((err) => {
5866
- console.warn(err);
5867
- return void 0;
5868
- });
5869
- }
5870
- static async getCapesDev(uuid, type = "all") {
5871
- return Requests.genericRequest({
5872
- baseURL: "https://api.capes.dev",
5873
- url: "/load/" + uuid + "/" + type
5874
- }).then((res) => {
5875
- if (res.status === 200) {
5876
- return res.data;
5877
- }
5878
- return void 0;
5879
- }).catch((err) => {
5880
- console.warn(err);
5881
- return void 0;
5882
- });
5883
- }
5884
- static getCrafatarSkinUrl(uuid) {
5885
- return "https://crafatar.com/skins/" + uuid;
5886
- }
5887
- static getCrafatarCapeUrl(uuid) {
5888
- return "https://crafatar.com/capes/" + uuid;
5889
- }
5890
- static getMcHeadsSkinUrl(uuid) {
5891
- return "https://mc-heads.net/skin/" + uuid;
5892
- }
5893
- static getMineSkinPlayerSkinUrl(uuid) {
5894
- return "https://mineskin.org/skin/player/" + uuid;
5895
- }
5896
- static getSkinProxySkinUrl(uuid) {
5897
- return "https://minecraft-skin-proxy.inventive.workers.dev/skin/" + uuid;
5898
- }
5899
- static getSkinProxyCapeUrl(uuid) {
5900
- return "https://minecraft-skin-proxy.inventive.workers.dev/cape/" + uuid;
5901
- }
5902
- //</editor-fold>
5903
- };
5904
-
5905
- // src/three/OrbitControls.js
5906
- var import_three20 = require("three");
5907
- var _changeEvent = { type: "change" };
5908
- var _startEvent = { type: "start" };
5909
- var _endEvent = { type: "end" };
5910
- var OrbitControls = class extends import_three20.EventDispatcher {
5911
- constructor(object, domElement) {
5912
- super();
5913
- if (domElement === void 0) console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.');
5914
- if (domElement === document) console.error('THREE.OrbitControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.');
5915
- this.object = object;
5916
- this.domElement = domElement;
5917
- this.domElement.style.touchAction = "none";
5918
- this.enabled = true;
5919
- this.target = new import_three20.Vector3();
5920
- this.minDistance = 0;
5921
- this.maxDistance = Infinity;
5922
- this.minZoom = 0;
5923
- this.maxZoom = Infinity;
5924
- this.minPolarAngle = 0;
5925
- this.maxPolarAngle = Math.PI;
5926
- this.minAzimuthAngle = -Infinity;
5927
- this.maxAzimuthAngle = Infinity;
5928
- this.enableDamping = false;
5929
- this.dampingFactor = 0.05;
5930
- this.enableZoom = true;
5931
- this.zoomSpeed = 1;
5932
- this.enableRotate = true;
5933
- this.rotateSpeed = 1;
5934
- this.enablePan = true;
5935
- this.panSpeed = 1;
5936
- this.screenSpacePanning = true;
5937
- this.keyPanSpeed = 7;
5938
- this.autoRotate = false;
5939
- this.autoRotateSpeed = 2;
5940
- this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" };
5941
- this.mouseButtons = { LEFT: import_three20.MOUSE.ROTATE, MIDDLE: import_three20.MOUSE.DOLLY, RIGHT: import_three20.MOUSE.PAN };
5942
- this.touches = { ONE: import_three20.TOUCH.ROTATE, TWO: import_three20.TOUCH.DOLLY_PAN };
5943
- this.target0 = this.target.clone();
5944
- this.position0 = this.object.position.clone();
5945
- this.zoom0 = this.object.zoom;
5946
- this._domElementKeyEvents = null;
5947
- this.getPolarAngle = function() {
5948
- return spherical.phi;
5949
- };
5950
- this.getAzimuthalAngle = function() {
5951
- return spherical.theta;
5952
- };
5953
- this.getDistance = function() {
5954
- return this.object.position.distanceTo(this.target);
5955
- };
5956
- this.saveState = function() {
5957
- scope.target0.copy(scope.target);
5958
- scope.position0.copy(scope.object.position);
5959
- scope.zoom0 = scope.object.zoom;
5960
- };
5961
- this.reset = function() {
5962
- scope.target.copy(scope.target0);
5963
- scope.object.position.copy(scope.position0);
5964
- scope.object.zoom = scope.zoom0;
5965
- scope.object.updateProjectionMatrix();
5966
- scope.dispatchEvent(_changeEvent);
5967
- scope.update();
5968
- state = STATE.NONE;
5969
- };
5970
- this.update = function() {
5971
- const offset = new import_three20.Vector3();
5972
- const quat = new import_three20.Quaternion().setFromUnitVectors(object.up, new import_three20.Vector3(0, 1, 0));
5973
- const quatInverse = quat.clone().invert();
5974
- const lastPosition = new import_three20.Vector3();
5975
- const lastQuaternion = new import_three20.Quaternion();
5976
- const twoPI = 2 * Math.PI;
5977
- return function update() {
5978
- const position = scope.object.position;
5979
- offset.copy(position).sub(scope.target);
5980
- offset.applyQuaternion(quat);
5981
- spherical.setFromVector3(offset);
5982
- if (scope.autoRotate && state === STATE.NONE) {
5983
- rotateLeft(getAutoRotationAngle());
5984
- }
5985
- if (scope.enableDamping) {
5986
- spherical.theta += sphericalDelta.theta * scope.dampingFactor;
5987
- spherical.phi += sphericalDelta.phi * scope.dampingFactor;
5988
- } else {
5989
- spherical.theta += sphericalDelta.theta;
5990
- spherical.phi += sphericalDelta.phi;
5991
- }
5992
- let min = scope.minAzimuthAngle;
5993
- let max = scope.maxAzimuthAngle;
5994
- if (isFinite(min) && isFinite(max)) {
5995
- if (min < -Math.PI) min += twoPI;
5996
- else if (min > Math.PI) min -= twoPI;
5997
- if (max < -Math.PI) max += twoPI;
5998
- else if (max > Math.PI) max -= twoPI;
5999
- if (min <= max) {
6000
- spherical.theta = Math.max(min, Math.min(max, spherical.theta));
6001
- } else {
6002
- spherical.theta = spherical.theta > (min + max) / 2 ? Math.max(min, spherical.theta) : Math.min(max, spherical.theta);
6003
- }
6004
- }
6005
- spherical.phi = Math.max(scope.minPolarAngle, Math.min(scope.maxPolarAngle, spherical.phi));
6006
- spherical.makeSafe();
6007
- spherical.radius *= scale;
6008
- spherical.radius = Math.max(scope.minDistance, Math.min(scope.maxDistance, spherical.radius));
6009
- if (scope.enableDamping === true) {
6010
- scope.target.addScaledVector(panOffset, scope.dampingFactor);
6011
- } else {
6012
- scope.target.add(panOffset);
6013
- }
6014
- offset.setFromSpherical(spherical);
6015
- offset.applyQuaternion(quatInverse);
6016
- position.copy(scope.target).add(offset);
6017
- scope.object.lookAt(scope.target);
6018
- if (scope.enableDamping === true) {
6019
- sphericalDelta.theta *= 1 - scope.dampingFactor;
6020
- sphericalDelta.phi *= 1 - scope.dampingFactor;
6021
- panOffset.multiplyScalar(1 - scope.dampingFactor);
6022
- } else {
6023
- sphericalDelta.set(0, 0, 0);
6024
- panOffset.set(0, 0, 0);
6025
- }
6026
- scale = 1;
6027
- if (zoomChanged || lastPosition.distanceToSquared(scope.object.position) > EPS || 8 * (1 - lastQuaternion.dot(scope.object.quaternion)) > EPS) {
6028
- scope.dispatchEvent(_changeEvent);
6029
- lastPosition.copy(scope.object.position);
6030
- lastQuaternion.copy(scope.object.quaternion);
6031
- zoomChanged = false;
6032
- return true;
6033
- }
6034
- return false;
6035
- };
6036
- }();
6037
- this.dispose = function() {
6038
- scope.domElement.removeEventListener("contextmenu", onContextMenu);
6039
- scope.domElement.removeEventListener("pointerdown", onPointerDown);
6040
- scope.domElement.removeEventListener("pointercancel", onPointerCancel);
6041
- scope.domElement.removeEventListener("wheel", onMouseWheel);
6042
- scope.domElement.removeEventListener("pointermove", onPointerMove);
6043
- scope.domElement.removeEventListener("pointerup", onPointerUp);
6044
- if (scope._domElementKeyEvents !== null) {
6045
- scope._domElementKeyEvents.removeEventListener("keydown", onKeyDown);
6046
- }
6047
- };
6048
- const scope = this;
6049
- const STATE = {
6050
- NONE: -1,
6051
- ROTATE: 0,
6052
- DOLLY: 1,
6053
- PAN: 2,
6054
- TOUCH_ROTATE: 3,
6055
- TOUCH_PAN: 4,
6056
- TOUCH_DOLLY_PAN: 5,
6057
- TOUCH_DOLLY_ROTATE: 6
6058
- };
6059
- let state = STATE.NONE;
6060
- const EPS = 1e-6;
6061
- const spherical = new import_three20.Spherical();
6062
- const sphericalDelta = new import_three20.Spherical();
6063
- let scale = 1;
6064
- const panOffset = new import_three20.Vector3();
6065
- let zoomChanged = false;
6066
- const rotateStart = new import_three20.Vector2();
6067
- const rotateEnd = new import_three20.Vector2();
6068
- const rotateDelta = new import_three20.Vector2();
6069
- const panStart = new import_three20.Vector2();
6070
- const panEnd = new import_three20.Vector2();
6071
- const panDelta = new import_three20.Vector2();
6072
- const dollyStart = new import_three20.Vector2();
6073
- const dollyEnd = new import_three20.Vector2();
6074
- const dollyDelta = new import_three20.Vector2();
6075
- const pointers = [];
6076
- const pointerPositions = {};
6077
- function getAutoRotationAngle() {
6078
- return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
6079
- }
6080
- function getZoomScale() {
6081
- return Math.pow(0.95, scope.zoomSpeed);
6082
- }
6083
- function rotateLeft(angle) {
6084
- sphericalDelta.theta -= angle;
6085
- }
6086
- function rotateUp(angle) {
6087
- sphericalDelta.phi -= angle;
5842
+ function handleKeyDown(event) {
5843
+ let needsUpdate = false;
5844
+ switch (event.code) {
5845
+ case scope.keys.UP:
5846
+ pan(0, scope.keyPanSpeed);
5847
+ needsUpdate = true;
5848
+ break;
5849
+ case scope.keys.BOTTOM:
5850
+ pan(0, -scope.keyPanSpeed);
5851
+ needsUpdate = true;
5852
+ break;
5853
+ case scope.keys.LEFT:
5854
+ pan(scope.keyPanSpeed, 0);
5855
+ needsUpdate = true;
5856
+ break;
5857
+ case scope.keys.RIGHT:
5858
+ pan(-scope.keyPanSpeed, 0);
5859
+ needsUpdate = true;
5860
+ break;
5861
+ }
5862
+ if (needsUpdate) {
5863
+ event.preventDefault();
5864
+ scope.update();
5865
+ }
6088
5866
  }
6089
- const panLeft = function() {
6090
- const v = new import_three20.Vector3();
6091
- return function panLeft2(distance, objectMatrix) {
6092
- v.setFromMatrixColumn(objectMatrix, 0);
6093
- v.multiplyScalar(-distance);
6094
- panOffset.add(v);
6095
- };
6096
- }();
6097
- const panUp = function() {
6098
- const v = new import_three20.Vector3();
6099
- return function panUp2(distance, objectMatrix) {
6100
- if (scope.screenSpacePanning === true) {
6101
- v.setFromMatrixColumn(objectMatrix, 1);
6102
- } else {
6103
- v.setFromMatrixColumn(objectMatrix, 0);
6104
- v.crossVectors(scope.object.up, v);
6105
- }
6106
- v.multiplyScalar(distance);
6107
- panOffset.add(v);
6108
- };
6109
- }();
6110
- const pan = function() {
6111
- const offset = new import_three20.Vector3();
6112
- return function pan2(deltaX, deltaY) {
6113
- const element = scope.domElement;
6114
- if (scope.object.isPerspectiveCamera) {
6115
- const position = scope.object.position;
6116
- offset.copy(position).sub(scope.target);
6117
- let targetDistance = offset.length();
6118
- targetDistance *= Math.tan(scope.object.fov / 2 * Math.PI / 180);
6119
- panLeft(2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix);
6120
- panUp(2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix);
6121
- } else if (scope.object.isOrthographicCamera) {
6122
- panLeft(deltaX * (scope.object.right - scope.object.left) / scope.object.zoom / element.clientWidth, scope.object.matrix);
6123
- panUp(deltaY * (scope.object.top - scope.object.bottom) / scope.object.zoom / element.clientHeight, scope.object.matrix);
6124
- } else {
6125
- console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.");
6126
- scope.enablePan = false;
6127
- }
6128
- };
6129
- }();
6130
- function dollyOut(dollyScale) {
6131
- if (scope.object.isPerspectiveCamera) {
6132
- scale /= dollyScale;
6133
- } else if (scope.object.isOrthographicCamera) {
6134
- scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom * dollyScale));
6135
- scope.object.updateProjectionMatrix();
6136
- zoomChanged = true;
5867
+ function handleTouchStartRotate() {
5868
+ if (pointers.length === 1) {
5869
+ rotateStart.set(pointers[0].pageX, pointers[0].pageY);
6137
5870
  } else {
6138
- console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
6139
- scope.enableZoom = false;
5871
+ const x = 0.5 * (pointers[0].pageX + pointers[1].pageX);
5872
+ const y = 0.5 * (pointers[0].pageY + pointers[1].pageY);
5873
+ rotateStart.set(x, y);
6140
5874
  }
6141
5875
  }
6142
- function dollyIn(dollyScale) {
6143
- if (scope.object.isPerspectiveCamera) {
6144
- scale *= dollyScale;
6145
- } else if (scope.object.isOrthographicCamera) {
6146
- scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / dollyScale));
6147
- scope.object.updateProjectionMatrix();
6148
- zoomChanged = true;
5876
+ function handleTouchStartPan() {
5877
+ if (pointers.length === 1) {
5878
+ panStart.set(pointers[0].pageX, pointers[0].pageY);
6149
5879
  } else {
6150
- console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
6151
- scope.enableZoom = false;
5880
+ const x = 0.5 * (pointers[0].pageX + pointers[1].pageX);
5881
+ const y = 0.5 * (pointers[0].pageY + pointers[1].pageY);
5882
+ panStart.set(x, y);
6152
5883
  }
6153
5884
  }
6154
- function handleMouseDownRotate(event) {
6155
- rotateStart.set(event.clientX, event.clientY);
5885
+ function handleTouchStartDolly() {
5886
+ const dx = pointers[0].pageX - pointers[1].pageX;
5887
+ const dy = pointers[0].pageY - pointers[1].pageY;
5888
+ const distance = Math.sqrt(dx * dx + dy * dy);
5889
+ dollyStart.set(0, distance);
6156
5890
  }
6157
- function handleMouseDownDolly(event) {
6158
- dollyStart.set(event.clientX, event.clientY);
5891
+ function handleTouchStartDollyPan() {
5892
+ if (scope.enableZoom) handleTouchStartDolly();
5893
+ if (scope.enablePan) handleTouchStartPan();
6159
5894
  }
6160
- function handleMouseDownPan(event) {
6161
- panStart.set(event.clientX, event.clientY);
5895
+ function handleTouchStartDollyRotate() {
5896
+ if (scope.enableZoom) handleTouchStartDolly();
5897
+ if (scope.enableRotate) handleTouchStartRotate();
6162
5898
  }
6163
- function handleMouseMoveRotate(event) {
6164
- rotateEnd.set(event.clientX, event.clientY);
5899
+ function handleTouchMoveRotate(event) {
5900
+ if (pointers.length == 1) {
5901
+ rotateEnd.set(event.pageX, event.pageY);
5902
+ } else {
5903
+ const position = getSecondPointerPosition(event);
5904
+ const x = 0.5 * (event.pageX + position.x);
5905
+ const y = 0.5 * (event.pageY + position.y);
5906
+ rotateEnd.set(x, y);
5907
+ }
6165
5908
  rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed);
6166
5909
  const element = scope.domElement;
6167
5910
  rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight);
6168
5911
  rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight);
6169
5912
  rotateStart.copy(rotateEnd);
6170
- scope.update();
6171
5913
  }
6172
- function handleMouseMoveDolly(event) {
6173
- dollyEnd.set(event.clientX, event.clientY);
6174
- dollyDelta.subVectors(dollyEnd, dollyStart);
6175
- if (dollyDelta.y > 0) {
6176
- dollyOut(getZoomScale());
6177
- } else if (dollyDelta.y < 0) {
6178
- dollyIn(getZoomScale());
5914
+ function handleTouchMovePan(event) {
5915
+ if (pointers.length === 1) {
5916
+ panEnd.set(event.pageX, event.pageY);
5917
+ } else {
5918
+ const position = getSecondPointerPosition(event);
5919
+ const x = 0.5 * (event.pageX + position.x);
5920
+ const y = 0.5 * (event.pageY + position.y);
5921
+ panEnd.set(x, y);
5922
+ }
5923
+ panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
5924
+ pan(panDelta.x, panDelta.y);
5925
+ panStart.copy(panEnd);
5926
+ }
5927
+ function handleTouchMoveDolly(event) {
5928
+ const position = getSecondPointerPosition(event);
5929
+ const dx = event.pageX - position.x;
5930
+ const dy = event.pageY - position.y;
5931
+ const distance = Math.sqrt(dx * dx + dy * dy);
5932
+ dollyEnd.set(0, distance);
5933
+ dollyDelta.set(0, Math.pow(dollyEnd.y / dollyStart.y, scope.zoomSpeed));
5934
+ dollyOut(dollyDelta.y);
5935
+ dollyStart.copy(dollyEnd);
5936
+ }
5937
+ function handleTouchMoveDollyPan(event) {
5938
+ if (scope.enableZoom) handleTouchMoveDolly(event);
5939
+ if (scope.enablePan) handleTouchMovePan(event);
5940
+ }
5941
+ function handleTouchMoveDollyRotate(event) {
5942
+ if (scope.enableZoom) handleTouchMoveDolly(event);
5943
+ if (scope.enableRotate) handleTouchMoveRotate(event);
5944
+ }
5945
+ function handleTouchEnd() {
5946
+ }
5947
+ function onPointerDown(event) {
5948
+ if (scope.enabled === false) return;
5949
+ if (pointers.length === 0) {
5950
+ scope.domElement.setPointerCapture(event.pointerId);
5951
+ scope.domElement.addEventListener("pointermove", onPointerMove);
5952
+ scope.domElement.addEventListener("pointerup", onPointerUp);
5953
+ }
5954
+ addPointer(event);
5955
+ if (event.pointerType === "touch") {
5956
+ onTouchStart(event);
5957
+ } else {
5958
+ onMouseDown(event);
5959
+ }
5960
+ }
5961
+ function onPointerMove(event) {
5962
+ if (scope.enabled === false) return;
5963
+ if (event.pointerType === "touch") {
5964
+ onTouchMove(event);
5965
+ } else {
5966
+ onMouseMove(event);
5967
+ }
5968
+ }
5969
+ function onPointerUp(event) {
5970
+ if (scope.enabled === false) return;
5971
+ if (event.pointerType === "touch") {
5972
+ onTouchEnd();
5973
+ } else {
5974
+ onMouseUp(event);
5975
+ }
5976
+ removePointer(event);
5977
+ if (pointers.length === 0) {
5978
+ scope.domElement.releasePointerCapture(event.pointerId);
5979
+ scope.domElement.removeEventListener("pointermove", onPointerMove);
5980
+ scope.domElement.removeEventListener("pointerup", onPointerUp);
5981
+ }
5982
+ }
5983
+ function onPointerCancel(event) {
5984
+ removePointer(event);
5985
+ }
5986
+ function onMouseDown(event) {
5987
+ let mouseAction;
5988
+ switch (event.button) {
5989
+ case 0:
5990
+ mouseAction = scope.mouseButtons.LEFT;
5991
+ break;
5992
+ case 1:
5993
+ mouseAction = scope.mouseButtons.MIDDLE;
5994
+ break;
5995
+ case 2:
5996
+ mouseAction = scope.mouseButtons.RIGHT;
5997
+ break;
5998
+ default:
5999
+ mouseAction = -1;
6000
+ }
6001
+ switch (mouseAction) {
6002
+ case import_three18.MOUSE.DOLLY:
6003
+ if (scope.enableZoom === false) return;
6004
+ handleMouseDownDolly(event);
6005
+ state = STATE.DOLLY;
6006
+ break;
6007
+ case import_three18.MOUSE.ROTATE:
6008
+ if (event.ctrlKey || event.metaKey || event.shiftKey) {
6009
+ if (scope.enablePan === false) return;
6010
+ handleMouseDownPan(event);
6011
+ state = STATE.PAN;
6012
+ } else {
6013
+ if (scope.enableRotate === false) return;
6014
+ handleMouseDownRotate(event);
6015
+ state = STATE.ROTATE;
6016
+ }
6017
+ break;
6018
+ case import_three18.MOUSE.PAN:
6019
+ if (event.ctrlKey || event.metaKey || event.shiftKey) {
6020
+ if (scope.enableRotate === false) return;
6021
+ handleMouseDownRotate(event);
6022
+ state = STATE.ROTATE;
6023
+ } else {
6024
+ if (scope.enablePan === false) return;
6025
+ handleMouseDownPan(event);
6026
+ state = STATE.PAN;
6027
+ }
6028
+ break;
6029
+ default:
6030
+ state = STATE.NONE;
6031
+ }
6032
+ if (state !== STATE.NONE) {
6033
+ scope.dispatchEvent(_startEvent);
6034
+ }
6035
+ }
6036
+ function onMouseMove(event) {
6037
+ if (scope.enabled === false) return;
6038
+ switch (state) {
6039
+ case STATE.ROTATE:
6040
+ if (scope.enableRotate === false) return;
6041
+ handleMouseMoveRotate(event);
6042
+ break;
6043
+ case STATE.DOLLY:
6044
+ if (scope.enableZoom === false) return;
6045
+ handleMouseMoveDolly(event);
6046
+ break;
6047
+ case STATE.PAN:
6048
+ if (scope.enablePan === false) return;
6049
+ handleMouseMovePan(event);
6050
+ break;
6179
6051
  }
6180
- dollyStart.copy(dollyEnd);
6181
- scope.update();
6182
6052
  }
6183
- function handleMouseMovePan(event) {
6184
- panEnd.set(event.clientX, event.clientY);
6185
- panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
6186
- pan(panDelta.x, panDelta.y);
6187
- panStart.copy(panEnd);
6188
- scope.update();
6053
+ function onMouseUp(event) {
6054
+ handleMouseUp(event);
6055
+ scope.dispatchEvent(_endEvent);
6056
+ state = STATE.NONE;
6189
6057
  }
6190
- function handleMouseUp() {
6058
+ function onMouseWheel(event) {
6059
+ if (scope.enabled === false || scope.enableZoom === false || state !== STATE.NONE) return;
6060
+ event.preventDefault();
6061
+ scope.dispatchEvent(_startEvent);
6062
+ handleMouseWheel(event);
6063
+ scope.dispatchEvent(_endEvent);
6191
6064
  }
6192
- function handleMouseWheel(event) {
6193
- if (event.deltaY < 0) {
6194
- dollyIn(getZoomScale());
6195
- } else if (event.deltaY > 0) {
6196
- dollyOut(getZoomScale());
6065
+ function onKeyDown(event) {
6066
+ if (scope.enabled === false || scope.enablePan === false) return;
6067
+ handleKeyDown(event);
6068
+ }
6069
+ function onTouchStart(event) {
6070
+ trackPointer(event);
6071
+ switch (pointers.length) {
6072
+ case 1:
6073
+ switch (scope.touches.ONE) {
6074
+ case import_three18.TOUCH.ROTATE:
6075
+ if (scope.enableRotate === false) return;
6076
+ handleTouchStartRotate();
6077
+ state = STATE.TOUCH_ROTATE;
6078
+ break;
6079
+ case import_three18.TOUCH.PAN:
6080
+ if (scope.enablePan === false) return;
6081
+ handleTouchStartPan();
6082
+ state = STATE.TOUCH_PAN;
6083
+ break;
6084
+ default:
6085
+ state = STATE.NONE;
6086
+ }
6087
+ break;
6088
+ case 2:
6089
+ switch (scope.touches.TWO) {
6090
+ case import_three18.TOUCH.DOLLY_PAN:
6091
+ if (scope.enableZoom === false && scope.enablePan === false) return;
6092
+ handleTouchStartDollyPan();
6093
+ state = STATE.TOUCH_DOLLY_PAN;
6094
+ break;
6095
+ case import_three18.TOUCH.DOLLY_ROTATE:
6096
+ if (scope.enableZoom === false && scope.enableRotate === false) return;
6097
+ handleTouchStartDollyRotate();
6098
+ state = STATE.TOUCH_DOLLY_ROTATE;
6099
+ break;
6100
+ default:
6101
+ state = STATE.NONE;
6102
+ }
6103
+ break;
6104
+ default:
6105
+ state = STATE.NONE;
6106
+ }
6107
+ if (state !== STATE.NONE) {
6108
+ scope.dispatchEvent(_startEvent);
6197
6109
  }
6198
- scope.update();
6199
6110
  }
6200
- function handleKeyDown(event) {
6201
- let needsUpdate = false;
6202
- switch (event.code) {
6203
- case scope.keys.UP:
6204
- pan(0, scope.keyPanSpeed);
6205
- needsUpdate = true;
6111
+ function onTouchMove(event) {
6112
+ trackPointer(event);
6113
+ switch (state) {
6114
+ case STATE.TOUCH_ROTATE:
6115
+ if (scope.enableRotate === false) return;
6116
+ handleTouchMoveRotate(event);
6117
+ scope.update();
6206
6118
  break;
6207
- case scope.keys.BOTTOM:
6208
- pan(0, -scope.keyPanSpeed);
6209
- needsUpdate = true;
6119
+ case STATE.TOUCH_PAN:
6120
+ if (scope.enablePan === false) return;
6121
+ handleTouchMovePan(event);
6122
+ scope.update();
6210
6123
  break;
6211
- case scope.keys.LEFT:
6212
- pan(scope.keyPanSpeed, 0);
6213
- needsUpdate = true;
6124
+ case STATE.TOUCH_DOLLY_PAN:
6125
+ if (scope.enableZoom === false && scope.enablePan === false) return;
6126
+ handleTouchMoveDollyPan(event);
6127
+ scope.update();
6214
6128
  break;
6215
- case scope.keys.RIGHT:
6216
- pan(-scope.keyPanSpeed, 0);
6217
- needsUpdate = true;
6129
+ case STATE.TOUCH_DOLLY_ROTATE:
6130
+ if (scope.enableZoom === false && scope.enableRotate === false) return;
6131
+ handleTouchMoveDollyRotate(event);
6132
+ scope.update();
6218
6133
  break;
6219
- }
6220
- if (needsUpdate) {
6221
- event.preventDefault();
6222
- scope.update();
6134
+ default:
6135
+ state = STATE.NONE;
6223
6136
  }
6224
6137
  }
6225
- function handleTouchStartRotate() {
6226
- if (pointers.length === 1) {
6227
- rotateStart.set(pointers[0].pageX, pointers[0].pageY);
6228
- } else {
6229
- const x = 0.5 * (pointers[0].pageX + pointers[1].pageX);
6230
- const y = 0.5 * (pointers[0].pageY + pointers[1].pageY);
6231
- rotateStart.set(x, y);
6138
+ function onTouchEnd(event) {
6139
+ handleTouchEnd(event);
6140
+ scope.dispatchEvent(_endEvent);
6141
+ state = STATE.NONE;
6142
+ }
6143
+ function onContextMenu(event) {
6144
+ if (scope.enabled === false) return;
6145
+ event.preventDefault();
6146
+ }
6147
+ function addPointer(event) {
6148
+ pointers.push(event);
6149
+ }
6150
+ function removePointer(event) {
6151
+ delete pointerPositions[event.pointerId];
6152
+ for (let i = 0; i < pointers.length; i++) {
6153
+ if (pointers[i].pointerId == event.pointerId) {
6154
+ pointers.splice(i, 1);
6155
+ return;
6156
+ }
6232
6157
  }
6233
6158
  }
6234
- function handleTouchStartPan() {
6235
- if (pointers.length === 1) {
6236
- panStart.set(pointers[0].pageX, pointers[0].pageY);
6237
- } else {
6238
- const x = 0.5 * (pointers[0].pageX + pointers[1].pageX);
6239
- const y = 0.5 * (pointers[0].pageY + pointers[1].pageY);
6240
- panStart.set(x, y);
6159
+ function trackPointer(event) {
6160
+ let position = pointerPositions[event.pointerId];
6161
+ if (position === void 0) {
6162
+ position = new import_three18.Vector2();
6163
+ pointerPositions[event.pointerId] = position;
6241
6164
  }
6165
+ position.set(event.pageX, event.pageY);
6242
6166
  }
6243
- function handleTouchStartDolly() {
6244
- const dx = pointers[0].pageX - pointers[1].pageX;
6245
- const dy = pointers[0].pageY - pointers[1].pageY;
6246
- const distance = Math.sqrt(dx * dx + dy * dy);
6247
- dollyStart.set(0, distance);
6167
+ function getSecondPointerPosition(event) {
6168
+ const pointer = event.pointerId === pointers[0].pointerId ? pointers[1] : pointers[0];
6169
+ return pointerPositions[pointer.pointerId];
6248
6170
  }
6249
- function handleTouchStartDollyPan() {
6250
- if (scope.enableZoom) handleTouchStartDolly();
6251
- if (scope.enablePan) handleTouchStartPan();
6171
+ scope.domElement.addEventListener("contextmenu", onContextMenu);
6172
+ scope.domElement.addEventListener("pointerdown", onPointerDown);
6173
+ scope.domElement.addEventListener("pointercancel", onPointerCancel);
6174
+ scope.domElement.addEventListener("wheel", onMouseWheel, { passive: false });
6175
+ this.update();
6176
+ }
6177
+ };
6178
+ var MapControls = class extends OrbitControls {
6179
+ constructor(object, domElement) {
6180
+ super(object, domElement);
6181
+ this.screenSpacePanning = false;
6182
+ this.mouseButtons.LEFT = import_three18.MOUSE.PAN;
6183
+ this.mouseButtons.RIGHT = import_three18.MOUSE.ROTATE;
6184
+ this.touches.ONE = import_three18.TOUCH.PAN;
6185
+ this.touches.TWO = import_three18.TOUCH.DOLLY_ROTATE;
6186
+ }
6187
+ };
6188
+
6189
+ // src/renderer/Renderer.ts
6190
+ var _Renderer = class _Renderer {
6191
+ constructor(options) {
6192
+ this._dirty = true;
6193
+ this._resizeListener = void 0;
6194
+ this._disposed = false;
6195
+ this._debugHelpers = [];
6196
+ this._eventDispatchers = /* @__PURE__ */ new Map();
6197
+ this._changeListener = () => {
6198
+ this._dirty = true;
6199
+ };
6200
+ this.options = (0, import_ts_deepmerge10.default)({}, _Renderer.DEFAULT_OPTIONS, options ?? {});
6201
+ this._animationLoop = this.animate.bind(this);
6202
+ this._frameInterval = this.options.render.fpsLimit > 0 ? 1e3 / this.options.render.fpsLimit : void 0;
6203
+ this._scene = this.createScene();
6204
+ this._camera = this.createCamera();
6205
+ this._renderer = this.createRenderer();
6206
+ this._composer = this.createComposer();
6207
+ if (this.options.render.stats) {
6208
+ this._stats = new import_stats.default();
6209
+ document.body.appendChild(this._stats.dom);
6252
6210
  }
6253
- function handleTouchStartDollyRotate() {
6254
- if (scope.enableZoom) handleTouchStartDolly();
6255
- if (scope.enableRotate) handleTouchStartRotate();
6211
+ this.init();
6212
+ this._controls = this.createControls();
6213
+ }
6214
+ //<editor-fold desc="INIT">
6215
+ createScene() {
6216
+ return new MineRenderScene();
6217
+ }
6218
+ createCamera() {
6219
+ switch (this.options.camera.type) {
6220
+ case "perspective":
6221
+ default:
6222
+ return new import_three19.PerspectiveCamera(
6223
+ this.options.camera.perspective.fov,
6224
+ this.options.camera.perspective.aspect ?? this.viewWidth / this.viewHeight,
6225
+ this.options.camera.near,
6226
+ this.options.camera.far
6227
+ );
6228
+ case "orthographic":
6229
+ return new import_three19.OrthographicCamera(
6230
+ this.options.camera.orthographic.left ?? this.viewWidth / -2,
6231
+ this.options.camera.orthographic.right ?? this.viewWidth / 2,
6232
+ this.options.camera.orthographic.top ?? this.viewHeight / 2,
6233
+ this.options.camera.orthographic.bottom ?? this.viewHeight / -2,
6234
+ this.options.camera.near,
6235
+ this.options.camera.far
6236
+ );
6256
6237
  }
6257
- function handleTouchMoveRotate(event) {
6258
- if (pointers.length == 1) {
6259
- rotateEnd.set(event.pageX, event.pageY);
6260
- } else {
6261
- const position = getSecondPointerPosition(event);
6262
- const x = 0.5 * (event.pageX + position.x);
6263
- const y = 0.5 * (event.pageY + position.y);
6264
- rotateEnd.set(x, y);
6238
+ }
6239
+ createRenderer() {
6240
+ const renderer = new import_three19.WebGLRenderer({
6241
+ antialias: this.options.render.antialias,
6242
+ alpha: true,
6243
+ powerPreference: "high-performance",
6244
+ depth: true
6245
+ });
6246
+ renderer.setClearColor(0, 0);
6247
+ renderer.shadowMap.enabled = true;
6248
+ renderer.shadowMap.type = import_three19.PCFSoftShadowMap;
6249
+ renderer.outputEncoding = import_three19.LinearEncoding;
6250
+ renderer.setSize(this.viewWidth, this.viewHeight);
6251
+ return renderer;
6252
+ }
6253
+ createComposer() {
6254
+ const composer = new import_postprocessing.EffectComposer(this.renderer);
6255
+ if (!this.options.composer.enabled) return composer;
6256
+ composer.setSize(this.viewWidth, this.viewHeight);
6257
+ composer.addPass(new import_postprocessing.RenderPass(this.scene, this.camera));
6258
+ return composer;
6259
+ }
6260
+ createControls() {
6261
+ if (!this.options.controls?.enabled) return void 0;
6262
+ const position = this.camera.position.clone();
6263
+ const controls = new OrbitControls(this.camera, this.renderer.domElement);
6264
+ this.camera.position.copy(position);
6265
+ const target = this.options.camera.lookingAt;
6266
+ if (isVector3(target)) {
6267
+ controls.target.copy(target);
6268
+ } else if (isTripleArray(target)) {
6269
+ controls.target.set(target[0], target[1], target[2]);
6270
+ }
6271
+ controls.update();
6272
+ controls.saveState();
6273
+ this.registerEventDispatcher(controls);
6274
+ return controls;
6275
+ }
6276
+ //</editor-fold>
6277
+ init() {
6278
+ if (this._disposed) return;
6279
+ if (typeof window["__THREE_DEVTOOLS__"] !== "undefined") {
6280
+ window["__THREE_DEVTOOLS__"].dispatchEvent(new CustomEvent("observe", { detail: this.scene }));
6281
+ }
6282
+ if (this.options.debug.grid) {
6283
+ const gridHelper = new import_three19.GridHelper(128, 16);
6284
+ this._debugHelpers.push(gridHelper);
6285
+ this.scene.add(gridHelper);
6286
+ const gridHelper2 = new import_three19.GridHelper(128, 16);
6287
+ this._debugHelpers.push(gridHelper2);
6288
+ gridHelper2.rotation.x = 90 * (Math.PI / 180);
6289
+ this.scene.add(gridHelper2);
6290
+ const gridHelper3 = new import_three19.GridHelper(128, 16);
6291
+ this._debugHelpers.push(gridHelper3);
6292
+ gridHelper3.rotation.z = 90 * (Math.PI / 180);
6293
+ this.scene.add(gridHelper3);
6294
+ }
6295
+ if (this.options.debug.axes) {
6296
+ const axesHelper = new import_three19.AxesHelper(64);
6297
+ this._debugHelpers.push(axesHelper);
6298
+ this.scene.add(axesHelper);
6299
+ }
6300
+ if (this.options.camera.position) {
6301
+ if (isVector3(this.options.camera.position)) {
6302
+ this.camera.position.set(this.options.camera.position.x, this.options.camera.position.y, this.options.camera.position.z);
6303
+ } else if (isTripleArray(this.options.camera.position)) {
6304
+ this.camera.position.set(this.options.camera.position[0], this.options.camera.position[1], this.options.camera.position[2]);
6265
6305
  }
6266
- rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed);
6267
- const element = scope.domElement;
6268
- rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight);
6269
- rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight);
6270
- rotateStart.copy(rotateEnd);
6271
6306
  }
6272
- function handleTouchMovePan(event) {
6273
- if (pointers.length === 1) {
6274
- panEnd.set(event.pageX, event.pageY);
6275
- } else {
6276
- const position = getSecondPointerPosition(event);
6277
- const x = 0.5 * (event.pageX + position.x);
6278
- const y = 0.5 * (event.pageY + position.y);
6279
- panEnd.set(x, y);
6307
+ if (this.options.camera.lookingAt) {
6308
+ if (isVector3(this.options.camera.lookingAt)) {
6309
+ this.camera.lookAt(this.options.camera.lookingAt);
6310
+ } else if (isTripleArray(this.options.camera.lookingAt)) {
6311
+ this.camera.lookAt(this.options.camera.lookingAt[0], this.options.camera.lookingAt[1], this.options.camera.lookingAt[2]);
6280
6312
  }
6281
- panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
6282
- pan(panDelta.x, panDelta.y);
6283
- panStart.copy(panEnd);
6284
6313
  }
6285
- function handleTouchMoveDolly(event) {
6286
- const position = getSecondPointerPosition(event);
6287
- const dx = event.pageX - position.x;
6288
- const dy = event.pageY - position.y;
6289
- const distance = Math.sqrt(dx * dx + dy * dy);
6290
- dollyEnd.set(0, distance);
6291
- dollyDelta.set(0, Math.pow(dollyEnd.y / dollyStart.y, scope.zoomSpeed));
6292
- dollyOut(dollyDelta.y);
6293
- dollyStart.copy(dollyEnd);
6314
+ if (this.options.render.autoResize && !this._resizeListener) {
6315
+ this._resizeListener = () => {
6316
+ this.resize(this.viewWidth, this.viewHeight);
6317
+ };
6318
+ window.addEventListener("resize", this._resizeListener);
6294
6319
  }
6295
- function handleTouchMoveDollyPan(event) {
6296
- if (scope.enableZoom) handleTouchMoveDolly(event);
6297
- if (scope.enablePan) handleTouchMovePan(event);
6320
+ }
6321
+ get element() {
6322
+ return this._element;
6323
+ }
6324
+ appendTo(element) {
6325
+ if (this._disposed) return;
6326
+ this._element = element;
6327
+ this._element.appendChild(this.renderer.domElement);
6328
+ if (this.viewWidth == 0) {
6329
+ console.warn("0 element width");
6298
6330
  }
6299
- function handleTouchMoveDollyRotate(event) {
6300
- if (scope.enableZoom) handleTouchMoveDolly(event);
6301
- if (scope.enableRotate) handleTouchMoveRotate(event);
6331
+ if (this.viewHeight == 0) {
6332
+ console.warn("0 element height");
6302
6333
  }
6303
- function handleTouchEnd() {
6334
+ this.resize(this.viewWidth, this.viewHeight);
6335
+ }
6336
+ /**
6337
+ * Redraws when the dispatcher emits the selected event. Registering the same pair twice has no effect.
6338
+ * The renderer removes its listener on disposal; the caller retains ownership of the dispatcher.
6339
+ */
6340
+ registerEventDispatcher(dispatcher, changeEvent2 = "change") {
6341
+ if (this._disposed) return;
6342
+ let events = this._eventDispatchers.get(dispatcher);
6343
+ if (!events) {
6344
+ events = /* @__PURE__ */ new Set();
6345
+ this._eventDispatchers.set(dispatcher, events);
6304
6346
  }
6305
- function onPointerDown(event) {
6306
- if (scope.enabled === false) return;
6307
- if (pointers.length === 0) {
6308
- scope.domElement.setPointerCapture(event.pointerId);
6309
- scope.domElement.addEventListener("pointermove", onPointerMove);
6310
- scope.domElement.addEventListener("pointerup", onPointerUp);
6311
- }
6312
- addPointer(event);
6313
- if (event.pointerType === "touch") {
6314
- onTouchStart(event);
6315
- } else {
6316
- onMouseDown(event);
6317
- }
6347
+ if (events.has(changeEvent2)) return;
6348
+ events.add(changeEvent2);
6349
+ dispatcher.addEventListener(changeEvent2, this._changeListener);
6350
+ }
6351
+ resize(width, height) {
6352
+ if (this._disposed) return;
6353
+ if (isPerspectiveCamera(this.camera)) {
6354
+ this.camera.aspect = width / height;
6355
+ this.camera.updateProjectionMatrix();
6356
+ } else if (isOrthographicCamera(this.camera)) {
6357
+ this.camera.left = width / -2;
6358
+ this.camera.right = width / 2;
6359
+ this.camera.top = height / 2;
6360
+ this.camera.bottom = height / -2;
6361
+ this.camera.updateProjectionMatrix();
6318
6362
  }
6319
- function onPointerMove(event) {
6320
- if (scope.enabled === false) return;
6321
- if (event.pointerType === "touch") {
6322
- onTouchMove(event);
6323
- } else {
6324
- onMouseMove(event);
6325
- }
6363
+ this.renderer.setSize(width, height);
6364
+ this.composer.setSize(width, height);
6365
+ this._dirty = true;
6366
+ }
6367
+ //<editor-fold desc="RENDER">
6368
+ get dirty() {
6369
+ return this._dirty || this.scene.dirty;
6370
+ }
6371
+ set dirty(dirty) {
6372
+ this._dirty = dirty;
6373
+ this.scene.dirty = dirty;
6374
+ }
6375
+ start() {
6376
+ if (this._disposed) return;
6377
+ this.stop();
6378
+ this.renderer.setAnimationLoop(this._animationLoop);
6379
+ }
6380
+ stop() {
6381
+ if (this._disposed) return;
6382
+ this.renderer.setAnimationLoop(null);
6383
+ this._nextFrameTime = void 0;
6384
+ }
6385
+ /**
6386
+ * Stops rendering and releases owned resources. Repeated calls have no effect, and a disposed
6387
+ * renderer cannot be restarted. Scene objects are detached; shared assets and caller-owned
6388
+ * controls must be managed by their owners.
6389
+ */
6390
+ dispose() {
6391
+ if (this._disposed) return;
6392
+ this.stop();
6393
+ this._disposed = true;
6394
+ if (this._resizeListener) {
6395
+ window.removeEventListener("resize", this._resizeListener);
6396
+ this._resizeListener = void 0;
6397
+ }
6398
+ for (const [dispatcher, events] of this._eventDispatchers) {
6399
+ for (const event of events) {
6400
+ dispatcher.removeEventListener(event, this._changeListener);
6401
+ }
6402
+ }
6403
+ this._eventDispatchers.clear();
6404
+ this._stats?.dom.remove();
6405
+ this._stats = void 0;
6406
+ this.renderer.domElement.remove();
6407
+ this._element = void 0;
6408
+ if (this._controls) {
6409
+ const controls = this._controls;
6410
+ this._controls = void 0;
6411
+ controls.enabled = false;
6412
+ controls.dispose();
6413
+ }
6414
+ this.scene.clear();
6415
+ for (const helper of this._debugHelpers) {
6416
+ helper.geometry.dispose();
6417
+ const materials = Array.isArray(helper.material) ? helper.material : [helper.material];
6418
+ for (const material of materials) {
6419
+ material.dispose();
6420
+ }
6421
+ }
6422
+ this._debugHelpers.length = 0;
6423
+ this.composer.dispose();
6424
+ this.renderer.dispose();
6425
+ this.renderer.forceContextLoss();
6426
+ }
6427
+ animate(t = performance.now()) {
6428
+ if (this._disposed) return;
6429
+ if (this._controls?.enabled) {
6430
+ this._controls.update();
6431
+ }
6432
+ if (this._disposed) return;
6433
+ if (!this.dirty && !this.options.render.renderAlways) return;
6434
+ const interval = this._frameInterval;
6435
+ if (interval) {
6436
+ const next = this._nextFrameTime;
6437
+ if (next !== void 0 && t + 0.1 < next) return;
6438
+ this._nextFrameTime = next !== void 0 && t - next < interval ? next + interval : t + interval;
6326
6439
  }
6327
- function onPointerUp(event) {
6328
- if (scope.enabled === false) return;
6329
- if (event.pointerType === "touch") {
6330
- onTouchEnd();
6331
- } else {
6332
- onMouseUp(event);
6333
- }
6334
- removePointer(event);
6335
- if (pointers.length === 0) {
6336
- scope.domElement.releasePointerCapture(event.pointerId);
6337
- scope.domElement.removeEventListener("pointermove", onPointerMove);
6338
- scope.domElement.removeEventListener("pointerup", onPointerUp);
6339
- }
6440
+ if (this._stats) {
6441
+ this._stats.begin();
6340
6442
  }
6341
- function onPointerCancel(event) {
6342
- removePointer(event);
6443
+ if (this.options.composer.enabled) {
6444
+ this.composer.render();
6445
+ } else {
6446
+ this.renderer.render(this.scene, this.camera);
6343
6447
  }
6344
- function onMouseDown(event) {
6345
- let mouseAction;
6346
- switch (event.button) {
6347
- case 0:
6348
- mouseAction = scope.mouseButtons.LEFT;
6349
- break;
6350
- case 1:
6351
- mouseAction = scope.mouseButtons.MIDDLE;
6352
- break;
6353
- case 2:
6354
- mouseAction = scope.mouseButtons.RIGHT;
6355
- break;
6356
- default:
6357
- mouseAction = -1;
6358
- }
6359
- switch (mouseAction) {
6360
- case import_three20.MOUSE.DOLLY:
6361
- if (scope.enableZoom === false) return;
6362
- handleMouseDownDolly(event);
6363
- state = STATE.DOLLY;
6364
- break;
6365
- case import_three20.MOUSE.ROTATE:
6366
- if (event.ctrlKey || event.metaKey || event.shiftKey) {
6367
- if (scope.enablePan === false) return;
6368
- handleMouseDownPan(event);
6369
- state = STATE.PAN;
6370
- } else {
6371
- if (scope.enableRotate === false) return;
6372
- handleMouseDownRotate(event);
6373
- state = STATE.ROTATE;
6374
- }
6375
- break;
6376
- case import_three20.MOUSE.PAN:
6377
- if (event.ctrlKey || event.metaKey || event.shiftKey) {
6378
- if (scope.enableRotate === false) return;
6379
- handleMouseDownRotate(event);
6380
- state = STATE.ROTATE;
6381
- } else {
6382
- if (scope.enablePan === false) return;
6383
- handleMouseDownPan(event);
6384
- state = STATE.PAN;
6385
- }
6386
- break;
6387
- default:
6388
- state = STATE.NONE;
6448
+ this.dirty = false;
6449
+ if (this._stats) {
6450
+ this._stats.end();
6451
+ }
6452
+ }
6453
+ //</editor-fold>
6454
+ toImage() {
6455
+ return this.renderer.domElement.toDataURL();
6456
+ }
6457
+ ///
6458
+ get attachedToBody() {
6459
+ return this.element === document.body;
6460
+ }
6461
+ get viewWidth() {
6462
+ return this.attachedToBody ? window.innerWidth : this.element?.offsetWidth || 0;
6463
+ }
6464
+ get viewHeight() {
6465
+ return this.attachedToBody ? window.innerHeight : this.element?.offsetHeight || 0;
6466
+ }
6467
+ get scene() {
6468
+ return this._scene;
6469
+ }
6470
+ get camera() {
6471
+ return this._camera;
6472
+ }
6473
+ get renderer() {
6474
+ return this._renderer;
6475
+ }
6476
+ get composer() {
6477
+ return this._composer;
6478
+ }
6479
+ /** Renderer-owned controls, or undefined when disabled at construction or after disposal. */
6480
+ get controls() {
6481
+ return this._controls;
6482
+ }
6483
+ ///
6484
+ };
6485
+ _Renderer.DEFAULT_OPTIONS = (0, import_ts_deepmerge10.default)({}, {
6486
+ camera: {
6487
+ type: "perspective",
6488
+ near: 1,
6489
+ far: 5e3,
6490
+ perspective: {
6491
+ aspect: void 0,
6492
+ fov: 50
6493
+ },
6494
+ orthographic: {
6495
+ left: void 0,
6496
+ right: void 0,
6497
+ top: void 0,
6498
+ bottom: void 0
6499
+ },
6500
+ position: new import_three19.Vector3(50, 50, 50),
6501
+ lookingAt: new import_three19.Vector3(0, 0, 0)
6502
+ },
6503
+ render: {
6504
+ fpsLimit: 60,
6505
+ stats: false,
6506
+ antialias: true,
6507
+ shade: true,
6508
+ autoResize: true,
6509
+ renderAlways: false
6510
+ },
6511
+ composer: {
6512
+ enabled: true
6513
+ },
6514
+ controls: {
6515
+ enabled: false
6516
+ },
6517
+ debug: {
6518
+ grid: false,
6519
+ axes: false
6520
+ }
6521
+ });
6522
+ var Renderer = _Renderer;
6523
+
6524
+ // src/skin/Skins.ts
6525
+ var Skins = class {
6526
+ //<editor-fold desc="Skins">
6527
+ static async fromUuidOrUsername(uuidOrUsername) {
6528
+ if (uuidOrUsername.length === 32 || uuidOrUsername.length === 36) {
6529
+ return this.fromUuid(uuidOrUsername);
6530
+ }
6531
+ return this.fromUsername(uuidOrUsername);
6532
+ }
6533
+ static async fromUuid(uuid) {
6534
+ return this.getSkinProxySkinUrl(uuid);
6535
+ }
6536
+ static async fromUsername(username) {
6537
+ return this.usernameToUuid(username).then((uuid) => {
6538
+ if (uuid) {
6539
+ return this.fromUuid(uuid);
6389
6540
  }
6390
- if (state !== STATE.NONE) {
6391
- scope.dispatchEvent(_startEvent);
6541
+ return void 0;
6542
+ });
6543
+ }
6544
+ static async fromMineSkin(mineskinId) {
6545
+ return this.getMineSkin(mineskinId).then((mineskin) => {
6546
+ if (mineskin) {
6547
+ return mineskin["data"]["texture"]["value"]["urls"]["skins"];
6392
6548
  }
6549
+ return void 0;
6550
+ });
6551
+ }
6552
+ //</editor-fold>
6553
+ //<editor-fold desc="Capes">
6554
+ static async capeFromUuidOrUsername(uuidOrUsername) {
6555
+ if (uuidOrUsername.length === 32 || uuidOrUsername.length === 36) {
6556
+ return this.capeFromUuid(uuidOrUsername);
6393
6557
  }
6394
- function onMouseMove(event) {
6395
- if (scope.enabled === false) return;
6396
- switch (state) {
6397
- case STATE.ROTATE:
6398
- if (scope.enableRotate === false) return;
6399
- handleMouseMoveRotate(event);
6400
- break;
6401
- case STATE.DOLLY:
6402
- if (scope.enableZoom === false) return;
6403
- handleMouseMoveDolly(event);
6404
- break;
6405
- case STATE.PAN:
6406
- if (scope.enablePan === false) return;
6407
- handleMouseMovePan(event);
6408
- break;
6558
+ return this.capeFromUsername(uuidOrUsername);
6559
+ }
6560
+ static async capeFromUuid(uuid) {
6561
+ return this.getSkinProxyCapeUrl(uuid);
6562
+ }
6563
+ static async capeFromUsername(username) {
6564
+ return this.usernameToUuid(username).then((uuid) => {
6565
+ if (uuid) {
6566
+ return this.capeFromUuid(uuid);
6409
6567
  }
6410
- }
6411
- function onMouseUp(event) {
6412
- handleMouseUp(event);
6413
- scope.dispatchEvent(_endEvent);
6414
- state = STATE.NONE;
6415
- }
6416
- function onMouseWheel(event) {
6417
- if (scope.enabled === false || scope.enableZoom === false || state !== STATE.NONE) return;
6418
- event.preventDefault();
6419
- scope.dispatchEvent(_startEvent);
6420
- handleMouseWheel(event);
6421
- scope.dispatchEvent(_endEvent);
6422
- }
6423
- function onKeyDown(event) {
6424
- if (scope.enabled === false || scope.enablePan === false) return;
6425
- handleKeyDown(event);
6426
- }
6427
- function onTouchStart(event) {
6428
- trackPointer(event);
6429
- switch (pointers.length) {
6430
- case 1:
6431
- switch (scope.touches.ONE) {
6432
- case import_three20.TOUCH.ROTATE:
6433
- if (scope.enableRotate === false) return;
6434
- handleTouchStartRotate();
6435
- state = STATE.TOUCH_ROTATE;
6436
- break;
6437
- case import_three20.TOUCH.PAN:
6438
- if (scope.enablePan === false) return;
6439
- handleTouchStartPan();
6440
- state = STATE.TOUCH_PAN;
6441
- break;
6442
- default:
6443
- state = STATE.NONE;
6444
- }
6445
- break;
6446
- case 2:
6447
- switch (scope.touches.TWO) {
6448
- case import_three20.TOUCH.DOLLY_PAN:
6449
- if (scope.enableZoom === false && scope.enablePan === false) return;
6450
- handleTouchStartDollyPan();
6451
- state = STATE.TOUCH_DOLLY_PAN;
6452
- break;
6453
- case import_three20.TOUCH.DOLLY_ROTATE:
6454
- if (scope.enableZoom === false && scope.enableRotate === false) return;
6455
- handleTouchStartDollyRotate();
6456
- state = STATE.TOUCH_DOLLY_ROTATE;
6457
- break;
6458
- default:
6459
- state = STATE.NONE;
6460
- }
6461
- break;
6462
- default:
6463
- state = STATE.NONE;
6568
+ return void 0;
6569
+ });
6570
+ }
6571
+ static async capeFromCapesDev(uuid, capeType = "minecraft") {
6572
+ return this.getCapesDev(uuid, capeType).then((cape) => {
6573
+ if (cape) {
6574
+ return cape?.stillImageUrl;
6464
6575
  }
6465
- if (state !== STATE.NONE) {
6466
- scope.dispatchEvent(_startEvent);
6576
+ return void 0;
6577
+ });
6578
+ }
6579
+ //</editor-fold>
6580
+ //<editor-fold desc="Helpers">
6581
+ static async usernameToUuid(username) {
6582
+ return this.usernameToUuidSkinProxy(username);
6583
+ }
6584
+ static async usernameToUuidSkinProxy(username) {
6585
+ return Requests.genericRequest({
6586
+ baseURL: "https://minecraft-skin-proxy.inventive.workers.dev",
6587
+ url: "/uuid/" + username
6588
+ }).then((res) => {
6589
+ if (res.status === 200) {
6590
+ return res.data["id"];
6467
6591
  }
6468
- }
6469
- function onTouchMove(event) {
6470
- trackPointer(event);
6471
- switch (state) {
6472
- case STATE.TOUCH_ROTATE:
6473
- if (scope.enableRotate === false) return;
6474
- handleTouchMoveRotate(event);
6475
- scope.update();
6476
- break;
6477
- case STATE.TOUCH_PAN:
6478
- if (scope.enablePan === false) return;
6479
- handleTouchMovePan(event);
6480
- scope.update();
6481
- break;
6482
- case STATE.TOUCH_DOLLY_PAN:
6483
- if (scope.enableZoom === false && scope.enablePan === false) return;
6484
- handleTouchMoveDollyPan(event);
6485
- scope.update();
6486
- break;
6487
- case STATE.TOUCH_DOLLY_ROTATE:
6488
- if (scope.enableZoom === false && scope.enableRotate === false) return;
6489
- handleTouchMoveDollyRotate(event);
6490
- scope.update();
6491
- break;
6492
- default:
6493
- state = STATE.NONE;
6592
+ return void 0;
6593
+ }).catch((err) => {
6594
+ console.warn(err);
6595
+ return void 0;
6596
+ });
6597
+ }
6598
+ static async usernameToUuidMineTools(username) {
6599
+ return Requests.genericRequest({
6600
+ baseURL: "https://api.minetools.eu",
6601
+ url: "/uuid/" + username
6602
+ }).then((res) => {
6603
+ if (res.status === 200) {
6604
+ return res.data["id"];
6494
6605
  }
6495
- }
6496
- function onTouchEnd(event) {
6497
- handleTouchEnd(event);
6498
- scope.dispatchEvent(_endEvent);
6499
- state = STATE.NONE;
6500
- }
6501
- function onContextMenu(event) {
6502
- if (scope.enabled === false) return;
6503
- event.preventDefault();
6504
- }
6505
- function addPointer(event) {
6506
- pointers.push(event);
6507
- }
6508
- function removePointer(event) {
6509
- delete pointerPositions[event.pointerId];
6510
- for (let i = 0; i < pointers.length; i++) {
6511
- if (pointers[i].pointerId == event.pointerId) {
6512
- pointers.splice(i, 1);
6513
- return;
6514
- }
6606
+ return void 0;
6607
+ }).catch((err) => {
6608
+ console.warn(err);
6609
+ return void 0;
6610
+ });
6611
+ }
6612
+ static async getProfileFromMinetools(uuid) {
6613
+ return Requests.genericRequest({
6614
+ baseURL: "https://api.minetools.eu",
6615
+ url: "/profile/" + uuid
6616
+ }).then((res) => {
6617
+ if (res.status === 200) {
6618
+ return res.data;
6515
6619
  }
6516
- }
6517
- function trackPointer(event) {
6518
- let position = pointerPositions[event.pointerId];
6519
- if (position === void 0) {
6520
- position = new import_three20.Vector2();
6521
- pointerPositions[event.pointerId] = position;
6620
+ });
6621
+ }
6622
+ static async getMineSkin(mineskinId) {
6623
+ return Requests.genericRequest({
6624
+ baseURL: "https://api.mineskin.org",
6625
+ url: "/get/uuid/" + mineskinId
6626
+ }).then((res) => {
6627
+ if (res.status === 200) {
6628
+ return res.data;
6522
6629
  }
6523
- position.set(event.pageX, event.pageY);
6524
- }
6525
- function getSecondPointerPosition(event) {
6526
- const pointer = event.pointerId === pointers[0].pointerId ? pointers[1] : pointers[0];
6527
- return pointerPositions[pointer.pointerId];
6528
- }
6529
- scope.domElement.addEventListener("contextmenu", onContextMenu);
6530
- scope.domElement.addEventListener("pointerdown", onPointerDown);
6531
- scope.domElement.addEventListener("pointercancel", onPointerCancel);
6532
- scope.domElement.addEventListener("wheel", onMouseWheel, { passive: false });
6533
- this.update();
6630
+ return void 0;
6631
+ }).catch((err) => {
6632
+ console.warn(err);
6633
+ return void 0;
6634
+ });
6534
6635
  }
6535
- };
6536
- var MapControls = class extends OrbitControls {
6537
- constructor(object, domElement) {
6538
- super(object, domElement);
6539
- this.screenSpacePanning = false;
6540
- this.mouseButtons.LEFT = import_three20.MOUSE.PAN;
6541
- this.mouseButtons.RIGHT = import_three20.MOUSE.ROTATE;
6542
- this.touches.ONE = import_three20.TOUCH.PAN;
6543
- this.touches.TWO = import_three20.TOUCH.DOLLY_ROTATE;
6636
+ static async getCapesDev(uuid, type = "all") {
6637
+ return Requests.genericRequest({
6638
+ baseURL: "https://api.capes.dev",
6639
+ url: "/load/" + uuid + "/" + type
6640
+ }).then((res) => {
6641
+ if (res.status === 200) {
6642
+ return res.data;
6643
+ }
6644
+ return void 0;
6645
+ }).catch((err) => {
6646
+ console.warn(err);
6647
+ return void 0;
6648
+ });
6649
+ }
6650
+ static getCrafatarSkinUrl(uuid) {
6651
+ return "https://crafatar.com/skins/" + uuid;
6544
6652
  }
6653
+ static getCrafatarCapeUrl(uuid) {
6654
+ return "https://crafatar.com/capes/" + uuid;
6655
+ }
6656
+ static getMcHeadsSkinUrl(uuid) {
6657
+ return "https://mc-heads.net/skin/" + uuid;
6658
+ }
6659
+ static getMineSkinPlayerSkinUrl(uuid) {
6660
+ return "https://mineskin.org/skin/player/" + uuid;
6661
+ }
6662
+ static getSkinProxySkinUrl(uuid) {
6663
+ return "https://minecraft-skin-proxy.inventive.workers.dev/skin/" + uuid;
6664
+ }
6665
+ static getSkinProxyCapeUrl(uuid) {
6666
+ return "https://minecraft-skin-proxy.inventive.workers.dev/cape/" + uuid;
6667
+ }
6668
+ //</editor-fold>
6545
6669
  };
6546
6670
 
6547
6671
  // src/world/Chunk.ts