gaesup-world 0.0.783 → 0.1.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 +226 -132
- package/dist/gaesup/animation/actions.d.ts +7 -4
- package/dist/gaesup/animation/actions.js +77 -75
- package/dist/gaesup/camera/control/normal.js +1 -1
- package/dist/gaesup/component/active/airplane/index.js +3 -4
- package/dist/gaesup/component/active/common/InnerGroupRef.js +5 -2
- package/dist/gaesup/component/active/common/RiderGroupRef.d.ts +7 -0
- package/dist/gaesup/component/active/common/RiderGroupRef.js +32 -0
- package/dist/gaesup/component/active/vehicle/index.js +3 -4
- package/dist/gaesup/component/index.js +1 -1
- package/dist/gaesup/component/passive/airplane/index.js +7 -7
- package/dist/gaesup/component/passive/airplane/type.d.ts +2 -0
- package/dist/gaesup/component/passive/common/RigidbodyRef.d.ts +2 -1
- package/dist/gaesup/component/passive/common/RigidbodyRef.js +3 -3
- package/dist/gaesup/component/passive/vehicle/index.js +7 -2
- package/dist/gaesup/component/passive/vehicle/type.d.ts +2 -0
- package/dist/gaesup/controller/index.d.ts +1 -0
- package/dist/gaesup/controller/index.js +7 -1
- package/dist/gaesup/controller/initialize/callback/index.js +3 -5
- package/dist/gaesup/controller/initialize/callback/type.d.ts +2 -1
- package/dist/gaesup/gaesupProps/index.d.ts +2 -1
- package/dist/gaesup/gaesupProps/index.js +7 -3
- package/dist/gaesup/hooks/useGaesupAnimation/index.d.ts +8 -0
- package/dist/gaesup/hooks/useGaesupAnimation/index.js +94 -0
- package/dist/gaesup/hooks/useRideable/index.d.ts +28 -0
- package/dist/gaesup/hooks/useRideable/index.js +198 -0
- package/dist/gaesup/hooks/useTeleport/index.d.ts +3 -0
- package/dist/gaesup/hooks/useTeleport/index.js +12 -0
- package/dist/gaesup/physics/airplane/direction.js +0 -1
- package/dist/gaesup/physics/airplane/index.js +2 -0
- package/dist/gaesup/physics/airplane/landing.d.ts +2 -0
- package/dist/gaesup/physics/airplane/landing.js +29 -0
- package/dist/gaesup/physics/check/index.js +4 -0
- package/dist/gaesup/physics/check/push.d.ts +2 -0
- package/dist/gaesup/physics/check/push.js +6 -0
- package/dist/gaesup/physics/check/riding.d.ts +2 -0
- package/dist/gaesup/physics/check/riding.js +7 -0
- package/dist/gaesup/physics/index.js +1 -1
- package/dist/gaesup/physics/vehicle/direction.js +0 -6
- package/dist/gaesup/physics/vehicle/index.js +2 -0
- package/dist/gaesup/physics/vehicle/landing.d.ts +2 -0
- package/dist/gaesup/physics/vehicle/landing.js +29 -0
- package/dist/gaesup/tools/jumpPortal/index.d.ts +1 -1
- package/dist/gaesup/tools/jumpPortal/index.js +6 -7
- package/dist/gaesup/tools/keyBoardToolTip/type.d.ts +2 -0
- package/dist/gaesup/tools/miniMap/index.js +22 -8
- package/dist/gaesup/tools/miniMap/type.d.ts +4 -1
- package/dist/gaesup/tools/rideable/index.d.ts +2 -8
- package/dist/gaesup/tools/rideable/index.js +37 -72
- package/dist/gaesup/tools/zoomButton/index.d.ts +7 -0
- package/dist/gaesup/tools/zoomButton/index.js +37 -13
- package/dist/gaesup/world/context/index.js +16 -12
- package/dist/gaesup/world/context/reducer.d.ts +3 -1
- package/dist/gaesup/world/context/type.d.ts +30 -5
- package/dist/gaesup/world/debug/index.js +1 -23
- package/dist/gaesup/world/initalize/index.d.ts +3 -1
- package/dist/gaesup/world/initalize/index.js +1 -1
- package/package.json +6 -5
- package/dist/gaesup/component/passive/vehicle/collider.d.ts +0 -6
- package/dist/gaesup/component/passive/vehicle/collider.js +0 -7
|
@@ -12,26 +12,49 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
import { useAnimations, useKeyboardControls } from "@react-three/drei";
|
|
13
13
|
import { useFrame } from "@react-three/fiber";
|
|
14
14
|
import { useContext, useEffect } from "react";
|
|
15
|
+
import { useGaesupAnimation } from "../hooks/useGaesupAnimation";
|
|
15
16
|
import { GaesupWorldContext, GaesupWorldDispatchContext, } from "../world/context";
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
// 캐릭터 등록, 애니메이션 이름 설정, 애니메이션 실행
|
|
18
|
+
export function readyAnimation() {
|
|
19
|
+
var _a = useContext(GaesupWorldContext), characterGltf = _a.characterGltf, vehicleGltf = _a.vehicleGltf, airplaneGltf = _a.airplaneGltf;
|
|
18
20
|
var resultRef = {
|
|
19
21
|
character: null,
|
|
20
22
|
vehicle: null,
|
|
21
23
|
airplane: null,
|
|
22
24
|
};
|
|
23
|
-
if (characterGltf && characterGltf.animations)
|
|
25
|
+
if (characterGltf && characterGltf.animations)
|
|
24
26
|
resultRef.character = useAnimations(characterGltf.animations);
|
|
25
|
-
|
|
26
|
-
if (vehicleGltf && vehicleGltf.animations) {
|
|
27
|
+
if (vehicleGltf && vehicleGltf.animations)
|
|
27
28
|
resultRef.vehicle = useAnimations(vehicleGltf.animations);
|
|
28
|
-
|
|
29
|
-
if (airplaneGltf && airplaneGltf.animations) {
|
|
29
|
+
if (airplaneGltf && airplaneGltf.animations)
|
|
30
30
|
resultRef.airplane = useAnimations(airplaneGltf.animations);
|
|
31
|
-
|
|
31
|
+
return {
|
|
32
|
+
resultRef: resultRef,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export default function playCharacterActions(_a) {
|
|
36
|
+
var groundRay = _a.groundRay;
|
|
37
|
+
var _b = useContext(GaesupWorldContext), states = _b.states, activeState = _b.activeState, animations = _b.animations, mode = _b.mode, characterGltf = _b.characterGltf, vehicleGltf = _b.vehicleGltf, airplaneGltf = _b.airplaneGltf;
|
|
32
38
|
var dispatch = useContext(GaesupWorldDispatchContext);
|
|
39
|
+
var control = useKeyboardControls()[1]();
|
|
40
|
+
var _c = useGaesupAnimation(), subscribeAll = _c.subscribeAll, notify = _c.notify, store = _c.store;
|
|
41
|
+
var resultRef = {
|
|
42
|
+
character: null,
|
|
43
|
+
vehicle: null,
|
|
44
|
+
airplane: null,
|
|
45
|
+
};
|
|
46
|
+
if (characterGltf && characterGltf.animations)
|
|
47
|
+
resultRef.character = useAnimations(characterGltf.animations);
|
|
48
|
+
if (vehicleGltf && vehicleGltf.animations)
|
|
49
|
+
resultRef.vehicle = useAnimations(vehicleGltf.animations);
|
|
50
|
+
if (airplaneGltf && airplaneGltf.animations)
|
|
51
|
+
resultRef.airplane = useAnimations(airplaneGltf.animations);
|
|
33
52
|
var play = function (tag) {
|
|
34
53
|
animations.current = tag;
|
|
54
|
+
var currentAnimation = store[tag];
|
|
55
|
+
if (currentAnimation === null || currentAnimation === void 0 ? void 0 : currentAnimation.action) {
|
|
56
|
+
currentAnimation.action();
|
|
57
|
+
}
|
|
35
58
|
dispatch({
|
|
36
59
|
type: "update",
|
|
37
60
|
payload: {
|
|
@@ -39,39 +62,46 @@ export function usePlayActions() {
|
|
|
39
62
|
},
|
|
40
63
|
});
|
|
41
64
|
};
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
var _a;
|
|
45
|
-
return __assign(__assign({}, acc), (_a = {}, _a[cur] = cur, _a));
|
|
46
|
-
}, {}));
|
|
47
|
-
dispatch({
|
|
48
|
-
type: "update",
|
|
49
|
-
payload: {
|
|
50
|
-
animations: __assign({}, animations),
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
return { resultRef: resultRef, play: play, setAnimationName: setAnimationName };
|
|
55
|
-
}
|
|
56
|
-
export default function playCharacterActions(_a) {
|
|
57
|
-
var groundRay = _a.groundRay;
|
|
58
|
-
var _b = usePlayActions(), _c = _b.resultRef.character, actions = _c.actions, ref = _c.ref, play = _b.play, setAnimationName = _b.setAnimationName;
|
|
59
|
-
var _d = useContext(GaesupWorldContext), states = _d.states, activeState = _d.activeState, animations = _d.animations, mode = _d.mode;
|
|
60
|
-
var isNotMoving = states.isNotMoving, isMoving = states.isMoving, isJumping = states.isJumping, isRunning = states.isRunning, isAnimationOuter = states.isAnimationOuter, isOnTheGround = states.isOnTheGround;
|
|
61
|
-
var dispatch = useContext(GaesupWorldDispatchContext);
|
|
62
|
-
var control = useKeyboardControls()[1]();
|
|
63
|
-
var resetAni = function () { return play("idle"); };
|
|
64
|
-
var playIdle = function () { return play("idle"); };
|
|
65
|
-
var playWalk = function () { return play("walk"); };
|
|
66
|
-
var playRun = function () { return play("run"); };
|
|
67
|
-
var playJump = function () { return play("jump"); };
|
|
68
|
-
var playFall = function () { return play("fall"); };
|
|
69
|
-
var playRide = function () { return play("ride"); };
|
|
70
|
-
var playLanding = function () { return play("land"); };
|
|
65
|
+
var _d = resultRef.character, actions = _d.actions, ref = _d.ref;
|
|
66
|
+
// 초기 기본 애니메이션 등록
|
|
71
67
|
useEffect(function () {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
subscribeAll([
|
|
69
|
+
{
|
|
70
|
+
tag: "walk",
|
|
71
|
+
condition: function () { return !states.isRunning && states.isMoving; },
|
|
72
|
+
action: function () { },
|
|
73
|
+
animationName: "walk",
|
|
74
|
+
key: "walk",
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
tag: "run",
|
|
78
|
+
condition: function () { return states.isRunning; },
|
|
79
|
+
action: function () { },
|
|
80
|
+
animationName: "run",
|
|
81
|
+
key: "run",
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
tag: "jump",
|
|
85
|
+
condition: function () { return states.isJumping; },
|
|
86
|
+
action: function () { },
|
|
87
|
+
animationName: "jump",
|
|
88
|
+
key: "jump",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
tag: "fall",
|
|
92
|
+
condition: function () { return groundRay.hit === null && activeState.velocity.y < 0; },
|
|
93
|
+
action: function () { },
|
|
94
|
+
animationName: "fall",
|
|
95
|
+
key: "fall",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
tag: "ride",
|
|
99
|
+
condition: function () { return states.isPush["keyR"]; },
|
|
100
|
+
action: function () { },
|
|
101
|
+
animationName: "ride",
|
|
102
|
+
key: "ride",
|
|
103
|
+
},
|
|
104
|
+
]);
|
|
75
105
|
}, []);
|
|
76
106
|
useEffect(function () {
|
|
77
107
|
animations.keyControl = control;
|
|
@@ -84,45 +114,17 @@ export default function playCharacterActions(_a) {
|
|
|
84
114
|
}, [control]);
|
|
85
115
|
useEffect(function () {
|
|
86
116
|
var _a;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
action_1 === null || action_1 === void 0 ? void 0 : action_1.fadeOut(0.2);
|
|
92
|
-
};
|
|
93
|
-
}
|
|
117
|
+
var action = (_a = actions[animations.current]) === null || _a === void 0 ? void 0 : _a.reset().fadeIn(0.2).play();
|
|
118
|
+
return function () {
|
|
119
|
+
action === null || action === void 0 ? void 0 : action.fadeOut(0.2);
|
|
120
|
+
};
|
|
94
121
|
}, [animations.current, mode.type]);
|
|
95
122
|
useFrame(function () {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (isJumping) {
|
|
99
|
-
playJump();
|
|
100
|
-
}
|
|
101
|
-
else if (isNotMoving) {
|
|
102
|
-
playIdle();
|
|
103
|
-
}
|
|
104
|
-
else if (isRunning) {
|
|
105
|
-
playRun();
|
|
106
|
-
}
|
|
107
|
-
else if (isMoving) {
|
|
108
|
-
playWalk();
|
|
109
|
-
}
|
|
110
|
-
// if (groundRay.hit) {
|
|
111
|
-
// if (!isJumping && !isOnTheGround) {
|
|
112
|
-
// if (groundRay.hit.toi < 5) {
|
|
113
|
-
// playLanding();
|
|
114
|
-
// } else {
|
|
115
|
-
// playFall();
|
|
116
|
-
// }
|
|
117
|
-
// }
|
|
118
|
-
// }
|
|
119
|
-
// if (groundRay.hit === null && activeState.velocity.y < 0) {
|
|
120
|
-
// playFall();
|
|
121
|
-
// }
|
|
122
|
-
}
|
|
123
|
-
}
|
|
123
|
+
var tag = notify();
|
|
124
|
+
play(tag);
|
|
124
125
|
});
|
|
125
126
|
return {
|
|
126
127
|
ref: ref,
|
|
128
|
+
resultRef: resultRef,
|
|
127
129
|
};
|
|
128
130
|
}
|
|
@@ -6,6 +6,6 @@ export default function normal(prop) {
|
|
|
6
6
|
var cameraPosition = activeState.position
|
|
7
7
|
.clone()
|
|
8
8
|
.add(V3(0, cameraOption.YDistance, cameraOption.XZDistance));
|
|
9
|
-
state.camera.position.lerp(cameraPosition,
|
|
9
|
+
state.camera.position.lerp(cameraPosition, 1);
|
|
10
10
|
state.camera.lookAt(activeState.position.clone());
|
|
11
11
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from "react";
|
|
3
3
|
import { GaesupWorldContext } from "../../../world/context";
|
|
4
|
-
import { InnerGroupRef } from "../common/InnerGroupRef";
|
|
5
4
|
import { WrapperRef } from "../common/WrapperRef";
|
|
6
5
|
import { AirplaneCollider } from "./collider";
|
|
7
6
|
export function AirplaneRef(_a) {
|
|
8
7
|
var props = _a.props, refs = _a.refs;
|
|
9
|
-
var
|
|
10
|
-
return (
|
|
8
|
+
var airplaneGltf = useContext(GaesupWorldContext).airplaneGltf;
|
|
9
|
+
return (_jsx(WrapperRef, { props: props, refs: refs, gltf: airplaneGltf, children: _jsx(AirplaneCollider, { props: props }) }));
|
|
11
10
|
}
|
|
@@ -10,17 +10,20 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
-
import { Suspense, forwardRef, useMemo } from "react";
|
|
13
|
+
import { Suspense, forwardRef, useContext, useMemo } from "react";
|
|
14
14
|
import { useGraph } from "@react-three/fiber";
|
|
15
15
|
import * as THREE from "three";
|
|
16
16
|
import { SkeletonUtils } from "three-stdlib";
|
|
17
|
+
import { GaesupWorldContext } from "../../../world/context";
|
|
18
|
+
import { RiderGroup } from "./RiderGroupRef";
|
|
17
19
|
export var InnerGroupRef = forwardRef(function (_a, ref) {
|
|
18
20
|
var props = _a.props, animationRef = _a.animationRef, gltf = _a.gltf;
|
|
21
|
+
var _b = useContext(GaesupWorldContext), mode = _b.mode, states = _b.states;
|
|
19
22
|
var scene = gltf.scene;
|
|
20
23
|
var clone = useMemo(function () { return SkeletonUtils.clone(scene); }, [scene]);
|
|
21
24
|
var nodes = useGraph(clone).nodes;
|
|
22
25
|
var objectNode = Object.values(nodes).find(function (node) { return node.type === "Object3D"; });
|
|
23
|
-
return (_jsx(Suspense, { children: _jsxs("group", __assign({ receiveShadow: true, castShadow: true }, props.groupProps, { ref: ref, children: [objectNode && animationRef && (_jsx("primitive", { object: objectNode, visible: false, receiveShadow: true, castShadow: true, ref: animationRef })), Object.keys(nodes).map(function (name, key) {
|
|
26
|
+
return (_jsx(Suspense, { fallback: null, children: _jsxs("group", __assign({ receiveShadow: true, castShadow: true }, props.groupProps, { ref: ref, children: [mode.type !== "character" && states.isRiderOn && (_jsx(RiderGroup, { props: props })), objectNode && animationRef && (_jsx("primitive", { object: objectNode, visible: false, receiveShadow: true, castShadow: true, ref: animationRef })), Object.keys(nodes).map(function (name, key) {
|
|
24
27
|
var node = nodes[name];
|
|
25
28
|
if (node instanceof THREE.SkinnedMesh) {
|
|
26
29
|
return (_jsx("skinnedMesh", { castShadow: true, receiveShadow: true, material: node.material, geometry: node.geometry, skeleton: node.skeleton }, key));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Ref } from "react";
|
|
2
|
+
import { controllerInnerType } from "../../../controller/type";
|
|
3
|
+
import * as THREE from "three";
|
|
4
|
+
export type RiderGroupRefType = {
|
|
5
|
+
props: controllerInnerType;
|
|
6
|
+
};
|
|
7
|
+
export declare const RiderGroup: ({ props }: RiderGroupRefType, ref: Ref<THREE.Group>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useContext, useMemo } from "react";
|
|
3
|
+
import { useGraph } from "@react-three/fiber";
|
|
4
|
+
import * as THREE from "three";
|
|
5
|
+
import { SkeletonUtils } from "three-stdlib";
|
|
6
|
+
import playPassiveActions from "../../../animation/passiveActions";
|
|
7
|
+
import { GaesupWorldContext } from "../../../world/context";
|
|
8
|
+
export var RiderGroup = function (_a, ref) {
|
|
9
|
+
var props = _a.props;
|
|
10
|
+
var _b = useContext(GaesupWorldContext), characterGltf = _b.characterGltf, states = _b.states, characterCollider = _b.characterCollider;
|
|
11
|
+
var characterAnimationRef = playPassiveActions({
|
|
12
|
+
current: "ride",
|
|
13
|
+
animations: characterGltf.animations,
|
|
14
|
+
}).animationRef;
|
|
15
|
+
var characterScene = characterGltf.scene;
|
|
16
|
+
var characterClone = useMemo(function () { return SkeletonUtils.clone(characterScene); }, [characterScene]);
|
|
17
|
+
var characterNodes = useGraph(characterClone).nodes;
|
|
18
|
+
var characterObjectNode = Object.values(characterNodes).find(function (node) { return node.type === "Object3D"; });
|
|
19
|
+
return (_jsx(_Fragment, { children: characterAnimationRef && (_jsxs("group", { position: [
|
|
20
|
+
(characterCollider === null || characterCollider === void 0 ? void 0 : characterCollider.riderOffsetX) || 0,
|
|
21
|
+
(characterCollider === null || characterCollider === void 0 ? void 0 : characterCollider.riderOffsetY) || 0,
|
|
22
|
+
(characterCollider === null || characterCollider === void 0 ? void 0 : characterCollider.riderOffsetZ) || 0,
|
|
23
|
+
], children: [characterObjectNode && (_jsx("primitive", { object: characterObjectNode, visible: false, receiveShadow: true, castShadow: true, ref: characterAnimationRef })), Object.keys(characterNodes).map(function (name, key) {
|
|
24
|
+
var characterNode = characterNodes[name];
|
|
25
|
+
if (characterNode instanceof THREE.SkinnedMesh) {
|
|
26
|
+
return (_jsx("skinnedMesh", { castShadow: true, receiveShadow: true, material: characterNode.material, geometry: characterNode.geometry, skeleton: characterNode.skeleton }, key));
|
|
27
|
+
}
|
|
28
|
+
else if (characterNode instanceof THREE.Mesh) {
|
|
29
|
+
return (_jsx("mesh", { castShadow: true, receiveShadow: true, material: characterNode.material, geometry: characterNode.geometry }, key));
|
|
30
|
+
}
|
|
31
|
+
})] })) }));
|
|
32
|
+
};
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useContext } from "react";
|
|
3
3
|
import { GaesupWorldContext } from "../../../world/context";
|
|
4
|
-
import { InnerGroupRef } from "../common/InnerGroupRef";
|
|
5
4
|
import { WrapperRef } from "../common/WrapperRef";
|
|
6
5
|
import { VehicleCollider } from "./collider";
|
|
7
6
|
import { Wheels } from "./wheels";
|
|
8
7
|
export function VehicleRef(_a) {
|
|
9
8
|
var props = _a.props, refs = _a.refs;
|
|
10
|
-
var _b = useContext(GaesupWorldContext), url = _b.url,
|
|
11
|
-
return (
|
|
9
|
+
var _b = useContext(GaesupWorldContext), url = _b.url, vehicleGltf = _b.vehicleGltf;
|
|
10
|
+
return (_jsx(WrapperRef, { props: props, refs: refs, gltf: vehicleGltf, outerChildren: url.wheelUrl ? _jsx(Wheels, { props: props }) : _jsx(_Fragment, {}), children: _jsx(VehicleCollider, {}) }));
|
|
12
11
|
}
|
|
@@ -7,7 +7,7 @@ import { CharacterRef } from "./active/character";
|
|
|
7
7
|
import { VehicleRef } from "./active/vehicle";
|
|
8
8
|
export function GaesupComponent(_a) {
|
|
9
9
|
var props = _a.props, refs = _a.refs;
|
|
10
|
-
var
|
|
10
|
+
var mode = useContext(GaesupWorldContext).mode;
|
|
11
11
|
calculation(props);
|
|
12
12
|
return (_jsxs(_Fragment, { children: [mode.type === "character" && _jsx(CharacterRef, { props: props, refs: refs }), mode.type === "vehicle" && _jsx(VehicleRef, { props: props, refs: refs }), mode.type === "airplane" && _jsx(AirplaneRef, { props: props, refs: refs })] }));
|
|
13
13
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useFrame } from "@react-three/fiber";
|
|
3
|
-
import { quat } from "@react-three/rapier";
|
|
3
|
+
import { CuboidCollider, quat } from "@react-three/rapier";
|
|
4
4
|
import { useMemo, useRef } from "react";
|
|
5
5
|
import { InnerGroupRef } from "../common/InnerGroupRef";
|
|
6
6
|
import { OuterGroupRef } from "../common/OuterGroupRef";
|
|
7
7
|
import { RigidBodyRef } from "../common/RigidbodyRef";
|
|
8
|
-
import { AirplaneCollider } from "./collider";
|
|
9
8
|
export function PassiveAirplane(props) {
|
|
10
9
|
var rigidBodyRef = useRef(null);
|
|
11
10
|
var outerGroupRef = useRef(null);
|
|
@@ -23,8 +22,9 @@ export function PassiveAirplane(props) {
|
|
|
23
22
|
euler: props.euler,
|
|
24
23
|
currentAnimation: props.currentAnimation,
|
|
25
24
|
airplaneUrl: props.airplaneUrl,
|
|
25
|
+
airplaneSize: props.airplaneSize,
|
|
26
26
|
};
|
|
27
|
-
}, [props]), position = _a.position, euler = _a.euler, currentAnimation = _a.currentAnimation, airplaneUrl = _a.airplaneUrl;
|
|
27
|
+
}, [props]), position = _a.position, euler = _a.euler, currentAnimation = _a.currentAnimation, airplaneUrl = _a.airplaneUrl, airplaneSize = _a.airplaneSize;
|
|
28
28
|
useFrame(function () {
|
|
29
29
|
if (innerGroupRef && innerGroupRef.current) {
|
|
30
30
|
var _euler = euler.clone();
|
|
@@ -33,9 +33,9 @@ export function PassiveAirplane(props) {
|
|
|
33
33
|
.setFromEuler(innerGroupRef.current.rotation.clone())
|
|
34
34
|
.slerp(quat().setFromEuler(_euler), 0.2));
|
|
35
35
|
}
|
|
36
|
-
if (rigidBodyRef && rigidBodyRef.current) {
|
|
37
|
-
|
|
38
|
-
}
|
|
36
|
+
// if (rigidBodyRef && rigidBodyRef.current) {
|
|
37
|
+
// rigidBodyRef.current.setGravityScale(props.gravity, false);
|
|
38
|
+
// }
|
|
39
39
|
});
|
|
40
|
-
return (
|
|
40
|
+
return (_jsxs(OuterGroupRef, { ref: refs.outerGroupRef, children: [props.children, airplaneUrl && (_jsxs(RigidBodyRef, { ref: refs.rigidBodyRef, position: position, rotation: euler, onCollisionEnter: props.onCollisionEnter, children: [_jsx(InnerGroupRef, { currentAnimation: currentAnimation, ref: refs.innerGroupRef, url: airplaneUrl }), _jsx(CuboidCollider, { ref: colliderRef, args: [airplaneSize.x / 2, airplaneSize.y / 2, airplaneSize.z / 2], position: [0, airplaneSize.y / 2, 0] })] }))] }));
|
|
41
41
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { CollisionEnterPayload } from "@react-three/rapier";
|
|
2
3
|
export type passiveAirplanePropsType = {
|
|
3
4
|
position: THREE.Vector3;
|
|
4
5
|
euler: THREE.Euler;
|
|
@@ -7,4 +8,5 @@ export type passiveAirplanePropsType = {
|
|
|
7
8
|
currentAnimation: string;
|
|
8
9
|
children?: React.ReactNode;
|
|
9
10
|
gravity?: number;
|
|
11
|
+
onCollisionEnter?: (e: CollisionEnterPayload) => Promise<void>;
|
|
10
12
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { RapierRigidBody } from "@react-three/rapier";
|
|
1
|
+
import { CollisionEnterPayload, RapierRigidBody } from "@react-three/rapier";
|
|
2
2
|
import { ReactNode } from "react";
|
|
3
3
|
export declare const RigidBodyRef: import("react").ForwardRefExoticComponent<{
|
|
4
4
|
children: ReactNode;
|
|
5
5
|
position?: THREE.Vector3;
|
|
6
6
|
rotation?: THREE.Euler;
|
|
7
|
+
onCollisionEnter?: (e: CollisionEnterPayload) => Promise<void>;
|
|
7
8
|
} & import("react").RefAttributes<RapierRigidBody>>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { RigidBody } from "@react-three/rapier";
|
|
2
|
+
import { RigidBody, } from "@react-three/rapier";
|
|
3
3
|
import { forwardRef } from "react";
|
|
4
4
|
export var RigidBodyRef = forwardRef(function (_a, ref) {
|
|
5
|
-
var children = _a.children, position = _a.position, rotation = _a.rotation;
|
|
5
|
+
var children = _a.children, position = _a.position, rotation = _a.rotation, onCollisionEnter = _a.onCollisionEnter;
|
|
6
6
|
var _euler = rotation.clone();
|
|
7
7
|
_euler.x = 0;
|
|
8
8
|
_euler.z = 0;
|
|
9
|
-
return (_jsx(RigidBody, { colliders: false, ref: ref, position: position, rotation: _euler, userData: { intangible: true }, children: children }));
|
|
9
|
+
return (_jsx(RigidBody, { colliders: false, ref: ref, position: position, rotation: _euler, userData: { intangible: true }, onCollisionEnter: onCollisionEnter, children: children }));
|
|
10
10
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { CuboidCollider } from "@react-three/rapier";
|
|
3
|
-
import { useMemo, useRef } from "react";
|
|
3
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
4
4
|
import { InnerGroupRef } from "../common/InnerGroupRef";
|
|
5
5
|
import { OuterGroupRef } from "../common/OuterGroupRef";
|
|
6
6
|
import { RigidBodyRef } from "../common/RigidbodyRef";
|
|
@@ -27,5 +27,10 @@ export function PassiveVehicle(props) {
|
|
|
27
27
|
vehicleUrl: props.url.vehicleUrl,
|
|
28
28
|
};
|
|
29
29
|
}, [props]), position = _a.position, euler = _a.euler, vehicleSize = _a.vehicleSize, wheelSize = _a.wheelSize, currentAnimation = _a.currentAnimation, wheelUrl = _a.wheelUrl, vehicleUrl = _a.vehicleUrl;
|
|
30
|
-
|
|
30
|
+
useEffect(function () {
|
|
31
|
+
if (rigidBodyRef.current) {
|
|
32
|
+
rigidBodyRef.current.lockRotations(true, true);
|
|
33
|
+
}
|
|
34
|
+
}, []);
|
|
35
|
+
return (_jsxs(OuterGroupRef, { ref: refs.outerGroupRef, children: [props.children, vehicleUrl && (_jsxs(RigidBodyRef, { ref: refs.rigidBodyRef, position: position, rotation: euler, onCollisionEnter: props.onCollisionEnter, children: [_jsx(InnerGroupRef, { currentAnimation: currentAnimation, ref: refs.innerGroupRef, url: vehicleUrl }), wheelUrl ? (_jsx(CuboidCollider, { ref: colliderRef, args: [vehicleSize.x / 2, vehicleSize.y / 2, vehicleSize.z / 2], position: [0, vehicleSize.y + wheelSize.y / 2, 0] })) : (_jsx(CuboidCollider, { ref: colliderRef, args: [vehicleSize.x / 2, vehicleSize.y / 2, vehicleSize.z / 2], position: [0, vehicleSize.y, 0] }))] })), wheelUrl && (_jsx(Wheels, { vehicleSize: vehicleSize, wheelSize: wheelSize, rigidBodyRef: rigidBodyRef, url: wheelUrl }))] }));
|
|
31
36
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { CollisionEnterPayload } from "@react-three/rapier";
|
|
2
3
|
import { activeStateType, characterColliderType, modeType, urlType } from "../../../world/context/type";
|
|
3
4
|
export type gaesupPassiveCharacterPropsType = {
|
|
4
5
|
state: activeStateType;
|
|
@@ -16,4 +17,5 @@ export type passiveVehiclePropsType = {
|
|
|
16
17
|
url: urlType;
|
|
17
18
|
currentAnimation: string;
|
|
18
19
|
children?: React.ReactNode;
|
|
20
|
+
onCollisionEnter?: (e: CollisionEnterPayload) => Promise<void>;
|
|
19
21
|
};
|
|
@@ -10,14 +10,20 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
-
import { useMemo, useReducer, useRef } from "react";
|
|
13
|
+
import { useContext, useMemo, useReducer, useRef } from "react";
|
|
14
14
|
import Camera from "../camera";
|
|
15
|
+
import { KeyboardControls } from "@react-three/drei";
|
|
15
16
|
import { GaesupComponent } from "../component";
|
|
17
|
+
import { GaesupWorldContext } from "../world/context";
|
|
16
18
|
import { GaesupControllerContext, GaesupControllerDispatchContext, gaesupControllerDefault, } from "./context";
|
|
17
19
|
import { gaesupControllerReducer } from "./context/reducer";
|
|
18
20
|
import initDebug from "./debug";
|
|
19
21
|
import initControllerProps from "./initialize";
|
|
20
22
|
export function GaesupController(props) {
|
|
23
|
+
var keyBoardMap = useContext(GaesupWorldContext).keyBoardMap;
|
|
24
|
+
return (_jsx(KeyboardControls, { map: keyBoardMap, children: _jsx(GaesupControllerInner, __assign({}, props, { children: props.children })) }));
|
|
25
|
+
}
|
|
26
|
+
export function GaesupControllerInner(props) {
|
|
21
27
|
var capsuleColliderRef = useRef(null);
|
|
22
28
|
var rigidBodyRef = useRef(null);
|
|
23
29
|
var outerGroupRef = useRef(null);
|
|
@@ -12,18 +12,19 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
import { useAnimations } from "@react-three/drei";
|
|
13
13
|
import { useFrame } from "@react-three/fiber";
|
|
14
14
|
import { useContext, useEffect } from "react";
|
|
15
|
+
import { useGaesupAnimation } from "../../../hooks/useGaesupAnimation";
|
|
15
16
|
import { GaesupWorldContext, GaesupWorldDispatchContext, } from "../../../world/context";
|
|
16
17
|
export default function initCallback(props) {
|
|
17
18
|
var _a = useContext(GaesupWorldContext), characterGltf = _a.characterGltf, characterAnimations = _a.animations, activeState = _a.activeState, states = _a.states, control = _a.control;
|
|
18
19
|
var dispatch = useContext(GaesupWorldDispatchContext);
|
|
19
20
|
var animations = characterGltf.animations;
|
|
20
21
|
var actions = useAnimations(animations, props.outerGroupRef).actions;
|
|
22
|
+
var subscribe = useGaesupAnimation().subscribe;
|
|
21
23
|
var playAnimation = function (tag, key) {
|
|
22
24
|
if (!(key in control))
|
|
23
25
|
return;
|
|
24
26
|
if (control[key]) {
|
|
25
27
|
characterAnimations.current = tag;
|
|
26
|
-
states.isAnimationOuter = true;
|
|
27
28
|
dispatch({
|
|
28
29
|
type: "update",
|
|
29
30
|
payload: {
|
|
@@ -31,11 +32,8 @@ export default function initCallback(props) {
|
|
|
31
32
|
},
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
|
-
else {
|
|
35
|
-
states.isAnimationOuter = false;
|
|
36
|
-
}
|
|
37
35
|
};
|
|
38
|
-
var controllerProp = __assign(__assign({}, props), { activeState: activeState, control: control, states: states });
|
|
36
|
+
var controllerProp = __assign(__assign({}, props), { activeState: activeState, control: control, states: states, subscribe: subscribe });
|
|
39
37
|
useEffect(function () {
|
|
40
38
|
if (props.onReady) {
|
|
41
39
|
props.onReady(controllerProp);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RootState } from "@react-three/fiber";
|
|
2
2
|
import { cameraRayType } from "../../../camera/type";
|
|
3
|
-
import { activeStateType, animationPropType, keyControlType, statesType } from "../../../world/context/type";
|
|
3
|
+
import { activeStateType, animationAtomType, animationPropType, keyControlType, statesType } from "../../../world/context/type";
|
|
4
4
|
import { actionsType, groundRayType, slopeRayType } from "../../type";
|
|
5
5
|
export type callbackPropType = {
|
|
6
6
|
activeState: activeStateType;
|
|
@@ -9,6 +9,7 @@ export type callbackPropType = {
|
|
|
9
9
|
groundRay: groundRayType;
|
|
10
10
|
cameraRay: cameraRayType;
|
|
11
11
|
control: keyControlType;
|
|
12
|
+
subscribe: (props: animationAtomType) => void;
|
|
12
13
|
};
|
|
13
14
|
export type onFramePropType = callbackPropType & RootState;
|
|
14
15
|
export type onAnimatePropType = onFramePropType & {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
export declare function GaeSupProps({ text, position, children, }: {
|
|
2
|
+
export declare function GaeSupProps({ type, text, position, children, }: {
|
|
3
|
+
type?: "normal" | "ground";
|
|
3
4
|
text?: string;
|
|
4
5
|
position?: [number, number, number];
|
|
5
6
|
children: React.ReactNode;
|
|
@@ -11,20 +11,24 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
import { vec3 } from "@react-three/rapier";
|
|
14
|
-
import { Suspense, useContext, useEffect, useRef } from "react";
|
|
14
|
+
import { Suspense, useContext, useEffect, useMemo, useRef } from "react";
|
|
15
15
|
import * as THREE from "three";
|
|
16
16
|
import { GaesupWorldContext, GaesupWorldDispatchContext, } from "../world/context/index.js";
|
|
17
17
|
export function GaeSupProps(_a) {
|
|
18
|
-
var text = _a.text, position = _a.position, children = _a.children;
|
|
18
|
+
var type = _a.type, text = _a.text, position = _a.position, children = _a.children;
|
|
19
19
|
var groupRef = useRef(null);
|
|
20
20
|
var minimap = useContext(GaesupWorldContext).minimap;
|
|
21
21
|
var dispatch = useContext(GaesupWorldDispatchContext);
|
|
22
|
+
var groupComponent = useMemo(function () {
|
|
23
|
+
return (_jsx("group", { ref: groupRef, position: position, children: children }));
|
|
24
|
+
}, []);
|
|
22
25
|
useEffect(function () {
|
|
23
26
|
if (groupRef.current) {
|
|
24
27
|
var box = new THREE.Box3().setFromObject(groupRef.current);
|
|
25
28
|
var size = vec3(box.getSize(new THREE.Vector3())).clone();
|
|
26
29
|
var center = vec3(box.getCenter(new THREE.Vector3())).clone();
|
|
27
30
|
var obj = {
|
|
31
|
+
type: type ? type : "normal",
|
|
28
32
|
text: text,
|
|
29
33
|
size: size,
|
|
30
34
|
center: center,
|
|
@@ -38,5 +42,5 @@ export function GaeSupProps(_a) {
|
|
|
38
42
|
});
|
|
39
43
|
}
|
|
40
44
|
}, []);
|
|
41
|
-
return
|
|
45
|
+
return _jsx(Suspense, { fallback: null, children: groupComponent });
|
|
42
46
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { animationAtomType } from "../../world/context/type";
|
|
2
|
+
export declare function useGaesupAnimation(): {
|
|
3
|
+
subscribe: ({ tag, condition, action, animationName, key, }: animationAtomType) => void;
|
|
4
|
+
subscribeAll: (props: animationAtomType[]) => void;
|
|
5
|
+
store: {};
|
|
6
|
+
unsubscribe: (tag: string) => void;
|
|
7
|
+
notify: () => string;
|
|
8
|
+
};
|