@galacean/effects-threejs 2.3.0-beta.3 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects runtime threejs plugin for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v2.3.0-beta.3
6
+ * Version: v2.3.1
7
7
  */
8
8
 
9
9
  'use strict';
@@ -952,10 +952,10 @@ var PluginSystem = /*#__PURE__*/ function() {
952
952
  });
953
953
  })();
954
954
  };
955
- _proto.precompile = function precompile(compositions, renderer, options) {
955
+ _proto.precompile = function precompile(compositions, renderer) {
956
956
  for(var _iterator = _create_for_of_iterator_helper_loose(this.plugins), _step; !(_step = _iterator()).done;){
957
957
  var plugin = _step.value;
958
- plugin.precompile(compositions, renderer, options);
958
+ plugin.precompile(compositions, renderer);
959
959
  }
960
960
  };
961
961
  _proto.loadResources = function loadResources(scene, options) {
@@ -1030,7 +1030,7 @@ function getPluginUsageInfo(name) {
1030
1030
  * 在加载到 JSON 后,就可以进行提前编译
1031
1031
  * @param json
1032
1032
  * @param player
1033
- */ _proto.precompile = function precompile(compositions, renderer, options) {};
1033
+ */ _proto.precompile = function precompile(compositions, renderer) {};
1034
1034
  _proto.onCompositionConstructed = function onCompositionConstructed(composition, scene) {};
1035
1035
  _proto.onCompositionItemLifeBegin = function onCompositionItemLifeBegin(composition, item) {};
1036
1036
  _proto.onCompositionItemLifeEnd = function onCompositionItemLifeEnd(composition, item) {};
@@ -16349,7 +16349,6 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16349
16349
  _this.hasFill = false;
16350
16350
  _this.shapeDirty = true;
16351
16351
  _this.graphicsPath = new GraphicsPath();
16352
- _this.curveValues = [];
16353
16352
  _this.vert = "\nprecision highp float;\n\nattribute vec3 aPos;//x y\n\nuniform mat4 effects_MatrixVP;\nuniform mat4 effects_MatrixInvV;\nuniform mat4 effects_ObjectToWorld;\n\nvoid main() {\n vec4 pos = vec4(aPos.xyz, 1.0);\n gl_Position = effects_MatrixVP * effects_ObjectToWorld * pos;\n}\n";
16354
16353
  _this.frag = "\nprecision highp float;\n\nuniform vec4 _Color;\n\nvoid main() {\n vec4 color = _Color;\n color.rgb *= color.a;\n gl_FragColor = color;\n}\n";
16355
16354
  if (!_this.geometry) {
@@ -16531,31 +16530,25 @@ exports.ShapeComponent = /*#__PURE__*/ function(MeshComponent) {
16531
16530
  var easingOuts = customShapeAtribute.easingOuts;
16532
16531
  for(var _iterator = _create_for_of_iterator_helper_loose(customShapeAtribute.shapes), _step; !(_step = _iterator()).done;){
16533
16532
  var shape = _step.value;
16534
- this.curveValues = [];
16535
16533
  var indices = shape.indexes;
16534
+ var startPoint = points[indices[0].point];
16535
+ this.graphicsPath.moveTo(startPoint.x, startPoint.y);
16536
16536
  for(var i = 1; i < indices.length; i++){
16537
16537
  var pointIndex = indices[i];
16538
16538
  var lastPointIndex = indices[i - 1];
16539
- this.curveValues.push({
16540
- point: points[pointIndex.point],
16541
- controlPoint1: easingOuts[lastPointIndex.easingOut],
16542
- controlPoint2: easingIns[pointIndex.easingIn]
16543
- });
16544
- }
16545
- // Push the last curve
16546
- this.curveValues.push({
16547
- point: points[indices[0].point],
16548
- controlPoint1: easingOuts[indices[indices.length - 1].easingOut],
16549
- controlPoint2: easingIns[indices[0].easingIn]
16550
- });
16551
- this.graphicsPath.moveTo(this.curveValues[this.curveValues.length - 1].point.x, this.curveValues[this.curveValues.length - 1].point.y);
16552
- for(var _iterator1 = _create_for_of_iterator_helper_loose(this.curveValues), _step1; !(_step1 = _iterator1()).done;){
16553
- var curveValue = _step1.value;
16554
- var point = curveValue.point;
16555
- var control1 = curveValue.controlPoint1;
16556
- var control2 = curveValue.controlPoint2;
16557
- this.graphicsPath.bezierCurveTo(control1.x, control1.y, control2.x, control2.y, point.x, point.y, 1);
16539
+ var point = points[pointIndex.point];
16540
+ var lastPoint = points[lastPointIndex.point];
16541
+ var control1 = easingOuts[lastPointIndex.easingOut];
16542
+ var control2 = easingIns[pointIndex.easingIn];
16543
+ this.graphicsPath.bezierCurveTo(control1.x + lastPoint.x, control1.y + lastPoint.y, control2.x + point.x, control2.y + point.y, point.x, point.y, 1);
16558
16544
  }
16545
+ var pointIndex1 = indices[0];
16546
+ var lastPointIndex1 = indices[indices.length - 1];
16547
+ var point1 = points[pointIndex1.point];
16548
+ var lastPoint1 = points[lastPointIndex1.point];
16549
+ var control11 = easingOuts[lastPointIndex1.easingOut];
16550
+ var control21 = easingIns[pointIndex1.easingIn];
16551
+ this.graphicsPath.bezierCurveTo(control11.x + lastPoint1.x, control11.y + lastPoint1.y, control21.x + point1.x, control21.y + point1.y, point1.x, point1.y, 1);
16559
16552
  if (shape.close) {
16560
16553
  this.graphicsPath.closePath();
16561
16554
  }
@@ -26676,14 +26669,36 @@ function getStandardInteractContent(ui) {
26676
26669
  // @ts-expect-error
26677
26670
  customShapeComponent.fill = customShapeComponent.shapes[0].fill;
26678
26671
  }
26672
+ // easingIn 和 easingOut 绝对坐标转相对坐标
26673
+ var easingInFlag = new Array(customShapeComponent.easingIns.length);
26674
+ var easingOutFlag = new Array(customShapeComponent.easingOuts.length).fill(false);
26675
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(customShapeComponent.shapes), _step1; !(_step1 = _iterator1()).done;){
26676
+ var shape = _step1.value;
26677
+ for(var _iterator2 = _create_for_of_iterator_helper_loose(shape.indexes), _step2; !(_step2 = _iterator2()).done;){
26678
+ var index = _step2.value;
26679
+ var point = customShapeComponent.points[index.point];
26680
+ var easingIn = customShapeComponent.easingIns[index.easingIn];
26681
+ var easingOut = customShapeComponent.easingOuts[index.easingOut];
26682
+ if (!easingInFlag[index.easingIn]) {
26683
+ easingIn.x -= point.x;
26684
+ easingIn.y -= point.y;
26685
+ easingInFlag[index.easingIn] = true;
26686
+ }
26687
+ if (!easingOutFlag[index.easingOut]) {
26688
+ easingOut.x -= point.x;
26689
+ easingOut.y -= point.y;
26690
+ easingOutFlag[index.easingOut] = true;
26691
+ }
26692
+ }
26693
+ }
26679
26694
  }
26680
26695
  }
26681
26696
  }
26682
26697
  // Composition id 转 guid
26683
26698
  var compositionId = json.compositionId;
26684
26699
  var compositionIdToGUIDMap = {};
26685
- for(var _iterator1 = _create_for_of_iterator_helper_loose(json.compositions), _step1; !(_step1 = _iterator1()).done;){
26686
- var composition = _step1.value;
26700
+ for(var _iterator3 = _create_for_of_iterator_helper_loose(json.compositions), _step3; !(_step3 = _iterator3()).done;){
26701
+ var composition = _step3.value;
26687
26702
  var guid = generateGUID();
26688
26703
  compositionIdToGUIDMap[composition.id] = guid;
26689
26704
  if (composition.id === compositionId) {
@@ -26692,8 +26707,8 @@ function getStandardInteractContent(ui) {
26692
26707
  composition.id = guid;
26693
26708
  }
26694
26709
  // 预合成元素 refId 同步改为生成的合成 guid
26695
- for(var _iterator2 = _create_for_of_iterator_helper_loose(json.items), _step2; !(_step2 = _iterator2()).done;){
26696
- var item = _step2.value;
26710
+ for(var _iterator4 = _create_for_of_iterator_helper_loose(json.items), _step4; !(_step4 = _iterator4()).done;){
26711
+ var item = _step4.value;
26697
26712
  if (item.content) {
26698
26713
  var compositionOptions = item.content.options;
26699
26714
  if (compositionOptions && compositionOptions.refId !== undefined) {
@@ -27547,8 +27562,10 @@ function getStandardJSON(json) {
27547
27562
  json = version30Migration(version21Migration(json));
27548
27563
  }
27549
27564
  // 3.x 版本格式转换
27550
- if (mainVersion < 4 || mainVersion === 4 && minorVersion < 2) {
27551
- json = version31Migration(json);
27565
+ if (mainVersion < 4) {
27566
+ if (mainVersion === 3 && minorVersion < 2) {
27567
+ json = version31Migration(json);
27568
+ }
27552
27569
  }
27553
27570
  return json;
27554
27571
  }
@@ -32101,7 +32118,7 @@ registerPlugin("sprite", SpriteLoader, exports.VFXItem);
32101
32118
  registerPlugin("particle", ParticleLoader, exports.VFXItem);
32102
32119
  registerPlugin("cal", CalculateLoader, exports.VFXItem);
32103
32120
  registerPlugin("interact", InteractLoader, exports.VFXItem);
32104
- var version$1 = "2.3.0-beta.3";
32121
+ var version$1 = "2.3.1";
32105
32122
  logger.info("Core version: " + version$1 + ".");
32106
32123
 
32107
32124
  var _obj;
@@ -33361,6 +33378,7 @@ var ThreeRenderer = /*#__PURE__*/ function(Renderer) {
33361
33378
  _this.baseCompositionIndex = 0;
33362
33379
  var width = options.width, height = options.height, camera = options.camera;
33363
33380
  _this.renderer = new ThreeRenderer(context);
33381
+ _this.assetService = new AssetService(_this.renderer.engine);
33364
33382
  _this.width = width;
33365
33383
  _this.height = height;
33366
33384
  _this.camera = camera;
@@ -33370,63 +33388,109 @@ var ThreeRenderer = /*#__PURE__*/ function(Renderer) {
33370
33388
  _proto.loadScene = function loadScene(scene, options) {
33371
33389
  var _this = this;
33372
33390
  return _async_to_generator(function() {
33373
- var composition, baseOrder;
33391
+ var last, scenes, compositions, _options_autoplay, autoplay, baseOrder, _scenes, i, compositionNames, firstFrameTime, _iterator, _step, composition;
33374
33392
  return __generator(this, function(_state) {
33375
33393
  switch(_state.label){
33376
33394
  case 0:
33395
+ assertExist(_this.renderer, "Renderer is not exist, maybe the Player has been disabled or in gl 'debug-disable' mode.");
33396
+ last = performance.now();
33397
+ scenes = [];
33398
+ compositions = [];
33399
+ autoplay = (_options_autoplay = options == null ? void 0 : options.autoplay) != null ? _options_autoplay : true;
33377
33400
  baseOrder = _this.baseCompositionIndex;
33378
- if (!isArray(scene)) return [
33379
- 3,
33380
- 2
33381
- ];
33382
- _this.baseCompositionIndex += scene.length;
33401
+ if (isArray(scene)) {
33402
+ (_scenes = scenes).push.apply(_scenes, [].concat(scene));
33403
+ } else {
33404
+ scenes.push(scene);
33405
+ }
33383
33406
  return [
33384
33407
  4,
33385
- Promise.all(scene.map(/*#__PURE__*/ _async_to_generator(function(scn, index) {
33386
- var res;
33408
+ Promise.all(scenes.map(/*#__PURE__*/ _async_to_generator(function(url, index) {
33409
+ var _this_assetService_assembleSceneLoadOptions, source, opts, assetManager, _$scene, composition;
33387
33410
  return __generator(this, function(_state) {
33388
33411
  switch(_state.label){
33389
33412
  case 0:
33413
+ _this_assetService_assembleSceneLoadOptions = _this.assetService.assembleSceneLoadOptions(url, _extends({
33414
+ autoplay: autoplay
33415
+ }, options)), source = _this_assetService_assembleSceneLoadOptions.source, opts = _this_assetService_assembleSceneLoadOptions.options;
33416
+ assetManager = new AssetManager(opts);
33390
33417
  return [
33391
33418
  4,
33392
- _this.createComposition(scn, options)
33419
+ assetManager.loadScene(source, _this.renderer, {
33420
+ env: _this.env
33421
+ })
33393
33422
  ];
33394
33423
  case 1:
33395
- res = _state.sent();
33396
- res.setIndex(baseOrder + index);
33424
+ _$scene = _state.sent();
33425
+ _this.assetService.prepareAssets(_$scene, assetManager.getAssets());
33426
+ _this.assetService.updateTextVariables(_$scene, assetManager.options.variables);
33427
+ _this.assetService.initializeTexture(_$scene);
33428
+ _$scene.pluginSystem.precompile(_$scene.jsonScene.compositions, _this.renderer);
33429
+ composition = _this.createComposition(_$scene, opts);
33430
+ _this.baseCompositionIndex += 1;
33431
+ composition.setIndex(baseOrder + index);
33432
+ compositions[index] = composition;
33397
33433
  return [
33398
- 2,
33399
- res
33434
+ 2
33400
33435
  ];
33401
33436
  }
33402
33437
  });
33403
33438
  })))
33404
33439
  ];
33405
33440
  case 1:
33406
- composition = _state.sent();
33407
- return [
33408
- 3,
33409
- 4
33410
- ];
33411
- case 2:
33412
- _this.baseCompositionIndex += 1;
33413
- return [
33414
- 4,
33415
- _this.createComposition(scene, options)
33416
- ];
33417
- case 3:
33418
- composition = _state.sent();
33419
- composition.setIndex(baseOrder);
33420
- _state.label = 4;
33421
- case 4:
33441
+ _state.sent();
33442
+ for(i = 0; i < compositions.length; i++){
33443
+ if (autoplay) {
33444
+ compositions[i].play();
33445
+ } else {
33446
+ compositions[i].pause();
33447
+ }
33448
+ }
33449
+ compositionNames = compositions.map(function(composition) {
33450
+ return composition.name;
33451
+ });
33452
+ firstFrameTime = performance.now() - last;
33453
+ for(_iterator = _create_for_of_iterator_helper_loose(compositions); !(_step = _iterator()).done;){
33454
+ composition = _step.value;
33455
+ composition.statistic.firstFrameTime = firstFrameTime;
33456
+ }
33457
+ logger.info("First frame [" + compositionNames + "]: " + firstFrameTime.toFixed(4) + "ms.");
33422
33458
  return [
33423
33459
  2,
33424
- composition
33460
+ isArray(scene) ? compositions : compositions[0]
33425
33461
  ];
33426
33462
  }
33427
33463
  });
33428
33464
  })();
33429
33465
  };
33466
+ _proto.createComposition = function createComposition(scene, options) {
33467
+ var _this = this;
33468
+ if (options === void 0) options = {};
33469
+ var composition = new ThreeComposition(_extends({}, options, {
33470
+ width: this.width,
33471
+ height: this.height,
33472
+ renderer: this.renderer,
33473
+ handleItemMessage: function(message) {
33474
+ _this.dispatchEvent({
33475
+ type: "message",
33476
+ message: message
33477
+ });
33478
+ }
33479
+ }), scene);
33480
+ composition.on("end", function() {
33481
+ _this.dispatchEvent({
33482
+ type: "end",
33483
+ composition: composition
33484
+ });
33485
+ });
33486
+ this.renderer.engine.setOptions({
33487
+ threeCamera: this.camera,
33488
+ threeGroup: this,
33489
+ composition: composition
33490
+ });
33491
+ this.compositions.push(composition);
33492
+ return composition;
33493
+ };
33430
33494
  _proto.pause = function pause() {
33431
33495
  this.dispatchEvent({
33432
33496
  type: "pause"
@@ -33440,99 +33504,6 @@ var ThreeRenderer = /*#__PURE__*/ function(Renderer) {
33440
33504
  composition.resume();
33441
33505
  });
33442
33506
  };
33443
- _proto.createComposition = function createComposition(url, options) {
33444
- if (options === void 0) options = {};
33445
- var _this = this;
33446
- return _async_to_generator(function() {
33447
- var last, opts, source, scene, engine, i, composition, firstFrameTime;
33448
- return __generator(this, function(_state) {
33449
- switch(_state.label){
33450
- case 0:
33451
- last = performance.now();
33452
- opts = _extends({
33453
- autoplay: true
33454
- }, options);
33455
- source = url;
33456
- if (exports.Scene.isURL(url)) {
33457
- if (!exports.Scene.isJSONObject(url)) {
33458
- source = url.url;
33459
- }
33460
- if (exports.Scene.isWithOptions(url)) {
33461
- opts = _extends({}, opts, url.options || {});
33462
- }
33463
- }
33464
- if (_this.assetManager) {
33465
- _this.assetManager.updateOptions(opts);
33466
- } else {
33467
- _this.assetManager = new AssetManager(opts);
33468
- }
33469
- return [
33470
- 4,
33471
- _this.assetManager.loadScene(source, _this.renderer, {
33472
- env: _this.env
33473
- })
33474
- ];
33475
- case 1:
33476
- scene = _state.sent();
33477
- engine = _this.renderer.engine;
33478
- // TODO 多 json 之间目前不共用资源,如果后续需要多 json 共用,这边缓存机制需要额外处理
33479
- engine.clearResources();
33480
- engine.addPackageDatas(scene);
33481
- for(i = 0; i < scene.textureOptions.length; i++){
33482
- scene.textureOptions[i] = engine.assetLoader.loadGUID(scene.textureOptions[i].id);
33483
- scene.textureOptions[i].initialize();
33484
- }
33485
- if (!engine.database) return [
33486
- 3,
33487
- 3
33488
- ];
33489
- return [
33490
- 4,
33491
- engine.createVFXItems(scene)
33492
- ];
33493
- case 2:
33494
- _state.sent();
33495
- _state.label = 3;
33496
- case 3:
33497
- composition = new ThreeComposition(_extends({}, opts, {
33498
- width: _this.width,
33499
- height: _this.height,
33500
- renderer: _this.renderer,
33501
- handleItemMessage: function(message) {
33502
- _this.dispatchEvent({
33503
- type: "message",
33504
- message: message
33505
- });
33506
- }
33507
- }), scene);
33508
- composition.on("end", function() {
33509
- _this.dispatchEvent({
33510
- type: "end",
33511
- composition: composition
33512
- });
33513
- });
33514
- _this.renderer.engine.setOptions({
33515
- threeCamera: _this.camera,
33516
- threeGroup: _this,
33517
- composition: composition
33518
- });
33519
- if (opts.autoplay) {
33520
- composition.play();
33521
- } else {
33522
- composition.pause();
33523
- }
33524
- firstFrameTime = performance.now() - last + composition.statistic.loadTime;
33525
- composition.statistic.firstFrameTime = firstFrameTime;
33526
- logger.info("First frame: [" + composition.name + "]" + firstFrameTime.toFixed(4) + "ms.");
33527
- _this.compositions.push(composition);
33528
- return [
33529
- 2,
33530
- composition
33531
- ];
33532
- }
33533
- });
33534
- })();
33535
- };
33536
33507
  /**
33537
33508
  *
33538
33509
  * @param delta
@@ -33747,7 +33718,7 @@ setMaxSpriteMeshItemCount(8);
33747
33718
  */ Mesh.create = function(engine, props) {
33748
33719
  return new ThreeMesh(engine, props);
33749
33720
  };
33750
- var version = "2.3.0-beta.3";
33721
+ var version = "2.3.1";
33751
33722
  logger.info("THREEJS plugin version: " + version + ".");
33752
33723
 
33753
33724
  exports.AbstractPlugin = AbstractPlugin;