gaesup-world 0.8.47 → 0.8.51

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.
@@ -13,5 +13,5 @@ import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { CharacterInnerRef } from "../../inner/character";
14
14
  export function CharacterRef(_a) {
15
15
  var children = _a.children, props = _a.props, refs = _a.refs, urls = _a.urls;
16
- return (_jsx(CharacterInnerRef, __assign({ url: urls.characterUrl, isActive: true, componentType: "character", rigidbodyType: "dynamic", controllerOptions: props.controllerOptions, groundRay: props.groundRay, onAnimate: props.onAnimate, onFrame: props.onFrame, onReady: props.onReady, onDestory: props.onDestory, rigidBodyProps: props.rigidBodyProps }, refs, { children: children })));
16
+ return (_jsx(CharacterInnerRef, __assign({ url: urls.characterUrl, isActive: true, componentType: "character", rigidbodyType: "dynamic", controllerOptions: props.controllerOptions, groundRay: props.groundRay, onAnimate: props.onAnimate, onFrame: props.onFrame, onReady: props.onReady, onDestory: props.onDestory, rigidBodyProps: props.rigidBodyProps, parts: props.parts }, refs, { children: children })));
17
17
  }
@@ -1,9 +1,10 @@
1
1
  import { callbackType } from "../../../controller/initialize/callback/type";
2
- import { groundRayType } from "../../../controller/type";
2
+ import { groundRayType, partsType } from "../../../controller/type";
3
3
  import { passiveCharacterPropsType } from "../../passive/character/type";
4
4
  import { componentTypeString, innerRefType } from "../../passive/type";
5
5
  export type characterInnerType = {
6
6
  componentType: componentTypeString;
7
7
  isActive?: boolean;
8
8
  groundRay: groundRayType;
9
+ parts?: partsType;
9
10
  } & passiveCharacterPropsType & innerRefType & callbackType;
@@ -10,4 +10,5 @@ export declare const InnerGroupRef: import("react").ForwardRefExoticComponent<{
10
10
  isActive?: boolean;
11
11
  ridingUrl?: string;
12
12
  offset?: THREE.Vector3;
13
+ parts?: import("../../../controller/type").partsType;
13
14
  } & import("./type").ridingType & import("react").RefAttributes<THREE.Group<THREE.Object3DEventMap>>>;
