gaesup-world 0.6.4 → 0.6.6
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/camera/detector/index.js +26 -23
- package/dist/gaesup/camera/index.d.ts +2 -8
- package/dist/gaesup/camera/index.js +42 -48
- package/dist/gaesup/component/inner/character/index.js +1 -1
- package/dist/gaesup/component/inner/common/InnerGroupRef.js +16 -2
- package/dist/gaesup/controller/index.js +2 -3
- package/dist/gaesup/controller/type.d.ts +4 -2
- package/dist/gaesup/physics/airplane/direction.js +1 -1
- package/dist/gaesup/physics/index.js +1 -3
- package/dist/gaesup/physics/type.d.ts +1 -9
- package/dist/gaesup/physics/vehicle/direction.js +1 -1
- package/dist/gaesup/physics/vehicle/impulse.d.ts +0 -14
- package/dist/gaesup/physics/vehicle/impulse.js +0 -15
- package/package.json +1 -1
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
import * as THREE from "three";
|
|
2
1
|
export default function detector(cameraProp) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
2
|
+
// const { cameraRay, intersectObjectMap } = cameraProp;
|
|
3
|
+
//
|
|
4
|
+
// const intersects = cameraRay.rayCast.intersectObjects(
|
|
5
|
+
// Object.values(intersectObjectMap)
|
|
6
|
+
// );
|
|
7
|
+
//
|
|
8
|
+
// const intersectId = {};
|
|
9
|
+
//
|
|
10
|
+
// intersects.map(({ object }) => {
|
|
11
|
+
// if (object instanceof THREE.Mesh) {
|
|
12
|
+
// intersectId[object.uuid] = true;
|
|
13
|
+
// }
|
|
14
|
+
// });
|
|
15
|
+
//
|
|
16
|
+
// Object.values(intersectObjectMap).map((mesh) => {
|
|
17
|
+
// if (mesh instanceof THREE.Mesh && mesh.material instanceof THREE.Material) {
|
|
18
|
+
// const material = mesh.material;
|
|
19
|
+
// if (intersectId[mesh.uuid]) {
|
|
20
|
+
// material.opacity = 0.2;
|
|
21
|
+
// material.transparent = true;
|
|
22
|
+
// } else {
|
|
23
|
+
// material.opacity = 1;
|
|
24
|
+
// material.transparent = false;
|
|
25
|
+
// }
|
|
26
|
+
// }
|
|
27
|
+
// });
|
|
25
28
|
}
|
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default function Camera(
|
|
3
|
-
refs: refsType;
|
|
4
|
-
prop: controllerInnerType;
|
|
5
|
-
control: {
|
|
6
|
-
[key: string]: boolean;
|
|
7
|
-
};
|
|
8
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
1
|
+
import { cameraPropType } from "../physics/type";
|
|
2
|
+
export default function Camera(prop: cameraPropType): void;
|
|
@@ -1,62 +1,56 @@
|
|
|
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 { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import { CameraControls } from "@react-three/drei";
|
|
14
1
|
import { useFrame } from "@react-three/fiber";
|
|
15
|
-
import { useContext, useEffect, useMemo, useRef } from "react";
|
|
16
|
-
import * as THREE from "three";
|
|
17
|
-
import { GaesupControllerContext } from "../controller/context";
|
|
18
|
-
import { GaesupWorldContext } from "../world/context";
|
|
19
2
|
import normal, { makeNormalCameraPosition } from "./control/normal";
|
|
20
3
|
import orbit from "./control/orbit";
|
|
21
|
-
export default function Camera(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
4
|
+
export default function Camera(prop) {
|
|
5
|
+
// const worldContext = useContext(GaesupWorldContext);
|
|
6
|
+
// const controllerContext = useContext(GaesupControllerContext);
|
|
7
|
+
// const { mode, cameraOption, activeState } = worldContext;
|
|
8
|
+
// const cameraRef = useRef<CameraControls>();
|
|
9
|
+
// const intersectObjectMap: intersectObjectMapType = useMemo(() => ({}), []);
|
|
10
|
+
// const cameraProp: cameraPropType = {
|
|
11
|
+
// ...prop,
|
|
12
|
+
// // control,
|
|
13
|
+
// controllerContext,
|
|
14
|
+
// worldContext,
|
|
15
|
+
// // intersectObjectMap,
|
|
16
|
+
// };
|
|
17
|
+
// cameraProp.cameraRay.rayCast = new THREE.Raycaster(
|
|
18
|
+
// cameraProp.cameraRay.origin,
|
|
19
|
+
// cameraProp.cameraRay.dir,
|
|
20
|
+
// 0,
|
|
21
|
+
// -cameraOption.maxDistance
|
|
22
|
+
// );
|
|
31
23
|
useFrame(function (state, delta) {
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
// if (
|
|
25
|
+
// !rigidBodyRef ||
|
|
26
|
+
// !rigidBodyRef.current ||
|
|
27
|
+
// !outerGroupRef ||
|
|
28
|
+
// !outerGroupRef.current
|
|
29
|
+
// )
|
|
30
|
+
// return;
|
|
31
|
+
// cameraProp.delta = delta;
|
|
32
|
+
prop.state = state;
|
|
33
|
+
if (!prop.worldContext.block.camera) {
|
|
34
|
+
if (prop.worldContext.mode.control === "orbit") {
|
|
35
|
+
orbit(prop);
|
|
42
36
|
}
|
|
43
|
-
else if (mode.control === "normal") {
|
|
44
|
-
normal(
|
|
37
|
+
else if (prop.worldContext.mode.control === "normal") {
|
|
38
|
+
normal(prop);
|
|
45
39
|
}
|
|
46
40
|
}
|
|
47
41
|
});
|
|
48
42
|
// zoom
|
|
49
|
-
useEffect(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}, [worldContext.cameraOption.zoom]);
|
|
43
|
+
// useEffect(() => {
|
|
44
|
+
// if (cameraRef.current) {
|
|
45
|
+
// cameraRef.current.zoomTo(worldContext.cameraOption.zoom, true);
|
|
46
|
+
// }
|
|
47
|
+
// }, [worldContext.cameraOption.zoom]);
|
|
54
48
|
// 포커스가 아닐 때 카메라 activeStae 따라가기
|
|
55
49
|
useFrame(function () {
|
|
56
|
-
if (!cameraOption.focus) {
|
|
57
|
-
cameraOption.target =
|
|
58
|
-
|
|
50
|
+
if (!prop.worldContext.cameraOption.focus) {
|
|
51
|
+
prop.worldContext.cameraOption.target =
|
|
52
|
+
prop.worldContext.activeState.position;
|
|
53
|
+
prop.worldContext.cameraOption.position = makeNormalCameraPosition(prop.worldContext.activeState, prop.worldContext.cameraOption);
|
|
59
54
|
}
|
|
60
55
|
});
|
|
61
|
-
return _jsx(CameraControls, { ref: cameraRef });
|
|
62
56
|
}
|
|
@@ -24,5 +24,5 @@ export function CharacterInnerRef(_a) {
|
|
|
24
24
|
var outerGroupRef = refs.outerGroupRef, rigidBodyRef = refs.rigidBodyRef, colliderRef = refs.colliderRef, innerGroupRef = refs.innerGroupRef;
|
|
25
25
|
var size = useGltfAndSize({ url: urls.characterUrl }).size;
|
|
26
26
|
var collider = calcCharacterColliderProps(size);
|
|
27
|
-
return (_jsx(_Fragment, { children: collider && (_jsx(
|
|
27
|
+
return (_jsx(_Fragment, { children: collider && (_jsx(RigidBodyRef, { ref: rigidBodyRef, name: "character", position: position, positionLerp: positionLerp, rotation: euler, type: type, children: _jsxs(OuterGroupRef, { ref: outerGroupRef, children: [_jsx(CapsuleCollider, { ref: colliderRef, args: [collider.height, collider.radius], position: [0, collider.height + collider.radius, 0] }), _jsx(InnerGroupRef, { type: "character", ref: innerGroupRef, url: urls.characterUrl, currentAnimation: currentAnimation, children: children })] }) })) }));
|
|
28
28
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useGraph } from "@react-three/fiber";
|
|
3
|
-
import { forwardRef, useMemo } from "react";
|
|
2
|
+
import { useFrame, useGraph } from "@react-three/fiber";
|
|
3
|
+
import { forwardRef, useContext, useMemo } from "react";
|
|
4
4
|
import * as THREE from "three";
|
|
5
5
|
import { SkeletonUtils } from "three-stdlib";
|
|
6
6
|
import { useAnimations, useGLTF } from "@react-three/drei";
|
|
7
7
|
import playActions from "../../../animation/actions";
|
|
8
|
+
import Camera from "../../../camera";
|
|
9
|
+
import { GaesupControllerContext } from "../../../controller/context";
|
|
10
|
+
import { GaesupWorldContext } from "../../../world/context";
|
|
8
11
|
export var InnerGroupRef = forwardRef(function (_a, ref) {
|
|
9
12
|
var children = _a.children, type = _a.type, currentAnimation = _a.currentAnimation, url = _a.url, rotation = _a.rotation;
|
|
10
13
|
var _b = useGLTF(url), scene = _b.scene, animations = _b.animations;
|
|
@@ -17,6 +20,17 @@ export var InnerGroupRef = forwardRef(function (_a, ref) {
|
|
|
17
20
|
var clone = useMemo(function () { return SkeletonUtils.clone(scene); }, [scene]);
|
|
18
21
|
var nodes = useGraph(clone).nodes;
|
|
19
22
|
var objectNode = Object.values(nodes).find(function (node) { return node.type === "Object3D"; });
|
|
23
|
+
var worldContext = useContext(GaesupWorldContext);
|
|
24
|
+
var controllerContext = useContext(GaesupControllerContext);
|
|
25
|
+
var props = {
|
|
26
|
+
state: null,
|
|
27
|
+
worldContext: worldContext,
|
|
28
|
+
controllerContext: controllerContext,
|
|
29
|
+
};
|
|
30
|
+
useFrame(function (state) {
|
|
31
|
+
props.state = state;
|
|
32
|
+
});
|
|
33
|
+
Camera(props);
|
|
20
34
|
return (_jsxs("group", { receiveShadow: true, castShadow: true, ref: ref, rotation: rotation, userData: { intangible: true }, children: [children, objectNode && animationRef && (_jsx("primitive", { object: objectNode, visible: false, receiveShadow: true, castShadow: true, ref: animationRef })), Object.keys(nodes).map(function (name, key) {
|
|
21
35
|
var node = nodes[name];
|
|
22
36
|
if (node instanceof THREE.SkinnedMesh) {
|
|
@@ -10,9 +10,8 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
-
import { jsx as _jsx
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { useContext, useMemo, useReducer, useRef } from "react";
|
|
15
|
-
import Camera from "../camera";
|
|
16
15
|
import { KeyboardControls } from "@react-three/drei";
|
|
17
16
|
import { GaesupComponent } from "../component";
|
|
18
17
|
import { GaesupWorldContext } from "../world/context";
|
|
@@ -71,5 +70,5 @@ export function GaesupControllerInner(props) {
|
|
|
71
70
|
controllerContext: gaesupControl.value,
|
|
72
71
|
controllerDispatch: gaesupControl.dispatch,
|
|
73
72
|
});
|
|
74
|
-
return (
|
|
73
|
+
return (_jsx(GaesupControllerContext.Provider, { value: gaesupControl.value, children: _jsx(GaesupControllerDispatchContext.Provider, { value: gaesupControl.dispatch, children: _jsx(GaesupComponent, { props: prop, refs: refs, urls: props.urls }) }) }));
|
|
75
74
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Collider, Ray, RayColliderToi } from "@dimforge/rapier3d-compat";
|
|
2
|
-
import { GroupProps } from "@react-three/fiber";
|
|
3
|
-
import { RapierRigidBody, RigidBodyProps } from "@react-three/rapier";
|
|
2
|
+
import { GroupProps, Props } from "@react-three/fiber";
|
|
3
|
+
import { PhysicsProps, RapierRigidBody, RigidBodyProps } from "@react-three/rapier";
|
|
4
4
|
import { ReactNode, RefObject } from "react";
|
|
5
5
|
import * as THREE from "three";
|
|
6
6
|
import { cameraRayType } from "../camera/type";
|
|
@@ -81,5 +81,7 @@ export interface controllerOtherPropType extends RigidBodyProps {
|
|
|
81
81
|
groupProps?: GroupProps;
|
|
82
82
|
rigidBodyProps?: RigidBodyProps;
|
|
83
83
|
debug?: boolean;
|
|
84
|
+
CanvasProps?: Partial<Props>;
|
|
85
|
+
PhysicsProps?: Partial<PhysicsProps>;
|
|
84
86
|
}
|
|
85
87
|
export type controllerType = controllerOtherPropType & Partial<gaesupControllerContextPropType> & callbackType;
|
|
@@ -1,7 +1,7 @@
|
|
|
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,
|
|
4
|
+
var innerGroupRef = prop.innerGroupRef, _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
7
|
if (!matchSizes || !matchSizes["airplaneUrl"])
|
|
@@ -10,7 +10,6 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
12
|
import { useFrame } from "@react-three/fiber";
|
|
13
|
-
import { useRapier } from "@react-three/rapier";
|
|
14
13
|
import { useContext, useEffect } from "react";
|
|
15
14
|
import { GaesupControllerContext } from "../controller/context";
|
|
16
15
|
import { useGaesupGltf } from "../hooks/useGaesupGltf";
|
|
@@ -21,7 +20,6 @@ import characterCalculation from "./character";
|
|
|
21
20
|
import check from "./check";
|
|
22
21
|
import vehicleCalculation from "./vehicle";
|
|
23
22
|
export default function calculation(prop) {
|
|
24
|
-
var world = useRapier().world;
|
|
25
23
|
var worldContext = useContext(GaesupWorldContext);
|
|
26
24
|
var controllerContext = useContext(GaesupControllerContext);
|
|
27
25
|
var dispatch = useContext(GaesupWorldDispatchContext);
|
|
@@ -46,7 +44,7 @@ export default function calculation(prop) {
|
|
|
46
44
|
return null;
|
|
47
45
|
if (block.control)
|
|
48
46
|
return null;
|
|
49
|
-
var calcProp = __assign(__assign({}, prop), { state: state, delta: delta, worldContext: worldContext, controllerContext: controllerContext, dispatch: dispatch,
|
|
47
|
+
var calcProp = __assign(__assign({}, prop), { state: state, delta: delta, worldContext: worldContext, controllerContext: controllerContext, dispatch: dispatch, matchSizes: getSizesByUrls(controllerContext === null || controllerContext === void 0 ? void 0 : controllerContext.urls) });
|
|
50
48
|
if (mode.type === "vehicle")
|
|
51
49
|
vehicleCalculation(calcProp);
|
|
52
50
|
else if (mode.type === "character")
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { RootState } from "@react-three/fiber";
|
|
2
|
-
import { World } from "@dimforge/rapier3d-compat";
|
|
3
2
|
import * as THREE from "three";
|
|
4
3
|
import { gaesupControllerType } from "../controller/context/type";
|
|
5
4
|
import { controllerInnerType, refsType } from "../controller/type";
|
|
@@ -19,19 +18,12 @@ export type calcPropType = controllerInnerType & {
|
|
|
19
18
|
};
|
|
20
19
|
delta?: number;
|
|
21
20
|
dispatch?: dispatchType<gaesupWorldContextType>;
|
|
22
|
-
world: World;
|
|
23
21
|
};
|
|
24
22
|
export type intersectObjectMapType = {
|
|
25
23
|
[uuid: string]: THREE.Mesh;
|
|
26
24
|
};
|
|
27
|
-
export type cameraPropType =
|
|
28
|
-
control: {
|
|
29
|
-
[key: string]: boolean;
|
|
30
|
-
};
|
|
25
|
+
export type cameraPropType = {
|
|
31
26
|
state?: RootState;
|
|
32
27
|
worldContext?: gaesupWorldContextType;
|
|
33
28
|
controllerContext?: gaesupControllerType;
|
|
34
|
-
intersectObjectMap?: intersectObjectMapType;
|
|
35
|
-
delta?: number;
|
|
36
|
-
dist?: number;
|
|
37
29
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { vec3 } from "@react-three/rapier";
|
|
2
2
|
import { V3 } from "../../utils/vector";
|
|
3
3
|
export function joystick(prop) {
|
|
4
|
-
var
|
|
4
|
+
var _a = prop.worldContext, activeState = _a.activeState, joystick = _a.joystick;
|
|
5
5
|
var zAxis = joystick.joyStickOrigin.isOn ? 1 : 0;
|
|
6
6
|
var front = vec3().set(zAxis, 0, zAxis);
|
|
7
7
|
if (joystick.joyStickOrigin.isCenter)
|
|
@@ -1,16 +1,2 @@
|
|
|
1
1
|
import { calcPropType } from "../type";
|
|
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
2
|
export default function impulse(prop: calcPropType): void;
|
|
@@ -1,24 +1,9 @@
|
|
|
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
|
-
*/
|
|
16
2
|
export default function impulse(prop) {
|
|
17
3
|
var rigidBodyRef = prop.rigidBodyRef, _a = prop.worldContext, activeState = _a.activeState, control = _a.control, mode = _a.mode, joystick = _a.joystick, vehicle = prop.controllerContext.vehicle;
|
|
18
4
|
var shift = control.shift;
|
|
19
5
|
var maxSpeed = vehicle.maxSpeed, accelRatio = vehicle.accelRatio;
|
|
20
6
|
var velocity = rigidBodyRef.current.linvel();
|
|
21
|
-
// const V = vec3(velocity).length();
|
|
22
7
|
// a = v / t (t = 1) (approximate calculation)
|
|
23
8
|
var V = vec3(velocity).length();
|
|
24
9
|
if (V < maxSpeed) {
|