@hology/core 0.0.273 → 0.0.275

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.
Files changed (93) hide show
  1. package/dist/effects/sequence/sequence-player.js +1 -1
  2. package/dist/effects/vfx/gpu-sprite-runtime.js +1 -1
  3. package/dist/gameplay/actors/builtin/components/character/character-movement.d.ts +19 -0
  4. package/dist/gameplay/actors/builtin/components/character/character-movement.js +1 -1
  5. package/dist/gameplay/actors/builtin/water-spline-volume-actor.d.ts +10 -0
  6. package/dist/gameplay/actors/builtin/water-spline-volume-actor.js +1 -1
  7. package/dist/gameplay/actors/builtin/water-volume-actor.d.ts +3 -1
  8. package/dist/gameplay/actors/builtin/water-volume-actor.js +1 -1
  9. package/dist/gameplay/actors/camera/first-person-camera-component.js +1 -1
  10. package/dist/gameplay/actors/camera/third-person-camera-component.d.ts +7 -0
  11. package/dist/gameplay/actors/camera/third-person-camera-component.js +1 -1
  12. package/dist/gameplay/ai/behavior-tree/move.d.ts +5 -0
  13. package/dist/gameplay/ai/behavior-tree/move.js +1 -1
  14. package/dist/gameplay/ai/behavior-tree/move.test.d.ts +2 -0
  15. package/dist/gameplay/ai/behavior-tree/move.test.js +4 -0
  16. package/dist/gameplay/animation/root-motion.js +1 -1
  17. package/dist/gameplay/input/input-service.d.ts +9 -1
  18. package/dist/gameplay/input/input-service.js +1 -1
  19. package/dist/gameplay/services/physics/physics-system.d.ts +2 -0
  20. package/dist/gameplay/services/physics/physics-system.js +1 -1
  21. package/dist/gameplay/services/render.d.ts +4 -1
  22. package/dist/gameplay/services/render.js +1 -1
  23. package/dist/gameplay/services/world.d.ts +5 -0
  24. package/dist/rendering/node-material-webgpu-resolver.d.ts +4 -1
  25. package/dist/rendering/node-material-webgpu-resolver.js +1 -1
  26. package/dist/rendering/sdfgi-settings.d.ts +8 -0
  27. package/dist/rendering/sdfgi-settings.js +4 -0
  28. package/dist/rendering/sdfgi-surface-material.d.ts +8 -0
  29. package/dist/rendering/sdfgi-surface-material.js +4 -0
  30. package/dist/rendering/webgpu-experimental-backend.d.ts +12 -2
  31. package/dist/rendering/webgpu-experimental-backend.js +1 -1
  32. package/dist/rendering.d.ts +30 -3
  33. package/dist/rendering.js +1 -1
  34. package/dist/scene/asset-resource-loader.d.ts +4 -0
  35. package/dist/scene/asset-resource-loader.js +1 -1
  36. package/dist/scene/collision/collision-shape-import.js +1 -1
  37. package/dist/scene/collision/rapier-shape.js +1 -1
  38. package/dist/scene/landscape/landscape-geometry.d.ts +24 -0
  39. package/dist/scene/landscape/landscape-geometry.js +4 -0
  40. package/dist/scene/landscape/landscape-manager.d.ts +1 -0
  41. package/dist/scene/landscape/landscape-manager.js +1 -1
  42. package/dist/scene/materializer.d.ts +9 -1
  43. package/dist/scene/materializer.js +1 -1
  44. package/dist/scene/model.d.ts +2 -0
  45. package/dist/scene/scene-data-service.d.ts +2 -1
  46. package/dist/scene/scene-data-service.js +1 -1
  47. package/dist/scene/sky.d.ts +2 -0
  48. package/dist/scene/sky.js +1 -1
  49. package/dist/shader/graph/compiler.js +1 -1
  50. package/dist/shader/graph/registry.js +1 -1
  51. package/dist/shader/parameter.js +1 -1
  52. package/dist/shader/sprite-shader.js +1 -1
  53. package/dist/shader-nodes/depth.d.ts +6 -4
  54. package/dist/shader-nodes/depth.js +1 -1
  55. package/dist/shader-nodes/index.d.ts +2 -1
  56. package/dist/shader-nodes/index.js +1 -1
  57. package/dist/shader-nodes/surface-reflection.d.ts +10 -0
  58. package/dist/shader-nodes/surface-reflection.js +4 -0
  59. package/dist/shader-nodes/water-volume.d.ts +6 -2
  60. package/dist/shader-nodes/water-volume.js +1 -1
  61. package/dist/test/asset-resource-loader-texture-array.test.js +1 -1
  62. package/dist/test/character-movement-solve.test.js +1 -1
  63. package/dist/test/collision-shape-import.test.js +1 -1
  64. package/dist/test/first-person-camera-component.test.js +1 -1
  65. package/dist/test/frame-stats.test.js +1 -1
  66. package/dist/test/gpu-sprite-compiler.test.js +1 -1
  67. package/dist/test/input.test.js +1 -1
  68. package/dist/test/landscape-geometry.test.d.ts +2 -0
  69. package/dist/test/landscape-geometry.test.js +4 -0
  70. package/dist/test/material-assignment.test.js +1 -1
  71. package/dist/test/materializer-dynamic-transform.test.js +1 -1
  72. package/dist/test/materializer-prefetch.test.js +1 -1
  73. package/dist/test/net-character-movement.test.js +1 -1
  74. package/dist/test/node-material-webgpu-resolver.test.js +1 -1
  75. package/dist/test/parameter-definition.test.js +1 -1
  76. package/dist/test/physics-hitstop.test.d.ts +2 -0
  77. package/dist/test/physics-hitstop.test.js +4 -0
  78. package/dist/test/physics-ray-object.test.js +1 -1
  79. package/dist/test/post-process-effect.test.js +1 -1
  80. package/dist/test/rapier-trimesh.test.d.ts +2 -0
  81. package/dist/test/rapier-trimesh.test.js +4 -0
  82. package/dist/test/sdfgi-settings.test.d.ts +2 -0
  83. package/dist/test/sdfgi-settings.test.js +4 -0
  84. package/dist/test/sequence-animation-retiming.test.js +1 -1
  85. package/dist/test/sequence-vfx.test.js +1 -1
  86. package/dist/test/shader-graph.test.js +1 -1
  87. package/dist/test/surface-reflection.test.d.ts +2 -0
  88. package/dist/test/surface-reflection.test.js +4 -0
  89. package/dist/test/water-spline-volume-actor.test.js +1 -1
  90. package/dist/utils/three/frame-stats.d.ts +8 -0
  91. package/dist/utils/three/frame-stats.js +1 -1
  92. package/package.json +3 -3
  93. package/tsconfig.tsbuildinfo +1 -1
