lythreeframe 1.2.62 → 1.2.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +160 -1
- package/dist/bundle.cjs.js +193 -188
- package/dist/bundle.esm.js +193 -188
- 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
|
}
|
|
@@ -708,38 +742,17 @@ class SceneComponent extends Component {
|
|
|
708
742
|
return this.bCanClick;
|
|
709
743
|
}
|
|
710
744
|
onHorveringBegin() {
|
|
711
|
-
|
|
712
|
-
return;
|
|
713
|
-
}
|
|
714
|
-
if (this.parentActor) {
|
|
715
|
-
let comp = this;
|
|
716
|
-
this.parentActor.onComponentHorveringBegin(comp);
|
|
717
|
-
}
|
|
745
|
+
this._onHoverBeginDelegate.broadcast();
|
|
718
746
|
}
|
|
719
747
|
onHorveringEnd() {
|
|
720
|
-
|
|
721
|
-
return;
|
|
722
|
-
}
|
|
723
|
-
if (this.parentActor) {
|
|
724
|
-
let comp = this;
|
|
725
|
-
this.parentActor.onComponentHorveringEnd(comp);
|
|
726
|
-
}
|
|
748
|
+
this._onHoverEndDelegate.broadcast();
|
|
727
749
|
}
|
|
728
750
|
/* click */
|
|
729
751
|
onClicked() {
|
|
730
|
-
|
|
731
|
-
return;
|
|
732
|
-
}
|
|
733
|
-
if (this.parentActor) {
|
|
734
|
-
let comp = this;
|
|
735
|
-
this.parentActor.onComponentClicked(comp);
|
|
736
|
-
}
|
|
752
|
+
this._onClickDelegate.broadcast();
|
|
737
753
|
}
|
|
738
754
|
onDoubleClicked() {
|
|
739
|
-
|
|
740
|
-
let comp = this;
|
|
741
|
-
this.parentActor.onComponentDoubleClicked(comp);
|
|
742
|
-
}
|
|
755
|
+
this._onDoubleClickDelegate.broadcast();
|
|
743
756
|
}
|
|
744
757
|
}
|
|
745
758
|
|
|
@@ -1299,30 +1312,6 @@ var AssetType;
|
|
|
1299
1312
|
AssetType[AssetType["undefined"] = -1] = "undefined";
|
|
1300
1313
|
})(AssetType || (AssetType = {}));
|
|
1301
1314
|
|
|
1302
|
-
class Delegate {
|
|
1303
|
-
constructor() {
|
|
1304
|
-
this.functions = [];
|
|
1305
|
-
}
|
|
1306
|
-
broadcast(...args) {
|
|
1307
|
-
this.functions.forEach((func) => func(...args));
|
|
1308
|
-
}
|
|
1309
|
-
add(func) {
|
|
1310
|
-
this.functions.push(func);
|
|
1311
|
-
}
|
|
1312
|
-
remove(func) {
|
|
1313
|
-
const index = this.functions.indexOf(func);
|
|
1314
|
-
if (index >= 0) {
|
|
1315
|
-
this.functions.splice(index, 1);
|
|
1316
|
-
}
|
|
1317
|
-
else {
|
|
1318
|
-
console.warn("function not found");
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
clear() {
|
|
1322
|
-
this.functions = [];
|
|
1323
|
-
}
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1326
1315
|
const DefaultPostProcessParam = {
|
|
1327
1316
|
steps: []
|
|
1328
1317
|
};
|
|
@@ -2189,34 +2178,51 @@ class Controller {
|
|
|
2189
2178
|
get world() { return this._app.world; }
|
|
2190
2179
|
get viewPort() { return this._app.viewport; }
|
|
2191
2180
|
get app() { return this._app; }
|
|
2192
|
-
get onClickNothingDelegate() { return this._onClickNothingDelegate; }
|
|
2193
|
-
get onComponentClickDelegate() { return this._onComponentClickDelegate; }
|
|
2194
|
-
get onComponentDoubleClickDelegate() { return this._onComponentDoubleClickDelegate; }
|
|
2195
|
-
get onComponentHoverBeginDelegate() { return this._onComponentHoverBeginDelegate; }
|
|
2196
|
-
get onComponentHoverEndDelegate() { return this._onComponentHoverEndDelegate; }
|
|
2197
|
-
get onComponentPointerDownDelegate() { return this._onComponentPointerDownDelegate; }
|
|
2198
2181
|
get pawn() {
|
|
2199
2182
|
if (!this._pawn)
|
|
2200
2183
|
throw Error("pawn is null");
|
|
2201
2184
|
return this._pawn;
|
|
2202
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; }
|
|
2203
2198
|
constructor(app) {
|
|
2204
2199
|
this._pawn = null;
|
|
2200
|
+
// Component level state
|
|
2201
|
+
this.hoveringComponent = null;
|
|
2202
|
+
// Actor level state
|
|
2203
|
+
this.hoveringActor = null;
|
|
2204
|
+
// Click state
|
|
2205
2205
|
this.prepareClickComponent = null;
|
|
2206
2206
|
this.prepareClickHit = null;
|
|
2207
2207
|
this.prepareClickModifiers = { ctrlKey: false, shiftKey: false, altKey: false };
|
|
2208
|
-
this.hoveringComponent = null;
|
|
2209
2208
|
this._pointButtonIsDown = new Set();
|
|
2210
|
-
|
|
2209
|
+
// Component level delegates
|
|
2211
2210
|
this._onComponentClickDelegate = new Delegate();
|
|
2212
2211
|
this._onComponentDoubleClickDelegate = new Delegate();
|
|
2213
2212
|
this._onComponentHoverBeginDelegate = new Delegate();
|
|
2214
2213
|
this._onComponentHoverEndDelegate = new Delegate();
|
|
2215
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();
|
|
2216
2222
|
// Pointer state
|
|
2217
2223
|
this.pointerPosition = new Vector2();
|
|
2218
2224
|
this.pointerLeftDownPosition = new Vector2();
|
|
2219
|
-
// Reusable objects
|
|
2225
|
+
// Reusable objects
|
|
2220
2226
|
this._tempVec2 = new Vector2();
|
|
2221
2227
|
this._raycastVec2 = new Vector2();
|
|
2222
2228
|
// Double click detection
|
|
@@ -2255,7 +2261,7 @@ class Controller {
|
|
|
2255
2261
|
}
|
|
2256
2262
|
destroy() {
|
|
2257
2263
|
this.clearClickTimer();
|
|
2258
|
-
this.
|
|
2264
|
+
this.clearHovering();
|
|
2259
2265
|
const canvas = this.viewPort.canvas;
|
|
2260
2266
|
if (canvas) {
|
|
2261
2267
|
canvas.removeEventListener("pointerenter", this.onPointerEnter);
|
|
@@ -2266,7 +2272,9 @@ class Controller {
|
|
|
2266
2272
|
this.pawn.destroy();
|
|
2267
2273
|
this._pawn = null;
|
|
2268
2274
|
}
|
|
2275
|
+
// ==================== Pointer Events ====================
|
|
2269
2276
|
onPointerMoveEvent(event) {
|
|
2277
|
+
var _a, _b;
|
|
2270
2278
|
const canvas = this.viewPort.canvas;
|
|
2271
2279
|
if (!canvas)
|
|
2272
2280
|
throw Error("canvas is null");
|
|
@@ -2275,47 +2283,48 @@ class Controller {
|
|
|
2275
2283
|
if (this._pointButtonIsDown.size > 0)
|
|
2276
2284
|
return;
|
|
2277
2285
|
const hits = this.getHitResultUnderCursor();
|
|
2278
|
-
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 检测
|
|
2279
2289
|
if (component !== this.hoveringComponent) {
|
|
2280
|
-
this.
|
|
2281
|
-
|
|
2282
|
-
|
|
2290
|
+
if (this.hoveringComponent) {
|
|
2291
|
+
this.fireComponentHoverEnd(this.hoveringComponent);
|
|
2292
|
+
}
|
|
2293
|
+
if (component && component.isHoverEnabled && hits) {
|
|
2294
|
+
this.fireComponentHoverBegin(component, hits.hit);
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
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);
|
|
2283
2304
|
}
|
|
2284
2305
|
}
|
|
2306
|
+
this.hoveringComponent = component;
|
|
2307
|
+
this.hoveringActor = actor;
|
|
2285
2308
|
}
|
|
2286
|
-
|
|
2309
|
+
clearHovering() {
|
|
2287
2310
|
if (this.hoveringComponent) {
|
|
2288
|
-
this.
|
|
2311
|
+
this.fireComponentHoverEnd(this.hoveringComponent);
|
|
2289
2312
|
}
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
const event = { component, hit, handled: false };
|
|
2293
|
-
if (isBegin) {
|
|
2294
|
-
this._onComponentHoverBeginDelegate.broadcast(event);
|
|
2295
|
-
if (!event.handled) {
|
|
2296
|
-
component.onHorveringBegin();
|
|
2297
|
-
}
|
|
2298
|
-
this.hoveringComponent = component;
|
|
2299
|
-
}
|
|
2300
|
-
else {
|
|
2301
|
-
this._onComponentHoverEndDelegate.broadcast(event);
|
|
2302
|
-
if (!event.handled) {
|
|
2303
|
-
component.onHorveringEnd();
|
|
2304
|
-
}
|
|
2305
|
-
this.hoveringComponent = null;
|
|
2313
|
+
if (this.hoveringActor && this.hoveringComponent) {
|
|
2314
|
+
this.fireActorHoverEnd(this.hoveringActor, this.hoveringComponent);
|
|
2306
2315
|
}
|
|
2316
|
+
this.hoveringComponent = null;
|
|
2317
|
+
this.hoveringActor = null;
|
|
2307
2318
|
}
|
|
2308
2319
|
onPointerUpEvent(event) {
|
|
2309
2320
|
this._pointButtonIsDown.delete(event.button);
|
|
2310
2321
|
if (event.button !== 0)
|
|
2311
2322
|
return;
|
|
2312
|
-
// Check if pointer moved too much (drag instead of click)
|
|
2313
2323
|
const pointerOffset = this._tempVec2.subVectors(this.pointerLeftDownPosition, this.pointerPosition).length();
|
|
2314
2324
|
if (pointerOffset > 0.005) {
|
|
2315
2325
|
this.clearClickTimer();
|
|
2316
2326
|
return;
|
|
2317
2327
|
}
|
|
2318
|
-
// 保存修饰键状态
|
|
2319
2328
|
this.prepareClickModifiers = {
|
|
2320
2329
|
ctrlKey: event.ctrlKey,
|
|
2321
2330
|
shiftKey: event.shiftKey,
|
|
@@ -2337,7 +2346,7 @@ class Controller {
|
|
|
2337
2346
|
this.leftClickTimer = window.setTimeout(() => {
|
|
2338
2347
|
this.leftClickTimer = null;
|
|
2339
2348
|
if (this.prepareClickComponent && this.prepareClickHit) {
|
|
2340
|
-
this.
|
|
2349
|
+
this.fireClickEvents(this.prepareClickComponent, this.prepareClickHit, false);
|
|
2341
2350
|
this.prepareClickComponent = null;
|
|
2342
2351
|
this.prepareClickHit = null;
|
|
2343
2352
|
}
|
|
@@ -2350,7 +2359,7 @@ class Controller {
|
|
|
2350
2359
|
handleDoubleClick() {
|
|
2351
2360
|
this.clearClickTimer();
|
|
2352
2361
|
if (this.prepareClickComponent && this.prepareClickHit) {
|
|
2353
|
-
this.
|
|
2362
|
+
this.fireClickEvents(this.prepareClickComponent, this.prepareClickHit, true);
|
|
2354
2363
|
}
|
|
2355
2364
|
else {
|
|
2356
2365
|
this._onClickNothingDelegate.broadcast();
|
|
@@ -2358,8 +2367,40 @@ class Controller {
|
|
|
2358
2367
|
this.prepareClickComponent = null;
|
|
2359
2368
|
this.prepareClickHit = null;
|
|
2360
2369
|
}
|
|
2361
|
-
|
|
2362
|
-
|
|
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);
|
|
2363
2404
|
if (isDoubleClick) {
|
|
2364
2405
|
this._onComponentDoubleClickDelegate.broadcast(event);
|
|
2365
2406
|
if (!event.handled) {
|
|
@@ -2373,33 +2414,56 @@ class Controller {
|
|
|
2373
2414
|
}
|
|
2374
2415
|
}
|
|
2375
2416
|
}
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
this.leftClickTimer = null;
|
|
2380
|
-
}
|
|
2417
|
+
firePointerDownEvent(component, hit, button) {
|
|
2418
|
+
const event = { component, hit, button, handled: false };
|
|
2419
|
+
this._onComponentPointerDownDelegate.broadcast(event);
|
|
2381
2420
|
}
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
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);
|
|
2386
2427
|
}
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
const
|
|
2390
|
-
|
|
2391
|
-
|
|
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);
|
|
2392
2434
|
}
|
|
2393
2435
|
}
|
|
2394
|
-
|
|
2395
|
-
const event = { component, hit,
|
|
2396
|
-
|
|
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
|
+
}
|
|
2397
2450
|
}
|
|
2398
|
-
|
|
2399
|
-
|
|
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
|
+
}
|
|
2400
2460
|
}
|
|
2401
|
-
|
|
2402
|
-
|
|
2461
|
+
// ==================== Utility ====================
|
|
2462
|
+
clearClickTimer() {
|
|
2463
|
+
if (this.leftClickTimer) {
|
|
2464
|
+
window.clearTimeout(this.leftClickTimer);
|
|
2465
|
+
this.leftClickTimer = null;
|
|
2466
|
+
}
|
|
2403
2467
|
}
|
|
2404
2468
|
addCorePointerListeners() {
|
|
2405
2469
|
const canvas = this.viewPort.canvas;
|
|
@@ -2435,17 +2499,14 @@ class Controller {
|
|
|
2435
2499
|
this._raycastVec2.set(x, y);
|
|
2436
2500
|
this.raycaster.setFromCamera(this._raycastVec2, this.camera);
|
|
2437
2501
|
const hits = this.raycaster.intersectObjects(this.world.scene.children, true);
|
|
2438
|
-
|
|
2502
|
+
const out = [];
|
|
2439
2503
|
for (const hit of hits) {
|
|
2440
2504
|
if (hit.object.userData["rayIgnored"])
|
|
2441
2505
|
continue;
|
|
2442
2506
|
const component = hit.object.userData["LYObject"];
|
|
2443
2507
|
if (!component)
|
|
2444
2508
|
continue;
|
|
2445
|
-
out.push({
|
|
2446
|
-
component: component,
|
|
2447
|
-
hit: hit
|
|
2448
|
-
});
|
|
2509
|
+
out.push({ component, hit });
|
|
2449
2510
|
}
|
|
2450
2511
|
return out;
|
|
2451
2512
|
}
|
|
@@ -2638,15 +2699,21 @@ class Actor extends BaseObject {
|
|
|
2638
2699
|
this.app.world.removeTickableActor(this);
|
|
2639
2700
|
}
|
|
2640
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; }
|
|
2641
2707
|
constructor(app, uuid) {
|
|
2642
2708
|
super(uuid);
|
|
2643
2709
|
this._name = "Actor";
|
|
2644
2710
|
this._rootComponent = null;
|
|
2645
2711
|
this._world = null;
|
|
2646
|
-
|
|
2647
|
-
this.
|
|
2648
|
-
this.
|
|
2649
|
-
this.
|
|
2712
|
+
// Actor 级别事件 Delegates
|
|
2713
|
+
this._onHoverBeginDelegate = new Delegate();
|
|
2714
|
+
this._onHoverEndDelegate = new Delegate();
|
|
2715
|
+
this._onClickDelegate = new Delegate();
|
|
2716
|
+
this._onDoubleClickDelegate = new Delegate();
|
|
2650
2717
|
this.app = app;
|
|
2651
2718
|
this.rootComponent = this.constructRootComponent();
|
|
2652
2719
|
this.rootComponent.parentActor = this;
|
|
@@ -2901,80 +2968,18 @@ class Actor extends BaseObject {
|
|
|
2901
2968
|
set isClickEnabled(bCanHorver) {
|
|
2902
2969
|
this.rootComponent.isClickEnabled = bCanHorver;
|
|
2903
2970
|
}
|
|
2904
|
-
//
|
|
2905
|
-
|
|
2906
|
-
this.
|
|
2907
|
-
}
|
|
2908
|
-
removeHoveringBeginEvent(target) {
|
|
2909
|
-
let index = this.onHoverBeginEvent.indexOf(target);
|
|
2910
|
-
if (index >= 0) {
|
|
2911
|
-
this.onHoverBeginEvent.splice(index, 1);
|
|
2912
|
-
}
|
|
2913
|
-
}
|
|
2914
|
-
clearHoveringBeginEvent() {
|
|
2915
|
-
this.onHoverBeginEvent = [];
|
|
2916
|
-
}
|
|
2917
|
-
onComponentHorveringBegin(component) {
|
|
2918
|
-
for (let i = 0; i < this.onHoverBeginEvent.length; ++i) {
|
|
2919
|
-
this.onHoverBeginEvent[i](component);
|
|
2920
|
-
}
|
|
2921
|
-
}
|
|
2922
|
-
// hovering end
|
|
2923
|
-
addHoveringEndEvent(newFunc) {
|
|
2924
|
-
this.onHoverEndEvent.push(newFunc);
|
|
2925
|
-
}
|
|
2926
|
-
removeHoveringEndEvent(target) {
|
|
2927
|
-
let index = this.onHoverEndEvent.indexOf(target);
|
|
2928
|
-
if (index >= 0) {
|
|
2929
|
-
this.onHoverEndEvent.splice(index, 1);
|
|
2930
|
-
}
|
|
2931
|
-
}
|
|
2932
|
-
clearHoveringEndEvent() {
|
|
2933
|
-
this.onHoverEndEvent = [];
|
|
2934
|
-
}
|
|
2935
|
-
onComponentHorveringEnd(component) {
|
|
2936
|
-
// console.log("onComponentHorveringEnd", this)
|
|
2937
|
-
for (let i = 0; i < this.onHoverEndEvent.length; ++i) {
|
|
2938
|
-
this.onHoverEndEvent[i](component);
|
|
2939
|
-
}
|
|
2940
|
-
}
|
|
2941
|
-
//click
|
|
2942
|
-
addClickEvent(newFunc) {
|
|
2943
|
-
this.onClickedEvent.push(newFunc);
|
|
2944
|
-
}
|
|
2945
|
-
removeClickEvent(target) {
|
|
2946
|
-
let index = this.onClickedEvent.indexOf(target);
|
|
2947
|
-
if (index >= 0) {
|
|
2948
|
-
this.onClickedEvent.splice(index, 1);
|
|
2949
|
-
}
|
|
2950
|
-
}
|
|
2951
|
-
clearClickEvent() {
|
|
2952
|
-
this.onClickedEvent = [];
|
|
2971
|
+
// ==================== Actor Events ====================
|
|
2972
|
+
onActorHoverBegin(component) {
|
|
2973
|
+
this._onHoverBeginDelegate.broadcast(component);
|
|
2953
2974
|
}
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
for (let i = 0; i < this.onClickedEvent.length; ++i) {
|
|
2957
|
-
this.onClickedEvent[i](component);
|
|
2958
|
-
}
|
|
2975
|
+
onActorHoverEnd(component) {
|
|
2976
|
+
this._onHoverEndDelegate.broadcast(component);
|
|
2959
2977
|
}
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
this.onDoubleClickedEvent.push(newFunc);
|
|
2963
|
-
}
|
|
2964
|
-
removeDoubleClickEvent(target) {
|
|
2965
|
-
let index = this.onClickedEvent.indexOf(target);
|
|
2966
|
-
if (index >= 0) {
|
|
2967
|
-
this.onDoubleClickedEvent.splice(index, 1);
|
|
2968
|
-
}
|
|
2969
|
-
}
|
|
2970
|
-
onComponentDoubleClicked(component) {
|
|
2971
|
-
//console.log("onComponentClicked", this.Name, component)
|
|
2972
|
-
for (let i = 0; i < this.onDoubleClickedEvent.length; ++i) {
|
|
2973
|
-
this.onDoubleClickedEvent[i](component);
|
|
2974
|
-
}
|
|
2978
|
+
onActorClick(component) {
|
|
2979
|
+
this._onClickDelegate.broadcast(component);
|
|
2975
2980
|
}
|
|
2976
|
-
|
|
2977
|
-
this.
|
|
2981
|
+
onActorDoubleClick(component) {
|
|
2982
|
+
this._onDoubleClickDelegate.broadcast(component);
|
|
2978
2983
|
}
|
|
2979
2984
|
}
|
|
2980
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';
|