lythreeframe 1.2.61 → 1.2.63
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/dist/bundle.cjs.js +218 -200
- package/dist/bundle.esm.js +218 -200
- package/dist/index.d.ts +1 -0
- package/dist/lythreeframe/Frame/Controller.d.ts +42 -20
- package/dist/lythreeframe/Object/Actor.d.ts +13 -20
- package/dist/lythreeframe/Object/Components/SceneComponent.d.ts +9 -0
- package/package.json +1 -1
package/dist/bundle.esm.js
CHANGED
|
@@ -123,6 +123,30 @@ var AttachmentRules;
|
|
|
123
123
|
AttachmentRules[AttachmentRules["KeepRelative"] = 2] = "KeepRelative";
|
|
124
124
|
})(AttachmentRules || (AttachmentRules = {}));
|
|
125
125
|
|
|
126
|
+
class Delegate {
|
|
127
|
+
constructor() {
|
|
128
|
+
this.functions = [];
|
|
129
|
+
}
|
|
130
|
+
broadcast(...args) {
|
|
131
|
+
this.functions.forEach((func) => func(...args));
|
|
132
|
+
}
|
|
133
|
+
add(func) {
|
|
134
|
+
this.functions.push(func);
|
|
135
|
+
}
|
|
136
|
+
remove(func) {
|
|
137
|
+
const index = this.functions.indexOf(func);
|
|
138
|
+
if (index >= 0) {
|
|
139
|
+
this.functions.splice(index, 1);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
console.warn("function not found");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
clear() {
|
|
146
|
+
this.functions = [];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
126
150
|
class SceneComponent extends Component {
|
|
127
151
|
set parentActor(value) {
|
|
128
152
|
this.childrenComponents.forEach((elem) => {
|
|
@@ -133,6 +157,11 @@ class SceneComponent extends Component {
|
|
|
133
157
|
get parentActor() {
|
|
134
158
|
return this._parentActor;
|
|
135
159
|
}
|
|
160
|
+
// Delegate getters
|
|
161
|
+
get onHoverBeginDelegate() { return this._onHoverBeginDelegate; }
|
|
162
|
+
get onHoverEndDelegate() { return this._onHoverEndDelegate; }
|
|
163
|
+
get onClickDelegate() { return this._onClickDelegate; }
|
|
164
|
+
get onDoubleClickDelegate() { return this._onDoubleClickDelegate; }
|
|
136
165
|
get world() {
|
|
137
166
|
return this.app.world;
|
|
138
167
|
}
|
|
@@ -140,6 +169,11 @@ class SceneComponent extends Component {
|
|
|
140
169
|
super(uuid);
|
|
141
170
|
this.bCanHover = false;
|
|
142
171
|
this.bCanClick = false;
|
|
172
|
+
// Component 级别事件 Delegates
|
|
173
|
+
this._onHoverBeginDelegate = new Delegate();
|
|
174
|
+
this._onHoverEndDelegate = new Delegate();
|
|
175
|
+
this._onClickDelegate = new Delegate();
|
|
176
|
+
this._onDoubleClickDelegate = new Delegate();
|
|
143
177
|
this.app = app;
|
|
144
178
|
this.name = "SceneComponent";
|
|
145
179
|
}
|
|
@@ -308,12 +342,15 @@ class SceneComponent extends Component {
|
|
|
308
342
|
}
|
|
309
343
|
}
|
|
310
344
|
setPosition(...args) {
|
|
345
|
+
var _a;
|
|
311
346
|
if (!this.obj) {
|
|
312
347
|
throw Error("threeObject is invalid");
|
|
313
348
|
}
|
|
314
349
|
let newPosition = null;
|
|
315
|
-
|
|
316
|
-
|
|
350
|
+
// 使用 isVector3 属性检查,避免多个 Three.js 实例导致 instanceof 失败
|
|
351
|
+
if (args.length === 1 && ((_a = args[0]) === null || _a === void 0 ? void 0 : _a.isVector3)) {
|
|
352
|
+
const vec = args[0];
|
|
353
|
+
newPosition = new Vector3(vec.x, vec.y, vec.z);
|
|
317
354
|
}
|
|
318
355
|
else if (args.length === 3 &&
|
|
319
356
|
typeof args[0] === "number" &&
|
|
@@ -351,14 +388,17 @@ class SceneComponent extends Component {
|
|
|
351
388
|
}
|
|
352
389
|
}
|
|
353
390
|
setRotation(...args) {
|
|
391
|
+
var _a;
|
|
354
392
|
if (!this.obj) {
|
|
355
393
|
throw Error("threeObject is invalid");
|
|
356
394
|
}
|
|
357
395
|
let newRotation = null;
|
|
358
|
-
|
|
359
|
-
|
|
396
|
+
// 使用 isEuler 属性检查,避免多个 Three.js 实例导致 instanceof 失败
|
|
397
|
+
if ((_a = args[0]) === null || _a === void 0 ? void 0 : _a.isEuler) {
|
|
398
|
+
const euler = args[0];
|
|
399
|
+
newRotation = new Euler(euler.x, euler.y, euler.z, euler.order);
|
|
360
400
|
}
|
|
361
|
-
if (typeof (args[0]) === "number" && typeof (args[1]) === "number" && typeof (args[2]) === "number") {
|
|
401
|
+
else if (typeof (args[0]) === "number" && typeof (args[1]) === "number" && typeof (args[2]) === "number") {
|
|
362
402
|
newRotation = new Euler(args[0], args[1], args[2]);
|
|
363
403
|
}
|
|
364
404
|
if (!newRotation) {
|
|
@@ -388,14 +428,17 @@ class SceneComponent extends Component {
|
|
|
388
428
|
}
|
|
389
429
|
}
|
|
390
430
|
setQuaternion(...args) {
|
|
431
|
+
var _a;
|
|
391
432
|
if (!this.obj) {
|
|
392
433
|
throw Error("threeObject is invalid");
|
|
393
434
|
}
|
|
394
435
|
let newQuat = null;
|
|
395
|
-
|
|
396
|
-
|
|
436
|
+
// 使用 isQuaternion 属性检查,避免多个 Three.js 实例导致 instanceof 失败
|
|
437
|
+
if ((_a = args[0]) === null || _a === void 0 ? void 0 : _a.isQuaternion) {
|
|
438
|
+
const q = args[0];
|
|
439
|
+
newQuat = new Quaternion(q.x, q.y, q.z, q.w);
|
|
397
440
|
}
|
|
398
|
-
if (typeof args[0] === "number" && typeof args[1] === "number" && typeof args[2] === "number" && typeof args[3] === "number") {
|
|
441
|
+
else if (typeof args[0] === "number" && typeof args[1] === "number" && typeof args[2] === "number" && typeof args[3] === "number") {
|
|
399
442
|
newQuat = new Quaternion(args[0], args[1], args[2], args[3]);
|
|
400
443
|
}
|
|
401
444
|
if (!newQuat) {
|
|
@@ -433,14 +476,17 @@ class SceneComponent extends Component {
|
|
|
433
476
|
}
|
|
434
477
|
}
|
|
435
478
|
setScale(...args) {
|
|
479
|
+
var _a;
|
|
436
480
|
if (!this.obj) {
|
|
437
481
|
throw Error("threeObject is invalid");
|
|
438
482
|
}
|
|
439
483
|
let newScale = null;
|
|
440
|
-
|
|
441
|
-
|
|
484
|
+
// 使用 isVector3 属性检查,避免多个 Three.js 实例导致 instanceof 失败
|
|
485
|
+
if ((_a = args[0]) === null || _a === void 0 ? void 0 : _a.isVector3) {
|
|
486
|
+
const vec = args[0];
|
|
487
|
+
newScale = new Vector3(vec.x, vec.y, vec.z);
|
|
442
488
|
}
|
|
443
|
-
if (typeof (args[0]) === "number" && typeof (args[1]) === "number" && typeof (args[2]) === "number") {
|
|
489
|
+
else if (typeof (args[0]) === "number" && typeof (args[1]) === "number" && typeof (args[2]) === "number") {
|
|
444
490
|
newScale = new Vector3(args[0], args[1], args[2]);
|
|
445
491
|
}
|
|
446
492
|
if (!newScale) {
|
|
@@ -696,38 +742,17 @@ class SceneComponent extends Component {
|
|
|
696
742
|
return this.bCanClick;
|
|
697
743
|
}
|
|
698
744
|
onHorveringBegin() {
|
|
699
|
-
|
|
700
|
-
return;
|
|
701
|
-
}
|
|
702
|
-
if (this.parentActor) {
|
|
703
|
-
let comp = this;
|
|
704
|
-
this.parentActor.onComponentHorveringBegin(comp);
|
|
705
|
-
}
|
|
745
|
+
this._onHoverBeginDelegate.broadcast();
|
|
706
746
|
}
|
|
707
747
|
onHorveringEnd() {
|
|
708
|
-
|
|
709
|
-
return;
|
|
710
|
-
}
|
|
711
|
-
if (this.parentActor) {
|
|
712
|
-
let comp = this;
|
|
713
|
-
this.parentActor.onComponentHorveringEnd(comp);
|
|
714
|
-
}
|
|
748
|
+
this._onHoverEndDelegate.broadcast();
|
|
715
749
|
}
|
|
716
750
|
/* click */
|
|
717
751
|
onClicked() {
|
|
718
|
-
|
|
719
|
-
return;
|
|
720
|
-
}
|
|
721
|
-
if (this.parentActor) {
|
|
722
|
-
let comp = this;
|
|
723
|
-
this.parentActor.onComponentClicked(comp);
|
|
724
|
-
}
|
|
752
|
+
this._onClickDelegate.broadcast();
|
|
725
753
|
}
|
|
726
754
|
onDoubleClicked() {
|
|
727
|
-
|
|
728
|
-
let comp = this;
|
|
729
|
-
this.parentActor.onComponentDoubleClicked(comp);
|
|
730
|
-
}
|
|
755
|
+
this._onDoubleClickDelegate.broadcast();
|
|
731
756
|
}
|
|
732
757
|
}
|
|
733
758
|
|
|
@@ -1287,30 +1312,6 @@ var AssetType;
|
|
|
1287
1312
|
AssetType[AssetType["undefined"] = -1] = "undefined";
|
|
1288
1313
|
})(AssetType || (AssetType = {}));
|
|
1289
1314
|
|
|
1290
|
-
class Delegate {
|
|
1291
|
-
constructor() {
|
|
1292
|
-
this.functions = [];
|
|
1293
|
-
}
|
|
1294
|
-
broadcast(...args) {
|
|
1295
|
-
this.functions.forEach((func) => func(...args));
|
|
1296
|
-
}
|
|
1297
|
-
add(func) {
|
|
1298
|
-
this.functions.push(func);
|
|
1299
|
-
}
|
|
1300
|
-
remove(func) {
|
|
1301
|
-
const index = this.functions.indexOf(func);
|
|
1302
|
-
if (index >= 0) {
|
|
1303
|
-
this.functions.splice(index, 1);
|
|
1304
|
-
}
|
|
1305
|
-
else {
|
|
1306
|
-
console.warn("function not found");
|
|
1307
|
-
}
|
|
1308
|
-
}
|
|
1309
|
-
clear() {
|
|
1310
|
-
this.functions = [];
|
|
1311
|
-
}
|
|
1312
|
-
}
|
|
1313
|
-
|
|
1314
1315
|
const DefaultPostProcessParam = {
|
|
1315
1316
|
steps: []
|
|
1316
1317
|
};
|
|
@@ -2086,7 +2087,8 @@ class Orbital extends Pawn {
|
|
|
2086
2087
|
focusTo(targetPos, targetQuat, distance, time, onGoing = null, onFinished = null) {
|
|
2087
2088
|
this.stopFocusing();
|
|
2088
2089
|
let finalQuat = null;
|
|
2089
|
-
|
|
2090
|
+
// 使用 isEuler 属性检查,避免多个 Three.js 实例导致 instanceof 失败
|
|
2091
|
+
if (targetQuat === null || targetQuat === void 0 ? void 0 : targetQuat.isEuler) {
|
|
2090
2092
|
finalQuat = new Quaternion().setFromEuler(targetQuat);
|
|
2091
2093
|
}
|
|
2092
2094
|
else {
|
|
@@ -2176,34 +2178,51 @@ class Controller {
|
|
|
2176
2178
|
get world() { return this._app.world; }
|
|
2177
2179
|
get viewPort() { return this._app.viewport; }
|
|
2178
2180
|
get app() { return this._app; }
|
|
2179
|
-
get onClickNothingDelegate() { return this._onClickNothingDelegate; }
|
|
2180
|
-
get onComponentClickDelegate() { return this._onComponentClickDelegate; }
|
|
2181
|
-
get onComponentDoubleClickDelegate() { return this._onComponentDoubleClickDelegate; }
|
|
2182
|
-
get onComponentHoverBeginDelegate() { return this._onComponentHoverBeginDelegate; }
|
|
2183
|
-
get onComponentHoverEndDelegate() { return this._onComponentHoverEndDelegate; }
|
|
2184
|
-
get onComponentPointerDownDelegate() { return this._onComponentPointerDownDelegate; }
|
|
2185
2181
|
get pawn() {
|
|
2186
2182
|
if (!this._pawn)
|
|
2187
2183
|
throw Error("pawn is null");
|
|
2188
2184
|
return this._pawn;
|
|
2189
2185
|
}
|
|
2186
|
+
// Component level delegate getters
|
|
2187
|
+
get onComponentClickDelegate() { return this._onComponentClickDelegate; }
|
|
2188
|
+
get onComponentDoubleClickDelegate() { return this._onComponentDoubleClickDelegate; }
|
|
2189
|
+
get onComponentHoverBeginDelegate() { return this._onComponentHoverBeginDelegate; }
|
|
2190
|
+
get onComponentHoverEndDelegate() { return this._onComponentHoverEndDelegate; }
|
|
2191
|
+
get onComponentPointerDownDelegate() { return this._onComponentPointerDownDelegate; }
|
|
2192
|
+
// Actor level delegate getters
|
|
2193
|
+
get onActorClickDelegate() { return this._onActorClickDelegate; }
|
|
2194
|
+
get onActorDoubleClickDelegate() { return this._onActorDoubleClickDelegate; }
|
|
2195
|
+
get onActorHoverBeginDelegate() { return this._onActorHoverBeginDelegate; }
|
|
2196
|
+
get onActorHoverEndDelegate() { return this._onActorHoverEndDelegate; }
|
|
2197
|
+
get onClickNothingDelegate() { return this._onClickNothingDelegate; }
|
|
2190
2198
|
constructor(app) {
|
|
2191
2199
|
this._pawn = null;
|
|
2200
|
+
// Component level state
|
|
2201
|
+
this.hoveringComponent = null;
|
|
2202
|
+
// Actor level state
|
|
2203
|
+
this.hoveringActor = null;
|
|
2204
|
+
// Click state
|
|
2192
2205
|
this.prepareClickComponent = null;
|
|
2193
2206
|
this.prepareClickHit = null;
|
|
2194
2207
|
this.prepareClickModifiers = { ctrlKey: false, shiftKey: false, altKey: false };
|
|
2195
|
-
this.hoveringComponent = null;
|
|
2196
2208
|
this._pointButtonIsDown = new Set();
|
|
2197
|
-
|
|
2209
|
+
// Component level delegates
|
|
2198
2210
|
this._onComponentClickDelegate = new Delegate();
|
|
2199
2211
|
this._onComponentDoubleClickDelegate = new Delegate();
|
|
2200
2212
|
this._onComponentHoverBeginDelegate = new Delegate();
|
|
2201
2213
|
this._onComponentHoverEndDelegate = new Delegate();
|
|
2202
2214
|
this._onComponentPointerDownDelegate = new Delegate();
|
|
2215
|
+
// Actor level delegates
|
|
2216
|
+
this._onActorClickDelegate = new Delegate();
|
|
2217
|
+
this._onActorDoubleClickDelegate = new Delegate();
|
|
2218
|
+
this._onActorHoverBeginDelegate = new Delegate();
|
|
2219
|
+
this._onActorHoverEndDelegate = new Delegate();
|
|
2220
|
+
// Other delegates
|
|
2221
|
+
this._onClickNothingDelegate = new Delegate();
|
|
2203
2222
|
// Pointer state
|
|
2204
2223
|
this.pointerPosition = new Vector2();
|
|
2205
2224
|
this.pointerLeftDownPosition = new Vector2();
|
|
2206
|
-
// Reusable objects
|
|
2225
|
+
// Reusable objects
|
|
2207
2226
|
this._tempVec2 = new Vector2();
|
|
2208
2227
|
this._raycastVec2 = new Vector2();
|
|
2209
2228
|
// Double click detection
|
|
@@ -2242,7 +2261,7 @@ class Controller {
|
|
|
2242
2261
|
}
|
|
2243
2262
|
destroy() {
|
|
2244
2263
|
this.clearClickTimer();
|
|
2245
|
-
this.
|
|
2264
|
+
this.clearHovering();
|
|
2246
2265
|
const canvas = this.viewPort.canvas;
|
|
2247
2266
|
if (canvas) {
|
|
2248
2267
|
canvas.removeEventListener("pointerenter", this.onPointerEnter);
|
|
@@ -2253,7 +2272,9 @@ class Controller {
|
|
|
2253
2272
|
this.pawn.destroy();
|
|
2254
2273
|
this._pawn = null;
|
|
2255
2274
|
}
|
|
2275
|
+
// ==================== Pointer Events ====================
|
|
2256
2276
|
onPointerMoveEvent(event) {
|
|
2277
|
+
var _a, _b;
|
|
2257
2278
|
const canvas = this.viewPort.canvas;
|
|
2258
2279
|
if (!canvas)
|
|
2259
2280
|
throw Error("canvas is null");
|
|
@@ -2262,47 +2283,48 @@ class Controller {
|
|
|
2262
2283
|
if (this._pointButtonIsDown.size > 0)
|
|
2263
2284
|
return;
|
|
2264
2285
|
const hits = this.getHitResultUnderCursor();
|
|
2265
|
-
const component = hits === null || hits === void 0 ? void 0 : hits.component;
|
|
2286
|
+
const component = (_a = hits === null || hits === void 0 ? void 0 : hits.component) !== null && _a !== void 0 ? _a : null;
|
|
2287
|
+
const actor = (_b = component === null || component === void 0 ? void 0 : component.parentActor) !== null && _b !== void 0 ? _b : null;
|
|
2288
|
+
// Component 级别 hover 检测
|
|
2266
2289
|
if (component !== this.hoveringComponent) {
|
|
2267
|
-
this.
|
|
2268
|
-
|
|
2269
|
-
|
|
2290
|
+
if (this.hoveringComponent) {
|
|
2291
|
+
this.fireComponentHoverEnd(this.hoveringComponent);
|
|
2292
|
+
}
|
|
2293
|
+
if (component && component.isHoverEnabled && hits) {
|
|
2294
|
+
this.fireComponentHoverBegin(component, hits.hit);
|
|
2270
2295
|
}
|
|
2271
2296
|
}
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2297
|
+
// Actor 级别 hover 检测(独立于 Component)
|
|
2298
|
+
if (actor !== this.hoveringActor) {
|
|
2299
|
+
if (this.hoveringActor && this.hoveringComponent) {
|
|
2300
|
+
this.fireActorHoverEnd(this.hoveringActor, this.hoveringComponent);
|
|
2301
|
+
}
|
|
2302
|
+
if (actor && component && actor.isHoverEnabled && hits) {
|
|
2303
|
+
this.fireActorHoverBegin(actor, component, hits.hit);
|
|
2304
|
+
}
|
|
2276
2305
|
}
|
|
2306
|
+
this.hoveringComponent = component;
|
|
2307
|
+
this.hoveringActor = actor;
|
|
2277
2308
|
}
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
this._onComponentHoverBeginDelegate.broadcast(event);
|
|
2282
|
-
if (!event.handled) {
|
|
2283
|
-
component.onHorveringBegin();
|
|
2284
|
-
}
|
|
2285
|
-
this.hoveringComponent = component;
|
|
2309
|
+
clearHovering() {
|
|
2310
|
+
if (this.hoveringComponent) {
|
|
2311
|
+
this.fireComponentHoverEnd(this.hoveringComponent);
|
|
2286
2312
|
}
|
|
2287
|
-
|
|
2288
|
-
this.
|
|
2289
|
-
if (!event.handled) {
|
|
2290
|
-
component.onHorveringEnd();
|
|
2291
|
-
}
|
|
2292
|
-
this.hoveringComponent = null;
|
|
2313
|
+
if (this.hoveringActor && this.hoveringComponent) {
|
|
2314
|
+
this.fireActorHoverEnd(this.hoveringActor, this.hoveringComponent);
|
|
2293
2315
|
}
|
|
2316
|
+
this.hoveringComponent = null;
|
|
2317
|
+
this.hoveringActor = null;
|
|
2294
2318
|
}
|
|
2295
2319
|
onPointerUpEvent(event) {
|
|
2296
2320
|
this._pointButtonIsDown.delete(event.button);
|
|
2297
2321
|
if (event.button !== 0)
|
|
2298
2322
|
return;
|
|
2299
|
-
// Check if pointer moved too much (drag instead of click)
|
|
2300
2323
|
const pointerOffset = this._tempVec2.subVectors(this.pointerLeftDownPosition, this.pointerPosition).length();
|
|
2301
2324
|
if (pointerOffset > 0.005) {
|
|
2302
2325
|
this.clearClickTimer();
|
|
2303
2326
|
return;
|
|
2304
2327
|
}
|
|
2305
|
-
// 保存修饰键状态
|
|
2306
2328
|
this.prepareClickModifiers = {
|
|
2307
2329
|
ctrlKey: event.ctrlKey,
|
|
2308
2330
|
shiftKey: event.shiftKey,
|
|
@@ -2324,7 +2346,7 @@ class Controller {
|
|
|
2324
2346
|
this.leftClickTimer = window.setTimeout(() => {
|
|
2325
2347
|
this.leftClickTimer = null;
|
|
2326
2348
|
if (this.prepareClickComponent && this.prepareClickHit) {
|
|
2327
|
-
this.
|
|
2349
|
+
this.fireClickEvents(this.prepareClickComponent, this.prepareClickHit, false);
|
|
2328
2350
|
this.prepareClickComponent = null;
|
|
2329
2351
|
this.prepareClickHit = null;
|
|
2330
2352
|
}
|
|
@@ -2337,7 +2359,7 @@ class Controller {
|
|
|
2337
2359
|
handleDoubleClick() {
|
|
2338
2360
|
this.clearClickTimer();
|
|
2339
2361
|
if (this.prepareClickComponent && this.prepareClickHit) {
|
|
2340
|
-
this.
|
|
2362
|
+
this.fireClickEvents(this.prepareClickComponent, this.prepareClickHit, true);
|
|
2341
2363
|
}
|
|
2342
2364
|
else {
|
|
2343
2365
|
this._onClickNothingDelegate.broadcast();
|
|
@@ -2345,8 +2367,40 @@ class Controller {
|
|
|
2345
2367
|
this.prepareClickComponent = null;
|
|
2346
2368
|
this.prepareClickHit = null;
|
|
2347
2369
|
}
|
|
2348
|
-
|
|
2349
|
-
|
|
2370
|
+
onPointerDownEvent(event) {
|
|
2371
|
+
this._pointButtonIsDown.add(event.button);
|
|
2372
|
+
if (event.button === 0) {
|
|
2373
|
+
this.pointerLeftDownPosition.copy(this.pointerPosition);
|
|
2374
|
+
}
|
|
2375
|
+
const hit = this.getHitResultUnderCursor();
|
|
2376
|
+
const component = hit === null || hit === void 0 ? void 0 : hit.component;
|
|
2377
|
+
if (component instanceof SceneComponent && hit) {
|
|
2378
|
+
this.firePointerDownEvent(component, hit.hit, event.button);
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
onPointerEnterEvent(_event) {
|
|
2382
|
+
this.addCorePointerListeners();
|
|
2383
|
+
}
|
|
2384
|
+
onPointerLeaveEvent(_event) {
|
|
2385
|
+
this.removeCorePointerListeners();
|
|
2386
|
+
}
|
|
2387
|
+
// ==================== Component Level Events ====================
|
|
2388
|
+
fireComponentHoverBegin(component, hit) {
|
|
2389
|
+
const event = { component, hit, handled: false };
|
|
2390
|
+
this._onComponentHoverBeginDelegate.broadcast(event);
|
|
2391
|
+
if (!event.handled) {
|
|
2392
|
+
component.onHorveringBegin();
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
fireComponentHoverEnd(component) {
|
|
2396
|
+
const event = { component, hit: null, handled: false };
|
|
2397
|
+
this._onComponentHoverEndDelegate.broadcast(event);
|
|
2398
|
+
if (!event.handled) {
|
|
2399
|
+
component.onHorveringEnd();
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
fireComponentClick(component, hit, isDoubleClick) {
|
|
2403
|
+
const event = Object.assign({ component, hit, handled: false }, this.prepareClickModifiers);
|
|
2350
2404
|
if (isDoubleClick) {
|
|
2351
2405
|
this._onComponentDoubleClickDelegate.broadcast(event);
|
|
2352
2406
|
if (!event.handled) {
|
|
@@ -2360,33 +2414,56 @@ class Controller {
|
|
|
2360
2414
|
}
|
|
2361
2415
|
}
|
|
2362
2416
|
}
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
this.leftClickTimer = null;
|
|
2367
|
-
}
|
|
2417
|
+
firePointerDownEvent(component, hit, button) {
|
|
2418
|
+
const event = { component, hit, button, handled: false };
|
|
2419
|
+
this._onComponentPointerDownDelegate.broadcast(event);
|
|
2368
2420
|
}
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2421
|
+
// ==================== Actor Level Events ====================
|
|
2422
|
+
fireActorHoverBegin(actor, component, hit) {
|
|
2423
|
+
const event = { actor, component, hit, handled: false };
|
|
2424
|
+
this._onActorHoverBeginDelegate.broadcast(event);
|
|
2425
|
+
if (!event.handled) {
|
|
2426
|
+
actor.onActorHoverBegin(component);
|
|
2373
2427
|
}
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
const
|
|
2377
|
-
|
|
2378
|
-
|
|
2428
|
+
}
|
|
2429
|
+
fireActorHoverEnd(actor, component) {
|
|
2430
|
+
const event = { actor, component, hit: null, handled: false };
|
|
2431
|
+
this._onActorHoverEndDelegate.broadcast(event);
|
|
2432
|
+
if (!event.handled) {
|
|
2433
|
+
actor.onActorHoverEnd(component);
|
|
2379
2434
|
}
|
|
2380
2435
|
}
|
|
2381
|
-
|
|
2382
|
-
const event = { component, hit,
|
|
2383
|
-
|
|
2436
|
+
fireActorClick(actor, component, hit, isDoubleClick) {
|
|
2437
|
+
const event = Object.assign({ actor, component, hit, handled: false }, this.prepareClickModifiers);
|
|
2438
|
+
if (isDoubleClick) {
|
|
2439
|
+
this._onActorDoubleClickDelegate.broadcast(event);
|
|
2440
|
+
if (!event.handled) {
|
|
2441
|
+
actor.onActorDoubleClick(component);
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
else {
|
|
2445
|
+
this._onActorClickDelegate.broadcast(event);
|
|
2446
|
+
if (!event.handled) {
|
|
2447
|
+
actor.onActorClick(component);
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2384
2450
|
}
|
|
2385
|
-
|
|
2386
|
-
|
|
2451
|
+
// ==================== Combined Events ====================
|
|
2452
|
+
fireClickEvents(component, hit, isDoubleClick) {
|
|
2453
|
+
// Component level
|
|
2454
|
+
this.fireComponentClick(component, hit, isDoubleClick);
|
|
2455
|
+
// Actor level
|
|
2456
|
+
const actor = component.parentActor;
|
|
2457
|
+
if (actor && actor.isClickEnabled) {
|
|
2458
|
+
this.fireActorClick(actor, component, hit, isDoubleClick);
|
|
2459
|
+
}
|
|
2387
2460
|
}
|
|
2388
|
-
|
|
2389
|
-
|
|
2461
|
+
// ==================== Utility ====================
|
|
2462
|
+
clearClickTimer() {
|
|
2463
|
+
if (this.leftClickTimer) {
|
|
2464
|
+
window.clearTimeout(this.leftClickTimer);
|
|
2465
|
+
this.leftClickTimer = null;
|
|
2466
|
+
}
|
|
2390
2467
|
}
|
|
2391
2468
|
addCorePointerListeners() {
|
|
2392
2469
|
const canvas = this.viewPort.canvas;
|
|
@@ -2422,17 +2499,14 @@ class Controller {
|
|
|
2422
2499
|
this._raycastVec2.set(x, y);
|
|
2423
2500
|
this.raycaster.setFromCamera(this._raycastVec2, this.camera);
|
|
2424
2501
|
const hits = this.raycaster.intersectObjects(this.world.scene.children, true);
|
|
2425
|
-
|
|
2502
|
+
const out = [];
|
|
2426
2503
|
for (const hit of hits) {
|
|
2427
2504
|
if (hit.object.userData["rayIgnored"])
|
|
2428
2505
|
continue;
|
|
2429
2506
|
const component = hit.object.userData["LYObject"];
|
|
2430
2507
|
if (!component)
|
|
2431
2508
|
continue;
|
|
2432
|
-
out.push({
|
|
2433
|
-
component: component,
|
|
2434
|
-
hit: hit
|
|
2435
|
-
});
|
|
2509
|
+
out.push({ component, hit });
|
|
2436
2510
|
}
|
|
2437
2511
|
return out;
|
|
2438
2512
|
}
|
|
@@ -2625,15 +2699,21 @@ class Actor extends BaseObject {
|
|
|
2625
2699
|
this.app.world.removeTickableActor(this);
|
|
2626
2700
|
}
|
|
2627
2701
|
}
|
|
2702
|
+
// Delegate getters
|
|
2703
|
+
get onHoverBeginDelegate() { return this._onHoverBeginDelegate; }
|
|
2704
|
+
get onHoverEndDelegate() { return this._onHoverEndDelegate; }
|
|
2705
|
+
get onClickDelegate() { return this._onClickDelegate; }
|
|
2706
|
+
get onDoubleClickDelegate() { return this._onDoubleClickDelegate; }
|
|
2628
2707
|
constructor(app, uuid) {
|
|
2629
2708
|
super(uuid);
|
|
2630
2709
|
this._name = "Actor";
|
|
2631
2710
|
this._rootComponent = null;
|
|
2632
2711
|
this._world = null;
|
|
2633
|
-
|
|
2634
|
-
this.
|
|
2635
|
-
this.
|
|
2636
|
-
this.
|
|
2712
|
+
// Actor 级别事件 Delegates
|
|
2713
|
+
this._onHoverBeginDelegate = new Delegate();
|
|
2714
|
+
this._onHoverEndDelegate = new Delegate();
|
|
2715
|
+
this._onClickDelegate = new Delegate();
|
|
2716
|
+
this._onDoubleClickDelegate = new Delegate();
|
|
2637
2717
|
this.app = app;
|
|
2638
2718
|
this.rootComponent = this.constructRootComponent();
|
|
2639
2719
|
this.rootComponent.parentActor = this;
|
|
@@ -2888,80 +2968,18 @@ class Actor extends BaseObject {
|
|
|
2888
2968
|
set isClickEnabled(bCanHorver) {
|
|
2889
2969
|
this.rootComponent.isClickEnabled = bCanHorver;
|
|
2890
2970
|
}
|
|
2891
|
-
//
|
|
2892
|
-
|
|
2893
|
-
this.
|
|
2971
|
+
// ==================== Actor Events ====================
|
|
2972
|
+
onActorHoverBegin(component) {
|
|
2973
|
+
this._onHoverBeginDelegate.broadcast(component);
|
|
2894
2974
|
}
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
if (index >= 0) {
|
|
2898
|
-
this.onHoverBeginEvent.splice(index, 1);
|
|
2899
|
-
}
|
|
2975
|
+
onActorHoverEnd(component) {
|
|
2976
|
+
this._onHoverEndDelegate.broadcast(component);
|
|
2900
2977
|
}
|
|
2901
|
-
|
|
2902
|
-
this.
|
|
2903
|
-
}
|
|
2904
|
-
onComponentHorveringBegin(component) {
|
|
2905
|
-
for (let i = 0; i < this.onHoverBeginEvent.length; ++i) {
|
|
2906
|
-
this.onHoverBeginEvent[i](component);
|
|
2907
|
-
}
|
|
2908
|
-
}
|
|
2909
|
-
// hovering end
|
|
2910
|
-
addHoveringEndEvent(newFunc) {
|
|
2911
|
-
this.onHoverEndEvent.push(newFunc);
|
|
2912
|
-
}
|
|
2913
|
-
removeHoveringEndEvent(target) {
|
|
2914
|
-
let index = this.onHoverEndEvent.indexOf(target);
|
|
2915
|
-
if (index >= 0) {
|
|
2916
|
-
this.onHoverEndEvent.splice(index, 1);
|
|
2917
|
-
}
|
|
2918
|
-
}
|
|
2919
|
-
clearHoveringEndEvent() {
|
|
2920
|
-
this.onHoverEndEvent = [];
|
|
2921
|
-
}
|
|
2922
|
-
onComponentHorveringEnd(component) {
|
|
2923
|
-
// console.log("onComponentHorveringEnd", this)
|
|
2924
|
-
for (let i = 0; i < this.onHoverEndEvent.length; ++i) {
|
|
2925
|
-
this.onHoverEndEvent[i](component);
|
|
2926
|
-
}
|
|
2927
|
-
}
|
|
2928
|
-
//click
|
|
2929
|
-
addClickEvent(newFunc) {
|
|
2930
|
-
this.onClickedEvent.push(newFunc);
|
|
2931
|
-
}
|
|
2932
|
-
removeClickEvent(target) {
|
|
2933
|
-
let index = this.onClickedEvent.indexOf(target);
|
|
2934
|
-
if (index >= 0) {
|
|
2935
|
-
this.onClickedEvent.splice(index, 1);
|
|
2936
|
-
}
|
|
2937
|
-
}
|
|
2938
|
-
clearClickEvent() {
|
|
2939
|
-
this.onClickedEvent = [];
|
|
2940
|
-
}
|
|
2941
|
-
onComponentClicked(component) {
|
|
2942
|
-
//console.log("onComponentClicked", this.Name, component)
|
|
2943
|
-
for (let i = 0; i < this.onClickedEvent.length; ++i) {
|
|
2944
|
-
this.onClickedEvent[i](component);
|
|
2945
|
-
}
|
|
2946
|
-
}
|
|
2947
|
-
// double click
|
|
2948
|
-
addDoubleClickEvent(newFunc) {
|
|
2949
|
-
this.onDoubleClickedEvent.push(newFunc);
|
|
2950
|
-
}
|
|
2951
|
-
removeDoubleClickEvent(target) {
|
|
2952
|
-
let index = this.onClickedEvent.indexOf(target);
|
|
2953
|
-
if (index >= 0) {
|
|
2954
|
-
this.onDoubleClickedEvent.splice(index, 1);
|
|
2955
|
-
}
|
|
2956
|
-
}
|
|
2957
|
-
onComponentDoubleClicked(component) {
|
|
2958
|
-
//console.log("onComponentClicked", this.Name, component)
|
|
2959
|
-
for (let i = 0; i < this.onDoubleClickedEvent.length; ++i) {
|
|
2960
|
-
this.onDoubleClickedEvent[i](component);
|
|
2961
|
-
}
|
|
2978
|
+
onActorClick(component) {
|
|
2979
|
+
this._onClickDelegate.broadcast(component);
|
|
2962
2980
|
}
|
|
2963
|
-
|
|
2964
|
-
this.
|
|
2981
|
+
onActorDoubleClick(component) {
|
|
2982
|
+
this._onDoubleClickDelegate.broadcast(component);
|
|
2965
2983
|
}
|
|
2966
2984
|
}
|
|
2967
2985
|
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { AttachmentRules } from "./lythreeframe/Defines";
|
|
|
10
10
|
export { Delegate } from "./lythreeframe/Delegate";
|
|
11
11
|
export { ThreeJsApp } from "./lythreeframe/ThreeJsApp";
|
|
12
12
|
export { Controller } from "./lythreeframe/Frame/Controller";
|
|
13
|
+
export type { HitResult, ComponentInteractionEvent, ComponentHoverEvent, ComponentPointerDownEvent, ActorInteractionEvent, ActorHoverEvent } from "./lythreeframe/Frame/Controller";
|
|
13
14
|
export { Viewport } from "./lythreeframe/Frame/Viewport";
|
|
14
15
|
export { World } from "./lythreeframe/Frame/World";
|
|
15
16
|
export type { CameraParam, PerspectiveCameraParam, OrthographicCameraParam } from './lythreeframe/Frame/Parameters/CameraParameter';
|