@@ -60,6 +60,14 @@ export declare class CharacterMovementComponent extends ActorComponent {
60
60
  maxSpeedBackwards: number;
61
61
  maxSpeedSprint: number;
62
62
  maxSpeedCrouch: number;
63
+ swimmingEnabled: boolean;
64
+ maxSpeedSwimming: number;
65
+ /** Fraction of standing capsule height below the water surface while swimming. */
66
+ swimmingImmersion: number;
67
+ swimmingSurfaceResponse: number;
68
+ swimmingMaxVerticalSpeed: number;
69
+ /** Separate entry/exit depths prevent mode flickering at the waterline. */
70
+ swimmingDepthHysteresis: number;
63
71
  /** Enables crouch-press sliding without changing the existing steep-slope controller behavior. */
64
72
  slideEnabled: boolean;
65
73
  slideMinStartSpeed: number;
@@ -151,6 +159,10 @@ export declare class CharacterMovementComponent extends ActorComponent {
151
159
  private readonly groundRayTestOptions;
152
160
  private readonly physicsSystem;
153
161
  private readonly netService;
162
+ private readonly world;
163
+ private readonly waterVolumes;
164
+ private readonly waterProbe;
165
+ private swimmingSurfaceHeight;
154
166
  private readonly state;
155
167
  private readonly movementModes;
156
168
  private readonly savedMoves;
@@ -190,6 +202,10 @@ export declare class CharacterMovementComponent extends ActorComponent {
190
202
  registerMovementMode(strategy: NetCharacterMovementModeStrategy): void;
191
203
  applyImpulse(impulse: Vector3): void;
192
204
  getEffectiveGravity(): number;
205
+ /** Surface currently supporting swimming, in world units; null outside swimming. */
206
+ get swimmingWaterSurfaceHeight(): number | null;
207
+ /** Water surface intersecting the character while wading or swimming. */
208
+ get waterContactSurfaceHeight(): number | null;
193
209
  get isGrounded(): boolean;
194
210
  setRootMotionAction(action: AnimationAction, options?: RootMotionActionOptions): void;
195
211
  /**
@@ -215,6 +231,9 @@ export declare class CharacterMovementComponent extends ActorComponent {
215
231
  private performSubstep;
216
232
  private updateRotation;
217
233
  private applyMovement;
234
+ private getSwimmingDepth;
235
+ private updateWaterMovementMode;
236
+ private updateSwimmingMode;
218
237
  private updateModeAfterMove;
219
238
  private applyImpulseToVelocity;
220
239
  private sendSavedMoves;
@@ -1,4 +1,4 @@
1
- import{__decorate as t,__metadata as e}from"tslib";import i from"@dimforge/rapier3d-simd-compat";import{takeUntil as o}from"rxjs";import*as s from"three";import{ArrowHelper as n,MathUtils as r,Quaternion as a,Vector3 as h}from"three";import{RootMotionClip as l}from"../../../../animation/root-motion.js";import{inject as c}from"../../../../inject.js";import{ActionInput as d,AxisInput as u,RotationInput as m}from"../../../../input/index.js";import{NetRole as p}from"../../../../net/service/net-actor-role.js";import{RunOnClient as v,RunOnNotOwner as y,RunOnServer as g}from"../../../../net/service/rpc-decorator.js";import{NetService as S}from"../../../../net/service/net-service.js";import{PhysicsSystem as M,RayTestResult as f}from"../../../../services/physics/physics-system.js";import{CapsuleCollisionShape as x}from"../../../../../scene/collision/collision-shape.js";import{Parameter as T}from"../../../../../shader/parameter.js";import{PhysicsBodyType as C}from"../../../../services/physics/physics-system.js";import{ActorComponent as w,Component as R}from"../../../component.js";import{CharacterMovementMode as A}from"./modes.js";import{calculateRootMotionTargetApproachCorrection as D,constrainRootMotionTargetApproach as q,warpRootMotionTargetApproach as b}from"./root-motion-constraint.js";import{DEFAULT_MAX_CLIENT_TIME_AHEAD as z,DEFAULT_LARGE_CORRECTION_THRESHOLD as k,DEFAULT_MAX_COMBINED_MOVE_DELTA_TIME as P,DEFAULT_MAX_MOVE_DELTA_TIME as I,DEFAULT_MAX_MOVES_PER_PACKET as G,DEFAULT_MAX_REPLAYED_MOVES as O,DEFAULT_MAX_SERVER_MOVES_PER_TICK as j,DEFAULT_MAX_SAVED_MOVES as Y,DEFAULT_MAX_SERVER_MOVE_DELTA_TIME_SCALAR as N,DEFAULT_MAX_SERVER_MOVE_TIME_BUDGET as F,DEFAULT_MAX_SUBSTEP_DELTA_TIME as V,DEFAULT_MOVE_SEND_INTERVAL as H,DEFAULT_SIMULATED_INTERPOLATION_DELAY as E,DEFAULT_SIMULATED_STATE_INTERVAL as U,DEFAULT_SMALL_CORRECTION_TOLERANCE as X,DEFAULT_TELEPORT_SNAP_THRESHOLD as L,MOVE_FLAG_CROUCH as B,MOVE_FLAG_JUMP as Z,MOVE_FLAG_ROOT_MOTION as W,MOVE_FLAG_SLIDE_START as $,MOVE_FLAG_SPRINT as Q,MOVE_FLAG_SPRINT_START as J,SNAPSHOT_FLAG_CROUCH_SUPPRESSED as K,SNAPSHOT_FLAG_CROUCHING as _,NetCharacterProxySmoother as tt,NetCharacterSavedMoveBuffer as et,accrueNetCharacterServerMoveTime as it,createNetCharacterMovementSnapshot as ot,createNetCharacterServerMoveTimingState as st,consumeNetCharacterServerMoveTime as nt,decodeNetCharacterMoveBatch as rt,decodeNetCharacterOwnerAck as at,decodeNetCharacterOwnerCorrection as ht,decodeNetCharacterSimulatedState as lt,encodeNetCharacterMoveBatch as ct,encodeNetCharacterOwnerAck as dt,encodeNetCharacterOwnerCorrection as ut,encodeNetCharacterSimulatedState as mt,validateNetCharacterMove as pt}from"./net-character-movement-protocol.js";import{NetMode as vt}from"../../../../net/net-session.js";import{setSlideJumpVelocity as yt,shouldContinueSlide as gt,shouldStartSlide as St,updateSlideVelocity as Mt,updateSlideVelocityFromDisplacement as ft}from"./character-slide.js";export*from"./net-character-movement-protocol.js";const xt=131070,Tt=new h(0,1,0),Ct=new h,wt=new h,Rt=new h,At=new h,Dt=new h,qt=new h,bt=new h,zt=new h,kt=new h,Pt=new h,It=new h,Gt=new h,Ot=new h,jt=new h,Yt=new h(0,1,0),Nt=new h(0,-.05,0),Ft=new h,Vt=new a,Ht=new s.Euler,Et=new h,Ut=new h,Xt=new h,Lt=new h,Bt=new i.CharacterCollision;let Zt=class extends w{get autoStepMinWidth(){return this.cc.autostepMinWidth()}set autoStepMinWidth(t){this.cc.enableAutostep(this.cc.autostepMaxHeight(),t,this.cc.autostepIncludesDynamicBodies())}get autoStepDynamicObjects(){return this.cc.autostepIncludesDynamicBodies()}set autoStepDynamicObjects(t){this.cc.enableAutostep(this.cc.autostepMaxHeight(),this.cc.autostepMinWidth(),t)}get autoStepMaxHeight(){return this.cc.autostepMaxHeight()}set autoStepMaxHeight(t){this.cc.enableAutostep(t,this.cc.autostepMinWidth(),this.cc.autostepIncludesDynamicBodies())}get snapToGround(){return this.cc.snapToGroundDistance()}set snapToGround(t){this.cc.enableSnapToGround(t)}set offset(t){this.cc.setOffset(t)}get offset(){return this.cc.offset()}set normalNudgeFactor(t){this.cc.setNormalNudgeFactor(t)}get normalNudgeFactor(){return this.cc.normalNudgeFactor()}teleport(t,e=this.actor.rotation.y){this.state.position.copy(t),this.state.velocity.set(0,0,0),this.state.yaw=e,this.actor.position.copy(t),this.actor.rotation.y=e,this.rotationInput.rotation.y=e,this.physicsSystem.setPosition(this.actor,t),this.physicsSystem.setRotation(this.actor,this.actor.quaternion),this.physicsSystem.flushModifiedBodyPositionsToColliders()}constructor(){super(),this.isDefaultCharacterMovementComponent=!0,this.directionInput=new u,this.jumpInput=new d,this.sprintInput=new d,this.crouchInput=new d,this.rotationInput=new m,this.horizontalSpeed=0,this.maxSpeed=8,this.maxSpeedBackwards=8,this.maxSpeedSprint=12,this.maxSpeedCrouch=4,this.slideEnabled=!1,this.slideMinStartSpeed=8,this.slideMinExitSpeed=4,this.slideDeceleration=3,this.slideGravityScale=1,this.slideSteeringRate=2,this.sprintStartBoostSpeed=0,this.sprintStartBoostDamping=6,this.jumpVelocity=7,this.fallingMovementControl=.5,this.fallingReorientation=!1,this.groundAccelerationRate=4,this.gravityOverride=null,this.colliderHeight=2,this.colliderRadius=.5,this.crouchColliderHeight=1,this.crouchColliderRadius=null,this.jumpInAir=!1,this.mass=50,this.allowSliding=!0,this.minSlopeSlideAngle=r.degToRad(70),this.maxSlopeClimbAngle=r.degToRad(70),this.applyImpulsesToDynamicBodies=!0,this.normalizedDirection=!0,this.characterCollision=!1,this.allowRootMotionJumpCancel=!1,this.enabled=!0,this.movementInputEnabled=!0,this.rotateToMovementDirection=!1,this.smoothRotation=!0,this.rotationSpeed=40,this.maxRotationSpeed=100,this.impulseDamping=2,this.moveSendInterval=H,this.simulatedStateInterval=U,this.maxSavedMoves=Y,this.maxReplayedMoves=O,this.maxServerMovesPerTick=j,this.maxMovesPerPacket=G,this.maxMoveDeltaTime=I,this.maxCombinedMoveDeltaTime=P,this.maxServerMoveDeltaTimeScalar=N,this.maxClientTimeAhead=z,this.maxServerMoveTimeBudget=F,this.maxSubstepDeltaTime=V,this.fallGraceTime=.1,this.correctionToleranceSq=X*X,this.largeCorrectionThreshold=k,this.teleportSnapThreshold=L,this.listenServerSmoothing=!0,this.listenServerSmoothLocationTime=.04,this.listenServerMaxSmoothUpdateDistance=1,this.listenServerNoSmoothUpdateDistance=2.5,this.debugCorrections=!0,this.suppressUncrouchLift=!1,this.velocity=new h,this.visualSmoothingOffset=new h,this.slideDirection=new h,this.slideSurfaceNormal=new h(0,1,0),this.mode=A.walking,this.isSprinting=!1,this.isCrouching=!1,this.isSliding=!1,this.pressedJump=!1,this.rayTestResult=new f,this.groundRayTestOptions={debug:!1,excludeTriggers:!0,excludeActor:void 0,resolveActor:!1},this.physicsSystem=c(M),this.netService=c(S),this.state={sequence:0,position:new h,velocity:new h,yaw:0,lookYaw:0,mode:A.walking,grounded:!1,currentSpeed:0,fallGraceTime:0,prevInputDirection:new h,prevRotateToMovementDirection:!1},this.movementModes=new Map,this.savedMoves=new et(Y),this.serverMoveTiming=st(),this.serverMoveQueue=[],this.inputMoveScratch={sequence:0,clientTime:0,dt:0,inputX:0,inputY:0,yaw:0,flags:0,clientX:0,clientY:0,clientZ:0,rootMotionX:0,rootMotionY:0,rootMotionZ:0},this.authoritativeMoveScratch={sequence:0,clientTime:0,dt:0,inputX:0,inputY:0,yaw:0,flags:0,clientX:0,clientY:0,clientZ:0,rootMotionX:0,rootMotionY:0,rootMotionZ:0},this.movementModeContext={component:this,state:this.state,move:this.inputMoveScratch,deltaTime:0,rotatedDirection:wt,platformVelocity:At,outVelocity:Rt,rootMotionActive:!1,startedSprinting:!1},this.proxySmoother=new tt(E,L),this.proxySample=ot(),this.pendingSnapshot=ot(),this.impulse=new h,this.prevRootMotionPos=new h,this.rootMotionOptions={},this.rootMotionTargetConstraints=new Set,this.resetRootMotion=!1,this.nextMoveSequence=0,this.clientMoveTime=0,this.lastSentClientMoveTime=0,this.moveSendAccumulator=0,this.simulatedStateAccumulator=0,this.proxyTime=0,this.lastServerProcessedSequence=0,this.lastServerReceivedSequence=0,this.lastAutonomousMoveFlags=0,this.previousSprintInput=!1,this.previousCrouchInput=!1,this.crouchSuppressedUntilRelease=!1,this.slideOnLandingRequested=!1,this.initialized=!1,this.cc=this.physicsSystem.getCharacterController(.1),this.cc.enableSnapToGround(.1),this.cc.enableAutostep(0,.1,!1),this.registerMovementMode(Wt),this.registerMovementMode($t),this.registerMovementMode({mode:A.sliding,update:t=>this.updateSlidingMode(t)})}onInit(){this.groundRayTestOptions.excludeActor=this.actor,this.configureCharacterController(),this.physicsSystem.addActor(this.actor,[this.createCollisionShape()],{mass:0,type:C.kinematic,continousCollisionDetection:!1,friction:0,restitution:.5,ignoreForNavMesh:!0}),this.rotationInput.rotation.copy(this.actor.rotation),this.initializeStateFromActor(),this.initialized=!0,this.physicsSystem.beforeStep.pipe(o(this.disposed)).subscribe(t=>this.tick(t))}onLateUpdate(t){this.updateVisualSmoothing(t)}registerMovementMode(t){this.movementModes.set(t.mode,t)}applyImpulse(t){this.impulse.add(t)}getEffectiveGravity(){return this.gravityOverride??this.physicsSystem.getGravity().y}get isGrounded(){return this.rayTestResult.hasHit||this.cc.computedGrounded()}setRootMotionAction(t,e={}){const i=t?.getClip();if(i instanceof l){this.rootMotionAction=t,this.rootMotionOptions=e,this.resetRootMotion=!0;const o=[];this.rootMotionInterpolant=i.motionTrack.InterpolantFactoryMethodSmooth(o);const n=s.PropertyBinding.parseTrackName(i.motionTrack.name);this.rootMotionRootBone=this.actor.object.getObjectByName(n.nodeName)}}addRootMotionTargetConstraint(t,e,i=0){const o={targetPosition:t,minimumHorizontalDistance:Math.max(0,e),maximumAddedHorizontalDistance:Math.max(0,i),initialHorizontalDistance:Math.hypot(t.x-this.actor.position.x,t.z-this.actor.position.z),addedHorizontalDistance:0,requestedProgress:0};this.rootMotionTargetConstraints.add(o);let s=!1;return{setProgress:t=>{o.requestedProgress=Math.max(o.requestedProgress,Math.min(1,Math.max(0,t)))},dispose:()=>{s||(s=!0,this.rootMotionTargetConstraints.delete(o))}}}serverMove(t){const e=rt(t);if(e.ok)for(const t of e.value.moves)pt(t,this.lastServerReceivedSequence,this.maxMoveDeltaTime)&&(this.lastServerReceivedSequence=t.sequence,this.serverMoveQueue.push(t))}clientMoveAck(t){const e=at(t);e.ok&&this.actor.netRole===p.autonomousProxy&&(this.savedMoves.ack(e.value.sequence),this.sprintPolicy?.ack?.(e.value.sequence,!1))}clientMoveCorrection(t){const e=ht(t);e.ok&&this.actor.netRole===p.autonomousProxy&&(this.debugCorrections&&(null==this.correctionDebug&&(this.correctionDebug=new _t(ee(this.actor.object))),this.correctionDebug.update(this.state.position,e.value.snapshot)),this.applyCorrection(e.value.snapshot))}simulatedState(t){const e=lt(t);e.ok&&this.actor.netRole===p.simulatedProxy&&this.proxySmoother.push(e.value,this.proxyTime)}tick(t){if(!this.initialized)return;t=Math.min(.1,t);const e=this.actor.netRole,i=this.netService.mode;e!==p.simulatedProxy?this.enabled&&(e!==p.autonomousProxy?this.isRemoteControlledAuthority(i,e)?this.tickRemoteAuthority(t):this.tickAuthority(t,i):this.tickAutonomousProxy(t)):this.tickSimulatedProxy(t)}tickAutonomousProxy(t){const e=this.state.mode,i=this.lastAutonomousMoveFlags,o=this.createMoveFromInput(t,++this.nextMoveSequence,{quantizeClientTime:!0});this.performMove(o,ie),this.resetToggleCrouchAfterSlide(e);const s=this.state.mode!==e||o.flags!==i;this.lastAutonomousMoveFlags=o.flags,this.savedMoves.capacity=this.maxSavedMoves,this.savedMoves.maxCombinedDeltaTime=Math.min(this.maxCombinedMoveDeltaTime,this.maxMoveDeltaTime),this.savedMoves.push(o),this.sendSavedMoves(t,s)}tickAuthority(t,e){const i=this.state.mode,o=this.createMoveFromInput(t,++this.nextMoveSequence);this.performMove(o,ie),this.resetToggleCrouchAfterSlide(i),e!==vt.none&&this.sendSimulatedState(t,!1)}resetToggleCrouchAfterSlide(t){t===A.sliding&&this.state.mode!==A.sliding&&"toggle"===this.crouchInput.mode&&this.crouchInput.activated&&this.crouchInput.setActivated(!1)}tickRemoteAuthority(t){it(this.serverMoveTiming,t,this.maxServerMoveTimeBudget);let e=!1;const i=Number.isFinite(this.maxServerMovesPerTick)?Math.max(1,Math.floor(this.maxServerMovesPerTick)):this.serverMoveQueue.length,o=Math.min(this.serverMoveQueue.length,i),s=Xt.copy(this.actor.position);let n=!1;for(let t=0;t<o;t++){const t=this.serverMoveQueue.shift();if(null==t)break;if(!pt(t,this.lastServerProcessedSequence,this.maxMoveDeltaTime)){console.log("Net: Invalid move",t),this.sendOwnerCorrection(!0),e=!0;continue}const i=nt(this.serverMoveTiming,t,{maxMoveDeltaTime:this.maxMoveDeltaTime,maxServerMoveDeltaTimeScalar:this.maxServerMoveDeltaTimeScalar,maxClientTimeAhead:this.maxClientTimeAhead});if(i<0){this.sendOwnerCorrection(!0),e=!0;continue}const o=Jt(t,this.authoritativeMoveScratch);o.dt=i,o.rootMotionX=0,o.rootMotionY=0,o.rootMotionZ=0,o.flags&=~W,this.performMove(o,{immediate:!0,savedRootMotion:!1}),n=!0,this.lastServerProcessedSequence=o.sequence;const s=Kt(this.state,t);if(s>this.correctionToleranceSq){console.log(`Net server: Correction error: ${Math.sqrt(s)}`);const o=this.state.position.x-t.clientX,n=this.state.position.y-t.clientY,r=this.state.position.z-t.clientZ;console.log(`diff x: ${o}, y: ${n}, z: ${r}`),console.log({sequence:t.sequence,moveDt:t.dt,serverMoveDeltaTime:i,flags:t.flags,mode:this.state.mode,grounded:this.state.grounded,fallGraceTime:this.state.fallGraceTime}),this.sendOwnerCorrection(s>this.largeCorrectionThreshold*this.largeCorrectionThreshold),e=!0}}0===this.lastServerProcessedSequence||e||(this.sprintPolicy?.ack?.(this.lastServerProcessedSequence,!1),this.clientMoveAck(dt(this.lastServerProcessedSequence))),n&&this.accumulateListenServerVisualSmoothing(s,this.actor.position),this.sendSimulatedState(t,!1)}tickSimulatedProxy(t){this.proxyTime+=t,this.proxySmoother.sample(this.proxyTime,this.proxySample)&&this.applySnapshot(this.proxySample,!0)}accumulateListenServerVisualSmoothing(t,e){if(!this.shouldSmoothListenServerRemoteAuthority())return void this.visualSmoothingOffset.set(0,0,0);Lt.subVectors(t,e);const i=Lt.lengthSq();i>1e-8&&(i>this.listenServerNoSmoothUpdateDistance*this.listenServerNoSmoothUpdateDistance?this.visualSmoothingOffset.set(0,0,0):(i>this.listenServerMaxSmoothUpdateDistance*this.listenServerMaxSmoothUpdateDistance&&Lt.setLength(this.listenServerMaxSmoothUpdateDistance),this.visualSmoothingOffset.add(Lt)))}updateVisualSmoothing(t){if(this.visualSmoothingOffset.lengthSq()<=1e-8)return void this.visualSmoothingOffset.set(0,0,0);if(!this.shouldSmoothListenServerRemoteAuthority())return void this.visualSmoothingOffset.set(0,0,0);const e=Math.max(.001,this.listenServerSmoothLocationTime);t<e?this.visualSmoothingOffset.multiplyScalar(1-t/e):this.visualSmoothingOffset.set(0,0,0),this.visualSmoothingOffset.lengthSq()<=1e-4&&this.visualSmoothingOffset.set(0,0,0)}shouldSmoothListenServerRemoteAuthority(){return this.listenServerSmoothing&&this.actor.netRole===p.authority&&this.netService.isServer&&!this.netService.isDedicatedServer&&this.isRemoteControlledAuthority()}createMoveFromInput(t,e,i={}){const o=r.clamp(t,.001,this.maxMoveDeltaTime);this.clientMoveTime+=o;let s=this.clientMoveTime,n=o;!0===i.quantizeClientTime&&(s=Math.max(this.lastSentClientMoveTime+.001,Math.round(1e3*this.clientMoveTime)/1e3),n=r.clamp(s-this.lastSentClientMoveTime,.001,this.maxMoveDeltaTime),this.lastSentClientMoveTime=s),this.sampleRootMotion(bt);const a=this.crouchInput.activated,h=a&&!this.previousCrouchInput;this.previousCrouchInput=a;const l=this.movementInputEnabled&&!a&&this.sprintInput.activated,c=l&&!this.previousSprintInput;this.previousSprintInput=l;const d=(this.movementInputEnabled&&this.jumpInput.activated?Z:0)|(l?Q:0)|(a?B:0)|(this.movementInputEnabled&&h&&this.slideEnabled?$:0)|(c?J:0)|(bt.lengthSq()>0?W:0),u=function(t,e){e.set(t.x,0,t.y),e.lengthSq()>1&&e.normalize();return e}(this.directionInput.vector,Et);this.movementInputEnabled||u.set(0,0,0);const m=this.inputMoveScratch;return m.sequence=e>>>0,m.clientTime=s,m.dt=n,m.inputX=u.x,m.inputY=u.z,m.yaw=this.rotationInput.rotation.y,m.flags=d,m.clientX=this.state.position.x,m.clientY=this.state.position.y,m.clientZ=this.state.position.z,m.rootMotionX=bt.x,m.rootMotionY=bt.y,m.rootMotionZ=bt.z,m}performMove(t,e){const i=r.clamp(t.dt,.001,this.maxMoveDeltaTime),o=Math.max(1,Math.ceil(i/this.maxSubstepDeltaTime)),s=0!==(t.flags&Q)&&0===(t.flags&B);this.sprintPolicy?.update?.(i,t.sequence,s),Gt.set(e.savedRootMotion?t.rootMotionX:0,e.savedRootMotion?t.rootMotionY:0,e.savedRootMotion?t.rootMotionZ:0),e.savedRootMotion||this.sampleRootMotion(Gt);let n=i;const a=i/o;for(let s=0;s<o;s++){const o=i>0?a/i:1;this.performSubstep(t,Math.min(a,n),Gt,o,e.immediate,0===s),n-=a}t.clientX=this.state.position.x,t.clientY=this.state.position.y,t.clientZ=this.state.position.z,t.flags=Gt.lengthSq()>0?t.flags|W:t.flags&~W,this.state.sequence=t.sequence,this.syncPublicState()}performSubstep(t,e,i,o,s,n){if(e<.001)return;this.checkGrounded(this.state.position),this.state.grounded=this.isGrounded;const r=null!=this.rootMotionAction&&this.rootMotionAction.enabled,a=i.lengthSq()>0,h=!r&&0!==(t.flags&Z),l=r||a;this.updateCrouchState(t,n,l,h),this.pressedJump=h,this.isSprinting=!1,this.updateRotation(t,e,r,a),this.resolvePlatformVelocity(At);const c=this.movementModeContext,d=this.movementModes.get(this.state.mode);if(null!=d){c.move=t,c.deltaTime=e,c.rootMotionActive=l,c.startedSprinting=n&&!l&&0===(t.flags&B)&&0!==(t.flags&J);const i=d.update(c);"number"==typeof i&&(this.state.mode=i)}else Rt.set(0,0,0);if(a){zt.copy(i).multiplyScalar(o).applyQuaternion(this.actor.quaternion),kt.copy(zt).divideScalar(e),this.state.mode===A.walking?(Rt.x=kt.x+At.x,Rt.z=kt.z+At.z):(Rt.x=kt.x,Rt.z=kt.z);const t=Math.sqrt(kt.x*kt.x+kt.z*kt.z);t>.4&&(this.state.currentSpeed=t)}if(this.applyImpulseToVelocity(Rt,e),h&&this.isSprinting){const t=Math.max(0,this.maxSpeedSprint),e=Qt(Rt);if(e>t){const i=t/e;Rt.x*=i,Rt.z*=i,this.state.velocity.x*=i,this.state.velocity.z*=i}}this.state.mode===A.walking&&this.state.velocity.copy(Rt),this.applyMovement(Rt,e,s),this.state.mode===A.sliding&&(ft(this.state.velocity,qt,At,this.slideSurfaceNormal,e),this.state.currentSpeed=Qt(this.state.velocity)),this.checkGrounded(this.state.position),this.state.grounded=this.isGrounded,this.updateModeAfterMove(Rt,e),this.state.mode===A.sliding&&this.state.velocity.length()<Math.max(0,this.slideMinExitSpeed)&&(this.state.mode=A.walking)}updateRotation(t,e,i,o){Ct.set(-t.inputX,0,t.inputY),Ct.lengthSq()>1&&Ct.normalize();const s=this.state.prevRotateToMovementDirection!==this.rotateToMovementDirection;let n=r.euclideanModulo(t.yaw-this.state.lookYaw+Math.PI,2*Math.PI)-Math.PI;if(s&&(this.actor.object.quaternion.setFromEuler(Ht.set(0,t.yaw,0)),n=0,this.state.lookYaw=t.yaw,this.state.prevRotateToMovementDirection=this.rotateToMovementDirection),wt.set(0,0,0),i)this.state.lookYaw=t.yaw;else if(this.rotateToMovementDirection){if(Ct.lengthSq()>0&&this.state.mode!==A.falling){const i=Ht.setFromQuaternion(this.actor.object.quaternion,"YXZ").y,o=Math.atan2(Ct.x,Ct.z),s=.99*t.yaw+o;if(this.smoothRotation){const t=r.euclideanModulo(s-i+Math.PI,2*Math.PI)-Math.PI;let o=r.clamp(t*this.rotationSpeed*e,-this.maxRotationSpeed*e,this.maxRotationSpeed*e);Math.abs(o)>Math.abs(t)&&(o=t),this.actor.object.quaternion.setFromEuler(Ht.set(0,i+o,0))}else this.actor.object.quaternion.setFromEuler(Ht.set(0,s,0));this.state.prevInputDirection.lerp(Ct,e*this.rotationSpeed),this.state.lookYaw+=n,wt.copy(this.actor.object.getWorldDirection(Et).normalize())}}else o||(this.state.lookYaw=t.yaw,this.actor.object.quaternion.setFromEuler(Ht.set(0,t.yaw,0)),Ct.lengthSq()>0&&wt.copy(Ct).applyAxisAngle(Tt,t.yaw).normalize())}applyMovement(t,e,i){if(t.lengthSq()>0||!this.state.grounded)if(Dt.copy(t).multiplyScalar(e),this.state.grounded&&((o=this.state.mode)===A.walking||o===A.sliding)){if(this.state.mode===A.walking&&this.rayTestResult.distance<=this.cc.offset()&&(Dt.y=Math.max(0,At.y*e)),qt.copy(this.physicsSystem.getActorComputedMovement(this.actor,this.cc,Dt,this.getCollisionGroup())),this.cc.computedCollision(0,Bt),null!=Bt.normal1){const t=Et.copy(Bt.normal1);if(Math.acos(r.clamp(t.dot(Tt),-1,1))>this.cc.maxSlopeClimbAngle()){const t=.016*this.getEffectiveGravity()*.5;Dt.y!==t&&(Dt.y=t,qt.copy(this.physicsSystem.getActorComputedMovement(this.actor,this.cc,Dt,this.getCollisionGroup())))}}}else qt.copy(this.physicsSystem.getActorComputedMovement(this.actor,this.cc,Dt,this.getCollisionGroup()));else qt.set(0,0,0);var o;this.suppressUncrouchLift&&(this.suppressUncrouchLift=!1,this.state.grounded&&this.state.mode===A.walking&&Dt.y<=1e-6&&qt.y>0&&(qt.y=0)),this.state.position.add(qt),i?(this.actor.position.copy(this.state.position),this.physicsSystem.updateActorTransform(this.actor),this.physicsSystem.flushModifiedBodyPositionsToColliders()):this.physicsSystem.setNextKinematicPosition(this.actor,this.state.position)}updateModeAfterMove(t,e){const i=function(t){if(0===t.numComputedCollisions())return!1;const e=t.computedCollision(0);Ft.set(e.normal2.x,e.normal2.y,e.normal2.z);const i=Ft.angleTo(Tt);Ft.set(e.normal1.x,e.normal1.y,e.normal1.z);const o=Ft.angleTo(Tt);if(i<100)return!1;return o>t.minSlopeSlideAngle()}(this.cc);!this.state.grounded||i?this.state.mode!==A.falling&&(this.state.fallGraceTime+=e,this.state.fallGraceTime>this.fallGraceTime+1e-6&&(this.state.mode=A.falling,this.state.velocity.copy(t))):this.state.velocity.y<=0&&(this.state.mode===A.falling&&(this.state.mode=A.walking),this.state.mode!==A.sliding&&(this.state.velocity.y=0),this.state.fallGraceTime=0)}applyImpulseToVelocity(t,e){if(this.impulse.lengthSq()<=.1)return void this.impulse.set(0,0,0);const i=Math.min(1,this.impulse.length()/5);t.x=r.lerp(t.x,this.impulse.x,i),t.z=r.lerp(t.z,this.impulse.z,i),t.y+=this.impulse.y;const o=Math.exp(-this.impulseDamping*e);this.impulse.x*=o,this.impulse.y>0?this.impulse.y+=e*this.getEffectiveGravity():this.impulse.y*=o,this.impulse.z*=o}sendSavedMoves(t,e=!1){if(this.moveSendAccumulator+=t,!e&&this.moveSendAccumulator<this.moveSendInterval)return;this.moveSendAccumulator=0;const i=this.savedMoves.getMovesForSend(this.maxMovesPerPacket);0!==i.length&&this.serverMove(ct(i))}sendOwnerCorrection(t){const e=this.toSnapshot(this.pendingSnapshot);t&&(e.horizontalSpeed=this.horizontalSpeed),this.sprintPolicy?.ack?.(e.sequence,!0),this.clientMoveCorrection(ut(e))}sendSimulatedState(t,e){this.simulatedStateAccumulator+=t,!e&&this.simulatedStateAccumulator<this.simulatedStateInterval||(this.simulatedStateAccumulator=0,this.simulatedState(mt(this.toSnapshot(this.pendingSnapshot))))}applyCorrection(t){this.sprintPolicy?.restore?.(t.sequence),this.savedMoves.ack(t.sequence),this.sprintPolicy?.ack?.(t.sequence,!0),this.applySnapshot(t,!0),this.savedMoves.replayAfter(t.sequence,t=>(this.performMove(t,{immediate:!0,savedRootMotion:!0}),null),this.maxReplayedMoves)}applySnapshot(t,e){this.state.sequence=t.sequence,this.state.position.set(t.x,t.y,t.z),this.state.velocity.set(t.velocityX,t.velocityY,t.velocityZ),this.state.yaw=t.yaw,this.state.lookYaw=t.yaw,this.state.mode=t.mode,this.state.currentSpeed=t.horizontalSpeed,this.state.fallGraceTime=0,this.actor.position.copy(this.state.position),this.actor.object.quaternion.setFromEuler(Ht.set(0,t.yaw,0)),this.crouchSuppressedUntilRelease=0!==(t.flags&K),this.setCrouching(0!==(t.flags&_)||t.mode===A.sliding),e&&(this.physicsSystem.updateActorTransform(this.actor),this.physicsSystem.flushModifiedBodyPositionsToColliders()),this.checkGrounded(this.state.position),this.state.grounded=this.isGrounded,this.syncPublicState()}toSnapshot(t){return t.sequence=this.state.sequence,t.x=this.state.position.x,t.y=this.state.position.y,t.z=this.state.position.z,t.velocityX=this.state.velocity.x,t.velocityY=this.state.velocity.y,t.velocityZ=this.state.velocity.z,t.yaw=Ht.setFromQuaternion(this.actor.object.quaternion,"YXZ").y,t.mode=this.state.mode,t.flags=(this.isCrouching?_:0)|(this.crouchSuppressedUntilRelease?K:0),t.horizontalSpeed=this.state.currentSpeed,t}syncPublicState(){this.velocity.copy(this.state.velocity),this.mode=this.state.mode,this.horizontalSpeed=this.state.currentSpeed,this.isSliding=this.state.mode===A.sliding,this.isSliding?(this.resolveGroundNormal(this.slideSurfaceNormal),this.slideDirection.copy(this.state.velocity).projectOnPlane(this.slideSurfaceNormal),this.slideDirection.lengthSq()>1e-8?this.slideDirection.normalize():this.slideDirection.set(0,0,0)):(this.slideDirection.set(0,0,0),this.slideSurfaceNormal.copy(Tt))}sampleRootMotion(t){if(t.set(0,0,0),null==this.rootMotionAction||this.rootMotionAction.isRunning()||this.clearRootMotionAction(this.rootMotionAction),null!=this.rootMotionAction&&this.rootMotionOptions.cancelWithJump&&this.jumpInput.activated&&(this.isGrounded||this.jumpInAir)){const e=this.rootMotionAction,i=this.rootMotionOptions.onJumpCancel;return this.clearRootMotionAction(e),e.stop(),i?.(),t}if(null==this.rootMotionAction)return t;if(!(this.rootMotionAction.getClip()instanceof l))return t;const e=this.rootMotionInterpolant;this.resetRootMotion&&(this.prevRootMotionPos.fromArray(e.evaluate(0)),this.resetRootMotion=!1),It.fromArray(e.evaluate(this.rootMotionAction.time)),t.subVectors(It,this.prevRootMotionPos),this.prevRootMotionPos.copy(It);if((this.rootMotionRootBone??this.rootMotionAction.getRoot()).getWorldScale(Pt),t.multiply(Pt),this.rootMotionTargetConstraints.size>0){zt.copy(t).applyQuaternion(this.actor.quaternion);for(const t of this.rootMotionTargetConstraints)if(t.requestedProgress>0&&t.addedHorizontalDistance<t.maximumAddedHorizontalDistance){const e=r.lerp(t.initialHorizontalDistance,t.minimumHorizontalDistance,t.requestedProgress),i=Math.min(D(zt,this.actor.position,t.targetPosition,e),t.maximumAddedHorizontalDistance-t.addedHorizontalDistance);t.addedHorizontalDistance+=b(zt,this.actor.position,t.targetPosition,t.minimumHorizontalDistance,i)}else q(zt,this.actor.position,t.targetPosition,t.minimumHorizontalDistance);t.copy(zt).applyQuaternion(Vt.copy(this.actor.quaternion).invert())}return t}clearRootMotionAction(t){null!=t&&this.rootMotionAction!==t||(this.rootMotionAction=null,this.rootMotionOptions={},this.resetRootMotion=!1)}isRemoteControlledAuthority(t=this.netService.mode,e=this.actor.netRole){if(t===vt.none||e!==p.authority||t>=vt.client)return!1;return null!=this.netService.resolveActorConnection(this.actor)&&!this.netService.isLocalOwner(this.actor)}configureCharacterController(){const t=this.cc;t.setApplyImpulsesToDynamicBodies(this.applyImpulsesToDynamicBodies),t.setMinSlopeSlideAngle(this.minSlopeSlideAngle),t.setMaxSlopeClimbAngle(this.maxSlopeClimbAngle),t.setCharacterMass(this.mass),t.setSlideEnabled(this.allowSliding)}initializeStateFromActor(){this.state.position.copy(this.actor.position),this.state.velocity.set(0,0,0),this.state.yaw=this.actor.rotation.y,this.state.lookYaw=this.rotationInput.rotation.y,this.state.mode=this.mode,this.state.currentSpeed=this.horizontalSpeed,this.state.prevRotateToMovementDirection=this.rotateToMovementDirection}createCollisionShape(){const t=this.getColliderHeight(!1),e=this.getColliderRadius(!1),i=new x(t,e);return i.offset.y=this.getCapsuleOffsetY(t,e),i.collisionGroup=xt,i}updateCrouchState(t,e,i,o){if(!(0!==(t.flags&B)))return this.crouchSuppressedUntilRelease=!1,this.slideOnLandingRequested=!1,this.state.mode===A.sliding&&(this.state.mode=A.walking),void this.tryUncrouch();if(this.state.mode===A.sliding&&(!this.slideEnabled||i))return this.slideOnLandingRequested=!1,this.state.mode=A.walking,void(this.crouchSuppressedUntilRelease||this.setCrouching(!0));if(this.state.mode===A.sliding&&o)return this.crouchSuppressedUntilRelease=!0,this.slideOnLandingRequested=!1,void this.tryUncrouch();if(this.crouchSuppressedUntilRelease)return void(this.slideOnLandingRequested=!1);if(this.setCrouching(!0),!this.slideEnabled||i)return void(this.slideOnLandingRequested=!1);if(this.state.mode===A.falling)return void(this.slideOnLandingRequested=!0);this.resolveGroundNormal(Ut);const s=this.slideOnLandingRequested&&this.state.mode===A.walking&&this.state.grounded,n=e&&0!==(t.flags&$)||s;s&&(this.slideOnLandingRequested=!1);const r=Qt(this.state.velocity);this.state.mode===A.walking&&St(this.slideEnabled,n,this.state.grounded,this.isWalkableSlideSurface(Ut),i,r,this.slideMinStartSpeed)&&(this.state.mode=A.sliding,this.slideSurfaceNormal.copy(Ut),this.state.velocity.projectOnPlane(this.slideSurfaceNormal),this.state.currentSpeed=Qt(this.state.velocity))}updateSlidingMode(t){const e=t.state,i=t.move;this.resolveGroundNormal(this.slideSurfaceNormal);const o=this.isWalkableSlideSurface(this.slideSurfaceNormal),s=e.velocity.length();if(!e.grounded||!o)return e.mode=A.falling,$t.update(t),A.falling;if(this.slideEnabled&&0!==(i.flags&B)&&!t.rootMotionActive&&0!==(i.flags&Z))return yt(t.outVelocity,e.velocity,this.jumpVelocity),e.velocity.copy(t.outVelocity),e.currentSpeed=Qt(e.velocity),A.falling;if(!gt(this.slideEnabled,0!==(i.flags&B),e.grounded,o,t.rootMotionActive,s,this.slideMinExitSpeed))return e.mode=A.walking,Wt.update(t),A.walking;const n=Mt(e.velocity,e.velocity,this.slideSurfaceNormal,t.rotatedDirection,this.getEffectiveGravity(),t.deltaTime,this.slideDeceleration,this.slideGravityScale,this.slideSteeringRate);if(e.currentSpeed=Qt(e.velocity),n<Math.max(0,this.slideMinExitSpeed))return e.mode=A.walking,Wt.update(t),A.walking;t.outVelocity.copy(e.velocity).add(t.platformVelocity)}tryUncrouch(){this.isCrouching&&this.canUncrouch()&&this.setCrouching(!1)&&(this.suppressUncrouchLift=!0,this.state.fallGraceTime=0)}resolveGroundNormal(t){return!this.rayTestResult.hasHit||this.rayTestResult.hitNormal.lengthSq()<=1e-8?t.copy(Tt):(t.copy(this.rayTestResult.hitNormal).normalize(),t.dot(Tt)<0&&t.multiplyScalar(-1),t)}isWalkableSlideSurface(t){return t.dot(Tt)>=Math.cos(this.cc.maxSlopeClimbAngle())}setCrouching(t){return this.isCrouching!==t&&(this.isCrouching=t,this.syncColliderShape(),!0)}canUncrouch(){const t=this.getColliderHeight(!1),e=this.getColliderRadius(!1);return!this.physicsSystem.hasActorCapsuleIntersection(this.actor,this.state.position,t,e,this.getCapsuleOffsetY(t,e),this.getCollisionGroup())}syncColliderShape(){const t=this.getColliderHeight(this.isCrouching),e=this.getColliderRadius(this.isCrouching);this.physicsSystem.setActorCapsuleCollider(this.actor,t,e,this.getCapsuleOffsetY(t,e))}getColliderHeight(t){const e=Number.isFinite(this.colliderHeight)?Math.max(0,this.colliderHeight):0;if(!t)return e;const i=Number.isFinite(this.crouchColliderHeight)?this.crouchColliderHeight:e;return r.clamp(i,0,e)}getColliderRadius(t){const e=Number.isFinite(this.colliderRadius)?Math.max(.001,this.colliderRadius):.001;if(!t)return e;const i=this.crouchColliderRadius??e,o=Number.isFinite(i)?i:e;return r.clamp(o,.001,e)}getCapsuleOffsetY(t,e){return e+t/2+this.offset}checkGrounded(t){Nt.y=-Math.max(.05,this.cc.snapToGroundDistance()),this.physicsSystem.rayTest(Ot.addVectors(t,Yt.set(0,this.offset,0)),jt.addVectors(t,Nt),this.rayTestResult,this.groundRayTestOptions)}resolvePlatformVelocity(t){return t.set(0,0,0),this.rayTestResult.hasHit&&null!=this.rayTestResult.actor&&this.physicsSystem.getLinearVelocity(this.rayTestResult.actor,t),t}getCollisionGroup(){return this.characterCollision?null:xt}};t([T(),e("design:type",Number)],Zt.prototype,"colliderHeight",void 0),t([T(),e("design:type",Number)],Zt.prototype,"colliderRadius",void 0),t([T(),e("design:type",Number)],Zt.prototype,"crouchColliderHeight",void 0),t([T({optional:!0}),e("design:type",Number)],Zt.prototype,"crouchColliderRadius",void 0),t([g(!1),e("design:type",Function),e("design:paramtypes",[Uint8Array]),e("design:returntype",void 0)],Zt.prototype,"serverMove",null),t([v(!1),e("design:type",Function),e("design:paramtypes",[Uint8Array]),e("design:returntype",void 0)],Zt.prototype,"clientMoveAck",null),t([v(!0),e("design:type",Function),e("design:paramtypes",[Uint8Array]),e("design:returntype",void 0)],Zt.prototype,"clientMoveCorrection",null),t([y(!1),e("design:type",Function),e("design:paramtypes",[Uint8Array]),e("design:returntype",void 0)],Zt.prototype,"simulatedState",null),Zt=t([R({inEditor:!1}),e("design:paramtypes",[])],Zt);export{Zt as CharacterMovementComponent};const Wt={mode:A.walking,update(t){const e=t.component,i=t.move,o=t.state,s=t.rotatedDirection,n=Math.min(1,Math.sqrt(i.inputX*i.inputX+i.inputY*i.inputY)),r=!e.rotateToMovementDirection&&i.inputY<0,a=e.isCrouching,h=!t.rootMotionActive&&!a&&0===(i.flags&B)&&0!==(i.flags&Q)&&!r&&0!==s.lengthSq()&&(e.sprintPolicy?.canSprint()??!0),l=(a?e.maxSpeedCrouch:r?e.maxSpeedBackwards:h?e.maxSpeedSprint:e.maxSpeed)*(e.normalizedDirection?1:n);if(0!==s.lengthSq()){e.isSprinting=h,h&&e.sprintPolicy?.commitSprint(t.deltaTime,i.sequence);let a=Math.min(l,o.currentSpeed),c=e.groundAccelerationRate;if(h&&t.startedSprinting&&e.sprintStartBoostSpeed>0){const t=e.normalizedDirection?1:n;a=Math.max(a,l+e.sprintStartBoostSpeed*t),c=e.sprintStartBoostDamping}else h&&!r&&e.sprintStartBoostSpeed>0&&o.currentSpeed>l&&(a=o.currentSpeed,c=e.sprintStartBoostDamping);o.currentSpeed=function(t,e,i,o){return e+(t-e)*Math.exp(-i*o)}(a,l,c,t.deltaTime),t.outVelocity.copy(s).multiplyScalar(function(t,e,i,o){const s=i*o;if(s<=1e-6)return t;return e+(t-e)*(1-Math.exp(-s))/s}(a,l,c,t.deltaTime))}else o.currentSpeed=0,t.outVelocity.set(0,0,0);if(0!==(i.flags&Z))return o.mode=A.falling,o.velocity.copy(t.outVelocity),o.velocity.y=e.jumpVelocity,A.falling;t.outVelocity.y=t.deltaTime*e.getEffectiveGravity(),t.outVelocity.add(t.platformVelocity)}},$t={mode:A.falling,update(t){const e=t.component,i=t.state,o=t.move;0!==(o.flags&Z)&&e.jumpInAir&&(i.velocity.copy(t.outVelocity),i.velocity.y=e.jumpVelocity),i.velocity.y+=t.deltaTime*e.getEffectiveGravity(),t.outVelocity.copy(i.velocity),t.outVelocity.addScaledVector(t.rotatedDirection,e.fallingMovementControl),e.fallingReorientation&&t.outVelocity.applyAxisAngle(Tt,r.euclideanModulo(o.yaw-i.lookYaw+Math.PI,2*Math.PI)-Math.PI)}};function Qt(t){return Math.sqrt(t.x*t.x+t.z*t.z)}function Jt(t,e){return e.sequence=t.sequence,e.clientTime=t.clientTime,e.dt=t.dt,e.inputX=t.inputX,e.inputY=t.inputY,e.yaw=t.yaw,e.flags=t.flags,e.clientX=t.clientX,e.clientY=t.clientY,e.clientZ=t.clientZ,e.rootMotionX=t.rootMotionX,e.rootMotionY=t.rootMotionY,e.rootMotionZ=t.rootMotionZ,e}function Kt(t,e){const i=t.position.x-e.clientX,o=t.position.y-e.clientY,s=t.position.z-e.clientZ;return i*i+o*o+s*s}class _t{constructor(t){this.scene=t,this.serverPosition=new h,this.direction=new h}update(t,e){const i=this.serverPosition.set(e.x,e.y,e.z),o=i.distanceTo(t);o>.1&&console.log(`Correction applied. Error: ${o.toFixed(3)}. Server position: (${i.x.toFixed(2)}, ${i.y.toFixed(2)}, ${i.z.toFixed(2)}), Client position: (${t.x.toFixed(2)}, ${t.y.toFixed(2)}, ${t.z.toFixed(2)})`);const s=this.direction.copy(i).sub(t).normalize();te.position.copy(t),te.setDirection(s),te.setLength(o);const n=ee(this.scene);n.add(te),setTimeout(()=>{n.remove(te)},1e3)}}const te=new n(new h(0,1,0),new h,1,16711680);function ee(t){return null==t.parent?t:ee(t.parent)}const ie={immediate:!1,savedRootMotion:!0};/*
1
+ import{__decorate as t,__metadata as e}from"tslib";import i from"@dimforge/rapier3d-simd-compat";import{takeUntil as o}from"rxjs";import*as s from"three";import{ArrowHelper as n,MathUtils as r,Quaternion as a,Vector3 as h}from"three";import{RootMotionClip as l}from"../../../../animation/root-motion.js";import{inject as c}from"../../../../inject.js";import{ActionInput as m,AxisInput as d,RotationInput as u}from"../../../../input/index.js";import{NetRole as p}from"../../../../net/service/net-actor-role.js";import{RunOnClient as g,RunOnNotOwner as y,RunOnServer as v}from"../../../../net/service/rpc-decorator.js";import{NetService as S}from"../../../../net/service/net-service.js";import{PhysicsSystem as M,RayTestResult as f}from"../../../../services/physics/physics-system.js";import{CapsuleCollisionShape as w}from"../../../../../scene/collision/collision-shape.js";import{Parameter as x}from"../../../../../shader/parameter.js";import{PhysicsBodyType as T}from"../../../../services/physics/physics-system.js";import{ActorComponent as C,Component as R}from"../../../component.js";import{CharacterMovementMode as A}from"./modes.js";import{calculateRootMotionTargetApproachCorrection as b,constrainRootMotionTargetApproach as D,warpRootMotionTargetApproach as q}from"./root-motion-constraint.js";import{DEFAULT_MAX_CLIENT_TIME_AHEAD as P,DEFAULT_LARGE_CORRECTION_THRESHOLD as z,DEFAULT_MAX_COMBINED_MOVE_DELTA_TIME as k,DEFAULT_MAX_MOVE_DELTA_TIME as I,DEFAULT_MAX_MOVES_PER_PACKET as j,DEFAULT_MAX_REPLAYED_MOVES as O,DEFAULT_MAX_SERVER_MOVES_PER_TICK as G,DEFAULT_MAX_SAVED_MOVES as V,DEFAULT_MAX_SERVER_MOVE_DELTA_TIME_SCALAR as H,DEFAULT_MAX_SERVER_MOVE_TIME_BUDGET as Y,DEFAULT_MAX_SUBSTEP_DELTA_TIME as N,DEFAULT_MOVE_SEND_INTERVAL as F,DEFAULT_SIMULATED_INTERPOLATION_DELAY as E,DEFAULT_SIMULATED_STATE_INTERVAL as U,DEFAULT_SMALL_CORRECTION_TOLERANCE as X,DEFAULT_TELEPORT_SNAP_THRESHOLD as L,MOVE_FLAG_CROUCH as B,MOVE_FLAG_JUMP as Z,MOVE_FLAG_ROOT_MOTION as W,MOVE_FLAG_SLIDE_START as $,MOVE_FLAG_SPRINT as Q,MOVE_FLAG_SPRINT_START as J,SNAPSHOT_FLAG_CROUCH_SUPPRESSED as K,SNAPSHOT_FLAG_CROUCHING as _,NetCharacterProxySmoother as tt,NetCharacterSavedMoveBuffer as et,accrueNetCharacterServerMoveTime as it,createNetCharacterMovementSnapshot as ot,createNetCharacterServerMoveTimingState as st,consumeNetCharacterServerMoveTime as nt,decodeNetCharacterMoveBatch as rt,decodeNetCharacterOwnerAck as at,decodeNetCharacterOwnerCorrection as ht,decodeNetCharacterSimulatedState as lt,encodeNetCharacterMoveBatch as ct,encodeNetCharacterOwnerAck as mt,encodeNetCharacterOwnerCorrection as dt,encodeNetCharacterSimulatedState as ut,validateNetCharacterMove as pt}from"./net-character-movement-protocol.js";import{NetMode as gt}from"../../../../net/net-session.js";import{World as yt}from"../../../../services/world.js";import{WaterVolume as vt}from"../../water-volume-actor.js";import{WaterSplineVolume as St}from"../../water-spline-volume-actor.js";import{setSlideJumpVelocity as Mt,shouldContinueSlide as ft,shouldStartSlide as wt,updateSlideVelocity as xt,updateSlideVelocityFromDisplacement as Tt}from"./character-slide.js";export*from"./net-character-movement-protocol.js";const Ct=131070,Rt=new h(0,1,0),At=new h,bt=new h,Dt=new h,qt=new h,Pt=new h,zt=new h,kt=new h,It=new h,jt=new h,Ot=new h,Gt=new h,Vt=new h,Ht=new h,Yt=new h,Nt=new h(0,1,0),Ft=new h(0,-.05,0),Et=new h,Ut=new a,Xt=new s.Euler,Lt=new h,Bt=new h,Zt=new h,Wt=new h,$t=new i.CharacterCollision;let Qt=class extends C{get autoStepMinWidth(){return this.cc.autostepMinWidth()}set autoStepMinWidth(t){this.cc.enableAutostep(this.cc.autostepMaxHeight(),t,this.cc.autostepIncludesDynamicBodies())}get autoStepDynamicObjects(){return this.cc.autostepIncludesDynamicBodies()}set autoStepDynamicObjects(t){this.cc.enableAutostep(this.cc.autostepMaxHeight(),this.cc.autostepMinWidth(),t)}get autoStepMaxHeight(){return this.cc.autostepMaxHeight()}set autoStepMaxHeight(t){this.cc.enableAutostep(t,this.cc.autostepMinWidth(),this.cc.autostepIncludesDynamicBodies())}get snapToGround(){return this.cc.snapToGroundDistance()}set snapToGround(t){this.cc.enableSnapToGround(t)}set offset(t){this.cc.setOffset(t)}get offset(){return this.cc.offset()}set normalNudgeFactor(t){this.cc.setNormalNudgeFactor(t)}get normalNudgeFactor(){return this.cc.normalNudgeFactor()}teleport(t,e=this.actor.rotation.y){this.state.position.copy(t),this.state.velocity.set(0,0,0),this.state.yaw=e,this.actor.position.copy(t),this.actor.rotation.y=e,this.rotationInput.rotation.y=e,this.physicsSystem.setPosition(this.actor,t),this.physicsSystem.setRotation(this.actor,this.actor.quaternion),this.physicsSystem.flushModifiedBodyPositionsToColliders()}constructor(){super(),this.isDefaultCharacterMovementComponent=!0,this.directionInput=new d,this.jumpInput=new m,this.sprintInput=new m,this.crouchInput=new m,this.rotationInput=new u,this.horizontalSpeed=0,this.maxSpeed=8,this.maxSpeedBackwards=8,this.maxSpeedSprint=12,this.maxSpeedCrouch=4,this.swimmingEnabled=!0,this.maxSpeedSwimming=3,this.swimmingImmersion=.7,this.swimmingSurfaceResponse=6,this.swimmingMaxVerticalSpeed=4,this.swimmingDepthHysteresis=.1,this.slideEnabled=!1,this.slideMinStartSpeed=8,this.slideMinExitSpeed=4,this.slideDeceleration=3,this.slideGravityScale=1,this.slideSteeringRate=2,this.sprintStartBoostSpeed=0,this.sprintStartBoostDamping=6,this.jumpVelocity=7,this.fallingMovementControl=.5,this.fallingReorientation=!1,this.groundAccelerationRate=4,this.gravityOverride=null,this.colliderHeight=2,this.colliderRadius=.5,this.crouchColliderHeight=1,this.crouchColliderRadius=null,this.jumpInAir=!1,this.mass=50,this.allowSliding=!0,this.minSlopeSlideAngle=r.degToRad(70),this.maxSlopeClimbAngle=r.degToRad(70),this.applyImpulsesToDynamicBodies=!0,this.normalizedDirection=!0,this.characterCollision=!1,this.allowRootMotionJumpCancel=!1,this.enabled=!0,this.movementInputEnabled=!0,this.rotateToMovementDirection=!1,this.smoothRotation=!0,this.rotationSpeed=40,this.maxRotationSpeed=100,this.impulseDamping=2,this.moveSendInterval=F,this.simulatedStateInterval=U,this.maxSavedMoves=V,this.maxReplayedMoves=O,this.maxServerMovesPerTick=G,this.maxMovesPerPacket=j,this.maxMoveDeltaTime=I,this.maxCombinedMoveDeltaTime=k,this.maxServerMoveDeltaTimeScalar=H,this.maxClientTimeAhead=P,this.maxServerMoveTimeBudget=Y,this.maxSubstepDeltaTime=N,this.fallGraceTime=.1,this.correctionToleranceSq=X*X,this.largeCorrectionThreshold=z,this.teleportSnapThreshold=L,this.listenServerSmoothing=!0,this.listenServerSmoothLocationTime=.04,this.listenServerMaxSmoothUpdateDistance=1,this.listenServerNoSmoothUpdateDistance=2.5,this.debugCorrections=!0,this.suppressUncrouchLift=!1,this.velocity=new h,this.visualSmoothingOffset=new h,this.slideDirection=new h,this.slideSurfaceNormal=new h(0,1,0),this.mode=A.walking,this.isSprinting=!1,this.isCrouching=!1,this.isSliding=!1,this.pressedJump=!1,this.rayTestResult=new f,this.groundRayTestOptions={debug:!1,excludeTriggers:!0,excludeActor:void 0,resolveActor:!1},this.physicsSystem=c(M),this.netService=c(S),this.world=c(yt),this.waterVolumes=[],this.waterProbe=new h,this.swimmingSurfaceHeight=0,this.state={sequence:0,position:new h,velocity:new h,yaw:0,lookYaw:0,mode:A.walking,grounded:!1,currentSpeed:0,fallGraceTime:0,prevInputDirection:new h,prevRotateToMovementDirection:!1},this.movementModes=new Map,this.savedMoves=new et(V),this.serverMoveTiming=st(),this.serverMoveQueue=[],this.inputMoveScratch={sequence:0,clientTime:0,dt:0,inputX:0,inputY:0,yaw:0,flags:0,clientX:0,clientY:0,clientZ:0,rootMotionX:0,rootMotionY:0,rootMotionZ:0},this.authoritativeMoveScratch={sequence:0,clientTime:0,dt:0,inputX:0,inputY:0,yaw:0,flags:0,clientX:0,clientY:0,clientZ:0,rootMotionX:0,rootMotionY:0,rootMotionZ:0},this.movementModeContext={component:this,state:this.state,move:this.inputMoveScratch,deltaTime:0,rotatedDirection:bt,platformVelocity:qt,outVelocity:Dt,rootMotionActive:!1,startedSprinting:!1},this.proxySmoother=new tt(E,L),this.proxySample=ot(),this.pendingSnapshot=ot(),this.impulse=new h,this.prevRootMotionPos=new h,this.rootMotionOptions={},this.rootMotionTargetConstraints=new Set,this.resetRootMotion=!1,this.nextMoveSequence=0,this.clientMoveTime=0,this.lastSentClientMoveTime=0,this.moveSendAccumulator=0,this.simulatedStateAccumulator=0,this.proxyTime=0,this.lastServerProcessedSequence=0,this.lastServerReceivedSequence=0,this.lastAutonomousMoveFlags=0,this.previousSprintInput=!1,this.previousCrouchInput=!1,this.crouchSuppressedUntilRelease=!1,this.slideOnLandingRequested=!1,this.initialized=!1,this.cc=this.physicsSystem.getCharacterController(.1),this.cc.enableSnapToGround(.1),this.cc.enableAutostep(0,.1,!1),this.registerMovementMode(Jt),this.registerMovementMode(Kt),this.registerMovementMode({mode:A.swimming,update:t=>this.updateSwimmingMode(t)}),this.registerMovementMode({mode:A.sliding,update:t=>this.updateSlidingMode(t)})}onInit(){for(const t of this.world.actors)(t instanceof vt||t instanceof St)&&this.waterVolumes.push(t);this.world.actorAdded.pipe(o(this.disposed)).subscribe(t=>{(t instanceof vt||t instanceof St)&&this.waterVolumes.push(t)}),this.world.actorRemoved.pipe(o(this.disposed)).subscribe(t=>{const e=this.waterVolumes.indexOf(t);e>=0&&this.waterVolumes.splice(e,1)}),this.groundRayTestOptions.excludeActor=this.actor,this.configureCharacterController(),this.physicsSystem.addActor(this.actor,[this.createCollisionShape()],{mass:0,type:T.kinematic,continousCollisionDetection:!1,friction:0,restitution:.5,ignoreForNavMesh:!0}),this.rotationInput.rotation.copy(this.actor.rotation),this.initializeStateFromActor(),this.initialized=!0,this.physicsSystem.beforeStep.pipe(o(this.disposed)).subscribe(t=>this.tick(t))}onLateUpdate(t){this.updateVisualSmoothing(t)}registerMovementMode(t){this.movementModes.set(t.mode,t)}applyImpulse(t){this.impulse.add(t)}getEffectiveGravity(){return this.gravityOverride??this.physicsSystem.getGravity().y}get swimmingWaterSurfaceHeight(){return this.state.mode===A.swimming?this.swimmingSurfaceHeight:null}get waterContactSurfaceHeight(){if(this.state.mode===A.swimming)return this.swimmingSurfaceHeight;this.waterProbe.copy(this.state.position),this.waterProbe.y+=.01;const t=this.state.position.y+this.getColliderHeight(this.isCrouching)+2*this.getColliderRadius(this.isCrouching);let e=null;for(const i of this.waterVolumes){const o=i.getWaterSurfaceHeight(this.waterProbe);null!=o&&o>=this.waterProbe.y&&o<=t&&(null==e||o>e)&&(e=o)}return e}get isGrounded(){return this.state.mode!==A.swimming&&(this.rayTestResult.hasHit||this.cc.computedGrounded())}setRootMotionAction(t,e={}){const i=t?.getClip();if(i instanceof l){this.rootMotionAction=t,this.rootMotionOptions=e,this.resetRootMotion=!0;const o=[];this.rootMotionInterpolant=i.motionTrack.InterpolantFactoryMethodSmooth(o);const n=s.PropertyBinding.parseTrackName(i.motionTrack.name);this.rootMotionRootBone=this.actor.object.getObjectByName(n.nodeName)}}addRootMotionTargetConstraint(t,e,i=0){const o={targetPosition:t,minimumHorizontalDistance:Math.max(0,e),maximumAddedHorizontalDistance:Math.max(0,i),initialHorizontalDistance:Math.hypot(t.x-this.actor.position.x,t.z-this.actor.position.z),addedHorizontalDistance:0,requestedProgress:0};this.rootMotionTargetConstraints.add(o);let s=!1;return{setProgress:t=>{o.requestedProgress=Math.max(o.requestedProgress,Math.min(1,Math.max(0,t)))},dispose:()=>{s||(s=!0,this.rootMotionTargetConstraints.delete(o))}}}serverMove(t){const e=rt(t);if(e.ok)for(const t of e.value.moves)pt(t,this.lastServerReceivedSequence,this.maxMoveDeltaTime)&&(this.lastServerReceivedSequence=t.sequence,this.serverMoveQueue.push(t))}clientMoveAck(t){const e=at(t);e.ok&&this.actor.netRole===p.autonomousProxy&&(this.savedMoves.ack(e.value.sequence),this.sprintPolicy?.ack?.(e.value.sequence,!1))}clientMoveCorrection(t){const e=ht(t);e.ok&&this.actor.netRole===p.autonomousProxy&&(this.debugCorrections&&(null==this.correctionDebug&&(this.correctionDebug=new se(re(this.actor.object))),this.correctionDebug.update(this.state.position,e.value.snapshot)),this.applyCorrection(e.value.snapshot))}simulatedState(t){const e=lt(t);e.ok&&this.actor.netRole===p.simulatedProxy&&this.proxySmoother.push(e.value,this.proxyTime)}tick(t){if(!this.initialized)return;t=Math.min(.1,t);const e=this.actor.netRole,i=this.netService.mode;e!==p.simulatedProxy?this.enabled&&(e!==p.autonomousProxy?this.isRemoteControlledAuthority(i,e)?this.tickRemoteAuthority(t):this.tickAuthority(t,i):this.tickAutonomousProxy(t)):this.tickSimulatedProxy(t)}tickAutonomousProxy(t){const e=this.state.mode,i=this.lastAutonomousMoveFlags,o=this.createMoveFromInput(t,++this.nextMoveSequence,{quantizeClientTime:!0});this.performMove(o,ae),this.resetToggleCrouchAfterSlide(e);const s=this.state.mode!==e||o.flags!==i;this.lastAutonomousMoveFlags=o.flags,this.savedMoves.capacity=this.maxSavedMoves,this.savedMoves.maxCombinedDeltaTime=Math.min(this.maxCombinedMoveDeltaTime,this.maxMoveDeltaTime),this.savedMoves.push(o),this.sendSavedMoves(t,s)}tickAuthority(t,e){const i=this.state.mode,o=this.createMoveFromInput(t,++this.nextMoveSequence);this.performMove(o,ae),this.resetToggleCrouchAfterSlide(i),e!==gt.none&&this.sendSimulatedState(t,!1)}resetToggleCrouchAfterSlide(t){t===A.sliding&&this.state.mode!==A.sliding&&"toggle"===this.crouchInput.mode&&this.crouchInput.activated&&this.crouchInput.setActivated(!1)}tickRemoteAuthority(t){it(this.serverMoveTiming,t,this.maxServerMoveTimeBudget);let e=!1;const i=Number.isFinite(this.maxServerMovesPerTick)?Math.max(1,Math.floor(this.maxServerMovesPerTick)):this.serverMoveQueue.length,o=Math.min(this.serverMoveQueue.length,i),s=Zt.copy(this.actor.position);let n=!1;for(let t=0;t<o;t++){const t=this.serverMoveQueue.shift();if(null==t)break;if(!pt(t,this.lastServerProcessedSequence,this.maxMoveDeltaTime)){console.log("Net: Invalid move",t),this.sendOwnerCorrection(!0),e=!0;continue}const i=nt(this.serverMoveTiming,t,{maxMoveDeltaTime:this.maxMoveDeltaTime,maxServerMoveDeltaTimeScalar:this.maxServerMoveDeltaTimeScalar,maxClientTimeAhead:this.maxClientTimeAhead});if(i<0){this.sendOwnerCorrection(!0),e=!0;continue}const o=ie(t,this.authoritativeMoveScratch);o.dt=i,o.rootMotionX=0,o.rootMotionY=0,o.rootMotionZ=0,o.flags&=~W,this.performMove(o,{immediate:!0,savedRootMotion:!1}),n=!0,this.lastServerProcessedSequence=o.sequence;const s=oe(this.state,t);if(s>this.correctionToleranceSq){console.log(`Net server: Correction error: ${Math.sqrt(s)}`);const o=this.state.position.x-t.clientX,n=this.state.position.y-t.clientY,r=this.state.position.z-t.clientZ;console.log(`diff x: ${o}, y: ${n}, z: ${r}`),console.log({sequence:t.sequence,moveDt:t.dt,serverMoveDeltaTime:i,flags:t.flags,mode:this.state.mode,grounded:this.state.grounded,fallGraceTime:this.state.fallGraceTime}),this.sendOwnerCorrection(s>this.largeCorrectionThreshold*this.largeCorrectionThreshold),e=!0}}0===this.lastServerProcessedSequence||e||(this.sprintPolicy?.ack?.(this.lastServerProcessedSequence,!1),this.clientMoveAck(mt(this.lastServerProcessedSequence))),n&&this.accumulateListenServerVisualSmoothing(s,this.actor.position),this.sendSimulatedState(t,!1)}tickSimulatedProxy(t){this.proxyTime+=t,this.proxySmoother.sample(this.proxyTime,this.proxySample)&&this.applySnapshot(this.proxySample,!0)}accumulateListenServerVisualSmoothing(t,e){if(!this.shouldSmoothListenServerRemoteAuthority())return void this.visualSmoothingOffset.set(0,0,0);Wt.subVectors(t,e);const i=Wt.lengthSq();i>1e-8&&(i>this.listenServerNoSmoothUpdateDistance*this.listenServerNoSmoothUpdateDistance?this.visualSmoothingOffset.set(0,0,0):(i>this.listenServerMaxSmoothUpdateDistance*this.listenServerMaxSmoothUpdateDistance&&Wt.setLength(this.listenServerMaxSmoothUpdateDistance),this.visualSmoothingOffset.add(Wt)))}updateVisualSmoothing(t){if(this.visualSmoothingOffset.lengthSq()<=1e-8)return void this.visualSmoothingOffset.set(0,0,0);if(!this.shouldSmoothListenServerRemoteAuthority())return void this.visualSmoothingOffset.set(0,0,0);const e=Math.max(.001,this.listenServerSmoothLocationTime);t<e?this.visualSmoothingOffset.multiplyScalar(1-t/e):this.visualSmoothingOffset.set(0,0,0),this.visualSmoothingOffset.lengthSq()<=1e-4&&this.visualSmoothingOffset.set(0,0,0)}shouldSmoothListenServerRemoteAuthority(){return this.listenServerSmoothing&&this.actor.netRole===p.authority&&this.netService.isServer&&!this.netService.isDedicatedServer&&this.isRemoteControlledAuthority()}createMoveFromInput(t,e,i={}){const o=r.clamp(t,.001,this.maxMoveDeltaTime);this.clientMoveTime+=o;let s=this.clientMoveTime,n=o;!0===i.quantizeClientTime&&(s=Math.max(this.lastSentClientMoveTime+.001,Math.round(1e3*this.clientMoveTime)/1e3),n=r.clamp(s-this.lastSentClientMoveTime,.001,this.maxMoveDeltaTime),this.lastSentClientMoveTime=s),this.sampleRootMotion(kt);const a=this.crouchInput.activated,h=a&&!this.previousCrouchInput;this.previousCrouchInput=a;const l=this.movementInputEnabled&&!a&&this.sprintInput.activated,c=l&&!this.previousSprintInput;this.previousSprintInput=l;const m=(this.movementInputEnabled&&this.jumpInput.activated?Z:0)|(l?Q:0)|(a?B:0)|(this.movementInputEnabled&&h&&this.slideEnabled?$:0)|(c?J:0)|(kt.lengthSq()>0?W:0),d=function(t,e){e.set(t.x,0,t.y),e.lengthSq()>1&&e.normalize();return e}(this.directionInput.vector,Lt);this.movementInputEnabled||d.set(0,0,0);const u=this.inputMoveScratch;return u.sequence=e>>>0,u.clientTime=s,u.dt=n,u.inputX=d.x,u.inputY=d.z,u.yaw=this.rotationInput.rotation.y,u.flags=m,u.clientX=this.state.position.x,u.clientY=this.state.position.y,u.clientZ=this.state.position.z,u.rootMotionX=kt.x,u.rootMotionY=kt.y,u.rootMotionZ=kt.z,u}performMove(t,e){const i=r.clamp(t.dt,.001,this.maxMoveDeltaTime),o=Math.max(1,Math.ceil(i/this.maxSubstepDeltaTime)),s=0!==(t.flags&Q)&&0===(t.flags&B);this.sprintPolicy?.update?.(i,t.sequence,s),Vt.set(e.savedRootMotion?t.rootMotionX:0,e.savedRootMotion?t.rootMotionY:0,e.savedRootMotion?t.rootMotionZ:0),e.savedRootMotion||this.sampleRootMotion(Vt);let n=i;const a=i/o;for(let s=0;s<o;s++){const o=i>0?a/i:1;this.performSubstep(t,Math.min(a,n),Vt,o,e.immediate,0===s),n-=a}t.clientX=this.state.position.x,t.clientY=this.state.position.y,t.clientZ=this.state.position.z,t.flags=Vt.lengthSq()>0?t.flags|W:t.flags&~W,this.state.sequence=t.sequence,this.syncPublicState()}performSubstep(t,e,i,o,s,n){if(e<.001)return;this.checkGrounded(this.state.position),this.state.grounded=this.isGrounded,this.updateWaterMovementMode();const r=null!=this.rootMotionAction&&this.rootMotionAction.enabled,a=i.lengthSq()>0,h=!r&&0!==(t.flags&Z),l=r||a;this.updateCrouchState(t,n,l,h),this.pressedJump=h,this.isSprinting=!1,this.updateRotation(t,e,r,a),this.resolvePlatformVelocity(qt);const c=this.movementModeContext,m=this.movementModes.get(this.state.mode);if(null!=m){c.move=t,c.deltaTime=e,c.rootMotionActive=l,c.startedSprinting=n&&!l&&0===(t.flags&B)&&0!==(t.flags&J);const i=m.update(c);"number"==typeof i&&(this.state.mode=i)}else Dt.set(0,0,0);if(a){It.copy(i).multiplyScalar(o).applyQuaternion(this.actor.quaternion),jt.copy(It).divideScalar(e),this.state.mode===A.walking?(Dt.x=jt.x+qt.x,Dt.z=jt.z+qt.z):(Dt.x=jt.x,Dt.z=jt.z);const t=Math.sqrt(jt.x*jt.x+jt.z*jt.z);t>.4&&(this.state.currentSpeed=t)}if(this.applyImpulseToVelocity(Dt,e),h&&this.isSprinting){const t=Math.max(0,this.maxSpeedSprint),e=_t(Dt);if(e>t){const i=t/e;Dt.x*=i,Dt.z*=i,this.state.velocity.x*=i,this.state.velocity.z*=i}}this.state.mode!==A.walking&&this.state.mode!==A.swimming||this.state.velocity.copy(Dt),this.applyMovement(Dt,e,s),this.state.mode===A.sliding&&(Tt(this.state.velocity,zt,qt,this.slideSurfaceNormal,e),this.state.currentSpeed=_t(this.state.velocity)),this.checkGrounded(this.state.position),this.state.grounded=this.isGrounded,this.updateModeAfterMove(Dt,e),this.state.mode===A.sliding&&this.state.velocity.length()<Math.max(0,this.slideMinExitSpeed)&&(this.state.mode=A.walking)}updateRotation(t,e,i,o){At.set(-t.inputX,0,t.inputY),At.lengthSq()>1&&At.normalize();const s=this.state.prevRotateToMovementDirection!==this.rotateToMovementDirection;let n=r.euclideanModulo(t.yaw-this.state.lookYaw+Math.PI,2*Math.PI)-Math.PI;if(s&&(this.actor.object.quaternion.setFromEuler(Xt.set(0,t.yaw,0)),n=0,this.state.lookYaw=t.yaw,this.state.prevRotateToMovementDirection=this.rotateToMovementDirection),bt.set(0,0,0),i)this.state.lookYaw=t.yaw;else if(this.rotateToMovementDirection){if(At.lengthSq()>0&&this.state.mode!==A.falling){const i=Xt.setFromQuaternion(this.actor.object.quaternion,"YXZ").y,o=Math.atan2(At.x,At.z),s=.99*t.yaw+o;if(this.smoothRotation){const t=r.euclideanModulo(s-i+Math.PI,2*Math.PI)-Math.PI;let o=r.clamp(t*this.rotationSpeed*e,-this.maxRotationSpeed*e,this.maxRotationSpeed*e);Math.abs(o)>Math.abs(t)&&(o=t),this.actor.object.quaternion.setFromEuler(Xt.set(0,i+o,0))}else this.actor.object.quaternion.setFromEuler(Xt.set(0,s,0));this.state.prevInputDirection.lerp(At,e*this.rotationSpeed),this.state.lookYaw+=n,bt.copy(this.actor.object.getWorldDirection(Lt).normalize())}}else o||(this.state.lookYaw=t.yaw,this.actor.object.quaternion.setFromEuler(Xt.set(0,t.yaw,0)),At.lengthSq()>0&&bt.copy(At).applyAxisAngle(Rt,t.yaw).normalize())}applyMovement(t,e,i){if(t.lengthSq()>0||!this.state.grounded)if(Pt.copy(t).multiplyScalar(e),this.state.grounded&&((o=this.state.mode)===A.walking||o===A.sliding)){if(this.state.mode===A.walking&&this.rayTestResult.distance<=this.cc.offset()&&(Pt.y=Math.max(0,qt.y*e)),zt.copy(this.physicsSystem.getActorComputedMovement(this.actor,this.cc,Pt,this.getCollisionGroup())),null!=this.cc.computedCollision(0,$t)){const t=Lt.copy($t.normal1);if(Math.acos(r.clamp(t.dot(Rt),-1,1))>this.cc.maxSlopeClimbAngle()){const t=.016*this.getEffectiveGravity()*.5;Pt.y!==t&&(Pt.y=t,zt.copy(this.physicsSystem.getActorComputedMovement(this.actor,this.cc,Pt,this.getCollisionGroup())))}}}else{const t=this.state.mode===A.swimming,e=t?this.cc.snapToGroundDistance():null;t&&this.cc.disableSnapToGround(),zt.copy(this.physicsSystem.getActorComputedMovement(this.actor,this.cc,Pt,this.getCollisionGroup())),t&&null!=e&&this.cc.enableSnapToGround(e)}else zt.set(0,0,0);var o;this.suppressUncrouchLift&&(this.suppressUncrouchLift=!1,this.state.grounded&&this.state.mode===A.walking&&Pt.y<=1e-6&&zt.y>0&&(zt.y=0)),this.state.position.add(zt),i?(this.actor.position.copy(this.state.position),this.physicsSystem.updateActorTransform(this.actor),this.physicsSystem.flushModifiedBodyPositionsToColliders()):this.physicsSystem.setNextKinematicPosition(this.actor,this.state.position)}getSwimmingDepth(){return(this.getColliderHeight(!1)+2*this.getColliderRadius(!1))*this.swimmingImmersion}updateWaterMovementMode(){const t=this.state.mode===A.swimming;if(this.state.mode===A.falling&&this.state.velocity.y>0)return;if(!t&&this.state.mode!==A.walking&&this.state.mode!==A.falling&&this.state.mode!==A.sliding)return;let e=null;if(this.swimmingEnabled){this.waterProbe.copy(this.state.position),this.waterProbe.y+=this.getSwimmingDepth()+(t?-1:1)*this.swimmingDepthHysteresis;for(const t of this.waterVolumes){const i=t.getWaterSurfaceHeight(this.waterProbe);null!=i&&(null==e||i>e)&&(e=i)}}null!=e?(this.swimmingSurfaceHeight=e,this.state.mode=A.swimming,this.state.grounded=!1,this.state.fallGraceTime=0,t||(this.state.currentSpeed=Math.min(this.state.currentSpeed,this.maxSpeedSwimming),this.state.velocity.y=0)):t&&(this.state.mode=A.falling,this.state.fallGraceTime=0)}updateSwimmingMode(t){const e=t.state,i=Math.min(1,Math.hypot(t.move.inputX,t.move.inputY)),o=t.rotatedDirection.lengthSq()>0?this.maxSpeedSwimming*(this.normalizedDirection?1:i):0,s=Math.min(e.currentSpeed,this.maxSpeedSwimming);if(e.currentSpeed=o>0?te(s,o,this.groundAccelerationRate,t.deltaTime):0,t.outVelocity.copy(t.rotatedDirection).multiplyScalar(ee(s,o,this.groundAccelerationRate,t.deltaTime)),!t.rootMotionActive&&0!==(t.move.flags&Z))return t.outVelocity.y=this.jumpVelocity,e.velocity.copy(t.outVelocity),e.mode=A.falling,e.grounded=!1,void(e.fallGraceTime=0);const n=this.swimmingSurfaceHeight-this.getSwimmingDepth()-e.position.y;t.outVelocity.y=r.clamp(n*(1-Math.exp(-this.swimmingSurfaceResponse*t.deltaTime))/t.deltaTime,-this.swimmingMaxVerticalSpeed,this.swimmingMaxVerticalSpeed)}updateModeAfterMove(t,e){if(this.state.mode===A.swimming)return;const i=function(t){if(0===t.numComputedCollisions())return!1;const e=t.computedCollision(0);Et.set(e.normal2.x,e.normal2.y,e.normal2.z);const i=Et.angleTo(Rt);Et.set(e.normal1.x,e.normal1.y,e.normal1.z);const o=Et.angleTo(Rt);if(i<100)return!1;return o>t.minSlopeSlideAngle()}(this.cc);!this.state.grounded||i?this.state.mode!==A.falling&&(this.state.fallGraceTime+=e,this.state.fallGraceTime>this.fallGraceTime+1e-6&&(this.state.mode=A.falling,this.state.velocity.copy(t))):this.state.velocity.y<=0&&(this.state.mode===A.falling&&(this.state.mode=A.walking),this.state.mode!==A.sliding&&(this.state.velocity.y=0),this.state.fallGraceTime=0)}applyImpulseToVelocity(t,e){if(this.impulse.lengthSq()<=.1)return void this.impulse.set(0,0,0);const i=Math.min(1,this.impulse.length()/5);t.x=r.lerp(t.x,this.impulse.x,i),t.z=r.lerp(t.z,this.impulse.z,i),t.y+=this.impulse.y;const o=Math.exp(-this.impulseDamping*e);this.impulse.x*=o,this.impulse.y>0?this.impulse.y+=e*this.getEffectiveGravity():this.impulse.y*=o,this.impulse.z*=o}sendSavedMoves(t,e=!1){if(this.moveSendAccumulator+=t,!e&&this.moveSendAccumulator<this.moveSendInterval)return;this.moveSendAccumulator=0;const i=this.savedMoves.getMovesForSend(this.maxMovesPerPacket);0!==i.length&&this.serverMove(ct(i))}sendOwnerCorrection(t){const e=this.toSnapshot(this.pendingSnapshot);t&&(e.horizontalSpeed=this.horizontalSpeed),this.sprintPolicy?.ack?.(e.sequence,!0),this.clientMoveCorrection(dt(e))}sendSimulatedState(t,e){this.simulatedStateAccumulator+=t,!e&&this.simulatedStateAccumulator<this.simulatedStateInterval||(this.simulatedStateAccumulator=0,this.simulatedState(ut(this.toSnapshot(this.pendingSnapshot))))}applyCorrection(t){this.sprintPolicy?.restore?.(t.sequence),this.savedMoves.ack(t.sequence),this.sprintPolicy?.ack?.(t.sequence,!0),this.applySnapshot(t,!0),this.savedMoves.replayAfter(t.sequence,t=>(this.performMove(t,{immediate:!0,savedRootMotion:!0}),null),this.maxReplayedMoves)}applySnapshot(t,e){this.state.sequence=t.sequence,this.state.position.set(t.x,t.y,t.z),this.state.velocity.set(t.velocityX,t.velocityY,t.velocityZ),this.state.yaw=t.yaw,this.state.lookYaw=t.yaw,this.state.mode=t.mode,this.state.currentSpeed=t.horizontalSpeed,this.state.fallGraceTime=0,this.actor.position.copy(this.state.position),this.actor.object.quaternion.setFromEuler(Xt.set(0,t.yaw,0)),this.crouchSuppressedUntilRelease=0!==(t.flags&K),this.setCrouching(0!==(t.flags&_)||t.mode===A.sliding),e&&(this.physicsSystem.updateActorTransform(this.actor),this.physicsSystem.flushModifiedBodyPositionsToColliders()),this.checkGrounded(this.state.position),this.state.grounded=this.isGrounded,this.syncPublicState()}toSnapshot(t){return t.sequence=this.state.sequence,t.x=this.state.position.x,t.y=this.state.position.y,t.z=this.state.position.z,t.velocityX=this.state.velocity.x,t.velocityY=this.state.velocity.y,t.velocityZ=this.state.velocity.z,t.yaw=Xt.setFromQuaternion(this.actor.object.quaternion,"YXZ").y,t.mode=this.state.mode,t.flags=(this.isCrouching?_:0)|(this.crouchSuppressedUntilRelease?K:0),t.horizontalSpeed=this.state.currentSpeed,t}syncPublicState(){this.velocity.copy(this.state.velocity),this.mode=this.state.mode,this.horizontalSpeed=this.state.currentSpeed,this.isSliding=this.state.mode===A.sliding,this.isSliding?(this.resolveGroundNormal(this.slideSurfaceNormal),this.slideDirection.copy(this.state.velocity).projectOnPlane(this.slideSurfaceNormal),this.slideDirection.lengthSq()>1e-8?this.slideDirection.normalize():this.slideDirection.set(0,0,0)):(this.slideDirection.set(0,0,0),this.slideSurfaceNormal.copy(Rt))}sampleRootMotion(t){if(t.set(0,0,0),null==this.rootMotionAction||this.rootMotionAction.isRunning()||this.clearRootMotionAction(this.rootMotionAction),null!=this.rootMotionAction&&this.rootMotionOptions.cancelWithJump&&this.jumpInput.activated&&(this.isGrounded||this.jumpInAir)){const e=this.rootMotionAction,i=this.rootMotionOptions.onJumpCancel;return this.clearRootMotionAction(e),e.stop(),i?.(),t}if(null==this.rootMotionAction)return t;if(!(this.rootMotionAction.getClip()instanceof l))return t;const e=this.rootMotionInterpolant;this.resetRootMotion&&(this.prevRootMotionPos.fromArray(e.evaluate(0)),this.resetRootMotion=!1),Gt.fromArray(e.evaluate(this.rootMotionAction.time)),t.subVectors(Gt,this.prevRootMotionPos),this.prevRootMotionPos.copy(Gt);if((this.rootMotionRootBone??this.rootMotionAction.getRoot()).getWorldScale(Ot),t.multiply(Ot),this.rootMotionTargetConstraints.size>0){It.copy(t).applyQuaternion(this.actor.quaternion);for(const t of this.rootMotionTargetConstraints)if(t.requestedProgress>0&&t.addedHorizontalDistance<t.maximumAddedHorizontalDistance){const e=r.lerp(t.initialHorizontalDistance,t.minimumHorizontalDistance,t.requestedProgress),i=Math.min(b(It,this.actor.position,t.targetPosition,e),t.maximumAddedHorizontalDistance-t.addedHorizontalDistance);t.addedHorizontalDistance+=q(It,this.actor.position,t.targetPosition,t.minimumHorizontalDistance,i)}else D(It,this.actor.position,t.targetPosition,t.minimumHorizontalDistance);t.copy(It).applyQuaternion(Ut.copy(this.actor.quaternion).invert())}return t}clearRootMotionAction(t){null!=t&&this.rootMotionAction!==t||(this.rootMotionAction=null,this.rootMotionOptions={},this.resetRootMotion=!1)}isRemoteControlledAuthority(t=this.netService.mode,e=this.actor.netRole){if(t===gt.none||e!==p.authority||t>=gt.client)return!1;return null!=this.netService.resolveActorConnection(this.actor)&&!this.netService.isLocalOwner(this.actor)}configureCharacterController(){const t=this.cc;t.setApplyImpulsesToDynamicBodies(this.applyImpulsesToDynamicBodies),t.setMinSlopeSlideAngle(this.minSlopeSlideAngle),t.setMaxSlopeClimbAngle(this.maxSlopeClimbAngle),t.setCharacterMass(this.mass),t.setSlideEnabled(this.allowSliding)}initializeStateFromActor(){this.state.position.copy(this.actor.position),this.state.velocity.set(0,0,0),this.state.yaw=this.actor.rotation.y,this.state.lookYaw=this.rotationInput.rotation.y,this.state.mode=this.mode,this.state.currentSpeed=this.horizontalSpeed,this.state.prevRotateToMovementDirection=this.rotateToMovementDirection}createCollisionShape(){const t=this.getColliderHeight(!1),e=this.getColliderRadius(!1),i=new w(t,e);return i.offset.y=this.getCapsuleOffsetY(t,e),i.collisionGroup=Ct,i}updateCrouchState(t,e,i,o){if(this.state.mode===A.swimming)return this.slideOnLandingRequested=!1,void this.tryUncrouch();if(!(0!==(t.flags&B)))return this.crouchSuppressedUntilRelease=!1,this.slideOnLandingRequested=!1,this.state.mode===A.sliding&&(this.state.mode=A.walking),void this.tryUncrouch();if(this.state.mode===A.sliding&&(!this.slideEnabled||i))return this.slideOnLandingRequested=!1,this.state.mode=A.walking,void(this.crouchSuppressedUntilRelease||this.setCrouching(!0));if(this.state.mode===A.sliding&&o)return this.crouchSuppressedUntilRelease=!0,this.slideOnLandingRequested=!1,void this.tryUncrouch();if(this.crouchSuppressedUntilRelease)return void(this.slideOnLandingRequested=!1);if(this.setCrouching(!0),!this.slideEnabled||i)return void(this.slideOnLandingRequested=!1);if(this.state.mode===A.falling)return void(this.slideOnLandingRequested=!0);this.resolveGroundNormal(Bt);const s=this.slideOnLandingRequested&&this.state.mode===A.walking&&this.state.grounded,n=e&&0!==(t.flags&$)||s;s&&(this.slideOnLandingRequested=!1);const r=_t(this.state.velocity);this.state.mode===A.walking&&wt(this.slideEnabled,n,this.state.grounded,this.isWalkableSlideSurface(Bt),i,r,this.slideMinStartSpeed)&&(this.state.mode=A.sliding,this.slideSurfaceNormal.copy(Bt),this.state.velocity.projectOnPlane(this.slideSurfaceNormal),this.state.currentSpeed=_t(this.state.velocity))}updateSlidingMode(t){const e=t.state,i=t.move;this.resolveGroundNormal(this.slideSurfaceNormal);const o=this.isWalkableSlideSurface(this.slideSurfaceNormal),s=e.velocity.length();if(!e.grounded||!o)return e.mode=A.falling,Kt.update(t),A.falling;if(this.slideEnabled&&0!==(i.flags&B)&&!t.rootMotionActive&&0!==(i.flags&Z))return Mt(t.outVelocity,e.velocity,this.jumpVelocity),e.velocity.copy(t.outVelocity),e.currentSpeed=_t(e.velocity),A.falling;if(!ft(this.slideEnabled,0!==(i.flags&B),e.grounded,o,t.rootMotionActive,s,this.slideMinExitSpeed))return e.mode=A.walking,Jt.update(t),A.walking;const n=xt(e.velocity,e.velocity,this.slideSurfaceNormal,t.rotatedDirection,this.getEffectiveGravity(),t.deltaTime,this.slideDeceleration,this.slideGravityScale,this.slideSteeringRate);if(e.currentSpeed=_t(e.velocity),n<Math.max(0,this.slideMinExitSpeed))return e.mode=A.walking,Jt.update(t),A.walking;t.outVelocity.copy(e.velocity).add(t.platformVelocity)}tryUncrouch(){this.isCrouching&&this.canUncrouch()&&this.setCrouching(!1)&&(this.suppressUncrouchLift=!0,this.state.fallGraceTime=0)}resolveGroundNormal(t){return!this.rayTestResult.hasHit||this.rayTestResult.hitNormal.lengthSq()<=1e-8?t.copy(Rt):(t.copy(this.rayTestResult.hitNormal).normalize(),t.dot(Rt)<0&&t.multiplyScalar(-1),t)}isWalkableSlideSurface(t){return t.dot(Rt)>=Math.cos(this.cc.maxSlopeClimbAngle())}setCrouching(t){return this.isCrouching!==t&&(this.isCrouching=t,this.syncColliderShape(),!0)}canUncrouch(){const t=this.getColliderHeight(!1),e=this.getColliderRadius(!1);return!this.physicsSystem.hasActorCapsuleIntersection(this.actor,this.state.position,t,e,this.getCapsuleOffsetY(t,e),this.getCollisionGroup())}syncColliderShape(){const t=this.getColliderHeight(this.isCrouching),e=this.getColliderRadius(this.isCrouching);this.physicsSystem.setActorCapsuleCollider(this.actor,t,e,this.getCapsuleOffsetY(t,e))}getColliderHeight(t){const e=Number.isFinite(this.colliderHeight)?Math.max(0,this.colliderHeight):0;if(!t)return e;const i=Number.isFinite(this.crouchColliderHeight)?this.crouchColliderHeight:e;return r.clamp(i,0,e)}getColliderRadius(t){const e=Number.isFinite(this.colliderRadius)?Math.max(.001,this.colliderRadius):.001;if(!t)return e;const i=this.crouchColliderRadius??e,o=Number.isFinite(i)?i:e;return r.clamp(o,.001,e)}getCapsuleOffsetY(t,e){return e+t/2+this.offset}checkGrounded(t){Ft.y=-Math.max(.05,this.cc.snapToGroundDistance()),this.groundRayTestOptions.collisionFilter=this.getCollisionGroup(),this.physicsSystem.rayTest(Ht.addVectors(t,Nt.set(0,this.offset,0)),Yt.addVectors(t,Ft),this.rayTestResult,this.groundRayTestOptions)}resolvePlatformVelocity(t){return t.set(0,0,0),this.rayTestResult.hasHit&&null!=this.rayTestResult.actor&&this.physicsSystem.getLinearVelocity(this.rayTestResult.actor,t),t}getCollisionGroup(){return this.characterCollision?null:Ct}};t([x({group:"Swimming"}),e("design:type",Object)],Qt.prototype,"swimmingEnabled",void 0),t([x({group:"Swimming",range:[0,20]}),e("design:type",Object)],Qt.prototype,"maxSpeedSwimming",void 0),t([x({group:"Swimming",range:[.1,1]}),e("design:type",Object)],Qt.prototype,"swimmingImmersion",void 0),t([x({group:"Swimming",range:[0,20]}),e("design:type",Object)],Qt.prototype,"swimmingSurfaceResponse",void 0),t([x({group:"Swimming",range:[0,20]}),e("design:type",Object)],Qt.prototype,"swimmingMaxVerticalSpeed",void 0),t([x({group:"Swimming",range:[0,1]}),e("design:type",Object)],Qt.prototype,"swimmingDepthHysteresis",void 0),t([x(),e("design:type",Number)],Qt.prototype,"colliderHeight",void 0),t([x(),e("design:type",Number)],Qt.prototype,"colliderRadius",void 0),t([x(),e("design:type",Number)],Qt.prototype,"crouchColliderHeight",void 0),t([x({optional:!0}),e("design:type",Number)],Qt.prototype,"crouchColliderRadius",void 0),t([v(!1),e("design:type",Function),e("design:paramtypes",[Uint8Array]),e("design:returntype",void 0)],Qt.prototype,"serverMove",null),t([g(!1),e("design:type",Function),e("design:paramtypes",[Uint8Array]),e("design:returntype",void 0)],Qt.prototype,"clientMoveAck",null),t([g(!0),e("design:type",Function),e("design:paramtypes",[Uint8Array]),e("design:returntype",void 0)],Qt.prototype,"clientMoveCorrection",null),t([y(!1),e("design:type",Function),e("design:paramtypes",[Uint8Array]),e("design:returntype",void 0)],Qt.prototype,"simulatedState",null),Qt=t([R({inEditor:!1}),e("design:paramtypes",[])],Qt);export{Qt as CharacterMovementComponent};const Jt={mode:A.walking,update(t){const e=t.component,i=t.move,o=t.state,s=t.rotatedDirection,n=Math.min(1,Math.sqrt(i.inputX*i.inputX+i.inputY*i.inputY)),r=!e.rotateToMovementDirection&&i.inputY<0,a=e.isCrouching,h=!t.rootMotionActive&&!a&&0===(i.flags&B)&&0!==(i.flags&Q)&&!r&&0!==s.lengthSq()&&(e.sprintPolicy?.canSprint()??!0),l=(a?e.maxSpeedCrouch:r?e.maxSpeedBackwards:h?e.maxSpeedSprint:e.maxSpeed)*(e.normalizedDirection?1:n);if(0!==s.lengthSq()){e.isSprinting=h,h&&e.sprintPolicy?.commitSprint(t.deltaTime,i.sequence);let a=Math.min(l,o.currentSpeed),c=e.groundAccelerationRate;if(h&&t.startedSprinting&&e.sprintStartBoostSpeed>0){const t=e.normalizedDirection?1:n;a=Math.max(a,l+e.sprintStartBoostSpeed*t),c=e.sprintStartBoostDamping}else h&&!r&&e.sprintStartBoostSpeed>0&&o.currentSpeed>l&&(a=o.currentSpeed,c=e.sprintStartBoostDamping);o.currentSpeed=te(a,l,c,t.deltaTime),t.outVelocity.copy(s).multiplyScalar(ee(a,l,c,t.deltaTime))}else o.currentSpeed=0,t.outVelocity.set(0,0,0);if(0!==(i.flags&Z))return o.mode=A.falling,o.velocity.copy(t.outVelocity),o.velocity.y=e.jumpVelocity,A.falling;t.outVelocity.y=t.deltaTime*e.getEffectiveGravity(),t.outVelocity.add(t.platformVelocity)}},Kt={mode:A.falling,update(t){const e=t.component,i=t.state,o=t.move;0!==(o.flags&Z)&&e.jumpInAir&&(i.velocity.copy(t.outVelocity),i.velocity.y=e.jumpVelocity),i.velocity.y+=t.deltaTime*e.getEffectiveGravity(),t.outVelocity.copy(i.velocity),t.outVelocity.addScaledVector(t.rotatedDirection,e.fallingMovementControl),e.fallingReorientation&&t.outVelocity.applyAxisAngle(Rt,r.euclideanModulo(o.yaw-i.lookYaw+Math.PI,2*Math.PI)-Math.PI)}};function _t(t){return Math.sqrt(t.x*t.x+t.z*t.z)}function te(t,e,i,o){return e+(t-e)*Math.exp(-i*o)}function ee(t,e,i,o){const s=i*o;return s<=1e-6?t:e+(t-e)*(1-Math.exp(-s))/s}function ie(t,e){return e.sequence=t.sequence,e.clientTime=t.clientTime,e.dt=t.dt,e.inputX=t.inputX,e.inputY=t.inputY,e.yaw=t.yaw,e.flags=t.flags,e.clientX=t.clientX,e.clientY=t.clientY,e.clientZ=t.clientZ,e.rootMotionX=t.rootMotionX,e.rootMotionY=t.rootMotionY,e.rootMotionZ=t.rootMotionZ,e}function oe(t,e){const i=t.position.x-e.clientX,o=t.position.y-e.clientY,s=t.position.z-e.clientZ;return i*i+o*o+s*s}class se{constructor(t){this.scene=t,this.serverPosition=new h,this.direction=new h}update(t,e){const i=this.serverPosition.set(e.x,e.y,e.z),o=i.distanceTo(t);o>.1&&console.log(`Correction applied. Error: ${o.toFixed(3)}. Server position: (${i.x.toFixed(2)}, ${i.y.toFixed(2)}, ${i.z.toFixed(2)}), Client position: (${t.x.toFixed(2)}, ${t.y.toFixed(2)}, ${t.z.toFixed(2)})`);const s=this.direction.copy(i).sub(t).normalize();ne.position.copy(t),ne.setDirection(s),ne.setLength(o);const n=re(this.scene);n.add(ne),setTimeout(()=>{n.remove(ne)},1e3)}}const ne=new n(new h(0,1,0),new h,1,16711680);function re(t){return null==t.parent?t:re(t.parent)}const ae={immediate:!1,savedRootMotion:!0};/*
2
2
  * Copyright (©) 2026 Hology Interactive AB. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -9,6 +9,14 @@ export declare class WaterSplineVolume extends BaseActor implements NavigationAr
9
9
  private readonly surface;
10
10
  private readonly editorVisual;
11
11
  readonly underwater: WaterPostProcessSettings;
12
+ private waterSections;
13
+ private waterSurfaceTriangles;
14
+ private waterSplineData?;
15
+ private waterWidth;
16
+ private waterDepth;
17
+ private waterSampleDistance;
18
+ private readonly waterSectionsMatrix;
19
+ private updateWaterSections;
12
20
  width: number;
13
21
  depth: number;
14
22
  showSurface: boolean;
@@ -17,6 +25,8 @@ export declare class WaterSplineVolume extends BaseActor implements NavigationAr
17
25
  surfaceWidthSubdivisions: number;
18
26
  applySceneParameters(parameters: Record<string, unknown>, changedParameters: ReadonlySet<string>): boolean;
19
27
  containsWaterPoint(point: Vector3): boolean;
28
+ /** World-space surface height above a point inside the volume, or null outside. */
29
+ getWaterSurfaceHeight(point: Vector3): number | null;
20
30
  getNavigationAreaModifiers(): NavigationAreaModifier[];
21
31
  }
22
32
  export { createWaterSplineSurfaceGeometry } from '../../../navigation/water-spline-geometry.js';
@@ -1,4 +1,4 @@
1
- import{__decorate as e,__metadata as t}from"tslib";import{createCrossSections as i,createSurfaceGeometry as s,createVolumeGeometry as r}from"../../../navigation/water-spline-geometry.js";import{BufferGeometry as a,EdgesGeometry as o,Group as n,DoubleSide as h,LineBasicMaterial as l,LineSegments as u,Mesh as c,MeshBasicMaterial as p,Material as d,Matrix4 as f,Vector3 as m}from"three";import{takeUntil as g}from"rxjs";import{NavigationArea as b}from"../../ai/navigation-areas.js";import{Parameter as y}from"../../../shader/parameter.js";import{Actor as w,BaseActor as S}from"../actor.js";import{ActorComponent as v,Component as M,attach as x}from"../component.js";import{SplineComponent as z}from"./components/spline-component.js";import{WaterPostProcessSettings as W}from"./components/water-post-process-settings.js";const j=1477586;let D=class extends v{constructor(){super(...arguments),this.fallbackMaterial=new p({color:j,transparent:!0,opacity:.65,side:h}),this.surface=new c(new a,this.fallbackMaterial),this.initialized=!1}onInit(){this.initialized=!0,this.surface.name="Water Surface",this.actor.object.add(this.surface),this.actor.spline.changed.pipe(g(this.disposed)).subscribe(()=>this.rebuild()),this.setMaterial(this.actor.surfaceMaterial),this.rebuild()}setMaterial(e){this.surface.material=e??this.fallbackMaterial}rebuild(){if(!this.initialized)return;const e=this.surface.geometry;this.surface.geometry=s(this.actor.spline,this.actor.width,this.actor.surfaceSampleDistance,this.actor.surfaceWidthSubdivisions),this.surface.visible=this.actor.showSurface,e.dispose()}onEndPlay(){this.surface.geometry.dispose(),this.fallbackMaterial.dispose(),this.surface.removeFromParent()}};D=e([M({inEditor:!0})],D);let N=class extends v{constructor(){super(...arguments),this.visual=new n,this.fillMaterial=new p({color:j,transparent:!0,opacity:.18,depthWrite:!1}),this.edgeMaterial=new l({color:3520767}),this.fill=new c(new a,this.fillMaterial),this.edges=new u(new a,this.edgeMaterial),this.initialized=!1}onInit(){this.initialized=!0,this.visual.name="Water Spline Volume Visualization",this.visual.userData.isEditorVisualization=!0,this.fill.frustumCulled=!1,this.edges.frustumCulled=!1,this.visual.add(this.fill,this.edges),this.actor.object.add(this.visual),this.actor.spline.changed.pipe(g(this.disposed)).subscribe(()=>this.rebuild()),this.rebuild()}rebuild(){if(!this.initialized)return;const e=r(this.actor.spline,this.actor.width,this.actor.depth,this.actor.showSurface,this.actor.surfaceSampleDistance),t=0===e.getAttribute("position").count?new a:new o(e,20),i=this.fill.geometry,s=this.edges.geometry;this.fill.geometry=e,this.edges.geometry=t,i.dispose(),s.dispose(),this.visual.updateMatrixWorld(!0)}onEndPlay(){this.fill.geometry.dispose(),this.edges.geometry.dispose(),this.fillMaterial.dispose(),this.edgeMaterial.dispose(),this.visual.removeFromParent()}};N=e([M({inEditor:!0,editorOnly:!0})],N);let T=class extends S{constructor(){super(...arguments),this.spline=x(z),this.surface=x(D),this.editorVisual=x(N),this.underwater=x(W),this.width=5,this.depth=2,this.showSurface=!0,this.surfaceSampleDistance=1,this.surfaceWidthSubdivisions=1}applySceneParameters(e,t){if(![...t].every(e=>["width","depth","showSurface","surfaceMaterial","surfaceSampleDistance","surfaceWidthSubdivisions"].includes(e)))return!1;const i=t.has("width")?e.width:this.width,s=t.has("depth")?e.depth:this.depth;if("number"!=typeof i||!Number.isFinite(i)||i<=0)return!1;if("number"!=typeof s||!Number.isFinite(s)||s<=0)return!1;if(t.has("showSurface")&&"boolean"!=typeof e.showSurface)return!1;if(t.has("surfaceMaterial")&&null!=e.surfaceMaterial&&!(e.surfaceMaterial instanceof d))return!1;const r=t.has("surfaceSampleDistance")?e.surfaceSampleDistance:this.surfaceSampleDistance,a=t.has("surfaceWidthSubdivisions")?e.surfaceWidthSubdivisions:this.surfaceWidthSubdivisions;return!("number"!=typeof r||!Number.isFinite(r)||r<=0)&&(!("number"!=typeof a||!Number.isFinite(a)||a<1)&&(this.width=i,this.depth=s,t.has("showSurface")&&(this.showSurface=e.showSurface),t.has("surfaceMaterial")&&(this.surfaceMaterial=e.surfaceMaterial,this.surface.setMaterial(this.surfaceMaterial)),this.surfaceSampleDistance=r,this.surfaceWidthSubdivisions=Math.round(a),this.editorVisual.rebuild(),this.surface.rebuild(),!0))}containsWaterPoint(e){this.object.updateWorldMatrix(!0,!1);const t=P.copy(e).applyMatrix4(F.copy(this.object.matrixWorld).invert()),s=i(this.spline,this.width,this.depth,this.surfaceSampleDistance);for(let e=1;e<s.length;e++){const i=s[e-1],r=s[e];if(V(t,i.leftTop,i.rightTop,r.rightTop,r.leftTop,this.depth))return!0}return!1}getNavigationAreaModifiers(){const e=i(this.spline,this.width,this.depth);if(e.length<2)return[];this.object.updateWorldMatrix(!0,!1);const t=this.object.matrixWorld,s=[];for(let i=1;i<e.length;i++){const r=e[i-1],a=e[i],o=[r.leftTop,r.rightTop,a.rightTop,a.leftTop,r.leftBottom,r.rightBottom,a.rightBottom,a.leftBottom].map(e=>e.clone().applyMatrix4(t));s.push({area:b.Water,vertices:o.slice(0,4).map(e=>e.toArray()),minHeight:Math.min(...o.map(e=>e.y)),maxHeight:Math.max(...o.map(e=>e.y))})}return s}};e([y({range:[.01,1e3]}),t("design:type",Number)],T.prototype,"width",void 0),e([y({range:[.01,1e3]}),t("design:type",Number)],T.prototype,"depth",void 0),e([y({group:"Surface"}),t("design:type",Boolean)],T.prototype,"showSurface",void 0),e([y({type:d,group:"Surface",requires:{showSurface:!0},help:"Optional. Uses a translucent debug material when unset."}),t("design:type",d)],T.prototype,"surfaceMaterial",void 0),e([y({range:[.1,100],group:"Surface",requires:{showSurface:!0},help:"Target spacing in world units between sections along the spline."}),t("design:type",Number)],T.prototype,"surfaceSampleDistance",void 0),e([y({range:[1,64],stepSize:1,group:"Surface",requires:{showSurface:!0},help:"Subdivisions across the water. Increase for vertex displacement and detailed bank effects."}),t("design:type",Number)],T.prototype,"surfaceWidthSubdivisions",void 0),T=e([w({typeId:"WaterSplineVolume",icon:"ripple"})],T);export{T as WaterSplineVolume};export{createWaterSplineSurfaceGeometry}from"../../../navigation/water-spline-geometry.js";const F=new f,P=new m;function V(e,t,i,s,r,a){const o=k(e,t,i,s)??k(e,t,s,r);return null!=o&&e.y<=o&&e.y>=o-a}function k(e,t,i,s){const r=(i.z-s.z)*(t.x-s.x)+(s.x-i.x)*(t.z-s.z);if(Math.abs(r)<1e-8)return null;const a=((i.z-s.z)*(e.x-s.x)+(s.x-i.x)*(e.z-s.z))/r,o=((s.z-t.z)*(e.x-s.x)+(t.x-s.x)*(e.z-s.z))/r,n=1-a-o;return a>=0&&o>=0&&n>=0?a*t.y+o*i.y+n*s.y:null}/*
1
+ import{__decorate as t,__metadata as e}from"tslib";import{createCrossSections as i,createSurfaceGeometry as s,createVolumeGeometry as r}from"../../../navigation/water-spline-geometry.js";import{BufferGeometry as a,EdgesGeometry as o,Group as n,DoubleSide as h,LineBasicMaterial as l,LineSegments as c,Mesh as u,MeshBasicMaterial as p,Material as d,Matrix4 as f,Vector3 as m}from"three";import{takeUntil as w}from"rxjs";import{NavigationArea as g}from"../../ai/navigation-areas.js";import{Parameter as S}from"../../../shader/parameter.js";import{Actor as y,BaseActor as b}from"../actor.js";import{ActorComponent as M,Component as x,attach as v}from"../component.js";import{SplineComponent as W}from"./components/spline-component.js";import{WaterPostProcessSettings as D}from"./components/water-post-process-settings.js";const z=1477586;let j=class extends M{constructor(){super(...arguments),this.fallbackMaterial=new p({color:z,transparent:!0,opacity:.65,side:h}),this.surface=new u(new a,this.fallbackMaterial),this.initialized=!1}onInit(){this.initialized=!0,this.surface.name="Water Surface",this.actor.object.add(this.surface),this.actor.spline.changed.pipe(w(this.disposed)).subscribe(()=>this.rebuild()),this.setMaterial(this.actor.surfaceMaterial),this.rebuild()}setMaterial(t){this.surface.material=t??this.fallbackMaterial}rebuild(){if(!this.initialized)return;const t=this.surface.geometry;this.surface.geometry=s(this.actor.spline,this.actor.width,this.actor.surfaceSampleDistance,this.actor.surfaceWidthSubdivisions),this.surface.visible=this.actor.showSurface,t.dispose()}onEndPlay(){this.surface.geometry.dispose(),this.fallbackMaterial.dispose(),this.surface.removeFromParent()}};j=t([x({inEditor:!0})],j);let N=class extends M{constructor(){super(...arguments),this.visual=new n,this.fillMaterial=new p({color:z,transparent:!0,opacity:.18,depthWrite:!1}),this.edgeMaterial=new l({color:3520767}),this.fill=new u(new a,this.fillMaterial),this.edges=new c(new a,this.edgeMaterial),this.initialized=!1}onInit(){this.initialized=!0,this.visual.name="Water Spline Volume Visualization",this.visual.userData.isEditorVisualization=!0,this.fill.frustumCulled=!1,this.edges.frustumCulled=!1,this.visual.add(this.fill,this.edges),this.actor.object.add(this.visual),this.actor.spline.changed.pipe(w(this.disposed)).subscribe(()=>this.rebuild()),this.rebuild()}rebuild(){if(!this.initialized)return;const t=r(this.actor.spline,this.actor.width,this.actor.depth,this.actor.showSurface,this.actor.surfaceSampleDistance),e=0===t.getAttribute("position").count?new a:new o(t,20),i=this.fill.geometry,s=this.edges.geometry;this.fill.geometry=t,this.edges.geometry=e,i.dispose(),s.dispose(),this.visual.updateMatrixWorld(!0)}onEndPlay(){this.fill.geometry.dispose(),this.edges.geometry.dispose(),this.fillMaterial.dispose(),this.edgeMaterial.dispose(),this.visual.removeFromParent()}};N=t([x({inEditor:!0,editorOnly:!0})],N);let T=class extends b{constructor(){super(...arguments),this.spline=v(W),this.surface=v(j),this.editorVisual=v(N),this.underwater=v(D),this.waterSections=[],this.waterSurfaceTriangles=[],this.waterWidth=NaN,this.waterDepth=NaN,this.waterSampleDistance=NaN,this.waterSectionsMatrix=new f,this.width=5,this.depth=2,this.showSurface=!0,this.surfaceSampleDistance=1,this.surfaceWidthSubdivisions=1}updateWaterSections(){const t=this.spline.splineData!==this.waterSplineData||this.width!==this.waterWidth||this.depth!==this.waterDepth||this.surfaceSampleDistance!==this.waterSampleDistance;if(t&&(this.waterSplineData=this.spline.splineData,this.waterWidth=this.width,this.waterDepth=this.depth,this.waterSampleDistance=this.surfaceSampleDistance,this.waterSections=i(this.spline,this.width,this.depth,this.surfaceSampleDistance)),this.object.updateWorldMatrix(!0,!1),t||!this.waterSectionsMatrix.equals(this.object.matrixWorld)){this.waterSectionsMatrix.copy(this.object.matrixWorld),this.waterSurfaceTriangles.length=0;for(const t of this.waterSections)this.waterSurfaceTriangles.push(t.leftTop.clone().applyMatrix4(this.waterSectionsMatrix),t.rightTop.clone().applyMatrix4(this.waterSectionsMatrix))}}applySceneParameters(t,e){if(![...e].every(t=>["width","depth","showSurface","surfaceMaterial","surfaceSampleDistance","surfaceWidthSubdivisions"].includes(t)))return!1;const i=e.has("width")?t.width:this.width,s=e.has("depth")?t.depth:this.depth;if("number"!=typeof i||!Number.isFinite(i)||i<=0)return!1;if("number"!=typeof s||!Number.isFinite(s)||s<=0)return!1;if(e.has("showSurface")&&"boolean"!=typeof t.showSurface)return!1;if(e.has("surfaceMaterial")&&null!=t.surfaceMaterial&&!(t.surfaceMaterial instanceof d))return!1;const r=e.has("surfaceSampleDistance")?t.surfaceSampleDistance:this.surfaceSampleDistance,a=e.has("surfaceWidthSubdivisions")?t.surfaceWidthSubdivisions:this.surfaceWidthSubdivisions;return!("number"!=typeof r||!Number.isFinite(r)||r<=0)&&(!("number"!=typeof a||!Number.isFinite(a)||a<1)&&(this.width=i,this.depth=s,e.has("showSurface")&&(this.showSurface=t.showSurface),e.has("surfaceMaterial")&&(this.surfaceMaterial=t.surfaceMaterial,this.surface.setMaterial(this.surfaceMaterial)),this.surfaceSampleDistance=r,this.surfaceWidthSubdivisions=Math.round(a),this.editorVisual.rebuild(),this.surface.rebuild(),!0))}containsWaterPoint(t){this.updateWaterSections();const e=F.copy(t).applyMatrix4(P.copy(this.object.matrixWorld).invert()),i=this.waterSections;for(let t=1;t<i.length;t++){const s=i[t-1],r=i[t];if(V(e,s.leftTop,s.rightTop,r.rightTop,r.leftTop,this.depth))return!0}return!1}getWaterSurfaceHeight(t){if(!this.containsWaterPoint(t))return null;const e=this.waterSurfaceTriangles;let i=null;for(let s=2;s<e.length;s+=2){const r=e[s-2],a=e[s-1],o=e[s+1],n=e[s],h=k(t,r,a,o)??k(t,r,o,n);null!=h&&h>=t.y&&(null==i||h>i)&&(i=h)}return i}getNavigationAreaModifiers(){const t=i(this.spline,this.width,this.depth);if(t.length<2)return[];this.object.updateWorldMatrix(!0,!1);const e=this.object.matrixWorld,s=[];for(let i=1;i<t.length;i++){const r=t[i-1],a=t[i],o=[r.leftTop,r.rightTop,a.rightTop,a.leftTop,r.leftBottom,r.rightBottom,a.rightBottom,a.leftBottom].map(t=>t.clone().applyMatrix4(e));s.push({area:g.Water,vertices:o.slice(0,4).map(t=>t.toArray()),minHeight:Math.min(...o.map(t=>t.y)),maxHeight:Math.max(...o.map(t=>t.y))})}return s}};t([S({range:[.01,1e3]}),e("design:type",Number)],T.prototype,"width",void 0),t([S({range:[.01,1e3]}),e("design:type",Number)],T.prototype,"depth",void 0),t([S({group:"Surface"}),e("design:type",Boolean)],T.prototype,"showSurface",void 0),t([S({type:d,group:"Surface",requires:{showSurface:!0},help:"Optional. Uses a translucent debug material when unset."}),e("design:type",d)],T.prototype,"surfaceMaterial",void 0),t([S({range:[.1,100],group:"Surface",requires:{showSurface:!0},help:"Target spacing in world units between sections along the spline."}),e("design:type",Number)],T.prototype,"surfaceSampleDistance",void 0),t([S({range:[1,64],stepSize:1,group:"Surface",requires:{showSurface:!0},help:"Subdivisions across the water. Increase for vertex displacement and detailed bank effects."}),e("design:type",Number)],T.prototype,"surfaceWidthSubdivisions",void 0),T=t([y({typeId:"WaterSplineVolume",icon:"ripple"})],T);export{T as WaterSplineVolume};export{createWaterSplineSurfaceGeometry}from"../../../navigation/water-spline-geometry.js";const P=new f,F=new m;function V(t,e,i,s,r,a){const o=k(t,e,i,s)??k(t,e,s,r);return null!=o&&t.y<=o&&t.y>=o-a}function k(t,e,i,s){const r=(i.z-s.z)*(e.x-s.x)+(s.x-i.x)*(e.z-s.z);if(Math.abs(r)<1e-8)return null;const a=((i.z-s.z)*(t.x-s.x)+(s.x-i.x)*(t.z-s.z))/r,o=((s.z-e.z)*(t.x-s.x)+(e.x-s.x)*(t.z-s.z))/r,n=1-a-o;return a>=0&&o>=0&&n>=0?a*e.y+o*i.y+n*s.y:null}/*
2
2
  * Copyright (©) 2026 Hology Interactive AB. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -1,5 +1,5 @@
1
1
  import { Material, Matrix4, Vector3 } from 'three';
2
- import { BaseActor } from '../../index.js';
2
+ import { BaseActor } from '../actor.js';
3
3
  import { type NavigationAreaContributor, type NavigationAreaModifier } from '../../ai/navigation-areas.js';
4
4
  import { WaterPostProcessSettings, type WaterPostProcessVolume } from './components/water-post-process-settings.js';
5
5
  /** A semantic box of water. Its top face is the future water surface. */
@@ -13,6 +13,8 @@ export declare class WaterVolume extends BaseActor implements NavigationAreaCont
13
13
  applySceneParameters(parameters: Record<string, unknown>, changed: ReadonlySet<string>): boolean;
14
14
  getNavigationAreaModifiers(): NavigationAreaModifier[];
15
15
  containsWaterPoint(point: Vector3): boolean;
16
+ /** World-space surface height above a point inside the volume, or null outside. */
17
+ getWaterSurfaceHeight(point: Vector3): number | null;
16
18
  getWaterPostProcessWorldToLocal(target: Matrix4): Matrix4;
17
19
  isWaterPostProcessRelevant(cameraPosition: Vector3, transitionDistance: number): boolean;
18
20
  }
@@ -1,4 +1,4 @@
1
- import{__decorate as e,__metadata as t}from"tslib";import{BoxGeometry as a,DoubleSide as r,EdgesGeometry as s,Group as i,LineBasicMaterial as o,LineSegments as n,Material as c,Matrix4 as u,Mesh as h,MeshBasicMaterial as l,PlaneGeometry as p,Vector3 as f}from"three";import{Actor as d,BaseActor as m,Component as b,ActorComponent as w,attach as M}from"../../index.js";import{NavigationArea as y}from"../../ai/navigation-areas.js";import{Parameter as v}from"../../../shader/parameter.js";import{WaterPostProcessSettings as S,boxContainsWorldPoint as x}from"./components/water-post-process-settings.js";let g=class extends w{constructor(){super(...arguments),this.fallbackMaterial=new l({color:1477586,transparent:!0,opacity:.65,side:r}),this.surface=new h(new p,this.fallbackMaterial)}onInit(){this.surface.name="Water Surface",this.surface.position.y=.5,this.actor.object.add(this.surface),this.rebuild()}rebuild(){const e=this.surface.geometry,t=Math.max(1,Math.round(this.actor.surfaceSubdivisions));this.surface.geometry=new p(1,1,t,t).rotateX(-Math.PI/2),this.surface.material=this.actor.surfaceMaterial??this.fallbackMaterial,this.surface.visible=this.actor.showSurface,e.dispose()}onEndPlay(){this.surface.geometry.dispose(),this.fallbackMaterial.dispose(),this.surface.removeFromParent()}};g=e([b({inEditor:!0})],g);let W=class extends w{constructor(){super(...arguments),this.visual=new i}onInit(){const e=new a(1,1,1);this.visual.add(new h(e,new l({color:1477586,transparent:!0,opacity:.18,depthWrite:!1})),new n(new s(e),new o({color:3520767}))),this.actor.object.add(this.visual)}};W=e([b({inEditor:!0,editorOnly:!0})],W);let j=class extends m{constructor(){super(...arguments),this.surface=M(g),this.editorVisual=M(W),this.underwater=M(S),this.showSurface=!0,this.surfaceSubdivisions=1}applySceneParameters(e,t){if(![...t].every(e=>"showSurface"===e||"surfaceMaterial"===e||"surfaceSubdivisions"===e))return!1;if(t.has("showSurface")&&"boolean"!=typeof e.showSurface)return!1;if(t.has("surfaceMaterial")&&null!=e.surfaceMaterial&&!(e.surfaceMaterial instanceof c))return!1;const a=t.has("surfaceSubdivisions")?e.surfaceSubdivisions:this.surfaceSubdivisions;return!("number"!=typeof a||!Number.isFinite(a)||a<1)&&(t.has("showSurface")&&(this.showSurface=e.showSurface),t.has("surfaceMaterial")&&(this.surfaceMaterial=e.surfaceMaterial),this.surfaceSubdivisions=Math.round(a),this.surface.rebuild(),!0)}getNavigationAreaModifiers(){this.object.updateWorldMatrix(!0,!1);const e=this.object.matrixWorld,t=P.map(t=>t.clone().applyMatrix4(e).toArray());let a=1/0,r=-1/0;for(const t of I){const s=k.copy(t).applyMatrix4(e).y;a=Math.min(a,s),r=Math.max(r,s)}return[{area:y.Water,vertices:t,minHeight:a,maxHeight:r}]}containsWaterPoint(e){return x(this.object,e)}getWaterPostProcessWorldToLocal(e){return this.object.updateWorldMatrix(!0,!1),e.copy(this.object.matrixWorld).invert()}isWaterPostProcessRelevant(e,t){this.object.updateWorldMatrix(!0,!1),N.copy(e).applyMatrix4(E.copy(this.object.matrixWorld).invert());const a=this.object.matrixWorld.elements,r=Math.max(1e-6,Math.hypot(a[4],a[5],a[6])),s=Math.max(0,t);return Math.abs(N.y-.5)*r<=s&&Math.abs(N.x)<=.5&&Math.abs(N.z)<=.5}};e([v({group:"Surface"}),t("design:type",Boolean)],j.prototype,"showSurface",void 0),e([v({type:c,group:"Surface",requires:{showSurface:!0},help:"Optional. Uses a translucent debug material when unset."}),t("design:type",c)],j.prototype,"surfaceMaterial",void 0),e([v({range:[1,256],stepSize:1,group:"Surface",requires:{showSurface:!0},help:"Grid subdivisions per axis. Increase only when the material displaces vertices."}),t("design:type",Number)],j.prototype,"surfaceSubdivisions",void 0),j=e([d({typeId:"WaterVolume",icon:"ripple"})],j);export{j as WaterVolume};const P=[new f(-.5,0,-.5),new f(.5,0,-.5),new f(.5,0,.5),new f(-.5,0,.5)],I=[-.5,.5].flatMap(e=>[-.5,.5].flatMap(t=>[-.5,.5].map(a=>new f(e,t,a)))),k=new f,E=new u,N=new f;/*
1
+ import{__decorate as e,__metadata as t}from"tslib";import{BoxGeometry as r,DoubleSide as a,EdgesGeometry as s,Group as i,LineBasicMaterial as o,LineSegments as n,Material as c,Matrix4 as u,Mesh as l,MeshBasicMaterial as h,PlaneGeometry as p,Vector3 as f}from"three";import{Actor as d,BaseActor as m}from"../actor.js";import{Component as b,ActorComponent as y,attach as M}from"../component.js";import{NavigationArea as w}from"../../ai/navigation-areas.js";import{Parameter as v}from"../../../shader/parameter.js";import{WaterPostProcessSettings as S,boxContainsWorldPoint as x}from"./components/water-post-process-settings.js";let g=class extends y{constructor(){super(...arguments),this.fallbackMaterial=new h({color:1477586,transparent:!0,opacity:.65,side:a}),this.surface=new l(new p,this.fallbackMaterial)}onInit(){this.surface.name="Water Surface",this.surface.position.y=.5,this.actor.object.add(this.surface),this.rebuild()}rebuild(){const e=this.surface.geometry,t=Math.max(1,Math.round(this.actor.surfaceSubdivisions));this.surface.geometry=new p(1,1,t,t).rotateX(-Math.PI/2),this.surface.material=this.actor.surfaceMaterial??this.fallbackMaterial,this.surface.visible=this.actor.showSurface,e.dispose()}onEndPlay(){this.surface.geometry.dispose(),this.fallbackMaterial.dispose(),this.surface.removeFromParent()}};g=e([b({inEditor:!0})],g);let W=class extends y{constructor(){super(...arguments),this.visual=new i}onInit(){const e=new r(1,1,1);this.visual.add(new l(e,new h({color:1477586,transparent:!0,opacity:.18,depthWrite:!1})),new n(new s(e),new o({color:3520767}))),this.actor.object.add(this.visual)}};W=e([b({inEditor:!0,editorOnly:!0})],W);let j=class extends m{constructor(){super(...arguments),this.surface=M(g),this.editorVisual=M(W),this.underwater=M(S),this.showSurface=!0,this.surfaceSubdivisions=1}applySceneParameters(e,t){if(![...t].every(e=>"showSurface"===e||"surfaceMaterial"===e||"surfaceSubdivisions"===e))return!1;if(t.has("showSurface")&&"boolean"!=typeof e.showSurface)return!1;if(t.has("surfaceMaterial")&&null!=e.surfaceMaterial&&!(e.surfaceMaterial instanceof c))return!1;const r=t.has("surfaceSubdivisions")?e.surfaceSubdivisions:this.surfaceSubdivisions;return!("number"!=typeof r||!Number.isFinite(r)||r<1)&&(t.has("showSurface")&&(this.showSurface=e.showSurface),t.has("surfaceMaterial")&&(this.surfaceMaterial=e.surfaceMaterial),this.surfaceSubdivisions=Math.round(r),this.surface.rebuild(),!0)}getNavigationAreaModifiers(){this.object.updateWorldMatrix(!0,!1);const e=this.object.matrixWorld,t=P.map(t=>t.clone().applyMatrix4(e).toArray());let r=1/0,a=-1/0;for(const t of I){const s=k.copy(t).applyMatrix4(e).y;r=Math.min(r,s),a=Math.max(a,s)}return[{area:w.Water,vertices:t,minHeight:r,maxHeight:a}]}containsWaterPoint(e){return x(this.object,e)}getWaterSurfaceHeight(e){if(!this.containsWaterPoint(e))return null;const t=z.copy(this.object.matrixWorld).invert(),r=E.copy(e).applyMatrix4(t),a=t.elements[5];if(a<=1e-8)return null;const s=(.5-r.y)/a;return Math.abs(r.x+s*t.elements[4])>.5||Math.abs(r.z+s*t.elements[6])>.5?null:e.y+s}getWaterPostProcessWorldToLocal(e){return this.object.updateWorldMatrix(!0,!1),e.copy(this.object.matrixWorld).invert()}isWaterPostProcessRelevant(e,t){this.object.updateWorldMatrix(!0,!1),E.copy(e).applyMatrix4(z.copy(this.object.matrixWorld).invert());const r=this.object.matrixWorld.elements,a=Math.max(1e-6,Math.hypot(r[4],r[5],r[6])),s=Math.max(0,t);return Math.abs(E.y-.5)*a<=s&&Math.abs(E.x)<=.5&&Math.abs(E.z)<=.5}};e([v({group:"Surface"}),t("design:type",Boolean)],j.prototype,"showSurface",void 0),e([v({type:c,group:"Surface",requires:{showSurface:!0},help:"Optional. Uses a translucent debug material when unset."}),t("design:type",c)],j.prototype,"surfaceMaterial",void 0),e([v({range:[1,256],stepSize:1,group:"Surface",requires:{showSurface:!0},help:"Grid subdivisions per axis. Increase only when the material displaces vertices."}),t("design:type",Number)],j.prototype,"surfaceSubdivisions",void 0),j=e([d({typeId:"WaterVolume",icon:"ripple"})],j);export{j as WaterVolume};const P=[new f(-.5,0,-.5),new f(.5,0,-.5),new f(.5,0,.5),new f(-.5,0,.5)],I=[-.5,.5].flatMap(e=>[-.5,.5].flatMap(t=>[-.5,.5].map(r=>new f(e,t,r)))),k=new f,z=new u,E=new f;/*
2
2
  * Copyright (©) 2026 Hology Interactive AB. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -1,4 +1,4 @@
1
- import{__decorate as t,__metadata as e}from"tslib";import{Euler as i,Object3D as o,PerspectiveCamera as s,Quaternion as n,Vector3 as r}from"three";import{Parameter as a}from"../../../shader/parameter.js";import{inject as h}from"../../inject.js";import{RestrictedRotationInput as c}from"../../input/index.js";import{ViewController as d}from"../../services/render.js";import{World as m}from"../../services/world.js";import{ActorComponent as l,Component as p}from"../component.js";const u="undefined"!=typeof window&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),v=u?65:75,f=Math.PI/2-.01;let g=class extends l{constructor(){super(...arguments),this.viewController=h(d),this.world=h(m),this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.near=.05,this.far=500,this.viewAngle=v,this.eyeHeight=1.7,this.offsetX=0,this.offsetZ=0,this.autoActivate=!0,this.activated=!1,this.isMouseLocked=!1,this.rotationInput=new c(-f,f),this.camera=new s(this.viewAngle,this.aspect,this.near,this.far),this.viewModelRoot=new o,this.additivePositionOffset=new r,this.additiveRotationOffset=new i,this.additiveFov=0,this.pointerLockInactivatedAt=null,this.pointerEventsRegistered=!1,this.hiddenObjects=new Map,this.onMouseDown=t=>{this.isMouseLocked||"mouse"!==t.pointerType||this.hideCursor()},this.onKeyDown=t=>{"Escape"===t.key&&this.showCursor()},this.onPointerLockChange=()=>{this.isMouseLocked=null!=document.pointerLockElement||null!=document.mozPointerLockElement,this.isMouseLocked||(this.element.style.cursor="default",this.pointerLockInactivatedAt=performance.now())}}async onInit(){this.applyCameraSettings(),this.camera.add(this.viewModelRoot),this.world.scene.add(this.camera),this.rotationInput.rotation.x=0,this.updateCameraTransform(),this.disposed.subscribe(()=>{this.unregisterPointerEvents(),this.restoreHiddenObjects(),this.camera.removeFromParent()}),this.autoActivate&&this.activate()}activate(){this.activated=!0,this.updateCameraTransform(),this.viewController.setCamera(this.camera),this.isMouseLocked=null!=document.pointerLockElement||null!=document.mozPointerLockElement,this.registerPointerEvents()}deactivate(){this.activated=!1,this.isMouseLocked=!1,this.unregisterPointerEvents()}onLateUpdate(){this.activated&&this.updateCameraTransform()}hideCursor(){if(null!=this.pointerLockInactivatedAt&&performance.now()-this.pointerLockInactivatedAt<1600)return;this.element.style.cursor="none";const t=this.element.getElementsByTagName("canvas")[0];if(null!=t&&t.isConnected&&t.ownerDocument===document&&null!=t.requestPointerLock)try{const e=t.requestPointerLock({unadjustedMovement:!0});e?.catch(this.onPointerLockChange)}catch{this.onPointerLockChange()}else this.onPointerLockChange()}showCursor(){this.pointerLockInactivatedAt=performance.now(),this.element.style.cursor="default",null==document.pointerLockElement&&null==document.mozPointerLockElement||window.document.exitPointerLock(),this.isMouseLocked=!1}getAimOrigin(t){return this.camera.updateWorldMatrix(!0,!1),this.camera.getWorldPosition(t)}getAimDirection(t){return this.camera.updateWorldMatrix(!0,!1),this.camera.getWorldDirection(t)}getAimRay(t){return this.getAimOrigin(t.origin),this.getAimDirection(t.direction),t}hideObjects(...t){for(const e of t)null==e||this.hiddenObjects.has(e)||(this.hiddenObjects.set(e,e.visible),e.visible=!1)}restoreHiddenObjects(){for(const[t,e]of this.hiddenObjects)t.visible=e;this.hiddenObjects.clear()}get element(){return this.viewController.htmlElement}registerPointerEvents(){if(this.pointerEventsRegistered||null==document.body.requestPointerLock)return;const t=this.element;t.addEventListener("pointerdown",this.onMouseDown),t.addEventListener("keydown",this.onKeyDown),document.addEventListener("pointerlockchange",this.onPointerLockChange,!1),this.pointerEventsRegistered=!0}unregisterPointerEvents(){if(!this.pointerEventsRegistered)return;const t=this.element;t.removeEventListener("pointerdown",this.onMouseDown),t.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("pointerlockchange",this.onPointerLockChange,!1),this.pointerEventsRegistered=!1}applyCameraSettings(){const t=this.viewAngle+this.additiveFov;this.camera.near===this.near&&this.camera.far===this.far&&this.camera.fov===t&&this.camera.aspect===this.aspect||(this.camera.near=this.near,this.camera.far=this.far,this.camera.fov=t,this.camera.aspect=this.aspect,this.camera.updateProjectionMatrix())}updateCameraTransform(){this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.applyCameraSettings(),this.actor.object.updateWorldMatrix(!0,!1),w.set(this.offsetX,this.eyeHeight,this.offsetZ),this.camera.position.copy(w.applyMatrix4(this.actor.object.matrixWorld)),this.actor.object.getWorldQuaternion(L),b.set(-this.rotationInput.rotation.x,0,0),E.setFromEuler(b),this.camera.quaternion.copy(L).multiply(k).multiply(E),this.additivePositionOffset.lengthSq()>0&&(y.copy(this.additivePositionOffset).applyQuaternion(this.camera.quaternion),this.camera.position.add(y)),0===this.additiveRotationOffset.x&&0===this.additiveRotationOffset.y&&0===this.additiveRotationOffset.z||(P.setFromEuler(this.additiveRotationOffset),this.camera.quaternion.multiply(P)),this.camera.updateMatrixWorld(!0)}};t([a(),e("design:type",Number)],g.prototype,"near",void 0),t([a(),e("design:type",Number)],g.prototype,"far",void 0),t([a(),e("design:type",Number)],g.prototype,"viewAngle",void 0),t([a(),e("design:type",Number)],g.prototype,"eyeHeight",void 0),t([a(),e("design:type",Number)],g.prototype,"offsetX",void 0),t([a(),e("design:type",Number)],g.prototype,"offsetZ",void 0),g=t([p()],g);export{g as FirstPersonCameraComponent};const w=new r,y=new r,L=new n,k=(new n).setFromEuler(new i(0,Math.PI,0)),E=new n,P=new n,b=new i;/*
1
+ import{__decorate as t,__metadata as e}from"tslib";import{Euler as i,Object3D as o,PerspectiveCamera as s,Quaternion as n,Vector3 as r}from"three";import{Parameter as a}from"../../../shader/parameter.js";import{inject as h}from"../../inject.js";import{RestrictedRotationInput as c}from"../../input/index.js";import{ViewController as d}from"../../services/render.js";import{World as m}from"../../services/world.js";import{ActorComponent as l,Component as p}from"../component.js";const u="undefined"!=typeof window&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),v=u?65:75,f=Math.PI/2-.01;let g=class extends l{constructor(){super(...arguments),this.viewController=h(d),this.world=h(m),this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.near=.05,this.far=500,this.viewAngle=v,this.eyeHeight=1.7,this.offsetX=0,this.offsetZ=0,this.autoActivate=!0,this.activated=!1,this.isMouseLocked=!1,this.rotationInput=new c(-f,f),this.camera=new s(this.viewAngle,this.aspect,this.near,this.far),this.viewModelRoot=new o,this.additivePositionOffset=new r,this.additiveRotationOffset=new i,this.additiveFov=0,this.pointerLockInactivatedAt=null,this.pointerEventsRegistered=!1,this.hiddenObjects=new Map,this.onMouseDown=t=>{this.viewController.paused||this.isMouseLocked||"mouse"!==t.pointerType||this.hideCursor()},this.onKeyDown=t=>{"Escape"===t.key&&this.showCursor()},this.onPointerLockChange=()=>{this.isMouseLocked=null!=document.pointerLockElement||null!=document.mozPointerLockElement,this.isMouseLocked||(this.element.style.cursor="default",this.pointerLockInactivatedAt=performance.now())}}async onInit(){this.applyCameraSettings(),this.camera.add(this.viewModelRoot),this.world.scene.add(this.camera),this.rotationInput.rotation.x=0,this.updateCameraTransform(),this.disposed.subscribe(()=>{this.unregisterPointerEvents(),this.restoreHiddenObjects(),this.camera.removeFromParent()}),this.autoActivate&&this.activate()}activate(){this.activated=!0,this.updateCameraTransform(),this.viewController.setCamera(this.camera),this.isMouseLocked=null!=document.pointerLockElement||null!=document.mozPointerLockElement,this.registerPointerEvents()}deactivate(){this.activated=!1,this.isMouseLocked=!1,this.unregisterPointerEvents()}onLateUpdate(){this.activated&&this.updateCameraTransform()}hideCursor(){if(null!=this.pointerLockInactivatedAt&&performance.now()-this.pointerLockInactivatedAt<1600)return;this.element.style.cursor="none";const t=this.element.getElementsByTagName("canvas")[0];if(null!=t&&t.isConnected&&t.ownerDocument===document&&null!=t.requestPointerLock)try{const e=t.requestPointerLock({unadjustedMovement:!0});e?.catch(this.onPointerLockChange)}catch{this.onPointerLockChange()}else this.onPointerLockChange()}showCursor(){this.pointerLockInactivatedAt=performance.now(),this.element.style.cursor="default",null==document.pointerLockElement&&null==document.mozPointerLockElement||window.document.exitPointerLock(),this.isMouseLocked=!1}getAimOrigin(t){return this.camera.updateWorldMatrix(!0,!1),this.camera.getWorldPosition(t)}getAimDirection(t){return this.camera.updateWorldMatrix(!0,!1),this.camera.getWorldDirection(t)}getAimRay(t){return this.getAimOrigin(t.origin),this.getAimDirection(t.direction),t}hideObjects(...t){for(const e of t)null==e||this.hiddenObjects.has(e)||(this.hiddenObjects.set(e,e.visible),e.visible=!1)}restoreHiddenObjects(){for(const[t,e]of this.hiddenObjects)t.visible=e;this.hiddenObjects.clear()}get element(){return this.viewController.htmlElement}registerPointerEvents(){if(this.pointerEventsRegistered||null==document.body.requestPointerLock)return;const t=this.element;t.addEventListener("pointerdown",this.onMouseDown),t.addEventListener("keydown",this.onKeyDown),document.addEventListener("pointerlockchange",this.onPointerLockChange,!1),this.pointerEventsRegistered=!0}unregisterPointerEvents(){if(!this.pointerEventsRegistered)return;const t=this.element;t.removeEventListener("pointerdown",this.onMouseDown),t.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("pointerlockchange",this.onPointerLockChange,!1),this.pointerEventsRegistered=!1}applyCameraSettings(){const t=this.viewAngle+this.additiveFov;this.camera.near===this.near&&this.camera.far===this.far&&this.camera.fov===t&&this.camera.aspect===this.aspect||(this.camera.near=this.near,this.camera.far=this.far,this.camera.fov=t,this.camera.aspect=this.aspect,this.camera.updateProjectionMatrix())}updateCameraTransform(){this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.applyCameraSettings(),this.actor.object.updateWorldMatrix(!0,!1),w.set(this.offsetX,this.eyeHeight,this.offsetZ),this.camera.position.copy(w.applyMatrix4(this.actor.object.matrixWorld)),this.actor.object.getWorldQuaternion(L),C.set(-this.rotationInput.rotation.x,0,0),E.setFromEuler(C),this.camera.quaternion.copy(L).multiply(k).multiply(E),this.additivePositionOffset.lengthSq()>0&&(y.copy(this.additivePositionOffset).applyQuaternion(this.camera.quaternion),this.camera.position.add(y)),0===this.additiveRotationOffset.x&&0===this.additiveRotationOffset.y&&0===this.additiveRotationOffset.z||(P.setFromEuler(this.additiveRotationOffset),this.camera.quaternion.multiply(P)),this.camera.updateMatrixWorld(!0)}};t([a(),e("design:type",Number)],g.prototype,"near",void 0),t([a(),e("design:type",Number)],g.prototype,"far",void 0),t([a(),e("design:type",Number)],g.prototype,"viewAngle",void 0),t([a(),e("design:type",Number)],g.prototype,"eyeHeight",void 0),t([a(),e("design:type",Number)],g.prototype,"offsetX",void 0),t([a(),e("design:type",Number)],g.prototype,"offsetZ",void 0),g=t([p()],g);export{g as FirstPersonCameraComponent};const w=new r,y=new r,L=new n,k=(new n).setFromEuler(new i(0,Math.PI,0)),E=new n,P=new n,C=new i;/*
2
2
  * Copyright (©) 2026 Hology Interactive AB. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -1,10 +1,15 @@
1
1
  import { ActorComponent } from '../component.js';
2
2
  import { Vector3, PerspectiveCamera } from 'three';
3
3
  import { DecimalInput, RestrictedRotationInput } from '../../input/index.js';
4
+ import type { BaseActor } from '../actor.js';
4
5
  export type TemporaryThirdPersonCameraControlOptions = {
5
6
  blendInDuration?: number;
6
7
  blendOutDuration?: number;
7
8
  fieldOfView?: number;
9
+ /** Subject whose body should be ignored when checking the temporary shot. */
10
+ collisionExcludeActor?: BaseActor;
11
+ /** Minimum usable temporary shot distance, independent of gameplay orbit limits. */
12
+ minimumDistance?: number;
8
13
  };
