gaesup-world 0.3.5 → 0.3.7

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.
@@ -66,7 +66,7 @@ export function subscribeActions(_a) {
66
66
  export default function playActions(_a) {
67
67
  var _b;
68
68
  var type = _a.type, animationResult = _a.animationResult, currentAnimation = _a.currentAnimation;
69
- var _c = useContext(GaesupWorldContext), mode = _c.mode, animationState = _c.animationState;
69
+ var _c = useContext(GaesupWorldContext), mode = _c.mode, animationState = _c.animationState, block = _c.block;
70
70
  var dispatch = useContext(GaesupWorldDispatchContext);
71
71
  var _d = useGaesupAnimation({ type: type }), notify = _d.notify, store = _d.store;
72
72
  var actions = animationResult.actions, ref = animationResult.ref;
@@ -85,11 +85,21 @@ export default function playActions(_a) {
85
85
  };
86
86
  useEffect(function () {
87
87
  var _a;
88
- var action = (_a = actions[currentAnimation || animationState[type].current]) === null || _a === void 0 ? void 0 : _a.reset().fadeIn(0.2).play();
88
+ var animation = "idle";
89
+ if (block.animation) {
90
+ animation = "idle";
91
+ }
92
+ else if (currentAnimation) {
93
+ animation = currentAnimation;
94
+ }
95
+ else if (animationState[type].current) {
96
+ animation = animationState[type].current;
97
+ }
98
+ var action = (_a = actions[animation]) === null || _a === void 0 ? void 0 : _a.reset().fadeIn(0.2).play();
89
99
  return function () {
90
100
  action === null || action === void 0 ? void 0 : action.fadeOut(0.2);
91
101
  };
92
- }, [currentAnimation, mode.type]);
102
+ }, [currentAnimation, mode.type, block.animation]);
93
103
  useFrame(function () {
94
104
  if (!currentAnimation) {
95
105
  var tag = notify();
@@ -7,13 +7,12 @@ export var makeNormalCameraPosition = function (activeState, cameraOption) {
7
7
  return cameraPosition;
8
8
  };
9
9
  export default function normal(prop) {
10
- var state = prop.state, _a = prop.worldContext, activeState = _a.activeState, cameraOption = _a.cameraOption;
10
+ var delta = prop.delta, state = prop.state, _a = prop.worldContext, activeState = _a.activeState, cameraOption = _a.cameraOption;
11
11
  if (!state || !state.camera)
12
12
  return;
13
- var cameraPosition = activeState.position
14
- .clone()
15
- .add(V3(0, cameraOption.YDistance, cameraOption.ZDistance));
16
- state.camera.position.lerp(cameraPosition, 1);
17
- if (!cameraOption.target)
18
- state.camera.lookAt(activeState.position.clone());
13
+ // const cameraPosition = activeState.position
14
+ // .clone()
15
+ // .add(V3(0, cameraOption.YDistance, cameraOption.ZDistance));
16
+ state.camera.position.lerp(cameraOption.position.clone(), 1);
17
+ state.camera.lookAt(cameraOption.target);
19
18
  }
@@ -17,7 +17,7 @@ import { useContext, useEffect, useMemo, useRef } from "react";
17
17
  import * as THREE from "three";
18
18
  import { GaesupControllerContext } from "../controller/context";
19
19
  import { GaesupWorldContext } from "../world/context";
20
- import normal from "./control/normal";
20
+ import normal, { makeNormalCameraPosition } from "./control/normal";
21
21
  import orbit from "./control/orbit";
22
22
  export default function Camera(_a) {
23
23
  var refs = _a.refs, prop = _a.prop, control = _a.control;
@@ -60,18 +60,40 @@ export default function Camera(_a) {
60
60
  cameraRef.current.zoomTo(worldContext.cameraOption.zoom, true);
61
61
  }
62
62
  }, [worldContext.cameraOption.zoom]);
63
- // lookat
64
- useEffect(function () {
65
- if (cameraRef.current) {
66
- var currentCamera = camera.position.clone();
67
- if (cameraOption.focus) {
68
- cameraRef.current.setLookAt(currentCamera.x, currentCamera.y, currentCamera.z, cameraOption.target.x, cameraOption.target.y, cameraOption.target.z, true);
69
- // 포커스 품
70
- }
71
- else if (!cameraOption.focus) {
72
- cameraRef.current.setLookAt(currentCamera.x, currentCamera.y, currentCamera.z, activeState.position.x, activeState.position.y, activeState.position.z, true);
73
- }
63
+ // 포커스가 아닐 때 카메라 activeStae 따라가기
64
+ useFrame(function () {
65
+ if (!cameraOption.focus) {
66
+ cameraOption.target = activeState.position;
67
+ cameraOption.position = makeNormalCameraPosition(activeState, cameraOption);
74
68
  }
75
- }, [cameraOption.focus]);
69
+ });
70
+ // lookat
71
+ // useEffect(() => {
72
+ // if (cameraRef.current) {
73
+ // const currentCamera = camera.position.clone();
74
+ // if (cameraOption.focus) {
75
+ // cameraRef.current.setLookAt(
76
+ // currentCamera.x,
77
+ // currentCamera.y,
78
+ // currentCamera.z,
79
+ // cameraOption.target.x,
80
+ // cameraOption.target.y,
81
+ // cameraOption.target.z,
82
+ // true
83
+ // );
84
+ // // 포커스 품
85
+ // } else if (!cameraOption.focus) {
86
+ // cameraRef.current.setLookAt(
87
+ // currentCamera.x,
88
+ // currentCamera.y,
89
+ // currentCamera.z,
90
+ // activeState.position.x,
91
+ // activeState.position.y,
92
+ // activeState.position.z,
93
+ // true
94
+ // );
95
+ // }
96
+ // }
97
+ // }, [cameraOption.focus]);
76
98
  return _jsx(CameraControls, { ref: cameraRef });
77
99
  }
@@ -17,7 +17,8 @@ export function CharacterRef(_a) {
17
17
  });
18
18
  setGroundRay({
19
19
  groundRay: props.groundRay,
20
- length: (collider === null || collider === void 0 ? void 0 : collider.radius) || 0 + 2,
20
+ length: ((collider === null || collider === void 0 ? void 0 : collider.height) || 0) + 2,
21
+ // length: collider?.radius || 0 + 2,
21
22
  colliderRef: colliderRef,
22
23
  });
23
24
  var animationResult = subscribeActions({
@@ -1,4 +1,3 @@
1
- import _ from "lodash";
2
1
  import { useContext, useEffect } from "react";
3
2
  import { V3 } from "../../utils";
4
3
  import { GaesupWorldContext, GaesupWorldDispatchContext, } from "../../world/context";
@@ -13,33 +12,19 @@ export default function useClicker() {
13
12
  var newAngle = Math.atan2(newPosition.z - originPoint.z, newPosition.x - originPoint.x);
14
13
  var norm = Math.sqrt(Math.pow(newPosition.z - originPoint.z, 2) +
15
14
  Math.pow(newPosition.x - originPoint.x, 2));
16
- if (norm < 1)
15
+ if (norm < 2)
17
16
  return;
18
- var dispatcher = _.debounce(function () {
19
- dispatch({
20
- type: "update",
21
- payload: {
22
- clicker: {
23
- point: V3(e.point.x, e.point.y, e.point.z),
24
- angle: newAngle,
25
- isOn: true,
26
- isRun: isRun,
27
- },
17
+ dispatch({
18
+ type: "update",
19
+ payload: {
20
+ clicker: {
21
+ point: V3(e.point.x, e.point.y, e.point.z),
22
+ angle: newAngle,
23
+ isOn: true,
24
+ isRun: isRun,
28
25
  },
29
- });
30
- }, 100);
31
- dispatcher();
32
- // dispatch({
33
- // type: "update",
34
- // payload: {
35
- // clicker: {
36
- // point: V3(e.point.x, e.point.y, e.point.z),
37
- // angle: newAngle,
38
- // isOn: true,
39
- // isRun: isRun,
40
- // },
41
- // },
42
- // });
26
+ },
27
+ });
43
28
  };
44
29
  // const moveClicker = _.throttle(moveClick, 100);
45
30
  // 거리 계산
@@ -1,7 +1,22 @@
1
1
  export declare function useFocus(): {
2
- open: ({ zoom, target }: {
2
+ open: () => Promise<void>;
3
+ close: () => Promise<void>;
4
+ on: () => Promise<void>;
5
+ off: () => Promise<void>;
6
+ focus: ({ zoom, target, position, }: {
3
7
  zoom?: number;
4
8
  target: THREE.Vector3;
5
- }) => void;
6
- close: () => void;
9
+ position: THREE.Vector3;
10
+ }) => Promise<void>;
11
+ free: ({ zoom }: {
12
+ zoom?: number;
13
+ }) => Promise<void>;
14
+ focusOn: ({ zoom, target, position, }: {
15
+ zoom?: number;
16
+ target: THREE.Vector3;
17
+ position: THREE.Vector3;
18
+ }) => Promise<void>;
19
+ focusOff: ({ zoom }: {
20
+ zoom?: number;
21
+ }) => Promise<void>;
7
22
  };
@@ -1,32 +1,200 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
1
37
  import { useContext } from "react";
38
+ import { makeNormalCameraPosition } from "../../camera/control/normal";
2
39
  import { GaesupWorldContext, GaesupWorldDispatchContext, } from "../../world/context";
3
40
  export function useFocus() {
4
- var cameraOption = useContext(GaesupWorldContext).cameraOption;
41
+ var _this = this;
42
+ var _a = useContext(GaesupWorldContext), cameraOption = _a.cameraOption, activeState = _a.activeState, block = _a.block;
5
43
  var dispatch = useContext(GaesupWorldDispatchContext);
6
- var open = function (_a) {
7
- var zoom = _a.zoom, target = _a.target;
8
- if (zoom)
9
- cameraOption.zoom = zoom;
10
- cameraOption.target = target;
11
- cameraOption.focus = true;
12
- dispatch({
13
- type: "update",
14
- payload: {
15
- cameraOption: cameraOption,
16
- },
44
+ var dispatchAsync = function () { return __awaiter(_this, void 0, void 0, function () {
45
+ return __generator(this, function (_a) {
46
+ dispatch({
47
+ type: "update",
48
+ payload: {
49
+ cameraOption: cameraOption,
50
+ },
51
+ });
52
+ return [2 /*return*/];
53
+ });
54
+ }); };
55
+ var close = function () { return __awaiter(_this, void 0, void 0, function () {
56
+ return __generator(this, function (_a) {
57
+ block.control = true;
58
+ block.animation = true;
59
+ dispatch({
60
+ type: "update",
61
+ payload: {
62
+ block: block,
63
+ },
64
+ });
65
+ return [2 /*return*/];
66
+ });
67
+ }); };
68
+ var open = function () { return __awaiter(_this, void 0, void 0, function () {
69
+ return __generator(this, function (_a) {
70
+ block.control = false;
71
+ block.animation = false;
72
+ dispatch({
73
+ type: "update",
74
+ payload: {
75
+ block: block,
76
+ },
77
+ });
78
+ return [2 /*return*/];
79
+ });
80
+ }); };
81
+ var on = function () { return __awaiter(_this, void 0, void 0, function () {
82
+ return __generator(this, function (_a) {
83
+ cameraOption.focus = true;
84
+ dispatch({
85
+ type: "update",
86
+ payload: {
87
+ cameraOption: cameraOption,
88
+ },
89
+ });
90
+ return [2 /*return*/];
91
+ });
92
+ }); };
93
+ var off = function () { return __awaiter(_this, void 0, void 0, function () {
94
+ return __generator(this, function (_a) {
95
+ cameraOption.focus = false;
96
+ dispatch({
97
+ type: "update",
98
+ payload: {
99
+ cameraOption: cameraOption,
100
+ },
101
+ });
102
+ return [2 /*return*/];
103
+ });
104
+ }); };
105
+ var focus = function (_a) {
106
+ var zoom = _a.zoom, target = _a.target, position = _a.position;
107
+ return __awaiter(_this, void 0, void 0, function () {
108
+ return __generator(this, function (_b) {
109
+ if (zoom)
110
+ cameraOption.zoom = zoom;
111
+ cameraOption.position.lerp(position, 0.1);
112
+ cameraOption.target.lerp(target, 0.1);
113
+ return [2 /*return*/];
114
+ });
115
+ });
116
+ };
117
+ var free = function (_a) {
118
+ var zoom = _a.zoom;
119
+ return __awaiter(_this, void 0, void 0, function () {
120
+ return __generator(this, function (_b) {
121
+ if (zoom)
122
+ cameraOption.zoom = zoom;
123
+ cameraOption.position.lerp(makeNormalCameraPosition(activeState, cameraOption), 0.1);
124
+ cameraOption.target.lerp(activeState.position.clone(), 0.1);
125
+ return [2 /*return*/];
126
+ });
127
+ });
128
+ };
129
+ var move = function (_a) {
130
+ var newPosition = _a.newPosition;
131
+ return __awaiter(_this, void 0, void 0, function () {
132
+ return __generator(this, function (_b) {
133
+ cameraOption.position.lerp(newPosition.clone(), 0.1);
134
+ return [2 /*return*/];
135
+ });
136
+ });
137
+ };
138
+ var focusOn = function (_a) {
139
+ var zoom = _a.zoom, target = _a.target, position = _a.position;
140
+ return __awaiter(_this, void 0, void 0, function () {
141
+ return __generator(this, function (_b) {
142
+ switch (_b.label) {
143
+ case 0: return [4 /*yield*/, close()];
144
+ case 1:
145
+ _b.sent();
146
+ return [4 /*yield*/, on()];
147
+ case 2:
148
+ _b.sent();
149
+ return [4 /*yield*/, move({ newPosition: position })];
150
+ case 3:
151
+ _b.sent();
152
+ return [4 /*yield*/, focus({ zoom: zoom, target: target, position: position })];
153
+ case 4:
154
+ _b.sent();
155
+ return [4 /*yield*/, dispatchAsync()];
156
+ case 5:
157
+ _b.sent();
158
+ return [2 /*return*/];
159
+ }
160
+ });
17
161
  });
18
162
  };
19
- var close = function () {
20
- cameraOption.focus = false;
21
- dispatch({
22
- type: "update",
23
- payload: {
24
- cameraOption: cameraOption,
25
- },
163
+ var focusOff = function (_a) {
164
+ var zoom = _a.zoom;
165
+ return __awaiter(_this, void 0, void 0, function () {
166
+ return __generator(this, function (_b) {
167
+ switch (_b.label) {
168
+ case 0: return [4 /*yield*/, open()];
169
+ case 1:
170
+ _b.sent();
171
+ return [4 /*yield*/, off()];
172
+ case 2:
173
+ _b.sent();
174
+ return [4 /*yield*/, move({
175
+ newPosition: makeNormalCameraPosition(activeState, cameraOption),
176
+ })];
177
+ case 3:
178
+ _b.sent();
179
+ return [4 /*yield*/, free({ zoom: zoom })];
180
+ case 4:
181
+ _b.sent();
182
+ return [4 /*yield*/, dispatchAsync()];
183
+ case 5:
184
+ _b.sent();
185
+ return [2 /*return*/];
186
+ }
187
+ });
26
188
  });
27
189
  };
28
190
  return {
29
191
  open: open,
30
192
  close: close,
193
+ on: on,
194
+ off: off,
195
+ focus: focus,
196
+ free: free,
197
+ focusOn: focusOn,
198
+ focusOff: focusOff,
31
199
  };
32
200
  }
@@ -4,12 +4,14 @@ export default function checkOnTheGround(prop) {
4
4
  groundRay.origin.addVectors(activeState.position, vec3(groundRay.offset));
5
5
  if (!groundRay.hit || !groundRay.rayCast || !colliderRef.current) {
6
6
  states.isOnTheGround = false;
7
- return;
7
+ // return;
8
8
  }
9
- if (groundRay.hit.toi < groundRay.length + 0.5) {
10
- states.isOnTheGround = true;
11
- }
12
- else {
13
- states.isOnTheGround = false;
9
+ if (groundRay.hit) {
10
+ if (groundRay.hit.toi < groundRay.length + 0.5) {
11
+ states.isOnTheGround = true;
12
+ }
13
+ else {
14
+ states.isOnTheGround = false;
15
+ }
14
16
  }
15
17
  }
@@ -107,7 +107,8 @@ export var gaesupWorldDefault = {
107
107
  YDistance: 10,
108
108
  ZDistance: 20,
109
109
  zoom: 1,
110
- target: null,
110
+ target: vec3(),
111
+ position: vec3(),
111
112
  focus: false,
112
113
  },
113
114
  moveTo: null,
@@ -116,6 +117,7 @@ export var gaesupWorldDefault = {
116
117
  block: {
117
118
  camera: false,
118
119
  control: false,
120
+ animation: false,
119
121
  scroll: true,
120
122
  },
121
123
  callback: {
@@ -13,6 +13,7 @@ export type gaesupCameraOptionDebugType = {
13
13
  zoom?: number;
14
14
  target?: THREE.Vector3;
15
15
  focus?: boolean;
16
+ position?: THREE.Vector3;
16
17
  };
17
18
  export type cameraOptionType = {
18
19
  offset?: THREE.Vector3;
@@ -108,6 +109,7 @@ export type wheelStateType = {
108
109
  export type blockType = {
109
110
  camera: boolean;
110
111
  control: boolean;
112
+ animation: boolean;
111
113
  scroll: boolean;
112
114
  };
113
115
  export type sizeType = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gaesup-world",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",