gaesup-world 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/README.md +51 -0
  2. package/index.html +13 -0
  3. package/package.json +82 -0
  4. package/src/gaesup/animation/actions.ts +123 -0
  5. package/src/gaesup/camera/cameraCollisionDetecter.tsx +53 -0
  6. package/src/gaesup/camera/control/map.ts +10 -0
  7. package/src/gaesup/camera/control/normal copy.ts +19 -0
  8. package/src/gaesup/camera/control/normal.ts +15 -0
  9. package/src/gaesup/camera/control/orbit.ts +31 -0
  10. package/src/gaesup/camera/index.tsx +102 -0
  11. package/src/gaesup/camera/type.ts +17 -0
  12. package/src/gaesup/component/Airplane.tsx +46 -0
  13. package/src/gaesup/component/Character.tsx +48 -0
  14. package/src/gaesup/component/Vehicle.tsx +40 -0
  15. package/src/gaesup/component/gltf/AirplaneGltf.tsx +31 -0
  16. package/src/gaesup/component/gltf/CharacterGltf.tsx +81 -0
  17. package/src/gaesup/component/gltf/VehicleGltf.tsx +31 -0
  18. package/src/gaesup/component/gltf/WheelJoint.tsx +39 -0
  19. package/src/gaesup/component/gltf/type.ts +6 -0
  20. package/src/gaesup/component/ref/airplane.tsx +83 -0
  21. package/src/gaesup/component/ref/character.tsx +132 -0
  22. package/src/gaesup/component/ref/vehicle.tsx +145 -0
  23. package/src/gaesup/controller/index.tsx +103 -0
  24. package/src/gaesup/controller/type.ts +139 -0
  25. package/src/gaesup/gaesupProps/index.tsx +66 -0
  26. package/src/gaesup/initial/callback/index.ts +73 -0
  27. package/src/gaesup/initial/callback/type.ts +45 -0
  28. package/src/gaesup/initial/controller/index.ts +143 -0
  29. package/src/gaesup/initial/controller/initDebug.ts +102 -0
  30. package/src/gaesup/initial/gaesupWorld/collider/airplane.ts +26 -0
  31. package/src/gaesup/initial/gaesupWorld/collider/character.ts +32 -0
  32. package/src/gaesup/initial/gaesupWorld/collider/gltf.ts +91 -0
  33. package/src/gaesup/initial/gaesupWorld/collider/index.ts +26 -0
  34. package/src/gaesup/initial/gaesupWorld/collider/vehicle.ts +43 -0
  35. package/src/gaesup/initial/gaesupWorld/index.ts +82 -0
  36. package/src/gaesup/initial/gaesupWorld/type.ts +37 -0
  37. package/src/gaesup/physics/airplane/currentSetting.ts +20 -0
  38. package/src/gaesup/physics/airplane/damping.ts +8 -0
  39. package/src/gaesup/physics/airplane/direction.ts +70 -0
  40. package/src/gaesup/physics/airplane/gravity.ts +11 -0
  41. package/src/gaesup/physics/airplane/impulse.ts +22 -0
  42. package/src/gaesup/physics/airplane/index.tsx +16 -0
  43. package/src/gaesup/physics/airplane/turn.ts +12 -0
  44. package/src/gaesup/physics/airplane copy/currentSetting.ts +20 -0
  45. package/src/gaesup/physics/airplane copy/direction.ts +52 -0
  46. package/src/gaesup/physics/airplane copy/gravity.ts +6 -0
  47. package/src/gaesup/physics/airplane copy/impulse.ts +28 -0
  48. package/src/gaesup/physics/airplane copy/index.tsx +14 -0
  49. package/src/gaesup/physics/airplane copy/turn.ts +9 -0
  50. package/src/gaesup/physics/character/accelaration.ts +14 -0
  51. package/src/gaesup/physics/character/currentSetting.ts +20 -0
  52. package/src/gaesup/physics/character/damping.ts +6 -0
  53. package/src/gaesup/physics/character/direction.ts +104 -0
  54. package/src/gaesup/physics/character/impulse.ts +24 -0
  55. package/src/gaesup/physics/character/index.tsx +20 -0
  56. package/src/gaesup/physics/character/jump.ts +21 -0
  57. package/src/gaesup/physics/character/stabilizing.ts +6 -0
  58. package/src/gaesup/physics/character/turn.ts +17 -0
  59. package/src/gaesup/physics/check/ground.ts +19 -0
  60. package/src/gaesup/physics/check/index.ts +12 -0
  61. package/src/gaesup/physics/check/moving.ts +21 -0
  62. package/src/gaesup/physics/check/rotate.ts +13 -0
  63. package/src/gaesup/physics/check/slope.ts +50 -0
  64. package/src/gaesup/physics/index.ts +50 -0
  65. package/src/gaesup/physics/type.ts +35 -0
  66. package/src/gaesup/physics/vehicle/currentSetting.ts +20 -0
  67. package/src/gaesup/physics/vehicle/damping.ts +8 -0
  68. package/src/gaesup/physics/vehicle/direction.ts +27 -0
  69. package/src/gaesup/physics/vehicle/impulse.ts +22 -0
  70. package/src/gaesup/physics/vehicle/index.tsx +14 -0
  71. package/src/gaesup/physics/vehicle/turn.ts +11 -0
  72. package/src/gaesup/stores/active/index.ts +19 -0
  73. package/src/gaesup/stores/active/type.ts +16 -0
  74. package/src/gaesup/stores/airplane/index.ts +6 -0
  75. package/src/gaesup/stores/airplane/type.ts +4 -0
  76. package/src/gaesup/stores/animation/index.ts +18 -0
  77. package/src/gaesup/stores/animation/type.ts +9 -0
  78. package/src/gaesup/stores/collider/index.ts +55 -0
  79. package/src/gaesup/stores/context/controller/index.ts +36 -0
  80. package/src/gaesup/stores/context/controller/reducer.ts +18 -0
  81. package/src/gaesup/stores/context/controller/type.ts +38 -0
  82. package/src/gaesup/stores/context/gaesupworld/index.ts +11 -0
  83. package/src/gaesup/stores/context/gaesupworld/reducer.ts +21 -0
  84. package/src/gaesup/stores/context/gaesupworld/type.ts +66 -0
  85. package/src/gaesup/stores/control/index.ts +33 -0
  86. package/src/gaesup/stores/control/type.ts +11 -0
  87. package/src/gaesup/stores/joystick/index.ts +72 -0
  88. package/src/gaesup/stores/joystick/type.ts +23 -0
  89. package/src/gaesup/stores/minimap/index.ts +5 -0
  90. package/src/gaesup/stores/minimap/type.ts +22 -0
  91. package/src/gaesup/stores/point/type.ts +6 -0
  92. package/src/gaesup/stores/states/index.tsx +10 -0
  93. package/src/gaesup/stores/states/type.ts +10 -0
  94. package/src/gaesup/stores/url/index.ts +6 -0
  95. package/src/gaesup/stores/url/type.ts +6 -0
  96. package/src/gaesup/styles.css.ts +26 -0
  97. package/src/gaesup/tools/gameboy/GameBoyButton.tsx +38 -0
  98. package/src/gaesup/tools/gameboy/index.tsx +36 -0
  99. package/src/gaesup/tools/gameboy/style.css.ts +78 -0
  100. package/src/gaesup/tools/gamepad/GamePadButton.tsx +31 -0
  101. package/src/gaesup/tools/gamepad/index.tsx +55 -0
  102. package/src/gaesup/tools/gamepad/style.css.ts +16 -0
  103. package/src/gaesup/tools/index.tsx +61 -0
  104. package/src/gaesup/tools/joystick/index.tsx +145 -0
  105. package/src/gaesup/tools/joystick/style.css.ts +40 -0
  106. package/src/gaesup/tools/jumpPoint/index.tsx +27 -0
  107. package/src/gaesup/tools/jumpPoint/style.css.ts +33 -0
  108. package/src/gaesup/tools/keyBoardToolTip/constant.ts +144 -0
  109. package/src/gaesup/tools/keyBoardToolTip/index.tsx +85 -0
  110. package/src/gaesup/tools/keyBoardToolTip/style.css.ts +49 -0
  111. package/src/gaesup/tools/minimap/index.tsx +47 -0
  112. package/src/gaesup/tools/minimap/style.css.ts +144 -0
  113. package/src/gaesup/tools/style.css.ts +34 -0
  114. package/src/gaesup/utils/constant.ts +1 -0
  115. package/src/gaesup/utils/ray.ts +23 -0
  116. package/src/gaesup/utils/ref.ts +17 -0
  117. package/src/gaesup/utils/vector.ts +40 -0
  118. package/src/gaesup/world/index.tsx +17 -0
  119. package/src/gaesup/world/type.ts +10 -0
  120. package/src/styles/constants/boxshadow.css.ts +499 -0
  121. package/src/styles/constants/constant.css.ts +81 -0
  122. package/src/styles/constants/direction.css.ts +168 -0
  123. package/src/styles/constants/flex.css.ts +68 -0
  124. package/src/styles/constants/gradient.css.ts +10 -0
  125. package/src/styles/constants/grid.css.ts +37 -0
  126. package/src/styles/constants/palette.css.ts +324 -0
  127. package/src/styles/constants/translate.css.ts +129 -0
  128. package/src/styles/global.css.ts +91 -0
  129. package/src/styles/recipe/base.css.ts +31 -0
  130. package/src/styles/recipe/button.css.ts +109 -0
  131. package/src/styles/recipe/index.css.ts +134 -0
  132. package/src/styles/recipe/input.css.ts +33 -0
  133. package/src/styles/sprinkles/color.css.ts +62 -0
  134. package/src/styles/sprinkles/direction.css.ts +26 -0
  135. package/src/styles/sprinkles/display.css.ts +25 -0
  136. package/src/styles/sprinkles/fontSize.css.ts +25 -0
  137. package/src/styles/sprinkles/grid.css.ts +25 -0
  138. package/src/styles/sprinkles/index.css.ts +22 -0
  139. package/src/styles/sprinkles/margin.css.ts +30 -0
  140. package/src/styles/sprinkles/padding.css.ts +30 -0
  141. package/src/styles/sprinkles/position.css.ts +14 -0
  142. package/src/styles/sprinkles/size.css.ts +23 -0
  143. package/src/styles/theme.css.ts +98 -0
  144. package/tsconfig.json +27 -0
  145. package/tsconfig.node.json +10 -0
  146. package/vite.config.ts +9 -0
