three-base 1.0.81 → 1.0.82
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/ApngTexture.js +107 -40
- package/lib/ApngTextureManage.js +100 -51
- package/lib/EventMesh.js +42 -22
- package/lib/ExtrudeMesh.js +178 -147
- package/lib/FPScontrol.js +133 -116
- package/lib/InstancedGroupMesh.js +45 -25
- package/lib/KeyFrameAnimation.js +54 -37
- package/lib/PlaneText.js +34 -14
- package/lib/PlaneWithHtml.js +126 -48
- package/lib/PointLight/PointLight.js +65 -45
- package/lib/Sky/Sky.js +30 -11
- package/lib/SpriteText2.js +166 -90
- package/lib/Text3D/Text3D.js +61 -40
- package/lib/Text3D/fontController.js +284 -149
- package/lib/ThreeBase.js +341 -204
- package/lib/ThreeMouse.js +203 -244
- package/lib/Transition.js +161 -95
- package/lib/keyContorls.js +102 -74
- package/lib/planeModal1/PlaneModal1.js +162 -90
- package/lib/shaders.js +36 -178
- package/lib/spriteModal1/SpriteModal1.js +165 -93
- package/lib/threeLoader.js +89 -66
- package/lib/threeUtils.js +84 -59
- package/package.json +1 -1
package/lib/Transition.js
CHANGED
|
@@ -4,15 +4,60 @@
|
|
|
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
|
+
};
|
|
7
52
|
import threeUtils from "./threeUtils";
|
|
8
53
|
function bezier(arr, t) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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;
|
|
12
57
|
return result;
|
|
13
58
|
}
|
|
14
59
|
// 过渡动画插件
|
|
15
|
-
|
|
60
|
+
var Transition = /** @class */ (function () {
|
|
16
61
|
/**
|
|
17
62
|
*Creates an instance of transition.
|
|
18
63
|
* @param {{ [key: string]: number }} // 初始值
|
|
@@ -20,46 +65,55 @@ export default class Transition {
|
|
|
20
65
|
* @param {number} [duration=1000] // 过渡时间
|
|
21
66
|
* @memberof transition
|
|
22
67
|
*/
|
|
23
|
-
|
|
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;
|
|
24
91
|
this.setDuration(duration);
|
|
25
92
|
this.setBezier(bezier);
|
|
26
93
|
this.reset(param);
|
|
27
94
|
}
|
|
28
|
-
|
|
29
|
-
|
|
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];
|
|
95
|
+
Transition.prototype.setBezier = function (bezier) {
|
|
96
|
+
if (bezier === void 0) { bezier = [0.8, 0, 0.2, 1]; }
|
|
97
|
+
this._bezier = __spreadArray([], bezier, true);
|
|
38
98
|
this._Xbezier = [0, bezier[0], bezier[2], 1];
|
|
39
99
|
this._Ybezier = [0, bezier[1], bezier[3], 1];
|
|
40
100
|
return this;
|
|
41
|
-
}
|
|
42
|
-
// 当前时间戳
|
|
43
|
-
timeTemp = performance.now();
|
|
44
|
-
// 过渡时间
|
|
45
|
-
_duration = 0;
|
|
46
|
-
//延时
|
|
47
|
-
_delay = 0;
|
|
101
|
+
};
|
|
48
102
|
// 设置过渡时间
|
|
49
|
-
setDuration
|
|
103
|
+
Transition.prototype.setDuration = function (duration) {
|
|
104
|
+
if (duration === void 0) { duration = 500; }
|
|
50
105
|
this._duration = duration;
|
|
51
106
|
return this;
|
|
52
|
-
}
|
|
107
|
+
};
|
|
53
108
|
// 设置延时
|
|
54
|
-
setDelay
|
|
109
|
+
Transition.prototype.setDelay = function (delay) {
|
|
110
|
+
if (delay === void 0) { delay = 0; }
|
|
55
111
|
this._delay = delay;
|
|
56
112
|
return this;
|
|
57
|
-
}
|
|
58
|
-
// 存储 每个参数的 起始位置 起始时间 终止位置 终止时间
|
|
59
|
-
_ = {};
|
|
60
|
-
onChangeCall = (josn) => { };
|
|
113
|
+
};
|
|
61
114
|
// 执行过度动画
|
|
62
|
-
run
|
|
115
|
+
Transition.prototype.run = function (_a) {
|
|
116
|
+
var timeTemp = _a.timeTemp;
|
|
63
117
|
this.timeTemp = timeTemp;
|
|
64
118
|
if (!this.onChangeCall || this.isDone()) {
|
|
65
119
|
threeUtils.removeEventListener("requestAnimationFrame", this.runbindThis);
|
|
@@ -68,23 +122,22 @@ export default class Transition {
|
|
|
68
122
|
this.onChangeCall(this.getJson());
|
|
69
123
|
}
|
|
70
124
|
return this;
|
|
71
|
-
}
|
|
72
|
-
runbindThis = this.run.bind(this);
|
|
125
|
+
};
|
|
73
126
|
// 设置动画对象的回调事件
|
|
74
|
-
onChange(onChangeCall) {
|
|
127
|
+
Transition.prototype.onChange = function (onChangeCall) {
|
|
75
128
|
this.onChangeCall = onChangeCall;
|
|
76
129
|
this.onChangeCall(this.getJson());
|
|
77
130
|
return this;
|
|
78
|
-
}
|
|
131
|
+
};
|
|
79
132
|
// 计算当前 key 的值
|
|
80
|
-
get(key) {
|
|
133
|
+
Transition.prototype.get = function (key) {
|
|
81
134
|
key = String(key);
|
|
82
135
|
if (this._keys.includes(key) && this.timeTemp < (this._[key + "_startTime"] + this._duration)) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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));
|
|
86
139
|
// 斜率
|
|
87
|
-
|
|
140
|
+
var t = 0;
|
|
88
141
|
// 微分法 求斜率t
|
|
89
142
|
while (bezier(this._Xbezier, t + 0.1) < timeProgress) {
|
|
90
143
|
t += 0.1;
|
|
@@ -104,45 +157,56 @@ export default class Transition {
|
|
|
104
157
|
}
|
|
105
158
|
// `没有 ${key} 的值`;
|
|
106
159
|
return 0;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
+
};
|
|
143
207
|
// 重置起始和终止位置
|
|
144
|
-
reset(param) {
|
|
145
|
-
for (
|
|
208
|
+
Transition.prototype.reset = function (param) {
|
|
209
|
+
for (var key in param) {
|
|
146
210
|
if (!this._keys.includes(key)) {
|
|
147
211
|
this._keys.push(key);
|
|
148
212
|
}
|
|
@@ -155,32 +219,32 @@ export default class Transition {
|
|
|
155
219
|
}
|
|
156
220
|
this._isDone = true;
|
|
157
221
|
return this;
|
|
158
|
-
}
|
|
222
|
+
};
|
|
159
223
|
// 获取过渡对象上面的key
|
|
160
|
-
getKeys() {
|
|
161
|
-
return [
|
|
162
|
-
}
|
|
224
|
+
Transition.prototype.getKeys = function () {
|
|
225
|
+
return __spreadArray([], this._keys, true);
|
|
226
|
+
};
|
|
163
227
|
// 判断是否有这个参数
|
|
164
|
-
hasKey(key) {
|
|
228
|
+
Transition.prototype.hasKey = function (key) {
|
|
165
229
|
return this._keys.includes(key);
|
|
166
|
-
}
|
|
230
|
+
};
|
|
167
231
|
// 获取全部参数
|
|
168
|
-
getJson() {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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);
|
|
173
238
|
});
|
|
174
239
|
return json;
|
|
175
|
-
}
|
|
176
|
-
_isDone = false;
|
|
240
|
+
};
|
|
177
241
|
// 是否执行完成了
|
|
178
|
-
isDone() {
|
|
242
|
+
Transition.prototype.isDone = function () {
|
|
179
243
|
if (this._isDone) {
|
|
180
244
|
return true;
|
|
181
245
|
}
|
|
182
|
-
|
|
183
|
-
for (
|
|
246
|
+
var isisDone = false;
|
|
247
|
+
for (var i in this._keys) {
|
|
184
248
|
isisDone = this._[this._keys[i] + "_startTime"] + this._duration < this.timeTemp;
|
|
185
249
|
// 只要有一个没有完成 都算没有完成 过渡
|
|
186
250
|
if (!isisDone) {
|
|
@@ -192,5 +256,7 @@ export default class Transition {
|
|
|
192
256
|
return false;
|
|
193
257
|
}
|
|
194
258
|
return true;
|
|
195
|
-
}
|
|
196
|
-
|
|
259
|
+
};
|
|
260
|
+
return Transition;
|
|
261
|
+
}());
|
|
262
|
+
export default Transition;
|
package/lib/keyContorls.js
CHANGED
|
@@ -4,6 +4,32 @@
|
|
|
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
|
+
};
|
|
7
33
|
import { throttle } from "lodash";
|
|
8
34
|
import { EventDispatcher, Vector3 } from "three";
|
|
9
35
|
import { generateUUID } from "three/src/math/MathUtils";
|
|
@@ -13,86 +39,88 @@ import { generateUUID } from "three/src/math/MathUtils";
|
|
|
13
39
|
* @class KeyContorls
|
|
14
40
|
* @extends {EventDispatcher}
|
|
15
41
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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;
|
|
20
100
|
}
|
|
21
|
-
uuid = generateUUID();
|
|
22
|
-
direction = new Vector3(0, 0, 0);
|
|
23
101
|
// 添加事件需要由外部实现
|
|
24
|
-
add(e) {
|
|
25
|
-
this.dispatchEvent({
|
|
26
|
-
}
|
|
102
|
+
KeyContorls.prototype.add = function (e) {
|
|
103
|
+
this.dispatchEvent(__assign(__assign({}, e), { type: "add" }));
|
|
104
|
+
};
|
|
27
105
|
// 删除事件
|
|
28
|
-
delete(e) {
|
|
29
|
-
this.dispatchEvent({
|
|
30
|
-
}
|
|
106
|
+
KeyContorls.prototype.delete = function (e) {
|
|
107
|
+
this.dispatchEvent(__assign(__assign({}, e), { type: "delete" }));
|
|
108
|
+
};
|
|
31
109
|
// 回车按钮
|
|
32
|
-
enter(e) {
|
|
33
|
-
this.dispatchEvent({
|
|
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
|
-
});
|
|
110
|
+
KeyContorls.prototype.enter = function (e) {
|
|
111
|
+
this.dispatchEvent(__assign(__assign({}, e), { type: "enter" }));
|
|
80
112
|
};
|
|
81
|
-
|
|
82
|
-
// 节流 删除事件监听
|
|
83
|
-
removeEvent = throttle((type) => {
|
|
84
|
-
this._listeners = undefined;
|
|
85
|
-
}, 1000, { trailing: false });
|
|
86
|
-
addEventListener(type, listener) {
|
|
113
|
+
KeyContorls.prototype.addEventListener = function (type, listener) {
|
|
87
114
|
this.removeEvent(type);
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
addEvent() {
|
|
115
|
+
_super.prototype.addEventListener.call(this, type, listener);
|
|
116
|
+
};
|
|
117
|
+
KeyContorls.prototype.addEvent = function () {
|
|
91
118
|
document.addEventListener("keydown", this.keyDown);
|
|
92
|
-
}
|
|
93
|
-
dispose() {
|
|
119
|
+
};
|
|
120
|
+
KeyContorls.prototype.dispose = function () {
|
|
94
121
|
document.removeEventListener("keydown", this.keyDown);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
122
|
+
};
|
|
123
|
+
return KeyContorls;
|
|
124
|
+
}(EventDispatcher));
|
|
125
|
+
var keyContorls = new KeyContorls();
|
|
98
126
|
export default keyContorls;
|