three-base 1.129.15 → 2.0.1
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/README.md +1 -0
- package/index.js +1 -37
- package/index.ts +1 -61
- package/package.json +3 -4
- package/lib/ApngTexture.d.ts +0 -13
- package/lib/ApngTexture.js +0 -61
- package/lib/ApngTexture.ts +0 -91
- package/lib/ApngTextureManage.d.ts +0 -18
- package/lib/ApngTextureManage.js +0 -87
- package/lib/ApngTextureManage.ts +0 -130
- package/lib/EventMesh.d.ts +0 -18
- package/lib/EventMesh.js +0 -59
- package/lib/EventMesh.ts +0 -79
- package/lib/ExtrudeMesh.d.ts +0 -111
- package/lib/ExtrudeMesh.js +0 -363
- package/lib/ExtrudeMesh.ts +0 -571
- package/lib/FPScontrol.d.ts +0 -44
- package/lib/FPScontrol.js +0 -170
- package/lib/FPScontrol.ts +0 -209
- package/lib/InstancedGroupMesh.d.ts +0 -10
- package/lib/InstancedGroupMesh.js +0 -63
- package/lib/InstancedGroupMesh.ts +0 -80
- package/lib/KeyFrameAnimation.d.ts +0 -25
- package/lib/KeyFrameAnimation.js +0 -78
- package/lib/KeyFrameAnimation.ts +0 -122
- package/lib/PlaneText.d.ts +0 -37
- package/lib/PlaneText.js +0 -30
- package/lib/PlaneText.ts +0 -58
- package/lib/PlaneWithHtml.d.ts +0 -11
- package/lib/PlaneWithHtml.js +0 -67
- package/lib/PlaneWithHtml.ts +0 -84
- package/lib/PointLight/PointLight.d.ts +0 -13
- package/lib/PointLight/PointLight.js +0 -63
- package/lib/PointLight/PointLight.ts +0 -74
- package/lib/PointLight/pointLight_map.png +0 -0
- package/lib/Sky/Sky.d.ts +0 -13
- package/lib/Sky/Sky.js +0 -28
- package/lib/Sky/Sky.ts +0 -36
- package/lib/Sky/bluesky.jpg +0 -0
- package/lib/SpriteText.d.ts +0 -45
- package/lib/SpriteText.js +0 -162
- package/lib/SpriteText.ts +0 -189
- package/lib/SpriteText2.d.ts +0 -47
- package/lib/SpriteText2.js +0 -197
- package/lib/SpriteText2.ts +0 -236
- package/lib/Text3D/Text3D.d.ts +0 -20
- package/lib/Text3D/Text3D.js +0 -61
- package/lib/Text3D/Text3D.ts +0 -92
- package/lib/Text3D/fontController.d.ts +0 -59
- package/lib/Text3D/fontController.js +0 -200
- package/lib/Text3D/fontController.ts +0 -285
- package/lib/Text3D/gentilis.json +0 -811
- package/lib/ThreeBase.d.ts +0 -59
- package/lib/ThreeBase.js +0 -395
- package/lib/ThreeBase.ts +0 -475
- package/lib/ThreeMouse.d.ts +0 -39
- package/lib/ThreeMouse.js +0 -357
- package/lib/ThreeMouse.ts +0 -464
- package/lib/Transition.d.ts +0 -43
- package/lib/Transition.js +0 -196
- package/lib/Transition.ts +0 -268
- package/lib/index.d.ts +0 -22
- package/lib/keyContorls.d.ts +0 -25
- package/lib/keyContorls.js +0 -98
- package/lib/keyContorls.ts +0 -127
- package/lib/planeModal1/PlaneModal1.d.ts +0 -31
- package/lib/planeModal1/PlaneModal1.js +0 -104
- package/lib/planeModal1/PlaneModal1.ts +0 -150
- package/lib/planeModal1/planeModal.png +0 -0
- package/lib/shaders.d.ts +0 -17
- package/lib/shaders.js +0 -245
- package/lib/shaders.ts +0 -264
- package/lib/spriteModal1/SpriteModal1.d.ts +0 -30
- package/lib/spriteModal1/SpriteModal1.js +0 -109
- package/lib/spriteModal1/SpriteModal1.ts +0 -159
- package/lib/spriteModal1/spriteModal1.png +0 -0
- package/lib/stroke_pass/FullScreenQuad.d.ts +0 -7
- package/lib/stroke_pass/FullScreenQuad.js +0 -25
- package/lib/stroke_pass/FullScreenQuad.ts +0 -33
- package/lib/stroke_pass/stroke_pass.d.ts +0 -2
- package/lib/stroke_pass/stroke_pass.js +0 -190
- package/lib/stroke_pass/stroke_pass.ts +0 -211
- package/lib/threeLoader.d.ts +0 -20
- package/lib/threeLoader.js +0 -110
- package/lib/threeLoader.ts +0 -136
- package/lib/threeUtils.d.ts +0 -41
- package/lib/threeUtils.js +0 -179
- package/lib/threeUtils.ts +0 -212
- package/lib/type.d.ts +0 -0
- package/lib/type.js +0 -10
- package/lib/type.ts +0 -13
package/lib/ThreeMouse.ts
DELETED
|
@@ -1,464 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// 启动鼠标事件
|
|
7
|
-
import * as THREE from "three";
|
|
8
|
-
import { Object3D, Raycaster, Scene } from "three";
|
|
9
|
-
import type { Intersection } from "three";
|
|
10
|
-
import { debounce } from "lodash";
|
|
11
|
-
|
|
12
|
-
export interface ThreeMouseEvent extends Intersection {
|
|
13
|
-
renderer: THREE.Renderer;
|
|
14
|
-
camera: THREE.Camera;
|
|
15
|
-
type: string;
|
|
16
|
-
offsetX: number;
|
|
17
|
-
offsetY: number
|
|
18
|
-
x: number;
|
|
19
|
-
y: number;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* harp.gl 专用的鼠标拾取模型对象
|
|
25
|
-
*/
|
|
26
|
-
export default class ThreeMouse {
|
|
27
|
-
|
|
28
|
-
constructor(renderer: THREE.WebGLRenderer, camera: THREE.Camera, scene: THREE.Scene) {
|
|
29
|
-
|
|
30
|
-
this._renderer = renderer;
|
|
31
|
-
this._camera = camera;
|
|
32
|
-
this._scene = scene;
|
|
33
|
-
this._frame = this._renderer.info.render.frame;
|
|
34
|
-
|
|
35
|
-
this._renderer.domElement.addEventListener("mouseenter", () => { this._mouseInRenderer = true }, true); //鼠标进入开启拾取
|
|
36
|
-
this._renderer.domElement.addEventListener("mouseleave", this._mouseleave, true); //鼠标离开停止拾取
|
|
37
|
-
|
|
38
|
-
this._renderer.domElement.addEventListener("mousemove", this._mousemove, true); //鼠标移动监听事件
|
|
39
|
-
this._renderer.domElement.addEventListener("pointerdown", this._mousedown, true); //鼠标按下监听事件
|
|
40
|
-
|
|
41
|
-
this._renderer.domElement.addEventListener("pointerup", this._mouseup, true); //鼠标弹起监听事件
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// 渲染器
|
|
45
|
-
_renderer!: THREE.WebGLRenderer;
|
|
46
|
-
|
|
47
|
-
_camera!: THREE.Camera;
|
|
48
|
-
|
|
49
|
-
_scene!: Scene;
|
|
50
|
-
|
|
51
|
-
// 鼠标在渲染器上面的位置
|
|
52
|
-
_mosePosition = new THREE.Vector2(0, 0);
|
|
53
|
-
|
|
54
|
-
// 鼠标按下的位置 如果和鼠标弹起的位置相同 才算一次有效的点击事件
|
|
55
|
-
_mouseDownPosition = new THREE.Vector2(0, 0);
|
|
56
|
-
|
|
57
|
-
//当前鼠标指针上的对象
|
|
58
|
-
_mesh_on?: Object3D;
|
|
59
|
-
|
|
60
|
-
//鼠标按下的对象
|
|
61
|
-
_mesh_Down?: Object3D;
|
|
62
|
-
|
|
63
|
-
//射线拾取器
|
|
64
|
-
_raycaster = new Raycaster();
|
|
65
|
-
|
|
66
|
-
// 当前渲染的帧数 ( 鼠标滑动事件 一帧只需要执行费一次即可 )
|
|
67
|
-
_frame: number = 0;
|
|
68
|
-
|
|
69
|
-
//鼠标是否在渲染器上
|
|
70
|
-
_mouseInRenderer: boolean = false;
|
|
71
|
-
|
|
72
|
-
// 鼠标滑动的事件
|
|
73
|
-
_mousemoveEvent?: MouseEvent;
|
|
74
|
-
|
|
75
|
-
// 需要被拾取的对象数组
|
|
76
|
-
_object3ds: Object3D[] = [];
|
|
77
|
-
|
|
78
|
-
// 点击次数
|
|
79
|
-
_click_num = 0;
|
|
80
|
-
|
|
81
|
-
// 获取拾取到的对象
|
|
82
|
-
_getSelected(object3ds: Object3D[]): Intersection | undefined {
|
|
83
|
-
let intersection: Intersection | undefined;
|
|
84
|
-
|
|
85
|
-
if (object3ds.length) {
|
|
86
|
-
intersection = this._raycaster.intersectObjects(object3ds, false)[0];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return intersection;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
// 判断对象上面是否有事件
|
|
93
|
-
hasEvent(object?: Object3D, types: Array<"leftclick" | "rightclick" | "click" | "dbclick" | "mouseenter" | "mouseleave" | "mousemove" | "mousedown" | "mouseup"> = []) {
|
|
94
|
-
|
|
95
|
-
if (!object) {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// 如果 启用事件为关闭的话就不执行事件
|
|
100
|
-
if (object["userData"] && object["userData"]["enableEvent"] === false) {
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const hasevent = types.some(type => {
|
|
105
|
-
//@ts-ignore
|
|
106
|
-
if (object["_listeners"] && object["_listeners"][type] && object["_listeners"][type][0]) {
|
|
107
|
-
return true
|
|
108
|
-
}
|
|
109
|
-
// if (object["userData"] && object["userData"]["cursor"]) {
|
|
110
|
-
// return true;
|
|
111
|
-
// }
|
|
112
|
-
return false;
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
return hasevent;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// 判断对象上是否有鼠标样式
|
|
119
|
-
hasCursor(object?: Object3D) {
|
|
120
|
-
if (!object) {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
// 如果 启用事件为关闭的话就不执行事件
|
|
124
|
-
if (object["userData"] && object["userData"]["enableEvent"] === false) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
if (object["userData"] && object["userData"]["cursor"]) {
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// 分发鼠标拾取事件
|
|
133
|
-
dispatchEvent() {
|
|
134
|
-
// 提取有事件的对象
|
|
135
|
-
const meshs: Object3D[] = [];
|
|
136
|
-
|
|
137
|
-
this._scene.traverseVisible(mesh => {
|
|
138
|
-
// 判断对象是否有指定的事件
|
|
139
|
-
if (this.hasCursor(mesh) || this.hasEvent(mesh, ["leftclick", "rightclick", "click", "dbclick", "mouseenter", "mouseleave", "mousemove", "mousedown", "mouseup"])) {
|
|
140
|
-
meshs.push(mesh);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
this._object3ds = meshs;
|
|
145
|
-
|
|
146
|
-
// 没有鼠标事件就不往下执行了
|
|
147
|
-
if (!this._mousemoveEvent || !this._mouseInRenderer) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
// 拾取模型
|
|
151
|
-
let intersection = this._getSelected(meshs);
|
|
152
|
-
|
|
153
|
-
if (intersection) {
|
|
154
|
-
|
|
155
|
-
const MouseEvent: ThreeMouseEvent = Object.assign(intersection, { // 将来可能用到的对象
|
|
156
|
-
renderer: this._renderer,
|
|
157
|
-
camera: this._camera,
|
|
158
|
-
object: intersection.object,
|
|
159
|
-
type: this._mousemoveEvent.type,
|
|
160
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
161
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
162
|
-
x: this._mousemoveEvent.x,
|
|
163
|
-
y: this._mousemoveEvent.y
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
// 触发滑动事件
|
|
167
|
-
if (this._mesh_on === MouseEvent.object) {
|
|
168
|
-
if (this.hasEvent(MouseEvent.object, ["mousemove"])) {
|
|
169
|
-
MouseEvent.type = "mousemove";
|
|
170
|
-
MouseEvent.object.dispatchEvent(MouseEvent);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// 鼠标划入滑出事件
|
|
174
|
-
} else if (this._mesh_on !== MouseEvent.object) {
|
|
175
|
-
|
|
176
|
-
if (this.hasEvent(this._mesh_on, ["mouseleave"])) {
|
|
177
|
-
MouseEvent.type = "mouseleave";
|
|
178
|
-
this._mesh_on!.dispatchEvent(MouseEvent);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
if (this.hasEvent(MouseEvent.object, ["mouseenter"])) {
|
|
182
|
-
MouseEvent.type = "mouseenter";
|
|
183
|
-
MouseEvent.object.dispatchEvent(MouseEvent);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
this._mesh_on = MouseEvent.object || undefined; // 设置为当前鼠标上的对象
|
|
189
|
-
|
|
190
|
-
// 鼠标样式
|
|
191
|
-
if (this._mesh_on && this._mesh_on.userData && this._mesh_on.userData.cursor) {
|
|
192
|
-
this._renderer.domElement.style.cursor = this._mesh_on.userData.cursor;
|
|
193
|
-
} else {
|
|
194
|
-
this._renderer.domElement.style.cursor = "auto";
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
} else {
|
|
198
|
-
|
|
199
|
-
if (this.hasEvent(this._mesh_on, ["mouseleave"])) {
|
|
200
|
-
// 鼠标离开事件
|
|
201
|
-
this._mesh_on!.dispatchEvent({
|
|
202
|
-
renderer: this._renderer,
|
|
203
|
-
camera: this._camera,
|
|
204
|
-
object: this._mesh_on as Object3D,
|
|
205
|
-
type: "mouseleave",
|
|
206
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
207
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
208
|
-
x: this._mousemoveEvent.x,
|
|
209
|
-
y: this._mousemoveEvent.y
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
// 置空当前鼠标上面的对象
|
|
215
|
-
this._mesh_on = undefined;
|
|
216
|
-
|
|
217
|
-
this._renderer.domElement.style.cursor = "auto"; // 鼠标样式
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// 鼠标离开事件
|
|
223
|
-
_mouseleave = (e: MouseEvent) => {
|
|
224
|
-
this._mouseInRenderer = false;
|
|
225
|
-
|
|
226
|
-
// 鼠标离开事件
|
|
227
|
-
if (this._mousemoveEvent && this.hasEvent(this._mesh_on, ["mouseleave"])) {
|
|
228
|
-
this._mesh_on!.dispatchEvent({
|
|
229
|
-
renderer: this._renderer,
|
|
230
|
-
camera: this._camera,
|
|
231
|
-
object: this._mesh_on as Object3D,
|
|
232
|
-
type: "mouseleave",
|
|
233
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
234
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
235
|
-
x: this._mousemoveEvent.x,
|
|
236
|
-
y: this._mousemoveEvent.y
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// 置空当前鼠标上面的对象
|
|
241
|
-
this._mesh_on = undefined;
|
|
242
|
-
|
|
243
|
-
this._renderer.domElement.style.cursor = "auto"; // 鼠标样式
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// 鼠标滑动 设置鼠标位置
|
|
247
|
-
_mousemove = (e: MouseEvent) => {
|
|
248
|
-
|
|
249
|
-
this._mousemoveEvent = e;
|
|
250
|
-
|
|
251
|
-
this._frame = this._renderer.info.render.frame;
|
|
252
|
-
|
|
253
|
-
if (document.pointerLockElement) { // 如果当前有元素 锁住了鼠标
|
|
254
|
-
|
|
255
|
-
this._mosePosition.set(0, 0); // 鼠标就指向canvas 的正中心
|
|
256
|
-
} else {
|
|
257
|
-
|
|
258
|
-
this._mosePosition.x = (e.offsetX / this._renderer.domElement.offsetWidth) * 2 - 1;
|
|
259
|
-
this._mosePosition.y = -(e.offsetY / this._renderer.domElement.offsetHeight) * 2 + 1;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
this._raycaster.setFromCamera(this._mosePosition, this._camera); // 设置射线拾取的参数
|
|
263
|
-
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
// 鼠标按下事件
|
|
267
|
-
_mousedown = (e: MouseEvent) => {
|
|
268
|
-
// 记录按下的位置
|
|
269
|
-
this._mouseDownPosition.set(e.offsetX, e.offsetY);
|
|
270
|
-
|
|
271
|
-
this._mousemove(e);
|
|
272
|
-
|
|
273
|
-
let intersection = this._getSelected(this._object3ds);
|
|
274
|
-
|
|
275
|
-
if (!intersection || !this._mousemoveEvent) {
|
|
276
|
-
return
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
this._mesh_Down = this._mesh_on = intersection.object as Object3D;
|
|
280
|
-
|
|
281
|
-
// 触发鼠标按下事件
|
|
282
|
-
if (this.hasEvent(this._mesh_Down, ["mousedown"])) {
|
|
283
|
-
|
|
284
|
-
this._mesh_Down.dispatchEvent({
|
|
285
|
-
...intersection,
|
|
286
|
-
renderer: this._renderer,
|
|
287
|
-
camera: this._camera,
|
|
288
|
-
object: intersection.object as Object3D,
|
|
289
|
-
type: "mousedown",
|
|
290
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
291
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
292
|
-
x: this._mousemoveEvent.x,
|
|
293
|
-
y: this._mousemoveEvent.y
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// 鼠标弹起事件
|
|
301
|
-
_mouseup = debounce(async (e: PointerEvent) => {
|
|
302
|
-
|
|
303
|
-
// 提取有事件的对象
|
|
304
|
-
const meshs: Object3D[] = [];
|
|
305
|
-
|
|
306
|
-
let intersection = this._getSelected(this._object3ds);
|
|
307
|
-
|
|
308
|
-
if (!intersection || !this._mousemoveEvent) {
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
this._mesh_on = intersection.object as Object3D;
|
|
313
|
-
|
|
314
|
-
if (this.hasEvent(this._mesh_Down, ["mouseup"])) {
|
|
315
|
-
|
|
316
|
-
this._mesh_on.dispatchEvent({
|
|
317
|
-
...intersection,
|
|
318
|
-
renderer: this._renderer,
|
|
319
|
-
camera: this._camera,
|
|
320
|
-
object: intersection.object as Object3D,
|
|
321
|
-
type: "mouseup",
|
|
322
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
323
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
324
|
-
x: this._mousemoveEvent.x,
|
|
325
|
-
y: this._mousemoveEvent.y
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
// 触发鼠标弹起事件
|
|
330
|
-
if (
|
|
331
|
-
this._mesh_Down &&
|
|
332
|
-
this._mesh_Down === this._mesh_on &&
|
|
333
|
-
Math.abs(this._mouseDownPosition.x - e.offsetX) < 5 &&
|
|
334
|
-
Math.abs(this._mouseDownPosition.y - e.offsetY) < 5
|
|
335
|
-
) {
|
|
336
|
-
|
|
337
|
-
// 是否有双击事件
|
|
338
|
-
if (this.hasEvent(this._mesh_Down, ["dbclick"])) {
|
|
339
|
-
|
|
340
|
-
this._click_num++;
|
|
341
|
-
|
|
342
|
-
await new Promise(resolve => setTimeout(resolve, 200));
|
|
343
|
-
|
|
344
|
-
// 只点击了一次
|
|
345
|
-
if (this._click_num === 1) {
|
|
346
|
-
|
|
347
|
-
if (this.hasEvent(this._mesh_Down, ["click"])) {
|
|
348
|
-
this._mesh_Down.dispatchEvent({
|
|
349
|
-
...intersection,
|
|
350
|
-
renderer: this._renderer,
|
|
351
|
-
camera: this._camera,
|
|
352
|
-
object: intersection.object as Object3D,
|
|
353
|
-
type: "click",
|
|
354
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
355
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
356
|
-
x: this._mousemoveEvent.x,
|
|
357
|
-
y: this._mousemoveEvent.y
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
if (this.hasEvent(this._mesh_Down, ["leftclick"]) && (e.button === 0)) {
|
|
362
|
-
this._mesh_Down.dispatchEvent({
|
|
363
|
-
...intersection,
|
|
364
|
-
renderer: this._renderer,
|
|
365
|
-
camera: this._camera,
|
|
366
|
-
object: intersection.object as Object3D,
|
|
367
|
-
type: "leftclick",
|
|
368
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
369
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
370
|
-
x: this._mousemoveEvent.x,
|
|
371
|
-
y: this._mousemoveEvent.y
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
if (this.hasEvent(this._mesh_Down, ["rightclick"]) && (e.button === 2)) {
|
|
376
|
-
this._mesh_Down.dispatchEvent({
|
|
377
|
-
...intersection,
|
|
378
|
-
renderer: this._renderer,
|
|
379
|
-
camera: this._camera,
|
|
380
|
-
object: intersection.object as Object3D,
|
|
381
|
-
type: "rightclick",
|
|
382
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
383
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
384
|
-
x: this._mousemoveEvent.x,
|
|
385
|
-
y: this._mousemoveEvent.y
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
} else if (this._click_num > 1) {
|
|
390
|
-
|
|
391
|
-
if (this.hasEvent(this._mesh_Down, ["dbclick"]) && (new Date().valueOf() - this._click_num > 1) && (e.button === 0)) {
|
|
392
|
-
|
|
393
|
-
this._mesh_Down.dispatchEvent({
|
|
394
|
-
...intersection,
|
|
395
|
-
renderer: this._renderer,
|
|
396
|
-
camera: this._camera,
|
|
397
|
-
object: intersection.object as Object3D,
|
|
398
|
-
type: "dbclick",
|
|
399
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
400
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
401
|
-
x: this._mousemoveEvent.x,
|
|
402
|
-
y: this._mousemoveEvent.y
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
} else {
|
|
410
|
-
|
|
411
|
-
if (this.hasEvent(this._mesh_Down, ["click"])) {
|
|
412
|
-
this._mesh_Down.dispatchEvent({
|
|
413
|
-
...intersection,
|
|
414
|
-
renderer: this._renderer,
|
|
415
|
-
camera: this._camera,
|
|
416
|
-
object: intersection.object as Object3D,
|
|
417
|
-
type: "click",
|
|
418
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
419
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
420
|
-
x: this._mousemoveEvent.x,
|
|
421
|
-
y: this._mousemoveEvent.y
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
if (this.hasEvent(this._mesh_Down, ["leftclick"]) && (e.button === 0)) {
|
|
426
|
-
this._mesh_Down.dispatchEvent({
|
|
427
|
-
...intersection,
|
|
428
|
-
renderer: this._renderer,
|
|
429
|
-
camera: this._camera,
|
|
430
|
-
object: intersection.object as Object3D,
|
|
431
|
-
type: "leftclick",
|
|
432
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
433
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
434
|
-
x: this._mousemoveEvent.x,
|
|
435
|
-
y: this._mousemoveEvent.y
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
if (this.hasEvent(this._mesh_Down, ["rightclick"]) && (e.button === 2)) {
|
|
440
|
-
this._mesh_Down.dispatchEvent({
|
|
441
|
-
...intersection,
|
|
442
|
-
renderer: this._renderer,
|
|
443
|
-
camera: this._camera,
|
|
444
|
-
object: intersection.object as Object3D,
|
|
445
|
-
type: "rightclick",
|
|
446
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
447
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
448
|
-
x: this._mousemoveEvent.x,
|
|
449
|
-
y: this._mousemoveEvent.y
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
this._click_num = 0;
|
|
456
|
-
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
})
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
}
|
package/lib/Transition.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
interface TParam {
|
|
2
|
-
[key: string]: number;
|
|
3
|
-
}
|
|
4
|
-
export default class Transition {
|
|
5
|
-
/**
|
|
6
|
-
*Creates an instance of transition.
|
|
7
|
-
* @param {{ [key: string]: number }} // 初始值
|
|
8
|
-
* @param {[0.8, 0, 0.2, 1]} // 贝塞尔曲线
|
|
9
|
-
* @param {number} [duration=1000] // 过渡时间
|
|
10
|
-
* @memberof transition
|
|
11
|
-
*/
|
|
12
|
-
constructor(param?: TParam, bezier?: [number, number, number, number], duration?: number);
|
|
13
|
-
_keys: Array<string>;
|
|
14
|
-
_bezier: [number, number, number, number];
|
|
15
|
-
_Xbezier: [number, number, number, number];
|
|
16
|
-
_Ybezier: [number, number, number, number];
|
|
17
|
-
setBezier(bezier?: [number, number, number, number]): this;
|
|
18
|
-
timeTemp: number;
|
|
19
|
-
_duration: number;
|
|
20
|
-
_delay: number;
|
|
21
|
-
setDuration(duration?: number): this;
|
|
22
|
-
setDelay(delay?: number): this;
|
|
23
|
-
_: {
|
|
24
|
-
[key: string]: number;
|
|
25
|
-
};
|
|
26
|
-
private onChangeCall;
|
|
27
|
-
run({ timeTemp }: any): this;
|
|
28
|
-
runbindThis: any;
|
|
29
|
-
onChange(onChangeCall: (josn: {
|
|
30
|
-
[key: string]: number;
|
|
31
|
-
}) => void): this;
|
|
32
|
-
get(key: string | number): number;
|
|
33
|
-
set(param: TParam): Promise<this>;
|
|
34
|
-
reset(param: TParam): this;
|
|
35
|
-
getKeys(): string[];
|
|
36
|
-
hasKey(key: string): boolean;
|
|
37
|
-
getJson(): {
|
|
38
|
-
[key: string]: number;
|
|
39
|
-
};
|
|
40
|
-
_isDone: boolean;
|
|
41
|
-
isDone(): boolean;
|
|
42
|
-
}
|
|
43
|
-
export {};
|
package/lib/Transition.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: xiaosihan
|
|
3
|
-
* @Date: 2021-04-10 02:44:01
|
|
4
|
-
* @Last Modified by: xiaosihan
|
|
5
|
-
* @Last Modified time: 2022-06-22 19:44:23
|
|
6
|
-
*/
|
|
7
|
-
import threeUtils from "./threeUtils";
|
|
8
|
-
function bezier(arr, 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;
|
|
12
|
-
return result;
|
|
13
|
-
}
|
|
14
|
-
// 过渡动画插件
|
|
15
|
-
export default class Transition {
|
|
16
|
-
/**
|
|
17
|
-
*Creates an instance of transition.
|
|
18
|
-
* @param {{ [key: string]: number }} // 初始值
|
|
19
|
-
* @param {[0.8, 0, 0.2, 1]} // 贝塞尔曲线
|
|
20
|
-
* @param {number} [duration=1000] // 过渡时间
|
|
21
|
-
* @memberof transition
|
|
22
|
-
*/
|
|
23
|
-
constructor(param = {}, bezier = [0.8, 0, 0.2, 1], duration = 500) {
|
|
24
|
-
this.setDuration(duration);
|
|
25
|
-
this.setBezier(bezier);
|
|
26
|
-
this.reset(param);
|
|
27
|
-
}
|
|
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];
|
|
38
|
-
this._Xbezier = [0, bezier[0], bezier[2], 1];
|
|
39
|
-
this._Ybezier = [0, bezier[1], bezier[3], 1];
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
// 当前时间戳
|
|
43
|
-
timeTemp = performance.now();
|
|
44
|
-
// 过渡时间
|
|
45
|
-
_duration = 0;
|
|
46
|
-
//延时
|
|
47
|
-
_delay = 0;
|
|
48
|
-
// 设置过渡时间
|
|
49
|
-
setDuration(duration = 500) {
|
|
50
|
-
this._duration = duration;
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
// 设置延时
|
|
54
|
-
setDelay(delay = 0) {
|
|
55
|
-
this._delay = delay;
|
|
56
|
-
return this;
|
|
57
|
-
}
|
|
58
|
-
// 存储 每个参数的 起始位置 起始时间 终止位置 终止时间
|
|
59
|
-
_ = {};
|
|
60
|
-
onChangeCall = (josn) => { };
|
|
61
|
-
// 执行过度动画
|
|
62
|
-
run({ timeTemp }) {
|
|
63
|
-
this.timeTemp = timeTemp;
|
|
64
|
-
if (!this.onChangeCall || this.isDone()) {
|
|
65
|
-
threeUtils.removeEventListener("requestAnimationFrame", this.runbindThis);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
this.onChangeCall(this.getJson());
|
|
69
|
-
}
|
|
70
|
-
return this;
|
|
71
|
-
}
|
|
72
|
-
runbindThis = this.run.bind(this);
|
|
73
|
-
// 设置动画对象的回调事件
|
|
74
|
-
onChange(onChangeCall) {
|
|
75
|
-
this.onChangeCall = onChangeCall;
|
|
76
|
-
this.onChangeCall(this.getJson());
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
|
-
// 计算当前 key 的值
|
|
80
|
-
get(key) {
|
|
81
|
-
key = String(key);
|
|
82
|
-
if (this._keys.includes(key) && 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));
|
|
86
|
-
// 斜率
|
|
87
|
-
let t = 0;
|
|
88
|
-
// 微分法 求斜率t
|
|
89
|
-
while (bezier(this._Xbezier, t + 0.1) < timeProgress) {
|
|
90
|
-
t += 0.1;
|
|
91
|
-
}
|
|
92
|
-
while (bezier(this._Xbezier, t + 0.01) < timeProgress) {
|
|
93
|
-
t += 0.01;
|
|
94
|
-
}
|
|
95
|
-
while (bezier(this._Xbezier, t + 0.001) < timeProgress) {
|
|
96
|
-
t += 0.001;
|
|
97
|
-
}
|
|
98
|
-
t = Math.min(1, Math.max(0, t)); // 斜率最大为1
|
|
99
|
-
// 通过斜率求y值
|
|
100
|
-
return (bezier(this._Ybezier, t) * (end - start)) + start;
|
|
101
|
-
}
|
|
102
|
-
else if (this._keys.includes(key) && this.timeTemp >= (this._[key + "_startTime"] + this._duration)) {
|
|
103
|
-
return this._[key + "_end"];
|
|
104
|
-
}
|
|
105
|
-
// `没有 ${key} 的值`;
|
|
106
|
-
return 0;
|
|
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
|
-
}
|
|
143
|
-
// 重置起始和终止位置
|
|
144
|
-
reset(param) {
|
|
145
|
-
for (let key in param) {
|
|
146
|
-
if (!this._keys.includes(key)) {
|
|
147
|
-
this._keys.push(key);
|
|
148
|
-
}
|
|
149
|
-
this._[key + "_start"] = param[key];
|
|
150
|
-
this._[key + "_end"] = param[key];
|
|
151
|
-
this._[key + "_startTime"] = -this._duration;
|
|
152
|
-
}
|
|
153
|
-
if (this.onChangeCall) {
|
|
154
|
-
this.onChangeCall(this.getJson());
|
|
155
|
-
}
|
|
156
|
-
this._isDone = true;
|
|
157
|
-
return this;
|
|
158
|
-
}
|
|
159
|
-
// 获取过渡对象上面的key
|
|
160
|
-
getKeys() {
|
|
161
|
-
return [...this._keys];
|
|
162
|
-
}
|
|
163
|
-
// 判断是否有这个参数
|
|
164
|
-
hasKey(key) {
|
|
165
|
-
return this._keys.includes(key);
|
|
166
|
-
}
|
|
167
|
-
// 获取全部参数
|
|
168
|
-
getJson() {
|
|
169
|
-
let keys = this.getKeys();
|
|
170
|
-
let json = {};
|
|
171
|
-
keys.map(key => {
|
|
172
|
-
json[key] = this.get(key);
|
|
173
|
-
});
|
|
174
|
-
return json;
|
|
175
|
-
}
|
|
176
|
-
_isDone = false;
|
|
177
|
-
// 是否执行完成了
|
|
178
|
-
isDone() {
|
|
179
|
-
if (this._isDone) {
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
let isisDone = false;
|
|
183
|
-
for (let i in this._keys) {
|
|
184
|
-
isisDone = this._[this._keys[i] + "_startTime"] + this._duration < this.timeTemp;
|
|
185
|
-
// 只要有一个没有完成 都算没有完成 过渡
|
|
186
|
-
if (!isisDone) {
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if (!this._isDone) {
|
|
191
|
-
this._isDone = true;
|
|
192
|
-
return false;
|
|
193
|
-
}
|
|
194
|
-
return true;
|
|
195
|
-
}
|
|
196
|
-
}
|