@galacean/effects-threejs 1.2.2 → 1.3.0-alpha.0

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: v1.2.2
6
+ * Version: v1.3.0-alpha.0
7
7
  */
8
8
 
9
9
  'use strict';
@@ -708,7 +708,7 @@ function asserts(condition, msg) {
708
708
  * Name: @galacean/effects-specification
709
709
  * Description: Galacean Effects JSON Specification
710
710
  * Author: Ant Group CO., Ltd.
711
- * Version: v1.0.1
711
+ * Version: v1.1.0-alpha.0
712
712
  */
713
713
 
714
714
  /*********************************************/
@@ -1089,6 +1089,16 @@ var CompositionEndBehavior$1;
1089
1089
  CompositionEndBehavior[CompositionEndBehavior["pause_destroy"] = END_BEHAVIOR_PAUSE_AND_DESTROY$1] = "pause_destroy";
1090
1090
  })(CompositionEndBehavior$1 || (CompositionEndBehavior$1 = {}));
1091
1091
 
1092
+ /**
1093
+ * 动态换图类型
1094
+ * @since 1.3.0
1095
+ */
1096
+ var BackgroundType$1;
1097
+ (function (BackgroundType) {
1098
+ BackgroundType["video"] = "video";
1099
+ BackgroundType["image"] = "image";
1100
+ })(BackgroundType$1 || (BackgroundType$1 = {}));
1101
+
1092
1102
  /*********************************************/
1093
1103
  /* 基本数值属性参数 */
1094
1104
  /*********************************************/
@@ -1378,6 +1388,7 @@ var FontStyle$1;
1378
1388
 
