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,139 @@
1
+ import {
2
+ Collider,
3
+ Ray,
4
+ RayColliderToi,
5
+ RevoluteImpulseJoint,
6
+ } from "@dimforge/rapier3d-compat";
7
+ import { GroupProps, OrthographicCameraProps } from "@react-three/fiber";
8
+ import { RapierRigidBody, RigidBodyProps } from "@react-three/rapier";
9
+ import { ReactNode, RefObject } from "react";
10
+ import * as THREE from "three";
11
+ import { cameraRayType } from "../camera/type";
12
+ import { callbackType } from "../initial/callback/type";
13
+
14
+ import {
15
+ gaesupCameraOptionType,
16
+ gaesupCameraPropType,
17
+ perspectiveCameraPropType,
18
+ } from "../stores/context/controller/type";
19
+ import { keyControlType } from "../stores/control/type";
20
+
21
+ export type constantType = {
22
+ jumpSpeed: number;
23
+ turnSpeed: number;
24
+ walkSpeed: number;
25
+ runSpeed: number;
26
+ accelRate: number;
27
+ brakeRate: number;
28
+ wheelOffset: number;
29
+ linearDamping: number;
30
+ cameraInitDistance: number;
31
+ cameraMaxDistance: number;
32
+ cameraMinDistance: number;
33
+ cameraInitDirection: number;
34
+ cameraCollisionOff: number;
35
+ cameraDistance: number;
36
+ cameraCamFollow: number;
37
+ };
38
+
39
+ export type optionsType = {
40
+ debug: boolean;
41
+ mode?: "normal" | "vehicle" | "airplane";
42
+ controllerType: "none" | "gameboy" | "joystick" | "keyboard";
43
+ cameraCollisionType: "transparent" | "closeUp";
44
+ camera: {
45
+ type: "perspective" | "orthographic";
46
+ control: "orbit" | "normal";
47
+ };
48
+ minimap: boolean;
49
+ minimapRatio: number;
50
+ };
51
+
52
+ export type partialOptionsType = Partial<optionsType>;
53
+ export type partialConstantType = Partial<constantType>;
54
+
55
+ export type jumpInnerType = {
56
+ velocity: THREE.Vector3;
57
+ direction: THREE.Vector3;
58
+ };
59
+
60
+ export type jumpConstType = {
61
+ speed: number;
62
+ gravity: number;
63
+ };
64
+
65
+ export type jumpPropType = jumpInnerType & jumpConstType;
66
+
67
+ export type rayType = {
68
+ origin: THREE.Vector3;
69
+ hit: RayColliderToi | null;
70
+ rayCast: Ray | null;
71
+ dir: THREE.Vector3;
72
+ offset: THREE.Vector3;
73
+ length: number;
74
+ current?: THREE.Vector3;
75
+ angle?: number;
76
+ parent?: RapierRigidBody | null | undefined;
77
+ };
78
+
79
+ export type slopeRayType = Omit<rayType, "parent">;
80
+ export type groundRayType = Omit<rayType, "current" | "angle">;
81
+
82
+ export type propType = {
83
+ children?: ReactNode;
84
+ groupProps?: GroupProps;
85
+ slopeRay: slopeRayType;
86
+ groundRay: groundRayType;
87
+ cameraRay: cameraRayType;
88
+ constant: constantType;
89
+ capsuleColliderRef: RefObject<Collider>;
90
+ rigidBodyRef: RefObject<RapierRigidBody>;
91
+ outerGroupRef: RefObject<THREE.Group>;
92
+ innerGroupRef: RefObject<THREE.Group>;
93
+ slopeRayOriginRef: RefObject<THREE.Mesh>;
94
+ jointRefs?: RefObject<RevoluteImpulseJoint>;
95
+ characterUrl?: string;
96
+ kartUrl?: string;
97
+ airplaneUrl?: string;
98
+ keyControl: keyControlType;
99
+ debug?: boolean;
100
+ callbacks?: callbackType;
101
+ };
102
+
103
+ export type animationTagType = {
104
+ idle: string;
105
+ walk: string;
106
+ run: string;
107
+ jump: string;
108
+ jumpIdle: string;
109
+ jumpLand: string;
110
+ fall: string;
111
+ ride: string;
112
+ };
113
+
114
+ export type actionsType = animationTagType & {
115
+ [key: string]: string;
116
+ };
117
+
118
+ export type refsType = {
119
+ capsuleColliderRef: RefObject<Collider>;
120
+ rigidBodyRef: RefObject<RapierRigidBody>;
121
+ outerGroupRef: RefObject<THREE.Group>;
122
+ innerGroupRef: RefObject<THREE.Group>;
123
+ slopeRayOriginRef: RefObject<THREE.Mesh>;
124
+ jointRefs: RefObject<RevoluteImpulseJoint>;
125
+ };
126
+
127
+ export interface controllerPropType extends RigidBodyProps {
128
+ children?: ReactNode;
129
+ debug?: boolean;
130
+ slopeRay?: slopeRayType;
131
+ props?: RigidBodyProps;
132
+ constant?: partialConstantType;
133
+ groupProps?: GroupProps;
134
+ cameraMode?: gaesupCameraPropType;
135
+ cameraOption?: gaesupCameraOptionType;
136
+ perspectiveCamera?: perspectiveCameraPropType;
137
+ orthographicCamera?: OrthographicCameraProps;
138
+ }
139
+ export type controllerType = controllerPropType & {} & callbackType;
@@ -0,0 +1,66 @@
1
+ import { vec3 } from "@react-three/rapier";
2
+ import { useContext, useEffect, useRef } from "react";
3
+ import * as THREE from "three";
4
+ import {
5
+ GaesupWorldContext,
6
+ GaesupWorldDispatchContext,
7
+ } from "../stores/context/gaesupworld";
8
+
9
+ export default function GaeSupProps({
10
+ text,
11
+ position,
12
+ jumpPoint,
13
+ children,
14
+ }: {
15
+ text: string;
16
+ position?: [number, number, number];
17
+ jumpPoint?: boolean;
18
+ children: React.ReactNode;
19
+ }) {
20
+ const groupRef = useRef<THREE.Group>(null);
21
+ const { minimap, points } = useContext(GaesupWorldContext);
22
+ const dispatch = useContext(GaesupWorldDispatchContext);
23
+ useEffect(() => {
24
+ if (jumpPoint && position) {
25
+ points.push({
26
+ text,
27
+ position: vec3().set(position[0], 5, position[2]),
28
+ });
29
+ dispatch({
30
+ type: "update",
31
+ payload: {
32
+ points: [...points],
33
+ },
34
+ });
35
+ }
36
+ if (groupRef.current) {
37
+ const box = new THREE.Box3().setFromObject(groupRef.current);
38
+ const size = vec3(box.getSize(new THREE.Vector3()))
39
+ .clone()
40
+ .multiplyScalar(minimap.ratio);
41
+ const center = vec3(box.getCenter(new THREE.Vector3()))
42
+ .clone()
43
+ .multiplyScalar(minimap.ratio);
44
+ const obj = {
45
+ text,
46
+ size,
47
+ center,
48
+ };
49
+ minimap.props[text] = obj;
50
+ dispatch({
51
+ type: "update",
52
+ payload: {
53
+ minimap: {
54
+ ...minimap,
55
+ },
56
+ },
57
+ });
58
+ }
59
+ }, []);
60
+
61
+ return (
62
+ <group ref={groupRef} position={position}>
63
+ {children}
64
+ </group>
65
+ );
66
+ }
@@ -0,0 +1,73 @@
1
+ import { useFrame } from "@react-three/fiber";
2
+ import { useContext, useEffect } from "react";
3
+
4
+ import { useAnimations, useKeyboardControls } from "@react-three/drei";
5
+ import { animationTagType } from "../../controller/type";
6
+
7
+ import {
8
+ GaesupWorldContext,
9
+ GaesupWorldDispatchContext,
10
+ } from "../../stores/context/gaesupworld";
11
+ import { callbackPropType, initCallbackType } from "./type";
12
+
13
+ export default function initCallback({
14
+ prop,
15
+ callbacks,
16
+ outerGroupRef,
17
+ }: initCallbackType) {
18
+ const {
19
+ characterGltf,
20
+ animations: characterAnimations,
21
+ activeState,
22
+ states,
23
+ } = useContext(GaesupWorldContext);
24
+ const dispatch = useContext(GaesupWorldDispatchContext);
25
+ const { animations } = characterGltf;
26
+ const control = useKeyboardControls()[1]();
27
+ const { actions } = useAnimations(animations, outerGroupRef);
28
+
29
+ const playAnimation = (tag: keyof animationTagType) => {
30
+ characterAnimations.current = tag;
31
+ dispatch({
32
+ type: "update",
33
+ payload: {
34
+ animations: {
35
+ ...characterAnimations,
36
+ },
37
+ },
38
+ });
39
+ };
40
+
41
+ const controllerProp: callbackPropType = {
42
+ ...prop,
43
+ activeState,
44
+ control,
45
+ states,
46
+ };
47
+
48
+ useEffect(() => {
49
+ if (callbacks && callbacks.onReady) {
50
+ callbacks.onReady(controllerProp);
51
+ }
52
+ return () => {
53
+ if (callbacks && callbacks.onDestory) {
54
+ callbacks.onDestory(controllerProp);
55
+ }
56
+ };
57
+ }, []);
58
+
59
+ useFrame((prop) => {
60
+ if (callbacks && callbacks.onFrame) {
61
+ callbacks.onFrame({ ...controllerProp, ...prop });
62
+ }
63
+ if (callbacks && callbacks.onAnimate) {
64
+ callbacks.onAnimate({
65
+ ...controllerProp,
66
+ ...prop,
67
+ actions,
68
+ animation: characterAnimations,
69
+ playAnimation,
70
+ });
71
+ }
72
+ });
73
+ }
@@ -0,0 +1,45 @@
1
+ import { RootState } from "@react-three/fiber";
2
+ import { cameraRayType } from "../../camera/type";
3
+ import {
4
+ actionsType,
5
+ constantType,
6
+ groundRayType,
7
+ propType,
8
+ slopeRayType,
9
+ } from "../../controller/type";
10
+ import { activeStateType } from "../../stores/active/type";
11
+ import { animationPropType } from "../../stores/animation/type";
12
+ import { keyControlType } from "../../stores/control/type";
13
+ import { statesType } from "../../stores/states/type";
14
+
15
+ export type initCallbackType = {
16
+ prop: propType;
17
+ callbacks?: callbackType;
18
+ outerGroupRef: React.MutableRefObject<THREE.Group | undefined>;
19
+ };
20
+
21
+ export type callbackPropType = {
22
+ activeState: activeStateType;
23
+ states: statesType;
24
+ slopeRay: slopeRayType;
25
+ groundRay: groundRayType;
26
+ cameraRay: cameraRayType;
27
+ constant: constantType;
28
+ control: keyControlType;
29
+ };
30
+
31
+ export type onFramePropType = callbackPropType & RootState;
32
+ export type onAnimatePropType = onFramePropType & {
33
+ actions: {
34
+ [x: string]: THREE.AnimationAction | null;
35
+ };
36
+ animation: animationPropType;
37
+ playAnimation: (tag: keyof actionsType) => void;
38
+ };
39
+
40
+ export type callbackType = {
41
+ onReady?: (prop: callbackPropType) => void;
42
+ onFrame?: (prop: onFramePropType) => void;
43
+ onDestory?: (prop: callbackPropType) => void;
44
+ onAnimate?: (prop: onAnimatePropType) => void;
45
+ };
@@ -0,0 +1,143 @@
1
+ import { useKeyboardControls } from "@react-three/drei";
2
+ import { vec3 } from "@react-three/rapier";
3
+ import { useCallback, useContext, useEffect, useMemo } from "react";
4
+ import * as THREE from "three";
5
+ import {
6
+ constantType,
7
+ controllerType,
8
+ groundRayType,
9
+ refsType,
10
+ slopeRayType,
11
+ } from "../../controller/type";
12
+ import {
13
+ GaesupWorldContext,
14
+ GaesupWorldDispatchContext,
15
+ } from "../../stores/context/gaesupworld";
16
+ import { keyControlType } from "../../stores/control/type";
17
+ import initDebug from "./initDebug";
18
+
19
+ export default function initControllerProps({
20
+ props,
21
+ refs,
22
+ }: {
23
+ props: controllerType;
24
+ refs: refsType;
25
+ }) {
26
+ const context = useContext(GaesupWorldContext);
27
+ const dispatch = useContext(GaesupWorldDispatchContext);
28
+
29
+ const [_, getKeys] = useKeyboardControls();
30
+ const keyControl: keyControlType = getKeys();
31
+
32
+ const groundRay: groundRayType = useMemo(() => {
33
+ return {
34
+ origin: vec3(),
35
+ dir: vec3({ x: 0, y: -1, z: 0 }),
36
+ offset: vec3({ x: 0, y: -context.characterCollider.halfHeight, z: 0 }),
37
+ hit: null,
38
+ parent: null,
39
+ rayCast: null,
40
+ length: 0.5,
41
+ };
42
+ }, []);
43
+
44
+ const slopeRay: slopeRayType = useMemo(() => {
45
+ return {
46
+ current: vec3(),
47
+ origin: vec3(),
48
+ hit: null,
49
+ rayCast: null,
50
+ dir: vec3({ x: 0, y: -1, z: 0 }),
51
+ offset: vec3({ x: 0, y: 0, z: context.characterCollider.radius - 0.03 }),
52
+ length: context.characterCollider.radius + 3,
53
+ angle: 0,
54
+ };
55
+ }, []);
56
+
57
+ let constant: constantType = useMemo(() => {
58
+ return {
59
+ jumpSpeed: 5,
60
+ turnSpeed: 10,
61
+ walkSpeed: 4,
62
+ runSpeed: 10,
63
+ accelRate: 5,
64
+ brakeRate: 5,
65
+ wheelOffset: 0.1,
66
+ linearDamping: 1,
67
+ cameraInitDistance: -5,
68
+ cameraMaxDistance: -7,
69
+ cameraMinDistance: -0.7,
70
+ cameraInitDirection: 0,
71
+ cameraCollisionOff: 0.7,
72
+ cameraDistance: -1,
73
+ cameraCamFollow: 11,
74
+ };
75
+ }, []);
76
+
77
+ const cameraRay = useMemo(() => {
78
+ return {
79
+ origin: vec3(),
80
+ hit: new THREE.Raycaster(),
81
+ rayCast: new THREE.Raycaster(vec3(), vec3(), 0, -7),
82
+ lerpingPoint: vec3(),
83
+ dir: vec3(),
84
+ position: vec3(),
85
+ length: -1,
86
+ followCamera: new THREE.Object3D(),
87
+ pivot: new THREE.Object3D(),
88
+ intersetesAndTransParented: [],
89
+ intersects: [],
90
+ intersectObjects: [],
91
+ intersectObjectMap: {},
92
+ };
93
+ }, []);
94
+ cameraRay.rayCast = new THREE.Raycaster(
95
+ cameraRay.origin,
96
+ cameraRay.dir,
97
+ 0,
98
+ -constant.cameraMaxDistance
99
+ );
100
+
101
+ const initRefs = useCallback(
102
+ (refs: refsType) => {
103
+ dispatch({
104
+ type: "update",
105
+ payload: {
106
+ refs: {
107
+ ...refs,
108
+ },
109
+ },
110
+ });
111
+ },
112
+ [refs]
113
+ );
114
+
115
+ useEffect(() => {
116
+ if (refs) {
117
+ initRefs(refs);
118
+ }
119
+ }, []);
120
+
121
+ useEffect(() => {
122
+ if (props.constant) {
123
+ constant = {
124
+ ...constant,
125
+ ...Object.assign(constant, props.constant),
126
+ };
127
+ }
128
+ }, []);
129
+
130
+ return initDebug({
131
+ slopeRay,
132
+ groundRay,
133
+ constant,
134
+ cameraRay,
135
+ capsuleColliderRef: refs.capsuleColliderRef,
136
+ rigidBodyRef: refs.rigidBodyRef,
137
+ outerGroupRef: refs.outerGroupRef,
138
+ slopeRayOriginRef: refs.slopeRayOriginRef,
139
+ innerGroupRef: refs.innerGroupRef,
140
+ keyControl,
141
+ debug: props.debug,
142
+ });
143
+ }
@@ -0,0 +1,102 @@
1
+ import { useControls } from "leva";
2
+ import { propType } from "../../controller/type";
3
+
4
+ export default function initDebug(prop: propType) {
5
+ const debugProps = { ...prop };
6
+ if (prop.debug) {
7
+ debugProps.constant = useControls("constants", {
8
+ jumpSpeed: {
9
+ value: debugProps.constant.jumpSpeed,
10
+ min: 1,
11
+ max: 10,
12
+ step: 0.01,
13
+ },
14
+ turnSpeed: {
15
+ value: debugProps.constant.turnSpeed,
16
+ min: 5,
17
+ max: 30,
18
+ step: 0.01,
19
+ },
20
+ walkSpeed: {
21
+ value: debugProps.constant.walkSpeed,
22
+ min: 1,
23
+ max: 5,
24
+ step: 0.01,
25
+ },
26
+ runSpeed: {
27
+ value: debugProps.constant.runSpeed,
28
+ min: 1,
29
+ max: 5,
30
+ step: 0.01,
31
+ },
32
+ accelRate: {
33
+ value: debugProps.constant.accelRate,
34
+ min: 1,
35
+ max: 10,
36
+ step: 0.01,
37
+ },
38
+ brakeRate: {
39
+ value: debugProps.constant.brakeRate,
40
+ min: 1,
41
+ max: 10,
42
+ step: 0.01,
43
+ },
44
+ wheelOffset: {
45
+ value: debugProps.constant.wheelOffset,
46
+ min: 0,
47
+ max: 1,
48
+ step: 0.01,
49
+ },
50
+ linearDamping: {
51
+ value: debugProps.constant.linearDamping,
52
+ min: 0,
53
+ max: 1,
54
+ step: 0.01,
55
+ },
56
+ cameraInitDistance: {
57
+ value: debugProps.constant.cameraInitDistance,
58
+ min: 1,
59
+ max: 10,
60
+ step: 0.01,
61
+ },
62
+ cameraMaxDistance: {
63
+ value: debugProps.constant.cameraMaxDistance,
64
+ min: 1,
65
+ max: 10,
66
+ step: 0.01,
67
+ },
68
+ cameraMinDistance: {
69
+ value: debugProps.constant.cameraMinDistance,
70
+ min: 1,
71
+ max: 10,
72
+ step: 0.01,
73
+ },
74
+ cameraInitDirection: {
75
+ value: debugProps.constant.cameraInitDirection,
76
+ min: 1,
77
+ max: 10,
78
+ step: 0.01,
79
+ },
80
+ cameraCollisionOff: {
81
+ value: debugProps.constant.cameraCollisionOff,
82
+ min: 1,
83
+ max: 10,
84
+ step: 0.01,
85
+ },
86
+ cameraDistance: {
87
+ value: debugProps.constant.cameraDistance,
88
+ min: 1,
89
+ max: 10,
90
+ step: 0.01,
91
+ },
92
+ cameraCamFollow: {
93
+ value: debugProps.constant.cameraCamFollow,
94
+ min: 1,
95
+ max: 10,
96
+ step: 0.01,
97
+ },
98
+ });
99
+ }
100
+
101
+ return { ...debugProps };
102
+ }
@@ -0,0 +1,26 @@
1
+ import { useEffect } from "react";
2
+ import { innerColliderPropType } from "../type";
3
+
4
+ export function airplane({ gltf, value, dispatch }: innerColliderPropType) {
5
+ const { url } = value;
6
+ if (!url || !url.airplaneUrl) return;
7
+ const { airplaneSize } = gltf;
8
+
9
+ useEffect(() => {
10
+ if (airplaneSize.x !== 0 && airplaneSize.y !== 0 && airplaneSize.z !== 0) {
11
+ dispatch({
12
+ type: "update",
13
+ payload: {
14
+ airplaneCollider: {
15
+ airplaneSizeX: airplaneSize.x,
16
+ airplaneSizeY: airplaneSize.y,
17
+ airplaneSizeZ: airplaneSize.z,
18
+ airplaneX: airplaneSize.x / 2,
19
+ airplaneY: airplaneSize.y / 2,
20
+ airplaneZ: airplaneSize.z / 2,
21
+ },
22
+ },
23
+ });
24
+ }
25
+ }, [airplaneSize.x, airplaneSize.y, airplaneSize.z]);
26
+ }
@@ -0,0 +1,32 @@
1
+ import { useEffect } from "react";
2
+ import { innerColliderPropType } from "../type";
3
+
4
+ export function character({ gltf, value, dispatch }: innerColliderPropType) {
5
+ const { url } = value;
6
+ if (!url || !url.characterUrl) return;
7
+ const { characterSize } = gltf;
8
+ useEffect(() => {
9
+ if (
10
+ characterSize.x !== 0 &&
11
+ characterSize.y !== 0 &&
12
+ characterSize.z !== 0
13
+ ) {
14
+ const heightPlusDiameter = characterSize.y / 2;
15
+ const diameter = Math.max(characterSize.x, characterSize.z);
16
+ const radius = diameter / 2;
17
+ const height = heightPlusDiameter - radius;
18
+ const halfHeight = height / 2;
19
+ dispatch({
20
+ type: "update",
21
+ payload: {
22
+ characterCollider: {
23
+ height,
24
+ halfHeight,
25
+ radius,
26
+ diameter,
27
+ },
28
+ },
29
+ });
30
+ }
31
+ }, [characterSize.x, characterSize.y, characterSize.z]);
32
+ }