gaesup-world 0.0.691 → 0.0.761

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 (166) hide show
  1. package/README.md +16 -0
  2. package/dist/gaesup/animation/actions.d.ts +22 -5
  3. package/dist/gaesup/animation/actions.js +63 -35
  4. package/dist/gaesup/animation/passiveActions.d.ts +9 -0
  5. package/dist/gaesup/animation/passiveActions.js +16 -0
  6. package/dist/gaesup/camera/control/normal.js +2 -2
  7. package/dist/gaesup/camera/detector/index.d.ts +2 -0
  8. package/dist/gaesup/camera/detector/index.js +25 -0
  9. package/dist/gaesup/camera/index.js +11 -8
  10. package/dist/gaesup/camera/type.d.ts +3 -7
  11. package/dist/gaesup/component/active/airplane/collider.d.ts +6 -0
  12. package/dist/gaesup/component/active/airplane/collider.js +22 -0
  13. package/dist/gaesup/component/active/airplane/index.d.ts +5 -0
  14. package/dist/gaesup/component/active/airplane/index.js +11 -0
  15. package/dist/gaesup/component/active/character/collider.d.ts +6 -0
  16. package/dist/gaesup/component/active/character/collider.js +24 -0
  17. package/dist/gaesup/component/active/character/index.d.ts +5 -0
  18. package/dist/gaesup/component/active/character/index.js +16 -0
  19. package/dist/gaesup/component/active/common/InnerGroupRef.d.ts +10 -0
  20. package/dist/gaesup/component/active/common/InnerGroupRef.js +32 -0
  21. package/dist/gaesup/component/active/common/OuterGroupRef.d.ts +6 -0
  22. package/dist/gaesup/component/active/common/OuterGroupRef.js +17 -0
  23. package/dist/gaesup/component/active/common/RigidbodyRef.d.ts +7 -0
  24. package/dist/gaesup/component/active/common/RigidbodyRef.js +18 -0
  25. package/dist/gaesup/component/active/common/WrapperRef.d.ts +12 -0
  26. package/dist/gaesup/component/active/common/WrapperRef.js +9 -0
  27. package/dist/gaesup/component/active/common/slopeRayRef.d.ts +6 -0
  28. package/dist/gaesup/component/active/common/slopeRayRef.js +10 -0
  29. package/dist/gaesup/component/active/vehicle/collider.d.ts +3 -0
  30. package/dist/gaesup/component/active/vehicle/collider.js +9 -0
  31. package/dist/gaesup/component/active/vehicle/index.d.ts +5 -0
  32. package/dist/gaesup/component/active/vehicle/index.js +12 -0
  33. package/dist/gaesup/component/active/vehicle/wheel.d.ts +12 -0
  34. package/dist/gaesup/component/active/vehicle/wheel.js +13 -0
  35. package/dist/gaesup/component/active/vehicle/wheels.d.ts +7 -0
  36. package/dist/gaesup/component/{gltf/WheelJoint.js → active/vehicle/wheels.js} +6 -6
  37. package/dist/gaesup/component/index.d.ts +7 -5
  38. package/dist/gaesup/component/index.js +20 -5
  39. package/dist/gaesup/component/passive/airplane/collider.d.ts +6 -0
  40. package/dist/gaesup/component/passive/airplane/collider.js +8 -0
  41. package/dist/gaesup/component/passive/airplane/index.d.ts +4 -0
  42. package/dist/gaesup/component/passive/airplane/index.js +25 -0
  43. package/dist/gaesup/component/passive/character/collider.d.ts +6 -0
  44. package/dist/gaesup/component/passive/character/collider.js +7 -0
  45. package/dist/gaesup/component/passive/character/index.d.ts +4 -0
  46. package/dist/gaesup/component/passive/character/index.js +25 -0
  47. package/dist/gaesup/component/passive/common/InnerGroupRef.d.ts +8 -0
  48. package/dist/gaesup/component/passive/common/InnerGroupRef.js +27 -0
  49. package/dist/gaesup/component/passive/common/OuterGroupRef.d.ts +4 -0
  50. package/dist/gaesup/component/passive/common/OuterGroupRef.js +6 -0
  51. package/dist/gaesup/component/passive/common/PassiveWrapperRef.d.ts +10 -0
  52. package/dist/gaesup/component/passive/common/PassiveWrapperRef.js +8 -0
  53. package/dist/gaesup/component/passive/common/RigidbodyRef.d.ts +5 -0
  54. package/dist/gaesup/component/passive/common/RigidbodyRef.js +7 -0
  55. package/dist/gaesup/component/passive/type.d.ts +30 -0
  56. package/dist/gaesup/component/passive/vehicle/collider.d.ts +7 -0
  57. package/dist/gaesup/component/passive/vehicle/collider.js +8 -0
  58. package/dist/gaesup/component/passive/vehicle/index.d.ts +4 -0
  59. package/dist/gaesup/component/passive/vehicle/index.js +26 -0
  60. package/dist/gaesup/component/passive/vehicle/wheel.d.ts +16 -0
  61. package/dist/gaesup/component/passive/vehicle/wheel.js +10 -0
  62. package/dist/gaesup/component/passive/vehicle/wheels.d.ts +11 -0
  63. package/dist/gaesup/component/passive/vehicle/wheels.js +27 -0
  64. package/dist/gaesup/component/type.d.ts +18 -0
  65. package/dist/gaesup/controller/context/index.js +0 -1
  66. package/dist/gaesup/controller/context/reducer.d.ts +2 -2
  67. package/dist/gaesup/controller/context/type.d.ts +4 -4
  68. package/dist/gaesup/controller/debug/index.js +2 -0
  69. package/dist/gaesup/controller/index.js +14 -30
  70. package/dist/gaesup/controller/initialize/callback/index.d.ts +2 -0
  71. package/dist/gaesup/{initial → controller/initialize}/callback/index.js +5 -6
  72. package/dist/gaesup/{initial → controller/initialize}/callback/type.d.ts +3 -6
  73. package/dist/gaesup/controller/initialize/callback/type.js +1 -0
  74. package/dist/gaesup/controller/initialize/index.d.ts +2 -16
  75. package/dist/gaesup/controller/initialize/index.js +8 -11
  76. package/dist/gaesup/controller/type.d.ts +7 -6
  77. package/dist/gaesup/hooks/index.d.ts +1 -0
  78. package/dist/gaesup/hooks/index.js +1 -0
  79. package/dist/gaesup/hooks/useGaesupController/index.d.ts +12 -0
  80. package/dist/gaesup/hooks/useGaesupController/index.js +18 -0
  81. package/dist/gaesup/index.d.ts +2 -2
  82. package/dist/gaesup/index.js +2 -2
  83. package/dist/gaesup/mutation/airplane/index.d.ts +2 -0
  84. package/dist/gaesup/mutation/airplane/index.js +6 -0
  85. package/dist/gaesup/mutation/airplane/rotation.d.ts +2 -0
  86. package/dist/gaesup/mutation/airplane/rotation.js +9 -0
  87. package/dist/gaesup/mutation/character/index.d.ts +2 -0
  88. package/dist/gaesup/mutation/character/index.js +8 -0
  89. package/dist/gaesup/mutation/character/rotation.d.ts +2 -0
  90. package/dist/gaesup/mutation/character/rotation.js +5 -0
  91. package/dist/gaesup/mutation/common/stabilizing.d.ts +2 -0
  92. package/dist/gaesup/mutation/common/stabilizing.js +4 -0
  93. package/dist/gaesup/mutation/common/transition.d.ts +2 -0
  94. package/dist/gaesup/mutation/common/transition.js +4 -0
  95. package/dist/gaesup/mutation/index.d.ts +7 -0
  96. package/dist/gaesup/mutation/index.js +35 -0
  97. package/dist/gaesup/mutation/type.d.ts +21 -0
  98. package/dist/gaesup/mutation/type.js +1 -0
  99. package/dist/gaesup/mutation/vehicle/index.d.ts +2 -0
  100. package/dist/gaesup/mutation/vehicle/index.js +6 -0
  101. package/dist/gaesup/mutation/vehicle/rotation.d.ts +2 -0
  102. package/dist/gaesup/mutation/vehicle/rotation.js +5 -0
  103. package/dist/gaesup/physics/airplane/direction.js +1 -0
  104. package/dist/gaesup/physics/airplane/impulse.js +1 -1
  105. package/dist/gaesup/physics/character/direction.js +8 -9
  106. package/dist/gaesup/physics/character/impulse.js +1 -1
  107. package/dist/gaesup/physics/character/jump.js +1 -1
  108. package/dist/gaesup/physics/character/turn.js +6 -2
  109. package/dist/gaesup/physics/index.js +9 -2
  110. package/dist/gaesup/physics/type.d.ts +5 -2
  111. package/dist/gaesup/tools/minimap/index.js +5 -3
  112. package/dist/gaesup/tools/minimap/type.d.ts +2 -0
  113. package/dist/gaesup/utils/gltf.d.ts +7 -0
  114. package/dist/gaesup/utils/gltf.js +10 -0
  115. package/dist/gaesup/world/context/index.js +3 -6
  116. package/dist/gaesup/world/context/reducer.d.ts +4 -4
  117. package/dist/gaesup/world/context/type.d.ts +18 -7
  118. package/dist/gaesup/world/debug/index.js +3 -0
  119. package/dist/gaesup/world/initalize/collider/gltf.d.ts +1 -1
  120. package/dist/gaesup/world/initalize/collider/gltf.js +15 -32
  121. package/dist/gaesup/world/initalize/collider/vehicle.js +38 -17
  122. package/dist/gaesup/world/initalize/index.d.ts +4 -4
  123. package/dist/gaesup/world/initalize/index.js +1 -20
  124. package/dist/styles/sprinkles/color.css.d.ts +2 -2
  125. package/dist/styles/sprinkles/direction.css.d.ts +8 -8
  126. package/dist/styles/sprinkles/display.css.d.ts +3 -3
  127. package/dist/styles/sprinkles/fontSize.css.d.ts +4 -4
  128. package/dist/styles/sprinkles/index.css.d.ts +228 -228
  129. package/dist/styles/sprinkles/margin.css.d.ts +50 -50
  130. package/dist/styles/sprinkles/padding.css.d.ts +50 -50
  131. package/package.json +5 -2
  132. package/dist/gaesup/camera/cameraCollisionDetecter.d.ts +0 -4
  133. package/dist/gaesup/camera/cameraCollisionDetecter.js +0 -50
  134. package/dist/gaesup/component/Airplane.d.ts +0 -5
  135. package/dist/gaesup/component/Airplane.js +0 -14
  136. package/dist/gaesup/component/Character.d.ts +0 -5
  137. package/dist/gaesup/component/Character.js +0 -13
  138. package/dist/gaesup/component/Vehicle.d.ts +0 -5
  139. package/dist/gaesup/component/Vehicle.js +0 -15
  140. package/dist/gaesup/component/gltf/AirplaneGltf.d.ts +0 -2
  141. package/dist/gaesup/component/gltf/AirplaneGltf.js +0 -13
  142. package/dist/gaesup/component/gltf/CharacterGltf.d.ts +0 -11
  143. package/dist/gaesup/component/gltf/CharacterGltf.js +0 -44
  144. package/dist/gaesup/component/gltf/VehicleGltf.d.ts +0 -2
  145. package/dist/gaesup/component/gltf/VehicleGltf.js +0 -13
  146. package/dist/gaesup/component/gltf/WheelJoint.d.ts +0 -4
  147. package/dist/gaesup/component/gltf/index.d.ts +0 -4
  148. package/dist/gaesup/component/gltf/index.js +0 -4
  149. package/dist/gaesup/component/gltf/type.d.ts +0 -10
  150. package/dist/gaesup/component/ref/airplane.d.ts +0 -16
  151. package/dist/gaesup/component/ref/airplane.js +0 -46
  152. package/dist/gaesup/component/ref/character.d.ts +0 -20
  153. package/dist/gaesup/component/ref/character.js +0 -56
  154. package/dist/gaesup/component/ref/index.d.ts +0 -3
  155. package/dist/gaesup/component/ref/index.js +0 -3
  156. package/dist/gaesup/component/ref/vehicle.d.ts +0 -24
  157. package/dist/gaesup/component/ref/vehicle.js +0 -41
  158. package/dist/gaesup/component/setInit.d.ts +0 -3
  159. package/dist/gaesup/component/setInit.js +0 -10
  160. package/dist/gaesup/initial/callback/index.d.ts +0 -2
  161. package/dist/gaesup/initial/index.d.ts +0 -1
  162. package/dist/gaesup/initial/index.js +0 -1
  163. package/dist/gaesup/utils/constant.d.ts +0 -1
  164. package/dist/gaesup/utils/constant.js +0 -1
  165. /package/dist/gaesup/component/{gltf → passive}/type.js +0 -0
  166. /package/dist/gaesup/{initial/callback → component}/type.js +0 -0