1379
1389
  var index$1 = /*#__PURE__*/Object.freeze({
1380
1390
  __proto__: null,
1391
+ get BackgroundType () { return BackgroundType$1; },
1381
1392
  get BezierKeyframeType () { return BezierKeyframeType$1; },
1382
1393
  get BlendingMode () { return BlendingMode$1; },
1383
1394
  BloomFilterThresholdAvgColor: BloomFilterThresholdAvgColor,
@@ -10175,10 +10186,8 @@ function loadBlob(url) {
10175
10186
  /**
10176
10187
  * 异步加载一个视频文件
10177
10188
  * @param url - 视频文件的 URL 或 MediaProvider 对象
10178
- * @param options - 加载参数
10179
10189
  */
10180
- function loadVideo(url, options) {
10181
- if (options === void 0) { options = {}; }
10190
+ function loadVideo(url) {
10182
10191
  return __awaiter(this, void 0, void 0, function () {
10183
10192
  var video;
10184
10193
  return __generator(this, function (_a) {
@@ -10191,9 +10200,6 @@ function loadVideo(url, options) {
10191
10200
  }
10192
10201
  video.crossOrigin = 'anonymous';
10193
10202
  video.muted = true;
10194
- if (options.loop) {
10195
- video.addEventListener('ended', function () { return video.play(); });
10196
- }
10197
10203
  if (isAndroid()) {
10198
10204
  video.setAttribute('renderer', 'standard');
10199
10205
  }
@@ -19677,6 +19683,26 @@ function getBackgroundImage(template, variables) {
19677
19683
  }
19678
19684
  return templateBackground;
19679
19685
  }
19686
+ function loadMedia(url, loadFn) {
19687
+ return __awaiter(this, void 0, void 0, function () {
19688
+ return __generator(this, function (_a) {
19689
+ switch (_a.label) {
19690
+ case 0:
19691
+ if (!Array.isArray(url)) return [3 /*break*/, 5];
19692
+ _a.label = 1;
19693
+ case 1:
19694
+ _a.trys.push([1, 3, , 5]);
19695
+ return [4 /*yield*/, loadFn(url[0])];
19696
+ case 2: return [2 /*return*/, _a.sent()];
19697
+ case 3:
19698
+ _a.sent();
19699
+ return [4 /*yield*/, loadFn(url[1])];
19700
+ case 4: return [2 /*return*/, _a.sent()];
19701
+ case 5: return [2 /*return*/, loadFn(url)];
19702
+ }
19703
+ });
19704
+ });
19705
+ }
19680
19706
  function drawImageAndTemplate(viewer, image, template, variables, opt) {
19681
19707
  var _a;
19682
19708
  return __awaiter(this, void 0, void 0, function () {
@@ -21568,7 +21594,7 @@ var filters = {
21568
21594
  * Name: @galacean/effects-specification
21569
21595
  * Description: Galacean Effects JSON Specification
21570
21596
  * Author: Ant Group CO., Ltd.
21571
- * Version: v1.0.1
21597
+ * Version: v1.1.0-alpha.0
21572
21598
  */
21573
21599
 
21574
21600
  /*********************************************/
@@ -21947,6 +21973,16 @@ var CompositionEndBehavior;
21947
21973
  CompositionEndBehavior[CompositionEndBehavior["pause_destroy"] = END_BEHAVIOR_PAUSE_AND_DESTROY] = "pause_destroy";
21948
21974
  })(CompositionEndBehavior || (CompositionEndBehavior = {}));
21949
21975
 
21976
+ /**
21977
+ * 动态换图类型
21978
+ * @since 1.3.0
21979
+ */
21980
+ var BackgroundType;
21981
+ (function (BackgroundType) {
21982
+ BackgroundType["video"] = "video";
21983
+ BackgroundType["image"] = "image";
21984
+ })(BackgroundType || (BackgroundType = {}));
21985
+
21950
21986
  /*********************************************/
21951
21987
  /* 基本数值属性参数 */
21952
21988
  /*********************************************/
@@ -23031,11 +23067,9 @@ function getStandardImage(image, index, imageTags) {
23031
23067
  else if (image.url) {
23032
23068
  return {
23033
23069
  url: image.url,
23034
- type: image.type,
23035
23070
  webp: image.webp,
23036
23071
  renderLevel: renderLevel,
23037
23072
  oriY: oriY,
23038
- loop: image.loop,
23039
23073
  };
23040
23074
  }
23041
23075
  else if (image && image.sourceType) {
@@ -23492,6 +23526,26 @@ var AssetManager = /** @class */ (function () {
23492
23526
  var _a = options.timeout, timeout = _a === void 0 ? 10 : _a;
23493
23527
  this.timeout = timeout;
23494
23528
  };
23529
+ /**
23530
+ * 根据用户传入的参数修改场景数据
23531
+ */
23532
+ AssetManager.prototype.updateSceneData = function (compositions) {
23533
+ var variables = this.options.variables;
23534
+ if (!variables || Object.keys(variables).length <= 0) {
23535
+ return compositions;
23536
+ }
23537
+ compositions.forEach(function (composition) {
23538
+ composition.items.forEach(function (item) {
23539
+ if (item.type === ItemType$1.text) {
23540
+ var textVariable = variables[item.name];
23541
+ if (textVariable) {
23542
+ item.content.options.text = textVariable;
23543
+ }
23544
+ }
23545
+ });
23546
+ });
23547
+ return compositions;
23548
+ };
23495
23549
  /**
23496
23550
  * 场景创建,通过 json 创建出场景对象,并进行提前编译等工作
23497
23551
  * @param url - json 的 URL 链接或者 json 对象
@@ -23583,6 +23637,7 @@ var AssetManager = /** @class */ (function () {
23583
23637
  for (i = 0; i < scene.images.length; i++) {
23584
23638
  scene.textureOptions[i].image = scene.images[i];
23585
23639
  }
23640
+ scene.jsonScene.compositions = this.updateSceneData(scene.jsonScene.compositions);
23586
23641
  _e.label = 5;
23587
23642
  case 5: return [3 /*break*/, 12];
23588
23643
  case 6: return [4 /*yield*/, hookTimeInfo('processJSON', function () { return _this.processJSON(rawJSON); })];
@@ -23602,6 +23657,7 @@ var AssetManager = /** @class */ (function () {
23602
23657
  return [4 /*yield*/, hookTimeInfo('processTextures', function () { return _this.processTextures(loadedImages_1, loadedBins_1, jsonScene_1); })];
23603
23658
  case 10:
23604
23659
  loadedTextures = _e.sent();
23660
+ jsonScene_1.compositions = this.updateSceneData(jsonScene_1.compositions);
23605
23661
  scene = {
23606
23662
  url: url,
23607
23663
  renderLevel: this.options.renderLevel,
@@ -23765,79 +23821,61 @@ var AssetManager = /** @class */ (function () {
23765
23821
  _a = this.options, useCompressedTexture = _a.useCompressedTexture, variables = _a.variables;
23766
23822
  baseUrl = this.baseUrl;
23767
23823
  jobs = images.map(function (img, idx) { return __awaiter(_this, void 0, void 0, function () {
23768
- var png, webp, imageURL, webpURL, template, result, url_1, name_1, templateImage, loop, compressed, src, bufferURL, _a, url, image;
23769
- var _b, _c, _d;
23770
- return __generator(this, function (_e) {
23771
- switch (_e.label) {
23824
+ var png, webp, imageURL, webpURL, template, isTemplateV2, background, url_1, isVideo, loadFn, resultImage, resultImage, compressed, src, bufferURL, _a, url, image;
23825
+ return __generator(this, function (_b) {
23826
+ switch (_b.label) {
23772
23827
  case 0:
23773
- if (!usage[idx]) return [3 /*break*/, 19];
23828
+ if (!usage[idx]) {
23829
+ return [2 /*return*/, undefined];
23830
+ }
23774
23831
  png = img.url, webp = img.webp;
23775
23832
  imageURL = new URL(png, baseUrl).href;
23776
23833
  webpURL = webp && new URL(webp, baseUrl).href;
23777
- if (!('template' in img)) return [3 /*break*/, 16];
23834
+ if (!('template' in img)) return [3 /*break*/, 13];
23778
23835
  template = img.template;
23779
- result = void 0;
23780
- if (!('v' in template && template.v === 2 && template.background)) return [3 /*break*/, 9];
23836
+ isTemplateV2 = 'v' in template && template.v === 2 && template.background;
23837
+ background = isTemplateV2 ? template.background : undefined;
23838
+ if (!(isTemplateV2 && background)) return [3 /*break*/, 8];
23781
23839
  url_1 = getBackgroundImage(template, variables);
23782
- if (!(url_1 instanceof Array)) return [3 /*break*/, 6];
23783
- name_1 = template.background.name;
23784
- _e.label = 1;
23840
+ isVideo = background.type === BackgroundType$1.video;
23841
+ loadFn = background && isVideo ? loadVideo : loadImage;
23842
+ _b.label = 1;
23785
23843
  case 1:
23786
- _e.trys.push([1, 3, , 5]);
23787
- _b = {};
23788
- return [4 /*yield*/, loadImage(url_1[0])];
23844
+ _b.trys.push([1, 6, , 7]);
23845
+ return [4 /*yield*/, loadMedia(url_1, loadFn)];
23789
23846
  case 2:
23790
- result = (_b.image = _e.sent(),
23791
- _b.url = url_1[0],
23792
- _b);
23793
- return [3 /*break*/, 5];
23847
+ resultImage = _b.sent();
23848
+ if (!(resultImage instanceof HTMLVideoElement)) return [3 /*break*/, 3];
23849
+ return [2 /*return*/, resultImage];
23794
23850
  case 3:
23795
- _e.sent();
23796
- _c = {};
23797
- return [4 /*yield*/, loadImage(url_1[1])];
23798
- case 4:
23799
- result = (_c.image = _e.sent(),
23800
- _c.url = url_1[1],
23801
- _c);
23802
- return [3 /*break*/, 5];
23803
- case 5:
23804
- if (variables) {
23805
- variables[name_1] = result.url;
23851
+ // 如果是加载图片且是数组,设置变量,视频情况下不需要
23852
+ if (background && !Array.isArray(url_1) && variables) {
23853
+ variables[background.name] = url_1;
23806
23854
  }
23807
- return [3 /*break*/, 8];
23855
+ return [4 /*yield*/, combineImageTemplate(resultImage, template, variables, this.options, img.oriY === -1)];
23856
+ case 4: return [2 /*return*/, _b.sent()];
23857
+ case 5: return [3 /*break*/, 7];
23808
23858
  case 6:
23809
- if (!(typeof url_1 === 'string')) return [3 /*break*/, 8];
23810
- _d = {};
23811
- return [4 /*yield*/, loadImage(url_1)];
23812
- case 7:
23813
- result = (_d.image = _e.sent(),
23814
- _d.url = url_1,
23815
- _d);
23816
- _e.label = 8;
23817
- case 8: return [3 /*break*/, 11];
23818
- case 9: return [4 /*yield*/, loadWebPOptional(imageURL, webpURL)];
23819
- case 10:
23820
- // 测试场景:'年兽大爆炸——8个彩蛋t1'
23821
- result = _e.sent();
23822
- _e.label = 11;
23859
+ _b.sent();
23860
+ throw new Error("Failed to load. Check the template or if the URL is ".concat(isVideo ? 'video' : 'image', " type, URL: ").concat(url_1, "."));
23861
+ case 7: return [3 /*break*/, 12];
23862
+ case 8:
23863
+ _b.trys.push([8, 11, , 12]);
23864
+ return [4 /*yield*/, loadWebPOptional(imageURL, webpURL)];
23865
+ case 9:
23866
+ resultImage = _b.sent();
23867
+ return [4 /*yield*/, combineImageTemplate(resultImage.image, template, variables, this.options, img.oriY === -1)];
23868
+ case 10: return [2 /*return*/, _b.sent()];
23823
23869
  case 11:
23824
- templateImage = void 0;
23825
- _e.label = 12;
23826
- case 12:
23827
- _e.trys.push([12, 14, , 15]);
23828
- return [4 /*yield*/, combineImageTemplate(result.image, template, variables, this.options, img.oriY === -1)];
23870
+ _b.sent();
23871
+ throw new Error("Failed to load. Check the template, URL: ".concat(imageURL, "."));
23872
+ case 12: return [3 /*break*/, 14];
23829
23873
  case 13:
23830
- templateImage = _e.sent();
23831
- return [3 /*break*/, 15];
23832
- case 14:
23833
- _e.sent();
23834
- throw new Error("image template fail: ".concat(imageURL));
23835
- case 15: return [2 /*return*/, templateImage];
23836
- case 16:
23837
23874
  if ('type' in img && img.type === 'video') {
23838
- loop = img.loop;
23839
23875
  // 视频
23840
- return [2 /*return*/, loadVideo(img.url, { loop: loop })];
23876
+ // TODO: 2024.03.28 后面考虑下掉非推荐的视频元素使用方式
23877
+ console.warn('The video element is deprecated. Use template BackgroundType.video instead.');
23878
+ return [2 /*return*/, loadVideo(img.url)];
23841
23879
  }
23842
23880
  else if ('compressed' in img && useCompressedTexture && compressedTexture) {
23843
23881
  compressed = img.compressed;
@@ -23863,13 +23901,12 @@ var AssetManager = /** @class */ (function () {
23863
23901
  img instanceof Texture) {
23864
23902
  return [2 /*return*/, img];
23865
23903
  }
23866
- _e.label = 17;
23867
- case 17: return [4 /*yield*/, loadWebPOptional(imageURL, webpURL)];
23868
- case 18:
23869
- _a = _e.sent(), url = _a.url, image = _a.image;
23904
+ _b.label = 14;
23905
+ case 14: return [4 /*yield*/, loadWebPOptional(imageURL, webpURL)];
23906
+ case 15:
23907
+ _a = _b.sent(), url = _a.url, image = _a.image;
23870
23908
  this.assets[idx] = { url: url, type: exports.TextureSourceType.image };
23871
23909
  return [2 /*return*/, image];
23872
- case 19: return [2 /*return*/, undefined];
23873
23910
  }
23874
23911
  });
23875
23912
  }); });
@@ -26913,7 +26950,7 @@ Geometry.create = function (engine, options) {
26913
26950
  Mesh.create = function (engine, props) {
26914
26951
  return new ThreeMesh(engine, props);
26915
26952
  };
26916
- var version = "1.2.2";
26953
+ var version = "1.3.0-alpha.0";
26917
26954
  logger.info('THREEJS plugin version: ' + version);
26918
26955
 
26919
26956
  exports.AbstractPlugin = AbstractPlugin;
@@ -27119,6 +27156,7 @@ exports.itemVert = itemVert;
27119
27156
  exports.loadBinary = loadBinary;
27120
27157
  exports.loadBlob = loadBlob;
27121
27158
  exports.loadImage = loadImage;
27159
+ exports.loadMedia = loadMedia;
27122
27160
  exports.loadVideo = loadVideo;
27123
27161
  exports.loadWebPOptional = loadWebPOptional;
27124
27162
  exports.logger = logger;