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/ThreeMouse.js
CHANGED
|
@@ -1,3 +1,50 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
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;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
1
48
|
//
|
|
2
49
|
//
|
|
3
50
|
//
|
|
@@ -10,53 +57,153 @@ import { debounce } from "lodash";
|
|
|
10
57
|
/**
|
|
11
58
|
* harp.gl 专用的鼠标拾取模型对象
|
|
12
59
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
60
|
+
var ThreeMouse = /** @class */ (function () {
|
|
61
|
+
function ThreeMouse(renderer, camera, scene) {
|
|
62
|
+
var _this = this;
|
|
63
|
+
// 鼠标在渲染器上面的位置
|
|
64
|
+
this._mosePosition = new THREE.Vector2(0, 0);
|
|
65
|
+
// 鼠标按下的位置 如果和鼠标弹起的位置相同 才算一次有效的点击事件
|
|
66
|
+
this._mouseDownPosition = new THREE.Vector2(0, 0);
|
|
67
|
+
//射线拾取器
|
|
68
|
+
this._raycaster = new Raycaster();
|
|
69
|
+
// 当前渲染的帧数 ( 鼠标滑动事件 一帧只需要执行费一次即可 )
|
|
70
|
+
this._frame = 0;
|
|
71
|
+
//鼠标是否在渲染器上
|
|
72
|
+
this._mouseInRenderer = false;
|
|
73
|
+
// 需要被拾取的对象数组
|
|
74
|
+
this._object3ds = [];
|
|
75
|
+
// 点击次数
|
|
76
|
+
this._click_num = 0;
|
|
77
|
+
// 鼠标离开事件
|
|
78
|
+
this._mouseleave = function (e) {
|
|
79
|
+
_this._mouseInRenderer = false;
|
|
80
|
+
// 鼠标离开事件
|
|
81
|
+
if (_this._mousemoveEvent && _this.hasEvent(_this._mesh_on, ["mouseleave"])) {
|
|
82
|
+
_this._mesh_on.dispatchEvent({
|
|
83
|
+
renderer: _this._renderer,
|
|
84
|
+
camera: _this._camera,
|
|
85
|
+
object: _this._mesh_on,
|
|
86
|
+
type: "mouseleave",
|
|
87
|
+
offsetX: _this._mousemoveEvent.offsetX,
|
|
88
|
+
offsetY: _this._mousemoveEvent.offsetY,
|
|
89
|
+
x: _this._mousemoveEvent.x,
|
|
90
|
+
y: _this._mousemoveEvent.y
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
// 置空当前鼠标上面的对象
|
|
94
|
+
_this._mesh_on = undefined;
|
|
95
|
+
_this._renderer.domElement.style.cursor = "auto"; // 鼠标样式
|
|
96
|
+
};
|
|
97
|
+
// 鼠标滑动 设置鼠标位置
|
|
98
|
+
this._mousemove = function (e) {
|
|
99
|
+
_this._mousemoveEvent = e;
|
|
100
|
+
_this._frame = _this._renderer.info.render.frame;
|
|
101
|
+
if (document.pointerLockElement) { // 如果当前有元素 锁住了鼠标
|
|
102
|
+
_this._mosePosition.set(0, 0); // 鼠标就指向canvas 的正中心
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
_this._mosePosition.x = (e.offsetX / _this._renderer.domElement.offsetWidth) * 2 - 1;
|
|
106
|
+
_this._mosePosition.y = -(e.offsetY / _this._renderer.domElement.offsetHeight) * 2 + 1;
|
|
107
|
+
}
|
|
108
|
+
_this._raycaster.setFromCamera(_this._mosePosition, _this._camera); // 设置射线拾取的参数
|
|
109
|
+
};
|
|
110
|
+
// 鼠标按下事件
|
|
111
|
+
this._mousedown = function (e) {
|
|
112
|
+
// 记录按下的位置
|
|
113
|
+
_this._mouseDownPosition.set(e.offsetX, e.offsetY);
|
|
114
|
+
_this._mousemove(e);
|
|
115
|
+
var intersection = _this._getSelected(_this._object3ds);
|
|
116
|
+
if (!intersection || !_this._mousemoveEvent) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
_this._mesh_Down = _this._mesh_on = intersection.object;
|
|
120
|
+
// 触发鼠标按下事件
|
|
121
|
+
if (_this.hasEvent(_this._mesh_Down, ["mousedown"])) {
|
|
122
|
+
_this._mesh_Down.dispatchEvent(__assign(__assign({}, intersection), { renderer: _this._renderer, camera: _this._camera, object: intersection.object, type: "mousedown", offsetX: _this._mousemoveEvent.offsetX, offsetY: _this._mousemoveEvent.offsetY, x: _this._mousemoveEvent.x, y: _this._mousemoveEvent.y }));
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
// 鼠标弹起事件
|
|
126
|
+
this._mouseup = debounce(function (e) { return __awaiter(_this, void 0, void 0, function () {
|
|
127
|
+
var meshs, intersection;
|
|
128
|
+
return __generator(this, function (_a) {
|
|
129
|
+
switch (_a.label) {
|
|
130
|
+
case 0:
|
|
131
|
+
meshs = [];
|
|
132
|
+
intersection = this._getSelected(this._object3ds);
|
|
133
|
+
if (!intersection || !this._mousemoveEvent) {
|
|
134
|
+
return [2 /*return*/];
|
|
135
|
+
}
|
|
136
|
+
this._mesh_on = intersection.object;
|
|
137
|
+
if (this.hasEvent(this._mesh_Down, ["mouseup"])) {
|
|
138
|
+
this._mesh_on.dispatchEvent(__assign(__assign({}, intersection), { renderer: this._renderer, camera: this._camera, object: intersection.object, type: "mouseup", offsetX: this._mousemoveEvent.offsetX, offsetY: this._mousemoveEvent.offsetY, x: this._mousemoveEvent.x, y: this._mousemoveEvent.y }));
|
|
139
|
+
}
|
|
140
|
+
if (!(this._mesh_Down &&
|
|
141
|
+
this._mesh_Down === this._mesh_on &&
|
|
142
|
+
Math.abs(this._mouseDownPosition.x - e.offsetX) < 5 &&
|
|
143
|
+
Math.abs(this._mouseDownPosition.y - e.offsetY) < 5)) return [3 /*break*/, 4];
|
|
144
|
+
if (!this.hasEvent(this._mesh_Down, ["dbclick"])) return [3 /*break*/, 2];
|
|
145
|
+
this._click_num++;
|
|
146
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 200); })];
|
|
147
|
+
case 1:
|
|
148
|
+
_a.sent();
|
|
149
|
+
// 只点击了一次
|
|
150
|
+
if (this._click_num === 1) {
|
|
151
|
+
if (this.hasEvent(this._mesh_Down, ["click"])) {
|
|
152
|
+
this._mesh_Down.dispatchEvent(__assign(__assign({}, intersection), { renderer: this._renderer, camera: this._camera, object: intersection.object, type: "click", offsetX: this._mousemoveEvent.offsetX, offsetY: this._mousemoveEvent.offsetY, x: this._mousemoveEvent.x, y: this._mousemoveEvent.y }));
|
|
153
|
+
}
|
|
154
|
+
if (this.hasEvent(this._mesh_Down, ["leftclick"]) && (e.button === 0)) {
|
|
155
|
+
this._mesh_Down.dispatchEvent(__assign(__assign({}, intersection), { renderer: this._renderer, camera: this._camera, object: intersection.object, type: "leftclick", offsetX: this._mousemoveEvent.offsetX, offsetY: this._mousemoveEvent.offsetY, x: this._mousemoveEvent.x, y: this._mousemoveEvent.y }));
|
|
156
|
+
}
|
|
157
|
+
if (this.hasEvent(this._mesh_Down, ["rightclick"]) && (e.button === 2)) {
|
|
158
|
+
this._mesh_Down.dispatchEvent(__assign(__assign({}, intersection), { renderer: this._renderer, camera: this._camera, object: intersection.object, type: "rightclick", offsetX: this._mousemoveEvent.offsetX, offsetY: this._mousemoveEvent.offsetY, x: this._mousemoveEvent.x, y: this._mousemoveEvent.y }));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else if (this._click_num > 1) {
|
|
162
|
+
if (this.hasEvent(this._mesh_Down, ["dbclick"]) && (new Date().valueOf() - this._click_num > 1) && (e.button === 0)) {
|
|
163
|
+
this._mesh_Down.dispatchEvent(__assign(__assign({}, intersection), { renderer: this._renderer, camera: this._camera, object: intersection.object, type: "dbclick", offsetX: this._mousemoveEvent.offsetX, offsetY: this._mousemoveEvent.offsetY, x: this._mousemoveEvent.x, y: this._mousemoveEvent.y }));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return [3 /*break*/, 3];
|
|
167
|
+
case 2:
|
|
168
|
+
if (this.hasEvent(this._mesh_Down, ["click"])) {
|
|
169
|
+
this._mesh_Down.dispatchEvent(__assign(__assign({}, intersection), { renderer: this._renderer, camera: this._camera, object: intersection.object, type: "click", offsetX: this._mousemoveEvent.offsetX, offsetY: this._mousemoveEvent.offsetY, x: this._mousemoveEvent.x, y: this._mousemoveEvent.y }));
|
|
170
|
+
}
|
|
171
|
+
if (this.hasEvent(this._mesh_Down, ["leftclick"]) && (e.button === 0)) {
|
|
172
|
+
this._mesh_Down.dispatchEvent(__assign(__assign({}, intersection), { renderer: this._renderer, camera: this._camera, object: intersection.object, type: "leftclick", offsetX: this._mousemoveEvent.offsetX, offsetY: this._mousemoveEvent.offsetY, x: this._mousemoveEvent.x, y: this._mousemoveEvent.y }));
|
|
173
|
+
}
|
|
174
|
+
if (this.hasEvent(this._mesh_Down, ["rightclick"]) && (e.button === 2)) {
|
|
175
|
+
this._mesh_Down.dispatchEvent(__assign(__assign({}, intersection), { renderer: this._renderer, camera: this._camera, object: intersection.object, type: "rightclick", offsetX: this._mousemoveEvent.offsetX, offsetY: this._mousemoveEvent.offsetY, x: this._mousemoveEvent.x, y: this._mousemoveEvent.y }));
|
|
176
|
+
}
|
|
177
|
+
_a.label = 3;
|
|
178
|
+
case 3:
|
|
179
|
+
this._click_num = 0;
|
|
180
|
+
_a.label = 4;
|
|
181
|
+
case 4: return [2 /*return*/];
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}); });
|
|
15
185
|
this._renderer = renderer;
|
|
16
186
|
this._camera = camera;
|
|
17
187
|
this._scene = scene;
|
|
18
188
|
this._frame = this._renderer.info.render.frame;
|
|
19
|
-
this._renderer.domElement.addEventListener("mouseenter", ()
|
|
189
|
+
this._renderer.domElement.addEventListener("mouseenter", function () { _this._mouseInRenderer = true; }, true); //鼠标进入开启拾取
|
|
20
190
|
this._renderer.domElement.addEventListener("mouseleave", this._mouseleave, true); //鼠标离开停止拾取
|
|
21
191
|
this._renderer.domElement.addEventListener("mousemove", this._mousemove, true); //鼠标移动监听事件
|
|
22
192
|
this._renderer.domElement.addEventListener("pointerdown", this._mousedown, true); //鼠标按下监听事件
|
|
23
193
|
this._renderer.domElement.addEventListener("pointerup", this._mouseup, true); //鼠标弹起监听事件
|
|
24
194
|
}
|
|
25
|
-
// 渲染器
|
|
26
|
-
_renderer;
|
|
27
|
-
_camera;
|
|
28
|
-
_scene;
|
|
29
|
-
// 鼠标在渲染器上面的位置
|
|
30
|
-
_mosePosition = new THREE.Vector2(0, 0);
|
|
31
|
-
// 鼠标按下的位置 如果和鼠标弹起的位置相同 才算一次有效的点击事件
|
|
32
|
-
_mouseDownPosition = new THREE.Vector2(0, 0);
|
|
33
|
-
//当前鼠标指针上的对象
|
|
34
|
-
_mesh_on;
|
|
35
|
-
//鼠标按下的对象
|
|
36
|
-
_mesh_Down;
|
|
37
|
-
//射线拾取器
|
|
38
|
-
_raycaster = new Raycaster();
|
|
39
|
-
// 当前渲染的帧数 ( 鼠标滑动事件 一帧只需要执行费一次即可 )
|
|
40
|
-
_frame = 0;
|
|
41
|
-
//鼠标是否在渲染器上
|
|
42
|
-
_mouseInRenderer = false;
|
|
43
|
-
// 鼠标滑动的事件
|
|
44
|
-
_mousemoveEvent;
|
|
45
|
-
// 需要被拾取的对象数组
|
|
46
|
-
_object3ds = [];
|
|
47
|
-
// 点击次数
|
|
48
|
-
_click_num = 0;
|
|
49
195
|
// 获取拾取到的对象
|
|
50
|
-
_getSelected(object3ds) {
|
|
51
|
-
|
|
196
|
+
ThreeMouse.prototype._getSelected = function (object3ds) {
|
|
197
|
+
var intersection;
|
|
52
198
|
if (object3ds.length) {
|
|
53
199
|
intersection = this._raycaster.intersectObjects(object3ds, false)[0];
|
|
54
200
|
}
|
|
55
201
|
return intersection;
|
|
56
|
-
}
|
|
202
|
+
};
|
|
57
203
|
;
|
|
58
204
|
// 判断对象上面是否有事件
|
|
59
|
-
hasEvent(object, types
|
|
205
|
+
ThreeMouse.prototype.hasEvent = function (object, types) {
|
|
206
|
+
if (types === void 0) { types = []; }
|
|
60
207
|
if (!object) {
|
|
61
208
|
return false;
|
|
62
209
|
}
|
|
@@ -64,7 +211,7 @@ export default class ThreeMouse {
|
|
|
64
211
|
if (object["userData"] && object["userData"]["enableEvent"] === false) {
|
|
65
212
|
return false;
|
|
66
213
|
}
|
|
67
|
-
|
|
214
|
+
var hasevent = types.some(function (type) {
|
|
68
215
|
//@ts-ignore
|
|
69
216
|
if (object["_listeners"] && object["_listeners"][type] && object["_listeners"][type][0]) {
|
|
70
217
|
return true;
|
|
@@ -75,9 +222,9 @@ export default class ThreeMouse {
|
|
|
75
222
|
return false;
|
|
76
223
|
});
|
|
77
224
|
return hasevent;
|
|
78
|
-
}
|
|
225
|
+
};
|
|
79
226
|
// 判断对象上是否有鼠标样式
|
|
80
|
-
hasCursor(object) {
|
|
227
|
+
ThreeMouse.prototype.hasCursor = function (object) {
|
|
81
228
|
if (!object) {
|
|
82
229
|
return false;
|
|
83
230
|
}
|
|
@@ -88,14 +235,15 @@ export default class ThreeMouse {
|
|
|
88
235
|
if (object["userData"] && object["userData"]["cursor"]) {
|
|
89
236
|
return true;
|
|
90
237
|
}
|
|
91
|
-
}
|
|
238
|
+
};
|
|
92
239
|
// 分发鼠标拾取事件
|
|
93
|
-
dispatchEvent() {
|
|
240
|
+
ThreeMouse.prototype.dispatchEvent = function () {
|
|
241
|
+
var _this = this;
|
|
94
242
|
// 提取有事件的对象
|
|
95
|
-
|
|
96
|
-
this._scene.traverseVisible(mesh
|
|
243
|
+
var meshs = [];
|
|
244
|
+
this._scene.traverseVisible(function (mesh) {
|
|
97
245
|
// 判断对象是否有指定的事件
|
|
98
|
-
if (
|
|
246
|
+
if (_this.hasCursor(mesh) || _this.hasEvent(mesh, ["leftclick", "rightclick", "click", "dbclick", "mouseenter", "mouseleave", "mousemove", "mousedown", "mouseup"])) {
|
|
99
247
|
meshs.push(mesh);
|
|
100
248
|
}
|
|
101
249
|
});
|
|
@@ -105,9 +253,9 @@ export default class ThreeMouse {
|
|
|
105
253
|
return;
|
|
106
254
|
}
|
|
107
255
|
// 拾取模型
|
|
108
|
-
|
|
256
|
+
var intersection = this._getSelected(meshs);
|
|
109
257
|
if (intersection) {
|
|
110
|
-
|
|
258
|
+
var MouseEvent_1 = Object.assign(intersection, {
|
|
111
259
|
renderer: this._renderer,
|
|
112
260
|
camera: this._camera,
|
|
113
261
|
object: intersection.object,
|
|
@@ -118,24 +266,24 @@ export default class ThreeMouse {
|
|
|
118
266
|
y: this._mousemoveEvent.y
|
|
119
267
|
});
|
|
120
268
|
// 触发滑动事件
|
|
121
|
-
if (this._mesh_on ===
|
|
122
|
-
if (this.hasEvent(
|
|
123
|
-
|
|
124
|
-
|
|
269
|
+
if (this._mesh_on === MouseEvent_1.object) {
|
|
270
|
+
if (this.hasEvent(MouseEvent_1.object, ["mousemove"])) {
|
|
271
|
+
MouseEvent_1.type = "mousemove";
|
|
272
|
+
MouseEvent_1.object.dispatchEvent(MouseEvent_1);
|
|
125
273
|
}
|
|
126
274
|
// 鼠标划入滑出事件
|
|
127
275
|
}
|
|
128
|
-
else if (this._mesh_on !==
|
|
276
|
+
else if (this._mesh_on !== MouseEvent_1.object) {
|
|
129
277
|
if (this.hasEvent(this._mesh_on, ["mouseleave"])) {
|
|
130
|
-
|
|
131
|
-
this._mesh_on.dispatchEvent(
|
|
278
|
+
MouseEvent_1.type = "mouseleave";
|
|
279
|
+
this._mesh_on.dispatchEvent(MouseEvent_1);
|
|
132
280
|
}
|
|
133
|
-
if (this.hasEvent(
|
|
134
|
-
|
|
135
|
-
|
|
281
|
+
if (this.hasEvent(MouseEvent_1.object, ["mouseenter"])) {
|
|
282
|
+
MouseEvent_1.type = "mouseenter";
|
|
283
|
+
MouseEvent_1.object.dispatchEvent(MouseEvent_1);
|
|
136
284
|
}
|
|
137
285
|
}
|
|
138
|
-
this._mesh_on =
|
|
286
|
+
this._mesh_on = MouseEvent_1.object || undefined; // 设置为当前鼠标上的对象
|
|
139
287
|
// 鼠标样式
|
|
140
288
|
if (this._mesh_on && this._mesh_on.userData && this._mesh_on.userData.cursor) {
|
|
141
289
|
this._renderer.domElement.style.cursor = this._mesh_on.userData.cursor;
|
|
@@ -162,196 +310,7 @@ export default class ThreeMouse {
|
|
|
162
310
|
this._mesh_on = undefined;
|
|
163
311
|
this._renderer.domElement.style.cursor = "auto"; // 鼠标样式
|
|
164
312
|
}
|
|
165
|
-
}
|
|
166
|
-
// 鼠标离开事件
|
|
167
|
-
_mouseleave = (e) => {
|
|
168
|
-
this._mouseInRenderer = false;
|
|
169
|
-
// 鼠标离开事件
|
|
170
|
-
if (this._mousemoveEvent && this.hasEvent(this._mesh_on, ["mouseleave"])) {
|
|
171
|
-
this._mesh_on.dispatchEvent({
|
|
172
|
-
renderer: this._renderer,
|
|
173
|
-
camera: this._camera,
|
|
174
|
-
object: this._mesh_on,
|
|
175
|
-
type: "mouseleave",
|
|
176
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
177
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
178
|
-
x: this._mousemoveEvent.x,
|
|
179
|
-
y: this._mousemoveEvent.y
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
// 置空当前鼠标上面的对象
|
|
183
|
-
this._mesh_on = undefined;
|
|
184
|
-
this._renderer.domElement.style.cursor = "auto"; // 鼠标样式
|
|
185
|
-
};
|
|
186
|
-
// 鼠标滑动 设置鼠标位置
|
|
187
|
-
_mousemove = (e) => {
|
|
188
|
-
this._mousemoveEvent = e;
|
|
189
|
-
this._frame = this._renderer.info.render.frame;
|
|
190
|
-
if (document.pointerLockElement) { // 如果当前有元素 锁住了鼠标
|
|
191
|
-
this._mosePosition.set(0, 0); // 鼠标就指向canvas 的正中心
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
this._mosePosition.x = (e.offsetX / this._renderer.domElement.offsetWidth) * 2 - 1;
|
|
195
|
-
this._mosePosition.y = -(e.offsetY / this._renderer.domElement.offsetHeight) * 2 + 1;
|
|
196
|
-
}
|
|
197
|
-
this._raycaster.setFromCamera(this._mosePosition, this._camera); // 设置射线拾取的参数
|
|
198
313
|
};
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
this._mouseDownPosition.set(e.offsetX, e.offsetY);
|
|
203
|
-
this._mousemove(e);
|
|
204
|
-
let intersection = this._getSelected(this._object3ds);
|
|
205
|
-
if (!intersection || !this._mousemoveEvent) {
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
this._mesh_Down = this._mesh_on = intersection.object;
|
|
209
|
-
// 触发鼠标按下事件
|
|
210
|
-
if (this.hasEvent(this._mesh_Down, ["mousedown"])) {
|
|
211
|
-
this._mesh_Down.dispatchEvent({
|
|
212
|
-
...intersection,
|
|
213
|
-
renderer: this._renderer,
|
|
214
|
-
camera: this._camera,
|
|
215
|
-
object: intersection.object,
|
|
216
|
-
type: "mousedown",
|
|
217
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
218
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
219
|
-
x: this._mousemoveEvent.x,
|
|
220
|
-
y: this._mousemoveEvent.y
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
// 鼠标弹起事件
|
|
225
|
-
_mouseup = debounce(async (e) => {
|
|
226
|
-
// 提取有事件的对象
|
|
227
|
-
const meshs = [];
|
|
228
|
-
let intersection = this._getSelected(this._object3ds);
|
|
229
|
-
if (!intersection || !this._mousemoveEvent) {
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
this._mesh_on = intersection.object;
|
|
233
|
-
if (this.hasEvent(this._mesh_Down, ["mouseup"])) {
|
|
234
|
-
this._mesh_on.dispatchEvent({
|
|
235
|
-
...intersection,
|
|
236
|
-
renderer: this._renderer,
|
|
237
|
-
camera: this._camera,
|
|
238
|
-
object: intersection.object,
|
|
239
|
-
type: "mouseup",
|
|
240
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
241
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
242
|
-
x: this._mousemoveEvent.x,
|
|
243
|
-
y: this._mousemoveEvent.y
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
// 触发鼠标弹起事件
|
|
247
|
-
if (this._mesh_Down &&
|
|
248
|
-
this._mesh_Down === this._mesh_on &&
|
|
249
|
-
Math.abs(this._mouseDownPosition.x - e.offsetX) < 5 &&
|
|
250
|
-
Math.abs(this._mouseDownPosition.y - e.offsetY) < 5) {
|
|
251
|
-
// 是否有双击事件
|
|
252
|
-
if (this.hasEvent(this._mesh_Down, ["dbclick"])) {
|
|
253
|
-
this._click_num++;
|
|
254
|
-
await new Promise(resolve => setTimeout(resolve, 200));
|
|
255
|
-
// 只点击了一次
|
|
256
|
-
if (this._click_num === 1) {
|
|
257
|
-
if (this.hasEvent(this._mesh_Down, ["click"])) {
|
|
258
|
-
this._mesh_Down.dispatchEvent({
|
|
259
|
-
...intersection,
|
|
260
|
-
renderer: this._renderer,
|
|
261
|
-
camera: this._camera,
|
|
262
|
-
object: intersection.object,
|
|
263
|
-
type: "click",
|
|
264
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
265
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
266
|
-
x: this._mousemoveEvent.x,
|
|
267
|
-
y: this._mousemoveEvent.y
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
if (this.hasEvent(this._mesh_Down, ["leftclick"]) && (e.button === 0)) {
|
|
271
|
-
this._mesh_Down.dispatchEvent({
|
|
272
|
-
...intersection,
|
|
273
|
-
renderer: this._renderer,
|
|
274
|
-
camera: this._camera,
|
|
275
|
-
object: intersection.object,
|
|
276
|
-
type: "leftclick",
|
|
277
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
278
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
279
|
-
x: this._mousemoveEvent.x,
|
|
280
|
-
y: this._mousemoveEvent.y
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
if (this.hasEvent(this._mesh_Down, ["rightclick"]) && (e.button === 2)) {
|
|
284
|
-
this._mesh_Down.dispatchEvent({
|
|
285
|
-
...intersection,
|
|
286
|
-
renderer: this._renderer,
|
|
287
|
-
camera: this._camera,
|
|
288
|
-
object: intersection.object,
|
|
289
|
-
type: "rightclick",
|
|
290
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
291
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
292
|
-
x: this._mousemoveEvent.x,
|
|
293
|
-
y: this._mousemoveEvent.y
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
else if (this._click_num > 1) {
|
|
298
|
-
if (this.hasEvent(this._mesh_Down, ["dbclick"]) && (new Date().valueOf() - this._click_num > 1) && (e.button === 0)) {
|
|
299
|
-
this._mesh_Down.dispatchEvent({
|
|
300
|
-
...intersection,
|
|
301
|
-
renderer: this._renderer,
|
|
302
|
-
camera: this._camera,
|
|
303
|
-
object: intersection.object,
|
|
304
|
-
type: "dbclick",
|
|
305
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
306
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
307
|
-
x: this._mousemoveEvent.x,
|
|
308
|
-
y: this._mousemoveEvent.y
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
else {
|
|
314
|
-
if (this.hasEvent(this._mesh_Down, ["click"])) {
|
|
315
|
-
this._mesh_Down.dispatchEvent({
|
|
316
|
-
...intersection,
|
|
317
|
-
renderer: this._renderer,
|
|
318
|
-
camera: this._camera,
|
|
319
|
-
object: intersection.object,
|
|
320
|
-
type: "click",
|
|
321
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
322
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
323
|
-
x: this._mousemoveEvent.x,
|
|
324
|
-
y: this._mousemoveEvent.y
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
if (this.hasEvent(this._mesh_Down, ["leftclick"]) && (e.button === 0)) {
|
|
328
|
-
this._mesh_Down.dispatchEvent({
|
|
329
|
-
...intersection,
|
|
330
|
-
renderer: this._renderer,
|
|
331
|
-
camera: this._camera,
|
|
332
|
-
object: intersection.object,
|
|
333
|
-
type: "leftclick",
|
|
334
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
335
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
336
|
-
x: this._mousemoveEvent.x,
|
|
337
|
-
y: this._mousemoveEvent.y
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
if (this.hasEvent(this._mesh_Down, ["rightclick"]) && (e.button === 2)) {
|
|
341
|
-
this._mesh_Down.dispatchEvent({
|
|
342
|
-
...intersection,
|
|
343
|
-
renderer: this._renderer,
|
|
344
|
-
camera: this._camera,
|
|
345
|
-
object: intersection.object,
|
|
346
|
-
type: "rightclick",
|
|
347
|
-
offsetX: this._mousemoveEvent.offsetX,
|
|
348
|
-
offsetY: this._mousemoveEvent.offsetY,
|
|
349
|
-
x: this._mousemoveEvent.x,
|
|
350
|
-
y: this._mousemoveEvent.y
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
this._click_num = 0;
|
|
355
|
-
}
|
|
356
|
-
});
|
|
357
|
-
}
|
|
314
|
+
return ThreeMouse;
|
|
315
|
+
}());
|
|
316
|
+
export default ThreeMouse;
|