package/README.md CHANGED
@@ -182,3 +182,19 @@ This is the airplane control in Gaesup World. Characters can board the airplane.
182
182
  ## Tools
183
183
 
184
184
  #### [Tools](#tools)
185
+
186
+ #### [joystick](#joystick)
187
+
188
+ #### [keyboardtooltip](#keyboard tooltip)
189
+
190
+ #### [minimap](#minimap)
191
+
192
+ #### [gameboy](#gameboy)
193
+
194
+ ## joystick
195
+
196
+ ## keyboard tooltip
197
+
198
+ ## minimap
199
+
200
+ ## gameboy
@@ -1,8 +1,25 @@
1
- import { RefObject } from "react";
2
- import { groundRayType } from "../controller/type";
1
+ import { Ref } from "react";
2
+ import { Object3D, Object3DEventMap } from "three";
3
+ import { animationTagType, groundRayType } from "../controller/type";
3
4
  export type playActionsType = {
4
- outerGroupRef: RefObject<THREE.Group>;
5
5
  groundRay: groundRayType;
6
- isRider?: boolean;
7
6
  };
8
- export default function playActions({ outerGroupRef, groundRay, isRider, }: playActionsType): void;
7
+ export type actionsType = {
8
+ [x: string]: THREE.AnimationAction | null;
9
+ };
10
+ export type playResultType = {
11
+ actions: actionsType;
12
+ ref: Ref<Object3D<Object3DEventMap>>;
13
+ };
14
+ export declare function usePlayActions(): {
15
+ resultRef: {
16
+ character: playResultType;
17
+ vehicle: playResultType;
18
+ airplane: playResultType;
19
+ };
20
+ play: (tag: keyof animationTagType) => void;
21
+ setAnimationName: (actions: actionsType) => void;
22
+ };
23
+ export default function playCharacterActions({ groundRay }: playActionsType): {
24
+ ref: Ref<Object3D<Object3DEventMap>>;
25
+ };
@@ -13,43 +13,53 @@ import { useAnimations, useKeyboardControls } from "@react-three/drei";
13
13
  import { useFrame } from "@react-three/fiber";
