@hology/core 0.0.212 → 0.0.213
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/effects/sequence/index.d.ts +1 -0
- package/dist/effects/sequence/index.js +1 -1
- package/dist/effects/sequence/sequence-action.d.ts +5 -0
- package/dist/effects/sequence/sequence-actor.d.ts +7 -0
- package/dist/effects/sequence/sequence-actor.js +1 -1
- package/dist/effects/sequence/sequence-animation-retiming.js +1 -1
- package/dist/effects/sequence/sequence-data.d.ts +9 -0
- package/dist/effects/sequence/sequence-data.js +1 -1
- package/dist/effects/sequence/sequence-player.d.ts +12 -1
- package/dist/effects/sequence/sequence-player.js +1 -1
- package/dist/effects/sequence/sequence-transform.d.ts +10 -0
- package/dist/effects/sequence/sequence-transform.js +4 -0
- package/dist/effects/sequence/sequence-value-lane.d.ts +2 -0
- package/dist/effects/sequence/sequence-value-lane.js +1 -1
- package/dist/effects/vfx/vfx-actor.d.ts +5 -0
- package/dist/effects/vfx/vfx-actor.js +1 -1
- package/dist/effects/vfx/vfx-asset.d.ts +2 -1
- package/dist/effects/vfx/vfx-asset.js +1 -1
- package/dist/effects/vfx/vfx-materializer.js +1 -1
- package/dist/effects/vfx/vfx-renderers.d.ts +1 -0
- package/dist/effects/vfx/vfx-renderers.js +1 -1
- package/dist/gameplay/actors/actor.d.ts +3 -5
- package/dist/gameplay/actors/actor.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/character-animation.d.ts +3 -0
- package/dist/gameplay/actors/builtin/components/character/character-animation.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/character-movement-like.d.ts +2 -0
- package/dist/gameplay/actors/builtin/components/character/character-movement.d.ts +13 -0
- package/dist/gameplay/actors/builtin/components/character/character-movement.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/net-character-movement-protocol.d.ts +4 -1
- package/dist/gameplay/actors/builtin/components/character/net-character-movement-protocol.js +1 -1
- package/dist/gameplay/actors/builtin/components/mesh-component.d.ts +1 -0
- package/dist/gameplay/actors/builtin/components/mesh-component.js +1 -1
- package/dist/gameplay/actors/builtin/components/tween-component.js +1 -1
- package/dist/gameplay/actors/builtin/navmesh-actor.d.ts +2 -0
- package/dist/gameplay/actors/builtin/navmesh-actor.js +1 -1
- package/dist/gameplay/actors/builtin/trigger-volume.d.ts +3 -3
- package/dist/gameplay/actors/builtin/trigger-volume.js +1 -1
- package/dist/gameplay/actors/camera/camera-component.d.ts +1 -3
- package/dist/gameplay/actors/camera/camera-component.js +1 -1
- package/dist/gameplay/actors/component.d.ts +3 -0
- package/dist/gameplay/actors/component.js +1 -1
- package/dist/gameplay/actors/type-registry.d.ts +10 -0
- package/dist/gameplay/actors/type-registry.js +4 -0
- package/dist/gameplay/animation/retarget.d.ts +50 -0
- package/dist/gameplay/animation/retarget.js +4 -0
- package/dist/gameplay/animation/root-motion.js +1 -1
- package/dist/gameplay/event-graph/actor-transform-properties.d.ts +6 -0
- package/dist/gameplay/event-graph/actor-transform-properties.js +4 -0
- package/dist/gameplay/event-graph/asset-actor-types.d.ts +3 -0
- package/dist/gameplay/event-graph/asset-actor-types.js +4 -0
- package/dist/gameplay/event-graph/asset-references.d.ts +12 -0
- package/dist/gameplay/event-graph/asset-references.js +4 -0
- package/dist/gameplay/event-graph/compiler.d.ts +107 -0
- package/dist/gameplay/event-graph/compiler.js +4 -0
- package/dist/gameplay/event-graph/decorators.d.ts +74 -0
- package/dist/gameplay/event-graph/decorators.js +4 -0
- package/dist/gameplay/event-graph/document-compiler.d.ts +107 -0
- package/dist/gameplay/event-graph/document-compiler.js +4 -0
- package/dist/gameplay/event-graph/event-graph-demo.d.ts +2 -0
- package/dist/gameplay/event-graph/event-graph-demo.js +4 -0
- package/dist/gameplay/event-graph/graph.d.ts +106 -0
- package/dist/gameplay/event-graph/graph.js +4 -0
- package/dist/gameplay/event-graph/index.d.ts +13 -0
- package/dist/gameplay/event-graph/index.js +4 -0
- package/dist/gameplay/event-graph/model.d.ts +71 -0
- package/dist/gameplay/event-graph/model.js +4 -0
- package/dist/gameplay/event-graph/nodes/execution-nodes.d.ts +115 -0
- package/dist/gameplay/event-graph/nodes/execution-nodes.js +4 -0
- package/dist/gameplay/event-graph/nodes/gameplay-nodes.d.ts +208 -0
- package/dist/gameplay/event-graph/nodes/gameplay-nodes.js +4 -0
- package/dist/gameplay/event-graph/nodes/index.d.ts +4 -0
- package/dist/gameplay/event-graph/nodes/index.js +4 -0
- package/dist/gameplay/event-graph/nodes/value-nodes.d.ts +53 -0
- package/dist/gameplay/event-graph/nodes/value-nodes.js +4 -0
- package/dist/gameplay/event-graph/registry.d.ts +33 -0
- package/dist/gameplay/event-graph/registry.js +4 -0
- package/dist/gameplay/event-graph/runtime-assets.d.ts +21 -0
- package/dist/gameplay/event-graph/runtime-assets.js +4 -0
- package/dist/gameplay/event-graph/runtime.d.ts +160 -0
- package/dist/gameplay/event-graph/runtime.js +4 -0
- package/dist/gameplay/event-graph/type-inference.d.ts +41 -0
- package/dist/gameplay/event-graph/type-inference.js +4 -0
- package/dist/gameplay/event-graph/types.d.ts +77 -0
- package/dist/gameplay/event-graph/types.js +4 -0
- package/dist/gameplay/index.d.ts +15 -2
- package/dist/gameplay/index.js +1 -1
- package/dist/gameplay/initiate.js +1 -1
- package/dist/gameplay/input/input.d.ts +22 -17
- package/dist/gameplay/input/input.js +1 -1
- package/dist/gameplay/net/service/net-decorator.d.ts +1 -1
- package/dist/gameplay/net/service/net-decorator.js +1 -1
- package/dist/gameplay/net/service/net-serializer.js +1 -1
- package/dist/gameplay/net/service/net-service.d.ts +6 -6
- package/dist/gameplay/net/service/net-service.js +1 -1
- package/dist/gameplay/net/service/rpc-decorator.js +1 -1
- package/dist/gameplay/services/asset-loader.d.ts +7 -0
- package/dist/gameplay/services/asset-loader.js +1 -1
- package/dist/gameplay/services/physics/physics-system.d.ts +14 -0
- package/dist/gameplay/services/physics/physics-system.js +1 -1
- package/dist/gameplay/services/world.d.ts +12 -0
- package/dist/gameplay/services/world.js +1 -1
- package/dist/rendering.js +1 -1
- package/dist/scene/asset-resource-loader.d.ts +7 -1
- package/dist/scene/asset-resource-loader.js +1 -1
- package/dist/scene/custom-param-deserialize.js +1 -1
- package/dist/scene/custom-param-runtime-types.js +1 -1
- package/dist/scene/materializer.d.ts +25 -0
- package/dist/scene/materializer.js +1 -1
- package/dist/scene/model.d.ts +114 -2
- package/dist/scene/model.js +1 -1
- package/dist/scene/objects/prefab.js +1 -1
- package/dist/shader/graph/compiler.d.ts +3 -0
- package/dist/shader/graph/compiler.js +1 -1
- package/dist/shader/graph/model.d.ts +1 -1
- package/dist/shader/graph/registry.js +1 -1
- package/dist/test/animation-retarget.test.d.ts +2 -0
- package/dist/test/animation-retarget.test.js +4 -0
- package/dist/test/event-graph-generated-code.test.d.ts +2 -0
- package/dist/test/event-graph-generated-code.test.js +4 -0
- package/dist/test/event-graph-types.test.d.ts +2 -0
- package/dist/test/event-graph-types.test.js +4 -0
- package/dist/test/event-graph.test.d.ts +2 -0
- package/dist/test/event-graph.test.js +4 -0
- package/dist/test/input.test.d.ts +2 -0
- package/dist/test/input.test.js +4 -0
- package/dist/test/net-character-movement.test.js +1 -1
- package/dist/test/prefab-instance-params.test.js +1 -1
- package/dist/test/sequence-camera-control.test.js +1 -1
- package/dist/test/sequence-scene-binding.test.d.ts +2 -0
- package/dist/test/sequence-scene-binding.test.js +4 -0
- package/dist/test/sequence-transform.test.d.ts +2 -0
- package/dist/test/sequence-transform.test.js +4 -0
- package/dist/test/shader-graph.test.js +1 -1
- package/package.json +10 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -41,11 +41,13 @@ export declare class CharacterMovementComponent extends ActorComponent {
|
|
|
41
41
|
readonly directionInput: AxisInput;
|
|
42
42
|
readonly jumpInput: ActionInput;
|
|
43
43
|
readonly sprintInput: ActionInput;
|
|
44
|
+
readonly crouchInput: ActionInput;
|
|
44
45
|
readonly rotationInput: RotationInput;
|
|
45
46
|
horizontalSpeed: number;
|
|
46
47
|
maxSpeed: number;
|
|
47
48
|
maxSpeedBackwards: number;
|
|
48
49
|
maxSpeedSprint: number;
|
|
50
|
+
maxSpeedCrouch: number;
|
|
49
51
|
sprintStartBoostSpeed: number;
|
|
50
52
|
sprintStartBoostDamping: number;
|
|
51
53
|
jumpVelocity: number;
|
|
@@ -55,6 +57,8 @@ export declare class CharacterMovementComponent extends ActorComponent {
|
|
|
55
57
|
gravityOverride: number;
|
|
56
58
|
colliderHeight: number;
|
|
57
59
|
colliderRadius: number;
|
|
60
|
+
crouchColliderHeight: number;
|
|
61
|
+
crouchColliderRadius: number;
|
|
58
62
|
jumpInAir: boolean;
|
|
59
63
|
mass: number;
|
|
60
64
|
allowSliding: boolean;
|
|
@@ -93,10 +97,12 @@ export declare class CharacterMovementComponent extends ActorComponent {
|
|
|
93
97
|
sprintPolicy?: SprintPolicy;
|
|
94
98
|
debugCorrections: boolean;
|
|
95
99
|
private correctionDebug?;
|
|
100
|
+
private suppressUncrouchLift;
|
|
96
101
|
readonly velocity: THREE.Vector3;
|
|
97
102
|
readonly visualSmoothingOffset: THREE.Vector3;
|
|
98
103
|
mode: CharacterMovementMode;
|
|
99
104
|
isSprinting: boolean;
|
|
105
|
+
isCrouching: boolean;
|
|
100
106
|
pressedJump: boolean;
|
|
101
107
|
get autoStepMinWidth(): number;
|
|
102
108
|
set autoStepMinWidth(minWidth: number);
|
|
@@ -183,6 +189,13 @@ export declare class CharacterMovementComponent extends ActorComponent {
|
|
|
183
189
|
private configureCharacterController;
|
|
184
190
|
private initializeStateFromActor;
|
|
185
191
|
private createCollisionShape;
|
|
192
|
+
private updateCrouchState;
|
|
193
|
+
private setCrouching;
|
|
194
|
+
private canUncrouch;
|
|
195
|
+
private syncColliderShape;
|
|
196
|
+
private getColliderHeight;
|
|
197
|
+
private getColliderRadius;
|
|
198
|
+
private getCapsuleOffsetY;
|
|
186
199
|
private checkGrounded;
|
|
187
200
|
private resolvePlatformVelocity;
|
|
188
201
|
private getCollisionGroup;
|
|
@@ -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 c}from"../../../../animation/root-motion.js";import{inject as l}from"../../../../inject.js";import{ActionInput as m,AxisInput as p,RotationInput as u}from"../../../../input/index.js";import{NetRole as d}from"../../../../net/service/net-actor-role.js";import{RunOnClient as v,RunOnNotOwner as y,RunOnServer as S}from"../../../../net/service/rpc-decorator.js";import{NetService as M}from"../../../../net/service/net-service.js";import{PhysicsSystem as g,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 w}from"../../../../services/physics/physics-system.js";import{ActorComponent as A,Component as R}from"../../../component.js";import{CharacterMovementMode as C}from"./modes.js";import{DEFAULT_MAX_CLIENT_TIME_AHEAD as D,DEFAULT_LARGE_CORRECTION_THRESHOLD as q,DEFAULT_MAX_COMBINED_MOVE_DELTA_TIME as b,DEFAULT_MAX_MOVE_DELTA_TIME as k,DEFAULT_MAX_MOVES_PER_PACKET as P,DEFAULT_MAX_REPLAYED_MOVES as z,DEFAULT_MAX_SERVER_MOVES_PER_TICK as I,DEFAULT_MAX_SAVED_MOVES as j,DEFAULT_MAX_SERVER_MOVE_DELTA_TIME_SCALAR as Y,DEFAULT_MAX_SERVER_MOVE_TIME_BUDGET as G,DEFAULT_MAX_SUBSTEP_DELTA_TIME as F,DEFAULT_MOVE_SEND_INTERVAL as O,DEFAULT_SIMULATED_INTERPOLATION_DELAY as V,DEFAULT_SIMULATED_STATE_INTERVAL as X,DEFAULT_SMALL_CORRECTION_TOLERANCE as B,DEFAULT_TELEPORT_SNAP_THRESHOLD as Z,MOVE_FLAG_JUMP as N,MOVE_FLAG_ROOT_MOTION as E,MOVE_FLAG_SPRINT as L,MOVE_FLAG_SPRINT_START as U,NetCharacterProxySmoother as H,NetCharacterSavedMoveBuffer as $,accrueNetCharacterServerMoveTime as Q,createNetCharacterMovementSnapshot as W,createNetCharacterServerMoveTimingState as J,consumeNetCharacterServerMoveTime as K,decodeNetCharacterMoveBatch as _,decodeNetCharacterOwnerAck as tt,decodeNetCharacterOwnerCorrection as et,decodeNetCharacterSimulatedState as it,encodeNetCharacterMoveBatch as ot,encodeNetCharacterOwnerAck as st,encodeNetCharacterOwnerCorrection as nt,encodeNetCharacterSimulatedState as rt,validateNetCharacterMove as at}from"./net-character-movement-protocol.js";import{NetMode as ht}from"../../../../net/net-session.js";export*from"./net-character-movement-protocol.js";const ct=131070,lt=new h(0,1,0),mt=new h,pt=new h,ut=new h,dt=new h,vt=new h,yt=new h,St=new h,Mt=new h,gt=new h,ft=new h,xt=new h,Tt=new h,wt=new h,At=new h,Rt=new h(0,1,0),Ct=new h(0,-.05,0),Dt=new h,qt=new a,bt=new s.Euler,kt=new h,Pt=new h,zt=new h,It=new i.CharacterCollision;let jt=class extends A{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()}constructor(){super(),this.isDefaultCharacterMovementComponent=!0,this.directionInput=new p,this.jumpInput=new m,this.sprintInput=new m,this.rotationInput=new u,this.horizontalSpeed=0,this.maxSpeed=8,this.maxSpeedBackwards=8,this.maxSpeedSprint=12,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.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.rotateToMovementDirection=!1,this.smoothRotation=!0,this.rotationSpeed=40,this.maxRotationSpeed=100,this.impulseDamping=2,this.moveSendInterval=O,this.simulatedStateInterval=X,this.maxSavedMoves=j,this.maxReplayedMoves=z,this.maxServerMovesPerTick=I,this.maxMovesPerPacket=P,this.maxMoveDeltaTime=k,this.maxCombinedMoveDeltaTime=b,this.maxServerMoveDeltaTimeScalar=Y,this.maxClientTimeAhead=D,this.maxServerMoveTimeBudget=G,this.maxSubstepDeltaTime=F,this.fallGraceTime=.1,this.correctionToleranceSq=B*B,this.largeCorrectionThreshold=q,this.teleportSnapThreshold=Z,this.listenServerSmoothing=!0,this.listenServerSmoothLocationTime=.04,this.listenServerMaxSmoothUpdateDistance=1,this.listenServerNoSmoothUpdateDistance=2.5,this.debugCorrections=!0,this.velocity=new h,this.visualSmoothingOffset=new h,this.mode=C.walking,this.isSprinting=!1,this.pressedJump=!1,this.rayTestResult=new f,this.physicsSystem=l(g),this.netService=l(M),this.state={sequence:0,position:new h,velocity:new h,yaw:0,lookYaw:0,mode:C.walking,grounded:!1,currentSpeed:0,fallGraceTime:0,prevInputDirection:new h,prevRotateToMovementDirection:!1},this.movementModes=new Map,this.savedMoves=new $(j),this.serverMoveTiming=J(),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:pt,platformVelocity:dt,outVelocity:ut,rootMotionActive:!1,startedSprinting:!1},this.proxySmoother=new H(V,Z),this.proxySample=W(),this.pendingSnapshot=W(),this.impulse=new h,this.prevRootMotionPos=new h,this.rootMotionOptions={},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.initialized=!1,this.cc=this.physicsSystem.getCharacterController(.1),this.cc.enableSnapToGround(.1),this.cc.enableAutostep(0,.1,!1),this.registerMovementMode(Yt),this.registerMovementMode(Gt)}onInit(){this.configureCharacterController(),this.physicsSystem.addActor(this.actor,[this.createCollisionShape()],{mass:0,type:w.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 c){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)}}serverMove(t){const e=_(t);if(e.ok)for(const t of e.value.moves)at(t,this.lastServerReceivedSequence,this.maxMoveDeltaTime)&&(this.lastServerReceivedSequence=t.sequence,this.serverMoveQueue.push(t))}clientMoveAck(t){const e=tt(t);e.ok&&this.actor.netRole===d.autonomousProxy&&(this.savedMoves.ack(e.value.sequence),this.sprintPolicy?.ack?.(e.value.sequence,!1))}clientMoveCorrection(t){const e=et(t);e.ok&&this.actor.netRole===d.autonomousProxy&&(this.debugCorrections&&(null==this.correctionDebug&&(this.correctionDebug=new Vt(Bt(this.actor.object))),this.correctionDebug.update(this.state.position,e.value.snapshot)),this.applyCorrection(e.value.snapshot))}simulatedState(t){const e=it(t);e.ok&&this.actor.netRole===d.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!==d.simulatedProxy?this.enabled&&(e!==d.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,Zt);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.createMoveFromInput(t,++this.nextMoveSequence);this.performMove(i,Zt),e!==ht.none&&this.sendSimulatedState(t,!1)}tickRemoteAuthority(t){Q(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=Pt.copy(this.actor.position);let n=!1;for(let t=0;t<o;t++){const t=this.serverMoveQueue.shift();if(null==t)break;if(!at(t,this.lastServerProcessedSequence,this.maxMoveDeltaTime)){console.log("Net: Invalid move",t),this.sendOwnerCorrection(!0),e=!0;continue}const i=K(this.serverMoveTiming,t,{maxMoveDeltaTime:this.maxMoveDeltaTime,maxServerMoveDeltaTimeScalar:this.maxServerMoveDeltaTimeScalar,maxClientTimeAhead:this.maxClientTimeAhead});if(i<0){this.sendOwnerCorrection(!0),e=!0;continue}const o=Ft(t,this.authoritativeMoveScratch);o.dt=i,o.rootMotionX=0,o.rootMotionY=0,o.rootMotionZ=0,o.flags&=~E,this.performMove(o,{immediate:!0,savedRootMotion:!1}),n=!0,this.lastServerProcessedSequence=o.sequence;const s=Ot(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(st(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);zt.subVectors(t,e);const i=zt.lengthSq();i>1e-8&&(i>this.listenServerNoSmoothUpdateDistance*this.listenServerNoSmoothUpdateDistance?this.visualSmoothingOffset.set(0,0,0):(i>this.listenServerMaxSmoothUpdateDistance*this.listenServerMaxSmoothUpdateDistance&&zt.setLength(this.listenServerMaxSmoothUpdateDistance),this.visualSmoothingOffset.add(zt)))}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===d.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(St);const a=this.sprintInput.activated,h=a&&!this.previousSprintInput;this.previousSprintInput=a;const c=(this.jumpInput.activated?N:0)|(a?L:0)|(h?U:0)|(St.lengthSq()>0?E:0),l=function(t,e){e.set(t.x,0,t.y),e.lengthSq()>1&&e.normalize();return e}(this.directionInput.vector,kt),m=this.inputMoveScratch;return m.sequence=e>>>0,m.clientTime=s,m.dt=n,m.inputX=l.x,m.inputY=l.z,m.yaw=this.rotationInput.rotation.y,m.flags=c,m.clientX=this.state.position.x,m.clientY=this.state.position.y,m.clientZ=this.state.position.z,m.rootMotionX=St.x,m.rootMotionY=St.y,m.rootMotionZ=St.z,m}performMove(t,e){const i=r.clamp(t.dt,.001,this.maxMoveDeltaTime),o=Math.max(1,Math.ceil(i/this.maxSubstepDeltaTime));this.sprintPolicy?.update?.(i,t.sequence,0!==(t.flags&L)),Tt.set(e.savedRootMotion?t.rootMotionX:0,e.savedRootMotion?t.rootMotionY:0,e.savedRootMotion?t.rootMotionZ:0),e.savedRootMotion||this.sampleRootMotion(Tt);let s=i;const n=i/o;for(let r=0;r<o;r++){const o=i>0?n/i:1;this.performSubstep(t,Math.min(n,s),Tt,o,e.immediate,0===r),s-=n}t.clientX=this.state.position.x,t.clientY=this.state.position.y,t.clientZ=this.state.position.z,t.flags=Tt.lengthSq()>0?t.flags|E:t.flags&~E,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&N),c=r||a;this.pressedJump=h,this.isSprinting=!1,this.updateRotation(t,e,r,a),this.resolvePlatformVelocity(dt);const l=this.movementModeContext,m=this.movementModes.get(this.state.mode);if(null!=m){l.move=t,l.deltaTime=e,l.rootMotionActive=c,l.startedSprinting=n&&!c&&0!==(t.flags&U);const i=m.update(l);"number"==typeof i&&(this.state.mode=i)}else ut.set(0,0,0);if(a){Mt.copy(i).multiplyScalar(o).applyQuaternion(this.actor.quaternion),gt.copy(Mt).divideScalar(e),this.state.mode===C.walking?(ut.x=gt.x+dt.x,ut.z=gt.z+dt.z):(ut.x=gt.x,ut.z=gt.z);const t=Math.sqrt(gt.x*gt.x+gt.z*gt.z);t>.4&&(this.state.currentSpeed=t)}this.applyImpulseToVelocity(ut,e),this.state.mode===C.walking&&this.state.velocity.copy(ut),this.applyMovement(ut,e,s),this.checkGrounded(this.state.position),this.state.grounded=this.isGrounded,this.updateModeAfterMove(ut,e)}updateRotation(t,e,i,o){mt.set(-t.inputX,0,t.inputY),mt.lengthSq()>1&&mt.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(bt.set(0,t.yaw,0)),this.state.prevRotateToMovementDirection||(n=0,this.state.lookYaw=t.yaw),this.state.prevRotateToMovementDirection=this.rotateToMovementDirection),pt.set(0,0,0),i)this.state.lookYaw=t.yaw;else if(this.rotateToMovementDirection){if(mt.lengthSq()>0&&this.state.mode!==C.falling){const i=bt.setFromQuaternion(this.actor.object.quaternion,"YXZ").y,o=Math.atan2(mt.x,mt.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(bt.set(0,i+o,0))}else this.actor.object.quaternion.setFromEuler(bt.set(0,s,0));this.state.prevInputDirection.lerp(mt,e*this.rotationSpeed),this.state.lookYaw+=n,pt.copy(this.actor.object.getWorldDirection(kt).normalize())}}else o||(this.state.lookYaw+=n,this.actor.object.quaternion.multiply(qt.setFromEuler(bt.set(0,n,0))),mt.lengthSq()>0&&pt.copy(mt).applyQuaternion(this.actor.object.quaternion).normalize())}applyMovement(t,e,i){if(t.lengthSq()>0||!this.state.grounded){if(vt.copy(t).multiplyScalar(e),this.state.grounded&&this.state.mode===C.walking&&(this.rayTestResult.distance<=this.cc.offset()&&(vt.y=Math.max(0,dt.y*e)),this.physicsSystem.getActorComputedMovement(this.actor,this.cc,vt,this.getCollisionGroup()),this.cc.computedCollision(0,It),null!=It.normal1)){const t=kt.copy(It.normal1);Math.acos(r.clamp(t.dot(lt),-1,1))>this.cc.maxSlopeClimbAngle()&&(vt.y=.016*this.getEffectiveGravity()*.5)}yt.copy(this.physicsSystem.getActorComputedMovement(this.actor,this.cc,vt,this.getCollisionGroup()))}else yt.set(0,0,0);this.state.position.add(yt),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);Dt.set(e.normal2.x,e.normal2.y,e.normal2.z);const i=Dt.angleTo(lt);Dt.set(e.normal1.x,e.normal1.y,e.normal1.z);const o=Dt.angleTo(lt);if(i<100)return!1;return o>t.minSlopeSlideAngle()}(this.cc);!this.state.grounded||i?this.state.mode!==C.falling&&(this.state.fallGraceTime+=e,this.state.fallGraceTime>this.fallGraceTime+1e-6&&(this.state.mode=C.falling,this.state.velocity.copy(t))):this.state.velocity.y<=0&&(this.state.mode=C.walking,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(ot(i))}sendOwnerCorrection(t){const e=this.toSnapshot(this.pendingSnapshot);t&&(e.horizontalSpeed=this.horizontalSpeed),this.sprintPolicy?.ack?.(e.sequence,!0),this.clientMoveCorrection(nt(e))}sendSimulatedState(t,e){this.simulatedStateAccumulator+=t,!e&&this.simulatedStateAccumulator<this.simulatedStateInterval||(this.simulatedStateAccumulator=0,this.simulatedState(rt(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(bt.set(0,t.yaw,0)),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=bt.setFromQuaternion(this.actor.object.quaternion,"YXZ").y,t.mode=this.state.mode,t.horizontalSpeed=this.state.currentSpeed,t}syncPublicState(){this.velocity.copy(this.state.velocity),this.mode=this.state.mode,this.horizontalSpeed=this.state.currentSpeed}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 c))return t;const e=this.rootMotionInterpolant;this.resetRootMotion&&(this.prevRootMotionPos.fromArray(e.evaluate(0)),this.resetRootMotion=!1),xt.fromArray(e.evaluate(this.rootMotionAction.time)),t.subVectors(xt,this.prevRootMotionPos),this.prevRootMotionPos.copy(xt);return(this.rootMotionRootBone??this.rootMotionAction.getRoot()).getWorldScale(ft),t.multiply(ft),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===ht.none||e!==d.authority||t>=ht.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=new x(this.colliderHeight,this.colliderRadius);return t.offset.y=this.colliderRadius+this.colliderHeight/2+this.offset,t.collisionGroup=ct,t}checkGrounded(t){Ct.y=-Math.max(.05,this.cc.snapToGroundDistance()),this.physicsSystem.rayTest(wt.addVectors(t,Rt.set(0,this.offset,0)),At.addVectors(t,Ct),this.rayTestResult,{excludeActor:this.actor,excludeTriggers:!0})}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([T(),e("design:type",Object)],jt.prototype,"colliderHeight",void 0),t([T(),e("design:type",Object)],jt.prototype,"colliderRadius",void 0),t([S(!1),e("design:type",Function),e("design:paramtypes",[Uint8Array]),e("design:returntype",void 0)],jt.prototype,"serverMove",null),t([v(!1),e("design:type",Function),e("design:paramtypes",[Uint8Array]),e("design:returntype",void 0)],jt.prototype,"clientMoveAck",null),t([v(!0),e("design:type",Function),e("design:paramtypes",[Uint8Array]),e("design:returntype",void 0)],jt.prototype,"clientMoveCorrection",null),t([y(!1),e("design:type",Function),e("design:paramtypes",[Uint8Array]),e("design:returntype",void 0)],jt.prototype,"simulatedState",null),jt=t([R({inEditor:!1}),e("design:paramtypes",[])],jt);export{jt as CharacterMovementComponent};const Yt={mode:C.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=!t.rootMotionActive&&0!==(i.flags&L)&&!r&&0!==s.lengthSq()&&(e.sprintPolicy?.canSprint()??!0),h=(r?e.maxSpeedBackwards:a?e.maxSpeedSprint:e.maxSpeed)*(e.normalizedDirection?1:n);if(0!==s.lengthSq()){e.isSprinting=a,a&&e.sprintPolicy?.commitSprint(t.deltaTime,i.sequence);let c=Math.min(h,o.currentSpeed),l=e.groundAccelerationRate;if(a&&t.startedSprinting&&e.sprintStartBoostSpeed>0){const t=e.normalizedDirection?1:n;c=Math.max(c,h+e.sprintStartBoostSpeed*t),l=e.sprintStartBoostDamping}else a&&!r&&e.sprintStartBoostSpeed>0&&o.currentSpeed>h&&(c=o.currentSpeed,l=e.sprintStartBoostDamping);o.currentSpeed=function(t,e,i,o){return e+(t-e)*Math.exp(-i*o)}(c,h,l,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}(c,h,l,t.deltaTime))}else o.currentSpeed=0,t.outVelocity.set(0,0,0);if(0!==(i.flags&N))return o.mode=C.falling,o.velocity.copy(t.outVelocity),o.velocity.y=e.jumpVelocity,C.falling;t.outVelocity.y=t.deltaTime*e.getEffectiveGravity(),t.outVelocity.add(t.platformVelocity)}},Gt={mode:C.falling,update(t){const e=t.component,i=t.state,o=t.move;0!==(o.flags&N)&&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(lt,r.euclideanModulo(o.yaw-i.lookYaw+Math.PI,2*Math.PI)-Math.PI)}};function Ft(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 Ot(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 Vt{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();Xt.position.copy(t),Xt.setDirection(s),Xt.setLength(o);const n=Bt(this.scene);n.add(Xt),setTimeout(()=>{n.remove(Xt)},1e3)}}const Xt=new n(new h(0,1,0),new h,1,16711680);function Bt(t){return null==t.parent?t:Bt(t.parent)}const Zt={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 c}from"../../../../animation/root-motion.js";import{inject as l}from"../../../../inject.js";import{ActionInput as u,AxisInput as p,RotationInput as m}from"../../../../input/index.js";import{NetRole as d}from"../../../../net/service/net-actor-role.js";import{RunOnClient as v,RunOnNotOwner as y,RunOnServer as S}from"../../../../net/service/rpc-decorator.js";import{NetService as M}from"../../../../net/service/net-service.js";import{PhysicsSystem as g,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 A}from"../../../component.js";import{CharacterMovementMode as R}from"./modes.js";import{DEFAULT_MAX_CLIENT_TIME_AHEAD as D,DEFAULT_LARGE_CORRECTION_THRESHOLD as q,DEFAULT_MAX_COMBINED_MOVE_DELTA_TIME as b,DEFAULT_MAX_MOVE_DELTA_TIME as k,DEFAULT_MAX_MOVES_PER_PACKET as P,DEFAULT_MAX_REPLAYED_MOVES as I,DEFAULT_MAX_SERVER_MOVES_PER_TICK as z,DEFAULT_MAX_SAVED_MOVES as j,DEFAULT_MAX_SERVER_MOVE_DELTA_TIME_SCALAR as Y,DEFAULT_MAX_SERVER_MOVE_TIME_BUDGET as F,DEFAULT_MAX_SUBSTEP_DELTA_TIME as G,DEFAULT_MOVE_SEND_INTERVAL as O,DEFAULT_SIMULATED_INTERPOLATION_DELAY as V,DEFAULT_SIMULATED_STATE_INTERVAL as X,DEFAULT_SMALL_CORRECTION_TOLERANCE as B,DEFAULT_TELEPORT_SNAP_THRESHOLD as N,MOVE_FLAG_CROUCH as H,MOVE_FLAG_JUMP as Z,MOVE_FLAG_ROOT_MOTION as U,MOVE_FLAG_SPRINT as L,MOVE_FLAG_SPRINT_START as E,SNAPSHOT_FLAG_CROUCHING as $,NetCharacterProxySmoother as Q,NetCharacterSavedMoveBuffer as W,accrueNetCharacterServerMoveTime as J,createNetCharacterMovementSnapshot as K,createNetCharacterServerMoveTimingState as _,consumeNetCharacterServerMoveTime as tt,decodeNetCharacterMoveBatch as et,decodeNetCharacterOwnerAck as it,decodeNetCharacterOwnerCorrection as ot,decodeNetCharacterSimulatedState as st,encodeNetCharacterMoveBatch as nt,encodeNetCharacterOwnerAck as rt,encodeNetCharacterOwnerCorrection as at,encodeNetCharacterSimulatedState as ht,validateNetCharacterMove as ct}from"./net-character-movement-protocol.js";import{NetMode as lt}from"../../../../net/net-session.js";export*from"./net-character-movement-protocol.js";const ut=131070,pt=new h(0,1,0),mt=new h,dt=new h,vt=new h,yt=new h,St=new h,Mt=new h,gt=new h,ft=new h,xt=new h,Tt=new h,Ct=new h,wt=new h,At=new h,Rt=new h,Dt=new h(0,1,0),qt=new h(0,-.05,0),bt=new h,kt=new a,Pt=new s.Euler,It=new h,zt=new h,jt=new h,Yt=new i.CharacterCollision;let Ft=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()}constructor(){super(),this.isDefaultCharacterMovementComponent=!0,this.directionInput=new p,this.jumpInput=new u,this.sprintInput=new u,this.crouchInput=new u,this.rotationInput=new m,this.horizontalSpeed=0,this.maxSpeed=8,this.maxSpeedBackwards=8,this.maxSpeedSprint=12,this.maxSpeedCrouch=4,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.rotateToMovementDirection=!1,this.smoothRotation=!0,this.rotationSpeed=40,this.maxRotationSpeed=100,this.impulseDamping=2,this.moveSendInterval=O,this.simulatedStateInterval=X,this.maxSavedMoves=j,this.maxReplayedMoves=I,this.maxServerMovesPerTick=z,this.maxMovesPerPacket=P,this.maxMoveDeltaTime=k,this.maxCombinedMoveDeltaTime=b,this.maxServerMoveDeltaTimeScalar=Y,this.maxClientTimeAhead=D,this.maxServerMoveTimeBudget=F,this.maxSubstepDeltaTime=G,this.fallGraceTime=.1,this.correctionToleranceSq=B*B,this.largeCorrectionThreshold=q,this.teleportSnapThreshold=N,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.mode=R.walking,this.isSprinting=!1,this.isCrouching=!1,this.pressedJump=!1,this.rayTestResult=new f,this.physicsSystem=l(g),this.netService=l(M),this.state={sequence:0,position:new h,velocity:new h,yaw:0,lookYaw:0,mode:R.walking,grounded:!1,currentSpeed:0,fallGraceTime:0,prevInputDirection:new h,prevRotateToMovementDirection:!1},this.movementModes=new Map,this.savedMoves=new W(j),this.serverMoveTiming=_(),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:dt,platformVelocity:yt,outVelocity:vt,rootMotionActive:!1,startedSprinting:!1},this.proxySmoother=new Q(V,N),this.proxySample=K(),this.pendingSnapshot=K(),this.impulse=new h,this.prevRootMotionPos=new h,this.rootMotionOptions={},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.initialized=!1,this.cc=this.physicsSystem.getCharacterController(.1),this.cc.enableSnapToGround(.1),this.cc.enableAutostep(0,.1,!1),this.registerMovementMode(Gt),this.registerMovementMode(Ot)}onInit(){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 c){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)}}serverMove(t){const e=et(t);if(e.ok)for(const t of e.value.moves)ct(t,this.lastServerReceivedSequence,this.maxMoveDeltaTime)&&(this.lastServerReceivedSequence=t.sequence,this.serverMoveQueue.push(t))}clientMoveAck(t){const e=it(t);e.ok&&this.actor.netRole===d.autonomousProxy&&(this.savedMoves.ack(e.value.sequence),this.sprintPolicy?.ack?.(e.value.sequence,!1))}clientMoveCorrection(t){const e=ot(t);e.ok&&this.actor.netRole===d.autonomousProxy&&(this.debugCorrections&&(null==this.correctionDebug&&(this.correctionDebug=new Bt(Ht(this.actor.object))),this.correctionDebug.update(this.state.position,e.value.snapshot)),this.applyCorrection(e.value.snapshot))}simulatedState(t){const e=st(t);e.ok&&this.actor.netRole===d.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!==d.simulatedProxy?this.enabled&&(e!==d.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,Zt);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.createMoveFromInput(t,++this.nextMoveSequence);this.performMove(i,Zt),e!==lt.none&&this.sendSimulatedState(t,!1)}tickRemoteAuthority(t){J(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(!ct(t,this.lastServerProcessedSequence,this.maxMoveDeltaTime)){console.log("Net: Invalid move",t),this.sendOwnerCorrection(!0),e=!0;continue}const i=tt(this.serverMoveTiming,t,{maxMoveDeltaTime:this.maxMoveDeltaTime,maxServerMoveDeltaTimeScalar:this.maxServerMoveDeltaTimeScalar,maxClientTimeAhead:this.maxClientTimeAhead});if(i<0){this.sendOwnerCorrection(!0),e=!0;continue}const o=Vt(t,this.authoritativeMoveScratch);o.dt=i,o.rootMotionX=0,o.rootMotionY=0,o.rootMotionZ=0,o.flags&=~U,this.performMove(o,{immediate:!0,savedRootMotion:!1}),n=!0,this.lastServerProcessedSequence=o.sequence;const s=Xt(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(rt(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);jt.subVectors(t,e);const i=jt.lengthSq();i>1e-8&&(i>this.listenServerNoSmoothUpdateDistance*this.listenServerNoSmoothUpdateDistance?this.visualSmoothingOffset.set(0,0,0):(i>this.listenServerMaxSmoothUpdateDistance*this.listenServerMaxSmoothUpdateDistance&&jt.setLength(this.listenServerMaxSmoothUpdateDistance),this.visualSmoothingOffset.add(jt)))}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===d.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(gt);const a=this.crouchInput.activated,h=!a&&this.sprintInput.activated,c=h&&!this.previousSprintInput;this.previousSprintInput=h;const l=(this.jumpInput.activated?Z:0)|(h?L:0)|(a?H:0)|(c?E:0)|(gt.lengthSq()>0?U:0),u=function(t,e){e.set(t.x,0,t.y),e.lengthSq()>1&&e.normalize();return e}(this.directionInput.vector,It),p=this.inputMoveScratch;return p.sequence=e>>>0,p.clientTime=s,p.dt=n,p.inputX=u.x,p.inputY=u.z,p.yaw=this.rotationInput.rotation.y,p.flags=l,p.clientX=this.state.position.x,p.clientY=this.state.position.y,p.clientZ=this.state.position.z,p.rootMotionX=gt.x,p.rootMotionY=gt.y,p.rootMotionZ=gt.z,p}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&L)&&0===(t.flags&H);this.sprintPolicy?.update?.(i,t.sequence,s),wt.set(e.savedRootMotion?t.rootMotionX:0,e.savedRootMotion?t.rootMotionY:0,e.savedRootMotion?t.rootMotionZ:0),e.savedRootMotion||this.sampleRootMotion(wt);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),wt,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=wt.lengthSq()>0?t.flags|U:t.flags&~U,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.updateCrouchState(t);const r=null!=this.rootMotionAction&&this.rootMotionAction.enabled,a=i.lengthSq()>0,h=!r&&0!==(t.flags&Z),c=r||a;this.pressedJump=h,this.isSprinting=!1,this.updateRotation(t,e,r,a),this.resolvePlatformVelocity(yt);const l=this.movementModeContext,u=this.movementModes.get(this.state.mode);if(null!=u){l.move=t,l.deltaTime=e,l.rootMotionActive=c,l.startedSprinting=n&&!c&&0===(t.flags&H)&&0!==(t.flags&E);const i=u.update(l);"number"==typeof i&&(this.state.mode=i)}else vt.set(0,0,0);if(a){ft.copy(i).multiplyScalar(o).applyQuaternion(this.actor.quaternion),xt.copy(ft).divideScalar(e),this.state.mode===R.walking?(vt.x=xt.x+yt.x,vt.z=xt.z+yt.z):(vt.x=xt.x,vt.z=xt.z);const t=Math.sqrt(xt.x*xt.x+xt.z*xt.z);t>.4&&(this.state.currentSpeed=t)}this.applyImpulseToVelocity(vt,e),this.state.mode===R.walking&&this.state.velocity.copy(vt),this.applyMovement(vt,e,s),this.checkGrounded(this.state.position),this.state.grounded=this.isGrounded,this.updateModeAfterMove(vt,e)}updateRotation(t,e,i,o){mt.set(-t.inputX,0,t.inputY),mt.lengthSq()>1&&mt.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(Pt.set(0,t.yaw,0)),this.state.prevRotateToMovementDirection||(n=0,this.state.lookYaw=t.yaw),this.state.prevRotateToMovementDirection=this.rotateToMovementDirection),dt.set(0,0,0),i)this.state.lookYaw=t.yaw;else if(this.rotateToMovementDirection){if(mt.lengthSq()>0&&this.state.mode!==R.falling){const i=Pt.setFromQuaternion(this.actor.object.quaternion,"YXZ").y,o=Math.atan2(mt.x,mt.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(Pt.set(0,i+o,0))}else this.actor.object.quaternion.setFromEuler(Pt.set(0,s,0));this.state.prevInputDirection.lerp(mt,e*this.rotationSpeed),this.state.lookYaw+=n,dt.copy(this.actor.object.getWorldDirection(It).normalize())}}else o||(this.state.lookYaw+=n,this.actor.object.quaternion.multiply(kt.setFromEuler(Pt.set(0,n,0))),mt.lengthSq()>0&&dt.copy(mt).applyQuaternion(this.actor.object.quaternion).normalize())}applyMovement(t,e,i){if(t.lengthSq()>0||!this.state.grounded){if(St.copy(t).multiplyScalar(e),this.state.grounded&&this.state.mode===R.walking&&(this.rayTestResult.distance<=this.cc.offset()&&(St.y=Math.max(0,yt.y*e)),this.physicsSystem.getActorComputedMovement(this.actor,this.cc,St,this.getCollisionGroup()),this.cc.computedCollision(0,Yt),null!=Yt.normal1)){const t=It.copy(Yt.normal1);Math.acos(r.clamp(t.dot(pt),-1,1))>this.cc.maxSlopeClimbAngle()&&(St.y=.016*this.getEffectiveGravity()*.5)}Mt.copy(this.physicsSystem.getActorComputedMovement(this.actor,this.cc,St,this.getCollisionGroup()))}else Mt.set(0,0,0);this.suppressUncrouchLift&&(this.suppressUncrouchLift=!1,this.state.grounded&&this.state.mode===R.walking&&St.y<=1e-6&&Mt.y>0&&(Mt.y=0)),this.state.position.add(Mt),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);bt.set(e.normal2.x,e.normal2.y,e.normal2.z);const i=bt.angleTo(pt);bt.set(e.normal1.x,e.normal1.y,e.normal1.z);const o=bt.angleTo(pt);if(i<100)return!1;return o>t.minSlopeSlideAngle()}(this.cc);!this.state.grounded||i?this.state.mode!==R.falling&&(this.state.fallGraceTime+=e,this.state.fallGraceTime>this.fallGraceTime+1e-6&&(this.state.mode=R.falling,this.state.velocity.copy(t))):this.state.velocity.y<=0&&(this.state.mode=R.walking,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(nt(i))}sendOwnerCorrection(t){const e=this.toSnapshot(this.pendingSnapshot);t&&(e.horizontalSpeed=this.horizontalSpeed),this.sprintPolicy?.ack?.(e.sequence,!0),this.clientMoveCorrection(at(e))}sendSimulatedState(t,e){this.simulatedStateAccumulator+=t,!e&&this.simulatedStateAccumulator<this.simulatedStateInterval||(this.simulatedStateAccumulator=0,this.simulatedState(ht(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(Pt.set(0,t.yaw,0)),this.setCrouching(0!==(t.flags&$)),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=Pt.setFromQuaternion(this.actor.object.quaternion,"YXZ").y,t.mode=this.state.mode,t.flags=this.isCrouching?$:0,t.horizontalSpeed=this.state.currentSpeed,t}syncPublicState(){this.velocity.copy(this.state.velocity),this.mode=this.state.mode,this.horizontalSpeed=this.state.currentSpeed}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 c))return t;const e=this.rootMotionInterpolant;this.resetRootMotion&&(this.prevRootMotionPos.fromArray(e.evaluate(0)),this.resetRootMotion=!1),Ct.fromArray(e.evaluate(this.rootMotionAction.time)),t.subVectors(Ct,this.prevRootMotionPos),this.prevRootMotionPos.copy(Ct);return(this.rootMotionRootBone??this.rootMotionAction.getRoot()).getWorldScale(Tt),t.multiply(Tt),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===lt.none||e!==d.authority||t>=lt.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=ut,i}updateCrouchState(t){0===(t.flags&H)?this.isCrouching&&this.canUncrouch()&&this.setCrouching(!1)&&(this.suppressUncrouchLift=!0,this.state.fallGraceTime=0):this.setCrouching(!0)}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){qt.y=-Math.max(.05,this.cc.snapToGroundDistance()),this.physicsSystem.rayTest(At.addVectors(t,Dt.set(0,this.offset,0)),Rt.addVectors(t,qt),this.rayTestResult,{excludeActor:this.actor,excludeTriggers:!0})}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:ut}};t([T(),e("design:type",Object)],Ft.prototype,"colliderHeight",void 0),t([T(),e("design:type",Object)],Ft.prototype,"colliderRadius",void 0),t([T(),e("design:type",Object)],Ft.prototype,"crouchColliderHeight",void 0),t([T(),e("design:type",Number)],Ft.prototype,"crouchColliderRadius",void 0),t([S(!1),e("design:type",Function),e("design:paramtypes",[Uint8Array]),e("design:returntype",void 0)],Ft.prototype,"serverMove",null),t([v(!1),e("design:type",Function),e("design:paramtypes",[Uint8Array]),e("design:returntype",void 0)],Ft.prototype,"clientMoveAck",null),t([v(!0),e("design:type",Function),e("design:paramtypes",[Uint8Array]),e("design:returntype",void 0)],Ft.prototype,"clientMoveCorrection",null),t([y(!1),e("design:type",Function),e("design:paramtypes",[Uint8Array]),e("design:returntype",void 0)],Ft.prototype,"simulatedState",null),Ft=t([A({inEditor:!1}),e("design:paramtypes",[])],Ft);export{Ft as CharacterMovementComponent};const Gt={mode:R.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&H)&&0!==(i.flags&L)&&!r&&0!==s.lengthSq()&&(e.sprintPolicy?.canSprint()??!0),c=(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(c,o.currentSpeed),l=e.groundAccelerationRate;if(h&&t.startedSprinting&&e.sprintStartBoostSpeed>0){const t=e.normalizedDirection?1:n;a=Math.max(a,c+e.sprintStartBoostSpeed*t),l=e.sprintStartBoostDamping}else h&&!r&&e.sprintStartBoostSpeed>0&&o.currentSpeed>c&&(a=o.currentSpeed,l=e.sprintStartBoostDamping);o.currentSpeed=function(t,e,i,o){return e+(t-e)*Math.exp(-i*o)}(a,c,l,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,c,l,t.deltaTime))}else o.currentSpeed=0,t.outVelocity.set(0,0,0);if(0!==(i.flags&Z))return o.mode=R.falling,o.velocity.copy(t.outVelocity),o.velocity.y=e.jumpVelocity,R.falling;t.outVelocity.y=t.deltaTime*e.getEffectiveGravity(),t.outVelocity.add(t.platformVelocity)}},Ot={mode:R.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(pt,r.euclideanModulo(o.yaw-i.lookYaw+Math.PI,2*Math.PI)-Math.PI)}};function Vt(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 Xt(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 Bt{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();Nt.position.copy(t),Nt.setDirection(s),Nt.setLength(o);const n=Ht(this.scene);n.add(Nt),setTimeout(()=>{n.remove(Nt)},1e3)}}const Nt=new n(new h(0,1,0),new h,1,16711680);function Ht(t){return null==t.parent?t:Ht(t.parent)}const Zt={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
|
*/
|
package/dist/gameplay/actors/builtin/components/character/net-character-movement-protocol.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CharacterMovementMode } from "./modes.js";
|
|
2
|
-
export declare const NET_CHARACTER_MOVEMENT_VERSION =
|
|
2
|
+
export declare const NET_CHARACTER_MOVEMENT_VERSION = 3;
|
|
3
3
|
export declare const MOVE_PACKET_KIND = 1;
|
|
4
4
|
export declare const OWNER_ACK_PACKET_KIND = 2;
|
|
5
5
|
export declare const OWNER_CORRECTION_PACKET_KIND = 3;
|
|
@@ -24,6 +24,8 @@ export declare const MOVE_FLAG_JUMP: number;
|
|
|
24
24
|
export declare const MOVE_FLAG_SPRINT: number;
|
|
25
25
|
export declare const MOVE_FLAG_ROOT_MOTION: number;
|
|
26
26
|
export declare const MOVE_FLAG_SPRINT_START: number;
|
|
27
|
+
export declare const MOVE_FLAG_CROUCH: number;
|
|
28
|
+
export declare const SNAPSHOT_FLAG_CROUCHING: number;
|
|
27
29
|
export type NetCharacterMove = {
|
|
28
30
|
sequence: number;
|
|
29
31
|
clientTime: number;
|
|
@@ -52,6 +54,7 @@ export type NetCharacterMovementSnapshot = {
|
|
|
52
54
|
velocityZ: number;
|
|
53
55
|
yaw: number;
|
|
54
56
|
mode: CharacterMovementMode;
|
|
57
|
+
flags: number;
|
|
55
58
|
horizontalSpeed: number;
|
|
56
59
|
};
|
|
57
60
|
export type NetCharacterOwnerAck = {
|
package/dist/gameplay/actors/builtin/components/character/net-character-movement-protocol.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{MathUtils as t}from"three";import{CharacterMovementMode as e}from"./modes.js";export const NET_CHARACTER_MOVEMENT_VERSION=2;export const MOVE_PACKET_KIND=1;export const OWNER_ACK_PACKET_KIND=2;export const OWNER_CORRECTION_PACKET_KIND=3;export const SIMULATED_STATE_PACKET_KIND=4;export const DEFAULT_MOVE_SEND_INTERVAL=1/30;export const DEFAULT_SIMULATED_STATE_INTERVAL=.05;export const DEFAULT_MAX_SAVED_MOVES=128;export const DEFAULT_MAX_REPLAYED_MOVES=64;export const DEFAULT_MAX_SERVER_MOVES_PER_TICK=4;export const DEFAULT_MAX_MOVES_PER_PACKET=16;export const DEFAULT_MAX_MOVE_DELTA_TIME=1/15;export const DEFAULT_MAX_COMBINED_MOVE_DELTA_TIME=1/15;export const DEFAULT_MAX_SUBSTEP_DELTA_TIME=.017;export const DEFAULT_MAX_SERVER_MOVE_DELTA_TIME_SCALAR=1.75;export const DEFAULT_MAX_CLIENT_TIME_AHEAD=.1;export const DEFAULT_MAX_SERVER_MOVE_TIME_BUDGET=.25;export const DEFAULT_SMALL_CORRECTION_TOLERANCE=.08;export const DEFAULT_LARGE_CORRECTION_THRESHOLD=1;export const DEFAULT_TELEPORT_SNAP_THRESHOLD=5;export const DEFAULT_SIMULATED_INTERPOLATION_DELAY=.1;export const MOVE_FLAG_JUMP=1;export const MOVE_FLAG_SPRINT=2;export const MOVE_FLAG_ROOT_MOTION=4;export const MOVE_FLAG_SPRINT_START=8;const n=.001;export class NetCharacterSavedMoveBuffer{constructor(t=128,e=.06666666666666667){this.capacity=t,this.maxCombinedDeltaTime=e,this.moves=[],this.freeMoves=[],this.sendScratch=[],this.replayScratch={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}}get length(){return this.moves.length+(null==this.pending?0:1)}push(e){if(null!=this.pending){if(function(e,o,i=.06666666666666667){if(i<0)return!1;if(s=e.sequence,r=o.sequence,(s>>>0)+1>>>0!=r>>>0)return!1;var s,r;if(e.flags!==o.flags||13&e.flags)return!1;const a=e.clientTime-e.dt,c=o.clientTime-o.dt,h=o.clientTime-a,u=i;if(h<=0||h>u+n)return!1;if(Math.abs(e.clientTime-c)>n)return!1;if(l(e.inputX)!==l(o.inputX)||l(e.inputY)!==l(o.inputY))return!1;return function(e,n){return Math.abs(t.euclideanModulo(n-e+Math.PI,2*Math.PI)-Math.PI)}(e.yaw,o.yaw)<=.001}(this.pending,e,this.maxCombinedDeltaTime))return void function(t,e){const n=t.clientTime-t.dt;t.sequence=e.sequence,t.clientTime=e.clientTime,t.dt=Math.max(.001,e.clientTime-n),t.inputX=e.inputX,t.inputY=e.inputY,t.yaw=e.yaw,t.flags=e.flags,t.clientX=e.clientX,t.clientY=e.clientY,t.clientZ=e.clientZ,t.rootMotionX+=e.rootMotionX,t.rootMotionY+=e.rootMotionY,t.rootMotionZ+=e.rootMotionZ}(this.pending,e);this.commitPending()}this.pending=this.acquireMove(e),this.trimToCapacity()}ack(t){let e=0;for(let n=0;n<this.moves.length;n++)isSequenceLessOrEqual(this.moves[n].sequence,t)&&(e=n+1);if(e>0){for(let t=0;t<e;t++)this.releaseMove(this.moves[t]);this.moves.splice(0,e)}null!=this.pending&&isSequenceLessOrEqual(this.pending.sequence,t)&&(this.releaseMove(this.pending),this.pending=void 0)}clear(){for(let t=0;t<this.moves.length;t++)this.releaseMove(this.moves[t]);this.moves.length=0,null!=this.pending&&this.releaseMove(this.pending),this.pending=void 0,this.sendScratch.length=0}getMovesForSend(t){if(this.commitPending(),this.sendScratch.length=0,t<=0||0===this.moves.length)return this.sendScratch;if(1===t||this.moves.length<=t){for(let e=1===t?this.moves.length-1:0;e<this.moves.length;e++)this.sendScratch.push(this.moves[e]);return this.sendScratch}this.sendScratch.push(this.moves[0]);const e=t-1;for(let t=Math.max(1,this.moves.length-e);t<this.moves.length;t++)this.sendScratch.push(this.moves[t]);return this.sendScratch}replayAfter(t,e,n=64){let o=0;for(let i=0;i<this.moves.length&&o<n;i++){const n=this.moves[i];isSequenceGreater(n.sequence,t)&&(e(s(n,this.replayScratch)),o++)}null!=this.pending&&isSequenceGreater(this.pending.sequence,t)&&o<n&&e(s(this.pending,this.replayScratch))}commitPending(){null!=this.pending&&(this.moves.push(this.pending),this.pending=void 0,this.trimToCapacity())}trimToCapacity(){const t=Math.max(1,Math.floor(this.capacity)),e=this.length-t;if(e>0){for(let t=0;t<e;t++)this.releaseMove(this.moves[t]);this.moves.splice(0,e)}}acquireMove(t){return s(t,this.freeMoves.pop()??{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})}releaseMove(t){this.freeMoves.length<Math.max(1,Math.floor(this.capacity))&&this.freeMoves.push(t)}}export class NetCharacterProxySmoother{constructor(t=.1,e=5,n=32){this.interpolationDelay=t,this.snapDistance=e,this.maxSnapshots=n,this.snapshots=[]}push(t,e){const n=function(t){return{...t}}(t);this.snapshots.push({time:e,snapshot:n}),this.snapshots.sort((t,e)=>t.time-e.time),this.snapshots.length>this.maxSnapshots&&this.snapshots.splice(0,this.snapshots.length-this.maxSnapshots)}reset(t,e=0){this.snapshots.length=0,null!=t&&this.push(t,e)}sample(e,n){if(0===this.snapshots.length)return!1;const o=e-this.interpolationDelay,i=this.snapshots[0],s=this.snapshots[this.snapshots.length-1];if(null==i||null==s)return!1;if(o<=i.time||1===this.snapshots.length)return r(i.snapshot,n),!0;if(o>=s.time)return r(s.snapshot,n),!0;for(let e=1;e<this.snapshots.length;e++){const i=this.snapshots[e-1],s=this.snapshots[e];if(null==i||null==s||o>s.time)continue;if(c(i.snapshot,s.snapshot)>this.snapDistance*this.snapDistance)return r(s.snapshot,n),!0;const l=s.time-i.time,h=l>0?t.clamp((o-i.time)/l,0,1):1;return a(i.snapshot,s.snapshot,h,n),!0}return r(s.snapshot,n),!0}}export function validateNetCharacterMove(t,e,n=.06666666666666667){return!!isSequenceGreater(t.sequence,e)&&(!(!Number.isFinite(t.clientTime)||t.clientTime<=0)&&(!(!Number.isFinite(t.dt)||t.dt<=0||t.dt>n)&&(!(!Number.isFinite(t.inputX)||!Number.isFinite(t.inputY))&&(!(t.inputX*t.inputX+t.inputY*t.inputY>1.0001)&&(Number.isFinite(t.yaw)&&Number.isFinite(t.clientX)&&Number.isFinite(t.clientY)&&Number.isFinite(t.clientZ))))))}export function encodeNetCharacterMoveBatch(e){const n=Math.min(65535,e.length),o=new Uint8Array(4+43*n),i=new DataView(o.buffer);let s=0;i.setUint8(s++,2),i.setUint8(s++,1),i.setUint16(s,n,!0),s+=2;for(let o=0;o<n;o++){const n=e[o];i.setUint32(s,n.sequence>>>0,!0),s+=4,i.setUint32(s,t.clamp(Math.round(1e3*n.clientTime),0,4294967295),!0),s+=4,i.setUint16(s,t.clamp(Math.round(1e3*n.dt),1,65535),!0),s+=2,i.setInt16(s,l(n.inputX),!0),s+=2,i.setInt16(s,l(n.inputY),!0),s+=2,i.setFloat32(s,n.yaw,!0),s+=4,i.setUint8(s++,255&n.flags),i.setFloat32(s,n.clientX,!0),s+=4,i.setFloat32(s,n.clientY,!0),s+=4,i.setFloat32(s,n.clientZ,!0),s+=4,i.setFloat32(s,n.rootMotionX,!0),s+=4,i.setFloat32(s,n.rootMotionY,!0),s+=4,i.setFloat32(s,n.rootMotionZ,!0),s+=4}return o}export function decodeNetCharacterMoveBatch(t){if(t.byteLength<4)return{ok:!1,reason:"malformed"};const e=u(t);let n=0;if(2!==e.getUint8(n++))return{ok:!1,reason:"unsupported-version"};if(1!==e.getUint8(n++))return{ok:!1,reason:"wrong-kind"};const o=e.getUint16(n,!0);if(n+=2,t.byteLength!==4+43*o)return{ok:!1,reason:"malformed"};const i=[];for(let t=0;t<o;t++){const t=e.getUint32(n,!0);n+=4;const o=e.getUint32(n,!0)/1e3;n+=4;const s=e.getUint16(n,!0)/1e3;n+=2;const r=h(e.getInt16(n,!0));n+=2;const a=h(e.getInt16(n,!0));n+=2;const c=e.getFloat32(n,!0);n+=4;const l=e.getUint8(n++),u=e.getFloat32(n,!0);n+=4;const p=e.getFloat32(n,!0);n+=4;const m=e.getFloat32(n,!0);n+=4;const M=e.getFloat32(n,!0);n+=4;const d=e.getFloat32(n,!0);n+=4;const g=e.getFloat32(n,!0);n+=4,i.push({sequence:t,clientTime:o,dt:s,inputX:r,inputY:a,yaw:c,flags:l,clientX:u,clientY:p,clientZ:m,rootMotionX:M,rootMotionY:d,rootMotionZ:g})}return{ok:!0,value:{moves:i}}}export function encodeNetCharacterOwnerAck(t){const e=new Uint8Array(6),n=new DataView(e.buffer);return n.setUint8(0,2),n.setUint8(1,2),n.setUint32(2,t>>>0,!0),e}export function decodeNetCharacterOwnerAck(t){if(6!==t.byteLength)return{ok:!1,reason:"malformed"};const e=u(t);return 2!==e.getUint8(0)?{ok:!1,reason:"unsupported-version"}:2!==e.getUint8(1)?{ok:!1,reason:"wrong-kind"}:{ok:!0,value:{sequence:e.getUint32(2,!0)}}}export function encodeNetCharacterOwnerCorrection(t){return o(3,t)}export function decodeNetCharacterOwnerCorrection(t){const e=i(t,3);return!1===e.ok?{ok:!1,reason:e.reason}:{ok:!0,value:{snapshot:e.value}}}export function encodeNetCharacterSimulatedState(t){return o(4,t)}export function decodeNetCharacterSimulatedState(t){return i(t,4)}export function replayNetCharacterSavedMoves(t,e,n,o=64){let i=t;const s=Math.min(o,e.length);for(let t=0;t<s;t++)i=n(i,e[t]);return i}export function createNetCharacterServerMoveTimingState(){return{lastClientTime:0,serverTimeBudget:0}}export function accrueNetCharacterServerMoveTime(t,e,n=.25){!Number.isFinite(e)||e<=0||(t.serverTimeBudget=Math.min(n,t.serverTimeBudget+e))}export function consumeNetCharacterServerMoveTime(t,e,n={}){if(!Number.isFinite(e.clientTime))return-1;const o=e.clientTime-t.lastClientTime;if(!Number.isFinite(o)||o<=0)return-1;const i=n.maxMoveDeltaTime??.06666666666666667,s=Math.max(1,n.maxServerMoveDeltaTimeScalar??1.75),r=n.maxClientTimeAhead??.1,a=Math.max(.001,i*s),c=Math.min(o,a),l=t.serverTimeBudget-c;return l<-r?-1:(t.serverTimeBudget=l,t.lastClientTime=e.clientTime,Math.max(.001,c))}export function createNetCharacterMovementSnapshot(t={}){return{sequence:0,x:0,y:0,z:0,velocityX:0,velocityY:0,velocityZ:0,yaw:0,mode:e.walking,horizontalSpeed:0,...t}}export function isSequenceGreater(t,e){return t-e>>>0<2147483648&&t!==e}export function isSequenceLessOrEqual(t,e){return t===e||!isSequenceGreater(t,e)}function o(t,e){const n=new Uint8Array(40),o=new DataView(n.buffer);let i=0;return o.setUint8(i++,2),o.setUint8(i++,t),o.setUint32(i,e.sequence>>>0,!0),i+=4,o.setFloat32(i,e.x,!0),i+=4,o.setFloat32(i,e.y,!0),i+=4,o.setFloat32(i,e.z,!0),i+=4,o.setFloat32(i,e.velocityX,!0),i+=4,o.setFloat32(i,e.velocityY,!0),i+=4,o.setFloat32(i,e.velocityZ,!0),i+=4,o.setFloat32(i,e.yaw,!0),i+=4,o.setUint8(i++,e.mode),o.setFloat32(i,e.horizontalSpeed,!0),n}function i(t,e){if(40!==t.byteLength)return{ok:!1,reason:"malformed"};const n=u(t);let o=0;if(2!==n.getUint8(o++))return{ok:!1,reason:"unsupported-version"};if(n.getUint8(o++)!==e)return{ok:!1,reason:"wrong-kind"};const i=n.getUint32(o,!0);o+=4;const s=n.getFloat32(o,!0);o+=4;const r=n.getFloat32(o,!0);o+=4;const a=n.getFloat32(o,!0);o+=4;const c=n.getFloat32(o,!0);o+=4;const l=n.getFloat32(o,!0);o+=4;const h=n.getFloat32(o,!0);o+=4;const p=n.getFloat32(o,!0);o+=4;return{ok:!0,value:{sequence:i,x:s,y:r,z:a,velocityX:c,velocityY:l,velocityZ:h,yaw:p,mode:n.getUint8(o++),horizontalSpeed:n.getFloat32(o,!0)}}}function s(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 r(t,e){e.sequence=t.sequence,e.x=t.x,e.y=t.y,e.z=t.z,e.velocityX=t.velocityX,e.velocityY=t.velocityY,e.velocityZ=t.velocityZ,e.yaw=t.yaw,e.mode=t.mode,e.horizontalSpeed=t.horizontalSpeed}function a(e,n,o,i){i.sequence=n.sequence,i.x=t.lerp(e.x,n.x,o),i.y=t.lerp(e.y,n.y,o),i.z=t.lerp(e.z,n.z,o),i.velocityX=t.lerp(e.velocityX,n.velocityX,o),i.velocityY=t.lerp(e.velocityY,n.velocityY,o),i.velocityZ=t.lerp(e.velocityZ,n.velocityZ,o),i.yaw=e.yaw+(t.euclideanModulo(n.yaw-e.yaw+Math.PI,2*Math.PI)-Math.PI)*o,i.mode=o<1?e.mode:n.mode,i.horizontalSpeed=t.lerp(e.horizontalSpeed,n.horizontalSpeed,o)}function c(t,e){const n=t.x-e.x,o=t.y-e.y,i=t.z-e.z;return n*n+o*o+i*i}function l(e){return t.clamp(Math.round(32767*t.clamp(e,-1,1)),-32767,32767)}function h(e){return t.clamp(e/32767,-1,1)}function u(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}/*
|
|
1
|
+
import{MathUtils as t}from"three";import{CharacterMovementMode as e}from"./modes.js";export const NET_CHARACTER_MOVEMENT_VERSION=3;export const MOVE_PACKET_KIND=1;export const OWNER_ACK_PACKET_KIND=2;export const OWNER_CORRECTION_PACKET_KIND=3;export const SIMULATED_STATE_PACKET_KIND=4;export const DEFAULT_MOVE_SEND_INTERVAL=1/30;export const DEFAULT_SIMULATED_STATE_INTERVAL=.05;export const DEFAULT_MAX_SAVED_MOVES=128;export const DEFAULT_MAX_REPLAYED_MOVES=64;export const DEFAULT_MAX_SERVER_MOVES_PER_TICK=4;export const DEFAULT_MAX_MOVES_PER_PACKET=16;export const DEFAULT_MAX_MOVE_DELTA_TIME=1/15;export const DEFAULT_MAX_COMBINED_MOVE_DELTA_TIME=1/15;export const DEFAULT_MAX_SUBSTEP_DELTA_TIME=.017;export const DEFAULT_MAX_SERVER_MOVE_DELTA_TIME_SCALAR=1.75;export const DEFAULT_MAX_CLIENT_TIME_AHEAD=.1;export const DEFAULT_MAX_SERVER_MOVE_TIME_BUDGET=.25;export const DEFAULT_SMALL_CORRECTION_TOLERANCE=.08;export const DEFAULT_LARGE_CORRECTION_THRESHOLD=1;export const DEFAULT_TELEPORT_SNAP_THRESHOLD=5;export const DEFAULT_SIMULATED_INTERPOLATION_DELAY=.1;export const MOVE_FLAG_JUMP=1;export const MOVE_FLAG_SPRINT=2;export const MOVE_FLAG_ROOT_MOTION=4;export const MOVE_FLAG_SPRINT_START=8;export const MOVE_FLAG_CROUCH=16;export const SNAPSHOT_FLAG_CROUCHING=1;const n=.001;export class NetCharacterSavedMoveBuffer{constructor(t=128,e=.06666666666666667){this.capacity=t,this.maxCombinedDeltaTime=e,this.moves=[],this.freeMoves=[],this.sendScratch=[],this.replayScratch={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}}get length(){return this.moves.length+(null==this.pending?0:1)}push(e){if(null!=this.pending){if(function(e,o,i=.06666666666666667){if(i<0)return!1;if(s=e.sequence,r=o.sequence,(s>>>0)+1>>>0!=r>>>0)return!1;var s,r;if(e.flags!==o.flags||13&e.flags)return!1;const a=e.clientTime-e.dt,c=o.clientTime-o.dt,h=o.clientTime-a,u=i;if(h<=0||h>u+n)return!1;if(Math.abs(e.clientTime-c)>n)return!1;if(l(e.inputX)!==l(o.inputX)||l(e.inputY)!==l(o.inputY))return!1;return function(e,n){return Math.abs(t.euclideanModulo(n-e+Math.PI,2*Math.PI)-Math.PI)}(e.yaw,o.yaw)<=.001}(this.pending,e,this.maxCombinedDeltaTime))return void function(t,e){const n=t.clientTime-t.dt;t.sequence=e.sequence,t.clientTime=e.clientTime,t.dt=Math.max(.001,e.clientTime-n),t.inputX=e.inputX,t.inputY=e.inputY,t.yaw=e.yaw,t.flags=e.flags,t.clientX=e.clientX,t.clientY=e.clientY,t.clientZ=e.clientZ,t.rootMotionX+=e.rootMotionX,t.rootMotionY+=e.rootMotionY,t.rootMotionZ+=e.rootMotionZ}(this.pending,e);this.commitPending()}this.pending=this.acquireMove(e),this.trimToCapacity()}ack(t){let e=0;for(let n=0;n<this.moves.length;n++)isSequenceLessOrEqual(this.moves[n].sequence,t)&&(e=n+1);if(e>0){for(let t=0;t<e;t++)this.releaseMove(this.moves[t]);this.moves.splice(0,e)}null!=this.pending&&isSequenceLessOrEqual(this.pending.sequence,t)&&(this.releaseMove(this.pending),this.pending=void 0)}clear(){for(let t=0;t<this.moves.length;t++)this.releaseMove(this.moves[t]);this.moves.length=0,null!=this.pending&&this.releaseMove(this.pending),this.pending=void 0,this.sendScratch.length=0}getMovesForSend(t){if(this.commitPending(),this.sendScratch.length=0,t<=0||0===this.moves.length)return this.sendScratch;if(1===t||this.moves.length<=t){for(let e=1===t?this.moves.length-1:0;e<this.moves.length;e++)this.sendScratch.push(this.moves[e]);return this.sendScratch}this.sendScratch.push(this.moves[0]);const e=t-1;for(let t=Math.max(1,this.moves.length-e);t<this.moves.length;t++)this.sendScratch.push(this.moves[t]);return this.sendScratch}replayAfter(t,e,n=64){let o=0;for(let i=0;i<this.moves.length&&o<n;i++){const n=this.moves[i];isSequenceGreater(n.sequence,t)&&(e(s(n,this.replayScratch)),o++)}null!=this.pending&&isSequenceGreater(this.pending.sequence,t)&&o<n&&e(s(this.pending,this.replayScratch))}commitPending(){null!=this.pending&&(this.moves.push(this.pending),this.pending=void 0,this.trimToCapacity())}trimToCapacity(){const t=Math.max(1,Math.floor(this.capacity)),e=this.length-t;if(e>0){for(let t=0;t<e;t++)this.releaseMove(this.moves[t]);this.moves.splice(0,e)}}acquireMove(t){return s(t,this.freeMoves.pop()??{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})}releaseMove(t){this.freeMoves.length<Math.max(1,Math.floor(this.capacity))&&this.freeMoves.push(t)}}export class NetCharacterProxySmoother{constructor(t=.1,e=5,n=32){this.interpolationDelay=t,this.snapDistance=e,this.maxSnapshots=n,this.snapshots=[]}push(t,e){const n=function(t){return{...t}}(t);this.snapshots.push({time:e,snapshot:n}),this.snapshots.sort((t,e)=>t.time-e.time),this.snapshots.length>this.maxSnapshots&&this.snapshots.splice(0,this.snapshots.length-this.maxSnapshots)}reset(t,e=0){this.snapshots.length=0,null!=t&&this.push(t,e)}sample(e,n){if(0===this.snapshots.length)return!1;const o=e-this.interpolationDelay,i=this.snapshots[0],s=this.snapshots[this.snapshots.length-1];if(null==i||null==s)return!1;if(o<=i.time||1===this.snapshots.length)return r(i.snapshot,n),!0;if(o>=s.time)return r(s.snapshot,n),!0;for(let e=1;e<this.snapshots.length;e++){const i=this.snapshots[e-1],s=this.snapshots[e];if(null==i||null==s||o>s.time)continue;if(c(i.snapshot,s.snapshot)>this.snapDistance*this.snapDistance)return r(s.snapshot,n),!0;const l=s.time-i.time,h=l>0?t.clamp((o-i.time)/l,0,1):1;return a(i.snapshot,s.snapshot,h,n),!0}return r(s.snapshot,n),!0}}export function validateNetCharacterMove(t,e,n=.06666666666666667){return!!isSequenceGreater(t.sequence,e)&&(!(!Number.isFinite(t.clientTime)||t.clientTime<=0)&&(!(!Number.isFinite(t.dt)||t.dt<=0||t.dt>n)&&(!(!Number.isFinite(t.inputX)||!Number.isFinite(t.inputY))&&(!(t.inputX*t.inputX+t.inputY*t.inputY>1.0001)&&(!(!Number.isInteger(t.flags)||t.flags<0||-32&t.flags)&&(Number.isFinite(t.yaw)&&Number.isFinite(t.clientX)&&Number.isFinite(t.clientY)&&Number.isFinite(t.clientZ)))))))}export function encodeNetCharacterMoveBatch(e){const n=Math.min(65535,e.length),o=new Uint8Array(4+43*n),i=new DataView(o.buffer);let s=0;i.setUint8(s++,3),i.setUint8(s++,1),i.setUint16(s,n,!0),s+=2;for(let o=0;o<n;o++){const n=e[o];i.setUint32(s,n.sequence>>>0,!0),s+=4,i.setUint32(s,t.clamp(Math.round(1e3*n.clientTime),0,4294967295),!0),s+=4,i.setUint16(s,t.clamp(Math.round(1e3*n.dt),1,65535),!0),s+=2,i.setInt16(s,l(n.inputX),!0),s+=2,i.setInt16(s,l(n.inputY),!0),s+=2,i.setFloat32(s,n.yaw,!0),s+=4,i.setUint8(s++,255&n.flags),i.setFloat32(s,n.clientX,!0),s+=4,i.setFloat32(s,n.clientY,!0),s+=4,i.setFloat32(s,n.clientZ,!0),s+=4,i.setFloat32(s,n.rootMotionX,!0),s+=4,i.setFloat32(s,n.rootMotionY,!0),s+=4,i.setFloat32(s,n.rootMotionZ,!0),s+=4}return o}export function decodeNetCharacterMoveBatch(t){if(t.byteLength<4)return{ok:!1,reason:"malformed"};const e=u(t);let n=0;if(3!==e.getUint8(n++))return{ok:!1,reason:"unsupported-version"};if(1!==e.getUint8(n++))return{ok:!1,reason:"wrong-kind"};const o=e.getUint16(n,!0);if(n+=2,t.byteLength!==4+43*o)return{ok:!1,reason:"malformed"};const i=[];for(let t=0;t<o;t++){const t=e.getUint32(n,!0);n+=4;const o=e.getUint32(n,!0)/1e3;n+=4;const s=e.getUint16(n,!0)/1e3;n+=2;const r=h(e.getInt16(n,!0));n+=2;const a=h(e.getInt16(n,!0));n+=2;const c=e.getFloat32(n,!0);n+=4;const l=e.getUint8(n++),u=e.getFloat32(n,!0);n+=4;const p=e.getFloat32(n,!0);n+=4;const m=e.getFloat32(n,!0);n+=4;const g=e.getFloat32(n,!0);n+=4;const f=e.getFloat32(n,!0);n+=4;const M=e.getFloat32(n,!0);n+=4,i.push({sequence:t,clientTime:o,dt:s,inputX:r,inputY:a,yaw:c,flags:l,clientX:u,clientY:p,clientZ:m,rootMotionX:g,rootMotionY:f,rootMotionZ:M})}return{ok:!0,value:{moves:i}}}export function encodeNetCharacterOwnerAck(t){const e=new Uint8Array(6),n=new DataView(e.buffer);return n.setUint8(0,3),n.setUint8(1,2),n.setUint32(2,t>>>0,!0),e}export function decodeNetCharacterOwnerAck(t){if(6!==t.byteLength)return{ok:!1,reason:"malformed"};const e=u(t);return 3!==e.getUint8(0)?{ok:!1,reason:"unsupported-version"}:2!==e.getUint8(1)?{ok:!1,reason:"wrong-kind"}:{ok:!0,value:{sequence:e.getUint32(2,!0)}}}export function encodeNetCharacterOwnerCorrection(t){return o(3,t)}export function decodeNetCharacterOwnerCorrection(t){const e=i(t,3);return!1===e.ok?{ok:!1,reason:e.reason}:{ok:!0,value:{snapshot:e.value}}}export function encodeNetCharacterSimulatedState(t){return o(4,t)}export function decodeNetCharacterSimulatedState(t){return i(t,4)}export function replayNetCharacterSavedMoves(t,e,n,o=64){let i=t;const s=Math.min(o,e.length);for(let t=0;t<s;t++)i=n(i,e[t]);return i}export function createNetCharacterServerMoveTimingState(){return{lastClientTime:0,serverTimeBudget:0}}export function accrueNetCharacterServerMoveTime(t,e,n=.25){!Number.isFinite(e)||e<=0||(t.serverTimeBudget=Math.min(n,t.serverTimeBudget+e))}export function consumeNetCharacterServerMoveTime(t,e,n={}){if(!Number.isFinite(e.clientTime))return-1;const o=e.clientTime-t.lastClientTime;if(!Number.isFinite(o)||o<=0)return-1;const i=n.maxMoveDeltaTime??.06666666666666667,s=Math.max(1,n.maxServerMoveDeltaTimeScalar??1.75),r=n.maxClientTimeAhead??.1,a=Math.max(.001,i*s),c=Math.min(o,a),l=t.serverTimeBudget-c;return l<-r?-1:(t.serverTimeBudget=l,t.lastClientTime=e.clientTime,Math.max(.001,c))}export function createNetCharacterMovementSnapshot(t={}){return{sequence:0,x:0,y:0,z:0,velocityX:0,velocityY:0,velocityZ:0,yaw:0,mode:e.walking,flags:0,horizontalSpeed:0,...t}}export function isSequenceGreater(t,e){return t-e>>>0<2147483648&&t!==e}export function isSequenceLessOrEqual(t,e){return t===e||!isSequenceGreater(t,e)}function o(t,e){const n=new Uint8Array(41),o=new DataView(n.buffer);let i=0;return o.setUint8(i++,3),o.setUint8(i++,t),o.setUint32(i,e.sequence>>>0,!0),i+=4,o.setFloat32(i,e.x,!0),i+=4,o.setFloat32(i,e.y,!0),i+=4,o.setFloat32(i,e.z,!0),i+=4,o.setFloat32(i,e.velocityX,!0),i+=4,o.setFloat32(i,e.velocityY,!0),i+=4,o.setFloat32(i,e.velocityZ,!0),i+=4,o.setFloat32(i,e.yaw,!0),i+=4,o.setUint8(i++,e.mode),o.setUint8(i++,255&e.flags),o.setFloat32(i,e.horizontalSpeed,!0),n}function i(t,e){if(41!==t.byteLength)return{ok:!1,reason:"malformed"};const n=u(t);let o=0;if(3!==n.getUint8(o++))return{ok:!1,reason:"unsupported-version"};if(n.getUint8(o++)!==e)return{ok:!1,reason:"wrong-kind"};const i=n.getUint32(o,!0);o+=4;const s=n.getFloat32(o,!0);o+=4;const r=n.getFloat32(o,!0);o+=4;const a=n.getFloat32(o,!0);o+=4;const c=n.getFloat32(o,!0);o+=4;const l=n.getFloat32(o,!0);o+=4;const h=n.getFloat32(o,!0);o+=4;const p=n.getFloat32(o,!0);o+=4;return{ok:!0,value:{sequence:i,x:s,y:r,z:a,velocityX:c,velocityY:l,velocityZ:h,yaw:p,mode:n.getUint8(o++),flags:n.getUint8(o++),horizontalSpeed:n.getFloat32(o,!0)}}}function s(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 r(t,e){e.sequence=t.sequence,e.x=t.x,e.y=t.y,e.z=t.z,e.velocityX=t.velocityX,e.velocityY=t.velocityY,e.velocityZ=t.velocityZ,e.yaw=t.yaw,e.mode=t.mode,e.flags=t.flags,e.horizontalSpeed=t.horizontalSpeed}function a(e,n,o,i){i.sequence=n.sequence,i.x=t.lerp(e.x,n.x,o),i.y=t.lerp(e.y,n.y,o),i.z=t.lerp(e.z,n.z,o),i.velocityX=t.lerp(e.velocityX,n.velocityX,o),i.velocityY=t.lerp(e.velocityY,n.velocityY,o),i.velocityZ=t.lerp(e.velocityZ,n.velocityZ,o),i.yaw=e.yaw+(t.euclideanModulo(n.yaw-e.yaw+Math.PI,2*Math.PI)-Math.PI)*o,i.mode=o<1?e.mode:n.mode,i.flags=o<1?e.flags:n.flags,i.horizontalSpeed=t.lerp(e.horizontalSpeed,n.horizontalSpeed,o)}function c(t,e){const n=t.x-e.x,o=t.y-e.y,i=t.z-e.z;return n*n+o*o+i*i}function l(e){return t.clamp(Math.round(32767*t.clamp(e,-1,1)),-32767,32767)}function h(e){return t.clamp(e/32767,-1,1)}function u(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -16,6 +16,7 @@ export declare class MeshComponent<TObj extends Object3D = Object3D> extends Act
|
|
|
16
16
|
private currentMesh;
|
|
17
17
|
private physicsSystem;
|
|
18
18
|
onInit(): void | Promise<void>;
|
|
19
|
+
applySceneParameters(parameters: Record<string, unknown>, changedParameters: ReadonlySet<string>): boolean;
|
|
19
20
|
setObject(replacement: TObj): void;
|
|
20
21
|
private updateMesh;
|
|
21
22
|
private getCollisionShapes;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as t,__metadata as i}from"tslib";import{PhysicsBodyType as e,PhysicsSystem as o}from"../../../../gameplay/services/physics/physics-system.js";import{AssetMeshInstance as s}from"../../../../scene/asset-resource-loader.js";import{PhysicalShapeMesh as
|
|
1
|
+
import{__decorate as t,__metadata as i}from"tslib";import{PhysicsBodyType as e,PhysicsSystem as o}from"../../../../gameplay/services/physics/physics-system.js";import{AssetMeshInstance as s}from"../../../../scene/asset-resource-loader.js";import{PhysicalShapeMesh as n}from"../../../../scene/collision/collision-shape.js";import{Parameter as r}from"../../../../shader/parameter.js";import{Euler as c,Object3D as h,Vector3 as p}from"three";import{ActorComponent as l,Component as a}from"../../component.js";import{firstValueFrom as y}from"rxjs";import{inject as u}from"../../../../gameplay/inject.js";let m=null;let d=class extends l{constructor(){super(...arguments),this.position=new p,this.rotation=new c,this.scale=new p(1,1,1),this.collision=!0,this.bodyType=2,this.mass=0,this.friction=.1,this.restitution=1,this.isTrigger=!1,this.continousCollisionDetection=!1,this.physicsSystem=u(o)}onInit(){null!=this.object&&(this.currentMesh=this.object,this.updateMesh()),y(this.disposed).then(()=>{this.physicsSystem.removeActor(this.actor)})}applySceneParameters(t,i){return!(!this.currentMesh||1!==i.size)&&(i.has("position")&&t.position instanceof p?(this.currentMesh.position.copy(t.position),!0):i.has("rotation")&&t.rotation instanceof c?(this.currentMesh.rotation.copy(t.rotation),!0):!!(i.has("scale")&&t.scale instanceof p)&&(this.currentMesh.scale.copy(t.scale),!0))}setObject(t){null!=this.currentMesh&&this.actor.object.remove(this.currentMesh),this.object=this.currentMesh=t,this.updateMesh()}updateMesh(){this.currentMesh.position.copy(this.position),this.currentMesh.rotation.copy(this.rotation),this.currentMesh.scale.copy(this.scale);const t=this.getCollisionShapes();this.collision&&t.length>0&&this.physicsSystem.addActor(this.actor,t,{...(null===m&&(m={friction:.1,mass:0,restitution:1,bodyType:e.static,continousCollisionDetection:!1}),m),isTrigger:this.isTrigger??!1,mass:this.mass,friction:this.friction,type:this.bodyType,continousCollisionDetection:this.continousCollisionDetection,restitution:this.restitution}),this.actor.object.add(this.currentMesh)}getCollisionShapes(){return this.currentMesh instanceof s?this.currentMesh.collisionShapes:this.currentMesh instanceof n?[this.currentMesh.collisionShape]:"collisionShape"in this.currentMesh?(console.error("Could not understand wehre to get collision shapes from. This is likely due to an import issue"),[this.currentMesh.collisionShape]):[]}};t([r({type:h,label:"Model"}),i("design:type",Object)],d.prototype,"object",void 0),t([r(),i("design:type",p)],d.prototype,"position",void 0),t([r(),i("design:type",c)],d.prototype,"rotation",void 0),t([r(),i("design:type",p)],d.prototype,"scale",void 0),t([r({help:"Whether this mesh should have collision and/or physics simulation"}),i("design:type",Boolean)],d.prototype,"collision",void 0),t([r({requires:{collision:!0},options:[{name:"Static",value:2},{name:"Kinematic",value:4},{name:"Dynamic",value:1}]}),i("design:type",Number)],d.prototype,"bodyType",void 0),t([r({help:"Only for dynamic objects.",requires:{collision:!0,bodyType:1}}),i("design:type",Number)],d.prototype,"mass",void 0),t([r({help:"How much it slows down when touching other objects. Only for dynamic objects.",requires:{collision:!0,bodyType:1}}),i("design:type",Number)],d.prototype,"friction",void 0),t([r({help:"Control how much to bounce. Only for dynamic objects.",requires:{collision:!0,bodyType:1}}),i("design:type",Number)],d.prototype,"restitution",void 0),t([r({requires:{collision:!0}}),i("design:type",Boolean)],d.prototype,"isTrigger",void 0),d=t([a({inEditor:!0})],d);export{d as MeshComponent};/*
|
|
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 i}from"tslib";import{Euler as e,Vector3 as o}from"three";import{Subject as s}from"rxjs";import{ActorComponent as a,Component as n}from"../../component.js";import{Parameter as h}from"../../../../shader/parameter.js";import{Curve2 as r}from"../../../../utils/curve.js";import{inject as l}from"../../../../gameplay/inject.js";import{PhysicsSystem as p}from"../../../../gameplay/services/physics/physics-system.js";let d=class extends a{constructor(){super(...arguments),this.animatePosition=!1,this.targetPosition=new o(0,1,0),this.animateRotation=!1,this.targetRotation=new o(0,0,0),this.animateScale=!1,this.targetScale=new o(1,1,1),this.duration=1,this.delay=0,this.easing=r.linear(),this.relative=!0,this.loop=!1,this.pingPong=!1,this.autoPlay=!0,this.inEditor=!1,this.onComplete=new s,this.onLoop=new s,this.isPlaying=!1,this.isPaused=!1,this.elapsed=0,this.delayRemaining=0,this.direction=1,this.loopCount=0,this.startPosition=new o,this.startRotation=new e,this.startScale=new o,this.endPosition=new o,this.endRotation=new e,this.endScale=new o,this.physics=l(p)}onInit(){this.autoPlay&&this.inEditor&&this.play()}onBeginPlay(){this.autoPlay&&!this.inEditor&&this.play()}onEndPlay(){this.onComplete.complete(),this.onLoop.complete()}play(){this.isPlaying&&!this.isPaused||(this.isPlaying||(this.captureStartValues(),this.computeEndValues(),this.elapsed=0,this.delayRemaining=this.delay,this.direction=1,this.loopCount=0),this.isPlaying=!0,this.isPaused=!1
|
|
1
|
+
import{__decorate as t,__metadata as i}from"tslib";import{Euler as e,Vector3 as o}from"three";import{Subject as s}from"rxjs";import{ActorComponent as a,Component as n}from"../../component.js";import{Parameter as h}from"../../../../shader/parameter.js";import{Curve2 as r}from"../../../../utils/curve.js";import{inject as l}from"../../../../gameplay/inject.js";import{PhysicsSystem as p}from"../../../../gameplay/services/physics/physics-system.js";let d=class extends a{constructor(){super(...arguments),this.animatePosition=!1,this.targetPosition=new o(0,1,0),this.animateRotation=!1,this.targetRotation=new o(0,0,0),this.animateScale=!1,this.targetScale=new o(1,1,1),this.duration=1,this.delay=0,this.easing=r.linear(),this.relative=!0,this.loop=!1,this.pingPong=!1,this.autoPlay=!0,this.inEditor=!1,this.onComplete=new s,this.onLoop=new s,this.isPlaying=!1,this.isPaused=!1,this.elapsed=0,this.delayRemaining=0,this.direction=1,this.loopCount=0,this.startPosition=new o,this.startRotation=new e,this.startScale=new o,this.endPosition=new o,this.endRotation=new e,this.endScale=new o,this.physics=l(p)}onInit(){this.autoPlay&&this.inEditor&&this.play()}onBeginPlay(){this.autoPlay&&!this.inEditor&&this.play()}onEndPlay(){this.onComplete.complete(),this.onLoop.complete()}play(){this.isPlaying&&!this.isPaused||(this.isPlaying||(this.captureStartValues(),this.computeEndValues(),this.elapsed=0,this.delayRemaining=this.delay,this.direction=1,this.loopCount=0),this.isPlaying=!0,this.isPaused=!1)}pause(){this.isPaused=!0}stop(){this.isPlaying=!1,this.isPaused=!1,this.elapsed=0,this.applyValues(0)}reverse(){this.direction*=-1}restart(){this.stop(),this.play()}get progress(){return this.duration>0?this.elapsed/this.duration:0}get playing(){return this.isPlaying&&!this.isPaused}onUpdate(t){if(!this.isPlaying||this.isPaused)return;if(this.delayRemaining>0)return void(this.delayRemaining-=t);this.elapsed+=t*this.direction,this.elapsed>=this.duration?(this.elapsed=this.duration,this.handleComplete()):this.elapsed<=0&&(this.elapsed=0,this.handleComplete());const i=this.elapsed/this.duration,e=this.easing.getY(i);this.applyValues(e)}captureStartValues(){this.startPosition.copy(this.actor.position),this.startRotation.copy(this.actor.rotation),this.startScale.copy(this.actor.object.scale)}computeEndValues(){if(this.animatePosition&&(this.relative?this.endPosition.copy(this.startPosition).add(this.targetPosition):this.endPosition.copy(this.targetPosition)),this.animateRotation){const t=new o(this.targetRotation.x*Math.PI/180,this.targetRotation.y*Math.PI/180,this.targetRotation.z*Math.PI/180);this.relative?this.endRotation.set(this.startRotation.x+t.x,this.startRotation.y+t.y,this.startRotation.z+t.z):this.endRotation.set(t.x,t.y,t.z)}this.animateScale&&(this.relative?this.endScale.set(this.startScale.x*this.targetScale.x,this.startScale.y*this.targetScale.y,this.startScale.z*this.targetScale.z):this.endScale.copy(this.targetScale))}applyValues(t){let i=!1;this.animatePosition&&(this.actor.position.lerpVectors(this.startPosition,this.endPosition,t),i=!0),this.animateRotation&&(this.actor.rotation.set(this.startRotation.x+(this.endRotation.x-this.startRotation.x)*t,this.startRotation.y+(this.endRotation.y-this.startRotation.y)*t,this.startRotation.z+(this.endRotation.z-this.startRotation.z)*t),i=!0),this.animateScale&&this.actor.object.scale.lerpVectors(this.startScale,this.endScale,t),i&&this.physics.updateActorTransform(this.actor)}handleComplete(){this.loopCount++,this.onLoop.next(this.loopCount),this.loop?this.pingPong?this.direction*=-1:this.elapsed=0:(this.isPlaying=!1,this.onComplete.next())}};t([h({help:"Enable position animation"}),i("design:type",Boolean)],d.prototype,"animatePosition",void 0),t([h({help:"The position to animate to (relative offset or absolute world position)",requires:{animatePosition:!0}}),i("design:type",o)],d.prototype,"targetPosition",void 0),t([h({help:"Enable rotation animation"}),i("design:type",Boolean)],d.prototype,"animateRotation",void 0),t([h({help:"The rotation to animate to in degrees (relative offset or absolute)",requires:{animateRotation:!0}}),i("design:type",o)],d.prototype,"targetRotation",void 0),t([h({label:"Animate Scale",help:"Enable scale animation"}),i("design:type",Boolean)],d.prototype,"animateScale",void 0),t([h({help:"The scale to animate to (relative multiplier or absolute)",requires:{animateScale:!0}}),i("design:type",o)],d.prototype,"targetScale",void 0),t([h({help:"Animation duration in seconds",range:[.01,60],precision:2}),i("design:type",Number)],d.prototype,"duration",void 0),t([h({help:"Delay before animation starts in seconds",range:[0,60],precision:2}),i("design:type",Number)],d.prototype,"delay",void 0),t([h({help:"The easing curve for the animation"}),i("design:type",r)],d.prototype,"easing",void 0),t([h({help:"If true, targets are offsets from initial values. If false, targets are absolute values."}),i("design:type",Boolean)],d.prototype,"relative",void 0),t([h({help:"Repeat the animation forever"}),i("design:type",Boolean)],d.prototype,"loop",void 0),t([h({help:"Reverse direction each loop (yo-yo effect)",requires:{loop:!0}}),i("design:type",Boolean)],d.prototype,"pingPong",void 0),t([h({help:"Start animation automatically when the actor spawns"}),i("design:type",Boolean)],d.prototype,"autoPlay",void 0),t([h({help:"Play the animation in the editor. Useful for testing."}),i("design:type",Boolean)],d.prototype,"inEditor",void 0),d=t([n({inEditor:!0})],d);export{d as TweenComponent};/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -17,10 +17,12 @@ declare class NavMeshActor extends BaseActor {
|
|
|
17
17
|
walkableHeight: number;
|
|
18
18
|
cellSize: number;
|
|
19
19
|
navMesh: NavMesh;
|
|
20
|
+
private debugDrawer;
|
|
20
21
|
private bounds;
|
|
21
22
|
private recreateInterval;
|
|
22
23
|
onInit(): Promise<void>;
|
|
23
24
|
onEndPlay(): void;
|
|
25
|
+
applySceneParameters(parameters: Record<string, unknown>, changedParameters: ReadonlySet<string>): boolean;
|
|
24
26
|
private init;
|
|
25
27
|
}
|
|
26
28
|
export default NavMeshActor;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as e,__metadata as t}from"tslib";import{Ball as n,Capsule as s,Cone as o,ConvexPolyhedron as i,Cuboid as r,Cylinder as a,Heightfield as l,ShapeType as c,TriMesh as h}from"@dimforge/rapier3d-simd-compat";import{init as p}from"@recast-navigation/core";import{DebugDrawer as u,getPositionsAndIndices as d}from"@recast-navigation/three";import{BehaviorSubject as m,Subject as f,debounceTime as w,filter as b,firstValueFrom as g,takeUntil as y}from"rxjs";import*as x from"three";import{BufferGeometryUtils as v,ConvexHull as M}from"three/examples/jsm/Addons.js";import{Actor as B,BaseActor as S,Parameter as z,PhysicsSystem as A,ViewController as k,World as C,attach as j,inject as
|
|
1
|
+
import{__decorate as e,__metadata as t}from"tslib";import{Ball as n,Capsule as s,Cone as o,ConvexPolyhedron as i,Cuboid as r,Cylinder as a,Heightfield as l,ShapeType as c,TriMesh as h}from"@dimforge/rapier3d-simd-compat";import{init as p}from"@recast-navigation/core";import{DebugDrawer as u,getPositionsAndIndices as d}from"@recast-navigation/three";import{BehaviorSubject as m,Subject as f,debounceTime as w,filter as b,firstValueFrom as g,takeUntil as y}from"rxjs";import*as x from"three";import{BufferGeometryUtils as v,ConvexHull as M}from"three/examples/jsm/Addons.js";import{Actor as B,BaseActor as S,Parameter as z,PhysicsSystem as A,ViewController as k,World as C,attach as j,inject as P}from"../../";import{sleepDelay as F}from"../../../utils/async";import{hasSharedArrayBufferSupport as I,toSharedFloat32Array as D,toSharedUint32Array as V}from"../../../utils/buffer";import{DynamicTiledNavMesh as G}from"../../ai/dynamic-tiled-navmesh";import{TriggerVolumeMesh as N}from"./components/volume-editor-component";var H;!function(e){e[e.none=0]="none",e[e.starting=1]="starting",e[e.started=2]="started"}(H||(H={}));let E=H.none,T=new m(!1);export async function safeRecastInit(){return E===H.none?(E=H.starting,p().then(()=>{T.next(!0),E=H.started})):g(T.pipe(b(e=>e)))}new x.Box3(new x.Vector3(-100,-100,-100),new x.Vector3(100,100,100));const R=navigator.hardwareConcurrency??1;let U=!1,q=class extends S{constructor(){super(...arguments),this.physics=P(A),this.view=P(k),this.world=P(C),this.editorVisualisation=j(N),this.debug=!0,this.refreshMs=4e3,this.tileSize=50,this.walkableClimb=.3,this.walkableSlopeAngle=45,this.walkableHeight=2,this.cellSize=.2,this.bounds=new x.Box3}async onInit(){U||(await safeRecastInit(),U=!0),setTimeout(()=>{this.init()},10),this.recreateInterval=setInterval(()=>{if("_hology_transform_group"===this.object.parent?.name)return;$.setFromCenterAndSize(this.position,this.object.scale).equals(this.bounds)||(this.disposed.next(!0),this.disposed=new f,this.init())},2e3)}onEndPlay(){clearInterval(this.recreateInterval)}applySceneParameters(e,t){return!(null==this.debugDrawer||!t.has("debug")||"boolean"!=typeof e.debug)&&(this.debugDrawer.visible=e.debug,!0)}init(){this.bounds.setFromCenterAndSize(this.position,this.object.scale);const e=this.bounds.max.x-this.bounds.min.x,t=this.bounds.max.z-this.bounds.min.z,n=Math.max(1,Math.min(e,t)),s=Math.min(400,Math.max(50,Math.ceil(n/2))),o=Math.max(this.cellSize,.01),i={tileSize:Math.max(32,Math.floor(s/o)),walkableClimb:this.walkableClimb/o,walkableSlopeAngle:this.walkableSlopeAngle,walkableRadius:2,walkableHeight:this.walkableHeight/o,detailSampleDist:1,minRegionArea:6,mergeRegionArea:400,cs:o,ch:o,maxSimplificationError:1.3,maxEdgeLen:200},r=new G({navMeshBounds:this.bounds,recastConfig:i,maxTiles:1024,workers:R,cacheId:"nav"+this.object.userData?.src?.id});this.navMesh=r.navMesh;const a=this.tileSize*i.cs*2,l=performance.now(),c=new Map,h=new u;h.userData.isDebugDrawer=!0,this.debugDrawer=h;r.navMesh;const p=this.bounds,m=()=>{const e=this.view.getCamera().getWorldPosition(new x.Vector3),t=new x.Box3((new x.Vector3).copy(e).subScalar(a),(new x.Vector3).copy(e).addScalar(a)),n=[],s=this.physics.world.bodies;if(null==s)return[];const o=new x.Box3;for(const e of s.getAll())for(let s=0,i=e.numColliders();s<i;s++){const i=e.collider(s);if(i.isSensor()||null!=i.parent().userData&&!0===i.parent().userData.ignoreForNavMesh)continue;const r=e.handle+","+s,a=c.get(r)?.mesh,l=a??L(i);if(X(i,l),null!=l){o.copy(l.geometry.boundingBox),o.min.add(l.position),o.max.add(l.position);const e=o.intersectsBox(t)||!0,s=o.intersectsBox(this.bounds);c.set(r,{pos:i.translation(),mesh:l}),e&&s&&n.push(l)}}return n},f=new x.Box3,b=new Map,g=new Map;let v=!0,M=performance.now(),B=!1;const S=function(e,t){let n=!1;return(async()=>{for(;!n;)await e(),await F(t)})(),()=>{n=!0}}(async()=>{if(B)return;const e=new x.Box3,t=m();for(const n of t){const t=b.get(n);!0!==t?.equals(n.position)&&(null!=t&&e.expandByPoint(t),e.expandByObject(n),b.set(n,n.position.clone()))}e.min.subScalar(50),e.max.addScalar(50);const n=r.getTilesForBounds(e);n.length>500&&console.warn("Too many tiles to update. Consider increasing tile size");const s=n.slice(0,500);if(0!=s.length){const n=[];for(const s of t)f.setFromObject(s),f.intersectsBox(e)&&n.push(s);let[o,i]=d(n);i=function(e,t,n){const s=new x.Vector3,o=[];for(let i=0;i<t.length;i+=3){let r=!0;for(let o=0;o<3;o++){const a=3*t[i+o];if(s.fromArray(e,a),!n.containsPoint(s)){r=!1;break}}r&&o.push(t[i],t[i+1],t[i+2])}return new Uint32Array(o)}(o,i,p),I&&(o=D(o),i=V(i));const a=v;v=!1,await Promise.all(s.map(e=>(M=performance.now(),r.buildTile(o,i,e,a).then(()=>{const t=e[0]+","+e[1];g.set(t,(g.get(t)??0)+1),this.debug})))).then(()=>{this.debug,B=!1})}else B=!1},this.refreshMs??1e4);this.disposed.subscribe(()=>S()),r.onNavMeshUpdate.pipe(y(this.disposed),w(200)).subscribe(()=>{h.clear(),h.drawNavMesh(r.navMesh)}),console.log("Create navmesh with debug",this.debug),this.debug&&(this.object.rotation.set(0,0,0),this.object.updateMatrix(),this.object.updateMatrixWorld(),this.object.parent.add(h)),this.disposed.subscribe(()=>{r?.destroy(),h.removeFromParent(),h.dispose()});const z=performance.now()-l;z>1e3&&console.warn(`NavMesh update took ${z} ms. Consider changing tileSize or other parameter that may affect performance`)}};e([z(),t("design:type",Boolean)],q.prototype,"debug",void 0),e([z(),t("design:type",Number)],q.prototype,"walkableClimb",void 0),e([z({range:[0,89]}),t("design:type",Number)],q.prototype,"walkableSlopeAngle",void 0),e([z(),t("design:type",Number)],q.prototype,"walkableHeight",void 0),e([z({range:[.01,10]}),t("design:type",Number)],q.prototype,"cellSize",void 0),q=e([B()],q);export default q;const O=new Map,W=new WeakMap;function _(e){if(e.shape instanceof l)return function(e){const t=e.shape;if(t.type!==c.HeightField)throw new Error("The provided collider is not a height field.");let n=!1;const s=t,o=s.heights,i=s.nrows,r=s.ncols,a=s.scale.x,l=s.scale.z,h=s.scale.y,p=i+1,u=new x.PlaneGeometry(l,a,r,i);u.rotateX(-Math.PI/2);const d=u.attributes.position.array;let m=0;for(let e=0;e<p;e++)for(let t=0;t<p;t++)d[m+1]=o[t*p+e]*h,m+=3,0!=d[m+1]&&(n=!0);if(!n){const e=new x.PlaneGeometry(a,l,2,2);return e.rotateX(-Math.PI/2),e}return u}(e);if(e.shape instanceof n)return new x.SphereGeometry(e.shape.radius);if(e.shape instanceof r){const t=e.shape.halfExtents;return new x.BoxGeometry(2*t.x,2*t.y,2*t.z)}if(e.shape instanceof i){const t=function(e){const t=W.get(e);if(void 0!==t)return t;const n=new Uint32Array(e.buffer,e.byteOffset,e.byteLength>>>2);let s=2166136261;for(let e=0;e<n.length;e++)s=Math.imul(s^n[e],16777619)>>>0;return W.set(e,s),s}(e.shape.vertices);let n=O.get(t);return n||(n=function(e){const t=[];for(let n=0;n<e.length;n+=3)t.push(new x.Vector3(e[n],e[n+1],e[n+2]));const n=(new M).setFromPoints(t),s=[];n.faces.forEach(e=>{const t=e.edge.head().point,n=e.edge.next.head().point,o=e.edge.next.next.head().point;s.push(t.x,t.y,t.z),s.push(n.x,n.y,n.z),s.push(o.x,o.y,o.z)});const o=new x.BufferGeometry;return o.setAttribute("position",new x.Float32BufferAttribute(s,3)),o}(e.shape.vertices),O.set(t,n)),n}if(e.shape instanceof h){const t=e.shape.vertices,n=e.shape.indices;let s=new x.BufferGeometry;return s.setAttribute("position",new x.Float32BufferAttribute(t,3)),null!=n?s.setIndex(new x.Uint16BufferAttribute(n,1)):s=v.mergeVertices(s),s.computeVertexNormals(),s}if(e.shape instanceof a){const t=e.shape.halfHeight,n=e.shape.radius;return new x.CylinderGeometry(n,n,2*t)}if(e.shape instanceof o){const t=e.shape.halfHeight,n=e.shape.radius;return new x.ConeGeometry(n,2*t)}if(e.shape instanceof s){const t=e.shape.halfHeight,n=e.shape.radius;return new x.CapsuleGeometry(n,2*t)}return console.warn("Unsupported shape",e.shape.type,e),null}function L(e){const t=_(e);if(null==t)return null;const n=J,s=new x.Mesh(t,n);return s.geometry.computeBoundingBox(),s.geometry.scale(1.01,1.01,1.01),s}function X(e,t){const n=e.translation(),s=e.rotation();t.position.set(n.x,n.y,n.z),t.quaternion.set(s.x,s.y,s.z,s.w)}const $=new x.Box3,J=new x.MeshBasicMaterial({wireframe:!1,color:16711680,side:x.FrontSide});/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Vector3, Color } from "three";
|
|
2
2
|
import { BaseActor } from '../actor.js';
|
|
3
3
|
import { ActorComponent } from '../component.js';
|
|
4
|
-
import { PhysicsSystem } from '../../services/physics/physics-system.js';
|
|
5
4
|
import { Observable } from "rxjs";
|
|
6
5
|
import { Type } from '../../../utils/type.js';
|
|
7
6
|
export declare class TriggerVolumeMesh extends ActorComponent {
|
|
@@ -10,12 +9,13 @@ export declare class TriggerVolumeMesh extends ActorComponent {
|
|
|
10
9
|
onInit(): void | Promise<void>;
|
|
11
10
|
}
|
|
12
11
|
export declare class TriggerVolumeComponent extends ActorComponent {
|
|
13
|
-
private physicsSystem;
|
|
14
12
|
readonly dimensions: Vector3;
|
|
15
13
|
readonly offset: Vector3;
|
|
16
14
|
private editorMesh;
|
|
17
|
-
|
|
15
|
+
private physicsSystem;
|
|
18
16
|
onInit(): Promise<void> | void;
|
|
17
|
+
onBeginOverlap(): Observable<BaseActor>;
|
|
18
|
+
onEndOverlap(): Observable<BaseActor>;
|
|
19
19
|
onBeginOverlapWithActor<A extends BaseActor>(actor: A): Observable<A>;
|
|
20
20
|
onEndOverlapWithActor<A extends BaseActor>(actor: A): Observable<A>;
|
|
21
21
|
onBeginOverlapWithActorType<A extends BaseActor>(actorType: Type<A>): Observable<A>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as
|
|
1
|
+
var e,t;import{__decorate as r,__metadata as i}from"tslib";import{EdgesGeometry as n,LineSegments as o,LineBasicMaterial as s,Vector3 as p,BoxGeometry as a,Mesh as c,MeshBasicMaterial as l,Group as y,Color as h}from"three";import{Actor as d,BaseActor as m}from"../actor.js";import{Component as g,ActorComponent as O,attach as u}from"../component.js";import{PhysicsSystem as v}from"../../services/physics/physics-system.js";import{BoxCollisionShape as f}from"../../../scene/collision/collision-shape.js";import{Parameter as b}from"../../../shader/parameter.js";import{firstValueFrom as j,Observable as W}from"rxjs";import{inject as w}from"../../../gameplay/inject.js";import{EventGraphEventSource as E,EventGraphProperty as B}from"../../event-graph/decorators.js";import{EVENT_GRAPH_ACTOR_CLASS_TYPE as T,EVENT_GRAPH_ACTOR_TYPE as S}from"../../event-graph/types.js";let x=class extends O{constructor(){super(...arguments),this.color=new h(16777215),this.dimensions=new p(1,1,1)}onInit(){const e=new a(this.dimensions.x,this.dimensions.y,this.dimensions.z),t=new n(e),r=new o(t,new s({color:this.color})),i=(new c(e,new l({color:this.color,transparent:!0,opacity:.3,visible:!1})),new y);i.add(r),this.actor.object.add(i)}};r([b(),i("design:type",h)],x.prototype,"color",void 0),r([b(),i("design:type",p)],x.prototype,"dimensions",void 0),x=r([g({inEditor:!0,editorOnly:!0})],x);export{x as TriggerVolumeMesh};let F=class extends O{constructor(){super(...arguments),this.dimensions=new p(1,1,1),this.offset=new p(0,0,0),this.editorMesh=u(x),this.physicsSystem=w(v)}onInit(){this.physicsSystem.addActor(this.actor,[new f(this.dimensions).withOffset(this.offset)],{isTrigger:!0}),j(this.disposed).then(()=>{this.physicsSystem.removeActor(this.actor)})}onBeginOverlap(){return this.physicsSystem.onBeginOverlap(this.actor)}onEndOverlap(){return this.physicsSystem.onEndOverlap(this.actor)}onBeginOverlapWithActor(e){return this.physicsSystem.onBeginOverlapWithActor(this.actor,e)}onEndOverlapWithActor(e){return this.physicsSystem.onEndOverlapWithActor(this.actor,e)}onBeginOverlapWithActorType(e){return this.physicsSystem.onBeginOverlapWithActorType(this.actor,e)}onEndOverlapWithActorType(e){return this.physicsSystem.onEndOverlapWithActorType(this.actor,e)}};r([E({label:"On Begin Overlap",emits:S,valueLabel:"Other Actor"}),i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",W)],F.prototype,"onBeginOverlap",null),r([E({label:"On End Overlap",emits:S,valueLabel:"Other Actor"}),i("design:type",Function),i("design:paramtypes",[]),i("design:returntype",W)],F.prototype,"onEndOverlap",null),r([E({label:"On Begin Overlap With Actor",parameters:[{name:"actor",type:S}],emits:S,valueLabel:"Other Actor"}),i("design:type",Function),i("design:paramtypes",["function"==typeof(e="undefined"!=typeof A&&A)?e:Object]),i("design:returntype",W)],F.prototype,"onBeginOverlapWithActor",null),r([E({label:"On End Overlap With Actor",parameters:[{name:"actor",type:S}],emits:S,valueLabel:"Other Actor"}),i("design:type",Function),i("design:paramtypes",["function"==typeof(t="undefined"!=typeof A&&A)?t:Object]),i("design:returntype",W)],F.prototype,"onEndOverlapWithActor",null),r([E({label:"On Begin Overlap With Actor Type",parameters:[{name:"actorType",type:T}],emits:S,valueLabel:"Other Actor"}),i("design:type",Function),i("design:paramtypes",[Object]),i("design:returntype",W)],F.prototype,"onBeginOverlapWithActorType",null),r([E({label:"On End Overlap With Actor Type",parameters:[{name:"actorType",type:T}],emits:S,valueLabel:"Other Actor"}),i("design:type",Function),i("design:paramtypes",[Object]),i("design:returntype",W)],F.prototype,"onEndOverlapWithActorType",null),F=r([g({inEditor:!0,editorOnly:!1})],F);export{F as TriggerVolumeComponent};let L=class extends m{constructor(){super(...arguments),this.trigger=u(F)}};r([B({type:F,writable:!1}),i("design:type",Object)],L.prototype,"trigger",void 0),L=r([d({typeId:"TriggerVolume"})],L);export{L as TriggerVolume};/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { PerspectiveCamera } from 'three';
|
|
2
|
-
import { ViewController } from '../../services/render.js';
|
|
3
2
|
import { ActorComponent } from '../component.js';
|
|
4
3
|
export declare class CameraComponent extends ActorComponent {
|
|
5
|
-
private viewController;
|
|
6
4
|
near: number;
|
|
7
5
|
far: number;
|
|
8
6
|
viewAngle: number;
|
|
7
|
+
private viewController;
|
|
9
8
|
private debugMesh;
|
|
10
9
|
private aspect;
|
|
11
10
|
instance: PerspectiveCamera;
|
|
12
|
-
constructor(viewController: ViewController);
|
|
13
11
|
onInit(): void | Promise<void>;
|
|
14
12
|
}
|
|
15
13
|
export declare class CameraMesh extends ActorComponent {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as e,__metadata as t}from"tslib";import{ArrowHelper as r,ConeGeometry as i,EdgesGeometry as
|
|
1
|
+
import{__decorate as e,__metadata as t}from"tslib";import{ArrowHelper as r,ConeGeometry as i,EdgesGeometry as o,LineBasicMaterial as s,LineSegments as n,MeshStandardMaterial as a,PerspectiveCamera as l,Vector3 as h}from"three";import{Parameter as c}from"../../../shader/parameter.js";import{ViewController as d}from"../../services/render.js";import{ActorComponent as p,attach as m,Component as w}from"../component.js";import{inject as v}from"../../../gameplay/inject.js";const b=void 0!==window&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let y=class extends p{constructor(){super(...arguments),this.near=.5,this.far=500,this.viewAngle=b?30:45,this.viewController=v(d),this.debugMesh=m(f),this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.instance=new l(this.viewAngle,this.aspect,this.near,this.far)}onInit(){this.actor.object.add(this.instance),this.instance.near=this.near,this.instance.far=this.far,this.instance.fov=this.viewAngle}};e([c(),t("design:type",Number)],y.prototype,"near",void 0),e([c(),t("design:type",Number)],y.prototype,"far",void 0),e([c(),t("design:type",Number)],y.prototype,"viewAngle",void 0),y=e([w({inEditor:!0})],y);export{y as CameraComponent};let f=class extends p{constructor(){super(...arguments),this.arrowColor=16101442}onInit(){const e=new i(1,1,4);e.rotateX(Math.PI/2),e.rotateZ(Math.PI/4),e.scale(1,9/16,1);const t=new o(e),l=(new a({color:3355443}),new n(t,new s({color:16777215}))),c=new r(new h(0,0,-1),new h(0,0,0),1.2,this.arrowColor,.15,.2);l.add(c),c.layers.disableAll(),c.layers.enable(19),c.traverse(e=>{e.layers.disableAll(),e.layers.enable(19)}),this.actor.object.add(l)}};f=e([w({inEditor:!0,editorOnly:!0})],f);export{f as CameraMesh};/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Constructable } from 'typedi';
|
|
2
2
|
import { BaseActor } from './actor.js';
|
|
3
|
+
export { getComponentClassById, getComponentClassId, getRegisteredComponentClasses, } from './type-registry.js';
|
|
3
4
|
export declare abstract class ActorComponent<ActorType extends BaseActor = BaseActor> {
|
|
4
5
|
actor: ActorType;
|
|
5
6
|
constructor();
|
|
@@ -22,6 +23,8 @@ export declare abstract class ActorComponent<ActorType extends BaseActor = BaseA
|
|
|
22
23
|
protected attach<T extends ActorComponent>(type: Constructable<T>, props?: ComponentAttachProps<T>): T;
|
|
23
24
|
}
|
|
24
25
|
export type ComponentOptions = {
|
|
26
|
+
/** Stable serialized identity. Defaults to the class name for backwards compatibility. */
|
|
27
|
+
typeId?: string;
|
|
25
28
|
/**
|
|
26
29
|
* While in the editor, only components explicitly set to be used in the editor should be initiated.
|
|
27
30
|
* This is because other components may fail as there will be many things that are not
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Container as t,Service as o,Inject as
|
|
1
|
+
import{Container as t,Service as o,Inject as e}from"typedi";import{_setupActorUpdateEventHandlers as n}from"./actor.js";import{activeContainerInstance as r}from"./internal/container-map.js";import{randomString as i}from"../../utils/math.js";import{actorConstructContext as a}from"./factory.js";import{registerComponentClass as s}from"./type-registry.js";export{getComponentClassById,getComponentClassId,getRegisteredComponentClasses}from"./type-registry.js";export class ActorComponent{constructor(){this.actor=a.actor,n.call(this)}onInit(){}onBeginPlay(){}onEndPlay(){}applySceneParameters(t,o){return!1}onUpdate(t){}onLateUpdate(t){}get disposed(){return this.actor.disposed}attach(t,o){return this.actor.attach(t,o)}}ActorComponent.__isActorComponent=!0;export function Component(t={inEditor:!1,editorOnly:!1}){const e=o({transient:!0});return function(o){const n=arguments[1],r=t.typeId??n?.name?.toString()??o.name,i=s(r,o);null!=i&&i!==o&&console.warn(`Duplicate component class id ${r}`),o.__componentId=r,o.__inEditor=t.inEditor,o.__onlyEditor=t.editorOnly,e(o)}}export function Attach(o={},n){return function(r,i,a){if(null==r)return void Reflect.defineMetadata("design:type",n,n.prototype,i);const s=n??Reflect.getMetadata("design:type",r,i);e(()=>s)(r,i,a);const c=t.handlers.find(t=>t.object===r&&t.propertyName===i&&t.index===a),p=c.value;c.value=t=>{const e=p(t);return Object.assign(e,o)}}}export function attach(o,e){const n=r.value??t.of("default"),a=i();n.set({id:a,type:o,transient:!0});const s=n.get(a);if(null!=e)for(const t of Object.keys(e))s[t]=e[t];return s}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Type } from '../../utils/type.js';
|
|
2
|
+
import type { BaseActor } from './actor.js';
|
|
3
|
+
import type { ActorComponent } from './component.js';
|
|
4
|
+
export declare function getActorClassById(id: string): Type<BaseActor> | undefined;
|
|
5
|
+
export declare function getActorClassId(type: Function): string | undefined;
|
|
6
|
+
export declare function getRegisteredActorClasses(): ReadonlyMap<string, Type<BaseActor>>;
|
|
7
|
+
export declare function getComponentClassById(id: string): Type<ActorComponent> | undefined;
|
|
8
|
+
export declare function getComponentClassId(type: Function): string | undefined;
|
|
9
|
+
export declare function getRegisteredComponentClasses(): ReadonlyMap<string, Type<ActorComponent>>;
|
|
10
|
+
//# sourceMappingURL=type-registry.d.ts.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
const t=new Map,e=new Map;export function getActorClassById(e){return t.get(e)}export function getActorClassId(t){return t.__actorId}export function getRegisteredActorClasses(){return t}export function registerActorClass(e,n){const r=t.get(e);return t.set(e,n),r}export function getComponentClassById(t){return e.get(t)}export function getComponentClassId(t){return t.__componentId}export function getRegisteredComponentClasses(){return e}export function registerComponentClass(t,n){const r=e.get(t);return e.set(t,n),r}/*
|
|
2
|
+
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
|
+
* See the LICENSE.md file for details.
|
|
4
|
+
*/
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AnimationClip, Object3D, Quaternion } from 'three';
|
|
2
|
+
import type { AnimationRetargetPose, AnimationRetargeterData, AnimationRigChain, AnimationRigData, Asset, AssetId } from '../../scene/model.js';
|
|
3
|
+
export declare const ANIMATION_RETARGET_GENERATOR_VERSION = 9;
|
|
4
|
+
export type ExtractedAnimationRig = Omit<AnimationRigData, 'previewMeshId'>;
|
|
5
|
+
export type AnimationRigExtractionResult = {
|
|
6
|
+
rigs: ExtractedAnimationRig[];
|
|
7
|
+
skinnedMeshNames: string[];
|
|
8
|
+
};
|
|
9
|
+
export type AnimationRetargetDiagnostic = {
|
|
10
|
+
severity: 'warning' | 'error';
|
|
11
|
+
code: string;
|
|
12
|
+
message: string;
|
|
13
|
+
};
|
|
14
|
+
export type BakeRetargetedAnimationOptions = {
|
|
15
|
+
sourceRig: AnimationRigData;
|
|
16
|
+
targetRig: AnimationRigData;
|
|
17
|
+
retargeter: AnimationRetargeterData;
|
|
18
|
+
sourceObject: Object3D;
|
|
19
|
+
targetObject: Object3D;
|
|
20
|
+
clip: AnimationClip;
|
|
21
|
+
};
|
|
22
|
+
export declare function resolveAnimationRigBasisRotation(rig: AnimationRigData): Quaternion;
|
|
23
|
+
export declare function detectAnimationRigBasisRotation(rig: Pick<AnimationRigData, 'bones' | 'pelvisBoneId' | 'chains'>): Quaternion;
|
|
24
|
+
/**
|
|
25
|
+
* Extracts every distinct skeleton used by skinned meshes or represented by a
|
|
26
|
+
* standalone bone hierarchy below an object. Meshes sharing the same Skeleton
|
|
27
|
+
* instance are represented once.
|
|
28
|
+
*/
|
|
29
|
+
export declare function extractAnimationRigs(object: Object3D): AnimationRigExtractionResult;
|
|
30
|
+
export declare function areAnimationRigsCompatible(a: AnimationRigData, b: AnimationRigData): boolean;
|
|
31
|
+
export declare function validateAnimationRig(rig: AnimationRigData): AnimationRetargetDiagnostic[];
|
|
32
|
+
export declare function validateAnimationRetargeter(retargeter: AnimationRetargeterData, sourceRig: AnimationRigData, targetRig: AnimationRigData): AnimationRetargetDiagnostic[];
|
|
33
|
+
export declare function createDefaultAnimationRetargeter(sourceRigId: AssetId, targetRigId: AssetId, sourceRig: AnimationRigData, targetRig: AnimationRigData): AnimationRetargeterData;
|
|
34
|
+
export declare function createAutoAlignedRetargetPose(sourceRig: AnimationRigData, targetRig: AnimationRigData, retargeter: AnimationRetargeterData, id?: string, name?: string): AnimationRetargetPose;
|
|
35
|
+
/**
|
|
36
|
+
* Bakes a target-specific clip. The saved rig/retargeter model is Hology-owned;
|
|
37
|
+
* SkeletonUtils is intentionally isolated here so the solver can be replaced
|
|
38
|
+
* without migrating authored assets.
|
|
39
|
+
*/
|
|
40
|
+
export declare function bakeRetargetedAnimationClip(options: BakeRetargetedAnimationOptions): AnimationClip;
|
|
41
|
+
export declare function getAnimationRigIdFromObject(object: Object3D | null | undefined): AssetId | undefined;
|
|
42
|
+
export declare function getAnimationRigDataFromObject(object: Object3D | null | undefined): AnimationRigData | undefined;
|
|
43
|
+
export declare function getAnimationRigChainBoneNames(rig: AnimationRigData | null | undefined, role: AnimationRigChain['role']): string[];
|
|
44
|
+
export declare function getAnimationClipBoneNames(clip: AnimationClip): string[];
|
|
45
|
+
export declare function isAnimationClipCompatibleWithRig(clip: AnimationClip, rig: AnimationRigData): boolean;
|
|
46
|
+
export declare function getAnimationClipRigId(clip: AnimationClip | null | undefined): AssetId | undefined;
|
|
47
|
+
export declare function setAnimationClipRigId(clip: AnimationClip, rigId: AssetId | undefined): void;
|
|
48
|
+
export declare function findGeneratedAnimationOutput(assets: readonly Asset[], sourceClipId: AssetId, targetRigId: AssetId): Asset | undefined;
|
|
49
|
+
export declare function resolveAnimationClipAssetForTarget(source: Asset, assets: readonly Asset[], targetRigId?: AssetId): Asset;
|
|
50
|
+
//# sourceMappingURL=retarget.d.ts.map
|