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.
- package/README.md +51 -0
- package/index.html +13 -0
- package/package.json +82 -0
- package/src/gaesup/animation/actions.ts +123 -0
- package/src/gaesup/camera/cameraCollisionDetecter.tsx +53 -0
- package/src/gaesup/camera/control/map.ts +10 -0
- package/src/gaesup/camera/control/normal copy.ts +19 -0
- package/src/gaesup/camera/control/normal.ts +15 -0
- package/src/gaesup/camera/control/orbit.ts +31 -0
- package/src/gaesup/camera/index.tsx +102 -0
- package/src/gaesup/camera/type.ts +17 -0
- package/src/gaesup/component/Airplane.tsx +46 -0
- package/src/gaesup/component/Character.tsx +48 -0
- package/src/gaesup/component/Vehicle.tsx +40 -0
- package/src/gaesup/component/gltf/AirplaneGltf.tsx +31 -0
- package/src/gaesup/component/gltf/CharacterGltf.tsx +81 -0
- package/src/gaesup/component/gltf/VehicleGltf.tsx +31 -0
- package/src/gaesup/component/gltf/WheelJoint.tsx +39 -0
- package/src/gaesup/component/gltf/type.ts +6 -0
- package/src/gaesup/component/ref/airplane.tsx +83 -0
- package/src/gaesup/component/ref/character.tsx +132 -0
- package/src/gaesup/component/ref/vehicle.tsx +145 -0
- package/src/gaesup/controller/index.tsx +103 -0
- package/src/gaesup/controller/type.ts +139 -0
- package/src/gaesup/gaesupProps/index.tsx +66 -0
- package/src/gaesup/initial/callback/index.ts +73 -0
- package/src/gaesup/initial/callback/type.ts +45 -0
- package/src/gaesup/initial/controller/index.ts +143 -0
- package/src/gaesup/initial/controller/initDebug.ts +102 -0
- package/src/gaesup/initial/gaesupWorld/collider/airplane.ts +26 -0
- package/src/gaesup/initial/gaesupWorld/collider/character.ts +32 -0
- package/src/gaesup/initial/gaesupWorld/collider/gltf.ts +91 -0
- package/src/gaesup/initial/gaesupWorld/collider/index.ts +26 -0
- package/src/gaesup/initial/gaesupWorld/collider/vehicle.ts +43 -0
- package/src/gaesup/initial/gaesupWorld/index.ts +82 -0
- package/src/gaesup/initial/gaesupWorld/type.ts +37 -0
- package/src/gaesup/physics/airplane/currentSetting.ts +20 -0
- package/src/gaesup/physics/airplane/damping.ts +8 -0
- package/src/gaesup/physics/airplane/direction.ts +70 -0
- package/src/gaesup/physics/airplane/gravity.ts +11 -0
- package/src/gaesup/physics/airplane/impulse.ts +22 -0
- package/src/gaesup/physics/airplane/index.tsx +16 -0
- package/src/gaesup/physics/airplane/turn.ts +12 -0
- package/src/gaesup/physics/airplane copy/currentSetting.ts +20 -0
- package/src/gaesup/physics/airplane copy/direction.ts +52 -0
- package/src/gaesup/physics/airplane copy/gravity.ts +6 -0
- package/src/gaesup/physics/airplane copy/impulse.ts +28 -0
- package/src/gaesup/physics/airplane copy/index.tsx +14 -0
- package/src/gaesup/physics/airplane copy/turn.ts +9 -0
- package/src/gaesup/physics/character/accelaration.ts +14 -0
- package/src/gaesup/physics/character/currentSetting.ts +20 -0
- package/src/gaesup/physics/character/damping.ts +6 -0
- package/src/gaesup/physics/character/direction.ts +104 -0
- package/src/gaesup/physics/character/impulse.ts +24 -0
- package/src/gaesup/physics/character/index.tsx +20 -0
- package/src/gaesup/physics/character/jump.ts +21 -0
- package/src/gaesup/physics/character/stabilizing.ts +6 -0
- package/src/gaesup/physics/character/turn.ts +17 -0
- package/src/gaesup/physics/check/ground.ts +19 -0
- package/src/gaesup/physics/check/index.ts +12 -0
- package/src/gaesup/physics/check/moving.ts +21 -0
- package/src/gaesup/physics/check/rotate.ts +13 -0
- package/src/gaesup/physics/check/slope.ts +50 -0
- package/src/gaesup/physics/index.ts +50 -0
- package/src/gaesup/physics/type.ts +35 -0
- package/src/gaesup/physics/vehicle/currentSetting.ts +20 -0
- package/src/gaesup/physics/vehicle/damping.ts +8 -0
- package/src/gaesup/physics/vehicle/direction.ts +27 -0
- package/src/gaesup/physics/vehicle/impulse.ts +22 -0
- package/src/gaesup/physics/vehicle/index.tsx +14 -0
- package/src/gaesup/physics/vehicle/turn.ts +11 -0
- package/src/gaesup/stores/active/index.ts +19 -0
- package/src/gaesup/stores/active/type.ts +16 -0
- package/src/gaesup/stores/airplane/index.ts +6 -0
- package/src/gaesup/stores/airplane/type.ts +4 -0
- package/src/gaesup/stores/animation/index.ts +18 -0
- package/src/gaesup/stores/animation/type.ts +9 -0
- package/src/gaesup/stores/collider/index.ts +55 -0
- package/src/gaesup/stores/context/controller/index.ts +36 -0
- package/src/gaesup/stores/context/controller/reducer.ts +18 -0
- package/src/gaesup/stores/context/controller/type.ts +38 -0
- package/src/gaesup/stores/context/gaesupworld/index.ts +11 -0
- package/src/gaesup/stores/context/gaesupworld/reducer.ts +21 -0
- package/src/gaesup/stores/context/gaesupworld/type.ts +66 -0
- package/src/gaesup/stores/control/index.ts +33 -0
- package/src/gaesup/stores/control/type.ts +11 -0
- package/src/gaesup/stores/joystick/index.ts +72 -0
- package/src/gaesup/stores/joystick/type.ts +23 -0
- package/src/gaesup/stores/minimap/index.ts +5 -0
- package/src/gaesup/stores/minimap/type.ts +22 -0
- package/src/gaesup/stores/point/type.ts +6 -0
- package/src/gaesup/stores/states/index.tsx +10 -0
- package/src/gaesup/stores/states/type.ts +10 -0
- package/src/gaesup/stores/url/index.ts +6 -0
- package/src/gaesup/stores/url/type.ts +6 -0
- package/src/gaesup/styles.css.ts +26 -0
- package/src/gaesup/tools/gameboy/GameBoyButton.tsx +38 -0
- package/src/gaesup/tools/gameboy/index.tsx +36 -0
- package/src/gaesup/tools/gameboy/style.css.ts +78 -0
- package/src/gaesup/tools/gamepad/GamePadButton.tsx +31 -0
- package/src/gaesup/tools/gamepad/index.tsx +55 -0
- package/src/gaesup/tools/gamepad/style.css.ts +16 -0
- package/src/gaesup/tools/index.tsx +61 -0
- package/src/gaesup/tools/joystick/index.tsx +145 -0
- package/src/gaesup/tools/joystick/style.css.ts +40 -0
- package/src/gaesup/tools/jumpPoint/index.tsx +27 -0
- package/src/gaesup/tools/jumpPoint/style.css.ts +33 -0
- package/src/gaesup/tools/keyBoardToolTip/constant.ts +144 -0
- package/src/gaesup/tools/keyBoardToolTip/index.tsx +85 -0
- package/src/gaesup/tools/keyBoardToolTip/style.css.ts +49 -0
- package/src/gaesup/tools/minimap/index.tsx +47 -0
- package/src/gaesup/tools/minimap/style.css.ts +144 -0
- package/src/gaesup/tools/style.css.ts +34 -0
- package/src/gaesup/utils/constant.ts +1 -0
- package/src/gaesup/utils/ray.ts +23 -0
- package/src/gaesup/utils/ref.ts +17 -0
- package/src/gaesup/utils/vector.ts +40 -0
- package/src/gaesup/world/index.tsx +17 -0
- package/src/gaesup/world/type.ts +10 -0
- package/src/styles/constants/boxshadow.css.ts +499 -0
- package/src/styles/constants/constant.css.ts +81 -0
- package/src/styles/constants/direction.css.ts +168 -0
- package/src/styles/constants/flex.css.ts +68 -0
- package/src/styles/constants/gradient.css.ts +10 -0
- package/src/styles/constants/grid.css.ts +37 -0
- package/src/styles/constants/palette.css.ts +324 -0
- package/src/styles/constants/translate.css.ts +129 -0
- package/src/styles/global.css.ts +91 -0
- package/src/styles/recipe/base.css.ts +31 -0
- package/src/styles/recipe/button.css.ts +109 -0
- package/src/styles/recipe/index.css.ts +134 -0
- package/src/styles/recipe/input.css.ts +33 -0
- package/src/styles/sprinkles/color.css.ts +62 -0
- package/src/styles/sprinkles/direction.css.ts +26 -0
- package/src/styles/sprinkles/display.css.ts +25 -0
- package/src/styles/sprinkles/fontSize.css.ts +25 -0
- package/src/styles/sprinkles/grid.css.ts +25 -0
- package/src/styles/sprinkles/index.css.ts +22 -0
- package/src/styles/sprinkles/margin.css.ts +30 -0
- package/src/styles/sprinkles/padding.css.ts +30 -0
- package/src/styles/sprinkles/position.css.ts +14 -0
- package/src/styles/sprinkles/size.css.ts +23 -0
- package/src/styles/theme.css.ts +98 -0
- package/tsconfig.json +27 -0
- package/tsconfig.node.json +10 -0
- package/vite.config.ts +9 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { useLoader } from "@react-three/fiber";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import * as THREE from "three";
|
|
4
|
+
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
5
|
+
import { GLTFResult } from "../../../component/gltf/type";
|
|
6
|
+
import { S3 } from "../../../utils/constant";
|
|
7
|
+
import { innerColliderPropType } from "../type";
|
|
8
|
+
|
|
9
|
+
export type getGltfResultType = {
|
|
10
|
+
characterGltf: GLTFResult;
|
|
11
|
+
vehicleGltf: GLTFResult;
|
|
12
|
+
wheelGltf: GLTFResult;
|
|
13
|
+
airplaneGltf: GLTFResult;
|
|
14
|
+
characterSize: THREE.Vector3;
|
|
15
|
+
vehicleSize: THREE.Vector3;
|
|
16
|
+
wheelSize: THREE.Vector3;
|
|
17
|
+
airplaneSize: THREE.Vector3;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default function getGltf({
|
|
21
|
+
value,
|
|
22
|
+
dispatch,
|
|
23
|
+
}: innerColliderPropType): getGltfResultType {
|
|
24
|
+
const { url } = value;
|
|
25
|
+
const result = {
|
|
26
|
+
characterGltf: null,
|
|
27
|
+
vehicleGltf: null,
|
|
28
|
+
wheelGltf: null,
|
|
29
|
+
airplaneGltf: null,
|
|
30
|
+
characterSize: null,
|
|
31
|
+
vehicleSize: null,
|
|
32
|
+
wheelSize: null,
|
|
33
|
+
airplaneSize: null,
|
|
34
|
+
};
|
|
35
|
+
if (url.characterUrl) {
|
|
36
|
+
const characterGltf: GLTFResult = useLoader(GLTFLoader, url.characterUrl);
|
|
37
|
+
const { scene: characterScene } = characterGltf;
|
|
38
|
+
const characterSize = new THREE.Box3()
|
|
39
|
+
.setFromObject(characterScene)
|
|
40
|
+
.getSize(new THREE.Vector3());
|
|
41
|
+
result.characterGltf = characterGltf;
|
|
42
|
+
result.characterSize = characterSize;
|
|
43
|
+
}
|
|
44
|
+
if (url.vehicleUrl) {
|
|
45
|
+
const vehicleGltf: GLTFResult = useLoader(GLTFLoader, url.vehicleUrl);
|
|
46
|
+
const wheelGltf: GLTFResult = useLoader(
|
|
47
|
+
GLTFLoader,
|
|
48
|
+
url.wheelUrl || S3 + "/wheel.glb"
|
|
49
|
+
);
|
|
50
|
+
const { scene: vehicleScene } = vehicleGltf;
|
|
51
|
+
const { scene: wheelScene } = wheelGltf;
|
|
52
|
+
const vehicleSize = new THREE.Box3()
|
|
53
|
+
.setFromObject(vehicleScene)
|
|
54
|
+
.getSize(new THREE.Vector3());
|
|
55
|
+
const wheelsize = new THREE.Box3()
|
|
56
|
+
.setFromObject(wheelScene)
|
|
57
|
+
.getSize(new THREE.Vector3());
|
|
58
|
+
result.vehicleGltf = vehicleGltf;
|
|
59
|
+
result.wheelGltf = wheelGltf;
|
|
60
|
+
result.vehicleSize = vehicleSize;
|
|
61
|
+
result.wheelSize = wheelsize;
|
|
62
|
+
}
|
|
63
|
+
if (url.airplaneUrl) {
|
|
64
|
+
const airplaneGltf: GLTFResult = useLoader(GLTFLoader, url.airplaneUrl);
|
|
65
|
+
const { scene: airplaneScene } = airplaneGltf;
|
|
66
|
+
const airplaneSize = new THREE.Box3()
|
|
67
|
+
.setFromObject(airplaneScene)
|
|
68
|
+
.getSize(new THREE.Vector3());
|
|
69
|
+
result.airplaneGltf = airplaneGltf;
|
|
70
|
+
result.airplaneSize = airplaneSize;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
dispatch({
|
|
75
|
+
type: "update",
|
|
76
|
+
payload: {
|
|
77
|
+
characterGltf: result.characterGltf,
|
|
78
|
+
vehicleGltf: result.vehicleGltf,
|
|
79
|
+
wheelGltf: result.wheelGltf,
|
|
80
|
+
airplaneGltf: result.airplaneGltf,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}, [
|
|
84
|
+
url,
|
|
85
|
+
result.airplaneGltf,
|
|
86
|
+
result.characterGltf,
|
|
87
|
+
result.vehicleGltf,
|
|
88
|
+
result.wheelGltf,
|
|
89
|
+
]);
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Dispatch } from "react";
|
|
2
|
+
import { gaesupWorldPropType } from "../../../stores/context/gaesupworld/type";
|
|
3
|
+
import { innerColliderPropType } from "../type";
|
|
4
|
+
import { airplane } from "./airplane";
|
|
5
|
+
import { character } from "./character";
|
|
6
|
+
import getGltf from "./gltf";
|
|
7
|
+
import { vehicle } from "./vehicle";
|
|
8
|
+
|
|
9
|
+
export default function initColider(
|
|
10
|
+
value: gaesupWorldPropType,
|
|
11
|
+
dispatch: Dispatch<{
|
|
12
|
+
type: string;
|
|
13
|
+
payload?: Partial<gaesupWorldPropType>;
|
|
14
|
+
}>
|
|
15
|
+
) {
|
|
16
|
+
const colliderProps: innerColliderPropType = {
|
|
17
|
+
gltf: null,
|
|
18
|
+
value,
|
|
19
|
+
dispatch,
|
|
20
|
+
};
|
|
21
|
+
const gltf = getGltf(colliderProps);
|
|
22
|
+
colliderProps.gltf = gltf;
|
|
23
|
+
character(colliderProps);
|
|
24
|
+
vehicle(colliderProps);
|
|
25
|
+
airplane(colliderProps);
|
|
26
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { innerColliderPropType } from "../type";
|
|
3
|
+
|
|
4
|
+
export function vehicle({ gltf, value, dispatch }: innerColliderPropType) {
|
|
5
|
+
const { url } = value;
|
|
6
|
+
if (!url || !url.vehicleUrl) return;
|
|
7
|
+
const { vehicleSize, wheelSize } = gltf;
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (
|
|
11
|
+
vehicleSize.x !== 0 &&
|
|
12
|
+
vehicleSize.y !== 0 &&
|
|
13
|
+
vehicleSize.z !== 0 &&
|
|
14
|
+
wheelSize.x !== 0 &&
|
|
15
|
+
wheelSize.y !== 0 &&
|
|
16
|
+
wheelSize.z !== 0
|
|
17
|
+
) {
|
|
18
|
+
dispatch({
|
|
19
|
+
type: "update",
|
|
20
|
+
payload: {
|
|
21
|
+
vehicleCollider: {
|
|
22
|
+
vehicleSizeX: vehicleSize.x,
|
|
23
|
+
vehicleSizeY: wheelSize.y,
|
|
24
|
+
vehicleSizeZ: vehicleSize.z,
|
|
25
|
+
wheelSizeX: wheelSize.x,
|
|
26
|
+
wheelSizeY: wheelSize.y,
|
|
27
|
+
wheelSizeZ: wheelSize.z,
|
|
28
|
+
vehicleX: vehicleSize.x / 2,
|
|
29
|
+
vehicleY: wheelSize.y / 2,
|
|
30
|
+
vehicleZ: vehicleSize.z / 2,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}, [
|
|
36
|
+
vehicleSize.x,
|
|
37
|
+
vehicleSize.y,
|
|
38
|
+
vehicleSize.z,
|
|
39
|
+
wheelSize.x,
|
|
40
|
+
wheelSize.y,
|
|
41
|
+
wheelSize.z,
|
|
42
|
+
]);
|
|
43
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { useMemo, useReducer } from "react";
|
|
2
|
+
import { activeStateDefault } from "../../stores/active";
|
|
3
|
+
import { animationDefault } from "../../stores/animation";
|
|
4
|
+
import {
|
|
5
|
+
airplaneColliderDefault,
|
|
6
|
+
characterColliderDefault,
|
|
7
|
+
vehicleColliderDefault,
|
|
8
|
+
} from "../../stores/collider";
|
|
9
|
+
import { modeDefault } from "../../stores/context/gaesupworld";
|
|
10
|
+
import { gaesupReducer } from "../../stores/context/gaesupworld/reducer";
|
|
11
|
+
import { controlDefault } from "../../stores/control";
|
|
12
|
+
import { joyStickDefault } from "../../stores/joystick";
|
|
13
|
+
import { minimapDefault } from "../../stores/minimap";
|
|
14
|
+
import { statesDefault } from "../../stores/states";
|
|
15
|
+
import { urlDefault } from "../../stores/url";
|
|
16
|
+
import minimap from "../../tools/minimap";
|
|
17
|
+
import { V3 } from "../../utils/vector";
|
|
18
|
+
import initColider from "./collider";
|
|
19
|
+
import { initGaesupWorldPropsType } from "./type";
|
|
20
|
+
|
|
21
|
+
export default function initGaesupWorld(props: initGaesupWorldPropsType) {
|
|
22
|
+
const [value, dispatch] = useReducer(gaesupReducer, {
|
|
23
|
+
activeState: {
|
|
24
|
+
...activeStateDefault,
|
|
25
|
+
...{ position: props.startPosition || V3(0, 2, 5) },
|
|
26
|
+
},
|
|
27
|
+
characterCollider: Object.assign(
|
|
28
|
+
characterColliderDefault,
|
|
29
|
+
props.characterCollider || {}
|
|
30
|
+
),
|
|
31
|
+
vehicleCollider: Object.assign(
|
|
32
|
+
vehicleColliderDefault,
|
|
33
|
+
props.vehicleCollider || {}
|
|
34
|
+
),
|
|
35
|
+
airplaneCollider: Object.assign(
|
|
36
|
+
airplaneColliderDefault,
|
|
37
|
+
props.airplaneCollider || {}
|
|
38
|
+
),
|
|
39
|
+
mode: Object.assign(modeDefault, props.mode || {}),
|
|
40
|
+
url: Object.assign(urlDefault, props.url || {}),
|
|
41
|
+
characterGltf: null,
|
|
42
|
+
vehicleGltf: null,
|
|
43
|
+
wheelGltf: null,
|
|
44
|
+
airplaneGltf: null,
|
|
45
|
+
states: statesDefault,
|
|
46
|
+
debug: false,
|
|
47
|
+
minimap: Object.assign(minimapDefault, minimap || {}),
|
|
48
|
+
joystick: joyStickDefault,
|
|
49
|
+
control: controlDefault,
|
|
50
|
+
points: [],
|
|
51
|
+
refs: null,
|
|
52
|
+
animations: animationDefault,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const gaesupProps = useMemo(
|
|
56
|
+
() => ({ value, dispatch }),
|
|
57
|
+
[
|
|
58
|
+
value.characterCollider,
|
|
59
|
+
value.vehicleCollider,
|
|
60
|
+
value.airplaneCollider,
|
|
61
|
+
value.airplaneGltf,
|
|
62
|
+
value.vehicleGltf,
|
|
63
|
+
value.wheelGltf,
|
|
64
|
+
value.url,
|
|
65
|
+
value.mode,
|
|
66
|
+
value.states,
|
|
67
|
+
value.debug,
|
|
68
|
+
value.minimap,
|
|
69
|
+
value.joystick,
|
|
70
|
+
value.control,
|
|
71
|
+
value.points,
|
|
72
|
+
value.refs,
|
|
73
|
+
value.animations,
|
|
74
|
+
value.activeState,
|
|
75
|
+
dispatch,
|
|
76
|
+
]
|
|
77
|
+
);
|
|
78
|
+
initColider(value, dispatch);
|
|
79
|
+
return {
|
|
80
|
+
gaesupProps,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Dispatch, ReactNode } from "react";
|
|
2
|
+
import {
|
|
3
|
+
airplaneColliderType,
|
|
4
|
+
characterColliderType,
|
|
5
|
+
vehicleColliderType,
|
|
6
|
+
} from "../../stores/collider";
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
gaesupControllerPropType,
|
|
10
|
+
gaesupWorldPartialPropType,
|
|
11
|
+
gaesupWorldPropType,
|
|
12
|
+
} from "../../stores/context/gaesupworld/type";
|
|
13
|
+
import { minimapType } from "../../stores/minimap/type";
|
|
14
|
+
import { urlType } from "../../stores/url/type";
|
|
15
|
+
import { getGltfResultType } from "./collider/gltf";
|
|
16
|
+
|
|
17
|
+
export type initGaesupWorldPropsType = {
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
startPosition?: THREE.Vector3;
|
|
20
|
+
props?: gaesupWorldPartialPropType;
|
|
21
|
+
url?: urlType;
|
|
22
|
+
characterCollider?: characterColliderType;
|
|
23
|
+
vehicleCollider?: vehicleColliderType;
|
|
24
|
+
airplaneCollider?: airplaneColliderType;
|
|
25
|
+
mode?: gaesupControllerPropType;
|
|
26
|
+
debug?: boolean;
|
|
27
|
+
minimap?: Omit<minimapType, "props">;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type innerColliderPropType = {
|
|
31
|
+
gltf?: getGltfResultType;
|
|
32
|
+
value: gaesupWorldPropType;
|
|
33
|
+
dispatch: Dispatch<{
|
|
34
|
+
type: string;
|
|
35
|
+
payload?: Partial<gaesupWorldPropType>;
|
|
36
|
+
}>;
|
|
37
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { vec3 } from "@react-three/rapier";
|
|
2
|
+
import { calcPropType } from "../type";
|
|
3
|
+
|
|
4
|
+
export default function currentSetting(prop: calcPropType) {
|
|
5
|
+
const {
|
|
6
|
+
rigidBodyRef,
|
|
7
|
+
worldContext: { activeState },
|
|
8
|
+
dispatch,
|
|
9
|
+
} = prop;
|
|
10
|
+
activeState.position = vec3(rigidBodyRef.current.translation());
|
|
11
|
+
activeState.velocity = vec3(rigidBodyRef.current.linvel());
|
|
12
|
+
dispatch({
|
|
13
|
+
type: "update",
|
|
14
|
+
payload: {
|
|
15
|
+
activeState: {
|
|
16
|
+
...activeState,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { calcPropType } from "../type";
|
|
2
|
+
|
|
3
|
+
export default function damping(prop: calcPropType) {
|
|
4
|
+
const { rigidBodyRef, constant, control } = prop;
|
|
5
|
+
const { space } = control;
|
|
6
|
+
const { brakeRate } = constant;
|
|
7
|
+
rigidBodyRef.current.setLinearDamping(space ? brakeRate : 0.5);
|
|
8
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { V3 } from "../../utils/vector";
|
|
2
|
+
import { calcPropType } from "../type";
|
|
3
|
+
|
|
4
|
+
export default function direction(prop: calcPropType) {
|
|
5
|
+
const {
|
|
6
|
+
rigidBodyRef,
|
|
7
|
+
innerGroupRef,
|
|
8
|
+
worldContext: { activeState },
|
|
9
|
+
} = prop;
|
|
10
|
+
const { forward, backward, leftward, rightward, shift } = prop.control;
|
|
11
|
+
|
|
12
|
+
const boost = Number(shift);
|
|
13
|
+
const upDown = Number(backward) - Number(forward);
|
|
14
|
+
const leftRight = Number(rightward) - Number(leftward);
|
|
15
|
+
const front = V3().set(boost, boost, boost);
|
|
16
|
+
activeState.euler.y += (Number(leftward) - Number(rightward)) * 0.02;
|
|
17
|
+
|
|
18
|
+
const X = Math.PI * 0.01 * upDown;
|
|
19
|
+
const Z = Math.PI * 0.005 * leftRight;
|
|
20
|
+
|
|
21
|
+
const _x = innerGroupRef.current.rotation.x;
|
|
22
|
+
const _z = innerGroupRef.current.rotation.z;
|
|
23
|
+
|
|
24
|
+
const maxX = Math.PI / 16;
|
|
25
|
+
const maxZ = Math.PI / 16;
|
|
26
|
+
|
|
27
|
+
if (_x < -maxX) innerGroupRef.current.rotation.x = -maxX + X;
|
|
28
|
+
else if (_x > maxX) innerGroupRef.current.rotation.x = maxX + X;
|
|
29
|
+
else innerGroupRef.current.rotateX(X);
|
|
30
|
+
|
|
31
|
+
if (_z < -maxZ) innerGroupRef.current.rotation.z = -maxZ + Z;
|
|
32
|
+
else if (_z > maxZ) innerGroupRef.current.rotation.z = maxZ + Z;
|
|
33
|
+
else innerGroupRef.current.rotateZ(Z);
|
|
34
|
+
|
|
35
|
+
// current.dir = V3(
|
|
36
|
+
// Math.sin(current.euler.y),
|
|
37
|
+
// 0,
|
|
38
|
+
// Math.cos(current.euler.y)
|
|
39
|
+
// ).normalize();
|
|
40
|
+
// current.direction = front
|
|
41
|
+
// .multiply(current.dir)
|
|
42
|
+
// .multiplyScalar(shift ? accelRate : 1);
|
|
43
|
+
activeState.direction = front.multiply(
|
|
44
|
+
V3(Math.sin(activeState.euler.y), -upDown, Math.cos(activeState.euler.y))
|
|
45
|
+
);
|
|
46
|
+
activeState.dir = activeState.direction.normalize();
|
|
47
|
+
|
|
48
|
+
// const pitch = Number(forward) - Number(backward);
|
|
49
|
+
// // const front = vec3().set(start, start * 1, start);
|
|
50
|
+
// const yaw = Number(leftward) - Number(rightward);
|
|
51
|
+
//
|
|
52
|
+
// // activeState.euler.y += (side * Math.PI) / 64;
|
|
53
|
+
//
|
|
54
|
+
// // if (euler.x > Math.PI / 16) euler.x = Math.PI / 16 - 0.005;
|
|
55
|
+
// // else if (euler.x < -Math.PI / 16) euler.x = -Math.PI / 16 + 0.005;
|
|
56
|
+
// // if (euler.z > Math.PI / 16) euler.z = Math.PI / 16 - 0.005;
|
|
57
|
+
// // else if (euler.z < -Math.PI / 16) euler.z = -Math.PI / 16 + 0.005;
|
|
58
|
+
// // if (euler.y > Math.PI / 4) euler.y = Math.PI / 4 - 0.005;
|
|
59
|
+
// // else if (euler.y < -Math.PI / 4) euler.y = -Math.PI / 4 + 0.005;
|
|
60
|
+
//
|
|
61
|
+
// const delta = Math.PI * 0.005;
|
|
62
|
+
// euler.x += pitch * delta * Math.cos(euler.z) * Math.cos(euler.y);
|
|
63
|
+
// euler.z += -yaw * delta;
|
|
64
|
+
// euler.y += pitch * delta * Math.sin(euler.z) * Math.sin(euler.y);
|
|
65
|
+
//
|
|
66
|
+
// // activeState.direction = front.multiply(
|
|
67
|
+
// // V3(Math.sin(activeState.euler.y), 1, Math.cos(activeState.euler.y))
|
|
68
|
+
// // );
|
|
69
|
+
// // activeState.dir = activeState.direction.normalize();
|
|
70
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { calcPropType } from "../type";
|
|
2
|
+
|
|
3
|
+
export default function gravity(prop: calcPropType) {
|
|
4
|
+
const { rigidBodyRef, groundRay } = prop;
|
|
5
|
+
|
|
6
|
+
if (groundRay.hit) {
|
|
7
|
+
rigidBodyRef.current.setGravityScale(1, false);
|
|
8
|
+
} else {
|
|
9
|
+
rigidBodyRef.current.setGravityScale(0.2, false);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { vec3 } from "@react-three/rapier";
|
|
2
|
+
import { calcPropType } from "../type";
|
|
3
|
+
|
|
4
|
+
export default function impulse(prop: calcPropType) {
|
|
5
|
+
const {
|
|
6
|
+
rigidBodyRef,
|
|
7
|
+
constant,
|
|
8
|
+
control,
|
|
9
|
+
worldContext: { activeState },
|
|
10
|
+
} = prop;
|
|
11
|
+
const { shift } = control;
|
|
12
|
+
const { accelRate } = constant;
|
|
13
|
+
|
|
14
|
+
rigidBodyRef.current.applyImpulse(
|
|
15
|
+
vec3({
|
|
16
|
+
x: activeState.direction.x,
|
|
17
|
+
y: activeState.direction.y,
|
|
18
|
+
z: activeState.direction.z,
|
|
19
|
+
}),
|
|
20
|
+
false
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { calcPropType } from "../type";
|
|
2
|
+
import currentSetting from "./currentSetting";
|
|
3
|
+
import damping from "./damping";
|
|
4
|
+
import direction from "./direction";
|
|
5
|
+
import gravity from "./gravity";
|
|
6
|
+
import impulse from "./impulse";
|
|
7
|
+
import turn from "./turn";
|
|
8
|
+
|
|
9
|
+
export default function airplaneCalculation(calcProp: calcPropType) {
|
|
10
|
+
direction(calcProp);
|
|
11
|
+
turn(calcProp);
|
|
12
|
+
impulse(calcProp);
|
|
13
|
+
damping(calcProp);
|
|
14
|
+
gravity(calcProp);
|
|
15
|
+
currentSetting(calcProp);
|
|
16
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { calcPropType } from "../type";
|
|
2
|
+
|
|
3
|
+
export default function turn(prop: calcPropType) {
|
|
4
|
+
const {
|
|
5
|
+
rigidBodyRef,
|
|
6
|
+
innerGroupRef,
|
|
7
|
+
worldContext: { activeState },
|
|
8
|
+
} = prop;
|
|
9
|
+
|
|
10
|
+
activeState.quat.setFromEuler(activeState.euler);
|
|
11
|
+
rigidBodyRef.current.setRotation(activeState.quat, true);
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { vec3 } from "@react-three/rapier";
|
|
2
|
+
import { calcPropType } from "../type";
|
|
3
|
+
|
|
4
|
+
export default function currentSetting(prop: calcPropType) {
|
|
5
|
+
const {
|
|
6
|
+
rigidBodyRef,
|
|
7
|
+
worldContext: { activeState },
|
|
8
|
+
dispatch,
|
|
9
|
+
} = prop;
|
|
10
|
+
activeState.position = vec3(rigidBodyRef.current.translation());
|
|
11
|
+
activeState.velocity = vec3(rigidBodyRef.current.linvel());
|
|
12
|
+
dispatch({
|
|
13
|
+
type: "update",
|
|
14
|
+
payload: {
|
|
15
|
+
activeState: {
|
|
16
|
+
...activeState,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import { calcPropType } from "../type";
|
|
3
|
+
|
|
4
|
+
export default function direction(prop: calcPropType) {
|
|
5
|
+
const {
|
|
6
|
+
rigidBodyRef,
|
|
7
|
+
worldContext: { activeState },
|
|
8
|
+
} = prop;
|
|
9
|
+
const { forward, backward, leftward, rightward } = prop.control;
|
|
10
|
+
const maxVelocity = 0.04;
|
|
11
|
+
activeState.yaw *= 0.95;
|
|
12
|
+
activeState.pitch *= 0.95;
|
|
13
|
+
if (Math.abs(activeState.yaw) > maxVelocity)
|
|
14
|
+
activeState.yaw = Math.sign(activeState.yaw) * maxVelocity;
|
|
15
|
+
|
|
16
|
+
if (Math.abs(activeState.pitch) > maxVelocity)
|
|
17
|
+
activeState.pitch = Math.sign(activeState.pitch) * maxVelocity;
|
|
18
|
+
activeState.yaw += (Number(rightward) - Number(leftward)) * 0.0025;
|
|
19
|
+
activeState.pitch += (Number(backward) - Number(forward)) * 0.0025;
|
|
20
|
+
|
|
21
|
+
activeState.axisX.applyAxisAngle(activeState.axisZ, activeState.yaw);
|
|
22
|
+
activeState.axisY.applyAxisAngle(activeState.axisX, activeState.pitch);
|
|
23
|
+
activeState.axisY.applyAxisAngle(activeState.axisZ, activeState.yaw);
|
|
24
|
+
activeState.axisZ.applyAxisAngle(activeState.axisX, activeState.pitch);
|
|
25
|
+
activeState.axisX.normalize();
|
|
26
|
+
activeState.axisY.normalize();
|
|
27
|
+
activeState.axisZ.normalize();
|
|
28
|
+
const rotMatrix = new THREE.Matrix4().makeBasis(
|
|
29
|
+
activeState.axisX,
|
|
30
|
+
activeState.axisY,
|
|
31
|
+
activeState.axisZ
|
|
32
|
+
);
|
|
33
|
+
activeState.position.add(activeState.axisZ.clone().multiplyScalar(0.1));
|
|
34
|
+
const matrix = new THREE.Matrix4()
|
|
35
|
+
.multiply(
|
|
36
|
+
new THREE.Matrix4().makeTranslation(
|
|
37
|
+
activeState.position.x,
|
|
38
|
+
activeState.position.y,
|
|
39
|
+
activeState.position.z
|
|
40
|
+
)
|
|
41
|
+
)
|
|
42
|
+
.multiply(rotMatrix);
|
|
43
|
+
|
|
44
|
+
// rigidBodyRef.current.setTranslation(
|
|
45
|
+
// vec3().setFromMatrixPosition(matrix),
|
|
46
|
+
// true
|
|
47
|
+
// );
|
|
48
|
+
// rigidBodyRef.current.setRotation(
|
|
49
|
+
// new THREE.Quaternion().setFromRotationMatrix(matrix),
|
|
50
|
+
// true
|
|
51
|
+
// );
|
|
52
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { calcPropType } from "../type";
|
|
2
|
+
|
|
3
|
+
export default function impulse(prop: calcPropType) {
|
|
4
|
+
const { rigidBodyRef, constant, control, outerGroupRef } = prop;
|
|
5
|
+
const { accelRate } = constant;
|
|
6
|
+
const { shift } = control;
|
|
7
|
+
// current.direction.multiplyScalar(shift ? accelRate : 1);
|
|
8
|
+
// current.position.setFrom
|
|
9
|
+
// rigidBodyRef.current.applyImpulse(
|
|
10
|
+
// V30()
|
|
11
|
+
// .addScalar(shift ? 1 : 0)
|
|
12
|
+
// .multiply(
|
|
13
|
+
// vec3({
|
|
14
|
+
// x: current.direction.x,
|
|
15
|
+
// y: current.direction.y,
|
|
16
|
+
// z: current.direction.z,
|
|
17
|
+
// })
|
|
18
|
+
// ),
|
|
19
|
+
// false
|
|
20
|
+
// );
|
|
21
|
+
// current.position.setFromEuler(current.euler);
|
|
22
|
+
|
|
23
|
+
// setCurrent((current) => ({
|
|
24
|
+
// ...current,
|
|
25
|
+
// position: vec3(rigidBodyRef.current!.translation()),
|
|
26
|
+
// velocity: vec3(rigidBodyRef.current!.linvel()),
|
|
27
|
+
// }));
|
|
28
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { calcPropType } from "../type";
|
|
2
|
+
import currentSetting from "./currentSetting";
|
|
3
|
+
import direction from "./direction";
|
|
4
|
+
import gravity from "./gravity";
|
|
5
|
+
import impulse from "./impulse";
|
|
6
|
+
import turn from "./turn";
|
|
7
|
+
|
|
8
|
+
export default function airplaneCalculation(calcProp: calcPropType) {
|
|
9
|
+
direction(calcProp);
|
|
10
|
+
turn(calcProp);
|
|
11
|
+
impulse(calcProp);
|
|
12
|
+
gravity(calcProp);
|
|
13
|
+
currentSetting(calcProp);
|
|
14
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { calcPropType } from "../type";
|
|
2
|
+
|
|
3
|
+
export default function turn(prop: calcPropType) {
|
|
4
|
+
// const [current] = prop.current;
|
|
5
|
+
// const { constant, rigidBodyRef } = prop;
|
|
6
|
+
// const { turnSpeed } = constant;
|
|
7
|
+
// current.quat.setFromEuler(current.euler);
|
|
8
|
+
// rigidBodyRef.current.setRotation(current.quat, false);
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { vec3 } from "@react-three/rapier";
|
|
2
|
+
import { calcPropType } from "../type";
|
|
3
|
+
|
|
4
|
+
export default function accelaration(prop: calcPropType) {
|
|
5
|
+
const {
|
|
6
|
+
constant: { walkSpeed, runSpeed },
|
|
7
|
+
worldContext: { states, activeState },
|
|
8
|
+
} = prop;
|
|
9
|
+
const { isMoving, isRunning } = states;
|
|
10
|
+
if (!isMoving) return null;
|
|
11
|
+
const speed = isRunning ? runSpeed : walkSpeed;
|
|
12
|
+
const velocity = vec3().addScalar(speed).multiply(activeState.dir);
|
|
13
|
+
activeState.acceleration.copy(velocity).sub(activeState.velocity);
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { vec3 } from "@react-three/rapier";
|
|
2
|
+
import { calcPropType } from "../type";
|
|
3
|
+
|
|
4
|
+
export default function currentSetting(prop: calcPropType) {
|
|
5
|
+
const {
|
|
6
|
+
rigidBodyRef,
|
|
7
|
+
worldContext: { activeState },
|
|
8
|
+
dispatch,
|
|
9
|
+
} = prop;
|
|
10
|
+
activeState.position = vec3(rigidBodyRef.current.translation());
|
|
11
|
+
activeState.velocity = vec3(rigidBodyRef.current.linvel());
|
|
12
|
+
dispatch({
|
|
13
|
+
type: "update",
|
|
14
|
+
payload: {
|
|
15
|
+
activeState: {
|
|
16
|
+
...activeState,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|