@@ -10,6 +10,7 @@ export declare const RigidBodyRef: import("react").ForwardRefExoticComponent<{
10
10
  ridingUrl?: string;
11
11
  groundRay?: import("../../../controller/type").groundRayType;
12
12
  rigidBodyProps?: import("@react-three/rapier").RigidBodyProps;
13
+ parts?: import("../../../controller/type").partsType;
13
14
  } & {
14
15
  children?: import("react").ReactNode;
15
16
  groundRay?: import("../../../controller/type").groundRayType;
@@ -32,4 +33,5 @@ export declare const RigidBodyRef: import("react").ForwardRefExoticComponent<{
32
33
  rigidBodyProps?: import("@react-three/rapier").RigidBodyProps;
33
34
  outerGroupProps?: THREE.Group<THREE.Object3DEventMap>;
34
35
  innerGroupProps?: THREE.Group<THREE.Object3DEventMap>;
36
+ parts?: string[];
35
37
  } & import("./type").ridingType & import("../../passive/type").innerRefType & import("../../../controller/initialize/callback/type").callbackType & import("react").RefAttributes<RapierRigidBody>>;
@@ -25,6 +25,7 @@ import calculation from "../../../physics";
25
25
  import { V3 } from "../../../utils";
26
26
  import { GaesupWorldContext } from "../../../world/context";
27
27
  import { InnerGroupRef } from "./InnerGroupRef";
28
+ import { PartsGroupRef } from "./partsGroupRef";
28
29
  import { setGroundRay } from "./setGroundRay";
29
30
  export var RigidBodyRef = forwardRef(function (props, ref) {
30
31
  var _a;
@@ -85,5 +86,8 @@ export var RigidBodyRef = forwardRef(function (props, ref) {
85
86
  });
86
87
  return (_jsxs(RigidBody, __assign({ colliders: false, ref: ref, name: props.name, rotation: euler()
87
88
  .set(0, ((_a = props.rotation) === null || _a === void 0 ? void 0 : _a.clone().y) || 0, 0)
88
- .clone(), userData: props.userData, type: props.rigidbodyType || (props.isActive ? "dynamic" : "fixed"), sensor: props.sensor, onIntersectionEnter: props.onIntersectionEnter, onCollisionEnter: props.onCollisionEnter }, props.rigidBodyProps, { children: [_jsx(CapsuleCollider, { ref: props.colliderRef, args: [(size.y / 2 - size.x) * 1.2, size.x * 1.2], position: [0, (size.y / 2 + size.x / 2) * 1.2, 0] }), _jsx(InnerGroupRef, { objectNode: objectNode, animationRef: animationRef, nodes: nodes, ref: props.innerGroupRef, isActive: props.isActive, isRiderOn: props.isRiderOn, enableRiding: props.enableRiding, ridingUrl: props.ridingUrl, offset: props.offset, children: props.children })] })));
89
+ .clone(), userData: props.userData, type: props.rigidbodyType || (props.isActive ? "dynamic" : "fixed"), sensor: props.sensor, onIntersectionEnter: props.onIntersectionEnter, onCollisionEnter: props.onCollisionEnter }, props.rigidBodyProps, { children: [_jsx(CapsuleCollider, { ref: props.colliderRef, args: [(size.y / 2 - size.x) * 1.2, size.x * 1.2], position: [0, (size.y / 2 + size.x / 2) * 1.2, 0] }), _jsxs(InnerGroupRef, { objectNode: objectNode, animationRef: animationRef, nodes: nodes, ref: props.innerGroupRef, isActive: props.isActive, isRiderOn: props.isRiderOn, enableRiding: props.enableRiding, ridingUrl: props.ridingUrl, offset: props.offset, parts: props.parts, children: [props.children, props.parts &&
90
+ props.parts.map(function (url, key) {
91
+ return (_jsx(PartsGroupRef, { url: url, isActive: props.isActive, componentType: props.componentType, currentAnimation: props.currentAnimation }, key + url));
92
+ })] })] })));
89
93
  });
