three-base 1.0.82 → 1.0.83
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/index.js +1 -1
- package/index.ts +1 -1
- package/lib/ApngTexture.js +40 -107
- package/lib/ApngTextureManage.js +51 -100
- package/lib/EventMesh.js +22 -42
- package/lib/ExtrudeMesh.js +147 -178
- package/lib/FPScontrol.js +116 -133
- package/lib/InstancedGroupMesh.js +25 -45
- package/lib/KeyFrameAnimation.js +37 -54
- package/lib/PlaneText.d.ts +2 -2
- package/lib/PlaneText.js +16 -36
- package/lib/PlaneText.ts +2 -3
- package/lib/PlaneWithHtml.js +48 -126
- package/lib/PointLight/PointLight.d.ts +2 -2
- package/lib/PointLight/PointLight.js +47 -67
- package/lib/PointLight/PointLight.ts +3 -3
- package/lib/Sky/Sky.js +11 -30
- package/lib/SpriteText.d.ts +45 -0
- package/lib/SpriteText.js +162 -0
- package/lib/SpriteText.ts +189 -0
- package/lib/SpriteText2.d.ts +4 -4
- package/lib/SpriteText2.js +90 -166
- package/lib/Text3D/Text3D.js +40 -61
- package/lib/Text3D/fontController.js +149 -284
- package/lib/ThreeBase.js +204 -341
- package/lib/ThreeMouse.js +244 -203
- package/lib/Transition.js +95 -161
- package/lib/keyContorls.js +74 -102
- package/lib/planeModal1/PlaneModal1.js +90 -162
- package/lib/shaders.js +178 -36
- package/lib/spriteModal1/SpriteModal1.js +93 -165
- package/lib/threeLoader.js +66 -89
- package/lib/threeUtils.js +61 -85
- package/lib/threeUtils.ts +2 -1
- package/package.json +2 -4
package/lib/ThreeMouse.js
CHANGED
|
@@ -1,50 +1,3 @@
|
|
|
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
|
-
};
|
|
48
1
|
//
|
|
49
2
|
//
|
|
50
3
|
//
|
|
@@ -57,153 +10,53 @@ import { debounce } from "lodash";
|
|
|
57
10
|
/**
|
|
58
11
|
* harp.gl 专用的鼠标拾取模型对象
|
|
59
12
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
}); });
|
|
13
|
+
export default class ThreeMouse {
|
|
14
|
+
constructor(renderer, camera, scene) {
|
|
185
15
|
this._renderer = renderer;
|
|
186
16
|
this._camera = camera;
|
|
187
17
|
this._scene = scene;
|
|
188
18
|
this._frame = this._renderer.info.render.frame;
|
|
189
|
-
this._renderer.domElement.addEventListener("mouseenter",
|
|
19
|
+
this._renderer.domElement.addEventListener("mouseenter", () => { this._mouseInRenderer = true; }, true); //鼠标进入开启拾取
|
|
190
20
|
this._renderer.domElement.addEventListener("mouseleave", this._mouseleave, true); //鼠标离开停止拾取
|
|
191
21
|
this._renderer.domElement.addEventListener("mousemove", this._mousemove, true); //鼠标移动监听事件
|
|
192
22
|
this._renderer.domElement.addEventListener("pointerdown", this._mousedown, true); //鼠标按下监听事件
|
|
193
23
|
this._renderer.domElement.addEventListener("pointerup", this._mouseup, true); //鼠标弹起监听事件
|
|
194
24
|
}
|
|
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;
|
|
195
49
|
// 获取拾取到的对象
|
|
196
|
-
|
|
197
|
-
|
|
50
|
+
_getSelected(object3ds) {
|
|
51
|
+
let intersection;
|
|
198
52
|
if (object3ds.length) {
|
|
199
53
|
intersection = this._raycaster.intersectObjects(object3ds, false)[0];
|
|
200
54
|
}
|
|
201
55
|
return intersection;
|
|
202
|
-
}
|
|
56
|
+
}
|
|
203
57
|
;
|
|
204
58
|
// 判断对象上面是否有事件
|
|
205
|
-
|
|
206
|
-
if (types === void 0) { types = []; }
|
|
59
|
+
hasEvent(object, types = []) {
|
|
207
60
|
if (!object) {
|
|
208
61
|
return false;
|
|
209
62
|
}
|
|
@@ -211,7 +64,7 @@ var ThreeMouse = /** @class */ (function () {
|
|
|
211
64
|
if (object["userData"] && object["userData"]["enableEvent"] === false) {
|
|
212
65
|
return false;
|
|
213
66
|
}
|
|
214
|
-
|
|
67
|
+
const hasevent = types.some(type => {
|
|
215
68
|
//@ts-ignore
|
|
216
69
|
if (object["_listeners"] && object["_listeners"][type] && object["_listeners"][type][0]) {
|
|
217
70
|
return true;
|
|
@@ -222,9 +75,9 @@ var ThreeMouse = /** @class */ (function () {
|
|
|
222
75
|
return false;
|
|
223
76
|
});
|
|
224
77
|
return hasevent;
|
|
225
|
-
}
|
|
78
|
+
}
|
|
226
79
|
// 判断对象上是否有鼠标样式
|
|
227
|
-
|
|
80
|
+
hasCursor(object) {
|
|
228
81
|
if (!object) {
|
|
229
82
|
return false;
|
|
230
83
|
}
|
|
@@ -235,15 +88,14 @@ var ThreeMouse = /** @class */ (function () {
|
|
|
235
88
|
if (object["userData"] && object["userData"]["cursor"]) {
|
|
236
89
|
return true;
|
|
237
90
|
}
|
|
238
|
-
}
|
|
91
|
+
}
|
|
239
92
|
// 分发鼠标拾取事件
|
|
240
|
-
|
|
241
|
-
var _this = this;
|
|
93
|
+
dispatchEvent() {
|
|
242
94
|
// 提取有事件的对象
|
|
243
|
-
|
|
244
|
-
this._scene.traverseVisible(
|
|
95
|
+
const meshs = [];
|
|
96
|
+
this._scene.traverseVisible(mesh => {
|
|
245
97
|
// 判断对象是否有指定的事件
|
|
246
|
-
if (
|
|
98
|
+
if (this.hasCursor(mesh) || this.hasEvent(mesh, ["leftclick", "rightclick", "click", "dbclick", "mouseenter", "mouseleave", "mousemove", "mousedown", "mouseup"])) {
|
|
247
99
|
meshs.push(mesh);
|
|
248
100
|
}
|
|
249
101
|
});
|
|
@@ -253,9 +105,9 @@ var ThreeMouse = /** @class */ (function () {
|
|
|
253
105
|
return;
|
|
254
106
|
}
|
|
255
107
|
// 拾取模型
|
|
256
|
-
|
|
108
|
+
let intersection = this._getSelected(meshs);
|
|
257
109
|
if (intersection) {
|
|
258
|
-
|
|
110
|
+
const MouseEvent = Object.assign(intersection, {
|
|
259
111
|
renderer: this._renderer,
|
|
260
112
|
camera: this._camera,
|
|
261
113
|
object: intersection.object,
|
|
@@ -266,24 +118,24 @@ var ThreeMouse = /** @class */ (function () {
|
|
|
266
118
|
y: this._mousemoveEvent.y
|
|
267
119
|
});
|
|
268
120
|
// 触发滑动事件
|
|
269
|
-
if (this._mesh_on ===
|
|
270
|
-
if (this.hasEvent(
|
|
271
|
-
|
|
272
|
-
|
|
121
|
+
if (this._mesh_on === MouseEvent.object) {
|
|
122
|
+
if (this.hasEvent(MouseEvent.object, ["mousemove"])) {
|
|
123
|
+
MouseEvent.type = "mousemove";
|
|
124
|
+
MouseEvent.object.dispatchEvent(MouseEvent);
|
|
273
125
|
}
|
|
274
126
|
// 鼠标划入滑出事件
|
|
275
127
|
}
|
|
276
|
-
else if (this._mesh_on !==
|
|
128
|
+
else if (this._mesh_on !== MouseEvent.object) {
|
|
277
129
|
if (this.hasEvent(this._mesh_on, ["mouseleave"])) {
|
|
278
|
-
|
|
279
|
-
this._mesh_on.dispatchEvent(
|
|
130
|
+
MouseEvent.type = "mouseleave";
|
|
131
|
+
this._mesh_on.dispatchEvent(MouseEvent);
|
|
280
132
|
}
|
|
281
|
-
if (this.hasEvent(
|
|
282
|
-
|
|
283
|
-
|
|
133
|
+
if (this.hasEvent(MouseEvent.object, ["mouseenter"])) {
|
|
134
|
+
MouseEvent.type = "mouseenter";
|
|
135
|
+
MouseEvent.object.dispatchEvent(MouseEvent);
|
|
284
136
|
}
|
|
285
137
|
}
|
|
286
|
-
this._mesh_on =
|
|
138
|
+
this._mesh_on = MouseEvent.object || undefined; // 设置为当前鼠标上的对象
|
|
287
139
|
// 鼠标样式
|
|
288
140
|
if (this._mesh_on && this._mesh_on.userData && this._mesh_on.userData.cursor) {
|
|
289
141
|
this._renderer.domElement.style.cursor = this._mesh_on.userData.cursor;
|
|
@@ -310,7 +162,196 @@ var ThreeMouse = /** @class */ (function () {
|
|
|
310
162
|
this._mesh_on = undefined;
|
|
311
163
|
this._renderer.domElement.style.cursor = "auto"; // 鼠标样式
|
|
312
164
|
}
|
|
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); // 设置射线拾取的参数
|
|
313
198
|
};
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
199
|
+
// 鼠标按下事件
|
|
200
|
+
_mousedown = (e) => {
|
|
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
|
+
}
|