@@ -0,0 +1,104 @@
1
+ import { RootState } from "@react-three/fiber";
2
+ import { activeStateType } from "../../stores/active/type";
3
+
4
+ import { gaesupControllerPropType } from "../../stores/context/gaesupworld/type";
5
+ import { joyStickType } from "../../stores/joystick/type";
6
+ import { V3 } from "../../utils/vector";
7
+ import { calcPropType } from "../type";
8
+
9
+ export function joystickDirection() {}
10
+
11
+ export function orbitDirection({
12
+ activeState,
13
+ control,
14
+ mode,
15
+ joystick,
16
+ state,
17
+ }: {
18
+ state: RootState;
19
+ activeState: activeStateType;
20
+ mode: gaesupControllerPropType;
21
+ joystick: joyStickType;
22
+ control: {
23
+ [key: string]: boolean;
24
+ };
25
+ }) {
26
+ const { forward, backward, leftward, rightward } = control;
27
+ let start = 0;
28
+ if (mode.controller === "joystick") {
29
+ activeState.euler.y =
30
+ -state.camera.rotation.y - joystick.joyStickOrigin.angle - Math.PI / 2;
31
+ start = joystick.joyStickOrigin.isOn ? 1 : 0;
32
+ } else {
33
+ activeState.euler.y +=
34
+ ((Number(leftward) - Number(rightward)) * Math.PI) / 32;
35
+ start = Number(forward) - Number(backward);
36
+ }
37
+ const front = V3(start, 0, start);
38
+ activeState.direction = front.multiply(
39
+ V3(Math.sin(activeState.euler.y), 0, Math.cos(activeState.euler.y))
40
+ );
41
+ activeState.dir = activeState.direction.normalize();
42
+ }
43
+
44
+ export function normalDirection({
45
+ activeState,
46
+ control,
47
+ mode,
48
+ joystick,
49
+ state,
50
+ }: {
51
+ state: RootState;
52
+ activeState: activeStateType;
53
+ mode: gaesupControllerPropType;
54
+ joystick: joyStickType;
55
+ control: {
56
+ [key: string]: boolean;
57
+ };
58
+ }) {
59
+ const { forward, backward, leftward, rightward } = control;
60
+ let start = 0;
61
+ if (mode.controller === "joystick") {
62
+ activeState.euler.y =
63
+ -state.camera.rotation.y - joystick.joyStickOrigin.angle - Math.PI / 2;
64
+ start = joystick.joyStickOrigin.isOn ? 1 : 0;
65
+ } else {
66
+ if (forward) {
67
+ activeState.euler.y =
68
+ -state.camera.rotation.y +
69
+ (leftward ? Math.PI / 4 : 0) -
70
+ (rightward ? Math.PI / 4 : 0);
71
+ } else if (backward) {
72
+ activeState.euler.y =
73
+ -state.camera.rotation.y +
74
+ Math.PI -
75
+ (leftward ? Math.PI / 4 : 0) +
76
+ (rightward ? Math.PI / 4 : 0);
77
+ } else if (leftward) {
78
+ activeState.euler.y = -state.camera.rotation.y + Math.PI / 2;
79
+ } else if (rightward) {
80
+ activeState.euler.y = -state.camera.rotation.y - Math.PI / 2;
81
+ }
82
+ }
83
+ const front = V3(
84
+ Number(backward) - Number(forward),
85
+ 0,
86
+ Number(leftward) - Number(rightward)
87
+ );
88
+ activeState.direction = front;
89
+ activeState.dir = activeState.direction.normalize();
90
+ }
91
+
92
+ export default function direction(prop: calcPropType) {
93
+ const {
94
+ control,
95
+ state,
96
+ worldContext: { joystick, mode, activeState },
97
+ controllerContext: { cameraMode },
98
+ } = prop;
99
+ if (cameraMode.controlType === "normal") {
100
+ normalDirection({ activeState, control, mode, joystick, state });
101
+ } else if (cameraMode.controlType === "orbit") {
102
+ orbitDirection({ activeState, control, mode, joystick, state });
103
+ }
104
+ }
@@ -0,0 +1,24 @@
1
+ import { V3 } from "../../utils/vector";
2
+ import { calcPropType } from "../type";
3
+
4
+ export default function impulse(prop: calcPropType) {
5
+ const {
6
+ rigidBodyRef,
7
+ slopeRay,
8
+ worldContext: { states, activeState },
9
+ } = prop;
10
+ const { isMoving } = states;
11
+
12
+ if (isMoving) {
13
+ const M = rigidBodyRef.current.mass();
14
+ const A = activeState.acceleration;
15
+ const F = A.multiplyScalar(M);
16
+
17
+ activeState.impulse = V3(
18
+ F.x,
19
+ activeState.direction.normalize().y * Math.abs(Math.sin(slopeRay.angle)),
20
+ F.z
21
+ );
22
+ rigidBodyRef.current.applyImpulse(activeState.impulse, false);
23
+ }
24
+ }
@@ -0,0 +1,20 @@
1
+ import { calcPropType } from "../type";
2
+ import accelaration from "./accelaration";
3
+ import currentSetting from "./currentSetting";
4
+ import damping from "./damping";
5
+ import direction from "./direction";
6
+ import impulse from "./impulse";
7
+ import jump from "./jump";
8
+ import stabilizing from "./stabilizing";
9
+ import turn from "./turn";
10
+
11
+ export default function characterCalculation(calcProp: calcPropType) {
12
+ direction(calcProp);
13
+ turn(calcProp);
14
+ jump(calcProp);
15
+ accelaration(calcProp);
16
+ impulse(calcProp);
17
+ damping(calcProp);
18
+ stabilizing(calcProp);
19
+ currentSetting(calcProp);
20
+ }
@@ -0,0 +1,21 @@
1
+ import { V3 } from "../../utils/vector";
2
+ import { calcPropType } from "../type";
3
+
4
+ export default function jump(prop: calcPropType) {
5
+ const {
6
+ rigidBodyRef,
7
+ slopeRay,
8
+ constant,
9
+ worldContext: { states, activeState },
10
+ } = prop;
11
+ const { isOnTheGround, isJumping } = states;
12
+ const { jumpSpeed } = constant;
13
+ if (isJumping && isOnTheGround) {
14
+ rigidBodyRef.current.setLinvel(
15
+ V3(0, jumpSpeed * 0.25, 0)
16
+ .projectOnVector(slopeRay.current)
17
+ .add(activeState.velocity.setY(jumpSpeed)),
18
+ false
19
+ );
20
+ }
21
+ }
@@ -0,0 +1,6 @@
1
+ import { calcPropType } from "../type";
2
+
3
+ export default function stabilizing(prop: calcPropType) {
4
+ const { rigidBodyRef } = prop;
5
+ rigidBodyRef.current.setEnabledRotations(false, false, false, false);
6
+ }
@@ -0,0 +1,17 @@
1
+ import { calcPropType } from "../type";
2
+
3
+ export default function turn(prop: calcPropType) {
4
+ const {
5
+ outerGroupRef,
6
+ constant,
7
+ delta,
8
+ worldContext: { activeState },
9
+ } = prop;
10
+ const { turnSpeed } = constant;
11
+
12
+ activeState.quat.setFromEuler(activeState.euler);
13
+ outerGroupRef.current.quaternion.rotateTowards(
14
+ activeState.quat,
15
+ delta * turnSpeed
16
+ );
17
+ }
@@ -0,0 +1,19 @@
1
+ import { vec3 } from "@react-three/rapier";
2
+ import { calcPropType } from "../type";
3
+
4
+ export default function checkOnTheGround(prop: calcPropType) {
5
+ const {
6
+ capsuleColliderRef,
7
+ groundRay,
8
+ worldContext: { characterCollider: collider, states, activeState },
9
+ } = prop;
10
+
11
+ groundRay.origin.addVectors(activeState.position, vec3(groundRay.offset));
12
+ if (!groundRay.hit || !groundRay.rayCast || !capsuleColliderRef.current)
13
+ return null;
14
+ if (groundRay.hit.toi < collider.radius + 0.4) {
15
+ states.isOnTheGround = true;
16
+ } else {
17
+ states.isOnTheGround = false;
18
+ }
19
+ }
@@ -0,0 +1,12 @@
1
+ import { calcPropType } from "../type";
2
+ import ground from "./ground";
3
+ import moving from "./moving";
4
+ import rotate from "./rotate";
5
+ import slope from "./slope";
6
+
7
+ export default function check(calcProp: calcPropType) {
8
+ ground(calcProp);
9
+ slope(calcProp);
10
+ moving(calcProp);
11
+ rotate(calcProp);
12
+ }
@@ -0,0 +1,21 @@
1
+ import { calcPropType } from "../type";
2
+
3
+ export default function moving(prop: calcPropType) {
4
+ const {
5
+ control: calcControl,
6
+ worldContext: { states, joystick, mode },
7
+ } = prop;
8
+ const { forward, backward, leftward, rightward, shift, space } = calcControl;
9
+ if (mode.controller === "gameboy" || mode.controller === "keyboard") {
10
+ states.isMoving = forward || backward || leftward || rightward;
11
+ states.isNotMoving = !states.isMoving;
12
+ states.isRunning = shift && states.isMoving;
13
+ states.isJumping = space;
14
+ } else if (mode.controller === "joystick") {
15
+ states.isMoving = joystick.joyStickOrigin.isOn;
16
+ states.isNotMoving = !joystick.joyStickOrigin.isOn;
17
+ states.isRunning =
18
+ joystick.joyStickOrigin.isOn && joystick.joyStickOrigin.isIn;
19
+ states.isJumping = space;
20
+ }
21
+ }
@@ -0,0 +1,13 @@
1
+ import { calcPropType } from "../type";
2
+
3
+ export default function rotate(prop: calcPropType) {
4
+ const {
5
+ outerGroupRef,
6
+ worldContext: { states, activeState },
7
+ } = prop;
8
+ if (states.isMoving && outerGroupRef && outerGroupRef.current) {
9
+ states.isRotated =
10
+ Math.sin(outerGroupRef.current.rotation.y).toFixed(3) ===
11
+ Math.sin(activeState.euler.y).toFixed(3);
12
+ }
13
+ }
@@ -0,0 +1,50 @@
1
+ import { vec3 } from "@react-three/rapier";
2
+ import { calcPropType } from "../type";
3
+
4
+ export default function slope(prop: calcPropType) {
5
+ const {
6
+ capsuleColliderRef,
7
+ slopeRayOriginRef,
8
+ slopeRay,
9
+ groundRay,
10
+ worldContext,
11
+ world,
12
+ } = prop;
13
+ const { characterCollider: collider } = worldContext;
14
+ if (
15
+ !slopeRayOriginRef.current ||
16
+ !capsuleColliderRef.current ||
17
+ !slopeRay.rayCast
18
+ )
19
+ return null;
20
+ slopeRayOriginRef.current.getWorldPosition(slopeRay.origin);
21
+ slopeRay.origin.y = groundRay.origin.y;
22
+ slopeRay.hit = world.castRay(
23
+ slopeRay.rayCast,
24
+ slopeRay.length,
25
+ true,
26
+ undefined,
27
+ undefined,
28
+ capsuleColliderRef.current
29
+ );
30
+
31
+ if (slopeRay.hit && groundRay.rayCast) {
32
+ const castRayNormal = slopeRay.hit.collider.castRayAndGetNormal(
33
+ groundRay.rayCast,
34
+ slopeRay.length,
35
+ false
36
+ );
37
+ if (castRayNormal) slopeRay.current = vec3(castRayNormal.normal);
38
+ }
39
+ if (
40
+ slopeRay.hit &&
41
+ groundRay.hit &&
42
+ slopeRay.hit.toi < collider.radius + 0.3 + 0.5
43
+ ) {
44
+ slopeRay.angle = Number(
45
+ Math.atan(
46
+ (groundRay.hit.toi - slopeRay.hit.toi) / slopeRay.offset.z
47
+ ).toFixed(2)
48
+ );
49
+ }
50
+ }
@@ -0,0 +1,50 @@
1
+ import { useFrame } from "@react-three/fiber";
2
+
3
+ import { useKeyboardControls } from "@react-three/drei";
4
+ import { useContext } from "react";
5
+ import { propType } from "../controller/type";
6
+
7
+ import { useRapier } from "@react-three/rapier";
8
+ import { GaesupControllerContext } from "../stores/context/controller";
9
+ import {
10
+ GaesupWorldContext,
11
+ GaesupWorldDispatchContext,
12
+ } from "../stores/context/gaesupworld";
13
+ import airplaneCalculation from "./airplane";
14
+ import characterCalculation from "./character";
15
+ import check from "./check";
16
+ import { calcPropType } from "./type";
17
+ import vehicleCalculation from "./vehicle";
18
+
19
+ export default function calculation(prop: propType) {
20
+ const { world } = useRapier();
21
+ const worldContext = useContext(GaesupWorldContext);
22
+ const controllerContext = useContext(GaesupControllerContext);
23
+ const dispatch = useContext(GaesupWorldDispatchContext);
24
+ const control = useKeyboardControls()[1]();
25
+ const { mode } = worldContext;
26
+ useFrame((state, delta) => {
27
+ const { rigidBodyRef, outerGroupRef } = prop;
28
+ if (
29
+ !rigidBodyRef ||
30
+ !rigidBodyRef.current ||
31
+ !outerGroupRef ||
32
+ !outerGroupRef.current
33
+ )
34
+ return null;
35
+ const calcProp: calcPropType = {
36
+ ...prop,
37
+ control,
38
+ state,
39
+ delta,
40
+ worldContext,
41
+ controllerContext,
42
+ dispatch,
43
+ world,
44
+ };
45
+ if (mode.type === "vehicle") vehicleCalculation(calcProp);
46
+ else if (mode.type === "character") characterCalculation(calcProp);
47
+ else if (mode.type === "airplane") airplaneCalculation(calcProp);
48
+ check(calcProp);
49
+ });
50
+ }
@@ -0,0 +1,35 @@
1
+ import { RootState } from "@react-three/fiber";
2
+ import { propType } from "../controller/type";
3
+
4
+ import { World } from "@dimforge/rapier3d-compat";
5
+ import { gaesupControllerType } from "../stores/context/controller/type";
6
+ import {
7
+ gaesupDisptachType,
8
+ gaesupWorldPropType,
9
+ } from "../stores/context/gaesupworld/type";
10
+
11
+ export type SetAtom<Args extends unknown[], Result> = (...args: Args) => Result;
12
+
13
+ export type calcPropType = propType & {
14
+ control: {
15
+ [key: string]: boolean;
16
+ };
17
+ state?: RootState;
18
+ checkCollision?: (delta: number) => void;
19
+ worldContext?: gaesupWorldPropType;
20
+ controllerContext?: gaesupControllerType;
21
+ delta?: number;
22
+ dispatch?: gaesupDisptachType;
23
+ world: World;
24
+ };
25
+
26
+ export type cameraPropType = propType & {
27
+ control: {
28
+ [key: string]: boolean;
29
+ };
30
+ state?: RootState;
31
+ worldContext?: gaesupWorldPropType;
32
+ checkCollision?: (delta: number) => void;
33
+ controllerContext?: gaesupControllerType;
34
+ delta?: number;
35
+ };
@@ -0,0 +1,20 @@
1
+ import { vec3 } from "@react-three/rapier";
2
+ import { calcPropType } from "../type";
3
+
4
+ export default function currentSetting(prop: calcPropType) {
5
+ const {
6
+ rigidBodyRef,
7
+ worldContext: { activeState },
8
+ dispatch,
9
+ } = prop;
10
+ activeState.position = vec3(rigidBodyRef.current.translation());
11
+ activeState.velocity = vec3(rigidBodyRef.current.linvel());
12
+ dispatch({
13
+ type: "update",
14
+ payload: {
15
+ activeState: {
16
+ ...activeState,
17
+ },
18
+ },
19
+ });
20
+ }
@@ -0,0 +1,8 @@
1
+ import { calcPropType } from "../type";
2
+
3
+ export default function damping(prop: calcPropType) {
4
+ const { rigidBodyRef, constant, control } = prop;
5
+ const { space } = control;
6
+ const { brakeRate } = constant;
7
+ rigidBodyRef.current.setLinearDamping(space ? brakeRate : 0.5);
8
+ }
@@ -0,0 +1,27 @@
1
+ import { vec3 } from "@react-three/rapier";
2
+ import { V3 } from "../../utils/vector";
3
+ import { calcPropType } from "../type";
4
+
5
+ export default function direction(prop: calcPropType) {
6
+ const {
7
+ worldContext: { activeState },
8
+ } = prop;
9
+ const { forward, backward, leftward, rightward } = prop.control;
10
+
11
+ const start = Number(forward) - Number(backward);
12
+ const front = vec3().set(start, 0, start);
13
+ activeState.euler.y +=
14
+ ((Number(leftward) - Number(rightward)) * Math.PI) / 64;
15
+ // current.dir = V3(
16
+ // Math.sin(current.euler.y),
17
+ // 0,
18
+ // Math.cos(current.euler.y)
19
+ // ).normalize();
20
+ // current.direction = front
21
+ // .multiply(current.dir)
22
+ // .multiplyScalar(shift ? accelRate : 1);
23
+ activeState.direction = front.multiply(
24
+ V3(Math.sin(activeState.euler.y), 0, Math.cos(activeState.euler.y))
25
+ );
26
+ activeState.dir = activeState.direction.normalize();
27
+ }
@@ -0,0 +1,22 @@
1
+ import { vec3 } from "@react-three/rapier";
2
+ import { calcPropType } from "../type";
3
+
4
+ export default function impulse(prop: calcPropType) {
5
+ const {
6
+ rigidBodyRef,
7
+ constant,
8
+ control,
9
+ worldContext: { activeState },
10
+ } = prop;
11
+ const { shift } = control;
12
+ const { accelRate } = constant;
13
+
14
+ rigidBodyRef.current.applyImpulse(
15
+ vec3({
16
+ x: activeState.direction.x,
17
+ y: 0,
18
+ z: activeState.direction.z,
19
+ }).multiplyScalar(shift ? accelRate : 1),
20
+ false
21
+ );
22
+ }
@@ -0,0 +1,14 @@
1
+ import { calcPropType } from "../type";
2
+ import currentSetting from "./currentSetting";
3
+ import damping from "./damping";
4
+ import direction from "./direction";
5
+ import impulse from "./impulse";
6
+ import turn from "./turn";
7
+
8
+ export default function vehicleCalculation(calcProp: calcPropType) {
9
+ direction(calcProp);
10
+ turn(calcProp);
11
+ impulse(calcProp);
12
+ damping(calcProp);
13
+ currentSetting(calcProp);
14
+ }
@@ -0,0 +1,11 @@
1
+ import { calcPropType } from "../type";
2
+
3
+ export default function turn(prop: calcPropType) {
4
+ const {
5
+ rigidBodyRef,
6
+ worldContext: { activeState },
7
+ } = prop;
8
+
9
+ activeState.quat.setFromEuler(activeState.euler);
10
+ rigidBodyRef.current.setRotation(activeState.quat, false);
11
+ }
@@ -0,0 +1,19 @@
1
+ import { euler, quat, vec3 } from "@react-three/rapier";
2
+ import { V3 } from "../../utils/vector";
3
+
4
+ export const activeStateDefault = {
5
+ position: V3(0, 2, 5),
6
+ impulse: vec3(),
7
+ velocity: vec3(),
8
+ acceleration: vec3(),
9
+ quat: quat(),
10
+ euler: euler(),
11
+ dir: vec3(),
12
+ direction: vec3(),
13
+ axisX: V3(1, 0, 0),
14
+ axisY: V3(0, 1, 0),
15
+ axisZ: V3(0, 0, 1),
16
+ yaw: 0,
17
+ pitch: 0,
18
+ roll: 0,
19
+ };
@@ -0,0 +1,16 @@
1
+ export type activeStateType = {
2
+ position: THREE.Vector3;
3
+ impulse: THREE.Vector3;
4
+ velocity: THREE.Vector3;
5
+ acceleration: THREE.Vector3;
6
+ quat: THREE.Quaternion;
7
+ euler: THREE.Euler;
8
+ direction: THREE.Vector3;
9
+ dir: THREE.Vector3;
10
+ axisX: THREE.Vector3;
11
+ axisY: THREE.Vector3;
12
+ axisZ: THREE.Vector3;
13
+ yaw: number;
14
+ pitch: number;
15
+ roll: number;
16
+ };
@@ -0,0 +1,6 @@
1
+ import { V3 } from "../../utils/vector";
2
+
3
+ export const airplaneDefault = {
4
+ angleChange: V3(0.02, 0.01, 0.01),
5
+ maxAngle: V3(0.2, 0.2, 0.2),
6
+ };
@@ -0,0 +1,4 @@
1
+ export type airplaneType = {
2
+ angleChange: THREE.Vector3;
3
+ maxAngle: THREE.Vector3;
4
+ };
@@ -0,0 +1,18 @@
1
+ import { animationTagType } from "../../controller/type";
2
+
3
+ export const animationDefault = {
4
+ current: "idle" as keyof animationTagType,
5
+ animationNames: {
6
+ idle: "idle",
7
+ walk: "walk",
8
+ run: "run",
9
+ accel: "accel",
10
+ break: "break",
11
+ ride: "ride",
12
+ jump: "jump",
13
+ jumpIdle: "jumpIdle",
14
+ jumpLand: "jumpLand",
15
+ fall: "fall",
16
+ },
17
+ keyControl: {},
18
+ };
@@ -0,0 +1,9 @@
1
+ import { actionsType, animationTagType } from "../../controller/type";
2
+
3
+ export type animationPropType = {
4
+ current: keyof animationTagType;
5
+ animationNames: actionsType;
6
+ keyControl: {
7
+ [key: string]: boolean;
8
+ };
9
+ };
@@ -0,0 +1,55 @@
1
+ export type characterColliderType = {
2
+ halfHeight?: number;
3
+ height?: number;
4
+ radius?: number;
5
+ diameter?: number;
6
+ };
7
+
8
+ export type vehicleColliderType = {
9
+ wheelSizeX?: number;
10
+ wheelSizeY?: number;
11
+ wheelSizeZ?: number;
12
+ vehicleSizeX?: number;
13
+ vehicleSizeY?: number;
14
+ vehicleSizeZ?: number;
15
+ vehicleX?: number;
16
+ vehicleY?: number;
17
+ vehicleZ?: number;
18
+ };
19
+
20
+ export type airplaneColliderType = {
21
+ airplaneSizeX?: number;
22
+ airplaneSizeY?: number;
23
+ airplaneSizeZ?: number;
24
+ airplaneX?: number;
25
+ airplaneY?: number;
26
+ airplaneZ?: number;
27
+ };
28
+
29
+ export const characterColliderDefault = {
30
+ halfHeight: 0.35,
31
+ height: 0.7,
32
+ radius: 0.3,
33
+ diameter: 0.6,
34
+ };
35
+
36
+ export const vehicleColliderDefault = {
37
+ wheelSizeX: 0.5,
38
+ wheelSizeY: 0.5,
39
+ wheelSizeZ: 0.5,
40
+ vehicleSizeX: 1,
41
+ vehicleSizeY: 1,
42
+ vehicleSizeZ: 1,
43
+ vehicleX: 0.5,
44
+ vehicleY: 0.5,
45
+ vehicleZ: 0.5,
46
+ };
47
+
48
+ export const airplaneColliderDefault = {
49
+ airplaneSizeX: 1,
50
+ airplaneSizeY: 1,
51
+ airplaneSizeZ: 1,
52
+ airplaneX: 0.5,
53
+ airplaneY: 0.5,
54
+ airplaneZ: 0.5,
55
+ };