14
14
  import { useContext, useEffect } from "react";
15
15
  import { GaesupWorldContext, GaesupWorldDispatchContext, } from "../world/context";
16
- export default function playActions(_a) {
17
- var outerGroupRef = _a.outerGroupRef, groundRay = _a.groundRay, isRider = _a.isRider;
18
- var _b = useContext(GaesupWorldContext), characterGltf = _b.characterGltf, characterAnimations = _b.animations;
16
+ export function usePlayActions() {
17
+ var _a = useContext(GaesupWorldContext), characterGltf = _a.characterGltf, vehicleGltf = _a.vehicleGltf, airplaneGltf = _a.airplaneGltf, animations = _a.animations;
18
+ var resultRef = {
19
+ character: null,
20
+ vehicle: null,
21
+ airplane: null,
22
+ };
23
+ if (characterGltf && characterGltf.animations) {
24
+ resultRef.character = useAnimations(characterGltf.animations);
25
+ }
26
+ if (vehicleGltf && vehicleGltf.animations) {
27
+ resultRef.vehicle = useAnimations(vehicleGltf.animations);
28
+ }
29
+ if (airplaneGltf && airplaneGltf.animations) {
30
+ resultRef.airplane = useAnimations(airplaneGltf.animations);
31
+ }
19
32
  var dispatch = useContext(GaesupWorldDispatchContext);
20
- var animations = characterGltf.animations;
21
- var control = useKeyboardControls()[1]();
22
- var actions = useAnimations(animations, outerGroupRef).actions;
23
- useEffect(function () {
24
- characterAnimations.keyControl = control;
25
- dispatch({
26
- type: "update",
27
- payload: {
28
- animations: __assign({}, characterAnimations),
29
- },
30
- });
31
- }, [control]);
32
33
  var play = function (tag) {
33
- characterAnimations.current = tag;
34
+ animations.current = tag;
34
35
  dispatch({
35
36
  type: "update",
36
37
  payload: {
37
- animations: __assign({}, characterAnimations),
38
+ animations: __assign({}, animations),
38
39
  },
39
40
  });
40
41
  };
41
42
  var setAnimationName = function (actions) {
42
- characterAnimations.animationNames = Object.assign(characterAnimations.animationNames, Object.keys(actions).reduce(function (acc, cur) {
43
+ animations.animationNames = Object.assign(animations.animationNames, Object.keys(actions).reduce(function (acc, cur) {
43
44
  var _a;
44
45
  return __assign(__assign({}, acc), (_a = {}, _a[cur] = cur, _a));
45
46
  }, {}));
46
47
  dispatch({
47
48
  type: "update",
48
49
  payload: {
49
- animations: __assign({}, characterAnimations),
50
+ animations: __assign({}, animations),
50
51
  },
51
52
  });
52
53
  };
54
+ return { resultRef: resultRef, play: play, setAnimationName: setAnimationName };
55
+ }
56
+ export default function playCharacterActions(_a) {
57
+ var groundRay = _a.groundRay;
58
+ var _b = usePlayActions(), _c = _b.resultRef.character, actions = _c.actions, ref = _c.ref, play = _b.play, setAnimationName = _b.setAnimationName;
59
+ var _d = useContext(GaesupWorldContext), states = _d.states, activeState = _d.activeState, animations = _d.animations, mode = _d.mode;
60
+ var isNotMoving = states.isNotMoving, isMoving = states.isMoving, isJumping = states.isJumping, isRunning = states.isRunning, isAnimationOuter = states.isAnimationOuter, isOnTheGround = states.isOnTheGround;
61
+ var dispatch = useContext(GaesupWorldDispatchContext);
62
+ var control = useKeyboardControls()[1]();
53
63
  var resetAni = function () { return play("idle"); };
54
64
  var playIdle = function () { return play("idle"); };
55
65
  var playWalk = function () { return play("walk"); };
@@ -57,27 +67,33 @@ export default function playActions(_a) {
57
67
  var playJump = function () { return play("jump"); };
58
68
  var playFall = function () { return play("fall"); };
59
69
  var playRide = function () { return play("ride"); };
70
+ var playLanding = function () { return play("land"); };
60
71
  useEffect(function () {
61
72
  return function () {
62
73
  resetAni();
63
74
  };
64
75
  }, []);
76
+ useEffect(function () {
77
+ animations.keyControl = control;
78
+ dispatch({
79
+ type: "update",
80
+ payload: {
81
+ animations: __assign({}, animations),
82
+ },
83
+ });
84
+ }, [control]);
65
85
  useEffect(function () {
66
86
  var _a;
67
- // Play animation
68
- var action = (_a = actions[characterAnimations.current]) === null || _a === void 0 ? void 0 : _a.reset().fadeIn(0.2).play();
69
- setAnimationName(actions);
70
- return function () {
71
- action === null || action === void 0 ? void 0 : action.fadeOut(0.2);
72
- };
73
- }, [characterAnimations.current]);
74
- var _c = useContext(GaesupWorldContext), states = _c.states, activeState = _c.activeState;
75
- var isNotMoving = states.isNotMoving, isMoving = states.isMoving, isJumping = states.isJumping, isRunning = states.isRunning, isAnimationOuter = states.isAnimationOuter;
76
- useFrame(function () {
77
- if (isRider) {
78
- playRide();
87
+ if (mode.type === "character") {
88
+ var action_1 = (_a = actions[animations.current]) === null || _a === void 0 ? void 0 : _a.reset().fadeIn(0.2).play();
89
+ setAnimationName(actions);
90
+ return function () {
91
+ action_1 === null || action_1 === void 0 ? void 0 : action_1.fadeOut(0.2);
92
+ };
79
93
  }
80
- else {
94
+ }, [animations.current, mode.type]);
95
+ useFrame(function () {
96
+ if (mode.type === "character") {
81
97
  if (!isAnimationOuter) {
82
98
  if (isJumping) {
83
99
  playJump();
@@ -91,10 +107,22 @@ export default function playActions(_a) {
91
107
  else if (isMoving) {
92
108
  playWalk();
93
109
  }
94
- if (groundRay.hit === null && activeState.velocity.y < 0) {
95
- playFall();
96
- }
110
+ // if (groundRay.hit) {
111
+ // if (!isJumping && !isOnTheGround) {
112
+ // if (groundRay.hit.toi < 5) {
113
+ // playLanding();
114
+ // } else {
115
+ // playFall();
116
+ // }
117
+ // }
118
+ // }
119
+ // if (groundRay.hit === null && activeState.velocity.y < 0) {
120
+ // playFall();
121
+ // }
97
122
  }
98
123
  }
99
124
  });
125
+ return {
126
+ ref: ref,
127
+ };
100
128
  }
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { AnimationClip } from "three";
3
+ export type playPassiveActionsType = {
4
+ current: string;
5
+ animations: AnimationClip[];
6
+ };
7
+ export default function playPassiveActions({ current, animations, }: playPassiveActionsType): {
8
+ animationRef: import("react").MutableRefObject<import("three").Object3D<import("three").Object3DEventMap>>;
9
+ };
@@ -0,0 +1,16 @@
1
+ import { useAnimations } from "@react-three/drei";
2
+ import { useEffect } from "react";
3
+ export default function playPassiveActions(_a) {
4
+ var current = _a.current, animations = _a.animations;
5
+ var _b = useAnimations(animations), actions = _b.actions, animationRef = _b.ref;
6
+ useEffect(function () {
7
+ var _a;
8
+ var action = (_a = actions[current]) === null || _a === void 0 ? void 0 : _a.reset().fadeIn(0.2).play();
9
+ return function () {
10
+ action === null || action === void 0 ? void 0 : action.fadeOut(0.2);
11
+ };
12
+ }, [current]);
13
+ return {
14
+ animationRef: animationRef,
15
+ };
16
+ }
@@ -3,7 +3,7 @@ export default function normal(prop) {
3
3
  var state = prop.state, perspectiveCamera = prop.controllerContext.perspectiveCamera, activeState = prop.worldContext.activeState;
4
4
  var cameraPosition = activeState.position
5
5
  .clone()
6
- .add(V3(perspectiveCamera.XZDistance, perspectiveCamera.YDistance, 0));
7
- state.camera.position.lerp(cameraPosition, 1);
6
+ .add(V3(0, perspectiveCamera.YDistance, perspectiveCamera.XZDistance));
7
+ state.camera.position.lerp(cameraPosition, 0.9);
8
8
  state.camera.lookAt(activeState.position.clone());
9
9
  }
@@ -0,0 +1,2 @@
1
+ import { cameraPropType } from "../../physics/type";
2
+ export default function detector(cameraProp: cameraPropType): void;
@@ -0,0 +1,25 @@
1
+ import * as THREE from "three";
2
+ export default function detector(cameraProp) {
3
+ var cameraRay = cameraProp.cameraRay, intersectObjectMap = cameraProp.intersectObjectMap;
4
+ var intersects = cameraRay.rayCast.intersectObjects(Object.values(intersectObjectMap));
5
+ var intersectId = {};
6
+ intersects.map(function (_a) {
7
+ var object = _a.object;
8
+ if (object instanceof THREE.Mesh) {
9
+ intersectId[object.uuid] = true;
10
+ }
11
+ });
12
+ Object.values(intersectObjectMap).map(function (mesh) {
13
+ if (mesh instanceof THREE.Mesh && mesh.material instanceof THREE.Material) {
14
+ var material = mesh.material;
15
+ if (intersectId[mesh.uuid]) {
16
+ material.opacity = 0.2;
17
+ material.transparent = true;
18
+ }
19
+ else {
20
+ material.opacity = 1;
21
+ material.transparent = false;
22
+ }
23
+ }
24
+ });
25
+ }
@@ -12,11 +12,10 @@ var __assign = (this && this.__assign) || function () {
12
12
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import { MapControls, OrbitControls, OrthographicCamera, PerspectiveCamera, } from "@react-three/drei";
14
14
  import { useFrame, useThree } from "@react-three/fiber";
15
- import { useContext } from "react";
15
+ import { useContext, useEffect, useMemo } from "react";
16
16
  import * as THREE from "three";
17
17
  import { GaesupControllerContext } from "../controller/context";
18
18
  import { GaesupWorldContext } from "../world/context";
19
- import cameraCollisionDetector from "./cameraCollisionDetecter";
20
19
  import mapControl from "./control/map";
21
20
  import normal from "./control/normal";
22
21
  import orbit from "./control/orbit";
@@ -27,11 +26,10 @@ export default function Camera(_a) {
27
26
  var cameraMode = controllerContext.cameraMode, perspectiveCamera = controllerContext.perspectiveCamera, orthographicCamera = controllerContext.orthographicCamera;
28
27
  var rigidBodyRef = refs.rigidBodyRef, outerGroupRef = refs.outerGroupRef;
29
28
  var cameraRay = prop.cameraRay;
30
- var checkCollision = cameraCollisionDetector(prop).checkCollision;
31
- var scene = useThree().scene;
29
+ var _b = useThree(), camera = _b.camera, scene = _b.scene;
32
30
  var activeState = worldContext.activeState;
33
- var intersectObjectMap = {};
34
- var cameraProp = __assign(__assign({}, prop), { checkCollision: checkCollision, control: control, controllerContext: controllerContext, worldContext: worldContext });
31
+ var intersectObjectMap = useMemo(function () { return ({}); }, []);
32
+ var cameraProp = __assign(__assign({}, prop), { control: control, controllerContext: controllerContext, worldContext: worldContext, intersectObjectMap: intersectObjectMap });
35
33
  var getMeshs = function (object) {
36
34
  if (object.userData && object.userData.intangible)
37
35
  return;
@@ -43,6 +41,9 @@ export default function Camera(_a) {
43
41
  getMeshs(child);
44
42
  });
45
43
  };
44
+ useEffect(function () {
45
+ scene.children.forEach(function (child) { return getMeshs(child); });
46
+ }, []);
46
47
  useFrame(function (state, delta) {
47
48
  if (!rigidBodyRef ||
48
49
  !rigidBodyRef.current ||
@@ -52,8 +53,6 @@ export default function Camera(_a) {
52
53
  cameraProp.state = state;
53
54
  cameraProp.delta = delta;
54
55
  if (cameraMode.cameraType === "perspective") {
55
- scene.children.forEach(function (child) { return getMeshs(child); });
56
- cameraRay.intersectObjectMap = intersectObjectMap;
57
56
  if (cameraMode.controlType === "orbit") {
58
57
  orbit(cameraProp);
59
58
  }
@@ -64,6 +63,10 @@ export default function Camera(_a) {
64
63
  else if (cameraMode.cameraType === "orthographic") {
65
64
  mapControl(cameraProp);
66
65
  }
66
+ // const distV3 = camera.position.clone().sub(activeState.position);
67
+ // cameraRay.origin.copy(camera.position);
68
+ // cameraRay.dir.copy(distV3.negate().normalize());
69
+ // detector(cameraProp);
67
70
  });
68
71
  return (_jsxs(_Fragment, { children: [cameraMode.cameraType === "perspective" && (_jsxs(_Fragment, { children: [_jsx(OrbitControls, { target: activeState.position }), _jsx(PerspectiveCamera, __assign({ makeDefault: true }, perspectiveCamera))] })), cameraMode.cameraType === "orthographic" && (_jsxs(_Fragment, { children: [_jsx(MapControls, { target: activeState.position }), _jsx(OrthographicCamera, __assign({ makeDefault: true }, orthographicCamera))] }))] }));
69
72
  }
@@ -2,16 +2,12 @@ export type cameraRayType = {
2
2
  origin: THREE.Vector3;
3
3
  hit: THREE.Raycaster;
4
4
  rayCast: THREE.Raycaster | null;
5
- lerpingPoint: THREE.Vector3;
6
5
  length: number;
7
6
  dir: THREE.Vector3;
8
7
  position: THREE.Vector3;
9
- followCamera: THREE.Object3D;
10
- pivot: THREE.Object3D;
11
- intersetesAndTransParented: THREE.Intersection<THREE.Object3D<THREE.Object3DEventMap>>[];
12
- intersects: THREE.Intersection<THREE.Object3D<THREE.Object3DEventMap>>[];
13
- intersectObjects: THREE.Object3D[];
8
+ intersects: THREE.Intersection<THREE.Mesh>[];
9
+ detected: THREE.Intersection<THREE.Mesh>[];
14
10
  intersectObjectMap: {
15
- [uuid: string]: THREE.Object3D;
11
+ [uuid: string]: THREE.Mesh;
16
12
  };
17
13
  };
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { Collider } from "@dimforge/rapier3d-compat";
3
+ import { controllerInnerType } from "../../../controller/type";
4
+ export declare const AirplaneCollider: import("react").ForwardRefExoticComponent<{
5
+ props: controllerInnerType;
6
+ } & import("react").RefAttributes<Collider>>;
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { CuboidCollider, useRapier } from "@react-three/rapier";
3
+ import { forwardRef, useContext } from "react";
4
+ import { getRayHit, useForwardRef } from "../../../utils";
5
+ import { GaesupWorldContext } from "../../../world/context";
6
+ export var AirplaneCollider = forwardRef(function (_a, ref) {
7
+ var _b;
8
+ var props = _a.props;
9
+ var collider = useContext(GaesupWorldContext).airplaneCollider;
10
+ var airplaneSizeX = collider.airplaneSizeX, airplaneSizeY = collider.airplaneSizeY, airplaneSizeZ = collider.airplaneSizeZ;
11
+ var colliderRef = useForwardRef(ref);
12
+ var rapier = useRapier().rapier;
13
+ var groundRay = props.groundRay;
14
+ groundRay.length = airplaneSizeY * 5 + 2;
15
+ groundRay.rayCast = new rapier.Ray(groundRay.origin, groundRay.dir);
16
+ groundRay.hit = getRayHit({
17
+ ray: groundRay,
18
+ ref: colliderRef,
19
+ });
20
+ groundRay.parent = (_b = groundRay.hit) === null || _b === void 0 ? void 0 : _b.collider.parent();
21
+ return (_jsx(CuboidCollider, { ref: ref, args: [airplaneSizeX / 2, airplaneSizeY / 2, airplaneSizeZ / 2], position: [0, airplaneSizeY / 2, 0] }));
22
+ });
@@ -0,0 +1,5 @@
1
+ import { controllerInnerType, refsType } from "../../../controller/type";
2
+ export declare function AirplaneRef({ props, refs, }: {
3
+ props: controllerInnerType;
4
+ refs: refsType;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useContext } from "react";
3
+ import { GaesupWorldContext } from "../../../world/context";
4
+ import { InnerGroupRef } from "../common/InnerGroupRef";
5
+ import { WrapperRef } from "../common/WrapperRef";
6
+ import { AirplaneCollider } from "./collider";
7
+ export function AirplaneRef(_a) {
8
+ var props = _a.props, refs = _a.refs;
9
+ var _b = useContext(GaesupWorldContext), characterGltf = _b.characterGltf, airplaneGltf = _b.airplaneGltf;
10
+ return (_jsxs(WrapperRef, { props: props, refs: refs, gltf: airplaneGltf, children: [props.isRider && (_jsx(InnerGroupRef, { props: props, gltf: characterGltf, ref: refs.characterInnerRef })), _jsx(AirplaneCollider, { props: props })] }));
11
+ }
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { Collider } from "@dimforge/rapier3d-compat";
3
+ import { controllerInnerType } from "../../../controller/type";
4
+ export declare const CharacterCapsuleCollider: import("react").ForwardRefExoticComponent<{
5
+ props: controllerInnerType;
6
+ } & import("react").RefAttributes<Collider>>;
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { CapsuleCollider, useRapier } from "@react-three/rapier";
3
+ import { forwardRef, useContext } from "react";
4
+ import { getRayHit, useForwardRef } from "../../../utils";
5
+ import { GaesupWorldContext } from "../../../world/context";
6
+ export var CharacterCapsuleCollider = forwardRef(function (_a, ref) {
7
+ var _b;
8
+ var props = _a.props;
9
+ var collider = useContext(GaesupWorldContext).characterCollider;
10
+ var colliderRef = useForwardRef(ref);
11
+ var rapier = useRapier().rapier;
12
+ var groundRay = props.groundRay, slopeRay = props.slopeRay;
13
+ groundRay.length = collider.radius + 2;
14
+ groundRay.rayCast = new rapier.Ray(groundRay.origin, groundRay.dir);
15
+ groundRay.hit = getRayHit({
16
+ ray: groundRay,
17
+ ref: colliderRef,
18
+ });
19
+ groundRay.parent = (_b = groundRay.hit) === null || _b === void 0 ? void 0 : _b.collider.parent();
20
+ slopeRay.rayCast = new rapier.Ray(slopeRay.origin, slopeRay.dir);
21
+ slopeRay.length = collider.radius + 3;
22
+ slopeRay.rayCast = new rapier.Ray(slopeRay.origin, slopeRay.dir);
23
+ return (_jsx(_Fragment, { children: _jsx(CapsuleCollider, { ref: ref, args: [collider.height, collider.radius], position: [0, collider.height + collider.radius, 0] }) }));
24
+ });
@@ -0,0 +1,5 @@
1
+ import { controllerInnerType, refsType } from "../../../controller/type";
2
+ export declare function CharacterRef({ props, refs, }: {
3
+ props: controllerInnerType;
4
+ refs: refsType;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useContext } from "react";
3
+ import initCallback from "../../../controller/initialize/callback";
4
+ import { GaesupWorldContext } from "../../../world/context";
5
+ import { CharacterCapsuleCollider } from "./collider";
6
+ import playCharacterActions from "../../../animation/actions";
7
+ import { WrapperRef } from "../common/WrapperRef";
8
+ export function CharacterRef(_a) {
9
+ var props = _a.props, refs = _a.refs;
10
+ initCallback(props);
11
+ var _b = useContext(GaesupWorldContext), characterGltf = _b.characterGltf, characterCollider = _b.characterCollider, vehicleCollider = _b.vehicleCollider;
12
+ var ref = playCharacterActions({
13
+ groundRay: props.groundRay,
14
+ }).ref;
15
+ return (_jsx(WrapperRef, { props: props, refs: refs, gltf: characterGltf, animationRef: ref, children: _jsx(CharacterCapsuleCollider, { props: props, ref: refs.capsuleColliderRef }) }));
16
+ }
@@ -0,0 +1,10 @@
1
+ import { Ref } from "react";
2
+ import { controllerInnerType } from "../../../controller/type";
3
+ import * as THREE from "three";
4
+ import { GLTFResult } from "../../type";
5
+ export type InnerGroupRefType = {
6
+ props: controllerInnerType;
7
+ animationRef?: Ref<THREE.Object3D<THREE.Object3DEventMap>>;
8
+ gltf: GLTFResult;
9
+ };
10
+ export declare const InnerGroupRef: import("react").ForwardRefExoticComponent<InnerGroupRefType & import("react").RefAttributes<THREE.Group<THREE.Object3DEventMap>>>;
@@ -0,0 +1,32 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { forwardRef, useMemo } from "react";
14
+ import { useGraph } from "@react-three/fiber";
15
+ import * as THREE from "three";
16
+ import { SkeletonUtils } from "three-stdlib";
17
+ export var InnerGroupRef = forwardRef(function (_a, ref) {
18
+ var props = _a.props, animationRef = _a.animationRef, gltf = _a.gltf;
19
+ var scene = gltf.scene;
20
+ var clone = useMemo(function () { return SkeletonUtils.clone(scene); }, [scene]);
21
+ var nodes = useGraph(clone).nodes;
22
+ var objectNode = Object.values(nodes).find(function (node) { return node.type === "Object3D"; });
23
+ return (_jsxs("group", __assign({ receiveShadow: true, castShadow: true }, props.groupProps, { ref: ref, children: [objectNode && animationRef && (_jsx("primitive", { object: objectNode, visible: false, receiveShadow: true, castShadow: true, ref: animationRef })), Object.keys(nodes).map(function (name, key) {
24
+ var node = nodes[name];
25
+ if (node instanceof THREE.SkinnedMesh) {
26
+ return (_jsx("skinnedMesh", { castShadow: true, receiveShadow: true, material: node.material, geometry: node.geometry, skeleton: node.skeleton }, key));
27
+ }
28
+ else if (node instanceof THREE.Mesh) {
29
+ return (_jsx("mesh", { castShadow: true, receiveShadow: true, material: node.material, geometry: node.geometry }, key));
30
+ }
31
+ })] })));
32
+ });
@@ -0,0 +1,6 @@
1
+ import { ReactNode } from "react";
2
+ import { controllerType } from "../../../controller/type";
3
+ export declare const OuterGroupRef: import("react").ForwardRefExoticComponent<{
4
+ props: controllerType;
5
+ children: ReactNode;
6
+ } & import("react").RefAttributes<import("three").Group<import("three").Object3DEventMap>>>;
@@ -0,0 +1,17 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { forwardRef } from "react";
14
+ export var OuterGroupRef = forwardRef(function (_a, ref) {
15
+ var props = _a.props, children = _a.children;
16
+ return (_jsx("group", __assign({ ref: ref, userData: { intangible: true } }, props.vehicle, { children: children })));
17
+ });
@@ -0,0 +1,7 @@
1
+ import { RapierRigidBody } from "@react-three/rapier";
2
+ import { ReactNode } from "react";
3
+ import { controllerInnerType } from "../../../controller/type";
4
+ export declare const RigidBodyRef: import("react").ForwardRefExoticComponent<{
5
+ props: controllerInnerType;
6
+ children: ReactNode;
7
+ } & import("react").RefAttributes<RapierRigidBody>>;
@@ -0,0 +1,18 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { RigidBody } from "@react-three/rapier";
14
+ import { forwardRef } from "react";
15
+ export var RigidBodyRef = forwardRef(function (_a, ref) {
16
+ var props = _a.props, children = _a.children;
17
+ return (_jsx(RigidBody, __assign({ colliders: false, ref: ref }, props.rigidBodyProps, { children: children })));
18
+ });
@@ -0,0 +1,12 @@
1
+ import { ReactNode, Ref } from "react";
2
+ import * as THREE from "three";
3
+ import { controllerInnerType, refsType } from "../../../controller/type";
4
+ import { GLTFResult } from "../../type";
5
+ export declare function WrapperRef({ children, outerChildren, props, refs, gltf, animationRef, }: {
6
+ children: ReactNode;
7
+ outerChildren?: ReactNode;
8
+ props: controllerInnerType;
9
+ refs: refsType;
10
+ gltf: GLTFResult;
11
+ animationRef?: Ref<THREE.Object3D<THREE.Object3DEventMap>>;
12
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { InnerGroupRef } from "../common/InnerGroupRef";
3
+ import { OuterGroupRef } from "../common/OuterGroupRef";
4
+ import { SlopeRayRef } from "../common/slopeRayRef";
5
+ import { RigidBodyRef } from "./RigidbodyRef";
6
+ export function WrapperRef(_a) {
7
+ var children = _a.children, outerChildren = _a.outerChildren, props = _a.props, refs = _a.refs, gltf = _a.gltf, animationRef = _a.animationRef;
8
+ return (_jsxs(OuterGroupRef, { ref: refs.outerGroupRef, props: props, children: [_jsxs(RigidBodyRef, { ref: refs.rigidBodyRef, props: props, children: [_jsx(SlopeRayRef, { slopeRay: props.slopeRay, groundRay: props.groundRay, ref: refs.slopeRayOriginRef }), children, props.children, _jsx(InnerGroupRef, { props: props, gltf: gltf, ref: refs.innerGroupRef, animationRef: animationRef })] }), outerChildren] }));
9
+ }
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { groundRayType, slopeRayType } from "../../../controller/type";
3
+ export declare const SlopeRayRef: import("react").ForwardRefExoticComponent<{
4
+ groundRay: groundRayType;
5
+ slopeRay: slopeRayType;
6
+ } & import("react").RefAttributes<import("three").Mesh<import("three").BufferGeometry<import("three").NormalBufferAttributes>, import("three").Material | import("three").Material[], import("three").Object3DEventMap>>>;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ export var SlopeRayRef = forwardRef(function (_a, ref) {
4
+ var groundRay = _a.groundRay, slopeRay = _a.slopeRay;
5
+ return (_jsx("mesh", { position: [
6
+ groundRay.offset.x,
7
+ groundRay.offset.y,
8
+ groundRay.offset.z + slopeRay.offset.z,
9
+ ], ref: ref, visible: false, children: _jsx("boxGeometry", { args: [0.15, 0.15, 0.15] }) }));
10
+ });
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { Collider } from "@dimforge/rapier3d-compat";
3
+ export declare const VehicleCollider: import("react").ForwardRefExoticComponent<import("react").RefAttributes<Collider>>;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { CuboidCollider } from "@react-three/rapier";
3
+ import { forwardRef, useContext } from "react";
4
+ import { GaesupWorldContext } from "../../../world/context";
5
+ export var VehicleCollider = forwardRef(function (_, ref) {
6
+ var _a = useContext(GaesupWorldContext), collider = _a.vehicleCollider, url = _a.url;
7
+ var vehicleSizeX = collider.vehicleSizeX, vehicleSizeY = collider.vehicleSizeY, vehicleSizeZ = collider.vehicleSizeZ;
8
+ return (_jsx(CuboidCollider, { ref: ref, args: [vehicleSizeX / 2, vehicleSizeY / 2, vehicleSizeZ / 2], position: [0, vehicleSizeY + url.wheelUrl ? collider.wheelSizeY : 0, 0] }));
9
+ });
@@ -0,0 +1,5 @@
1
+ import { controllerInnerType, refsType } from "../../../controller/type";
2
+ export declare function VehicleRef({ props, refs, }: {
3
+ props: controllerInnerType;
4
+ refs: refsType;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useContext } from "react";
3
+ import { GaesupWorldContext } from "../../../world/context";
4
+ import { InnerGroupRef } from "../common/InnerGroupRef";
5
+ import { WrapperRef } from "../common/WrapperRef";
6
+ import { VehicleCollider } from "./collider";
7
+ import { Wheels } from "./wheels";
8
+ export function VehicleRef(_a) {
9
+ var props = _a.props, refs = _a.refs;
10
+ var _b = useContext(GaesupWorldContext), url = _b.url, characterGltf = _b.characterGltf, vehicleGltf = _b.vehicleGltf;
11
+ return (_jsxs(WrapperRef, { props: props, refs: refs, gltf: vehicleGltf, outerChildren: url.wheelUrl ? _jsx(Wheels, { props: props }) : _jsx(_Fragment, {}), children: [props.isRider && (_jsx(InnerGroupRef, { props: props, gltf: characterGltf, ref: refs.characterInnerRef })), _jsx(VehicleCollider, {})] }));
12
+ }