three-base 2.0.1 → 2.0.2
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/ApngTexture.d.ts +13 -0
- package/ApngTexture.js +61 -0
- package/ApngTexture.ts +91 -0
- package/ApngTextureManage.d.ts +18 -0
- package/ApngTextureManage.js +87 -0
- package/ApngTextureManage.ts +130 -0
- package/EventMesh.d.ts +18 -0
- package/EventMesh.js +59 -0
- package/EventMesh.ts +79 -0
- package/ExtrudeMesh.d.ts +111 -0
- package/ExtrudeMesh.js +363 -0
- package/ExtrudeMesh.ts +571 -0
- package/FPScontrol.d.ts +44 -0
- package/FPScontrol.js +170 -0
- package/FPScontrol.ts +209 -0
- package/InstancedGroupMesh.d.ts +10 -0
- package/InstancedGroupMesh.js +63 -0
- package/InstancedGroupMesh.ts +80 -0
- package/KeyFrameAnimation.d.ts +25 -0
- package/KeyFrameAnimation.js +78 -0
- package/KeyFrameAnimation.ts +122 -0
- package/PlaneModal1/PlaneModal1.d.ts +31 -0
- package/PlaneModal1/PlaneModal1.js +105 -0
- package/PlaneModal1/PlaneModal1.ts +151 -0
- package/PlaneModal1/index.d.ts +1 -0
- package/PlaneModal1/index.js +1 -0
- package/PlaneModal1/index.ts +1 -0
- package/PlaneModal1/planeModal.png +0 -0
- package/PlaneText.d.ts +37 -0
- package/PlaneText.js +30 -0
- package/PlaneText.ts +58 -0
- package/PlaneWithHtml.d.ts +11 -0
- package/PlaneWithHtml.js +67 -0
- package/PlaneWithHtml.ts +84 -0
- package/PointLight/PointLight.d.ts +13 -0
- package/PointLight/PointLight.js +63 -0
- package/PointLight/PointLight.ts +74 -0
- package/PointLight/index.d.ts +1 -0
- package/PointLight/index.js +1 -0
- package/PointLight/index.ts +1 -0
- package/PointLight/pointLight_map.png +0 -0
- package/Sky/Sky.d.ts +13 -0
- package/Sky/Sky.js +28 -0
- package/Sky/Sky.ts +36 -0
- package/Sky/bluesky.jpg +0 -0
- package/Sky/index.d.ts +1 -0
- package/Sky/index.js +1 -0
- package/Sky/index.ts +1 -0
- package/SpriteModal1/SpriteModal1.d.ts +30 -0
- package/SpriteModal1/SpriteModal1.js +110 -0
- package/SpriteModal1/SpriteModal1.ts +160 -0
- package/SpriteModal1/index.d.ts +1 -0
- package/SpriteModal1/index.js +1 -0
- package/SpriteModal1/index.ts +1 -0
- package/SpriteModal1/spriteModal1.png +0 -0
- package/SpriteText.d.ts +45 -0
- package/SpriteText.js +162 -0
- package/SpriteText.ts +189 -0
- package/SpriteText2.d.ts +47 -0
- package/SpriteText2.js +197 -0
- package/SpriteText2.ts +236 -0
- package/Text3D/Text3D.d.ts +20 -0
- package/Text3D/Text3D.js +62 -0
- package/Text3D/Text3D.ts +93 -0
- package/Text3D/fontController.d.ts +59 -0
- package/Text3D/fontController.js +200 -0
- package/Text3D/fontController.ts +285 -0
- package/Text3D/gentilis.json +811 -0
- package/Text3D/index.d.ts +1 -0
- package/Text3D/index.js +1 -0
- package/Text3D/index.ts +1 -0
- package/ThreeBase.d.ts +61 -0
- package/ThreeBase.js +401 -0
- package/ThreeBase.ts +482 -0
- package/ThreeMouse.d.ts +39 -0
- package/ThreeMouse.js +359 -0
- package/ThreeMouse.ts +465 -0
- package/Transition.d.ts +43 -0
- package/Transition.js +196 -0
- package/Transition.ts +268 -0
- package/index.d.ts +1 -0
- package/keyContorls.d.ts +25 -0
- package/keyContorls.js +98 -0
- package/keyContorls.ts +127 -0
- package/package.json +15 -20
- package/pass/FullScreenQuad.d.ts +7 -0
- package/pass/FullScreenQuad.js +25 -0
- package/pass/FullScreenQuad.ts +33 -0
- package/pass/stroke_pass.d.ts +2 -0
- package/pass/stroke_pass.js +190 -0
- package/pass/stroke_pass.ts +211 -0
- package/shaders.d.ts +17 -0
- package/shaders.js +245 -0
- package/shaders.ts +264 -0
- package/threeLoader.d.ts +20 -0
- package/threeLoader.js +118 -0
- package/threeLoader.ts +147 -0
- package/threeUtils.d.ts +44 -0
- package/threeUtils.js +233 -0
- package/threeUtils.ts +271 -0
- package/tsconfig.json +39 -0
package/ThreeMouse.ts
ADDED
|
@@ -0,0 +1,465 @@
|
|
|
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
|
+
const { face, object } = intersection;
|
|
155
|
+
face && face.normal.applyMatrix4(object.matrixWorld);
|
|
156
|
+
const MouseEvent: ThreeMouseEvent = Object.assign(intersection, { // 将来可能用到的对象
|
|
157
|
+
renderer: this._renderer,
|
|
158
|
+
camera: this._camera,
|
|
159
|
+
object: intersection.object,
|
|
160
|
+
type: this._mousemoveEvent.type,
|
|
161
|
+
offsetX: this._mousemoveEvent.offsetX,
|
|
162
|
+
offsetY: this._mousemoveEvent.offsetY,
|
|
163
|
+
x: this._mousemoveEvent.x,
|
|
164
|
+
y: this._mousemoveEvent.y
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// 触发滑动事件
|
|
168
|
+
if (this._mesh_on === MouseEvent.object) {
|
|
169
|
+
if (this.hasEvent(MouseEvent.object, ["mousemove"])) {
|
|
170
|
+
MouseEvent.type = "mousemove";
|
|
171
|
+
MouseEvent.object.dispatchEvent(MouseEvent);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// 鼠标划入滑出事件
|
|
175
|
+
} else if (this._mesh_on !== MouseEvent.object) {
|
|
176
|
+
|
|
177
|
+
if (this.hasEvent(this._mesh_on, ["mouseleave"])) {
|
|
178
|
+
MouseEvent.type = "mouseleave";
|
|
179
|
+
this._mesh_on!.dispatchEvent(MouseEvent);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (this.hasEvent(MouseEvent.object, ["mouseenter"])) {
|
|
183
|
+
MouseEvent.type = "mouseenter";
|
|
184
|
+
MouseEvent.object.dispatchEvent(MouseEvent);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
this._mesh_on = MouseEvent.object || undefined; // 设置为当前鼠标上的对象
|
|
190
|
+
|
|
191
|
+
// 鼠标样式
|
|
192
|
+
if (this._mesh_on && this._mesh_on.userData && this._mesh_on.userData.cursor) {
|
|
193
|
+
this._renderer.domElement.style.cursor = this._mesh_on.userData.cursor;
|
|
194
|
+
} else {
|
|
195
|
+
this._renderer.domElement.style.cursor = "auto";
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
} else {
|
|
199
|
+
|
|
200
|
+
if (this.hasEvent(this._mesh_on, ["mouseleave"])) {
|
|
201
|
+
// 鼠标离开事件
|
|
202
|
+
this._mesh_on!.dispatchEvent({
|
|
203
|
+
renderer: this._renderer,
|
|
204
|
+
camera: this._camera,
|
|
205
|
+
object: this._mesh_on as Object3D,
|
|
206
|
+
type: "mouseleave",
|
|
207
|
+
offsetX: this._mousemoveEvent.offsetX,
|
|
208
|
+
offsetY: this._mousemoveEvent.offsetY,
|
|
209
|
+
x: this._mousemoveEvent.x,
|
|
210
|
+
y: this._mousemoveEvent.y
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
// 置空当前鼠标上面的对象
|
|
216
|
+
this._mesh_on = undefined;
|
|
217
|
+
|
|
218
|
+
this._renderer.domElement.style.cursor = "auto"; // 鼠标样式
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// 鼠标离开事件
|
|
224
|
+
_mouseleave = (e: MouseEvent) => {
|
|
225
|
+
this._mouseInRenderer = false;
|
|
226
|
+
|
|
227
|
+
// 鼠标离开事件
|
|
228
|
+
if (this._mousemoveEvent && this.hasEvent(this._mesh_on, ["mouseleave"])) {
|
|
229
|
+
this._mesh_on!.dispatchEvent({
|
|
230
|
+
renderer: this._renderer,
|
|
231
|
+
camera: this._camera,
|
|
232
|
+
object: this._mesh_on as Object3D,
|
|
233
|
+
type: "mouseleave",
|
|
234
|
+
offsetX: this._mousemoveEvent.offsetX,
|
|
235
|
+
offsetY: this._mousemoveEvent.offsetY,
|
|
236
|
+
x: this._mousemoveEvent.x,
|
|
237
|
+
y: this._mousemoveEvent.y
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// 置空当前鼠标上面的对象
|
|
242
|
+
this._mesh_on = undefined;
|
|
243
|
+
|
|
244
|
+
this._renderer.domElement.style.cursor = "auto"; // 鼠标样式
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// 鼠标滑动 设置鼠标位置
|
|
248
|
+
_mousemove = (e: MouseEvent) => {
|
|
249
|
+
|
|
250
|
+
this._mousemoveEvent = e;
|
|
251
|
+
|
|
252
|
+
this._frame = this._renderer.info.render.frame;
|
|
253
|
+
|
|
254
|
+
if (document.pointerLockElement) { // 如果当前有元素 锁住了鼠标
|
|
255
|
+
|
|
256
|
+
this._mosePosition.set(0, 0); // 鼠标就指向canvas 的正中心
|
|
257
|
+
} else {
|
|
258
|
+
|
|
259
|
+
this._mosePosition.x = (e.offsetX / this._renderer.domElement.offsetWidth) * 2 - 1;
|
|
260
|
+
this._mosePosition.y = -(e.offsetY / this._renderer.domElement.offsetHeight) * 2 + 1;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
this._raycaster.setFromCamera(this._mosePosition, this._camera); // 设置射线拾取的参数
|
|
264
|
+
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
// 鼠标按下事件
|
|
268
|
+
_mousedown = (e: MouseEvent) => {
|
|
269
|
+
// 记录按下的位置
|
|
270
|
+
this._mouseDownPosition.set(e.offsetX, e.offsetY);
|
|
271
|
+
|
|
272
|
+
this._mousemove(e);
|
|
273
|
+
|
|
274
|
+
let intersection = this._getSelected(this._object3ds);
|
|
275
|
+
|
|
276
|
+
if (!intersection || !this._mousemoveEvent) {
|
|
277
|
+
return
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
this._mesh_Down = this._mesh_on = intersection.object as Object3D;
|
|
281
|
+
|
|
282
|
+
// 触发鼠标按下事件
|
|
283
|
+
if (this.hasEvent(this._mesh_Down, ["mousedown"])) {
|
|
284
|
+
|
|
285
|
+
this._mesh_Down.dispatchEvent({
|
|
286
|
+
...intersection,
|
|
287
|
+
renderer: this._renderer,
|
|
288
|
+
camera: this._camera,
|
|
289
|
+
object: intersection.object as Object3D,
|
|
290
|
+
type: "mousedown",
|
|
291
|
+
offsetX: this._mousemoveEvent.offsetX,
|
|
292
|
+
offsetY: this._mousemoveEvent.offsetY,
|
|
293
|
+
x: this._mousemoveEvent.x,
|
|
294
|
+
y: this._mousemoveEvent.y
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// 鼠标弹起事件
|
|
302
|
+
_mouseup = debounce(async (e: PointerEvent) => {
|
|
303
|
+
|
|
304
|
+
// 提取有事件的对象
|
|
305
|
+
const meshs: Object3D[] = [];
|
|
306
|
+
|
|
307
|
+
let intersection = this._getSelected(this._object3ds);
|
|
308
|
+
|
|
309
|
+
if (!intersection || !this._mousemoveEvent) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
this._mesh_on = intersection.object as Object3D;
|
|
314
|
+
|
|
315
|
+
if (this.hasEvent(this._mesh_Down, ["mouseup"])) {
|
|
316
|
+
|
|
317
|
+
this._mesh_on.dispatchEvent({
|
|
318
|
+
...intersection,
|
|
319
|
+
renderer: this._renderer,
|
|
320
|
+
camera: this._camera,
|
|
321
|
+
object: intersection.object as Object3D,
|
|
322
|
+
type: "mouseup",
|
|
323
|
+
offsetX: this._mousemoveEvent.offsetX,
|
|
324
|
+
offsetY: this._mousemoveEvent.offsetY,
|
|
325
|
+
x: this._mousemoveEvent.x,
|
|
326
|
+
y: this._mousemoveEvent.y
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// 触发鼠标弹起事件
|
|
331
|
+
if (
|
|
332
|
+
this._mesh_Down &&
|
|
333
|
+
this._mesh_Down === this._mesh_on &&
|
|
334
|
+
Math.abs(this._mouseDownPosition.x - e.offsetX) < 5 &&
|
|
335
|
+
Math.abs(this._mouseDownPosition.y - e.offsetY) < 5
|
|
336
|
+
) {
|
|
337
|
+
|
|
338
|
+
// 是否有双击事件
|
|
339
|
+
if (this.hasEvent(this._mesh_Down, ["dbclick"])) {
|
|
340
|
+
|
|
341
|
+
this._click_num++;
|
|
342
|
+
|
|
343
|
+
await new Promise(resolve => setTimeout(resolve, 200));
|
|
344
|
+
|
|
345
|
+
// 只点击了一次
|
|
346
|
+
if (this._click_num === 1) {
|
|
347
|
+
|
|
348
|
+
if (this.hasEvent(this._mesh_Down, ["click"])) {
|
|
349
|
+
this._mesh_Down.dispatchEvent({
|
|
350
|
+
...intersection,
|
|
351
|
+
renderer: this._renderer,
|
|
352
|
+
camera: this._camera,
|
|
353
|
+
object: intersection.object as Object3D,
|
|
354
|
+
type: "click",
|
|
355
|
+
offsetX: this._mousemoveEvent.offsetX,
|
|
356
|
+
offsetY: this._mousemoveEvent.offsetY,
|
|
357
|
+
x: this._mousemoveEvent.x,
|
|
358
|
+
y: this._mousemoveEvent.y
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if (this.hasEvent(this._mesh_Down, ["leftclick"]) && (e.button === 0)) {
|
|
363
|
+
this._mesh_Down.dispatchEvent({
|
|
364
|
+
...intersection,
|
|
365
|
+
renderer: this._renderer,
|
|
366
|
+
camera: this._camera,
|
|
367
|
+
object: intersection.object as Object3D,
|
|
368
|
+
type: "leftclick",
|
|
369
|
+
offsetX: this._mousemoveEvent.offsetX,
|
|
370
|
+
offsetY: this._mousemoveEvent.offsetY,
|
|
371
|
+
x: this._mousemoveEvent.x,
|
|
372
|
+
y: this._mousemoveEvent.y
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
if (this.hasEvent(this._mesh_Down, ["rightclick"]) && (e.button === 2)) {
|
|
377
|
+
this._mesh_Down.dispatchEvent({
|
|
378
|
+
...intersection,
|
|
379
|
+
renderer: this._renderer,
|
|
380
|
+
camera: this._camera,
|
|
381
|
+
object: intersection.object as Object3D,
|
|
382
|
+
type: "rightclick",
|
|
383
|
+
offsetX: this._mousemoveEvent.offsetX,
|
|
384
|
+
offsetY: this._mousemoveEvent.offsetY,
|
|
385
|
+
x: this._mousemoveEvent.x,
|
|
386
|
+
y: this._mousemoveEvent.y
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
} else if (this._click_num > 1) {
|
|
391
|
+
|
|
392
|
+
if (this.hasEvent(this._mesh_Down, ["dbclick"]) && (new Date().valueOf() - this._click_num > 1) && (e.button === 0)) {
|
|
393
|
+
|
|
394
|
+
this._mesh_Down.dispatchEvent({
|
|
395
|
+
...intersection,
|
|
396
|
+
renderer: this._renderer,
|
|
397
|
+
camera: this._camera,
|
|
398
|
+
object: intersection.object as Object3D,
|
|
399
|
+
type: "dbclick",
|
|
400
|
+
offsetX: this._mousemoveEvent.offsetX,
|
|
401
|
+
offsetY: this._mousemoveEvent.offsetY,
|
|
402
|
+
x: this._mousemoveEvent.x,
|
|
403
|
+
y: this._mousemoveEvent.y
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
} else {
|
|
411
|
+
|
|
412
|
+
if (this.hasEvent(this._mesh_Down, ["click"])) {
|
|
413
|
+
this._mesh_Down.dispatchEvent({
|
|
414
|
+
...intersection,
|
|
415
|
+
renderer: this._renderer,
|
|
416
|
+
camera: this._camera,
|
|
417
|
+
object: intersection.object as Object3D,
|
|
418
|
+
type: "click",
|
|
419
|
+
offsetX: this._mousemoveEvent.offsetX,
|
|
420
|
+
offsetY: this._mousemoveEvent.offsetY,
|
|
421
|
+
x: this._mousemoveEvent.x,
|
|
422
|
+
y: this._mousemoveEvent.y
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (this.hasEvent(this._mesh_Down, ["leftclick"]) && (e.button === 0)) {
|
|
427
|
+
this._mesh_Down.dispatchEvent({
|
|
428
|
+
...intersection,
|
|
429
|
+
renderer: this._renderer,
|
|
430
|
+
camera: this._camera,
|
|
431
|
+
object: intersection.object as Object3D,
|
|
432
|
+
type: "leftclick",
|
|
433
|
+
offsetX: this._mousemoveEvent.offsetX,
|
|
434
|
+
offsetY: this._mousemoveEvent.offsetY,
|
|
435
|
+
x: this._mousemoveEvent.x,
|
|
436
|
+
y: this._mousemoveEvent.y
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
if (this.hasEvent(this._mesh_Down, ["rightclick"]) && (e.button === 2)) {
|
|
441
|
+
this._mesh_Down.dispatchEvent({
|
|
442
|
+
...intersection,
|
|
443
|
+
renderer: this._renderer,
|
|
444
|
+
camera: this._camera,
|
|
445
|
+
object: intersection.object as Object3D,
|
|
446
|
+
type: "rightclick",
|
|
447
|
+
offsetX: this._mousemoveEvent.offsetX,
|
|
448
|
+
offsetY: this._mousemoveEvent.offsetY,
|
|
449
|
+
x: this._mousemoveEvent.x,
|
|
450
|
+
y: this._mousemoveEvent.y
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
this._click_num = 0;
|
|
457
|
+
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
})
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
}
|
package/Transition.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
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/Transition.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
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
|
+
}
|