9
14
  /**
10
15
  * A camera that is behind the actor.
@@ -57,6 +62,8 @@ export declare class ThirdPersonCameraComponent extends ActorComponent {
57
62
  private temporaryControlPositionEnabled;
58
63
  private temporaryControlBaseFieldOfView;
59
64
  private temporaryControlFieldOfView;
65
+ private temporaryControlCollisionExcludeActor?;
66
+ private temporaryControlMinimumDistance;
60
67
  private readonly temporaryControlPosition;
61
68
  private readonly temporaryControlLookAt;
62
69
  onInit(): Promise<void>;
@@ -1,4 +1,4 @@
1
- import{__decorate as t,__metadata as o}from"tslib";import{ActorComponent as e,Component as i}from"../component.js";import{Vector3 as s,MathUtils as r,PerspectiveCamera as n,Object3D as h}from"three";import{ViewController as a}from"../../services/render.js";import{DecimalInput as l,RestrictedRotationInput as c}from"../../input/index.js";import{PhysicsSystem as d}from"../../services/physics/physics-system.js";import{Parameter as p}from"../../../shader/parameter.js";import{World as m}from"../../services/world.js";import{inject as u}from"../../inject.js";import{ease as y}from"@hology/nebula";const f=void 0!==window&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let C=class extends e{constructor(){super(),this.viewController=u(a),this.physicsSystem=u(d),this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.near=.1,this.far=500,this.viewAngle=f?30:45,this.collision=!0,this.collisionSphereRadius=.25,this.smoothCamera=!1,this.smoothSpeed=10,this.teleportSnapDistance=5,this.camera=new n(this.viewAngle,this.aspect,this.near,this.far),this.distance=9,this.minDistance=1.5,this.maxDistance=this.distance,this.height=3,this.offsetX=-1,this.offsetY=2,this.offsetZ=1.5,this.shoulderOffset=0,this.autoActivate=!0,this.bounceBackSpeed=3,this.restrictedDistance=0,this.hasCollisionRestriction=!1,this.rotationInput=new c(-Math.PI/4,Math.PI/2-.7),this.zoomInput=new l(1,0,1),this.offset=new s,this.shoulderTranslation=new s,this.lookAtOffset=new s(this.offsetX,0,this.offsetZ),this.fixedBehind=!0,this.world=u(m),this.activated=!1,this.isMouseLocked=!1,this.prevFixedBehind=!1,this.blendDurationLeft=0,this.pointerEventsRegistered=!1,this.temporaryControlActive=!1,this.temporaryControlWeight=0,this.temporaryControlTargetWeight=0,this.temporaryControlBlendInDuration=.5,this.temporaryControlBlendOutDuration=.5,this.temporaryControlPositionEnabled=!1,this.temporaryControlBaseFieldOfView=this.camera.fov,this.temporaryControlFieldOfView=null,this.temporaryControlPosition=new s,this.temporaryControlLookAt=new s,this.pointerLockInactivatedAt=null,this.onMouseDown=t=>{this.isMouseLocked||"mouse"!==t.pointerType||this.hideCursor()},this.onKeyDown=t=>{"Escape"===t.key&&this.showCursor()},this.onPointerLockChange=()=>{this.isMouseLocked=null!=document.pointerLockElement||null!=document.mozPointerLockElement,this.element.style.cursor=this.isMouseLocked?"none":"default",this.isMouseLocked||(this.pointerLockInactivatedAt=performance.now())},this.prevLookAt=new s,this.smoothedLookAt=new s,this.previousTargetLookAt=new s,this.hasSmoothedLookAt=!1,this.smoothedRotX=0,this.smoothedRotY=0,this.smoothZoom=0}async onInit(){this.prevFixedBehind=this.fixedBehind,this.world.scene.add(this.camera),this.rotationInput.rotation.copy(this.actor.rotation),this.smoothedRotX=this.rotationInput.rotation.x,this.smoothedRotY=this.rotationInput.rotation.y,this.hasCollisionRestriction=!1,this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.smoothZoom=this.zoomInput.value,this.autoActivate&&this.activate(),this.disposed.subscribe(()=>{this.unregisterPointerEvents()})}activate(){this.activated=!0,this.hasSmoothedLookAt=!1,this.viewController.setCamera(this.camera),this.isMouseLocked=null!=document.pointerLockElement||null!=document.mozPointerLockElement,this.registerPointerEvents()}deactivate(){this.activated=!1,this.isMouseLocked=!1,this.unregisterPointerEvents()}setTemporaryControl(t,o,e={}){this.temporaryControlPosition.copy(t),this.temporaryControlLookAt.copy(o),this.temporaryControlPositionEnabled=!0,this.activateTemporaryControl(e)}setTemporaryLookAt(t,o={}){this.temporaryControlLookAt.copy(t),this.temporaryControlPositionEnabled=!1,this.activateTemporaryControl(o)}activateTemporaryControl(t){this.temporaryControlActive||(this.temporaryControlBaseFieldOfView=this.camera.fov),this.temporaryControlFieldOfView=null==t.fieldOfView?null:r.clamp(t.fieldOfView,1,179),null!=t.blendInDuration&&(this.temporaryControlBlendInDuration=Math.max(0,t.blendInDuration)),null!=t.blendOutDuration&&(this.temporaryControlBlendOutDuration=Math.max(0,t.blendOutDuration)),this.temporaryControlActive=!0,this.temporaryControlTargetWeight=1}clearTemporaryControl(t){this.temporaryControlActive&&(null!=t&&(this.temporaryControlBlendOutDuration=Math.max(0,t)),this.temporaryControlTargetWeight=0)}registerPointerEvents(){if(this.pointerEventsRegistered||null==document.body.requestPointerLock)return;const t=this.element;t.addEventListener("pointerdown",this.onMouseDown),t.addEventListener("keydown",this.onKeyDown),document.addEventListener("pointerlockchange",this.onPointerLockChange,!1),this.pointerEventsRegistered=!0}unregisterPointerEvents(){if(!this.pointerEventsRegistered)return;const t=this.element;t.removeEventListener("pointerdown",this.onMouseDown),t.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("pointerlockchange",this.onPointerLockChange,!1),this.pointerEventsRegistered=!1}onLateUpdate(t){this.activated&&this.setFromRotation(t)}get element(){return this.viewController.htmlElement}hideCursor({ignoreRecentUnlock:t=!1}={}){const o=!1!==navigator.pointerLockRequiresCooldown;!t&&o&&null!=this.pointerLockInactivatedAt&&performance.now()-this.pointerLockInactivatedAt<1600||this.requestPointerLock()}requestPointerLock(){const t=this.element.getElementsByTagName("canvas")[0],o=null!=t?.requestPointerLock?t:null!=this.element.requestPointerLock?this.element:null;if(null!=o)try{const t=o.requestPointerLock({unadjustedMovement:!0});t?.catch(()=>this.onPointerLockChange())}catch{this.onPointerLockChange()}else this.onPointerLockChange()}showCursor(){this.pointerLockInactivatedAt=performance.now(),this.element.style.cursor="default",null==document.pointerLockElement&&null==document.mozPointerLockElement||window.document.exitPointerLock(),this.isMouseLocked=!1}setFromRotation(t){this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.fixedBehind!==this.prevFixedBehind?(this.blendDurationLeft=1,this.prevFixedBehind=this.fixedBehind):this.blendDurationLeft>0&&(this.blendDurationLeft-=t);let o=this.zoomInput.value,e=this.rotationInput.rotation.x,i=this.rotationInput.rotation.y;if(this.smoothCamera){const s=1-Math.exp(-this.smoothSpeed*t*2);this.smoothedRotX=r.lerp(this.smoothedRotX,e,s),this.smoothedRotY=r.lerp(this.smoothedRotY,i,s),e=this.smoothedRotX,i=this.smoothedRotY,this.smoothZoom=r.lerp(this.smoothZoom,o,.4*s),o=this.smoothZoom}else this.smoothedRotX=e,this.smoothedRotY=i;const s=r.clamp(this.distance,this.minDistance,Math.max(this.distance*o,this.minDistance)),n=Math.cos(e)*s,h=this.fixedBehind?0:i;this.fixedBehind?(this.actor.object.updateWorldMatrix(!0,!1),this.shoulderTranslation.set(-1,0,0).transformDirection(this.actor.object.matrixWorld)):this.shoulderTranslation.set(-Math.cos(h),0,Math.sin(h)),this.shoulderTranslation.multiplyScalar(this.shoulderOffset),this.offset.x=Math.sin(-h)*n,this.offset.y=Math.sin(e)*s+this.offsetY,this.offset.z=Math.cos(-h)*-n,this.fixedBehind&&this.offset.add(this.lookAtOffset),this.updateCameraPosition(t)}checkForCollision(t,o){const e=g.subVectors(this.camera.position,t),i=e.length();if(i<.001)return;e.divideScalar(i);const s=this.physicsSystem.sphereCast(t,this.collisionSphereRadius,e,i,void 0,{excludeActor:this.actor,excludeTriggers:!0,collisionFilter:-2}),n=s.hasHit?Math.max(this.minDistance,s.distance-.05):i;if(!this.hasCollisionRestriction||n<=this.restrictedDistance)this.restrictedDistance=n,this.hasCollisionRestriction=!0;else{const t=1-Math.exp(-this.bounceBackSpeed*o);this.restrictedDistance=r.lerp(this.restrictedDistance,n,t)}this.camera.position.copy(t).addScaledVector(e,Math.min(i,this.restrictedDistance))}getLookAtPosition(){const t=k;return t.set(0,0,0),t.y=this.height,this.fixedBehind&&t.add(this.lookAtOffset),t.applyMatrix4(this.actor.object.matrixWorld),t.add(this.shoulderTranslation),t}updateCameraPosition(t){this.actor.object.updateWorldMatrix(!0,!1),this.fixedBehind?(v.position.set(this.offset.x,this.offset.y,this.offset.z),v.rotation.set(0,0,0),v.scale.set(1,1,1),v.applyMatrix4(this.actor.object.matrix)):v.position.copy(this.actor.position).add(this.offset),v.position.add(this.shoulderTranslation);const o=y.easeInOutCubic(1-this.blendDurationLeft);if(this.blendDurationLeft>0){const t=this.getLookAtPosition();this.prevLookAt.lerp(t,o),this.camera.lookAt(this.prevLookAt),this.camera.position.lerp(v.position,o),this.smoothedLookAt.copy(this.prevLookAt),this.previousTargetLookAt.copy(t),this.hasSmoothedLookAt=!0}else{const o=this.getLookAtPosition();if(this.smoothCamera){const e=1-Math.exp(-this.smoothSpeed*t),i=Math.max(0,this.teleportSnapDistance);!this.hasSmoothedLookAt||this.previousTargetLookAt.distanceToSquared(o)>i*i?this.smoothedLookAt.copy(o):this.smoothedLookAt.lerp(o,e)}else this.smoothedLookAt.copy(o);this.previousTargetLookAt.copy(o),this.hasSmoothedLookAt=!0,L.subVectors(v.position,o),this.camera.position.copy(this.smoothedLookAt).add(L),this.camera.lookAt(this.smoothedLookAt),this.prevLookAt.copy(this.smoothedLookAt)}this.collision&&(this.checkForCollision(this.prevLookAt,t),this.camera.lookAt(this.prevLookAt)),this.applyTemporaryControl(t)}applyTemporaryControl(t){if(!this.temporaryControlActive)return;this.temporaryControlTargetWeight>this.temporaryControlWeight?this.temporaryControlWeight=0===this.temporaryControlBlendInDuration?1:Math.min(1,this.temporaryControlWeight+t/this.temporaryControlBlendInDuration):this.temporaryControlTargetWeight<this.temporaryControlWeight&&(this.temporaryControlWeight=0===this.temporaryControlBlendOutDuration?0:Math.max(0,this.temporaryControlWeight-t/this.temporaryControlBlendOutDuration));const o=y.easeInOutCubic(this.temporaryControlWeight);this.temporaryControlPositionEnabled&&this.camera.position.lerp(this.getTemporaryControlPosition(),o),x.position.copy(this.camera.position),x.up.copy(this.camera.up),x.lookAt(this.temporaryControlLookAt),this.camera.quaternion.slerp(x.quaternion,o);const e=this.temporaryControlFieldOfView??this.temporaryControlBaseFieldOfView,i=r.lerp(this.temporaryControlBaseFieldOfView,e,o);this.camera.fov!==i&&(this.camera.fov=i,this.camera.updateProjectionMatrix()),0===this.temporaryControlTargetWeight&&0===this.temporaryControlWeight&&(this.temporaryControlActive=!1)}getTemporaryControlPosition(){if(!this.collision)return this.temporaryControlPosition;A.subVectors(this.temporaryControlPosition,this.temporaryControlLookAt);const t=A.length();if(t<.001)return this.temporaryControlPosition;A.divideScalar(t);const o=this.physicsSystem.sphereCast(this.temporaryControlLookAt,this.collisionSphereRadius,A,t,void 0,{excludeActor:this.actor,excludeTriggers:!0,collisionFilter:-2});return!o.hasHit||o.distance>=t?this.temporaryControlPosition:w.copy(this.temporaryControlLookAt).addScaledVector(A,Math.max(0,o.distance-.05))}};t([p(),o("design:type",Number)],C.prototype,"near",void 0),t([p(),o("design:type",Number)],C.prototype,"far",void 0),t([p(),o("design:type",Number)],C.prototype,"viewAngle",void 0),t([p(),o("design:type",Boolean)],C.prototype,"collision",void 0),t([p(),o("design:type",Number)],C.prototype,"collisionSphereRadius",void 0),t([p(),o("design:type",Boolean)],C.prototype,"smoothCamera",void 0),t([p(),o("design:type",Number)],C.prototype,"smoothSpeed",void 0),t([p(),o("design:type",Number)],C.prototype,"teleportSnapDistance",void 0),t([p(),o("design:type",Number)],C.prototype,"shoulderOffset",void 0),C=t([i(),o("design:paramtypes",[])],C);export{C as ThirdPersonCameraComponent};const v=new h,k=new s,L=new s,g=new s,A=new s,w=new s,x=new n;export class ThirdPartyCameraComponent extends C{}/*
1
+ import{__decorate as t,__metadata as o}from"tslib";import{ActorComponent as e,Component as i}from"../component.js";import{Vector3 as s,MathUtils as r,PerspectiveCamera as n,Object3D as h}from"three";import{ViewController as a}from"../../services/render.js";import{DecimalInput as l,RestrictedRotationInput as c}from"../../input/index.js";import{PhysicsSystem as m}from"../../services/physics/physics-system.js";import{Parameter as p}from"../../../shader/parameter.js";import{World as d}from"../../services/world.js";import{inject as u}from"../../inject.js";import{ease as y}from"@hology/nebula";const f=void 0!==window&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let C=class extends e{constructor(){super(),this.viewController=u(a),this.physicsSystem=u(m),this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.near=.1,this.far=500,this.viewAngle=f?30:45,this.collision=!0,this.collisionSphereRadius=.25,this.smoothCamera=!1,this.smoothSpeed=10,this.teleportSnapDistance=5,this.camera=new n(this.viewAngle,this.aspect,this.near,this.far),this.distance=9,this.minDistance=1.5,this.maxDistance=this.distance,this.height=3,this.offsetX=-1,this.offsetY=2,this.offsetZ=1.5,this.shoulderOffset=0,this.autoActivate=!0,this.bounceBackSpeed=3,this.restrictedDistance=0,this.hasCollisionRestriction=!1,this.rotationInput=new c(-Math.PI/4,Math.PI/2-.7),this.zoomInput=new l(1,0,1),this.offset=new s,this.shoulderTranslation=new s,this.lookAtOffset=new s(this.offsetX,0,this.offsetZ),this.fixedBehind=!0,this.world=u(d),this.activated=!1,this.isMouseLocked=!1,this.prevFixedBehind=!1,this.blendDurationLeft=0,this.pointerEventsRegistered=!1,this.temporaryControlActive=!1,this.temporaryControlWeight=0,this.temporaryControlTargetWeight=0,this.temporaryControlBlendInDuration=.5,this.temporaryControlBlendOutDuration=.5,this.temporaryControlPositionEnabled=!1,this.temporaryControlBaseFieldOfView=this.camera.fov,this.temporaryControlFieldOfView=null,this.temporaryControlMinimumDistance=.75,this.temporaryControlPosition=new s,this.temporaryControlLookAt=new s,this.pointerLockInactivatedAt=null,this.onMouseDown=t=>{this.viewController.paused||this.isMouseLocked||"mouse"!==t.pointerType||this.hideCursor()},this.onKeyDown=t=>{"Escape"===t.key&&this.showCursor()},this.onPointerLockChange=()=>{this.isMouseLocked=null!=document.pointerLockElement||null!=document.mozPointerLockElement,this.element.style.cursor=this.isMouseLocked?"none":"default",this.isMouseLocked||(this.pointerLockInactivatedAt=performance.now())},this.prevLookAt=new s,this.smoothedLookAt=new s,this.previousTargetLookAt=new s,this.hasSmoothedLookAt=!1,this.smoothedRotX=0,this.smoothedRotY=0,this.smoothZoom=0}async onInit(){this.prevFixedBehind=this.fixedBehind,this.world.scene.add(this.camera),this.rotationInput.rotation.copy(this.actor.rotation),this.smoothedRotX=this.rotationInput.rotation.x,this.smoothedRotY=this.rotationInput.rotation.y,this.hasCollisionRestriction=!1,this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.smoothZoom=this.zoomInput.value,this.autoActivate&&this.activate(),this.disposed.subscribe(()=>{this.unregisterPointerEvents()})}activate(){this.activated=!0,this.hasSmoothedLookAt=!1,this.viewController.setCamera(this.camera),this.isMouseLocked=null!=document.pointerLockElement||null!=document.mozPointerLockElement,this.registerPointerEvents()}deactivate(){this.activated=!1,this.isMouseLocked=!1,this.unregisterPointerEvents()}setTemporaryControl(t,o,e={}){this.temporaryControlPosition.copy(t),this.temporaryControlLookAt.copy(o),this.temporaryControlPositionEnabled=!0,this.activateTemporaryControl(e)}setTemporaryLookAt(t,o={}){this.temporaryControlLookAt.copy(t),this.temporaryControlPositionEnabled=!1,this.activateTemporaryControl(o)}activateTemporaryControl(t){this.temporaryControlCollisionExcludeActor=t.collisionExcludeActor,this.temporaryControlMinimumDistance=Math.max(0,t.minimumDistance??.75),this.temporaryControlActive||(this.temporaryControlBaseFieldOfView=this.camera.fov),this.temporaryControlFieldOfView=null==t.fieldOfView?null:r.clamp(t.fieldOfView,1,179),null!=t.blendInDuration&&(this.temporaryControlBlendInDuration=Math.max(0,t.blendInDuration)),null!=t.blendOutDuration&&(this.temporaryControlBlendOutDuration=Math.max(0,t.blendOutDuration)),this.temporaryControlActive=!0,this.temporaryControlTargetWeight=1}clearTemporaryControl(t){this.temporaryControlActive&&(null!=t&&(this.temporaryControlBlendOutDuration=Math.max(0,t)),this.temporaryControlTargetWeight=0)}registerPointerEvents(){if(this.pointerEventsRegistered||null==document.body.requestPointerLock)return;const t=this.element;t.addEventListener("pointerdown",this.onMouseDown),t.addEventListener("keydown",this.onKeyDown),document.addEventListener("pointerlockchange",this.onPointerLockChange,!1),this.pointerEventsRegistered=!0}unregisterPointerEvents(){if(!this.pointerEventsRegistered)return;const t=this.element;t.removeEventListener("pointerdown",this.onMouseDown),t.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("pointerlockchange",this.onPointerLockChange,!1),this.pointerEventsRegistered=!1}onLateUpdate(t){this.activated&&this.setFromRotation(t)}get element(){return this.viewController.htmlElement}hideCursor({ignoreRecentUnlock:t=!1}={}){const o=!1!==navigator.pointerLockRequiresCooldown;!t&&o&&null!=this.pointerLockInactivatedAt&&performance.now()-this.pointerLockInactivatedAt<1600||this.requestPointerLock()}requestPointerLock(){const t=this.element.getElementsByTagName("canvas")[0],o=null!=t?.requestPointerLock?t:null!=this.element.requestPointerLock?this.element:null;if(null!=o)try{const t=o.requestPointerLock({unadjustedMovement:!0});t?.catch(()=>this.onPointerLockChange())}catch{this.onPointerLockChange()}else this.onPointerLockChange()}showCursor(){this.pointerLockInactivatedAt=performance.now(),this.element.style.cursor="default",null==document.pointerLockElement&&null==document.mozPointerLockElement||window.document.exitPointerLock(),this.isMouseLocked=!1}setFromRotation(t){this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.fixedBehind!==this.prevFixedBehind?(this.blendDurationLeft=1,this.prevFixedBehind=this.fixedBehind):this.blendDurationLeft>0&&(this.blendDurationLeft-=t);let o=this.zoomInput.value,e=this.rotationInput.rotation.x,i=this.rotationInput.rotation.y;if(this.smoothCamera){const s=1-Math.exp(-this.smoothSpeed*t*2);this.smoothedRotX=r.lerp(this.smoothedRotX,e,s),this.smoothedRotY=r.lerp(this.smoothedRotY,i,s),e=this.smoothedRotX,i=this.smoothedRotY,this.smoothZoom=r.lerp(this.smoothZoom,o,.4*s),o=this.smoothZoom}else this.smoothedRotX=e,this.smoothedRotY=i;const s=r.clamp(this.distance,this.minDistance,Math.max(this.distance*o,this.minDistance)),n=Math.cos(e)*s,h=this.fixedBehind?0:i;this.fixedBehind?(this.actor.object.updateWorldMatrix(!0,!1),this.shoulderTranslation.set(-1,0,0).transformDirection(this.actor.object.matrixWorld)):this.shoulderTranslation.set(-Math.cos(h),0,Math.sin(h)),this.shoulderTranslation.multiplyScalar(this.shoulderOffset),this.offset.x=Math.sin(-h)*n,this.offset.y=Math.sin(e)*s+this.offsetY,this.offset.z=Math.cos(-h)*-n,this.fixedBehind&&this.offset.add(this.lookAtOffset),this.updateCameraPosition(t)}checkForCollision(t,o){const e=g.subVectors(this.camera.position,t),i=e.length();if(i<.001)return;e.divideScalar(i);const s=this.physicsSystem.sphereCast(t,this.collisionSphereRadius,e,i,void 0,{excludeActor:this.actor,excludeTriggers:!0,collisionFilter:-2}),n=s.hasHit?Math.max(this.minDistance,s.distance-.05):i;if(!this.hasCollisionRestriction||n<=this.restrictedDistance)this.restrictedDistance=n,this.hasCollisionRestriction=!0;else{const t=1-Math.exp(-this.bounceBackSpeed*o);this.restrictedDistance=r.lerp(this.restrictedDistance,n,t)}this.camera.position.copy(t).addScaledVector(e,Math.min(i,this.restrictedDistance))}getLookAtPosition(){const t=k;return t.set(0,0,0),t.y=this.height,this.fixedBehind&&t.add(this.lookAtOffset),t.applyMatrix4(this.actor.object.matrixWorld),t.add(this.shoulderTranslation),t}updateCameraPosition(t){this.actor.object.updateWorldMatrix(!0,!1),this.fixedBehind?(v.position.set(this.offset.x,this.offset.y,this.offset.z),v.rotation.set(0,0,0),v.scale.set(1,1,1),v.applyMatrix4(this.actor.object.matrix)):v.position.copy(this.actor.position).add(this.offset),v.position.add(this.shoulderTranslation);const o=y.easeInOutCubic(1-this.blendDurationLeft);if(this.blendDurationLeft>0){const t=this.getLookAtPosition();this.prevLookAt.lerp(t,o),this.camera.lookAt(this.prevLookAt),this.camera.position.lerp(v.position,o),this.smoothedLookAt.copy(this.prevLookAt),this.previousTargetLookAt.copy(t),this.hasSmoothedLookAt=!0}else{const o=this.getLookAtPosition();if(this.smoothCamera){const e=1-Math.exp(-this.smoothSpeed*t),i=Math.max(0,this.teleportSnapDistance);!this.hasSmoothedLookAt||this.previousTargetLookAt.distanceToSquared(o)>i*i?this.smoothedLookAt.copy(o):this.smoothedLookAt.lerp(o,e)}else this.smoothedLookAt.copy(o);this.previousTargetLookAt.copy(o),this.hasSmoothedLookAt=!0,L.subVectors(v.position,o),this.camera.position.copy(this.smoothedLookAt).add(L),this.camera.lookAt(this.smoothedLookAt),this.prevLookAt.copy(this.smoothedLookAt)}this.collision&&(this.checkForCollision(this.prevLookAt,t),this.camera.lookAt(this.prevLookAt)),this.applyTemporaryControl(t)}applyTemporaryControl(t){if(!this.temporaryControlActive)return;this.temporaryControlTargetWeight>this.temporaryControlWeight?this.temporaryControlWeight=0===this.temporaryControlBlendInDuration?1:Math.min(1,this.temporaryControlWeight+t/this.temporaryControlBlendInDuration):this.temporaryControlTargetWeight<this.temporaryControlWeight&&(this.temporaryControlWeight=0===this.temporaryControlBlendOutDuration?0:Math.max(0,this.temporaryControlWeight-t/this.temporaryControlBlendOutDuration));let o=y.easeInOutCubic(this.temporaryControlWeight);if(this.temporaryControlPositionEnabled){const t=this.getTemporaryControlPosition();null==t?o=0:this.camera.position.lerp(t,o)}x.position.copy(this.camera.position),x.up.copy(this.camera.up),x.lookAt(this.temporaryControlLookAt),this.camera.quaternion.slerp(x.quaternion,o);const e=this.temporaryControlFieldOfView??this.temporaryControlBaseFieldOfView,i=r.lerp(this.temporaryControlBaseFieldOfView,e,o);this.camera.fov!==i&&(this.camera.fov=i,this.camera.updateProjectionMatrix()),0===this.temporaryControlTargetWeight&&0===this.temporaryControlWeight&&(this.temporaryControlActive=!1,this.temporaryControlCollisionExcludeActor=void 0)}getTemporaryControlPosition(){if(!this.collision)return this.temporaryControlPosition;A.subVectors(this.temporaryControlPosition,this.temporaryControlLookAt);const t=A.length();if(t<.001)return this.temporaryControlPosition;A.divideScalar(t);const o=this.physicsSystem.sphereCast(this.temporaryControlLookAt,this.collisionSphereRadius,A,t,void 0,{excludeActor:this.temporaryControlCollisionExcludeActor??this.actor,stopAtPenetration:!1,excludeTriggers:!0,collisionFilter:-2});return!o.hasHit||o.distance>=t?this.temporaryControlPosition:o.distance-.05<this.temporaryControlMinimumDistance?null:w.copy(this.temporaryControlLookAt).addScaledVector(A,Math.max(0,o.distance-.05))}};t([p(),o("design:type",Number)],C.prototype,"near",void 0),t([p(),o("design:type",Number)],C.prototype,"far",void 0),t([p(),o("design:type",Number)],C.prototype,"viewAngle",void 0),t([p(),o("design:type",Boolean)],C.prototype,"collision",void 0),t([p(),o("design:type",Number)],C.prototype,"collisionSphereRadius",void 0),t([p(),o("design:type",Boolean)],C.prototype,"smoothCamera",void 0),t([p(),o("design:type",Number)],C.prototype,"smoothSpeed",void 0),t([p(),o("design:type",Number)],C.prototype,"teleportSnapDistance",void 0),t([p(),o("design:type",Number)],C.prototype,"shoulderOffset",void 0),C=t([i(),o("design:paramtypes",[])],C);export{C as ThirdPersonCameraComponent};const v=new h,k=new s,L=new s,g=new s,A=new s,w=new s,x=new n;export class ThirdPartyCameraComponent extends C{}/*
2
2
  * Copyright (©) 2026 Hology Interactive AB. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -21,6 +21,11 @@ export declare class CharacterMoveToNode extends LeafNode {
21
21
  * expressed relative to that facing so characters can strafe or backpedal. */
