gaesup-world 0.1.3 → 0.2.0
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 +220 -228
- package/dist/gaesup/animation/actions.d.ts +29 -13
- package/dist/gaesup/animation/actions.js +33 -60
- package/dist/gaesup/camera/index.js +1 -2
- package/dist/gaesup/component/active/airplane/index.d.ts +9 -3
- package/dist/gaesup/component/active/airplane/index.js +3 -7
- package/dist/gaesup/component/active/character/index.d.ts +3 -1
- package/dist/gaesup/component/active/character/index.js +29 -11
- package/dist/gaesup/component/active/vehicle/index.d.ts +10 -3
- package/dist/gaesup/component/active/vehicle/index.js +29 -9
- package/dist/gaesup/component/index.d.ts +3 -1
- package/dist/gaesup/component/index.js +9 -3
- package/dist/gaesup/component/inner/airplane/index.d.ts +2 -0
- package/dist/gaesup/component/inner/airplane/index.js +16 -0
- package/dist/gaesup/component/inner/character/index.d.ts +25 -0
- package/dist/gaesup/component/inner/character/index.js +28 -0
- package/dist/gaesup/component/{passive → inner}/common/InnerGroupRef.d.ts +2 -0
- package/dist/gaesup/component/{passive → inner}/common/InnerGroupRef.js +12 -10
- package/dist/gaesup/component/{passive → inner}/common/RigidbodyRef.d.ts +4 -0
- package/dist/gaesup/component/inner/common/RigidbodyRef.js +7 -0
- package/dist/gaesup/component/inner/common/setGroundRay.d.ts +9 -0
- package/dist/gaesup/component/inner/common/setGroundRay.js +14 -0
- package/dist/gaesup/component/inner/common/type.d.ts +20 -0
- package/dist/gaesup/component/inner/rider/index.d.ts +11 -0
- package/dist/gaesup/component/inner/rider/index.js +31 -0
- package/dist/gaesup/component/inner/vehicle/collider.d.ts +10 -0
- package/dist/gaesup/component/inner/vehicle/collider.js +19 -0
- package/dist/gaesup/component/inner/vehicle/index.d.ts +2 -0
- package/dist/gaesup/component/inner/vehicle/index.js +17 -0
- package/dist/gaesup/component/inner/vehicle/wheels.d.ts +7 -0
- package/dist/gaesup/component/inner/vehicle/wheels.js +64 -0
- package/dist/gaesup/component/passive/airplane/index.d.ts +12 -1
- package/dist/gaesup/component/passive/airplane/index.js +6 -9
- package/dist/gaesup/component/passive/character/index.d.ts +9 -1
- package/dist/gaesup/component/passive/character/index.js +16 -9
- package/dist/gaesup/component/passive/type.d.ts +1 -11
- package/dist/gaesup/component/passive/vehicle/index.d.ts +12 -1
- package/dist/gaesup/component/passive/vehicle/index.js +6 -25
- package/dist/gaesup/controller/context/index.d.ts +7 -3
- package/dist/gaesup/controller/context/index.js +7 -3
- package/dist/gaesup/controller/context/reducer.d.ts +1 -1
- package/dist/gaesup/controller/index.js +5 -8
- package/dist/gaesup/controller/initialize/callback/index.d.ts +1 -1
- package/dist/gaesup/controller/initialize/callback/index.js +61 -54
- package/dist/gaesup/controller/initialize/index.d.ts +1 -2
- package/dist/gaesup/controller/initialize/index.js +1 -14
- package/dist/gaesup/controller/type.d.ts +3 -6
- package/dist/gaesup/gaesupProps/index.js +1 -1
- package/dist/gaesup/hooks/useGaesupAnimation/index.d.ts +3 -1
- package/dist/gaesup/hooks/useGaesupAnimation/index.js +17 -16
- package/dist/gaesup/hooks/useGaesupController/index.d.ts +2 -5
- package/dist/gaesup/hooks/useGaesupController/index.js +4 -5
- package/dist/gaesup/hooks/useGaesupGltf/index.d.ts +25 -0
- package/dist/gaesup/hooks/useGaesupGltf/index.js +73 -0
- package/dist/gaesup/hooks/useRideable/index.js +36 -35
- package/dist/gaesup/physics/airplane/direction.d.ts +1 -1
- package/dist/gaesup/physics/airplane/direction.js +3 -1
- package/dist/gaesup/physics/airplane/gravity.js +1 -1
- package/dist/gaesup/physics/airplane/landing.js +1 -1
- package/dist/gaesup/physics/check/ground.js +3 -3
- package/dist/gaesup/physics/check/index.js +0 -2
- package/dist/gaesup/physics/check/riding.js +3 -3
- package/dist/gaesup/physics/index.js +8 -6
- package/dist/gaesup/physics/type.d.ts +4 -1
- package/dist/gaesup/physics/vehicle/impulse.d.ts +15 -1
- package/dist/gaesup/physics/vehicle/impulse.js +32 -12
- package/dist/gaesup/physics/vehicle/innerCalc.js +1 -1
- package/dist/gaesup/physics/vehicle/landing.js +1 -1
- package/dist/gaesup/tools/joyStick/index.d.ts +1 -1
- package/dist/gaesup/tools/keyBoardToolTip/index.js +3 -3
- package/dist/gaesup/tools/rideable/index.js +5 -6
- package/dist/gaesup/tools/zoomButton/index.js +5 -3
- package/dist/gaesup/world/context/index.js +27 -62
- package/dist/gaesup/world/context/reducer.d.ts +7 -12
- package/dist/gaesup/world/context/type.d.ts +36 -49
- package/dist/gaesup/world/debug/index.d.ts +6 -2
- package/dist/gaesup/world/initalize/index.d.ts +7 -12
- package/dist/gaesup/world/initalize/index.js +8 -15
- package/dist/gaesup/world/type.d.ts +3 -8
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/package.json +1 -1
- package/dist/gaesup/animation/index.d.ts +0 -1
- package/dist/gaesup/animation/index.js +0 -1
- package/dist/gaesup/animation/passiveActions.d.ts +0 -9
- package/dist/gaesup/animation/passiveActions.js +0 -16
- package/dist/gaesup/component/active/airplane/collider.d.ts +0 -6
- package/dist/gaesup/component/active/airplane/collider.js +0 -22
- package/dist/gaesup/component/active/character/collider.d.ts +0 -6
- package/dist/gaesup/component/active/character/collider.js +0 -24
- package/dist/gaesup/component/active/common/InnerGroupRef.d.ts +0 -10
- package/dist/gaesup/component/active/common/InnerGroupRef.js +0 -35
- package/dist/gaesup/component/active/common/OuterGroupRef.d.ts +0 -6
- package/dist/gaesup/component/active/common/OuterGroupRef.js +0 -17
- package/dist/gaesup/component/active/common/RiderGroupRef.d.ts +0 -7
- package/dist/gaesup/component/active/common/RiderGroupRef.js +0 -32
- package/dist/gaesup/component/active/common/RigidbodyRef.d.ts +0 -11
- package/dist/gaesup/component/active/common/RigidbodyRef.js +0 -22
- package/dist/gaesup/component/active/common/WrapperRef.d.ts +0 -13
- package/dist/gaesup/component/active/common/WrapperRef.js +0 -9
- package/dist/gaesup/component/active/common/slopeRayRef.d.ts +0 -6
- package/dist/gaesup/component/active/common/slopeRayRef.js +0 -10
- package/dist/gaesup/component/active/vehicle/collider.d.ts +0 -3
- package/dist/gaesup/component/active/vehicle/collider.js +0 -9
- package/dist/gaesup/component/active/vehicle/wheel.d.ts +0 -12
- package/dist/gaesup/component/active/vehicle/wheel.js +0 -13
- package/dist/gaesup/component/active/vehicle/wheels.d.ts +0 -7
- package/dist/gaesup/component/active/vehicle/wheels.js +0 -20
- package/dist/gaesup/component/passive/airplane/collider.d.ts +0 -5
- package/dist/gaesup/component/passive/airplane/collider.js +0 -7
- package/dist/gaesup/component/passive/airplane/type.d.ts +0 -12
- package/dist/gaesup/component/passive/character/collider.d.ts +0 -6
- package/dist/gaesup/component/passive/character/collider.js +0 -7
- package/dist/gaesup/component/passive/character/type.d.ts +0 -27
- package/dist/gaesup/component/passive/character/type.js +0 -1
- package/dist/gaesup/component/passive/common/RigidbodyRef.js +0 -10
- package/dist/gaesup/component/passive/vehicle/type.d.ts +0 -21
- package/dist/gaesup/component/passive/vehicle/type.js +0 -1
- package/dist/gaesup/component/passive/vehicle/wheel.d.ts +0 -15
- package/dist/gaesup/component/passive/vehicle/wheel.js +0 -16
- package/dist/gaesup/component/passive/vehicle/wheels.d.ts +0 -11
- package/dist/gaesup/component/passive/vehicle/wheels.js +0 -25
- package/dist/gaesup/physics/check/slope.d.ts +0 -2
- package/dist/gaesup/physics/check/slope.js +0 -30
- package/dist/gaesup/utils/gltf.d.ts +0 -7
- package/dist/gaesup/utils/gltf.js +0 -10
- package/dist/gaesup/world/initalize/collider/airplane.d.ts +0 -2
- package/dist/gaesup/world/initalize/collider/airplane.js +0 -25
- package/dist/gaesup/world/initalize/collider/character.d.ts +0 -2
- package/dist/gaesup/world/initalize/collider/character.js +0 -27
- package/dist/gaesup/world/initalize/collider/gltf.d.ts +0 -14
- package/dist/gaesup/world/initalize/collider/gltf.js +0 -54
- package/dist/gaesup/world/initalize/collider/index.d.ts +0 -2
- package/dist/gaesup/world/initalize/collider/index.js +0 -17
- package/dist/gaesup/world/initalize/collider/vehicle.d.ts +0 -2
- package/dist/gaesup/world/initalize/collider/vehicle.js +0 -55
- package/dist/gaesup/world/initalize/type.d.ts +0 -13
- package/dist/gaesup/world/initalize/type.js +0 -1
- /package/dist/gaesup/component/{passive → inner}/common/OuterGroupRef.d.ts +0 -0
- /package/dist/gaesup/component/{passive → inner}/common/OuterGroupRef.js +0 -0
- /package/dist/gaesup/component/{passive/airplane → inner/common}/type.js +0 -0
|
@@ -11,23 +11,24 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
};
|
|
12
12
|
import { useContext } from "react";
|
|
13
13
|
import { GaesupWorldContext, GaesupWorldDispatchContext, } from "../../world/context";
|
|
14
|
-
export function useGaesupAnimation() {
|
|
15
|
-
var
|
|
14
|
+
export function useGaesupAnimation(_a) {
|
|
15
|
+
var type = _a.type;
|
|
16
|
+
var animationState = useContext(GaesupWorldContext).animationState;
|
|
16
17
|
var dispatch = useContext(GaesupWorldDispatchContext);
|
|
17
18
|
var getAnimationTag = function (tag) {
|
|
18
|
-
var animation =
|
|
19
|
+
var animation = animationState[type].store[tag];
|
|
19
20
|
if (!animation)
|
|
20
|
-
return { name:
|
|
21
|
+
return { name: animationState[type].default, isValid: false };
|
|
21
22
|
if (animation.condition()) {
|
|
22
23
|
return { name: animation.animationName, isValid: true };
|
|
23
24
|
}
|
|
24
25
|
else {
|
|
25
|
-
return { name:
|
|
26
|
+
return { name: animationState[type].default, isValid: false };
|
|
26
27
|
}
|
|
27
28
|
};
|
|
28
29
|
var notify = function () {
|
|
29
|
-
var tag =
|
|
30
|
-
for (var _i = 0, _a = Object.keys(
|
|
30
|
+
var tag = animationState[type].default;
|
|
31
|
+
for (var _i = 0, _a = Object.keys(animationState[type].store); _i < _a.length; _i++) {
|
|
31
32
|
var key = _a[_i];
|
|
32
33
|
var checked = getAnimationTag(key);
|
|
33
34
|
if (checked.isValid) {
|
|
@@ -35,27 +36,27 @@ export function useGaesupAnimation() {
|
|
|
35
36
|
break;
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
animationState[type].current = tag;
|
|
39
40
|
dispatch({
|
|
40
41
|
type: "update",
|
|
41
42
|
payload: {
|
|
42
|
-
|
|
43
|
+
animationState: __assign({}, animationState),
|
|
43
44
|
},
|
|
44
45
|
});
|
|
45
46
|
return tag;
|
|
46
47
|
};
|
|
47
48
|
var unsubscribe = function (tag) {
|
|
48
|
-
delete
|
|
49
|
+
delete animationState[type].store[tag];
|
|
49
50
|
dispatch({
|
|
50
51
|
type: "update",
|
|
51
52
|
payload: {
|
|
52
|
-
|
|
53
|
+
animationState: __assign({}, animationState),
|
|
53
54
|
},
|
|
54
55
|
});
|
|
55
56
|
};
|
|
56
57
|
var subscribe = function (_a) {
|
|
57
58
|
var tag = _a.tag, condition = _a.condition, action = _a.action, animationName = _a.animationName, key = _a.key;
|
|
58
|
-
|
|
59
|
+
animationState[type].store[tag] = {
|
|
59
60
|
condition: condition,
|
|
60
61
|
action: action || (function () { }),
|
|
61
62
|
animationName: animationName || tag,
|
|
@@ -64,13 +65,13 @@ export function useGaesupAnimation() {
|
|
|
64
65
|
dispatch({
|
|
65
66
|
type: "update",
|
|
66
67
|
payload: {
|
|
67
|
-
|
|
68
|
+
animationState: __assign({}, animationState),
|
|
68
69
|
},
|
|
69
70
|
});
|
|
70
71
|
};
|
|
71
72
|
var subscribeAll = function (props) {
|
|
72
73
|
props.forEach(function (item) {
|
|
73
|
-
|
|
74
|
+
animationState[type].store[item.tag] = {
|
|
74
75
|
condition: item.condition,
|
|
75
76
|
action: item.action,
|
|
76
77
|
animationName: item.animationName,
|
|
@@ -80,14 +81,14 @@ export function useGaesupAnimation() {
|
|
|
80
81
|
dispatch({
|
|
81
82
|
type: "update",
|
|
82
83
|
payload: {
|
|
83
|
-
|
|
84
|
+
animationState: __assign({}, animationState),
|
|
84
85
|
},
|
|
85
86
|
});
|
|
86
87
|
};
|
|
87
88
|
return {
|
|
88
89
|
subscribe: subscribe,
|
|
89
90
|
subscribeAll: subscribeAll,
|
|
90
|
-
store:
|
|
91
|
+
store: animationState[type].store,
|
|
91
92
|
unsubscribe: unsubscribe,
|
|
92
93
|
notify: notify,
|
|
93
94
|
};
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { activeStateType,
|
|
2
|
+
import { activeStateType, modeType, urlsType } from "../../world/context/type";
|
|
3
3
|
export declare function useGaesupController(): gaesupPassivePropsType;
|
|
4
4
|
export type gaesupPassivePropsType = {
|
|
5
5
|
state: activeStateType;
|
|
6
|
-
vehicleCollider: vehicleColliderType;
|
|
7
|
-
characterCollider?: characterColliderType;
|
|
8
|
-
airplaneCollider?: airplaneColliderType;
|
|
9
6
|
mode: modeType;
|
|
10
|
-
|
|
7
|
+
urls: urlsType;
|
|
11
8
|
currentAnimation: string;
|
|
12
9
|
children?: React.ReactNode;
|
|
13
10
|
};
|
|
@@ -5,11 +5,10 @@ export function useGaesupController() {
|
|
|
5
5
|
var worldContext = useContext(GaesupWorldContext);
|
|
6
6
|
return {
|
|
7
7
|
state: worldContext.activeState,
|
|
8
|
-
vehicleCollider: worldContext.vehicleCollider,
|
|
9
|
-
characterCollider: worldContext.characterCollider,
|
|
10
|
-
airplaneCollider: worldContext.airplaneCollider,
|
|
11
8
|
mode: worldContext.mode,
|
|
12
|
-
|
|
13
|
-
currentAnimation: worldContext.
|
|
9
|
+
urls: worldContext.urls,
|
|
10
|
+
currentAnimation: worldContext.mode.type
|
|
11
|
+
? worldContext.animationState[worldContext.mode.type].current
|
|
12
|
+
: "idle",
|
|
14
13
|
};
|
|
15
14
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import { GLTFResult } from "../../component/type";
|
|
3
|
+
import { urlsType } from "../../world/context/type";
|
|
4
|
+
export type gltfAndSizeType = {
|
|
5
|
+
size: THREE.Vector3;
|
|
6
|
+
setSize: (size: THREE.Vector3, keyName?: string) => void;
|
|
7
|
+
getSize: () => THREE.Vector3;
|
|
8
|
+
};
|
|
9
|
+
export type useGltfAndSizeType = {
|
|
10
|
+
url: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const useGltfAndSize: ({ url }: useGltfAndSizeType) => {
|
|
13
|
+
gltf: GLTFResult;
|
|
14
|
+
size: THREE.Vector3;
|
|
15
|
+
setSize: (size?: THREE.Vector3, keyName?: string) => THREE.Vector3;
|
|
16
|
+
getSize: (keyName?: string) => THREE.Vector3;
|
|
17
|
+
};
|
|
18
|
+
export declare const useGaesupGltf: () => {
|
|
19
|
+
getSizesByUrls: (urls?: urlsType) => {
|
|
20
|
+
characterUrl?: THREE.Vector3;
|
|
21
|
+
vehicleUrl?: THREE.Vector3;
|
|
22
|
+
airplaneUrl?: THREE.Vector3;
|
|
23
|
+
wheelUrl?: THREE.Vector3;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { useGLTF } from "@react-three/drei";
|
|
13
|
+
import { useContext } from "react";
|
|
14
|
+
import * as THREE from "three";
|
|
15
|
+
import { GaesupWorldContext, GaesupWorldDispatchContext, } from "../../world/context";
|
|
16
|
+
export var useGltfAndSize = function (_a) {
|
|
17
|
+
var url = _a.url;
|
|
18
|
+
var sizes = useContext(GaesupWorldContext).sizes;
|
|
19
|
+
var dispatch = useContext(GaesupWorldDispatchContext);
|
|
20
|
+
var gltf = useGLTF(url);
|
|
21
|
+
var scene = gltf.scene;
|
|
22
|
+
var makeGltfSize = function () {
|
|
23
|
+
return new THREE.Box3().setFromObject(scene).getSize(new THREE.Vector3());
|
|
24
|
+
};
|
|
25
|
+
// getter
|
|
26
|
+
var getSize = function (keyName) {
|
|
27
|
+
var key = keyName || url;
|
|
28
|
+
if (key in sizes) {
|
|
29
|
+
return sizes[key];
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
// setter
|
|
36
|
+
var setSize = function (size, keyName) {
|
|
37
|
+
var key = keyName || url;
|
|
38
|
+
if (!(key in sizes)) {
|
|
39
|
+
sizes[key] = size || makeGltfSize();
|
|
40
|
+
dispatch({
|
|
41
|
+
type: "update",
|
|
42
|
+
payload: {
|
|
43
|
+
sizes: __assign({}, sizes),
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
return sizes[key];
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return sizes[key];
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
return { gltf: gltf, size: setSize(), setSize: setSize, getSize: getSize };
|
|
53
|
+
};
|
|
54
|
+
export var useGaesupGltf = function () {
|
|
55
|
+
var sizes = useContext(GaesupWorldContext).sizes;
|
|
56
|
+
// get size by url
|
|
57
|
+
var getSizesByUrls = function (urls) {
|
|
58
|
+
var matchedSizes = {};
|
|
59
|
+
if (!urls)
|
|
60
|
+
return matchedSizes;
|
|
61
|
+
Object.keys(urls).forEach(function (key) {
|
|
62
|
+
var url = urls[key];
|
|
63
|
+
if (url in sizes) {
|
|
64
|
+
matchedSizes[key] = sizes[url];
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
matchedSizes[key] = null;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return matchedSizes;
|
|
71
|
+
};
|
|
72
|
+
return { getSizesByUrls: getSizesByUrls };
|
|
73
|
+
};
|
|
@@ -47,8 +47,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
47
47
|
};
|
|
48
48
|
import { euler, vec3 } from "@react-three/rapier";
|
|
49
49
|
import { useContext } from "react";
|
|
50
|
-
import { V3 } from "../../utils";
|
|
51
50
|
import { GaesupWorldContext, GaesupWorldDispatchContext, } from "../../world/context";
|
|
51
|
+
import { useGaesupGltf } from "../useGaesupGltf";
|
|
52
52
|
/**
|
|
53
53
|
* Default rideable object properties.
|
|
54
54
|
* @type {Object}
|
|
@@ -71,20 +71,22 @@ export var rideableDefault = {
|
|
|
71
71
|
export function useRideable() {
|
|
72
72
|
var _this = this;
|
|
73
73
|
var worldContext = useContext(GaesupWorldContext);
|
|
74
|
+
var urls = worldContext.urls, states = worldContext.states, rideable = worldContext.rideable, mode = worldContext.mode;
|
|
74
75
|
var dispatch = useContext(GaesupWorldDispatchContext);
|
|
76
|
+
var getSizesByUrls = useGaesupGltf().getSizesByUrls;
|
|
75
77
|
/**
|
|
76
78
|
* Initialize a rideable object with the provided properties.
|
|
77
79
|
* @param {rideableType} props - The properties of the rideable object to initialize.
|
|
78
80
|
*/
|
|
79
81
|
var initRideable = function (props) {
|
|
80
|
-
|
|
82
|
+
rideable[props.objectkey] = __assign(__assign({}, rideableDefault), props);
|
|
81
83
|
};
|
|
82
84
|
/**
|
|
83
85
|
* Set the properties of a rideable object.
|
|
84
86
|
* @param {rideableType} props - The properties to set for the rideable object.
|
|
85
87
|
*/
|
|
86
88
|
var setRideable = function (props) {
|
|
87
|
-
|
|
89
|
+
rideable[props.objectkey] = props;
|
|
88
90
|
};
|
|
89
91
|
/**
|
|
90
92
|
* Get the rideable object with the specified object key.
|
|
@@ -92,31 +94,34 @@ export function useRideable() {
|
|
|
92
94
|
* @returns {rideableType} The rideable object with the specified key.
|
|
93
95
|
*/
|
|
94
96
|
var getRideable = function (objectkey) {
|
|
95
|
-
return
|
|
97
|
+
return rideable[objectkey];
|
|
96
98
|
};
|
|
97
99
|
/**
|
|
98
100
|
* Handle landing of a rideable object.
|
|
99
101
|
* @param {string} objectkey - The key of the rideable object to land.
|
|
100
102
|
*/
|
|
101
103
|
var landing = function (objectkey) {
|
|
102
|
-
var activeState = worldContext.activeState,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
104
|
+
var activeState = worldContext.activeState, refs = worldContext.refs;
|
|
105
|
+
states.enableRiding = false;
|
|
106
|
+
states.isRiderOn = false;
|
|
107
|
+
states.rideableId = null;
|
|
108
|
+
var modeType = rideable[objectkey].objectType;
|
|
109
|
+
var _a = getSizesByUrls(urls), vehicleUrl = _a.vehicleUrl, airplaneUrl = _a.airplaneUrl, characterUrl = _a.characterUrl;
|
|
110
|
+
var size = modeType === "vehicle" ? vehicleUrl : airplaneUrl;
|
|
111
|
+
var mySize = characterUrl;
|
|
112
|
+
rideable[objectkey].visible = true;
|
|
113
|
+
rideable[objectkey].position.copy(activeState.position.clone());
|
|
114
|
+
if (refs && refs.rigidBodyRef) {
|
|
115
|
+
refs.rigidBodyRef.current.setTranslation(activeState.position
|
|
116
|
+
.clone()
|
|
117
|
+
.add(size.clone().add(mySize.clone()).addScalar(1)), false);
|
|
118
|
+
}
|
|
114
119
|
dispatch({
|
|
115
120
|
type: "update",
|
|
116
121
|
payload: {
|
|
117
|
-
rideable: __assign({},
|
|
118
|
-
states: __assign({},
|
|
119
|
-
|
|
122
|
+
rideable: __assign({}, rideable),
|
|
123
|
+
states: __assign({}, states),
|
|
124
|
+
activeState: __assign({}, activeState),
|
|
120
125
|
},
|
|
121
126
|
});
|
|
122
127
|
};
|
|
@@ -127,16 +132,16 @@ export function useRideable() {
|
|
|
127
132
|
var setUrl = function (props) { return __awaiter(_this, void 0, void 0, function () {
|
|
128
133
|
return __generator(this, function (_a) {
|
|
129
134
|
if (props.objectType === "vehicle") {
|
|
130
|
-
|
|
131
|
-
|
|
135
|
+
urls.vehicleUrl = props.url;
|
|
136
|
+
urls.wheelUrl = props.wheelUrl || null;
|
|
132
137
|
}
|
|
133
138
|
else if (props.objectType === "airplane") {
|
|
134
|
-
|
|
139
|
+
urls.airplaneUrl = props.url;
|
|
135
140
|
}
|
|
136
141
|
dispatch({
|
|
137
142
|
type: "update",
|
|
138
143
|
payload: {
|
|
139
|
-
|
|
144
|
+
urls: __assign({}, urls),
|
|
140
145
|
},
|
|
141
146
|
});
|
|
142
147
|
return [2 /*return*/];
|
|
@@ -147,21 +152,17 @@ export function useRideable() {
|
|
|
147
152
|
* @param {rideableType} props - The properties of the rideable object to set mode and riding state.
|
|
148
153
|
*/
|
|
149
154
|
var setModeAndRiding = function (props) { return __awaiter(_this, void 0, void 0, function () {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
worldContext.characterCollider.riderOffsetY = ((_b = props === null || props === void 0 ? void 0 : props.offset) === null || _b === void 0 ? void 0 : _b.y) || 0;
|
|
157
|
-
worldContext.characterCollider.riderOffsetZ = ((_c = props === null || props === void 0 ? void 0 : props.offset) === null || _c === void 0 ? void 0 : _c.z) || 0;
|
|
158
|
-
worldContext.rideable[props.objectkey].visible = false;
|
|
155
|
+
return __generator(this, function (_a) {
|
|
156
|
+
mode.type = props.objectType;
|
|
157
|
+
states.enableRiding = props.enableRiding;
|
|
158
|
+
states.isRiderOn = true;
|
|
159
|
+
states.rideableId = props.objectkey;
|
|
160
|
+
rideable[props.objectkey].visible = false;
|
|
159
161
|
dispatch({
|
|
160
162
|
type: "update",
|
|
161
163
|
payload: {
|
|
162
|
-
mode: __assign({},
|
|
163
|
-
states: __assign({},
|
|
164
|
-
characterCollider: __assign({}, worldContext.characterCollider),
|
|
164
|
+
mode: __assign({}, mode),
|
|
165
|
+
states: __assign({}, states),
|
|
165
166
|
},
|
|
166
167
|
});
|
|
167
168
|
return [2 /*return*/];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { calcPropType } from "../type";
|
|
2
|
-
export default function direction(prop: calcPropType):
|
|
2
|
+
export default function direction(prop: calcPropType): any;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { quat } from "@react-three/rapier";
|
|
2
2
|
import { V3 } from "../../utils/vector";
|
|
3
3
|
export default function direction(prop) {
|
|
4
|
-
var innerGroupRef = prop.innerGroupRef, _a = prop.worldContext, joystick = _a.joystick, activeState = _a.activeState, control = _a.control, mode = _a.mode, airplane = prop.controllerContext.airplane;
|
|
4
|
+
var innerGroupRef = prop.innerGroupRef, rigidBodyRef = prop.rigidBodyRef, _a = prop.worldContext, joystick = _a.joystick, activeState = _a.activeState, control = _a.control, mode = _a.mode, airplane = prop.controllerContext.airplane, matchSizes = prop.matchSizes;
|
|
5
5
|
var forward = control.forward, backward = control.backward, leftward = control.leftward, rightward = control.rightward, shift = control.shift, space = control.space;
|
|
6
6
|
var angleDelta = airplane.angleDelta, maxAngle = airplane.maxAngle, accelRatio = airplane.accelRatio;
|
|
7
|
+
if (!matchSizes || !matchSizes["airplaneUrl"])
|
|
8
|
+
return null;
|
|
7
9
|
var boost = 0;
|
|
8
10
|
if (mode.controller === "joystick") {
|
|
9
11
|
boost = space
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* Otherwise, gravity is set to 0.1.
|
|
12
12
|
*/
|
|
13
13
|
export default function gravity(prop) {
|
|
14
|
-
var rigidBodyRef = prop.rigidBodyRef, activeState = prop.worldContext.activeState;
|
|
14
|
+
var rigidBodyRef = prop.rigidBodyRef, activeState = prop.worldContext.activeState, matchSizes = prop.matchSizes;
|
|
15
15
|
rigidBodyRef.current.setGravityScale(activeState.position.y < 10
|
|
16
16
|
? ((1 - 0.1) / (0 - 10)) * activeState.position.y + 1
|
|
17
17
|
: 0.1, false);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { vec3 } from "@react-three/rapier";
|
|
2
2
|
export default function checkOnTheGround(prop) {
|
|
3
|
-
var
|
|
3
|
+
var colliderRef = prop.colliderRef, groundRay = prop.groundRay, _a = prop.worldContext, states = _a.states, activeState = _a.activeState;
|
|
4
4
|
groundRay.origin.addVectors(activeState.position, vec3(groundRay.offset));
|
|
5
|
-
if (!groundRay.hit || !groundRay.rayCast || !
|
|
5
|
+
if (!groundRay.hit || !groundRay.rayCast || !colliderRef.current) {
|
|
6
6
|
states.isOnTheGround = false;
|
|
7
7
|
return;
|
|
8
8
|
}
|
|
9
|
-
if (groundRay.hit.toi <
|
|
9
|
+
if (groundRay.hit.toi < groundRay.length + 0.5) {
|
|
10
10
|
states.isOnTheGround = true;
|
|
11
11
|
}
|
|
12
12
|
else {
|
|
@@ -3,10 +3,8 @@ import moving from "./moving";
|
|
|
3
3
|
import push from "./push";
|
|
4
4
|
import riding from "./riding";
|
|
5
5
|
import rotate from "./rotate";
|
|
6
|
-
import slope from "./slope";
|
|
7
6
|
export default function check(calcProp) {
|
|
8
7
|
ground(calcProp);
|
|
9
|
-
slope(calcProp);
|
|
10
8
|
moving(calcProp);
|
|
11
9
|
rotate(calcProp);
|
|
12
10
|
push(calcProp);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export default function riding(prop) {
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
if (
|
|
2
|
+
var states = prop.worldContext.states;
|
|
3
|
+
var isRiderOn = states.isRiderOn;
|
|
4
|
+
if (isRiderOn && states.isPush["keyR"]) {
|
|
5
5
|
states.isLanding = true;
|
|
6
6
|
}
|
|
7
7
|
}
|
|
@@ -9,10 +9,11 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
-
import {
|
|
12
|
+
import { useFrame } from "@react-three/fiber";
|
|
13
13
|
import { useRapier } from "@react-three/rapier";
|
|
14
|
+
import { useContext, useEffect } from "react";
|
|
14
15
|
import { GaesupControllerContext } from "../controller/context";
|
|
15
|
-
import {
|
|
16
|
+
import { useGaesupGltf } from "../hooks/useGaesupGltf";
|
|
16
17
|
import { V3 } from "../utils";
|
|
17
18
|
import { GaesupWorldContext, GaesupWorldDispatchContext, } from "../world/context";
|
|
18
19
|
import airplaneCalculation from "./airplane";
|
|
@@ -24,11 +25,12 @@ export default function calculation(prop) {
|
|
|
24
25
|
var worldContext = useContext(GaesupWorldContext);
|
|
25
26
|
var controllerContext = useContext(GaesupControllerContext);
|
|
26
27
|
var dispatch = useContext(GaesupWorldDispatchContext);
|
|
27
|
-
var mode = worldContext.mode, activeState = worldContext.activeState,
|
|
28
|
+
var mode = worldContext.mode, activeState = worldContext.activeState, block = worldContext.block;
|
|
29
|
+
var getSizesByUrls = useGaesupGltf().getSizesByUrls;
|
|
28
30
|
useEffect(function () {
|
|
29
31
|
var rigidBodyRef = prop.rigidBodyRef, innerGroupRef = prop.innerGroupRef;
|
|
30
32
|
if (rigidBodyRef.current && innerGroupRef.current) {
|
|
31
|
-
|
|
33
|
+
rigidBodyRef.current.lockRotations(false, true);
|
|
32
34
|
activeState.euler.set(0, 0, 0);
|
|
33
35
|
rigidBodyRef.current.setTranslation(activeState.position.clone().add(V3(0, 2, 0)), true);
|
|
34
36
|
}
|
|
@@ -42,9 +44,9 @@ export default function calculation(prop) {
|
|
|
42
44
|
!innerGroupRef ||
|
|
43
45
|
!innerGroupRef.current)
|
|
44
46
|
return null;
|
|
45
|
-
if (
|
|
47
|
+
if (block.control)
|
|
46
48
|
return null;
|
|
47
|
-
var calcProp = __assign(__assign({}, prop), { state: state, delta: delta, worldContext: worldContext, controllerContext: controllerContext, dispatch: dispatch, world: world });
|
|
49
|
+
var calcProp = __assign(__assign({}, prop), { state: state, delta: delta, worldContext: worldContext, controllerContext: controllerContext, dispatch: dispatch, world: world, matchSizes: getSizesByUrls(controllerContext === null || controllerContext === void 0 ? void 0 : controllerContext.urls) });
|
|
48
50
|
if (mode.type === "vehicle")
|
|
49
51
|
vehicleCalculation(calcProp);
|
|
50
52
|
else if (mode.type === "character")
|
|
@@ -3,7 +3,7 @@ import { World } from "@dimforge/rapier3d-compat";
|
|
|
3
3
|
import { gaesupControllerType } from "../controller/context/type";
|
|
4
4
|
import { controllerInnerType, refsType } from "../controller/type";
|
|
5
5
|
import { dispatchType } from "../utils/type";
|
|
6
|
-
import { gaesupWorldContextType } from "../world/context/type";
|
|
6
|
+
import { gaesupWorldContextType, urlsType } from "../world/context/type";
|
|
7
7
|
export type SetAtom<Args extends unknown[], Result> = (...args: Args) => Result;
|
|
8
8
|
export type hidratePropType = {
|
|
9
9
|
position: THREE.Vector3;
|
|
@@ -13,6 +13,9 @@ export type calcPropType = controllerInnerType & {
|
|
|
13
13
|
state?: RootState;
|
|
14
14
|
worldContext?: gaesupWorldContextType;
|
|
15
15
|
controllerContext?: gaesupControllerType;
|
|
16
|
+
matchSizes?: {
|
|
17
|
+
[key in keyof urlsType]?: THREE.Vector3;
|
|
18
|
+
};
|
|
16
19
|
delta?: number;
|
|
17
20
|
dispatch?: dispatchType<gaesupWorldContextType>;
|
|
18
21
|
world: World;
|
|
@@ -1,2 +1,16 @@
|
|
|
1
1
|
import { calcPropType } from "../type";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* This function applies an impulse to a rigid body in the game world.
|
|
4
|
+
*
|
|
5
|
+
* @param {calcPropType} prop - An object containing properties necessary for applying the impulse.
|
|
6
|
+
* @param {object} prop.rigidBodyRef - A reference to the rigid body to which the impulse is applied.
|
|
7
|
+
* @param {object} prop.worldContext - An object representing the current state of the game world.
|
|
8
|
+
* @param {object} prop.controllerContext - An object containing controller-specific context data.
|
|
9
|
+
* @param {object} prop.controllerContext.vehicle - An object representing the vehicle controller context.
|
|
10
|
+
* @param {number} prop.controllerContext.vehicle.maxSpeed - The maximum speed of the vehicle.
|
|
11
|
+
*
|
|
12
|
+
* This function calculates the current speed of the rigid body and compares it to the maximum speed.
|
|
13
|
+
* If the current speed is greater than the maximum speed, no impulse is applied.
|
|
14
|
+
* Otherwise, an impulse is applied to the rigid body in the direction specified by `activeState.dir.
|
|
15
|
+
*/
|
|
16
|
+
export default function impulse(prop: calcPropType): void;
|
|
@@ -1,20 +1,40 @@
|
|
|
1
1
|
import { vec3 } from "@react-three/rapier";
|
|
2
|
+
/**
|
|
3
|
+
* This function applies an impulse to a rigid body in the game world.
|
|
4
|
+
*
|
|
5
|
+
* @param {calcPropType} prop - An object containing properties necessary for applying the impulse.
|
|
6
|
+
* @param {object} prop.rigidBodyRef - A reference to the rigid body to which the impulse is applied.
|
|
7
|
+
* @param {object} prop.worldContext - An object representing the current state of the game world.
|
|
8
|
+
* @param {object} prop.controllerContext - An object containing controller-specific context data.
|
|
9
|
+
* @param {object} prop.controllerContext.vehicle - An object representing the vehicle controller context.
|
|
10
|
+
* @param {number} prop.controllerContext.vehicle.maxSpeed - The maximum speed of the vehicle.
|
|
11
|
+
*
|
|
12
|
+
* This function calculates the current speed of the rigid body and compares it to the maximum speed.
|
|
13
|
+
* If the current speed is greater than the maximum speed, no impulse is applied.
|
|
14
|
+
* Otherwise, an impulse is applied to the rigid body in the direction specified by `activeState.dir.
|
|
15
|
+
*/
|
|
2
16
|
export default function impulse(prop) {
|
|
3
17
|
var rigidBodyRef = prop.rigidBodyRef, _a = prop.worldContext, activeState = _a.activeState, control = _a.control, mode = _a.mode, joystick = _a.joystick, vehicle = prop.controllerContext.vehicle;
|
|
4
18
|
var shift = control.shift;
|
|
5
19
|
var maxSpeed = vehicle.maxSpeed, accelRatio = vehicle.accelRatio;
|
|
6
20
|
var velocity = rigidBodyRef.current.linvel();
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
21
|
+
// const V = vec3(velocity).length();
|
|
22
|
+
// a = v / t (t = 1) (approximate calculation)
|
|
23
|
+
var V = vec3(velocity).length();
|
|
24
|
+
if (V < maxSpeed) {
|
|
25
|
+
var M = rigidBodyRef.current.mass();
|
|
26
|
+
var speed = 1;
|
|
27
|
+
if (mode.controller === "joystick") {
|
|
28
|
+
if (!joystick.joyStickOrigin.isCenter)
|
|
29
|
+
speed = joystick.joyStickOrigin.isIn ? accelRatio : 1;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
speed = shift ? accelRatio : 1;
|
|
33
|
+
}
|
|
34
|
+
// impulse = mass * velocity
|
|
35
|
+
rigidBodyRef.current.applyImpulse(vec3()
|
|
36
|
+
.addScalar(speed)
|
|
37
|
+
.multiply(activeState.dir.clone().normalize())
|
|
38
|
+
.multiplyScalar(M), false);
|
|
10
39
|
}
|
|
11
|
-
var speed = 1;
|
|
12
|
-
if (mode.controller === "joystick") {
|
|
13
|
-
if (!joystick.joyStickOrigin.isCenter)
|
|
14
|
-
speed = joystick.joyStickOrigin.isIn ? accelRatio : 1;
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
speed = shift ? accelRatio : 1;
|
|
18
|
-
}
|
|
19
|
-
rigidBodyRef.current.applyImpulse(vec3().addScalar(speed).multiply(activeState.dir.clone().normalize()), false);
|
|
20
40
|
}
|
|
@@ -14,7 +14,7 @@ export default function innerCalc(prop) {
|
|
|
14
14
|
var rigidBodyRef = prop.rigidBodyRef, activeState = prop.worldContext.activeState, dispatch = prop.dispatch;
|
|
15
15
|
activeState.position = vec3(rigidBodyRef.current.translation());
|
|
16
16
|
activeState.velocity = vec3(rigidBodyRef.current.linvel());
|
|
17
|
-
rigidBodyRef.current.setRotation(quat().setFromEuler(activeState.euler), false);
|
|
17
|
+
rigidBodyRef.current.setRotation(quat().setFromEuler(activeState.euler.clone()), false);
|
|
18
18
|
dispatch({
|
|
19
19
|
type: "update",
|
|
20
20
|
payload: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CSSProperties } from "react";
|
|
2
2
|
import "./style.css";
|
|
3
3
|
export type joyStickType = {
|
|
4
|
-
[key in "joyStickBallStyle" | "joyStickStyle"
|
|
4
|
+
[key in "joyStickBallStyle" | "joyStickStyle"]?: CSSProperties;
|
|
5
5
|
};
|
|
6
6
|
export declare function JoyStick(props: joyStickType): import("react/jsx-runtime").JSX.Element;
|
|
@@ -17,7 +17,7 @@ import "./style.css";
|
|
|
17
17
|
export function KeyBoardToolTip(props) {
|
|
18
18
|
var worldContext = useContext(GaesupWorldContext);
|
|
19
19
|
var keyBoardMap = props.keyBoardMap, keyBoardToolTipInnerStyle = props.keyBoardToolTipInnerStyle, selectedKeyCapStyle = props.selectedKeyCapStyle, notSelectedkeyCapStyle = props.notSelectedkeyCapStyle, keyCapStyle = props.keyCapStyle, label = props.label;
|
|
20
|
-
var
|
|
20
|
+
var mode = worldContext.mode, control = worldContext.control;
|
|
21
21
|
var keyArray = Object.entries(KeyBoardAll).reduce(function (keyArray, cur) {
|
|
22
22
|
var key = cur[0], value = cur[1];
|
|
23
23
|
var gridRow = value.gridRow, gridColumn = value.gridColumn, name = value.name;
|
|
@@ -42,7 +42,7 @@ export function KeyBoardToolTip(props) {
|
|
|
42
42
|
var boxShadow = "0 0 5px rgba(0, 0, 0, 0.2)";
|
|
43
43
|
var isSelect = "none";
|
|
44
44
|
if (codeToActionObj[item.code]) {
|
|
45
|
-
if (
|
|
45
|
+
if (control[codeToActionObj[item.code]]) {
|
|
46
46
|
isSelect = "select";
|
|
47
47
|
background = "linear-gradient( 68.4deg, rgba(99,251,215,1) -0.4%, rgba(5,222,250,1) 100.2% )";
|
|
48
48
|
boxShadow = "0 0 10px rgba(99,251,215,1)";
|
|
@@ -55,7 +55,7 @@ export function KeyBoardToolTip(props) {
|
|
|
55
55
|
}
|
|
56
56
|
var color = "white";
|
|
57
57
|
if (codeToActionObj[item.code] &&
|
|
58
|
-
|
|
58
|
+
control[codeToActionObj[item.code]]) {
|
|
59
59
|
color = "black";
|
|
60
60
|
}
|
|
61
61
|
var keyStyle = keyCapStyle;
|