@galacean/effects-core 1.6.0-beta.0 → 1.6.0-beta.2
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 +1 -0
- package/dist/index.js +82 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +82 -47
- package/dist/index.mjs.map +1 -1
- package/dist/plugins/interact/interact-vfx-item.d.ts +13 -1
- package/dist/plugins/text/text-layout.d.ts +1 -1
- package/dist/scene.d.ts +4 -0
- package/package.json +1 -1
package/dist/composition.d.ts
CHANGED
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.0-beta.
|
|
6
|
+
* Version: v1.6.0-beta.2
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
@@ -13520,6 +13520,14 @@ var InteractVFXItem = /** @class */ (function (_super) {
|
|
|
13520
13520
|
function InteractVFXItem(props, composition) {
|
|
13521
13521
|
var _a;
|
|
13522
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];
|
|
13523
13531
|
_this.engine = (_a = _this.composition) === null || _a === void 0 ? void 0 : _a.getEngine();
|
|
13524
13532
|
return _this;
|
|
13525
13533
|
}
|
|
@@ -13530,8 +13538,23 @@ var InteractVFXItem = /** @class */ (function (_super) {
|
|
|
13530
13538
|
enumerable: false,
|
|
13531
13539
|
configurable: true
|
|
13532
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
|
+
});
|
|
13533
13555
|
InteractVFXItem.prototype.onConstructed = function (options) {
|
|
13534
13556
|
this.ui = options.content;
|
|
13557
|
+
this.enabled = true;
|
|
13535
13558
|
};
|
|
13536
13559
|
InteractVFXItem.prototype.onLifetimeBegin = function (composition) {
|
|
13537
13560
|
var _a, _b, _c;
|
|
@@ -13550,9 +13573,8 @@ var InteractVFXItem = /** @class */ (function (_super) {
|
|
|
13550
13573
|
if (!this.dragEvent || !this.bouncingArg) {
|
|
13551
13574
|
return;
|
|
13552
13575
|
}
|
|
13553
|
-
|
|
13554
|
-
this.bouncingArg.
|
|
13555
|
-
this.bouncingArg.vy *= downgrade;
|
|
13576
|
+
this.bouncingArg.vx *= this.downgrade;
|
|
13577
|
+
this.bouncingArg.vy *= this.downgrade;
|
|
13556
13578
|
this.bouncingArg.dy += this.bouncingArg.vy;
|
|
13557
13579
|
this.bouncingArg.dx += this.bouncingArg.vx;
|
|
13558
13580
|
if (shouldIgnoreBouncing(this.bouncingArg)) {
|
|
@@ -13588,7 +13610,7 @@ var InteractVFXItem = /** @class */ (function (_super) {
|
|
|
13588
13610
|
};
|
|
13589
13611
|
};
|
|
13590
13612
|
InteractVFXItem.prototype.getHitTestParams = function () {
|
|
13591
|
-
if (!this.clickable) {
|
|
13613
|
+
if (!this.clickable || !this.canInteract()) {
|
|
13592
13614
|
return;
|
|
13593
13615
|
}
|
|
13594
13616
|
var behavior = this.ui.options.behavior;
|
|
@@ -13624,13 +13646,13 @@ var InteractVFXItem = /** @class */ (function (_super) {
|
|
|
13624
13646
|
var dragEvent;
|
|
13625
13647
|
var handlerMap = {
|
|
13626
13648
|
touchstart: function (event) {
|
|
13627
|
-
var _a
|
|
13628
|
-
if (!
|
|
13649
|
+
var _a;
|
|
13650
|
+
if (!_this.canInteract()) {
|
|
13629
13651
|
return;
|
|
13630
13652
|
}
|
|
13631
13653
|
_this.dragEvent = null;
|
|
13632
13654
|
_this.bouncingArg = null;
|
|
13633
|
-
var camera = (
|
|
13655
|
+
var camera = (_a = _this.composition) === null || _a === void 0 ? void 0 : _a.camera;
|
|
13634
13656
|
dragEvent = {
|
|
13635
13657
|
x: event.x,
|
|
13636
13658
|
y: event.y,
|
|
@@ -13645,8 +13667,7 @@ var InteractVFXItem = /** @class */ (function (_super) {
|
|
|
13645
13667
|
_this.bouncingArg = event;
|
|
13646
13668
|
},
|
|
13647
13669
|
touchend: function (event) {
|
|
13648
|
-
|
|
13649
|
-
if (!((_a = _this.composition) === null || _a === void 0 ? void 0 : _a.interactive)) {
|
|
13670
|
+
if (!_this.canInteract()) {
|
|
13650
13671
|
return;
|
|
13651
13672
|
}
|
|
13652
13673
|
var bouncingArg = _this.bouncingArg;
|
|
@@ -13673,36 +13694,40 @@ var InteractVFXItem = /** @class */ (function (_super) {
|
|
|
13673
13694
|
// OVERRIDE
|
|
13674
13695
|
};
|
|
13675
13696
|
InteractVFXItem.prototype.handleDragMove = function (evt, event) {
|
|
13676
|
-
var _a, _b
|
|
13677
|
-
if (!(evt
|
|
13697
|
+
var _a, _b;
|
|
13698
|
+
if (!(evt === null || evt === void 0 ? void 0 : evt.cameraParam) || !this.canInteract() || !this.composition) {
|
|
13678
13699
|
return;
|
|
13679
13700
|
}
|
|
13680
13701
|
var options = this.ui.options;
|
|
13681
|
-
var
|
|
13702
|
+
var _c = evt.cameraParam, position = _c.position, fov = _c.fov;
|
|
13682
13703
|
var dy = event.dy;
|
|
13683
13704
|
var dx = event.dx * event.width / event.height;
|
|
13684
13705
|
var depth = position[2];
|
|
13685
13706
|
var sp = Math.tan(fov * Math.PI / 180 / 2) * Math.abs(depth);
|
|
13686
13707
|
var height = dy * sp;
|
|
13687
13708
|
var width = dx * sp;
|
|
13688
|
-
var nx = position[0] - width;
|
|
13689
|
-
var ny = position[1] - height;
|
|
13709
|
+
var nx = position[0] - this.dragRatio[0] * width;
|
|
13710
|
+
var ny = position[1] - this.dragRatio[1] * height;
|
|
13690
13711
|
if (options.dxRange) {
|
|
13691
|
-
var
|
|
13712
|
+
var _d = __read$3(options.dxRange, 2), min = _d[0], max = _d[1];
|
|
13692
13713
|
nx = clamp$1(nx, min, max);
|
|
13693
13714
|
if (nx !== min && nx !== max && min !== max) {
|
|
13694
|
-
(
|
|
13715
|
+
(_a = event.origin) === null || _a === void 0 ? void 0 : _a.preventDefault();
|
|
13695
13716
|
}
|
|
13696
13717
|
}
|
|
13697
13718
|
if (options.dyRange) {
|
|
13698
|
-
var
|
|
13719
|
+
var _e = __read$3(options.dyRange, 2), min = _e[0], max = _e[1];
|
|
13699
13720
|
ny = clamp$1(ny, min, max);
|
|
13700
13721
|
if (ny !== min && ny !== max && min !== max) {
|
|
13701
|
-
(
|
|
13722
|
+
(_b = event.origin) === null || _b === void 0 ? void 0 : _b.preventDefault();
|
|
13702
13723
|
}
|
|
13703
13724
|
}
|
|
13704
13725
|
this.composition.camera.position = new Vector3(nx, ny, depth);
|
|
13705
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
|
+
};
|
|
13706
13731
|
return InteractVFXItem;
|
|
13707
13732
|
}(VFXItem));
|
|
13708
13733
|
function shouldIgnoreBouncing(arg, mul) {
|
|
@@ -20259,32 +20284,37 @@ var TextLayout = /** @class */ (function () {
|
|
|
20259
20284
|
this.textAlign = textAlign;
|
|
20260
20285
|
this.lineHeight = lineHeight;
|
|
20261
20286
|
}
|
|
20262
|
-
TextLayout.prototype.getOffsetY = function (style) {
|
|
20263
|
-
var
|
|
20264
|
-
var
|
|
20287
|
+
TextLayout.prototype.getOffsetY = function (style, lineCount, lineHeight) {
|
|
20288
|
+
var offsetResult = 0;
|
|
20289
|
+
var fontSize = style.fontSize, outlineWidth = style.outlineWidth, fontScale = style.fontScale;
|
|
20290
|
+
// 计算基础偏移量
|
|
20291
|
+
var baseOffset = (fontSize + outlineWidth) * fontScale;
|
|
20292
|
+
// /3 计算Y轴偏移量,以匹配编辑器行为
|
|
20293
|
+
var offsetY = (lineHeight - fontSize) / 3;
|
|
20294
|
+
var commonCalculation = lineHeight * (lineCount - 1);
|
|
20265
20295
|
switch (this.textBaseline) {
|
|
20266
|
-
case
|
|
20267
|
-
|
|
20296
|
+
case TextBaseline$1.top:
|
|
20297
|
+
offsetResult = baseOffset + offsetY;
|
|
20268
20298
|
break;
|
|
20269
|
-
case 1:
|
|
20270
|
-
|
|
20299
|
+
case TextBaseline$1.middle:
|
|
20300
|
+
offsetResult = (this.height * fontScale - commonCalculation + baseOffset) / 2;
|
|
20271
20301
|
break;
|
|
20272
|
-
case
|
|
20273
|
-
|
|
20302
|
+
case TextBaseline$1.bottom:
|
|
20303
|
+
offsetResult = (this.height * fontScale - commonCalculation) - offsetY;
|
|
20274
20304
|
break;
|
|
20275
20305
|
}
|
|
20276
|
-
return
|
|
20306
|
+
return offsetResult;
|
|
20277
20307
|
};
|
|
20278
20308
|
TextLayout.prototype.getOffsetX = function (style, maxWidth) {
|
|
20279
20309
|
var offsetX = 0;
|
|
20280
20310
|
switch (this.textAlign) {
|
|
20281
|
-
case
|
|
20311
|
+
case TextAlignment$1.left:
|
|
20282
20312
|
offsetX = style.outlineWidth * style.fontScale;
|
|
20283
20313
|
break;
|
|
20284
|
-
case 1:
|
|
20314
|
+
case TextAlignment$1.middle:
|
|
20285
20315
|
offsetX = (this.width * style.fontScale - maxWidth) / 2;
|
|
20286
20316
|
break;
|
|
20287
|
-
case
|
|
20317
|
+
case TextAlignment$1.right:
|
|
20288
20318
|
offsetX = (this.width * style.fontScale - maxWidth);
|
|
20289
20319
|
break;
|
|
20290
20320
|
}
|
|
@@ -20518,7 +20548,7 @@ var TextItem = /** @class */ (function (_super) {
|
|
|
20518
20548
|
var fontScale = style.fontScale;
|
|
20519
20549
|
var width = (layout.width + style.fontOffset) * fontScale;
|
|
20520
20550
|
var height = layout.height * fontScale;
|
|
20521
|
-
|
|
20551
|
+
style.fontSize * fontScale;
|
|
20522
20552
|
var lineHeight = layout.lineHeight * fontScale;
|
|
20523
20553
|
this.char = (this.text || '').split('');
|
|
20524
20554
|
this.canvas.width = width;
|
|
@@ -20538,10 +20568,9 @@ var TextItem = /** @class */ (function (_super) {
|
|
|
20538
20568
|
// 文本颜色
|
|
20539
20569
|
context.fillStyle = "rgba(".concat(style.textColor[0], ", ").concat(style.textColor[1], ", ").concat(style.textColor[2], ", ").concat(style.textColor[3], ")");
|
|
20540
20570
|
var charsInfo = [];
|
|
20541
|
-
// /3 为了和编辑器行为保持一致
|
|
20542
|
-
var offsetY = (lineHeight - fontSize) / 3;
|
|
20543
20571
|
var x = 0;
|
|
20544
|
-
var
|
|
20572
|
+
var lineCount = this.text.split('\n').length;
|
|
20573
|
+
var y = layout.getOffsetY(style, lineCount, lineHeight);
|
|
20545
20574
|
var charsArray = [];
|
|
20546
20575
|
var charOffsetX = [];
|
|
20547
20576
|
for (var i = 0; i < this.char.length; i++) {
|
|
@@ -24008,27 +24037,28 @@ var AssetManager = /** @class */ (function () {
|
|
|
24008
24037
|
AssetManager.prototype.loadScene = function (url, renderer, options) {
|
|
24009
24038
|
var _a, _b, _c;
|
|
24010
24039
|
return __awaiter(this, void 0, void 0, function () {
|
|
24011
|
-
var rawJSON, assetUrl, startTime,
|
|
24040
|
+
var rawJSON, assetUrl, startTime, timeInfoMessages, gpuInstance, asyncShaderCompile, compressedTexture, timeInfos, loadTimer, cancelLoading, waitPromise, hookTimeInfo, loadResourcePromise;
|
|
24012
24041
|
var _this = this;
|
|
24013
24042
|
return __generator(this, function (_d) {
|
|
24014
24043
|
assetUrl = isString(url) ? url : this.id;
|
|
24015
24044
|
startTime = performance.now();
|
|
24016
|
-
|
|
24045
|
+
timeInfoMessages = [];
|
|
24017
24046
|
gpuInstance = renderer === null || renderer === void 0 ? void 0 : renderer.engine.gpuCapability;
|
|
24018
24047
|
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;
|
|
24019
24048
|
compressedTexture = (_c = gpuInstance === null || gpuInstance === void 0 ? void 0 : gpuInstance.detail.compressedTexture) !== null && _c !== void 0 ? _c : 0;
|
|
24049
|
+
timeInfos = {};
|
|
24020
24050
|
cancelLoading = false;
|
|
24021
24051
|
waitPromise = new Promise(function (resolve, reject) {
|
|
24022
24052
|
loadTimer = window.setTimeout(function () {
|
|
24023
24053
|
cancelLoading = true;
|
|
24024
24054
|
_this.removeTimer(loadTimer);
|
|
24025
24055
|
var totalTime = performance.now() - startTime;
|
|
24026
|
-
reject("Load time out: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(
|
|
24056
|
+
reject("Load time out: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(timeInfoMessages.join(' '), ", url: ").concat(assetUrl));
|
|
24027
24057
|
}, _this.timeout * 1000);
|
|
24028
24058
|
_this.timers.push(loadTimer);
|
|
24029
24059
|
});
|
|
24030
24060
|
hookTimeInfo = function (label, func) { return __awaiter(_this, void 0, void 0, function () {
|
|
24031
|
-
var st, result, e_1;
|
|
24061
|
+
var st, result, time, e_1;
|
|
24032
24062
|
return __generator(this, function (_a) {
|
|
24033
24063
|
switch (_a.label) {
|
|
24034
24064
|
case 0:
|
|
@@ -24040,7 +24070,9 @@ var AssetManager = /** @class */ (function () {
|
|
|
24040
24070
|
return [4 /*yield*/, func()];
|
|
24041
24071
|
case 2:
|
|
24042
24072
|
result = _a.sent();
|
|
24043
|
-
|
|
24073
|
+
time = performance.now() - st;
|
|
24074
|
+
timeInfoMessages.push("[".concat(label, ": ").concat(time.toFixed(2), "]"));
|
|
24075
|
+
timeInfos[label] = time;
|
|
24044
24076
|
return [2 /*return*/, result];
|
|
24045
24077
|
case 3:
|
|
24046
24078
|
e_1 = _a.sent();
|
|
@@ -24099,7 +24131,7 @@ var AssetManager = /** @class */ (function () {
|
|
|
24099
24131
|
return [4 /*yield*/, Promise.all([
|
|
24100
24132
|
hookTimeInfo('processBins', function () { return _this.processBins(bins_1); }),
|
|
24101
24133
|
hookTimeInfo('processImages', function () { return _this.processImages(images_2, usedImages_1, compressedTexture); }),
|
|
24102
|
-
hookTimeInfo("".concat(asyncShaderCompile ? 'async' : 'sync', "
|
|
24134
|
+
hookTimeInfo("".concat(asyncShaderCompile ? 'async' : 'sync', "Compile"), function () { return _this.precompile(compositions_1, pluginSystem_1, renderer, options); }),
|
|
24103
24135
|
])];
|
|
24104
24136
|
case 8:
|
|
24105
24137
|
_d = __read$3.apply(void 0, [_e.sent(), 2]), loadedBins_1 = _d[0], loadedImages_1 = _d[1];
|
|
@@ -24111,6 +24143,7 @@ var AssetManager = /** @class */ (function () {
|
|
|
24111
24143
|
loadedTextures = _e.sent();
|
|
24112
24144
|
jsonScene_1.compositions = this.updateSceneData(jsonScene_1.compositions);
|
|
24113
24145
|
scene = {
|
|
24146
|
+
timeInfos: timeInfos,
|
|
24114
24147
|
url: url,
|
|
24115
24148
|
renderLevel: this.options.renderLevel,
|
|
24116
24149
|
storage: {},
|
|
@@ -24129,11 +24162,13 @@ var AssetManager = /** @class */ (function () {
|
|
|
24129
24162
|
_e.label = 12;
|
|
24130
24163
|
case 12:
|
|
24131
24164
|
totalTime = performance.now() - startTime;
|
|
24132
|
-
logger.info("Load asset: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(
|
|
24165
|
+
logger.info("Load asset: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(timeInfoMessages.join(' '), ", url: ").concat(assetUrl));
|
|
24133
24166
|
window.clearTimeout(loadTimer);
|
|
24134
24167
|
this.removeTimer(loadTimer);
|
|
24135
24168
|
scene.totalTime = totalTime;
|
|
24136
24169
|
scene.startTime = startTime;
|
|
24170
|
+
// 各部分分段时长
|
|
24171
|
+
scene.timeInfos = timeInfos;
|
|
24137
24172
|
return [2 /*return*/, scene];
|
|
24138
24173
|
}
|
|
24139
24174
|
});
|
|
@@ -24981,7 +25016,7 @@ var Composition = /** @class */ (function () {
|
|
|
24981
25016
|
* @param props - composition 的创建参数
|
|
24982
25017
|
*/
|
|
24983
25018
|
function Composition(props, scene) {
|
|
24984
|
-
var _a;
|
|
25019
|
+
var _a, _b;
|
|
24985
25020
|
/**
|
|
24986
25021
|
* 动画播放速度
|
|
24987
25022
|
*/
|
|
@@ -25010,7 +25045,7 @@ var Composition = /** @class */ (function () {
|
|
|
25010
25045
|
this.paused = false;
|
|
25011
25046
|
this.lastVideoUpdateTime = 0;
|
|
25012
25047
|
this.postLoaders = [];
|
|
25013
|
-
var
|
|
25048
|
+
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;
|
|
25014
25049
|
this.compositionSourceManager = new CompositionSourceManager(scene, renderer.engine);
|
|
25015
25050
|
scene.jsonScene.imgUsage = undefined;
|
|
25016
25051
|
if (reusable) {
|
|
@@ -25018,7 +25053,7 @@ var Composition = /** @class */ (function () {
|
|
|
25018
25053
|
scene.textures = undefined;
|
|
25019
25054
|
scene.consumed = true;
|
|
25020
25055
|
}
|
|
25021
|
-
var
|
|
25056
|
+
var _f = this.compositionSourceManager, sourceContent = _f.sourceContent, pluginSystem = _f.pluginSystem, imgUsage = _f.imgUsage, totalTime = _f.totalTime, renderLevel = _f.renderLevel, refCompositionProps = _f.refCompositionProps;
|
|
25022
25057
|
assertExist(sourceContent);
|
|
25023
25058
|
this.refCompositionProps = refCompositionProps;
|
|
25024
25059
|
var vfxItem = new CompVFXItem(sourceContent, this);
|
|
@@ -25035,7 +25070,7 @@ var Composition = /** @class */ (function () {
|
|
|
25035
25070
|
this.renderer = renderer;
|
|
25036
25071
|
this.texInfo = imageUsage !== null && imageUsage !== void 0 ? imageUsage : {};
|
|
25037
25072
|
this.event = event;
|
|
25038
|
-
this.statistic = { loadTime: totalTime !== null && totalTime !== void 0 ? totalTime : 0, loadStart: (_a = scene.startTime) !== null && _a !== void 0 ? _a : 0, firstFrameTime: 0 };
|
|
25073
|
+
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'] };
|
|
25039
25074
|
this.reusable = reusable;
|
|
25040
25075
|
this.speed = speed;
|
|
25041
25076
|
this.renderLevel = renderLevel;
|