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,31 @@
1
+ import { Ref, forwardRef, useContext } from "react";
2
+ import { GaesupWorldContext } from "../../stores/context/gaesupworld";
3
+
4
+ export const AirplaneInnerGroupRef = forwardRef((_, ref: Ref<THREE.Group>) => {
5
+ const { airplaneGltf: gltf } = useContext(GaesupWorldContext);
6
+ const { materials, nodes } = gltf;
7
+ return (
8
+ <>
9
+ {nodes && materials && (
10
+ <group receiveShadow castShadow ref={ref}>
11
+ {Object.keys(nodes).map((name: string, key: number) => {
12
+ if (
13
+ nodes[name].type === "Mesh" ||
14
+ nodes[name].type === "SkinnedMesh"
15
+ ) {
16
+ return (
17
+ <mesh
18
+ castShadow
19
+ receiveShadow
20
+ material={materials[name]}
21
+ geometry={nodes[name].geometry}
22
+ key={key}
23
+ />
24
+ );
25
+ }
26
+ })}
27
+ </group>
28
+ )}
29
+ </>
30
+ );
31
+ });
@@ -0,0 +1,81 @@
1
+ import { GroupProps } from "@react-three/fiber";
2
+ import { useContext } from "react";
3
+ import playActions from "../../animation/actions";
4
+ import { groundRayType, propType, refsType } from "../../controller/type";
5
+ import initCallback from "../../initial/callback";
6
+ import { callbackType } from "../../initial/callback/type";
7
+ import { GaesupWorldContext } from "../../stores/context/gaesupworld";
8
+
9
+ export type characterGltfType = {
10
+ prop: propType;
11
+ groupProps?: GroupProps;
12
+ groundRay: groundRayType;
13
+ refs: refsType;
14
+ callbacks?: callbackType;
15
+ isRider?: boolean;
16
+ };
17
+
18
+ export default function CharacterGltf({
19
+ prop,
20
+ groupProps,
21
+ groundRay,
22
+ refs,
23
+ callbacks,
24
+ isRider,
25
+ }: characterGltfType) {
26
+ const { characterGltf: gltf } = useContext(GaesupWorldContext);
27
+ const { materials, nodes } = gltf;
28
+ const { characterCollider, vehicleCollider } = useContext(GaesupWorldContext);
29
+
30
+ initCallback({
31
+ prop,
32
+ callbacks,
33
+ outerGroupRef: refs.outerGroupRef,
34
+ });
35
+
36
+ playActions({
37
+ outerGroupRef: refs.outerGroupRef,
38
+ groundRay: groundRay,
39
+ isRider,
40
+ });
41
+
42
+ return (
43
+ <group
44
+ receiveShadow
45
+ castShadow
46
+ {...groupProps}
47
+ position={[
48
+ 0,
49
+ isRider ? vehicleCollider.vehicleSizeY / 2 : -characterCollider.height,
50
+ 0,
51
+ ]}
52
+ >
53
+ {nodes &&
54
+ Object.values(nodes).find((node) => node.type === "Object3D") && (
55
+ <primitive
56
+ object={Object.values(nodes).find(
57
+ (node) => node.type === "Object3D"
58
+ )}
59
+ visible={false}
60
+ receiveShadow
61
+ castShadow
62
+ />
63
+ )}
64
+ {nodes &&
65
+ Object.keys(nodes).map((name: string, key: number) => {
66
+ if (nodes[name].type === "SkinnedMesh") {
67
+ return (
68
+ <skinnedMesh
69
+ castShadow
70
+ receiveShadow
71
+ material={materials[name]}
72
+ geometry={nodes[name].geometry}
73
+ skeleton={(nodes[name] as THREE.SkinnedMesh).skeleton}
74
+ key={key}
75
+ />
76
+ );
77
+ }
78
+ })}
79
+ </group>
80
+ );
81
+ }
@@ -0,0 +1,31 @@
1
+ import { useContext } from "react";
2
+ import { GaesupWorldContext } from "../../stores/context/gaesupworld";
3
+
4
+ export default function VehicleGltf() {
5
+ const { vehicleGltf: gltf } = useContext(GaesupWorldContext);
6
+ const { materials, nodes } = gltf;
7
+ return (
8
+ <>
9
+ {nodes && materials && (
10
+ <group receiveShadow castShadow rotation={[0, Math.PI, 0]}>
11
+ {Object.keys(nodes).map((name: string, key: number) => {
12
+ if (
13
+ nodes[name].type === "Mesh" ||
14
+ nodes[name].type === "SkinnedMesh"
15
+ ) {
16
+ return (
17
+ <mesh
18
+ castShadow
19
+ receiveShadow
20
+ material={materials[name]}
21
+ geometry={nodes[name].geometry}
22
+ key={key}
23
+ />
24
+ );
25
+ }
26
+ })}
27
+ </group>
28
+ )}
29
+ </>
30
+ );
31
+ }
@@ -0,0 +1,39 @@
1
+ import { RapierRigidBody } from "@react-three/rapier";
2
+ import { createRef, useContext, useRef } from "react";
3
+ import { propType } from "../../controller/type";
4
+ import { GaesupWorldContext } from "../../stores/context/gaesupworld";
5
+ import { WheelRegidBodyRef } from "../ref/vehicle";
6
+
7
+ export function Wheels({ prop }: { prop: propType }) {
8
+ const { rigidBodyRef, constant } = prop;
9
+ const { wheelOffset } = constant;
10
+ const { vehicleCollider: collider } = useContext(GaesupWorldContext);
11
+ const { vehicleSizeX, vehicleSizeZ, wheelSizeX, wheelSizeZ } = collider;
12
+ const X = (vehicleSizeX + wheelSizeX) / 2 + wheelOffset;
13
+ const Z = (vehicleSizeZ + wheelSizeZ) / 2 + wheelOffset;
14
+ const wheelPositions: [number, number, number][] = [
15
+ [-X, 0, Z],
16
+ [-X, 0, -Z],
17
+ [X, 0, Z],
18
+ [X, 0, -Z],
19
+ ];
20
+ const wheelRefs = useRef(
21
+ wheelPositions.map(() => createRef<RapierRigidBody>())
22
+ );
23
+ return (
24
+ <>
25
+ {wheelPositions.map((wheelPosition, index) => (
26
+ <WheelRegidBodyRef
27
+ key={index}
28
+ ref={wheelRefs.current[index]}
29
+ wheelPosition={wheelPosition}
30
+ bodyRef={rigidBodyRef}
31
+ wheel={wheelRefs.current[index]}
32
+ bodyAnchor={wheelPosition}
33
+ wheelAnchor={[0, 0, 0]}
34
+ rotationAxis={[1, 0, 0]}
35
+ />
36
+ ))}
37
+ </>
38
+ );
39
+ }
@@ -0,0 +1,6 @@
1
+ import { GLTF } from "three-stdlib";
2
+
3
+ export type GLTFResult = GLTF & {
4
+ nodes: { [name: string]: THREE.Mesh | THREE.SkinnedMesh };
5
+ materials: { [name: string]: THREE.Material | THREE.MeshStandardMaterial };
6
+ };
@@ -0,0 +1,83 @@
1
+ import { Collider } from "@dimforge/rapier3d-compat";
2
+
3
+ import {
4
+ CuboidCollider,
5
+ RapierRigidBody,
6
+ RigidBody,
7
+ useRapier,
8
+ } from "@react-three/rapier";
9
+ import { ReactNode, Ref, forwardRef, useContext } from "react";
10
+ import * as THREE from "three";
11
+ import { groundRayType, propType } from "../../controller/type";
12
+ import { GaesupWorldContext } from "../../stores/context/gaesupworld";
13
+ import { getRayHit } from "../../utils/ray";
14
+ import { useForwardRef } from "../../utils/ref";
15
+
16
+ export const AirplaneRigidBody = forwardRef(
17
+ (
18
+ {
19
+ groundRay,
20
+ children,
21
+ }: {
22
+ groundRay: groundRayType;
23
+ children: ReactNode;
24
+ },
25
+ ref: Ref<RapierRigidBody>
26
+ ) => {
27
+ return (
28
+ <RigidBody colliders={false} ref={ref}>
29
+ {/* {options.debug && (
30
+ <mesh visible={options.debug}>
31
+ <arrowHelper
32
+ args={[groundRay.dir, groundRay.origin, groundRay.length]}
33
+ />
34
+ </mesh>
35
+ )} */}
36
+ {children}
37
+ </RigidBody>
38
+ );
39
+ }
40
+ );
41
+
42
+ export const AirplaneCollider = forwardRef(
43
+ ({ prop }: { prop: propType }, ref: Ref<Collider>) => {
44
+ const { airplaneCollider: collider } = useContext(GaesupWorldContext);
45
+ const { airplaneSizeX, airplaneSizeY, airplaneSizeZ } = collider;
46
+ console.log(airplaneSizeY);
47
+ const colliderRef = useForwardRef<Collider>(ref);
48
+ const { rapier } = useRapier();
49
+ const { groundRay, slopeRay } = prop;
50
+ groundRay.length = airplaneSizeY * 5 + 2;
51
+ groundRay.rayCast = new rapier.Ray(groundRay.origin, groundRay.dir);
52
+ groundRay.hit = getRayHit<groundRayType>({
53
+ ray: groundRay,
54
+ ref: colliderRef,
55
+ });
56
+ groundRay.parent = groundRay.hit?.collider.parent();
57
+
58
+ return (
59
+ <CuboidCollider
60
+ ref={ref}
61
+ args={[airplaneSizeX / 2, airplaneSizeY / 2, airplaneSizeZ / 2]}
62
+ position={[0, airplaneSizeY / 2, 0]}
63
+ />
64
+ );
65
+ }
66
+ );
67
+
68
+ export const AirplaneGroup = forwardRef(
69
+ (
70
+ {
71
+ children,
72
+ }: {
73
+ children: ReactNode;
74
+ },
75
+ ref: Ref<THREE.Group>
76
+ ) => {
77
+ return (
78
+ <group ref={ref} userData={{ intangible: true }}>
79
+ {children}
80
+ </group>
81
+ );
82
+ }
83
+ );
@@ -0,0 +1,132 @@
1
+ import { Collider } from "@dimforge/rapier3d-compat";
2
+
3
+ import {
4
+ CapsuleCollider,
5
+ RapierRigidBody,
6
+ RigidBody,
7
+ useRapier,
8
+ } from "@react-three/rapier";
9
+ import { ReactNode, Ref, forwardRef, useContext } from "react";
10
+ import * as THREE from "three";
11
+
12
+ import {
13
+ controllerType,
14
+ groundRayType,
15
+ propType,
16
+ slopeRayType,
17
+ } from "../../controller/type";
18
+ import { GaesupWorldContext } from "../../stores/context/gaesupworld";
19
+ import { getRayHit } from "../../utils/ray";
20
+ import { useForwardRef } from "../../utils/ref";
21
+
22
+ export const CharacterRigidBody = forwardRef(
23
+ (
24
+ {
25
+ controllerProps,
26
+ children,
27
+ }: {
28
+ controllerProps: controllerType;
29
+ children: ReactNode;
30
+ },
31
+ ref: Ref<RapierRigidBody>
32
+ ) => {
33
+ return (
34
+ <RigidBody
35
+ colliders={false}
36
+ canSleep={false}
37
+ ref={ref}
38
+ {...controllerProps}
39
+ >
40
+ {/* {options.debug && (
41
+ <mesh
42
+ visible={options.debug}
43
+ userData={{
44
+ intangible: true,
45
+ }}
46
+ >
47
+ <arrowHelper
48
+ args={[groundRay.dir, groundRay.origin, groundRay.length]}
49
+ />
50
+ </mesh>
51
+ )} */}
52
+ {children}
53
+ </RigidBody>
54
+ );
55
+ }
56
+ );
57
+
58
+ export const CharacterCapsuleCollider = forwardRef(
59
+ ({ prop }: { prop: propType }, ref: Ref<Collider>) => {
60
+ const { characterCollider: collider } = useContext(GaesupWorldContext);
61
+ const colliderRef = useForwardRef<Collider>(ref);
62
+ const { rapier } = useRapier();
63
+ const { groundRay, slopeRay } = prop;
64
+ groundRay.length = collider.radius + 2;
65
+ groundRay.rayCast = new rapier.Ray(groundRay.origin, groundRay.dir);
66
+ groundRay.hit = getRayHit<groundRayType>({
67
+ ray: groundRay,
68
+ ref: colliderRef,
69
+ });
70
+ groundRay.parent = groundRay.hit?.collider.parent();
71
+
72
+ slopeRay.rayCast = new rapier.Ray(slopeRay.origin, slopeRay.dir);
73
+ slopeRay.length = collider.radius + 3;
74
+ slopeRay.rayCast = new rapier.Ray(slopeRay.origin, slopeRay.dir);
75
+
76
+ return (
77
+ <CapsuleCollider ref={ref} args={[collider.height, collider.radius]} />
78
+ );
79
+ }
80
+ );
81
+
82
+ export const CharacterGroup = forwardRef(
83
+ (
84
+ {
85
+ children,
86
+ }: {
87
+ children: ReactNode;
88
+ },
89
+ ref: Ref<THREE.Group>
90
+ ) => {
91
+ return (
92
+ <group ref={ref} userData={{ intangible: true }}>
93
+ {children}
94
+ </group>
95
+ );
96
+ }
97
+ );
98
+
99
+ export const CharacterSlopeRay = forwardRef(
100
+ (
101
+ {
102
+ groundRay,
103
+ slopeRay,
104
+ }: {
105
+ groundRay: groundRayType;
106
+ slopeRay: slopeRayType;
107
+ },
108
+ ref: Ref<THREE.Mesh>
109
+ ) => {
110
+ return (
111
+ <mesh
112
+ position={[
113
+ groundRay.offset.x,
114
+ groundRay.offset.y,
115
+ groundRay.offset.z + slopeRay.offset.z,
116
+ ]}
117
+ ref={ref}
118
+ visible={false}
119
+ userData={{ intangible: true }}
120
+ >
121
+ {/* {options.debug && (
122
+ <mesh userData={{ intangible: true }}>
123
+ <arrowHelper
124
+ args={[slopeRay.dir, slopeRay.origin, slopeRay.length, "#ff0000"]}
125
+ />
126
+ </mesh>
127
+ )} */}
128
+ <boxGeometry args={[0.15, 0.15, 0.15]} />
129
+ </mesh>
130
+ );
131
+ }
132
+ );
@@ -0,0 +1,145 @@
1
+ import { Collider } from "@dimforge/rapier3d-compat";
2
+ import { Gltf } from "@react-three/drei";
3
+ import {
4
+ CuboidCollider,
5
+ CylinderCollider,
6
+ RapierRigidBody,
7
+ RigidBody,
8
+ useRevoluteJoint,
9
+ } from "@react-three/rapier";
10
+ import { ReactNode, Ref, RefObject, forwardRef, useContext } from "react";
11
+ import * as THREE from "three";
12
+ import { groundRayType } from "../../controller/type";
13
+ import { GaesupWorldContext } from "../../stores/context/gaesupworld";
14
+ import { S3 } from "../../utils/constant";
15
+
16
+ export const VehicleRigidBody = forwardRef(
17
+ (
18
+ {
19
+ groundRay,
20
+ children,
21
+ }: {
22
+ groundRay: groundRayType;
23
+ children: ReactNode;
24
+ },
25
+ ref: Ref<RapierRigidBody>
26
+ ) => {
27
+ return (
28
+ <RigidBody colliders={false} ref={ref}>
29
+ {/* {options.debug && (
30
+ <mesh visible={options.debug}>
31
+ <arrowHelper
32
+ args={[groundRay.dir, groundRay.origin, groundRay.length]}
33
+ />
34
+ </mesh>
35
+ )} */}
36
+ {children}
37
+ </RigidBody>
38
+ );
39
+ }
40
+ );
41
+
42
+ export const VehicleCollider = forwardRef((_, ref: Ref<Collider>) => {
43
+ const { vehicleCollider: collider } = useContext(GaesupWorldContext);
44
+ const { vehicleSizeX, vehicleSizeY, vehicleSizeZ } = collider;
45
+ return (
46
+ <CuboidCollider
47
+ ref={ref}
48
+ args={[vehicleSizeX / 2, vehicleSizeY / 2, vehicleSizeZ / 2]}
49
+ position={[0, vehicleSizeY / 2, 0]}
50
+ />
51
+ );
52
+ });
53
+
54
+ export const VehicleGroup = forwardRef(
55
+ (
56
+ {
57
+ children,
58
+ }: {
59
+ children: ReactNode;
60
+ },
61
+ ref: Ref<THREE.Group>
62
+ ) => {
63
+ return (
64
+ <group ref={ref} userData={{ intangible: true }}>
65
+ {children}
66
+ </group>
67
+ );
68
+ }
69
+ );
70
+
71
+ export type wheelRegidBodyType = {
72
+ wheelPosition: [number, number, number];
73
+ wheelsUrl?: string;
74
+ bodyRef: RefObject<RapierRigidBody>;
75
+ wheel: RefObject<RapierRigidBody>;
76
+ bodyAnchor: THREE.Vector3Tuple;
77
+ wheelAnchor: THREE.Vector3Tuple;
78
+ rotationAxis: THREE.Vector3Tuple;
79
+ };
80
+
81
+ export const WheelRegidBodyRef = forwardRef(
82
+ (
83
+ {
84
+ wheelPosition,
85
+ wheelsUrl,
86
+ bodyRef,
87
+ wheel,
88
+ bodyAnchor,
89
+ wheelAnchor,
90
+ rotationAxis,
91
+ }: wheelRegidBodyType,
92
+ ref: Ref<RapierRigidBody>
93
+ ) => {
94
+ const { vehicleCollider: collider } = useContext(GaesupWorldContext);
95
+ const { wheelSizeX, wheelSizeY } = collider;
96
+ useRevoluteJoint(bodyRef, wheel, [bodyAnchor, wheelAnchor, rotationAxis]);
97
+
98
+ return (
99
+ <RigidBody position={wheelPosition} colliders={false} ref={ref}>
100
+ <CylinderCollider
101
+ args={[wheelSizeX / 2, wheelSizeY / 2]}
102
+ rotation={[0, 0, Math.PI / 2]}
103
+ />
104
+ <Gltf src={wheelsUrl || S3 + "/wheel.glb"} />
105
+ </RigidBody>
106
+ );
107
+ }
108
+ );
109
+
110
+ //
111
+ // export const GaesupSlopeRay = forwardRef(
112
+ // (
113
+ // {
114
+ // groundRay,
115
+ // slopeRay,
116
+ // }: {
117
+ // groundRay: groundRayType;
118
+ // slopeRay: slopeRayType;
119
+ // },
120
+ // ref: Ref<THREE.Mesh>
121
+ // ) => {
122
+ // const options = useAtomValue(optionsAtom);
123
+ // return (
124
+ // <mesh
125
+ // position={[
126
+ // groundRay.offset.x,
127
+ // groundRay.offset.y,
128
+ // groundRay.offset.z + slopeRay.offset.z,
129
+ // ]}
130
+ // ref={ref}
131
+ // visible={false}
132
+ // userData={{ intangible: true }}
133
+ // >
134
+ // {options.debug && (
135
+ // <mesh>
136
+ // <arrowHelper
137
+ // args={[slopeRay.dir, slopeRay.origin, slopeRay.length, "#ff0000"]}
138
+ // />
139
+ // </mesh>
140
+ // )}
141
+ // <boxGeometry args={[0.15, 0.15, 0.15]} />
142
+ // </mesh>
143
+ // );
144
+ // }
145
+ // );
@@ -0,0 +1,103 @@
1
+ "use client";
2
+
3
+ import { Collider, RevoluteImpulseJoint } from "@dimforge/rapier3d-compat";
4
+ import { RapierRigidBody } from "@react-three/rapier";
5
+ import React, { useContext, useMemo, useReducer, useRef } from "react";
6
+ import Camera from "../camera";
7
+ import { Airplane } from "../component/Airplane";
8
+ import { Character } from "../component/Character";
9
+ import { Vehicle } from "../component/Vehicle";
10
+ import initControllerProps from "../initial/controller";
11
+ import {
12
+ GaesupControllerContext,
13
+ GaesupControllerDispatchContext,
14
+ gaesupControllerDefault,
15
+ } from "../stores/context/controller";
16
+ import { gaesupControllerReducer } from "../stores/context/controller/reducer";
17
+ import { GaesupWorldContext } from "../stores/context/gaesupworld";
18
+ import { controllerType, propType, refsType } from "./type";
19
+
20
+ export default function GaesupController(props: controllerType) {
21
+ const { mode } = useContext(GaesupWorldContext);
22
+ const [controller, controllerDispatch] = useReducer(gaesupControllerReducer, {
23
+ cameraMode: Object.assign(
24
+ gaesupControllerDefault.cameraMode,
25
+ props.cameraMode || {}
26
+ ),
27
+ cameraOption: Object.assign(
28
+ gaesupControllerDefault.cameraOption,
29
+ props.cameraOption || {}
30
+ ),
31
+ perspectiveCamera: Object.assign(
32
+ gaesupControllerDefault.perspectiveCamera,
33
+ props.perspectiveCamera || {}
34
+ ),
35
+ orthographicCamera: Object.assign(
36
+ gaesupControllerDefault.orthographicCamera,
37
+ props.orthographicCamera || {}
38
+ ),
39
+ });
40
+
41
+ const capsuleColliderRef = useRef<Collider>(null);
42
+ const rigidBodyRef = useRef<RapierRigidBody>(null);
43
+ const outerGroupRef = useRef<THREE.Group>(null);
44
+ const innerGroupRef = useRef<THREE.Group>(null);
45
+ const slopeRayOriginRef = useRef<THREE.Mesh>(null);
46
+ const jointRefs = useRef<RevoluteImpulseJoint>(null);
47
+
48
+ const gaesupControl = useMemo(
49
+ () => ({
50
+ value: controller,
51
+ dispatch: controllerDispatch,
52
+ }),
53
+ [
54
+ controller.cameraMode,
55
+ controller.cameraOption,
56
+ controller.perspectiveCamera,
57
+ controller.orthographicCamera,
58
+ controllerDispatch,
59
+ ]
60
+ );
61
+
62
+ const refs: refsType = {
63
+ capsuleColliderRef,
64
+ rigidBodyRef,
65
+ outerGroupRef,
66
+ innerGroupRef,
67
+ slopeRayOriginRef,
68
+ jointRefs,
69
+ };
70
+
71
+ const prop: propType = {
72
+ ...initControllerProps({
73
+ props,
74
+ refs,
75
+ }),
76
+ callbacks: {
77
+ onReady: props.onReady,
78
+ onFrame: props.onFrame,
79
+ onDestory: props.onDestory,
80
+ onAnimate: props.onAnimate,
81
+ },
82
+ children: props.children,
83
+ groupProps: props.groupProps,
84
+ ...refs,
85
+ };
86
+
87
+ return (
88
+ <GaesupControllerContext.Provider value={gaesupControl.value}>
89
+ <Camera refs={refs} prop={prop} control={prop.keyControl} />
90
+ <GaesupControllerDispatchContext.Provider value={gaesupControl.dispatch}>
91
+ {mode.type === "character" && (
92
+ <Character controllerProps={prop} refs={refs} />
93
+ )}
94
+ {mode.type === "vehicle" && (
95
+ <Vehicle controllerProps={prop} refs={refs} />
96
+ )}
97
+ {mode.type === "airplane" && (
98
+ <Airplane controllerProps={prop} refs={refs} />
99
+ )}
100
+ </GaesupControllerDispatchContext.Provider>
101
+ </GaesupControllerContext.Provider>
102
+ );
103
+ }