@galacean/effects-threejs 2.0.0-alpha.14 → 2.0.0-alpha.15

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: v2.0.0-alpha.14
6
+ * Version: v2.0.0-alpha.15
7
7
  */
8
8
 
9
9
  'use strict';
@@ -765,6 +765,11 @@ function noop() {}
765
765
  */ function isObject(obj) {
766
766
  return Object.prototype.toString.call(obj) === "[object Object]";
767
767
  }
768
+ function isCanvas(canvas) {
769
+ var _canvas_tagName;
770
+ // 小程序 Canvas 无法使用 instanceof HTMLCanvasElement 判断
771
+ return typeof canvas === "object" && canvas !== null && ((_canvas_tagName = canvas.tagName) == null ? void 0 : _canvas_tagName.toUpperCase()) === "CANVAS";
772
+ }
768
773
  function deepClone(obj) {
769
774
  if (isArray(obj)) {
770
775
  return obj.map(deepClone);
@@ -792,6 +797,37 @@ function throwDestroyedError() {
792
797
  function generateGUID() {
793
798
  return v4().replace(/-/g, "");
794
799
  }
800
+ function base64ToFile(base64, filename, contentType) {
801
+ if (filename === void 0) filename = "base64File";
802
+ if (contentType === void 0) contentType = "";
803
+ // 去掉 Base64 字符串的 Data URL 部分(如果存在)
804
+ var base64WithoutPrefix = base64.split(",")[1] || base64;
805
+ // 将 base64 编码的字符串转换为二进制字符串
806
+ var byteCharacters = atob(base64WithoutPrefix);
807
+ // 创建一个 8 位无符号整数值的数组,即“字节数组”
808
+ var byteArrays = [];
809
+ // 切割二进制字符串为多个片段,并将每个片段转换成一个字节数组
810
+ for(var offset = 0; offset < byteCharacters.length; offset += 512){
811
+ var slice = byteCharacters.slice(offset, offset + 512);
812
+ var byteNumbers = new Array(slice.length);
813
+ for(var i = 0; i < slice.length; i++){
814
+ byteNumbers[i] = slice.charCodeAt(i);
815
+ }
816
+ var byteArray = new Uint8Array(byteNumbers);
817
+ byteArrays.push(byteArray);
818
+ }
819
+ // 使用字节数组创建 Blob 对象
820
+ var blob = new Blob(byteArrays, {
821
+ type: contentType
822
+ });
823
+ // 创建 File 对象
824
+ var file = new File([
825
+ blob
826
+ ], filename, {
827
+ type: contentType
828
+ });
829
+ return file;
830
+ }
795
831
 
796
832
  function _defineProperties(target, props) {
797
833
  for(var i = 0; i < props.length; i++){
@@ -18663,17 +18699,15 @@ exports.TrackAsset = /*#__PURE__*/ function(PlayableAsset) {
18663
18699
  return _this;
18664
18700
  }
18665
18701
  var _proto = TrackAsset.prototype;
18666
- _proto.initializeBinding = function initializeBinding(parentBinding) {
18667
- this.binding = parentBinding;
18702
+ /**
18703
+ * 重写该方法以获取自定义对象绑定
18704
+ */ _proto.resolveBinding = function resolveBinding(parentBinding) {
18705
+ return parentBinding;
18668
18706
  };
18669
18707
  /**
18670
- * @internal
18671
- */ _proto.initializeBindingRecursive = function initializeBindingRecursive(parentBinding) {
18672
- this.initializeBinding(parentBinding);
18673
- for(var _iterator = _create_for_of_iterator_helper_loose(this.children), _step; !(_step = _iterator()).done;){
18674
- var subTrack = _step.value;
18675
- subTrack.initializeBindingRecursive(this.binding);
18676
- }
18708
+ * 重写该方法以创建自定义混合器
18709
+ */ _proto.createTrackMixer = function createTrackMixer(graph) {
18710
+ return new Playable(graph);
18677
18711
  };
18678
18712
  _proto.createOutput = function createOutput() {
18679
18713
  var output = new PlayableOutput();
@@ -18704,11 +18738,6 @@ exports.TrackAsset = /*#__PURE__*/ function(PlayableAsset) {
18704
18738
  }
18705
18739
  return mixer;
18706
18740
  };
18707
- /**
18708
- * 重写该方法以创建自定义混合器
18709
- */ _proto.createTrackMixer = function createTrackMixer(graph) {
18710
- return new Playable(graph);
18711
- };
18712
18741
  _proto.createPlayable = function createPlayable(graph) {
18713
18742
  return new Playable(graph);
18714
18743
  };
@@ -18858,13 +18887,6 @@ exports.ObjectBindingTrack = /*#__PURE__*/ function(TrackAsset1) {
18858
18887
  var _proto = ObjectBindingTrack.prototype;
18859
18888
  _proto.create = function create(timelineAsset) {
18860
18889
  var boundItem = this.binding;
18861
- this.options = {
18862
- start: boundItem.start,
18863
- duration: boundItem.duration,
18864
- looping: boundItem.endBehavior === ItemEndBehavior.loop,
18865
- endBehavior: boundItem.endBehavior || ItemEndBehavior.destroy
18866
- };
18867
- this.name = boundItem.name;
18868
18890
  // 添加粒子动画 clip
18869
18891
  if (boundItem.getComponent(exports.ParticleSystem)) {
18870
18892
  var particleTrack = timelineAsset.createTrack(exports.TrackAsset, this, "ParticleTrack");
@@ -18875,18 +18897,6 @@ exports.ObjectBindingTrack = /*#__PURE__*/ function(TrackAsset1) {
18875
18897
  particleClip.endBehaviour = boundItem.endBehavior;
18876
18898
  }
18877
18899
  };
18878
- _proto.toLocalTime = function toLocalTime(time) {
18879
- var localTime = time - this.options.start;
18880
- var duration = this.options.duration;
18881
- if (localTime - duration > 0.001) {
18882
- if (this.options.endBehavior === END_BEHAVIOR_RESTART) {
18883
- localTime = localTime % duration;
18884
- } else if (this.options.endBehavior === END_BEHAVIOR_FREEZE) {
18885
- localTime = Math.min(duration, localTime);
18886
- }
18887
- }
18888
- return localTime;
18889
- };
18890
18900
  _proto.fromData = function fromData(data) {
18891
18901
  TrackAsset1.prototype.fromData.call(this, data);
18892
18902
  this.data = data;
@@ -18962,9 +18972,6 @@ exports.ActivationTrack = /*#__PURE__*/ function(TrackAsset) {
18962
18972
  return TrackAsset.apply(this, arguments);
18963
18973
  }
18964
18974
  var _proto = ActivationTrack.prototype;
18965
- _proto.initializeBinding = function initializeBinding(parentBinding) {
18966
- this.binding = parentBinding;
18967
- };
18968
18975
  _proto.createTrackMixer = function createTrackMixer(graph) {
18969
18976
  return new ActivationMixerPlayable(graph);
18970
18977
  };
@@ -18995,7 +19002,6 @@ exports.TimelineAsset = /*#__PURE__*/ function(PlayableAsset) {
18995
19002
  }
18996
19003
  var _proto = TimelineAsset.prototype;
18997
19004
  _proto.createPlayable = function createPlayable(graph) {
18998
- this.graph = graph;
18999
19005
  var timelinePlayable = new TimelinePlayable(graph);
19000
19006
  timelinePlayable.setTraversalMode(PlayableTraversalMode.Passthrough);
19001
19007
  for(var _iterator = _create_for_of_iterator_helper_loose(this.tracks), _step; !(_step = _iterator()).done;){
@@ -19113,176 +19119,448 @@ function compareTracks(a, b) {
19113
19119
  }
19114
19120
  }
19115
19121
 
19116
- function _possible_constructor_return(self, call) {
19117
- if (call && (_type_of(call) === "object" || typeof call === "function")) return call;
19118
- return _assert_this_initialized(self);
19119
- }
19120
-
19121
- var TextLayout = /*#__PURE__*/ function() {
19122
- function TextLayout(options) {
19123
- this.width = 0;
19124
- this.height = 0;
19125
- var _options_textHeight = options.textHeight, textHeight = _options_textHeight === void 0 ? 100 : _options_textHeight, _options_textWidth = options.textWidth, textWidth = _options_textWidth === void 0 ? 100 : _options_textWidth, _options_textOverflow = options.textOverflow, textOverflow = _options_textOverflow === void 0 ? TextOverflow.display : _options_textOverflow, _options_textBaseline = options.textBaseline, textBaseline = _options_textBaseline === void 0 ? TextBaseline.top : _options_textBaseline, _options_textAlign = options.textAlign, textAlign = _options_textAlign === void 0 ? TextAlignment.left : _options_textAlign, text = options.text, _options_letterSpace = options.letterSpace, letterSpace = _options_letterSpace === void 0 ? 0 : _options_letterSpace, _options_autoWidth = options.autoWidth, autoWidth = _options_autoWidth === void 0 ? false : _options_autoWidth, fontSize = options.fontSize, _options_lineHeight = options.lineHeight, lineHeight = _options_lineHeight === void 0 ? fontSize : _options_lineHeight;
19126
- var tempWidth = fontSize + letterSpace;
19127
- this.autoWidth = autoWidth;
19128
- this.maxTextWidth = text.length * tempWidth;
19129
- // if (autoWidth) {
19130
- // this.width = this.maxTextWidth + this.lineWidth;
19131
- // this.height = fontSize + this.lineHeight;
19132
- // } else {
19133
- // if (textWidth) {
19134
- // this.maxCharCount = Math.floor((textWidth - this.lineWidth) / (tempWidth));
19135
- // this.width = textWidth;
19136
- // } else {
19137
- // this.width = basicScale[0] * 100;
19138
- // }
19139
- // this.height = basicScale[1] * 100;
19140
- // }
19141
- this.width = textWidth;
19142
- this.height = textHeight;
19143
- this.letterSpace = letterSpace;
19144
- this.overFlow = textOverflow;
19145
- this.textBaseline = textBaseline;
19146
- this.textAlign = textAlign;
19147
- this.lineHeight = lineHeight;
19122
+ /**
19123
+ * @since 2.0.0
19124
+ * @internal
19125
+ */ var CompositionComponent = /*#__PURE__*/ function(ItemBehaviour) {
19126
+ _inherits(CompositionComponent, ItemBehaviour);
19127
+ function CompositionComponent() {
19128
+ var _this;
19129
+ _this = ItemBehaviour.apply(this, arguments) || this;
19130
+ _this.time = 0;
19131
+ _this.startTime = 0;
19132
+ _this.items = [] // 场景的所有元素
19133
+ ;
19134
+ _this.reusable = false;
19135
+ _this.sceneBindings = [];
19136
+ _this.graph = new PlayableGraph();
19137
+ return _this;
19148
19138
  }
19149
- var _proto = TextLayout.prototype;
19150
- _proto.getOffsetY = function getOffsetY(style) {
19151
- var offsetY = 0;
19152
- var offset = (style.fontSize + style.outlineWidth) * style.fontScale;
19153
- switch(this.textBaseline){
19154
- case TextBaseline.top:
19155
- offsetY = offset;
19156
- break;
19157
- case TextBaseline.middle:
19158
- offsetY = (this.height + offset) / 2; // fonSize;
19159
- break;
19160
- case TextBaseline.bottom:
19161
- offsetY = this.height - offset / 2;
19162
- break;
19139
+ var _proto = CompositionComponent.prototype;
19140
+ _proto.start = function start() {
19141
+ var _this_item_props = this.item.props, _this_item_props_startTime = _this_item_props.startTime, startTime = _this_item_props_startTime === void 0 ? 0 : _this_item_props_startTime;
19142
+ this.startTime = startTime;
19143
+ this.resolveBindings();
19144
+ this.timelinePlayable = this.timelineAsset.createPlayable(this.graph);
19145
+ this.timelinePlayable.play();
19146
+ // 重播不销毁元素
19147
+ if (this.item.endBehavior !== ItemEndBehavior.destroy) {
19148
+ this.setReusable(true);
19163
19149
  }
19164
- return offsetY;
19165
19150
  };
19166
- _proto.getOffsetX = function getOffsetX(style, maxWidth) {
19167
- var offsetX = 0;
19168
- switch(this.textAlign){
19169
- case TextAlignment.left:
19170
- offsetX = style.outlineWidth * style.fontScale;
19171
- break;
19172
- case TextAlignment.middle:
19173
- offsetX = (this.width * style.fontScale - maxWidth) / 2;
19174
- break;
19175
- case TextAlignment.right:
19176
- offsetX = this.width * style.fontScale - maxWidth;
19177
- break;
19151
+ _proto.setReusable = function setReusable(value) {
19152
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.timelineAsset.tracks), _step; !(_step = _iterator()).done;){
19153
+ var track = _step.value;
19154
+ var binding = track.binding;
19155
+ if (_instanceof1(binding, exports.VFXItem)) {
19156
+ if (_instanceof1(track, exports.ObjectBindingTrack)) {
19157
+ binding.reusable = value;
19158
+ }
19159
+ var subCompositionComponent = binding.getComponent(CompositionComponent);
19160
+ if (subCompositionComponent) {
19161
+ subCompositionComponent.setReusable(value);
19162
+ }
19163
+ }
19178
19164
  }
19179
- return offsetX;
19180
- };
19181
- /**
19182
- * 设置文本框的宽度和高度
19183
- * @param width 文本框宽度
19184
- * @param height 文本框高度
19185
- */ _proto.setSize = function setSize(width, height) {
19186
- this.width = width;
19187
- this.height = height;
19188
19165
  };
19189
- return TextLayout;
19190
- }();
19191
-
19192
- var TextStyle = function TextStyle(options) {
19193
- /**
19194
- * 是否有下划线(暂时无效)
19195
- */ this.isUnderline = false // ttf
19196
- ;
19197
- /**
19198
- * 下划线高度(暂时无效)
19199
- */ this.underlineHeight = 1 // ttf
19200
- ;
19201
- /**
19202
- * 是否有外描边
19203
- */ this.isOutlined = false // both // ttf & char
19204
- ;
19205
- /**
19206
- * 外描边宽度
19207
- */ this.outlineWidth = 0 // both // ttf & char
19208
- ;
19209
- /**
19210
- * 是否有阴影
19211
- */ this.hasShadow = false // ttf
19212
- ;
19213
- this.fontDesc = "" // both
19214
- ;
19215
- /**
19216
- * 字体倍数
19217
- */ this.fontScale = 2;
19218
- this.fontOffset = 0;
19219
- var _options_textColor = options.textColor, textColor = _options_textColor === void 0 ? [
19220
- 1,
19221
- 1,
19222
- 1,
19223
- 1
19224
- ] : _options_textColor, _options_fontSize = options.fontSize, fontSize = _options_fontSize === void 0 ? 40 : _options_fontSize, outline = options.outline, shadow = options.shadow, _options_fontWeight = options.fontWeight, fontWeight = _options_fontWeight === void 0 ? "normal" : _options_fontWeight, _options_fontStyle = options.fontStyle, fontStyle = _options_fontStyle === void 0 ? "normal" : _options_fontStyle, _options_fontFamily = options.fontFamily, fontFamily = _options_fontFamily === void 0 ? "sans-serif" : _options_fontFamily;
19225
- this.textColor = textColor;
19226
- //@ts-expect-error
19227
- this.textWeight = fontWeight;
19228
- //@ts-expect-error
19229
- this.fontStyle = fontStyle;
19230
- this.fontFamily = fontFamily;
19231
- this.fontSize = fontSize; // 暂时取消字号限制 Math.min(fontSize, this.maxFontSize);
19232
- if (outline) {
19233
- this.isOutlined = true;
19234
- var _outline_outlineColor;
19235
- this.outlineColor = (_outline_outlineColor = outline.outlineColor) != null ? _outline_outlineColor : [
19236
- 1,
19237
- 1,
19238
- 1,
19239
- 1
19240
- ];
19241
- var _outline_outlineWidth;
19242
- this.outlineWidth = (_outline_outlineWidth = outline.outlineWidth) != null ? _outline_outlineWidth : 1;
19243
- this.fontOffset += this.outlineWidth;
19244
- }
19245
- if (shadow) {
19246
- this.hasShadow = true;
19247
- var _shadow_shadowBlur;
19248
- this.shadowBlur = (_shadow_shadowBlur = shadow.shadowBlur) != null ? _shadow_shadowBlur : 2;
19249
- var _shadow_shadowColor;
19250
- this.shadowColor = (_shadow_shadowColor = shadow.shadowColor) != null ? _shadow_shadowColor : [
19251
- 0,
19252
- 0,
19253
- 0,
19254
- 1
19255
- ];
19256
- var _shadow_shadowOffsetX;
19257
- this.shadowOffsetX = (_shadow_shadowOffsetX = shadow.shadowOffsetX) != null ? _shadow_shadowOffsetX : 0;
19258
- var _shadow_shadowOffsetY;
19259
- this.shadowOffsetY = (_shadow_shadowOffsetY = shadow.shadowOffsetY) != null ? _shadow_shadowOffsetY : 0;
19260
- }
19261
- if (this.fontStyle !== FontStyle.normal) {
19262
- // 0.0174532925 = 3.141592653 / 180
19263
- this.fontOffset += this.fontSize * Math.tan(12 * 0.0174532925);
19264
- }
19265
- };
19266
-
19267
- var CanvasPool = /*#__PURE__*/ function() {
19268
- function CanvasPool() {
19269
- this.elements = [];
19270
- }
19271
- var _proto = CanvasPool.prototype;
19272
- _proto.dispose = function dispose() {
19273
- this.elements.forEach(function(e) {
19274
- return e.remove();
19275
- });
19276
- // clearing the array
19277
- this.elements.length = 0;
19166
+ _proto.getReusable = function getReusable() {
19167
+ return this.reusable;
19278
19168
  };
19279
- _proto.getCanvas = function getCanvas() {
19280
- if (this.elements.length !== 0) {
19281
- return this.elements.shift();
19169
+ _proto.update = function update(dt) {
19170
+ var time = this.time;
19171
+ // 主合成 rootItem 没有绑定轨道,增加结束行为判断。
19172
+ if (this.item.isEnded(this.time) && !this.item.parent) {
19173
+ this.item.ended = true;
19282
19174
  }
19283
- if (getConfig(TEMPLATE_USE_OFFSCREEN_CANVAS)) {
19284
- // @ts-expect-error
19285
- return window._createOffscreenCanvas(10, 10);
19175
+ this.timelinePlayable.setTime(time);
19176
+ this.graph.evaluate(dt);
19177
+ };
19178
+ _proto.createContent = function createContent() {
19179
+ var sceneBindings = [];
19180
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.data.sceneBindings), _step; !(_step = _iterator()).done;){
19181
+ var sceneBindingData = _step.value;
19182
+ sceneBindings.push({
19183
+ key: this.engine.assetLoader.loadGUID(sceneBindingData.key.id),
19184
+ value: this.engine.assetLoader.loadGUID(sceneBindingData.value.id)
19185
+ });
19186
+ }
19187
+ this.sceneBindings = sceneBindings;
19188
+ var timelineAsset = this.data.timelineAsset ? this.engine.assetLoader.loadGUID(this.data.timelineAsset.id) : new exports.TimelineAsset(this.engine);
19189
+ this.timelineAsset = timelineAsset;
19190
+ var items = this.items;
19191
+ this.items.length = 0;
19192
+ if (this.item.composition) {
19193
+ var assetLoader = this.item.engine.assetLoader;
19194
+ var itemProps = this.item.props.items ? this.item.props.items : [];
19195
+ for(var i = 0; i < itemProps.length; i++){
19196
+ var item = void 0;
19197
+ var itemData = itemProps[i];
19198
+ // 设置预合成作为元素时的时长、结束行为和渲染延时
19199
+ if (exports.Item.isComposition(itemData)) {
19200
+ var refId = itemData.content.options.refId;
19201
+ var props = this.item.composition.refCompositionProps.get(refId);
19202
+ if (!props) {
19203
+ throw new Error("引用的Id: " + refId + " 的预合成不存在");
19204
+ }
19205
+ // endBehaviour 类型需优化
19206
+ props.content = itemData.content;
19207
+ item = assetLoader.loadGUID(itemData.id);
19208
+ item.composition = this.item.composition;
19209
+ var compositionComponent = item.addComponent(CompositionComponent);
19210
+ compositionComponent.data = props;
19211
+ compositionComponent.refId = refId;
19212
+ item.transform.parentTransform = this.transform;
19213
+ this.item.composition.refContent.push(item);
19214
+ if (item.endBehavior === ItemEndBehavior.loop) {
19215
+ this.item.composition.autoRefTex = false;
19216
+ }
19217
+ compositionComponent.createContent();
19218
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(compositionComponent.items), _step1; !(_step1 = _iterator1()).done;){
19219
+ var vfxItem = _step1.value;
19220
+ vfxItem.setInstanceId(generateGUID());
19221
+ for(var _iterator2 = _create_for_of_iterator_helper_loose(vfxItem.components), _step2; !(_step2 = _iterator2()).done;){
19222
+ var component = _step2.value;
19223
+ component.setInstanceId(generateGUID());
19224
+ }
19225
+ }
19226
+ } else {
19227
+ item = assetLoader.loadGUID(itemData.id);
19228
+ item.composition = this.item.composition;
19229
+ }
19230
+ item.parent = this.item;
19231
+ // 相机不跟随合成移动
19232
+ item.transform.parentTransform = itemData.type === ItemType.camera ? new Transform() : this.transform;
19233
+ if (exports.VFXItem.isExtraCamera(item)) {
19234
+ this.item.composition.extraCamera = item;
19235
+ }
19236
+ items.push(item);
19237
+ }
19238
+ }
19239
+ };
19240
+ _proto.onDestroy = function onDestroy() {
19241
+ if (this.item.composition) {
19242
+ if (this.items) {
19243
+ this.items.forEach(function(item) {
19244
+ return item.dispose();
19245
+ });
19246
+ this.items.length = 0;
19247
+ }
19248
+ }
19249
+ };
19250
+ _proto.hitTest = function hitTest(ray, x, y, regions, force, options) {
19251
+ var _this, _loop = function(i) {
19252
+ var item = _this.items[i];
19253
+ if (item.getVisible() && !item.ended && !exports.VFXItem.isComposition(item) && !skip(item)) {
19254
+ var hitParams = item.getHitTestParams(force);
19255
+ if (hitParams) {
19256
+ var success = false;
19257
+ var intersectPoint = new Vector3();
19258
+ if (hitParams.type === exports.HitTestType.triangle) {
19259
+ var triangles = hitParams.triangles, backfaceCulling = hitParams.backfaceCulling;
19260
+ for(var j = 0; j < triangles.length; j++){
19261
+ var triangle = triangles[j];
19262
+ if (ray.intersectTriangle(triangle, intersectPoint, backfaceCulling)) {
19263
+ success = true;
19264
+ hitPositions.push(intersectPoint);
19265
+ break;
19266
+ }
19267
+ }
19268
+ } else if (hitParams.type === exports.HitTestType.box) {
19269
+ var center = hitParams.center, size = hitParams.size;
19270
+ var boxMin = center.clone().addScaledVector(size, 0.5);
19271
+ var boxMax = center.clone().addScaledVector(size, -0.5);
19272
+ if (ray.intersectBox({
19273
+ min: boxMin,
19274
+ max: boxMax
19275
+ }, intersectPoint)) {
19276
+ success = true;
19277
+ hitPositions.push(intersectPoint);
19278
+ }
19279
+ } else if (hitParams.type === exports.HitTestType.sphere) {
19280
+ var center1 = hitParams.center, radius = hitParams.radius;
19281
+ if (ray.intersectSphere({
19282
+ center: center1,
19283
+ radius: radius
19284
+ }, intersectPoint)) {
19285
+ success = true;
19286
+ hitPositions.push(intersectPoint);
19287
+ }
19288
+ } else if (hitParams.type === exports.HitTestType.custom) {
19289
+ var tempPosition = hitParams.collect(ray, new Vector2(x, y));
19290
+ if (tempPosition && tempPosition.length > 0) {
19291
+ tempPosition.forEach(function(pos) {
19292
+ hitPositions.push(pos);
19293
+ });
19294
+ success = true;
19295
+ }
19296
+ }
19297
+ if (success) {
19298
+ var region = {
19299
+ compContent: _this.item,
19300
+ id: item.id,
19301
+ name: item.name,
19302
+ position: hitPositions[hitPositions.length - 1],
19303
+ parentId: item.parentId,
19304
+ hitPositions: hitPositions,
19305
+ behavior: hitParams.behavior
19306
+ };
19307
+ regions.push(region);
19308
+ if (stop(region)) {
19309
+ return {
19310
+ v: regions
19311
+ };
19312
+ }
19313
+ }
19314
+ }
19315
+ }
19316
+ };
19317
+ var hitPositions = [];
19318
+ var stop = (options == null ? void 0 : options.stop) || noop;
19319
+ var skip = (options == null ? void 0 : options.skip) || noop;
19320
+ var maxCount = (options == null ? void 0 : options.maxCount) || this.items.length;
19321
+ for(var i = 0; i < this.items.length && regions.length < maxCount; i++){
19322
+ var _ret = (_this = this, _loop(i));
19323
+ if (_type_of(_ret) === "object") return _ret.v;
19324
+ }
19325
+ return regions;
19326
+ };
19327
+ _proto.fromData = function fromData(data) {};
19328
+ _proto.resolveBindings = function resolveBindings() {
19329
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.sceneBindings), _step; !(_step = _iterator()).done;){
19330
+ var sceneBinding = _step.value;
19331
+ sceneBinding.key.binding = sceneBinding.value;
19332
+ }
19333
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(this.timelineAsset.tracks), _step1; !(_step1 = _iterator1()).done;){
19334
+ var masterTrack = _step1.value;
19335
+ this.resolveTrackBindingsWithRoot(masterTrack);
19336
+ }
19337
+ };
19338
+ _proto.resolveTrackBindingsWithRoot = function resolveTrackBindingsWithRoot(track) {
19339
+ for(var _iterator = _create_for_of_iterator_helper_loose(track.getChildTracks()), _step; !(_step = _iterator()).done;){
19340
+ var subTrack = _step.value;
19341
+ subTrack.binding = subTrack.resolveBinding(track.binding);
19342
+ this.resolveTrackBindingsWithRoot(subTrack);
19343
+ }
19344
+ };
19345
+ return CompositionComponent;
19346
+ }(ItemBehaviour);
19347
+
19348
+ exports.SubCompositionTrack = /*#__PURE__*/ function(TrackAsset) {
19349
+ _inherits(SubCompositionTrack, TrackAsset);
19350
+ function SubCompositionTrack() {
19351
+ return TrackAsset.apply(this, arguments);
19352
+ }
19353
+ var _proto = SubCompositionTrack.prototype;
19354
+ _proto.resolveBinding = function resolveBinding(parentBinding) {
19355
+ if (!_instanceof1(parentBinding, exports.VFXItem)) {
19356
+ throw new Error("SubCompositionTrack needs to be set under the VFXItem track");
19357
+ }
19358
+ return parentBinding.getComponent(CompositionComponent);
19359
+ };
19360
+ return SubCompositionTrack;
19361
+ }(exports.TrackAsset);
19362
+ exports.SubCompositionTrack = __decorate([
19363
+ effectsClass("SubCompositionTrack")
19364
+ ], exports.SubCompositionTrack);
19365
+
19366
+ var SubCompositionClipPlayable = /*#__PURE__*/ function(Playable) {
19367
+ _inherits(SubCompositionClipPlayable, Playable);
19368
+ function SubCompositionClipPlayable() {
19369
+ return Playable.apply(this, arguments);
19370
+ }
19371
+ var _proto = SubCompositionClipPlayable.prototype;
19372
+ _proto.processFrame = function processFrame(context) {
19373
+ var boundObject = context.output.getUserData();
19374
+ boundObject.time = this.getTime();
19375
+ };
19376
+ return SubCompositionClipPlayable;
19377
+ }(Playable);
19378
+
19379
+ exports.SubCompositionPlayableAsset = /*#__PURE__*/ function(PlayableAsset) {
19380
+ _inherits(SubCompositionPlayableAsset, PlayableAsset);
19381
+ function SubCompositionPlayableAsset() {
19382
+ return PlayableAsset.apply(this, arguments);
19383
+ }
19384
+ var _proto = SubCompositionPlayableAsset.prototype;
19385
+ _proto.createPlayable = function createPlayable(graph) {
19386
+ return new SubCompositionClipPlayable(graph);
19387
+ };
19388
+ return SubCompositionPlayableAsset;
19389
+ }(PlayableAsset);
19390
+ exports.SubCompositionPlayableAsset = __decorate([
19391
+ effectsClass("SubCompositionPlayableAsset")
19392
+ ], exports.SubCompositionPlayableAsset);
19393
+
19394
+ function _possible_constructor_return(self, call) {
19395
+ if (call && (_type_of(call) === "object" || typeof call === "function")) return call;
19396
+ return _assert_this_initialized(self);
19397
+ }
19398
+
19399
+ var TextLayout = /*#__PURE__*/ function() {
19400
+ function TextLayout(options) {
19401
+ this.width = 0;
19402
+ this.height = 0;
19403
+ var _options_textHeight = options.textHeight, textHeight = _options_textHeight === void 0 ? 100 : _options_textHeight, _options_textWidth = options.textWidth, textWidth = _options_textWidth === void 0 ? 100 : _options_textWidth, _options_textOverflow = options.textOverflow, textOverflow = _options_textOverflow === void 0 ? TextOverflow.display : _options_textOverflow, _options_textBaseline = options.textBaseline, textBaseline = _options_textBaseline === void 0 ? TextBaseline.top : _options_textBaseline, _options_textAlign = options.textAlign, textAlign = _options_textAlign === void 0 ? TextAlignment.left : _options_textAlign, text = options.text, _options_letterSpace = options.letterSpace, letterSpace = _options_letterSpace === void 0 ? 0 : _options_letterSpace, _options_autoWidth = options.autoWidth, autoWidth = _options_autoWidth === void 0 ? false : _options_autoWidth, fontSize = options.fontSize, _options_lineHeight = options.lineHeight, lineHeight = _options_lineHeight === void 0 ? fontSize : _options_lineHeight;
19404
+ var tempWidth = fontSize + letterSpace;
19405
+ this.autoWidth = autoWidth;
19406
+ this.maxTextWidth = text.length * tempWidth;
19407
+ // if (autoWidth) {
19408
+ // this.width = this.maxTextWidth + this.lineWidth;
19409
+ // this.height = fontSize + this.lineHeight;
19410
+ // } else {
19411
+ // if (textWidth) {
19412
+ // this.maxCharCount = Math.floor((textWidth - this.lineWidth) / (tempWidth));
19413
+ // this.width = textWidth;
19414
+ // } else {
19415
+ // this.width = basicScale[0] * 100;
19416
+ // }
19417
+ // this.height = basicScale[1] * 100;
19418
+ // }
19419
+ this.width = textWidth;
19420
+ this.height = textHeight;
19421
+ this.letterSpace = letterSpace;
19422
+ this.overFlow = textOverflow;
19423
+ this.textBaseline = textBaseline;
19424
+ this.textAlign = textAlign;
19425
+ this.lineHeight = lineHeight;
19426
+ }
19427
+ var _proto = TextLayout.prototype;
19428
+ _proto.getOffsetY = function getOffsetY(style) {
19429
+ var offsetY = 0;
19430
+ var offset = (style.fontSize + style.outlineWidth) * style.fontScale;
19431
+ switch(this.textBaseline){
19432
+ case TextBaseline.top:
19433
+ offsetY = offset;
19434
+ break;
19435
+ case TextBaseline.middle:
19436
+ offsetY = (this.height + offset) / 2; // fonSize;
19437
+ break;
19438
+ case TextBaseline.bottom:
19439
+ offsetY = this.height - offset / 2;
19440
+ break;
19441
+ }
19442
+ return offsetY;
19443
+ };
19444
+ _proto.getOffsetX = function getOffsetX(style, maxWidth) {
19445
+ var offsetX = 0;
19446
+ switch(this.textAlign){
19447
+ case TextAlignment.left:
19448
+ offsetX = style.outlineWidth * style.fontScale;
19449
+ break;
19450
+ case TextAlignment.middle:
19451
+ offsetX = (this.width * style.fontScale - maxWidth) / 2;
19452
+ break;
19453
+ case TextAlignment.right:
19454
+ offsetX = this.width * style.fontScale - maxWidth;
19455
+ break;
19456
+ }
19457
+ return offsetX;
19458
+ };
19459
+ /**
19460
+ * 设置文本框的宽度和高度
19461
+ * @param width 文本框宽度
19462
+ * @param height 文本框高度
19463
+ */ _proto.setSize = function setSize(width, height) {
19464
+ this.width = width;
19465
+ this.height = height;
19466
+ };
19467
+ return TextLayout;
19468
+ }();
19469
+
19470
+ var TextStyle = function TextStyle(options) {
19471
+ /**
19472
+ * 是否有下划线(暂时无效)
19473
+ */ this.isUnderline = false // ttf
19474
+ ;
19475
+ /**
19476
+ * 下划线高度(暂时无效)
19477
+ */ this.underlineHeight = 1 // ttf
19478
+ ;
19479
+ /**
19480
+ * 是否有外描边
19481
+ */ this.isOutlined = false // both // ttf & char
19482
+ ;
19483
+ /**
19484
+ * 外描边宽度
19485
+ */ this.outlineWidth = 0 // both // ttf & char
19486
+ ;
19487
+ /**
19488
+ * 是否有阴影
19489
+ */ this.hasShadow = false // ttf
19490
+ ;
19491
+ this.fontDesc = "" // both
19492
+ ;
19493
+ /**
19494
+ * 字体倍数
19495
+ */ this.fontScale = 2;
19496
+ this.fontOffset = 0;
19497
+ var _options_textColor = options.textColor, textColor = _options_textColor === void 0 ? [
19498
+ 1,
19499
+ 1,
19500
+ 1,
19501
+ 1
19502
+ ] : _options_textColor, _options_fontSize = options.fontSize, fontSize = _options_fontSize === void 0 ? 40 : _options_fontSize, outline = options.outline, shadow = options.shadow, _options_fontWeight = options.fontWeight, fontWeight = _options_fontWeight === void 0 ? "normal" : _options_fontWeight, _options_fontStyle = options.fontStyle, fontStyle = _options_fontStyle === void 0 ? "normal" : _options_fontStyle, _options_fontFamily = options.fontFamily, fontFamily = _options_fontFamily === void 0 ? "sans-serif" : _options_fontFamily;
19503
+ this.textColor = textColor;
19504
+ //@ts-expect-error
19505
+ this.textWeight = fontWeight;
19506
+ //@ts-expect-error
19507
+ this.fontStyle = fontStyle;
19508
+ this.fontFamily = fontFamily;
19509
+ this.fontSize = fontSize; // 暂时取消字号限制 Math.min(fontSize, this.maxFontSize);
19510
+ if (outline) {
19511
+ this.isOutlined = true;
19512
+ var _outline_outlineColor;
19513
+ this.outlineColor = (_outline_outlineColor = outline.outlineColor) != null ? _outline_outlineColor : [
19514
+ 1,
19515
+ 1,
19516
+ 1,
19517
+ 1
19518
+ ];
19519
+ var _outline_outlineWidth;
19520
+ this.outlineWidth = (_outline_outlineWidth = outline.outlineWidth) != null ? _outline_outlineWidth : 1;
19521
+ this.fontOffset += this.outlineWidth;
19522
+ }
19523
+ if (shadow) {
19524
+ this.hasShadow = true;
19525
+ var _shadow_shadowBlur;
19526
+ this.shadowBlur = (_shadow_shadowBlur = shadow.shadowBlur) != null ? _shadow_shadowBlur : 2;
19527
+ var _shadow_shadowColor;
19528
+ this.shadowColor = (_shadow_shadowColor = shadow.shadowColor) != null ? _shadow_shadowColor : [
19529
+ 0,
19530
+ 0,
19531
+ 0,
19532
+ 1
19533
+ ];
19534
+ var _shadow_shadowOffsetX;
19535
+ this.shadowOffsetX = (_shadow_shadowOffsetX = shadow.shadowOffsetX) != null ? _shadow_shadowOffsetX : 0;
19536
+ var _shadow_shadowOffsetY;
19537
+ this.shadowOffsetY = (_shadow_shadowOffsetY = shadow.shadowOffsetY) != null ? _shadow_shadowOffsetY : 0;
19538
+ }
19539
+ if (this.fontStyle !== FontStyle.normal) {
19540
+ // 0.0174532925 = 3.141592653 / 180
19541
+ this.fontOffset += this.fontSize * Math.tan(12 * 0.0174532925);
19542
+ }
19543
+ };
19544
+
19545
+ var CanvasPool = /*#__PURE__*/ function() {
19546
+ function CanvasPool() {
19547
+ this.elements = [];
19548
+ }
19549
+ var _proto = CanvasPool.prototype;
19550
+ _proto.dispose = function dispose() {
19551
+ this.elements.forEach(function(e) {
19552
+ return e.remove();
19553
+ });
19554
+ // clearing the array
19555
+ this.elements.length = 0;
19556
+ };
19557
+ _proto.getCanvas = function getCanvas() {
19558
+ if (this.elements.length !== 0) {
19559
+ return this.elements.shift();
19560
+ }
19561
+ if (getConfig(TEMPLATE_USE_OFFSCREEN_CANVAS)) {
19562
+ // @ts-expect-error
19563
+ return window._createOffscreenCanvas(10, 10);
19286
19564
  } else {
19287
19565
  // in hongmeng system, create too many canvas will case render error
19288
19566
  var defCanvas = document.createElement("canvas");
@@ -20692,6 +20970,9 @@ var SerializationHelper = /*#__PURE__*/ function() {
20692
20970
  SerializationHelper.checkGLTFNode = function checkGLTFNode(value) {
20693
20971
  return _instanceof1(value, Object) && value.nodeIndex !== undefined && value.isJoint !== undefined;
20694
20972
  };
20973
+ SerializationHelper.checkImageSource = function checkImageSource(value) {
20974
+ return isCanvas(value) || _instanceof1(value, HTMLImageElement);
20975
+ };
20695
20976
  SerializationHelper.deserializeProperty = function deserializeProperty(property, engine, level, type) {
20696
20977
  if (level > 14) {
20697
20978
  console.error("序列化数据的内嵌对象层数大于上限");
@@ -20709,7 +20990,7 @@ var SerializationHelper = /*#__PURE__*/ function() {
20709
20990
  // TODO json 数据避免传 typedArray
20710
20991
  } else if (SerializationHelper.checkDataPath(property)) {
20711
20992
  return engine.assetLoader.loadGUID(property.id);
20712
- } else if (_instanceof1(property, EffectsObject) || SerializationHelper.checkTypedArray(property) || SerializationHelper.checkGLTFNode(property)) {
20993
+ } else if (_instanceof1(property, EffectsObject) || SerializationHelper.checkImageSource(property) || SerializationHelper.checkTypedArray(property) || SerializationHelper.checkGLTFNode(property)) {
20713
20994
  return property;
20714
20995
  } else if (_instanceof1(property, Object)) {
20715
20996
  var res1;
@@ -20797,7 +21078,7 @@ var SerializationHelper = /*#__PURE__*/ function() {
20797
21078
  res1
20798
21079
  ];
20799
21080
  case 8:
20800
- if (_instanceof1(property, EffectsObject) || SerializationHelper.checkTypedArray(property) || SerializationHelper.checkGLTFNode(property)) {
21081
+ if (_instanceof1(property, EffectsObject) || SerializationHelper.checkImageSource(property) || SerializationHelper.checkTypedArray(property) || SerializationHelper.checkGLTFNode(property)) {
20801
21082
  return [
20802
21083
  2,
20803
21084
  property
@@ -20920,9 +21201,8 @@ var SerializationHelper = /*#__PURE__*/ function() {
20920
21201
  effectsObject = Geometry.create(this.engine);
20921
21202
  break;
20922
21203
  case DataType.Texture:
20923
- // @ts-expect-error
20924
- effectsObject = Texture.create(this.engine, effectsObjectData);
20925
- return effectsObject;
21204
+ effectsObject = Texture.create(this.engine);
21205
+ break;
20926
21206
  default:
20927
21207
  {
20928
21208
  var classConstructor = AssetLoader.getClass(effectsObjectData.dataType);
@@ -20993,12 +21273,8 @@ var SerializationHelper = /*#__PURE__*/ function() {
20993
21273
  effectsObject = Geometry.create(_this.engine);
20994
21274
  break;
20995
21275
  case DataType.Texture:
20996
- // @ts-expect-error
20997
- effectsObject = Texture.create(_this.engine, effectsObjectData);
20998
- return [
20999
- 2,
21000
- effectsObject
21001
- ];
21276
+ effectsObject = Texture.create(_this.engine);
21277
+ break;
21002
21278
  default:
21003
21279
  {
21004
21280
  classConstructor = AssetLoader.getClass(effectsObjectData.dataType);
@@ -21918,8 +22194,15 @@ function getStandardCameraContent(model) {
21918
22194
  id: item.id
21919
22195
  };
21920
22196
  });
22197
+ var compositionData = _extends({}, composition, {
22198
+ timelineAsset: {
22199
+ id: ""
22200
+ },
22201
+ sceneBindings: []
22202
+ });
22203
+ result.compositions.push(compositionData);
21921
22204
  // 生成时间轴数据
21922
- convertTimelineAsset(composition, guidToItemMap, result);
22205
+ convertTimelineAsset(compositionData, guidToItemMap, result);
21923
22206
  };
21924
22207
  var // 更正 spine 数据中的 images 属性
21925
22208
  _json_spines;
@@ -21927,6 +22210,7 @@ function getStandardCameraContent(model) {
21927
22210
  _result;
21928
22211
  var result = _extends({}, json, {
21929
22212
  items: [],
22213
+ compositions: [],
21930
22214
  components: [],
21931
22215
  materials: [],
21932
22216
  shaders: [],
@@ -22136,10 +22420,7 @@ function getStandardCameraContent(model) {
22136
22420
  item.type = "orientation-transformer";
22137
22421
  }
22138
22422
  // item 的 content 转为 component data 加入 JSONScene.components
22139
- if (item.type === ItemType.sprite || item.type === ItemType.particle || item.type === ItemType.mesh || item.type === ItemType.skybox || item.type === ItemType.light || // @ts-expect-error
22140
- item.type === "camera" || item.type === ItemType.tree || item.type === ItemType.interact || item.type === ItemType.camera || item.type === ItemType.text || item.type === ItemType.spine || // @ts-expect-error
22141
- item.type === "editor-gizmo" || // @ts-expect-error
22142
- item.type === "orientation-transformer") {
22423
+ if (item.type === ItemType.sprite || item.type === ItemType.particle || item.type === ItemType.mesh || item.type === ItemType.skybox || item.type === ItemType.light || item.type === "camera" || item.type === ItemType.tree || item.type === ItemType.interact || item.type === ItemType.camera || item.type === ItemType.text || item.type === ItemType.spine || item.type === "editor-gizmo" || item.type === "orientation-transformer") {
22143
22424
  item.components = [];
22144
22425
  result.components.push(item.content);
22145
22426
  item.content.id = generateGUID();
@@ -22171,15 +22452,12 @@ function getStandardCameraContent(model) {
22171
22452
  case ItemType.light:
22172
22453
  item.content.dataType = DataType.LightComponent;
22173
22454
  break;
22174
- // @ts-expect-error
22175
22455
  case "camera":
22176
22456
  item.content.dataType = DataType.CameraComponent;
22177
22457
  break;
22178
- // @ts-expect-error
22179
22458
  case "editor-gizmo":
22180
22459
  item.content.dataType = "GizmoComponent";
22181
22460
  break;
22182
- // @ts-expect-error
22183
22461
  case "orientation-transformer":
22184
22462
  item.content.dataType = "OrientationComponent";
22185
22463
  break;
@@ -22332,6 +22610,32 @@ function convertTimelineAsset(composition, guidToItemMap, jsonScene) {
22332
22610
  });
22333
22611
  trackDatas.push(newTrackData1);
22334
22612
  }
22613
+ if (item.type === ItemType.composition) {
22614
+ var newSubCompositionPlayableAssetData = {
22615
+ id: generateGUID(),
22616
+ dataType: "SubCompositionPlayableAsset"
22617
+ };
22618
+ playableAssetDatas.push(newSubCompositionPlayableAssetData);
22619
+ var newTrackData2 = {
22620
+ id: generateGUID(),
22621
+ dataType: "SubCompositionTrack",
22622
+ children: [],
22623
+ clips: [
22624
+ {
22625
+ start: item.delay,
22626
+ duration: item.duration,
22627
+ endBehaviour: item.endBehavior,
22628
+ asset: {
22629
+ id: newSubCompositionPlayableAssetData.id
22630
+ }
22631
+ }
22632
+ ]
22633
+ };
22634
+ subTrackDatas.push({
22635
+ id: newTrackData2.id
22636
+ });
22637
+ trackDatas.push(newTrackData2);
22638
+ }
22335
22639
  var bindingTrackData = {
22336
22640
  id: generateGUID(),
22337
22641
  dataType: "ObjectBindingTrack",
@@ -22358,11 +22662,9 @@ function convertTimelineAsset(composition, guidToItemMap, jsonScene) {
22358
22662
  id: trackData.id
22359
22663
  });
22360
22664
  }
22361
- //@ts-expect-error
22362
22665
  composition.timelineAsset = {
22363
22666
  id: timelineAssetData.id
22364
22667
  };
22365
- //@ts-expect-error
22366
22668
  composition.sceneBindings = sceneBindings;
22367
22669
  if (!jsonScene.animations) {
22368
22670
  jsonScene.animations = [];
@@ -23607,42 +23909,6 @@ function createTextureOptionsBySource(image, sourceFrom) {
23607
23909
  }
23608
23910
  throw new Error("Invalid texture options");
23609
23911
  }
23610
- function base64ToFile(base64, filename, contentType) {
23611
- if (filename === void 0) filename = "base64File";
23612
- if (contentType === void 0) contentType = "";
23613
- // 去掉 Base64 字符串的 Data URL 部分(如果存在)
23614
- var base64WithoutPrefix = base64.split(",")[1] || base64;
23615
- // 将 base64 编码的字符串转换为二进制字符串
23616
- var byteCharacters = atob(base64WithoutPrefix);
23617
- // 创建一个 8 位无符号整数值的数组,即“字节数组”
23618
- var byteArrays = [];
23619
- // 切割二进制字符串为多个片段,并将每个片段转换成一个字节数组
23620
- for(var offset = 0; offset < byteCharacters.length; offset += 512){
23621
- var slice = byteCharacters.slice(offset, offset + 512);
23622
- var byteNumbers = new Array(slice.length);
23623
- for(var i = 0; i < slice.length; i++){
23624
- byteNumbers[i] = slice.charCodeAt(i);
23625
- }
23626
- var byteArray = new Uint8Array(byteNumbers);
23627
- byteArrays.push(byteArray);
23628
- }
23629
- // 使用字节数组创建 Blob 对象
23630
- var blob = new Blob(byteArrays, {
23631
- type: contentType
23632
- });
23633
- // 创建 File 对象
23634
- var file = new File([
23635
- blob
23636
- ], filename, {
23637
- type: contentType
23638
- });
23639
- return file;
23640
- }
23641
- function isCanvas(canvas) {
23642
- var _canvas_tagName;
23643
- // 小程序 Canvas 无法使用 instanceof HTMLCanvasElement 判断
23644
- return typeof canvas === "object" && canvas !== null && ((_canvas_tagName = canvas.tagName) == null ? void 0 : _canvas_tagName.toUpperCase()) === "CANVAS";
23645
- }
23646
23912
 
23647
23913
  var tmpScale = new Vector3(1, 1, 1);
23648
23914
  /**
@@ -23920,260 +24186,213 @@ var tmpScale = new Vector3(1, 1, 1);
23920
24186
  return Camera;
23921
24187
  }();
23922
24188
 
24189
+ var listOrder = 0;
23923
24190
  /**
23924
- * @since 2.0.0
23925
- * @internal
23926
- */ var CompositionComponent = /*#__PURE__*/ function(ItemBehaviour) {
23927
- _inherits(CompositionComponent, ItemBehaviour);
23928
- function CompositionComponent() {
23929
- var _this;
23930
- _this = ItemBehaviour.apply(this, arguments) || this;
23931
- _this.time = 0;
23932
- _this.startTime = 0;
23933
- _this.items = [] // 场景的所有元素
23934
- ;
23935
- _this.reusable = false;
23936
- _this.sceneBindings = [];
23937
- _this.masterTracks = [];
23938
- _this.graph = new PlayableGraph();
23939
- return _this;
24191
+ * 合成资源管理
24192
+ */ var CompositionSourceManager = /*#__PURE__*/ function() {
24193
+ function CompositionSourceManager(scene, engine) {
24194
+ this.refCompositions = new Map();
24195
+ this.refCompositionProps = new Map();
24196
+ this.mask = 0;
24197
+ this.engine = engine;
24198
+ // 资源
24199
+ var jsonScene = scene.jsonScene, renderLevel = scene.renderLevel, textureOptions = scene.textureOptions, pluginSystem = scene.pluginSystem, totalTime = scene.totalTime;
24200
+ var compositions = jsonScene.compositions, imgUsage = jsonScene.imgUsage, compositionId = jsonScene.compositionId;
24201
+ if (!textureOptions) {
24202
+ throw new Error("scene.textures expected");
24203
+ }
24204
+ var cachedTextures = textureOptions;
24205
+ for(var _iterator = _create_for_of_iterator_helper_loose(compositions), _step; !(_step = _iterator()).done;){
24206
+ var comp = _step.value;
24207
+ if (comp.id === compositionId) {
24208
+ this.composition = comp;
24209
+ } else {
24210
+ this.refCompositions.set(comp.id, comp);
24211
+ }
24212
+ }
24213
+ if (!this.composition) {
24214
+ throw new Error("Invalid composition id: " + compositionId);
24215
+ }
24216
+ this.jsonScene = jsonScene;
24217
+ this.renderLevel = renderLevel;
24218
+ this.pluginSystem = pluginSystem;
24219
+ this.totalTime = totalTime != null ? totalTime : 0;
24220
+ this.imgUsage = imgUsage != null ? imgUsage : {};
24221
+ this.textures = cachedTextures;
24222
+ listOrder = 0;
24223
+ this.sourceContent = this.getContent(this.composition);
23940
24224
  }
23941
- var _proto = CompositionComponent.prototype;
23942
- _proto.start = function start() {
23943
- var _this_item_props = this.item.props, _this_item_props_startTime = _this_item_props.startTime, startTime = _this_item_props_startTime === void 0 ? 0 : _this_item_props_startTime;
23944
- this.startTime = startTime;
23945
- this.masterTracks = [];
23946
- for(var _iterator = _create_for_of_iterator_helper_loose(this.sceneBindings), _step; !(_step = _iterator()).done;){
23947
- var sceneBinding = _step.value;
23948
- sceneBinding.key.binding = sceneBinding.value;
24225
+ var _proto = CompositionSourceManager.prototype;
24226
+ _proto.getContent = function getContent(composition) {
24227
+ // TODO: specification 中补充 globalVolume 类型
24228
+ // @ts-expect-error
24229
+ var id = composition.id, duration = composition.duration, name = composition.name, endBehavior = composition.endBehavior, camera = composition.camera, globalVolume = composition.globalVolume, _composition_startTime = composition.startTime, startTime = _composition_startTime === void 0 ? 0 : _composition_startTime;
24230
+ var items = this.assembleItems(composition);
24231
+ return _extends({}, composition, {
24232
+ id: id,
24233
+ duration: duration,
24234
+ name: name,
24235
+ endBehavior: isNaN(endBehavior) ? END_BEHAVIOR_PAUSE : endBehavior,
24236
+ // looping,
24237
+ items: items,
24238
+ camera: camera,
24239
+ startTime: startTime,
24240
+ globalVolume: globalVolume
24241
+ });
24242
+ };
24243
+ _proto.assembleItems = function assembleItems(composition) {
24244
+ var _this = this;
24245
+ var items = [];
24246
+ this.mask++;
24247
+ var componentMap = {};
24248
+ //@ts-expect-error
24249
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.jsonScene.components), _step; !(_step = _iterator()).done;){
24250
+ var component = _step.value;
24251
+ componentMap[component.id] = component;
23949
24252
  }
23950
- this.initializeTrackBindings(this.timelineAsset.tracks);
23951
- this.timelinePlayable = this.timelineAsset.createPlayable(this.graph);
23952
- this.timelinePlayable.play();
23953
- for(var _iterator1 = _create_for_of_iterator_helper_loose(this.timelineAsset.tracks), _step1; !(_step1 = _iterator1()).done;){
23954
- var track = _step1.value;
23955
- var binding = track.binding;
23956
- if (_instanceof1(binding, exports.VFXItem)) {
23957
- // 重播不销毁元素
23958
- if (this.item.endBehavior !== ItemEndBehavior.destroy || this.reusable) {
23959
- if (_instanceof1(track, exports.ObjectBindingTrack)) {
23960
- binding.reusable = true;
24253
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(composition.items), _step1; !(_step1 = _iterator1()).done;){
24254
+ var itemDataPath = _step1.value;
24255
+ //@ts-expect-error
24256
+ var sourceItemData = this.engine.jsonSceneData[itemDataPath.id];
24257
+ var itemProps = sourceItemData;
24258
+ if (passRenderLevel(sourceItemData.renderLevel, this.renderLevel)) {
24259
+ if (itemProps.type === ItemType.sprite || itemProps.type === ItemType.particle) {
24260
+ for(var _iterator2 = _create_for_of_iterator_helper_loose(itemProps.components), _step2; !(_step2 = _iterator2()).done;){
24261
+ var componentPath = _step2.value;
24262
+ var componentData = componentMap[componentPath.id];
24263
+ this.preProcessItemContent(componentData);
24264
+ }
24265
+ } else {
24266
+ var renderContent = itemProps.content;
24267
+ if (renderContent) {
24268
+ this.preProcessItemContent(renderContent);
24269
+ }
24270
+ }
24271
+ itemProps.listIndex = listOrder++;
24272
+ // 处理预合成的渲染顺序
24273
+ if (itemProps.type === ItemType.composition) {
24274
+ var refId = sourceItemData.content.options.refId;
24275
+ if (!this.refCompositions.get(refId)) {
24276
+ throw new Error("Invalid Ref Composition id: " + refId);
23961
24277
  }
23962
- var subCompositionComponent = binding.getComponent(CompositionComponent);
23963
- if (subCompositionComponent) {
23964
- subCompositionComponent.reusable = true;
24278
+ var ref = this.getContent(this.refCompositions.get(refId));
24279
+ if (!this.refCompositionProps.has(refId)) {
24280
+ this.refCompositionProps.set(refId, ref);
23965
24281
  }
24282
+ ref.items.forEach(function(item) {
24283
+ _this.processMask(item.content);
24284
+ });
24285
+ itemProps.items = ref.items;
23966
24286
  }
24287
+ items.push(itemProps);
23967
24288
  }
23968
- this.masterTracks.push(track);
23969
- }
23970
- };
23971
- _proto.initializeTrackBindings = function initializeTrackBindings(masterTracks) {
23972
- for(var _iterator = _create_for_of_iterator_helper_loose(masterTracks), _step; !(_step = _iterator()).done;){
23973
- var track = _step.value;
23974
- track.initializeBindingRecursive(track.binding);
23975
24289
  }
24290
+ return items;
23976
24291
  };
23977
- _proto.update = function update(dt) {
23978
- var time = this.time;
23979
- // 主合成 rootItem 没有绑定轨道,增加结束行为判断。
23980
- if (this.item.isEnded(this.time) && !this.item.parent) {
23981
- this.item.ended = true;
23982
- }
23983
- this.timelinePlayable.setTime(time);
23984
- this.graph.evaluate(dt);
23985
- for(var i = 0; i < this.items.length; i++){
23986
- var item = this.items[i];
23987
- var subCompostionComponent = item.getComponent(CompositionComponent);
23988
- if (subCompostionComponent) {
23989
- var subCompositionTrack = this.masterTracks[i];
23990
- subCompostionComponent.time = subCompositionTrack.toLocalTime(time);
24292
+ _proto.preProcessItemContent = function preProcessItemContent(renderContent) {
24293
+ if (renderContent.renderer) {
24294
+ renderContent.renderer = this.changeTex(renderContent.renderer);
24295
+ if (!renderContent.renderer.mask) {
24296
+ this.processMask(renderContent.renderer);
24297
+ }
24298
+ var split = renderContent.splits && !renderContent.textureSheetAnimation && renderContent.splits[0];
24299
+ if (Number.isInteger(renderContent.renderer.shape)) {
24300
+ var _this_jsonScene;
24301
+ // TODO: scene.shapes 类型问题?
24302
+ renderContent.renderer.shape = getGeometryByShape((_this_jsonScene = this.jsonScene) == null ? void 0 : _this_jsonScene.shapes[renderContent.renderer.shape], split);
24303
+ } else if (renderContent.renderer.shape && isObject(renderContent.renderer.shape)) {
24304
+ renderContent.renderer.shape = getGeometryByShape(renderContent.renderer.shape, split);
23991
24305
  }
23992
24306
  }
24307
+ if (renderContent.trails) {
24308
+ renderContent.trails = this.changeTex(renderContent.trails);
24309
+ }
23993
24310
  };
23994
- /**
23995
- * 重置元素状态属性
23996
- */ _proto.resetStatus = function resetStatus() {
23997
- this.item.ended = false;
23998
- };
23999
- _proto.createContent = function createContent() {
24000
- var sceneBindings = [];
24001
- for(var _iterator = _create_for_of_iterator_helper_loose(this.data.sceneBindings), _step; !(_step = _iterator()).done;){
24002
- var sceneBindingData = _step.value;
24003
- sceneBindings.push({
24004
- key: this.engine.assetLoader.loadGUID(sceneBindingData.key.id),
24005
- value: this.engine.assetLoader.loadGUID(sceneBindingData.value.id)
24006
- });
24311
+ _proto.changeTex = function changeTex(renderer) {
24312
+ if (!renderer.texture) {
24313
+ return renderer;
24007
24314
  }
24008
- this.sceneBindings = sceneBindings;
24009
- var timelineAsset = this.data.timelineAsset ? this.engine.assetLoader.loadGUID(this.data.timelineAsset.id) : new exports.TimelineAsset(this.engine);
24010
- this.timelineAsset = timelineAsset;
24011
- var items = this.items;
24012
- this.items.length = 0;
24013
- if (this.item.composition) {
24014
- var assetLoader = this.item.engine.assetLoader;
24015
- var itemProps = this.item.props.items ? this.item.props.items : [];
24016
- for(var i = 0; i < itemProps.length; i++){
24017
- var item = void 0;
24018
- var itemData = itemProps[i];
24019
- // 设置预合成作为元素时的时长、结束行为和渲染延时
24020
- if (exports.Item.isComposition(itemData)) {
24021
- var refId = itemData.content.options.refId;
24022
- var props = this.item.composition.refCompositionProps.get(refId);
24023
- if (!props) {
24024
- throw new Error("引用的Id: " + refId + " 的预合成不存在");
24025
- }
24026
- // endBehaviour 类型需优化
24027
- props.content = itemData.content;
24028
- item = assetLoader.loadGUID(itemData.id);
24029
- item.composition = this.item.composition;
24030
- var compositionComponent = item.addComponent(CompositionComponent);
24031
- compositionComponent.data = props;
24032
- compositionComponent.refId = refId;
24033
- item.transform.parentTransform = this.transform;
24034
- this.item.composition.refContent.push(item);
24035
- if (item.endBehavior === ItemEndBehavior.loop) {
24036
- this.item.composition.autoRefTex = false;
24037
- }
24038
- compositionComponent.createContent();
24039
- for(var _iterator1 = _create_for_of_iterator_helper_loose(compositionComponent.items), _step1; !(_step1 = _iterator1()).done;){
24040
- var vfxItem = _step1.value;
24041
- vfxItem.setInstanceId(generateGUID());
24042
- for(var _iterator2 = _create_for_of_iterator_helper_loose(vfxItem.components), _step2; !(_step2 = _iterator2()).done;){
24043
- var component = _step2.value;
24044
- component.setInstanceId(generateGUID());
24045
- }
24046
- }
24047
- } else {
24048
- item = assetLoader.loadGUID(itemData.id);
24049
- item.composition = this.item.composition;
24050
- }
24051
- item.parent = this.item;
24052
- // 相机不跟随合成移动
24053
- item.transform.parentTransform = itemData.type === ItemType.camera ? new Transform() : this.transform;
24054
- if (exports.VFXItem.isExtraCamera(item)) {
24055
- this.item.composition.extraCamera = item;
24056
- }
24057
- items.push(item);
24058
- }
24315
+ //@ts-expect-error
24316
+ var texIdx = renderer.texture.id;
24317
+ if (texIdx !== undefined) {
24318
+ //@ts-expect-error
24319
+ this.addTextureUsage(texIdx) || texIdx;
24059
24320
  }
24321
+ return renderer;
24060
24322
  };
24061
- _proto.onDestroy = function onDestroy() {
24062
- if (this.item.composition) {
24063
- if (this.items) {
24064
- this.items.forEach(function(item) {
24065
- return item.dispose();
24066
- });
24067
- this.items.length = 0;
24323
+ _proto.addTextureUsage = function addTextureUsage(texIdx) {
24324
+ var texId = texIdx;
24325
+ var _this_imgUsage;
24326
+ // FIXME: imageUsage 取自 scene.imgUsage,类型为 Record<string, number[]>,这里给的 number,类型对不上
24327
+ var imageUsage = (_this_imgUsage = this.imgUsage) != null ? _this_imgUsage : {};
24328
+ if (texId && imageUsage) {
24329
+ // eslint-disable-next-line no-prototype-builtins
24330
+ if (!imageUsage.hasOwnProperty(texId)) {
24331
+ imageUsage[texId] = 0;
24068
24332
  }
24333
+ imageUsage[texId]++;
24069
24334
  }
24070
24335
  };
24071
- _proto.hitTest = function hitTest(ray, x, y, regions, force, options) {
24072
- var _this, _loop = function(i) {
24073
- var item = _this.items[i];
24074
- if (item.getVisible() && !item.ended && !exports.VFXItem.isComposition(item) && !skip(item)) {
24075
- var hitParams = item.getHitTestParams(force);
24076
- if (hitParams) {
24077
- var success = false;
24078
- var intersectPoint = new Vector3();
24079
- if (hitParams.type === exports.HitTestType.triangle) {
24080
- var triangles = hitParams.triangles, backfaceCulling = hitParams.backfaceCulling;
24081
- for(var j = 0; j < triangles.length; j++){
24082
- var triangle = triangles[j];
24083
- if (ray.intersectTriangle(triangle, intersectPoint, backfaceCulling)) {
24084
- success = true;
24085
- hitPositions.push(intersectPoint);
24086
- break;
24087
- }
24088
- }
24089
- } else if (hitParams.type === exports.HitTestType.box) {
24090
- var center = hitParams.center, size = hitParams.size;
24091
- var boxMin = center.clone().addScaledVector(size, 0.5);
24092
- var boxMax = center.clone().addScaledVector(size, -0.5);
24093
- if (ray.intersectBox({
24094
- min: boxMin,
24095
- max: boxMax
24096
- }, intersectPoint)) {
24097
- success = true;
24098
- hitPositions.push(intersectPoint);
24099
- }
24100
- } else if (hitParams.type === exports.HitTestType.sphere) {
24101
- var center1 = hitParams.center, radius = hitParams.radius;
24102
- if (ray.intersectSphere({
24103
- center: center1,
24104
- radius: radius
24105
- }, intersectPoint)) {
24106
- success = true;
24107
- hitPositions.push(intersectPoint);
24108
- }
24109
- } else if (hitParams.type === exports.HitTestType.custom) {
24110
- var tempPosition = hitParams.collect(ray, new Vector2(x, y));
24111
- if (tempPosition && tempPosition.length > 0) {
24112
- tempPosition.forEach(function(pos) {
24113
- hitPositions.push(pos);
24114
- });
24115
- success = true;
24116
- }
24117
- }
24118
- if (success) {
24119
- var region = {
24120
- compContent: _this.item,
24121
- id: item.id,
24122
- name: item.name,
24123
- position: hitPositions[hitPositions.length - 1],
24124
- parentId: item.parentId,
24125
- hitPositions: hitPositions,
24126
- behavior: hitParams.behavior
24127
- };
24128
- regions.push(region);
24129
- if (stop(region)) {
24130
- return {
24131
- v: regions
24132
- };
24133
- }
24134
- }
24135
- }
24336
+ /**
24337
+ * 处理蒙版和遮挡关系写入 stencil ref
24338
+ */ _proto.processMask = function processMask(renderer) {
24339
+ var maskMode = renderer.maskMode;
24340
+ if (maskMode === MaskMode.NONE) {
24341
+ return;
24342
+ }
24343
+ if (!renderer.mask) {
24344
+ if (maskMode === MaskMode.MASK) {
24345
+ renderer.mask = ++this.mask;
24346
+ } else if (maskMode === MaskMode.OBSCURED || maskMode === MaskMode.REVERSE_OBSCURED) {
24347
+ renderer.mask = this.mask;
24136
24348
  }
24137
- };
24138
- var hitPositions = [];
24139
- var stop = (options == null ? void 0 : options.stop) || noop;
24140
- var skip = (options == null ? void 0 : options.skip) || noop;
24141
- var maxCount = (options == null ? void 0 : options.maxCount) || this.items.length;
24142
- for(var i = 0; i < this.items.length && regions.length < maxCount; i++){
24143
- var _ret = (_this = this, _loop(i));
24144
- if (_type_of(_ret) === "object") return _ret.v;
24145
24349
  }
24146
- return regions;
24147
24350
  };
24148
- _proto.fromData = function fromData(data) {
24149
- // this.timelineAsset = data.timelineAsset;
24351
+ _proto.dispose = function dispose() {
24352
+ this.textures = [];
24353
+ this.composition = undefined;
24354
+ this.jsonScene = undefined;
24355
+ this.totalTime = 0;
24356
+ this.pluginSystem = undefined;
24357
+ this.sourceContent = undefined;
24358
+ this.refCompositions.clear();
24359
+ this.refCompositionProps.clear();
24150
24360
  };
24151
- return CompositionComponent;
24152
- }(ItemBehaviour);
24361
+ return CompositionSourceManager;
24362
+ }();
24153
24363
 
24154
24364
  /**
24155
24365
  * 合成抽象类:核心对象,通常一个场景只包含一个合成,可能会有多个合成。
24156
24366
  * 合成中包含了相关的 Item 元素,支持对 Item 元素的创建、更新和销毁。
24157
24367
  * 也负责 Item 相关的动画播放控制,和持有渲染帧数据。
24158
24368
  */ var Composition = /*#__PURE__*/ function() {
24159
- function Composition(props, scene, compositionSourceManager) {
24369
+ function Composition(props, scene) {
24160
24370
  var _this = this;
24161
- this.compositionSourceManager = compositionSourceManager;
24162
- this./**
24371
+ /**
24163
24372
  * 动画播放速度
24164
- */ speed = 1;
24165
- this.loaderData = {};
24166
- this.refContent = [];
24167
- this./**
24373
+ */ this.speed = 1;
24374
+ /**
24375
+ * 用于保存与当前合成相关的插件数据
24376
+ */ this.loaderData = {};
24377
+ /**
24378
+ * 预合成数组
24379
+ */ this.refContent = [];
24380
+ /**
24168
24381
  * 预合成的合成属性,在 content 中会被其元素属性覆盖
24169
- */ refCompositionProps = new Map();
24382
+ */ this.refCompositionProps = new Map();
24170
24383
  this.editorScaleRatio = 1.0;
24384
+ // TODO: 待优化
24171
24385
  this.assigned = false;
24172
- this.destroyed = false;
24173
- this.paused = false;
24386
+ /**
24387
+ * 销毁状态位
24388
+ */ this.destroyed = false;
24389
+ /**
24390
+ * 合成暂停/播放 标识
24391
+ */ this.paused = false;
24174
24392
  this.lastVideoUpdateTime = 0;
24175
24393
  this.postLoaders = [];
24176
24394
  var _props_reusable = props.reusable, reusable = _props_reusable === void 0 ? false : _props_reusable, _props_speed = props.speed, speed = _props_speed === void 0 ? 1 : _props_speed, _props_baseRenderOrder = props.baseRenderOrder, baseRenderOrder = _props_baseRenderOrder === void 0 ? 0 : _props_baseRenderOrder, renderer = props.renderer, onPlayerPause = props.onPlayerPause, onMessageItem = props.onMessageItem, onEnd = props.onEnd, event = props.event, width = props.width, height = props.height;
24395
+ this.compositionSourceManager = new CompositionSourceManager(scene, renderer.engine);
24177
24396
  scene.jsonScene.imgUsage = undefined;
24178
24397
  if (reusable) {
24179
24398
  this.keepResource = true;
@@ -24184,19 +24403,12 @@ var tmpScale = new Vector3(1, 1, 1);
24184
24403
  assertExist(sourceContent);
24185
24404
  this.renderer = renderer;
24186
24405
  this.refCompositionProps = refCompositionProps;
24187
- var vfxItem = new exports.VFXItem(this.getEngine(), sourceContent);
24188
- vfxItem.name = "rootItem";
24189
- // TODO 编辑器数据传入 composition type 后移除
24190
- vfxItem.type = ItemType.composition;
24191
- vfxItem.composition = this;
24192
- this.rootComposition = vfxItem.addComponent(CompositionComponent);
24406
+ this.rootItem = new exports.VFXItem(this.getEngine(), sourceContent);
24407
+ this.rootItem.name = "rootItem";
24408
+ this.rootItem.composition = this;
24409
+ this.rootComposition = this.rootItem.addComponent(CompositionComponent);
24193
24410
  this.rootComposition.data = sourceContent;
24194
24411
  var imageUsage = !reusable && imgUsage;
24195
- this.transform = new Transform({
24196
- name: this.name
24197
- });
24198
- this.transform.engine = this.getEngine();
24199
- vfxItem.transform = this.transform;
24200
24412
  this.globalVolume = sourceContent.globalVolume;
24201
24413
  this.width = width;
24202
24414
  this.height = height;
@@ -24214,8 +24426,7 @@ var tmpScale = new Vector3(1, 1, 1);
24214
24426
  this.reusable = reusable;
24215
24427
  this.speed = speed;
24216
24428
  this.renderLevel = renderLevel;
24217
- this.autoRefTex = !this.keepResource && imageUsage && vfxItem.endBehavior !== ItemEndBehavior.loop;
24218
- this.rootItem = vfxItem;
24429
+ this.autoRefTex = !this.keepResource && imageUsage && this.rootItem.endBehavior !== ItemEndBehavior.loop;
24219
24430
  this.name = sourceContent.name;
24220
24431
  this.pluginSystem = pluginSystem;
24221
24432
  this.pluginSystem.initializeComposition(this, scene);
@@ -24248,16 +24459,8 @@ var tmpScale = new Vector3(1, 1, 1);
24248
24459
  /**
24249
24460
  * 重新开始合成
24250
24461
  */ _proto.restart = function restart() {
24251
- // const contentItems = this.rootComposition.items;
24252
- // contentItems.forEach(item => item.dispose());
24253
- // contentItems.length = 0;
24254
- this.prepareRender();
24255
24462
  this.reset();
24256
- this.transform.setValid(true);
24257
- this.rootComposition.resetStatus();
24258
24463
  this.forwardTime(this.startTime);
24259
- // this.content.onUpdate(0);
24260
- // this.loaderData.spriteGroup.onUpdate(0);
24261
24464
  };
24262
24465
  /**
24263
24466
  * 设置当前合成的渲染顺序
@@ -24385,28 +24588,9 @@ var tmpScale = new Vector3(1, 1, 1);
24385
24588
  /**
24386
24589
  * 重置状态函数
24387
24590
  */ _proto.reset = function reset() {
24388
- var _this = this;
24389
- var vfxItem = new exports.VFXItem(this.getEngine(), this.compositionSourceManager.sourceContent);
24390
- // TODO 编辑器数据传入 composition type 后移除
24391
- vfxItem.type = ItemType.composition;
24392
- vfxItem.composition = this;
24393
- this.rootComposition = vfxItem.addComponent(CompositionComponent);
24394
- this.rootComposition.data = this.compositionSourceManager.sourceContent;
24395
- this.transform = new Transform({
24396
- name: this.name
24397
- });
24398
- this.transform.engine = this.getEngine();
24399
- vfxItem.transform = this.transform;
24400
- this.rootItem = vfxItem;
24401
24591
  this.rendererOptions = null;
24402
24592
  this.globalTime = 0;
24403
- this.rootComposition.createContent();
24404
- this.buildItemTree(this.rootItem);
24405
- this.rootItem.onEnd = function() {
24406
- window.setTimeout(function() {
24407
- _this.onEnd == null ? void 0 : _this.onEnd.call(_this, _this);
24408
- }, 0);
24409
- };
24593
+ this.rootItem.ended = false;
24410
24594
  this.pluginSystem.resetComposition(this, this.renderFrame);
24411
24595
  };
24412
24596
  _proto.prepareRender = function prepareRender() {
@@ -24452,7 +24636,6 @@ var tmpScale = new Vector3(1, 1, 1);
24452
24636
  }
24453
24637
  var _this_rootItem = this.rootItem, ended = _this_rootItem.ended, endBehavior = _this_rootItem.endBehavior;
24454
24638
  // TODO: 合成结束行为
24455
- // @ts-expect-error
24456
24639
  return ended && (!endBehavior || endBehavior === END_BEHAVIOR_PAUSE_AND_DESTROY);
24457
24640
  };
24458
24641
  /**
@@ -24548,7 +24731,7 @@ var tmpScale = new Vector3(1, 1, 1);
24548
24731
  var child = _step2.value;
24549
24732
  if (exports.VFXItem.isComposition(child)) {
24550
24733
  if (child.ended && child.endBehavior === ItemEndBehavior.loop) {
24551
- child.getComponent(CompositionComponent).resetStatus();
24734
+ child.ended = false;
24552
24735
  // TODO K帧动画在元素重建后需要 tick ,否则会导致元素位置和 k 帧第一帧位置不一致
24553
24736
  this.callUpdate(child, 0);
24554
24737
  } else {
@@ -24955,6 +25138,14 @@ var tmpScale = new Vector3(1, 1, 1);
24955
25138
  })();
24956
25139
  };
24957
25140
  _create_class(Composition, [
25141
+ {
25142
+ key: "transform",
25143
+ get: /**
25144
+ * 所有合成 Item 的根变换
25145
+ */ function get() {
25146
+ return this.rootItem.transform;
25147
+ }
25148
+ },
24958
25149
  {
24959
25150
  key: "textures",
24960
25151
  get: /**
@@ -25000,189 +25191,6 @@ var tmpScale = new Vector3(1, 1, 1);
25000
25191
  return Composition;
25001
25192
  }();
25002
25193
 
25003
- var listOrder = 0;
25004
- /**
25005
- * 合成资源管理
25006
- */ var CompositionSourceManager = /*#__PURE__*/ function() {
25007
- function CompositionSourceManager(scene, engine) {
25008
- this.refCompositions = new Map();
25009
- this.refCompositionProps = new Map();
25010
- this.mask = 0;
25011
- this.engine = engine;
25012
- // 资源
25013
- var jsonScene = scene.jsonScene, renderLevel = scene.renderLevel, textureOptions = scene.textureOptions, pluginSystem = scene.pluginSystem, totalTime = scene.totalTime;
25014
- var compositions = jsonScene.compositions, imgUsage = jsonScene.imgUsage, compositionId = jsonScene.compositionId;
25015
- if (!textureOptions) {
25016
- throw new Error("scene.textures expected");
25017
- }
25018
- var cachedTextures = textureOptions;
25019
- for(var _iterator = _create_for_of_iterator_helper_loose(compositions), _step; !(_step = _iterator()).done;){
25020
- var comp = _step.value;
25021
- if (comp.id === compositionId) {
25022
- this.composition = comp;
25023
- } else {
25024
- this.refCompositions.set(comp.id, comp);
25025
- }
25026
- }
25027
- if (!this.composition) {
25028
- throw new Error("Invalid composition id: " + compositionId);
25029
- }
25030
- this.jsonScene = jsonScene;
25031
- this.renderLevel = renderLevel;
25032
- this.pluginSystem = pluginSystem;
25033
- this.totalTime = totalTime != null ? totalTime : 0;
25034
- this.imgUsage = imgUsage != null ? imgUsage : {};
25035
- this.textures = cachedTextures;
25036
- listOrder = 0;
25037
- this.sourceContent = this.getContent(this.composition);
25038
- }
25039
- var _proto = CompositionSourceManager.prototype;
25040
- _proto.getContent = function getContent(composition) {
25041
- // TODO: specification 中补充 globalVolume 类型
25042
- // @ts-expect-error
25043
- var id = composition.id, duration = composition.duration, name = composition.name, endBehavior = composition.endBehavior, camera = composition.camera, globalVolume = composition.globalVolume, _composition_startTime = composition.startTime, startTime = _composition_startTime === void 0 ? 0 : _composition_startTime, timelineAsset = composition.timelineAsset;
25044
- var items = this.assembleItems(composition);
25045
- //@ts-expect-error
25046
- if (!composition.sceneBindings) {
25047
- //@ts-expect-error
25048
- composition.sceneBindings = [];
25049
- }
25050
- return {
25051
- id: id,
25052
- duration: duration,
25053
- name: name,
25054
- endBehavior: isNaN(endBehavior) ? END_BEHAVIOR_PAUSE : endBehavior,
25055
- // looping,
25056
- items: items,
25057
- camera: camera,
25058
- startTime: startTime,
25059
- globalVolume: globalVolume,
25060
- timelineAsset: timelineAsset,
25061
- //@ts-expect-error
25062
- sceneBindings: composition.sceneBindings
25063
- };
25064
- };
25065
- _proto.assembleItems = function assembleItems(composition) {
25066
- var _this = this;
25067
- var items = [];
25068
- this.mask++;
25069
- var componentMap = {};
25070
- //@ts-expect-error
25071
- for(var _iterator = _create_for_of_iterator_helper_loose(this.jsonScene.components), _step; !(_step = _iterator()).done;){
25072
- var component = _step.value;
25073
- componentMap[component.id] = component;
25074
- }
25075
- for(var _iterator1 = _create_for_of_iterator_helper_loose(composition.items), _step1; !(_step1 = _iterator1()).done;){
25076
- var itemDataPath = _step1.value;
25077
- //@ts-expect-error
25078
- var sourceItemData = this.engine.jsonSceneData[itemDataPath.id];
25079
- var itemProps = sourceItemData;
25080
- if (passRenderLevel(sourceItemData.renderLevel, this.renderLevel)) {
25081
- if (itemProps.type === ItemType.sprite || itemProps.type === ItemType.particle) {
25082
- for(var _iterator2 = _create_for_of_iterator_helper_loose(itemProps.components), _step2; !(_step2 = _iterator2()).done;){
25083
- var componentPath = _step2.value;
25084
- var componentData = componentMap[componentPath.id];
25085
- this.preProcessItemContent(componentData);
25086
- }
25087
- } else {
25088
- var renderContent = itemProps.content;
25089
- if (renderContent) {
25090
- this.preProcessItemContent(renderContent);
25091
- }
25092
- }
25093
- itemProps.listIndex = listOrder++;
25094
- // 处理预合成的渲染顺序
25095
- if (itemProps.type === ItemType.composition) {
25096
- var refId = sourceItemData.content.options.refId;
25097
- if (!this.refCompositions.get(refId)) {
25098
- throw new Error("Invalid Ref Composition id: " + refId);
25099
- }
25100
- var ref = this.getContent(this.refCompositions.get(refId));
25101
- if (!this.refCompositionProps.has(refId)) {
25102
- this.refCompositionProps.set(refId, ref);
25103
- }
25104
- ref.items.forEach(function(item) {
25105
- _this.processMask(item.content);
25106
- });
25107
- itemProps.items = ref.items;
25108
- }
25109
- items.push(itemProps);
25110
- }
25111
- }
25112
- return items;
25113
- };
25114
- _proto.preProcessItemContent = function preProcessItemContent(renderContent) {
25115
- if (renderContent.renderer) {
25116
- renderContent.renderer = this.changeTex(renderContent.renderer);
25117
- if (!renderContent.renderer.mask) {
25118
- this.processMask(renderContent.renderer);
25119
- }
25120
- var split = renderContent.splits && !renderContent.textureSheetAnimation && renderContent.splits[0];
25121
- if (Number.isInteger(renderContent.renderer.shape)) {
25122
- var _this_jsonScene;
25123
- // TODO: scene.shapes 类型问题?
25124
- renderContent.renderer.shape = getGeometryByShape((_this_jsonScene = this.jsonScene) == null ? void 0 : _this_jsonScene.shapes[renderContent.renderer.shape], split);
25125
- } else if (renderContent.renderer.shape && isObject(renderContent.renderer.shape)) {
25126
- renderContent.renderer.shape = getGeometryByShape(renderContent.renderer.shape, split);
25127
- }
25128
- }
25129
- if (renderContent.trails) {
25130
- renderContent.trails = this.changeTex(renderContent.trails);
25131
- }
25132
- };
25133
- _proto.changeTex = function changeTex(renderer) {
25134
- if (!renderer.texture) {
25135
- return renderer;
25136
- }
25137
- //@ts-expect-error
25138
- var texIdx = renderer.texture.id;
25139
- if (texIdx !== undefined) {
25140
- //@ts-expect-error
25141
- this.addTextureUsage(texIdx) || texIdx;
25142
- }
25143
- return renderer;
25144
- };
25145
- _proto.addTextureUsage = function addTextureUsage(texIdx) {
25146
- var texId = texIdx;
25147
- var _this_imgUsage;
25148
- // FIXME: imageUsage 取自 scene.imgUsage,类型为 Record<string, number[]>,这里给的 number,类型对不上
25149
- var imageUsage = (_this_imgUsage = this.imgUsage) != null ? _this_imgUsage : {};
25150
- if (texId && imageUsage) {
25151
- // eslint-disable-next-line no-prototype-builtins
25152
- if (!imageUsage.hasOwnProperty(texId)) {
25153
- imageUsage[texId] = 0;
25154
- }
25155
- imageUsage[texId]++;
25156
- }
25157
- };
25158
- /**
25159
- * 处理蒙版和遮挡关系写入 stencil 的 ref 值
25160
- */ _proto.processMask = function processMask(renderer) {
25161
- var maskMode = renderer.maskMode;
25162
- if (maskMode === MaskMode.NONE) {
25163
- return;
25164
- }
25165
- if (!renderer.mask) {
25166
- if (maskMode === MaskMode.MASK) {
25167
- renderer.mask = ++this.mask;
25168
- } else if (maskMode === MaskMode.OBSCURED || maskMode === MaskMode.REVERSE_OBSCURED) {
25169
- renderer.mask = this.mask;
25170
- }
25171
- }
25172
- };
25173
- _proto.dispose = function dispose() {
25174
- this.textures = [];
25175
- this.composition = undefined;
25176
- this.jsonScene = undefined;
25177
- this.totalTime = 0;
25178
- this.pluginSystem = undefined;
25179
- this.sourceContent = undefined;
25180
- this.refCompositions.clear();
25181
- this.refCompositionProps.clear();
25182
- };
25183
- return CompositionSourceManager;
25184
- }();
25185
-
25186
25194
  /**
25187
25195
  * Engine 基类,负责维护所有 GPU 资源的管理及销毁
25188
25196
  */ var Engine = /*#__PURE__*/ function() {
@@ -25223,61 +25231,46 @@ var listOrder = 0;
25223
25231
  delete this.objectInstance[id];
25224
25232
  };
25225
25233
  _proto.addPackageDatas = function addPackageDatas(scene) {
25226
- var jsonScene = scene.jsonScene;
25227
- if (jsonScene.items) {
25228
- for(var _iterator = _create_for_of_iterator_helper_loose(jsonScene.items), _step; !(_step = _iterator()).done;){
25229
- var vfxItemData = _step.value;
25230
- this.addEffectsObjectData(vfxItemData);
25231
- }
25232
- }
25233
- if (jsonScene.materials) {
25234
- for(var _iterator1 = _create_for_of_iterator_helper_loose(jsonScene.materials), _step1; !(_step1 = _iterator1()).done;){
25235
- var materialData = _step1.value;
25236
- this.addEffectsObjectData(materialData);
25237
- }
25238
- }
25239
- if (jsonScene.shaders) {
25240
- for(var _iterator2 = _create_for_of_iterator_helper_loose(jsonScene.shaders), _step2; !(_step2 = _iterator2()).done;){
25241
- var shaderData = _step2.value;
25242
- this.addEffectsObjectData(shaderData);
25243
- }
25244
- }
25245
- if (jsonScene.geometries) {
25246
- for(var _iterator3 = _create_for_of_iterator_helper_loose(jsonScene.geometries), _step3; !(_step3 = _iterator3()).done;){
25247
- var geometryData = _step3.value;
25248
- this.addEffectsObjectData(geometryData);
25249
- }
25250
- }
25251
- if (jsonScene.components) {
25252
- for(var _iterator4 = _create_for_of_iterator_helper_loose(jsonScene.components), _step4; !(_step4 = _iterator4()).done;){
25253
- var componentData = _step4.value;
25254
- this.addEffectsObjectData(componentData);
25255
- }
25256
- }
25257
- if (jsonScene.animations) {
25258
- for(var _iterator5 = _create_for_of_iterator_helper_loose(jsonScene.animations), _step5; !(_step5 = _iterator5()).done;){
25259
- var animationData = _step5.value;
25260
- this.addEffectsObjectData(animationData);
25261
- }
25262
- }
25263
- if (jsonScene.bins) {
25264
- for(var i = 0; i < jsonScene.bins.length; i++){
25265
- var binaryData = jsonScene.bins[i];
25266
- var binaryBuffer = scene.bins[i];
25267
- //@ts-expect-error
25268
- binaryData.buffer = binaryBuffer;
25234
+ var jsonScene = scene.jsonScene, _scene_textureOptions = scene.textureOptions, textureOptions = _scene_textureOptions === void 0 ? [] : _scene_textureOptions;
25235
+ var _jsonScene_items = jsonScene.items, items = _jsonScene_items === void 0 ? [] : _jsonScene_items, _jsonScene_materials = jsonScene.materials, materials = _jsonScene_materials === void 0 ? [] : _jsonScene_materials, _jsonScene_shaders = jsonScene.shaders, shaders = _jsonScene_shaders === void 0 ? [] : _jsonScene_shaders, _jsonScene_geometries = jsonScene.geometries, geometries = _jsonScene_geometries === void 0 ? [] : _jsonScene_geometries, _jsonScene_components = jsonScene.components, components = _jsonScene_components === void 0 ? [] : _jsonScene_components, _jsonScene_animations = jsonScene.animations, animations = _jsonScene_animations === void 0 ? [] : _jsonScene_animations, _jsonScene_bins = jsonScene.bins, bins = _jsonScene_bins === void 0 ? [] : _jsonScene_bins;
25236
+ for(var _iterator = _create_for_of_iterator_helper_loose(items), _step; !(_step = _iterator()).done;){
25237
+ var vfxItemData = _step.value;
25238
+ this.addEffectsObjectData(vfxItemData);
25239
+ }
25240
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(materials), _step1; !(_step1 = _iterator1()).done;){
25241
+ var materialData = _step1.value;
25242
+ this.addEffectsObjectData(materialData);
25243
+ }
25244
+ for(var _iterator2 = _create_for_of_iterator_helper_loose(shaders), _step2; !(_step2 = _iterator2()).done;){
25245
+ var shaderData = _step2.value;
25246
+ this.addEffectsObjectData(shaderData);
25247
+ }
25248
+ for(var _iterator3 = _create_for_of_iterator_helper_loose(geometries), _step3; !(_step3 = _iterator3()).done;){
25249
+ var geometryData = _step3.value;
25250
+ this.addEffectsObjectData(geometryData);
25251
+ }
25252
+ for(var _iterator4 = _create_for_of_iterator_helper_loose(components), _step4; !(_step4 = _iterator4()).done;){
25253
+ var componentData = _step4.value;
25254
+ this.addEffectsObjectData(componentData);
25255
+ }
25256
+ for(var _iterator5 = _create_for_of_iterator_helper_loose(animations), _step5; !(_step5 = _iterator5()).done;){
25257
+ var animationData = _step5.value;
25258
+ this.addEffectsObjectData(animationData);
25259
+ }
25260
+ for(var i = 0; i < bins.length; i++){
25261
+ var binaryData = bins[i];
25262
+ var binaryBuffer = scene.bins[i];
25263
+ //@ts-expect-error
25264
+ binaryData.buffer = binaryBuffer;
25265
+ //@ts-expect-error
25266
+ if (binaryData.id) {
25269
25267
  //@ts-expect-error
25270
- if (binaryData.id) {
25271
- //@ts-expect-error
25272
- this.addEffectsObjectData(binaryData);
25273
- }
25268
+ this.addEffectsObjectData(binaryData);
25274
25269
  }
25275
25270
  }
25276
- if (scene.textureOptions) {
25277
- for(var _iterator6 = _create_for_of_iterator_helper_loose(scene.textureOptions), _step6; !(_step6 = _iterator6()).done;){
25278
- var textureData = _step6.value;
25279
- this.addEffectsObjectData(textureData);
25280
- }
25271
+ for(var _iterator6 = _create_for_of_iterator_helper_loose(textureOptions), _step6; !(_step6 = _iterator6()).done;){
25272
+ var textureData = _step6.value;
25273
+ this.addEffectsObjectData(textureData);
25281
25274
  }
25282
25275
  };
25283
25276
  _proto.createVFXItems = function createVFXItems(scene) {
@@ -25297,9 +25290,7 @@ var listOrder = 0;
25297
25290
  ];
25298
25291
  itemData = _step.value;
25299
25292
  itemType = itemData.type;
25300
- if (!// @ts-expect-error
25301
- (itemType === "ECS" || // @ts-expect-error
25302
- itemType === "camera" || itemType === ItemType.sprite || itemType === ItemType.particle || itemType === ItemType.mesh || itemType === ItemType.skybox || itemType === ItemType.light || itemType === ItemType.tree || itemType === ItemType.interact || itemType === ItemType.camera)) {
25293
+ if (!(itemType === "ECS" || itemType === "camera" || itemType === ItemType.sprite || itemType === ItemType.particle || itemType === ItemType.mesh || itemType === ItemType.skybox || itemType === ItemType.light || itemType === ItemType.tree || itemType === ItemType.interact || itemType === ItemType.camera)) {
25303
25294
  return [
25304
25295
  3,
25305
25296
  3
@@ -25416,19 +25407,19 @@ var listOrder = 0;
25416
25407
  logger.warn("Release GPU memory: " + info.join(", "));
25417
25408
  }
25418
25409
  this.renderPasses.forEach(function(pass) {
25419
- pass.dispose();
25410
+ return pass.dispose();
25420
25411
  });
25421
25412
  this.meshes.forEach(function(mesh) {
25422
- mesh.dispose();
25413
+ return mesh.dispose();
25423
25414
  });
25424
25415
  this.geometries.forEach(function(geo) {
25425
- geo.dispose();
25416
+ return geo.dispose();
25426
25417
  });
25427
25418
  this.materials.forEach(function(mat) {
25428
- mat.dispose();
25419
+ return mat.dispose();
25429
25420
  });
25430
25421
  this.textures.forEach(function(tex) {
25431
- tex.dispose();
25422
+ return tex.dispose();
25432
25423
  });
25433
25424
  this.textures = [];
25434
25425
  this.materials = [];
@@ -26741,11 +26732,8 @@ var seed = 1;
26741
26732
  * composition 抽象类的实现
26742
26733
  */ var ThreeComposition = /*#__PURE__*/ function(Composition) {
26743
26734
  _inherits(ThreeComposition, Composition);
26744
- function ThreeComposition(props, scene, compositionSourceManager) {
26745
- var _this;
26746
- _this = Composition.call(this, props, scene, compositionSourceManager) || this;
26747
- _this.rootItem.getComponent(CompositionComponent).resetStatus();
26748
- return _this;
26735
+ function ThreeComposition(props, scene) {
26736
+ return Composition.call(this, props, scene);
26749
26737
  }
26750
26738
  var _proto = ThreeComposition.prototype;
26751
26739
  /**
@@ -26937,7 +26925,7 @@ var ThreeRenderer = /*#__PURE__*/ function(Renderer) {
26937
26925
  if (options === void 0) options = {};
26938
26926
  var _this = this;
26939
26927
  return _async_to_generator(function() {
26940
- var last, opts, source, scene, engine, i, compositionSourceManager, composition, firstFrameTime;
26928
+ var last, opts, source, scene, engine, i, composition, firstFrameTime;
26941
26929
  return __generator(this, function(_state) {
26942
26930
  switch(_state.label){
26943
26931
  case 0:
@@ -26974,7 +26962,6 @@ var ThreeRenderer = /*#__PURE__*/ function(Renderer) {
26974
26962
  scene.textureOptions[i] = engine.assetLoader.loadGUID(scene.textureOptions[i].id);
26975
26963
  scene.textureOptions[i].initialize();
26976
26964
  }
26977
- compositionSourceManager = new CompositionSourceManager(scene, engine);
26978
26965
  if (!engine.database) return [
26979
26966
  3,
26980
26967
  3
@@ -26991,7 +26978,7 @@ var ThreeRenderer = /*#__PURE__*/ function(Renderer) {
26991
26978
  width: _this.width,
26992
26979
  height: _this.height,
26993
26980
  renderer: _this.renderer
26994
- }), scene, compositionSourceManager);
26981
+ }), scene);
26995
26982
  _this.renderer.engine.setOptions({
26996
26983
  threeCamera: _this.camera,
26997
26984
  threeGroup: _this,
@@ -27170,7 +27157,7 @@ setMaxSpriteMeshItemCount(8);
27170
27157
  */ Mesh.create = function(engine, props) {
27171
27158
  return new ThreeMesh(engine, props);
27172
27159
  };
27173
- var version = "2.0.0-alpha.14";
27160
+ var version = "2.0.0-alpha.15";
27174
27161
  logger.info("THREEJS plugin version: " + version);
27175
27162
 
27176
27163
  exports.AbstractPlugin = AbstractPlugin;
@@ -27282,6 +27269,7 @@ exports.addItem = addItem;
27282
27269
  exports.addItemWithOrder = addItemWithOrder;
27283
27270
  exports.assertExist = assertExist;
27284
27271
  exports.asserts = asserts;
27272
+ exports.base64ToFile = base64ToFile;
27285
27273
  exports.blend = blend;
27286
27274
  exports.calculateTranslation = calculateTranslation;
27287
27275
  exports.canvasPool = canvasPool;
@@ -27350,6 +27338,7 @@ exports.interpolateColor = interpolateColor;
27350
27338
  exports.isAlipayMiniApp = isAlipayMiniApp;
27351
27339
  exports.isAndroid = isAndroid;
27352
27340
  exports.isArray = isArray;
27341
+ exports.isCanvas = isCanvas;
27353
27342
  exports.isFunction = isFunction;
27354
27343
  exports.isIOS = isIOS;
27355
27344
  exports.isObject = isObject;