@galacean/effects-threejs 2.3.0-beta.2 → 2.3.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: v2.3.0-beta.2
6
+ * Version: v2.3.0
7
7
  */
8
8
 
9
9
  'use strict';
@@ -25543,9 +25543,12 @@ var TextComponentBase = /*#__PURE__*/ function() {
25543
25543
  this.textStyle = new TextStyle(options);
25544
25544
  this.textLayout = new TextLayout(options);
25545
25545
  this.text = options.text.toString();
25546
+ this.lineCount = this.getLineCount(options.text, true);
25546
25547
  };
25547
- _proto.getLineCount = function getLineCount(text, context) {
25548
+ _proto.getLineCount = function getLineCount(text, init) {
25549
+ var context = this.context;
25548
25550
  var _this_textLayout = this.textLayout, letterSpace = _this_textLayout.letterSpace, overflow = _this_textLayout.overflow;
25551
+ var fontScale = init ? this.textStyle.fontSize / 10 : 1 / this.textStyle.fontScale;
25549
25552
  var width = this.textLayout.width + this.textStyle.fontOffset;
25550
25553
  var lineCount = 1;
25551
25554
  var x = 0;
@@ -25553,7 +25556,7 @@ var TextComponentBase = /*#__PURE__*/ function() {
25553
25556
  var _context_measureText;
25554
25557
  var str = text[i];
25555
25558
  var _context_measureText_width;
25556
- var textMetrics = (_context_measureText_width = context == null ? void 0 : (_context_measureText = context.measureText(str)) == null ? void 0 : _context_measureText.width) != null ? _context_measureText_width : 0;
25559
+ var textMetrics = ((_context_measureText_width = context == null ? void 0 : (_context_measureText = context.measureText(str)) == null ? void 0 : _context_measureText.width) != null ? _context_measureText_width : 0) * fontScale;
25557
25560
  // 和浏览器行为保持一致
25558
25561
  x += letterSpace;
25559
25562
  // 处理文本结束行为
@@ -25623,6 +25626,7 @@ var TextComponentBase = /*#__PURE__*/ function() {
25623
25626
  return;
25624
25627
  }
25625
25628
  this.text = value.toString();
25629
+ this.lineCount = this.getLineCount(value, false);
25626
25630
  this.isDirty = true;
25627
25631
  };
25628
25632
  /**
@@ -25783,35 +25787,32 @@ var TextComponentBase = /*#__PURE__*/ function() {
25783
25787
  var layout = this.textLayout;
25784
25788
  var fontScale = style.fontScale;
25785
25789
  var width = (layout.width + style.fontOffset) * fontScale;
25790
+ var finalHeight = layout.lineHeight * this.lineCount;
25786
25791
  var fontSize = style.fontSize * fontScale;
25787
25792
  var lineHeight = layout.lineHeight * fontScale;
25788
25793
  style.fontDesc = this.getFontDesc(fontSize);
25789
25794
  this.char = (this.text || "").split("");
25790
25795
  this.canvas.width = width;
25791
- var height = this.canvas.height;
25792
- context.font = style.fontDesc;
25793
- this.lineCount = this.getLineCount(this.text, context);
25794
- var finalHeight = layout.lineHeight * this.lineCount;
25795
25796
  if (layout.autoWidth) {
25796
25797
  this.canvas.height = finalHeight * fontScale;
25797
25798
  this.item.transform.size.set(1, finalHeight / layout.height);
25798
25799
  } else {
25799
25800
  this.canvas.height = layout.height * fontScale;
25800
25801
  }
25802
+ var height = this.canvas.height;
25803
+ // fix bug 1/255
25804
+ context.fillStyle = "rgba(255, 255, 255, 0.0039)";
25805
+ if (!flipY) {
25806
+ context.translate(0, height);
25807
+ context.scale(1, -1);
25808
+ }
25801
25809
  // canvas size 变化后重新刷新 context
25802
25810
  if (this.maxLineWidth > width && layout.overflow === TextOverflow.display) {
25803
25811
  context.font = this.getFontDesc(fontSize * width / this.maxLineWidth);
25804
25812
  } else {
25805
25813
  context.font = style.fontDesc;
25806
25814
  }
25807
- // fix bug 1/255
25808
- context.fillStyle = "rgba(255, 255, 255, 0.0039)";
25809
25815
  context.clearRect(0, 0, width, height);
25810
- if (!flipY) {
25811
- context.translate(0, height);
25812
- context.scale(1, -1);
25813
- }
25814
- context.fillRect(0, 0, width, height);
25815
25816
  if (style.hasShadow) {
25816
25817
  this.setupShadow();
25817
25818
  }
@@ -25883,9 +25884,9 @@ var TextComponentBase = /*#__PURE__*/ function() {
25883
25884
  this.material.setTexture("_MainTex", texture);
25884
25885
  this.isDirty = false;
25885
25886
  };
25886
- _proto.getFontDesc = function getFontDesc(fontSize) {
25887
- var _this_textStyle = this.textStyle, fontFamily = _this_textStyle.fontFamily, textWeight = _this_textStyle.textWeight, fontStyle = _this_textStyle.fontStyle;
25888
- var fontDesc = "" + fontSize.toString() + "px ";
25887
+ _proto.getFontDesc = function getFontDesc(size) {
25888
+ var _this_textStyle = this.textStyle, fontSize = _this_textStyle.fontSize, fontScale = _this_textStyle.fontScale, fontFamily = _this_textStyle.fontFamily, textWeight = _this_textStyle.textWeight, fontStyle = _this_textStyle.fontStyle;
25889
+ var fontDesc = "" + (size || fontSize * fontScale).toString() + "px ";
25889
25890
  if (!DEFAULT_FONTS.includes(fontFamily)) {
25890
25891
  fontDesc += '"' + fontFamily + '"';
25891
25892
  } else {
@@ -32100,7 +32101,7 @@ registerPlugin("sprite", SpriteLoader, exports.VFXItem);
32100
32101
  registerPlugin("particle", ParticleLoader, exports.VFXItem);
32101
32102
  registerPlugin("cal", CalculateLoader, exports.VFXItem);
32102
32103
  registerPlugin("interact", InteractLoader, exports.VFXItem);
32103
- var version$1 = "2.3.0-beta.2";
32104
+ var version$1 = "2.3.0";
32104
32105
  logger.info("Core version: " + version$1 + ".");
32105
32106
 
32106
32107
  var _obj;
@@ -33360,6 +33361,7 @@ var ThreeRenderer = /*#__PURE__*/ function(Renderer) {
33360
33361
  _this.baseCompositionIndex = 0;
33361
33362
  var width = options.width, height = options.height, camera = options.camera;
33362
33363
  _this.renderer = new ThreeRenderer(context);
33364
+ _this.assetService = new AssetService(_this.renderer.engine);
33363
33365
  _this.width = width;
33364
33366
  _this.height = height;
33365
33367
  _this.camera = camera;
@@ -33369,63 +33371,109 @@ var ThreeRenderer = /*#__PURE__*/ function(Renderer) {
33369
33371
  _proto.loadScene = function loadScene(scene, options) {
33370
33372
  var _this = this;
33371
33373
  return _async_to_generator(function() {
33372
- var composition, baseOrder;
33374
+ var last, scenes, compositions, _options_autoplay, autoplay, baseOrder, _scenes, i, compositionNames, firstFrameTime, _iterator, _step, composition;
33373
33375
  return __generator(this, function(_state) {
33374
33376
  switch(_state.label){
33375
33377
  case 0:
33378
+ assertExist(_this.renderer, "Renderer is not exist, maybe the Player has been disabled or in gl 'debug-disable' mode.");
33379
+ last = performance.now();
33380
+ scenes = [];
33381
+ compositions = [];
33382
+ autoplay = (_options_autoplay = options == null ? void 0 : options.autoplay) != null ? _options_autoplay : true;
33376
33383
  baseOrder = _this.baseCompositionIndex;
33377
- if (!isArray(scene)) return [
33378
- 3,
33379
- 2
33380
- ];
33381
- _this.baseCompositionIndex += scene.length;
33384
+ if (isArray(scene)) {
33385
+ (_scenes = scenes).push.apply(_scenes, [].concat(scene));
33386
+ } else {
33387
+ scenes.push(scene);
33388
+ }
33382
33389
  return [
33383
33390
  4,
33384
- Promise.all(scene.map(/*#__PURE__*/ _async_to_generator(function(scn, index) {
33385
- var res;
33391
+ Promise.all(scenes.map(/*#__PURE__*/ _async_to_generator(function(url, index) {
33392
+ var _this_assetService_assembleSceneLoadOptions, source, opts, assetManager, _$scene, composition;
33386
33393
  return __generator(this, function(_state) {
33387
33394
  switch(_state.label){
33388
33395
  case 0:
33396
+ _this_assetService_assembleSceneLoadOptions = _this.assetService.assembleSceneLoadOptions(url, _extends({
33397
+ autoplay: autoplay
33398
+ }, options)), source = _this_assetService_assembleSceneLoadOptions.source, opts = _this_assetService_assembleSceneLoadOptions.options;
33399
+ assetManager = new AssetManager(opts);
33389
33400
  return [
33390
33401
  4,
33391
- _this.createComposition(scn, options)
33402
+ assetManager.loadScene(source, _this.renderer, {
33403
+ env: _this.env
33404
+ })
33392
33405
  ];
33393
33406
  case 1:
33394
- res = _state.sent();
33395
- res.setIndex(baseOrder + index);
33407
+ _$scene = _state.sent();
33408
+ _this.assetService.prepareAssets(_$scene, assetManager.getAssets());
33409
+ _this.assetService.updateTextVariables(_$scene, assetManager.options.variables);
33410
+ _this.assetService.initializeTexture(_$scene);
33411
+ _$scene.pluginSystem.precompile(_$scene.jsonScene.compositions, _this.renderer, options);
33412
+ composition = _this.createComposition(_$scene, opts);
33413
+ _this.baseCompositionIndex += 1;
33414
+ composition.setIndex(baseOrder + index);
33415
+ compositions[index] = composition;
33396
33416
  return [
33397
- 2,
33398
- res
33417
+ 2
33399
33418
  ];
33400
33419
  }
33401
33420
  });
33402
33421
  })))
33403
33422
  ];
33404
33423
  case 1:
33405
- composition = _state.sent();
33406
- return [
33407
- 3,
33408
- 4
33409
- ];
33410
- case 2:
33411
- _this.baseCompositionIndex += 1;
33412
- return [
33413
- 4,
33414
- _this.createComposition(scene, options)
33415
- ];
33416
- case 3:
33417
- composition = _state.sent();
33418
- composition.setIndex(baseOrder);
33419
- _state.label = 4;
33420
- case 4:
33424
+ _state.sent();
33425
+ for(i = 0; i < compositions.length; i++){
33426
+ if (autoplay) {
33427
+ compositions[i].play();
33428
+ } else {
33429
+ compositions[i].pause();
33430
+ }
33431
+ }
33432
+ compositionNames = compositions.map(function(composition) {
33433
+ return composition.name;
33434
+ });
33435
+ firstFrameTime = performance.now() - last;
33436
+ for(_iterator = _create_for_of_iterator_helper_loose(compositions); !(_step = _iterator()).done;){
33437
+ composition = _step.value;
33438
+ composition.statistic.firstFrameTime = firstFrameTime;
33439
+ }
33440
+ logger.info("First frame [" + compositionNames + "]: " + firstFrameTime.toFixed(4) + "ms.");
33421
33441
  return [
33422
33442
  2,
33423
- composition
33443
+ isArray(scene) ? compositions : compositions[0]
33424
33444
  ];
33425
33445
  }
33426
33446
  });
33427
33447
  })();
33428
33448
  };
33449
+ _proto.createComposition = function createComposition(scene, options) {
33450
+ var _this = this;
33451
+ if (options === void 0) options = {};
33452
+ var composition = new ThreeComposition(_extends({}, options, {
33453
+ width: this.width,
33454
+ height: this.height,
33455
+ renderer: this.renderer,
33456
+ handleItemMessage: function(message) {
33457
+ _this.dispatchEvent({
33458
+ type: "message",
33459
+ message: message
33460
+ });
33461
+ }
33462
+ }), scene);
33463
+ composition.on("end", function() {
33464
+ _this.dispatchEvent({
33465
+ type: "end",
33466
+ composition: composition
33467
+ });
33468
+ });
33469
+ this.renderer.engine.setOptions({
33470
+ threeCamera: this.camera,
33471
+ threeGroup: this,
33472
+ composition: composition
33473
+ });
33474
+ this.compositions.push(composition);
33475
+ return composition;
33476
+ };
33429
33477
  _proto.pause = function pause() {
33430
33478
  this.dispatchEvent({
33431
33479
  type: "pause"
@@ -33439,99 +33487,6 @@ var ThreeRenderer = /*#__PURE__*/ function(Renderer) {
33439
33487
  composition.resume();
33440
33488
  });
33441
33489
  };
33442
- _proto.createComposition = function createComposition(url, options) {
33443
- if (options === void 0) options = {};
33444
- var _this = this;
33445
- return _async_to_generator(function() {
33446
- var last, opts, source, scene, engine, i, composition, firstFrameTime;
33447
- return __generator(this, function(_state) {
33448
- switch(_state.label){
33449
- case 0:
33450
- last = performance.now();
33451
- opts = _extends({
33452
- autoplay: true
33453
- }, options);
33454
- source = url;
33455
- if (exports.Scene.isURL(url)) {
33456
- if (!exports.Scene.isJSONObject(url)) {
33457
- source = url.url;
33458
- }
33459
- if (exports.Scene.isWithOptions(url)) {
33460
- opts = _extends({}, opts, url.options || {});
33461
- }
33462
- }
33463
- if (_this.assetManager) {
33464
- _this.assetManager.updateOptions(opts);
33465
- } else {
33466
- _this.assetManager = new AssetManager(opts);
33467
- }
33468
- return [
33469
- 4,
33470
- _this.assetManager.loadScene(source, _this.renderer, {
33471
- env: _this.env
33472
- })
33473
- ];
33474
- case 1:
33475
- scene = _state.sent();
33476
- engine = _this.renderer.engine;
33477
- // TODO 多 json 之间目前不共用资源,如果后续需要多 json 共用,这边缓存机制需要额外处理
33478
- engine.clearResources();
33479
- engine.addPackageDatas(scene);
33480
- for(i = 0; i < scene.textureOptions.length; i++){
33481
- scene.textureOptions[i] = engine.assetLoader.loadGUID(scene.textureOptions[i].id);
33482
- scene.textureOptions[i].initialize();
33483
- }
33484
- if (!engine.database) return [
33485
- 3,
33486
- 3
33487
- ];
33488
- return [
33489
- 4,
33490
- engine.createVFXItems(scene)
33491
- ];
33492
- case 2:
33493
- _state.sent();
33494
- _state.label = 3;
33495
- case 3:
33496
- composition = new ThreeComposition(_extends({}, opts, {
33497
- width: _this.width,
33498
- height: _this.height,
33499
- renderer: _this.renderer,
33500
- handleItemMessage: function(message) {
33501
- _this.dispatchEvent({
33502
- type: "message",
33503
- message: message
33504
- });
33505
- }
33506
- }), scene);
33507
- composition.on("end", function() {
33508
- _this.dispatchEvent({
33509
- type: "end",
33510
- composition: composition
33511
- });
33512
- });
33513
- _this.renderer.engine.setOptions({
33514
- threeCamera: _this.camera,
33515
- threeGroup: _this,
33516
- composition: composition
33517
- });
33518
- if (opts.autoplay) {
33519
- composition.play();
33520
- } else {
33521
- composition.pause();
33522
- }
33523
- firstFrameTime = performance.now() - last + composition.statistic.loadTime;
33524
- composition.statistic.firstFrameTime = firstFrameTime;
33525
- logger.info("First frame: [" + composition.name + "]" + firstFrameTime.toFixed(4) + "ms.");
33526
- _this.compositions.push(composition);
33527
- return [
33528
- 2,
33529
- composition
33530
- ];
33531
- }
33532
- });
33533
- })();
33534
- };
33535
33490
  /**
33536
33491
  *
33537
33492
  * @param delta
@@ -33746,7 +33701,7 @@ setMaxSpriteMeshItemCount(8);
33746
33701
  */ Mesh.create = function(engine, props) {
33747
33702
  return new ThreeMesh(engine, props);
33748
33703
  };
33749
- var version = "2.3.0-beta.2";
33704
+ var version = "2.3.0";
33750
33705
  logger.info("THREEJS plugin version: " + version + ".");
33751
33706
 
33752
33707
  exports.AbstractPlugin = AbstractPlugin;