gaesup-world 0.9.56 → 0.9.58
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/dist/gaesup/component/inner/common/RigidbodyRef.tsx +2 -157
- package/dist/gaesup/component/inner/common/setGroundRay.ts +18 -12
- package/dist/gaesup/hooks/useTeleport/index.tsx +8 -10
- package/dist/gaesup/tools/rideable/index.tsx +67 -75
- package/dist/gaesup/tools/rideable/type.ts +1 -0
- package/package.json +1 -1
|
@@ -1,159 +1,3 @@
|
|
|
1
|
-
// import { useAnimations, useGLTF } from "@react-three/drei";
|
|
2
|
-
// import { useFrame, useGraph } from "@react-three/fiber";
|
|
3
|
-
// import {
|
|
4
|
-
// CapsuleCollider,
|
|
5
|
-
// RapierRigidBody,
|
|
6
|
-
// RigidBody,
|
|
7
|
-
// euler,
|
|
8
|
-
// } from "@react-three/rapier";
|
|
9
|
-
// import { MutableRefObject, forwardRef, useContext, useMemo } from "react";
|
|
10
|
-
// import * as THREE from "three";
|
|
11
|
-
// import { SkeletonUtils } from "three-stdlib";
|
|
12
|
-
// import playActions, { subscribeActions } from "../../../animation/actions";
|
|
13
|
-
// import Camera from "../../../camera";
|
|
14
|
-
// import { GaesupControllerContext } from "../../../controller/context";
|
|
15
|
-
// import initCallback from "../../../controller/initialize/callback";
|
|
16
|
-
// import { useGltfAndSize } from "../../../hooks/useGaesupGltf";
|
|
17
|
-
// import calculation from "../../../physics";
|
|
18
|
-
// import { cameraPropType } from "../../../physics/type";
|
|
19
|
-
// import { V3 } from "../../../utils";
|
|
20
|
-
// import { GaesupWorldContext } from "../../../world/context";
|
|
21
|
-
// import { InnerGroupRef } from "./InnerGroupRef";
|
|
22
|
-
// import { PartsGroupRef } from "./partsGroupRef";
|
|
23
|
-
// import { setGroundRay } from "./setGroundRay";
|
|
24
|
-
// import { rigidBodyRefType } from "./type";
|
|
25
|
-
//
|
|
26
|
-
// export const RigidBodyRef = forwardRef(
|
|
27
|
-
// (props: rigidBodyRefType, ref: MutableRefObject<RapierRigidBody>) => {
|
|
28
|
-
// const { size } = useGltfAndSize({ url: props.url });
|
|
29
|
-
//
|
|
30
|
-
// props.groundRay &&
|
|
31
|
-
// setGroundRay({
|
|
32
|
-
// groundRay: props.groundRay,
|
|
33
|
-
// length: 0.5,
|
|
34
|
-
// colliderRef: props.colliderRef,
|
|
35
|
-
// });
|
|
36
|
-
// const { scene, animations } = useGLTF(props.url);
|
|
37
|
-
// const { actions, ref: animationRef } = useAnimations(animations);
|
|
38
|
-
// const worldContext = useContext(GaesupWorldContext);
|
|
39
|
-
// const controllerContext = useContext(GaesupControllerContext);
|
|
40
|
-
// if (props.isActive) {
|
|
41
|
-
// subscribeActions({
|
|
42
|
-
// type: props.componentType,
|
|
43
|
-
// groundRay: props.groundRay,
|
|
44
|
-
// animations: animations,
|
|
45
|
-
// });
|
|
46
|
-
// const cameraProps: cameraPropType = {
|
|
47
|
-
// state: null,
|
|
48
|
-
// worldContext,
|
|
49
|
-
// controllerContext,
|
|
50
|
-
// controllerOptions: props.controllerOptions,
|
|
51
|
-
// };
|
|
52
|
-
//
|
|
53
|
-
// Camera(cameraProps);
|
|
54
|
-
// calculation({
|
|
55
|
-
// outerGroupRef: props.outerGroupRef,
|
|
56
|
-
// innerGroupRef: props.innerGroupRef,
|
|
57
|
-
// rigidBodyRef: ref,
|
|
58
|
-
// colliderRef: props.colliderRef,
|
|
59
|
-
// groundRay: props.groundRay,
|
|
60
|
-
// });
|
|
61
|
-
// }
|
|
62
|
-
// playActions({
|
|
63
|
-
// type: props.componentType,
|
|
64
|
-
// actions,
|
|
65
|
-
// animationRef,
|
|
66
|
-
// currentAnimation: props.isActive ? undefined : props.currentAnimation,
|
|
67
|
-
// isActive: props.isActive,
|
|
68
|
-
// });
|
|
69
|
-
// initCallback({
|
|
70
|
-
// props,
|
|
71
|
-
// actions,
|
|
72
|
-
// componentType: props.componentType,
|
|
73
|
-
// });
|
|
74
|
-
// const clone = useMemo(() => SkeletonUtils.clone(scene), [scene]);
|
|
75
|
-
// const { nodes } = useGraph(clone);
|
|
76
|
-
// const objectNode = Object.values(nodes).find(
|
|
77
|
-
// (node) => node.type === "Object3D"
|
|
78
|
-
// );
|
|
79
|
-
// useFrame(() => {
|
|
80
|
-
// if (props.isActive || !props.position || !ref || !ref.current) return;
|
|
81
|
-
// ref.current.setTranslation(
|
|
82
|
-
// V3(
|
|
83
|
-
// THREE.MathUtils.lerp(
|
|
84
|
-
// ref.current.translation().x,
|
|
85
|
-
// props.position.x,
|
|
86
|
-
// props.controllerOptions.lerp.cameraPosition
|
|
87
|
-
// ),
|
|
88
|
-
// THREE.MathUtils.lerp(
|
|
89
|
-
// ref.current.translation().y,
|
|
90
|
-
// props.position.y,
|
|
91
|
-
// props.controllerOptions.lerp.cameraPosition
|
|
92
|
-
// ),
|
|
93
|
-
// THREE.MathUtils.lerp(
|
|
94
|
-
// ref.current.translation().z,
|
|
95
|
-
// props.position.z,
|
|
96
|
-
// props.controllerOptions.lerp.cameraPosition
|
|
97
|
-
// )
|
|
98
|
-
// ),
|
|
99
|
-
// false
|
|
100
|
-
// );
|
|
101
|
-
// });
|
|
102
|
-
// return (
|
|
103
|
-
// <RigidBody
|
|
104
|
-
// colliders={false}
|
|
105
|
-
// ref={ref}
|
|
106
|
-
// name={props.name}
|
|
107
|
-
// rotation={euler()
|
|
108
|
-
// .set(0, props.rotation?.clone().y || 0, 0)
|
|
109
|
-
// .clone()}
|
|
110
|
-
// userData={props.userData}
|
|
111
|
-
// type={props.rigidbodyType || (props.isActive ? "dynamic" : "fixed")}
|
|
112
|
-
// sensor={props.sensor}
|
|
113
|
-
// onIntersectionEnter={props.onIntersectionEnter}
|
|
114
|
-
// onCollisionEnter={props.onCollisionEnter}
|
|
115
|
-
// {...props.rigidBodyProps}
|
|
116
|
-
// >
|
|
117
|
-
// {!props.isNotColliding && (
|
|
118
|
-
// <CapsuleCollider
|
|
119
|
-
// ref={props.colliderRef as any}
|
|
120
|
-
// args={[(size.y / 2 - size.x) * 1.2, size.x * 1.2]}
|
|
121
|
-
// position={[0, (size.y / 2 + size.x / 2) * 1.2, 0]}
|
|
122
|
-
// />
|
|
123
|
-
// )}
|
|
124
|
-
// <InnerGroupRef
|
|
125
|
-
// objectNode={objectNode}
|
|
126
|
-
// animationRef={animationRef}
|
|
127
|
-
// nodes={nodes}
|
|
128
|
-
// ref={props.innerGroupRef}
|
|
129
|
-
// isActive={props.isActive}
|
|
130
|
-
// isRiderOn={props.isRiderOn}
|
|
131
|
-
// enableRiding={props.enableRiding}
|
|
132
|
-
// ridingUrl={props.ridingUrl}
|
|
133
|
-
// offset={props.offset}
|
|
134
|
-
// parts={props.parts}
|
|
135
|
-
// >
|
|
136
|
-
// {props.children}
|
|
137
|
-
// {props.parts &&
|
|
138
|
-
// props.parts.length > 0 &&
|
|
139
|
-
// props.parts.map(({ url, color }, key) => {
|
|
140
|
-
// if (!url) return null;
|
|
141
|
-
// return (
|
|
142
|
-
// <PartsGroupRef
|
|
143
|
-
// url={url}
|
|
144
|
-
// isActive={props.isActive}
|
|
145
|
-
// componentType={props.componentType}
|
|
146
|
-
// currentAnimation={props.currentAnimation}
|
|
147
|
-
// color={color}
|
|
148
|
-
// key={key + url}
|
|
149
|
-
// />
|
|
150
|
-
// );
|
|
151
|
-
// })}
|
|
152
|
-
// </InnerGroupRef>
|
|
153
|
-
// </RigidBody>
|
|
154
|
-
// );
|
|
155
|
-
// }
|
|
156
|
-
// );
|
|
157
1
|
import { useAnimations, useGLTF } from "@react-three/drei";
|
|
158
2
|
import { useFrame, useGraph } from "@react-three/fiber";
|
|
159
3
|
import {
|
|
@@ -176,12 +20,13 @@ import { V3 } from "../../../utils";
|
|
|
176
20
|
import { GaesupWorldContext } from "../../../world/context";
|
|
177
21
|
import { InnerGroupRef } from "./InnerGroupRef";
|
|
178
22
|
import { PartsGroupRef } from "./partsGroupRef";
|
|
179
|
-
import {
|
|
23
|
+
import { useSetGroundRay } from "./setGroundRay";
|
|
180
24
|
import { rigidBodyRefType } from "./type";
|
|
181
25
|
|
|
182
26
|
export const RigidBodyRef = forwardRef(
|
|
183
27
|
(props: rigidBodyRefType, ref: MutableRefObject<RapierRigidBody>) => {
|
|
184
28
|
const { size } = useGltfAndSize({ url: props.url });
|
|
29
|
+
const setGroundRay = useSetGroundRay();
|
|
185
30
|
|
|
186
31
|
props.groundRay &&
|
|
187
32
|
setGroundRay({
|
|
@@ -1,19 +1,25 @@
|
|
|
1
|
+
// useSetGroundRay.ts
|
|
1
2
|
import { useRapier } from "@react-three/rapier";
|
|
2
3
|
import { groundRayType } from "../../../controller/type";
|
|
3
4
|
import { getRayHit } from "../../../utils";
|
|
4
5
|
import { setGroundRayType } from "./type";
|
|
5
6
|
|
|
6
|
-
export function
|
|
7
|
-
groundRay,
|
|
8
|
-
length,
|
|
9
|
-
colliderRef,
|
|
10
|
-
}: setGroundRayType) {
|
|
7
|
+
export function useSetGroundRay() {
|
|
11
8
|
const { rapier } = useRapier();
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
})
|
|
18
|
-
|
|
9
|
+
|
|
10
|
+
const setGroundRay = ({
|
|
11
|
+
groundRay,
|
|
12
|
+
length,
|
|
13
|
+
colliderRef,
|
|
14
|
+
}: setGroundRayType) => {
|
|
15
|
+
groundRay.length = length;
|
|
16
|
+
groundRay.rayCast = new rapier.Ray(groundRay.origin, groundRay.dir);
|
|
17
|
+
groundRay.hit = getRayHit<groundRayType>({
|
|
18
|
+
ray: groundRay,
|
|
19
|
+
ref: colliderRef,
|
|
20
|
+
});
|
|
21
|
+
groundRay.parent = groundRay.hit?.collider.parent();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
return setGroundRay;
|
|
19
25
|
}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
2
1
|
import * as THREE from "three";
|
|
3
|
-
import { GaesupWorldContext } from "../../world/context";
|
|
4
2
|
|
|
5
3
|
export function useTeleport() {
|
|
6
|
-
const worldContext = useContext(GaesupWorldContext);
|
|
4
|
+
// const worldContext = useContext(GaesupWorldContext);
|
|
7
5
|
|
|
8
6
|
const Teleport = (position: THREE.Vector3) => {
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
)
|
|
15
|
-
|
|
7
|
+
// if (
|
|
8
|
+
// worldContext &&
|
|
9
|
+
// worldContext?.refs &&
|
|
10
|
+
// worldContext?.refs?.rigidBodyRef &&
|
|
11
|
+
// worldContext?.refs?.rigidBodyRef?.current
|
|
12
|
+
// )
|
|
13
|
+
// worldContext.refs.rigidBodyRef.current.setTranslation(position, true);
|
|
16
14
|
};
|
|
17
15
|
|
|
18
16
|
return {
|
|
@@ -1,80 +1,72 @@
|
|
|
1
1
|
// Rideable.tsx
|
|
2
|
-
import { CollisionEnterPayload, euler } from "@react-three/rapier";
|
|
3
|
-
import { useContext, useEffect, useState } from "react";
|
|
4
|
-
import * as THREE from "three";
|
|
5
|
-
import { PassiveAirplane } from "../../component/passive/airplane";
|
|
6
|
-
import { PassiveVehicle } from "../../component/passive/vehicle";
|
|
7
|
-
import { useRideable } from "../../hooks/useRideable";
|
|
8
|
-
import { V3 } from "../../utils";
|
|
9
|
-
import { GaesupWorldContext } from "../../world/context";
|
|
10
2
|
import { rideablePropType } from "./type";
|
|
11
3
|
|
|
12
4
|
export function Rideable(props: rideablePropType) {
|
|
13
|
-
const { states, rideable } = useContext(GaesupWorldContext);
|
|
14
|
-
const { initRideable, ride, landing } = useRideable();
|
|
15
|
-
const [_rideable] = useState<{
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}>({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
|
|
25
|
-
}, []);
|
|
26
|
-
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}, [states?.isRiding]);
|
|
36
|
-
|
|
37
|
-
const onIntersectionEnter = async (e: CollisionEnterPayload) => {
|
|
38
|
-
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
);
|
|
5
|
+
// const { states, rideable } = useContext(GaesupWorldContext);
|
|
6
|
+
// const { initRideable, ride, landing } = useRideable();
|
|
7
|
+
// const [_rideable] = useState<{
|
|
8
|
+
// position: THREE.Vector3;
|
|
9
|
+
// rotation: THREE.Euler;
|
|
10
|
+
// }>({
|
|
11
|
+
// position: props.position || V3(0, 0, 0),
|
|
12
|
+
// rotation: props.rotation || euler(),
|
|
13
|
+
// });
|
|
14
|
+
//
|
|
15
|
+
// useEffect(() => {
|
|
16
|
+
// initRideable(props);
|
|
17
|
+
// }, []);
|
|
18
|
+
//
|
|
19
|
+
// useEffect(() => {
|
|
20
|
+
// if (
|
|
21
|
+
// states?.isRiding &&
|
|
22
|
+
// rideable[props.objectkey] &&
|
|
23
|
+
// !rideable[props.objectkey].visible
|
|
24
|
+
// ) {
|
|
25
|
+
// landing(props.objectkey);
|
|
26
|
+
// }
|
|
27
|
+
// }, [states?.isRiding]);
|
|
28
|
+
//
|
|
29
|
+
// const onIntersectionEnter = async (e: CollisionEnterPayload) => {
|
|
30
|
+
// await ride(e, props);
|
|
31
|
+
// };
|
|
32
|
+
//
|
|
33
|
+
// return (
|
|
34
|
+
// <>
|
|
35
|
+
// {rideable?.[props.objectkey]?.visible && (
|
|
36
|
+
// <group userData={{ intangible: true }}>
|
|
37
|
+
// {props.objectType === "vehicle" && (
|
|
38
|
+
// <PassiveVehicle
|
|
39
|
+
// controllerOptions={props.controllerOptions}
|
|
40
|
+
// position={_rideable.position}
|
|
41
|
+
// rotation={_rideable.rotation}
|
|
42
|
+
// currentAnimation={"idle"}
|
|
43
|
+
// url={props.url}
|
|
44
|
+
// wheelUrl={props.wheelUrl}
|
|
45
|
+
// ridingUrl={props.ridingUrl}
|
|
46
|
+
// offset={props.offset}
|
|
47
|
+
// enableRiding={props.enableRiding}
|
|
48
|
+
// rigidBodyProps={props.rigidBodyProps}
|
|
49
|
+
// sensor={true}
|
|
50
|
+
// onIntersectionEnter={onIntersectionEnter}
|
|
51
|
+
// />
|
|
52
|
+
// )}
|
|
53
|
+
// {props.objectType === "airplane" && (
|
|
54
|
+
// <PassiveAirplane
|
|
55
|
+
// controllerOptions={props.controllerOptions}
|
|
56
|
+
// position={_rideable.position.clone()}
|
|
57
|
+
// rotation={_rideable.rotation.clone()}
|
|
58
|
+
// currentAnimation={"idle"}
|
|
59
|
+
// url={props.url}
|
|
60
|
+
// ridingUrl={props.ridingUrl}
|
|
61
|
+
// offset={props.offset}
|
|
62
|
+
// enableRiding={props.enableRiding}
|
|
63
|
+
// rigidBodyProps={props.rigidBodyProps}
|
|
64
|
+
// sensor={true}
|
|
65
|
+
// onIntersectionEnter={onIntersectionEnter}
|
|
66
|
+
// />
|
|
67
|
+
// )}
|
|
68
|
+
// </group>
|
|
69
|
+
// )}
|
|
70
|
+
// </>
|
|
71
|
+
// );
|
|
80
72
|
}
|