@@ -0,0 +1,7 @@
1
+ import { componentTypeString } from "../../passive/type";
2
+ export declare const PartsGroupRef: ({ url, isActive, componentType, currentAnimation, }: {
3
+ url: string;
4
+ isActive: boolean;
5
+ componentType: componentTypeString;
6
+ currentAnimation: string;
7
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useAnimations, useGLTF } from "@react-three/drei";
3
+ import { useGraph } from "@react-three/fiber";
4
+ import { useMemo } from "react";
5
+ import * as THREE from "three";
6
+ import { SkeletonUtils } from "three-stdlib";
7
+ import playActions from "../../../animation/actions";
8
+ export var PartsGroupRef = function (_a) {
9
+ var url = _a.url, isActive = _a.isActive, componentType = _a.componentType, currentAnimation = _a.currentAnimation;
10
+ var _b = useGLTF(url), scene = _b.scene, animations = _b.animations;
11
+ var clone = useMemo(function () { return SkeletonUtils.clone(scene); }, [scene]);
12
+ var _c = useAnimations(animations), actions = _c.actions, ref = _c.ref;
13
+ var nodes = useGraph(clone).nodes;
14
+ var objectNode = Object.values(nodes).find(function (node) { return node.type === "Object3D"; });
15
+ playActions({
16
+ type: componentType,
17
+ actions: actions,
18
+ animationRef: ref,
19
+ currentAnimation: isActive ? undefined : currentAnimation,
20
+ isActive: isActive,
21
+ });
22
+ return (_jsxs(_Fragment, { children: [_jsx("primitive", { object: objectNode, visible: false, receiveShadow: true, castShadow: true, ref: ref }), Object.keys(nodes).map(function (name, key) {
23
+ var node = nodes[name];
24
+ if (node instanceof THREE.SkinnedMesh) {
25
+ return (_jsx("skinnedMesh", { castShadow: true, receiveShadow: true, material: node.material, geometry: node.geometry, skeleton: node.skeleton }, key));
26
+ }
27
+ else if (node instanceof THREE.Mesh) {
28
+ return (_jsx("mesh", { castShadow: true, receiveShadow: true, material: node.material, geometry: node.geometry }, key));
29
+ }
30
+ })] }));
31
+ };
@@ -3,7 +3,7 @@ import { RigidBodyProps, RigidBodyTypeString } from "@react-three/rapier";
3
3
  import { MutableRefObject, RefObject } from "react";
4
4
  import * as THREE from "three";
5
5
  import { callbackType } from "../../../controller/initialize/callback/type";
6
- import { groundRayType } from "../../../controller/type";
6
+ import { groundRayType, partsType } from "../../../controller/type";
7
7
  import { urlsType } from "../../../world/context/type";
8
8
  import { innerRefType, passivePropsType } from "../../passive/type";
9
9
  export type characterColliderType = {
@@ -22,6 +22,7 @@ export type InnerGroupRefType = {
22
22
  isActive?: boolean;
23
23
  ridingUrl?: string;
24
24
  offset?: THREE.Vector3;
25
+ parts?: partsType;
25
26
  } & ridingType;
26
27
  export type ridingType = {
27
28
  isRiderOn?: boolean;
@@ -56,4 +57,5 @@ export type rigidBodyRefType = {
56
57
  ridingUrl?: string;
57
58
  groundRay?: groundRayType;
58
59
  rigidBodyProps?: RigidBodyProps;
60
+ parts?: partsType;
59
61
  } & passivePropsType & innerRefType & callbackType;
@@ -33,4 +33,5 @@ export type passivePropsType = {
33
33
  rigidBodyProps?: RigidBodyProps;
34
34
  outerGroupProps?: THREE.Group;
35
35
  innerGroupProps?: THREE.Group;
36
+ parts?: string[];
36
37
  } & ridingType;
@@ -65,7 +65,7 @@ export function GaesupControllerInner(props) {
65
65
  }, []);
66
66
  var prop = __assign(__assign(__assign(__assign({}, initControllerProps({
67
67
  refs: refs,
68
- })), { children: props.children, groupProps: props.groupProps, rigidBodyProps: props.rigidBodyProps, controllerOptions: gaesupControl.value.controllerOptions }), gaesupControl.value.callbacks), refs);
68
+ })), { children: props.children, groupProps: props.groupProps, rigidBodyProps: props.rigidBodyProps, controllerOptions: gaesupControl.value.controllerOptions, parts: props.parts }), gaesupControl.value.callbacks), refs);
69
69
  initDebug({
70
70
  controllerContext: gaesupControl.value,
71
71
  controllerDispatch: gaesupControl.dispatch,
@@ -54,6 +54,7 @@ export type controllerInnerType = {
54
54
  cameraRay: cameraRayType;
55
55
  keyControl: keyControlType;
56
56
  controllerOptions: controllerOptionsType;
57
+ parts?: partsType;
57
58
  } & controllerOtherPropType & refsType & callbackType;
58
59
  export type animationTagType = {
59
60
  idle: string;
@@ -89,6 +90,8 @@ export interface controllerOtherPropType extends RigidBodyProps {
89
90
  rigidBodyProps?: RigidBodyProps;
90
91
  debug?: boolean;
91
92
  }
93
+ export type partsType = string[];
92
94
  export type controllerType = controllerOtherPropType & urlsType & Partial<gaesupControllerContextPropType> & callbackType & {
93
95
  controllerOptions?: controllerOptionsType;
96
+ parts?: partsType;
94
97
  };
@@ -1,10 +1,12 @@
1
1
  import direction from "./direction";
2
2
  import impulse from "./impulse";
3
3
  import innerCalc from "./innerCalc";
4
+ import queue from "./queue";
4
5
  import stop from "./stop";
5
6
  export default function characterCalculation(calcProp) {
6
7
  direction(calcProp);
7
8
  impulse(calcProp);
8
9
  innerCalc(calcProp);
9
10
  stop(calcProp);
11
+ queue(calcProp);
10
12
  }
@@ -0,0 +1,2 @@
1
+ import { calcType } from "../type";
2
+ export default function queue(prop: calcType): void;
@@ -0,0 +1,48 @@
1
+ import { vec3 } from "@react-three/rapier";
2
+ import * as THREE from "three";
3
+ import { calcNorm } from "../../utils";
4
+ export default function queue(prop) {
5
+ var _a;
6
+ var rigidBodyRef = prop.rigidBodyRef, state = prop.state, _b = prop.worldContext, clicker = _b.clicker, mode = _b.mode, clickerOption = _b.clickerOption, block = _b.block;
7
+ var u = vec3((_a = rigidBodyRef.current) === null || _a === void 0 ? void 0 : _a.translation());
8
+ var norm = calcNorm(u, clicker.point, false);
9
+ if (clickerOption.autoStart) {
10
+ if (clickerOption.queue[0] instanceof THREE.Vector3) {
11
+ clicker.isOn = true;
12
+ norm = calcNorm(u, clickerOption.queue[0], false);
13
+ var v = vec3(clickerOption.queue[0]);
14
+ var newAngle = Math.atan2(v.z - u.z, v.x - u.x);
15
+ clicker.angle = newAngle;
16
+ }
17
+ }
18
+ if (norm < 1 && mode.controller === "clicker") {
19
+ if (clickerOption.track && clickerOption.queue.length !== 0) {
20
+ var Q = clickerOption.queue.shift();
21
+ if (Q instanceof THREE.Vector3) {
22
+ clicker.point = Q;
23
+ var v = vec3(clicker.point);
24
+ var newAngle = Math.atan2(v.z - u.z, v.x - u.x);
25
+ clicker.angle = newAngle;
26
+ }
27
+ else {
28
+ var action = Q.action, beforeCB = Q.beforeCB, afterCB_1 = Q.afterCB, time = Q.time;
29
+ if (action === "stop") {
30
+ state.clock.stop();
31
+ beforeCB(state);
32
+ console.log();
33
+ setTimeout(function () {
34
+ state.clock.start();
35
+ afterCB_1(state);
36
+ }, time);
37
+ }
38
+ }
39
+ if (clickerOption.loop) {
40
+ clickerOption.queue.push(Q);
41
+ }
42
+ }
43
+ else {
44
+ clicker.isOn = false;
45
+ clicker.isRun = false;
46
+ }
47
+ }
48
+ }
@@ -1,35 +1,8 @@
1
- import { vec3 } from "@react-three/rapier";
2
- import { calcNorm } from "../../utils";
3
1
  export default function stop(prop) {
4
- var _a;
5
- var rigidBodyRef = prop.rigidBodyRef, _b = prop.worldContext, control = _b.control, clicker = _b.clicker, mode = _b.mode, clickerOption = _b.clickerOption;
2
+ var _a = prop.worldContext, control = _a.control, clicker = _a.clicker, mode = _a.mode;
6
3
  var keyS = control.keyS;
7
4
  if (keyS && mode.controller === "clicker") {
8
5
  clicker.isOn = false;
9
6
  clicker.isRun = false;
10
7
  }
11
- var u = vec3((_a = rigidBodyRef.current) === null || _a === void 0 ? void 0 : _a.translation());
12
- var norm = calcNorm(u, clicker.point, false);
13
- if (clickerOption.autoStart) {
14
- clicker.isOn = true;
15
- norm = calcNorm(u, clickerOption.queue[0], false);
16
- var v = vec3(clickerOption.queue[0]);
17
- var newAngle = Math.atan2(v.z - u.z, v.x - u.x);
18
- clicker.angle = newAngle;
19
- }
20
- if (norm < 1 && mode.controller === "clicker") {
21
- if (clickerOption.track && clickerOption.queue.length !== 0) {
22
- clicker.point = clickerOption.queue.shift();
23
- var v = vec3(clicker.point);
24
- var newAngle = Math.atan2(v.z - u.z, v.x - u.x);
25
- clicker.angle = newAngle;
26
- if (clickerOption.loop) {
27
- clickerOption.queue.push(clicker.point);
28
- }
29
- }
30
- else {
31
- clicker.isOn = false;
32
- clicker.isRun = false;
33
- }
34
- }
35
8
  }
@@ -1,17 +1,23 @@
1
1
  import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { Line } from "@react-three/drei";
3
3
  import { useContext } from "react";
4
+ import * as THREE from "three";
4
5
  import { GaesupWorldContext } from "../../world/context";
5
6
  export function Clicker(_a) {
6
7
  var onMarker = _a.onMarker, runMarker = _a.runMarker;
7
8
  var _b = useContext(GaesupWorldContext), clicker = _b.clicker, mode = _b.mode, clickerOption = _b.clickerOption;
9
+ var pointQ = [];
10
+ for (var i = 0; i < clickerOption.queue.length; i++) {
11
+ if (clickerOption.queue[i] instanceof THREE.Vector3) {
12
+ pointQ.push(clickerOption.queue[i]);
13
+ }
14
+ }
8
15
  return (_jsxs(_Fragment, { children: [mode.controller === "clicker" && (_jsxs("group", { position: clicker.point, children: [clicker.isOn && onMarker, clicker.isOn && clickerOption.isRun && clicker.isRun && runMarker] })), clickerOption.line &&
9
- clickerOption.queue.map(function (item, key) {
10
- var current = key;
11
- var before = key === 0 ? clickerOption.queue.length - 1 : key - 1;
12
- return (_jsxs("group", { position: [0, 1, 0], children: [_jsx(Line, { worldUnits: true, points: [
13
- clickerOption.queue[before],
14
- clickerOption.queue[current],
15
- ], color: "turquoise", transparent: true, opacity: 0.5, lineWidth: 0.4 }), _jsxs("mesh", { position: item, children: [_jsx("sphereGeometry", { args: [0.6, 30, 0.6] }), _jsx("meshStandardMaterial", { color: "turquoise", transparent: true, opacity: 0.8 })] }, key)] }));
16
+ pointQ.map(function (queueItem, key) {
17
+ if (queueItem instanceof THREE.Vector3) {
18
+ var current = key;
19
+ var before = key === 0 ? pointQ.length - 1 : key - 1;
20
+ return (_jsxs("group", { position: [0, 1, 0], children: [_jsx(Line, { worldUnits: true, points: [pointQ[before], pointQ[current]], color: "turquoise", transparent: true, opacity: 0.5, lineWidth: 0.4 }), _jsxs("mesh", { position: queueItem, children: [_jsx("sphereGeometry", { args: [0.6, 30, 0.6] }), _jsx("meshStandardMaterial", { color: "turquoise", transparent: true, opacity: 0.8 })] }, key)] }, key));
21
+ }
16
22
  })] }));
17
23
  }
@@ -1,5 +1,6 @@
1
1
  import { CSSProperties } from "react";
2
2
  import { actionsType, refsType } from "../../controller/type";
3
+ import { RootState } from "@react-three/fiber";
3
4
  import * as THREE from "three";
4
5
  import { rideableType } from "../../hooks/useRideable/type";
5
6
  import { joyStickInnerType } from "../../tools/joystick/type";
@@ -107,13 +108,22 @@ export type clickerType = {
107
108
  isOn: boolean;
108
109
  isRun: boolean;
109
110
  };
111
+ export type queueActionType = "stop";
112
+ export type queueFunctionType = {
113
+ action: queueActionType;
114
+ beforeCB: (state: RootState) => void;
115
+ afterCB: (state: RootState) => void;
116
+ time: number;
117
+ };
118
+ export type queueItemtype = THREE.Vector3 | queueFunctionType;
119
+ export type queueType = queueItemtype[];
110
120
  export type clickerOptionType = {
111
121
  autoStart?: boolean;
112
122
  isRun?: boolean;
113
123
  throttle?: number;
114
124
  track?: boolean;
115
125
  loop?: boolean;
116
- queue?: THREE.Vector3[];
126
+ queue?: queueType;
117
127
  line?: boolean;
118
128
  };
119
129
  export type wheelStateType = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gaesup-world",
3
- "version": "0.8.47",
3
+ "version": "0.8.51",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",