three-base 1.0.82 → 1.0.84

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/lib/Transition.js CHANGED
@@ -4,60 +4,15 @@
4
4
  * @Last Modified by: xiaosihan
5
5
  * @Last Modified time: 2022-06-22 19:44:23
6
6
  */
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- var __generator = (this && this.__generator) || function (thisArg, body) {
17
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
18
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
19
- function verb(n) { return function (v) { return step([n, v]); }; }
20
- function step(op) {
21
- if (f) throw new TypeError("Generator is already executing.");
22
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
23
- 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;
24
- if (y = 0, t) op = [op[0] & 2, t.value];
25
- switch (op[0]) {
26
- case 0: case 1: t = op; break;
27
- case 4: _.label++; return { value: op[1], done: false };
28
- case 5: _.label++; y = op[1]; op = [0]; continue;
29
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
30
- default:
31
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
32
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
33
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
34
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
35
- if (t[2]) _.ops.pop();
36
- _.trys.pop(); continue;
37
- }
38
- op = body.call(thisArg, _);
39
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
40
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
41
- }
42
- };
43
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
44
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
45
- if (ar || !(i in from)) {
46
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
47
- ar[i] = from[i];
48
- }
49
- }
50
- return to.concat(ar || Array.prototype.slice.call(from));
51
- };
52
7
  import threeUtils from "./threeUtils";
53
8
  function bezier(arr, t) {
54
- var ut = 1 - t;
55
- var a1 = arr[1] * ut + arr[2] * t;
56
- var result = ((arr[0] * ut + arr[1] * t) * ut + a1 * t) * ut + (a1 * ut + (arr[2] * ut + arr[3] * t) * t) * t;
9
+ const ut = 1 - t;
10
+ const a1 = arr[1] * ut + arr[2] * t;
11
+ const result = ((arr[0] * ut + arr[1] * t) * ut + a1 * t) * ut + (a1 * ut + (arr[2] * ut + arr[3] * t) * t) * t;
57
12
  return result;
58
13
  }
59
14
  // 过渡动画插件
