@galacean/effects-threejs 0.0.1-alpha.0 → 0.0.1-alpha.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/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects runtime threejs plugin for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v0.0.1-alpha.0
6
+ * Version: v0.0.1-alpha.1
7
7
  */
8
8
 
9
9
  'use strict';
@@ -6689,7 +6689,7 @@ function asserts(condition, msg) {
6689
6689
  * Name: @galacean/effects-specification
6690
6690
  * Description: Galacean Effects JSON Specification
6691
6691
  * Author: Ant Group CO., Ltd.
6692
- * Version: v0.0.1
6692
+ * Version: v0.0.2
6693
6693
  */
6694
6694
 
6695
6695
  /*********************************************/
@@ -7162,7 +7162,7 @@ var ItemEndBehavior$1;
7162
7162
  (function (ItemEndBehavior) {
7163
7163
  ItemEndBehavior[ItemEndBehavior["destroy"] = END_BEHAVIOR_DESTROY$1] = "destroy";
7164
7164
  ItemEndBehavior[ItemEndBehavior["loop"] = END_BEHAVIOR_RESTART$1] = "loop";
7165
- ItemEndBehavior[ItemEndBehavior["forward"] = END_BEHAVIOR_FREEZE$1] = "forward";
7165
+ ItemEndBehavior[ItemEndBehavior["freeze"] = END_BEHAVIOR_FREEZE$1] = "freeze";
7166
7166
  })(ItemEndBehavior$1 || (ItemEndBehavior$1 = {}));
7167
7167
  var ParentItemEndBehavior$1;
7168
7168
  (function (ParentItemEndBehavior) {
@@ -9762,12 +9762,11 @@ var VFXItem = /** @class */ (function () {
9762
9762
  */
9763
9763
  this._frozen = false;
9764
9764
  var id = props.id, name = props.name, delay = props.delay, parentId = props.parentId, endBehavior = props.endBehavior, transform = props.transform, _a = props.listIndex, listIndex = _a === void 0 ? 0 : _a, _b = props.duration, duration = _b === void 0 ? 0 : _b;
9765
- var rootTransform = composition.rootTransform;
9766
9765
  this.composition = composition;
9767
9766
  this.id = id;
9768
9767
  this.name = name;
9769
9768
  this.delay = delay;
9770
- this.transform = new Transform(__assign$1({ name: this.name }, transform), rootTransform);
9769
+ this.transform = new Transform(__assign$1({ name: this.name }, transform), composition.transform);
9771
9770
  this.parentId = parentId;
9772
9771
  this.duration = duration;
9773
9772
  this.delayInms = (delay || 0) * 1000;
@@ -10014,6 +10013,10 @@ var VFXItem = /** @class */ (function () {
10014
10013
  VFXItem.prototype.onEnd = function () {
10015
10014
  // OVERRIDE
10016
10015
  };
10016
+ VFXItem.prototype.setColor = function (r, g, b, a) {
10017
+ };
10018
+ VFXItem.prototype.setOpacity = function (opacity) {
10019
+ };
10017
10020
  /**
10018
10021
  * 获取元素显隐属性
10019
10022
  */
@@ -10065,6 +10068,50 @@ var VFXItem = /** @class */ (function () {
10065
10068
  VFXItem.prototype.getNodeTransform = function (itemId) {
10066
10069
  return this.transform;
10067
10070
  };
10071
+ /**
10072
+ * 设置元素在 3D 坐标轴上相对移动
10073
+ */
10074
+ VFXItem.prototype.translate = function (x, y, z) {
10075
+ this.transform.translate(x, y, z);
10076
+ };
10077
+ /**
10078
+ * 设置元素在 3D 坐标轴上相对旋转(角度)
10079
+ */
10080
+ VFXItem.prototype.rotate = function (x, y, z) {
10081
+ var q = [0, 0, 0, 1];
10082
+ quatFromRotation(q, x, y, z);
10083
+ quatStar(q, q);
10084
+ this.transform.rotateByQuat(q);
10085
+ };
10086
+ /**
10087
+ * 设置元素在 3D 坐标轴上相对缩放
10088
+ */
10089
+ VFXItem.prototype.scale = function (x, y, z) {
10090
+ this.transform.scaleBy(x, y, z);
10091
+ };
10092
+ /**
10093
+ * 元素的在画布上的像素位置
10094
+ */
10095
+ VFXItem.prototype.setPositionByPixel = function (x, y) {
10096
+ };
10097
+ /**
10098
+ * 设置元素在 3D 坐标轴的位置
10099
+ */
10100
+ VFXItem.prototype.setPosition = function (x, y, z) {
10101
+ this.transform.setPosition(x, y, z);
10102
+ };
10103
+ /**
10104
+ * 设置元素在 3D 坐标轴的角度
10105
+ */
10106
+ VFXItem.prototype.setRotation = function (x, y, z) {
10107
+ this.transform.setRotation(x, y, z);
10108
+ };
10109
+ /**
10110
+ * 设置元素在 3D 坐标轴的缩放
10111
+ */
10112
+ VFXItem.prototype.setScale = function (x, y, z) {
10113
+ this.transform.setScale(x, y, z);
10114
+ };
10068
10115
  /**
10069
10116
  * 获取元素包围盒
10070
10117
  * @override
@@ -10119,6 +10166,13 @@ var VFXItem = /** @class */ (function () {
10119
10166
  }
10120
10167
  this.started = false;
10121
10168
  };
10169
+ VFXItem.prototype.translateByPixel = function (x, y) {
10170
+ if (this.composition) {
10171
+ var camera = this.composition.camera;
10172
+ camera.getViewProjectionMatrix();
10173
+ camera.getInverseViewProjectionMatrix();
10174
+ }
10175
+ };
10122
10176
  /**
10123
10177
  * 销毁元素
10124
10178
  */
@@ -11178,6 +11232,21 @@ function generateHalfFloatTexture(engine, data, width, height) {
11178
11232
  });
11179
11233
  }
11180
11234
 
11235
+ var RUNTIME_ENV = 'runtime_env';
11236
+ var LOG_TYPE = 'mars';
11237
+ var RENDER_PREFER_LOOKUP_TEXTURE = 'lookup_texture';
11238
+ // 数据模板使用 offscreen canvas 绘制
11239
+ var TEMPLATE_USE_OFFSCREEN_CANVAS = 'offscreen_canvas';
11240
+ // 后处理配置相关
11241
+ var POST_PROCESS_SETTINGS = 'post_process_settings';
11242
+ var config = {};
11243
+ function getConfig(name) {
11244
+ return config[name];
11245
+ }
11246
+ function setConfig(name, value) {
11247
+ return config[name] = value;
11248
+ }
11249
+
11181
11250
  var HEADER_LEN = 12 + 13 * 4; // identifier + header elements (not including key value meta-data pairs)
11182
11251
  var COMPRESSED_2D = 0; // uses a gl.compressedTexImage2D()
11183
11252
  //const COMPRESSED_3D = 1; // uses a gl.compressedTexImage3D()
@@ -11226,15 +11295,24 @@ var KTXTexture = /** @class */ (function () {
11226
11295
  // value of zero is an indication to generate mipmaps @ runtime. Not usually allowed for compressed, so disregard.
11227
11296
  this.numberOfMipmapLevels = Math.max(1, this.numberOfMipmapLevels);
11228
11297
  if (this.pixelHeight === 0 || this.pixelDepth !== 0) {
11229
- console.warn('only 2D textures currently supported');
11298
+ console.warn({
11299
+ content: 'only 2D textures currently supported',
11300
+ type: LOG_TYPE,
11301
+ });
11230
11302
  return;
11231
11303
  }
11232
11304
  if (this.numberOfArrayElements !== 0) {
11233
- console.warn('texture arrays not currently supported');
11305
+ console.warn({
11306
+ content: 'texture arrays not currently supported',
11307
+ type: LOG_TYPE,
11308
+ });
11234
11309
  return;
11235
11310
  }
11236
11311
  if (this.numberOfFaces !== facesExpected) {
11237
- console.warn('number of faces expected' + facesExpected + ', but found ' + this.numberOfFaces);
11312
+ console.warn({
11313
+ content: 'number of faces expected' + facesExpected + ', but found ' + this.numberOfFaces,
11314
+ type: LOG_TYPE,
11315
+ });
11238
11316
  return;
11239
11317
  }
11240
11318
  // we now have a completely validated file, so could use existence of loadType as success
@@ -11921,20 +11999,6 @@ function generateEmptyTypedArray(type) {
11921
11999
  return new Float32Array(0);
11922
12000
  }
11923
12001
 
11924
- var RUNTIME_ENV = 'runtime_env';
11925
- var RENDER_PREFER_LOOKUP_TEXTURE = 'lookup_texture';
11926
- // 数据模板使用 offscreen canvas 绘制
11927
- var TEMPLATE_USE_OFFSCREEN_CANVAS = 'offscreen_canvas';
11928
- // 后处理配置相关
11929
- var POST_PROCESS_SETTINGS = 'post_process_settings';
11930
- var config = {};
11931
- function getConfig(name) {
11932
- return config[name];
11933
- }
11934
- function setConfig(name, value) {
11935
- return config[name] = value;
11936
- }
11937
-
11938
12002
  var seed$8 = 1;
11939
12003
  /**
11940
12004
  * Mesh 抽象类
@@ -15657,6 +15721,12 @@ var SpriteItem = /** @class */ (function (_super) {
15657
15721
  }
15658
15722
  return ret;
15659
15723
  };
15724
+ SpriteItem.prototype.setColor = function (r, g, b, a) {
15725
+ this.options.startColor = [r, g, b, a];
15726
+ };
15727
+ SpriteItem.prototype.setOpacity = function (opacity) {
15728
+ this.options.startColor[3] = opacity;
15729
+ };
15660
15730
  SpriteItem.prototype.getRenderData = function (_time, init) {
15661
15731
  var ret = _super.prototype.getRenderData.call(this, _time, init);
15662
15732
  var colorInc = vecFill(tempColor, 1);
@@ -15780,6 +15850,12 @@ var SpriteVFXItem = /** @class */ (function (_super) {
15780
15850
  this.transform.assignWorldTRS(pos);
15781
15851
  return pos;
15782
15852
  };
15853
+ SpriteVFXItem.prototype.setColor = function (r, g, b, a) {
15854
+ this.content.setColor(r, g, b, a);
15855
+ };
15856
+ SpriteVFXItem.prototype.setOpacity = function (opacity) {
15857
+ this.content.setOpacity(opacity);
15858
+ };
15783
15859
  /**
15784
15860
  * 获取图层包围盒的类型和世界坐标
15785
15861
  * @returns
@@ -18462,6 +18538,22 @@ var ParticleSystem = /** @class */ (function () {
18462
18538
  this.trailMesh.mesh.setVisible(visible);
18463
18539
  }
18464
18540
  };
18541
+ ParticleSystem.prototype.setOpacity = function (opacity) {
18542
+ var material = this.particleMesh.mesh.material;
18543
+ material.setVector4('uOpacityOverLifetimeValue', [1, 1, 1, opacity]);
18544
+ };
18545
+ ParticleSystem.prototype.setColor = function (r, g, b, a) {
18546
+ var material = this.particleMesh.mesh.material;
18547
+ var geometry = this.particleMesh.mesh.geometry;
18548
+ var data = geometry.getAttributeData('aRot') || [];
18549
+ for (var i = 0; i < data.length; i += 4) {
18550
+ data[0] = r;
18551
+ data[1] = g;
18552
+ data[2] = b;
18553
+ data[3] = a;
18554
+ }
18555
+ material.setVector4('uOpacityOverLifetimeValue', [r, g, b, a]);
18556
+ };
18465
18557
  ParticleSystem.prototype.setParentTransform = function (transform) {
18466
18558
  this.parentTransform = transform;
18467
18559
  };
@@ -19012,6 +19104,12 @@ var ParticleVFXItem = /** @class */ (function (_super) {
19012
19104
  content.meshes.forEach(function (mesh) { return mesh.dispose({ material: { textures: exports.DestroyOptions.keep } }); });
19013
19105
  }
19014
19106
  };
19107
+ ParticleVFXItem.prototype.setColor = function (r, g, b, a) {
19108
+ this.content.setColor(r, g, b, a);
19109
+ };
19110
+ ParticleVFXItem.prototype.setOpacity = function (opacity) {
19111
+ this.content.setOpacity(opacity);
19112
+ };
19015
19113
  ParticleVFXItem.prototype.stopParticleEmission = function () {
19016
19114
  if (this.content) {
19017
19115
  this.content.emissionStopped = true;
@@ -20903,11 +21001,12 @@ var TextItem = /** @class */ (function (_super) {
20903
21001
  var layout = this.textLayout;
20904
21002
  var fontScale = style.fontScale;
20905
21003
  var width = (layout.width + style.fontOffset) * fontScale;
21004
+ var height = layout.height * fontScale;
20906
21005
  var fontSize = style.fontSize * fontScale;
20907
21006
  var lineHeight = layout.lineHeight * fontScale;
20908
21007
  this.char = this.text.split('');
20909
21008
  this.canvas.width = width;
20910
- this.canvas.height = layout.height * fontScale;
21009
+ this.canvas.height = height;
20911
21010
  context.clearRect(0, 0, width, this.canvas.height);
20912
21011
  // fix bug 1/255
20913
21012
  context.fillStyle = 'rgba(255, 255, 255, 0.0039)';
@@ -20972,12 +21071,16 @@ var TextItem = /** @class */ (function (_super) {
20972
21071
  }
20973
21072
  //与 toDataURL() 两种方式都需要像素读取操作
20974
21073
  var imageData = context.getImageData(0, 0, this.canvas.width, this.canvas.height);
20975
- (_a = this.mesh) === null || _a === void 0 ? void 0 : _a.mesh.material.setTexture('uSampler0', Texture.createWithData(this.engine, imageData, {
21074
+ (_a = this.mesh) === null || _a === void 0 ? void 0 : _a.mesh.material.setTexture('uSampler0', Texture.createWithData(this.engine, {
21075
+ data: new Uint8Array(imageData.data),
21076
+ width: imageData.width,
21077
+ height: imageData.height,
21078
+ }, {
20976
21079
  flipY: true,
20977
21080
  magFilter: glContext.LINEAR,
20978
21081
  minFilter: glContext.LINEAR,
20979
- wrapS: glContext.REPEAT,
20980
- wrapT: glContext.REPEAT,
21082
+ wrapS: glContext.CLAMP_TO_EDGE,
21083
+ wrapT: glContext.CLAMP_TO_EDGE,
20981
21084
  }));
20982
21085
  this.isDirty = false;
20983
21086
  };
@@ -21121,7 +21224,7 @@ var TextLoader = /** @class */ (function (_super) {
21121
21224
  return _this;
21122
21225
  }
21123
21226
  TextLoader.prototype.onCompositionDestroyed = function (composition) {
21124
- if (composition.reusable || composition.keepResource) {
21227
+ if (composition.reusable) {
21125
21228
  this.addItems.forEach(function (vfxitem) {
21126
21229
  var _a;
21127
21230
  (_a = vfxitem.content.mesh) === null || _a === void 0 ? void 0 : _a.mesh.dispose({ material: { textures: exports.DestroyOptions.keep } });
@@ -22075,6 +22178,15 @@ var Camera = /** @class */ (function () {
22075
22178
  Camera.prototype.getModelViewProjection = function (out, model) {
22076
22179
  return mat4multiply(out, this.viewProjectionMatrix, model);
22077
22180
  };
22181
+ /**
22182
+ * 获取归一化坐标和 3D 世界坐标的换算比例
22183
+ */
22184
+ Camera.prototype.getInverseVPRatio = function () {
22185
+ var pos = [0, 0, 0];
22186
+ var nz = vec3MulMat4(pos, [0, 0, 0], this.getViewProjectionMatrix())[2];
22187
+ vec3MulMat4(pos, [1, 1, nz], this.getInverseViewProjectionMatrix());
22188
+ return [pos[0], pos[1]];
22189
+ };
22078
22190
  /**
22079
22191
  * 设置相机的旋转四元数
22080
22192
  * @param value - 旋转四元数
@@ -22265,7 +22377,7 @@ var filters = {
22265
22377
  * Name: @galacean/effects-specification
22266
22378
  * Description: Galacean Effects JSON Specification
22267
22379
  * Author: Ant Group CO., Ltd.
22268
- * Version: v0.0.1
22380
+ * Version: v0.0.2
22269
22381
  */
22270
22382
 
22271
22383
  /*********************************************/
@@ -22736,7 +22848,7 @@ var ItemEndBehavior;
22736
22848
  (function (ItemEndBehavior) {
22737
22849
  ItemEndBehavior[ItemEndBehavior["destroy"] = END_BEHAVIOR_DESTROY] = "destroy";
22738
22850
  ItemEndBehavior[ItemEndBehavior["loop"] = END_BEHAVIOR_RESTART] = "loop";
22739
- ItemEndBehavior[ItemEndBehavior["forward"] = END_BEHAVIOR_FREEZE] = "forward";
22851
+ ItemEndBehavior[ItemEndBehavior["freeze"] = END_BEHAVIOR_FREEZE] = "freeze";
22740
22852
  })(ItemEndBehavior || (ItemEndBehavior = {}));
22741
22853
  var ParentItemEndBehavior;
22742
22854
  (function (ParentItemEndBehavior) {
@@ -23604,7 +23716,7 @@ function version21Migration(json) {
23604
23716
  composition.items.forEach(function (item) {
23605
23717
  if (item.type === ItemType.null) {
23606
23718
  if (item.endBehavior === ItemEndBehavior.destroy) {
23607
- item.endBehavior = ItemEndBehavior.forward;
23719
+ item.endBehavior = ItemEndBehavior.freeze;
23608
23720
  }
23609
23721
  }
23610
23722
  });
@@ -23612,6 +23724,24 @@ function version21Migration(json) {
23612
23724
  json.version = '2.1';
23613
23725
  return json;
23614
23726
  }
23727
+ /**
23728
+ * 2.2 以下版本数据适配(mars-player@2.5.0 及以上版本支持 2.2 以下数据的适配)
23729
+ */
23730
+ function version22Migration(json) {
23731
+ var _a;
23732
+ var singleVersion = (_a = json.version) === null || _a === void 0 ? void 0 : _a.split('.');
23733
+ if (!singleVersion || Number(singleVersion[0]) > 2 || (Number(singleVersion[0]) === 2 && Number(singleVersion[1]) >= 2)) {
23734
+ return json;
23735
+ }
23736
+ json.compositions.forEach(function (composition) {
23737
+ composition.items.forEach(function (item) {
23738
+ if (item.type === ItemType.mesh || item.type === ItemType.light) {
23739
+ item.endBehavior = item.endBehavior === 1 ? ItemEndBehavior.destroy : item.endBehavior;
23740
+ }
23741
+ });
23742
+ });
23743
+ return json;
23744
+ }
23615
23745
 
23616
23746
  var v0 = /^(\d+)\.(\d+)\.(\d+)(-(\w+)\.\d+)?$/;
23617
23747
  var standardVersion = /^(\d+)\.(\d+)$/;
@@ -23621,6 +23751,8 @@ function getStandardJSON(json) {
23621
23751
  if (!json || typeof json !== 'object') {
23622
23752
  throw Error('expect a json object');
23623
23753
  }
23754
+ // 修正老版本数据中,meshItem以及lightItem结束行为错误问题
23755
+ version22Migration(json);
23624
23756
  if (v0.test(json.version)) {
23625
23757
  reverseParticle = ((_a = (/^(\d+)/).exec(json.version)) === null || _a === void 0 ? void 0 : _a[0]) === '0';
23626
23758
  return version21Migration(getStandardJSONFromV0(json));
@@ -24219,7 +24351,10 @@ var AssetManager = /** @class */ (function () {
24219
24351
  // 触发插件系统 pluginSystem 的回调 prepareResource
24220
24352
  _d.sent();
24221
24353
  totalTime = performance.now() - startTime;
24222
- console.debug("".concat(timeLabel, ": ").concat(totalTime.toFixed(4), "ms, ").concat(timeInfos.join(' ')));
24354
+ console.info({
24355
+ content: "".concat(timeLabel, ": ").concat(totalTime.toFixed(4), "ms, ").concat(timeInfos.join(' ')),
24356
+ type: LOG_TYPE,
24357
+ });
24223
24358
  window.clearTimeout(loadTimer);
24224
24359
  scene.totalTime = totalTime;
24225
24360
  scene.startTime = startTime;
@@ -24343,7 +24478,10 @@ var AssetManager = /** @class */ (function () {
24343
24478
  return [3 /*break*/, 4];
24344
24479
  case 3:
24345
24480
  _b.sent();
24346
- console.warn("Invalid fonts source: ".concat(font.fontURL));
24481
+ console.warn({
24482
+ content: "Invalid fonts source: ".concat(font.fontURL),
24483
+ type: LOG_TYPE,
24484
+ });
24347
24485
  return [3 /*break*/, 4];
24348
24486
  case 4: return [2 /*return*/];
24349
24487
  }
@@ -24750,6 +24888,9 @@ var CompVFXItem = /** @class */ (function (_super) {
24750
24888
  this.tempQueue.length = 0;
24751
24889
  this.itemsToRemove.length = 0;
24752
24890
  };
24891
+ CompVFXItem.prototype.handleVisibleChanged = function (visible) {
24892
+ this.items.forEach(function (item) { return item.setVisible(visible); });
24893
+ };
24753
24894
  CompVFXItem.prototype.getUpdateTime = function (t) {
24754
24895
  var startTime = this.startTimeInms;
24755
24896
  var now = this.timeInms;
@@ -24817,6 +24958,7 @@ var CompVFXItem = /** @class */ (function (_super) {
24817
24958
  };
24818
24959
  /**
24819
24960
  * 获取指定元素当前时刻真正起作用的父元素, 需要在元素生命周期内获取
24961
+ * @internal
24820
24962
  * @param item - 指定元素
24821
24963
  * @return 当父元素生命周期结束时,返回空
24822
24964
  */
@@ -24927,17 +25069,22 @@ var Composition = /** @class */ (function () {
24927
25069
  this.paused = false;
24928
25070
  this.lastVideoUpdateTime = 0;
24929
25071
  this.postLoaders = [];
24930
- var keepResource = props.keepResource, _b = props.reusable, reusable = _b === void 0 ? false : _b, _c = props.baseRenderOrder, baseRenderOrder = _c === void 0 ? 0 : _c, renderer = props.renderer, handlePlayerPause = props.handlePlayerPause, handleMessageItem = props.handleMessageItem, handleEnd = props.handleEnd, event = props.event, width = props.width, height = props.height;
25072
+ var _b = props.reusable, reusable = _b === void 0 ? false : _b, _c = props.speed, speed = _c === void 0 ? 1 : _c, _d = props.baseRenderOrder, baseRenderOrder = _d === void 0 ? 0 : _d, renderer = props.renderer, handlePlayerPause = props.handlePlayerPause, handleMessageItem = props.handleMessageItem, handleEnd = props.handleEnd, event = props.event, width = props.width, height = props.height;
24931
25073
  this.compositionSourceManager = new CompositionSourceManager(scene, renderer.engine);
24932
25074
  scene.jsonScene.imgUsage = undefined;
24933
- if (!keepResource) {
25075
+ if (reusable) {
25076
+ this.keepResource = true;
24934
25077
  scene.textures = undefined;
24935
25078
  scene.consumed = true;
24936
25079
  }
24937
- var _d = this.compositionSourceManager, sourceContent = _d.sourceContent, pluginSystem = _d.pluginSystem, imgUsage = _d.imgUsage, totalTime = _d.totalTime, renderLevel = _d.renderLevel;
25080
+ var _e = this.compositionSourceManager, sourceContent = _e.sourceContent, pluginSystem = _e.pluginSystem, imgUsage = _e.imgUsage, totalTime = _e.totalTime, renderLevel = _e.renderLevel;
24938
25081
  assertExist(sourceContent);
24939
25082
  var vfxItem = new CompVFXItem(sourceContent, this);
24940
25083
  var imageUsage = (!reusable && imgUsage);
25084
+ this.transform = new Transform({
25085
+ name: this.name,
25086
+ });
25087
+ vfxItem.transform = this.transform;
24941
25088
  this.globalVolume = sourceContent.globalVolume;
24942
25089
  this.width = width;
24943
25090
  this.height = height;
@@ -24948,21 +25095,19 @@ var Composition = /** @class */ (function () {
24948
25095
  this.event = event;
24949
25096
  this.statistic = { loadTime: totalTime !== null && totalTime !== void 0 ? totalTime : 0, loadStart: (_a = scene.startTime) !== null && _a !== void 0 ? _a : 0, firstFrameTime: 0 };
24950
25097
  this.reusable = reusable;
25098
+ this.speed = speed;
24951
25099
  this.renderLevel = renderLevel;
24952
- this.handlePlayerPause = handlePlayerPause;
24953
- this.handleMessageItem = handleMessageItem;
24954
- this.handleEnd = handleEnd;
24955
- this.rootTransform = new Transform();
24956
- vfxItem.transform = this.rootTransform;
24957
- this.autoRefTex = !keepResource && imageUsage && vfxItem.endBehavior !== END_BEHAVIOR_RESTART$1;
25100
+ this.autoRefTex = !this.keepResource && imageUsage && vfxItem.endBehavior !== END_BEHAVIOR_RESTART$1;
24958
25101
  this.content = vfxItem;
24959
25102
  this.name = vfxItem.name;
24960
- this.rootTransform.name = this.name;
24961
25103
  this.pluginSystem = pluginSystem;
24962
25104
  this.pluginSystem.initializeComposition(this, scene);
24963
25105
  this.camera = new Camera(this.name, __assign$1(__assign$1({}, sourceContent === null || sourceContent === void 0 ? void 0 : sourceContent.camera), { aspect: width / height }));
24964
25106
  this.url = scene.url;
24965
25107
  this.assigned = true;
25108
+ this.handlePlayerPause = handlePlayerPause;
25109
+ this.handleMessageItem = handleMessageItem;
25110
+ this.handleEnd = handleEnd;
24966
25111
  this.createRenderFrame();
24967
25112
  this.reset();
24968
25113
  }
@@ -25024,7 +25169,7 @@ var Composition = /** @class */ (function () {
25024
25169
  this.content.reset();
25025
25170
  this.prepareRender();
25026
25171
  this.reset();
25027
- this.rootTransform.setValid(true);
25172
+ this.transform.setValid(true);
25028
25173
  this.content.start();
25029
25174
  this.forwardTime(this.startTime);
25030
25175
  this.content.onUpdate(0);
@@ -25045,10 +25190,10 @@ var Composition = /** @class */ (function () {
25045
25190
  return this.renderOrder;
25046
25191
  };
25047
25192
  Composition.prototype.play = function () {
25048
- if (this.paused) {
25049
- this.resume();
25193
+ if (this.content.ended && this.reusable) {
25194
+ this.restart();
25050
25195
  }
25051
- this.content.start();
25196
+ this.gotoAndPlay(this.time);
25052
25197
  };
25053
25198
  /**
25054
25199
  * 暂停合成的播放
@@ -25063,12 +25208,16 @@ var Composition = /** @class */ (function () {
25063
25208
  this.paused = false;
25064
25209
  };
25065
25210
  Composition.prototype.gotoAndPlay = function (time) {
25211
+ this.resume();
25212
+ if (!this.content.started) {
25213
+ this.content.start();
25214
+ this.forwardTime(this.startTime);
25215
+ }
25216
+ this.forwardTime(time);
25066
25217
  };
25067
- Composition.prototype.gotoAndPause = function (time) {
25068
- };
25069
- // TODO: 待废弃
25070
- Composition.prototype.start = function () {
25071
- this.content.start();
25218
+ Composition.prototype.gotoAndStop = function (time) {
25219
+ this.gotoAndPlay(time);
25220
+ this.pause();
25072
25221
  };
25073
25222
  /**
25074
25223
  *
@@ -25085,29 +25234,29 @@ var Composition = /** @class */ (function () {
25085
25234
  };
25086
25235
  /**
25087
25236
  * 跳到指定时间点(不做任何播放行为)
25088
- *
25089
- * @param time - 时间点(秒),可正可负
25237
+ * @param time - 指定的时间
25090
25238
  */
25091
25239
  Composition.prototype.setTime = function (time) {
25240
+ var pause = this.paused;
25241
+ if (pause) {
25242
+ this.resume();
25243
+ }
25244
+ this.forwardTime(time, true);
25245
+ if (pause) {
25246
+ this.pause();
25247
+ }
25092
25248
  };
25093
- /**
25094
- * 快进/快退指定时间间隔
25095
- * @param timeInSeconds - 需要快进/快退的时间长度(秒),可正可负
25096
- */
25097
- Composition.prototype.forwardTime = function (timeInSeconds) {
25098
- var time = Math.round(timeInSeconds * 1000);
25099
- if (time) {
25100
- var reverse = time < 0;
25101
- var step = 15;
25102
- var t = Math.abs(time);
25103
- for (var ss = reverse ? -step : step; t > step; t -= step) {
25104
- this.update(ss);
25105
- }
25106
- if (t > 0) {
25107
- var ss = reverse ? -t : t;
25108
- this.update(ss);
25109
- }
25249
+ Composition.prototype.forwardTime = function (time, skipRender) {
25250
+ if (skipRender === void 0) { skipRender = false; }
25251
+ var deltaTime = (this.startTime + Math.max(0, time)) * 1000 - this.content.timeInms;
25252
+ var reverse = deltaTime < 0;
25253
+ var step = 15;
25254
+ var t = Math.abs(deltaTime);
25255
+ var ss = reverse ? -step : step;
25256
+ for (t; t > step; t -= step) {
25257
+ this.update(ss, skipRender);
25110
25258
  }
25259
+ this.update(reverse ? -t : t, skipRender);
25111
25260
  };
25112
25261
  /**
25113
25262
  * 重置状态函数
@@ -25149,14 +25298,19 @@ var Composition = /** @class */ (function () {
25149
25298
  * @returns 销毁合成标志位
25150
25299
  */
25151
25300
  Composition.prototype.shouldDispose = function () {
25301
+ if (this.reusable) {
25302
+ return false;
25303
+ }
25152
25304
  var _a = this.content, ended = _a.ended, endBehavior = _a.endBehavior;
25153
25305
  return ended && (!endBehavior || endBehavior === END_BEHAVIOR_PAUSE_AND_DESTROY$1);
25154
25306
  };
25155
25307
  /**
25156
25308
  * 合成更新,针对所有 item 的更新
25157
25309
  * @param deltaTime - 更新的时间步长
25310
+ * @param skipRender - 是否需要渲染
25158
25311
  */
25159
- Composition.prototype.update = function (deltaTime) {
25312
+ Composition.prototype.update = function (deltaTime, skipRender) {
25313
+ if (skipRender === void 0) { skipRender = false; }
25160
25314
  if (!this.assigned || this.paused) {
25161
25315
  return;
25162
25316
  }
@@ -25173,7 +25327,9 @@ var Composition = /** @class */ (function () {
25173
25327
  this.dispose();
25174
25328
  }
25175
25329
  else {
25176
- this.prepareRender();
25330
+ if (!skipRender) {
25331
+ this.prepareRender();
25332
+ }
25177
25333
  }
25178
25334
  };
25179
25335
  /**
@@ -25461,7 +25617,10 @@ var Composition = /** @class */ (function () {
25461
25617
  (_a = this.rendererOptions) === null || _a === void 0 ? void 0 : _a.emptyTexture.dispose();
25462
25618
  (_b = this.pluginSystem) === null || _b === void 0 ? void 0 : _b.destroyComposition(this);
25463
25619
  this.update = function () {
25464
- console.error("Update disposed composition: ".concat(_this.name, "."));
25620
+ console.error({
25621
+ content: "Update disposed composition: ".concat(_this.name, "."),
25622
+ type: LOG_TYPE,
25623
+ });
25465
25624
  };
25466
25625
  this.handlePlayerPause = noop;
25467
25626
  this.dispose = noop;
@@ -25480,6 +25639,37 @@ var Composition = /** @class */ (function () {
25480
25639
  Composition.prototype.setEditorTransform = function (scale, dx, dy) {
25481
25640
  this.renderFrame.editorTransform = [scale, scale, dx, dy];
25482
25641
  };
25642
+ /**
25643
+ * 合成整体在水平方向移动 x 像素,垂直方向移动 y 像素
25644
+ */
25645
+ Composition.prototype.translateByPixel = function (x, y) {
25646
+ if (!this.renderer) {
25647
+ console.warn('Can not translate position when container not assigned');
25648
+ return;
25649
+ }
25650
+ var _a = __read$1(this.camera.getInverseVPRatio(), 2), rx = _a[0], ry = _a[1];
25651
+ var width = this.renderer.getWidth();
25652
+ var height = this.renderer.getHeight();
25653
+ this.content.translate(2 * x * rx / width, -2 * y * ry / height, 0);
25654
+ };
25655
+ /**
25656
+ * 设置合成在 3D 坐标轴上相对移动
25657
+ */
25658
+ Composition.prototype.translate = function (x, y, z) {
25659
+ this.content.translate(x, y, z);
25660
+ };
25661
+ /**
25662
+ * 设置合成在 3D 坐标轴上相对旋转(角度)
25663
+ */
25664
+ Composition.prototype.rotate = function (x, y, z) {
25665
+ this.content.rotate(x, y, z);
25666
+ };
25667
+ /**
25668
+ * 设置合成在 3D 坐标轴上相对缩放
25669
+ */
25670
+ Composition.prototype.scale = function (x, y, z) {
25671
+ this.content.scale(x, y, z);
25672
+ };
25483
25673
  /**
25484
25674
  * 卸载贴图纹理方法,减少内存
25485
25675
  */
@@ -25519,14 +25709,6 @@ var Composition = /** @class */ (function () {
25519
25709
  };
25520
25710
  return Composition;
25521
25711
  }());
25522
- /**
25523
- * 根据 id 查找对应的合成,可能找不到
25524
- * @param compositions - 合成列表
25525
- * @param id - 目标合成 id
25526
- */
25527
- function getComposition(compositions, id) {
25528
- return compositions.find(function (f) { return f.id === id; });
25529
- }
25530
25712
 
25531
25713
  /**
25532
25714
  * Engine 基类,负责维护所有 GPU 资源的销毁
@@ -25632,7 +25814,10 @@ var Engine = /** @class */ (function () {
25632
25814
  info.push("Tex ".concat(this.textures.length));
25633
25815
  }
25634
25816
  if (info.length > 0) {
25635
- console.warn("Release GPU memory: ".concat(info.join(', ')));
25817
+ console.warn({
25818
+ content: "Release GPU memory: ".concat(info.join(', ')),
25819
+ type: LOG_TYPE,
25820
+ });
25636
25821
  }
25637
25822
  this.renderPasses.forEach(function (pass) {
25638
25823
  pass.dispose();
@@ -27273,8 +27458,11 @@ Geometry.create = function (engine, options) {
27273
27458
  Mesh.create = function (engine, props) {
27274
27459
  return new ThreeMesh(engine, props);
27275
27460
  };
27276
- var version = "0.0.1-alpha.0";
27277
- console.info('[Galacean Effects THREEJS] version: ' + "0.0.1-alpha.0");
27461
+ var version = "0.0.1-alpha.1";
27462
+ console.info({
27463
+ content: '[Galacean Effects THREEJS] version: ' + "0.0.1-alpha.1",
27464
+ type: LOG_TYPE,
27465
+ });
27278
27466
 
27279
27467
  exports.AbstractPlugin = AbstractPlugin;
27280
27468
  exports.AssetManager = AssetManager;
@@ -27323,6 +27511,7 @@ exports.InteractLoader = InteractLoader;
27323
27511
  exports.InteractMesh = InteractMesh;
27324
27512
  exports.InteractVFXItem = InteractVFXItem;
27325
27513
  exports.KTXTexture = KTXTexture;
27514
+ exports.LOG_TYPE = LOG_TYPE;
27326
27515
  exports.LineSegments = LineSegments;
27327
27516
  exports.LinearValue = LinearValue;
27328
27517
  exports.Material = Material;
@@ -27442,7 +27631,6 @@ exports.generateEmptyTypedArray = generateEmptyTypedArray;
27442
27631
  exports.generateHalfFloatTexture = generateHalfFloatTexture;
27443
27632
  exports.getBackgroundImage = getBackgroundImage;
27444
27633
  exports.getColorFromGradientStops = getColorFromGradientStops;
27445
- exports.getComposition = getComposition;
27446
27634
  exports.getConfig = getConfig;
27447
27635
  exports.getDefaultTemplateCanvasPool = getDefaultTemplateCanvasPool;
27448
27636
  exports.getDefaultTextureFactory = getDefaultTextureFactory;