gaesup-world 0.1.4 → 0.2.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 (139) hide show
  1. package/dist/gaesup/animation/actions.d.ts +29 -13
  2. package/dist/gaesup/animation/actions.js +33 -60
  3. package/dist/gaesup/camera/index.js +1 -1
  4. package/dist/gaesup/component/active/airplane/index.d.ts +9 -3
  5. package/dist/gaesup/component/active/airplane/index.js +3 -7
  6. package/dist/gaesup/component/active/character/index.d.ts +3 -1
  7. package/dist/gaesup/component/active/character/index.js +29 -11
  8. package/dist/gaesup/component/active/vehicle/index.d.ts +10 -3
  9. package/dist/gaesup/component/active/vehicle/index.js +29 -9
  10. package/dist/gaesup/component/index.d.ts +3 -1
  11. package/dist/gaesup/component/index.js +9 -3
  12. package/dist/gaesup/component/inner/airplane/index.d.ts +2 -0
  13. package/dist/gaesup/component/inner/airplane/index.js +16 -0
  14. package/dist/gaesup/component/inner/character/index.d.ts +25 -0
  15. package/dist/gaesup/component/inner/character/index.js +28 -0
  16. package/dist/gaesup/component/{passive → inner}/common/InnerGroupRef.d.ts +2 -0
  17. package/dist/gaesup/component/{passive → inner}/common/InnerGroupRef.js +12 -10
  18. package/dist/gaesup/component/{passive → inner}/common/RigidbodyRef.d.ts +4 -0
  19. package/dist/gaesup/component/inner/common/RigidbodyRef.js +7 -0
  20. package/dist/gaesup/component/inner/common/setGroundRay.d.ts +9 -0
  21. package/dist/gaesup/component/inner/common/setGroundRay.js +14 -0
  22. package/dist/gaesup/component/inner/common/type.d.ts +20 -0
  23. package/dist/gaesup/component/inner/rider/index.d.ts +11 -0
  24. package/dist/gaesup/component/inner/rider/index.js +31 -0
  25. package/dist/gaesup/component/inner/vehicle/collider.d.ts +10 -0
  26. package/dist/gaesup/component/inner/vehicle/collider.js +19 -0
  27. package/dist/gaesup/component/inner/vehicle/index.d.ts +2 -0
  28. package/dist/gaesup/component/inner/vehicle/index.js +17 -0
  29. package/dist/gaesup/component/inner/vehicle/wheels.d.ts +7 -0
  30. package/dist/gaesup/component/inner/vehicle/wheels.js +64 -0
  31. package/dist/gaesup/component/passive/airplane/index.d.ts +12 -1
  32. package/dist/gaesup/component/passive/airplane/index.js +6 -9
  33. package/dist/gaesup/component/passive/character/index.d.ts +9 -1
  34. package/dist/gaesup/component/passive/character/index.js +16 -9
  35. package/dist/gaesup/component/passive/type.d.ts +1 -11
  36. package/dist/gaesup/component/passive/vehicle/index.d.ts +12 -1
  37. package/dist/gaesup/component/passive/vehicle/index.js +6 -25
  38. package/dist/gaesup/controller/context/index.d.ts +7 -3
  39. package/dist/gaesup/controller/context/index.js +7 -3
  40. package/dist/gaesup/controller/context/reducer.d.ts +1 -1
  41. package/dist/gaesup/controller/index.js +5 -8
  42. package/dist/gaesup/controller/initialize/callback/index.d.ts +1 -1
  43. package/dist/gaesup/controller/initialize/callback/index.js +61 -54
  44. package/dist/gaesup/controller/initialize/index.d.ts +1 -2
  45. package/dist/gaesup/controller/initialize/index.js +1 -14
  46. package/dist/gaesup/controller/type.d.ts +3 -6
  47. package/dist/gaesup/gaesupProps/index.js +1 -1
  48. package/dist/gaesup/hooks/useGaesupAnimation/index.d.ts +3 -1
  49. package/dist/gaesup/hooks/useGaesupAnimation/index.js +17 -16
  50. package/dist/gaesup/hooks/useGaesupController/index.d.ts +2 -5
  51. package/dist/gaesup/hooks/useGaesupController/index.js +4 -5
  52. package/dist/gaesup/hooks/useGaesupGltf/index.d.ts +25 -0
  53. package/dist/gaesup/hooks/useGaesupGltf/index.js +73 -0
  54. package/dist/gaesup/hooks/useRideable/index.js +36 -35
  55. package/dist/gaesup/physics/airplane/direction.d.ts +1 -1
  56. package/dist/gaesup/physics/airplane/direction.js +3 -1
  57. package/dist/gaesup/physics/airplane/gravity.js +1 -1
  58. package/dist/gaesup/physics/airplane/landing.js +1 -1
  59. package/dist/gaesup/physics/check/ground.js +3 -3
  60. package/dist/gaesup/physics/check/index.js +0 -2
  61. package/dist/gaesup/physics/check/riding.js +3 -3
  62. package/dist/gaesup/physics/index.js +8 -6
  63. package/dist/gaesup/physics/type.d.ts +4 -1
  64. package/dist/gaesup/physics/vehicle/impulse.js +0 -3
  65. package/dist/gaesup/physics/vehicle/innerCalc.js +1 -1
  66. package/dist/gaesup/physics/vehicle/landing.js +1 -1
  67. package/dist/gaesup/tools/keyBoardToolTip/index.js +3 -3
  68. package/dist/gaesup/tools/rideable/index.js +5 -6
  69. package/dist/gaesup/tools/zoomButton/index.js +5 -3
  70. package/dist/gaesup/world/context/index.js +27 -62
  71. package/dist/gaesup/world/context/reducer.d.ts +7 -12
  72. package/dist/gaesup/world/context/type.d.ts +36 -49
  73. package/dist/gaesup/world/debug/index.d.ts +6 -2
  74. package/dist/gaesup/world/initalize/index.d.ts +7 -12
  75. package/dist/gaesup/world/initalize/index.js +8 -15
  76. package/dist/gaesup/world/type.d.ts +3 -8
  77. package/dist/index.d.ts +0 -1
  78. package/dist/index.js +0 -1
  79. package/index.ts +24 -2
  80. package/package.json +1 -1
  81. package/dist/gaesup/animation/index.d.ts +0 -1
  82. package/dist/gaesup/animation/index.js +0 -1
  83. package/dist/gaesup/animation/passiveActions.d.ts +0 -9
  84. package/dist/gaesup/animation/passiveActions.js +0 -16
  85. package/dist/gaesup/component/active/airplane/collider.d.ts +0 -6
  86. package/dist/gaesup/component/active/airplane/collider.js +0 -22
  87. package/dist/gaesup/component/active/character/collider.d.ts +0 -6
  88. package/dist/gaesup/component/active/character/collider.js +0 -24
  89. package/dist/gaesup/component/active/common/InnerGroupRef.d.ts +0 -10
  90. package/dist/gaesup/component/active/common/InnerGroupRef.js +0 -35
  91. package/dist/gaesup/component/active/common/OuterGroupRef.d.ts +0 -6
  92. package/dist/gaesup/component/active/common/OuterGroupRef.js +0 -17
  93. package/dist/gaesup/component/active/common/RiderGroupRef.d.ts +0 -7
  94. package/dist/gaesup/component/active/common/RiderGroupRef.js +0 -32
  95. package/dist/gaesup/component/active/common/RigidbodyRef.d.ts +0 -11
  96. package/dist/gaesup/component/active/common/RigidbodyRef.js +0 -22
  97. package/dist/gaesup/component/active/common/WrapperRef.d.ts +0 -13
  98. package/dist/gaesup/component/active/common/WrapperRef.js +0 -9
  99. package/dist/gaesup/component/active/common/slopeRayRef.d.ts +0 -6
  100. package/dist/gaesup/component/active/common/slopeRayRef.js +0 -10
  101. package/dist/gaesup/component/active/vehicle/collider.d.ts +0 -3
  102. package/dist/gaesup/component/active/vehicle/collider.js +0 -9
  103. package/dist/gaesup/component/active/vehicle/wheel.d.ts +0 -12
  104. package/dist/gaesup/component/active/vehicle/wheel.js +0 -13
  105. package/dist/gaesup/component/active/vehicle/wheels.d.ts +0 -7
  106. package/dist/gaesup/component/active/vehicle/wheels.js +0 -22
  107. package/dist/gaesup/component/passive/airplane/collider.d.ts +0 -5
  108. package/dist/gaesup/component/passive/airplane/collider.js +0 -7
  109. package/dist/gaesup/component/passive/airplane/type.d.ts +0 -12
  110. package/dist/gaesup/component/passive/character/collider.d.ts +0 -6
  111. package/dist/gaesup/component/passive/character/collider.js +0 -7
  112. package/dist/gaesup/component/passive/character/type.d.ts +0 -27
  113. package/dist/gaesup/component/passive/character/type.js +0 -1
  114. package/dist/gaesup/component/passive/common/RigidbodyRef.js +0 -10
  115. package/dist/gaesup/component/passive/vehicle/type.d.ts +0 -21
  116. package/dist/gaesup/component/passive/vehicle/type.js +0 -1
  117. package/dist/gaesup/component/passive/vehicle/wheel.d.ts +0 -15
  118. package/dist/gaesup/component/passive/vehicle/wheel.js +0 -16
  119. package/dist/gaesup/component/passive/vehicle/wheels.d.ts +0 -11
  120. package/dist/gaesup/component/passive/vehicle/wheels.js +0 -25
  121. package/dist/gaesup/physics/check/slope.d.ts +0 -2
  122. package/dist/gaesup/physics/check/slope.js +0 -30
  123. package/dist/gaesup/utils/gltf.d.ts +0 -7
  124. package/dist/gaesup/utils/gltf.js +0 -10
  125. package/dist/gaesup/world/initalize/collider/airplane.d.ts +0 -2
  126. package/dist/gaesup/world/initalize/collider/airplane.js +0 -25
  127. package/dist/gaesup/world/initalize/collider/character.d.ts +0 -2
  128. package/dist/gaesup/world/initalize/collider/character.js +0 -27
  129. package/dist/gaesup/world/initalize/collider/gltf.d.ts +0 -14
  130. package/dist/gaesup/world/initalize/collider/gltf.js +0 -54
  131. package/dist/gaesup/world/initalize/collider/index.d.ts +0 -2
  132. package/dist/gaesup/world/initalize/collider/index.js +0 -17
  133. package/dist/gaesup/world/initalize/collider/vehicle.d.ts +0 -2
  134. package/dist/gaesup/world/initalize/collider/vehicle.js +0 -55
  135. package/dist/gaesup/world/initalize/type.d.ts +0 -13
  136. package/dist/gaesup/world/initalize/type.js +0 -1
  137. /package/dist/gaesup/component/{passive → inner}/common/OuterGroupRef.d.ts +0 -0
  138. /package/dist/gaesup/component/{passive → inner}/common/OuterGroupRef.js +0 -0
  139. /package/dist/gaesup/component/{passive/airplane → inner/common}/type.js +0 -0
