@@ -120,13 +120,13 @@ const Ecctrl: ForwardRefRenderFunction<RapierRigidBody, EcctrlProps> = ({
120
120
} : EcctrlProps , ref ) => {
121
121
const characterRef = ref as RefObject < RapierRigidBody > || useRef < RapierRigidBody > ( )
122
122
const characterModelRef = useRef < THREE . Group > ( ) ;
123
- const characterModelIndicator = useMemo ( ( ) => new THREE . Object3D ( ) , [ ] )
123
+ const characterModelIndicator : THREE . Object3D = useMemo ( ( ) => new THREE . Object3D ( ) , [ ] )
124
124
const defaultControllerKeys = { forward : 12 , backward : 13 , leftward : 14 , rightward : 15 , jump : 2 , action1 : 11 , action2 : 3 , action3 : 1 , action4 : 0 }
125
125
126
126
/**
127
127
* Mode setup
128
128
*/
129
- let isModePointToMove = false
129
+ let isModePointToMove : boolean = false
130
130
const setCameraBased = useGame ( ( state ) => state . setCameraBased ) ;
131
131
const getCameraBased = useGame ( ( state ) => state . getCameraBased ) ;
132
132
if ( mode ) {
@@ -137,15 +137,20 @@ const Ecctrl: ForwardRefRenderFunction<RapierRigidBody, EcctrlProps> = ({
137
137
/**
138
138
* Body collider setup
139
139
*/
140
- const modelFacingVec = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
141
- const bodyFacingVec = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
142
- const bodyBalanceVec = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
143
- const bodyBalanceVecOnX = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
144
- const bodyFacingVecOnY = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
145
- const bodyBalanceVecOnZ = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
146
- const vectorY = useMemo ( ( ) => new THREE . Vector3 ( 0 , 1 , 0 ) , [ ] ) ;
147
- const vectorZ = useMemo ( ( ) => new THREE . Vector3 ( 0 , 0 , 1 ) , [ ] ) ;
148
- const bodyContactForce = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
140
+ const modelFacingVec : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
141
+ const bodyFacingVec : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
142
+ const bodyBalanceVec : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
143
+ const bodyBalanceVecOnX : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
144
+ const bodyFacingVecOnY : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
145
+ const bodyBalanceVecOnZ : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
146
+ const vectorY : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( 0 , 1 , 0 ) , [ ] ) ;
147
+ const vectorZ : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( 0 , 0 , 1 ) , [ ] ) ;
148
+ const crossVecOnX : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
149
+ const crossVecOnY : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
150
+ const crossVecOnZ : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
151
+ const bodyContactForce : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
152
+ const slopeRayOriginUpdatePosition : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
153
+ const camBasedMoveCrossVecOnY : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
149
154
150
155
// Animation change functions
151
156
const idleAnimation = ! animated ? null : useGame ( ( state ) => state . idle ) ;
@@ -454,7 +459,7 @@ const Ecctrl: ForwardRefRenderFunction<RapierRigidBody, EcctrlProps> = ({
454
459
*/
455
460
let controllerIndex : number = null
456
461
const gamepadKeys = { forward : false , backward : false , leftward : false , rightward : false } ;
457
- const gamepadJoystickVec2 = useMemo ( ( ) => new THREE . Vector2 ( ) , [ ] )
462
+ const gamepadJoystickVec2 : THREE . Vector2 = useMemo ( ( ) => new THREE . Vector2 ( ) , [ ] )
458
463
let gamepadJoystickDis : number = 0
459
464
let gamepadJoystickAng : number = 0
460
465
const gamepadConnect = ( e : any ) => { controllerIndex = e . gamepad . index }
@@ -500,20 +505,20 @@ const Ecctrl: ForwardRefRenderFunction<RapierRigidBody, EcctrlProps> = ({
500
505
}
501
506
502
507
// can jump setup
503
- let canJump = false ;
504
- let isFalling = false ;
508
+ let canJump : boolean = false ;
509
+ let isFalling : boolean = false ;
505
510
const initialGravityScale : number = useMemo ( ( ) => props . gravityScale || 1 , [ ] )
506
511
507
512
// on moving object state
508
- let massRatio = 1 ;
509
- let isOnMovingObject = false ;
510
- const standingForcePoint = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
511
- const movingObjectDragForce = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
512
- const movingObjectVelocity = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
513
- const movingObjectVelocityInCharacterDir = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
514
- const distanceFromCharacterToObject = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
515
- const objectAngvelToLinvel = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
516
- const velocityDiff = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
513
+ let massRatio : number = 1 ;
514
+ let isOnMovingObject : boolean = false ;
515
+ const standingForcePoint : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
516
+ const movingObjectDragForce : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
517
+ const movingObjectVelocity : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
518
+ const movingObjectVelocityInCharacterDir : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
519
+ const distanceFromCharacterToObject : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
520
+ const objectAngvelToLinvel : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
521
+ const velocityDiff : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
517
522
518
523
/**
519
524
* Initial light setup
@@ -541,28 +546,28 @@ const Ecctrl: ForwardRefRenderFunction<RapierRigidBody, EcctrlProps> = ({
541
546
*/
542
547
const { pivot, cameraCollisionDetect, joystickCamMove } =
543
548
useFollowCam ( cameraSetups ) ;
544
- const pivotPosition = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
545
- const modelEuler = useMemo ( ( ) => new THREE . Euler ( ) , [ ] ) ;
546
- const modelQuat = useMemo ( ( ) => new THREE . Quaternion ( ) , [ ] ) ;
547
- const moveImpulse = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
548
- const movingDirection = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
549
- const moveAccNeeded = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
550
- const jumpVelocityVec = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
551
- const jumpDirection = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
552
- const currentVel = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
553
- const currentPos = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
554
- const dragForce = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
555
- const dragAngForce = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
556
- const wantToMoveVel = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
557
- const rejectVel = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
549
+ const pivotPosition : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
550
+ const modelEuler : THREE . Euler = useMemo ( ( ) => new THREE . Euler ( ) , [ ] ) ;
551
+ const modelQuat : THREE . Quaternion = useMemo ( ( ) => new THREE . Quaternion ( ) , [ ] ) ;
552
+ const moveImpulse : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
553
+ const movingDirection : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
554
+ const moveAccNeeded : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
555
+ const jumpVelocityVec : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
556
+ const jumpDirection : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
557
+ const currentVel : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
558
+ const currentPos : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
559
+ const dragForce : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
560
+ const dragAngForce : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
561
+ const wantToMoveVel : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
562
+ const rejectVel : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
558
563
559
564
/**
560
565
* Floating Ray setup
561
566
*/
562
567
let floatingForce = null ;
563
- const springDirVec = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
564
- const characterMassForce = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
565
- const rayOrigin = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
568
+ const springDirVec : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
569
+ const characterMassForce : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
570
+ const rayOrigin : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
566
571
const rayCast = new rapier . Ray ( rayOrigin , rayDir ) ;
567
572
let rayHit : RayColliderToi = null ;
568
573
@@ -575,10 +580,10 @@ const Ecctrl: ForwardRefRenderFunction<RapierRigidBody, EcctrlProps> = ({
575
580
let slopeAngle : number = null ;
576
581
let actualSlopeNormal : Vector = null ;
577
582
let actualSlopeAngle : number = null ;
578
- const actualSlopeNormalVec = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
579
- const floorNormal = useMemo ( ( ) => new THREE . Vector3 ( 0 , 1 , 0 ) , [ ] ) ;
583
+ const actualSlopeNormalVec : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
584
+ const floorNormal : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( 0 , 1 , 0 ) , [ ] ) ;
580
585
const slopeRayOriginRef = useRef < THREE . Mesh > ( ) ;
581
- const slopeRayorigin = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
586
+ const slopeRayorigin : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
582
587
const slopeRayCast = new rapier . Ray ( slopeRayorigin , slopeRayDir ) ;
583
588
let slopeRayHit : RayColliderToi = null ;
584
589
@@ -587,8 +592,8 @@ const Ecctrl: ForwardRefRenderFunction<RapierRigidBody, EcctrlProps> = ({
587
592
*/
588
593
let isBodyHitWall = false ;
589
594
let isPointMoving = false ;
590
- const crossVector = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
591
- const pointToPoint = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
595
+ const crossVector : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
596
+ const pointToPoint : THREE . Vector3 = useMemo ( ( ) => new THREE . Vector3 ( ) , [ ] ) ;
592
597
const getMoveToPoint = useGame ( ( state ) => state . getMoveToPoint ) ;
593
598
const bodySensorRef = useRef < Collider > ( ) ;
594
599
const handleOnIntersectionEnter = ( ) => {
@@ -601,7 +606,7 @@ const Ecctrl: ForwardRefRenderFunction<RapierRigidBody, EcctrlProps> = ({
601
606
/**
602
607
* Character moving function
603
608
*/
604
- let characterRotated = true ;
609
+ let characterRotated : boolean = true ;
605
610
const moveCharacter = (
606
611
_ : number ,
607
612
run : boolean ,
@@ -758,16 +763,16 @@ const Ecctrl: ForwardRefRenderFunction<RapierRigidBody, EcctrlProps> = ({
758
763
modelEuler . y = pivot . rotation . y
759
764
pivot . getWorldDirection ( modelFacingVec )
760
765
// Update slopeRayOrigin to new positon
761
- const slopeRayOriginNewPosition = new THREE . Vector3 ( movingDirection . x , 0 , movingDirection . z )
762
- const crossVecOnY = slopeRayOriginNewPosition . clone ( ) . cross ( modelFacingVec )
763
- slopeRayOriginRef . current . position . x = slopeRayOriginOffest * Math . sin ( slopeRayOriginNewPosition . angleTo ( modelFacingVec ) * ( crossVecOnY . y < 0 ? 1 : - 1 ) )
764
- slopeRayOriginRef . current . position . z = slopeRayOriginOffest * Math . cos ( slopeRayOriginNewPosition . angleTo ( modelFacingVec ) * ( crossVecOnY . y < 0 ? 1 : - 1 ) )
766
+ slopeRayOriginUpdatePosition . set ( movingDirection . x , 0 , movingDirection . z )
767
+ camBasedMoveCrossVecOnY . copy ( slopeRayOriginUpdatePosition ) . cross ( modelFacingVec )
768
+ slopeRayOriginRef . current . position . x = slopeRayOriginOffest * Math . sin ( slopeRayOriginUpdatePosition . angleTo ( modelFacingVec ) * ( camBasedMoveCrossVecOnY . y < 0 ? 1 : - 1 ) )
769
+ slopeRayOriginRef . current . position . z = slopeRayOriginOffest * Math . cos ( slopeRayOriginUpdatePosition . angleTo ( modelFacingVec ) * ( camBasedMoveCrossVecOnY . y < 0 ? 1 : - 1 ) )
765
770
} else {
766
771
characterModelIndicator . getWorldDirection ( modelFacingVec )
767
772
}
768
- const crossVecOnX = vectorY . clone ( ) . cross ( bodyBalanceVecOnX ) ;
769
- const crossVecOnY = modelFacingVec . clone ( ) . cross ( bodyFacingVecOnY ) ;
770
- const crossVecOnZ = vectorY . clone ( ) . cross ( bodyBalanceVecOnZ ) ;
773
+ crossVecOnX . copy ( vectorY ) . cross ( bodyBalanceVecOnX ) ;
774
+ crossVecOnY . copy ( modelFacingVec ) . cross ( bodyFacingVecOnY ) ;
775
+ crossVecOnZ . copy ( vectorY ) . cross ( bodyBalanceVecOnZ ) ;
771
776
772
777
dragAngForce . set (
773
778
( crossVecOnX . x < 0 ? 1 : - 1 ) *
0 commit comments