60
- var Transition = /** @class */ (function () {
15
+ export default class Transition {
61
16
  /**
62
17
  *Creates an instance of transition.
63
18
  * @param {{ [key: string]: number }} // 初始值
@@ -65,55 +20,46 @@ var Transition = /** @class */ (function () {
65
20
  * @param {number} [duration=1000] // 过渡时间
66
21
  * @memberof transition
67
22
  */
68
- function Transition(param, bezier, duration) {
69
- if (param === void 0) { param = {}; }
70
- if (bezier === void 0) { bezier = [0.8, 0, 0.2, 1]; }
71
- if (duration === void 0) { duration = 500; }
72
- // 所有的 key 的枚举
73
- this._keys = [];
74
- // 贝塞尔曲线
75
- this._bezier = [0.8, 0, 0.2, 1];
76
- // x轴贝塞尔
77
- this._Xbezier = [0, 0.8, 0.2, 1];
78
- // y轴贝塞尔
79
- this._Ybezier = [0, 0, 1, 1];
80
- // 当前时间戳
81
- this.timeTemp = performance.now();
82
- // 过渡时间
83
- this._duration = 0;
84
- //延时
85
- this._delay = 0;
86
- // 存储 每个参数的 起始位置 起始时间 终止位置 终止时间
87
- this._ = {};
88
- this.onChangeCall = function (josn) { };
89
- this.runbindThis = this.run.bind(this);
90
- this._isDone = false;
23
+ constructor(param = {}, bezier = [0.8, 0, 0.2, 1], duration = 500) {
91
24
  this.setDuration(duration);
92
25
  this.setBezier(bezier);
93
26
  this.reset(param);
94
27
  }
95
- Transition.prototype.setBezier = function (bezier) {
96
- if (bezier === void 0) { bezier = [0.8, 0, 0.2, 1]; }
97
- this._bezier = __spreadArray([], bezier, true);
28
+ // 所有的 key 的枚举
29
+ _keys = [];
30
+ // 贝塞尔曲线
31
+ _bezier = [0.8, 0, 0.2, 1];
32
+ // x轴贝塞尔
33
+ _Xbezier = [0, 0.8, 0.2, 1];
34
+ // y轴贝塞尔
35
+ _Ybezier = [0, 0, 1, 1];
36
+ setBezier(bezier = [0.8, 0, 0.2, 1]) {
37
+ this._bezier = [...bezier];
98
38
  this._Xbezier = [0, bezier[0], bezier[2], 1];
99
39
  this._Ybezier = [0, bezier[1], bezier[3], 1];
100
40
  return this;
101
- };
41
+ }
42
+ // 当前时间戳
43
+ timeTemp = performance.now();
44
+ // 过渡时间
45
+ _duration = 0;
46
+ //延时
47
+ _delay = 0;
102
48
  // 设置过渡时间
103
- Transition.prototype.setDuration = function (duration) {
104
- if (duration === void 0) { duration = 500; }
49
+ setDuration(duration = 500) {
105
50
  this._duration = duration;
106
51
  return this;
107
- };
52
+ }
108
53
  // 设置延时
109
- Transition.prototype.setDelay = function (delay) {
110
- if (delay === void 0) { delay = 0; }
54
+ setDelay(delay = 0) {
111
55
  this._delay = delay;
112
56
  return this;
113
- };
57
+ }
58
+ // 存储 每个参数的 起始位置 起始时间 终止位置 终止时间
59
+ _ = {};
60
+ onChangeCall = (josn) => { };
114
61
  // 执行过度动画
115
- Transition.prototype.run = function (_a) {
116
- var timeTemp = _a.timeTemp;
62
+ run({ timeTemp }) {
117
63
  this.timeTemp = timeTemp;
118
64
  if (!this.onChangeCall || this.isDone()) {
119
65
  threeUtils.removeEventListener("requestAnimationFrame", this.runbindThis);
@@ -122,22 +68,23 @@ var Transition = /** @class */ (function () {
122
68
  this.onChangeCall(this.getJson());
123
69
  }
124
70
  return this;
125
- };
71
+ }
72
+ runbindThis = this.run.bind(this);
126
73
  // 设置动画对象的回调事件
127
- Transition.prototype.onChange = function (onChangeCall) {
74
+ onChange(onChangeCall) {
128
75
  this.onChangeCall = onChangeCall;
129
76
  this.onChangeCall(this.getJson());
130
77
  return this;
131
- };
78
+ }
132
79
  // 计算当前 key 的值
133
- Transition.prototype.get = function (key) {
80
+ get(key) {
134
81
  key = String(key);
135
82
  if (this._keys.includes(key) && this.timeTemp < (this._[key + "_startTime"] + this._duration)) {
136
- var start = this._[key + "_start"];
137
- var end = this._[key + "_end"];
138
- var timeProgress = Math.min(1, Math.max(0, (this.timeTemp - this._[key + "_startTime"]) / this._duration));
83
+ let start = this._[key + "_start"];
84
+ let end = this._[key + "_end"];
85
+ let timeProgress = Math.min(1, Math.max(0, (this.timeTemp - this._[key + "_startTime"]) / this._duration));
139
86
  // 斜率
140
- var t = 0;
87
+ let t = 0;
141
88
  // 微分法 求斜率t
142
89
  while (bezier(this._Xbezier, t + 0.1) < timeProgress) {
143
90
  t += 0.1;
@@ -157,56 +104,45 @@ var Transition = /** @class */ (function () {
157
104
  }
158
105
  // `没有 ${key} 的值`;
159
106
  return 0;
160
- };
161
- Transition.prototype.set = function (param) {
162
- return __awaiter(this, void 0, void 0, function () {
163
- var timetemp, key;
164
- var _this = this;
165
- return __generator(this, function (_a) {
166
- switch (_a.label) {
167
- case 0:
168
- timetemp = performance.now() + this._delay;
169
- ;
170
- for (key in param) {
171
- // 有就赋值
172
- if (this._keys.includes(key) && Math.abs(param[key] - this._[key + "_end"]) > 0.001) {
173
- this._[key + "_start"] = this.get(key);
174
- this._[key + "_end"] = param[key];
175
- // 起始时间
176
- this._[key + "_startTime"] = timetemp;
177
- // 执行状态未完成
178
- this._isDone = false;
179
- // 没有就添加一个
180
- }
181
- else if (!this._keys.includes(key)) {
182
- this._[key + "_start"] = param[key];
183
- this._[key + "_end"] = param[key];
184
- // 起始时间
185
- this._[key + "_startTime"] = timetemp - this._duration;
186
- // 执行状态未完成
187
- this._isDone = false;
188
- }
189
- if (!this._keys.includes(key)) {
190
- this._keys.push(key);
191
- }
192
- // // 执行状态未完成
193
- // this._isDone = false;
194
- }
195
- if (!!this._isDone) return [3 /*break*/, 2];
196
- threeUtils.removeEventListener("requestAnimationFrame", this.runbindThis);
197
- threeUtils.addEventListener("requestAnimationFrame", this.runbindThis);
198
- return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, _this._duration + 50); })];
199
- case 1:
200
- _a.sent();
201
- _a.label = 2;
202
- case 2: return [2 /*return*/, this];
203
- }
204
- });
205
- });
206
- };
107
+ }
108
+ async set(param) {
109
+ let timetemp = performance.now() + this._delay;
110
+ ;
111
+ for (let key in param) {
112
+ // 有就赋值
113
+ if (this._keys.includes(key) && Math.abs(param[key] - this._[key + "_end"]) > 0.001) {
114
+ this._[key + "_start"] = this.get(key);
115
+ this._[key + "_end"] = param[key];
116
+ // 起始时间
117
+ this._[key + "_startTime"] = timetemp;
118
+ // 执行状态未完成
119
+ this._isDone = false;
120
+ // 没有就添加一个
121
+ }
122
+ else if (!this._keys.includes(key)) {
123
+ this._[key + "_start"] = param[key];
124
+ this._[key + "_end"] = param[key];
125
+ // 起始时间
126
+ this._[key + "_startTime"] = timetemp - this._duration;
127
+ // 执行状态未完成
128
+ this._isDone = false;
129
+ }
130
+ if (!this._keys.includes(key)) {
131
+ this._keys.push(key);
132
+ }
133
+ // // 执行状态未完成
134
+ // this._isDone = false;
135
+ }
136
+ if (!this._isDone) {
137
+ threeUtils.removeEventListener("requestAnimationFrame", this.runbindThis);
138
+ threeUtils.addEventListener("requestAnimationFrame", this.runbindThis);
139
+ await new Promise(resolve => setTimeout(resolve, this._duration + 50));
140
+ }
141
+ return this;
142
+ }
207
143
  // 重置起始和终止位置
208
- Transition.prototype.reset = function (param) {
209
- for (var key in param) {
144
+ reset(param) {
145
+ for (let key in param) {
210
146
  if (!this._keys.includes(key)) {
211
147
  this._keys.push(key);
212
148
  }
@@ -219,32 +155,32 @@ var Transition = /** @class */ (function () {
219
155
  }
220
156
  this._isDone = true;
221
157
  return this;
222
- };
158
+ }
223
159
  // 获取过渡对象上面的key
224
- Transition.prototype.getKeys = function () {
225
- return __spreadArray([], this._keys, true);
226
- };
160
+ getKeys() {
161
+ return [...this._keys];
162
+ }
227
163
  // 判断是否有这个参数
228
- Transition.prototype.hasKey = function (key) {
164
+ hasKey(key) {
229
165
  return this._keys.includes(key);
230
- };
166
+ }
231
167
  // 获取全部参数
232
- Transition.prototype.getJson = function () {
233
- var _this = this;
234
- var keys = this.getKeys();
235
- var json = {};
236
- keys.map(function (key) {
237
- json[key] = _this.get(key);
168
+ getJson() {
169
+ let keys = this.getKeys();
170
+ let json = {};
171
+ keys.map(key => {
172
+ json[key] = this.get(key);
238
173
  });
239
174
  return json;
240
- };
175
+ }
176
+ _isDone = false;
241
177
  // 是否执行完成了
242
- Transition.prototype.isDone = function () {
178
+ isDone() {
243
179
  if (this._isDone) {
244
180
  return true;
245
181
  }
246
- var isisDone = false;
247
- for (var i in this._keys) {
182
+ let isisDone = false;
183
+ for (let i in this._keys) {
248
184
  isisDone = this._[this._keys[i] + "_startTime"] + this._duration < this.timeTemp;
249
185
  // 只要有一个没有完成 都算没有完成 过渡
250
186
  if (!isisDone) {
@@ -256,7 +192,5 @@ var Transition = /** @class */ (function () {
256
192
  return false;
257
193
  }
258
194
  return true;
259
- };
260
- return Transition;
261
- }());
262
- export default Transition;
195
+ }
196
+ }
@@ -4,32 +4,6 @@
4
4
  * @Last Modified by: xiaosihan
5
5
  * @Last Modified time: 2022-09-30 00:12:28
6
6
  */
7
- var __extends = (this && this.__extends) || (function () {
8
- var extendStatics = function (d, b) {
9
- extendStatics = Object.setPrototypeOf ||
10
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
11
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
12
- return extendStatics(d, b);
13
- };
14
- return function (d, b) {
15
- if (typeof b !== "function" && b !== null)
16
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
17
- extendStatics(d, b);
18
- function __() { this.constructor = d; }
19
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
20
- };
21
- })();
22
- var __assign = (this && this.__assign) || function () {
23
- __assign = Object.assign || function(t) {
24
- for (var s, i = 1, n = arguments.length; i < n; i++) {
25
- s = arguments[i];
26
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
27
- t[p] = s[p];
28
- }
29
- return t;
30
- };
31
- return __assign.apply(this, arguments);
32
- };
33
7
  import { throttle } from "lodash";
34
8
  import { EventDispatcher, Vector3 } from "three";
35
9
  import { generateUUID } from "three/src/math/MathUtils";
@@ -39,88 +13,86 @@ import { generateUUID } from "three/src/math/MathUtils";
39
13
  * @class KeyContorls
40
14
  * @extends {EventDispatcher}
41
15
  */
42
- var KeyContorls = /** @class */ (function (_super) {
43
- __extends(KeyContorls, _super);
44
- function KeyContorls() {
45
- var _this = _super.call(this) || this;
46
- _this.uuid = generateUUID();
47
- _this.direction = new Vector3(0, 0, 0);
48
- _this.keyDown = function (e) {
49
- switch (e.keyCode) {
50
- case 46: // 删除按钮
51
- _this.delete(e);
52
- return;
53
- case 13: // 回车按钮
54
- _this.enter(e);
55
- return;
56
- case 97: // 小键盘1
57
- _this.direction.set(0, 1, 0);
58
- break;
59
- case 96: // 小键盘0
60
- _this.direction.set(0, -1, 0);
61
- break;
62
- case 35: //
63
- _this.direction.set(0, 0.001, 0);
64
- break;
65
- case 45:
66
- _this.direction.set(0, -0.001, 0);
67
- break;
68
- case 38: // 前
69
- _this.direction.set(0, 0, -1);
70
- break;
71
- case 37: // 后
72
- _this.direction.set(-1, 0, 0);
73
- break;
74
- case 40: // 左
75
- _this.direction.set(0, 0, 1);
76
- break;
77
- case 39: // 右
78
- _this.direction.set(1, 0, 0);
79
- break;
80
- default:
81
- return;
82
- }
83
- if (e.shiftKey) {
84
- _this.direction.multiplyScalar(0.001);
85
- }
86
- if (e.ctrlKey) {
87
- _this.direction.multiplyScalar(0.1);
88
- }
89
- _this.dispatchEvent({
90
- type: "change",
91
- direction: _this.direction
92
- });
93
- };
94
- // 节流 删除事件监听
95
- _this.removeEvent = throttle(function (type) {
96
- _this._listeners = undefined;
97
- }, 1000, { trailing: false });
98
- _this.addEvent();
99
- return _this;
16
+ class KeyContorls extends EventDispatcher {
17
+ constructor() {
18
+ super();
19
+ this.addEvent();
100
20
  }
21
+ uuid = generateUUID();
22
+ direction = new Vector3(0, 0, 0);
101
23
  // 添加事件需要由外部实现
102
- KeyContorls.prototype.add = function (e) {
103
- this.dispatchEvent(__assign(__assign({}, e), { type: "add" }));
104
- };
24
+ add(e) {
25
+ this.dispatchEvent({ ...e, type: "add" });
26
+ }
105
27
  // 删除事件
106
- KeyContorls.prototype.delete = function (e) {
107
- this.dispatchEvent(__assign(__assign({}, e), { type: "delete" }));
108
- };
28
+ delete(e) {
29
+ this.dispatchEvent({ ...e, type: "delete" });
30
+ }
109
31
  // 回车按钮
110
- KeyContorls.prototype.enter = function (e) {
111
- this.dispatchEvent(__assign(__assign({}, e), { type: "enter" }));
32
+ enter(e) {
33
+ this.dispatchEvent({ ...e, type: "enter" });
34
+ }
35
+ keyDown = (e) => {
36
+ switch (e.keyCode) {
37
+ case 46: // 删除按钮
38
+ this.delete(e);
39
+ return;
40
+ case 13: // 回车按钮
41
+ this.enter(e);
42
+ return;
43
+ case 97: // 小键盘1
44
+ this.direction.set(0, 1, 0);
45
+ break;
46
+ case 96: // 小键盘0
47
+ this.direction.set(0, -1, 0);
48
+ break;
49
+ case 35: //
50
+ this.direction.set(0, 0.001, 0);
51
+ break;
52
+ case 45:
53
+ this.direction.set(0, -0.001, 0);
54
+ break;
55
+ case 38: // 前
56
+ this.direction.set(0, 0, -1);
57
+ break;
58
+ case 37: // 后
59
+ this.direction.set(-1, 0, 0);
60
+ break;
61
+ case 40: // 左
62
+ this.direction.set(0, 0, 1);
63
+ break;
64
+ case 39: // 右
65
+ this.direction.set(1, 0, 0);
66
+ break;
67
+ default:
68
+ return;
69
+ }
70
+ if (e.shiftKey) {
71
+ this.direction.multiplyScalar(0.001);
72
+ }
73
+ if (e.ctrlKey) {
74
+ this.direction.multiplyScalar(0.1);
75
+ }
76
+ this.dispatchEvent({
77
+ type: "change",
78
+ direction: this.direction
79
+ });
112
80
  };
113
- KeyContorls.prototype.addEventListener = function (type, listener) {
81
+ _listeners;
82
+ // 节流 删除事件监听
83
+ removeEvent = throttle((type) => {
84
+ this._listeners = undefined;
85
+ }, 1000, { trailing: false });
86
+ addEventListener(type, listener) {
114
87
  this.removeEvent(type);
115
- _super.prototype.addEventListener.call(this, type, listener);
116
- };
117
- KeyContorls.prototype.addEvent = function () {
88
+ super.addEventListener(type, listener);
89
+ }
90
+ addEvent() {
118
91
  document.addEventListener("keydown", this.keyDown);
119
- };
120
- KeyContorls.prototype.dispose = function () {
92
+ }
93
+ dispose() {
121
94
  document.removeEventListener("keydown", this.keyDown);
122
- };
123
- return KeyContorls;
124
- }(EventDispatcher));
125
- var keyContorls = new KeyContorls();
95
+ }
96
+ }
97
+ const keyContorls = new KeyContorls();
126
98
  export default keyContorls;