@@ -1,8 +1,24 @@
1
1
  import { Ref } from "react";
2
- import { Object3D, Object3DEventMap } from "three";
2
+ import { AnimationAction, AnimationClip, AnimationMixer, Object3D, Object3DEventMap } from "three";
3
3
  import { groundRayType } from "../controller/type";
4
+ export type Api<T extends AnimationClip> = {
5
+ ref: React.MutableRefObject<Object3D | undefined | null>;
6
+ clips: AnimationClip[];
7
+ mixer: AnimationMixer;
8
+ names: T["name"][];
9
+ actions: {
10
+ [key in T["name"]]: AnimationAction | null;
11
+ };
12
+ };
4
13
  export type playActionsType = {
14
+ type: "character" | "vehicle" | "airplane";
15
+ animationResult: Api<AnimationClip>;
16
+ currentAnimation?: string;
17
+ };
18
+ export type subscribeActionsType = {
19
+ type: "character" | "vehicle" | "airplane";
5
20
  groundRay: groundRayType;
21
+ animations: AnimationClip[];
6
22
  };
7
23
  export type actionsType = {
8
24
  [x: string]: THREE.AnimationAction | null;
@@ -11,18 +27,18 @@ export type playResultType = {
11
27
  actions: actionsType;
12
28
  ref: Ref<Object3D<Object3DEventMap>>;
13
29
  };
14
- export declare function readyAnimation(): {
15
- resultRef: {
16
- character: playResultType;
17
- vehicle: playResultType;
18
- airplane: playResultType;
30
+ export declare function subscribeActions({ type, groundRay, animations, }: subscribeActionsType): {
31
+ animationResult: {
32
+ ref: import("react").MutableRefObject<Object3D<Object3DEventMap>>;
33
+ clips: AnimationClip[];
34
+ mixer: AnimationMixer;
35
+ names: string[];
36
+ actions: {
37
+ [x: string]: AnimationAction;
38
+ };
19
39
  };
20
40
  };
21
- export default function playCharacterActions({ groundRay }: playActionsType): {
22
- ref: Ref<Object3D<Object3DEventMap>>;
23
- resultRef: {
24
- character: playResultType;
25
- vehicle: playResultType;
26
- airplane: playResultType;
27
- };
41
+ export default function playActions({ type, animationResult, currentAnimation, }: playActionsType): {
42
+ animationRef: import("react").MutableRefObject<Object3D<Object3DEventMap>>;
43
+ currentAnimation: string;
28
44
  };
@@ -9,60 +9,16 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { useAnimations, useKeyboardControls } from "@react-three/drei";
12
+ import { useAnimations } from "@react-three/drei";
13
13
  import { useFrame } from "@react-three/fiber";
14
14
  import { useContext, useEffect } from "react";
15
15
  import { useGaesupAnimation } from "../hooks/useGaesupAnimation";
16
16
  import { GaesupWorldContext, GaesupWorldDispatchContext, } from "../world/context";
17
- // 캐릭터 등록, 애니메이션 이름 설정, 애니메이션 실행
18
- export function readyAnimation() {
19
- var _a = useContext(GaesupWorldContext), characterGltf = _a.characterGltf, vehicleGltf = _a.vehicleGltf, airplaneGltf = _a.airplaneGltf;
20
- var resultRef = {
21
- character: null,
22
- vehicle: null,
23
- airplane: null,
24
- };
25
- if (characterGltf && characterGltf.animations)
26
- resultRef.character = useAnimations(characterGltf.animations);
27
- if (vehicleGltf && vehicleGltf.animations)
28
- resultRef.vehicle = useAnimations(vehicleGltf.animations);
29
- if (airplaneGltf && airplaneGltf.animations)
30
- resultRef.airplane = useAnimations(airplaneGltf.animations);
31
- return {
32
- resultRef: resultRef,
33
- };
34
- }
35
- export default function playCharacterActions(_a) {
36
- var groundRay = _a.groundRay;
37
- var _b = useContext(GaesupWorldContext), states = _b.states, activeState = _b.activeState, animations = _b.animations, mode = _b.mode, characterGltf = _b.characterGltf, vehicleGltf = _b.vehicleGltf, airplaneGltf = _b.airplaneGltf;
38
- var dispatch = useContext(GaesupWorldDispatchContext);
39
- var control = useKeyboardControls()[1]();
40
- var _c = useGaesupAnimation(), subscribeAll = _c.subscribeAll, notify = _c.notify, store = _c.store;
41
- var resultRef = {
42
- character: null,
43
- vehicle: null,
44
- airplane: null,
45
- };
46
- if (characterGltf && characterGltf.animations)
47
- resultRef.character = useAnimations(characterGltf.animations);
48
- if (vehicleGltf && vehicleGltf.animations)
49
- resultRef.vehicle = useAnimations(vehicleGltf.animations);
50
- if (airplaneGltf && airplaneGltf.animations)
51
- resultRef.airplane = useAnimations(airplaneGltf.animations);
52
- var play = function (tag) {
53
- animations.current = tag;
54
- var currentAnimation = store[tag];
55
- if (currentAnimation === null || currentAnimation === void 0 ? void 0 : currentAnimation.action) {
56
- currentAnimation.action();
57
- }
58
- dispatch({
59
- type: "update",
60
- payload: {
61
- animations: __assign({}, animations),
62
- },
63
- });
64
- };
65
- var _d = resultRef.character, actions = _d.actions, ref = _d.ref;
17
+ export function subscribeActions(_a) {
18
+ var type = _a.type, groundRay = _a.groundRay, animations = _a.animations;
19
+ var _b = useContext(GaesupWorldContext), states = _b.states, activeState = _b.activeState;
20
+ var subscribeAll = useGaesupAnimation({ type: type }).subscribeAll;
21
+ var animationResult = useAnimations(animations);
66
22
  // 초기 기본 애니메이션 등록
67
23
  useEffect(function () {
68
24
  subscribeAll([
@@ -103,28 +59,45 @@ export default function playCharacterActions(_a) {
103
59
  },
104
60
  ]);
105
61
  }, []);
106
- useEffect(function () {
107
- animations.keyControl = control;
62
+ return {
63
+ animationResult: animationResult,
64
+ };
65
+ }
66
+ export default function playActions(_a) {
67
+ var _b;
68
+ var type = _a.type, animationResult = _a.animationResult, currentAnimation = _a.currentAnimation;
69
+ var _c = useContext(GaesupWorldContext), mode = _c.mode, animationState = _c.animationState;
70
+ var dispatch = useContext(GaesupWorldDispatchContext);
71
+ var _d = useGaesupAnimation({ type: type }), notify = _d.notify, store = _d.store;
72
+ var actions = animationResult.actions, ref = animationResult.ref;
73
+ var play = function (tag) {
74
+ animationState[type].current = tag;
75
+ var currentAnimation = store[tag];
76
+ if (currentAnimation === null || currentAnimation === void 0 ? void 0 : currentAnimation.action) {
77
+ currentAnimation.action();
78
+ }
108
79
  dispatch({
109
80
  type: "update",
110
81
  payload: {
111
- animations: __assign({}, animations),
82
+ animationState: __assign({}, animationState),
112
83
  },
113
84
  });
114
- }, [control]);
85
+ };
115
86
  useEffect(function () {
116
87
  var _a;
117
- var action = (_a = actions[animations.current]) === null || _a === void 0 ? void 0 : _a.reset().fadeIn(0.2).play();
88
+ var action = (_a = actions[currentAnimation || animationState[type].current]) === null || _a === void 0 ? void 0 : _a.reset().fadeIn(0.2).play();
118
89
  return function () {
119
90
  action === null || action === void 0 ? void 0 : action.fadeOut(0.2);
120
91
  };
121
- }, [animations.current, mode.type]);
92
+ }, [currentAnimation, mode.type]);
122
93
  useFrame(function () {
123
- var tag = notify();
124
- play(tag);
94
+ if (!currentAnimation) {
95
+ var tag = notify();
96
+ play(tag);
97
+ }
125
98
  });
126
99
  return {
127
- ref: ref,
128
- resultRef: resultRef,
100
+ animationRef: ref,
101
+ currentAnimation: (_b = animationState === null || animationState === void 0 ? void 0 : animationState[type]) === null || _b === void 0 ? void 0 : _b.current,
129
102
  };
130
103
  }
@@ -96,7 +96,7 @@ export default function Camera(_a) {
96
96
  return;
97
97
  cameraProp.delta = delta;
98
98
  cameraProp.state = state;
99
- if (!worldContext.cameraBlock) {
99
+ if (!worldContext.block.camera) {
100
100
  if (mode.control === "orbit") {
101
101
  orbit(cameraProp);
102
102
  }
@@ -1,5 +1,11 @@
1
- import { controllerInnerType, refsType } from "../../../controller/type";
2
- export declare function AirplaneRef({ props, refs, }: {
3
- props: controllerInnerType;
1
+ import { ReactNode } from "react";
2
+ import { refsType } from "../../../controller/type";
3
+ import { urlsType } from "../../../world/context/type";
4
+ export declare function AirplaneRef({ children, enableRiding, isRiderOn, offset, refs, urls, }: {
5
+ children: ReactNode;
6
+ enableRiding?: boolean;
7
+ isRiderOn?: boolean;
8
+ offset?: THREE.Vector3;
4
9
  refs: refsType;
10
+ urls: urlsType;
5
11
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,10 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useContext } from "react";
3
- import { GaesupWorldContext } from "../../../world/context";
4
- import { WrapperRef } from "../common/WrapperRef";
5
- import { AirplaneCollider } from "./collider";
2
+ import { AirplaneInnerRef } from "../../inner/airplane";
6
3
  export function AirplaneRef(_a) {
7
- var props = _a.props, refs = _a.refs;
8
- var airplaneGltf = useContext(GaesupWorldContext).airplaneGltf;
9
- return (_jsx(WrapperRef, { props: props, refs: refs, gltf: airplaneGltf, children: _jsx(AirplaneCollider, { props: props }) }));
4
+ var children = _a.children, enableRiding = _a.enableRiding, isRiderOn = _a.isRiderOn, offset = _a.offset, refs = _a.refs, urls = _a.urls;
5
+ return (_jsx(AirplaneInnerRef, { refs: refs, urls: urls, isRiderOn: isRiderOn, enableRiding: enableRiding, offset: offset, children: children }));
10
6
  }
@@ -1,5 +1,7 @@
1
1
  import { controllerInnerType, refsType } from "../../../controller/type";
2
- export declare function CharacterRef({ props, refs, }: {
2
+ import { urlsType } from "../../../world/context/type";
3
+ export declare function CharacterRef({ props, refs, urls, }: {
3
4
  props: controllerInnerType;
4
5
  refs: refsType;
6
+ urls: urlsType;
5
7
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,16 +1,34 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useContext } from "react";
2
+ import { vec3 } from "@react-three/rapier";
3
+ import playActions, { subscribeActions } from "../../../animation/actions";
3
4
  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";
5
+ import { useGltfAndSize } from "../../../hooks/useGaesupGltf";
6
+ import { CharacterInnerRef, calcCharacterColliderProps, } from "../../inner/character";
7
+ import { setGroundRay } from "../../inner/common/setGroundRay";
8
8
  export function CharacterRef(_a) {
9
- var props = _a.props, refs = _a.refs;
10
- initCallback(props);
11
- var characterGltf = useContext(GaesupWorldContext).characterGltf;
12
- var ref = playCharacterActions({
9
+ var props = _a.props, refs = _a.refs, urls = _a.urls;
10
+ initCallback(props, "character");
11
+ var colliderRef = refs.colliderRef;
12
+ var _b = useGltfAndSize({ url: urls.characterUrl }), size = _b.size, gltf = _b.gltf;
13
+ var collider = calcCharacterColliderProps(size);
14
+ props.groundRay.offset = vec3({
15
+ x: 0,
16
+ y: (collider === null || collider === void 0 ? void 0 : collider.halfHeight) ? -(collider === null || collider === void 0 ? void 0 : collider.halfHeight) : -1,
17
+ z: 0,
18
+ });
19
+ setGroundRay({
13
20
  groundRay: props.groundRay,
14
- }).ref;
15
- return (_jsx(WrapperRef, { props: props, refs: refs, gltf: characterGltf, animationRef: ref, name: "character", children: _jsx(CharacterCapsuleCollider, { props: props, ref: refs.capsuleColliderRef }) }));
21
+ length: (collider === null || collider === void 0 ? void 0 : collider.radius) || 0 + 2,
22
+ colliderRef: colliderRef,
23
+ });
24
+ var animationResult = subscribeActions({
25
+ type: "character",
26
+ groundRay: props.groundRay,
27
+ animations: gltf.animations,
28
+ }).animationResult;
29
+ var _c = playActions({
30
+ type: "character",
31
+ animationResult: animationResult,
32
+ }), animationRef = _c.animationRef, currentAnimation = _c.currentAnimation;
33
+ return (_jsx(CharacterInnerRef, { animationRef: animationRef, refs: refs, urls: urls, currentAnimation: currentAnimation, children: props.children }));
16
34
  }
@@ -1,5 +1,12 @@
1
- import { controllerInnerType, refsType } from "../../../controller/type";
2
- export declare function VehicleRef({ props, refs, }: {
3
- props: controllerInnerType;
1
+ import { ReactNode } from "react";
2
+ import { groundRayType, refsType } from "../../../controller/type";
3
+ import { urlsType } from "../../../world/context/type";
4
+ export declare function VehicleRef({ children, groundRay, enableRiding, isRiderOn, offset, refs, urls, }: {
5
+ children: ReactNode;
6
+ groundRay: groundRayType;
7
+ enableRiding?: boolean;
8
+ isRiderOn?: boolean;
9
+ offset?: THREE.Vector3;
4
10
  refs: refsType;
11
+ urls: urlsType;
5
12
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,11 +1,31 @@
1
- import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useContext } from "react";
3
- import { GaesupWorldContext } from "../../../world/context";
4
- import { WrapperRef } from "../common/WrapperRef";
5
- import { VehicleCollider } from "./collider";
6
- import { Wheels } from "./wheels";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { vec3 } from "@react-three/rapier";
3
+ import playActions, { subscribeActions } from "../../../animation/actions";
4
+ import { useGltfAndSize } from "../../../hooks/useGaesupGltf";
5
+ import { setGroundRay } from "../../inner/common/setGroundRay";
6
+ import { VehicleInnerRef } from "../../inner/vehicle";
7
7
  export function VehicleRef(_a) {
8
- var props = _a.props, refs = _a.refs;
9
- var _b = useContext(GaesupWorldContext), url = _b.url, vehicleGltf = _b.vehicleGltf;
10
- return (_jsx(WrapperRef, { props: props, refs: refs, gltf: vehicleGltf, outerChildren: url.wheelUrl ? _jsx(Wheels, { props: props }) : _jsx(_Fragment, {}), children: _jsx(VehicleCollider, {}) }));
8
+ var children = _a.children, groundRay = _a.groundRay, enableRiding = _a.enableRiding, isRiderOn = _a.isRiderOn, offset = _a.offset, refs = _a.refs, urls = _a.urls;
9
+ var colliderRef = refs.colliderRef;
10
+ var _b = useGltfAndSize({ url: urls.vehicleUrl }), size = _b.size, gltf = _b.gltf;
11
+ groundRay.offset = vec3({
12
+ x: 0,
13
+ y: size.y * 3,
14
+ z: 0,
15
+ });
16
+ setGroundRay({
17
+ groundRay: groundRay,
18
+ length: size.y * 3,
19
+ colliderRef: colliderRef,
20
+ });
21
+ var animationResult = subscribeActions({
22
+ type: "vehicle",
23
+ groundRay: groundRay,
24
+ animations: gltf.animations,
25
+ }).animationResult;
26
+ var _c = playActions({
27
+ type: "vehicle",
28
+ animationResult: animationResult,
29
+ }), animationRef = _c.animationRef, currentAnimation = _c.currentAnimation;
30
+ return (_jsx(VehicleInnerRef, { refs: refs, urls: urls, isRiderOn: isRiderOn, enableRiding: enableRiding, offset: offset, currentAnimation: currentAnimation, children: children }));
11
31
  }
@@ -1,5 +1,7 @@
1
1
  import { controllerInnerType, refsType } from "../controller/type";
2
- export declare function GaesupComponent({ props, refs, }: {
2
+ import { urlsType } from "../world/context/type";
3
+ export declare function GaesupComponent({ props, refs, urls, }: {
3
4
  props: controllerInnerType;
4
5
  refs: refsType;
6
+ urls: urlsType;
5
7
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { vec3 } from "@react-three/rapier";
2
3
  import { useContext } from "react";
3
4
  import calculation from "../physics";
4
5
  import { GaesupWorldContext } from "../world/context";
@@ -6,8 +7,13 @@ import { AirplaneRef } from "./active/airplane";
6
7
  import { CharacterRef } from "./active/character";
7
8
  import { VehicleRef } from "./active/vehicle";
8
9
  export function GaesupComponent(_a) {
9
- var props = _a.props, refs = _a.refs;
10
- var mode = useContext(GaesupWorldContext).mode;
10
+ var props = _a.props, refs = _a.refs, urls = _a.urls;
11
+ var _b = useContext(GaesupWorldContext), mode = _b.mode, states = _b.states, rideable = _b.rideable;
12
+ var enableRiding = states.enableRiding, isRiderOn = states.isRiderOn, rideableId = states.rideableId;
11
13
  calculation(props);
12
- return (_jsxs(_Fragment, { children: [mode.type === "character" && _jsx(CharacterRef, { props: props, refs: refs }), mode.type === "vehicle" && _jsx(VehicleRef, { props: props, refs: refs }), mode.type === "airplane" && _jsx(AirplaneRef, { props: props, refs: refs })] }));
14
+ return (_jsxs(_Fragment, { children: [mode.type === "character" && (_jsx(CharacterRef, { props: props, refs: refs, urls: urls })), mode.type === "vehicle" && (_jsx(VehicleRef, { groundRay: props.groundRay, refs: refs, urls: urls, enableRiding: enableRiding, isRiderOn: isRiderOn, offset: rideableId && rideable[rideableId]
15
+ ? rideable[rideableId].offset
16
+ : vec3(), children: props.children })), mode.type === "airplane" && (_jsx(AirplaneRef, { refs: refs, urls: urls, enableRiding: enableRiding, isRiderOn: isRiderOn, offset: rideableId && rideable[rideableId]
17
+ ? rideable[rideableId].offset
18
+ : vec3(), children: props.children }))] }));
13
19
  }
@@ -0,0 +1,2 @@
1
+ import { refPropsType } from "../common/type";
2
+ export declare function AirplaneInnerRef({ children, refs, urls, isRiderOn, enableRiding, offset, name, position, rotation, userData, onCollisionEnter, }: refPropsType): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { CuboidCollider } from "@react-three/rapier";
3
+ import { useGltfAndSize } from "../../../hooks/useGaesupGltf";
4
+ import { InnerGroupRef } from "../common/InnerGroupRef";
5
+ import { OuterGroupRef } from "../common/OuterGroupRef";
6
+ import { RigidBodyRef } from "../common/RigidbodyRef";
7
+ import RiderRef from "../rider";
8
+ export function AirplaneInnerRef(_a) {
9
+ var children = _a.children, refs = _a.refs, urls = _a.urls, isRiderOn = _a.isRiderOn, enableRiding = _a.enableRiding, offset = _a.offset, name = _a.name, position = _a.position, rotation = _a.rotation, userData = _a.userData, onCollisionEnter = _a.onCollisionEnter;
10
+ var airplaneUrl = urls.airplaneUrl;
11
+ var rigidBodyRef = refs.rigidBodyRef, innerGroupRef = refs.innerGroupRef, outerGroupRef = refs.outerGroupRef;
12
+ var size = useGltfAndSize({
13
+ url: airplaneUrl,
14
+ }).size;
15
+ return (_jsx(OuterGroupRef, { ref: outerGroupRef, children: airplaneUrl && (_jsxs(RigidBodyRef, { ref: rigidBodyRef, name: name, position: position, rotation: rotation, userData: userData, onCollisionEnter: onCollisionEnter, children: [_jsx(CuboidCollider, { args: [size.x / 2, size.y / 2, size.z / 2], position: [0, size.y / 2, 0] }), children, _jsx(InnerGroupRef, { type: "airplane", url: airplaneUrl, currentAnimation: "idle", ref: innerGroupRef, children: enableRiding && isRiderOn && urls.characterUrl && (_jsx(RiderRef, { urls: urls, offset: offset })) })] })) }));
16
+ }
@@ -0,0 +1,25 @@
1
+ import { refsType } from "../../../controller/type";
2
+ import { ReactNode, Ref } from "react";
3
+ import { Object3D, Object3DEventMap } from "three";
4
+ import { urlsType } from "../../../world/context/type";
5
+ export declare const calcCharacterColliderProps: (characterSize: THREE.Vector3) => {
6
+ height: number;
7
+ halfHeight: number;
8
+ radius: number;
9
+ diameter: number;
10
+ };
11
+ export type characterColliderType = {
12
+ height: number;
13
+ halfHeight: number;
14
+ radius: number;
15
+ diameter: number;
16
+ };
17
+ export declare function CharacterInnerRef({ children, refs, urls, position, euler, currentAnimation, }: {
18
+ children: ReactNode;
19
+ refs: Partial<refsType>;
20
+ urls: urlsType;
21
+ position?: THREE.Vector3;
22
+ euler?: THREE.Euler;
23
+ animationRef?: Ref<Object3D<Object3DEventMap>>;
24
+ currentAnimation?: string;
25
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { CapsuleCollider } from "@react-three/rapier";
3
+ import { useGltfAndSize } from "../../../hooks/useGaesupGltf";
4
+ import { InnerGroupRef } from "../common/InnerGroupRef";
5
+ import { OuterGroupRef } from "../common/OuterGroupRef";
6
+ import { RigidBodyRef } from "../common/RigidbodyRef";
7
+ export var calcCharacterColliderProps = function (characterSize) {
8
+ if (!characterSize)
9
+ return null;
10
+ var heightPlusDiameter = characterSize.y / 2;
11
+ var diameter = Math.max(characterSize.x, characterSize.z);
12
+ var radius = diameter / 2;
13
+ var height = heightPlusDiameter - radius;
14
+ var halfHeight = height / 2;
15
+ return {
16
+ height: height,
17
+ halfHeight: halfHeight,
18
+ radius: radius,
19
+ diameter: diameter,
20
+ };
21
+ };
22
+ export function CharacterInnerRef(_a) {
23
+ var children = _a.children, refs = _a.refs, urls = _a.urls, position = _a.position, euler = _a.euler, currentAnimation = _a.currentAnimation;
24
+ var outerGroupRef = refs.outerGroupRef, rigidBodyRef = refs.rigidBodyRef, colliderRef = refs.colliderRef, innerGroupRef = refs.innerGroupRef;
25
+ var size = useGltfAndSize({ url: urls.characterUrl }).size;
26
+ var collider = calcCharacterColliderProps(size);
27
+ return (_jsx(_Fragment, { children: collider && (_jsxs(OuterGroupRef, { ref: outerGroupRef, children: [children, _jsxs(RigidBodyRef, { ref: rigidBodyRef, name: "character", position: position, rotation: euler, children: [_jsx(CapsuleCollider, { ref: colliderRef, args: [collider.height, collider.radius], position: [0, collider.height + collider.radius, 0] }), _jsx(InnerGroupRef, { type: "character", ref: innerGroupRef, url: urls.characterUrl, currentAnimation: currentAnimation })] })] })) }));
28
+ }
@@ -1,6 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import * as THREE from "three";
3
3
  export type InnerGroupRefType = {
4
+ children?: React.ReactNode;
5
+ type: "character" | "vehicle" | "airplane";
4
6
  currentAnimation: string;
5
7
  url: string;
6
8
  rotation?: THREE.Euler;
@@ -1,27 +1,29 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Suspense, forwardRef, useMemo } from "react";
3
- import { useGLTF } from "@react-three/drei";
4
2
  import { useGraph } from "@react-three/fiber";
3
+ import { Suspense, forwardRef, useMemo } from "react";
5
4
  import * as THREE from "three";
6
5
  import { SkeletonUtils } from "three-stdlib";
7
- import playPassiveActions from "../../../animation/passiveActions";
6
+ import { useAnimations, useGLTF } from "@react-three/drei";
7
+ import playActions from "../../../animation/actions";
8
8
  export var InnerGroupRef = forwardRef(function (_a, ref) {
9
- var currentAnimation = _a.currentAnimation, url = _a.url, rotation = _a.rotation;
9
+ var children = _a.children, type = _a.type, currentAnimation = _a.currentAnimation, url = _a.url, rotation = _a.rotation;
10
10
  var _b = useGLTF(url), scene = _b.scene, animations = _b.animations;
11
- var animationRef = playPassiveActions({
12
- current: currentAnimation,
13
- animations: animations,
11
+ var animationResult = useAnimations(animations);
12
+ var animationRef = playActions({
13
+ type: type,
14
+ animationResult: animationResult,
15
+ currentAnimation: currentAnimation,
14
16
  }).animationRef;
15
17
  var clone = useMemo(function () { return SkeletonUtils.clone(scene); }, [scene]);
16
18
  var nodes = useGraph(clone).nodes;
17
19
  var objectNode = Object.values(nodes).find(function (node) { return node.type === "Object3D"; });
18
- return (_jsx(Suspense, { fallback: null, children: _jsxs("group", { receiveShadow: true, castShadow: true, ref: ref, rotation: rotation, userData: { intangible: true }, children: [objectNode && animationRef && (_jsx("primitive", { object: objectNode, visible: false, receiveShadow: true, castShadow: true, ref: animationRef })), Object.keys(nodes).map(function (name, key) {
20
+ return (_jsx(Suspense, { fallback: null, children: _jsxs("group", { receiveShadow: true, castShadow: true, ref: ref, rotation: rotation, userData: { intangible: true }, children: [children, objectNode && animationRef && (_jsx("primitive", { object: objectNode, visible: false, receiveShadow: true, castShadow: true, ref: animationRef })), Object.keys(nodes).map(function (name, key) {
19
21
  var node = nodes[name];
20
22
  if (node instanceof THREE.SkinnedMesh) {
21
- return (_jsx("skinnedMesh", { castShadow: true, receiveShadow: true, material: node.material, geometry: node.geometry, skeleton: node.skeleton, userData: { intangible: true } }, key));
23
+ return (_jsx("skinnedMesh", { castShadow: true, receiveShadow: true, material: node.material, geometry: node.geometry, skeleton: node.skeleton }, key));
22
24
  }
23
25
  else if (node instanceof THREE.Mesh) {
24
- return (_jsx("mesh", { castShadow: true, receiveShadow: true, material: node.material, geometry: node.geometry, userData: { intangible: true } }, key));
26
+ return (_jsx("mesh", { castShadow: true, receiveShadow: true, material: node.material, geometry: node.geometry }, key));
25
27
  }
26
28
  })] }) }));
27
29
  });
@@ -2,7 +2,11 @@ import { CollisionEnterPayload, RapierRigidBody } from "@react-three/rapier";
2
2
  import { ReactNode } from "react";
3
3
  export declare const RigidBodyRef: import("react").ForwardRefExoticComponent<{
4
4
  children: ReactNode;
5
+ name?: string;
5
6
  position?: THREE.Vector3;
6
7
  rotation?: THREE.Euler;
8
+ userData?: {
9
+ intangible: boolean;
10
+ };
7
11
  onCollisionEnter?: (e: CollisionEnterPayload) => Promise<void>;
8
12
  } & import("react").RefAttributes<RapierRigidBody>>;
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { RigidBody, euler, } from "@react-three/rapier";
3
+ import { forwardRef } from "react";
4
+ export var RigidBodyRef = forwardRef(function (_a, ref) {
5
+ var children = _a.children, name = _a.name, position = _a.position, rotation = _a.rotation, userData = _a.userData, onCollisionEnter = _a.onCollisionEnter;
6
+ return (_jsx(RigidBody, { colliders: false, ref: ref, name: name, position: position, rotation: euler().set(0, (rotation === null || rotation === void 0 ? void 0 : rotation.clone().y) || 0, 0), userData: userData, onCollisionEnter: onCollisionEnter, children: children }));
7
+ });
@@ -0,0 +1,9 @@
1
+ import { Collider } from "@dimforge/rapier3d-compat";
2
+ import { RefObject } from "react";
3
+ import { groundRayType } from "../../../controller/type";
4
+ export type setGroundRayType = {
5
+ groundRay: groundRayType;
6
+ length: number;
7
+ colliderRef: RefObject<Collider>;
8
+ };
9
+ export declare function setGroundRay({ groundRay, length, colliderRef, }: setGroundRayType): void;
@@ -0,0 +1,14 @@
1
+ import { useRapier } from "@react-three/rapier";
2
+ import { getRayHit } from "../../../utils";
3
+ export function setGroundRay(_a) {
4
+ var _b;
5
+ var groundRay = _a.groundRay, length = _a.length, colliderRef = _a.colliderRef;
6
+ var rapier = useRapier().rapier;
7
+ groundRay.length = length;
8
+ groundRay.rayCast = new rapier.Ray(groundRay.origin, groundRay.dir);
9
+ groundRay.hit = getRayHit({
10
+ ray: groundRay,
11
+ ref: colliderRef,
12
+ });
13
+ groundRay.parent = (_b = groundRay.hit) === null || _b === void 0 ? void 0 : _b.collider.parent();
14
+ }
@@ -0,0 +1,20 @@
1
+ /// <reference types="react" />
2
+ import { CollisionEnterPayload } from "@react-three/rapier";
3
+ import { refsType } from "../../../controller/type";
4
+ import { urlsType } from "../../../world/context/type";
5
+ export type refPropsType = {
6
+ children: React.ReactNode;
7
+ refs: Partial<refsType>;
8
+ urls: urlsType;
9
+ isRiderOn?: boolean;
10
+ enableRiding?: boolean;
11
+ offset?: THREE.Vector3;
12
+ name?: string;
13
+ position?: THREE.Vector3;
14
+ rotation?: THREE.Euler;
15
+ userData?: {
16
+ intangible: boolean;
17
+ };
18
+ currentAnimation?: string;
19
+ onCollisionEnter?: (e: CollisionEnterPayload) => Promise<void>;
20
+ };
@@ -0,0 +1,11 @@
1
+ import { ReactNode } from "react";
2
+ import * as THREE from "three";
3
+ import { urlsType } from "../../../world/context/type";
4
+ export type riderRefType = {
5
+ urls: urlsType;
6
+ children?: ReactNode;
7
+ offset?: THREE.Vector3;
8
+ euler?: THREE.Euler;
9
+ currentAnimation?: string;
10
+ };
11
+ export default function RiderRef({ urls, children, offset, euler, currentAnimation, }: riderRefType): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useAnimations } from "@react-three/drei";
3
+ import { useGraph } from "@react-three/fiber";
4
+ import { useMemo } from "react";
5
+ import * as THREE from "three";
6
+ import { SkeletonUtils } from "three-stdlib";
7
+ import playActions from "../../../animation/actions";
8
+ import { useGltfAndSize } from "../../../hooks/useGaesupGltf";
9
+ export default function RiderRef(_a) {
10
+ var urls = _a.urls, children = _a.children, offset = _a.offset, euler = _a.euler, currentAnimation = _a.currentAnimation;
11
+ var gltf = useGltfAndSize({ url: urls.characterUrl }).gltf;
12
+ var animations = gltf.animations, scene = gltf.scene;
13
+ var animationResult = useAnimations(animations);
14
+ var animationRef = playActions({
15
+ type: "character",
16
+ animationResult: animationResult,
17
+ currentAnimation: currentAnimation || "ride",
18
+ }).animationRef;
19
+ var characterClone = useMemo(function () { return SkeletonUtils.clone(scene); }, [scene]);
20
+ var characterNodes = useGraph(characterClone).nodes;
21
+ var characterObjectNode = Object.values(characterNodes).find(function (node) { return node.type === "Object3D"; });
22
+ return (_jsx(_Fragment, { children: _jsxs("group", { position: offset, rotation: euler, children: [characterObjectNode && (_jsx("primitive", { object: characterObjectNode, visible: false, receiveShadow: true, castShadow: true, ref: animationRef })), Object.keys(characterNodes).map(function (name, key) {
23
+ var characterNode = characterNodes[name];
24
+ if (characterNode instanceof THREE.SkinnedMesh) {
25
+ return (_jsx("skinnedMesh", { castShadow: true, receiveShadow: true, material: characterNode.material, geometry: characterNode.geometry, skeleton: characterNode.skeleton }, key));
26
+ }
27
+ else if (characterNode instanceof THREE.Mesh) {
28
+ return (_jsx("mesh", { castShadow: true, receiveShadow: true, material: characterNode.material, geometry: characterNode.geometry }, key));
29
+ }
30
+ }), children] }) }));
31
+ }
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { Collider } from "@dimforge/rapier3d-compat";
3
+ import { urlsType } from "../../../world/context/type";
4
+ export declare const VehicleWheelCollider: import("react").ForwardRefExoticComponent<{
5
+ urls: urlsType;
6
+ vehicleSize: THREE.Vector3;
7
+ } & import("react").RefAttributes<Collider>>;
8
+ export declare const VehicleCollider: import("react").ForwardRefExoticComponent<{
9
+ vehicleSize: THREE.Vector3;
10
+ } & import("react").RefAttributes<Collider>>;