22
22
  facingTarget?: () => Vector3 | null | undefined;
23
23
  constructor(navigation: Navigation, movement: CharacterMovementLike);
24
+ /** Opt-in diagnostics of the last tick. Treat path points as read-only.
25
+ * Retains the existing navigation result without copying or issuing another query. */
26
+ captureDebugPath: boolean;
27
+ debugPath: readonly Vector3[] | undefined;
28
+ debugPathValid: boolean;
24
29
  private cardinalAxis?;
25
30
  tick(dt: number): NodeState;
26
31
  stop(): void;
@@ -1,4 +1,4 @@
1
- import{Vector3 as t}from"three";import{LeafNode as i,NodeState as e}from"./bt.js";export class CharacterMoveToNode extends i{constructor(t,i){super(),this.navigation=t,this.movement=i,this.distanceFrom=.5,this.speedScale=1,this.lateralSpeedScale=1,this.cardinalMovement=!1}tick(t){const i=this.movement.actor.object.position,s=null!=this.target?this.target():null;if(null==s)return this.movement.directionInput.vector.set(0,0),this.cardinalAxis=void 0,e.FAILURE;if(i.distanceTo(s)<this.distanceFrom)return this.movement.directionInput.vector.set(0,0),this.cardinalAxis=void 0,e.SUCCESS;const{success:a,path:o}=this.navigation.findPath(i,s);if(!a||o.length<2)return this.movement.directionInput.vector.set(0,0),this.cardinalAxis=void 0,e.FAILURE;const r=o[1],c=n.subVectors(r,i);c.y=0,c.normalize();const h=this.facingTarget?.(),l=null!=h?h.x-i.x:0,m=null!=h?h.z-i.z:0,d=l*l+m*m;if(null!=h&&d>1e-4){const t=Math.atan2(l,m),i=1/Math.sqrt(d),e=l*i,n=m*i,s=n,a=-e;this.movement.rotationInput.rotation.y=t,this.movement.directionInput.vector.set(-(c.x*s+c.z*a),c.x*e+c.z*n)}else this.movement.rotationInput.rotation.y=Math.atan2(c.x,c.z),this.movement.directionInput.vector.set(0,1);return this.cardinalMovement&&this.snapInputToCardinalAxis(),Math.abs(this.movement.directionInput.vector.x)>Math.abs(this.movement.directionInput.vector.y)&&this.movement.directionInput.vector.multiplyScalar(Math.max(0,Math.min(1,this.lateralSpeedScale))),this.movement.directionInput.vector.multiplyScalar(Math.max(0,Math.min(1,this.speedScale))),e.RUNNING}stop(){this.cardinalAxis=void 0}snapInputToCardinalAxis(){const t=this.movement.directionInput.vector,i=Math.abs(t.x),e=Math.abs(t.y);if(i+e<=1e-4)return void(this.cardinalAxis=void 0);const n=i>e?"x":"y";if(null==this.cardinalAxis)this.cardinalAxis=n;else{const t="x"===this.cardinalAxis?i:e;("x"===this.cardinalAxis?e:i)>t*s&&(this.cardinalAxis="x"===this.cardinalAxis?"y":"x")}"x"===this.cardinalAxis?t.set(Math.sign(t.x),0):t.set(0,Math.sign(t.y))}}const n=new t,s=1.25;/*
1
+ import{Vector3 as t}from"three";import{LeafNode as i,NodeState as e}from"./bt.js";export class CharacterMoveToNode extends i{constructor(t,i){super(),this.navigation=t,this.movement=i,this.distanceFrom=.5,this.speedScale=1,this.lateralSpeedScale=1,this.cardinalMovement=!1,this.captureDebugPath=!1,this.debugPathValid=!1}tick(t){this.debugPath=void 0,this.debugPathValid=!1;const i=this.movement.actor.object.position,n=null!=this.target?this.target():null;if(null==n)return this.movement.directionInput.vector.set(0,0),this.cardinalAxis=void 0,e.FAILURE;if(i.distanceTo(n)<this.distanceFrom)return this.movement.directionInput.vector.set(0,0),this.cardinalAxis=void 0,e.SUCCESS;const{success:a,path:o}=this.navigation.findPath(i,n);if(this.captureDebugPath&&(this.debugPath=o,this.debugPathValid=a&&o.length>=2),!a||o.length<2)return this.movement.directionInput.vector.set(0,0),this.cardinalAxis=void 0,e.FAILURE;const r=o[1],h=s.subVectors(r,i);h.y=0,h.normalize();const c=this.facingTarget?.(),l=null!=c?c.x-i.x:0,d=null!=c?c.z-i.z:0,m=l*l+d*d;if(null!=c&&m>1e-4){const t=Math.atan2(l,d),i=1/Math.sqrt(m),e=l*i,s=d*i,n=s,a=-e;this.movement.rotationInput.rotation.y=t,this.movement.directionInput.vector.set(-(h.x*n+h.z*a),h.x*e+h.z*s)}else this.movement.rotationInput.rotation.y=Math.atan2(h.x,h.z),this.movement.directionInput.vector.set(0,1);return this.cardinalMovement&&this.snapInputToCardinalAxis(),Math.abs(this.movement.directionInput.vector.x)>Math.abs(this.movement.directionInput.vector.y)&&this.movement.directionInput.vector.multiplyScalar(Math.max(0,Math.min(1,this.lateralSpeedScale))),this.movement.directionInput.vector.multiplyScalar(Math.max(0,Math.min(1,this.speedScale))),e.RUNNING}stop(){this.cardinalAxis=void 0}snapInputToCardinalAxis(){const t=this.movement.directionInput.vector,i=Math.abs(t.x),e=Math.abs(t.y);if(i+e<=1e-4)return void(this.cardinalAxis=void 0);const s=i>e?"x":"y";if(null==this.cardinalAxis)this.cardinalAxis=s;else{const t="x"===this.cardinalAxis?i:e;("x"===this.cardinalAxis?e:i)>t*n&&(this.cardinalAxis="x"===this.cardinalAxis?"y":"x")}"x"===this.cardinalAxis?t.set(Math.sign(t.x),0):t.set(0,Math.sign(t.y))}}const s=new t,n=1.25;/*
2
2
  * Copyright (©) 2026 Hology Interactive AB. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=move.test.d.ts.map
@@ -0,0 +1,4 @@
1
+ import{describe as t,expect as e,it as n,vi as o}from"vitest";import{Object3D as a,Vector2 as i,Vector3 as d,Euler as r}from"three";import{CharacterMoveToNode as c}from"./move.js";import{NodeState as u}from"./bt.js";function s(){const t=[new d,new d(0,0,3)],e=o.fn(()=>({success:!0,path:t})),n={actor:{object:new a},directionInput:{vector:new i},rotationInput:{rotation:new r}},u=new c({findPath:e},n);return u.target=()=>t[1],{node:u,findPath:e,movement:n,path:t}}t("movement path diagnostics",()=>{n("observes the exact navigation result without changing input or adding queries",()=>{const{node:t,findPath:n,movement:o,path:a}=s();e(t.tick(.016)).toBe(u.RUNNING);const i=o.directionInput.vector.clone();e(t.debugPath).toBeUndefined(),t.captureDebugPath=!0,e(t.tick(.016)).toBe(u.RUNNING),e(n).toHaveBeenCalledTimes(2),e(t.debugPath).toBe(a),e(t.debugPathValid).toBe(!0),e(o.directionInput.vector).toEqual(i)}),n("distinguishes failed paths from arrival and clears data when disabled",()=>{const{node:t,findPath:n}=s();t.captureDebugPath=!0,t.tick(.016),n.mockReturnValue({success:!1,path:[]}),e(t.tick(.016)).toBe(u.FAILURE),e(t.debugPath).toEqual([]),e(t.debugPathValid).toBe(!1),t.target=()=>new d,e(t.tick(.016)).toBe(u.SUCCESS),e(t.debugPath).toBeUndefined(),e(n).toHaveBeenCalledTimes(2),t.target=()=>new d(0,0,3),t.captureDebugPath=!1,t.tick(.016),e(t.debugPath).toBeUndefined()})});/*
2
+ * Copyright (©) 2026 Hology Interactive AB. All rights reserved.
3
+ * See the LICENSE.md file for details.
4
+ */
@@ -1,4 +1,4 @@
1
- import{AnimationClip as t,Vector3 as o,Quaternion as e,Matrix3 as n,Matrix4 as r}from"three";import{getAnimationClipRigId as i,setAnimationClipRigId as a}from"./retarget.js";import{getAnimationFootContacts as s,setAnimationFootContacts as l}from"./foot-contact.js";export class RootMotionClip extends t{constructor(){super(...arguments),this.displacement=0,this.fixedInPlace=!1}static fromClip(t,c=!1,u,d){const m=new RootMotionClip(t.name,t.duration,t.tracks.slice(),t.blendMode);if(m.fixedInPlace=c,m.rootBone=u,m.animationRoot=d,m.source=t,m.uuid=t.uuid,a(m,i(t)),l(m,s(t)),m.motionTrack=null!=u?t.tracks.find(t=>t.name===`${u.name}.position`):t.tracks.find(t=>t.name.endsWith(".position")),m.motionTrack){m.tracks.splice(m.tracks.indexOf(m.motionTrack),1);const t=(new o).fromArray(m.motionTrack.values,0),i=(new o).fromArray(m.motionTrack.values,m.motionTrack.values.length-3),a=new o(0,1,0);if(null!=u?.parent){u.parent.updateWorldMatrix(!0,!1);const t=u.parent.getWorldQuaternion(new e);a.applyQuaternion(t.invert()).normalize()}const s=m.motionTrack.clone(),l=new o;for(let t=0;t<m.motionTrack.values.length;t+=3){l.fromArray(m.motionTrack.values,t);const o=l.dot(a);l.copy(a).multiplyScalar(o),s.values[t+0]=l.x,s.values[t+1]=l.y,s.values[t+2]=l.z}m.tracks.push(s);const c=i.sub(t);if(c.addScaledVector(a,-c.dot(a)),null!=u?.parent&&null!=d){d.updateWorldMatrix(!0,!1),u.parent.updateWorldMatrix(!0,!1);const t=(new r).copy(d.matrixWorld).invert().multiply(u.parent.matrixWorld);c.applyMatrix3((new n).setFromMatrix4(t))}m.displacement=c.length()}else console.error("Could not find root motion track",t,u);return m}static fromClipWithDistance(t,o){const e=new RootMotionClip(t.name,t.duration,t.tracks.slice(),t.blendMode);return e.fixedInPlace=!0,e.source=t,e.uuid=t.uuid,a(e,i(t)),l(e,s(t)),e.displacement=o,e}clone(){const t=RootMotionClip.fromClip(this.source.clone(),this.fixedInPlace,this.rootBone,this.animationRoot);return t.displacement=this.displacement,l(t,s(this)),t}}let c=53912381;export class BoneLayer{constructor(){this.uuid=c++,this.order=0,this.boneMask=[]}}/*
1
+ import{AnimationClip as t,Vector3 as o,Quaternion as n,Matrix3 as e,Matrix4 as r,PropertyBinding as i}from"three";import{getAnimationClipRigId as a,setAnimationClipRigId as s}from"./retarget.js";import{getAnimationFootContacts as l,setAnimationFootContacts as c}from"./foot-contact.js";export class RootMotionClip extends t{constructor(){super(...arguments),this.displacement=0,this.fixedInPlace=!1}static fromClip(t,d=!1,u,m){if(null==u&&null!=m){const o=t.tracks.find(t=>t.name.endsWith(".position"));if(null!=o){const t=i.parseTrackName(o.name);u=i.findNode(m,t.nodeName)}}const p=new RootMotionClip(t.name,t.duration,t.tracks.slice(),t.blendMode);if(p.fixedInPlace=d,p.rootBone=u,p.animationRoot=m,p.source=t,p.uuid=t.uuid,s(p,a(t)),c(p,l(t)),p.motionTrack=null!=u?t.tracks.find(t=>t.name===`${u.name}.position`):t.tracks.find(t=>t.name.endsWith(".position")),p.motionTrack){p.tracks.splice(p.tracks.indexOf(p.motionTrack),1);const t=(new o).fromArray(p.motionTrack.values,0),i=(new o).fromArray(p.motionTrack.values,p.motionTrack.values.length-3),a=new o(0,1,0);if(null!=u?.parent){u.parent.updateWorldMatrix(!0,!1);const t=u.parent.getWorldQuaternion(new n);a.applyQuaternion(t.invert()).normalize()}const s=p.motionTrack.clone(),l=new o;for(let t=0;t<p.motionTrack.values.length;t+=3){l.fromArray(p.motionTrack.values,t);const o=l.dot(a);l.copy(a).multiplyScalar(o),s.values[t+0]=l.x,s.values[t+1]=l.y,s.values[t+2]=l.z}p.tracks.push(s);const c=i.sub(t);if(c.addScaledVector(a,-c.dot(a)),null!=u?.parent&&null!=m){m.updateWorldMatrix(!0,!1),u.parent.updateWorldMatrix(!0,!1);const t=(new r).copy(m.matrixWorld).invert().multiply(u.parent.matrixWorld);c.applyMatrix3((new e).setFromMatrix4(t))}p.displacement=c.length()}else console.error("Could not find root motion track",t,u);return p}static fromClipWithDistance(t,o){const n=new RootMotionClip(t.name,t.duration,t.tracks.slice(),t.blendMode);return n.fixedInPlace=!0,n.source=t,n.uuid=t.uuid,s(n,a(t)),c(n,l(t)),n.displacement=o,n}clone(){const t=RootMotionClip.fromClip(this.source.clone(),this.fixedInPlace,this.rootBone,this.animationRoot);return t.displacement=this.displacement,c(t,l(this)),t}}let d=53912381;export class BoneLayer{constructor(){this.uuid=d++,this.order=0,this.boneMask=[]}}/*
2
2
  * Copyright (©) 2026 Hology Interactive AB. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -17,6 +17,9 @@ export declare class InputService {
17
17
  private gamepadButtonBinds;
18
18
  private gamepadAxisBinds;
19
19
  private lastActiveDevice;
20
+ private activeGamepadIndex;
21
+ private vibrationActuator?;
22
+ private pauseSubscription?;
20
23
  readonly onDeviceChanged: Subject<InputDevice>;
21
24
  private prevGamepadButtonStates;
22
25
  private suppressedGamepadButtons;
@@ -69,7 +72,12 @@ export declare class InputService {
69
72
  removeWheelbind(name: ActionIdentifier): void;
70
73
  removeGamepadButtonBind(name: ActionIdentifier): void;
71
74
  removeGamepadAxisBind(name: ActionIdentifier): void;
72
- vibrate(duration: number, strongMagnitude?: number, weakMagnitude?: number): void;
75
+ /** Request a pulse in milliseconds on the controller currently providing input. */
76
+ vibrate(duration: number, strongMagnitude?: number, weakMagnitude?: number): boolean;
77
+ stopVibration(): void;
78
+ private onFocusLost;
79
+ private onVisibilityChanged;
80
+ private onGamepadDisconnected;
73
81
  }
74
82
  export {};
75
83
  //# sourceMappingURL=input-service.d.ts.map