hytopia 0.2.6 → 0.2.7

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.
@@ -304,7 +304,6 @@ function spawnPayloadEntity(world: World) {
304
304
  // We use a onCollision handler specific to this sensor, and
305
305
  // not the whole entity, so we can track the number of players in the payload sensor.
306
306
  onCollision: (other: BlockType | Entity, started: boolean) => {
307
- console.log(other.name, started);
308
307
  if (other instanceof PlayerEntity) {
309
308
  started ? payloadPlayerEntityCount++ : payloadPlayerEntityCount--;
310
309
  console.log('player count change', payloadPlayerEntityCount, started, other.name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hytopia",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "The HYTOPIA SDK makes it easy for developers to create massively multiplayer games using JavaScript or TypeScript.",
5
5
  "main": "server.js",
6
6
  "bin": {
package/server.js CHANGED
@@ -335,6 +335,6 @@ Please see the 3.x to 4.x migration guide for details on how to update your app.
335
335
  `),Z.write(`Content-Length: ${K.length}\r
336
336
  `),Z.write(`Connection: close\r
337
337
  `),Z.write(`\r
338
- `),Z.write(K),Z.end();return}K0.serverInstance.emit("WEBSERVER.UPGRADE",{req:J,socket:Z,head:Y})};_onError=(J)=>{K0.serverInstance.emit("WEBSERVER.ERROR",{error:J})};_onStopped=()=>{K0.serverInstance.emit("WEBSERVER.STOPPED",{})}}class Z7{static instance=new Z7;_wss;constructor(){this._wss=new Bu({noServer:!0}),this._wss.on("connection",this._onConnection),this._wss.on("error",this._onError),K0.serverInstance.on("WEBSERVER.UPGRADE",({req:J,socket:Z,head:Y})=>this._onUpgrade(J,Z,Y))}_onConnection=(J,Z)=>{new RZ(J,Z)};_onError=(J,Z)=>{K0.serverInstance.emit("SOCKET.ERROR",{ws:J,error:Z})};_onUpgrade=(J,Z,Y)=>{this._wss.handleUpgrade(J,Z,Y,(X)=>{this._wss.emit("connection",X,J)})}}var g=new Error("RigidBody has been removed from the simulation and is therefore inaccessible."),CY;((F)=>{F.DYNAMIC="dynamic";F.FIXED="fixed";F.KINEMATIC_POSITION="kinematic_position";F.KINEMATIC_VELOCITY="kinematic_velocity"})(CY||={});var D6=0.001,bR="dynamic";class r9{_additionalMass=0;_colliders=new Set;_explicitSleep=!1;_enabledPositions={x:!0,y:!0,z:!0};_enabledRotations={x:!0,y:!0,z:!0};_rigidBody;_rigidBodyDesc;_rigidBodyType;_simulation;constructor(J){J.type??=bR,this._rigidBodyDesc=this._createRigidBodyDesc(J),this._rigidBodyType=J.type,this._applyRigidBodyOptions(J),this._autoAddToSimulation(J)}get additionalMass(){if(this._rigidBody||this._rigidBodyDesc)return this._additionalMass;throw g}get additionalSolverIterations(){if(this._rigidBody)return this._rigidBody.additionalSolverIterations();if(this._rigidBodyDesc)return this._rigidBodyDesc.additionalSolverIterations;throw g}get angularDamping(){if(this._rigidBody)return this._rigidBody.angularDamping();if(this._rigidBodyDesc)return this._rigidBodyDesc.angularDamping;throw g}get angularVelocity(){if(this._rigidBody)return this._rigidBody.angvel();if(this._rigidBodyDesc)return this._rigidBodyDesc.angvel;throw g}get colliders(){return this._colliders}get dominanceGroup(){if(this._rigidBody)return this._rigidBody.dominanceGroup();if(this._rigidBodyDesc)return this._rigidBodyDesc.dominanceGroup;throw g}get directionFromRotation(){let{x:J,y:Z,z:Y,w:X}=this.rotation;return{x:2*(J*Y+X*Z),y:2*(Z*Y-X*J),z:1-2*(J*J+Z*Z)}}get effectiveAngularInertia(){if(this._rigidBody)return this._rigidBody.effectiveAngularInertia();if(this._rigidBodyDesc)return;throw g}get effectiveInverseMass(){if(this._rigidBody)return this._rigidBody.effectiveInvMass();if(this._rigidBodyDesc)return;throw g}get effectiveWorldInversePrincipalAngularInertiaSqrt(){if(this._rigidBody)return this._rigidBody.effectiveWorldInvInertiaSqrt();if(this._rigidBodyDesc)return;throw g}get enabledRotations(){if(this._rigidBody||this._rigidBodyDesc)return this._enabledRotations;throw g}get enabledPositions(){if(this._rigidBody||this._rigidBodyDesc)return this._enabledPositions;throw g}get gravityScale(){if(this._rigidBody)return this._rigidBody.gravityScale();if(this._rigidBodyDesc)return this._rigidBodyDesc.gravityScale;throw g}get inverseMass(){if(this._rigidBody)return this._rigidBody.invMass();if(this._rigidBodyDesc)return;throw g}get inversePrincipalAngularInertiaSqrt(){if(this._rigidBody)return this._rigidBody.invPrincipalInertiaSqrt();if(this._rigidBodyDesc)return;throw g}get isCcdEnabled(){if(this._rigidBody)return this._rigidBody.isCcdEnabled();if(this._rigidBodyDesc)return this._rigidBodyDesc.ccdEnabled;throw g}get isDynamic(){if(this._rigidBody||this._rigidBodyDesc)return this._rigidBodyType==="dynamic";throw g}get isEnabled(){if(this._rigidBody)return this._rigidBody.isEnabled();if(this._rigidBodyDesc)return this._rigidBodyDesc.enabled;throw g}get isFixed(){if(this._rigidBody||this._rigidBodyDesc)return this._rigidBodyType==="fixed";throw g}get isKinematic(){if(this._rigidBody||this._rigidBodyDesc)return["kinematic_position","kinematic_velocity"].includes(this._rigidBodyType);throw g}get isKinematicPositionBased(){if(this._rigidBody||this._rigidBodyDesc)return this._rigidBodyType==="kinematic_position";throw g}get isKinematicVelocityBased(){if(this._rigidBody||this._rigidBodyDesc)return this._rigidBodyType==="kinematic_velocity";throw g}get isMoving(){if(this._rigidBody)return this._rigidBody.isMoving();if(this._rigidBodyDesc)return!1;throw g}get isRemoved(){return!this._rigidBody&&!this._rigidBodyDesc}get isSimulated(){if(this._rigidBody)return!0;if(this._rigidBodyDesc)return!1;throw g}get isSleeping(){if(this._rigidBody)return this._rigidBody.isSleeping();if(this._rigidBodyDesc)return this._rigidBodyDesc.sleeping;throw g}get linearDamping(){if(this._rigidBody)return this._rigidBody.linearDamping();if(this._rigidBodyDesc)return this._rigidBodyDesc.linearDamping;throw g}get linearVelocity(){if(this._rigidBody)return this._rigidBody.linvel();if(this._rigidBodyDesc)return this._rigidBodyDesc.linvel;throw g}get localCenterOfMass(){if(this._rigidBody)return this._rigidBody.localCom();if(this._rigidBodyDesc)return this._rigidBodyDesc.centerOfMass;throw g}get mass(){if(this._rigidBody)return this._rigidBody.mass();if(this._rigidBodyDesc)return this._rigidBodyDesc.mass;throw g}get nextKinematicRotation(){if(this._rigidBody)return this._rigidBody.nextRotation();if(this._rigidBodyDesc)return this._rigidBodyDesc.rotation;throw g}get nextKinematicPosition(){if(this._rigidBody)return this._rigidBody.nextTranslation();if(this._rigidBodyDesc)return this._rigidBodyDesc.translation;throw g}get numColliders(){return this._colliders.size}get principalAngularInertia(){if(this._rigidBody)return this._rigidBody.principalInertia();if(this._rigidBodyDesc)return this._rigidBodyDesc.principalAngularInertia;throw g}get principalAngularInertiaLocalFrame(){if(this._rigidBody)return this._rigidBody.principalInertiaLocalFrame();if(this._rigidBodyDesc)return;throw g}get position(){if(this._rigidBody)return this._rigidBody.translation();if(this._rigidBodyDesc)return this._rigidBodyDesc.translation;throw g}get rawRigidBody(){if(this._rigidBody)return this._rigidBody;if(this._rigidBodyDesc)return;throw g}get rotation(){if(this._rigidBody)return this._rigidBody.rotation();if(this._rigidBodyDesc)return this._rigidBodyDesc.rotation;throw g}get softCcdPrediction(){if(this._rigidBody)return this._rigidBody.softCcdPrediction();if(this._rigidBodyDesc)return this._rigidBodyDesc.softCcdPrediction;throw g}get type(){if(this._rigidBody||this._rigidBodyDesc)return this._rigidBodyType;throw g}get worldCenterOfMass(){if(this._rigidBody)return this._rigidBody.worldCom();if(this._rigidBodyDesc)return;throw g}setAdditionalMass(J){if(this._requireDynamic(),this._rigidBody)this._rigidBody.setAdditionalMass(J,!this._explicitSleep);else if(this._rigidBodyDesc)this._rigidBodyDesc.setAdditionalMass(J);else throw g}setAdditionalMassProperties(J){this._requireDynamic();let{additionalMass:Z,centerOfMass:Y,principalAngularInertia:X,principalAngularInertiaLocalFrame:F}=J;if(this._rigidBody)this._rigidBody.setAdditionalMassProperties(Z,Y,X,F,!this._explicitSleep);else if(this._rigidBodyDesc)this._rigidBodyDesc.setAdditionalMassProperties(Z,Y,X,F);else throw g;this._additionalMass=Z}setAdditionalSolverIterations(J){if(this._requireDynamic(),this._rigidBody)this._rigidBody.setAdditionalSolverIterations(J);else if(this._rigidBodyDesc)this._rigidBodyDesc.setAdditionalSolverIterations(J);else throw g}setAngularDamping(J){if(this._requireDynamic(),this._rigidBody)this._rigidBody.setAngularDamping(J);else if(this._rigidBodyDesc)this._rigidBodyDesc.setAngularDamping(J);else throw g}setAngularVelocity(J){if(this._requireNotKinematicPositionBased(),this._rigidBody)this._rigidBody.setAngvel(J,!this._explicitSleep);else if(this._rigidBodyDesc)this._rigidBodyDesc.setAngvel(J);else throw g}setCcdEnabled(J){if(this._requireDynamic(),this._rigidBody)this._rigidBody.enableCcd(J);else if(this._rigidBodyDesc)this._rigidBodyDesc.setCcdEnabled(J);else throw g}setDominanceGroup(J){if(this._requireDynamic(),this._rigidBody)this._rigidBody.setDominanceGroup(J);else if(this._rigidBodyDesc)this._rigidBodyDesc.setDominanceGroup(J);else throw g}setEnabled(J){if(this._rigidBody)this._rigidBody.setEnabled(J);else if(this._rigidBodyDesc)this._rigidBodyDesc.setEnabled(J);else throw g}setEnabledPositions(J){if(this._requireDynamic(),this._rigidBody)this._rigidBody.setEnabledTranslations(J.x,J.y,J.z,!this._explicitSleep);else if(this._rigidBodyDesc)this._rigidBodyDesc.enabledTranslations(J.x,J.y,J.z);else throw g;this._enabledPositions=J}setEnabledRotations(J){if(this._requireDynamic(),this._rigidBody)this._rigidBody.setEnabledRotations(J.x,J.y,J.z,!this._explicitSleep);else if(this._rigidBodyDesc)this._rigidBodyDesc.enabledRotations(J.x,J.y,J.z);else throw g;this._enabledRotations=J}setGravityScale(J){if(this._requireDynamic(),this._rigidBody)this._rigidBody.setGravityScale(J,!this._explicitSleep);else if(this._rigidBodyDesc)this._rigidBodyDesc.setGravityScale(J);else throw g}setLinearDamping(J){if(this._requireDynamic(),this._rigidBody)this._rigidBody.setLinearDamping(J);else if(this._rigidBodyDesc)this._rigidBodyDesc.setLinearDamping(J);else throw g}setLinearVelocity(J){if(this._requireNotKinematicPositionBased(),this._rigidBody)this._rigidBody.setLinvel(J,!this._explicitSleep);else if(this._rigidBodyDesc)this._rigidBodyDesc.setLinvel(J.x,J.y,J.z);else throw g}setNextKinematicRotation(J){if(this._requireKinematic(),this._rigidBody)this._rigidBody.setNextKinematicRotation(J);else if(this._rigidBodyDesc)this._rigidBodyDesc.setRotation(J);else throw g}setNextKinematicPosition(J){if(this._requireKinematic(),this._rigidBody)this._rigidBody.setNextKinematicTranslation(J);else if(this._rigidBodyDesc)this._rigidBodyDesc.setTranslation(J.x,J.y,J.z);else throw g}setPosition(J){if(this._rigidBody)this._rigidBody.setTranslation(J,!this._explicitSleep);else if(this._rigidBodyDesc)this._rigidBodyDesc.setTranslation(J.x,J.y,J.z);else throw g}setRotation(J){if(this._rigidBody)this._rigidBody.setRotation(J,!this._explicitSleep);else if(this._rigidBodyDesc)this._rigidBodyDesc.setRotation(J);else throw g}setSleeping(J){if(this._requireDynamic(),this._rigidBody)J?this._rigidBody.sleep():this._rigidBody.wakeUp();else if(this._rigidBodyDesc)this._rigidBodyDesc.sleeping=J;else throw g;this._explicitSleep=J}setSoftCcdPrediction(J){if(this._requireDynamic(),this._rigidBody)this._rigidBody.setSoftCcdPrediction(J);else if(this._rigidBodyDesc)this._rigidBodyDesc.setSoftCcdPrediction(J);else throw g}setCollisionGroupsForSolidColliders(J){this._requireNotRemoved(),this._colliders.forEach((Z)=>{if(Z.isSensor)return;Z.setCollisionGroups(J)})}setCollisionGroupsForSensorColliders(J){this._requireNotRemoved(),this._colliders.forEach((Z)=>{if(!Z.isSensor)return;Z.setCollisionGroups(J)})}setType(J){let Y={["dynamic"]:v0.RigidBodyType.Dynamic,["fixed"]:v0.RigidBodyType.Fixed,["kinematic_position"]:v0.RigidBodyType.KinematicPositionBased,["kinematic_velocity"]:v0.RigidBodyType.KinematicVelocityBased}[J];if(Y===void 0)throw new Error(`Invalid RigidBodyType: ${J}`);if(this._rigidBody)this._rigidBody.setBodyType(Y,!this._explicitSleep);else if(this._rigidBodyDesc)this._rigidBodyDesc.status=Y;else throw g;this._rigidBodyType=J}addForce(J){if(this._requireNotRemoved(),this._requireCreated(),this._requireDynamic(),this._isNegligibleVector(J))return;this._rigidBody.addForce(J,!this._explicitSleep)}addTorque(J){if(this._requireNotRemoved(),this._requireCreated(),this._requireDynamic(),this._isNegligibleVector(J))return;this._rigidBody.addTorque(J,!this._explicitSleep)}addChildColliderToSimulation(J){this._requireNotRemoved(),this._requireCreated(),J.addToSimulation(this._simulation,this)}addToSimulation(J){if(this._requireNotRemoved(),this._rigidBody)throw new Error("RigidBody.create(): Rigid body already exists in the simulation!");this._simulation=J,this._rigidBody=this._simulation.createRawRigidBody(this._rigidBodyDesc),this._colliders.forEach((Z)=>{if(!Z.isSimulated)Z.addToSimulation(J,this)})}applyImpulse(J){if(this._requireNotRemoved(),this._requireCreated(),this._requireDynamic(),this._isNegligibleVector(J))return;this._rigidBody.applyImpulse(J,!this._explicitSleep)}applyImpulseAtPoint(J,Z){if(this._requireNotRemoved(),this._requireCreated(),this._requireDynamic(),this._isNegligibleVector(J))return;this._rigidBody.applyImpulseAtPoint(J,Z,!this._explicitSleep)}applyTorqueImpulse(J){this._requireNotRemoved(),this._requireCreated(),this._requireDynamic(),this._rigidBody.applyTorqueImpulse(J,!this._explicitSleep)}createAndAddChildCollider(J){return this._requireNotRemoved(),this._simulation?new m8({...J,parentRigidBody:this,simulation:this._simulation}):this._createAndAddPendingChildCollider(J)}createAndAddChildCollidersToSimulation(J){let Z=[];return J.forEach((Y)=>{Z.push(this.createAndAddChildCollider(Y))}),Z}getCollidersByTag(J){let Z=[];for(let Y of this._colliders)if(Y.tag===J)Z.push(Y);return Z}linkCollider(J){if(this._requireNotRemoved(),J.parentRigidBody!==this)throw new Error("RigidBody.linkCollider(): Collider cannot be linked because it is not a child of this rigid body!");this._colliders.add(J)}lockAllRotations(){this._requireNotRemoved(),this.setEnabledRotations({x:!1,y:!1,z:!1})}lockAllPositions(){this._requireNotRemoved(),this.setEnabledPositions({x:!1,y:!1,z:!1})}removeFromSimulation(){if(this._requireNotRemoved(),!this._rigidBody)throw new Error("RigidBody.removeFromSimulation(): Rigid body does not exist in the simulation!");this._colliders.forEach((J)=>{J.removeFromSimulation()}),this._simulation.removeRawRigidBody(this._rigidBody),this._simulation=void 0,this._rigidBody=void 0}unlinkCollider(J){if(this._requireNotRemoved(),!J.isRemoved)throw new Error("RigidBody.unlinkCollider(): Collider is still simulated and therefore cannot be unlinked from this rigid body!");this._colliders.delete(J)}resetAngularVelocity(){this._requireNotRemoved(),this._requireCreated(),this.setAngularVelocity({x:0,y:0,z:0})}resetForces(){this._requireNotRemoved(),this._requireCreated(),this._rigidBody.resetForces(!this._explicitSleep)}resetLinearVelocity(){this._requireNotRemoved(),this._requireCreated(),this.setLinearVelocity({x:0,y:0,z:0})}resetTorques(){this._requireNotRemoved(),this._requireCreated(),this._rigidBody.resetTorques(!this._explicitSleep)}sleep(){this._requireNotRemoved(),this.setSleeping(!0)}wakeUp(){this._requireNotRemoved(),this.setSleeping(!1)}_applyRigidBodyOptions(J){[["additionalMass",this.setAdditionalMass.bind(this)],["additionalMassProperties",this.setAdditionalMassProperties.bind(this)],["additionalSolverIterations",this.setAdditionalSolverIterations.bind(this)],["angularDamping",this.setAngularDamping.bind(this)],["angularVelocity",this.setAngularVelocity.bind(this)],["dominanceGroup",this.setDominanceGroup.bind(this)],["ccdEnabled",this.setCcdEnabled.bind(this)],["enabled",this.setEnabled.bind(this)],["enabledPositions",this.setEnabledPositions.bind(this)],["enabledRotations",this.setEnabledRotations.bind(this)],["gravityScale",this.setGravityScale.bind(this)],["linearDamping",this.setLinearDamping.bind(this)],["linearVelocity",this.setLinearVelocity.bind(this)],["position",this.setPosition.bind(this)],["rotation",this.setRotation.bind(this)],["sleeping",this.setSleeping.bind(this)],["softCcdPrediction",this.setSoftCcdPrediction.bind(this)]].forEach(([Y,X])=>{if(J[Y]!==void 0)X.call(this,J[Y])})}_autoAddToSimulation(J){if(J.colliders)this._createAndAddPendingChildColliders(J.colliders);if(J.simulation)this.addToSimulation(J.simulation)}_createAndAddPendingChildCollider(J){this._requireNotRemoved(),this._requireNotSimulated();let Z=new m8(J);return this._colliders.add(Z),Z}_createAndAddPendingChildColliders(J){let Z=[];return J.forEach((Y)=>{Z.push(this._createAndAddPendingChildCollider(Y))}),Z}_createRigidBodyDesc(J){let Z=J.type??bR;return{["dynamic"]:()=>v0.RigidBodyDesc.dynamic(),["fixed"]:()=>v0.RigidBodyDesc.fixed(),["kinematic_position"]:()=>v0.RigidBodyDesc.kinematicPositionBased(),["kinematic_velocity"]:()=>v0.RigidBodyDesc.kinematicVelocityBased()}[Z]()}_requireCreated(){if(!this._rigidBody||!this._simulation)throw new Error("RigidBody._requireCreated(): Rigid body has not been created and therefore does not support the invoked method.")}_requireDynamic(){if(!this.isDynamic)throw new Error("RigidBody._requireDynamic(): Rigid body is not dynamic and therefore does not support the invoked method.")}_requireKinematic(){if(!this.isKinematic)throw new Error("RigidBody._requireKinematic(): Rigid body is not kinematic and therefore does not support the invoked method.")}_requireNotKinematicPositionBased(){if(this.isKinematicPositionBased)throw new Error("RigidBody._requireNotKinematicPositionBased(): Rigid body is kinematic position based and therefore does not support the invoked method.")}_requireNotRemoved(){if(!this._rigidBody&&!this._rigidBodyDesc)throw g}_requireNotSimulated(){if(this.isSimulated)throw new Error("RigidBody._requireNotSimulated(): Rigid body is simulated and therefore does not support the invoked method.")}_isEqualVectors(J,Z){return Math.abs(J.x-Z.x)<D6&&Math.abs(J.y-Z.y)<D6&&Math.abs(J.z-Z.z)<D6}_isEqualRotations(J,Z){return Math.abs(J.x-Z.x)<D6&&Math.abs(J.y-Z.y)<D6&&Math.abs(J.z-Z.z)<D6&&Math.abs(J.w-Z.w)<D6}_isNegligibleVector(J){return Math.abs(J.x)<D6&&Math.abs(J.y)<D6&&Math.abs(J.z)<D6}}var n0=16,nQ=n0-1,mR=n0**3,Tu=[{neighborOffset:[-1,0,0],generateVertices:(J,Z,Y)=>[J+0,Z+0,Y+0,J+0,Z+0,Y+1,J+0,Z+1,Y+0,J+0,Z+1,Y+0,J+0,Z+1,Y+1,J+0,Z+0,Y+1]},{neighborOffset:[1,0,0],generateVertices:(J,Z,Y)=>[J+1,Z+0,Y+0,J+1,Z+0,Y+1,J+1,Z+1,Y+0,J+1,Z+1,Y+0,J+1,Z+1,Y+1,J+1,Z+0,Y+1]},{neighborOffset:[0,-1,0],generateVertices:(J,Z,Y)=>[J+0,Z+0,Y+0,J+0,Z+0,Y+1,J+1,Z+0,Y+1,J+1,Z+0,Y+1,J+1,Z+0,Y+0,J+0,Z+0,Y+0]},{neighborOffset:[0,1,0],generateVertices:(J,Z,Y)=>[J+0,Z+1,Y+0,J+0,Z+1,Y+1,J+1,Z+1,Y+1,J+1,Z+1,Y+1,J+1,Z+1,Y+0,J+0,Z+1,Y+0]},{neighborOffset:[0,0,-1],generateVertices:(J,Z,Y)=>[J+0,Z+0,Y+0,J+1,Z+0,Y+0,J+0,Z+1,Y+0,J+0,Z+1,Y+0,J+1,Z+1,Y+0,J+1,Z+0,Y+0]},{neighborOffset:[0,0,1],generateVertices:(J,Z,Y)=>[J+0,Z+0,Y+1,J+1,Z+0,Y+1,J+0,Z+1,Y+1,J+0,Z+1,Y+1,J+1,Z+1,Y+1,J+1,Z+0,Y+1]}],uQ;((X)=>{X.DESPAWN="CHUNK.DESPAWN";X.SET_BLOCK="CHUNK.SET_BLOCK";X.SPAWN="CHUNK.SPAWN"})(uQ||={});class I8{_blocks;_originCoordinate;_requiresUpdate=!1;_rigidBody;_world;constructor(){this._blocks=new Uint8Array(mR)}get blocks(){return this._blocks}get requiresUpdate(){return this._requiresUpdate}get isSimulated(){return!!this._rigidBody}get isSpawned(){return!!this._originCoordinate&&!!this._world}get originCoordinate(){return this._originCoordinate}get world(){return this._world}static blockIndexToLocalCoordinate(J){return{x:J%n0,y:(J/n0|0)%n0,z:J/(n0*n0)|0}}static globalCoordinateToLocalCoordinate(J){return{x:J.x&n0-1,y:J.y&n0-1,z:J.z&n0-1}}static globalCoordinateToOriginCoordinate(J){return{x:J.x&~(n0-1),y:J.y&~(n0-1),z:J.z&~(n0-1)}}static isValidOriginCoordinate(J){return J.x%n0===0&&J.y%n0===0&&J.z%n0===0}spawn(J,Z){if(this.isSpawned){let{x:Y,y:X,z:F}=this.originCoordinate;throw new Error(`Chunk.spawn(): Chunk is already spawned at origin ${Y}, ${X}, ${F}!`)}if(!I8.isValidOriginCoordinate(Z))throw new Error(`Chunk.spawn(): Chunk coordinates must be divisible by ${n0}`);this._originCoordinate=Z,this._world=J,this._world.chunkLattice.registerChunk(this),this._requiresUpdate=!0}despawn(){if(!this.isSpawned)throw new Error("Chunk.despawn(): Chunk has not been spawned and cannot be despawned!");this._world.eventRouter.emit("CHUNK.DESPAWN",{chunk:this}),this._removeFromSimulation(),this._world.chunkLattice.unregisterChunk(this),this._originCoordinate=void 0,this._world=void 0}getBlockId(J){return this._blocks[this._getIndex(J)]}hasBlock(J){return this._blocks[this._getIndex(J)]!==0}setBlock(J,Z){if(!this._isValidLocalCoordinate(J))throw new Error("Chunk.setBlock(): Block local coordinate is out of bounds");if(this._blocks[this._getIndex(J)]===Z)return;if(this._blocks[this._getIndex(J)]=Z,this.isSpawned&&this.isSimulated)this._world.eventRouter.emit("CHUNK.SET_BLOCK",{chunk:this,globalCoordinate:this._getGlobalCoordinate(J),localCoordinate:J,blockTypeId:Z});this._requiresUpdate=!0}update(){if(!this._requiresUpdate)return;if(!this.isSpawned)throw new Error("Chunk.update(): Chunk is not spawned and cannot be updated.");let J=!this._rigidBody,Z=this._world.simulation;if(this._removeFromSimulation(),this._rigidBody=new r9({type:"fixed",position:this._originCoordinate,simulation:this._world.simulation}),this._meshColliders().map(([Y,X])=>{if(!Y.isSimulated)Y.addToSimulation(Z,this._rigidBody);Z.colliderMap.setColliderBlockType(Y,X)}),this._requiresUpdate=!1,J)this._world.eventRouter.emit("CHUNK.SPAWN",{chunk:this})}serialize(){return t.serializeChunk(this)}_meshColliders(){if(!this._world)throw new Error("Chunk._meshColliders(): Chunk is not spawned and cannot be meshed.");let J=new Map,Z=[];for(let X=0;X<mR;X++){if(this._blocks[X]===0)continue;let F=this._blocks[X],K=this._world.blockTypeRegistry.getBlockType(F),{x:$,y:Q,z:W}=I8.blockIndexToLocalCoordinate(X);if(!K.isMeshable){let V=K.createCollider();V.setRelativePosition({x:$,y:Q,z:W}),Z.push([V,K]);continue}let G=J.get(K)??{indices:[],vertices:[]};J.set(K,G);for(let V of Tu){let[O,v,w]=V.neighborOffset,H={x:$+O,y:Q+v,z:W+w},N=this._getGlobalCoordinate(H),q=this._world.chunkLattice.getBlockType(N);if(q&&!q.isLiquid)continue;let M=G.indices.length;G.indices.push(M,M+1,M+2,M+3,M+4,M+5),G.vertices.push(...V.generateVertices($,Q,W))}}let Y=[];return J.forEach((X,F)=>{if(!X.indices.length)return;let K=F.createCollider(new Uint32Array(X.indices),new Float32Array(X.vertices));Y.push([K,F])}),[...Z,...Y]}_removeFromSimulation(){if(!this._rigidBody||!this._world)return;this._rigidBody.removeFromSimulation(),this._rigidBody=void 0}_getGlobalCoordinate(J){if(!this.originCoordinate)throw new Error("Chunk._getGlobalCoordinate(): Chunk is not spawned, calculating global coordinate is impossible.");return{x:this.originCoordinate.x+J.x,y:this.originCoordinate.y+J.y,z:this.originCoordinate.z+J.z}}_getIndex(J){return J.x+n0*(J.y+n0*J.z)}_isValidLocalCoordinate(J){return J.x>=0&&J.x<=nQ&&J.y>=0&&J.y<=nQ&&J.z>=0&&J.z<=nQ}}class Y7{_chunks=new Map;_world;constructor(J){this._world=J}registerChunk(J){if(!J.isSpawned)throw new Error("ChunkLattice.registerChunk(): Chunk is not spawned.");if(this.hasChunk(J.originCoordinate)){let{x:Z,y:Y,z:X}=J.originCoordinate;throw new Error(`ChunkLattice.registerChunk(): Chunk exists at origin (${Z}, ${Y}, ${X}), despawn the current chunk before registering another at the same origin.`)}if(J.world.id!==this._world.id)throw new Error("ChunkLattice.registerChunk(): Chunk world does not match lattice world.");this._chunks.set(this._getChunkKey(J.originCoordinate),J)}unregisterChunk(J){if(!J.isSpawned)throw new Error("ChunkLattice.unregisterChunk(): Chunk is not spawned.");if(J.world.id!==this._world.id)throw new Error("ChunkLattice.unregisterChunk(): Chunk world does not match lattice world.");this._chunks.delete(this._getChunkKey(J.originCoordinate))}getBlockId(J){let Z=this.getChunk(I8.globalCoordinateToOriginCoordinate(J));if(!Z)return 0;return Z.getBlockId(I8.globalCoordinateToLocalCoordinate(J))}getBlockType(J){let Z=this.getBlockId(J);return Z?this._world.blockTypeRegistry.getBlockType(Z):null}getChunk(J){if(!I8.isValidOriginCoordinate(J))throw new Error(`ChunkLattice.getChunk(): Chunk coordinates must be divisible by CHUNK_SIZE (${n0})`);return this._chunks.get(this._getChunkKey(J))}getAllChunks(){return Array.from(this._chunks.values())}hasBlock(J){let Z=this.getChunk(I8.globalCoordinateToOriginCoordinate(J));if(!Z)return!1;return Z.hasBlock(I8.globalCoordinateToLocalCoordinate(J))}hasChunk(J){return this._chunks.has(this._getChunkKey(J))}setBlock(J,Z){let Y=I8.globalCoordinateToLocalCoordinate(J),X=I8.globalCoordinateToOriginCoordinate(J),F=this.getChunk(X);if(!F)F=new I8,F.spawn(this._world,X);F.setBlock(Y,Z)}updateChunks(){this._chunks.forEach((J)=>{if(J.requiresUpdate)J.update()})}_getChunkKey(J){return`${J.x},${J.y},${J.z}`}}var gR={type:"dynamic",softCcdPrediction:1},AR=0.0025000000000000005,iR=Math.cos(0.005),dQ;((v)=>{v.DESPAWN="ENTITY.DESPAWN";v.SET_MODEL_ANIMATIONS_PLAYBACK_RATE="ENTITY.SET_MODEL_ANIMATIONS_PLAYBACK_RATE";v.SET_MODEL_HIDDEN_NODES="ENTITY.SET_MODEL_HIDDEN_NODES";v.SET_OPACITY="ENTITY.SET_OPACITY";v.SET_PARENT="ENTITY.SET_PARENT";v.SET_TINT_COLOR="ENTITY.SET_TINT_COLOR";v.SPAWN="ENTITY.SPAWN";v.START_MODEL_LOOPED_ANIMATIONS="ENTITY.START_MODEL_LOOPED_ANIMATIONS";v.START_MODEL_ONESHOT_ANIMATIONS="ENTITY.START_MODEL_ONESHOT_ANIMATIONS";v.STOP_MODEL_ANIMATIONS="ENTITY.STOP_MODEL_ANIMATIONS";v.UPDATE_POSITION="ENTITY.UPDATE_POSITION";v.UPDATE_ROTATION="ENTITY.UPDATE_ROTATION"})(dQ||={});class J8 extends r9{onBlockCollision;onBlockContactForce;onEntityCollision;onEntityContactForce;onSpawn;onDespawn;onTick;_id;_blockHalfExtents;_blockTextureUri;_controller;_modelAnimationsPlaybackRate=1;_modelHiddenNodes;_modelLoopedAnimations;_modelOneshotAnimations;_modelScale;_modelUri;_name;_opacity;_parent;_parentNodeName;_tag;_tintColor;_lastUpdatedPosition={x:0,y:0,z:0};_lastUpdatedRotation={x:0,y:0,z:0,w:1};_lastParentlessType="dynamic";_world;constructor(J){if(!J.blockTextureUri===!J.modelUri)throw new Error("Entity.constructor(): Entity data must include a blockTextureUri or modelUri, but not both.");if(J.blockTextureUri&&!J.blockHalfExtents)throw new Error("Entity.constructor(): Block entity must have blockHalfExtents!");if(J.parent&&!J.parent.isSpawned)throw new Error("Entity.constructor(): Parent entity must be spawned before child entity!");if(J.parent?.modelUri&&J.parentNodeName&&!F6.instance.modelHasNode(J.parent.modelUri,J.parentNodeName))throw new Error(`Entity.constructor(): Parent node name ${J.parentNodeName} not found in parent model ${J.parent.modelUri}!`);super(J.rigidBodyOptions??gR);if(this._blockHalfExtents=J.blockHalfExtents,this._blockTextureUri=J.blockTextureUri,this._modelAnimationsPlaybackRate=J.modelAnimationsPlaybackRate??1,this._modelHiddenNodes=new Set(J.modelHiddenNodes??[]),this._modelLoopedAnimations=new Set(J.modelLoopedAnimations??[]),this._modelOneshotAnimations=new Set,this._modelScale=J.modelScale,this._modelUri=J.modelUri,this._name=J.name??"Nameless",this._opacity=J.opacity??1,this._parent=J.parent,this._parentNodeName=J.parentNodeName,this._tag=J.tag,this._tintColor=J.tintColor,J.controller)this.setController(J.controller)}get id(){return this._id}get blockHalfExtents(){return this._blockHalfExtents}get blockTextureUri(){return this._blockTextureUri}get controller(){return this._controller}get height(){return this.isModelEntity?F6.instance.getHeight(this._modelUri)*(this._modelScale??1):this._blockHalfExtents.y*2}get modelAnimationsPlaybackRate(){return this._modelAnimationsPlaybackRate}get modelHiddenNodes(){return this._modelHiddenNodes}get modelLoopedAnimations(){return this._modelLoopedAnimations}get modelScale(){return this._modelScale}get modelUri(){return this._modelUri}get name(){return this._name}get opacity(){return this._opacity}get parent(){return this._parent}get parentNodeName(){return this._parentNodeName}get tag(){return this._tag}get tintColor(){return this._tintColor}get isBlockEntity(){return!!this._blockTextureUri}get isModelEntity(){return!!this._modelUri}get isSpawned(){return!!this._world}get world(){return this._world}spawn(J,Z,Y){if(this.isSpawned)return console.warn(`Entity.spawn(): Entity ${this._name} is already spawned with id ${this._id}!`);if(!this.isSimulated)this.addToSimulation(J.simulation);if(this._blockTextureUri&&this._blockHalfExtents&&this.numColliders===0)this.addChildColliderToSimulation(new m8(m8.optionsFromBlockHalfExtents(this._blockHalfExtents)));if(this._modelUri&&this.numColliders===0)this.addChildColliderToSimulation(new m8(m8.optionsFromModelUri(this._modelUri,this._modelScale)));if(this.colliders.forEach((X)=>{if(this.onBlockCollision||this.onEntityCollision)X.enableCollisionEvents(!0);if(this.onBlockContactForce||this.onEntityContactForce)X.enableContactForceEvents(!0);if(X6.isDefaultCollisionGroups(X.collisionGroups))X.setCollisionGroups({belongsTo:[X.isSensor?4:2],collidesWith:[65535]})}),this.setPosition(Z),Y)this.setRotation(Y);if(this._id=J.entityManager.registerEntity(this),this._world=J,this.onSpawn)this.onSpawn(this);if(this._controller)this._controller.spawn(this);if(this._parent)this.setParent(this._parent,this._parentNodeName,Z,Y);this.colliders.forEach((X)=>{J.simulation.colliderMap.setColliderEntity(X,this)}),this._world.eventRouter.emit("ENTITY.SPAWN",{entity:this})}despawn(){if(!this.isSpawned)return console.warn(`Entity.despawn(): Entity ${this._name} is not been spawned and cannot be despawned!`);this._world.entityManager.getEntityChildren(this).forEach((Z)=>{Z.despawn()});let{eventRouter:J}=this._world;if(this.onDespawn)this.onDespawn(this);if(this._controller)this._controller.detach(this),this._controller.despawn(this);if(J.emit("ENTITY.DESPAWN",{entity:this}),this.isSimulated)this.removeFromSimulation();this._world.entityManager.unregisterEntity(this),this._world.audioManager.unregisterEntityAttachedAudios(this),this._world.lightManager.despawnEntityAttachedLights(this),this._world.sceneUIManager.unloadEntityAttachedSceneUIs(this),this._id=void 0,this._world=void 0}setModelAnimationsPlaybackRate(J){if(this._requireSpawned(),!this.isModelEntity||this._modelAnimationsPlaybackRate===J)return;this._modelAnimationsPlaybackRate=J,this._world.eventRouter.emit("ENTITY.SET_MODEL_ANIMATIONS_PLAYBACK_RATE",{entity:this,playbackRate:J})}setController(J){if(this._controller===J)return;if(this._controller)this._controller.detach(this);if(this._controller=J,this._controller)this._controller.attach(this)}setModelHiddenNodes(J){this._requireSpawned(),this._modelHiddenNodes=new Set(J.map((Z)=>Z.toLowerCase())),this._world.eventRouter.emit("ENTITY.SET_MODEL_HIDDEN_NODES",{entity:this,modelHiddenNodes:this._modelHiddenNodes})}setOpacity(J){if(this._requireSpawned(),this._opacity===J)return;this._opacity=J,this._world.eventRouter.emit("ENTITY.SET_OPACITY",{entity:this,opacity:J})}setParent(J,Z,Y,X){if(this._requireSpawned(),J&&!J.isSpawned)throw new Error("Entity.setParent(): Parent entity is not spawned, cannot set parent!");if(!this._parent&&J)this._lastParentlessType=this.type;if(this._parent=J,this._parentNodeName=Z,this.colliders.forEach((F)=>F.setEnabled(!J)),this.setType(!J?this._lastParentlessType:"kinematic_velocity"),this.setPosition(Y??{x:0,y:0,z:0}),this.setRotation(X??{x:0,y:0,z:0,w:1}),!this.isKinematicPositionBased)this.resetAngularVelocity(),this.resetForces(),this.resetLinearVelocity(),this.resetTorques();this._world.eventRouter.emit("ENTITY.SET_PARENT",{entity:this,parent:J,parentNodeName:Z})}setTintColor(J){if(this._requireSpawned(),!J&&!this._tintColor||J&&this._tintColor&&J.r===this._tintColor.r&&J.g===this._tintColor.g&&J.b===this._tintColor.b)return;this._tintColor=J,this._world.eventRouter.emit("ENTITY.SET_TINT_COLOR",{entity:this,tintColor:J})}startModelLoopedAnimations(J){if(this._requireSpawned(),!this.isModelEntity)return;if(!J.some((Z)=>!this._modelLoopedAnimations.has(Z)))return;J.forEach((Z)=>{this._modelLoopedAnimations.add(Z)}),this._world.eventRouter.emit("ENTITY.START_MODEL_LOOPED_ANIMATIONS",{entity:this,animations:new Set(J)})}startModelOneshotAnimations(J){if(this._requireSpawned(),!this.isModelEntity)return;J.forEach((Z)=>{this._modelOneshotAnimations.add(Z)}),this._world.eventRouter.emit("ENTITY.START_MODEL_ONESHOT_ANIMATIONS",{entity:this,animations:new Set(J)})}stopModelAnimations(J){if(this._requireSpawned(),!this.isModelEntity)return;if(!J.some((Z)=>this._modelLoopedAnimations.has(Z))&&!J.some((Z)=>this._modelOneshotAnimations.has(Z)))return;J.forEach((Z)=>{this._modelLoopedAnimations.delete(Z),this._modelOneshotAnimations.delete(Z)}),this._world.eventRouter.emit("ENTITY.STOP_MODEL_ANIMATIONS",{entity:this,animations:new Set(J)})}serialize(){return t.serializeEntity(this)}tick(J){if(this.onTick)this.onTick(this,J);if(this._controller)this._controller.tick(this,J)}checkAndEmitUpdates(){this._requireSpawned();let J=this.position,Z=this.rotation;if(this._rotationExceedsThreshold(Z,this._lastUpdatedRotation))this._lastUpdatedRotation=Z,this._world.eventRouter.emit("ENTITY.UPDATE_ROTATION",{entity:this,rotation:Z});if(this._positionExceedsThreshold(J,this._lastUpdatedPosition))this._lastUpdatedPosition=J,this._world.eventRouter.emit("ENTITY.UPDATE_POSITION",{entity:this,position:J})}_requireSpawned(){if(!this.isSpawned)throw new Error(`Entity._requireSpawned(): Entity ${this._name} is not spawned!`)}_positionExceedsThreshold(J,Z){let Y=J.x-Z.x,X=J.y-Z.y,F=J.z-Z.z;return Y*Y+X*X+F*F>AR}_rotationExceedsThreshold(J,Z){return Math.abs(J.x*Z.x+J.y*Z.y+J.z*Z.z+J.w*Z.w)<iR}}class X7 extends z9{autoCancelMouseLeftClick=!0;canWalk=()=>!0;canRun=()=>!0;canJump=()=>!0;idleLoopedAnimations=["idle_upper","idle_lower"];interactOneshotAnimations=["simple_interact"];jumpOneshotAnimations=["jump_loop"];jumpVelocity=10;runLoopedAnimations=["run_upper","run_lower"];runVelocity=8;sticksToPlatforms=!0;walkLoopedAnimations=["walk_upper","walk_lower"];walkVelocity=4;_stepAudio;_groundContactCount=0;_platform;constructor(J={}){super();this.autoCancelMouseLeftClick=J.autoCancelMouseLeftClick??this.autoCancelMouseLeftClick,this.jumpVelocity=J.jumpVelocity??this.jumpVelocity,this.runVelocity=J.runVelocity??this.runVelocity,this.walkVelocity=J.walkVelocity??this.walkVelocity,this.canWalk=J.canWalk??this.canWalk,this.canRun=J.canRun??this.canRun,this.canJump=J.canJump??this.canJump,this.sticksToPlatforms=J.sticksToPlatforms??this.sticksToPlatforms}get isGrounded(){return this._groundContactCount>0}get isOnPlatform(){return!!this._platform}get platform(){return this._platform}attach(J){this._stepAudio=new Z5({uri:"audio/sfx/step/stone/stone-step-04.mp3",loop:!0,volume:0.1,attachedToEntity:J}),J.lockAllRotations()}spawn(J){if(!J.isSpawned)throw new Error("PlayerEntityController.createColliders(): Entity is not spawned!");J.createAndAddChildCollider({shape:"cylinder",radius:0.23,halfHeight:0.125,collisionGroups:{belongsTo:[4],collidesWith:[1,2]},isSensor:!0,relativePosition:{x:0,y:-0.75,z:0},tag:"groundSensor",onCollision:(Z,Y)=>{if(this._groundContactCount+=Y?1:-1,!this._groundContactCount)J.startModelOneshotAnimations(this.jumpOneshotAnimations);else J.stopModelAnimations(this.jumpOneshotAnimations);if(!(Z instanceof J8)||!Z.isKinematic)return;if(Y&&this.sticksToPlatforms)this._platform=Z;else if(Z===this._platform&&!Y)this._platform=void 0}}),J.createAndAddChildCollider({shape:"capsule",halfHeight:0.31,radius:0.38,collisionGroups:{belongsTo:[4],collidesWith:[1,2]},friction:0,frictionCombineRule:1,tag:"wallCollider"})}tickWithPlayerInput(J,Z,Y,X){if(!J.isSpawned||!J.world)return;super.tickWithPlayerInput(J,Z,Y,X);let{w:F,a:K,s:$,d:Q,sp:W,sh:G,ml:V}=Z,{yaw:O}=Y,v=J.linearVelocity,w={x:0,y:0,z:0},H=G;if(this.isGrounded&&(F||K||$||Q)){if(H)J.stopModelAnimations(Array.from(J.modelLoopedAnimations).filter((R)=>!this.runLoopedAnimations.includes(R))),J.startModelLoopedAnimations(this.runLoopedAnimations),this._stepAudio?.setPlaybackRate(0.75);else J.stopModelAnimations(Array.from(J.modelLoopedAnimations).filter((R)=>!this.walkLoopedAnimations.includes(R))),J.startModelLoopedAnimations(this.walkLoopedAnimations),this._stepAudio?.setPlaybackRate(0.51);this._stepAudio?.play(J.world,!this._stepAudio?.isPlaying)}else this._stepAudio?.pause(),J.stopModelAnimations(Array.from(J.modelLoopedAnimations).filter((R)=>!this.idleLoopedAnimations.includes(R))),J.startModelLoopedAnimations(this.idleLoopedAnimations);if(V)J.startModelOneshotAnimations(this.interactOneshotAnimations),Z.ml=!this.autoCancelMouseLeftClick;if(H&&this.canRun(this)||!H&&this.canWalk(this)){let R=H?this.runVelocity:this.walkVelocity;if(F)w.x-=R*Math.sin(O),w.z-=R*Math.cos(O);if($)w.x+=R*Math.sin(O),w.z+=R*Math.cos(O);if(K)w.x-=R*Math.cos(O),w.z+=R*Math.sin(O);if(Q)w.x+=R*Math.cos(O),w.z-=R*Math.sin(O);let P=Math.sqrt(w.x*w.x+w.z*w.z);if(P>R){let x=R/P;w.x*=x,w.z*=x}}if(W&&this.canJump(this)){if(this.isGrounded&&v.y>-0.001&&v.y<=3)w.y=this.jumpVelocity}let N=this._platform?this._platform.linearVelocity:{x:0,y:0,z:0},q={x:w.x-v.x+N.x,y:w.y+N.y,z:w.z-v.z+N.z};if(!(this.runVelocity>0&&Math.abs(v.x)>this.runVelocity||this.jumpVelocity>0&&Math.abs(v.y)>this.jumpVelocity||this.runVelocity>0&&Math.abs(v.z)>this.runVelocity)||this.isOnPlatform){if(Object.values(q).some((R)=>R!==0)){let R=J.mass;J.applyImpulse({x:q.x*R,y:q.y*R,z:q.z*R})}}if(O!==void 0){let R=O/2;J.setRotation({x:0,y:Math.fround(Math.sin(R)),z:0,w:Math.fround(Math.cos(R))})}}}class H9 extends J8{player;constructor(J){super(J);if(this.player=J.player,!J.controller)this.setController(new X7)}tick(J){if(!this.isSpawned||!this.world||!this.controller)return;let{input:Z,camera:Y}=this.player;this.controller.tickWithPlayerInput(this,Z,Y.orientation,J),super.tick(J)}}class F7{_entities=new Map;_nextEntityId=1;_world;constructor(J){this._world=J}get world(){return this._world}registerEntity(J){if(J.id!==void 0)throw new Error(`EntityManager.registerEntity(): Entity ${J.name} is already assigned the id ${J.id}!`);let Z=this._nextEntityId;return this._entities.set(Z,J),this._nextEntityId++,Z}unregisterEntity(J){if(J.id===void 0)throw new Error(`EntityManager.unregisterEntity(): Entity ${J.name} is not assigned an id!`);this._entities.delete(J.id)}getAllEntities(){return Array.from(this._entities.values())}getAllPlayerEntities(){let J=[];return this._entities.forEach((Z)=>{if(Z instanceof H9)J.push(Z)}),J}getPlayerEntitiesByPlayer(J){let Z=[];return this._entities.forEach((Y)=>{if(Y instanceof H9&&Y.player===J)Z.push(Y)}),Z}getEntity(J){return this._entities.get(J)}getEntitiesByTag(J){let Z=[];return this._entities.forEach((Y)=>{if(Y.tag===J)Z.push(Y)}),Z}getEntitiesByTagSubstring(J){let Z=[];return this._entities.forEach((Y)=>{if(Y.tag?.includes(J))Z.push(Y)}),Z}getEntityChildren(J){let Z=[];return this._entities.forEach((Y)=>{if(Y.parent===J)Z.push(Y)}),Z}tickEntities(J){this._entities.forEach((Z)=>{Z.tick(J)})}checkAndEmitUpdates(){this._entities.forEach((J)=>{if(!J.isSpawned)return;J.checkAndEmitUpdates()})}}class K7{_lights=new Map;_nextLightId=1;_world;constructor(J){this._world=J}get world(){return this._world}despawnEntityAttachedLights(J){this.getAllEntityAttachedLights(J).forEach((Z)=>{Z.despawn()})}getAllLights(){return Array.from(this._lights.values())}getAllEntityAttachedLights(J){return this.getAllLights().filter((Z)=>Z.attachedToEntity===J)}registerLight(J){if(J.id!==void 0)return J.id;let Z=this._nextLightId;return this._lights.set(Z,J),this._nextLightId++,Z}unregisterLight(J){if(J.id===void 0)return;this._lights.delete(J.id)}}var yR;((Y)=>{Y[Y.POINTLIGHT=0]="POINTLIGHT";Y[Y.SPOTLIGHT=1]="SPOTLIGHT"})(yR||={});var sQ;((w)=>{w.DESPAWN="LIGHT.DESPAWN";w.SET_ANGLE="LIGHT.SET_ANGLE";w.SET_ATTACHED_TO_ENTITY="LIGHT.SET_ATTACHED_TO_ENTITY";w.SET_COLOR="LIGHT.SET_COLOR";w.SET_DISTANCE="LIGHT.SET_DISTANCE";w.SET_INTENSITY="LIGHT.SET_INTENSITY";w.SET_OFFSET="LIGHT.SET_OFFSET";w.SET_PENUMBRA="LIGHT.SET_PENUMBRA";w.SET_POSITION="LIGHT.SET_POSITION";w.SET_TRACKED_ENTITY="LIGHT.SET_TRACKED_ENTITY";w.SET_TRACKED_POSITION="LIGHT.SET_TRACKED_POSITION";w.SET_TYPE="LIGHT.SET_TYPE";w.SPAWN="LIGHT.SPAWN"})(sQ||={});class aQ{_id;_angle;_attachedToEntity;_color;_distance;_intensity;_offset;_penumbra;_position;_trackedEntity;_trackedPosition;_type;_world;constructor(J){if(!!J.attachedToEntity===!!J.position)throw new Error("Either attachedToEntity or position must be set, but not both");this._angle=J.angle,this._attachedToEntity=J.attachedToEntity,this._color=J.color??{r:255,g:255,b:255},this._distance=J.distance,this._intensity=J.intensity??1,this._offset=J.offset,this._penumbra=J.penumbra,this._position=J.position,this._trackedEntity=J.trackedEntity,this._trackedPosition=J.trackedPosition,this._type=J.type??0}get id(){return this._id}get angle(){return this._angle}get attachedToEntity(){return this._attachedToEntity}get color(){return this._color}get distance(){return this._distance}get intensity(){return this._intensity}get isSpawned(){return this._id!==void 0}get offset(){return this._offset}get penumbra(){return this._penumbra}get position(){return this._position}get trackedEntity(){return this._trackedEntity}get trackedPosition(){return this._trackedPosition}get type(){return this._type}get world(){return this._world}setAngle(J){if(this._angle===J)return;if(this._angle=J,this.isSpawned)this._world.eventRouter.emit("LIGHT.SET_ANGLE",{light:this,angle:J})}setAttachedToEntity(J){if(!J.isSpawned)throw new Error(`Light.setAttachedToEntity(): Entity ${J.id} is not spawned!`);if(this._attachedToEntity===J)return;if(this._attachedToEntity=J,this._position=void 0,this.isSpawned)this._world.eventRouter.emit("LIGHT.SET_ATTACHED_TO_ENTITY",{light:this,entity:J})}setColor(J){if(this._color.r===J.r&&this._color.g===J.g&&this._color.b===J.b)return;if(this._color=J,this.isSpawned)this._world.eventRouter.emit("LIGHT.SET_COLOR",{light:this,color:J})}setDistance(J){if(this._distance===J)return;if(this._distance=J,this.isSpawned)this._world.eventRouter.emit("LIGHT.SET_DISTANCE",{light:this,distance:J})}setIntensity(J){if(this._intensity===J)return;if(this._intensity=J,this.isSpawned)this._world.eventRouter.emit("LIGHT.SET_INTENSITY",{light:this,intensity:J})}setOffset(J){if(this._offset===J)return;if(this._offset=J,this.isSpawned)this._world.eventRouter.emit("LIGHT.SET_OFFSET",{light:this,offset:J})}setPenumbra(J){if(this._penumbra===J)return;if(this._penumbra=J,this.isSpawned)this._world.eventRouter.emit("LIGHT.SET_PENUMBRA",{light:this,penumbra:J})}setPosition(J){if(this._position===J)return;if(this._position=J,this._attachedToEntity=void 0,this.isSpawned)this._world.eventRouter.emit("LIGHT.SET_POSITION",{light:this,position:J})}setTrackedEntity(J){if(!J.isSpawned)throw new Error(`Light.setTrackedEntity(): Entity ${J.id} is not spawned!`);if(this._trackedEntity===J)return;if(this._trackedEntity=J,this._trackedPosition=void 0,this.isSpawned)this._world.eventRouter.emit("LIGHT.SET_TRACKED_ENTITY",{light:this,entity:J})}setTrackedPosition(J){if(this._trackedPosition===J)return;if(this._trackedPosition=J,this._trackedEntity=void 0,this.isSpawned)this._world.eventRouter.emit("LIGHT.SET_TRACKED_POSITION",{light:this,position:J})}despawn(){if(!this.isSpawned||!this._world)return;this._world.lightManager.unregisterLight(this),this._world.eventRouter.emit("LIGHT.DESPAWN",{light:this}),this._id=void 0,this._world=void 0}spawn(J){if(this.isSpawned)return;this._id=J.lightManager.registerLight(this),this._world=J,J.eventRouter.emit("LIGHT.SPAWN",{light:this})}serialize(){return t.serializeLight(this)}}var nR;((Y)=>{Y[Y.FIRST_PERSON=0]="FIRST_PERSON";Y[Y.THIRD_PERSON=1]="THIRD_PERSON"})(nR||={});var oQ;((w)=>{w.LOOK_AT_ENTITY="PLAYER_CAMERA.LOOK_AT_ENTITY";w.LOOK_AT_POSITION="PLAYER_CAMERA.LOOK_AT_POSITION";w.SET_ATTACHED_TO_ENTITY="PLAYER_CAMERA.SET_ATTACHED_TO_ENTITY";w.SET_ATTACHED_TO_POSITION="PLAYER_CAMERA.SET_ATTACHED_TO_POSITION";w.SET_FILM_OFFSET="PLAYER_CAMERA.SET_FILM_OFFSET";w.SET_FORWARD_OFFSET="PLAYER_CAMERA.SET_FORWARD_OFFSET";w.SET_FOV="PLAYER_CAMERA.SET_FOV";w.SET_MODEL_HIDDEN_NODES="PLAYER_CAMERA.SET_MODEL_HIDDEN_NODES";w.SET_MODE="PLAYER_CAMERA.SET_MODE";w.SET_OFFSET="PLAYER_CAMERA.SET_OFFSET";w.SET_TRACKED_ENTITY="PLAYER_CAMERA.SET_TRACKED_ENTITY";w.SET_TRACKED_POSITION="PLAYER_CAMERA.SET_TRACKED_POSITION";w.SET_ZOOM="PLAYER_CAMERA.SET_ZOOM"})(oQ||={});class $7{player;_attachedToEntity;_attachedToPosition;_filmOffset=0;_forwardOffset=0;_fov=75;_modelHiddenNodes=new Set;_mode=1;_offset={x:0,y:0,z:0};_orientation={pitch:0,yaw:0};_trackedEntity;_trackedPosition;_zoom=1;constructor(J){this.player=J}get attachedToEntity(){return this._attachedToEntity}get attachedToPosition(){return this._attachedToPosition}get facingDirection(){return{x:-Math.sin(this._orientation.yaw)*Math.cos(this._orientation.pitch),y:Math.sin(this._orientation.pitch),z:-Math.cos(this._orientation.yaw)*Math.cos(this._orientation.pitch)}}get filmOffset(){return this._filmOffset}get forwardOffset(){return this._forwardOffset}get fov(){return this._fov}get modelHiddenNodes(){return this._modelHiddenNodes}get mode(){return this._mode}get offset(){return this._offset}get orientation(){return this._orientation}get trackedEntity(){return this._trackedEntity}get trackedPosition(){return this._trackedPosition}get zoom(){return this._zoom}lookAtEntity(J){this._requirePlayerWorld(),this.player.world.eventRouter.emit("PLAYER_CAMERA.LOOK_AT_ENTITY",{playerCamera:this,entity:J})}lookAtPosition(J){this._requirePlayerWorld(),this.player.world.eventRouter.emit("PLAYER_CAMERA.LOOK_AT_POSITION",{playerCamera:this,position:J})}setAttachedToEntity(J){if(this._requirePlayerWorld(),!J.isSpawned)throw new Error(`PlayerCamera.setAttachedToEntity(): Entity ${J.id} is not spawned!`);this._attachedToEntity=J,this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_ATTACHED_TO_ENTITY",{playerCamera:this,entity:J})}setAttachedToPosition(J){this._requirePlayerWorld(),this._attachedToPosition=J,this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_ATTACHED_TO_POSITION",{playerCamera:this,position:J})}setFilmOffset(J){this._requirePlayerWorld(),this._filmOffset=J,this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_FILM_OFFSET",{playerCamera:this,filmOffset:J})}setForwardOffset(J){this._requirePlayerWorld(),this._forwardOffset=J,this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_FORWARD_OFFSET",{playerCamera:this,forwardOffset:J})}setFov(J){this._requirePlayerWorld(),this._fov=J,this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_FOV",{playerCamera:this,fov:J})}setModelHiddenNodes(J){this._requirePlayerWorld(),this._modelHiddenNodes=new Set(J.map((Z)=>Z.toLowerCase())),this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_MODEL_HIDDEN_NODES",{playerCamera:this,modelHiddenNodes:this._modelHiddenNodes})}setMode(J){this._requirePlayerWorld(),this._mode=J,this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_MODE",{playerCamera:this,mode:J})}setOffset(J){this._requirePlayerWorld(),this._offset=J,this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_OFFSET",{playerCamera:this,offset:J})}setOrientationPitch(J){this._orientation.pitch=J}setOrientationYaw(J){this._orientation.yaw=J}setTrackedEntity(J){this._requirePlayerWorld(),this._trackedEntity=J,this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_TRACKED_ENTITY",{playerCamera:this,entity:J})}setTrackedPosition(J){this._requirePlayerWorld(),this._trackedPosition=J,this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_TRACKED_POSITION",{playerCamera:this,position:J})}setZoom(J){this._requirePlayerWorld(),this._zoom=J,this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_ZOOM",{playerCamera:this,zoom:J})}serialize(){return t.serializePlayerCamera(this)}_requirePlayerWorld(){if(!this.player.world)throw new Error(`PlayerCamera._requirePlayerWorld(): Player ${this.player.id} is not in a world!`)}}var rQ;((X)=>{X.LOAD="PLAYER_UI.LOAD";X.LOCK_POINTER="PLAYER_UI.LOCK_POINTER";X.SEND_DATA="PLAYER_UI.SEND_DATA"})(rQ||={});class Q7{player;onData;constructor(J){this.player=J}load(J){if(!this.player.world)return;this.player.world.eventRouter.emit("PLAYER_UI.LOAD",{playerUI:this,htmlUri:J})}lockPointer(J){if(!this.player.world)return;this.player.world.eventRouter.emit("PLAYER_UI.LOCK_POINTER",{playerUI:this,lock:J})}sendData(J){if(!this.player.world)return;this.player.world.eventRouter.emit("PLAYER_UI.SEND_DATA",{playerUI:this,data:J})}}class tQ{_id;_attachedToEntity;_offset;_position;_state={};_templateId;_viewDistance;_world;constructor(J){if(!!J.attachedToEntity===!!J.position)throw new Error("Either attachedToEntity or position must be set, but not both");this._attachedToEntity=J.attachedToEntity,this._offset=J.offset,this._position=J.position,this._state=J.state??{},this._templateId=J.templateId,this._viewDistance=J.viewDistance}get id(){return this._id}get attachedToEntity(){return this._attachedToEntity}get isLoaded(){return this._id!==void 0}get offset(){return this._offset}get position(){return this._position}get state(){return this._state}get templateId(){return this._templateId}get viewDistance(){return this._viewDistance}get world(){return this._world}load(J){if(this.isLoaded)return;this._id=J.sceneUIManager.registerSceneUI(this),this._world=J,J.eventRouter.emit("SCENE_UI.LOAD",{sceneUI:this})}setAttachedToEntity(J){if(!J.isSpawned)throw new Error(`SceneUI.setAttachedToEntity(): Entity ${J.id} is not spawned!`);if(this._attachedToEntity===J)return;if(this._attachedToEntity=J,this._position=void 0,this.isLoaded)this._world.eventRouter.emit("SCENE_UI.SET_ATTACHED_TO_ENTITY",{sceneUI:this,entity:J})}setOffset(J){if(this._offset===J)return;if(this._offset=J,this.isLoaded)this._world.eventRouter.emit("SCENE_UI.SET_OFFSET",{sceneUI:this,offset:J})}setPosition(J){if(this._position===J)return;if(this._attachedToEntity=void 0,this._position=J,this.isLoaded)this._world.eventRouter.emit("SCENE_UI.SET_POSITION",{sceneUI:this,position:J})}setState(J){if(this._state={...this._state,...J},this.isLoaded)this._world.eventRouter.emit("SCENE_UI.SET_STATE",{sceneUI:this,state:this._state})}setViewDistance(J){if(this._viewDistance=J,this.isLoaded)this._world.eventRouter.emit("SCENE_UI.SET_VIEW_DISTANCE",{sceneUI:this,viewDistance:J})}unload(){if(!this.isLoaded||!this._world)return;this._world.sceneUIManager.unregisterSceneUI(this),this._world.eventRouter.emit("SCENE_UI.UNLOAD",{sceneUI:this}),this._id=void 0,this._world=void 0}serialize(){return t.serializeSceneUI(this)}}class G7{_colliderHandleBlockTypeMap=new Map;_colliderHandleCollisionCallbackMap=new Map;_colliderHandleEntityMap=new Map;_cleanupBlockTypeColliderHandles=new Map;_cleanupCollisionCallbackColliderHandles=new Map;_cleanupEntityColliderHandles=new Map;getColliderBlockType(J){return this._requireSimulatedCollider(J),this._colliderHandleBlockTypeMap.get(J.rawCollider.handle)}getColliderCollisionCallback(J){return this._requireSimulatedCollider(J),this._colliderHandleCollisionCallbackMap.get(J.rawCollider.handle)}getColliderEntity(J){return this._requireSimulatedCollider(J),this._colliderHandleEntityMap.get(J.rawCollider.handle)}getColliderHandleBlockType(J){return this._colliderHandleBlockTypeMap.get(J)}getColliderHandleCollisionCallback(J){return this._colliderHandleCollisionCallbackMap.get(J)}getColliderHandleEntity(J){return this._colliderHandleEntityMap.get(J)}setColliderBlockType(J,Z){this._requireSimulatedCollider(J),this.setColliderHandleBlockType(J.rawCollider.handle,Z)}setColliderCollisionCallback(J,Z){this._requireSimulatedCollider(J),this.setColliderHandleCollisionCallback(J.rawCollider.handle,Z)}setColliderEntity(J,Z){this._requireSimulatedCollider(J),this.setColliderHandleEntity(J.rawCollider.handle,Z)}setColliderHandleBlockType(J,Z){this._colliderHandleBlockTypeMap.set(J,Z),this._cleanupBlockTypeColliderHandles.delete(J)}setColliderHandleCollisionCallback(J,Z){this._colliderHandleCollisionCallbackMap.set(J,Z),this._cleanupCollisionCallbackColliderHandles.delete(J)}setColliderHandleEntity(J,Z){this._colliderHandleEntityMap.set(J,Z),this._cleanupEntityColliderHandles.delete(J)}queueColliderHandleForCleanup(J){if(this._colliderHandleBlockTypeMap.has(J))this._cleanupBlockTypeColliderHandles.set(J,!0);if(this._colliderHandleCollisionCallbackMap.has(J))this._cleanupCollisionCallbackColliderHandles.set(J,!0);if(this._colliderHandleEntityMap.has(J))this._cleanupEntityColliderHandles.set(J,!0)}cleanup(){if(this._cleanupBlockTypeColliderHandles.size){for(let J of this._cleanupBlockTypeColliderHandles.keys())this._colliderHandleBlockTypeMap.delete(J);this._cleanupBlockTypeColliderHandles.clear()}if(this._cleanupCollisionCallbackColliderHandles.size){for(let J of this._cleanupCollisionCallbackColliderHandles.keys())this._colliderHandleCollisionCallbackMap.delete(J);this._cleanupCollisionCallbackColliderHandles.clear()}if(this._cleanupEntityColliderHandles.size){for(let J of this._cleanupEntityColliderHandles.keys())this._colliderHandleEntityMap.delete(J);this._cleanupEntityColliderHandles.clear()}}_requireSimulatedCollider(J){if(!J.rawCollider)throw new Error("ColliderMap._requireSimulatedCollider(): Collider is not in the simulation.")}}var Su={x:0,y:-32,z:0},eQ=60;class W7{_colliderMap=new G7;_debugRaycastingEnabled=!1;_debugRenderingEnabled=!1;_rapierEventQueue;_rapierSimulation;_world;constructor(J,Z=eQ,Y=Su){this._rapierEventQueue=new v0.EventQueue(!0),this._rapierSimulation=new v0.World(Y),this._rapierSimulation.timestep=Math.fround(1/Z),this._world=J}get colliderMap(){return this._colliderMap}get isDebugRaycastingEnabled(){return this._debugRaycastingEnabled}get isDebugRenderingEnabled(){return this._debugRenderingEnabled}get gravity(){return this._rapierSimulation.gravity}get timestepS(){return this._rapierSimulation.timestep}get world(){return this._world}raycast(J,Z,Y,X={}){let F=new v0.Ray(J,Z),K=this._rapierSimulation.castRay(F,Y,X.ignoresSensors??!0,X.filterFlags,X.filterGroups,X.filterExcludeCollider,X.filterExcludeRigidBody,X.filterPredicate);if(this._debugRaycastingEnabled)this._world.eventRouter.emit("SIMULATION.DEBUG_RAYCAST",{simulation:this,origin:J,direction:Z,length:Y,hit:!!K});if(!K)return null;let $=F.pointAt(K.timeOfImpact),Q=K.timeOfImpact,W=K.collider,G=this._colliderMap.getColliderHandleBlockType(W.handle);if(G)return{hitBlock:J1.fromGlobalCoordinate({x:Math.floor($.x-(F.dir.x<0?0.0001:-0.0001)),y:Math.floor($.y-(F.dir.y<0?0.0001:-0.0001)),z:Math.floor($.z-(F.dir.z<0?0.0001:-0.0001))},G),hitPoint:$,hitDistance:Q};let V=this._colliderMap.getColliderHandleEntity(W.handle);if(V)return{hitEntity:V,hitPoint:$,hitDistance:Q};return null}createRawCollider(J,Z){return this._rapierSimulation.createCollider(J,Z)}createRawRigidBody(J){return this._rapierSimulation.createRigidBody(J)}enableDebugRaycasting(J){this._debugRaycastingEnabled=J}enableDebugRendering(J){this._debugRenderingEnabled=J}getContactManifolds(J,Z){let Y=[];return this._rapierSimulation.narrowPhase.contactPair(J,Z,(X,F)=>{if(X.numContacts()===0)return;let K=X.normal(),$=[];for(let Q=0;Q<X.numSolverContacts();Q++)$.push(X.solverContactPoint(Q));Y.push({contactPoints:$,localNormalA:!F?X.localNormal1():X.localNormal2(),localNormalB:!F?X.localNormal2():X.localNormal1(),normal:!F?K:{x:-K.x,y:-K.y,z:-K.z}})}),Y}removeRawCollider(J){this._colliderMap.queueColliderHandleForCleanup(J.handle),this._rapierSimulation.removeCollider(J,!1)}removeRawRigidBody(J){this._rapierSimulation.removeRigidBody(J)}setGravity(J){this._rapierSimulation.gravity=J}step=(J)=>{this._world.eventRouter.emit("SIMULATION.STEP_START",{simulation:this,tickDeltaMs:J});let Z=performance.now();if(this._rapierSimulation.step(this._rapierEventQueue),this._rapierEventQueue.drainContactForceEvents(this._onContactForceEvent),this._rapierEventQueue.drainCollisionEvents(this._onCollisionEvent),this._colliderMap.cleanup(),this._world.eventRouter.emit("SIMULATION.STEP_END",{simulation:this,stepDurationMs:performance.now()-Z}),this._debugRenderingEnabled)this._world.eventRouter.emit("SIMULATION.DEBUG_RENDER",{simulation:this,...this._rapierSimulation.debugRender()})};_onCollisionEvent=(J,Z,Y)=>{let[X,F]=this._getCollisionObjects(J,Z);if(!X||!F)return;let K=($,Q)=>{if($ instanceof K6&&Q instanceof J8&&$.onEntityCollision)$.onEntityCollision($,Q,Y,J,Z);else if($ instanceof J8&&Q instanceof K6&&$.onBlockCollision)$.onBlockCollision($,Q,Y,J,Z);else if($ instanceof J8&&Q instanceof J8&&$.onEntityCollision)$.onEntityCollision($,Q,Y,J,Z);else if(typeof $==="function"&&(Q instanceof J8||Q instanceof K6))$(Q,Y,J,Z)};K(X,F),K(F,X)};_onContactForceEvent=(J)=>{let[Z,Y]=this._getCollisionObjects(J.collider1(),J.collider2());if(!Z||typeof Z==="function"||!Y||typeof Y==="function")return;let X={totalForce:J.totalForce(),totalForceMagnitude:J.totalForceMagnitude(),maxForceDirection:J.maxForceDirection(),maxForceMagnitude:J.maxForceMagnitude()},F=(K,$)=>{if(K instanceof K6&&$ instanceof J8&&K.onEntityContactForce)K.onEntityContactForce(K,$,X);else if(K instanceof J8&&$ instanceof K6&&K.onBlockContactForce)K.onBlockContactForce(K,$,X);else if(K instanceof J8&&$ instanceof J8&&K.onEntityContactForce)K.onEntityContactForce(K,$,X)};F(Z,Y),F(Y,Z)};_getCollisionObjects(J,Z){let Y=this._colliderMap.getColliderHandleBlockType(J)??this._colliderMap.getColliderHandleCollisionCallback(J)??this._colliderMap.getColliderHandleEntity(J),X=this._colliderMap.getColliderHandleBlockType(Z)??this._colliderMap.getColliderHandleCollisionCallback(Z)??this._colliderMap.getColliderHandleEntity(Z);return[Y,X]}}class _Y{_queuedBroadcasts=[];_queuedAudioSynchronizations={};_queuedBlockSynchronizations={};_queuedBlockTypeSynchronizations={};_queuedChunkSynchronizations={};_queuedDebugRaycastSynchronizations=[];_queuedEntitySynchronizations={};_queuedLightSynchronizations={};_queuedPlayerPackets=new Map;_queuedPlayerCameraSynchronizations=new Map;_queuedPlayerUISynchronizations=new Map;_queuedPlayerUIDatasSynchronizations=new Map;_queuedSceneUISynchronizations={};_queuedWorldSynchronization;_spawnedChunks=new Set;_spawnedEntities=new Set;_world;constructor(J){this._world=J,this._subscribeToAudioEvents(),this._subscribeToBlockTypeRegistryEvents(),this._subscribeToChatEvents(),this._subscribeToChunkEvents(),this._subscribeToEntityEvents(),this._subscribeToLightEvents(),this._subscribeToPlayerEvents(),this._subscribeToPlayerCameraEvents(),this._subscribeToPlayerUIEvents(),this._subscribeToSceneUIEvents(),this._subscribeToSimulationEvents(),this._subscribeToWorldEvents()}synchronize(){for(let[W,G]of this._queuedPlayerPackets)for(let V of G)W.connection.send(V);let J=Object.values(this._queuedEntitySynchronizations);if(J.length>0){let W=A.createPacket(A.outboundPackets.entitiesPacketDefinition,J,this._world.loop.currentTick);O8.instance.broadcastForWorld(this._world.id,W)}let Z=Object.values(this._queuedAudioSynchronizations);if(Z.length>0){let W=A.createPacket(A.outboundPackets.audiosPacketDefinition,Z,this._world.loop.currentTick);O8.instance.broadcastForWorld(this._world.id,W)}let Y=Object.values(this._queuedBlockTypeSynchronizations);if(Y.length>0){let W=A.createPacket(A.outboundPackets.blockTypesPacketDefinition,Y,this._world.loop.currentTick);O8.instance.broadcastForWorld(this._world.id,W)}let X=Object.values(this._queuedBlockSynchronizations);if(X.length>0){let W=A.createPacket(A.outboundPackets.blocksPacketDefinition,X,this._world.loop.currentTick);O8.instance.broadcastForWorld(this._world.id,W)}let F=Object.values(this._queuedChunkSynchronizations);if(F.length>0){let W=A.createPacket(A.outboundPackets.chunksPacketDefinition,F,this._world.loop.currentTick);O8.instance.broadcastForWorld(this._world.id,W)}let K=Object.values(this._queuedLightSynchronizations);if(K.length>0){let W=A.createPacket(A.outboundPackets.lightsPacketDefinition,K,this._world.loop.currentTick);O8.instance.broadcastForWorld(this._world.id,W)}for(let[W,G]of this._queuedPlayerUISynchronizations){let V=A.createPacket(A.outboundPackets.uiPacketDefinition,G,this._world.loop.currentTick);W.connection.send(V)}for(let[W,G]of this._queuedPlayerUIDatasSynchronizations){let V=A.createPacket(A.outboundPackets.uiDatasPacketDefinition,G,this._world.loop.currentTick);W.connection.send(V)}let $=Object.values(this._queuedSceneUISynchronizations);if($.length>0){let W=A.createPacket(A.outboundPackets.sceneUIsPacketDefinition,$,this._world.loop.currentTick);O8.instance.broadcastForWorld(this._world.id,W)}if(this._queuedWorldSynchronization){let W=A.createPacket(A.outboundPackets.worldPacketDefinition,this._queuedWorldSynchronization,this._world.loop.currentTick);O8.instance.broadcastForWorld(this._world.id,W)}for(let[W,G]of this._queuedPlayerCameraSynchronizations){let V=A.createPacket(A.outboundPackets.cameraPacketDefinition,G,this._world.loop.currentTick);W.connection.send(V)}for(let W of this._queuedBroadcasts)O8.instance.broadcastForWorld(this._world.id,W);let Q=this._queuedDebugRaycastSynchronizations;if(Q.length>0){let W=A.createPacket(A.outboundPackets.physicsDebugRaycastsPacketDefinition,Q,this._world.loop.currentTick);O8.instance.broadcastForWorld(this._world.id,W)}this._queuedBroadcasts=[],this._queuedAudioSynchronizations={},this._queuedBlockSynchronizations={},this._queuedBlockTypeSynchronizations={},this._queuedChunkSynchronizations={},this._queuedDebugRaycastSynchronizations=[],this._queuedEntitySynchronizations={},this._queuedLightSynchronizations={},this._queuedPlayerPackets.clear(),this._queuedPlayerCameraSynchronizations.clear(),this._queuedPlayerUISynchronizations.clear(),this._queuedPlayerUIDatasSynchronizations.clear(),this._queuedSceneUISynchronizations={},this._queuedWorldSynchronization=void 0,this._spawnedChunks.clear(),this._spawnedEntities.clear()}_subscribeToAudioEvents(){this._world.eventRouter.on("AUDIO.PAUSE",this._onAudioPause),this._world.eventRouter.on("AUDIO.PLAY",this._onAudioPlay),this._world.eventRouter.on("AUDIO.PLAY_RESTART",this._onAudioPlayRestart),this._world.eventRouter.on("AUDIO.SET_ATTACHED_TO_ENTITY",this._onAudioSetAttachedToEntity),this._world.eventRouter.on("AUDIO.SET_DETUNE",this._onAudioSetDetune),this._world.eventRouter.on("AUDIO.SET_DISTORTION",this._onAudioSetDistortion),this._world.eventRouter.on("AUDIO.SET_POSITION",this._onAudioSetPosition),this._world.eventRouter.on("AUDIO.SET_PLAYBACK_RATE",this._onAudioSetPlaybackRate),this._world.eventRouter.on("AUDIO.SET_REFERENCE_DISTANCE",this._onAudioSetReferenceDistance),this._world.eventRouter.on("AUDIO.SET_VOLUME",this._onAudioSetVolume)}_subscribeToBlockTypeRegistryEvents(){this._world.eventRouter.on("BLOCK_TYPE_REGISTRY.REGISTER_BLOCK_TYPE",this._onBlockTypeRegistryRegisterBlockType)}_subscribeToChatEvents(){this._world.eventRouter.on("CHAT.SEND_BROADCAST_MESSAGE",this._onChatSendBroadcastMessage),this._world.eventRouter.on("CHAT.SEND_PLAYER_MESSAGE",this._onChatSendPlayerMessage)}_subscribeToChunkEvents(){this._world.eventRouter.on("CHUNK.SPAWN",this._onChunkSpawn),this._world.eventRouter.on("CHUNK.DESPAWN",this._onChunkDespawn),this._world.eventRouter.on("CHUNK.SET_BLOCK",this._onChunkSetBlock)}_subscribeToEntityEvents(){this._world.eventRouter.on("ENTITY.SPAWN",this._onEntitySpawn),this._world.eventRouter.on("ENTITY.DESPAWN",this._onEntityDespawn),this._world.eventRouter.on("ENTITY.SET_MODEL_ANIMATIONS_PLAYBACK_RATE",this._onEntitySetModelAnimationsPlaybackRate),this._world.eventRouter.on("ENTITY.SET_MODEL_HIDDEN_NODES",this._onEntitySetModelHiddenNodes),this._world.eventRouter.on("ENTITY.SET_OPACITY",this._onEntitySetOpacity),this._world.eventRouter.on("ENTITY.SET_PARENT",this._onEntitySetParent),this._world.eventRouter.on("ENTITY.SET_TINT_COLOR",this._onEntitySetTintColor),this._world.eventRouter.on("ENTITY.START_MODEL_LOOPED_ANIMATIONS",this._onEntityStartModelLoopedAnimations),this._world.eventRouter.on("ENTITY.START_MODEL_ONESHOT_ANIMATIONS",this._onEntityStartModelOneshotAnimations),this._world.eventRouter.on("ENTITY.STOP_MODEL_ANIMATIONS",this._onEntityStopModelAnimations),this._world.eventRouter.on("ENTITY.UPDATE_POSITION",this._onEntityUpdatePosition),this._world.eventRouter.on("ENTITY.UPDATE_ROTATION",this._onEntityUpdateRotation)}_subscribeToLightEvents(){this._world.eventRouter.on("LIGHT.DESPAWN",this._onLightDespawn),this._world.eventRouter.on("LIGHT.SET_ANGLE",this._onLightSetAngle),this._world.eventRouter.on("LIGHT.SET_ATTACHED_TO_ENTITY",this._onLightSetAttachedToEntity),this._world.eventRouter.on("LIGHT.SET_COLOR",this._onLightSetColor),this._world.eventRouter.on("LIGHT.SET_DISTANCE",this._onLightSetDistance),this._world.eventRouter.on("LIGHT.SET_INTENSITY",this._onLightSetIntensity),this._world.eventRouter.on("LIGHT.SET_OFFSET",this._onLightSetOffset),this._world.eventRouter.on("LIGHT.SET_PENUMBRA",this._onLightSetPenumbra),this._world.eventRouter.on("LIGHT.SET_POSITION",this._onLightSetPosition),this._world.eventRouter.on("LIGHT.SET_TRACKED_ENTITY",this._onLightSetTrackedEntity),this._world.eventRouter.on("LIGHT.SET_TRACKED_POSITION",this._onLightSetTrackedPosition),this._world.eventRouter.on("LIGHT.SPAWN",this._onLightSpawn)}_subscribeToPlayerEvents(){this._world.eventRouter.on("PLAYER.JOINED_WORLD",this._onPlayerJoinedWorld),this._world.eventRouter.on("PLAYER.LEFT_WORLD",this._onPlayerLeftWorld),this._world.eventRouter.on("PLAYER.REQUEST_SYNC",this._onPlayerRequestSync)}_subscribeToPlayerCameraEvents(){this._world.eventRouter.on("PLAYER_CAMERA.LOOK_AT_ENTITY",this._onPlayerCameraLookAtEntity),this._world.eventRouter.on("PLAYER_CAMERA.LOOK_AT_POSITION",this._onPlayerCameraLookAtPosition),this._world.eventRouter.on("PLAYER_CAMERA.SET_ATTACHED_TO_ENTITY",this._onPlayerCameraSetAttachedToEntity),this._world.eventRouter.on("PLAYER_CAMERA.SET_ATTACHED_TO_POSITION",this._onPlayerCameraSetAttachedToPosition),this._world.eventRouter.on("PLAYER_CAMERA.SET_FILM_OFFSET",this._onPlayerCameraSetFilmOffset),this._world.eventRouter.on("PLAYER_CAMERA.SET_FORWARD_OFFSET",this._onPlayerCameraSetForwardOffset),this._world.eventRouter.on("PLAYER_CAMERA.SET_FOV",this._onPlayerCameraSetFov),this._world.eventRouter.on("PLAYER_CAMERA.SET_MODEL_HIDDEN_NODES",this._onPlayerCameraSetModelHiddenNodes),this._world.eventRouter.on("PLAYER_CAMERA.SET_MODE",this._onPlayerCameraSetMode),this._world.eventRouter.on("PLAYER_CAMERA.SET_OFFSET",this._onPlayerCameraSetOffset),this._world.eventRouter.on("PLAYER_CAMERA.SET_TRACKED_ENTITY",this._onPlayerCameraSetTrackedEntity),this._world.eventRouter.on("PLAYER_CAMERA.SET_TRACKED_POSITION",this._onPlayerCameraSetTrackedPosition),this._world.eventRouter.on("PLAYER_CAMERA.SET_ZOOM",this._onPlayerCameraSetZoom)}_subscribeToPlayerUIEvents(){this._world.eventRouter.on("PLAYER_UI.LOAD",this._onPlayerUILoad),this._world.eventRouter.on("PLAYER_UI.LOCK_POINTER",this._onPlayerUILockPointer),this._world.eventRouter.on("PLAYER_UI.SEND_DATA",this._onPlayerUISendData)}_subscribeToSceneUIEvents(){this._world.eventRouter.on("SCENE_UI.LOAD",this._onSceneUILoad),this._world.eventRouter.on("SCENE_UI.SET_ATTACHED_TO_ENTITY",this._onSceneUISetAttachedToEntity),this._world.eventRouter.on("SCENE_UI.SET_OFFSET",this._onSceneUISetOffset),this._world.eventRouter.on("SCENE_UI.SET_POSITION",this._onSceneUISetPosition),this._world.eventRouter.on("SCENE_UI.SET_STATE",this._onSceneUISetState),this._world.eventRouter.on("SCENE_UI.SET_VIEW_DISTANCE",this._onSceneUISetViewDistance),this._world.eventRouter.on("SCENE_UI.UNLOAD",this._onSceneUIUnload)}_subscribeToSimulationEvents(){this._world.eventRouter.on("SIMULATION.DEBUG_RAYCAST",this._onSimulationDebugRaycast),this._world.eventRouter.on("SIMULATION.DEBUG_RENDER",this._onSimulationDebugRender)}_subscribeToWorldEvents(){this._world.eventRouter.on("WORLD.SET_AMBIENT_LIGHT_COLOR",this._onWorldSetAmbientLightColor),this._world.eventRouter.on("WORLD.SET_AMBIENT_LIGHT_INTENSITY",this._onWorldSetAmbientLightIntensity),this._world.eventRouter.on("WORLD.SET_DIRECTIONAL_LIGHT_COLOR",this._onWorldSetDirectionalLightColor),this._world.eventRouter.on("WORLD.SET_DIRECTIONAL_LIGHT_INTENSITY",this._onWorldSetDirectionalLightIntensity),this._world.eventRouter.on("WORLD.SET_DIRECTIONAL_LIGHT_POSITION",this._onWorldSetDirectionalLightPosition)}_onAudioPause=(J)=>{let Z=this._createOrGetQueuedAudioSync(J.audio);Z.pa=!0,delete Z.pl,delete Z.r};_onAudioPlay=(J)=>{let Z=J.audio.serialize();Z.pl=!0,delete Z.pa,delete Z.r,this._queuedAudioSynchronizations[Z.i]=Z};_onAudioPlayRestart=(J)=>{let Z=this._createOrGetQueuedAudioSync(J.audio);Z.r=!0,delete Z.pa,delete Z.pl,this._queuedAudioSynchronizations[Z.i]=Z};_onAudioSetAttachedToEntity=(J)=>{let Z=this._createOrGetQueuedAudioSync(J.audio);Z.e=J.entity?J.entity.id:void 0,Z.p=J.entity?void 0:Z.p};_onAudioSetDetune=(J)=>{let Z=this._createOrGetQueuedAudioSync(J.audio);Z.de=J.detune};_onAudioSetDistortion=(J)=>{let Z=this._createOrGetQueuedAudioSync(J.audio);Z.di=J.distortion};_onAudioSetPosition=(J)=>{let Z=this._createOrGetQueuedAudioSync(J.audio);Z.e=J.position?void 0:Z.e,Z.p=J.position?t.serializeVector(J.position):void 0};_onAudioSetPlaybackRate=(J)=>{let Z=this._createOrGetQueuedAudioSync(J.audio);Z.pr=J.playbackRate};_onAudioSetReferenceDistance=(J)=>{let Z=this._createOrGetQueuedAudioSync(J.audio);Z.rd=J.referenceDistance};_onAudioSetVolume=(J)=>{let Z=this._createOrGetQueuedAudioSync(J.audio);Z.v=J.volume};_onBlockTypeRegistryRegisterBlockType=(J)=>{let Z=J.blockType.serialize();this._queuedBlockTypeSynchronizations[J.blockType.id]=Z};_onChatSendBroadcastMessage=(J)=>{let{message:Z,color:Y}=J;this._queuedBroadcasts.push(A.createPacket(A.outboundPackets.chatMessagesPacketDefinition,[{m:Z,c:Y}],this._world.loop.currentTick))};_onChatSendPlayerMessage=(J)=>{let{player:Z,message:Y,color:X}=J,F=this._queuedPlayerPackets.get(Z)??[];F.push(A.createPacket(A.outboundPackets.chatMessagesPacketDefinition,[{m:Y,c:X}],this._world.loop.currentTick)),this._queuedPlayerPackets.set(Z,F)};_onChunkSpawn=(J)=>{let Z=this._createOrGetQueuedChunkSync(J.chunk);Z.b=Array.from(J.chunk.blocks),Z.rm=void 0,this._spawnedChunks.add(Z.c.join(","))};_onChunkDespawn=(J)=>{let Z=this._createOrGetQueuedChunkSync(J.chunk),Y=Z.c.join(",");if(this._spawnedChunks.has(Y))delete this._queuedChunkSynchronizations[Y],this._spawnedChunks.delete(Y);else Z.rm=!0};_onChunkSetBlock=(J)=>{let Z=this._createOrGetQueuedBlockSync(J.globalCoordinate);Z.i=J.blockTypeId};_onEntitySetModelAnimationsPlaybackRate=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);Z.ap=J.playbackRate};_onEntitySpawn=(J)=>{let Z=J.entity.serialize();this._queuedEntitySynchronizations[Z.i]=Z,this._spawnedEntities.add(Z.i)};_onEntityDespawn=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);if(this._spawnedEntities.has(Z.i))delete this._queuedEntitySynchronizations[Z.i],this._spawnedEntities.delete(Z.i);else Z.rm=!0};_onEntitySetModelHiddenNodes=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);Z.h=Array.from(J.modelHiddenNodes)};_onEntitySetOpacity=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);Z.o=J.opacity};_onEntitySetParent=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);Z.pe=J.parent?J.parent.id:void 0,Z.pn=J.parentNodeName};_onEntitySetTintColor=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);Z.t=J.tintColor?t.serializeRgbColor(J.tintColor):void 0};_onEntityStartModelLoopedAnimations=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);if(Z.al=Array.from(new Set([...Z.al??[],...J.animations])),Z.as)Z.as=Z.as.filter((Y)=>!J.animations.has(Y)).filter(Boolean)};_onEntityStartModelOneshotAnimations=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);if(Z.ao=Array.from(new Set([...Z.ao??[],...J.animations])),Z.as)Z.as=Z.as.filter((Y)=>!J.animations.has(Y)).filter(Boolean)};_onEntityStopModelAnimations=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);if(Z.al)Z.al=Z.al.filter((Y)=>!J.animations.has(Y)).filter(Boolean);if(Z.ao)Z.ao=Z.ao.filter((Y)=>!J.animations.has(Y)).filter(Boolean);Z.as=Array.from(new Set([...Z.as??[],...J.animations]))};_onEntityUpdateRotation=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);Z.r=[J.rotation.x,J.rotation.y,J.rotation.z,J.rotation.w]};_onEntityUpdatePosition=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);Z.p=[J.position.x,J.position.y,J.position.z]};_onLightDespawn=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.rm=!0};_onLightSetAngle=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.a=J.angle};_onLightSetAttachedToEntity=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.e=J.entity?J.entity.id:void 0,Z.p=J.entity?void 0:Z.p};_onLightSetColor=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.c=t.serializeRgbColor(J.color)};_onLightSetDistance=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.d=J.distance};_onLightSetIntensity=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.n=J.intensity};_onLightSetOffset=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.o=J.offset?t.serializeVector(J.offset):void 0};_onLightSetPenumbra=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.pe=J.penumbra};_onLightSetPosition=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.p=J.position?t.serializeVector(J.position):void 0,Z.e=J.position?void 0:Z.e};_onLightSetTrackedEntity=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.te=J.entity?J.entity.id:void 0,Z.tp=J.entity?void 0:Z.tp};_onLightSetTrackedPosition=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.tp=J.position?t.serializeVector(J.position):void 0,Z.te=J.position?void 0:Z.te};_onLightSpawn=(J)=>{let Z=J.light.serialize();this._queuedLightSynchronizations[Z.i]=Z};_onPlayerCameraLookAtEntity=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.pl=t.serializeVector(J.entity.position),delete Z.et,delete Z.pt};_onPlayerCameraLookAtPosition=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.pl=J.position?t.serializeVector(J.position):void 0,delete Z.et,delete Z.pt};_onPlayerCameraSetAttachedToEntity=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.e=J.entity.id,delete Z.p};_onPlayerCameraSetAttachedToPosition=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.p=J.position?t.serializeVector(J.position):void 0,delete Z.e};_onPlayerCameraSetFilmOffset=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.fo=J.filmOffset};_onPlayerCameraSetForwardOffset=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.ffo=J.forwardOffset};_onPlayerCameraSetFov=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.fv=J.fov};_onPlayerCameraSetModelHiddenNodes=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.h=Array.from(J.modelHiddenNodes)};_onPlayerCameraSetMode=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.m=J.mode};_onPlayerCameraSetOffset=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.o=J.offset?t.serializeVector(J.offset):void 0};_onPlayerCameraSetTrackedEntity=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.et=J.entity?J.entity.id:void 0,delete Z.pl,delete Z.pt};_onPlayerCameraSetTrackedPosition=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.pt=J.position?t.serializeVector(J.position):void 0,delete Z.et,delete Z.pl};_onPlayerCameraSetZoom=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.z=J.zoom};_onPlayerJoinedWorld=(J)=>{let{player:Z}=J,Y=this._queuedPlayerPackets.get(Z)??[];Y.push(A.createPacket(A.outboundPackets.worldPacketDefinition,this._world.serialize(),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.blockTypesPacketDefinition,this._world.blockTypeRegistry.serialize(),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.chunksPacketDefinition,this._world.chunkLattice.getAllChunks().map((F)=>F.serialize()),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.entitiesPacketDefinition,this._world.entityManager.getAllEntities().map((F)=>{if(Z.camera.attachedToEntity===void 0&&F instanceof H9&&F.player===Z)Z.camera.setAttachedToEntity(F);return F.serialize()}),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.audiosPacketDefinition,this._world.audioManager.getAllLoopedAudios().map((F)=>F.serialize()),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.lightsPacketDefinition,this._world.lightManager.getAllLights().map((F)=>F.serialize()),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.sceneUIsPacketDefinition,this._world.sceneUIManager.getAllSceneUIs().map((F)=>F.serialize()),this._world.loop.currentTick));let X=this._createOrGetQueuedPlayerCameraSync(Z.camera);this._queuedPlayerCameraSynchronizations.set(Z,{...Z.camera.serialize(),...X}),this._queuedPlayerPackets.set(Z,Y)};_onPlayerLeftWorld=(J)=>{};_onPlayerRequestSync=(J)=>{J.player.connection.send(A.createPacket(A.outboundPackets.syncResponsePacketDefinition,{r:J.receivedAt,s:Date.now(),p:performance.now()-J.receivedAtMs,n:this._world.loop.nextTickMs},this._world.loop.currentTick))};_onPlayerUILoad=(J)=>{let Z=this._createOrGetQueuedPlayerUISync(J.playerUI);Z.u=J.htmlUri};_onPlayerUILockPointer=(J)=>{let Z=this._createOrGetQueuedPlayerUISync(J.playerUI);Z.p=J.lock};_onPlayerUISendData=(J)=>{this._createOrGetQueuedPlayerUIDatasSync(J.playerUI).push(J.data)};_onSceneUILoad=(J)=>{let Z=J.sceneUI.serialize();this._queuedSceneUISynchronizations[Z.i]=Z};_onSceneUISetAttachedToEntity=(J)=>{let Z=this._createOrGetQueuedSceneUISync(J.sceneUI);Z.e=J.entity?J.entity.id:void 0,Z.p=J.entity?void 0:Z.p};_onSceneUISetOffset=(J)=>{let Z=this._createOrGetQueuedSceneUISync(J.sceneUI);Z.o=J.offset?t.serializeVector(J.offset):void 0};_onSceneUISetPosition=(J)=>{let Z=this._createOrGetQueuedSceneUISync(J.sceneUI);Z.p=J.position?t.serializeVector(J.position):void 0,Z.e=J.position?void 0:Z.e};_onSceneUISetState=(J)=>{let Z=this._createOrGetQueuedSceneUISync(J.sceneUI);Z.s=J.state};_onSceneUISetViewDistance=(J)=>{let Z=this._createOrGetQueuedSceneUISync(J.sceneUI);Z.v=J.viewDistance};_onSceneUIUnload=(J)=>{let Z=this._createOrGetQueuedSceneUISync(J.sceneUI);Z.rm=!0};_onSimulationDebugRaycast=(J)=>{this._queuedDebugRaycastSynchronizations.push(t.serializePhysicsDebugRaycast(J))};_onSimulationDebugRender=(J)=>{this._queuedBroadcasts.push(A.createPacket(A.outboundPackets.physicsDebugRenderPacketDefinition,{v:Array.from(J.vertices),c:Array.from(J.colors)},this._world.loop.currentTick))};_onWorldSetAmbientLightColor=(J)=>{let Z=this._createOrGetQueuedWorldSync(J.world);Z.ac=t.serializeRgbColor(J.color)};_onWorldSetAmbientLightIntensity=(J)=>{let Z=this._createOrGetQueuedWorldSync(J.world);Z.ai=J.intensity};_onWorldSetDirectionalLightColor=(J)=>{let Z=this._createOrGetQueuedWorldSync(J.world);Z.dc=t.serializeRgbColor(J.color)};_onWorldSetDirectionalLightIntensity=(J)=>{let Z=this._createOrGetQueuedWorldSync(J.world);Z.di=J.intensity};_onWorldSetDirectionalLightPosition=(J)=>{let Z=this._createOrGetQueuedWorldSync(J.world);Z.dp=t.serializeVector(J.position)};_createOrGetQueuedAudioSync(J){if(J.id===void 0)throw new Error("NetworkSynchronizer._createOrGetQueuedAudioSync(): Audio has no id!");return this._queuedAudioSynchronizations[J.id]??={i:J.id}}_createOrGetQueuedBlockSync(J){let{x:Z,y:Y,z:X}=J;return this._queuedBlockSynchronizations[`${Z},${Y},${X}`]??={i:0,c:[Z,Y,X]}}_createOrGetQueuedChunkSync(J){if(!J.originCoordinate)throw new Error("NetworkSynchronizer._createOrGetQueuedChunkSync(): Chunk has no origin coordinate!");let{x:Z,y:Y,z:X}=J.originCoordinate;return this._queuedChunkSynchronizations[`${Z},${Y},${X}`]??={c:[Z,Y,X]}}_createOrGetQueuedEntitySync(J){if(J.id===void 0)throw new Error("NetworkSynchronizer._createOrGetQueuedEntitySync(): Entity has no id!");return this._queuedEntitySynchronizations[J.id]??={i:J.id}}_createOrGetQueuedLightSync(J){if(J.id===void 0)throw new Error("NetworkSynchronizer._createOrGetQueuedLightSync(): Light has no id!");return this._queuedLightSynchronizations[J.id]??={i:J.id}}_createOrGetQueuedPlayerCameraSync(J){let Z=this._queuedPlayerCameraSynchronizations.get(J.player);if(!Z)Z={},this._queuedPlayerCameraSynchronizations.set(J.player,Z);return Z}_createOrGetQueuedPlayerUISync(J){let Z=this._queuedPlayerUISynchronizations.get(J.player);if(!Z)Z={},this._queuedPlayerUISynchronizations.set(J.player,Z);return Z}_createOrGetQueuedPlayerUIDatasSync(J){let Z=this._queuedPlayerUIDatasSynchronizations.get(J.player);if(!Z)Z=[],this._queuedPlayerUIDatasSynchronizations.set(J.player,Z);return Z}_createOrGetQueuedSceneUISync(J){if(J.id===void 0)throw new Error("NetworkSynchronizer._createOrGetQueuedSceneUISync(): SceneUI has no id!");return this._queuedSceneUISynchronizations[J.id]??={i:J.id}}_createOrGetQueuedWorldSync(J){if(J.id!==this._world.id)throw new Error("NetworkSynchronizer._createOrGetQueuedWorldSync(): World does not match this network synchronizer world!");return this._queuedWorldSynchronization??={i:J.id}}}class V7{_sceneUIs=new Map;_nextSceneUIId=1;_world;constructor(J){this._world=J}get world(){return this._world}getAllSceneUIs(){return Array.from(this._sceneUIs.values())}getAllEntityAttachedSceneUIs(J){return this.getAllSceneUIs().filter((Z)=>Z.attachedToEntity===J)}getSceneUIById(J){return this._sceneUIs.get(J)}registerSceneUI(J){if(J.id!==void 0)return J.id;let Z=this._nextSceneUIId;return this._sceneUIs.set(Z,J),this._nextSceneUIId++,Z}unloadEntityAttachedSceneUIs(J){this.getAllEntityAttachedSceneUIs(J).forEach((Z)=>{Z.unload()})}unregisterSceneUI(J){if(J.id===void 0)return;this._sceneUIs.delete(J.id)}}class O7{_accumulatorMs=0;_targetTicksPerSecond;_fixedTimestepMs;_fixedTimestepS;_nextTickMs=0;_lastLoopTimeMs=0;_tickFunction;_tickErrorCallback;_tickHandle=null;constructor(J,Z,Y){this._targetTicksPerSecond=J,this._fixedTimestepS=Math.fround(1/J),this._fixedTimestepMs=Math.fround(this._fixedTimestepS*1000),this._tickFunction=Z,this._tickErrorCallback=Y}get targetTicksPerSecond(){return this._targetTicksPerSecond}get fixedTimestepMs(){return this._fixedTimestepMs}get fixedTimestepS(){return this._fixedTimestepS}get nextTickMs(){return this._nextTickMs}start(){if(this._tickHandle)return console.warn("Ticker.start(): ticker already running.");this._lastLoopTimeMs=performance.now();let J=()=>{let Z=performance.now(),Y=Z-this._lastLoopTimeMs;if(this._lastLoopTimeMs=Z,Y>250)Y=250;this._accumulatorMs+=Y;while(this._accumulatorMs>=this._fixedTimestepMs)this._tick(this._fixedTimestepMs),this._accumulatorMs-=this._fixedTimestepMs;this._nextTickMs=this._fixedTimestepMs-this._accumulatorMs,this._tickHandle=setTimeout(J,0)};J()}stop(){if(!this._tickHandle)return console.warn("Ticker.stop(): ticker not running.");clearTimeout(this._tickHandle),this._tickHandle=null}_tick(J){try{this._tickFunction(J)}catch(Z){if(Z instanceof Error&&this._tickErrorCallback)this._tickErrorCallback(Z);else console.warn("Ticker._tick(): tick callback threw an error, but it was not an instance of Error. Error:",Z)}}}var uR;((K)=>{K.START="WORLD_LOOP.START";K.STOP="WORLD_LOOP.STOP";K.TICK_START="WORLD_LOOP.TICK_START";K.TICK_END="WORLD_LOOP.TICK_END";K.TICK_ERROR="WORLD_LOOP.TICK_ERROR"})(uR||={});class v7{_currentTick=0;_ticker;_world;constructor(J,Z=eQ){this._ticker=new O7(Z,this._tick,this._onTickError),this._world=J}get currentTick(){return this._currentTick}get nextTickMs(){return this._ticker.nextTickMs}get timestepS(){return this._ticker.fixedTimestepS}get world(){return this._world}start(){this._ticker.start(),this._world.eventRouter.emit("WORLD_LOOP.START",{worldLoop:this})}stop(){this._ticker.stop(),this._world.eventRouter.emit("WORLD_LOOP.STOP",{worldLoop:this})}_tick=(J)=>{this._world.eventRouter.emit("WORLD_LOOP.TICK_START",{worldLoop:this,tickDeltaMs:J});let Z=performance.now();this._world.chunkLattice.updateChunks(),this._world.entityManager.tickEntities(J),this._world.simulation.step(J),this._world.entityManager.checkAndEmitUpdates(),this._world.networkSynchronizer.synchronize(),this._currentTick++,this._world.eventRouter.emit("WORLD_LOOP.TICK_END",{worldLoop:this,tickDurationMs:performance.now()-Z})};_onTickError=(J)=>{console.error(J),this._world.eventRouter.emit("WORLD_LOOP.TICK_ERROR",{worldLoop:this,error:J})}}class L7{onPlayerJoin;onPlayerLeave;_id;_ambientLightColor;_ambientLightIntensity;_directionalLightColor;_directionalLightIntensity;_directionalLightPosition;_name;_skyboxUri;_audioManager;_blockTypeRegistry;_chatManager;_chunkLattice;_entityManager;_eventRouter;_lightManager;_loop;_networkSynchronizer;_sceneUIManager;_simulation;constructor(J){this._id=J.id,this._ambientLightColor=J.ambientLightColor??{r:255,g:255,b:255},this._ambientLightIntensity=J.ambientLightIntensity??1,this._directionalLightColor=J.directionalLightColor??{r:255,g:255,b:255},this._directionalLightIntensity=J.directionalLightIntensity??3,this._directionalLightPosition=J.directionalLightPosition??{x:100,y:150,z:100},this._name=J.name,this._skyboxUri=J.skyboxUri,this._eventRouter=new K0(`world.${J.id}.${J.name}`),this._audioManager=new Y5(this),this._blockTypeRegistry=new D5(this),this._chatManager=new q7(this),this._chunkLattice=new Y7(this),this._entityManager=new F7(this),this._lightManager=new K7(this),this._loop=new v7(this,J.tickRate),this._networkSynchronizer=new _Y(this),this._sceneUIManager=new V7(this),this._simulation=new W7(this,J.tickRate,J.gravity)}get id(){return this._id}get ambientLightColor(){return this._ambientLightColor}get ambientLightIntensity(){return this._ambientLightIntensity}get directionalLightColor(){return this._directionalLightColor}get directionalLightIntensity(){return this._directionalLightIntensity}get directionalLightPosition(){return this._directionalLightPosition}get name(){return this._name}get skyboxUri(){return this._skyboxUri}get audioManager(){return this._audioManager}get blockTypeRegistry(){return this._blockTypeRegistry}get chatManager(){return this._chatManager}get chunkLattice(){return this._chunkLattice}get entityManager(){return this._entityManager}get eventRouter(){return this._eventRouter}get lightManager(){return this._lightManager}get loop(){return this._loop}get networkSynchronizer(){return this._networkSynchronizer}get sceneUIManager(){return this._sceneUIManager}get simulation(){return this._simulation}loadMap(J){if(J.blockTypes)for(let Z of J.blockTypes)this.blockTypeRegistry.registerGenericBlockType({id:Z.id,isLiquid:Z.isLiquid,name:Z.name,textureUri:Z.textureUri});if(J.blocks)for(let[Z,Y]of Object.entries(J.blocks)){let[X,F,K]=Z.split(",").map(Number);this.chunkLattice.setBlock({x:X,y:F,z:K},Y)}if(J.entities)for(let[Z,Y]of Object.entries(J.entities)){let[X,F,K]=Z.split(",").map(Number);new J8(Y).spawn(this,{x:X,y:F,z:K})}}setAmbientLightColor(J){this._ambientLightColor=J,this._eventRouter.emit("WORLD.SET_AMBIENT_LIGHT_COLOR",{world:this,color:J})}setAmbientLightIntensity(J){this._ambientLightIntensity=J,this._eventRouter.emit("WORLD.SET_AMBIENT_LIGHT_INTENSITY",{world:this,intensity:J})}setDirectionalLightColor(J){this._directionalLightColor=J,this._eventRouter.emit("WORLD.SET_DIRECTIONAL_LIGHT_COLOR",{world:this,color:J})}setDirectionalLightIntensity(J){this._directionalLightIntensity=J,this._eventRouter.emit("WORLD.SET_DIRECTIONAL_LIGHT_INTENSITY",{world:this,intensity:J})}setDirectionalLightPosition(J){this._directionalLightPosition=J,this._eventRouter.emit("WORLD.SET_DIRECTIONAL_LIGHT_POSITION",{world:this,position:J})}start(){this._loop.start(),this._eventRouter.emit("WORLD.START",{world:this,startedAtMs:Date.now()})}stop(){this._loop.stop(),this._eventRouter.emit("WORLD.STOP",{world:this,stoppedAtMs:Date.now()})}serialize(){return t.serializeWorld(this)}}var dR;((Y)=>{Y.START="GAMESERVER.START";Y.STOP="GAMESERVER.STOP"})(dR||={});function Eu(J){v0.init().then(()=>{return d6.instance.modelRegistry.preloadModels()}).then(()=>{J(d6.instance.worlds[0]),d6.instance.start()}).catch((Z)=>{console.error("Failed to initialize the game engine, exiting. Error:",Z),process.exit(1)})}class d6{static _instance;_modelRegistry=F6.instance;_playerManager=O8.instance;_socket=Z7.instance;_webServer=a1.instance;_worlds={};constructor(){let J=new L7({id:0,name:"Default World",skyboxUri:"skyboxes/partly-cloudy"});this._worlds[J.id]=J}static get instance(){if(!this._instance)this._instance=new d6;return this._instance}get modelRegistry(){return this._modelRegistry}get playerManager(){return this._playerManager}get socket(){return this._socket}get webServer(){return this._webServer}get worlds(){return this._worlds}start(){K0.serverInstance.emit("GAMESERVER.START",{startedAtMs:performance.now()}),Object.values(this._worlds).forEach((J)=>J.start()),this._webServer.start()}stop(){K0.serverInstance.emit("GAMESERVER.STOP",{stoppedAtMs:performance.now()}),Object.values(this._worlds).forEach((J)=>J.stop())}}var sR=["w","a","s","d","sp","sh","tb","ml","mr","q","e","r","f","z","x","c","v","1","2","3","4","5","6","7","8","9","0"],pY;((F)=>{F.CHAT_MESSAGE_SEND="PLAYER.CHAT_MESSAGE_SEND";F.JOINED_WORLD="PLAYER.JOINED_WORLD";F.LEFT_WORLD="PLAYER.LEFT_WORLD";F.REQUEST_SYNC="PLAYER.REQUEST_SYNC"})(pY||={});class Y4{id;username;profilePictureUrl;camera;connection;ui;_input={};_world;constructor(J,Z){this.id=Z?.id??"unknown",this.username=Z?.user.username??`Unknown-Player-${Math.floor(Math.random()*1e6)}`,this.profilePictureUrl=Z?.user.profilePictureURL??void 0,this.camera=new $7(this),this.connection=J,this.ui=new Q7(this),J.onPacket(A.PacketId.CHAT_MESSAGE_SEND,this._onChatMessageSendPacket),J.onPacket(A.PacketId.DEBUG_CONFIG,this._onDebugConfigPacket),J.onPacket(A.PacketId.INPUT,this._onInputPacket),J.onPacket(A.PacketId.SYNC_REQUEST,this._onSyncRequestPacket),J.onPacket(A.PacketId.UI_DATA_SEND,this._onUIDataSendPacket),this.joinWorld(d6.instance.worlds[0])}get input(){return this._input}get world(){return this._world}joinWorld(J){if(this.leaveWorld(),this._world=J,this._world.onPlayerJoin)this._world.onPlayerJoin(this);this._world.eventRouter.emit("PLAYER.JOINED_WORLD",{player:this,world:this._world})}leaveWorld(){if(!this._world)return;if(this._world.onPlayerLeave)this._world.onPlayerLeave(this);this._world.eventRouter.emit("PLAYER.LEFT_WORLD",{player:this,world:this._world}),this._world=void 0}disconnect(){this.leaveWorld(),this.connection.close()}_onChatMessageSendPacket=(J)=>{if(this._world)this._world.eventRouter.emit("PLAYER.CHAT_MESSAGE_SEND",{player:this,message:J[1]})};_onDebugConfigPacket=(J)=>{console.log(J)};_onInputPacket=(J)=>{let Z=J[1];if(sR.forEach((Y)=>{let X=Y;if(Z[X]!==void 0)this._input[X]=Boolean(Z[X])}),Z.cp!==void 0)this.camera.setOrientationPitch(Z.cp);if(Z.cy!==void 0)this.camera.setOrientationYaw(Z.cy)};_onSyncRequestPacket=()=>{if(this._world)this._world.eventRouter.emit("PLAYER.REQUEST_SYNC",{player:this,receivedAt:Date.now(),receivedAtMs:performance.now()})};_onUIDataSendPacket=(J)=>{if(this.ui.onData)this.ui.onData(this.ui,J[1])}}var JG;((Y)=>{Y.SEND_BROADCAST_MESSAGE="CHAT.SEND_BROADCAST_MESSAGE";Y.SEND_PLAYER_MESSAGE="CHAT.SEND_PLAYER_MESSAGE"})(JG||={});class q7{onBroadcastMessage;_commandCallbacks={};_world;constructor(J){this._world=J,this._subscribeToPlayerEvents()}registerCommand(J,Z){this._commandCallbacks[J]=Z}unregisterCommand(J){delete this._commandCallbacks[J]}sendBroadcastMessage(J,Z){this._sendBroadcastMessage(void 0,J,Z)}sendPlayerMessage(J,Z,Y){this._world.eventRouter.emit("CHAT.SEND_PLAYER_MESSAGE",{player:J,message:Z,color:Y})}_subscribeToPlayerEvents(){this._world.eventRouter.on("PLAYER.CHAT_MESSAGE_SEND",this._onPlayerChatMessage)}_onPlayerChatMessage=(J)=>{let{player:Z,message:Y}=J,[X,...F]=Y.m.split(" "),K=this._commandCallbacks[X];if(K){K(Z,F,Y.m);return}this._sendBroadcastMessage(Z,`${Z.username}: ${Y.m}`)};_sendBroadcastMessage(J,Z,Y){if(this.onBroadcastMessage)this.onBroadcastMessage(J,Z,Y);this._world.eventRouter.emit("CHAT.SEND_BROADCAST_MESSAGE",{message:Z,color:Y})}}var i=0.000001,$0=typeof Float32Array!=="undefined"?Float32Array:Array,B6=Math.random;var UZ0=Math.PI/180;if(!Math.hypot)Math.hypot=function(){var J=0,Z=arguments.length;while(Z--)J+=arguments[Z]*arguments[Z];return Math.sqrt(J)};var t0={};E6(t0,{transpose:()=>cu,subtract:()=>oR,sub:()=>Jd,str:()=>nu,set:()=>hu,scale:()=>Au,rotate:()=>gu,multiplyScalarAndAdd:()=>tu,multiplyScalar:()=>ru,multiply:()=>aR,mul:()=>eu,invert:()=>lu,identity:()=>fu,fromValues:()=>Iu,fromScaling:()=>yu,fromRotation:()=>iu,frob:()=>uu,exactEquals:()=>au,equals:()=>ou,determinant:()=>mu,create:()=>Cu,copy:()=>pu,clone:()=>_u,adjoint:()=>bu,add:()=>su,LDU:()=>du});function Cu(){var J=new $0(4);if($0!=Float32Array)J[1]=0,J[2]=0;return J[0]=1,J[3]=1,J}function _u(J){var Z=new $0(4);return Z[0]=J[0],Z[1]=J[1],Z[2]=J[2],Z[3]=J[3],Z}function pu(J,Z){return J[0]=Z[0],J[1]=Z[1],J[2]=Z[2],J[3]=Z[3],J}function fu(J){return J[0]=1,J[1]=0,J[2]=0,J[3]=1,J}function Iu(J,Z,Y,X){var F=new $0(4);return F[0]=J,F[1]=Z,F[2]=Y,F[3]=X,F}function hu(J,Z,Y,X,F){return J[0]=Z,J[1]=Y,J[2]=X,J[3]=F,J}function cu(J,Z){if(J===Z){var Y=Z[1];J[1]=Z[2],J[2]=Y}else J[0]=Z[0],J[1]=Z[2],J[2]=Z[1],J[3]=Z[3];return J}function lu(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Y*K-F*X;if(!$)return null;return $=1/$,J[0]=K*$,J[1]=-X*$,J[2]=-F*$,J[3]=Y*$,J}function bu(J,Z){var Y=Z[0];return J[0]=Z[3],J[1]=-Z[1],J[2]=-Z[2],J[3]=Y,J}function mu(J){return J[0]*J[3]-J[2]*J[1]}function aR(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Y[0],W=Y[1],G=Y[2],V=Y[3];return J[0]=X*Q+K*W,J[1]=F*Q+$*W,J[2]=X*G+K*V,J[3]=F*G+$*V,J}function gu(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Math.sin(Y),W=Math.cos(Y);return J[0]=X*W+K*Q,J[1]=F*W+$*Q,J[2]=X*-Q+K*W,J[3]=F*-Q+$*W,J}function Au(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Y[0],W=Y[1];return J[0]=X*Q,J[1]=F*Q,J[2]=K*W,J[3]=$*W,J}function iu(J,Z){var Y=Math.sin(Z),X=Math.cos(Z);return J[0]=X,J[1]=Y,J[2]=-Y,J[3]=X,J}function yu(J,Z){return J[0]=Z[0],J[1]=0,J[2]=0,J[3]=Z[1],J}function nu(J){return"mat2("+J[0]+", "+J[1]+", "+J[2]+", "+J[3]+")"}function uu(J){return Math.hypot(J[0],J[1],J[2],J[3])}function du(J,Z,Y,X){return J[2]=X[2]/X[0],Y[0]=X[0],Y[1]=X[1],Y[3]=X[3]-J[2]*Y[1],[J,Z,Y]}function su(J,Z,Y){return J[0]=Z[0]+Y[0],J[1]=Z[1]+Y[1],J[2]=Z[2]+Y[2],J[3]=Z[3]+Y[3],J}function oR(J,Z,Y){return J[0]=Z[0]-Y[0],J[1]=Z[1]-Y[1],J[2]=Z[2]-Y[2],J[3]=Z[3]-Y[3],J}function au(J,Z){return J[0]===Z[0]&&J[1]===Z[1]&&J[2]===Z[2]&&J[3]===Z[3]}function ou(J,Z){var Y=J[0],X=J[1],F=J[2],K=J[3],$=Z[0],Q=Z[1],W=Z[2],G=Z[3];return Math.abs(Y-$)<=i*Math.max(1,Math.abs(Y),Math.abs($))&&Math.abs(X-Q)<=i*Math.max(1,Math.abs(X),Math.abs(Q))&&Math.abs(F-W)<=i*Math.max(1,Math.abs(F),Math.abs(W))&&Math.abs(K-G)<=i*Math.max(1,Math.abs(K),Math.abs(G))}function ru(J,Z,Y){return J[0]=Z[0]*Y,J[1]=Z[1]*Y,J[2]=Z[2]*Y,J[3]=Z[3]*Y,J}function tu(J,Z,Y,X){return J[0]=Z[0]+Y[0]*X,J[1]=Z[1]+Y[1]*X,J[2]=Z[2]+Y[2]*X,J[3]=Z[3]+Y[3]*X,J}var eu=aR,Jd=oR;var f0={};E6(f0,{transpose:()=>Qd,translate:()=>Od,subtract:()=>tR,sub:()=>Sd,str:()=>Pd,set:()=>Kd,scale:()=>Ld,rotate:()=>vd,projection:()=>Ud,normalFromMat4:()=>Md,multiplyScalarAndAdd:()=>kd,multiplyScalar:()=>xd,multiply:()=>rR,mul:()=>Td,invert:()=>Gd,identity:()=>$d,fromValues:()=>Fd,fromTranslation:()=>qd,fromScaling:()=>Hd,fromRotation:()=>wd,fromQuat:()=>zd,fromMat4:()=>Zd,fromMat2d:()=>Nd,frob:()=>Rd,exactEquals:()=>Dd,equals:()=>Bd,determinant:()=>Vd,create:()=>ZG,copy:()=>Xd,clone:()=>Yd,adjoint:()=>Wd,add:()=>jd});function ZG(){var J=new $0(9);if($0!=Float32Array)J[1]=0,J[2]=0,J[3]=0,J[5]=0,J[6]=0,J[7]=0;return J[0]=1,J[4]=1,J[8]=1,J}function Zd(J,Z){return J[0]=Z[0],J[1]=Z[1],J[2]=Z[2],J[3]=Z[4],J[4]=Z[5],J[5]=Z[6],J[6]=Z[8],J[7]=Z[9],J[8]=Z[10],J}function Yd(J){var Z=new $0(9);return Z[0]=J[0],Z[1]=J[1],Z[2]=J[2],Z[3]=J[3],Z[4]=J[4],Z[5]=J[5],Z[6]=J[6],Z[7]=J[7],Z[8]=J[8],Z}function Xd(J,Z){return J[0]=Z[0],J[1]=Z[1],J[2]=Z[2],J[3]=Z[3],J[4]=Z[4],J[5]=Z[5],J[6]=Z[6],J[7]=Z[7],J[8]=Z[8],J}function Fd(J,Z,Y,X,F,K,$,Q,W){var G=new $0(9);return G[0]=J,G[1]=Z,G[2]=Y,G[3]=X,G[4]=F,G[5]=K,G[6]=$,G[7]=Q,G[8]=W,G}function Kd(J,Z,Y,X,F,K,$,Q,W,G){return J[0]=Z,J[1]=Y,J[2]=X,J[3]=F,J[4]=K,J[5]=$,J[6]=Q,J[7]=W,J[8]=G,J}function $d(J){return J[0]=1,J[1]=0,J[2]=0,J[3]=0,J[4]=1,J[5]=0,J[6]=0,J[7]=0,J[8]=1,J}function Qd(J,Z){if(J===Z){var Y=Z[1],X=Z[2],F=Z[5];J[1]=Z[3],J[2]=Z[6],J[3]=Y,J[5]=Z[7],J[6]=X,J[7]=F}else J[0]=Z[0],J[1]=Z[3],J[2]=Z[6],J[3]=Z[1],J[4]=Z[4],J[5]=Z[7],J[6]=Z[2],J[7]=Z[5],J[8]=Z[8];return J}function Gd(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Z[4],Q=Z[5],W=Z[6],G=Z[7],V=Z[8],O=V*$-Q*G,v=-V*K+Q*W,w=G*K-$*W,H=Y*O+X*v+F*w;if(!H)return null;return H=1/H,J[0]=O*H,J[1]=(-V*X+F*G)*H,J[2]=(Q*X-F*$)*H,J[3]=v*H,J[4]=(V*Y-F*W)*H,J[5]=(-Q*Y+F*K)*H,J[6]=w*H,J[7]=(-G*Y+X*W)*H,J[8]=($*Y-X*K)*H,J}function Wd(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Z[4],Q=Z[5],W=Z[6],G=Z[7],V=Z[8];return J[0]=$*V-Q*G,J[1]=F*G-X*V,J[2]=X*Q-F*$,J[3]=Q*W-K*V,J[4]=Y*V-F*W,J[5]=F*K-Y*Q,J[6]=K*G-$*W,J[7]=X*W-Y*G,J[8]=Y*$-X*K,J}function Vd(J){var Z=J[0],Y=J[1],X=J[2],F=J[3],K=J[4],$=J[5],Q=J[6],W=J[7],G=J[8];return Z*(G*K-$*W)+Y*(-G*F+$*Q)+X*(W*F-K*Q)}function rR(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Z[4],W=Z[5],G=Z[6],V=Z[7],O=Z[8],v=Y[0],w=Y[1],H=Y[2],N=Y[3],q=Y[4],M=Y[5],R=Y[6],P=Y[7],x=Y[8];return J[0]=v*X+w*$+H*G,J[1]=v*F+w*Q+H*V,J[2]=v*K+w*W+H*O,J[3]=N*X+q*$+M*G,J[4]=N*F+q*Q+M*V,J[5]=N*K+q*W+M*O,J[6]=R*X+P*$+x*G,J[7]=R*F+P*Q+x*V,J[8]=R*K+P*W+x*O,J}function Od(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Z[4],W=Z[5],G=Z[6],V=Z[7],O=Z[8],v=Y[0],w=Y[1];return J[0]=X,J[1]=F,J[2]=K,J[3]=$,J[4]=Q,J[5]=W,J[6]=v*X+w*$+G,J[7]=v*F+w*Q+V,J[8]=v*K+w*W+O,J}function vd(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Z[4],W=Z[5],G=Z[6],V=Z[7],O=Z[8],v=Math.sin(Y),w=Math.cos(Y);return J[0]=w*X+v*$,J[1]=w*F+v*Q,J[2]=w*K+v*W,J[3]=w*$-v*X,J[4]=w*Q-v*F,J[5]=w*W-v*K,J[6]=G,J[7]=V,J[8]=O,J}function Ld(J,Z,Y){var X=Y[0],F=Y[1];return J[0]=X*Z[0],J[1]=X*Z[1],J[2]=X*Z[2],J[3]=F*Z[3],J[4]=F*Z[4],J[5]=F*Z[5],J[6]=Z[6],J[7]=Z[7],J[8]=Z[8],J}function qd(J,Z){return J[0]=1,J[1]=0,J[2]=0,J[3]=0,J[4]=1,J[5]=0,J[6]=Z[0],J[7]=Z[1],J[8]=1,J}function wd(J,Z){var Y=Math.sin(Z),X=Math.cos(Z);return J[0]=X,J[1]=Y,J[2]=0,J[3]=-Y,J[4]=X,J[5]=0,J[6]=0,J[7]=0,J[8]=1,J}function Hd(J,Z){return J[0]=Z[0],J[1]=0,J[2]=0,J[3]=0,J[4]=Z[1],J[5]=0,J[6]=0,J[7]=0,J[8]=1,J}function Nd(J,Z){return J[0]=Z[0],J[1]=Z[1],J[2]=0,J[3]=Z[2],J[4]=Z[3],J[5]=0,J[6]=Z[4],J[7]=Z[5],J[8]=1,J}function zd(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Y+Y,Q=X+X,W=F+F,G=Y*$,V=X*$,O=X*Q,v=F*$,w=F*Q,H=F*W,N=K*$,q=K*Q,M=K*W;return J[0]=1-O-H,J[3]=V-M,J[6]=v+q,J[1]=V+M,J[4]=1-G-H,J[7]=w-N,J[2]=v-q,J[5]=w+N,J[8]=1-G-O,J}function Md(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Z[4],Q=Z[5],W=Z[6],G=Z[7],V=Z[8],O=Z[9],v=Z[10],w=Z[11],H=Z[12],N=Z[13],q=Z[14],M=Z[15],R=Y*Q-X*$,P=Y*W-F*$,x=Y*G-K*$,j=X*W-F*Q,z=X*G-K*Q,B=F*G-K*W,S=V*N-O*H,E=V*q-v*H,C=V*M-w*H,f=O*q-v*N,p=O*M-w*N,c=v*M-w*q,_=R*c-P*p+x*f+j*C-z*E+B*S;if(!_)return null;return _=1/_,J[0]=(Q*c-W*p+G*f)*_,J[1]=(W*C-$*c-G*E)*_,J[2]=($*p-Q*C+G*S)*_,J[3]=(F*p-X*c-K*f)*_,J[4]=(Y*c-F*C+K*E)*_,J[5]=(X*C-Y*p-K*S)*_,J[6]=(N*B-q*z+M*j)*_,J[7]=(q*x-H*B-M*P)*_,J[8]=(H*z-N*x+M*R)*_,J}function Ud(J,Z,Y){return J[0]=2/Z,J[1]=0,J[2]=0,J[3]=0,J[4]=-2/Y,J[5]=0,J[6]=-1,J[7]=1,J[8]=1,J}function Pd(J){return"mat3("+J[0]+", "+J[1]+", "+J[2]+", "+J[3]+", "+J[4]+", "+J[5]+", "+J[6]+", "+J[7]+", "+J[8]+")"}function Rd(J){return Math.hypot(J[0],J[1],J[2],J[3],J[4],J[5],J[6],J[7],J[8])}function jd(J,Z,Y){return J[0]=Z[0]+Y[0],J[1]=Z[1]+Y[1],J[2]=Z[2]+Y[2],J[3]=Z[3]+Y[3],J[4]=Z[4]+Y[4],J[5]=Z[5]+Y[5],J[6]=Z[6]+Y[6],J[7]=Z[7]+Y[7],J[8]=Z[8]+Y[8],J}function tR(J,Z,Y){return J[0]=Z[0]-Y[0],J[1]=Z[1]-Y[1],J[2]=Z[2]-Y[2],J[3]=Z[3]-Y[3],J[4]=Z[4]-Y[4],J[5]=Z[5]-Y[5],J[6]=Z[6]-Y[6],J[7]=Z[7]-Y[7],J[8]=Z[8]-Y[8],J}function xd(J,Z,Y){return J[0]=Z[0]*Y,J[1]=Z[1]*Y,J[2]=Z[2]*Y,J[3]=Z[3]*Y,J[4]=Z[4]*Y,J[5]=Z[5]*Y,J[6]=Z[6]*Y,J[7]=Z[7]*Y,J[8]=Z[8]*Y,J}function kd(J,Z,Y,X){return J[0]=Z[0]+Y[0]*X,J[1]=Z[1]+Y[1]*X,J[2]=Z[2]+Y[2]*X,J[3]=Z[3]+Y[3]*X,J[4]=Z[4]+Y[4]*X,J[5]=Z[5]+Y[5]*X,J[6]=Z[6]+Y[6]*X,J[7]=Z[7]+Y[7]*X,J[8]=Z[8]+Y[8]*X,J}function Dd(J,Z){return J[0]===Z[0]&&J[1]===Z[1]&&J[2]===Z[2]&&J[3]===Z[3]&&J[4]===Z[4]&&J[5]===Z[5]&&J[6]===Z[6]&&J[7]===Z[7]&&J[8]===Z[8]}function Bd(J,Z){var Y=J[0],X=J[1],F=J[2],K=J[3],$=J[4],Q=J[5],W=J[6],G=J[7],V=J[8],O=Z[0],v=Z[1],w=Z[2],H=Z[3],N=Z[4],q=Z[5],M=Z[6],R=Z[7],P=Z[8];return Math.abs(Y-O)<=i*Math.max(1,Math.abs(Y),Math.abs(O))&&Math.abs(X-v)<=i*Math.max(1,Math.abs(X),Math.abs(v))&&Math.abs(F-w)<=i*Math.max(1,Math.abs(F),Math.abs(w))&&Math.abs(K-H)<=i*Math.max(1,Math.abs(K),Math.abs(H))&&Math.abs($-N)<=i*Math.max(1,Math.abs($),Math.abs(N))&&Math.abs(Q-q)<=i*Math.max(1,Math.abs(Q),Math.abs(q))&&Math.abs(W-M)<=i*Math.max(1,Math.abs(W),Math.abs(M))&&Math.abs(G-R)<=i*Math.max(1,Math.abs(G),Math.abs(R))&&Math.abs(V-P)<=i*Math.max(1,Math.abs(V),Math.abs(P))}var Td=rR,Sd=tR;var J0={};E6(J0,{transpose:()=>Id,translate:()=>bd,targetTo:()=>Vs,subtract:()=>Kj,sub:()=>Ms,str:()=>Os,set:()=>fd,scale:()=>md,rotateZ:()=>yd,rotateY:()=>id,rotateX:()=>Ad,rotate:()=>gd,perspectiveZO:()=>Ks,perspectiveNO:()=>Xj,perspectiveFromFieldOfView:()=>$s,perspective:()=>Fs,orthoZO:()=>Gs,orthoNO:()=>Fj,ortho:()=>Qs,multiplyScalarAndAdd:()=>ws,multiplyScalar:()=>qs,multiply:()=>Jj,mul:()=>zs,lookAt:()=>Ws,invert:()=>hd,identity:()=>eR,getTranslation:()=>td,getScaling:()=>Yj,getRotation:()=>ed,frustum:()=>Xs,fromZRotation:()=>od,fromYRotation:()=>ad,fromXRotation:()=>sd,fromValues:()=>pd,fromTranslation:()=>nd,fromScaling:()=>ud,fromRotationTranslationScaleOrigin:()=>Zs,fromRotationTranslationScale:()=>Js,fromRotationTranslation:()=>Zj,fromRotation:()=>dd,fromQuat2:()=>rd,fromQuat:()=>Ys,frob:()=>vs,exactEquals:()=>Hs,equals:()=>Ns,determinant:()=>ld,create:()=>Ed,copy:()=>_d,clone:()=>Cd,adjoint:()=>cd,add:()=>Ls});function Ed(){var J=new $0(16);if($0!=Float32Array)J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[11]=0,J[12]=0,J[13]=0,J[14]=0;return J[0]=1,J[5]=1,J[10]=1,J[15]=1,J}function Cd(J){var Z=new $0(16);return Z[0]=J[0],Z[1]=J[1],Z[2]=J[2],Z[3]=J[3],Z[4]=J[4],Z[5]=J[5],Z[6]=J[6],Z[7]=J[7],Z[8]=J[8],Z[9]=J[9],Z[10]=J[10],Z[11]=J[11],Z[12]=J[12],Z[13]=J[13],Z[14]=J[14],Z[15]=J[15],Z}function _d(J,Z){return J[0]=Z[0],J[1]=Z[1],J[2]=Z[2],J[3]=Z[3],J[4]=Z[4],J[5]=Z[5],J[6]=Z[6],J[7]=Z[7],J[8]=Z[8],J[9]=Z[9],J[10]=Z[10],J[11]=Z[11],J[12]=Z[12],J[13]=Z[13],J[14]=Z[14],J[15]=Z[15],J}function pd(J,Z,Y,X,F,K,$,Q,W,G,V,O,v,w,H,N){var q=new $0(16);return q[0]=J,q[1]=Z,q[2]=Y,q[3]=X,q[4]=F,q[5]=K,q[6]=$,q[7]=Q,q[8]=W,q[9]=G,q[10]=V,q[11]=O,q[12]=v,q[13]=w,q[14]=H,q[15]=N,q}function fd(J,Z,Y,X,F,K,$,Q,W,G,V,O,v,w,H,N,q){return J[0]=Z,J[1]=Y,J[2]=X,J[3]=F,J[4]=K,J[5]=$,J[6]=Q,J[7]=W,J[8]=G,J[9]=V,J[10]=O,J[11]=v,J[12]=w,J[13]=H,J[14]=N,J[15]=q,J}function eR(J){return J[0]=1,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=1,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=1,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function Id(J,Z){if(J===Z){var Y=Z[1],X=Z[2],F=Z[3],K=Z[6],$=Z[7],Q=Z[11];J[1]=Z[4],J[2]=Z[8],J[3]=Z[12],J[4]=Y,J[6]=Z[9],J[7]=Z[13],J[8]=X,J[9]=K,J[11]=Z[14],J[12]=F,J[13]=$,J[14]=Q}else J[0]=Z[0],J[1]=Z[4],J[2]=Z[8],J[3]=Z[12],J[4]=Z[1],J[5]=Z[5],J[6]=Z[9],J[7]=Z[13],J[8]=Z[2],J[9]=Z[6],J[10]=Z[10],J[11]=Z[14],J[12]=Z[3],J[13]=Z[7],J[14]=Z[11],J[15]=Z[15];return J}function hd(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Z[4],Q=Z[5],W=Z[6],G=Z[7],V=Z[8],O=Z[9],v=Z[10],w=Z[11],H=Z[12],N=Z[13],q=Z[14],M=Z[15],R=Y*Q-X*$,P=Y*W-F*$,x=Y*G-K*$,j=X*W-F*Q,z=X*G-K*Q,B=F*G-K*W,S=V*N-O*H,E=V*q-v*H,C=V*M-w*H,f=O*q-v*N,p=O*M-w*N,c=v*M-w*q,_=R*c-P*p+x*f+j*C-z*E+B*S;if(!_)return null;return _=1/_,J[0]=(Q*c-W*p+G*f)*_,J[1]=(F*p-X*c-K*f)*_,J[2]=(N*B-q*z+M*j)*_,J[3]=(v*z-O*B-w*j)*_,J[4]=(W*C-$*c-G*E)*_,J[5]=(Y*c-F*C+K*E)*_,J[6]=(q*x-H*B-M*P)*_,J[7]=(V*B-v*x+w*P)*_,J[8]=($*p-Q*C+G*S)*_,J[9]=(X*C-Y*p-K*S)*_,J[10]=(H*z-N*x+M*R)*_,J[11]=(O*x-V*z-w*R)*_,J[12]=(Q*E-$*f-W*S)*_,J[13]=(Y*f-X*E+F*S)*_,J[14]=(N*P-H*j-q*R)*_,J[15]=(V*j-O*P+v*R)*_,J}function cd(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Z[4],Q=Z[5],W=Z[6],G=Z[7],V=Z[8],O=Z[9],v=Z[10],w=Z[11],H=Z[12],N=Z[13],q=Z[14],M=Z[15];return J[0]=Q*(v*M-w*q)-O*(W*M-G*q)+N*(W*w-G*v),J[1]=-(X*(v*M-w*q)-O*(F*M-K*q)+N*(F*w-K*v)),J[2]=X*(W*M-G*q)-Q*(F*M-K*q)+N*(F*G-K*W),J[3]=-(X*(W*w-G*v)-Q*(F*w-K*v)+O*(F*G-K*W)),J[4]=-($*(v*M-w*q)-V*(W*M-G*q)+H*(W*w-G*v)),J[5]=Y*(v*M-w*q)-V*(F*M-K*q)+H*(F*w-K*v),J[6]=-(Y*(W*M-G*q)-$*(F*M-K*q)+H*(F*G-K*W)),J[7]=Y*(W*w-G*v)-$*(F*w-K*v)+V*(F*G-K*W),J[8]=$*(O*M-w*N)-V*(Q*M-G*N)+H*(Q*w-G*O),J[9]=-(Y*(O*M-w*N)-V*(X*M-K*N)+H*(X*w-K*O)),J[10]=Y*(Q*M-G*N)-$*(X*M-K*N)+H*(X*G-K*Q),J[11]=-(Y*(Q*w-G*O)-$*(X*w-K*O)+V*(X*G-K*Q)),J[12]=-($*(O*q-v*N)-V*(Q*q-W*N)+H*(Q*v-W*O)),J[13]=Y*(O*q-v*N)-V*(X*q-F*N)+H*(X*v-F*O),J[14]=-(Y*(Q*q-W*N)-$*(X*q-F*N)+H*(X*W-F*Q)),J[15]=Y*(Q*v-W*O)-$*(X*v-F*O)+V*(X*W-F*Q),J}function ld(J){var Z=J[0],Y=J[1],X=J[2],F=J[3],K=J[4],$=J[5],Q=J[6],W=J[7],G=J[8],V=J[9],O=J[10],v=J[11],w=J[12],H=J[13],N=J[14],q=J[15],M=Z*$-Y*K,R=Z*Q-X*K,P=Z*W-F*K,x=Y*Q-X*$,j=Y*W-F*$,z=X*W-F*Q,B=G*H-V*w,S=G*N-O*w,E=G*q-v*w,C=V*N-O*H,f=V*q-v*H,p=O*q-v*N;return M*p-R*f+P*C+x*E-j*S+z*B}function Jj(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Z[4],W=Z[5],G=Z[6],V=Z[7],O=Z[8],v=Z[9],w=Z[10],H=Z[11],N=Z[12],q=Z[13],M=Z[14],R=Z[15],P=Y[0],x=Y[1],j=Y[2],z=Y[3];return J[0]=P*X+x*Q+j*O+z*N,J[1]=P*F+x*W+j*v+z*q,J[2]=P*K+x*G+j*w+z*M,J[3]=P*$+x*V+j*H+z*R,P=Y[4],x=Y[5],j=Y[6],z=Y[7],J[4]=P*X+x*Q+j*O+z*N,J[5]=P*F+x*W+j*v+z*q,J[6]=P*K+x*G+j*w+z*M,J[7]=P*$+x*V+j*H+z*R,P=Y[8],x=Y[9],j=Y[10],z=Y[11],J[8]=P*X+x*Q+j*O+z*N,J[9]=P*F+x*W+j*v+z*q,J[10]=P*K+x*G+j*w+z*M,J[11]=P*$+x*V+j*H+z*R,P=Y[12],x=Y[13],j=Y[14],z=Y[15],J[12]=P*X+x*Q+j*O+z*N,J[13]=P*F+x*W+j*v+z*q,J[14]=P*K+x*G+j*w+z*M,J[15]=P*$+x*V+j*H+z*R,J}function bd(J,Z,Y){var X=Y[0],F=Y[1],K=Y[2],$,Q,W,G,V,O,v,w,H,N,q,M;if(Z===J)J[12]=Z[0]*X+Z[4]*F+Z[8]*K+Z[12],J[13]=Z[1]*X+Z[5]*F+Z[9]*K+Z[13],J[14]=Z[2]*X+Z[6]*F+Z[10]*K+Z[14],J[15]=Z[3]*X+Z[7]*F+Z[11]*K+Z[15];else $=Z[0],Q=Z[1],W=Z[2],G=Z[3],V=Z[4],O=Z[5],v=Z[6],w=Z[7],H=Z[8],N=Z[9],q=Z[10],M=Z[11],J[0]=$,J[1]=Q,J[2]=W,J[3]=G,J[4]=V,J[5]=O,J[6]=v,J[7]=w,J[8]=H,J[9]=N,J[10]=q,J[11]=M,J[12]=$*X+V*F+H*K+Z[12],J[13]=Q*X+O*F+N*K+Z[13],J[14]=W*X+v*F+q*K+Z[14],J[15]=G*X+w*F+M*K+Z[15];return J}function md(J,Z,Y){var X=Y[0],F=Y[1],K=Y[2];return J[0]=Z[0]*X,J[1]=Z[1]*X,J[2]=Z[2]*X,J[3]=Z[3]*X,J[4]=Z[4]*F,J[5]=Z[5]*F,J[6]=Z[6]*F,J[7]=Z[7]*F,J[8]=Z[8]*K,J[9]=Z[9]*K,J[10]=Z[10]*K,J[11]=Z[11]*K,J[12]=Z[12],J[13]=Z[13],J[14]=Z[14],J[15]=Z[15],J}function gd(J,Z,Y,X){var F=X[0],K=X[1],$=X[2],Q=Math.hypot(F,K,$),W,G,V,O,v,w,H,N,q,M,R,P,x,j,z,B,S,E,C,f,p,c,_,b;if(Q<i)return null;if(Q=1/Q,F*=Q,K*=Q,$*=Q,W=Math.sin(Y),G=Math.cos(Y),V=1-G,O=Z[0],v=Z[1],w=Z[2],H=Z[3],N=Z[4],q=Z[5],M=Z[6],R=Z[7],P=Z[8],x=Z[9],j=Z[10],z=Z[11],B=F*F*V+G,S=K*F*V+$*W,E=$*F*V-K*W,C=F*K*V-$*W,f=K*K*V+G,p=$*K*V+F*W,c=F*$*V+K*W,_=K*$*V-F*W,b=$*$*V+G,J[0]=O*B+N*S+P*E,J[1]=v*B+q*S+x*E,J[2]=w*B+M*S+j*E,J[3]=H*B+R*S+z*E,J[4]=O*C+N*f+P*p,J[5]=v*C+q*f+x*p,J[6]=w*C+M*f+j*p,J[7]=H*C+R*f+z*p,J[8]=O*c+N*_+P*b,J[9]=v*c+q*_+x*b,J[10]=w*c+M*_+j*b,J[11]=H*c+R*_+z*b,Z!==J)J[12]=Z[12],J[13]=Z[13],J[14]=Z[14],J[15]=Z[15];return J}function Ad(J,Z,Y){var X=Math.sin(Y),F=Math.cos(Y),K=Z[4],$=Z[5],Q=Z[6],W=Z[7],G=Z[8],V=Z[9],O=Z[10],v=Z[11];if(Z!==J)J[0]=Z[0],J[1]=Z[1],J[2]=Z[2],J[3]=Z[3],J[12]=Z[12],J[13]=Z[13],J[14]=Z[14],J[15]=Z[15];return J[4]=K*F+G*X,J[5]=$*F+V*X,J[6]=Q*F+O*X,J[7]=W*F+v*X,J[8]=G*F-K*X,J[9]=V*F-$*X,J[10]=O*F-Q*X,J[11]=v*F-W*X,J}function id(J,Z,Y){var X=Math.sin(Y),F=Math.cos(Y),K=Z[0],$=Z[1],Q=Z[2],W=Z[3],G=Z[8],V=Z[9],O=Z[10],v=Z[11];if(Z!==J)J[4]=Z[4],J[5]=Z[5],J[6]=Z[6],J[7]=Z[7],J[12]=Z[12],J[13]=Z[13],J[14]=Z[14],J[15]=Z[15];return J[0]=K*F-G*X,J[1]=$*F-V*X,J[2]=Q*F-O*X,J[3]=W*F-v*X,J[8]=K*X+G*F,J[9]=$*X+V*F,J[10]=Q*X+O*F,J[11]=W*X+v*F,J}function yd(J,Z,Y){var X=Math.sin(Y),F=Math.cos(Y),K=Z[0],$=Z[1],Q=Z[2],W=Z[3],G=Z[4],V=Z[5],O=Z[6],v=Z[7];if(Z!==J)J[8]=Z[8],J[9]=Z[9],J[10]=Z[10],J[11]=Z[11],J[12]=Z[12],J[13]=Z[13],J[14]=Z[14],J[15]=Z[15];return J[0]=K*F+G*X,J[1]=$*F+V*X,J[2]=Q*F+O*X,J[3]=W*F+v*X,J[4]=G*F-K*X,J[5]=V*F-$*X,J[6]=O*F-Q*X,J[7]=v*F-W*X,J}function nd(J,Z){return J[0]=1,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=1,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=1,J[11]=0,J[12]=Z[0],J[13]=Z[1],J[14]=Z[2],J[15]=1,J}function ud(J,Z){return J[0]=Z[0],J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=Z[1],J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=Z[2],J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function dd(J,Z,Y){var X=Y[0],F=Y[1],K=Y[2],$=Math.hypot(X,F,K),Q,W,G;if($<i)return null;return $=1/$,X*=$,F*=$,K*=$,Q=Math.sin(Z),W=Math.cos(Z),G=1-W,J[0]=X*X*G+W,J[1]=F*X*G+K*Q,J[2]=K*X*G-F*Q,J[3]=0,J[4]=X*F*G-K*Q,J[5]=F*F*G+W,J[6]=K*F*G+X*Q,J[7]=0,J[8]=X*K*G+F*Q,J[9]=F*K*G-X*Q,J[10]=K*K*G+W,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function sd(J,Z){var Y=Math.sin(Z),X=Math.cos(Z);return J[0]=1,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=X,J[6]=Y,J[7]=0,J[8]=0,J[9]=-Y,J[10]=X,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function ad(J,Z){var Y=Math.sin(Z),X=Math.cos(Z);return J[0]=X,J[1]=0,J[2]=-Y,J[3]=0,J[4]=0,J[5]=1,J[6]=0,J[7]=0,J[8]=Y,J[9]=0,J[10]=X,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function od(J,Z){var Y=Math.sin(Z),X=Math.cos(Z);return J[0]=X,J[1]=Y,J[2]=0,J[3]=0,J[4]=-Y,J[5]=X,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=1,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function Zj(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=X+X,W=F+F,G=K+K,V=X*Q,O=X*W,v=X*G,w=F*W,H=F*G,N=K*G,q=$*Q,M=$*W,R=$*G;return J[0]=1-(w+N),J[1]=O+R,J[2]=v-M,J[3]=0,J[4]=O-R,J[5]=1-(V+N),J[6]=H+q,J[7]=0,J[8]=v+M,J[9]=H-q,J[10]=1-(V+w),J[11]=0,J[12]=Y[0],J[13]=Y[1],J[14]=Y[2],J[15]=1,J}function rd(J,Z){var Y=new $0(3),X=-Z[0],F=-Z[1],K=-Z[2],$=Z[3],Q=Z[4],W=Z[5],G=Z[6],V=Z[7],O=X*X+F*F+K*K+$*$;if(O>0)Y[0]=(Q*$+V*X+W*K-G*F)*2/O,Y[1]=(W*$+V*F+G*X-Q*K)*2/O,Y[2]=(G*$+V*K+Q*F-W*X)*2/O;else Y[0]=(Q*$+V*X+W*K-G*F)*2,Y[1]=(W*$+V*F+G*X-Q*K)*2,Y[2]=(G*$+V*K+Q*F-W*X)*2;return Zj(J,Z,Y),J}function td(J,Z){return J[0]=Z[12],J[1]=Z[13],J[2]=Z[14],J}function Yj(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[4],$=Z[5],Q=Z[6],W=Z[8],G=Z[9],V=Z[10];return J[0]=Math.hypot(Y,X,F),J[1]=Math.hypot(K,$,Q),J[2]=Math.hypot(W,G,V),J}function ed(J,Z){var Y=new $0(3);Yj(Y,Z);var X=1/Y[0],F=1/Y[1],K=1/Y[2],$=Z[0]*X,Q=Z[1]*F,W=Z[2]*K,G=Z[4]*X,V=Z[5]*F,O=Z[6]*K,v=Z[8]*X,w=Z[9]*F,H=Z[10]*K,N=$+V+H,q=0;if(N>0)q=Math.sqrt(N+1)*2,J[3]=0.25*q,J[0]=(O-w)/q,J[1]=(v-W)/q,J[2]=(Q-G)/q;else if($>V&&$>H)q=Math.sqrt(1+$-V-H)*2,J[3]=(O-w)/q,J[0]=0.25*q,J[1]=(Q+G)/q,J[2]=(v+W)/q;else if(V>H)q=Math.sqrt(1+V-$-H)*2,J[3]=(v-W)/q,J[0]=(Q+G)/q,J[1]=0.25*q,J[2]=(O+w)/q;else q=Math.sqrt(1+H-$-V)*2,J[3]=(Q-G)/q,J[0]=(v+W)/q,J[1]=(O+w)/q,J[2]=0.25*q;return J}function Js(J,Z,Y,X){var F=Z[0],K=Z[1],$=Z[2],Q=Z[3],W=F+F,G=K+K,V=$+$,O=F*W,v=F*G,w=F*V,H=K*G,N=K*V,q=$*V,M=Q*W,R=Q*G,P=Q*V,x=X[0],j=X[1],z=X[2];return J[0]=(1-(H+q))*x,J[1]=(v+P)*x,J[2]=(w-R)*x,J[3]=0,J[4]=(v-P)*j,J[5]=(1-(O+q))*j,J[6]=(N+M)*j,J[7]=0,J[8]=(w+R)*z,J[9]=(N-M)*z,J[10]=(1-(O+H))*z,J[11]=0,J[12]=Y[0],J[13]=Y[1],J[14]=Y[2],J[15]=1,J}function Zs(J,Z,Y,X,F){var K=Z[0],$=Z[1],Q=Z[2],W=Z[3],G=K+K,V=$+$,O=Q+Q,v=K*G,w=K*V,H=K*O,N=$*V,q=$*O,M=Q*O,R=W*G,P=W*V,x=W*O,j=X[0],z=X[1],B=X[2],S=F[0],E=F[1],C=F[2],f=(1-(N+M))*j,p=(w+x)*j,c=(H-P)*j,_=(w-x)*z,b=(1-(v+M))*z,r=(q+R)*z,c0=(H+P)*B,u0=(q-R)*B,t8=(1-(v+N))*B;return J[0]=f,J[1]=p,J[2]=c,J[3]=0,J[4]=_,J[5]=b,J[6]=r,J[7]=0,J[8]=c0,J[9]=u0,J[10]=t8,J[11]=0,J[12]=Y[0]+S-(f*S+_*E+c0*C),J[13]=Y[1]+E-(p*S+b*E+u0*C),J[14]=Y[2]+C-(c*S+r*E+t8*C),J[15]=1,J}function Ys(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Y+Y,Q=X+X,W=F+F,G=Y*$,V=X*$,O=X*Q,v=F*$,w=F*Q,H=F*W,N=K*$,q=K*Q,M=K*W;return J[0]=1-O-H,J[1]=V+M,J[2]=v-q,J[3]=0,J[4]=V-M,J[5]=1-G-H,J[6]=w+N,J[7]=0,J[8]=v+q,J[9]=w-N,J[10]=1-G-O,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function Xs(J,Z,Y,X,F,K,$){var Q=1/(Y-Z),W=1/(F-X),G=1/(K-$);return J[0]=K*2*Q,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=K*2*W,J[6]=0,J[7]=0,J[8]=(Y+Z)*Q,J[9]=(F+X)*W,J[10]=($+K)*G,J[11]=-1,J[12]=0,J[13]=0,J[14]=$*K*2*G,J[15]=0,J}function Xj(J,Z,Y,X,F){var K=1/Math.tan(Z/2),$;if(J[0]=K/Y,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=K,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[11]=-1,J[12]=0,J[13]=0,J[15]=0,F!=null&&F!==1/0)$=1/(X-F),J[10]=(F+X)*$,J[14]=2*F*X*$;else J[10]=-1,J[14]=-2*X;return J}var Fs=Xj;function Ks(J,Z,Y,X,F){var K=1/Math.tan(Z/2),$;if(J[0]=K/Y,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=K,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[11]=-1,J[12]=0,J[13]=0,J[15]=0,F!=null&&F!==1/0)$=1/(X-F),J[10]=F*$,J[14]=F*X*$;else J[10]=-1,J[14]=-X;return J}function $s(J,Z,Y,X){var F=Math.tan(Z.upDegrees*Math.PI/180),K=Math.tan(Z.downDegrees*Math.PI/180),$=Math.tan(Z.leftDegrees*Math.PI/180),Q=Math.tan(Z.rightDegrees*Math.PI/180),W=2/($+Q),G=2/(F+K);return J[0]=W,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=G,J[6]=0,J[7]=0,J[8]=-(($-Q)*W*0.5),J[9]=(F-K)*G*0.5,J[10]=X/(Y-X),J[11]=-1,J[12]=0,J[13]=0,J[14]=X*Y/(Y-X),J[15]=0,J}function Fj(J,Z,Y,X,F,K,$){var Q=1/(Z-Y),W=1/(X-F),G=1/(K-$);return J[0]=-2*Q,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=-2*W,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=2*G,J[11]=0,J[12]=(Z+Y)*Q,J[13]=(F+X)*W,J[14]=($+K)*G,J[15]=1,J}var Qs=Fj;function Gs(J,Z,Y,X,F,K,$){var Q=1/(Z-Y),W=1/(X-F),G=1/(K-$);return J[0]=-2*Q,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=-2*W,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=G,J[11]=0,J[12]=(Z+Y)*Q,J[13]=(F+X)*W,J[14]=K*G,J[15]=1,J}function Ws(J,Z,Y,X){var F,K,$,Q,W,G,V,O,v,w,H=Z[0],N=Z[1],q=Z[2],M=X[0],R=X[1],P=X[2],x=Y[0],j=Y[1],z=Y[2];if(Math.abs(H-x)<i&&Math.abs(N-j)<i&&Math.abs(q-z)<i)return eR(J);if(V=H-x,O=N-j,v=q-z,w=1/Math.hypot(V,O,v),V*=w,O*=w,v*=w,F=R*v-P*O,K=P*V-M*v,$=M*O-R*V,w=Math.hypot(F,K,$),!w)F=0,K=0,$=0;else w=1/w,F*=w,K*=w,$*=w;if(Q=O*$-v*K,W=v*F-V*$,G=V*K-O*F,w=Math.hypot(Q,W,G),!w)Q=0,W=0,G=0;else w=1/w,Q*=w,W*=w,G*=w;return J[0]=F,J[1]=Q,J[2]=V,J[3]=0,J[4]=K,J[5]=W,J[6]=O,J[7]=0,J[8]=$,J[9]=G,J[10]=v,J[11]=0,J[12]=-(F*H+K*N+$*q),J[13]=-(Q*H+W*N+G*q),J[14]=-(V*H+O*N+v*q),J[15]=1,J}function Vs(J,Z,Y,X){var F=Z[0],K=Z[1],$=Z[2],Q=X[0],W=X[1],G=X[2],V=F-Y[0],O=K-Y[1],v=$-Y[2],w=V*V+O*O+v*v;if(w>0)w=1/Math.sqrt(w),V*=w,O*=w,v*=w;var H=W*v-G*O,N=G*V-Q*v,q=Q*O-W*V;if(w=H*H+N*N+q*q,w>0)w=1/Math.sqrt(w),H*=w,N*=w,q*=w;return J[0]=H,J[1]=N,J[2]=q,J[3]=0,J[4]=O*q-v*N,J[5]=v*H-V*q,J[6]=V*N-O*H,J[7]=0,J[8]=V,J[9]=O,J[10]=v,J[11]=0,J[12]=F,J[13]=K,J[14]=$,J[15]=1,J}function Os(J){return"mat4("+J[0]+", "+J[1]+", "+J[2]+", "+J[3]+", "+J[4]+", "+J[5]+", "+J[6]+", "+J[7]+", "+J[8]+", "+J[9]+", "+J[10]+", "+J[11]+", "+J[12]+", "+J[13]+", "+J[14]+", "+J[15]+")"}function vs(J){return Math.hypot(J[0],J[1],J[2],J[3],J[4],J[5],J[6],J[7],J[8],J[9],J[10],J[11],J[12],J[13],J[14],J[15])}function Ls(J,Z,Y){return J[0]=Z[0]+Y[0],J[1]=Z[1]+Y[1],J[2]=Z[2]+Y[2],J[3]=Z[3]+Y[3],J[4]=Z[4]+Y[4],J[5]=Z[5]+Y[5],J[6]=Z[6]+Y[6],J[7]=Z[7]+Y[7],J[8]=Z[8]+Y[8],J[9]=Z[9]+Y[9],J[10]=Z[10]+Y[10],J[11]=Z[11]+Y[11],J[12]=Z[12]+Y[12],J[13]=Z[13]+Y[13],J[14]=Z[14]+Y[14],J[15]=Z[15]+Y[15],J}function Kj(J,Z,Y){return J[0]=Z[0]-Y[0],J[1]=Z[1]-Y[1],J[2]=Z[2]-Y[2],J[3]=Z[3]-Y[3],J[4]=Z[4]-Y[4],J[5]=Z[5]-Y[5],J[6]=Z[6]-Y[6],J[7]=Z[7]-Y[7],J[8]=Z[8]-Y[8],J[9]=Z[9]-Y[9],J[10]=Z[10]-Y[10],J[11]=Z[11]-Y[11],J[12]=Z[12]-Y[12],J[13]=Z[13]-Y[13],J[14]=Z[14]-Y[14],J[15]=Z[15]-Y[15],J}function qs(J,Z,Y){return J[0]=Z[0]*Y,J[1]=Z[1]*Y,J[2]=Z[2]*Y,J[3]=Z[3]*Y,J[4]=Z[4]*Y,J[5]=Z[5]*Y,J[6]=Z[6]*Y,J[7]=Z[7]*Y,J[8]=Z[8]*Y,J[9]=Z[9]*Y,J[10]=Z[10]*Y,J[11]=Z[11]*Y,J[12]=Z[12]*Y,J[13]=Z[13]*Y,J[14]=Z[14]*Y,J[15]=Z[15]*Y,J}function ws(J,Z,Y,X){return J[0]=Z[0]+Y[0]*X,J[1]=Z[1]+Y[1]*X,J[2]=Z[2]+Y[2]*X,J[3]=Z[3]+Y[3]*X,J[4]=Z[4]+Y[4]*X,J[5]=Z[5]+Y[5]*X,J[6]=Z[6]+Y[6]*X,J[7]=Z[7]+Y[7]*X,J[8]=Z[8]+Y[8]*X,J[9]=Z[9]+Y[9]*X,J[10]=Z[10]+Y[10]*X,J[11]=Z[11]+Y[11]*X,J[12]=Z[12]+Y[12]*X,J[13]=Z[13]+Y[13]*X,J[14]=Z[14]+Y[14]*X,J[15]=Z[15]+Y[15]*X,J}function Hs(J,Z){return J[0]===Z[0]&&J[1]===Z[1]&&J[2]===Z[2]&&J[3]===Z[3]&&J[4]===Z[4]&&J[5]===Z[5]&&J[6]===Z[6]&&J[7]===Z[7]&&J[8]===Z[8]&&J[9]===Z[9]&&J[10]===Z[10]&&J[11]===Z[11]&&J[12]===Z[12]&&J[13]===Z[13]&&J[14]===Z[14]&&J[15]===Z[15]}function Ns(J,Z){var Y=J[0],X=J[1],F=J[2],K=J[3],$=J[4],Q=J[5],W=J[6],G=J[7],V=J[8],O=J[9],v=J[10],w=J[11],H=J[12],N=J[13],q=J[14],M=J[15],R=Z[0],P=Z[1],x=Z[2],j=Z[3],z=Z[4],B=Z[5],S=Z[6],E=Z[7],C=Z[8],f=Z[9],p=Z[10],c=Z[11],_=Z[12],b=Z[13],r=Z[14],c0=Z[15];return Math.abs(Y-R)<=i*Math.max(1,Math.abs(Y),Math.abs(R))&&Math.abs(X-P)<=i*Math.max(1,Math.abs(X),Math.abs(P))&&Math.abs(F-x)<=i*Math.max(1,Math.abs(F),Math.abs(x))&&Math.abs(K-j)<=i*Math.max(1,Math.abs(K),Math.abs(j))&&Math.abs($-z)<=i*Math.max(1,Math.abs($),Math.abs(z))&&Math.abs(Q-B)<=i*Math.max(1,Math.abs(Q),Math.abs(B))&&Math.abs(W-S)<=i*Math.max(1,Math.abs(W),Math.abs(S))&&Math.abs(G-E)<=i*Math.max(1,Math.abs(G),Math.abs(E))&&Math.abs(V-C)<=i*Math.max(1,Math.abs(V),Math.abs(C))&&Math.abs(O-f)<=i*Math.max(1,Math.abs(O),Math.abs(f))&&Math.abs(v-p)<=i*Math.max(1,Math.abs(v),Math.abs(p))&&Math.abs(w-c)<=i*Math.max(1,Math.abs(w),Math.abs(c))&&Math.abs(H-_)<=i*Math.max(1,Math.abs(H),Math.abs(_))&&Math.abs(N-b)<=i*Math.max(1,Math.abs(N),Math.abs(b))&&Math.abs(q-r)<=i*Math.max(1,Math.abs(q),Math.abs(r))&&Math.abs(M-c0)<=i*Math.max(1,Math.abs(M),Math.abs(c0))}var zs=Jj,Ms=Kj;var R0={};E6(R0,{str:()=>wa,squaredLength:()=>fj,sqrLen:()=>xa,sqlerp:()=>Ta,slerp:()=>cY,setAxisAngle:()=>Dj,setAxes:()=>Sa,set:()=>Ma,scale:()=>Cj,rotationTo:()=>Ba,rotateZ:()=>Ga,rotateY:()=>Qa,rotateX:()=>$a,random:()=>Oa,pow:()=>Va,normalize:()=>KG,multiply:()=>Bj,mul:()=>Pa,ln:()=>Sj,lerp:()=>Ra,length:()=>pj,len:()=>ja,invert:()=>va,identity:()=>Xa,getAxisAngle:()=>Fa,getAngle:()=>Ka,fromValues:()=>Na,fromMat3:()=>Ej,fromEuler:()=>qa,exp:()=>Tj,exactEquals:()=>ka,equals:()=>Da,dot:()=>_j,create:()=>FG,copy:()=>za,conjugate:()=>La,clone:()=>Ha,calculateW:()=>Wa,add:()=>Ua});var Y0={};E6(Y0,{zero:()=>ys,transformQuat:()=>bs,transformMat4:()=>cs,transformMat3:()=>ls,subtract:()=>Qj,sub:()=>ss,str:()=>ns,squaredLength:()=>vj,squaredDistance:()=>Oj,sqrLen:()=>es,sqrDist:()=>ts,set:()=>Rs,scaleAndAdd:()=>Es,scale:()=>Ss,round:()=>Ts,rotateZ:()=>As,rotateY:()=>gs,rotateX:()=>ms,random:()=>hs,normalize:()=>YG,negate:()=>Cs,multiply:()=>Gj,mul:()=>as,min:()=>Ds,max:()=>Bs,lerp:()=>ps,length:()=>$j,len:()=>XG,inverse:()=>_s,hermite:()=>fs,fromValues:()=>IY,forEach:()=>Ja,floor:()=>ks,exactEquals:()=>us,equals:()=>ds,dot:()=>hY,divide:()=>Wj,div:()=>os,distance:()=>Vj,dist:()=>rs,cross:()=>w7,create:()=>fY,copy:()=>Ps,clone:()=>Us,ceil:()=>xs,bezier:()=>Is,angle:()=>is,add:()=>js});function fY(){var J=new $0(3);if($0!=Float32Array)J[0]=0,J[1]=0,J[2]=0;return J}function Us(J){var Z=new $0(3);return Z[0]=J[0],Z[1]=J[1],Z[2]=J[2],Z}function $j(J){var Z=J[0],Y=J[1],X=J[2];return Math.hypot(Z,Y,X)}function IY(J,Z,Y){var X=new $0(3);return X[0]=J,X[1]=Z,X[2]=Y,X}function Ps(J,Z){return J[0]=Z[0],J[1]=Z[1],J[2]=Z[2],J}function Rs(J,Z,Y,X){return J[0]=Z,J[1]=Y,J[2]=X,J}function js(J,Z,Y){return J[0]=Z[0]+Y[0],J[1]=Z[1]+Y[1],J[2]=Z[2]+Y[2],J}function Qj(J,Z,Y){return J[0]=Z[0]-Y[0],J[1]=Z[1]-Y[1],J[2]=Z[2]-Y[2],J}function Gj(J,Z,Y){return J[0]=Z[0]*Y[0],J[1]=Z[1]*Y[1],J[2]=Z[2]*Y[2],J}function Wj(J,Z,Y){return J[0]=Z[0]/Y[0],J[1]=Z[1]/Y[1],J[2]=Z[2]/Y[2],J}function xs(J,Z){return J[0]=Math.ceil(Z[0]),J[1]=Math.ceil(Z[1]),J[2]=Math.ceil(Z[2]),J}function ks(J,Z){return J[0]=Math.floor(Z[0]),J[1]=Math.floor(Z[1]),J[2]=Math.floor(Z[2]),J}function Ds(J,Z,Y){return J[0]=Math.min(Z[0],Y[0]),J[1]=Math.min(Z[1],Y[1]),J[2]=Math.min(Z[2],Y[2]),J}function Bs(J,Z,Y){return J[0]=Math.max(Z[0],Y[0]),J[1]=Math.max(Z[1],Y[1]),J[2]=Math.max(Z[2],Y[2]),J}function Ts(J,Z){return J[0]=Math.round(Z[0]),J[1]=Math.round(Z[1]),J[2]=Math.round(Z[2]),J}function Ss(J,Z,Y){return J[0]=Z[0]*Y,J[1]=Z[1]*Y,J[2]=Z[2]*Y,J}function Es(J,Z,Y,X){return J[0]=Z[0]+Y[0]*X,J[1]=Z[1]+Y[1]*X,J[2]=Z[2]+Y[2]*X,J}function Vj(J,Z){var Y=Z[0]-J[0],X=Z[1]-J[1],F=Z[2]-J[2];return Math.hypot(Y,X,F)}function Oj(J,Z){var Y=Z[0]-J[0],X=Z[1]-J[1],F=Z[2]-J[2];return Y*Y+X*X+F*F}function vj(J){var Z=J[0],Y=J[1],X=J[2];return Z*Z+Y*Y+X*X}function Cs(J,Z){return J[0]=-Z[0],J[1]=-Z[1],J[2]=-Z[2],J}function _s(J,Z){return J[0]=1/Z[0],J[1]=1/Z[1],J[2]=1/Z[2],J}function YG(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Y*Y+X*X+F*F;if(K>0)K=1/Math.sqrt(K);return J[0]=Z[0]*K,J[1]=Z[1]*K,J[2]=Z[2]*K,J}function hY(J,Z){return J[0]*Z[0]+J[1]*Z[1]+J[2]*Z[2]}function w7(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Y[0],Q=Y[1],W=Y[2];return J[0]=F*W-K*Q,J[1]=K*$-X*W,J[2]=X*Q-F*$,J}function ps(J,Z,Y,X){var F=Z[0],K=Z[1],$=Z[2];return J[0]=F+X*(Y[0]-F),J[1]=K+X*(Y[1]-K),J[2]=$+X*(Y[2]-$),J}function fs(J,Z,Y,X,F,K){var $=K*K,Q=$*(2*K-3)+1,W=$*(K-2)+K,G=$*(K-1),V=$*(3-2*K);return J[0]=Z[0]*Q+Y[0]*W+X[0]*G+F[0]*V,J[1]=Z[1]*Q+Y[1]*W+X[1]*G+F[1]*V,J[2]=Z[2]*Q+Y[2]*W+X[2]*G+F[2]*V,J}function Is(J,Z,Y,X,F,K){var $=1-K,Q=$*$,W=K*K,G=Q*$,V=3*K*Q,O=3*W*$,v=W*K;return J[0]=Z[0]*G+Y[0]*V+X[0]*O+F[0]*v,J[1]=Z[1]*G+Y[1]*V+X[1]*O+F[1]*v,J[2]=Z[2]*G+Y[2]*V+X[2]*O+F[2]*v,J}function hs(J,Z){Z=Z||1;var Y=B6()*2*Math.PI,X=B6()*2-1,F=Math.sqrt(1-X*X)*Z;return J[0]=Math.cos(Y)*F,J[1]=Math.sin(Y)*F,J[2]=X*Z,J}function cs(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Y[3]*X+Y[7]*F+Y[11]*K+Y[15];return $=$||1,J[0]=(Y[0]*X+Y[4]*F+Y[8]*K+Y[12])/$,J[1]=(Y[1]*X+Y[5]*F+Y[9]*K+Y[13])/$,J[2]=(Y[2]*X+Y[6]*F+Y[10]*K+Y[14])/$,J}function ls(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2];return J[0]=X*Y[0]+F*Y[3]+K*Y[6],J[1]=X*Y[1]+F*Y[4]+K*Y[7],J[2]=X*Y[2]+F*Y[5]+K*Y[8],J}function bs(J,Z,Y){var X=Y[0],F=Y[1],K=Y[2],$=Y[3],Q=Z[0],W=Z[1],G=Z[2],V=F*G-K*W,O=K*Q-X*G,v=X*W-F*Q,w=F*v-K*O,H=K*V-X*v,N=X*O-F*V,q=$*2;return V*=q,O*=q,v*=q,w*=2,H*=2,N*=2,J[0]=Q+V+w,J[1]=W+O+H,J[2]=G+v+N,J}function ms(J,Z,Y,X){var F=[],K=[];return F[0]=Z[0]-Y[0],F[1]=Z[1]-Y[1],F[2]=Z[2]-Y[2],K[0]=F[0],K[1]=F[1]*Math.cos(X)-F[2]*Math.sin(X),K[2]=F[1]*Math.sin(X)+F[2]*Math.cos(X),J[0]=K[0]+Y[0],J[1]=K[1]+Y[1],J[2]=K[2]+Y[2],J}function gs(J,Z,Y,X){var F=[],K=[];return F[0]=Z[0]-Y[0],F[1]=Z[1]-Y[1],F[2]=Z[2]-Y[2],K[0]=F[2]*Math.sin(X)+F[0]*Math.cos(X),K[1]=F[1],K[2]=F[2]*Math.cos(X)-F[0]*Math.sin(X),J[0]=K[0]+Y[0],J[1]=K[1]+Y[1],J[2]=K[2]+Y[2],J}function As(J,Z,Y,X){var F=[],K=[];return F[0]=Z[0]-Y[0],F[1]=Z[1]-Y[1],F[2]=Z[2]-Y[2],K[0]=F[0]*Math.cos(X)-F[1]*Math.sin(X),K[1]=F[0]*Math.sin(X)+F[1]*Math.cos(X),K[2]=F[2],J[0]=K[0]+Y[0],J[1]=K[1]+Y[1],J[2]=K[2]+Y[2],J}function is(J,Z){var Y=J[0],X=J[1],F=J[2],K=Z[0],$=Z[1],Q=Z[2],W=Math.sqrt(Y*Y+X*X+F*F),G=Math.sqrt(K*K+$*$+Q*Q),V=W*G,O=V&&hY(J,Z)/V;return Math.acos(Math.min(Math.max(O,-1),1))}function ys(J){return J[0]=0,J[1]=0,J[2]=0,J}function ns(J){return"vec3("+J[0]+", "+J[1]+", "+J[2]+")"}function us(J,Z){return J[0]===Z[0]&&J[1]===Z[1]&&J[2]===Z[2]}function ds(J,Z){var Y=J[0],X=J[1],F=J[2],K=Z[0],$=Z[1],Q=Z[2];return Math.abs(Y-K)<=i*Math.max(1,Math.abs(Y),Math.abs(K))&&Math.abs(X-$)<=i*Math.max(1,Math.abs(X),Math.abs($))&&Math.abs(F-Q)<=i*Math.max(1,Math.abs(F),Math.abs(Q))}var ss=Qj,as=Gj,os=Wj,rs=Vj,ts=Oj,XG=$j,es=vj,Ja=function(){var J=fY();return function(Z,Y,X,F,K,$){var Q,W;if(!Y)Y=3;if(!X)X=0;if(F)W=Math.min(F*Y+X,Z.length);else W=Z.length;for(Q=X;Q<W;Q+=Y)J[0]=Z[Q],J[1]=Z[Q+1],J[2]=Z[Q+2],K(J,J,$),Z[Q]=J[0],Z[Q+1]=J[1],Z[Q+2]=J[2];return Z}}();function Za(){var J=new $0(4);if($0!=Float32Array)J[0]=0,J[1]=0,J[2]=0,J[3]=0;return J}function Lj(J){var Z=new $0(4);return Z[0]=J[0],Z[1]=J[1],Z[2]=J[2],Z[3]=J[3],Z}function qj(J,Z,Y,X){var F=new $0(4);return F[0]=J,F[1]=Z,F[2]=Y,F[3]=X,F}function wj(J,Z){return J[0]=Z[0],J[1]=Z[1],J[2]=Z[2],J[3]=Z[3],J}function Hj(J,Z,Y,X,F){return J[0]=Z,J[1]=Y,J[2]=X,J[3]=F,J}function Nj(J,Z,Y){return J[0]=Z[0]+Y[0],J[1]=Z[1]+Y[1],J[2]=Z[2]+Y[2],J[3]=Z[3]+Y[3],J}function zj(J,Z,Y){return J[0]=Z[0]*Y,J[1]=Z[1]*Y,J[2]=Z[2]*Y,J[3]=Z[3]*Y,J}function Mj(J){var Z=J[0],Y=J[1],X=J[2],F=J[3];return Math.hypot(Z,Y,X,F)}function Uj(J){var Z=J[0],Y=J[1],X=J[2],F=J[3];return Z*Z+Y*Y+X*X+F*F}function Pj(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Y*Y+X*X+F*F+K*K;if($>0)$=1/Math.sqrt($);return J[0]=Y*$,J[1]=X*$,J[2]=F*$,J[3]=K*$,J}function Rj(J,Z){return J[0]*Z[0]+J[1]*Z[1]+J[2]*Z[2]+J[3]*Z[3]}function jj(J,Z,Y,X){var F=Z[0],K=Z[1],$=Z[2],Q=Z[3];return J[0]=F+X*(Y[0]-F),J[1]=K+X*(Y[1]-K),J[2]=$+X*(Y[2]-$),J[3]=Q+X*(Y[3]-Q),J}function xj(J,Z){return J[0]===Z[0]&&J[1]===Z[1]&&J[2]===Z[2]&&J[3]===Z[3]}function kj(J,Z){var Y=J[0],X=J[1],F=J[2],K=J[3],$=Z[0],Q=Z[1],W=Z[2],G=Z[3];return Math.abs(Y-$)<=i*Math.max(1,Math.abs(Y),Math.abs($))&&Math.abs(X-Q)<=i*Math.max(1,Math.abs(X),Math.abs(Q))&&Math.abs(F-W)<=i*Math.max(1,Math.abs(F),Math.abs(W))&&Math.abs(K-G)<=i*Math.max(1,Math.abs(K),Math.abs(G))}var PZ0=function(){var J=Za();return function(Z,Y,X,F,K,$){var Q,W;if(!Y)Y=4;if(!X)X=0;if(F)W=Math.min(F*Y+X,Z.length);else W=Z.length;for(Q=X;Q<W;Q+=Y)J[0]=Z[Q],J[1]=Z[Q+1],J[2]=Z[Q+2],J[3]=Z[Q+3],K(J,J,$),Z[Q]=J[0],Z[Q+1]=J[1],Z[Q+2]=J[2],Z[Q+3]=J[3];return Z}}();function FG(){var J=new $0(4);if($0!=Float32Array)J[0]=0,J[1]=0,J[2]=0;return J[3]=1,J}function Xa(J){return J[0]=0,J[1]=0,J[2]=0,J[3]=1,J}function Dj(J,Z,Y){Y=Y*0.5;var X=Math.sin(Y);return J[0]=X*Z[0],J[1]=X*Z[1],J[2]=X*Z[2],J[3]=Math.cos(Y),J}function Fa(J,Z){var Y=Math.acos(Z[3])*2,X=Math.sin(Y/2);if(X>i)J[0]=Z[0]/X,J[1]=Z[1]/X,J[2]=Z[2]/X;else J[0]=1,J[1]=0,J[2]=0;return Y}function Ka(J,Z){var Y=_j(J,Z);return Math.acos(2*Y*Y-1)}function Bj(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Y[0],W=Y[1],G=Y[2],V=Y[3];return J[0]=X*V+$*Q+F*G-K*W,J[1]=F*V+$*W+K*Q-X*G,J[2]=K*V+$*G+X*W-F*Q,J[3]=$*V-X*Q-F*W-K*G,J}function $a(J,Z,Y){Y*=0.5;var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Math.sin(Y),W=Math.cos(Y);return J[0]=X*W+$*Q,J[1]=F*W+K*Q,J[2]=K*W-F*Q,J[3]=$*W-X*Q,J}function Qa(J,Z,Y){Y*=0.5;var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Math.sin(Y),W=Math.cos(Y);return J[0]=X*W-K*Q,J[1]=F*W+$*Q,J[2]=K*W+X*Q,J[3]=$*W-F*Q,J}function Ga(J,Z,Y){Y*=0.5;var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Math.sin(Y),W=Math.cos(Y);return J[0]=X*W+F*Q,J[1]=F*W-X*Q,J[2]=K*W+$*Q,J[3]=$*W-K*Q,J}function Wa(J,Z){var Y=Z[0],X=Z[1],F=Z[2];return J[0]=Y,J[1]=X,J[2]=F,J[3]=Math.sqrt(Math.abs(1-Y*Y-X*X-F*F)),J}function Tj(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Math.sqrt(Y*Y+X*X+F*F),Q=Math.exp(K),W=$>0?Q*Math.sin($)/$:0;return J[0]=Y*W,J[1]=X*W,J[2]=F*W,J[3]=Q*Math.cos($),J}function Sj(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Math.sqrt(Y*Y+X*X+F*F),Q=$>0?Math.atan2($,K)/$:0;return J[0]=Y*Q,J[1]=X*Q,J[2]=F*Q,J[3]=0.5*Math.log(Y*Y+X*X+F*F+K*K),J}function Va(J,Z,Y){return Sj(J,Z),Cj(J,J,Y),Tj(J,J),J}function cY(J,Z,Y,X){var F=Z[0],K=Z[1],$=Z[2],Q=Z[3],W=Y[0],G=Y[1],V=Y[2],O=Y[3],v,w,H,N,q;if(w=F*W+K*G+$*V+Q*O,w<0)w=-w,W=-W,G=-G,V=-V,O=-O;if(1-w>i)v=Math.acos(w),H=Math.sin(v),N=Math.sin((1-X)*v)/H,q=Math.sin(X*v)/H;else N=1-X,q=X;return J[0]=N*F+q*W,J[1]=N*K+q*G,J[2]=N*$+q*V,J[3]=N*Q+q*O,J}function Oa(J){var Z=B6(),Y=B6(),X=B6(),F=Math.sqrt(1-Z),K=Math.sqrt(Z);return J[0]=F*Math.sin(2*Math.PI*Y),J[1]=F*Math.cos(2*Math.PI*Y),J[2]=K*Math.sin(2*Math.PI*X),J[3]=K*Math.cos(2*Math.PI*X),J}function va(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Y*Y+X*X+F*F+K*K,Q=$?1/$:0;return J[0]=-Y*Q,J[1]=-X*Q,J[2]=-F*Q,J[3]=K*Q,J}function La(J,Z){return J[0]=-Z[0],J[1]=-Z[1],J[2]=-Z[2],J[3]=Z[3],J}function Ej(J,Z){var Y=Z[0]+Z[4]+Z[8],X;if(Y>0)X=Math.sqrt(Y+1),J[3]=0.5*X,X=0.5/X,J[0]=(Z[5]-Z[7])*X,J[1]=(Z[6]-Z[2])*X,J[2]=(Z[1]-Z[3])*X;else{var F=0;if(Z[4]>Z[0])F=1;if(Z[8]>Z[F*3+F])F=2;var K=(F+1)%3,$=(F+2)%3;X=Math.sqrt(Z[F*3+F]-Z[K*3+K]-Z[$*3+$]+1),J[F]=0.5*X,X=0.5/X,J[3]=(Z[K*3+$]-Z[$*3+K])*X,J[K]=(Z[K*3+F]+Z[F*3+K])*X,J[$]=(Z[$*3+F]+Z[F*3+$])*X}return J}function qa(J,Z,Y,X){var F=0.5*Math.PI/180;Z*=F,Y*=F,X*=F;var K=Math.sin(Z),$=Math.cos(Z),Q=Math.sin(Y),W=Math.cos(Y),G=Math.sin(X),V=Math.cos(X);return J[0]=K*W*V-$*Q*G,J[1]=$*Q*V+K*W*G,J[2]=$*W*G-K*Q*V,J[3]=$*W*V+K*Q*G,J}function wa(J){return"quat("+J[0]+", "+J[1]+", "+J[2]+", "+J[3]+")"}var Ha=Lj,Na=qj,za=wj,Ma=Hj,Ua=Nj,Pa=Bj,Cj=zj,_j=Rj,Ra=jj,pj=Mj,ja=pj,fj=Uj,xa=fj,KG=Pj,ka=xj,Da=kj,Ba=function(){var J=fY(),Z=IY(1,0,0),Y=IY(0,1,0);return function(X,F,K){var $=hY(F,K);if($<-0.999999){if(w7(J,Z,F),XG(J)<0.000001)w7(J,Y,F);return YG(J,J),Dj(X,J,Math.PI),X}else if($>0.999999)return X[0]=0,X[1]=0,X[2]=0,X[3]=1,X;else return w7(J,F,K),X[0]=J[0],X[1]=J[1],X[2]=J[2],X[3]=1+$,KG(X,X)}}(),Ta=function(){var J=FG(),Z=FG();return function(Y,X,F,K,$,Q){return cY(J,X,$,Q),cY(Z,F,K,Q),cY(Y,J,Z,2*Q*(1-Q)),Y}}(),Sa=function(){var J=ZG();return function(Z,Y,X,F){return J[0]=X[0],J[3]=X[1],J[6]=X[2],J[1]=F[0],J[4]=F[1],J[7]=F[2],J[2]=-Y[0],J[5]=-Y[1],J[8]=-Y[2],KG(Z,Ej(Z,J))}}();var V0={};E6(V0,{zero:()=>Zo,transformMat4:()=>ta,transformMat3:()=>ra,transformMat2d:()=>oa,transformMat2:()=>aa,subtract:()=>hj,sub:()=>$o,str:()=>Yo,squaredLength:()=>Aj,squaredDistance:()=>mj,sqrLen:()=>Oo,sqrDist:()=>Vo,set:()=>pa,scaleAndAdd:()=>ga,scale:()=>ma,round:()=>ba,rotate:()=>ea,random:()=>sa,normalize:()=>ya,negate:()=>Aa,multiply:()=>cj,mul:()=>Qo,min:()=>ca,max:()=>la,lerp:()=>da,length:()=>gj,len:()=>Ko,inverse:()=>ia,fromValues:()=>Ca,forEach:()=>vo,floor:()=>ha,exactEquals:()=>Xo,equals:()=>Fo,dot:()=>na,divide:()=>lj,div:()=>Go,distance:()=>bj,dist:()=>Wo,cross:()=>ua,create:()=>Ij,copy:()=>_a,clone:()=>Ea,ceil:()=>Ia,angle:()=>Jo,add:()=>fa});function Ij(){var J=new $0(2);if($0!=Float32Array)J[0]=0,J[1]=0;return J}function Ea(J){var Z=new $0(2);return Z[0]=J[0],Z[1]=J[1],Z}function Ca(J,Z){var Y=new $0(2);return Y[0]=J,Y[1]=Z,Y}function _a(J,Z){return J[0]=Z[0],J[1]=Z[1],J}function pa(J,Z,Y){return J[0]=Z,J[1]=Y,J}function fa(J,Z,Y){return J[0]=Z[0]+Y[0],J[1]=Z[1]+Y[1],J}function hj(J,Z,Y){return J[0]=Z[0]-Y[0],J[1]=Z[1]-Y[1],J}function cj(J,Z,Y){return J[0]=Z[0]*Y[0],J[1]=Z[1]*Y[1],J}function lj(J,Z,Y){return J[0]=Z[0]/Y[0],J[1]=Z[1]/Y[1],J}function Ia(J,Z){return J[0]=Math.ceil(Z[0]),J[1]=Math.ceil(Z[1]),J}function ha(J,Z){return J[0]=Math.floor(Z[0]),J[1]=Math.floor(Z[1]),J}function ca(J,Z,Y){return J[0]=Math.min(Z[0],Y[0]),J[1]=Math.min(Z[1],Y[1]),J}function la(J,Z,Y){return J[0]=Math.max(Z[0],Y[0]),J[1]=Math.max(Z[1],Y[1]),J}function ba(J,Z){return J[0]=Math.round(Z[0]),J[1]=Math.round(Z[1]),J}function ma(J,Z,Y){return J[0]=Z[0]*Y,J[1]=Z[1]*Y,J}function ga(J,Z,Y,X){return J[0]=Z[0]+Y[0]*X,J[1]=Z[1]+Y[1]*X,J}function bj(J,Z){var Y=Z[0]-J[0],X=Z[1]-J[1];return Math.hypot(Y,X)}function mj(J,Z){var Y=Z[0]-J[0],X=Z[1]-J[1];return Y*Y+X*X}function gj(J){var Z=J[0],Y=J[1];return Math.hypot(Z,Y)}function Aj(J){var Z=J[0],Y=J[1];return Z*Z+Y*Y}function Aa(J,Z){return J[0]=-Z[0],J[1]=-Z[1],J}function ia(J,Z){return J[0]=1/Z[0],J[1]=1/Z[1],J}function ya(J,Z){var Y=Z[0],X=Z[1],F=Y*Y+X*X;if(F>0)F=1/Math.sqrt(F);return J[0]=Z[0]*F,J[1]=Z[1]*F,J}function na(J,Z){return J[0]*Z[0]+J[1]*Z[1]}function ua(J,Z,Y){var X=Z[0]*Y[1]-Z[1]*Y[0];return J[0]=J[1]=0,J[2]=X,J}function da(J,Z,Y,X){var F=Z[0],K=Z[1];return J[0]=F+X*(Y[0]-F),J[1]=K+X*(Y[1]-K),J}function sa(J,Z){Z=Z||1;var Y=B6()*2*Math.PI;return J[0]=Math.cos(Y)*Z,J[1]=Math.sin(Y)*Z,J}function aa(J,Z,Y){var X=Z[0],F=Z[1];return J[0]=Y[0]*X+Y[2]*F,J[1]=Y[1]*X+Y[3]*F,J}function oa(J,Z,Y){var X=Z[0],F=Z[1];return J[0]=Y[0]*X+Y[2]*F+Y[4],J[1]=Y[1]*X+Y[3]*F+Y[5],J}function ra(J,Z,Y){var X=Z[0],F=Z[1];return J[0]=Y[0]*X+Y[3]*F+Y[6],J[1]=Y[1]*X+Y[4]*F+Y[7],J}function ta(J,Z,Y){var X=Z[0],F=Z[1];return J[0]=Y[0]*X+Y[4]*F+Y[12],J[1]=Y[1]*X+Y[5]*F+Y[13],J}function ea(J,Z,Y,X){var F=Z[0]-Y[0],K=Z[1]-Y[1],$=Math.sin(X),Q=Math.cos(X);return J[0]=F*Q-K*$+Y[0],J[1]=F*$+K*Q+Y[1],J}function Jo(J,Z){var Y=J[0],X=J[1],F=Z[0],K=Z[1],$=Math.sqrt(Y*Y+X*X)*Math.sqrt(F*F+K*K),Q=$&&(Y*F+X*K)/$;return Math.acos(Math.min(Math.max(Q,-1),1))}function Zo(J){return J[0]=0,J[1]=0,J}function Yo(J){return"vec2("+J[0]+", "+J[1]+")"}function Xo(J,Z){return J[0]===Z[0]&&J[1]===Z[1]}function Fo(J,Z){var Y=J[0],X=J[1],F=Z[0],K=Z[1];return Math.abs(Y-F)<=i*Math.max(1,Math.abs(Y),Math.abs(F))&&Math.abs(X-K)<=i*Math.max(1,Math.abs(X),Math.abs(K))}var Ko=gj,$o=hj,Qo=cj,Go=lj,Wo=bj,Vo=mj,Oo=Aj,vo=function(){var J=Ij();return function(Z,Y,X,F,K,$){var Q,W;if(!Y)Y=2;if(!X)X=0;if(F)W=Math.min(F*Y+X,Z.length);else W=Z.length;for(Q=X;Q<W;Q+=Y)J[0]=Z[Q],J[1]=Z[Q+1],K(J,J,$),Z[Q]=J[0],Z[Q+1]=J[1];return Z}}();class e9 extends Float32Array{constructor(J,Z,Y,X){super([J,Z,Y,X])}get determinant(){return t0.determinant(this)}get frobeniusNorm(){return t0.frob(this)}static create(){let J=new e9(0,0,0,0);return t0.identity(J),J}static fromRotation(J){let Z=e9.create();return t0.fromRotation(Z,J),Z}static fromScaling(J){let Z=e9.create();return t0.fromScaling(Z,J),Z}add(J){return t0.add(this,this,J),this}adjoint(){return t0.adjoint(this,this),this}clone(){return new e9(this[0],this[1],this[2],this[3])}copy(J){return t0.copy(this,J),this}equals(J){return t0.equals(this,J)}exactEquals(J){return t0.exactEquals(this,J)}identity(){return t0.identity(this),this}invert(){return t0.invert(this,this),this}multiply(J){return t0.mul(this,this,J),this}multiplyScalar(J){return t0.multiplyScalar(this,this,J),this}rotate(J){return t0.rotate(this,this,J),this}subtract(J){return t0.sub(this,this,J),this}toString(){return`[${this[0]},${this[1]}][${this[2]},${this[3]}]`}transpose(){return t0.transpose(this,this),this}}class T6 extends Float32Array{constructor(J,Z,Y,X,F,K,$,Q,W){super([J,Z,Y,X,F,K,$,Q,W])}get determinant(){return f0.determinant(this)}get frobeniusNorm(){return f0.frob(this)}static create(){let J=new T6(0,0,0,0,0,0,0,0,0);return f0.identity(J),J}static fromMatrix4(J){let Z=T6.create();return f0.fromMat4(Z,J),Z}static fromQuaternion(J){let Z=T6.create();return f0.fromQuat(Z,J),Z}static fromRotation(J){let Z=T6.create();return f0.fromRotation(Z,J),Z}static fromScaling(J){let Z=T6.create();return f0.fromScaling(Z,J),Z}static fromTranslation(J){let Z=T6.create();return f0.fromTranslation(Z,J),Z}add(J){return f0.add(this,this,J),this}adjoint(){return f0.adjoint(this,this),this}clone(){return new T6(this[0],this[1],this[2],this[3],this[4],this[5],this[6],this[7],this[8])}copy(J){return f0.copy(this,J),this}equals(J){return f0.equals(this,J)}exactEquals(J){return f0.exactEquals(this,J)}identity(){return f0.identity(this),this}invert(){return f0.invert(this,this),this}multiply(J){return f0.mul(this,this,J),this}multiplyScalar(J){return f0.multiplyScalar(this,this,J),this}transformVector(J){return J.transformMatrix3(this)}projection(J,Z){return f0.projection(this,J,Z),this}rotate(J){return f0.rotate(this,this,J),this}subtract(J){return f0.sub(this,this,J),this}toString(){return`[${this[0]},${this[1]},${this[2]}][${this[3]},${this[4]},${this[5]}][${this[6]},${this[7]},${this[8]}]`}transpose(){return f0.transpose(this,this),this}}class k8 extends Float32Array{constructor(J,Z,Y,X,F,K,$,Q,W,G,V,O,v,w,H,N){super([J,Z,Y,X,F,K,$,Q,W,G,V,O,v,w,H,N])}get determinant(){return J0.determinant(this)}get frobeniusNorm(){return J0.frob(this)}static create(){let J=new k8(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);return J0.identity(J),J}static fromQuaternion(J){let Z=k8.create();return J0.fromQuat(Z,J),Z}static fromRotation(J,Z){let Y=k8.create();return J0.fromRotation(Y,J,Z),Y}static fromRotationTranslation(J,Z){let Y=k8.create();return J0.fromRotationTranslation(Y,J,Z),Y}static fromRotationTranslationScale(J,Z,Y){let X=k8.create();return J0.fromRotationTranslationScale(X,J,Z,Y),X}static fromRotationTranslationScaleOrigin(J,Z,Y,X){let F=k8.create();return J0.fromRotationTranslationScaleOrigin(F,J,Z,Y,X),F}static fromScaling(J){let Z=k8.create();return J0.fromScaling(Z,J),Z}static fromTranslation(J){let Z=k8.create();return J0.fromTranslation(Z,J),Z}static fromXRotation(J){let Z=k8.create();return J0.fromXRotation(Z,J),Z}static fromYRotation(J){let Z=k8.create();return J0.fromYRotation(Z,J),Z}static fromZRotation(J){let Z=k8.create();return J0.fromZRotation(Z,J),Z}add(J){return J0.add(this,this,J),this}adjoint(){return J0.adjoint(this,this),this}clone(){return new k8(this[0],this[1],this[2],this[3],this[4],this[5],this[6],this[7],this[8],this[9],this[10],this[11],this[12],this[13],this[14],this[15])}copy(J){return J0.copy(this,J),this}equals(J){return J0.equals(this,J)}exactEquals(J){return J0.exactEquals(this,J)}frustrum(J,Z,Y,X,F,K){return J0.frustum(this,J,Z,Y,X,F,K),this}identity(){return J0.identity(this),this}invert(){return J0.invert(this,this),this}lookAt(J,Z,Y){return J0.lookAt(this,J,Z,Y),this}multiply(J){return J0.mul(this,this,J),this}multiplyScalar(J){return J0.multiplyScalar(this,this,J),this}orthographic(J,Z,Y,X,F,K){return J0.ortho(this,J,Z,Y,X,F,K),this}perspective(J,Z,Y,X){return J0.perspective(this,J,Z,Y,X),this}rotate(J,Z){return J0.rotate(this,this,J,Z),this}rotateX(J){return J0.rotateX(this,this,J),this}rotateY(J){return J0.rotateY(this,this,J),this}rotateZ(J){return J0.rotateZ(this,this,J),this}scale(J){return J0.scale(this,this,J),this}subtract(J){return J0.sub(this,this,J),this}targetTo(J,Z,Y){return J0.targetTo(this,J,Z,Y),this}toString(){return`[${this[0]},${this[1]},${this[2]},${this[3]}][${this[4]},${this[5]},${this[6]},${this[7]}][${this[8]},${this[9]},${this[10]},${this[11]}][${this[12]},${this[13]},${this[14]},${this[15]}]`}translate(J){return J0.translate(this,this,J),this}transpose(){return J0.transpose(this,this),this}}class r1 extends Float32Array{constructor(J,Z,Y,X){super([J,Z,Y,X])}get length(){return R0.length(this)}get squaredLength(){return R0.squaredLength(this)}get magnitude(){return R0.length(this)}get squaredMagnitude(){return R0.squaredLength(this)}get x(){return this[0]}set x(J){this[0]=J}get y(){return this[1]}set y(J){this[1]=J}get z(){return this[2]}set z(J){this[2]=J}get w(){return this[3]}set w(J){this[3]=J}static fromEuler(J,Z,Y){let X=R0.fromEuler(new Float32Array(4),J,Z,Y);return new r1(X[0],X[1],X[2],X[3])}static fromQuaternionLike(J){return new r1(J.x,J.y,J.z,J.w)}clone(){return new r1(this.x,this.y,this.z,this.w)}conjugate(){return R0.conjugate(this,this),this}copy(J){return R0.copy(this,J),this}dot(J){return R0.dot(this,J)}exponential(){return R0.exp(this,this),this}equals(J){return R0.equals(this,J)}exactEquals(J){return R0.exactEquals(this,J)}getAngle(J){return R0.getAngle(this,J)}identity(){return R0.identity(this),this}invert(){return R0.invert(this,this),this}lerp(J,Z){return R0.lerp(this,this,J,Z),this}logarithm(){return R0.ln(this,this),this}multiply(J){return R0.multiply(this,this,J),this}transformVector(J){return J.transformQuaternion(this)}normalize(){return R0.normalize(this,this),this}power(J){return R0.pow(this,this,J),this}randomize(){return R0.random(this),this}rotateX(J){return R0.rotateX(this,this,J),this}rotateY(J){return R0.rotateY(this,this,J),this}rotateZ(J){return R0.rotateZ(this,this,J),this}scale(J){return R0.scale(this,this,J),this}setAxisAngle(J,Z){return R0.setAxisAngle(this,J,Z),this}slerp(J,Z){return R0.slerp(this,this,J,Z),this}toString(){return`${this.x},${this.y},${this.z},${this.w}`}}class H7 extends Float32Array{constructor(J,Z){super([J,Z])}get length(){return V0.length(this)}get squaredLength(){return V0.squaredLength(this)}get magnitude(){return V0.length(this)}get squaredMagnitude(){return V0.squaredLength(this)}get x(){return this[0]}set x(J){this[0]=J}get y(){return this[1]}set y(J){this[1]=J}static create(){return new H7(0,0)}add(J){return V0.add(this,this,J),this}angle(J){return V0.angle(this,J)}ceil(){return V0.ceil(this,this),this}clone(){return new H7(this.x,this.y)}copy(J){return V0.copy(this,J),this}distance(J){return V0.distance(this,J)}divide(J){return V0.divide(this,this,J),this}dot(J){return V0.dot(this,J)}equals(J){return V0.equals(this,J)}exactEquals(J){return V0.exactEquals(this,J)}floor(){return V0.floor(this,this),this}invert(){return V0.inverse(this,this),this}lerp(J,Z){return V0.lerp(this,this,J,Z),this}max(J){return V0.max(this,this,J),this}min(J){return V0.min(this,this,J),this}multiply(J){return V0.mul(this,this,J),this}negate(){return V0.negate(this,this),this}normalize(){return V0.normalize(this,this),this}randomize(J){return V0.random(this,J),this}rotate(J,Z){return V0.rotate(this,this,J,Z),this}round(){return V0.round(this,this),this}scale(J){return V0.scale(this,this,J),this}scaleAndAdd(J,Z){return V0.scaleAndAdd(this,this,J,Z),this}subtract(J){return V0.sub(this,this,J),this}toString(){return`${this.x},${this.y}`}transformMatrix2(J){return V0.transformMat2(this,this,J),this}transformMatrix3(J){return V0.transformMat3(this,this,J),this}transformMatrix4(J){return V0.transformMat4(this,this,J),this}zero(){return V0.zero(this),this}}class t1 extends Float32Array{constructor(J,Z,Y){super([J,Z,Y])}get length(){return Y0.length(this)}get squaredLength(){return Y0.squaredLength(this)}get magnitude(){return Y0.length(this)}get squaredMagnitude(){return Y0.squaredLength(this)}get x(){return this[0]}set x(J){this[0]=J}get y(){return this[1]}set y(J){this[1]=J}get z(){return this[2]}set z(J){this[2]=J}static create(){return new t1(0,0,0)}static fromVector3Like(J){return new t1(J.x,J.y,J.z)}add(J){return Y0.add(this,this,J),this}ceil(){return Y0.ceil(this,this),this}clone(){return new t1(this.x,this.y,this.z)}copy(J){return Y0.copy(this,J),this}cross(J){return Y0.cross(this,this,J),this}distance(J){return Y0.distance(this,J)}divide(J){return Y0.div(this,this,J),this}dot(J){return Y0.dot(this,J)}equals(J){return Y0.equals(this,J)}exactEquals(J){return Y0.exactEquals(this,J)}floor(){return Y0.floor(this,this),this}invert(){return Y0.inverse(this,this),this}lerp(J,Z){return Y0.lerp(this,this,J,Z),this}max(J){return Y0.max(this,this,J),this}min(J){return Y0.min(this,this,J),this}multiply(J){return Y0.mul(this,this,J),this}negate(){return Y0.negate(this,this),this}normalize(){return Y0.normalize(this,this),this}randomize(J){return Y0.random(this,J),this}rotateX(J,Z){return Y0.rotateX(this,this,J,Z),this}rotateY(J,Z){return Y0.rotateY(this,this,J,Z),this}rotateZ(J,Z){return Y0.rotateZ(this,this,J,Z),this}round(){return Y0.round(this,this),this}scale(J){return Y0.scale(this,this,J),this}scaleAndAdd(J,Z){return Y0.scaleAndAdd(this,this,J,Z),this}subtract(J){return Y0.sub(this,this,J),this}toString(){return`${this.x},${this.y},${this.z}`}transformMatrix3(J){return Y0.transformMat3(this,this,J),this}transformMatrix4(J){return Y0.transformMat4(this,this,J),this}transformQuaternion(J){return Y0.transformQuat(this,this,J),this}zero(){return Y0.zero(this),this}}var j0=function(J,Z,Y,X){function F(K){return K instanceof Y?K:new Y(function($){$(K)})}return new(Y||(Y=Promise))(function(K,$){function Q(V){try{G(X.next(V))}catch(O){$(O)}}function W(V){try{G(X.throw(V))}catch(O){$(O)}}function G(V){V.done?K(V.value):F(V.value).then(Q,W)}G((X=X.apply(J,Z||[])).next())})},P0=function(J,Z){var Y={label:0,sent:function(){if(K[0]&1)throw K[1];return K[1]},trys:[],ops:[]},X,F,K,$=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return $.next=Q(0),$.throw=Q(1),$.return=Q(2),typeof Symbol==="function"&&($[Symbol.iterator]=function(){return this}),$;function Q(G){return function(V){return W([G,V])}}function W(G){if(X)throw new TypeError("Generator is already executing.");while($&&($=0,G[0]&&(Y=0)),Y)try{if(X=1,F&&(K=G[0]&2?F.return:G[0]?F.throw||((K=F.return)&&K.call(F),0):F.next)&&!(K=K.call(F,G[1])).done)return K;if(F=0,K)G=[G[0]&2,K.value];switch(G[0]){case 0:case 1:K=G;break;case 4:return Y.label++,{value:G[1],done:!1};case 5:Y.label++,F=G[1],G=[0];continue;case 7:G=Y.ops.pop(),Y.trys.pop();continue;default:if((K=Y.trys,!(K=K.length>0&&K[K.length-1]))&&(G[0]===6||G[0]===2)){Y=0;continue}if(G[0]===3&&(!K||G[1]>K[0]&&G[1]<K[3])){Y.label=G[1];break}if(G[0]===6&&Y.label<K[1]){Y.label=K[1],K=G;break}if(K&&Y.label<K[2]){Y.label=K[2],Y.ops.push(G);break}if(K[2])Y.ops.pop();Y.trys.pop();continue}G=Z.call(J,Y)}catch(V){G=[6,V],F=0}finally{X=K=0}if(G[0]&5)throw G[1];return{value:G[0]?G[1]:void 0,done:!0}}},h8=function(J,Z){var Y=typeof Symbol==="function"&&J[Symbol.iterator];if(!Y)return J;var X=Y.call(J),F,K=[],$;try{while((Z===void 0||Z-- >0)&&!(F=X.next()).done)K.push(F.value)}catch(Q){$={error:Q}}finally{try{if(F&&!F.done&&(Y=X.return))Y.call(X)}finally{if($)throw $.error}}return K},r8=function(J,Z,Y){if(Y||arguments.length===2){for(var X=0,F=Z.length,K;X<F;X++)if(K||!(X in Z)){if(!K)K=Array.prototype.slice.call(Z,0,X);K[X]=Z[X]}}return J.concat(K||Array.prototype.slice.call(Z))},ij=function(J){var Z=typeof Symbol==="function"&&Symbol.iterator,Y=Z&&J[Z],X=0;if(Y)return Y.call(J);if(J&&typeof J.length==="number")return{next:function(){if(J&&X>=J.length)J=void 0;return{value:J&&J[X++],done:!J}}};throw new TypeError(Z?"Object is not iterable.":"Symbol.iterator is not defined.")},TZ0=function(){function J(Z){if(Z===void 0)Z=J.minComparator;var Y=this;this.compare=Z,this.heapArray=[],this._limit=0,this.offer=this.add,this.element=this.peek,this.poll=this.pop,this._invertedCompare=function(X,F){return Y.compare(X,F).then(function(K){return-1*K})}}return J.getChildrenIndexOf=function(Z){return[Z*2+1,Z*2+2]},J.getParentIndexOf=function(Z){if(Z<=0)return-1;var Y=Z%2?1:2;return Math.floor((Z-Y)/2)},J.getSiblingIndexOf=function(Z){if(Z<=0)return-1;var Y=Z%2?1:-1;return Z+Y},J.minComparator=function(Z,Y){return j0(this,void 0,void 0,function(){return P0(this,function(X){if(Z>Y)return[2,1];else if(Z<Y)return[2,-1];else return[2,0]})})},J.maxComparator=function(Z,Y){return j0(this,void 0,void 0,function(){return P0(this,function(X){if(Y>Z)return[2,1];else if(Y<Z)return[2,-1];else return[2,0]})})},J.minComparatorNumber=function(Z,Y){return j0(this,void 0,void 0,function(){return P0(this,function(X){return[2,Z-Y]})})},J.maxComparatorNumber=function(Z,Y){return j0(this,void 0,void 0,function(){return P0(this,function(X){return[2,Y-Z]})})},J.defaultIsEqual=function(Z,Y){return j0(this,void 0,void 0,function(){return P0(this,function(X){return[2,Z===Y]})})},J.print=function(Z){function Y(V){var O=J.getParentIndexOf(V);return Math.floor(Math.log2(O+1))}function X(V,O){var v="";for(;O>0;--O)v+=V;return v}var F=0,K=[],$=Y(Z.length-1)+2,Q=0;while(F<Z.length){var W=Y(F)+1;if(F===0)W=0;var G=String(Z.get(F));if(G.length>Q)Q=G.length;K[W]=K[W]||[],K[W].push(G),F+=1}return K.map(function(V,O){var v=Math.pow(2,$-O)-1;return X(" ",Math.floor(v/2)*Q)+V.map(function(w){var H=(Q-w.length)/2;return X(" ",Math.ceil(H))+w+X(" ",Math.floor(H))}).join(X(" ",v*Q))}).join(`
338
+ `),Z.write(K),Z.end();return}K0.serverInstance.emit("WEBSERVER.UPGRADE",{req:J,socket:Z,head:Y})};_onError=(J)=>{K0.serverInstance.emit("WEBSERVER.ERROR",{error:J})};_onStopped=()=>{K0.serverInstance.emit("WEBSERVER.STOPPED",{})}}class Z7{static instance=new Z7;_wss;constructor(){this._wss=new Bu({noServer:!0}),this._wss.on("connection",this._onConnection),this._wss.on("error",this._onError),K0.serverInstance.on("WEBSERVER.UPGRADE",({req:J,socket:Z,head:Y})=>this._onUpgrade(J,Z,Y))}_onConnection=(J,Z)=>{new RZ(J,Z)};_onError=(J,Z)=>{K0.serverInstance.emit("SOCKET.ERROR",{ws:J,error:Z})};_onUpgrade=(J,Z,Y)=>{this._wss.handleUpgrade(J,Z,Y,(X)=>{this._wss.emit("connection",X,J)})}}var g=new Error("RigidBody has been removed from the simulation and is therefore inaccessible."),CY;((F)=>{F.DYNAMIC="dynamic";F.FIXED="fixed";F.KINEMATIC_POSITION="kinematic_position";F.KINEMATIC_VELOCITY="kinematic_velocity"})(CY||={});var D6=0.001,bR="dynamic";class r9{_additionalMass=0;_colliders=new Set;_explicitSleep=!1;_enabledPositions={x:!0,y:!0,z:!0};_enabledRotations={x:!0,y:!0,z:!0};_rigidBody;_rigidBodyDesc;_rigidBodyType;_simulation;constructor(J){J.type??=bR,this._rigidBodyDesc=this._createRigidBodyDesc(J),this._rigidBodyType=J.type,this._applyRigidBodyOptions(J),this._autoAddToSimulation(J)}get additionalMass(){if(this._rigidBody||this._rigidBodyDesc)return this._additionalMass;throw g}get additionalSolverIterations(){if(this._rigidBody)return this._rigidBody.additionalSolverIterations();if(this._rigidBodyDesc)return this._rigidBodyDesc.additionalSolverIterations;throw g}get angularDamping(){if(this._rigidBody)return this._rigidBody.angularDamping();if(this._rigidBodyDesc)return this._rigidBodyDesc.angularDamping;throw g}get angularVelocity(){if(this._rigidBody)return this._rigidBody.angvel();if(this._rigidBodyDesc)return this._rigidBodyDesc.angvel;throw g}get colliders(){return this._colliders}get dominanceGroup(){if(this._rigidBody)return this._rigidBody.dominanceGroup();if(this._rigidBodyDesc)return this._rigidBodyDesc.dominanceGroup;throw g}get directionFromRotation(){let{x:J,y:Z,z:Y,w:X}=this.rotation;return{x:2*(J*Y+X*Z),y:2*(Z*Y-X*J),z:1-2*(J*J+Z*Z)}}get effectiveAngularInertia(){if(this._rigidBody)return this._rigidBody.effectiveAngularInertia();if(this._rigidBodyDesc)return;throw g}get effectiveInverseMass(){if(this._rigidBody)return this._rigidBody.effectiveInvMass();if(this._rigidBodyDesc)return;throw g}get effectiveWorldInversePrincipalAngularInertiaSqrt(){if(this._rigidBody)return this._rigidBody.effectiveWorldInvInertiaSqrt();if(this._rigidBodyDesc)return;throw g}get enabledRotations(){if(this._rigidBody||this._rigidBodyDesc)return this._enabledRotations;throw g}get enabledPositions(){if(this._rigidBody||this._rigidBodyDesc)return this._enabledPositions;throw g}get gravityScale(){if(this._rigidBody)return this._rigidBody.gravityScale();if(this._rigidBodyDesc)return this._rigidBodyDesc.gravityScale;throw g}get inverseMass(){if(this._rigidBody)return this._rigidBody.invMass();if(this._rigidBodyDesc)return;throw g}get inversePrincipalAngularInertiaSqrt(){if(this._rigidBody)return this._rigidBody.invPrincipalInertiaSqrt();if(this._rigidBodyDesc)return;throw g}get isCcdEnabled(){if(this._rigidBody)return this._rigidBody.isCcdEnabled();if(this._rigidBodyDesc)return this._rigidBodyDesc.ccdEnabled;throw g}get isDynamic(){if(this._rigidBody||this._rigidBodyDesc)return this._rigidBodyType==="dynamic";throw g}get isEnabled(){if(this._rigidBody)return this._rigidBody.isEnabled();if(this._rigidBodyDesc)return this._rigidBodyDesc.enabled;throw g}get isFixed(){if(this._rigidBody||this._rigidBodyDesc)return this._rigidBodyType==="fixed";throw g}get isKinematic(){if(this._rigidBody||this._rigidBodyDesc)return["kinematic_position","kinematic_velocity"].includes(this._rigidBodyType);throw g}get isKinematicPositionBased(){if(this._rigidBody||this._rigidBodyDesc)return this._rigidBodyType==="kinematic_position";throw g}get isKinematicVelocityBased(){if(this._rigidBody||this._rigidBodyDesc)return this._rigidBodyType==="kinematic_velocity";throw g}get isMoving(){if(this._rigidBody)return this._rigidBody.isMoving();if(this._rigidBodyDesc)return!1;throw g}get isRemoved(){return!this._rigidBody&&!this._rigidBodyDesc}get isSimulated(){if(this._rigidBody)return!0;if(this._rigidBodyDesc)return!1;throw g}get isSleeping(){if(this._rigidBody)return this._rigidBody.isSleeping();if(this._rigidBodyDesc)return this._rigidBodyDesc.sleeping;throw g}get linearDamping(){if(this._rigidBody)return this._rigidBody.linearDamping();if(this._rigidBodyDesc)return this._rigidBodyDesc.linearDamping;throw g}get linearVelocity(){if(this._rigidBody)return this._rigidBody.linvel();if(this._rigidBodyDesc)return this._rigidBodyDesc.linvel;throw g}get localCenterOfMass(){if(this._rigidBody)return this._rigidBody.localCom();if(this._rigidBodyDesc)return this._rigidBodyDesc.centerOfMass;throw g}get mass(){if(this._rigidBody)return this._rigidBody.mass();if(this._rigidBodyDesc)return this._rigidBodyDesc.mass;throw g}get nextKinematicRotation(){if(this._rigidBody)return this._rigidBody.nextRotation();if(this._rigidBodyDesc)return this._rigidBodyDesc.rotation;throw g}get nextKinematicPosition(){if(this._rigidBody)return this._rigidBody.nextTranslation();if(this._rigidBodyDesc)return this._rigidBodyDesc.translation;throw g}get numColliders(){return this._colliders.size}get principalAngularInertia(){if(this._rigidBody)return this._rigidBody.principalInertia();if(this._rigidBodyDesc)return this._rigidBodyDesc.principalAngularInertia;throw g}get principalAngularInertiaLocalFrame(){if(this._rigidBody)return this._rigidBody.principalInertiaLocalFrame();if(this._rigidBodyDesc)return;throw g}get position(){if(this._rigidBody)return this._rigidBody.translation();if(this._rigidBodyDesc)return this._rigidBodyDesc.translation;throw g}get rawRigidBody(){if(this._rigidBody)return this._rigidBody;if(this._rigidBodyDesc)return;throw g}get rotation(){if(this._rigidBody)return this._rigidBody.rotation();if(this._rigidBodyDesc)return this._rigidBodyDesc.rotation;throw g}get softCcdPrediction(){if(this._rigidBody)return this._rigidBody.softCcdPrediction();if(this._rigidBodyDesc)return this._rigidBodyDesc.softCcdPrediction;throw g}get type(){if(this._rigidBody||this._rigidBodyDesc)return this._rigidBodyType;throw g}get worldCenterOfMass(){if(this._rigidBody)return this._rigidBody.worldCom();if(this._rigidBodyDesc)return;throw g}setAdditionalMass(J){if(this._requireDynamic(),this._rigidBody)this._rigidBody.setAdditionalMass(J,!this._explicitSleep);else if(this._rigidBodyDesc)this._rigidBodyDesc.setAdditionalMass(J);else throw g}setAdditionalMassProperties(J){this._requireDynamic();let{additionalMass:Z,centerOfMass:Y,principalAngularInertia:X,principalAngularInertiaLocalFrame:F}=J;if(this._rigidBody)this._rigidBody.setAdditionalMassProperties(Z,Y,X,F,!this._explicitSleep);else if(this._rigidBodyDesc)this._rigidBodyDesc.setAdditionalMassProperties(Z,Y,X,F);else throw g;this._additionalMass=Z}setAdditionalSolverIterations(J){if(this._requireDynamic(),this._rigidBody)this._rigidBody.setAdditionalSolverIterations(J);else if(this._rigidBodyDesc)this._rigidBodyDesc.setAdditionalSolverIterations(J);else throw g}setAngularDamping(J){if(this._requireDynamic(),this._rigidBody)this._rigidBody.setAngularDamping(J);else if(this._rigidBodyDesc)this._rigidBodyDesc.setAngularDamping(J);else throw g}setAngularVelocity(J){if(this._requireNotKinematicPositionBased(),this._rigidBody)this._rigidBody.setAngvel(J,!this._explicitSleep);else if(this._rigidBodyDesc)this._rigidBodyDesc.setAngvel(J);else throw g}setCcdEnabled(J){if(this._requireDynamic(),this._rigidBody)this._rigidBody.enableCcd(J);else if(this._rigidBodyDesc)this._rigidBodyDesc.setCcdEnabled(J);else throw g}setDominanceGroup(J){if(this._requireDynamic(),this._rigidBody)this._rigidBody.setDominanceGroup(J);else if(this._rigidBodyDesc)this._rigidBodyDesc.setDominanceGroup(J);else throw g}setEnabled(J){if(this._rigidBody)this._rigidBody.setEnabled(J);else if(this._rigidBodyDesc)this._rigidBodyDesc.setEnabled(J);else throw g}setEnabledPositions(J){if(this._requireDynamic(),this._rigidBody)this._rigidBody.setEnabledTranslations(J.x,J.y,J.z,!this._explicitSleep);else if(this._rigidBodyDesc)this._rigidBodyDesc.enabledTranslations(J.x,J.y,J.z);else throw g;this._enabledPositions=J}setEnabledRotations(J){if(this._requireDynamic(),this._rigidBody)this._rigidBody.setEnabledRotations(J.x,J.y,J.z,!this._explicitSleep);else if(this._rigidBodyDesc)this._rigidBodyDesc.enabledRotations(J.x,J.y,J.z);else throw g;this._enabledRotations=J}setGravityScale(J){if(this._requireDynamic(),this._rigidBody)this._rigidBody.setGravityScale(J,!this._explicitSleep);else if(this._rigidBodyDesc)this._rigidBodyDesc.setGravityScale(J);else throw g}setLinearDamping(J){if(this._requireDynamic(),this._rigidBody)this._rigidBody.setLinearDamping(J);else if(this._rigidBodyDesc)this._rigidBodyDesc.setLinearDamping(J);else throw g}setLinearVelocity(J){if(this._requireNotKinematicPositionBased(),this._rigidBody)this._rigidBody.setLinvel(J,!this._explicitSleep);else if(this._rigidBodyDesc)this._rigidBodyDesc.setLinvel(J.x,J.y,J.z);else throw g}setNextKinematicRotation(J){if(this._requireKinematic(),this._rigidBody)this._rigidBody.setNextKinematicRotation(J);else if(this._rigidBodyDesc)this._rigidBodyDesc.setRotation(J);else throw g}setNextKinematicPosition(J){if(this._requireKinematic(),this._rigidBody)this._rigidBody.setNextKinematicTranslation(J);else if(this._rigidBodyDesc)this._rigidBodyDesc.setTranslation(J.x,J.y,J.z);else throw g}setPosition(J){if(this._rigidBody)this._rigidBody.setTranslation(J,!this._explicitSleep);else if(this._rigidBodyDesc)this._rigidBodyDesc.setTranslation(J.x,J.y,J.z);else throw g}setRotation(J){if(this._rigidBody)this._rigidBody.setRotation(J,!this._explicitSleep);else if(this._rigidBodyDesc)this._rigidBodyDesc.setRotation(J);else throw g}setSleeping(J){if(this._requireDynamic(),this._rigidBody)J?this._rigidBody.sleep():this._rigidBody.wakeUp();else if(this._rigidBodyDesc)this._rigidBodyDesc.sleeping=J;else throw g;this._explicitSleep=J}setSoftCcdPrediction(J){if(this._requireDynamic(),this._rigidBody)this._rigidBody.setSoftCcdPrediction(J);else if(this._rigidBodyDesc)this._rigidBodyDesc.setSoftCcdPrediction(J);else throw g}setCollisionGroupsForSolidColliders(J){this._requireNotRemoved(),this._colliders.forEach((Z)=>{if(Z.isSensor)return;Z.setCollisionGroups(J)})}setCollisionGroupsForSensorColliders(J){this._requireNotRemoved(),this._colliders.forEach((Z)=>{if(!Z.isSensor)return;Z.setCollisionGroups(J)})}setType(J){let Y={["dynamic"]:v0.RigidBodyType.Dynamic,["fixed"]:v0.RigidBodyType.Fixed,["kinematic_position"]:v0.RigidBodyType.KinematicPositionBased,["kinematic_velocity"]:v0.RigidBodyType.KinematicVelocityBased}[J];if(Y===void 0)throw new Error(`Invalid RigidBodyType: ${J}`);if(this._rigidBody)this._rigidBody.setBodyType(Y,!this._explicitSleep);else if(this._rigidBodyDesc)this._rigidBodyDesc.status=Y;else throw g;this._rigidBodyType=J}addForce(J){if(this._requireNotRemoved(),this._requireCreated(),this._requireDynamic(),this._isNegligibleVector(J))return;this._rigidBody.addForce(J,!this._explicitSleep)}addTorque(J){if(this._requireNotRemoved(),this._requireCreated(),this._requireDynamic(),this._isNegligibleVector(J))return;this._rigidBody.addTorque(J,!this._explicitSleep)}addChildColliderToSimulation(J){this._requireNotRemoved(),this._requireCreated(),J.addToSimulation(this._simulation,this)}addToSimulation(J){if(this._requireNotRemoved(),this._rigidBody)throw new Error("RigidBody.create(): Rigid body already exists in the simulation!");this._simulation=J,this._rigidBody=this._simulation.createRawRigidBody(this._rigidBodyDesc),this._colliders.forEach((Z)=>{if(!Z.isSimulated)Z.addToSimulation(J,this)})}applyImpulse(J){if(this._requireNotRemoved(),this._requireCreated(),this._requireDynamic(),this._isNegligibleVector(J))return;this._rigidBody.applyImpulse(J,!this._explicitSleep)}applyImpulseAtPoint(J,Z){if(this._requireNotRemoved(),this._requireCreated(),this._requireDynamic(),this._isNegligibleVector(J))return;this._rigidBody.applyImpulseAtPoint(J,Z,!this._explicitSleep)}applyTorqueImpulse(J){this._requireNotRemoved(),this._requireCreated(),this._requireDynamic(),this._rigidBody.applyTorqueImpulse(J,!this._explicitSleep)}createAndAddChildCollider(J){return this._requireNotRemoved(),this._simulation?new m8({...J,parentRigidBody:this,simulation:this._simulation}):this._createAndAddPendingChildCollider(J)}createAndAddChildCollidersToSimulation(J){let Z=[];return J.forEach((Y)=>{Z.push(this.createAndAddChildCollider(Y))}),Z}getCollidersByTag(J){let Z=[];for(let Y of this._colliders)if(Y.tag===J)Z.push(Y);return Z}linkCollider(J){if(this._requireNotRemoved(),J.parentRigidBody!==this)throw new Error("RigidBody.linkCollider(): Collider cannot be linked because it is not a child of this rigid body!");this._colliders.add(J)}lockAllRotations(){this._requireNotRemoved(),this.setEnabledRotations({x:!1,y:!1,z:!1})}lockAllPositions(){this._requireNotRemoved(),this.setEnabledPositions({x:!1,y:!1,z:!1})}removeFromSimulation(){if(this._requireNotRemoved(),!this._rigidBody)throw new Error("RigidBody.removeFromSimulation(): Rigid body does not exist in the simulation!");this._colliders.forEach((J)=>{J.removeFromSimulation()}),this._simulation.removeRawRigidBody(this._rigidBody),this._simulation=void 0,this._rigidBody=void 0}unlinkCollider(J){if(this._requireNotRemoved(),!J.isRemoved)throw new Error("RigidBody.unlinkCollider(): Collider is still simulated and therefore cannot be unlinked from this rigid body!");this._colliders.delete(J)}resetAngularVelocity(){this._requireNotRemoved(),this._requireCreated(),this.setAngularVelocity({x:0,y:0,z:0})}resetForces(){this._requireNotRemoved(),this._requireCreated(),this._rigidBody.resetForces(!this._explicitSleep)}resetLinearVelocity(){this._requireNotRemoved(),this._requireCreated(),this.setLinearVelocity({x:0,y:0,z:0})}resetTorques(){this._requireNotRemoved(),this._requireCreated(),this._rigidBody.resetTorques(!this._explicitSleep)}sleep(){this._requireNotRemoved(),this.setSleeping(!0)}wakeUp(){this._requireNotRemoved(),this.setSleeping(!1)}_applyRigidBodyOptions(J){[["additionalMass",this.setAdditionalMass.bind(this)],["additionalMassProperties",this.setAdditionalMassProperties.bind(this)],["additionalSolverIterations",this.setAdditionalSolverIterations.bind(this)],["angularDamping",this.setAngularDamping.bind(this)],["angularVelocity",this.setAngularVelocity.bind(this)],["dominanceGroup",this.setDominanceGroup.bind(this)],["ccdEnabled",this.setCcdEnabled.bind(this)],["enabled",this.setEnabled.bind(this)],["enabledPositions",this.setEnabledPositions.bind(this)],["enabledRotations",this.setEnabledRotations.bind(this)],["gravityScale",this.setGravityScale.bind(this)],["linearDamping",this.setLinearDamping.bind(this)],["linearVelocity",this.setLinearVelocity.bind(this)],["position",this.setPosition.bind(this)],["rotation",this.setRotation.bind(this)],["sleeping",this.setSleeping.bind(this)],["softCcdPrediction",this.setSoftCcdPrediction.bind(this)]].forEach(([Y,X])=>{if(J[Y]!==void 0)X.call(this,J[Y])})}_autoAddToSimulation(J){if(J.colliders)this._createAndAddPendingChildColliders(J.colliders);if(J.simulation)this.addToSimulation(J.simulation)}_createAndAddPendingChildCollider(J){this._requireNotRemoved(),this._requireNotSimulated();let Z=new m8(J);return this._colliders.add(Z),Z}_createAndAddPendingChildColliders(J){let Z=[];return J.forEach((Y)=>{Z.push(this._createAndAddPendingChildCollider(Y))}),Z}_createRigidBodyDesc(J){let Z=J.type??bR;return{["dynamic"]:()=>v0.RigidBodyDesc.dynamic(),["fixed"]:()=>v0.RigidBodyDesc.fixed(),["kinematic_position"]:()=>v0.RigidBodyDesc.kinematicPositionBased(),["kinematic_velocity"]:()=>v0.RigidBodyDesc.kinematicVelocityBased()}[Z]()}_requireCreated(){if(!this._rigidBody||!this._simulation)throw new Error("RigidBody._requireCreated(): Rigid body has not been created and therefore does not support the invoked method.")}_requireDynamic(){if(!this.isDynamic)throw new Error("RigidBody._requireDynamic(): Rigid body is not dynamic and therefore does not support the invoked method.")}_requireKinematic(){if(!this.isKinematic)throw new Error("RigidBody._requireKinematic(): Rigid body is not kinematic and therefore does not support the invoked method.")}_requireNotKinematicPositionBased(){if(this.isKinematicPositionBased)throw new Error("RigidBody._requireNotKinematicPositionBased(): Rigid body is kinematic position based and therefore does not support the invoked method.")}_requireNotRemoved(){if(!this._rigidBody&&!this._rigidBodyDesc)throw g}_requireNotSimulated(){if(this.isSimulated)throw new Error("RigidBody._requireNotSimulated(): Rigid body is simulated and therefore does not support the invoked method.")}_isEqualVectors(J,Z){return Math.abs(J.x-Z.x)<D6&&Math.abs(J.y-Z.y)<D6&&Math.abs(J.z-Z.z)<D6}_isEqualRotations(J,Z){return Math.abs(J.x-Z.x)<D6&&Math.abs(J.y-Z.y)<D6&&Math.abs(J.z-Z.z)<D6&&Math.abs(J.w-Z.w)<D6}_isNegligibleVector(J){return Math.abs(J.x)<D6&&Math.abs(J.y)<D6&&Math.abs(J.z)<D6}}var n0=16,nQ=n0-1,mR=n0**3,Tu=[{neighborOffset:[-1,0,0],generateVertices:(J,Z,Y)=>[J+0,Z+0,Y+0,J+0,Z+0,Y+1,J+0,Z+1,Y+0,J+0,Z+1,Y+0,J+0,Z+1,Y+1,J+0,Z+0,Y+1]},{neighborOffset:[1,0,0],generateVertices:(J,Z,Y)=>[J+1,Z+0,Y+0,J+1,Z+0,Y+1,J+1,Z+1,Y+0,J+1,Z+1,Y+0,J+1,Z+1,Y+1,J+1,Z+0,Y+1]},{neighborOffset:[0,-1,0],generateVertices:(J,Z,Y)=>[J+0,Z+0,Y+0,J+0,Z+0,Y+1,J+1,Z+0,Y+1,J+1,Z+0,Y+1,J+1,Z+0,Y+0,J+0,Z+0,Y+0]},{neighborOffset:[0,1,0],generateVertices:(J,Z,Y)=>[J+0,Z+1,Y+0,J+0,Z+1,Y+1,J+1,Z+1,Y+1,J+1,Z+1,Y+1,J+1,Z+1,Y+0,J+0,Z+1,Y+0]},{neighborOffset:[0,0,-1],generateVertices:(J,Z,Y)=>[J+0,Z+0,Y+0,J+1,Z+0,Y+0,J+0,Z+1,Y+0,J+0,Z+1,Y+0,J+1,Z+1,Y+0,J+1,Z+0,Y+0]},{neighborOffset:[0,0,1],generateVertices:(J,Z,Y)=>[J+0,Z+0,Y+1,J+1,Z+0,Y+1,J+0,Z+1,Y+1,J+0,Z+1,Y+1,J+1,Z+1,Y+1,J+1,Z+0,Y+1]}],uQ;((X)=>{X.DESPAWN="CHUNK.DESPAWN";X.SET_BLOCK="CHUNK.SET_BLOCK";X.SPAWN="CHUNK.SPAWN"})(uQ||={});class I8{_blocks;_originCoordinate;_requiresUpdate=!1;_rigidBody;_world;constructor(){this._blocks=new Uint8Array(mR)}get blocks(){return this._blocks}get requiresUpdate(){return this._requiresUpdate}get isSimulated(){return!!this._rigidBody}get isSpawned(){return!!this._originCoordinate&&!!this._world}get originCoordinate(){return this._originCoordinate}get world(){return this._world}static blockIndexToLocalCoordinate(J){return{x:J%n0,y:(J/n0|0)%n0,z:J/(n0*n0)|0}}static globalCoordinateToLocalCoordinate(J){return{x:J.x&n0-1,y:J.y&n0-1,z:J.z&n0-1}}static globalCoordinateToOriginCoordinate(J){return{x:J.x&~(n0-1),y:J.y&~(n0-1),z:J.z&~(n0-1)}}static isValidOriginCoordinate(J){return J.x%n0===0&&J.y%n0===0&&J.z%n0===0}spawn(J,Z){if(this.isSpawned){let{x:Y,y:X,z:F}=this.originCoordinate;throw new Error(`Chunk.spawn(): Chunk is already spawned at origin ${Y}, ${X}, ${F}!`)}if(!I8.isValidOriginCoordinate(Z))throw new Error(`Chunk.spawn(): Chunk coordinates must be divisible by ${n0}`);this._originCoordinate=Z,this._world=J,this._world.chunkLattice.registerChunk(this),this._requiresUpdate=!0}despawn(){if(!this.isSpawned)throw new Error("Chunk.despawn(): Chunk has not been spawned and cannot be despawned!");this._world.eventRouter.emit("CHUNK.DESPAWN",{chunk:this}),this._removeFromSimulation(),this._world.chunkLattice.unregisterChunk(this),this._originCoordinate=void 0,this._world=void 0}getBlockId(J){return this._blocks[this._getIndex(J)]}hasBlock(J){return this._blocks[this._getIndex(J)]!==0}setBlock(J,Z){if(!this._isValidLocalCoordinate(J))throw new Error("Chunk.setBlock(): Block local coordinate is out of bounds");if(this._blocks[this._getIndex(J)]===Z)return;if(this._blocks[this._getIndex(J)]=Z,this.isSpawned&&this.isSimulated)this._world.eventRouter.emit("CHUNK.SET_BLOCK",{chunk:this,globalCoordinate:this._getGlobalCoordinate(J),localCoordinate:J,blockTypeId:Z});this._requiresUpdate=!0}update(){if(!this._requiresUpdate)return;if(!this.isSpawned)throw new Error("Chunk.update(): Chunk is not spawned and cannot be updated.");let J=!this._rigidBody,Z=this._world.simulation;if(this._removeFromSimulation(),this._rigidBody=new r9({type:"fixed",position:this._originCoordinate,simulation:this._world.simulation}),this._meshColliders().map(([Y,X])=>{if(!Y.isSimulated)Y.addToSimulation(Z,this._rigidBody);Z.colliderMap.setColliderBlockType(Y,X)}),this._requiresUpdate=!1,J)this._world.eventRouter.emit("CHUNK.SPAWN",{chunk:this})}serialize(){return t.serializeChunk(this)}_meshColliders(){if(!this._world)throw new Error("Chunk._meshColliders(): Chunk is not spawned and cannot be meshed.");let J=new Map,Z=[];for(let X=0;X<mR;X++){if(this._blocks[X]===0)continue;let F=this._blocks[X],K=this._world.blockTypeRegistry.getBlockType(F),{x:$,y:Q,z:W}=I8.blockIndexToLocalCoordinate(X);if(!K.isMeshable){let V=K.createCollider();V.setRelativePosition({x:$,y:Q,z:W}),Z.push([V,K]);continue}let G=J.get(K)??{indices:[],vertices:[]};J.set(K,G);for(let V of Tu){let[O,v,w]=V.neighborOffset,H={x:$+O,y:Q+v,z:W+w},N=this._getGlobalCoordinate(H),q=this._world.chunkLattice.getBlockType(N);if(q&&!q.isLiquid)continue;let M=G.indices.length;G.indices.push(M,M+1,M+2,M+3,M+4,M+5),G.vertices.push(...V.generateVertices($,Q,W))}}let Y=[];return J.forEach((X,F)=>{if(!X.indices.length)return;let K=F.createCollider(new Uint32Array(X.indices),new Float32Array(X.vertices));Y.push([K,F])}),[...Z,...Y]}_removeFromSimulation(){if(!this._rigidBody||!this._world)return;this._rigidBody.removeFromSimulation(),this._rigidBody=void 0}_getGlobalCoordinate(J){if(!this.originCoordinate)throw new Error("Chunk._getGlobalCoordinate(): Chunk is not spawned, calculating global coordinate is impossible.");return{x:this.originCoordinate.x+J.x,y:this.originCoordinate.y+J.y,z:this.originCoordinate.z+J.z}}_getIndex(J){return J.x+n0*(J.y+n0*J.z)}_isValidLocalCoordinate(J){return J.x>=0&&J.x<=nQ&&J.y>=0&&J.y<=nQ&&J.z>=0&&J.z<=nQ}}class Y7{_chunks=new Map;_world;constructor(J){this._world=J}registerChunk(J){if(!J.isSpawned)throw new Error("ChunkLattice.registerChunk(): Chunk is not spawned.");if(this.hasChunk(J.originCoordinate)){let{x:Z,y:Y,z:X}=J.originCoordinate;throw new Error(`ChunkLattice.registerChunk(): Chunk exists at origin (${Z}, ${Y}, ${X}), despawn the current chunk before registering another at the same origin.`)}if(J.world.id!==this._world.id)throw new Error("ChunkLattice.registerChunk(): Chunk world does not match lattice world.");this._chunks.set(this._getChunkKey(J.originCoordinate),J)}unregisterChunk(J){if(!J.isSpawned)throw new Error("ChunkLattice.unregisterChunk(): Chunk is not spawned.");if(J.world.id!==this._world.id)throw new Error("ChunkLattice.unregisterChunk(): Chunk world does not match lattice world.");this._chunks.delete(this._getChunkKey(J.originCoordinate))}getBlockId(J){let Z=this.getChunk(I8.globalCoordinateToOriginCoordinate(J));if(!Z)return 0;return Z.getBlockId(I8.globalCoordinateToLocalCoordinate(J))}getBlockType(J){let Z=this.getBlockId(J);return Z?this._world.blockTypeRegistry.getBlockType(Z):null}getChunk(J){if(!I8.isValidOriginCoordinate(J))throw new Error(`ChunkLattice.getChunk(): Chunk coordinates must be divisible by CHUNK_SIZE (${n0})`);return this._chunks.get(this._getChunkKey(J))}getAllChunks(){return Array.from(this._chunks.values())}hasBlock(J){let Z=this.getChunk(I8.globalCoordinateToOriginCoordinate(J));if(!Z)return!1;return Z.hasBlock(I8.globalCoordinateToLocalCoordinate(J))}hasChunk(J){return this._chunks.has(this._getChunkKey(J))}setBlock(J,Z){let Y=I8.globalCoordinateToLocalCoordinate(J),X=I8.globalCoordinateToOriginCoordinate(J),F=this.getChunk(X);if(!F)F=new I8,F.spawn(this._world,X);F.setBlock(Y,Z)}updateChunks(){this._chunks.forEach((J)=>{if(J.requiresUpdate)J.update()})}_getChunkKey(J){return`${J.x},${J.y},${J.z}`}}var gR={type:"dynamic",softCcdPrediction:1},AR=0.0025000000000000005,iR=Math.cos(0.005),dQ;((v)=>{v.DESPAWN="ENTITY.DESPAWN";v.SET_MODEL_ANIMATIONS_PLAYBACK_RATE="ENTITY.SET_MODEL_ANIMATIONS_PLAYBACK_RATE";v.SET_MODEL_HIDDEN_NODES="ENTITY.SET_MODEL_HIDDEN_NODES";v.SET_OPACITY="ENTITY.SET_OPACITY";v.SET_PARENT="ENTITY.SET_PARENT";v.SET_TINT_COLOR="ENTITY.SET_TINT_COLOR";v.SPAWN="ENTITY.SPAWN";v.START_MODEL_LOOPED_ANIMATIONS="ENTITY.START_MODEL_LOOPED_ANIMATIONS";v.START_MODEL_ONESHOT_ANIMATIONS="ENTITY.START_MODEL_ONESHOT_ANIMATIONS";v.STOP_MODEL_ANIMATIONS="ENTITY.STOP_MODEL_ANIMATIONS";v.UPDATE_POSITION="ENTITY.UPDATE_POSITION";v.UPDATE_ROTATION="ENTITY.UPDATE_ROTATION"})(dQ||={});class J8 extends r9{onBlockCollision;onBlockContactForce;onEntityCollision;onEntityContactForce;onSpawn;onDespawn;onTick;_id;_blockHalfExtents;_blockTextureUri;_controller;_modelAnimationsPlaybackRate=1;_modelHiddenNodes;_modelLoopedAnimations;_modelOneshotAnimations;_modelScale;_modelUri;_name;_opacity;_parent;_parentNodeName;_tag;_tintColor;_lastUpdatedPosition={x:0,y:0,z:0};_lastUpdatedRotation={x:0,y:0,z:0,w:1};_lastParentlessType="dynamic";_world;constructor(J){if(!J.blockTextureUri===!J.modelUri)throw new Error("Entity.constructor(): Entity data must include a blockTextureUri or modelUri, but not both.");if(J.blockTextureUri&&!J.blockHalfExtents)throw new Error("Entity.constructor(): Block entity must have blockHalfExtents!");if(J.parent&&!J.parent.isSpawned)throw new Error("Entity.constructor(): Parent entity must be spawned before child entity!");if(J.parent?.modelUri&&J.parentNodeName&&!F6.instance.modelHasNode(J.parent.modelUri,J.parentNodeName))throw new Error(`Entity.constructor(): Parent node name ${J.parentNodeName} not found in parent model ${J.parent.modelUri}!`);super(J.rigidBodyOptions??gR);if(this._blockHalfExtents=J.blockHalfExtents,this._blockTextureUri=J.blockTextureUri,this._modelAnimationsPlaybackRate=J.modelAnimationsPlaybackRate??1,this._modelHiddenNodes=new Set(J.modelHiddenNodes??[]),this._modelLoopedAnimations=new Set(J.modelLoopedAnimations??[]),this._modelOneshotAnimations=new Set,this._modelScale=J.modelScale,this._modelUri=J.modelUri,this._name=J.name??"Nameless",this._opacity=J.opacity??1,this._parent=J.parent,this._parentNodeName=J.parentNodeName,this._tag=J.tag,this._tintColor=J.tintColor,J.controller)this.setController(J.controller)}get id(){return this._id}get blockHalfExtents(){return this._blockHalfExtents}get blockTextureUri(){return this._blockTextureUri}get controller(){return this._controller}get height(){return this.isModelEntity?F6.instance.getHeight(this._modelUri)*(this._modelScale??1):this._blockHalfExtents.y*2}get modelAnimationsPlaybackRate(){return this._modelAnimationsPlaybackRate}get modelHiddenNodes(){return this._modelHiddenNodes}get modelLoopedAnimations(){return this._modelLoopedAnimations}get modelScale(){return this._modelScale}get modelUri(){return this._modelUri}get name(){return this._name}get opacity(){return this._opacity}get parent(){return this._parent}get parentNodeName(){return this._parentNodeName}get tag(){return this._tag}get tintColor(){return this._tintColor}get isBlockEntity(){return!!this._blockTextureUri}get isModelEntity(){return!!this._modelUri}get isSpawned(){return!!this._world}get world(){return this._world}spawn(J,Z,Y){if(this.isSpawned)return console.warn(`Entity.spawn(): Entity ${this._name} is already spawned with id ${this._id}!`);if(!this.isSimulated)this.addToSimulation(J.simulation);if(this._blockTextureUri&&this._blockHalfExtents&&this.numColliders===0)this.addChildColliderToSimulation(new m8(m8.optionsFromBlockHalfExtents(this._blockHalfExtents)));if(this._modelUri&&this.numColliders===0)this.addChildColliderToSimulation(new m8(m8.optionsFromModelUri(this._modelUri,this._modelScale)));if(this.colliders.forEach((X)=>{if(this.onBlockCollision||this.onEntityCollision)X.enableCollisionEvents(!0);if(this.onBlockContactForce||this.onEntityContactForce)X.enableContactForceEvents(!0);if(X6.isDefaultCollisionGroups(X.collisionGroups))X.setCollisionGroups({belongsTo:[X.isSensor?4:2],collidesWith:[65535]})}),this.setPosition(Z),Y)this.setRotation(Y);if(this._id=J.entityManager.registerEntity(this),this._world=J,this.onSpawn)this.onSpawn(this);if(this._controller)this._controller.spawn(this);if(this._parent)this.setParent(this._parent,this._parentNodeName,Z,Y);this.colliders.forEach((X)=>{J.simulation.colliderMap.setColliderEntity(X,this)}),this._world.eventRouter.emit("ENTITY.SPAWN",{entity:this})}despawn(){if(!this.isSpawned)return console.warn(`Entity.despawn(): Entity ${this._name} is not been spawned and cannot be despawned!`);this._world.entityManager.getEntityChildren(this).forEach((Z)=>{Z.despawn()});let{eventRouter:J}=this._world;if(this.onDespawn)this.onDespawn(this);if(this._controller)this._controller.detach(this),this._controller.despawn(this);if(J.emit("ENTITY.DESPAWN",{entity:this}),this.isSimulated)this.removeFromSimulation();this._world.entityManager.unregisterEntity(this),this._world.audioManager.unregisterEntityAttachedAudios(this),this._world.lightManager.despawnEntityAttachedLights(this),this._world.sceneUIManager.unloadEntityAttachedSceneUIs(this),this._id=void 0,this._world=void 0}setModelAnimationsPlaybackRate(J){if(this._requireSpawned(),!this.isModelEntity||this._modelAnimationsPlaybackRate===J)return;this._modelAnimationsPlaybackRate=J,this._world.eventRouter.emit("ENTITY.SET_MODEL_ANIMATIONS_PLAYBACK_RATE",{entity:this,playbackRate:J})}setController(J){if(this._controller===J)return;if(this._controller)this._controller.detach(this);if(this._controller=J,this._controller)this._controller.attach(this)}setModelHiddenNodes(J){this._requireSpawned(),this._modelHiddenNodes=new Set(J.map((Z)=>Z.toLowerCase())),this._world.eventRouter.emit("ENTITY.SET_MODEL_HIDDEN_NODES",{entity:this,modelHiddenNodes:this._modelHiddenNodes})}setOpacity(J){if(this._requireSpawned(),this._opacity===J)return;this._opacity=J,this._world.eventRouter.emit("ENTITY.SET_OPACITY",{entity:this,opacity:J})}setParent(J,Z,Y,X){if(this._requireSpawned(),J&&!J.isSpawned)throw new Error("Entity.setParent(): Parent entity is not spawned, cannot set parent!");if(!this._parent&&J)this._lastParentlessType=this.type;if(this._parent=J,this._parentNodeName=Z,this.colliders.forEach((F)=>F.setEnabled(!J)),this.setType(!J?this._lastParentlessType:"kinematic_velocity"),this.setPosition(Y??{x:0,y:0,z:0}),this.setRotation(X??{x:0,y:0,z:0,w:1}),!this.isKinematicPositionBased)this.resetAngularVelocity(),this.resetForces(),this.resetLinearVelocity(),this.resetTorques();this._world.eventRouter.emit("ENTITY.SET_PARENT",{entity:this,parent:J,parentNodeName:Z})}setTintColor(J){if(this._requireSpawned(),!J&&!this._tintColor||J&&this._tintColor&&J.r===this._tintColor.r&&J.g===this._tintColor.g&&J.b===this._tintColor.b)return;this._tintColor=J,this._world.eventRouter.emit("ENTITY.SET_TINT_COLOR",{entity:this,tintColor:J})}startModelLoopedAnimations(J){if(this._requireSpawned(),!this.isModelEntity)return;if(!J.some((Z)=>!this._modelLoopedAnimations.has(Z)))return;J.forEach((Z)=>{this._modelLoopedAnimations.add(Z)}),this._world.eventRouter.emit("ENTITY.START_MODEL_LOOPED_ANIMATIONS",{entity:this,animations:new Set(J)})}startModelOneshotAnimations(J){if(this._requireSpawned(),!this.isModelEntity)return;J.forEach((Z)=>{this._modelOneshotAnimations.add(Z)}),this._world.eventRouter.emit("ENTITY.START_MODEL_ONESHOT_ANIMATIONS",{entity:this,animations:new Set(J)})}stopModelAnimations(J){if(this._requireSpawned(),!this.isModelEntity)return;if(!J.some((Z)=>this._modelLoopedAnimations.has(Z))&&!J.some((Z)=>this._modelOneshotAnimations.has(Z)))return;J.forEach((Z)=>{this._modelLoopedAnimations.delete(Z),this._modelOneshotAnimations.delete(Z)}),this._world.eventRouter.emit("ENTITY.STOP_MODEL_ANIMATIONS",{entity:this,animations:new Set(J)})}serialize(){return t.serializeEntity(this)}tick(J){if(this.onTick)this.onTick(this,J);if(this._controller)this._controller.tick(this,J)}checkAndEmitUpdates(){this._requireSpawned();let J=this.position,Z=this.rotation;if(this._rotationExceedsThreshold(Z,this._lastUpdatedRotation))this._lastUpdatedRotation=Z,this._world.eventRouter.emit("ENTITY.UPDATE_ROTATION",{entity:this,rotation:Z});if(this._positionExceedsThreshold(J,this._lastUpdatedPosition))this._lastUpdatedPosition=J,this._world.eventRouter.emit("ENTITY.UPDATE_POSITION",{entity:this,position:J})}_requireSpawned(){if(!this.isSpawned)throw new Error(`Entity._requireSpawned(): Entity ${this._name} is not spawned!`)}_positionExceedsThreshold(J,Z){let Y=J.x-Z.x,X=J.y-Z.y,F=J.z-Z.z;return Y*Y+X*X+F*F>AR}_rotationExceedsThreshold(J,Z){return Math.abs(J.x*Z.x+J.y*Z.y+J.z*Z.z+J.w*Z.w)<iR}}class X7 extends z9{autoCancelMouseLeftClick=!0;canWalk=()=>!0;canRun=()=>!0;canJump=()=>!0;idleLoopedAnimations=["idle_upper","idle_lower"];interactOneshotAnimations=["simple_interact"];jumpOneshotAnimations=["jump_loop"];jumpVelocity=10;runLoopedAnimations=["run_upper","run_lower"];runVelocity=8;sticksToPlatforms=!0;walkLoopedAnimations=["walk_upper","walk_lower"];walkVelocity=4;_stepAudio;_groundContactCount=0;_platform;constructor(J={}){super();this.autoCancelMouseLeftClick=J.autoCancelMouseLeftClick??this.autoCancelMouseLeftClick,this.jumpVelocity=J.jumpVelocity??this.jumpVelocity,this.runVelocity=J.runVelocity??this.runVelocity,this.walkVelocity=J.walkVelocity??this.walkVelocity,this.canWalk=J.canWalk??this.canWalk,this.canRun=J.canRun??this.canRun,this.canJump=J.canJump??this.canJump,this.sticksToPlatforms=J.sticksToPlatforms??this.sticksToPlatforms}get isGrounded(){return this._groundContactCount>0}get isOnPlatform(){return!!this._platform}get platform(){return this._platform}attach(J){this._stepAudio=new Z5({uri:"audio/sfx/step/stone/stone-step-04.mp3",loop:!0,volume:0.1,attachedToEntity:J}),J.lockAllRotations()}spawn(J){if(!J.isSpawned)throw new Error("PlayerEntityController.createColliders(): Entity is not spawned!");J.createAndAddChildCollider({shape:"cylinder",radius:0.23,halfHeight:0.125,collisionGroups:{belongsTo:[4],collidesWith:[1,2]},isSensor:!0,relativePosition:{x:0,y:-0.75,z:0},tag:"groundSensor",onCollision:(Z,Y)=>{if(this._groundContactCount+=Y?1:-1,!this._groundContactCount)J.startModelOneshotAnimations(this.jumpOneshotAnimations);else J.stopModelAnimations(this.jumpOneshotAnimations);if(!(Z instanceof J8)||!Z.isKinematic)return;if(Y&&this.sticksToPlatforms)this._platform=Z;else if(Z===this._platform&&!Y)this._platform=void 0}}),J.createAndAddChildCollider({shape:"capsule",halfHeight:0.31,radius:0.38,collisionGroups:{belongsTo:[4],collidesWith:[1,2]},friction:0,frictionCombineRule:1,tag:"wallCollider"})}tickWithPlayerInput(J,Z,Y,X){if(!J.isSpawned||!J.world)return;super.tickWithPlayerInput(J,Z,Y,X);let{w:F,a:K,s:$,d:Q,sp:W,sh:G,ml:V}=Z,{yaw:O}=Y,v=J.linearVelocity,w={x:0,y:0,z:0},H=G;if(this.isGrounded&&(F||K||$||Q)){if(H)J.stopModelAnimations(Array.from(J.modelLoopedAnimations).filter((R)=>!this.runLoopedAnimations.includes(R))),J.startModelLoopedAnimations(this.runLoopedAnimations),this._stepAudio?.setPlaybackRate(0.75);else J.stopModelAnimations(Array.from(J.modelLoopedAnimations).filter((R)=>!this.walkLoopedAnimations.includes(R))),J.startModelLoopedAnimations(this.walkLoopedAnimations),this._stepAudio?.setPlaybackRate(0.51);this._stepAudio?.play(J.world,!this._stepAudio?.isPlaying)}else this._stepAudio?.pause(),J.stopModelAnimations(Array.from(J.modelLoopedAnimations).filter((R)=>!this.idleLoopedAnimations.includes(R))),J.startModelLoopedAnimations(this.idleLoopedAnimations);if(V)J.startModelOneshotAnimations(this.interactOneshotAnimations),Z.ml=!this.autoCancelMouseLeftClick;if(H&&this.canRun(this)||!H&&this.canWalk(this)){let R=H?this.runVelocity:this.walkVelocity;if(F)w.x-=R*Math.sin(O),w.z-=R*Math.cos(O);if($)w.x+=R*Math.sin(O),w.z+=R*Math.cos(O);if(K)w.x-=R*Math.cos(O),w.z+=R*Math.sin(O);if(Q)w.x+=R*Math.cos(O),w.z-=R*Math.sin(O);let P=Math.sqrt(w.x*w.x+w.z*w.z);if(P>R){let x=R/P;w.x*=x,w.z*=x}}if(W&&this.canJump(this)){if(this.isGrounded&&v.y>-0.001&&v.y<=3)w.y=this.jumpVelocity}let N=this._platform?this._platform.linearVelocity:{x:0,y:0,z:0},q={x:w.x-v.x+N.x,y:w.y+N.y,z:w.z-v.z+N.z};if(!(this.runVelocity>0&&Math.abs(v.x)>this.runVelocity||this.jumpVelocity>0&&Math.abs(v.y)>this.jumpVelocity||this.runVelocity>0&&Math.abs(v.z)>this.runVelocity)||this.isOnPlatform){if(Object.values(q).some((R)=>R!==0)){let R=J.mass;J.applyImpulse({x:q.x*R,y:q.y*R,z:q.z*R})}}if(O!==void 0){let R=O/2;J.setRotation({x:0,y:Math.fround(Math.sin(R)),z:0,w:Math.fround(Math.cos(R))})}}}class H9 extends J8{player;constructor(J){super(J);if(this.player=J.player,!J.controller)this.setController(new X7)}tick(J){if(!this.isSpawned||!this.world||!this.controller)return;let{input:Z,camera:Y}=this.player;this.controller.tickWithPlayerInput(this,Z,Y.orientation,J),super.tick(J)}}class F7{_entities=new Map;_nextEntityId=1;_world;constructor(J){this._world=J}get world(){return this._world}registerEntity(J){if(J.id!==void 0)throw new Error(`EntityManager.registerEntity(): Entity ${J.name} is already assigned the id ${J.id}!`);let Z=this._nextEntityId;return this._entities.set(Z,J),this._nextEntityId++,Z}unregisterEntity(J){if(J.id===void 0)throw new Error(`EntityManager.unregisterEntity(): Entity ${J.name} is not assigned an id!`);this._entities.delete(J.id)}getAllEntities(){return Array.from(this._entities.values())}getAllPlayerEntities(){let J=[];return this._entities.forEach((Z)=>{if(Z instanceof H9)J.push(Z)}),J}getPlayerEntitiesByPlayer(J){let Z=[];return this._entities.forEach((Y)=>{if(Y instanceof H9&&Y.player===J)Z.push(Y)}),Z}getEntity(J){return this._entities.get(J)}getEntitiesByTag(J){let Z=[];return this._entities.forEach((Y)=>{if(Y.tag===J)Z.push(Y)}),Z}getEntitiesByTagSubstring(J){let Z=[];return this._entities.forEach((Y)=>{if(Y.tag?.includes(J))Z.push(Y)}),Z}getEntityChildren(J){let Z=[];return this._entities.forEach((Y)=>{if(Y.parent===J)Z.push(Y)}),Z}tickEntities(J){this._entities.forEach((Z)=>{Z.tick(J)})}checkAndEmitUpdates(){this._entities.forEach((J)=>{if(!J.isSpawned)return;J.checkAndEmitUpdates()})}}class K7{_lights=new Map;_nextLightId=1;_world;constructor(J){this._world=J}get world(){return this._world}despawnEntityAttachedLights(J){this.getAllEntityAttachedLights(J).forEach((Z)=>{Z.despawn()})}getAllLights(){return Array.from(this._lights.values())}getAllEntityAttachedLights(J){return this.getAllLights().filter((Z)=>Z.attachedToEntity===J)}registerLight(J){if(J.id!==void 0)return J.id;let Z=this._nextLightId;return this._lights.set(Z,J),this._nextLightId++,Z}unregisterLight(J){if(J.id===void 0)return;this._lights.delete(J.id)}}var yR;((Y)=>{Y[Y.POINTLIGHT=0]="POINTLIGHT";Y[Y.SPOTLIGHT=1]="SPOTLIGHT"})(yR||={});var sQ;((w)=>{w.DESPAWN="LIGHT.DESPAWN";w.SET_ANGLE="LIGHT.SET_ANGLE";w.SET_ATTACHED_TO_ENTITY="LIGHT.SET_ATTACHED_TO_ENTITY";w.SET_COLOR="LIGHT.SET_COLOR";w.SET_DISTANCE="LIGHT.SET_DISTANCE";w.SET_INTENSITY="LIGHT.SET_INTENSITY";w.SET_OFFSET="LIGHT.SET_OFFSET";w.SET_PENUMBRA="LIGHT.SET_PENUMBRA";w.SET_POSITION="LIGHT.SET_POSITION";w.SET_TRACKED_ENTITY="LIGHT.SET_TRACKED_ENTITY";w.SET_TRACKED_POSITION="LIGHT.SET_TRACKED_POSITION";w.SET_TYPE="LIGHT.SET_TYPE";w.SPAWN="LIGHT.SPAWN"})(sQ||={});class aQ{_id;_angle;_attachedToEntity;_color;_distance;_intensity;_offset;_penumbra;_position;_trackedEntity;_trackedPosition;_type;_world;constructor(J){if(!!J.attachedToEntity===!!J.position)throw new Error("Either attachedToEntity or position must be set, but not both");this._angle=J.angle,this._attachedToEntity=J.attachedToEntity,this._color=J.color??{r:255,g:255,b:255},this._distance=J.distance,this._intensity=J.intensity??1,this._offset=J.offset,this._penumbra=J.penumbra,this._position=J.position,this._trackedEntity=J.trackedEntity,this._trackedPosition=J.trackedPosition,this._type=J.type??0}get id(){return this._id}get angle(){return this._angle}get attachedToEntity(){return this._attachedToEntity}get color(){return this._color}get distance(){return this._distance}get intensity(){return this._intensity}get isSpawned(){return this._id!==void 0}get offset(){return this._offset}get penumbra(){return this._penumbra}get position(){return this._position}get trackedEntity(){return this._trackedEntity}get trackedPosition(){return this._trackedPosition}get type(){return this._type}get world(){return this._world}setAngle(J){if(this._angle===J)return;if(this._angle=J,this.isSpawned)this._world.eventRouter.emit("LIGHT.SET_ANGLE",{light:this,angle:J})}setAttachedToEntity(J){if(!J.isSpawned)throw new Error(`Light.setAttachedToEntity(): Entity ${J.id} is not spawned!`);if(this._attachedToEntity===J)return;if(this._attachedToEntity=J,this._position=void 0,this.isSpawned)this._world.eventRouter.emit("LIGHT.SET_ATTACHED_TO_ENTITY",{light:this,entity:J})}setColor(J){if(this._color.r===J.r&&this._color.g===J.g&&this._color.b===J.b)return;if(this._color=J,this.isSpawned)this._world.eventRouter.emit("LIGHT.SET_COLOR",{light:this,color:J})}setDistance(J){if(this._distance===J)return;if(this._distance=J,this.isSpawned)this._world.eventRouter.emit("LIGHT.SET_DISTANCE",{light:this,distance:J})}setIntensity(J){if(this._intensity===J)return;if(this._intensity=J,this.isSpawned)this._world.eventRouter.emit("LIGHT.SET_INTENSITY",{light:this,intensity:J})}setOffset(J){if(this._offset===J)return;if(this._offset=J,this.isSpawned)this._world.eventRouter.emit("LIGHT.SET_OFFSET",{light:this,offset:J})}setPenumbra(J){if(this._penumbra===J)return;if(this._penumbra=J,this.isSpawned)this._world.eventRouter.emit("LIGHT.SET_PENUMBRA",{light:this,penumbra:J})}setPosition(J){if(this._position===J)return;if(this._position=J,this._attachedToEntity=void 0,this.isSpawned)this._world.eventRouter.emit("LIGHT.SET_POSITION",{light:this,position:J})}setTrackedEntity(J){if(!J.isSpawned)throw new Error(`Light.setTrackedEntity(): Entity ${J.id} is not spawned!`);if(this._trackedEntity===J)return;if(this._trackedEntity=J,this._trackedPosition=void 0,this.isSpawned)this._world.eventRouter.emit("LIGHT.SET_TRACKED_ENTITY",{light:this,entity:J})}setTrackedPosition(J){if(this._trackedPosition===J)return;if(this._trackedPosition=J,this._trackedEntity=void 0,this.isSpawned)this._world.eventRouter.emit("LIGHT.SET_TRACKED_POSITION",{light:this,position:J})}despawn(){if(!this.isSpawned||!this._world)return;this._world.lightManager.unregisterLight(this),this._world.eventRouter.emit("LIGHT.DESPAWN",{light:this}),this._id=void 0,this._world=void 0}spawn(J){if(this.isSpawned)return;this._id=J.lightManager.registerLight(this),this._world=J,J.eventRouter.emit("LIGHT.SPAWN",{light:this})}serialize(){return t.serializeLight(this)}}var nR;((Y)=>{Y[Y.FIRST_PERSON=0]="FIRST_PERSON";Y[Y.THIRD_PERSON=1]="THIRD_PERSON"})(nR||={});var oQ;((w)=>{w.LOOK_AT_ENTITY="PLAYER_CAMERA.LOOK_AT_ENTITY";w.LOOK_AT_POSITION="PLAYER_CAMERA.LOOK_AT_POSITION";w.SET_ATTACHED_TO_ENTITY="PLAYER_CAMERA.SET_ATTACHED_TO_ENTITY";w.SET_ATTACHED_TO_POSITION="PLAYER_CAMERA.SET_ATTACHED_TO_POSITION";w.SET_FILM_OFFSET="PLAYER_CAMERA.SET_FILM_OFFSET";w.SET_FORWARD_OFFSET="PLAYER_CAMERA.SET_FORWARD_OFFSET";w.SET_FOV="PLAYER_CAMERA.SET_FOV";w.SET_MODEL_HIDDEN_NODES="PLAYER_CAMERA.SET_MODEL_HIDDEN_NODES";w.SET_MODE="PLAYER_CAMERA.SET_MODE";w.SET_OFFSET="PLAYER_CAMERA.SET_OFFSET";w.SET_TRACKED_ENTITY="PLAYER_CAMERA.SET_TRACKED_ENTITY";w.SET_TRACKED_POSITION="PLAYER_CAMERA.SET_TRACKED_POSITION";w.SET_ZOOM="PLAYER_CAMERA.SET_ZOOM"})(oQ||={});class $7{player;_attachedToEntity;_attachedToPosition;_filmOffset=0;_forwardOffset=0;_fov=75;_modelHiddenNodes=new Set;_mode=1;_offset={x:0,y:0,z:0};_orientation={pitch:0,yaw:0};_trackedEntity;_trackedPosition;_zoom=1;constructor(J){this.player=J}get attachedToEntity(){return this._attachedToEntity}get attachedToPosition(){return this._attachedToPosition}get facingDirection(){return{x:-Math.sin(this._orientation.yaw)*Math.cos(this._orientation.pitch),y:Math.sin(this._orientation.pitch),z:-Math.cos(this._orientation.yaw)*Math.cos(this._orientation.pitch)}}get filmOffset(){return this._filmOffset}get forwardOffset(){return this._forwardOffset}get fov(){return this._fov}get modelHiddenNodes(){return this._modelHiddenNodes}get mode(){return this._mode}get offset(){return this._offset}get orientation(){return this._orientation}get trackedEntity(){return this._trackedEntity}get trackedPosition(){return this._trackedPosition}get zoom(){return this._zoom}lookAtEntity(J){this._requirePlayerWorld(),this.player.world.eventRouter.emit("PLAYER_CAMERA.LOOK_AT_ENTITY",{playerCamera:this,entity:J})}lookAtPosition(J){this._requirePlayerWorld(),this.player.world.eventRouter.emit("PLAYER_CAMERA.LOOK_AT_POSITION",{playerCamera:this,position:J})}setAttachedToEntity(J){if(this._requirePlayerWorld(),!J.isSpawned)throw new Error(`PlayerCamera.setAttachedToEntity(): Entity ${J.id} is not spawned!`);this._attachedToEntity=J,this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_ATTACHED_TO_ENTITY",{playerCamera:this,entity:J})}setAttachedToPosition(J){this._requirePlayerWorld(),this._attachedToPosition=J,this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_ATTACHED_TO_POSITION",{playerCamera:this,position:J})}setFilmOffset(J){this._requirePlayerWorld(),this._filmOffset=J,this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_FILM_OFFSET",{playerCamera:this,filmOffset:J})}setForwardOffset(J){this._requirePlayerWorld(),this._forwardOffset=J,this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_FORWARD_OFFSET",{playerCamera:this,forwardOffset:J})}setFov(J){this._requirePlayerWorld(),this._fov=J,this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_FOV",{playerCamera:this,fov:J})}setModelHiddenNodes(J){this._requirePlayerWorld(),this._modelHiddenNodes=new Set(J.map((Z)=>Z.toLowerCase())),this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_MODEL_HIDDEN_NODES",{playerCamera:this,modelHiddenNodes:this._modelHiddenNodes})}setMode(J){this._requirePlayerWorld(),this._mode=J,this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_MODE",{playerCamera:this,mode:J})}setOffset(J){this._requirePlayerWorld(),this._offset=J,this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_OFFSET",{playerCamera:this,offset:J})}setOrientationPitch(J){this._orientation.pitch=J}setOrientationYaw(J){this._orientation.yaw=J}setTrackedEntity(J){this._requirePlayerWorld(),this._trackedEntity=J,this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_TRACKED_ENTITY",{playerCamera:this,entity:J})}setTrackedPosition(J){this._requirePlayerWorld(),this._trackedPosition=J,this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_TRACKED_POSITION",{playerCamera:this,position:J})}setZoom(J){this._requirePlayerWorld(),this._zoom=J,this.player.world.eventRouter.emit("PLAYER_CAMERA.SET_ZOOM",{playerCamera:this,zoom:J})}serialize(){return t.serializePlayerCamera(this)}_requirePlayerWorld(){if(!this.player.world)throw new Error(`PlayerCamera._requirePlayerWorld(): Player ${this.player.id} is not in a world!`)}}var rQ;((X)=>{X.LOAD="PLAYER_UI.LOAD";X.LOCK_POINTER="PLAYER_UI.LOCK_POINTER";X.SEND_DATA="PLAYER_UI.SEND_DATA"})(rQ||={});class Q7{player;onData;constructor(J){this.player=J}load(J){if(!this.player.world)return;this.player.world.eventRouter.emit("PLAYER_UI.LOAD",{playerUI:this,htmlUri:J})}lockPointer(J){if(!this.player.world)return;this.player.world.eventRouter.emit("PLAYER_UI.LOCK_POINTER",{playerUI:this,lock:J})}sendData(J){if(!this.player.world)return;this.player.world.eventRouter.emit("PLAYER_UI.SEND_DATA",{playerUI:this,data:J})}}class tQ{_id;_attachedToEntity;_offset;_position;_state={};_templateId;_viewDistance;_world;constructor(J){if(!!J.attachedToEntity===!!J.position)throw new Error("Either attachedToEntity or position must be set, but not both");this._attachedToEntity=J.attachedToEntity,this._offset=J.offset,this._position=J.position,this._state=J.state??{},this._templateId=J.templateId,this._viewDistance=J.viewDistance}get id(){return this._id}get attachedToEntity(){return this._attachedToEntity}get isLoaded(){return this._id!==void 0}get offset(){return this._offset}get position(){return this._position}get state(){return this._state}get templateId(){return this._templateId}get viewDistance(){return this._viewDistance}get world(){return this._world}load(J){if(this.isLoaded)return;this._id=J.sceneUIManager.registerSceneUI(this),this._world=J,J.eventRouter.emit("SCENE_UI.LOAD",{sceneUI:this})}setAttachedToEntity(J){if(!J.isSpawned)throw new Error(`SceneUI.setAttachedToEntity(): Entity ${J.id} is not spawned!`);if(this._attachedToEntity===J)return;if(this._attachedToEntity=J,this._position=void 0,this.isLoaded)this._world.eventRouter.emit("SCENE_UI.SET_ATTACHED_TO_ENTITY",{sceneUI:this,entity:J})}setOffset(J){if(this._offset===J)return;if(this._offset=J,this.isLoaded)this._world.eventRouter.emit("SCENE_UI.SET_OFFSET",{sceneUI:this,offset:J})}setPosition(J){if(this._position===J)return;if(this._attachedToEntity=void 0,this._position=J,this.isLoaded)this._world.eventRouter.emit("SCENE_UI.SET_POSITION",{sceneUI:this,position:J})}setState(J){if(this._state={...this._state,...J},this.isLoaded)this._world.eventRouter.emit("SCENE_UI.SET_STATE",{sceneUI:this,state:this._state})}setViewDistance(J){if(this._viewDistance=J,this.isLoaded)this._world.eventRouter.emit("SCENE_UI.SET_VIEW_DISTANCE",{sceneUI:this,viewDistance:J})}unload(){if(!this.isLoaded||!this._world)return;this._world.sceneUIManager.unregisterSceneUI(this),this._world.eventRouter.emit("SCENE_UI.UNLOAD",{sceneUI:this}),this._id=void 0,this._world=void 0}serialize(){return t.serializeSceneUI(this)}}class G7{_colliderHandleBlockTypeMap=new Map;_colliderHandleCollisionCallbackMap=new Map;_colliderHandleEntityMap=new Map;_cleanupBlockTypeColliderHandles=new Set;_pendingCleanupBlockTypeColliderHandles=new Set;_cleanupCollisionCallbackColliderHandles=new Set;_pendingCleanupCollisionCallbackColliderHandles=new Set;_cleanupEntityColliderHandles=new Set;_pendingCleanupEntityColliderHandles=new Set;getColliderBlockType(J){return this._requireSimulatedCollider(J),this._colliderHandleBlockTypeMap.get(J.rawCollider.handle)}getColliderCollisionCallback(J){return this._requireSimulatedCollider(J),this._colliderHandleCollisionCallbackMap.get(J.rawCollider.handle)}getColliderEntity(J){return this._requireSimulatedCollider(J),this._colliderHandleEntityMap.get(J.rawCollider.handle)}getColliderHandleBlockType(J){return this._colliderHandleBlockTypeMap.get(J)}getColliderHandleCollisionCallback(J){return this._colliderHandleCollisionCallbackMap.get(J)}getColliderHandleEntity(J){return this._colliderHandleEntityMap.get(J)}removeColliderBlockType(J){this._requireSimulatedCollider(J),this.removeColliderHandleBlockType(J.rawCollider.handle)}removeColliderCollisionCallback(J){this._requireSimulatedCollider(J),this.removeColliderHandleCollisionCallback(J.rawCollider.handle)}removeColliderEntity(J){this._requireSimulatedCollider(J),this.removeColliderHandleEntity(J.rawCollider.handle)}removeColliderHandleBlockType(J){this._colliderHandleBlockTypeMap.delete(J)}removeColliderHandleCollisionCallback(J){this._colliderHandleCollisionCallbackMap.delete(J)}removeColliderHandleEntity(J){this._colliderHandleEntityMap.delete(J)}setColliderBlockType(J,Z){this._requireSimulatedCollider(J),this.setColliderHandleBlockType(J.rawCollider.handle,Z)}setColliderCollisionCallback(J,Z){this._requireSimulatedCollider(J),this.setColliderHandleCollisionCallback(J.rawCollider.handle,Z)}setColliderEntity(J,Z){this._requireSimulatedCollider(J),this.setColliderHandleEntity(J.rawCollider.handle,Z)}setColliderHandleBlockType(J,Z){this._colliderHandleBlockTypeMap.set(J,Z),this._cleanupBlockTypeColliderHandles.delete(J),this._pendingCleanupBlockTypeColliderHandles.delete(J)}setColliderHandleCollisionCallback(J,Z){this._colliderHandleCollisionCallbackMap.set(J,Z),this._cleanupCollisionCallbackColliderHandles.delete(J),this._pendingCleanupCollisionCallbackColliderHandles.delete(J)}setColliderHandleEntity(J,Z){this._colliderHandleEntityMap.set(J,Z),this._cleanupEntityColliderHandles.delete(J),this._pendingCleanupEntityColliderHandles.delete(J)}queueColliderHandleForCleanup(J){if(this._colliderHandleBlockTypeMap.has(J))this._pendingCleanupBlockTypeColliderHandles.add(J);if(this._colliderHandleCollisionCallbackMap.has(J))this._pendingCleanupCollisionCallbackColliderHandles.add(J);if(this._colliderHandleEntityMap.has(J))this._pendingCleanupEntityColliderHandles.add(J)}cleanup(){for(let J of this._cleanupBlockTypeColliderHandles)this._colliderHandleBlockTypeMap.delete(J);this._cleanupBlockTypeColliderHandles.clear();for(let J of this._cleanupCollisionCallbackColliderHandles)this._colliderHandleCollisionCallbackMap.delete(J);this._cleanupCollisionCallbackColliderHandles.clear();for(let J of this._cleanupEntityColliderHandles)this._colliderHandleEntityMap.delete(J);this._cleanupEntityColliderHandles.clear(),[[this._pendingCleanupBlockTypeColliderHandles,this._cleanupBlockTypeColliderHandles],[this._pendingCleanupCollisionCallbackColliderHandles,this._cleanupCollisionCallbackColliderHandles],[this._pendingCleanupEntityColliderHandles,this._cleanupEntityColliderHandles]].forEach(([J,Z])=>{for(let Y of J.keys())Z.add(Y);J.clear()})}_requireSimulatedCollider(J){if(!J.rawCollider)throw new Error("ColliderMap._requireSimulatedCollider(): Collider is not in the simulation.")}}var Su={x:0,y:-32,z:0},eQ=60;class W7{_colliderMap=new G7;_debugRaycastingEnabled=!1;_debugRenderingEnabled=!1;_rapierEventQueue;_rapierSimulation;_world;constructor(J,Z=eQ,Y=Su){this._rapierEventQueue=new v0.EventQueue(!0),this._rapierSimulation=new v0.World(Y),this._rapierSimulation.timestep=Math.fround(1/Z),this._world=J}get colliderMap(){return this._colliderMap}get isDebugRaycastingEnabled(){return this._debugRaycastingEnabled}get isDebugRenderingEnabled(){return this._debugRenderingEnabled}get gravity(){return this._rapierSimulation.gravity}get timestepS(){return this._rapierSimulation.timestep}get world(){return this._world}raycast(J,Z,Y,X={}){let F=new v0.Ray(J,Z),K=this._rapierSimulation.castRay(F,Y,X.ignoresSensors??!0,X.filterFlags,X.filterGroups,X.filterExcludeCollider,X.filterExcludeRigidBody,X.filterPredicate);if(this._debugRaycastingEnabled)this._world.eventRouter.emit("SIMULATION.DEBUG_RAYCAST",{simulation:this,origin:J,direction:Z,length:Y,hit:!!K});if(!K)return null;let $=F.pointAt(K.timeOfImpact),Q=K.timeOfImpact,W=K.collider,G=this._colliderMap.getColliderHandleBlockType(W.handle);if(G)return{hitBlock:J1.fromGlobalCoordinate({x:Math.floor($.x-(F.dir.x<0?0.0001:-0.0001)),y:Math.floor($.y-(F.dir.y<0?0.0001:-0.0001)),z:Math.floor($.z-(F.dir.z<0?0.0001:-0.0001))},G),hitPoint:$,hitDistance:Q};let V=this._colliderMap.getColliderHandleEntity(W.handle);if(V)return{hitEntity:V,hitPoint:$,hitDistance:Q};return null}createRawCollider(J,Z){return this._rapierSimulation.createCollider(J,Z)}createRawRigidBody(J){return this._rapierSimulation.createRigidBody(J)}enableDebugRaycasting(J){this._debugRaycastingEnabled=J}enableDebugRendering(J){this._debugRenderingEnabled=J}getContactManifolds(J,Z){let Y=[];return this._rapierSimulation.narrowPhase.contactPair(J,Z,(X,F)=>{if(X.numContacts()===0)return;let K=X.normal(),$=[];for(let Q=0;Q<X.numSolverContacts();Q++)$.push(X.solverContactPoint(Q));Y.push({contactPoints:$,localNormalA:!F?X.localNormal1():X.localNormal2(),localNormalB:!F?X.localNormal2():X.localNormal1(),normal:!F?K:{x:-K.x,y:-K.y,z:-K.z}})}),Y}removeRawCollider(J){this._colliderMap.queueColliderHandleForCleanup(J.handle),this._rapierSimulation.removeCollider(J,!1)}removeRawRigidBody(J){this._rapierSimulation.removeRigidBody(J)}setGravity(J){this._rapierSimulation.gravity=J}step=(J)=>{this._world.eventRouter.emit("SIMULATION.STEP_START",{simulation:this,tickDeltaMs:J});let Z=performance.now();if(this._rapierSimulation.step(this._rapierEventQueue),this._rapierEventQueue.drainContactForceEvents(this._onContactForceEvent),this._rapierEventQueue.drainCollisionEvents(this._onCollisionEvent),this._colliderMap.cleanup(),this._world.eventRouter.emit("SIMULATION.STEP_END",{simulation:this,stepDurationMs:performance.now()-Z}),this._debugRenderingEnabled)this._world.eventRouter.emit("SIMULATION.DEBUG_RENDER",{simulation:this,...this._rapierSimulation.debugRender()})};_onCollisionEvent=(J,Z,Y)=>{let[X,F]=this._getCollisionObjects(J,Z);if(!X||!F)return;let K=($,Q)=>{if($ instanceof K6&&Q instanceof J8&&$.onEntityCollision)$.onEntityCollision($,Q,Y,J,Z);else if($ instanceof J8&&Q instanceof K6&&$.onBlockCollision)$.onBlockCollision($,Q,Y,J,Z);else if($ instanceof J8&&Q instanceof J8&&$.onEntityCollision)$.onEntityCollision($,Q,Y,J,Z);else if(typeof $==="function"&&(Q instanceof J8||Q instanceof K6))$(Q,Y,J,Z)};K(X,F),K(F,X)};_onContactForceEvent=(J)=>{let[Z,Y]=this._getCollisionObjects(J.collider1(),J.collider2());if(!Z||typeof Z==="function"||!Y||typeof Y==="function")return;let X={totalForce:J.totalForce(),totalForceMagnitude:J.totalForceMagnitude(),maxForceDirection:J.maxForceDirection(),maxForceMagnitude:J.maxForceMagnitude()},F=(K,$)=>{if(K instanceof K6&&$ instanceof J8&&K.onEntityContactForce)K.onEntityContactForce(K,$,X);else if(K instanceof J8&&$ instanceof K6&&K.onBlockContactForce)K.onBlockContactForce(K,$,X);else if(K instanceof J8&&$ instanceof J8&&K.onEntityContactForce)K.onEntityContactForce(K,$,X)};F(Z,Y),F(Y,Z)};_getCollisionObjects(J,Z){let Y=this._colliderMap.getColliderHandleBlockType(J)??this._colliderMap.getColliderHandleCollisionCallback(J)??this._colliderMap.getColliderHandleEntity(J),X=this._colliderMap.getColliderHandleBlockType(Z)??this._colliderMap.getColliderHandleCollisionCallback(Z)??this._colliderMap.getColliderHandleEntity(Z);return[Y,X]}}class _Y{_queuedBroadcasts=[];_queuedAudioSynchronizations={};_queuedBlockSynchronizations={};_queuedBlockTypeSynchronizations={};_queuedChunkSynchronizations={};_queuedDebugRaycastSynchronizations=[];_queuedEntitySynchronizations={};_queuedLightSynchronizations={};_queuedPlayerPackets=new Map;_queuedPlayerCameraSynchronizations=new Map;_queuedPlayerUISynchronizations=new Map;_queuedPlayerUIDatasSynchronizations=new Map;_queuedSceneUISynchronizations={};_queuedWorldSynchronization;_spawnedChunks=new Set;_spawnedEntities=new Set;_world;constructor(J){this._world=J,this._subscribeToAudioEvents(),this._subscribeToBlockTypeRegistryEvents(),this._subscribeToChatEvents(),this._subscribeToChunkEvents(),this._subscribeToEntityEvents(),this._subscribeToLightEvents(),this._subscribeToPlayerEvents(),this._subscribeToPlayerCameraEvents(),this._subscribeToPlayerUIEvents(),this._subscribeToSceneUIEvents(),this._subscribeToSimulationEvents(),this._subscribeToWorldEvents()}synchronize(){for(let[W,G]of this._queuedPlayerPackets)for(let V of G)W.connection.send(V);let J=Object.values(this._queuedEntitySynchronizations);if(J.length>0){let W=A.createPacket(A.outboundPackets.entitiesPacketDefinition,J,this._world.loop.currentTick);O8.instance.broadcastForWorld(this._world.id,W)}let Z=Object.values(this._queuedAudioSynchronizations);if(Z.length>0){let W=A.createPacket(A.outboundPackets.audiosPacketDefinition,Z,this._world.loop.currentTick);O8.instance.broadcastForWorld(this._world.id,W)}let Y=Object.values(this._queuedBlockTypeSynchronizations);if(Y.length>0){let W=A.createPacket(A.outboundPackets.blockTypesPacketDefinition,Y,this._world.loop.currentTick);O8.instance.broadcastForWorld(this._world.id,W)}let X=Object.values(this._queuedBlockSynchronizations);if(X.length>0){let W=A.createPacket(A.outboundPackets.blocksPacketDefinition,X,this._world.loop.currentTick);O8.instance.broadcastForWorld(this._world.id,W)}let F=Object.values(this._queuedChunkSynchronizations);if(F.length>0){let W=A.createPacket(A.outboundPackets.chunksPacketDefinition,F,this._world.loop.currentTick);O8.instance.broadcastForWorld(this._world.id,W)}let K=Object.values(this._queuedLightSynchronizations);if(K.length>0){let W=A.createPacket(A.outboundPackets.lightsPacketDefinition,K,this._world.loop.currentTick);O8.instance.broadcastForWorld(this._world.id,W)}for(let[W,G]of this._queuedPlayerUISynchronizations){let V=A.createPacket(A.outboundPackets.uiPacketDefinition,G,this._world.loop.currentTick);W.connection.send(V)}for(let[W,G]of this._queuedPlayerUIDatasSynchronizations){let V=A.createPacket(A.outboundPackets.uiDatasPacketDefinition,G,this._world.loop.currentTick);W.connection.send(V)}let $=Object.values(this._queuedSceneUISynchronizations);if($.length>0){let W=A.createPacket(A.outboundPackets.sceneUIsPacketDefinition,$,this._world.loop.currentTick);O8.instance.broadcastForWorld(this._world.id,W)}if(this._queuedWorldSynchronization){let W=A.createPacket(A.outboundPackets.worldPacketDefinition,this._queuedWorldSynchronization,this._world.loop.currentTick);O8.instance.broadcastForWorld(this._world.id,W)}for(let[W,G]of this._queuedPlayerCameraSynchronizations){let V=A.createPacket(A.outboundPackets.cameraPacketDefinition,G,this._world.loop.currentTick);W.connection.send(V)}for(let W of this._queuedBroadcasts)O8.instance.broadcastForWorld(this._world.id,W);let Q=this._queuedDebugRaycastSynchronizations;if(Q.length>0){let W=A.createPacket(A.outboundPackets.physicsDebugRaycastsPacketDefinition,Q,this._world.loop.currentTick);O8.instance.broadcastForWorld(this._world.id,W)}this._queuedBroadcasts=[],this._queuedAudioSynchronizations={},this._queuedBlockSynchronizations={},this._queuedBlockTypeSynchronizations={},this._queuedChunkSynchronizations={},this._queuedDebugRaycastSynchronizations=[],this._queuedEntitySynchronizations={},this._queuedLightSynchronizations={},this._queuedPlayerPackets.clear(),this._queuedPlayerCameraSynchronizations.clear(),this._queuedPlayerUISynchronizations.clear(),this._queuedPlayerUIDatasSynchronizations.clear(),this._queuedSceneUISynchronizations={},this._queuedWorldSynchronization=void 0,this._spawnedChunks.clear(),this._spawnedEntities.clear()}_subscribeToAudioEvents(){this._world.eventRouter.on("AUDIO.PAUSE",this._onAudioPause),this._world.eventRouter.on("AUDIO.PLAY",this._onAudioPlay),this._world.eventRouter.on("AUDIO.PLAY_RESTART",this._onAudioPlayRestart),this._world.eventRouter.on("AUDIO.SET_ATTACHED_TO_ENTITY",this._onAudioSetAttachedToEntity),this._world.eventRouter.on("AUDIO.SET_DETUNE",this._onAudioSetDetune),this._world.eventRouter.on("AUDIO.SET_DISTORTION",this._onAudioSetDistortion),this._world.eventRouter.on("AUDIO.SET_POSITION",this._onAudioSetPosition),this._world.eventRouter.on("AUDIO.SET_PLAYBACK_RATE",this._onAudioSetPlaybackRate),this._world.eventRouter.on("AUDIO.SET_REFERENCE_DISTANCE",this._onAudioSetReferenceDistance),this._world.eventRouter.on("AUDIO.SET_VOLUME",this._onAudioSetVolume)}_subscribeToBlockTypeRegistryEvents(){this._world.eventRouter.on("BLOCK_TYPE_REGISTRY.REGISTER_BLOCK_TYPE",this._onBlockTypeRegistryRegisterBlockType)}_subscribeToChatEvents(){this._world.eventRouter.on("CHAT.SEND_BROADCAST_MESSAGE",this._onChatSendBroadcastMessage),this._world.eventRouter.on("CHAT.SEND_PLAYER_MESSAGE",this._onChatSendPlayerMessage)}_subscribeToChunkEvents(){this._world.eventRouter.on("CHUNK.SPAWN",this._onChunkSpawn),this._world.eventRouter.on("CHUNK.DESPAWN",this._onChunkDespawn),this._world.eventRouter.on("CHUNK.SET_BLOCK",this._onChunkSetBlock)}_subscribeToEntityEvents(){this._world.eventRouter.on("ENTITY.SPAWN",this._onEntitySpawn),this._world.eventRouter.on("ENTITY.DESPAWN",this._onEntityDespawn),this._world.eventRouter.on("ENTITY.SET_MODEL_ANIMATIONS_PLAYBACK_RATE",this._onEntitySetModelAnimationsPlaybackRate),this._world.eventRouter.on("ENTITY.SET_MODEL_HIDDEN_NODES",this._onEntitySetModelHiddenNodes),this._world.eventRouter.on("ENTITY.SET_OPACITY",this._onEntitySetOpacity),this._world.eventRouter.on("ENTITY.SET_PARENT",this._onEntitySetParent),this._world.eventRouter.on("ENTITY.SET_TINT_COLOR",this._onEntitySetTintColor),this._world.eventRouter.on("ENTITY.START_MODEL_LOOPED_ANIMATIONS",this._onEntityStartModelLoopedAnimations),this._world.eventRouter.on("ENTITY.START_MODEL_ONESHOT_ANIMATIONS",this._onEntityStartModelOneshotAnimations),this._world.eventRouter.on("ENTITY.STOP_MODEL_ANIMATIONS",this._onEntityStopModelAnimations),this._world.eventRouter.on("ENTITY.UPDATE_POSITION",this._onEntityUpdatePosition),this._world.eventRouter.on("ENTITY.UPDATE_ROTATION",this._onEntityUpdateRotation)}_subscribeToLightEvents(){this._world.eventRouter.on("LIGHT.DESPAWN",this._onLightDespawn),this._world.eventRouter.on("LIGHT.SET_ANGLE",this._onLightSetAngle),this._world.eventRouter.on("LIGHT.SET_ATTACHED_TO_ENTITY",this._onLightSetAttachedToEntity),this._world.eventRouter.on("LIGHT.SET_COLOR",this._onLightSetColor),this._world.eventRouter.on("LIGHT.SET_DISTANCE",this._onLightSetDistance),this._world.eventRouter.on("LIGHT.SET_INTENSITY",this._onLightSetIntensity),this._world.eventRouter.on("LIGHT.SET_OFFSET",this._onLightSetOffset),this._world.eventRouter.on("LIGHT.SET_PENUMBRA",this._onLightSetPenumbra),this._world.eventRouter.on("LIGHT.SET_POSITION",this._onLightSetPosition),this._world.eventRouter.on("LIGHT.SET_TRACKED_ENTITY",this._onLightSetTrackedEntity),this._world.eventRouter.on("LIGHT.SET_TRACKED_POSITION",this._onLightSetTrackedPosition),this._world.eventRouter.on("LIGHT.SPAWN",this._onLightSpawn)}_subscribeToPlayerEvents(){this._world.eventRouter.on("PLAYER.JOINED_WORLD",this._onPlayerJoinedWorld),this._world.eventRouter.on("PLAYER.LEFT_WORLD",this._onPlayerLeftWorld),this._world.eventRouter.on("PLAYER.REQUEST_SYNC",this._onPlayerRequestSync)}_subscribeToPlayerCameraEvents(){this._world.eventRouter.on("PLAYER_CAMERA.LOOK_AT_ENTITY",this._onPlayerCameraLookAtEntity),this._world.eventRouter.on("PLAYER_CAMERA.LOOK_AT_POSITION",this._onPlayerCameraLookAtPosition),this._world.eventRouter.on("PLAYER_CAMERA.SET_ATTACHED_TO_ENTITY",this._onPlayerCameraSetAttachedToEntity),this._world.eventRouter.on("PLAYER_CAMERA.SET_ATTACHED_TO_POSITION",this._onPlayerCameraSetAttachedToPosition),this._world.eventRouter.on("PLAYER_CAMERA.SET_FILM_OFFSET",this._onPlayerCameraSetFilmOffset),this._world.eventRouter.on("PLAYER_CAMERA.SET_FORWARD_OFFSET",this._onPlayerCameraSetForwardOffset),this._world.eventRouter.on("PLAYER_CAMERA.SET_FOV",this._onPlayerCameraSetFov),this._world.eventRouter.on("PLAYER_CAMERA.SET_MODEL_HIDDEN_NODES",this._onPlayerCameraSetModelHiddenNodes),this._world.eventRouter.on("PLAYER_CAMERA.SET_MODE",this._onPlayerCameraSetMode),this._world.eventRouter.on("PLAYER_CAMERA.SET_OFFSET",this._onPlayerCameraSetOffset),this._world.eventRouter.on("PLAYER_CAMERA.SET_TRACKED_ENTITY",this._onPlayerCameraSetTrackedEntity),this._world.eventRouter.on("PLAYER_CAMERA.SET_TRACKED_POSITION",this._onPlayerCameraSetTrackedPosition),this._world.eventRouter.on("PLAYER_CAMERA.SET_ZOOM",this._onPlayerCameraSetZoom)}_subscribeToPlayerUIEvents(){this._world.eventRouter.on("PLAYER_UI.LOAD",this._onPlayerUILoad),this._world.eventRouter.on("PLAYER_UI.LOCK_POINTER",this._onPlayerUILockPointer),this._world.eventRouter.on("PLAYER_UI.SEND_DATA",this._onPlayerUISendData)}_subscribeToSceneUIEvents(){this._world.eventRouter.on("SCENE_UI.LOAD",this._onSceneUILoad),this._world.eventRouter.on("SCENE_UI.SET_ATTACHED_TO_ENTITY",this._onSceneUISetAttachedToEntity),this._world.eventRouter.on("SCENE_UI.SET_OFFSET",this._onSceneUISetOffset),this._world.eventRouter.on("SCENE_UI.SET_POSITION",this._onSceneUISetPosition),this._world.eventRouter.on("SCENE_UI.SET_STATE",this._onSceneUISetState),this._world.eventRouter.on("SCENE_UI.SET_VIEW_DISTANCE",this._onSceneUISetViewDistance),this._world.eventRouter.on("SCENE_UI.UNLOAD",this._onSceneUIUnload)}_subscribeToSimulationEvents(){this._world.eventRouter.on("SIMULATION.DEBUG_RAYCAST",this._onSimulationDebugRaycast),this._world.eventRouter.on("SIMULATION.DEBUG_RENDER",this._onSimulationDebugRender)}_subscribeToWorldEvents(){this._world.eventRouter.on("WORLD.SET_AMBIENT_LIGHT_COLOR",this._onWorldSetAmbientLightColor),this._world.eventRouter.on("WORLD.SET_AMBIENT_LIGHT_INTENSITY",this._onWorldSetAmbientLightIntensity),this._world.eventRouter.on("WORLD.SET_DIRECTIONAL_LIGHT_COLOR",this._onWorldSetDirectionalLightColor),this._world.eventRouter.on("WORLD.SET_DIRECTIONAL_LIGHT_INTENSITY",this._onWorldSetDirectionalLightIntensity),this._world.eventRouter.on("WORLD.SET_DIRECTIONAL_LIGHT_POSITION",this._onWorldSetDirectionalLightPosition)}_onAudioPause=(J)=>{let Z=this._createOrGetQueuedAudioSync(J.audio);Z.pa=!0,delete Z.pl,delete Z.r};_onAudioPlay=(J)=>{let Z=J.audio.serialize();Z.pl=!0,delete Z.pa,delete Z.r,this._queuedAudioSynchronizations[Z.i]=Z};_onAudioPlayRestart=(J)=>{let Z=this._createOrGetQueuedAudioSync(J.audio);Z.r=!0,delete Z.pa,delete Z.pl,this._queuedAudioSynchronizations[Z.i]=Z};_onAudioSetAttachedToEntity=(J)=>{let Z=this._createOrGetQueuedAudioSync(J.audio);Z.e=J.entity?J.entity.id:void 0,Z.p=J.entity?void 0:Z.p};_onAudioSetDetune=(J)=>{let Z=this._createOrGetQueuedAudioSync(J.audio);Z.de=J.detune};_onAudioSetDistortion=(J)=>{let Z=this._createOrGetQueuedAudioSync(J.audio);Z.di=J.distortion};_onAudioSetPosition=(J)=>{let Z=this._createOrGetQueuedAudioSync(J.audio);Z.e=J.position?void 0:Z.e,Z.p=J.position?t.serializeVector(J.position):void 0};_onAudioSetPlaybackRate=(J)=>{let Z=this._createOrGetQueuedAudioSync(J.audio);Z.pr=J.playbackRate};_onAudioSetReferenceDistance=(J)=>{let Z=this._createOrGetQueuedAudioSync(J.audio);Z.rd=J.referenceDistance};_onAudioSetVolume=(J)=>{let Z=this._createOrGetQueuedAudioSync(J.audio);Z.v=J.volume};_onBlockTypeRegistryRegisterBlockType=(J)=>{let Z=J.blockType.serialize();this._queuedBlockTypeSynchronizations[J.blockType.id]=Z};_onChatSendBroadcastMessage=(J)=>{let{message:Z,color:Y}=J;this._queuedBroadcasts.push(A.createPacket(A.outboundPackets.chatMessagesPacketDefinition,[{m:Z,c:Y}],this._world.loop.currentTick))};_onChatSendPlayerMessage=(J)=>{let{player:Z,message:Y,color:X}=J,F=this._queuedPlayerPackets.get(Z)??[];F.push(A.createPacket(A.outboundPackets.chatMessagesPacketDefinition,[{m:Y,c:X}],this._world.loop.currentTick)),this._queuedPlayerPackets.set(Z,F)};_onChunkSpawn=(J)=>{let Z=this._createOrGetQueuedChunkSync(J.chunk);Z.b=Array.from(J.chunk.blocks),Z.rm=void 0,this._spawnedChunks.add(Z.c.join(","))};_onChunkDespawn=(J)=>{let Z=this._createOrGetQueuedChunkSync(J.chunk),Y=Z.c.join(",");if(this._spawnedChunks.has(Y))delete this._queuedChunkSynchronizations[Y],this._spawnedChunks.delete(Y);else Z.rm=!0};_onChunkSetBlock=(J)=>{let Z=this._createOrGetQueuedBlockSync(J.globalCoordinate);Z.i=J.blockTypeId};_onEntitySetModelAnimationsPlaybackRate=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);Z.ap=J.playbackRate};_onEntitySpawn=(J)=>{let Z=J.entity.serialize();this._queuedEntitySynchronizations[Z.i]=Z,this._spawnedEntities.add(Z.i)};_onEntityDespawn=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);if(this._spawnedEntities.has(Z.i))delete this._queuedEntitySynchronizations[Z.i],this._spawnedEntities.delete(Z.i);else Z.rm=!0};_onEntitySetModelHiddenNodes=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);Z.h=Array.from(J.modelHiddenNodes)};_onEntitySetOpacity=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);Z.o=J.opacity};_onEntitySetParent=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);Z.pe=J.parent?J.parent.id:void 0,Z.pn=J.parentNodeName};_onEntitySetTintColor=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);Z.t=J.tintColor?t.serializeRgbColor(J.tintColor):void 0};_onEntityStartModelLoopedAnimations=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);if(Z.al=Array.from(new Set([...Z.al??[],...J.animations])),Z.as)Z.as=Z.as.filter((Y)=>!J.animations.has(Y)).filter(Boolean)};_onEntityStartModelOneshotAnimations=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);if(Z.ao=Array.from(new Set([...Z.ao??[],...J.animations])),Z.as)Z.as=Z.as.filter((Y)=>!J.animations.has(Y)).filter(Boolean)};_onEntityStopModelAnimations=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);if(Z.al)Z.al=Z.al.filter((Y)=>!J.animations.has(Y)).filter(Boolean);if(Z.ao)Z.ao=Z.ao.filter((Y)=>!J.animations.has(Y)).filter(Boolean);Z.as=Array.from(new Set([...Z.as??[],...J.animations]))};_onEntityUpdateRotation=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);Z.r=[J.rotation.x,J.rotation.y,J.rotation.z,J.rotation.w]};_onEntityUpdatePosition=(J)=>{let Z=this._createOrGetQueuedEntitySync(J.entity);Z.p=[J.position.x,J.position.y,J.position.z]};_onLightDespawn=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.rm=!0};_onLightSetAngle=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.a=J.angle};_onLightSetAttachedToEntity=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.e=J.entity?J.entity.id:void 0,Z.p=J.entity?void 0:Z.p};_onLightSetColor=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.c=t.serializeRgbColor(J.color)};_onLightSetDistance=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.d=J.distance};_onLightSetIntensity=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.n=J.intensity};_onLightSetOffset=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.o=J.offset?t.serializeVector(J.offset):void 0};_onLightSetPenumbra=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.pe=J.penumbra};_onLightSetPosition=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.p=J.position?t.serializeVector(J.position):void 0,Z.e=J.position?void 0:Z.e};_onLightSetTrackedEntity=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.te=J.entity?J.entity.id:void 0,Z.tp=J.entity?void 0:Z.tp};_onLightSetTrackedPosition=(J)=>{let Z=this._createOrGetQueuedLightSync(J.light);Z.tp=J.position?t.serializeVector(J.position):void 0,Z.te=J.position?void 0:Z.te};_onLightSpawn=(J)=>{let Z=J.light.serialize();this._queuedLightSynchronizations[Z.i]=Z};_onPlayerCameraLookAtEntity=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.pl=t.serializeVector(J.entity.position),delete Z.et,delete Z.pt};_onPlayerCameraLookAtPosition=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.pl=J.position?t.serializeVector(J.position):void 0,delete Z.et,delete Z.pt};_onPlayerCameraSetAttachedToEntity=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.e=J.entity.id,delete Z.p};_onPlayerCameraSetAttachedToPosition=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.p=J.position?t.serializeVector(J.position):void 0,delete Z.e};_onPlayerCameraSetFilmOffset=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.fo=J.filmOffset};_onPlayerCameraSetForwardOffset=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.ffo=J.forwardOffset};_onPlayerCameraSetFov=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.fv=J.fov};_onPlayerCameraSetModelHiddenNodes=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.h=Array.from(J.modelHiddenNodes)};_onPlayerCameraSetMode=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.m=J.mode};_onPlayerCameraSetOffset=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.o=J.offset?t.serializeVector(J.offset):void 0};_onPlayerCameraSetTrackedEntity=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.et=J.entity?J.entity.id:void 0,delete Z.pl,delete Z.pt};_onPlayerCameraSetTrackedPosition=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.pt=J.position?t.serializeVector(J.position):void 0,delete Z.et,delete Z.pl};_onPlayerCameraSetZoom=(J)=>{let Z=this._createOrGetQueuedPlayerCameraSync(J.playerCamera);Z.z=J.zoom};_onPlayerJoinedWorld=(J)=>{let{player:Z}=J,Y=this._queuedPlayerPackets.get(Z)??[];Y.push(A.createPacket(A.outboundPackets.worldPacketDefinition,this._world.serialize(),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.blockTypesPacketDefinition,this._world.blockTypeRegistry.serialize(),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.chunksPacketDefinition,this._world.chunkLattice.getAllChunks().map((F)=>F.serialize()),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.entitiesPacketDefinition,this._world.entityManager.getAllEntities().map((F)=>{if(Z.camera.attachedToEntity===void 0&&F instanceof H9&&F.player===Z)Z.camera.setAttachedToEntity(F);return F.serialize()}),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.audiosPacketDefinition,this._world.audioManager.getAllLoopedAudios().map((F)=>F.serialize()),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.lightsPacketDefinition,this._world.lightManager.getAllLights().map((F)=>F.serialize()),this._world.loop.currentTick)),Y.push(A.createPacket(A.outboundPackets.sceneUIsPacketDefinition,this._world.sceneUIManager.getAllSceneUIs().map((F)=>F.serialize()),this._world.loop.currentTick));let X=this._createOrGetQueuedPlayerCameraSync(Z.camera);this._queuedPlayerCameraSynchronizations.set(Z,{...Z.camera.serialize(),...X}),this._queuedPlayerPackets.set(Z,Y)};_onPlayerLeftWorld=(J)=>{};_onPlayerRequestSync=(J)=>{J.player.connection.send(A.createPacket(A.outboundPackets.syncResponsePacketDefinition,{r:J.receivedAt,s:Date.now(),p:performance.now()-J.receivedAtMs,n:this._world.loop.nextTickMs},this._world.loop.currentTick))};_onPlayerUILoad=(J)=>{let Z=this._createOrGetQueuedPlayerUISync(J.playerUI);Z.u=J.htmlUri};_onPlayerUILockPointer=(J)=>{let Z=this._createOrGetQueuedPlayerUISync(J.playerUI);Z.p=J.lock};_onPlayerUISendData=(J)=>{this._createOrGetQueuedPlayerUIDatasSync(J.playerUI).push(J.data)};_onSceneUILoad=(J)=>{let Z=J.sceneUI.serialize();this._queuedSceneUISynchronizations[Z.i]=Z};_onSceneUISetAttachedToEntity=(J)=>{let Z=this._createOrGetQueuedSceneUISync(J.sceneUI);Z.e=J.entity?J.entity.id:void 0,Z.p=J.entity?void 0:Z.p};_onSceneUISetOffset=(J)=>{let Z=this._createOrGetQueuedSceneUISync(J.sceneUI);Z.o=J.offset?t.serializeVector(J.offset):void 0};_onSceneUISetPosition=(J)=>{let Z=this._createOrGetQueuedSceneUISync(J.sceneUI);Z.p=J.position?t.serializeVector(J.position):void 0,Z.e=J.position?void 0:Z.e};_onSceneUISetState=(J)=>{let Z=this._createOrGetQueuedSceneUISync(J.sceneUI);Z.s=J.state};_onSceneUISetViewDistance=(J)=>{let Z=this._createOrGetQueuedSceneUISync(J.sceneUI);Z.v=J.viewDistance};_onSceneUIUnload=(J)=>{let Z=this._createOrGetQueuedSceneUISync(J.sceneUI);Z.rm=!0};_onSimulationDebugRaycast=(J)=>{this._queuedDebugRaycastSynchronizations.push(t.serializePhysicsDebugRaycast(J))};_onSimulationDebugRender=(J)=>{this._queuedBroadcasts.push(A.createPacket(A.outboundPackets.physicsDebugRenderPacketDefinition,{v:Array.from(J.vertices),c:Array.from(J.colors)},this._world.loop.currentTick))};_onWorldSetAmbientLightColor=(J)=>{let Z=this._createOrGetQueuedWorldSync(J.world);Z.ac=t.serializeRgbColor(J.color)};_onWorldSetAmbientLightIntensity=(J)=>{let Z=this._createOrGetQueuedWorldSync(J.world);Z.ai=J.intensity};_onWorldSetDirectionalLightColor=(J)=>{let Z=this._createOrGetQueuedWorldSync(J.world);Z.dc=t.serializeRgbColor(J.color)};_onWorldSetDirectionalLightIntensity=(J)=>{let Z=this._createOrGetQueuedWorldSync(J.world);Z.di=J.intensity};_onWorldSetDirectionalLightPosition=(J)=>{let Z=this._createOrGetQueuedWorldSync(J.world);Z.dp=t.serializeVector(J.position)};_createOrGetQueuedAudioSync(J){if(J.id===void 0)throw new Error("NetworkSynchronizer._createOrGetQueuedAudioSync(): Audio has no id!");return this._queuedAudioSynchronizations[J.id]??={i:J.id}}_createOrGetQueuedBlockSync(J){let{x:Z,y:Y,z:X}=J;return this._queuedBlockSynchronizations[`${Z},${Y},${X}`]??={i:0,c:[Z,Y,X]}}_createOrGetQueuedChunkSync(J){if(!J.originCoordinate)throw new Error("NetworkSynchronizer._createOrGetQueuedChunkSync(): Chunk has no origin coordinate!");let{x:Z,y:Y,z:X}=J.originCoordinate;return this._queuedChunkSynchronizations[`${Z},${Y},${X}`]??={c:[Z,Y,X]}}_createOrGetQueuedEntitySync(J){if(J.id===void 0)throw new Error("NetworkSynchronizer._createOrGetQueuedEntitySync(): Entity has no id!");return this._queuedEntitySynchronizations[J.id]??={i:J.id}}_createOrGetQueuedLightSync(J){if(J.id===void 0)throw new Error("NetworkSynchronizer._createOrGetQueuedLightSync(): Light has no id!");return this._queuedLightSynchronizations[J.id]??={i:J.id}}_createOrGetQueuedPlayerCameraSync(J){let Z=this._queuedPlayerCameraSynchronizations.get(J.player);if(!Z)Z={},this._queuedPlayerCameraSynchronizations.set(J.player,Z);return Z}_createOrGetQueuedPlayerUISync(J){let Z=this._queuedPlayerUISynchronizations.get(J.player);if(!Z)Z={},this._queuedPlayerUISynchronizations.set(J.player,Z);return Z}_createOrGetQueuedPlayerUIDatasSync(J){let Z=this._queuedPlayerUIDatasSynchronizations.get(J.player);if(!Z)Z=[],this._queuedPlayerUIDatasSynchronizations.set(J.player,Z);return Z}_createOrGetQueuedSceneUISync(J){if(J.id===void 0)throw new Error("NetworkSynchronizer._createOrGetQueuedSceneUISync(): SceneUI has no id!");return this._queuedSceneUISynchronizations[J.id]??={i:J.id}}_createOrGetQueuedWorldSync(J){if(J.id!==this._world.id)throw new Error("NetworkSynchronizer._createOrGetQueuedWorldSync(): World does not match this network synchronizer world!");return this._queuedWorldSynchronization??={i:J.id}}}class V7{_sceneUIs=new Map;_nextSceneUIId=1;_world;constructor(J){this._world=J}get world(){return this._world}getAllSceneUIs(){return Array.from(this._sceneUIs.values())}getAllEntityAttachedSceneUIs(J){return this.getAllSceneUIs().filter((Z)=>Z.attachedToEntity===J)}getSceneUIById(J){return this._sceneUIs.get(J)}registerSceneUI(J){if(J.id!==void 0)return J.id;let Z=this._nextSceneUIId;return this._sceneUIs.set(Z,J),this._nextSceneUIId++,Z}unloadEntityAttachedSceneUIs(J){this.getAllEntityAttachedSceneUIs(J).forEach((Z)=>{Z.unload()})}unregisterSceneUI(J){if(J.id===void 0)return;this._sceneUIs.delete(J.id)}}class O7{_accumulatorMs=0;_targetTicksPerSecond;_fixedTimestepMs;_fixedTimestepS;_nextTickMs=0;_lastLoopTimeMs=0;_tickFunction;_tickErrorCallback;_tickHandle=null;constructor(J,Z,Y){this._targetTicksPerSecond=J,this._fixedTimestepS=Math.fround(1/J),this._fixedTimestepMs=Math.fround(this._fixedTimestepS*1000),this._tickFunction=Z,this._tickErrorCallback=Y}get targetTicksPerSecond(){return this._targetTicksPerSecond}get fixedTimestepMs(){return this._fixedTimestepMs}get fixedTimestepS(){return this._fixedTimestepS}get nextTickMs(){return this._nextTickMs}start(){if(this._tickHandle)return console.warn("Ticker.start(): ticker already running.");this._lastLoopTimeMs=performance.now();let J=()=>{let Z=performance.now(),Y=Z-this._lastLoopTimeMs;if(this._lastLoopTimeMs=Z,Y>250)Y=250;this._accumulatorMs+=Y;while(this._accumulatorMs>=this._fixedTimestepMs)this._tick(this._fixedTimestepMs),this._accumulatorMs-=this._fixedTimestepMs;this._nextTickMs=this._fixedTimestepMs-this._accumulatorMs,this._tickHandle=setTimeout(J,0)};J()}stop(){if(!this._tickHandle)return console.warn("Ticker.stop(): ticker not running.");clearTimeout(this._tickHandle),this._tickHandle=null}_tick(J){try{this._tickFunction(J)}catch(Z){if(Z instanceof Error&&this._tickErrorCallback)this._tickErrorCallback(Z);else console.warn("Ticker._tick(): tick callback threw an error, but it was not an instance of Error. Error:",Z)}}}var uR;((K)=>{K.START="WORLD_LOOP.START";K.STOP="WORLD_LOOP.STOP";K.TICK_START="WORLD_LOOP.TICK_START";K.TICK_END="WORLD_LOOP.TICK_END";K.TICK_ERROR="WORLD_LOOP.TICK_ERROR"})(uR||={});class v7{_currentTick=0;_ticker;_world;constructor(J,Z=eQ){this._ticker=new O7(Z,this._tick,this._onTickError),this._world=J}get currentTick(){return this._currentTick}get nextTickMs(){return this._ticker.nextTickMs}get timestepS(){return this._ticker.fixedTimestepS}get world(){return this._world}start(){this._ticker.start(),this._world.eventRouter.emit("WORLD_LOOP.START",{worldLoop:this})}stop(){this._ticker.stop(),this._world.eventRouter.emit("WORLD_LOOP.STOP",{worldLoop:this})}_tick=(J)=>{this._world.eventRouter.emit("WORLD_LOOP.TICK_START",{worldLoop:this,tickDeltaMs:J});let Z=performance.now();this._world.chunkLattice.updateChunks(),this._world.entityManager.tickEntities(J),this._world.simulation.step(J),this._world.entityManager.checkAndEmitUpdates(),this._world.networkSynchronizer.synchronize(),this._currentTick++,this._world.eventRouter.emit("WORLD_LOOP.TICK_END",{worldLoop:this,tickDurationMs:performance.now()-Z})};_onTickError=(J)=>{console.error(J),this._world.eventRouter.emit("WORLD_LOOP.TICK_ERROR",{worldLoop:this,error:J})}}class L7{onPlayerJoin;onPlayerLeave;_id;_ambientLightColor;_ambientLightIntensity;_directionalLightColor;_directionalLightIntensity;_directionalLightPosition;_name;_skyboxUri;_audioManager;_blockTypeRegistry;_chatManager;_chunkLattice;_entityManager;_eventRouter;_lightManager;_loop;_networkSynchronizer;_sceneUIManager;_simulation;constructor(J){this._id=J.id,this._ambientLightColor=J.ambientLightColor??{r:255,g:255,b:255},this._ambientLightIntensity=J.ambientLightIntensity??1,this._directionalLightColor=J.directionalLightColor??{r:255,g:255,b:255},this._directionalLightIntensity=J.directionalLightIntensity??3,this._directionalLightPosition=J.directionalLightPosition??{x:100,y:150,z:100},this._name=J.name,this._skyboxUri=J.skyboxUri,this._eventRouter=new K0(`world.${J.id}.${J.name}`),this._audioManager=new Y5(this),this._blockTypeRegistry=new D5(this),this._chatManager=new q7(this),this._chunkLattice=new Y7(this),this._entityManager=new F7(this),this._lightManager=new K7(this),this._loop=new v7(this,J.tickRate),this._networkSynchronizer=new _Y(this),this._sceneUIManager=new V7(this),this._simulation=new W7(this,J.tickRate,J.gravity)}get id(){return this._id}get ambientLightColor(){return this._ambientLightColor}get ambientLightIntensity(){return this._ambientLightIntensity}get directionalLightColor(){return this._directionalLightColor}get directionalLightIntensity(){return this._directionalLightIntensity}get directionalLightPosition(){return this._directionalLightPosition}get name(){return this._name}get skyboxUri(){return this._skyboxUri}get audioManager(){return this._audioManager}get blockTypeRegistry(){return this._blockTypeRegistry}get chatManager(){return this._chatManager}get chunkLattice(){return this._chunkLattice}get entityManager(){return this._entityManager}get eventRouter(){return this._eventRouter}get lightManager(){return this._lightManager}get loop(){return this._loop}get networkSynchronizer(){return this._networkSynchronizer}get sceneUIManager(){return this._sceneUIManager}get simulation(){return this._simulation}loadMap(J){if(J.blockTypes)for(let Z of J.blockTypes)this.blockTypeRegistry.registerGenericBlockType({id:Z.id,isLiquid:Z.isLiquid,name:Z.name,textureUri:Z.textureUri});if(J.blocks)for(let[Z,Y]of Object.entries(J.blocks)){let[X,F,K]=Z.split(",").map(Number);this.chunkLattice.setBlock({x:X,y:F,z:K},Y)}if(J.entities)for(let[Z,Y]of Object.entries(J.entities)){let[X,F,K]=Z.split(",").map(Number);new J8(Y).spawn(this,{x:X,y:F,z:K})}}setAmbientLightColor(J){this._ambientLightColor=J,this._eventRouter.emit("WORLD.SET_AMBIENT_LIGHT_COLOR",{world:this,color:J})}setAmbientLightIntensity(J){this._ambientLightIntensity=J,this._eventRouter.emit("WORLD.SET_AMBIENT_LIGHT_INTENSITY",{world:this,intensity:J})}setDirectionalLightColor(J){this._directionalLightColor=J,this._eventRouter.emit("WORLD.SET_DIRECTIONAL_LIGHT_COLOR",{world:this,color:J})}setDirectionalLightIntensity(J){this._directionalLightIntensity=J,this._eventRouter.emit("WORLD.SET_DIRECTIONAL_LIGHT_INTENSITY",{world:this,intensity:J})}setDirectionalLightPosition(J){this._directionalLightPosition=J,this._eventRouter.emit("WORLD.SET_DIRECTIONAL_LIGHT_POSITION",{world:this,position:J})}start(){this._loop.start(),this._eventRouter.emit("WORLD.START",{world:this,startedAtMs:Date.now()})}stop(){this._loop.stop(),this._eventRouter.emit("WORLD.STOP",{world:this,stoppedAtMs:Date.now()})}serialize(){return t.serializeWorld(this)}}var dR;((Y)=>{Y.START="GAMESERVER.START";Y.STOP="GAMESERVER.STOP"})(dR||={});function Eu(J){v0.init().then(()=>{return d6.instance.modelRegistry.preloadModels()}).then(()=>{J(d6.instance.worlds[0]),d6.instance.start()}).catch((Z)=>{console.error("Failed to initialize the game engine, exiting. Error:",Z),process.exit(1)})}class d6{static _instance;_modelRegistry=F6.instance;_playerManager=O8.instance;_socket=Z7.instance;_webServer=a1.instance;_worlds={};constructor(){let J=new L7({id:0,name:"Default World",skyboxUri:"skyboxes/partly-cloudy"});this._worlds[J.id]=J}static get instance(){if(!this._instance)this._instance=new d6;return this._instance}get modelRegistry(){return this._modelRegistry}get playerManager(){return this._playerManager}get socket(){return this._socket}get webServer(){return this._webServer}get worlds(){return this._worlds}start(){K0.serverInstance.emit("GAMESERVER.START",{startedAtMs:performance.now()}),Object.values(this._worlds).forEach((J)=>J.start()),this._webServer.start()}stop(){K0.serverInstance.emit("GAMESERVER.STOP",{stoppedAtMs:performance.now()}),Object.values(this._worlds).forEach((J)=>J.stop())}}var sR=["w","a","s","d","sp","sh","tb","ml","mr","q","e","r","f","z","x","c","v","1","2","3","4","5","6","7","8","9","0"],pY;((F)=>{F.CHAT_MESSAGE_SEND="PLAYER.CHAT_MESSAGE_SEND";F.JOINED_WORLD="PLAYER.JOINED_WORLD";F.LEFT_WORLD="PLAYER.LEFT_WORLD";F.REQUEST_SYNC="PLAYER.REQUEST_SYNC"})(pY||={});class Y4{id;username;profilePictureUrl;camera;connection;ui;_input={};_world;constructor(J,Z){this.id=Z?.id??"unknown",this.username=Z?.user.username??`Unknown-Player-${Math.floor(Math.random()*1e6)}`,this.profilePictureUrl=Z?.user.profilePictureURL??void 0,this.camera=new $7(this),this.connection=J,this.ui=new Q7(this),J.onPacket(A.PacketId.CHAT_MESSAGE_SEND,this._onChatMessageSendPacket),J.onPacket(A.PacketId.DEBUG_CONFIG,this._onDebugConfigPacket),J.onPacket(A.PacketId.INPUT,this._onInputPacket),J.onPacket(A.PacketId.SYNC_REQUEST,this._onSyncRequestPacket),J.onPacket(A.PacketId.UI_DATA_SEND,this._onUIDataSendPacket),this.joinWorld(d6.instance.worlds[0])}get input(){return this._input}get world(){return this._world}joinWorld(J){if(this.leaveWorld(),this._world=J,this._world.onPlayerJoin)this._world.onPlayerJoin(this);this._world.eventRouter.emit("PLAYER.JOINED_WORLD",{player:this,world:this._world})}leaveWorld(){if(!this._world)return;if(this._world.onPlayerLeave)this._world.onPlayerLeave(this);this._world.eventRouter.emit("PLAYER.LEFT_WORLD",{player:this,world:this._world}),this._world=void 0}disconnect(){this.leaveWorld(),this.connection.close()}_onChatMessageSendPacket=(J)=>{if(this._world)this._world.eventRouter.emit("PLAYER.CHAT_MESSAGE_SEND",{player:this,message:J[1]})};_onDebugConfigPacket=(J)=>{console.log(J)};_onInputPacket=(J)=>{let Z=J[1];if(sR.forEach((Y)=>{let X=Y;if(Z[X]!==void 0)this._input[X]=Boolean(Z[X])}),Z.cp!==void 0)this.camera.setOrientationPitch(Z.cp);if(Z.cy!==void 0)this.camera.setOrientationYaw(Z.cy)};_onSyncRequestPacket=()=>{if(this._world)this._world.eventRouter.emit("PLAYER.REQUEST_SYNC",{player:this,receivedAt:Date.now(),receivedAtMs:performance.now()})};_onUIDataSendPacket=(J)=>{if(this.ui.onData)this.ui.onData(this.ui,J[1])}}var JG;((Y)=>{Y.SEND_BROADCAST_MESSAGE="CHAT.SEND_BROADCAST_MESSAGE";Y.SEND_PLAYER_MESSAGE="CHAT.SEND_PLAYER_MESSAGE"})(JG||={});class q7{onBroadcastMessage;_commandCallbacks={};_world;constructor(J){this._world=J,this._subscribeToPlayerEvents()}registerCommand(J,Z){this._commandCallbacks[J]=Z}unregisterCommand(J){delete this._commandCallbacks[J]}sendBroadcastMessage(J,Z){this._sendBroadcastMessage(void 0,J,Z)}sendPlayerMessage(J,Z,Y){this._world.eventRouter.emit("CHAT.SEND_PLAYER_MESSAGE",{player:J,message:Z,color:Y})}_subscribeToPlayerEvents(){this._world.eventRouter.on("PLAYER.CHAT_MESSAGE_SEND",this._onPlayerChatMessage)}_onPlayerChatMessage=(J)=>{let{player:Z,message:Y}=J,[X,...F]=Y.m.split(" "),K=this._commandCallbacks[X];if(K){K(Z,F,Y.m);return}this._sendBroadcastMessage(Z,`${Z.username}: ${Y.m}`)};_sendBroadcastMessage(J,Z,Y){if(this.onBroadcastMessage)this.onBroadcastMessage(J,Z,Y);this._world.eventRouter.emit("CHAT.SEND_BROADCAST_MESSAGE",{message:Z,color:Y})}}var i=0.000001,$0=typeof Float32Array!=="undefined"?Float32Array:Array,B6=Math.random;var UZ0=Math.PI/180;if(!Math.hypot)Math.hypot=function(){var J=0,Z=arguments.length;while(Z--)J+=arguments[Z]*arguments[Z];return Math.sqrt(J)};var t0={};E6(t0,{transpose:()=>cu,subtract:()=>oR,sub:()=>Jd,str:()=>nu,set:()=>hu,scale:()=>Au,rotate:()=>gu,multiplyScalarAndAdd:()=>tu,multiplyScalar:()=>ru,multiply:()=>aR,mul:()=>eu,invert:()=>lu,identity:()=>fu,fromValues:()=>Iu,fromScaling:()=>yu,fromRotation:()=>iu,frob:()=>uu,exactEquals:()=>au,equals:()=>ou,determinant:()=>mu,create:()=>Cu,copy:()=>pu,clone:()=>_u,adjoint:()=>bu,add:()=>su,LDU:()=>du});function Cu(){var J=new $0(4);if($0!=Float32Array)J[1]=0,J[2]=0;return J[0]=1,J[3]=1,J}function _u(J){var Z=new $0(4);return Z[0]=J[0],Z[1]=J[1],Z[2]=J[2],Z[3]=J[3],Z}function pu(J,Z){return J[0]=Z[0],J[1]=Z[1],J[2]=Z[2],J[3]=Z[3],J}function fu(J){return J[0]=1,J[1]=0,J[2]=0,J[3]=1,J}function Iu(J,Z,Y,X){var F=new $0(4);return F[0]=J,F[1]=Z,F[2]=Y,F[3]=X,F}function hu(J,Z,Y,X,F){return J[0]=Z,J[1]=Y,J[2]=X,J[3]=F,J}function cu(J,Z){if(J===Z){var Y=Z[1];J[1]=Z[2],J[2]=Y}else J[0]=Z[0],J[1]=Z[2],J[2]=Z[1],J[3]=Z[3];return J}function lu(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Y*K-F*X;if(!$)return null;return $=1/$,J[0]=K*$,J[1]=-X*$,J[2]=-F*$,J[3]=Y*$,J}function bu(J,Z){var Y=Z[0];return J[0]=Z[3],J[1]=-Z[1],J[2]=-Z[2],J[3]=Y,J}function mu(J){return J[0]*J[3]-J[2]*J[1]}function aR(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Y[0],W=Y[1],G=Y[2],V=Y[3];return J[0]=X*Q+K*W,J[1]=F*Q+$*W,J[2]=X*G+K*V,J[3]=F*G+$*V,J}function gu(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Math.sin(Y),W=Math.cos(Y);return J[0]=X*W+K*Q,J[1]=F*W+$*Q,J[2]=X*-Q+K*W,J[3]=F*-Q+$*W,J}function Au(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Y[0],W=Y[1];return J[0]=X*Q,J[1]=F*Q,J[2]=K*W,J[3]=$*W,J}function iu(J,Z){var Y=Math.sin(Z),X=Math.cos(Z);return J[0]=X,J[1]=Y,J[2]=-Y,J[3]=X,J}function yu(J,Z){return J[0]=Z[0],J[1]=0,J[2]=0,J[3]=Z[1],J}function nu(J){return"mat2("+J[0]+", "+J[1]+", "+J[2]+", "+J[3]+")"}function uu(J){return Math.hypot(J[0],J[1],J[2],J[3])}function du(J,Z,Y,X){return J[2]=X[2]/X[0],Y[0]=X[0],Y[1]=X[1],Y[3]=X[3]-J[2]*Y[1],[J,Z,Y]}function su(J,Z,Y){return J[0]=Z[0]+Y[0],J[1]=Z[1]+Y[1],J[2]=Z[2]+Y[2],J[3]=Z[3]+Y[3],J}function oR(J,Z,Y){return J[0]=Z[0]-Y[0],J[1]=Z[1]-Y[1],J[2]=Z[2]-Y[2],J[3]=Z[3]-Y[3],J}function au(J,Z){return J[0]===Z[0]&&J[1]===Z[1]&&J[2]===Z[2]&&J[3]===Z[3]}function ou(J,Z){var Y=J[0],X=J[1],F=J[2],K=J[3],$=Z[0],Q=Z[1],W=Z[2],G=Z[3];return Math.abs(Y-$)<=i*Math.max(1,Math.abs(Y),Math.abs($))&&Math.abs(X-Q)<=i*Math.max(1,Math.abs(X),Math.abs(Q))&&Math.abs(F-W)<=i*Math.max(1,Math.abs(F),Math.abs(W))&&Math.abs(K-G)<=i*Math.max(1,Math.abs(K),Math.abs(G))}function ru(J,Z,Y){return J[0]=Z[0]*Y,J[1]=Z[1]*Y,J[2]=Z[2]*Y,J[3]=Z[3]*Y,J}function tu(J,Z,Y,X){return J[0]=Z[0]+Y[0]*X,J[1]=Z[1]+Y[1]*X,J[2]=Z[2]+Y[2]*X,J[3]=Z[3]+Y[3]*X,J}var eu=aR,Jd=oR;var f0={};E6(f0,{transpose:()=>Qd,translate:()=>Od,subtract:()=>tR,sub:()=>Sd,str:()=>Pd,set:()=>Kd,scale:()=>Ld,rotate:()=>vd,projection:()=>Ud,normalFromMat4:()=>Md,multiplyScalarAndAdd:()=>kd,multiplyScalar:()=>xd,multiply:()=>rR,mul:()=>Td,invert:()=>Gd,identity:()=>$d,fromValues:()=>Fd,fromTranslation:()=>qd,fromScaling:()=>Hd,fromRotation:()=>wd,fromQuat:()=>zd,fromMat4:()=>Zd,fromMat2d:()=>Nd,frob:()=>Rd,exactEquals:()=>Dd,equals:()=>Bd,determinant:()=>Vd,create:()=>ZG,copy:()=>Xd,clone:()=>Yd,adjoint:()=>Wd,add:()=>jd});function ZG(){var J=new $0(9);if($0!=Float32Array)J[1]=0,J[2]=0,J[3]=0,J[5]=0,J[6]=0,J[7]=0;return J[0]=1,J[4]=1,J[8]=1,J}function Zd(J,Z){return J[0]=Z[0],J[1]=Z[1],J[2]=Z[2],J[3]=Z[4],J[4]=Z[5],J[5]=Z[6],J[6]=Z[8],J[7]=Z[9],J[8]=Z[10],J}function Yd(J){var Z=new $0(9);return Z[0]=J[0],Z[1]=J[1],Z[2]=J[2],Z[3]=J[3],Z[4]=J[4],Z[5]=J[5],Z[6]=J[6],Z[7]=J[7],Z[8]=J[8],Z}function Xd(J,Z){return J[0]=Z[0],J[1]=Z[1],J[2]=Z[2],J[3]=Z[3],J[4]=Z[4],J[5]=Z[5],J[6]=Z[6],J[7]=Z[7],J[8]=Z[8],J}function Fd(J,Z,Y,X,F,K,$,Q,W){var G=new $0(9);return G[0]=J,G[1]=Z,G[2]=Y,G[3]=X,G[4]=F,G[5]=K,G[6]=$,G[7]=Q,G[8]=W,G}function Kd(J,Z,Y,X,F,K,$,Q,W,G){return J[0]=Z,J[1]=Y,J[2]=X,J[3]=F,J[4]=K,J[5]=$,J[6]=Q,J[7]=W,J[8]=G,J}function $d(J){return J[0]=1,J[1]=0,J[2]=0,J[3]=0,J[4]=1,J[5]=0,J[6]=0,J[7]=0,J[8]=1,J}function Qd(J,Z){if(J===Z){var Y=Z[1],X=Z[2],F=Z[5];J[1]=Z[3],J[2]=Z[6],J[3]=Y,J[5]=Z[7],J[6]=X,J[7]=F}else J[0]=Z[0],J[1]=Z[3],J[2]=Z[6],J[3]=Z[1],J[4]=Z[4],J[5]=Z[7],J[6]=Z[2],J[7]=Z[5],J[8]=Z[8];return J}function Gd(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Z[4],Q=Z[5],W=Z[6],G=Z[7],V=Z[8],O=V*$-Q*G,v=-V*K+Q*W,w=G*K-$*W,H=Y*O+X*v+F*w;if(!H)return null;return H=1/H,J[0]=O*H,J[1]=(-V*X+F*G)*H,J[2]=(Q*X-F*$)*H,J[3]=v*H,J[4]=(V*Y-F*W)*H,J[5]=(-Q*Y+F*K)*H,J[6]=w*H,J[7]=(-G*Y+X*W)*H,J[8]=($*Y-X*K)*H,J}function Wd(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Z[4],Q=Z[5],W=Z[6],G=Z[7],V=Z[8];return J[0]=$*V-Q*G,J[1]=F*G-X*V,J[2]=X*Q-F*$,J[3]=Q*W-K*V,J[4]=Y*V-F*W,J[5]=F*K-Y*Q,J[6]=K*G-$*W,J[7]=X*W-Y*G,J[8]=Y*$-X*K,J}function Vd(J){var Z=J[0],Y=J[1],X=J[2],F=J[3],K=J[4],$=J[5],Q=J[6],W=J[7],G=J[8];return Z*(G*K-$*W)+Y*(-G*F+$*Q)+X*(W*F-K*Q)}function rR(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Z[4],W=Z[5],G=Z[6],V=Z[7],O=Z[8],v=Y[0],w=Y[1],H=Y[2],N=Y[3],q=Y[4],M=Y[5],R=Y[6],P=Y[7],x=Y[8];return J[0]=v*X+w*$+H*G,J[1]=v*F+w*Q+H*V,J[2]=v*K+w*W+H*O,J[3]=N*X+q*$+M*G,J[4]=N*F+q*Q+M*V,J[5]=N*K+q*W+M*O,J[6]=R*X+P*$+x*G,J[7]=R*F+P*Q+x*V,J[8]=R*K+P*W+x*O,J}function Od(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Z[4],W=Z[5],G=Z[6],V=Z[7],O=Z[8],v=Y[0],w=Y[1];return J[0]=X,J[1]=F,J[2]=K,J[3]=$,J[4]=Q,J[5]=W,J[6]=v*X+w*$+G,J[7]=v*F+w*Q+V,J[8]=v*K+w*W+O,J}function vd(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Z[4],W=Z[5],G=Z[6],V=Z[7],O=Z[8],v=Math.sin(Y),w=Math.cos(Y);return J[0]=w*X+v*$,J[1]=w*F+v*Q,J[2]=w*K+v*W,J[3]=w*$-v*X,J[4]=w*Q-v*F,J[5]=w*W-v*K,J[6]=G,J[7]=V,J[8]=O,J}function Ld(J,Z,Y){var X=Y[0],F=Y[1];return J[0]=X*Z[0],J[1]=X*Z[1],J[2]=X*Z[2],J[3]=F*Z[3],J[4]=F*Z[4],J[5]=F*Z[5],J[6]=Z[6],J[7]=Z[7],J[8]=Z[8],J}function qd(J,Z){return J[0]=1,J[1]=0,J[2]=0,J[3]=0,J[4]=1,J[5]=0,J[6]=Z[0],J[7]=Z[1],J[8]=1,J}function wd(J,Z){var Y=Math.sin(Z),X=Math.cos(Z);return J[0]=X,J[1]=Y,J[2]=0,J[3]=-Y,J[4]=X,J[5]=0,J[6]=0,J[7]=0,J[8]=1,J}function Hd(J,Z){return J[0]=Z[0],J[1]=0,J[2]=0,J[3]=0,J[4]=Z[1],J[5]=0,J[6]=0,J[7]=0,J[8]=1,J}function Nd(J,Z){return J[0]=Z[0],J[1]=Z[1],J[2]=0,J[3]=Z[2],J[4]=Z[3],J[5]=0,J[6]=Z[4],J[7]=Z[5],J[8]=1,J}function zd(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Y+Y,Q=X+X,W=F+F,G=Y*$,V=X*$,O=X*Q,v=F*$,w=F*Q,H=F*W,N=K*$,q=K*Q,M=K*W;return J[0]=1-O-H,J[3]=V-M,J[6]=v+q,J[1]=V+M,J[4]=1-G-H,J[7]=w-N,J[2]=v-q,J[5]=w+N,J[8]=1-G-O,J}function Md(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Z[4],Q=Z[5],W=Z[6],G=Z[7],V=Z[8],O=Z[9],v=Z[10],w=Z[11],H=Z[12],N=Z[13],q=Z[14],M=Z[15],R=Y*Q-X*$,P=Y*W-F*$,x=Y*G-K*$,j=X*W-F*Q,z=X*G-K*Q,B=F*G-K*W,S=V*N-O*H,E=V*q-v*H,C=V*M-w*H,f=O*q-v*N,p=O*M-w*N,c=v*M-w*q,_=R*c-P*p+x*f+j*C-z*E+B*S;if(!_)return null;return _=1/_,J[0]=(Q*c-W*p+G*f)*_,J[1]=(W*C-$*c-G*E)*_,J[2]=($*p-Q*C+G*S)*_,J[3]=(F*p-X*c-K*f)*_,J[4]=(Y*c-F*C+K*E)*_,J[5]=(X*C-Y*p-K*S)*_,J[6]=(N*B-q*z+M*j)*_,J[7]=(q*x-H*B-M*P)*_,J[8]=(H*z-N*x+M*R)*_,J}function Ud(J,Z,Y){return J[0]=2/Z,J[1]=0,J[2]=0,J[3]=0,J[4]=-2/Y,J[5]=0,J[6]=-1,J[7]=1,J[8]=1,J}function Pd(J){return"mat3("+J[0]+", "+J[1]+", "+J[2]+", "+J[3]+", "+J[4]+", "+J[5]+", "+J[6]+", "+J[7]+", "+J[8]+")"}function Rd(J){return Math.hypot(J[0],J[1],J[2],J[3],J[4],J[5],J[6],J[7],J[8])}function jd(J,Z,Y){return J[0]=Z[0]+Y[0],J[1]=Z[1]+Y[1],J[2]=Z[2]+Y[2],J[3]=Z[3]+Y[3],J[4]=Z[4]+Y[4],J[5]=Z[5]+Y[5],J[6]=Z[6]+Y[6],J[7]=Z[7]+Y[7],J[8]=Z[8]+Y[8],J}function tR(J,Z,Y){return J[0]=Z[0]-Y[0],J[1]=Z[1]-Y[1],J[2]=Z[2]-Y[2],J[3]=Z[3]-Y[3],J[4]=Z[4]-Y[4],J[5]=Z[5]-Y[5],J[6]=Z[6]-Y[6],J[7]=Z[7]-Y[7],J[8]=Z[8]-Y[8],J}function xd(J,Z,Y){return J[0]=Z[0]*Y,J[1]=Z[1]*Y,J[2]=Z[2]*Y,J[3]=Z[3]*Y,J[4]=Z[4]*Y,J[5]=Z[5]*Y,J[6]=Z[6]*Y,J[7]=Z[7]*Y,J[8]=Z[8]*Y,J}function kd(J,Z,Y,X){return J[0]=Z[0]+Y[0]*X,J[1]=Z[1]+Y[1]*X,J[2]=Z[2]+Y[2]*X,J[3]=Z[3]+Y[3]*X,J[4]=Z[4]+Y[4]*X,J[5]=Z[5]+Y[5]*X,J[6]=Z[6]+Y[6]*X,J[7]=Z[7]+Y[7]*X,J[8]=Z[8]+Y[8]*X,J}function Dd(J,Z){return J[0]===Z[0]&&J[1]===Z[1]&&J[2]===Z[2]&&J[3]===Z[3]&&J[4]===Z[4]&&J[5]===Z[5]&&J[6]===Z[6]&&J[7]===Z[7]&&J[8]===Z[8]}function Bd(J,Z){var Y=J[0],X=J[1],F=J[2],K=J[3],$=J[4],Q=J[5],W=J[6],G=J[7],V=J[8],O=Z[0],v=Z[1],w=Z[2],H=Z[3],N=Z[4],q=Z[5],M=Z[6],R=Z[7],P=Z[8];return Math.abs(Y-O)<=i*Math.max(1,Math.abs(Y),Math.abs(O))&&Math.abs(X-v)<=i*Math.max(1,Math.abs(X),Math.abs(v))&&Math.abs(F-w)<=i*Math.max(1,Math.abs(F),Math.abs(w))&&Math.abs(K-H)<=i*Math.max(1,Math.abs(K),Math.abs(H))&&Math.abs($-N)<=i*Math.max(1,Math.abs($),Math.abs(N))&&Math.abs(Q-q)<=i*Math.max(1,Math.abs(Q),Math.abs(q))&&Math.abs(W-M)<=i*Math.max(1,Math.abs(W),Math.abs(M))&&Math.abs(G-R)<=i*Math.max(1,Math.abs(G),Math.abs(R))&&Math.abs(V-P)<=i*Math.max(1,Math.abs(V),Math.abs(P))}var Td=rR,Sd=tR;var J0={};E6(J0,{transpose:()=>Id,translate:()=>bd,targetTo:()=>Vs,subtract:()=>Kj,sub:()=>Ms,str:()=>Os,set:()=>fd,scale:()=>md,rotateZ:()=>yd,rotateY:()=>id,rotateX:()=>Ad,rotate:()=>gd,perspectiveZO:()=>Ks,perspectiveNO:()=>Xj,perspectiveFromFieldOfView:()=>$s,perspective:()=>Fs,orthoZO:()=>Gs,orthoNO:()=>Fj,ortho:()=>Qs,multiplyScalarAndAdd:()=>ws,multiplyScalar:()=>qs,multiply:()=>Jj,mul:()=>zs,lookAt:()=>Ws,invert:()=>hd,identity:()=>eR,getTranslation:()=>td,getScaling:()=>Yj,getRotation:()=>ed,frustum:()=>Xs,fromZRotation:()=>od,fromYRotation:()=>ad,fromXRotation:()=>sd,fromValues:()=>pd,fromTranslation:()=>nd,fromScaling:()=>ud,fromRotationTranslationScaleOrigin:()=>Zs,fromRotationTranslationScale:()=>Js,fromRotationTranslation:()=>Zj,fromRotation:()=>dd,fromQuat2:()=>rd,fromQuat:()=>Ys,frob:()=>vs,exactEquals:()=>Hs,equals:()=>Ns,determinant:()=>ld,create:()=>Ed,copy:()=>_d,clone:()=>Cd,adjoint:()=>cd,add:()=>Ls});function Ed(){var J=new $0(16);if($0!=Float32Array)J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[11]=0,J[12]=0,J[13]=0,J[14]=0;return J[0]=1,J[5]=1,J[10]=1,J[15]=1,J}function Cd(J){var Z=new $0(16);return Z[0]=J[0],Z[1]=J[1],Z[2]=J[2],Z[3]=J[3],Z[4]=J[4],Z[5]=J[5],Z[6]=J[6],Z[7]=J[7],Z[8]=J[8],Z[9]=J[9],Z[10]=J[10],Z[11]=J[11],Z[12]=J[12],Z[13]=J[13],Z[14]=J[14],Z[15]=J[15],Z}function _d(J,Z){return J[0]=Z[0],J[1]=Z[1],J[2]=Z[2],J[3]=Z[3],J[4]=Z[4],J[5]=Z[5],J[6]=Z[6],J[7]=Z[7],J[8]=Z[8],J[9]=Z[9],J[10]=Z[10],J[11]=Z[11],J[12]=Z[12],J[13]=Z[13],J[14]=Z[14],J[15]=Z[15],J}function pd(J,Z,Y,X,F,K,$,Q,W,G,V,O,v,w,H,N){var q=new $0(16);return q[0]=J,q[1]=Z,q[2]=Y,q[3]=X,q[4]=F,q[5]=K,q[6]=$,q[7]=Q,q[8]=W,q[9]=G,q[10]=V,q[11]=O,q[12]=v,q[13]=w,q[14]=H,q[15]=N,q}function fd(J,Z,Y,X,F,K,$,Q,W,G,V,O,v,w,H,N,q){return J[0]=Z,J[1]=Y,J[2]=X,J[3]=F,J[4]=K,J[5]=$,J[6]=Q,J[7]=W,J[8]=G,J[9]=V,J[10]=O,J[11]=v,J[12]=w,J[13]=H,J[14]=N,J[15]=q,J}function eR(J){return J[0]=1,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=1,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=1,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function Id(J,Z){if(J===Z){var Y=Z[1],X=Z[2],F=Z[3],K=Z[6],$=Z[7],Q=Z[11];J[1]=Z[4],J[2]=Z[8],J[3]=Z[12],J[4]=Y,J[6]=Z[9],J[7]=Z[13],J[8]=X,J[9]=K,J[11]=Z[14],J[12]=F,J[13]=$,J[14]=Q}else J[0]=Z[0],J[1]=Z[4],J[2]=Z[8],J[3]=Z[12],J[4]=Z[1],J[5]=Z[5],J[6]=Z[9],J[7]=Z[13],J[8]=Z[2],J[9]=Z[6],J[10]=Z[10],J[11]=Z[14],J[12]=Z[3],J[13]=Z[7],J[14]=Z[11],J[15]=Z[15];return J}function hd(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Z[4],Q=Z[5],W=Z[6],G=Z[7],V=Z[8],O=Z[9],v=Z[10],w=Z[11],H=Z[12],N=Z[13],q=Z[14],M=Z[15],R=Y*Q-X*$,P=Y*W-F*$,x=Y*G-K*$,j=X*W-F*Q,z=X*G-K*Q,B=F*G-K*W,S=V*N-O*H,E=V*q-v*H,C=V*M-w*H,f=O*q-v*N,p=O*M-w*N,c=v*M-w*q,_=R*c-P*p+x*f+j*C-z*E+B*S;if(!_)return null;return _=1/_,J[0]=(Q*c-W*p+G*f)*_,J[1]=(F*p-X*c-K*f)*_,J[2]=(N*B-q*z+M*j)*_,J[3]=(v*z-O*B-w*j)*_,J[4]=(W*C-$*c-G*E)*_,J[5]=(Y*c-F*C+K*E)*_,J[6]=(q*x-H*B-M*P)*_,J[7]=(V*B-v*x+w*P)*_,J[8]=($*p-Q*C+G*S)*_,J[9]=(X*C-Y*p-K*S)*_,J[10]=(H*z-N*x+M*R)*_,J[11]=(O*x-V*z-w*R)*_,J[12]=(Q*E-$*f-W*S)*_,J[13]=(Y*f-X*E+F*S)*_,J[14]=(N*P-H*j-q*R)*_,J[15]=(V*j-O*P+v*R)*_,J}function cd(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Z[4],Q=Z[5],W=Z[6],G=Z[7],V=Z[8],O=Z[9],v=Z[10],w=Z[11],H=Z[12],N=Z[13],q=Z[14],M=Z[15];return J[0]=Q*(v*M-w*q)-O*(W*M-G*q)+N*(W*w-G*v),J[1]=-(X*(v*M-w*q)-O*(F*M-K*q)+N*(F*w-K*v)),J[2]=X*(W*M-G*q)-Q*(F*M-K*q)+N*(F*G-K*W),J[3]=-(X*(W*w-G*v)-Q*(F*w-K*v)+O*(F*G-K*W)),J[4]=-($*(v*M-w*q)-V*(W*M-G*q)+H*(W*w-G*v)),J[5]=Y*(v*M-w*q)-V*(F*M-K*q)+H*(F*w-K*v),J[6]=-(Y*(W*M-G*q)-$*(F*M-K*q)+H*(F*G-K*W)),J[7]=Y*(W*w-G*v)-$*(F*w-K*v)+V*(F*G-K*W),J[8]=$*(O*M-w*N)-V*(Q*M-G*N)+H*(Q*w-G*O),J[9]=-(Y*(O*M-w*N)-V*(X*M-K*N)+H*(X*w-K*O)),J[10]=Y*(Q*M-G*N)-$*(X*M-K*N)+H*(X*G-K*Q),J[11]=-(Y*(Q*w-G*O)-$*(X*w-K*O)+V*(X*G-K*Q)),J[12]=-($*(O*q-v*N)-V*(Q*q-W*N)+H*(Q*v-W*O)),J[13]=Y*(O*q-v*N)-V*(X*q-F*N)+H*(X*v-F*O),J[14]=-(Y*(Q*q-W*N)-$*(X*q-F*N)+H*(X*W-F*Q)),J[15]=Y*(Q*v-W*O)-$*(X*v-F*O)+V*(X*W-F*Q),J}function ld(J){var Z=J[0],Y=J[1],X=J[2],F=J[3],K=J[4],$=J[5],Q=J[6],W=J[7],G=J[8],V=J[9],O=J[10],v=J[11],w=J[12],H=J[13],N=J[14],q=J[15],M=Z*$-Y*K,R=Z*Q-X*K,P=Z*W-F*K,x=Y*Q-X*$,j=Y*W-F*$,z=X*W-F*Q,B=G*H-V*w,S=G*N-O*w,E=G*q-v*w,C=V*N-O*H,f=V*q-v*H,p=O*q-v*N;return M*p-R*f+P*C+x*E-j*S+z*B}function Jj(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Z[4],W=Z[5],G=Z[6],V=Z[7],O=Z[8],v=Z[9],w=Z[10],H=Z[11],N=Z[12],q=Z[13],M=Z[14],R=Z[15],P=Y[0],x=Y[1],j=Y[2],z=Y[3];return J[0]=P*X+x*Q+j*O+z*N,J[1]=P*F+x*W+j*v+z*q,J[2]=P*K+x*G+j*w+z*M,J[3]=P*$+x*V+j*H+z*R,P=Y[4],x=Y[5],j=Y[6],z=Y[7],J[4]=P*X+x*Q+j*O+z*N,J[5]=P*F+x*W+j*v+z*q,J[6]=P*K+x*G+j*w+z*M,J[7]=P*$+x*V+j*H+z*R,P=Y[8],x=Y[9],j=Y[10],z=Y[11],J[8]=P*X+x*Q+j*O+z*N,J[9]=P*F+x*W+j*v+z*q,J[10]=P*K+x*G+j*w+z*M,J[11]=P*$+x*V+j*H+z*R,P=Y[12],x=Y[13],j=Y[14],z=Y[15],J[12]=P*X+x*Q+j*O+z*N,J[13]=P*F+x*W+j*v+z*q,J[14]=P*K+x*G+j*w+z*M,J[15]=P*$+x*V+j*H+z*R,J}function bd(J,Z,Y){var X=Y[0],F=Y[1],K=Y[2],$,Q,W,G,V,O,v,w,H,N,q,M;if(Z===J)J[12]=Z[0]*X+Z[4]*F+Z[8]*K+Z[12],J[13]=Z[1]*X+Z[5]*F+Z[9]*K+Z[13],J[14]=Z[2]*X+Z[6]*F+Z[10]*K+Z[14],J[15]=Z[3]*X+Z[7]*F+Z[11]*K+Z[15];else $=Z[0],Q=Z[1],W=Z[2],G=Z[3],V=Z[4],O=Z[5],v=Z[6],w=Z[7],H=Z[8],N=Z[9],q=Z[10],M=Z[11],J[0]=$,J[1]=Q,J[2]=W,J[3]=G,J[4]=V,J[5]=O,J[6]=v,J[7]=w,J[8]=H,J[9]=N,J[10]=q,J[11]=M,J[12]=$*X+V*F+H*K+Z[12],J[13]=Q*X+O*F+N*K+Z[13],J[14]=W*X+v*F+q*K+Z[14],J[15]=G*X+w*F+M*K+Z[15];return J}function md(J,Z,Y){var X=Y[0],F=Y[1],K=Y[2];return J[0]=Z[0]*X,J[1]=Z[1]*X,J[2]=Z[2]*X,J[3]=Z[3]*X,J[4]=Z[4]*F,J[5]=Z[5]*F,J[6]=Z[6]*F,J[7]=Z[7]*F,J[8]=Z[8]*K,J[9]=Z[9]*K,J[10]=Z[10]*K,J[11]=Z[11]*K,J[12]=Z[12],J[13]=Z[13],J[14]=Z[14],J[15]=Z[15],J}function gd(J,Z,Y,X){var F=X[0],K=X[1],$=X[2],Q=Math.hypot(F,K,$),W,G,V,O,v,w,H,N,q,M,R,P,x,j,z,B,S,E,C,f,p,c,_,b;if(Q<i)return null;if(Q=1/Q,F*=Q,K*=Q,$*=Q,W=Math.sin(Y),G=Math.cos(Y),V=1-G,O=Z[0],v=Z[1],w=Z[2],H=Z[3],N=Z[4],q=Z[5],M=Z[6],R=Z[7],P=Z[8],x=Z[9],j=Z[10],z=Z[11],B=F*F*V+G,S=K*F*V+$*W,E=$*F*V-K*W,C=F*K*V-$*W,f=K*K*V+G,p=$*K*V+F*W,c=F*$*V+K*W,_=K*$*V-F*W,b=$*$*V+G,J[0]=O*B+N*S+P*E,J[1]=v*B+q*S+x*E,J[2]=w*B+M*S+j*E,J[3]=H*B+R*S+z*E,J[4]=O*C+N*f+P*p,J[5]=v*C+q*f+x*p,J[6]=w*C+M*f+j*p,J[7]=H*C+R*f+z*p,J[8]=O*c+N*_+P*b,J[9]=v*c+q*_+x*b,J[10]=w*c+M*_+j*b,J[11]=H*c+R*_+z*b,Z!==J)J[12]=Z[12],J[13]=Z[13],J[14]=Z[14],J[15]=Z[15];return J}function Ad(J,Z,Y){var X=Math.sin(Y),F=Math.cos(Y),K=Z[4],$=Z[5],Q=Z[6],W=Z[7],G=Z[8],V=Z[9],O=Z[10],v=Z[11];if(Z!==J)J[0]=Z[0],J[1]=Z[1],J[2]=Z[2],J[3]=Z[3],J[12]=Z[12],J[13]=Z[13],J[14]=Z[14],J[15]=Z[15];return J[4]=K*F+G*X,J[5]=$*F+V*X,J[6]=Q*F+O*X,J[7]=W*F+v*X,J[8]=G*F-K*X,J[9]=V*F-$*X,J[10]=O*F-Q*X,J[11]=v*F-W*X,J}function id(J,Z,Y){var X=Math.sin(Y),F=Math.cos(Y),K=Z[0],$=Z[1],Q=Z[2],W=Z[3],G=Z[8],V=Z[9],O=Z[10],v=Z[11];if(Z!==J)J[4]=Z[4],J[5]=Z[5],J[6]=Z[6],J[7]=Z[7],J[12]=Z[12],J[13]=Z[13],J[14]=Z[14],J[15]=Z[15];return J[0]=K*F-G*X,J[1]=$*F-V*X,J[2]=Q*F-O*X,J[3]=W*F-v*X,J[8]=K*X+G*F,J[9]=$*X+V*F,J[10]=Q*X+O*F,J[11]=W*X+v*F,J}function yd(J,Z,Y){var X=Math.sin(Y),F=Math.cos(Y),K=Z[0],$=Z[1],Q=Z[2],W=Z[3],G=Z[4],V=Z[5],O=Z[6],v=Z[7];if(Z!==J)J[8]=Z[8],J[9]=Z[9],J[10]=Z[10],J[11]=Z[11],J[12]=Z[12],J[13]=Z[13],J[14]=Z[14],J[15]=Z[15];return J[0]=K*F+G*X,J[1]=$*F+V*X,J[2]=Q*F+O*X,J[3]=W*F+v*X,J[4]=G*F-K*X,J[5]=V*F-$*X,J[6]=O*F-Q*X,J[7]=v*F-W*X,J}function nd(J,Z){return J[0]=1,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=1,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=1,J[11]=0,J[12]=Z[0],J[13]=Z[1],J[14]=Z[2],J[15]=1,J}function ud(J,Z){return J[0]=Z[0],J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=Z[1],J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=Z[2],J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function dd(J,Z,Y){var X=Y[0],F=Y[1],K=Y[2],$=Math.hypot(X,F,K),Q,W,G;if($<i)return null;return $=1/$,X*=$,F*=$,K*=$,Q=Math.sin(Z),W=Math.cos(Z),G=1-W,J[0]=X*X*G+W,J[1]=F*X*G+K*Q,J[2]=K*X*G-F*Q,J[3]=0,J[4]=X*F*G-K*Q,J[5]=F*F*G+W,J[6]=K*F*G+X*Q,J[7]=0,J[8]=X*K*G+F*Q,J[9]=F*K*G-X*Q,J[10]=K*K*G+W,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function sd(J,Z){var Y=Math.sin(Z),X=Math.cos(Z);return J[0]=1,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=X,J[6]=Y,J[7]=0,J[8]=0,J[9]=-Y,J[10]=X,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function ad(J,Z){var Y=Math.sin(Z),X=Math.cos(Z);return J[0]=X,J[1]=0,J[2]=-Y,J[3]=0,J[4]=0,J[5]=1,J[6]=0,J[7]=0,J[8]=Y,J[9]=0,J[10]=X,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function od(J,Z){var Y=Math.sin(Z),X=Math.cos(Z);return J[0]=X,J[1]=Y,J[2]=0,J[3]=0,J[4]=-Y,J[5]=X,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=1,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function Zj(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=X+X,W=F+F,G=K+K,V=X*Q,O=X*W,v=X*G,w=F*W,H=F*G,N=K*G,q=$*Q,M=$*W,R=$*G;return J[0]=1-(w+N),J[1]=O+R,J[2]=v-M,J[3]=0,J[4]=O-R,J[5]=1-(V+N),J[6]=H+q,J[7]=0,J[8]=v+M,J[9]=H-q,J[10]=1-(V+w),J[11]=0,J[12]=Y[0],J[13]=Y[1],J[14]=Y[2],J[15]=1,J}function rd(J,Z){var Y=new $0(3),X=-Z[0],F=-Z[1],K=-Z[2],$=Z[3],Q=Z[4],W=Z[5],G=Z[6],V=Z[7],O=X*X+F*F+K*K+$*$;if(O>0)Y[0]=(Q*$+V*X+W*K-G*F)*2/O,Y[1]=(W*$+V*F+G*X-Q*K)*2/O,Y[2]=(G*$+V*K+Q*F-W*X)*2/O;else Y[0]=(Q*$+V*X+W*K-G*F)*2,Y[1]=(W*$+V*F+G*X-Q*K)*2,Y[2]=(G*$+V*K+Q*F-W*X)*2;return Zj(J,Z,Y),J}function td(J,Z){return J[0]=Z[12],J[1]=Z[13],J[2]=Z[14],J}function Yj(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[4],$=Z[5],Q=Z[6],W=Z[8],G=Z[9],V=Z[10];return J[0]=Math.hypot(Y,X,F),J[1]=Math.hypot(K,$,Q),J[2]=Math.hypot(W,G,V),J}function ed(J,Z){var Y=new $0(3);Yj(Y,Z);var X=1/Y[0],F=1/Y[1],K=1/Y[2],$=Z[0]*X,Q=Z[1]*F,W=Z[2]*K,G=Z[4]*X,V=Z[5]*F,O=Z[6]*K,v=Z[8]*X,w=Z[9]*F,H=Z[10]*K,N=$+V+H,q=0;if(N>0)q=Math.sqrt(N+1)*2,J[3]=0.25*q,J[0]=(O-w)/q,J[1]=(v-W)/q,J[2]=(Q-G)/q;else if($>V&&$>H)q=Math.sqrt(1+$-V-H)*2,J[3]=(O-w)/q,J[0]=0.25*q,J[1]=(Q+G)/q,J[2]=(v+W)/q;else if(V>H)q=Math.sqrt(1+V-$-H)*2,J[3]=(v-W)/q,J[0]=(Q+G)/q,J[1]=0.25*q,J[2]=(O+w)/q;else q=Math.sqrt(1+H-$-V)*2,J[3]=(Q-G)/q,J[0]=(v+W)/q,J[1]=(O+w)/q,J[2]=0.25*q;return J}function Js(J,Z,Y,X){var F=Z[0],K=Z[1],$=Z[2],Q=Z[3],W=F+F,G=K+K,V=$+$,O=F*W,v=F*G,w=F*V,H=K*G,N=K*V,q=$*V,M=Q*W,R=Q*G,P=Q*V,x=X[0],j=X[1],z=X[2];return J[0]=(1-(H+q))*x,J[1]=(v+P)*x,J[2]=(w-R)*x,J[3]=0,J[4]=(v-P)*j,J[5]=(1-(O+q))*j,J[6]=(N+M)*j,J[7]=0,J[8]=(w+R)*z,J[9]=(N-M)*z,J[10]=(1-(O+H))*z,J[11]=0,J[12]=Y[0],J[13]=Y[1],J[14]=Y[2],J[15]=1,J}function Zs(J,Z,Y,X,F){var K=Z[0],$=Z[1],Q=Z[2],W=Z[3],G=K+K,V=$+$,O=Q+Q,v=K*G,w=K*V,H=K*O,N=$*V,q=$*O,M=Q*O,R=W*G,P=W*V,x=W*O,j=X[0],z=X[1],B=X[2],S=F[0],E=F[1],C=F[2],f=(1-(N+M))*j,p=(w+x)*j,c=(H-P)*j,_=(w-x)*z,b=(1-(v+M))*z,r=(q+R)*z,c0=(H+P)*B,u0=(q-R)*B,t8=(1-(v+N))*B;return J[0]=f,J[1]=p,J[2]=c,J[3]=0,J[4]=_,J[5]=b,J[6]=r,J[7]=0,J[8]=c0,J[9]=u0,J[10]=t8,J[11]=0,J[12]=Y[0]+S-(f*S+_*E+c0*C),J[13]=Y[1]+E-(p*S+b*E+u0*C),J[14]=Y[2]+C-(c*S+r*E+t8*C),J[15]=1,J}function Ys(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Y+Y,Q=X+X,W=F+F,G=Y*$,V=X*$,O=X*Q,v=F*$,w=F*Q,H=F*W,N=K*$,q=K*Q,M=K*W;return J[0]=1-O-H,J[1]=V+M,J[2]=v-q,J[3]=0,J[4]=V-M,J[5]=1-G-H,J[6]=w+N,J[7]=0,J[8]=v+q,J[9]=w-N,J[10]=1-G-O,J[11]=0,J[12]=0,J[13]=0,J[14]=0,J[15]=1,J}function Xs(J,Z,Y,X,F,K,$){var Q=1/(Y-Z),W=1/(F-X),G=1/(K-$);return J[0]=K*2*Q,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=K*2*W,J[6]=0,J[7]=0,J[8]=(Y+Z)*Q,J[9]=(F+X)*W,J[10]=($+K)*G,J[11]=-1,J[12]=0,J[13]=0,J[14]=$*K*2*G,J[15]=0,J}function Xj(J,Z,Y,X,F){var K=1/Math.tan(Z/2),$;if(J[0]=K/Y,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=K,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[11]=-1,J[12]=0,J[13]=0,J[15]=0,F!=null&&F!==1/0)$=1/(X-F),J[10]=(F+X)*$,J[14]=2*F*X*$;else J[10]=-1,J[14]=-2*X;return J}var Fs=Xj;function Ks(J,Z,Y,X,F){var K=1/Math.tan(Z/2),$;if(J[0]=K/Y,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=K,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[11]=-1,J[12]=0,J[13]=0,J[15]=0,F!=null&&F!==1/0)$=1/(X-F),J[10]=F*$,J[14]=F*X*$;else J[10]=-1,J[14]=-X;return J}function $s(J,Z,Y,X){var F=Math.tan(Z.upDegrees*Math.PI/180),K=Math.tan(Z.downDegrees*Math.PI/180),$=Math.tan(Z.leftDegrees*Math.PI/180),Q=Math.tan(Z.rightDegrees*Math.PI/180),W=2/($+Q),G=2/(F+K);return J[0]=W,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=G,J[6]=0,J[7]=0,J[8]=-(($-Q)*W*0.5),J[9]=(F-K)*G*0.5,J[10]=X/(Y-X),J[11]=-1,J[12]=0,J[13]=0,J[14]=X*Y/(Y-X),J[15]=0,J}function Fj(J,Z,Y,X,F,K,$){var Q=1/(Z-Y),W=1/(X-F),G=1/(K-$);return J[0]=-2*Q,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=-2*W,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=2*G,J[11]=0,J[12]=(Z+Y)*Q,J[13]=(F+X)*W,J[14]=($+K)*G,J[15]=1,J}var Qs=Fj;function Gs(J,Z,Y,X,F,K,$){var Q=1/(Z-Y),W=1/(X-F),G=1/(K-$);return J[0]=-2*Q,J[1]=0,J[2]=0,J[3]=0,J[4]=0,J[5]=-2*W,J[6]=0,J[7]=0,J[8]=0,J[9]=0,J[10]=G,J[11]=0,J[12]=(Z+Y)*Q,J[13]=(F+X)*W,J[14]=K*G,J[15]=1,J}function Ws(J,Z,Y,X){var F,K,$,Q,W,G,V,O,v,w,H=Z[0],N=Z[1],q=Z[2],M=X[0],R=X[1],P=X[2],x=Y[0],j=Y[1],z=Y[2];if(Math.abs(H-x)<i&&Math.abs(N-j)<i&&Math.abs(q-z)<i)return eR(J);if(V=H-x,O=N-j,v=q-z,w=1/Math.hypot(V,O,v),V*=w,O*=w,v*=w,F=R*v-P*O,K=P*V-M*v,$=M*O-R*V,w=Math.hypot(F,K,$),!w)F=0,K=0,$=0;else w=1/w,F*=w,K*=w,$*=w;if(Q=O*$-v*K,W=v*F-V*$,G=V*K-O*F,w=Math.hypot(Q,W,G),!w)Q=0,W=0,G=0;else w=1/w,Q*=w,W*=w,G*=w;return J[0]=F,J[1]=Q,J[2]=V,J[3]=0,J[4]=K,J[5]=W,J[6]=O,J[7]=0,J[8]=$,J[9]=G,J[10]=v,J[11]=0,J[12]=-(F*H+K*N+$*q),J[13]=-(Q*H+W*N+G*q),J[14]=-(V*H+O*N+v*q),J[15]=1,J}function Vs(J,Z,Y,X){var F=Z[0],K=Z[1],$=Z[2],Q=X[0],W=X[1],G=X[2],V=F-Y[0],O=K-Y[1],v=$-Y[2],w=V*V+O*O+v*v;if(w>0)w=1/Math.sqrt(w),V*=w,O*=w,v*=w;var H=W*v-G*O,N=G*V-Q*v,q=Q*O-W*V;if(w=H*H+N*N+q*q,w>0)w=1/Math.sqrt(w),H*=w,N*=w,q*=w;return J[0]=H,J[1]=N,J[2]=q,J[3]=0,J[4]=O*q-v*N,J[5]=v*H-V*q,J[6]=V*N-O*H,J[7]=0,J[8]=V,J[9]=O,J[10]=v,J[11]=0,J[12]=F,J[13]=K,J[14]=$,J[15]=1,J}function Os(J){return"mat4("+J[0]+", "+J[1]+", "+J[2]+", "+J[3]+", "+J[4]+", "+J[5]+", "+J[6]+", "+J[7]+", "+J[8]+", "+J[9]+", "+J[10]+", "+J[11]+", "+J[12]+", "+J[13]+", "+J[14]+", "+J[15]+")"}function vs(J){return Math.hypot(J[0],J[1],J[2],J[3],J[4],J[5],J[6],J[7],J[8],J[9],J[10],J[11],J[12],J[13],J[14],J[15])}function Ls(J,Z,Y){return J[0]=Z[0]+Y[0],J[1]=Z[1]+Y[1],J[2]=Z[2]+Y[2],J[3]=Z[3]+Y[3],J[4]=Z[4]+Y[4],J[5]=Z[5]+Y[5],J[6]=Z[6]+Y[6],J[7]=Z[7]+Y[7],J[8]=Z[8]+Y[8],J[9]=Z[9]+Y[9],J[10]=Z[10]+Y[10],J[11]=Z[11]+Y[11],J[12]=Z[12]+Y[12],J[13]=Z[13]+Y[13],J[14]=Z[14]+Y[14],J[15]=Z[15]+Y[15],J}function Kj(J,Z,Y){return J[0]=Z[0]-Y[0],J[1]=Z[1]-Y[1],J[2]=Z[2]-Y[2],J[3]=Z[3]-Y[3],J[4]=Z[4]-Y[4],J[5]=Z[5]-Y[5],J[6]=Z[6]-Y[6],J[7]=Z[7]-Y[7],J[8]=Z[8]-Y[8],J[9]=Z[9]-Y[9],J[10]=Z[10]-Y[10],J[11]=Z[11]-Y[11],J[12]=Z[12]-Y[12],J[13]=Z[13]-Y[13],J[14]=Z[14]-Y[14],J[15]=Z[15]-Y[15],J}function qs(J,Z,Y){return J[0]=Z[0]*Y,J[1]=Z[1]*Y,J[2]=Z[2]*Y,J[3]=Z[3]*Y,J[4]=Z[4]*Y,J[5]=Z[5]*Y,J[6]=Z[6]*Y,J[7]=Z[7]*Y,J[8]=Z[8]*Y,J[9]=Z[9]*Y,J[10]=Z[10]*Y,J[11]=Z[11]*Y,J[12]=Z[12]*Y,J[13]=Z[13]*Y,J[14]=Z[14]*Y,J[15]=Z[15]*Y,J}function ws(J,Z,Y,X){return J[0]=Z[0]+Y[0]*X,J[1]=Z[1]+Y[1]*X,J[2]=Z[2]+Y[2]*X,J[3]=Z[3]+Y[3]*X,J[4]=Z[4]+Y[4]*X,J[5]=Z[5]+Y[5]*X,J[6]=Z[6]+Y[6]*X,J[7]=Z[7]+Y[7]*X,J[8]=Z[8]+Y[8]*X,J[9]=Z[9]+Y[9]*X,J[10]=Z[10]+Y[10]*X,J[11]=Z[11]+Y[11]*X,J[12]=Z[12]+Y[12]*X,J[13]=Z[13]+Y[13]*X,J[14]=Z[14]+Y[14]*X,J[15]=Z[15]+Y[15]*X,J}function Hs(J,Z){return J[0]===Z[0]&&J[1]===Z[1]&&J[2]===Z[2]&&J[3]===Z[3]&&J[4]===Z[4]&&J[5]===Z[5]&&J[6]===Z[6]&&J[7]===Z[7]&&J[8]===Z[8]&&J[9]===Z[9]&&J[10]===Z[10]&&J[11]===Z[11]&&J[12]===Z[12]&&J[13]===Z[13]&&J[14]===Z[14]&&J[15]===Z[15]}function Ns(J,Z){var Y=J[0],X=J[1],F=J[2],K=J[3],$=J[4],Q=J[5],W=J[6],G=J[7],V=J[8],O=J[9],v=J[10],w=J[11],H=J[12],N=J[13],q=J[14],M=J[15],R=Z[0],P=Z[1],x=Z[2],j=Z[3],z=Z[4],B=Z[5],S=Z[6],E=Z[7],C=Z[8],f=Z[9],p=Z[10],c=Z[11],_=Z[12],b=Z[13],r=Z[14],c0=Z[15];return Math.abs(Y-R)<=i*Math.max(1,Math.abs(Y),Math.abs(R))&&Math.abs(X-P)<=i*Math.max(1,Math.abs(X),Math.abs(P))&&Math.abs(F-x)<=i*Math.max(1,Math.abs(F),Math.abs(x))&&Math.abs(K-j)<=i*Math.max(1,Math.abs(K),Math.abs(j))&&Math.abs($-z)<=i*Math.max(1,Math.abs($),Math.abs(z))&&Math.abs(Q-B)<=i*Math.max(1,Math.abs(Q),Math.abs(B))&&Math.abs(W-S)<=i*Math.max(1,Math.abs(W),Math.abs(S))&&Math.abs(G-E)<=i*Math.max(1,Math.abs(G),Math.abs(E))&&Math.abs(V-C)<=i*Math.max(1,Math.abs(V),Math.abs(C))&&Math.abs(O-f)<=i*Math.max(1,Math.abs(O),Math.abs(f))&&Math.abs(v-p)<=i*Math.max(1,Math.abs(v),Math.abs(p))&&Math.abs(w-c)<=i*Math.max(1,Math.abs(w),Math.abs(c))&&Math.abs(H-_)<=i*Math.max(1,Math.abs(H),Math.abs(_))&&Math.abs(N-b)<=i*Math.max(1,Math.abs(N),Math.abs(b))&&Math.abs(q-r)<=i*Math.max(1,Math.abs(q),Math.abs(r))&&Math.abs(M-c0)<=i*Math.max(1,Math.abs(M),Math.abs(c0))}var zs=Jj,Ms=Kj;var R0={};E6(R0,{str:()=>wa,squaredLength:()=>fj,sqrLen:()=>xa,sqlerp:()=>Ta,slerp:()=>cY,setAxisAngle:()=>Dj,setAxes:()=>Sa,set:()=>Ma,scale:()=>Cj,rotationTo:()=>Ba,rotateZ:()=>Ga,rotateY:()=>Qa,rotateX:()=>$a,random:()=>Oa,pow:()=>Va,normalize:()=>KG,multiply:()=>Bj,mul:()=>Pa,ln:()=>Sj,lerp:()=>Ra,length:()=>pj,len:()=>ja,invert:()=>va,identity:()=>Xa,getAxisAngle:()=>Fa,getAngle:()=>Ka,fromValues:()=>Na,fromMat3:()=>Ej,fromEuler:()=>qa,exp:()=>Tj,exactEquals:()=>ka,equals:()=>Da,dot:()=>_j,create:()=>FG,copy:()=>za,conjugate:()=>La,clone:()=>Ha,calculateW:()=>Wa,add:()=>Ua});var Y0={};E6(Y0,{zero:()=>ys,transformQuat:()=>bs,transformMat4:()=>cs,transformMat3:()=>ls,subtract:()=>Qj,sub:()=>ss,str:()=>ns,squaredLength:()=>vj,squaredDistance:()=>Oj,sqrLen:()=>es,sqrDist:()=>ts,set:()=>Rs,scaleAndAdd:()=>Es,scale:()=>Ss,round:()=>Ts,rotateZ:()=>As,rotateY:()=>gs,rotateX:()=>ms,random:()=>hs,normalize:()=>YG,negate:()=>Cs,multiply:()=>Gj,mul:()=>as,min:()=>Ds,max:()=>Bs,lerp:()=>ps,length:()=>$j,len:()=>XG,inverse:()=>_s,hermite:()=>fs,fromValues:()=>IY,forEach:()=>Ja,floor:()=>ks,exactEquals:()=>us,equals:()=>ds,dot:()=>hY,divide:()=>Wj,div:()=>os,distance:()=>Vj,dist:()=>rs,cross:()=>w7,create:()=>fY,copy:()=>Ps,clone:()=>Us,ceil:()=>xs,bezier:()=>Is,angle:()=>is,add:()=>js});function fY(){var J=new $0(3);if($0!=Float32Array)J[0]=0,J[1]=0,J[2]=0;return J}function Us(J){var Z=new $0(3);return Z[0]=J[0],Z[1]=J[1],Z[2]=J[2],Z}function $j(J){var Z=J[0],Y=J[1],X=J[2];return Math.hypot(Z,Y,X)}function IY(J,Z,Y){var X=new $0(3);return X[0]=J,X[1]=Z,X[2]=Y,X}function Ps(J,Z){return J[0]=Z[0],J[1]=Z[1],J[2]=Z[2],J}function Rs(J,Z,Y,X){return J[0]=Z,J[1]=Y,J[2]=X,J}function js(J,Z,Y){return J[0]=Z[0]+Y[0],J[1]=Z[1]+Y[1],J[2]=Z[2]+Y[2],J}function Qj(J,Z,Y){return J[0]=Z[0]-Y[0],J[1]=Z[1]-Y[1],J[2]=Z[2]-Y[2],J}function Gj(J,Z,Y){return J[0]=Z[0]*Y[0],J[1]=Z[1]*Y[1],J[2]=Z[2]*Y[2],J}function Wj(J,Z,Y){return J[0]=Z[0]/Y[0],J[1]=Z[1]/Y[1],J[2]=Z[2]/Y[2],J}function xs(J,Z){return J[0]=Math.ceil(Z[0]),J[1]=Math.ceil(Z[1]),J[2]=Math.ceil(Z[2]),J}function ks(J,Z){return J[0]=Math.floor(Z[0]),J[1]=Math.floor(Z[1]),J[2]=Math.floor(Z[2]),J}function Ds(J,Z,Y){return J[0]=Math.min(Z[0],Y[0]),J[1]=Math.min(Z[1],Y[1]),J[2]=Math.min(Z[2],Y[2]),J}function Bs(J,Z,Y){return J[0]=Math.max(Z[0],Y[0]),J[1]=Math.max(Z[1],Y[1]),J[2]=Math.max(Z[2],Y[2]),J}function Ts(J,Z){return J[0]=Math.round(Z[0]),J[1]=Math.round(Z[1]),J[2]=Math.round(Z[2]),J}function Ss(J,Z,Y){return J[0]=Z[0]*Y,J[1]=Z[1]*Y,J[2]=Z[2]*Y,J}function Es(J,Z,Y,X){return J[0]=Z[0]+Y[0]*X,J[1]=Z[1]+Y[1]*X,J[2]=Z[2]+Y[2]*X,J}function Vj(J,Z){var Y=Z[0]-J[0],X=Z[1]-J[1],F=Z[2]-J[2];return Math.hypot(Y,X,F)}function Oj(J,Z){var Y=Z[0]-J[0],X=Z[1]-J[1],F=Z[2]-J[2];return Y*Y+X*X+F*F}function vj(J){var Z=J[0],Y=J[1],X=J[2];return Z*Z+Y*Y+X*X}function Cs(J,Z){return J[0]=-Z[0],J[1]=-Z[1],J[2]=-Z[2],J}function _s(J,Z){return J[0]=1/Z[0],J[1]=1/Z[1],J[2]=1/Z[2],J}function YG(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Y*Y+X*X+F*F;if(K>0)K=1/Math.sqrt(K);return J[0]=Z[0]*K,J[1]=Z[1]*K,J[2]=Z[2]*K,J}function hY(J,Z){return J[0]*Z[0]+J[1]*Z[1]+J[2]*Z[2]}function w7(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Y[0],Q=Y[1],W=Y[2];return J[0]=F*W-K*Q,J[1]=K*$-X*W,J[2]=X*Q-F*$,J}function ps(J,Z,Y,X){var F=Z[0],K=Z[1],$=Z[2];return J[0]=F+X*(Y[0]-F),J[1]=K+X*(Y[1]-K),J[2]=$+X*(Y[2]-$),J}function fs(J,Z,Y,X,F,K){var $=K*K,Q=$*(2*K-3)+1,W=$*(K-2)+K,G=$*(K-1),V=$*(3-2*K);return J[0]=Z[0]*Q+Y[0]*W+X[0]*G+F[0]*V,J[1]=Z[1]*Q+Y[1]*W+X[1]*G+F[1]*V,J[2]=Z[2]*Q+Y[2]*W+X[2]*G+F[2]*V,J}function Is(J,Z,Y,X,F,K){var $=1-K,Q=$*$,W=K*K,G=Q*$,V=3*K*Q,O=3*W*$,v=W*K;return J[0]=Z[0]*G+Y[0]*V+X[0]*O+F[0]*v,J[1]=Z[1]*G+Y[1]*V+X[1]*O+F[1]*v,J[2]=Z[2]*G+Y[2]*V+X[2]*O+F[2]*v,J}function hs(J,Z){Z=Z||1;var Y=B6()*2*Math.PI,X=B6()*2-1,F=Math.sqrt(1-X*X)*Z;return J[0]=Math.cos(Y)*F,J[1]=Math.sin(Y)*F,J[2]=X*Z,J}function cs(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Y[3]*X+Y[7]*F+Y[11]*K+Y[15];return $=$||1,J[0]=(Y[0]*X+Y[4]*F+Y[8]*K+Y[12])/$,J[1]=(Y[1]*X+Y[5]*F+Y[9]*K+Y[13])/$,J[2]=(Y[2]*X+Y[6]*F+Y[10]*K+Y[14])/$,J}function ls(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2];return J[0]=X*Y[0]+F*Y[3]+K*Y[6],J[1]=X*Y[1]+F*Y[4]+K*Y[7],J[2]=X*Y[2]+F*Y[5]+K*Y[8],J}function bs(J,Z,Y){var X=Y[0],F=Y[1],K=Y[2],$=Y[3],Q=Z[0],W=Z[1],G=Z[2],V=F*G-K*W,O=K*Q-X*G,v=X*W-F*Q,w=F*v-K*O,H=K*V-X*v,N=X*O-F*V,q=$*2;return V*=q,O*=q,v*=q,w*=2,H*=2,N*=2,J[0]=Q+V+w,J[1]=W+O+H,J[2]=G+v+N,J}function ms(J,Z,Y,X){var F=[],K=[];return F[0]=Z[0]-Y[0],F[1]=Z[1]-Y[1],F[2]=Z[2]-Y[2],K[0]=F[0],K[1]=F[1]*Math.cos(X)-F[2]*Math.sin(X),K[2]=F[1]*Math.sin(X)+F[2]*Math.cos(X),J[0]=K[0]+Y[0],J[1]=K[1]+Y[1],J[2]=K[2]+Y[2],J}function gs(J,Z,Y,X){var F=[],K=[];return F[0]=Z[0]-Y[0],F[1]=Z[1]-Y[1],F[2]=Z[2]-Y[2],K[0]=F[2]*Math.sin(X)+F[0]*Math.cos(X),K[1]=F[1],K[2]=F[2]*Math.cos(X)-F[0]*Math.sin(X),J[0]=K[0]+Y[0],J[1]=K[1]+Y[1],J[2]=K[2]+Y[2],J}function As(J,Z,Y,X){var F=[],K=[];return F[0]=Z[0]-Y[0],F[1]=Z[1]-Y[1],F[2]=Z[2]-Y[2],K[0]=F[0]*Math.cos(X)-F[1]*Math.sin(X),K[1]=F[0]*Math.sin(X)+F[1]*Math.cos(X),K[2]=F[2],J[0]=K[0]+Y[0],J[1]=K[1]+Y[1],J[2]=K[2]+Y[2],J}function is(J,Z){var Y=J[0],X=J[1],F=J[2],K=Z[0],$=Z[1],Q=Z[2],W=Math.sqrt(Y*Y+X*X+F*F),G=Math.sqrt(K*K+$*$+Q*Q),V=W*G,O=V&&hY(J,Z)/V;return Math.acos(Math.min(Math.max(O,-1),1))}function ys(J){return J[0]=0,J[1]=0,J[2]=0,J}function ns(J){return"vec3("+J[0]+", "+J[1]+", "+J[2]+")"}function us(J,Z){return J[0]===Z[0]&&J[1]===Z[1]&&J[2]===Z[2]}function ds(J,Z){var Y=J[0],X=J[1],F=J[2],K=Z[0],$=Z[1],Q=Z[2];return Math.abs(Y-K)<=i*Math.max(1,Math.abs(Y),Math.abs(K))&&Math.abs(X-$)<=i*Math.max(1,Math.abs(X),Math.abs($))&&Math.abs(F-Q)<=i*Math.max(1,Math.abs(F),Math.abs(Q))}var ss=Qj,as=Gj,os=Wj,rs=Vj,ts=Oj,XG=$j,es=vj,Ja=function(){var J=fY();return function(Z,Y,X,F,K,$){var Q,W;if(!Y)Y=3;if(!X)X=0;if(F)W=Math.min(F*Y+X,Z.length);else W=Z.length;for(Q=X;Q<W;Q+=Y)J[0]=Z[Q],J[1]=Z[Q+1],J[2]=Z[Q+2],K(J,J,$),Z[Q]=J[0],Z[Q+1]=J[1],Z[Q+2]=J[2];return Z}}();function Za(){var J=new $0(4);if($0!=Float32Array)J[0]=0,J[1]=0,J[2]=0,J[3]=0;return J}function Lj(J){var Z=new $0(4);return Z[0]=J[0],Z[1]=J[1],Z[2]=J[2],Z[3]=J[3],Z}function qj(J,Z,Y,X){var F=new $0(4);return F[0]=J,F[1]=Z,F[2]=Y,F[3]=X,F}function wj(J,Z){return J[0]=Z[0],J[1]=Z[1],J[2]=Z[2],J[3]=Z[3],J}function Hj(J,Z,Y,X,F){return J[0]=Z,J[1]=Y,J[2]=X,J[3]=F,J}function Nj(J,Z,Y){return J[0]=Z[0]+Y[0],J[1]=Z[1]+Y[1],J[2]=Z[2]+Y[2],J[3]=Z[3]+Y[3],J}function zj(J,Z,Y){return J[0]=Z[0]*Y,J[1]=Z[1]*Y,J[2]=Z[2]*Y,J[3]=Z[3]*Y,J}function Mj(J){var Z=J[0],Y=J[1],X=J[2],F=J[3];return Math.hypot(Z,Y,X,F)}function Uj(J){var Z=J[0],Y=J[1],X=J[2],F=J[3];return Z*Z+Y*Y+X*X+F*F}function Pj(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Y*Y+X*X+F*F+K*K;if($>0)$=1/Math.sqrt($);return J[0]=Y*$,J[1]=X*$,J[2]=F*$,J[3]=K*$,J}function Rj(J,Z){return J[0]*Z[0]+J[1]*Z[1]+J[2]*Z[2]+J[3]*Z[3]}function jj(J,Z,Y,X){var F=Z[0],K=Z[1],$=Z[2],Q=Z[3];return J[0]=F+X*(Y[0]-F),J[1]=K+X*(Y[1]-K),J[2]=$+X*(Y[2]-$),J[3]=Q+X*(Y[3]-Q),J}function xj(J,Z){return J[0]===Z[0]&&J[1]===Z[1]&&J[2]===Z[2]&&J[3]===Z[3]}function kj(J,Z){var Y=J[0],X=J[1],F=J[2],K=J[3],$=Z[0],Q=Z[1],W=Z[2],G=Z[3];return Math.abs(Y-$)<=i*Math.max(1,Math.abs(Y),Math.abs($))&&Math.abs(X-Q)<=i*Math.max(1,Math.abs(X),Math.abs(Q))&&Math.abs(F-W)<=i*Math.max(1,Math.abs(F),Math.abs(W))&&Math.abs(K-G)<=i*Math.max(1,Math.abs(K),Math.abs(G))}var PZ0=function(){var J=Za();return function(Z,Y,X,F,K,$){var Q,W;if(!Y)Y=4;if(!X)X=0;if(F)W=Math.min(F*Y+X,Z.length);else W=Z.length;for(Q=X;Q<W;Q+=Y)J[0]=Z[Q],J[1]=Z[Q+1],J[2]=Z[Q+2],J[3]=Z[Q+3],K(J,J,$),Z[Q]=J[0],Z[Q+1]=J[1],Z[Q+2]=J[2],Z[Q+3]=J[3];return Z}}();function FG(){var J=new $0(4);if($0!=Float32Array)J[0]=0,J[1]=0,J[2]=0;return J[3]=1,J}function Xa(J){return J[0]=0,J[1]=0,J[2]=0,J[3]=1,J}function Dj(J,Z,Y){Y=Y*0.5;var X=Math.sin(Y);return J[0]=X*Z[0],J[1]=X*Z[1],J[2]=X*Z[2],J[3]=Math.cos(Y),J}function Fa(J,Z){var Y=Math.acos(Z[3])*2,X=Math.sin(Y/2);if(X>i)J[0]=Z[0]/X,J[1]=Z[1]/X,J[2]=Z[2]/X;else J[0]=1,J[1]=0,J[2]=0;return Y}function Ka(J,Z){var Y=_j(J,Z);return Math.acos(2*Y*Y-1)}function Bj(J,Z,Y){var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Y[0],W=Y[1],G=Y[2],V=Y[3];return J[0]=X*V+$*Q+F*G-K*W,J[1]=F*V+$*W+K*Q-X*G,J[2]=K*V+$*G+X*W-F*Q,J[3]=$*V-X*Q-F*W-K*G,J}function $a(J,Z,Y){Y*=0.5;var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Math.sin(Y),W=Math.cos(Y);return J[0]=X*W+$*Q,J[1]=F*W+K*Q,J[2]=K*W-F*Q,J[3]=$*W-X*Q,J}function Qa(J,Z,Y){Y*=0.5;var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Math.sin(Y),W=Math.cos(Y);return J[0]=X*W-K*Q,J[1]=F*W+$*Q,J[2]=K*W+X*Q,J[3]=$*W-F*Q,J}function Ga(J,Z,Y){Y*=0.5;var X=Z[0],F=Z[1],K=Z[2],$=Z[3],Q=Math.sin(Y),W=Math.cos(Y);return J[0]=X*W+F*Q,J[1]=F*W-X*Q,J[2]=K*W+$*Q,J[3]=$*W-K*Q,J}function Wa(J,Z){var Y=Z[0],X=Z[1],F=Z[2];return J[0]=Y,J[1]=X,J[2]=F,J[3]=Math.sqrt(Math.abs(1-Y*Y-X*X-F*F)),J}function Tj(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Math.sqrt(Y*Y+X*X+F*F),Q=Math.exp(K),W=$>0?Q*Math.sin($)/$:0;return J[0]=Y*W,J[1]=X*W,J[2]=F*W,J[3]=Q*Math.cos($),J}function Sj(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Math.sqrt(Y*Y+X*X+F*F),Q=$>0?Math.atan2($,K)/$:0;return J[0]=Y*Q,J[1]=X*Q,J[2]=F*Q,J[3]=0.5*Math.log(Y*Y+X*X+F*F+K*K),J}function Va(J,Z,Y){return Sj(J,Z),Cj(J,J,Y),Tj(J,J),J}function cY(J,Z,Y,X){var F=Z[0],K=Z[1],$=Z[2],Q=Z[3],W=Y[0],G=Y[1],V=Y[2],O=Y[3],v,w,H,N,q;if(w=F*W+K*G+$*V+Q*O,w<0)w=-w,W=-W,G=-G,V=-V,O=-O;if(1-w>i)v=Math.acos(w),H=Math.sin(v),N=Math.sin((1-X)*v)/H,q=Math.sin(X*v)/H;else N=1-X,q=X;return J[0]=N*F+q*W,J[1]=N*K+q*G,J[2]=N*$+q*V,J[3]=N*Q+q*O,J}function Oa(J){var Z=B6(),Y=B6(),X=B6(),F=Math.sqrt(1-Z),K=Math.sqrt(Z);return J[0]=F*Math.sin(2*Math.PI*Y),J[1]=F*Math.cos(2*Math.PI*Y),J[2]=K*Math.sin(2*Math.PI*X),J[3]=K*Math.cos(2*Math.PI*X),J}function va(J,Z){var Y=Z[0],X=Z[1],F=Z[2],K=Z[3],$=Y*Y+X*X+F*F+K*K,Q=$?1/$:0;return J[0]=-Y*Q,J[1]=-X*Q,J[2]=-F*Q,J[3]=K*Q,J}function La(J,Z){return J[0]=-Z[0],J[1]=-Z[1],J[2]=-Z[2],J[3]=Z[3],J}function Ej(J,Z){var Y=Z[0]+Z[4]+Z[8],X;if(Y>0)X=Math.sqrt(Y+1),J[3]=0.5*X,X=0.5/X,J[0]=(Z[5]-Z[7])*X,J[1]=(Z[6]-Z[2])*X,J[2]=(Z[1]-Z[3])*X;else{var F=0;if(Z[4]>Z[0])F=1;if(Z[8]>Z[F*3+F])F=2;var K=(F+1)%3,$=(F+2)%3;X=Math.sqrt(Z[F*3+F]-Z[K*3+K]-Z[$*3+$]+1),J[F]=0.5*X,X=0.5/X,J[3]=(Z[K*3+$]-Z[$*3+K])*X,J[K]=(Z[K*3+F]+Z[F*3+K])*X,J[$]=(Z[$*3+F]+Z[F*3+$])*X}return J}function qa(J,Z,Y,X){var F=0.5*Math.PI/180;Z*=F,Y*=F,X*=F;var K=Math.sin(Z),$=Math.cos(Z),Q=Math.sin(Y),W=Math.cos(Y),G=Math.sin(X),V=Math.cos(X);return J[0]=K*W*V-$*Q*G,J[1]=$*Q*V+K*W*G,J[2]=$*W*G-K*Q*V,J[3]=$*W*V+K*Q*G,J}function wa(J){return"quat("+J[0]+", "+J[1]+", "+J[2]+", "+J[3]+")"}var Ha=Lj,Na=qj,za=wj,Ma=Hj,Ua=Nj,Pa=Bj,Cj=zj,_j=Rj,Ra=jj,pj=Mj,ja=pj,fj=Uj,xa=fj,KG=Pj,ka=xj,Da=kj,Ba=function(){var J=fY(),Z=IY(1,0,0),Y=IY(0,1,0);return function(X,F,K){var $=hY(F,K);if($<-0.999999){if(w7(J,Z,F),XG(J)<0.000001)w7(J,Y,F);return YG(J,J),Dj(X,J,Math.PI),X}else if($>0.999999)return X[0]=0,X[1]=0,X[2]=0,X[3]=1,X;else return w7(J,F,K),X[0]=J[0],X[1]=J[1],X[2]=J[2],X[3]=1+$,KG(X,X)}}(),Ta=function(){var J=FG(),Z=FG();return function(Y,X,F,K,$,Q){return cY(J,X,$,Q),cY(Z,F,K,Q),cY(Y,J,Z,2*Q*(1-Q)),Y}}(),Sa=function(){var J=ZG();return function(Z,Y,X,F){return J[0]=X[0],J[3]=X[1],J[6]=X[2],J[1]=F[0],J[4]=F[1],J[7]=F[2],J[2]=-Y[0],J[5]=-Y[1],J[8]=-Y[2],KG(Z,Ej(Z,J))}}();var V0={};E6(V0,{zero:()=>Zo,transformMat4:()=>ta,transformMat3:()=>ra,transformMat2d:()=>oa,transformMat2:()=>aa,subtract:()=>hj,sub:()=>$o,str:()=>Yo,squaredLength:()=>Aj,squaredDistance:()=>mj,sqrLen:()=>Oo,sqrDist:()=>Vo,set:()=>pa,scaleAndAdd:()=>ga,scale:()=>ma,round:()=>ba,rotate:()=>ea,random:()=>sa,normalize:()=>ya,negate:()=>Aa,multiply:()=>cj,mul:()=>Qo,min:()=>ca,max:()=>la,lerp:()=>da,length:()=>gj,len:()=>Ko,inverse:()=>ia,fromValues:()=>Ca,forEach:()=>vo,floor:()=>ha,exactEquals:()=>Xo,equals:()=>Fo,dot:()=>na,divide:()=>lj,div:()=>Go,distance:()=>bj,dist:()=>Wo,cross:()=>ua,create:()=>Ij,copy:()=>_a,clone:()=>Ea,ceil:()=>Ia,angle:()=>Jo,add:()=>fa});function Ij(){var J=new $0(2);if($0!=Float32Array)J[0]=0,J[1]=0;return J}function Ea(J){var Z=new $0(2);return Z[0]=J[0],Z[1]=J[1],Z}function Ca(J,Z){var Y=new $0(2);return Y[0]=J,Y[1]=Z,Y}function _a(J,Z){return J[0]=Z[0],J[1]=Z[1],J}function pa(J,Z,Y){return J[0]=Z,J[1]=Y,J}function fa(J,Z,Y){return J[0]=Z[0]+Y[0],J[1]=Z[1]+Y[1],J}function hj(J,Z,Y){return J[0]=Z[0]-Y[0],J[1]=Z[1]-Y[1],J}function cj(J,Z,Y){return J[0]=Z[0]*Y[0],J[1]=Z[1]*Y[1],J}function lj(J,Z,Y){return J[0]=Z[0]/Y[0],J[1]=Z[1]/Y[1],J}function Ia(J,Z){return J[0]=Math.ceil(Z[0]),J[1]=Math.ceil(Z[1]),J}function ha(J,Z){return J[0]=Math.floor(Z[0]),J[1]=Math.floor(Z[1]),J}function ca(J,Z,Y){return J[0]=Math.min(Z[0],Y[0]),J[1]=Math.min(Z[1],Y[1]),J}function la(J,Z,Y){return J[0]=Math.max(Z[0],Y[0]),J[1]=Math.max(Z[1],Y[1]),J}function ba(J,Z){return J[0]=Math.round(Z[0]),J[1]=Math.round(Z[1]),J}function ma(J,Z,Y){return J[0]=Z[0]*Y,J[1]=Z[1]*Y,J}function ga(J,Z,Y,X){return J[0]=Z[0]+Y[0]*X,J[1]=Z[1]+Y[1]*X,J}function bj(J,Z){var Y=Z[0]-J[0],X=Z[1]-J[1];return Math.hypot(Y,X)}function mj(J,Z){var Y=Z[0]-J[0],X=Z[1]-J[1];return Y*Y+X*X}function gj(J){var Z=J[0],Y=J[1];return Math.hypot(Z,Y)}function Aj(J){var Z=J[0],Y=J[1];return Z*Z+Y*Y}function Aa(J,Z){return J[0]=-Z[0],J[1]=-Z[1],J}function ia(J,Z){return J[0]=1/Z[0],J[1]=1/Z[1],J}function ya(J,Z){var Y=Z[0],X=Z[1],F=Y*Y+X*X;if(F>0)F=1/Math.sqrt(F);return J[0]=Z[0]*F,J[1]=Z[1]*F,J}function na(J,Z){return J[0]*Z[0]+J[1]*Z[1]}function ua(J,Z,Y){var X=Z[0]*Y[1]-Z[1]*Y[0];return J[0]=J[1]=0,J[2]=X,J}function da(J,Z,Y,X){var F=Z[0],K=Z[1];return J[0]=F+X*(Y[0]-F),J[1]=K+X*(Y[1]-K),J}function sa(J,Z){Z=Z||1;var Y=B6()*2*Math.PI;return J[0]=Math.cos(Y)*Z,J[1]=Math.sin(Y)*Z,J}function aa(J,Z,Y){var X=Z[0],F=Z[1];return J[0]=Y[0]*X+Y[2]*F,J[1]=Y[1]*X+Y[3]*F,J}function oa(J,Z,Y){var X=Z[0],F=Z[1];return J[0]=Y[0]*X+Y[2]*F+Y[4],J[1]=Y[1]*X+Y[3]*F+Y[5],J}function ra(J,Z,Y){var X=Z[0],F=Z[1];return J[0]=Y[0]*X+Y[3]*F+Y[6],J[1]=Y[1]*X+Y[4]*F+Y[7],J}function ta(J,Z,Y){var X=Z[0],F=Z[1];return J[0]=Y[0]*X+Y[4]*F+Y[12],J[1]=Y[1]*X+Y[5]*F+Y[13],J}function ea(J,Z,Y,X){var F=Z[0]-Y[0],K=Z[1]-Y[1],$=Math.sin(X),Q=Math.cos(X);return J[0]=F*Q-K*$+Y[0],J[1]=F*$+K*Q+Y[1],J}function Jo(J,Z){var Y=J[0],X=J[1],F=Z[0],K=Z[1],$=Math.sqrt(Y*Y+X*X)*Math.sqrt(F*F+K*K),Q=$&&(Y*F+X*K)/$;return Math.acos(Math.min(Math.max(Q,-1),1))}function Zo(J){return J[0]=0,J[1]=0,J}function Yo(J){return"vec2("+J[0]+", "+J[1]+")"}function Xo(J,Z){return J[0]===Z[0]&&J[1]===Z[1]}function Fo(J,Z){var Y=J[0],X=J[1],F=Z[0],K=Z[1];return Math.abs(Y-F)<=i*Math.max(1,Math.abs(Y),Math.abs(F))&&Math.abs(X-K)<=i*Math.max(1,Math.abs(X),Math.abs(K))}var Ko=gj,$o=hj,Qo=cj,Go=lj,Wo=bj,Vo=mj,Oo=Aj,vo=function(){var J=Ij();return function(Z,Y,X,F,K,$){var Q,W;if(!Y)Y=2;if(!X)X=0;if(F)W=Math.min(F*Y+X,Z.length);else W=Z.length;for(Q=X;Q<W;Q+=Y)J[0]=Z[Q],J[1]=Z[Q+1],K(J,J,$),Z[Q]=J[0],Z[Q+1]=J[1];return Z}}();class e9 extends Float32Array{constructor(J,Z,Y,X){super([J,Z,Y,X])}get determinant(){return t0.determinant(this)}get frobeniusNorm(){return t0.frob(this)}static create(){let J=new e9(0,0,0,0);return t0.identity(J),J}static fromRotation(J){let Z=e9.create();return t0.fromRotation(Z,J),Z}static fromScaling(J){let Z=e9.create();return t0.fromScaling(Z,J),Z}add(J){return t0.add(this,this,J),this}adjoint(){return t0.adjoint(this,this),this}clone(){return new e9(this[0],this[1],this[2],this[3])}copy(J){return t0.copy(this,J),this}equals(J){return t0.equals(this,J)}exactEquals(J){return t0.exactEquals(this,J)}identity(){return t0.identity(this),this}invert(){return t0.invert(this,this),this}multiply(J){return t0.mul(this,this,J),this}multiplyScalar(J){return t0.multiplyScalar(this,this,J),this}rotate(J){return t0.rotate(this,this,J),this}subtract(J){return t0.sub(this,this,J),this}toString(){return`[${this[0]},${this[1]}][${this[2]},${this[3]}]`}transpose(){return t0.transpose(this,this),this}}class T6 extends Float32Array{constructor(J,Z,Y,X,F,K,$,Q,W){super([J,Z,Y,X,F,K,$,Q,W])}get determinant(){return f0.determinant(this)}get frobeniusNorm(){return f0.frob(this)}static create(){let J=new T6(0,0,0,0,0,0,0,0,0);return f0.identity(J),J}static fromMatrix4(J){let Z=T6.create();return f0.fromMat4(Z,J),Z}static fromQuaternion(J){let Z=T6.create();return f0.fromQuat(Z,J),Z}static fromRotation(J){let Z=T6.create();return f0.fromRotation(Z,J),Z}static fromScaling(J){let Z=T6.create();return f0.fromScaling(Z,J),Z}static fromTranslation(J){let Z=T6.create();return f0.fromTranslation(Z,J),Z}add(J){return f0.add(this,this,J),this}adjoint(){return f0.adjoint(this,this),this}clone(){return new T6(this[0],this[1],this[2],this[3],this[4],this[5],this[6],this[7],this[8])}copy(J){return f0.copy(this,J),this}equals(J){return f0.equals(this,J)}exactEquals(J){return f0.exactEquals(this,J)}identity(){return f0.identity(this),this}invert(){return f0.invert(this,this),this}multiply(J){return f0.mul(this,this,J),this}multiplyScalar(J){return f0.multiplyScalar(this,this,J),this}transformVector(J){return J.transformMatrix3(this)}projection(J,Z){return f0.projection(this,J,Z),this}rotate(J){return f0.rotate(this,this,J),this}subtract(J){return f0.sub(this,this,J),this}toString(){return`[${this[0]},${this[1]},${this[2]}][${this[3]},${this[4]},${this[5]}][${this[6]},${this[7]},${this[8]}]`}transpose(){return f0.transpose(this,this),this}}class k8 extends Float32Array{constructor(J,Z,Y,X,F,K,$,Q,W,G,V,O,v,w,H,N){super([J,Z,Y,X,F,K,$,Q,W,G,V,O,v,w,H,N])}get determinant(){return J0.determinant(this)}get frobeniusNorm(){return J0.frob(this)}static create(){let J=new k8(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);return J0.identity(J),J}static fromQuaternion(J){let Z=k8.create();return J0.fromQuat(Z,J),Z}static fromRotation(J,Z){let Y=k8.create();return J0.fromRotation(Y,J,Z),Y}static fromRotationTranslation(J,Z){let Y=k8.create();return J0.fromRotationTranslation(Y,J,Z),Y}static fromRotationTranslationScale(J,Z,Y){let X=k8.create();return J0.fromRotationTranslationScale(X,J,Z,Y),X}static fromRotationTranslationScaleOrigin(J,Z,Y,X){let F=k8.create();return J0.fromRotationTranslationScaleOrigin(F,J,Z,Y,X),F}static fromScaling(J){let Z=k8.create();return J0.fromScaling(Z,J),Z}static fromTranslation(J){let Z=k8.create();return J0.fromTranslation(Z,J),Z}static fromXRotation(J){let Z=k8.create();return J0.fromXRotation(Z,J),Z}static fromYRotation(J){let Z=k8.create();return J0.fromYRotation(Z,J),Z}static fromZRotation(J){let Z=k8.create();return J0.fromZRotation(Z,J),Z}add(J){return J0.add(this,this,J),this}adjoint(){return J0.adjoint(this,this),this}clone(){return new k8(this[0],this[1],this[2],this[3],this[4],this[5],this[6],this[7],this[8],this[9],this[10],this[11],this[12],this[13],this[14],this[15])}copy(J){return J0.copy(this,J),this}equals(J){return J0.equals(this,J)}exactEquals(J){return J0.exactEquals(this,J)}frustrum(J,Z,Y,X,F,K){return J0.frustum(this,J,Z,Y,X,F,K),this}identity(){return J0.identity(this),this}invert(){return J0.invert(this,this),this}lookAt(J,Z,Y){return J0.lookAt(this,J,Z,Y),this}multiply(J){return J0.mul(this,this,J),this}multiplyScalar(J){return J0.multiplyScalar(this,this,J),this}orthographic(J,Z,Y,X,F,K){return J0.ortho(this,J,Z,Y,X,F,K),this}perspective(J,Z,Y,X){return J0.perspective(this,J,Z,Y,X),this}rotate(J,Z){return J0.rotate(this,this,J,Z),this}rotateX(J){return J0.rotateX(this,this,J),this}rotateY(J){return J0.rotateY(this,this,J),this}rotateZ(J){return J0.rotateZ(this,this,J),this}scale(J){return J0.scale(this,this,J),this}subtract(J){return J0.sub(this,this,J),this}targetTo(J,Z,Y){return J0.targetTo(this,J,Z,Y),this}toString(){return`[${this[0]},${this[1]},${this[2]},${this[3]}][${this[4]},${this[5]},${this[6]},${this[7]}][${this[8]},${this[9]},${this[10]},${this[11]}][${this[12]},${this[13]},${this[14]},${this[15]}]`}translate(J){return J0.translate(this,this,J),this}transpose(){return J0.transpose(this,this),this}}class r1 extends Float32Array{constructor(J,Z,Y,X){super([J,Z,Y,X])}get length(){return R0.length(this)}get squaredLength(){return R0.squaredLength(this)}get magnitude(){return R0.length(this)}get squaredMagnitude(){return R0.squaredLength(this)}get x(){return this[0]}set x(J){this[0]=J}get y(){return this[1]}set y(J){this[1]=J}get z(){return this[2]}set z(J){this[2]=J}get w(){return this[3]}set w(J){this[3]=J}static fromEuler(J,Z,Y){let X=R0.fromEuler(new Float32Array(4),J,Z,Y);return new r1(X[0],X[1],X[2],X[3])}static fromQuaternionLike(J){return new r1(J.x,J.y,J.z,J.w)}clone(){return new r1(this.x,this.y,this.z,this.w)}conjugate(){return R0.conjugate(this,this),this}copy(J){return R0.copy(this,J),this}dot(J){return R0.dot(this,J)}exponential(){return R0.exp(this,this),this}equals(J){return R0.equals(this,J)}exactEquals(J){return R0.exactEquals(this,J)}getAngle(J){return R0.getAngle(this,J)}identity(){return R0.identity(this),this}invert(){return R0.invert(this,this),this}lerp(J,Z){return R0.lerp(this,this,J,Z),this}logarithm(){return R0.ln(this,this),this}multiply(J){return R0.multiply(this,this,J),this}transformVector(J){return J.transformQuaternion(this)}normalize(){return R0.normalize(this,this),this}power(J){return R0.pow(this,this,J),this}randomize(){return R0.random(this),this}rotateX(J){return R0.rotateX(this,this,J),this}rotateY(J){return R0.rotateY(this,this,J),this}rotateZ(J){return R0.rotateZ(this,this,J),this}scale(J){return R0.scale(this,this,J),this}setAxisAngle(J,Z){return R0.setAxisAngle(this,J,Z),this}slerp(J,Z){return R0.slerp(this,this,J,Z),this}toString(){return`${this.x},${this.y},${this.z},${this.w}`}}class H7 extends Float32Array{constructor(J,Z){super([J,Z])}get length(){return V0.length(this)}get squaredLength(){return V0.squaredLength(this)}get magnitude(){return V0.length(this)}get squaredMagnitude(){return V0.squaredLength(this)}get x(){return this[0]}set x(J){this[0]=J}get y(){return this[1]}set y(J){this[1]=J}static create(){return new H7(0,0)}add(J){return V0.add(this,this,J),this}angle(J){return V0.angle(this,J)}ceil(){return V0.ceil(this,this),this}clone(){return new H7(this.x,this.y)}copy(J){return V0.copy(this,J),this}distance(J){return V0.distance(this,J)}divide(J){return V0.divide(this,this,J),this}dot(J){return V0.dot(this,J)}equals(J){return V0.equals(this,J)}exactEquals(J){return V0.exactEquals(this,J)}floor(){return V0.floor(this,this),this}invert(){return V0.inverse(this,this),this}lerp(J,Z){return V0.lerp(this,this,J,Z),this}max(J){return V0.max(this,this,J),this}min(J){return V0.min(this,this,J),this}multiply(J){return V0.mul(this,this,J),this}negate(){return V0.negate(this,this),this}normalize(){return V0.normalize(this,this),this}randomize(J){return V0.random(this,J),this}rotate(J,Z){return V0.rotate(this,this,J,Z),this}round(){return V0.round(this,this),this}scale(J){return V0.scale(this,this,J),this}scaleAndAdd(J,Z){return V0.scaleAndAdd(this,this,J,Z),this}subtract(J){return V0.sub(this,this,J),this}toString(){return`${this.x},${this.y}`}transformMatrix2(J){return V0.transformMat2(this,this,J),this}transformMatrix3(J){return V0.transformMat3(this,this,J),this}transformMatrix4(J){return V0.transformMat4(this,this,J),this}zero(){return V0.zero(this),this}}class t1 extends Float32Array{constructor(J,Z,Y){super([J,Z,Y])}get length(){return Y0.length(this)}get squaredLength(){return Y0.squaredLength(this)}get magnitude(){return Y0.length(this)}get squaredMagnitude(){return Y0.squaredLength(this)}get x(){return this[0]}set x(J){this[0]=J}get y(){return this[1]}set y(J){this[1]=J}get z(){return this[2]}set z(J){this[2]=J}static create(){return new t1(0,0,0)}static fromVector3Like(J){return new t1(J.x,J.y,J.z)}add(J){return Y0.add(this,this,J),this}ceil(){return Y0.ceil(this,this),this}clone(){return new t1(this.x,this.y,this.z)}copy(J){return Y0.copy(this,J),this}cross(J){return Y0.cross(this,this,J),this}distance(J){return Y0.distance(this,J)}divide(J){return Y0.div(this,this,J),this}dot(J){return Y0.dot(this,J)}equals(J){return Y0.equals(this,J)}exactEquals(J){return Y0.exactEquals(this,J)}floor(){return Y0.floor(this,this),this}invert(){return Y0.inverse(this,this),this}lerp(J,Z){return Y0.lerp(this,this,J,Z),this}max(J){return Y0.max(this,this,J),this}min(J){return Y0.min(this,this,J),this}multiply(J){return Y0.mul(this,this,J),this}negate(){return Y0.negate(this,this),this}normalize(){return Y0.normalize(this,this),this}randomize(J){return Y0.random(this,J),this}rotateX(J,Z){return Y0.rotateX(this,this,J,Z),this}rotateY(J,Z){return Y0.rotateY(this,this,J,Z),this}rotateZ(J,Z){return Y0.rotateZ(this,this,J,Z),this}round(){return Y0.round(this,this),this}scale(J){return Y0.scale(this,this,J),this}scaleAndAdd(J,Z){return Y0.scaleAndAdd(this,this,J,Z),this}subtract(J){return Y0.sub(this,this,J),this}toString(){return`${this.x},${this.y},${this.z}`}transformMatrix3(J){return Y0.transformMat3(this,this,J),this}transformMatrix4(J){return Y0.transformMat4(this,this,J),this}transformQuaternion(J){return Y0.transformQuat(this,this,J),this}zero(){return Y0.zero(this),this}}var j0=function(J,Z,Y,X){function F(K){return K instanceof Y?K:new Y(function($){$(K)})}return new(Y||(Y=Promise))(function(K,$){function Q(V){try{G(X.next(V))}catch(O){$(O)}}function W(V){try{G(X.throw(V))}catch(O){$(O)}}function G(V){V.done?K(V.value):F(V.value).then(Q,W)}G((X=X.apply(J,Z||[])).next())})},P0=function(J,Z){var Y={label:0,sent:function(){if(K[0]&1)throw K[1];return K[1]},trys:[],ops:[]},X,F,K,$=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return $.next=Q(0),$.throw=Q(1),$.return=Q(2),typeof Symbol==="function"&&($[Symbol.iterator]=function(){return this}),$;function Q(G){return function(V){return W([G,V])}}function W(G){if(X)throw new TypeError("Generator is already executing.");while($&&($=0,G[0]&&(Y=0)),Y)try{if(X=1,F&&(K=G[0]&2?F.return:G[0]?F.throw||((K=F.return)&&K.call(F),0):F.next)&&!(K=K.call(F,G[1])).done)return K;if(F=0,K)G=[G[0]&2,K.value];switch(G[0]){case 0:case 1:K=G;break;case 4:return Y.label++,{value:G[1],done:!1};case 5:Y.label++,F=G[1],G=[0];continue;case 7:G=Y.ops.pop(),Y.trys.pop();continue;default:if((K=Y.trys,!(K=K.length>0&&K[K.length-1]))&&(G[0]===6||G[0]===2)){Y=0;continue}if(G[0]===3&&(!K||G[1]>K[0]&&G[1]<K[3])){Y.label=G[1];break}if(G[0]===6&&Y.label<K[1]){Y.label=K[1],K=G;break}if(K&&Y.label<K[2]){Y.label=K[2],Y.ops.push(G);break}if(K[2])Y.ops.pop();Y.trys.pop();continue}G=Z.call(J,Y)}catch(V){G=[6,V],F=0}finally{X=K=0}if(G[0]&5)throw G[1];return{value:G[0]?G[1]:void 0,done:!0}}},h8=function(J,Z){var Y=typeof Symbol==="function"&&J[Symbol.iterator];if(!Y)return J;var X=Y.call(J),F,K=[],$;try{while((Z===void 0||Z-- >0)&&!(F=X.next()).done)K.push(F.value)}catch(Q){$={error:Q}}finally{try{if(F&&!F.done&&(Y=X.return))Y.call(X)}finally{if($)throw $.error}}return K},r8=function(J,Z,Y){if(Y||arguments.length===2){for(var X=0,F=Z.length,K;X<F;X++)if(K||!(X in Z)){if(!K)K=Array.prototype.slice.call(Z,0,X);K[X]=Z[X]}}return J.concat(K||Array.prototype.slice.call(Z))},ij=function(J){var Z=typeof Symbol==="function"&&Symbol.iterator,Y=Z&&J[Z],X=0;if(Y)return Y.call(J);if(J&&typeof J.length==="number")return{next:function(){if(J&&X>=J.length)J=void 0;return{value:J&&J[X++],done:!J}}};throw new TypeError(Z?"Object is not iterable.":"Symbol.iterator is not defined.")},TZ0=function(){function J(Z){if(Z===void 0)Z=J.minComparator;var Y=this;this.compare=Z,this.heapArray=[],this._limit=0,this.offer=this.add,this.element=this.peek,this.poll=this.pop,this._invertedCompare=function(X,F){return Y.compare(X,F).then(function(K){return-1*K})}}return J.getChildrenIndexOf=function(Z){return[Z*2+1,Z*2+2]},J.getParentIndexOf=function(Z){if(Z<=0)return-1;var Y=Z%2?1:2;return Math.floor((Z-Y)/2)},J.getSiblingIndexOf=function(Z){if(Z<=0)return-1;var Y=Z%2?1:-1;return Z+Y},J.minComparator=function(Z,Y){return j0(this,void 0,void 0,function(){return P0(this,function(X){if(Z>Y)return[2,1];else if(Z<Y)return[2,-1];else return[2,0]})})},J.maxComparator=function(Z,Y){return j0(this,void 0,void 0,function(){return P0(this,function(X){if(Y>Z)return[2,1];else if(Y<Z)return[2,-1];else return[2,0]})})},J.minComparatorNumber=function(Z,Y){return j0(this,void 0,void 0,function(){return P0(this,function(X){return[2,Z-Y]})})},J.maxComparatorNumber=function(Z,Y){return j0(this,void 0,void 0,function(){return P0(this,function(X){return[2,Y-Z]})})},J.defaultIsEqual=function(Z,Y){return j0(this,void 0,void 0,function(){return P0(this,function(X){return[2,Z===Y]})})},J.print=function(Z){function Y(V){var O=J.getParentIndexOf(V);return Math.floor(Math.log2(O+1))}function X(V,O){var v="";for(;O>0;--O)v+=V;return v}var F=0,K=[],$=Y(Z.length-1)+2,Q=0;while(F<Z.length){var W=Y(F)+1;if(F===0)W=0;var G=String(Z.get(F));if(G.length>Q)Q=G.length;K[W]=K[W]||[],K[W].push(G),F+=1}return K.map(function(V,O){var v=Math.pow(2,$-O)-1;return X(" ",Math.floor(v/2)*Q)+V.map(function(w){var H=(Q-w.length)/2;return X(" ",Math.ceil(H))+w+X(" ",Math.floor(H))}).join(X(" ",v*Q))}).join(`
339
339
  `)},J.heapify=function(Z,Y){return j0(this,void 0,void 0,function(){var X;return P0(this,function(F){switch(F.label){case 0:return X=new J(Y),X.heapArray=Z,[4,X.init()];case 1:return F.sent(),[2,X]}})})},J.heappop=function(Z,Y){var X=new J(Y);return X.heapArray=Z,X.pop()},J.heappush=function(Z,Y,X){return j0(this,void 0,void 0,function(){var F;return P0(this,function(K){switch(K.label){case 0:return F=new J(X),F.heapArray=Z,[4,F.push(Y)];case 1:return K.sent(),[2]}})})},J.heappushpop=function(Z,Y,X){var F=new J(X);return F.heapArray=Z,F.pushpop(Y)},J.heapreplace=function(Z,Y,X){var F=new J(X);return F.heapArray=Z,F.replace(Y)},J.heaptop=function(Z,Y,X){if(Y===void 0)Y=1;var F=new J(X);return F.heapArray=Z,F.top(Y)},J.heapbottom=function(Z,Y,X){if(Y===void 0)Y=1;var F=new J(X);return F.heapArray=Z,F.bottom(Y)},J.nlargest=function(Z,Y,X){return j0(this,void 0,void 0,function(){var F;return P0(this,function(K){switch(K.label){case 0:return F=new J(X),F.heapArray=r8([],h8(Y),!1),[4,F.init()];case 1:return K.sent(),[2,F.top(Z)]}})})},J.nsmallest=function(Z,Y,X){return j0(this,void 0,void 0,function(){var F;return P0(this,function(K){switch(K.label){case 0:return F=new J(X),F.heapArray=r8([],h8(Y),!1),[4,F.init()];case 1:return K.sent(),[2,F.bottom(Z)]}})})},J.prototype.add=function(Z){return j0(this,void 0,void 0,function(){return P0(this,function(Y){switch(Y.label){case 0:return[4,this._sortNodeUp(this.heapArray.push(Z)-1)];case 1:return Y.sent(),this._applyLimit(),[2,!0]}})})},J.prototype.addAll=function(Z){return j0(this,void 0,void 0,function(){var Y,X,F;return P0(this,function(K){switch(K.label){case 0:Y=this.length,(F=this.heapArray).push.apply(F,r8([],h8(Z),!1)),X=this.length,K.label=1;case 1:if(!(Y<X))return[3,4];return[4,this._sortNodeUp(Y)];case 2:K.sent(),K.label=3;case 3:return++Y,[3,1];case 4:return this._applyLimit(),[2,!0]}})})},J.prototype.bottom=function(){return j0(this,arguments,void 0,function(Z){if(Z===void 0)Z=1;return P0(this,function(Y){if(this.heapArray.length===0||Z<=0)return[2,[]];else if(this.heapArray.length===1)return[2,[this.heapArray[0]]];else if(Z>=this.heapArray.length)return[2,r8([],h8(this.heapArray),!1)];else return[2,this._bottomN_push(~~Z)]})})},J.prototype.check=function(){return j0(this,void 0,void 0,function(){var Z,Y,X,F,K,$,Q,W,G;return P0(this,function(V){switch(V.label){case 0:Z=0,V.label=1;case 1:if(!(Z<this.heapArray.length))return[3,10];Y=this.heapArray[Z],X=this.getChildrenOf(Z),V.label=2;case 2:V.trys.push([2,7,8,9]),F=(W=void 0,ij(X)),K=F.next(),V.label=3;case 3:if(K.done)return[3,6];return $=K.value,[4,this.compare(Y,$)];case 4:if(V.sent()>0)return[2,Y];V.label=5;case 5:return K=F.next(),[3,3];case 6:return[3,9];case 7:return Q=V.sent(),W={error:Q},[3,9];case 8:try{if(K&&!K.done&&(G=F.return))G.call(F)}finally{if(W)throw W.error}return[7];case 9:return++Z,[3,1];case 10:return[2]}})})},J.prototype.clear=function(){this.heapArray=[]},J.prototype.clone=function(){var Z=new J(this.comparator());return Z.heapArray=this.toArray(),Z._limit=this._limit,Z},J.prototype.comparator=function(){return this.compare},J.prototype.contains=function(Z){return j0(this,arguments,void 0,function(Y,X){var F,K,$,Q,W,G;if(X===void 0)X=J.defaultIsEqual;return P0(this,function(V){switch(V.label){case 0:V.trys.push([0,5,6,7]),F=ij(this.heapArray),K=F.next(),V.label=1;case 1:if(K.done)return[3,4];return $=K.value,[4,X($,Y)];case 2:if(V.sent())return[2,!0];V.label=3;case 3:return K=F.next(),[3,1];case 4:return[3,7];case 5:return Q=V.sent(),W={error:Q},[3,7];case 6:try{if(K&&!K.done&&(G=F.return))G.call(F)}finally{if(W)throw W.error}return[7];case 7:return[2,!1]}})})},J.prototype.init=function(Z){return j0(this,void 0,void 0,function(){var Y;return P0(this,function(X){switch(X.label){case 0:if(Z)this.heapArray=r8([],h8(Z),!1);Y=Math.floor(this.heapArray.length),X.label=1;case 1:if(!(Y>=0))return[3,4];return[4,this._sortNodeDown(Y)];case 2:X.sent(),X.label=3;case 3:return--Y,[3,1];case 4:return this._applyLimit(),[2]}})})},J.prototype.isEmpty=function(){return this.length===0},J.prototype.leafs=function(){if(this.heapArray.length===0)return[];var Z=J.getParentIndexOf(this.heapArray.length-1);return this.heapArray.slice(Z+1)},Object.defineProperty(J.prototype,"length",{get:function(){return this.heapArray.length},enumerable:!1,configurable:!0}),Object.defineProperty(J.prototype,"limit",{get:function(){return this._limit},set:function(Z){this._limit=~~Z,this._applyLimit()},enumerable:!1,configurable:!0}),J.prototype.peek=function(){return this.heapArray[0]},J.prototype.pop=function(){return j0(this,void 0,void 0,function(){var Z;return P0(this,function(Y){if(Z=this.heapArray.pop(),this.length>0&&Z!==void 0)return[2,this.replace(Z)];return[2,Z]})})},J.prototype.push=function(){var Z=[];for(var Y=0;Y<arguments.length;Y++)Z[Y]=arguments[Y];return j0(this,void 0,void 0,function(){return P0(this,function(X){if(Z.length<1)return[2,!1];else if(Z.length===1)return[2,this.add(Z[0])];else return[2,this.addAll(Z)]})})},J.prototype.pushpop=function(Z){return j0(this,void 0,void 0,function(){var Y;return P0(this,function(X){switch(X.label){case 0:return[4,this.compare(this.heapArray[0],Z)];case 1:if(!(X.sent()<0))return[3,3];return Y=h8([this.heapArray[0],Z],2),Z=Y[0],this.heapArray[0]=Y[1],[4,this._sortNodeDown(0)];case 2:X.sent(),X.label=3;case 3:return[2,Z]}})})},J.prototype.remove=function(Z){return j0(this,arguments,void 0,function(Y,X){var F,K,$,Q=this;if(X===void 0)X=J.defaultIsEqual;return P0(this,function(W){switch(W.label){case 0:if(!this.heapArray.length)return[2,!1];if(Y!==void 0)return[3,2];return[4,this.pop()];case 1:return W.sent(),[2,!0];case 2:F=[0],W.label=3;case 3:if(!F.length)return[3,13];return K=F.shift(),[4,X(this.heapArray[K],Y)];case 4:if(!W.sent())return[3,11];if(K!==0)return[3,6];return[4,this.pop()];case 5:return W.sent(),[3,10];case 6:if(K!==this.heapArray.length-1)return[3,7];return this.heapArray.pop(),[3,10];case 7:return this.heapArray.splice(K,1,this.heapArray.pop()),[4,this._sortNodeUp(K)];case 8:return W.sent(),[4,this._sortNodeDown(K)];case 9:W.sent(),W.label=10;case 10:return[2,!0];case 11:$=J.getChildrenIndexOf(K).filter(function(G){return G<Q.heapArray.length}),F.push.apply(F,r8([],h8($),!1)),W.label=12;case 12:return[3,3];case 13:return[2,!1]}})})},J.prototype.replace=function(Z){return j0(this,void 0,void 0,function(){var Y;return P0(this,function(X){switch(X.label){case 0:return Y=this.heapArray[0],this.heapArray[0]=Z,[4,this._sortNodeDown(0)];case 1:return X.sent(),[2,Y]}})})},J.prototype.size=function(){return this.length},J.prototype.top=function(){return j0(this,arguments,void 0,function(Z){if(Z===void 0)Z=1;return P0(this,function(Y){if(this.heapArray.length===0||Z<=0)return[2,[]];else if(this.heapArray.length===1||Z===1)return[2,[this.heapArray[0]]];else if(Z>=this.heapArray.length)return[2,r8([],h8(this.heapArray),!1)];else return[2,this._topN_push(~~Z)]})})},J.prototype.toArray=function(){return r8([],h8(this.heapArray),!1)},J.prototype.toString=function(){return this.heapArray.toString()},J.prototype.get=function(Z){return this.heapArray[Z]},J.prototype.getChildrenOf=function(Z){var Y=this;return J.getChildrenIndexOf(Z).map(function(X){return Y.heapArray[X]}).filter(function(X){return X!==void 0})},J.prototype.getParentOf=function(Z){var Y=J.getParentIndexOf(Z);return this.heapArray[Y]},J.prototype[Symbol.iterator]=function(){return P0(this,function(Z){switch(Z.label){case 0:if(!this.length)return[3,2];return[4,this.pop()];case 1:return Z.sent(),[3,0];case 2:return[2]}})},J.prototype.iterator=function(){return this},J.prototype._applyLimit=function(){if(this._limit&&this._limit<this.heapArray.length){var Z=this.heapArray.length-this._limit;while(Z)this.heapArray.pop(),--Z}},J.prototype._bottomN_push=function(Z){return j0(this,void 0,void 0,function(){var Y,X,F,K,Q,$,Q;return P0(this,function(W){switch(W.label){case 0:return Y=new J(this.compare),Y.limit=Z,Y.heapArray=this.heapArray.slice(-Z),[4,Y.init()];case 1:W.sent(),X=this.heapArray.length-1-Z,F=J.getParentIndexOf(X),K=[];for(Q=X;Q>F;--Q)K.push(Q);$=this.heapArray,W.label=2;case 2:if(!K.length)return[3,6];return Q=K.shift(),[4,this.compare($[Q],Y.peek())];case 3:if(!(W.sent()>0))return[3,5];return[4,Y.replace($[Q])];case 4:if(W.sent(),Q%2)K.push(J.getParentIndexOf(Q));W.label=5;case 5:return[3,2];case 6:return[2,Y.toArray()]}})})},J.prototype._moveNode=function(Z,Y){var X;X=h8([this.heapArray[Y],this.heapArray[Z]],2),this.heapArray[Z]=X[0],this.heapArray[Y]=X[1]},J.prototype._sortNodeDown=function(Z){return j0(this,void 0,void 0,function(){var Y,X,F,K,$,Q;return P0(this,function(W){switch(W.label){case 0:Y=this.heapArray.length,W.label=1;case 1:if(X=2*Z+1,F=X+1,K=Z,$=X<Y,!$)return[3,3];return[4,this.compare(this.heapArray[X],this.heapArray[K])];case 2:$=W.sent()<0,W.label=3;case 3:if($)K=X;if(Q=F<Y,!Q)return[3,5];return[4,this.compare(this.heapArray[F],this.heapArray[K])];case 4:Q=W.sent()<0,W.label=5;case 5:if(Q)K=F;if(K===Z)return[3,7];this._moveNode(Z,K),Z=K,W.label=6;case 6:return[3,1];case 7:return[2]}})})},J.prototype._sortNodeUp=function(Z){return j0(this,void 0,void 0,function(){var Y;return P0(this,function(X){switch(X.label){case 0:if(!(Z>0))return[3,2];return Y=J.getParentIndexOf(Z),[4,this.compare(this.heapArray[Z],this.heapArray[Y])];case 1:if(X.sent()<0)this._moveNode(Z,Y),Z=Y;else return[3,2];return[3,0];case 2:return[2]}})})},J.prototype._topN_push=function(Z){return j0(this,void 0,void 0,function(){var Y,X,F,K;return P0(this,function($){switch($.label){case 0:Y=new J(this._invertedCompare),Y.limit=Z,X=[0],F=this.heapArray,$.label=1;case 1:if(!X.length)return[3,7];if(K=X.shift(),!(K<F.length))return[3,6];if(!(Y.length<Z))return[3,3];return[4,Y.push(F[K])];case 2:return $.sent(),X.push.apply(X,r8([],h8(J.getChildrenIndexOf(K)),!1)),[3,6];case 3:return[4,this.compare(F[K],Y.peek())];case 4:if(!($.sent()<0))return[3,6];return[4,Y.replace(F[K])];case 5:$.sent(),X.push.apply(X,r8([],h8(J.getChildrenIndexOf(K)),!1)),$.label=6;case 6:return[3,1];case 7:return[2,Y.toArray()]}})})},J.prototype._topN_fill=function(Z){return j0(this,void 0,void 0,function(){var Y,X,F,K,$,$;return P0(this,function(Q){switch(Q.label){case 0:return Y=this.heapArray,X=new J(this._invertedCompare),X.limit=Z,X.heapArray=Y.slice(0,Z),[4,X.init()];case 1:Q.sent(),F=J.getParentIndexOf(Z-1)+1,K=[];for($=F;$<Z;++$)K.push.apply(K,r8([],h8(J.getChildrenIndexOf($).filter(function(W){return W<Y.length})),!1));if((Z-1)%2)K.push(Z);Q.label=2;case 2:if(!K.length)return[3,6];if($=K.shift(),!($<Y.length))return[3,5];return[4,this.compare(Y[$],X.peek())];case 3:if(!(Q.sent()<0))return[3,5];return[4,X.replace(Y[$])];case 4:Q.sent(),K.push.apply(K,r8([],h8(J.getChildrenIndexOf($)),!1)),Q.label=5;case 5:return[3,2];case 6:return[2,X.toArray()]}})})},J.prototype._topN_heap=function(Z){return j0(this,void 0,void 0,function(){var Y,X,F,K,$;return P0(this,function(Q){switch(Q.label){case 0:Y=this.clone(),X=[],F=0,Q.label=1;case 1:if(!(F<Z))return[3,4];return $=(K=X).push,[4,Y.pop()];case 2:$.apply(K,[Q.sent()]),Q.label=3;case 3:return++F,[3,1];case 4:return[2,X]}})})},J.prototype._topIdxOf=function(Z){return j0(this,void 0,void 0,function(){var Y,X,F,K;return P0(this,function($){switch($.label){case 0:if(!Z.length)return[2,-1];Y=0,X=Z[Y],F=1,$.label=1;case 1:if(!(F<Z.length))return[3,4];return[4,this.compare(Z[F],X)];case 2:if(K=$.sent(),K<0)Y=F,X=Z[F];$.label=3;case 3:return++F,[3,1];case 4:return[2,Y]}})})},J.prototype._topOf=function(){var Z=[];for(var Y=0;Y<arguments.length;Y++)Z[Y]=arguments[Y];return j0(this,void 0,void 0,function(){var X;return P0(this,function(F){switch(F.label){case 0:return X=new J(this.compare),[4,X.init(Z)];case 1:return F.sent(),[2,X.peek()]}})})},J}(),Lo=function(J,Z){var Y={label:0,sent:function(){if(K[0]&1)throw K[1];return K[1]},trys:[],ops:[]},X,F,K,$=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return $.next=Q(0),$.throw=Q(1),$.return=Q(2),typeof Symbol==="function"&&($[Symbol.iterator]=function(){return this}),$;function Q(G){return function(V){return W([G,V])}}function W(G){if(X)throw new TypeError("Generator is already executing.");while($&&($=0,G[0]&&(Y=0)),Y)try{if(X=1,F&&(K=G[0]&2?F.return:G[0]?F.throw||((K=F.return)&&K.call(F),0):F.next)&&!(K=K.call(F,G[1])).done)return K;if(F=0,K)G=[G[0]&2,K.value];switch(G[0]){case 0:case 1:K=G;break;case 4:return Y.label++,{value:G[1],done:!1};case 5:Y.label++,F=G[1],G=[0];continue;case 7:G=Y.ops.pop(),Y.trys.pop();continue;default:if((K=Y.trys,!(K=K.length>0&&K[K.length-1]))&&(G[0]===6||G[0]===2)){Y=0;continue}if(G[0]===3&&(!K||G[1]>K[0]&&G[1]<K[3])){Y.label=G[1];break}if(G[0]===6&&Y.label<K[1]){Y.label=K[1],K=G;break}if(K&&Y.label<K[2]){Y.label=K[2],Y.ops.push(G);break}if(K[2])Y.ops.pop();Y.trys.pop();continue}G=Z.call(J,Y)}catch(V){G=[6,V],F=0}finally{X=K=0}if(G[0]&5)throw G[1];return{value:G[0]?G[1]:void 0,done:!0}}},v8=function(J,Z){var Y=typeof Symbol==="function"&&J[Symbol.iterator];if(!Y)return J;var X=Y.call(J),F,K=[],$;try{while((Z===void 0||Z-- >0)&&!(F=X.next()).done)K.push(F.value)}catch(Q){$={error:Q}}finally{try{if(F&&!F.done&&(Y=X.return))Y.call(X)}finally{if($)throw $.error}}return K},D8=function(J,Z,Y){if(Y||arguments.length===2){for(var X=0,F=Z.length,K;X<F;X++)if(K||!(X in Z)){if(!K)K=Array.prototype.slice.call(Z,0,X);K[X]=Z[X]}}return J.concat(K||Array.prototype.slice.call(Z))};var yj=function(){function J(Z){if(Z===void 0)Z=J.minComparator;var Y=this;this.compare=Z,this.heapArray=[],this._limit=0,this.offer=this.add,this.element=this.peek,this.poll=this.pop,this.removeAll=this.clear,this._invertedCompare=function(X,F){return-1*Y.compare(X,F)}}return J.getChildrenIndexOf=function(Z){return[Z*2+1,Z*2+2]},J.getParentIndexOf=function(Z){if(Z<=0)return-1;var Y=Z%2?1:2;return Math.floor((Z-Y)/2)},J.getSiblingIndexOf=function(Z){if(Z<=0)return-1;var Y=Z%2?1:-1;return Z+Y},J.minComparator=function(Z,Y){if(Z>Y)return 1;else if(Z<Y)return-1;else return 0},J.maxComparator=function(Z,Y){if(Y>Z)return 1;else if(Y<Z)return-1;else return 0},J.minComparatorNumber=function(Z,Y){return Z-Y},J.maxComparatorNumber=function(Z,Y){return Y-Z},J.defaultIsEqual=function(Z,Y){return Z===Y},J.print=function(Z){function Y(V){var O=J.getParentIndexOf(V);return Math.floor(Math.log2(O+1))}function X(V,O){var v="";for(;O>0;--O)v+=V;return v}var F=0,K=[],$=Y(Z.length-1)+2,Q=0;while(F<Z.length){var W=Y(F)+1;if(F===0)W=0;var G=String(Z.get(F));if(G.length>Q)Q=G.length;K[W]=K[W]||[],K[W].push(G),F+=1}return K.map(function(V,O){var v=Math.pow(2,$-O)-1;return X(" ",Math.floor(v/2)*Q)+V.map(function(w){var H=(Q-w.length)/2;return X(" ",Math.ceil(H))+w+X(" ",Math.floor(H))}).join(X(" ",v*Q))}).join(`
340
340
  `)},J.heapify=function(Z,Y){var X=new J(Y);return X.heapArray=Z,X.init(),X},J.heappop=function(Z,Y){var X=new J(Y);return X.heapArray=Z,X.pop()},J.heappush=function(Z,Y,X){var F=new J(X);F.heapArray=Z,F.push(Y)},J.heappushpop=function(Z,Y,X){var F=new J(X);return F.heapArray=Z,F.pushpop(Y)},J.heapreplace=function(Z,Y,X){var F=new J(X);return F.heapArray=Z,F.replace(Y)},J.heaptop=function(Z,Y,X){if(Y===void 0)Y=1;var F=new J(X);return F.heapArray=Z,F.top(Y)},J.heapbottom=function(Z,Y,X){if(Y===void 0)Y=1;var F=new J(X);return F.heapArray=Z,F.bottom(Y)},J.nlargest=function(Z,Y,X){var F=new J(X);return F.heapArray=D8([],v8(Y),!1),F.init(),F.top(Z)},J.nsmallest=function(Z,Y,X){var F=new J(X);return F.heapArray=D8([],v8(Y),!1),F.init(),F.bottom(Z)},J.prototype.add=function(Z){return this._sortNodeUp(this.heapArray.push(Z)-1),this._applyLimit(),!0},J.prototype.addAll=function(Z){var Y,X=this.length;(Y=this.heapArray).push.apply(Y,D8([],v8(Z),!1));for(var F=this.length;X<F;++X)this._sortNodeUp(X);return this._applyLimit(),!0},J.prototype.bottom=function(Z){if(Z===void 0)Z=1;if(this.heapArray.length===0||Z<=0)return[];else if(this.heapArray.length===1)return[this.heapArray[0]];else if(Z>=this.heapArray.length)return D8([],v8(this.heapArray),!1);else return this._bottomN_push(~~Z)},J.prototype.check=function(){var Z=this;return this.heapArray.find(function(Y,X){return!!Z.getChildrenOf(X).find(function(F){return Z.compare(Y,F)>0})})},J.prototype.clear=function(){this.heapArray=[]},J.prototype.clone=function(){var Z=new J(this.comparator());return Z.heapArray=this.toArray(),Z._limit=this._limit,Z},J.prototype.comparator=function(){return this.compare},J.prototype.contains=function(Z,Y){if(Y===void 0)Y=J.defaultIsEqual;return this.indexOf(Z,Y)!==-1},J.prototype.init=function(Z){if(Z)this.heapArray=D8([],v8(Z),!1);for(var Y=Math.floor(this.heapArray.length);Y>=0;--Y)this._sortNodeDown(Y);this._applyLimit()},J.prototype.isEmpty=function(){return this.length===0},J.prototype.indexOf=function(Z,Y){if(Y===void 0)Y=J.defaultIsEqual;if(this.heapArray.length===0)return-1;var X=[],F=0;while(F<this.heapArray.length){var K=this.heapArray[F];if(Y(K,Z))return F;else if(this.compare(K,Z)<=0)X.push.apply(X,D8([],v8(J.getChildrenIndexOf(F)),!1));F=X.shift()||this.heapArray.length}return-1},J.prototype.indexOfEvery=function(Z,Y){if(Y===void 0)Y=J.defaultIsEqual;if(this.heapArray.length===0)return[];var X=[],F=[],K=0;while(K<this.heapArray.length){var $=this.heapArray[K];if(Y($,Z))F.push(K),X.push.apply(X,D8([],v8(J.getChildrenIndexOf(K)),!1));else if(this.compare($,Z)<=0)X.push.apply(X,D8([],v8(J.getChildrenIndexOf(K)),!1));K=X.shift()||this.heapArray.length}return F},J.prototype.leafs=function(){if(this.heapArray.length===0)return[];var Z=J.getParentIndexOf(this.heapArray.length-1);return this.heapArray.slice(Z+1)},Object.defineProperty(J.prototype,"length",{get:function(){return this.heapArray.length},enumerable:!1,configurable:!0}),Object.defineProperty(J.prototype,"limit",{get:function(){return this._limit},set:function(Z){if(Z<0||isNaN(Z))this._limit=0;else this._limit=~~Z;this._applyLimit()},enumerable:!1,configurable:!0}),J.prototype.setLimit=function(Z){if(this.limit=Z,Z<0||isNaN(Z))return NaN;else return this._limit},J.prototype.peek=function(){return this.heapArray[0]},J.prototype.pop=function(){var Z=this.heapArray.pop();if(this.length>0&&Z!==void 0)return this.replace(Z);return Z},J.prototype.push=function(){var Z=[];for(var Y=0;Y<arguments.length;Y++)Z[Y]=arguments[Y];if(Z.length<1)return!1;else if(Z.length===1)return this.add(Z[0]);else return this.addAll(Z)},J.prototype.pushpop=function(Z){var Y;if(this.compare(this.heapArray[0],Z)<0)Y=v8([this.heapArray[0],Z],2),Z=Y[0],this.heapArray[0]=Y[1],this._sortNodeDown(0);return Z},J.prototype.remove=function(Z,Y){var X=this;if(Y===void 0)Y=J.defaultIsEqual;if(!this.heapArray.length)return!1;if(Z===void 0)return this.pop(),!0;var F=[0];while(F.length){var K=F.shift();if(Y(this.heapArray[K],Z)){if(K===0)this.pop();else if(K===this.heapArray.length-1)this.heapArray.pop();else this.heapArray.splice(K,1,this.heapArray.pop()),this._sortNodeUp(K),this._sortNodeDown(K);return!0}else if(this.compare(this.heapArray[K],Z)<=0){var $=J.getChildrenIndexOf(K).filter(function(Q){return Q<X.heapArray.length});F.push.apply(F,D8([],v8($),!1))}}return!1},J.prototype.replace=function(Z){var Y=this.heapArray[0];return this.heapArray[0]=Z,this._sortNodeDown(0),Y},J.prototype.size=function(){return this.length},J.prototype.top=function(Z){if(Z===void 0)Z=1;if(this.heapArray.length===0||Z<=0)return[];else if(this.heapArray.length===1||Z===1)return[this.heapArray[0]];else if(Z>=this.heapArray.length)return D8([],v8(this.heapArray),!1);else return this._topN_push(~~Z)},J.prototype.toArray=function(){return D8([],v8(this.heapArray),!1)},J.prototype.toString=function(){return this.heapArray.toString()},J.prototype.get=function(Z){return this.heapArray[Z]},J.prototype.getChildrenOf=function(Z){var Y=this;return J.getChildrenIndexOf(Z).map(function(X){return Y.heapArray[X]}).filter(function(X){return X!==void 0})},J.prototype.getParentOf=function(Z){var Y=J.getParentIndexOf(Z);return this.heapArray[Y]},J.prototype[Symbol.iterator]=function(){return Lo(this,function(Z){switch(Z.label){case 0:if(!this.length)return[3,2];return[4,this.pop()];case 1:return Z.sent(),[3,0];case 2:return[2]}})},J.prototype.iterator=function(){return this.toArray()},J.prototype._applyLimit=function(){if(this._limit>0&&this._limit<this.heapArray.length){var Z=this.heapArray.length-this._limit;while(Z)this.heapArray.pop(),--Z}},J.prototype._bottomN_push=function(Z){var Y=new J(this.compare);Y.limit=Z,Y.heapArray=this.heapArray.slice(-Z),Y.init();var X=this.heapArray.length-1-Z,F=J.getParentIndexOf(X),K=[];for(var $=X;$>F;--$)K.push($);var Q=this.heapArray;while(K.length){var $=K.shift();if(this.compare(Q[$],Y.peek())>0){if(Y.replace(Q[$]),$%2)K.push(J.getParentIndexOf($))}}return Y.toArray()},J.prototype._moveNode=function(Z,Y){var X;X=v8([this.heapArray[Y],this.heapArray[Z]],2),this.heapArray[Z]=X[0],this.heapArray[Y]=X[1]},J.prototype._sortNodeDown=function(Z){var Y=this.heapArray.length;while(!0){var X=2*Z+1,F=X+1,K=Z;if(X<Y&&this.compare(this.heapArray[X],this.heapArray[K])<0)K=X;if(F<Y&&this.compare(this.heapArray[F],this.heapArray[K])<0)K=F;if(K===Z)break;this._moveNode(Z,K),Z=K}},J.prototype._sortNodeUp=function(Z){while(Z>0){var Y=J.getParentIndexOf(Z);if(this.compare(this.heapArray[Z],this.heapArray[Y])<0)this._moveNode(Z,Y),Z=Y;else break}},J.prototype._topN_push=function(Z){var Y=new J(this._invertedCompare);Y.limit=Z;var X=[0],F=this.heapArray;while(X.length){var K=X.shift();if(K<F.length){if(Y.length<Z)Y.push(F[K]),X.push.apply(X,D8([],v8(J.getChildrenIndexOf(K)),!1));else if(this.compare(F[K],Y.peek())<0)Y.replace(F[K]),X.push.apply(X,D8([],v8(J.getChildrenIndexOf(K)),!1))}}return Y.toArray()},J.prototype._topN_fill=function(Z){var Y=this.heapArray,X=new J(this._invertedCompare);X.limit=Z,X.heapArray=Y.slice(0,Z),X.init();var F=J.getParentIndexOf(Z-1)+1,K=[];for(var $=F;$<Z;++$)K.push.apply(K,D8([],v8(J.getChildrenIndexOf($).filter(function(Q){return Q<Y.length})),!1));if((Z-1)%2)K.push(Z);while(K.length){var $=K.shift();if($<Y.length){if(this.compare(Y[$],X.peek())<0)X.replace(Y[$]),K.push.apply(K,D8([],v8(J.getChildrenIndexOf($)),!1))}}return X.toArray()},J.prototype._topN_heap=function(Z){var Y=this.clone(),X=[];for(var F=0;F<Z;++F)X.push(Y.pop());return X},J.prototype._topIdxOf=function(Z){if(!Z.length)return-1;var Y=0,X=Z[Y];for(var F=1;F<Z.length;++F){var K=this.compare(Z[F],X);if(K<0)Y=F,X=Z[F]}return Y},J.prototype._topOf=function(){var Z=[];for(var Y=0;Y<arguments.length;Y++)Z[Y]=arguments[Y];var X=new J(this.compare);return X.init(Z),X.peek()},J}();class N7 extends z9{_faceSpeed=0;_faceTarget;_jumpHeight=0;_moveSpeed=0;_moveTarget;_moveIgnoreAxes={};_onFace;_onFaceComplete;_onMove;_onMoveComplete;face(J,Z,Y){this._faceTarget=J,this._faceSpeed=Z,this._onFace=Y?.faceCallback,this._onFaceComplete=Y?.faceCompleteCallback}jump(J){this._jumpHeight=J}move(J,Z,Y){this._moveTarget=J,this._moveSpeed=Z,this._moveIgnoreAxes=Y?.moveIgnoreAxes??{},this._onMove=Y?.moveCallback,this._onMoveComplete=Y?.moveCompleteCallback}tick(J,Z){if(super.tick(J,Z),!this._moveTarget&&!this._faceTarget&&!this._jumpHeight)return;let Y=Z/1000,X=J.position;if(J.isDynamic&&this._jumpHeight>0){let F=Math.abs(J.world.simulation.gravity.y),K=Math.sqrt(2*F*this._jumpHeight);J.applyImpulse({x:0,y:K*J.mass,z:0}),this._jumpHeight=0}if(this._moveTarget){let F={x:this._moveIgnoreAxes.x?0:this._moveTarget.x-X.x,y:this._moveIgnoreAxes.y?0:this._moveTarget.y-X.y,z:this._moveIgnoreAxes.z?0:this._moveTarget.z-X.z},K=F.x*F.x+F.y*F.y+F.z*F.z;if(K>0.1){let $=Math.sqrt(K),Q=this._moveSpeed*Y,G=Math.min($,Q)/$,V={x:X.x+F.x*G,y:X.y+F.y*G,z:X.z+F.z*G};if(J.setPosition(V),this._onMove)this._onMove(V,this._moveTarget)}else if(this._moveTarget=void 0,this._onMoveComplete){let $=this._onMoveComplete;this._onMove=void 0,this._onMoveComplete=void 0,$(X)}}if(this._faceTarget){let F={x:this._faceTarget.x-X.x,z:this._faceTarget.z-X.z},K=Math.atan2(-F.x,-F.z),$=J.rotation,Q=Math.atan2(2*($.w*$.y),1-2*($.y*$.y)),W=K-Q;while(W>Math.PI)W-=2*Math.PI;while(W<-Math.PI)W+=2*Math.PI;if(Math.abs(W)>0.01){let G=this._faceSpeed*Y,V=Math.abs(W)<G?W:Math.sign(W)*G,v=(Q+V)/2,w={x:0,y:Math.fround(Math.sin(v)),z:0,w:Math.fround(Math.cos(v))};if(J.setRotation(w),this._onFace)this._onFace($,w)}else if(this._faceTarget=void 0,this._onFaceComplete){let G=this._onFaceComplete;this._onFaceComplete=void 0,G(J.rotation)}}}}class $G extends N7{_debug=!1;_entity;_maxFall=0;_maxJump=0;_maxOpenSetIterations=200;_onPathfindAbort;_onPathfindComplete;_onWaypointMoveComplete;_onWaypointMoveSkipped;_speed=0;_target;_verticalPenalty=0;_waypoints=[];_waypointNextIndex=0;_waypointTimeoutMs=2000;get debug(){return this._debug}get maxFall(){return this._maxFall}get maxJump(){return this._maxJump}get maxOpenSetIterations(){return this._maxOpenSetIterations}get speed(){return this._speed}get target(){return this._target}get verticalPenalty(){return this._verticalPenalty}get waypoints(){return this._waypoints}get waypointNextIndex(){return this._waypointNextIndex}get waypointTimeoutMs(){return this._waypointTimeoutMs}pathfind(J,Z,Y){if(this._target=J,this._speed=Z,this._debug=Y?.debug??!1,this._maxFall=Y?.maxFall?-Math.abs(Y.maxFall):0,this._maxJump=Y?.maxJump?Math.abs(Y.maxJump):0,this._maxOpenSetIterations=Y?.maxOpenSetIterations??200,this._onPathfindAbort=Y?.pathfindAbortCallback,this._onPathfindComplete=Y?.pathfindCompleteCallback,this._onWaypointMoveComplete=Y?.waypointMoveCompleteCallback,this._onWaypointMoveSkipped=Y?.waypointMoveSkippedCallback,this._verticalPenalty=Y?.verticalPenalty??0,this._waypoints=[],this._waypointNextIndex=0,this._waypointTimeoutMs=Y?.waypointTimeoutMs??2000/Z,!this._calculatePath())return!1;return this._moveToNextWaypoint(),!0}attach(J){super.attach(J),this._entity=J}detach(J){super.detach(J),this._entity=void 0}tick(J,Z){super.tick(J,Z)}_calculatePath(){if(!this._target||!this._entity?.world)throw new Error("PathfindingEntityController._calculatePath: No target or world");let J=this._entity.height,Z=this._findGroundedStart();if(!Z){if(this._debug)console.warn(`PathfindingEntityController._calculatePath: No valid grounded start found within maxFall distance, path search aborted. Start: ${this._coordinateToKey(this._target)}, Target: ${this._coordinateToKey(this._target)}`);return!1}let Y={x:Math.floor(this._target.x),y:Math.floor(this._target.y),z:Math.floor(this._target.z)},X=Math.abs(Y.x-Z.x),F=Math.abs(Y.y-Z.y),K=Math.abs(Y.z-Z.z);if(X<=2&&F<=2&&K<=2&&!this._isNeighborCoordinateBlocked(Z,Y,this._entity.height))return this._waypoints=[{x:Z.x+0.5,y:Z.y+J/2,z:Z.z+0.5},{x:Y.x+0.5,y:Y.y+J/2,z:Y.z+0.5}],!0;if(Z.x===Y.x&&Z.y===Y.y&&Z.z===Y.z)return this._waypoints=[{x:Z.x+0.5,y:Z.y+J/2,z:Z.z+0.5}],!0;let Q=this._coordinateToKey(Z),W=new Map,G=new Map([[Q,0]]),V=new Map([[Q,this._pathfindingHeuristic(Z,Y)]]),O=new Set,v=new yj((P,x)=>{let j=V.get(P[0])??1/0,z=V.get(x[0])??1/0;return j-z});v.push([Q,Z]);let w=[{x:0,y:0,z:1},{x:1,y:0,z:0},{x:0,y:0,z:-1},{x:-1,y:0,z:0},{x:1,y:0,z:1},{x:1,y:0,z:-1},{x:-1,y:0,z:1},{x:-1,y:0,z:-1}],H=[];for(let P=this._maxJump;P>=this._maxFall;P--){if(P===0)continue;let x=Math.abs(Z.y+P-Y.y);H.push({y:P,distanceToTargetY:x})}H.sort((P,x)=>P.distanceToTargetY-x.distanceToTargetY);let N=[...w,...H.flatMap(({y:P})=>w.map((x)=>({...x,y:P})))],q=0,M=Math.abs(Y.x-Z.x)+Math.abs(Y.y-Z.y)+Math.abs(Y.z-Z.z),R=Math.min(this._maxOpenSetIterations,M*20);while(!v.isEmpty()&&q<R){q++;let[P,x]=v.pop();if(x.x===Y.x&&x.y===Y.y&&x.z===Y.z){let B=this._reconstructPath(W,x);if(this._waypoints=B.map((S)=>({x:S.x+0.5,y:S.y+J/2,z:S.z+0.5})),this._debug)console.log(`PathfindingEntityController._calculatePath: Path found after ${q} open set iterations. Start: ${this._coordinateToKey(Z)}, Target: ${this._coordinateToKey(this._target)}`);return!0}O.add(P);let j=G.get(P),z=new Map;for(let B of N){let S=`${B.x},${B.z}`,E=B.y<0;if(E&&z.has(S))continue;let C={x:x.x+B.x,y:x.y+B.y,z:x.z+B.z};if(Math.abs(Y.x-C.x)+Math.abs(Y.y-C.y)+Math.abs(Y.z-C.z)>M*1.5)continue;let p=this._coordinateToKey(C);if(O.has(p))continue;let c=this._isNeighborCoordinateBlocked(x,C,this._entity.height);if(E&&c){z.set(S,!0);continue}if(c)continue;let _=Math.abs(B.x),b=Math.abs(B.y),r=Math.abs(B.z),c0=b===0?0:this._verticalPenalty,u0=(Math.max(_,b,r)===1&&_+b+r>1?1.4:1)+c0,t8=j+u0,S6=G.get(p)??1/0;if(t8>=S6)continue;W.set(p,x),G.set(p,t8);let e1=t8+this._pathfindingHeuristic(C,Y);V.set(p,e1),v.push([p,C])}}if(q>=R){if(this._onPathfindAbort?.(),this._debug)console.warn(`PathfindingEntityController._calculatePath: Maximum open set iterations reached (${R}), path search aborted. Start: ${this._coordinateToKey(Z)}, Target: ${this._coordinateToKey(this._target)}`)}else if(this._debug)console.warn(`PathfindingEntityController._calculatePath: No valid path found. Start: ${this._coordinateToKey(Z)}, Target: ${this._coordinateToKey(this._target)}`);return this._target=void 0,this._waypoints=[],!1}_reconstructPath(J,Z){let Y=[Z],X=Z;while(J.has(this._coordinateToKey(X)))X=J.get(this._coordinateToKey(X)),Y.unshift(X);return Y}_coordinateToKey(J){return`${J.x},${J.y},${J.z}`}_moveToNextWaypoint(){let J=this._waypointNextIndex>0?this._waypoints[this._waypointNextIndex-1]:void 0,Z=this._waypoints[this._waypointNextIndex];if(!Z||!this._entity)return;let Y=0;if(this._entity.isDynamic&&J&&Z.y>J.y){let X=Z.y-J.y,F=Math.min(X,this._maxJump)+0.75;this.jump(F);let K=Math.abs(this._entity.world.simulation.gravity.y),$=Math.sqrt(2*K*F),Q=J.x+0.5,W=J.z+0.5,G=Z.x+0.5,V=Z.z+0.5,O=G-Q,v=V-W,w=Math.sqrt(O*O+v*v),H=$/K,N=w/this._speed;Y=Math.min(H*0.8,N)*1000}setTimeout(()=>{if(!this._entity)return;let X=Date.now();this.face(Z,this._speed),this.move(Z,this._speed,{moveIgnoreAxes:{y:this._entity.isDynamic},moveCallback:()=>{if(Date.now()-X>this._waypointTimeoutMs&&this._waypointNextIndex<this._waypoints.length-1)this._onWaypointMoveSkipped?.(Z,this._waypointNextIndex),this._waypointNextIndex++,this._moveToNextWaypoint()},moveCompleteCallback:()=>{if(this._waypointNextIndex<this._waypoints.length-1)this._onWaypointMoveComplete?.(Z,this._waypointNextIndex),this._waypointNextIndex++,this._moveToNextWaypoint();else this._onPathfindComplete?.()}})},Y)}_pathfindingHeuristic(J,Z){return Math.abs(J.x-Z.x)+Math.abs(J.y-Z.y)+Math.abs(J.z-Z.z)}_isNeighborCoordinateBlocked(J,Z,Y){if(!this._entity?.world)return!1;let X=this._entity.world,F=Math.floor(Z.x),K=Math.floor(Z.y),$=Math.floor(Z.z),Q=Math.floor(J.x),W=Math.floor(J.z);if(!X.chunkLattice.hasBlock({x:F,y:K-1,z:$}))return!0;for(let G=0;G<Y;G++)if(X.chunkLattice.hasBlock({x:F,y:K+G,z:$}))return!0;if(F!==Q&&$!==W)for(let G=0;G<Y;G++){let V=X.chunkLattice.hasBlock({x:F,y:K+G,z:W}),O=X.chunkLattice.hasBlock({x:Q,y:K+G,z:$});if(V||O)return!0}return!1}_findGroundedStart(){if(!this._entity?.world)return;let{x:J,y:Z,z:Y}=this._entity.position,X={x:Math.floor(J),y:Math.floor(Z),z:Math.floor(Y)};for(let F=0;F<=Math.abs(this._maxFall);F++)if(this._entity.world.chunkLattice.hasBlock({...X,y:X.y-F-1}))return{...X,y:X.y-F};return}}export{Eu as startServer,uR as WorldLoopEventType,v7 as WorldLoop,L7 as World,yQ as WebServerEventType,a1 as WebServer,t1 as Vector3,H7 as Vector2,O7 as Ticker,W7 as Simulation,N7 as SimpleEntityController,V7 as SceneUIManager,tQ as SceneUI,sR as SUPPORTED_INPUT_KEYS,CY as RigidBodyType,r9 as RigidBody,iR as ROTATION_UPDATE_THRESHOLD,r1 as Quaternion,rQ as PlayerUIEventType,Q7 as PlayerUI,Eq as PlayerManagerEventType,O8 as PlayerManager,pY as PlayerEventType,X7 as PlayerEntityController,H9 as PlayerEntity,nR as PlayerCameraMode,oQ as PlayerCameraEventType,$7 as PlayerCamera,Y4 as Player,$G as PathfindingEntityController,AR as POSITION_UPDATE_THRESHOLD_SQ,iQ as PORT,F6 as ModelRegistry,k8 as Matrix4,T6 as Matrix3,e9 as Matrix2,yR as LightType,K7 as LightManager,sQ as LightEventType,aQ as Light,dR as GameServerEventType,d6 as GameServer,K0 as EventRouter,F7 as EntityManager,dQ as EntityEventType,J8 as Entity,gR as DEFAULT_ENTITY_RIGID_BODY_OPTIONS,X6 as CollisionGroupsBuilder,x9 as CollisionGroup,kJ as ColliderShape,G7 as ColliderMap,m8 as Collider,aX as CoefficientCombineRule,Y7 as ChunkLattice,uQ as ChunkEventType,I8 as Chunk,q7 as ChatManager,JG as ChatEventType,oX as BlockTypeRegistryEventType,D5 as BlockTypeRegistry,K6 as BlockType,J1 as Block,z9 as BaseEntityController,Y5 as AudioManager,mY as AudioEventType,Z5 as Audio};