@galacean/effects-core 1.5.2 → 1.6.0-beta.1
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/composition.d.ts +23 -1
- package/dist/index.js +74 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +74 -22
- package/dist/index.mjs.map +1 -1
- package/dist/plugins/interact/click-handler.d.ts +1 -1
- package/dist/plugins/interact/interact-vfx-item.d.ts +17 -5
- package/dist/scene.d.ts +4 -0
- package/package.json +1 -1
package/dist/composition.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as spec from '@galacean/effects-specification';
|
|
2
|
-
import type { Ray } from '@galacean/effects-math/es/core/
|
|
2
|
+
import type { Ray } from '@galacean/effects-math/es/core/ray';
|
|
3
|
+
import type { Vector3 } from '@galacean/effects-math/es/core/vector3';
|
|
3
4
|
import type { SceneType } from './asset-manager';
|
|
4
5
|
import type { Scene } from './scene';
|
|
5
6
|
import type { Disposable, LostHandler } from './utils';
|
|
@@ -18,6 +19,7 @@ export interface CompositionStatistic {
|
|
|
18
19
|
loadTime: number;
|
|
19
20
|
loadStart: number;
|
|
20
21
|
firstFrameTime: number;
|
|
22
|
+
precompileTime: number;
|
|
21
23
|
}
|
|
22
24
|
export interface MessageItem {
|
|
23
25
|
id: string;
|
|
@@ -25,6 +27,12 @@ export interface MessageItem {
|
|
|
25
27
|
phrase: number;
|
|
26
28
|
compositionId: number;
|
|
27
29
|
}
|
|
30
|
+
export interface CompItemClickedData {
|
|
31
|
+
name: string;
|
|
32
|
+
id: string;
|
|
33
|
+
hitPositions: Vector3[];
|
|
34
|
+
position: Vector3;
|
|
35
|
+
}
|
|
28
36
|
/**
|
|
29
37
|
*
|
|
30
38
|
*/
|
|
@@ -38,6 +46,7 @@ export interface CompositionProps {
|
|
|
38
46
|
baseRenderOrder?: number;
|
|
39
47
|
renderer: Renderer;
|
|
40
48
|
onPlayerPause?: (item: VFXItem<any>) => void;
|
|
49
|
+
onItemClicked?: (item: VFXItem<any>) => void;
|
|
41
50
|
onMessageItem?: (item: MessageItem) => void;
|
|
42
51
|
onEnd?: (composition: Composition) => void;
|
|
43
52
|
event?: EventSystem;
|
|
@@ -82,6 +91,11 @@ export declare class Composition implements Disposable, LostHandler {
|
|
|
82
91
|
* 是否播放完成后销毁 texture 对象
|
|
83
92
|
*/
|
|
84
93
|
keepResource: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* 合成内的元素否允许点击、拖拽交互
|
|
96
|
+
* @since 1.6.0
|
|
97
|
+
*/
|
|
98
|
+
interactive: boolean;
|
|
85
99
|
/**
|
|
86
100
|
* 合成结束行为是 spec.END_BEHAVIOR_PAUSE 或 spec.END_BEHAVIOR_PAUSE_AND_DESTROY 时执行的回调
|
|
87
101
|
* @internal
|
|
@@ -95,6 +109,14 @@ export declare class Composition implements Disposable, LostHandler {
|
|
|
95
109
|
* 合成中消息元素创建/销毁时触发的回调
|
|
96
110
|
*/
|
|
97
111
|
onMessageItem?: (item: MessageItem) => void;
|
|
112
|
+
/**
|
|
113
|
+
* 合成中元素点击时触发的回调
|
|
114
|
+
* 注意:此接口随时可能下线,请务使用!
|
|
115
|
+
* @since 1.6.0
|
|
116
|
+
* @ignore
|
|
117
|
+
* @deprecated
|
|
118
|
+
*/
|
|
119
|
+
onItemClicked?: (data: CompItemClickedData) => void;
|
|
98
120
|
/**
|
|
99
121
|
* 合成id
|
|
100
122
|
*/
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Description: Galacean Effects runtime core for the web
|
|
4
4
|
* Author: Ant Group CO., Ltd.
|
|
5
5
|
* Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
|
|
6
|
-
* Version: v1.
|
|
6
|
+
* Version: v1.6.0-beta.1
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
@@ -10073,10 +10073,23 @@ var EventSystem = /** @class */ (function () {
|
|
|
10073
10073
|
var getTouchEventValue = function (event, x, y, dx, dy) {
|
|
10074
10074
|
if (dx === void 0) { dx = 0; }
|
|
10075
10075
|
if (dy === void 0) { dy = 0; }
|
|
10076
|
-
var _a = _this.target, width = _a.width, height = _a.height;
|
|
10077
|
-
var ts = performance.now();
|
|
10078
10076
|
var vx = 0;
|
|
10079
10077
|
var vy = 0;
|
|
10078
|
+
var ts = performance.now();
|
|
10079
|
+
if (!_this.target) {
|
|
10080
|
+
logger.error('Trigger TouchEvent after EventSystem is disposed');
|
|
10081
|
+
return {
|
|
10082
|
+
x: x,
|
|
10083
|
+
y: y,
|
|
10084
|
+
vx: 0,
|
|
10085
|
+
vy: vy,
|
|
10086
|
+
dx: dx,
|
|
10087
|
+
dy: dy,
|
|
10088
|
+
ts: ts,
|
|
10089
|
+
width: 0, height: 0, origin: event,
|
|
10090
|
+
};
|
|
10091
|
+
}
|
|
10092
|
+
var _a = _this.target, width = _a.width, height = _a.height;
|
|
10080
10093
|
if (lastTouch) {
|
|
10081
10094
|
var dt = ts - lastTouch.ts;
|
|
10082
10095
|
vx = ((dx - lastTouch.dx) / dt) || 0;
|
|
@@ -13507,6 +13520,14 @@ var InteractVFXItem = /** @class */ (function (_super) {
|
|
|
13507
13520
|
function InteractVFXItem(props, composition) {
|
|
13508
13521
|
var _a;
|
|
13509
13522
|
var _this = _super.call(this, props, composition) || this;
|
|
13523
|
+
/**
|
|
13524
|
+
* 拖拽的惯性衰减系数,范围[0, 1], 越大惯性越强
|
|
13525
|
+
*/
|
|
13526
|
+
_this.downgrade = 0.95;
|
|
13527
|
+
/**
|
|
13528
|
+
* 拖拽的距离映射系数,越大越容易拖动
|
|
13529
|
+
*/
|
|
13530
|
+
_this.dragRatio = [1, 1];
|
|
13510
13531
|
_this.engine = (_a = _this.composition) === null || _a === void 0 ? void 0 : _a.getEngine();
|
|
13511
13532
|
return _this;
|
|
13512
13533
|
}
|
|
@@ -13517,8 +13538,23 @@ var InteractVFXItem = /** @class */ (function (_super) {
|
|
|
13517
13538
|
enumerable: false,
|
|
13518
13539
|
configurable: true
|
|
13519
13540
|
});
|
|
13541
|
+
Object.defineProperty(InteractVFXItem.prototype, "enable", {
|
|
13542
|
+
get: function () {
|
|
13543
|
+
return this.enabled;
|
|
13544
|
+
},
|
|
13545
|
+
set: function (enable) {
|
|
13546
|
+
this.enabled = enable;
|
|
13547
|
+
if (!enable) {
|
|
13548
|
+
// 立刻停止惯性滑动
|
|
13549
|
+
this.bouncingArg = null;
|
|
13550
|
+
}
|
|
13551
|
+
},
|
|
13552
|
+
enumerable: false,
|
|
13553
|
+
configurable: true
|
|
13554
|
+
});
|
|
13520
13555
|
InteractVFXItem.prototype.onConstructed = function (options) {
|
|
13521
13556
|
this.ui = options.content;
|
|
13557
|
+
this.enabled = true;
|
|
13522
13558
|
};
|
|
13523
13559
|
InteractVFXItem.prototype.onLifetimeBegin = function (composition) {
|
|
13524
13560
|
var _a, _b, _c;
|
|
@@ -13537,9 +13573,8 @@ var InteractVFXItem = /** @class */ (function (_super) {
|
|
|
13537
13573
|
if (!this.dragEvent || !this.bouncingArg) {
|
|
13538
13574
|
return;
|
|
13539
13575
|
}
|
|
13540
|
-
|
|
13541
|
-
this.bouncingArg.
|
|
13542
|
-
this.bouncingArg.vy *= downgrade;
|
|
13576
|
+
this.bouncingArg.vx *= this.downgrade;
|
|
13577
|
+
this.bouncingArg.vy *= this.downgrade;
|
|
13543
13578
|
this.bouncingArg.dy += this.bouncingArg.vy;
|
|
13544
13579
|
this.bouncingArg.dx += this.bouncingArg.vx;
|
|
13545
13580
|
if (shouldIgnoreBouncing(this.bouncingArg)) {
|
|
@@ -13575,7 +13610,7 @@ var InteractVFXItem = /** @class */ (function (_super) {
|
|
|
13575
13610
|
};
|
|
13576
13611
|
};
|
|
13577
13612
|
InteractVFXItem.prototype.getHitTestParams = function () {
|
|
13578
|
-
if (!this.clickable) {
|
|
13613
|
+
if (!this.clickable || !this.canInteract()) {
|
|
13579
13614
|
return;
|
|
13580
13615
|
}
|
|
13581
13616
|
var behavior = this.ui.options.behavior;
|
|
@@ -13612,6 +13647,9 @@ var InteractVFXItem = /** @class */ (function (_super) {
|
|
|
13612
13647
|
var handlerMap = {
|
|
13613
13648
|
touchstart: function (event) {
|
|
13614
13649
|
var _a;
|
|
13650
|
+
if (!_this.canInteract()) {
|
|
13651
|
+
return;
|
|
13652
|
+
}
|
|
13615
13653
|
_this.dragEvent = null;
|
|
13616
13654
|
_this.bouncingArg = null;
|
|
13617
13655
|
var camera = (_a = _this.composition) === null || _a === void 0 ? void 0 : _a.camera;
|
|
@@ -13629,6 +13667,9 @@ var InteractVFXItem = /** @class */ (function (_super) {
|
|
|
13629
13667
|
_this.bouncingArg = event;
|
|
13630
13668
|
},
|
|
13631
13669
|
touchend: function (event) {
|
|
13670
|
+
if (!_this.canInteract()) {
|
|
13671
|
+
return;
|
|
13672
|
+
}
|
|
13632
13673
|
var bouncingArg = _this.bouncingArg;
|
|
13633
13674
|
if (!shouldIgnoreBouncing(bouncingArg, 3) && bouncingArg) {
|
|
13634
13675
|
var speed = 5;
|
|
@@ -13654,7 +13695,7 @@ var InteractVFXItem = /** @class */ (function (_super) {
|
|
|
13654
13695
|
};
|
|
13655
13696
|
InteractVFXItem.prototype.handleDragMove = function (evt, event) {
|
|
13656
13697
|
var _a, _b;
|
|
13657
|
-
if (!(evt
|
|
13698
|
+
if (!(evt === null || evt === void 0 ? void 0 : evt.cameraParam) || !this.canInteract() || !this.composition) {
|
|
13658
13699
|
return;
|
|
13659
13700
|
}
|
|
13660
13701
|
var options = this.ui.options;
|
|
@@ -13665,8 +13706,8 @@ var InteractVFXItem = /** @class */ (function (_super) {
|
|
|
13665
13706
|
var sp = Math.tan(fov * Math.PI / 180 / 2) * Math.abs(depth);
|
|
13666
13707
|
var height = dy * sp;
|
|
13667
13708
|
var width = dx * sp;
|
|
13668
|
-
var nx = position[0] - width;
|
|
13669
|
-
var ny = position[1] - height;
|
|
13709
|
+
var nx = position[0] - this.dragRatio[0] * width;
|
|
13710
|
+
var ny = position[1] - this.dragRatio[1] * height;
|
|
13670
13711
|
if (options.dxRange) {
|
|
13671
13712
|
var _d = __read$3(options.dxRange, 2), min = _d[0], max = _d[1];
|
|
13672
13713
|
nx = clamp$1(nx, min, max);
|
|
@@ -13683,6 +13724,10 @@ var InteractVFXItem = /** @class */ (function (_super) {
|
|
|
13683
13724
|
}
|
|
13684
13725
|
this.composition.camera.position = new Vector3(nx, ny, depth);
|
|
13685
13726
|
};
|
|
13727
|
+
InteractVFXItem.prototype.canInteract = function () {
|
|
13728
|
+
var _a;
|
|
13729
|
+
return Boolean((_a = this.composition) === null || _a === void 0 ? void 0 : _a.interactive) && this.enabled;
|
|
13730
|
+
};
|
|
13686
13731
|
return InteractVFXItem;
|
|
13687
13732
|
}(VFXItem));
|
|
13688
13733
|
function shouldIgnoreBouncing(arg, mul) {
|
|
@@ -23988,27 +24033,28 @@ var AssetManager = /** @class */ (function () {
|
|
|
23988
24033
|
AssetManager.prototype.loadScene = function (url, renderer, options) {
|
|
23989
24034
|
var _a, _b, _c;
|
|
23990
24035
|
return __awaiter(this, void 0, void 0, function () {
|
|
23991
|
-
var rawJSON, assetUrl, startTime,
|
|
24036
|
+
var rawJSON, assetUrl, startTime, timeInfoMessages, gpuInstance, asyncShaderCompile, compressedTexture, timeInfos, loadTimer, cancelLoading, waitPromise, hookTimeInfo, loadResourcePromise;
|
|
23992
24037
|
var _this = this;
|
|
23993
24038
|
return __generator(this, function (_d) {
|
|
23994
24039
|
assetUrl = isString(url) ? url : this.id;
|
|
23995
24040
|
startTime = performance.now();
|
|
23996
|
-
|
|
24041
|
+
timeInfoMessages = [];
|
|
23997
24042
|
gpuInstance = renderer === null || renderer === void 0 ? void 0 : renderer.engine.gpuCapability;
|
|
23998
24043
|
asyncShaderCompile = (_b = (_a = gpuInstance === null || gpuInstance === void 0 ? void 0 : gpuInstance.detail) === null || _a === void 0 ? void 0 : _a.asyncShaderCompile) !== null && _b !== void 0 ? _b : false;
|
|
23999
24044
|
compressedTexture = (_c = gpuInstance === null || gpuInstance === void 0 ? void 0 : gpuInstance.detail.compressedTexture) !== null && _c !== void 0 ? _c : 0;
|
|
24045
|
+
timeInfos = {};
|
|
24000
24046
|
cancelLoading = false;
|
|
24001
24047
|
waitPromise = new Promise(function (resolve, reject) {
|
|
24002
24048
|
loadTimer = window.setTimeout(function () {
|
|
24003
24049
|
cancelLoading = true;
|
|
24004
24050
|
_this.removeTimer(loadTimer);
|
|
24005
24051
|
var totalTime = performance.now() - startTime;
|
|
24006
|
-
reject("Load time out: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(
|
|
24052
|
+
reject("Load time out: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(timeInfoMessages.join(' '), ", url: ").concat(assetUrl));
|
|
24007
24053
|
}, _this.timeout * 1000);
|
|
24008
24054
|
_this.timers.push(loadTimer);
|
|
24009
24055
|
});
|
|
24010
24056
|
hookTimeInfo = function (label, func) { return __awaiter(_this, void 0, void 0, function () {
|
|
24011
|
-
var st, result, e_1;
|
|
24057
|
+
var st, result, time, e_1;
|
|
24012
24058
|
return __generator(this, function (_a) {
|
|
24013
24059
|
switch (_a.label) {
|
|
24014
24060
|
case 0:
|
|
@@ -24020,7 +24066,9 @@ var AssetManager = /** @class */ (function () {
|
|
|
24020
24066
|
return [4 /*yield*/, func()];
|
|
24021
24067
|
case 2:
|
|
24022
24068
|
result = _a.sent();
|
|
24023
|
-
|
|
24069
|
+
time = performance.now() - st;
|
|
24070
|
+
timeInfoMessages.push("[".concat(label, ": ").concat(time.toFixed(2), "]"));
|
|
24071
|
+
timeInfos[label] = time;
|
|
24024
24072
|
return [2 /*return*/, result];
|
|
24025
24073
|
case 3:
|
|
24026
24074
|
e_1 = _a.sent();
|
|
@@ -24079,7 +24127,7 @@ var AssetManager = /** @class */ (function () {
|
|
|
24079
24127
|
return [4 /*yield*/, Promise.all([
|
|
24080
24128
|
hookTimeInfo('processBins', function () { return _this.processBins(bins_1); }),
|
|
24081
24129
|
hookTimeInfo('processImages', function () { return _this.processImages(images_2, usedImages_1, compressedTexture); }),
|
|
24082
|
-
hookTimeInfo("".concat(asyncShaderCompile ? 'async' : 'sync', "
|
|
24130
|
+
hookTimeInfo("".concat(asyncShaderCompile ? 'async' : 'sync', "Compile"), function () { return _this.precompile(compositions_1, pluginSystem_1, renderer, options); }),
|
|
24083
24131
|
])];
|
|
24084
24132
|
case 8:
|
|
24085
24133
|
_d = __read$3.apply(void 0, [_e.sent(), 2]), loadedBins_1 = _d[0], loadedImages_1 = _d[1];
|
|
@@ -24091,6 +24139,7 @@ var AssetManager = /** @class */ (function () {
|
|
|
24091
24139
|
loadedTextures = _e.sent();
|
|
24092
24140
|
jsonScene_1.compositions = this.updateSceneData(jsonScene_1.compositions);
|
|
24093
24141
|
scene = {
|
|
24142
|
+
timeInfos: timeInfos,
|
|
24094
24143
|
url: url,
|
|
24095
24144
|
renderLevel: this.options.renderLevel,
|
|
24096
24145
|
storage: {},
|
|
@@ -24109,11 +24158,13 @@ var AssetManager = /** @class */ (function () {
|
|
|
24109
24158
|
_e.label = 12;
|
|
24110
24159
|
case 12:
|
|
24111
24160
|
totalTime = performance.now() - startTime;
|
|
24112
|
-
logger.info("Load asset: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(
|
|
24161
|
+
logger.info("Load asset: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(timeInfoMessages.join(' '), ", url: ").concat(assetUrl));
|
|
24113
24162
|
window.clearTimeout(loadTimer);
|
|
24114
24163
|
this.removeTimer(loadTimer);
|
|
24115
24164
|
scene.totalTime = totalTime;
|
|
24116
24165
|
scene.startTime = startTime;
|
|
24166
|
+
// 各部分分段时长
|
|
24167
|
+
scene.timeInfos = timeInfos;
|
|
24117
24168
|
return [2 /*return*/, scene];
|
|
24118
24169
|
}
|
|
24119
24170
|
});
|
|
@@ -24961,7 +25012,7 @@ var Composition = /** @class */ (function () {
|
|
|
24961
25012
|
* @param props - composition 的创建参数
|
|
24962
25013
|
*/
|
|
24963
25014
|
function Composition(props, scene) {
|
|
24964
|
-
var _a;
|
|
25015
|
+
var _a, _b;
|
|
24965
25016
|
/**
|
|
24966
25017
|
* 动画播放速度
|
|
24967
25018
|
*/
|
|
@@ -24990,7 +25041,7 @@ var Composition = /** @class */ (function () {
|
|
|
24990
25041
|
this.paused = false;
|
|
24991
25042
|
this.lastVideoUpdateTime = 0;
|
|
24992
25043
|
this.postLoaders = [];
|
|
24993
|
-
var
|
|
25044
|
+
var _c = props.reusable, reusable = _c === void 0 ? false : _c, _d = props.speed, speed = _d === void 0 ? 1 : _d, _e = props.baseRenderOrder, baseRenderOrder = _e === void 0 ? 0 : _e, renderer = props.renderer, onPlayerPause = props.onPlayerPause, onMessageItem = props.onMessageItem, onEnd = props.onEnd, event = props.event, width = props.width, height = props.height;
|
|
24994
25045
|
this.compositionSourceManager = new CompositionSourceManager(scene, renderer.engine);
|
|
24995
25046
|
scene.jsonScene.imgUsage = undefined;
|
|
24996
25047
|
if (reusable) {
|
|
@@ -24998,7 +25049,7 @@ var Composition = /** @class */ (function () {
|
|
|
24998
25049
|
scene.textures = undefined;
|
|
24999
25050
|
scene.consumed = true;
|
|
25000
25051
|
}
|
|
25001
|
-
var
|
|
25052
|
+
var _f = this.compositionSourceManager, sourceContent = _f.sourceContent, pluginSystem = _f.pluginSystem, imgUsage = _f.imgUsage, totalTime = _f.totalTime, renderLevel = _f.renderLevel, refCompositionProps = _f.refCompositionProps;
|
|
25002
25053
|
assertExist(sourceContent);
|
|
25003
25054
|
this.refCompositionProps = refCompositionProps;
|
|
25004
25055
|
var vfxItem = new CompVFXItem(sourceContent, this);
|
|
@@ -25015,7 +25066,7 @@ var Composition = /** @class */ (function () {
|
|
|
25015
25066
|
this.renderer = renderer;
|
|
25016
25067
|
this.texInfo = imageUsage !== null && imageUsage !== void 0 ? imageUsage : {};
|
|
25017
25068
|
this.event = event;
|
|
25018
|
-
this.statistic = { loadTime: totalTime !== null && totalTime !== void 0 ? totalTime : 0, loadStart: (_a = scene.startTime) !== null && _a !== void 0 ? _a : 0, firstFrameTime: 0 };
|
|
25069
|
+
this.statistic = { loadTime: totalTime !== null && totalTime !== void 0 ? totalTime : 0, loadStart: (_a = scene.startTime) !== null && _a !== void 0 ? _a : 0, firstFrameTime: 0, precompileTime: (_b = scene.timeInfos['asyncCompile']) !== null && _b !== void 0 ? _b : scene.timeInfos['syncCompile'] };
|
|
25019
25070
|
this.reusable = reusable;
|
|
25020
25071
|
this.speed = speed;
|
|
25021
25072
|
this.renderLevel = renderLevel;
|
|
@@ -25027,6 +25078,7 @@ var Composition = /** @class */ (function () {
|
|
|
25027
25078
|
this.camera = new Camera(this.name, __assign$1(__assign$1({}, sourceContent === null || sourceContent === void 0 ? void 0 : sourceContent.camera), { aspect: width / height }));
|
|
25028
25079
|
this.url = scene.url;
|
|
25029
25080
|
this.assigned = true;
|
|
25081
|
+
this.interactive = true;
|
|
25030
25082
|
this.onPlayerPause = onPlayerPause;
|
|
25031
25083
|
this.onMessageItem = onMessageItem;
|
|
25032
25084
|
this.onEnd = onEnd;
|
|
@@ -25406,7 +25458,7 @@ var Composition = /** @class */ (function () {
|
|
|
25406
25458
|
* @param options - 最大求交数和求交时的回调
|
|
25407
25459
|
*/
|
|
25408
25460
|
Composition.prototype.hitTest = function (x, y, force, options) {
|
|
25409
|
-
if (this.isDestroyed) {
|
|
25461
|
+
if (this.isDestroyed || !this.interactive) {
|
|
25410
25462
|
return [];
|
|
25411
25463
|
}
|
|
25412
25464
|
var regions = [];
|