@galacean/effects-threejs 1.6.0-beta.0 → 1.6.0-beta.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.mjs 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.6.0-beta.0
6
+ * Version: v1.6.0-beta.1
7
7
  */
8
8
 
9
9
  import * as THREE from 'three';
@@ -13518,6 +13518,14 @@ var InteractVFXItem = /** @class */ (function (_super) {
13518
13518
  function InteractVFXItem(props, composition) {
13519
13519
  var _a;
13520
13520
  var _this = _super.call(this, props, composition) || this;
13521
+ /**
13522
+ * 拖拽的惯性衰减系数,范围[0, 1], 越大惯性越强
13523
+ */
13524
+ _this.downgrade = 0.95;
13525
+ /**
13526
+ * 拖拽的距离映射系数,越大越容易拖动
13527
+ */
13528
+ _this.dragRatio = [1, 1];
13521
13529
  _this.engine = (_a = _this.composition) === null || _a === void 0 ? void 0 : _a.getEngine();
13522
13530
  return _this;
13523
13531
  }
@@ -13528,8 +13536,23 @@ var InteractVFXItem = /** @class */ (function (_super) {
13528
13536
  enumerable: false,
13529
13537
  configurable: true
13530
13538
  });
13539
+ Object.defineProperty(InteractVFXItem.prototype, "enable", {
13540
+ get: function () {
13541
+ return this.enabled;
13542
+ },
13543
+ set: function (enable) {
13544
+ this.enabled = enable;
13545
+ if (!enable) {
13546
+ // 立刻停止惯性滑动
13547
+ this.bouncingArg = null;
13548
+ }
13549
+ },
13550
+ enumerable: false,
13551
+ configurable: true
13552
+ });
13531
13553
  InteractVFXItem.prototype.onConstructed = function (options) {
13532
13554
  this.ui = options.content;
13555
+ this.enabled = true;
13533
13556
  };
13534
13557
  InteractVFXItem.prototype.onLifetimeBegin = function (composition) {
13535
13558
  var _a, _b, _c;
@@ -13548,9 +13571,8 @@ var InteractVFXItem = /** @class */ (function (_super) {
13548
13571
  if (!this.dragEvent || !this.bouncingArg) {
13549
13572
  return;
13550
13573
  }
13551
- var downgrade = 0.95;
13552
- this.bouncingArg.vx *= downgrade;
13553
- this.bouncingArg.vy *= downgrade;
13574
+ this.bouncingArg.vx *= this.downgrade;
13575
+ this.bouncingArg.vy *= this.downgrade;
13554
13576
  this.bouncingArg.dy += this.bouncingArg.vy;
13555
13577
  this.bouncingArg.dx += this.bouncingArg.vx;
13556
13578
  if (shouldIgnoreBouncing(this.bouncingArg)) {
@@ -13586,7 +13608,7 @@ var InteractVFXItem = /** @class */ (function (_super) {
13586
13608
  };
13587
13609
  };
13588
13610
  InteractVFXItem.prototype.getHitTestParams = function () {
13589
- if (!this.clickable) {
13611
+ if (!this.clickable || !this.canInteract()) {
13590
13612
  return;
13591
13613
  }
13592
13614
  var behavior = this.ui.options.behavior;
@@ -13622,13 +13644,13 @@ var InteractVFXItem = /** @class */ (function (_super) {
13622
13644
  var dragEvent;
13623
13645
  var handlerMap = {
13624
13646
  touchstart: function (event) {
13625
- var _a, _b;
13626
- if (!((_a = _this.composition) === null || _a === void 0 ? void 0 : _a.interactive)) {
13647
+ var _a;
13648
+ if (!_this.canInteract()) {
13627
13649
  return;
13628
13650
  }
13629
13651
  _this.dragEvent = null;
13630
13652
  _this.bouncingArg = null;
13631
- var camera = (_b = _this.composition) === null || _b === void 0 ? void 0 : _b.camera;
13653
+ var camera = (_a = _this.composition) === null || _a === void 0 ? void 0 : _a.camera;
13632
13654
  dragEvent = {
13633
13655
  x: event.x,
13634
13656
  y: event.y,
@@ -13643,8 +13665,7 @@ var InteractVFXItem = /** @class */ (function (_super) {
13643
13665
  _this.bouncingArg = event;
13644
13666
  },
13645
13667
  touchend: function (event) {
13646
- var _a;
13647
- if (!((_a = _this.composition) === null || _a === void 0 ? void 0 : _a.interactive)) {
13668
+ if (!_this.canInteract()) {
13648
13669
  return;
13649
13670
  }
13650
13671
  var bouncingArg = _this.bouncingArg;
@@ -13671,36 +13692,40 @@ var InteractVFXItem = /** @class */ (function (_super) {
13671
13692
  // OVERRIDE
13672
13693
  };
13673
13694
  InteractVFXItem.prototype.handleDragMove = function (evt, event) {
13674
- var _a, _b, _c;
13675
- if (!(evt && evt.cameraParam) || !((_a = this.composition) === null || _a === void 0 ? void 0 : _a.interactive)) {
13695
+ var _a, _b;
13696
+ if (!(evt === null || evt === void 0 ? void 0 : evt.cameraParam) || !this.canInteract() || !this.composition) {
13676
13697
  return;
13677
13698
  }
13678
13699
  var options = this.ui.options;
13679
- var _d = evt.cameraParam, position = _d.position, fov = _d.fov;
13700
+ var _c = evt.cameraParam, position = _c.position, fov = _c.fov;
13680
13701
  var dy = event.dy;
13681
13702
  var dx = event.dx * event.width / event.height;
13682
13703
  var depth = position[2];
13683
13704
  var sp = Math.tan(fov * Math.PI / 180 / 2) * Math.abs(depth);
13684
13705
  var height = dy * sp;
13685
13706
  var width = dx * sp;
13686
- var nx = position[0] - width;
13687
- var ny = position[1] - height;
13707
+ var nx = position[0] - this.dragRatio[0] * width;
13708
+ var ny = position[1] - this.dragRatio[1] * height;
13688
13709
  if (options.dxRange) {
13689
- var _e = __read$3(options.dxRange, 2), min = _e[0], max = _e[1];
13710
+ var _d = __read$3(options.dxRange, 2), min = _d[0], max = _d[1];
13690
13711
  nx = clamp$1(nx, min, max);
13691
13712
  if (nx !== min && nx !== max && min !== max) {
13692
- (_b = event.origin) === null || _b === void 0 ? void 0 : _b.preventDefault();
13713
+ (_a = event.origin) === null || _a === void 0 ? void 0 : _a.preventDefault();
13693
13714
  }
13694
13715
  }
13695
13716
  if (options.dyRange) {
13696
- var _f = __read$3(options.dyRange, 2), min = _f[0], max = _f[1];
13717
+ var _e = __read$3(options.dyRange, 2), min = _e[0], max = _e[1];
13697
13718
  ny = clamp$1(ny, min, max);
13698
13719
  if (ny !== min && ny !== max && min !== max) {
13699
- (_c = event.origin) === null || _c === void 0 ? void 0 : _c.preventDefault();
13720
+ (_b = event.origin) === null || _b === void 0 ? void 0 : _b.preventDefault();
13700
13721
  }
13701
13722
  }
13702
13723
  this.composition.camera.position = new Vector3(nx, ny, depth);
13703
13724
  };
13725
+ InteractVFXItem.prototype.canInteract = function () {
13726
+ var _a;
13727
+ return Boolean((_a = this.composition) === null || _a === void 0 ? void 0 : _a.interactive) && this.enabled;
13728
+ };
13704
13729
  return InteractVFXItem;
13705
13730
  }(VFXItem));
13706
13731
  function shouldIgnoreBouncing(arg, mul) {
@@ -24006,27 +24031,28 @@ var AssetManager = /** @class */ (function () {
24006
24031
  AssetManager.prototype.loadScene = function (url, renderer, options) {
24007
24032
  var _a, _b, _c;
24008
24033
  return __awaiter(this, void 0, void 0, function () {
24009
- var rawJSON, assetUrl, startTime, timeInfos, gpuInstance, asyncShaderCompile, compressedTexture, loadTimer, cancelLoading, waitPromise, hookTimeInfo, loadResourcePromise;
24034
+ var rawJSON, assetUrl, startTime, timeInfoMessages, gpuInstance, asyncShaderCompile, compressedTexture, timeInfos, loadTimer, cancelLoading, waitPromise, hookTimeInfo, loadResourcePromise;
24010
24035
  var _this = this;
24011
24036
  return __generator(this, function (_d) {
24012
24037
  assetUrl = isString(url) ? url : this.id;
24013
24038
  startTime = performance.now();
24014
- timeInfos = [];
24039
+ timeInfoMessages = [];
24015
24040
  gpuInstance = renderer === null || renderer === void 0 ? void 0 : renderer.engine.gpuCapability;
24016
24041
  asyncShaderCompile = (_b = (_a = gpuInstance === null || gpuInstance === void 0 ? void 0 : gpuInstance.detail) === null || _a === void 0 ? void 0 : _a.asyncShaderCompile) !== null && _b !== void 0 ? _b : false;
24017
24042
  compressedTexture = (_c = gpuInstance === null || gpuInstance === void 0 ? void 0 : gpuInstance.detail.compressedTexture) !== null && _c !== void 0 ? _c : 0;
24043
+ timeInfos = {};
24018
24044
  cancelLoading = false;
24019
24045
  waitPromise = new Promise(function (resolve, reject) {
24020
24046
  loadTimer = window.setTimeout(function () {
24021
24047
  cancelLoading = true;
24022
24048
  _this.removeTimer(loadTimer);
24023
24049
  var totalTime = performance.now() - startTime;
24024
- reject("Load time out: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(timeInfos.join(' '), ", url: ").concat(assetUrl));
24050
+ reject("Load time out: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(timeInfoMessages.join(' '), ", url: ").concat(assetUrl));
24025
24051
  }, _this.timeout * 1000);
24026
24052
  _this.timers.push(loadTimer);
24027
24053
  });
24028
24054
  hookTimeInfo = function (label, func) { return __awaiter(_this, void 0, void 0, function () {
24029
- var st, result, e_1;
24055
+ var st, result, time, e_1;
24030
24056
  return __generator(this, function (_a) {
24031
24057
  switch (_a.label) {
24032
24058
  case 0:
@@ -24038,7 +24064,9 @@ var AssetManager = /** @class */ (function () {
24038
24064
  return [4 /*yield*/, func()];
24039
24065
  case 2:
24040
24066
  result = _a.sent();
24041
- timeInfos.push("[".concat(label, ": ").concat((performance.now() - st).toFixed(2), "]"));
24067
+ time = performance.now() - st;
24068
+ timeInfoMessages.push("[".concat(label, ": ").concat(time.toFixed(2), "]"));
24069
+ timeInfos[label] = time;
24042
24070
  return [2 /*return*/, result];
24043
24071
  case 3:
24044
24072
  e_1 = _a.sent();
@@ -24097,7 +24125,7 @@ var AssetManager = /** @class */ (function () {
24097
24125
  return [4 /*yield*/, Promise.all([
24098
24126
  hookTimeInfo('processBins', function () { return _this.processBins(bins_1); }),
24099
24127
  hookTimeInfo('processImages', function () { return _this.processImages(images_2, usedImages_1, compressedTexture); }),
24100
- hookTimeInfo("".concat(asyncShaderCompile ? 'async' : 'sync', " compile"), function () { return _this.precompile(compositions_1, pluginSystem_1, renderer, options); }),
24128
+ hookTimeInfo("".concat(asyncShaderCompile ? 'async' : 'sync', "Compile"), function () { return _this.precompile(compositions_1, pluginSystem_1, renderer, options); }),
24101
24129
  ])];
24102
24130
  case 8:
24103
24131
  _d = __read$3.apply(void 0, [_e.sent(), 2]), loadedBins_1 = _d[0], loadedImages_1 = _d[1];
@@ -24109,6 +24137,7 @@ var AssetManager = /** @class */ (function () {
24109
24137
  loadedTextures = _e.sent();
24110
24138
  jsonScene_1.compositions = this.updateSceneData(jsonScene_1.compositions);
24111
24139
  scene = {
24140
+ timeInfos: timeInfos,
24112
24141
  url: url,
24113
24142
  renderLevel: this.options.renderLevel,
24114
24143
  storage: {},
@@ -24127,11 +24156,13 @@ var AssetManager = /** @class */ (function () {
24127
24156
  _e.label = 12;
24128
24157
  case 12:
24129
24158
  totalTime = performance.now() - startTime;
24130
- logger.info("Load asset: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(timeInfos.join(' '), ", url: ").concat(assetUrl));
24159
+ logger.info("Load asset: totalTime: ".concat(totalTime.toFixed(4), "ms ").concat(timeInfoMessages.join(' '), ", url: ").concat(assetUrl));
24131
24160
  window.clearTimeout(loadTimer);
24132
24161
  this.removeTimer(loadTimer);
24133
24162
  scene.totalTime = totalTime;
24134
24163
  scene.startTime = startTime;
24164
+ // 各部分分段时长
24165
+ scene.timeInfos = timeInfos;
24135
24166
  return [2 /*return*/, scene];
24136
24167
  }
24137
24168
  });
@@ -24979,7 +25010,7 @@ var Composition = /** @class */ (function () {
24979
25010
  * @param props - composition 的创建参数
24980
25011
  */
24981
25012
  function Composition(props, scene) {
24982
- var _a;
25013
+ var _a, _b;
24983
25014
  /**
24984
25015
  * 动画播放速度
24985
25016
  */
@@ -25008,7 +25039,7 @@ var Composition = /** @class */ (function () {
25008
25039
  this.paused = false;
25009
25040
  this.lastVideoUpdateTime = 0;
25010
25041
  this.postLoaders = [];
25011
- var _b = props.reusable, reusable = _b === void 0 ? false : _b, _c = props.speed, speed = _c === void 0 ? 1 : _c, _d = props.baseRenderOrder, baseRenderOrder = _d === void 0 ? 0 : _d, renderer = props.renderer, onPlayerPause = props.onPlayerPause, onMessageItem = props.onMessageItem, onEnd = props.onEnd, event = props.event, width = props.width, height = props.height;
25042
+ var _c = props.reusable, reusable = _c === void 0 ? false : _c, _d = props.speed, speed = _d === void 0 ? 1 : _d, _e = props.baseRenderOrder, baseRenderOrder = _e === void 0 ? 0 : _e, renderer = props.renderer, onPlayerPause = props.onPlayerPause, onMessageItem = props.onMessageItem, onEnd = props.onEnd, event = props.event, width = props.width, height = props.height;
25012
25043
  this.compositionSourceManager = new CompositionSourceManager(scene, renderer.engine);
25013
25044
  scene.jsonScene.imgUsage = undefined;
25014
25045
  if (reusable) {
@@ -25016,7 +25047,7 @@ var Composition = /** @class */ (function () {
25016
25047
  scene.textures = undefined;
25017
25048
  scene.consumed = true;
25018
25049
  }
25019
- var _e = this.compositionSourceManager, sourceContent = _e.sourceContent, pluginSystem = _e.pluginSystem, imgUsage = _e.imgUsage, totalTime = _e.totalTime, renderLevel = _e.renderLevel, refCompositionProps = _e.refCompositionProps;
25050
+ var _f = this.compositionSourceManager, sourceContent = _f.sourceContent, pluginSystem = _f.pluginSystem, imgUsage = _f.imgUsage, totalTime = _f.totalTime, renderLevel = _f.renderLevel, refCompositionProps = _f.refCompositionProps;
25020
25051
  assertExist(sourceContent);
25021
25052
  this.refCompositionProps = refCompositionProps;
25022
25053
  var vfxItem = new CompVFXItem(sourceContent, this);
@@ -25033,7 +25064,7 @@ var Composition = /** @class */ (function () {
25033
25064
  this.renderer = renderer;
25034
25065
  this.texInfo = imageUsage !== null && imageUsage !== void 0 ? imageUsage : {};
25035
25066
  this.event = event;
25036
- this.statistic = { loadTime: totalTime !== null && totalTime !== void 0 ? totalTime : 0, loadStart: (_a = scene.startTime) !== null && _a !== void 0 ? _a : 0, firstFrameTime: 0 };
25067
+ this.statistic = { loadTime: totalTime !== null && totalTime !== void 0 ? totalTime : 0, loadStart: (_a = scene.startTime) !== null && _a !== void 0 ? _a : 0, firstFrameTime: 0, precompileTime: (_b = scene.timeInfos['asyncCompile']) !== null && _b !== void 0 ? _b : scene.timeInfos['syncCompile'] };
25037
25068
  this.reusable = reusable;
25038
25069
  this.speed = speed;
25039
25070
  this.renderLevel = renderLevel;
@@ -27423,7 +27454,7 @@ Geometry.create = function (engine, options) {
27423
27454
  Mesh.create = function (engine, props) {
27424
27455
  return new ThreeMesh(engine, props);
27425
27456
  };
27426
- var version = "1.6.0-beta.0";
27457
+ var version = "1.6.0-beta.1";
27427
27458
  logger.info('THREEJS plugin version: ' + version);
27428
27459
 
27429
27460
  export { AbstractPlugin, AssetManager, BYTES_TYPE_MAP, BezierCurve, BezierCurvePath, COMPRESSED_TEXTURE, CONSTANT_MAP_BLEND, CONSTANT_MAP_DEPTH, CONSTANT_MAP_STENCIL_FUNC, CONSTANT_MAP_STENCIL_OP, COPY_FRAGMENT_SHADER, COPY_MESH_SHADER_ID, COPY_VERTEX_SHADER, CalculateItem, CalculateLoader, CalculateVFXItem, Camera, CameraController, CameraVFXItem, CameraVFXItemLoader, Composition, CompositionSourceManager, DEFAULT_FONTS, DestroyOptions, Downloader, EFFECTS_COPY_MESH_NAME, EVENT_TYPE_CLICK, EVENT_TYPE_TOUCH_END, EVENT_TYPE_TOUCH_MOVE, EVENT_TYPE_TOUCH_START, Engine, EventSystem, FILTER_NAME_NONE, FilterMode, FilterSpriteVFXItem, Float16ArrayWrapper, FrameBuffer, GLSLVersion, GPUCapability, Geometry, GlobalUniforms, GradientValue, HELP_LINK, HitTestType, InteractBehavior$1 as InteractBehavior, InteractItem, InteractLoader, InteractMesh, InteractVFXItem, Item, KTXTexture, LineSegments, LinearValue, Material, MaterialDataBlock, MaterialRenderType, Mesh, OrderType, PLAYER_OPTIONS_ENV_EDITOR, POST_PROCESS_SETTINGS, ParticleLoader, ParticleMesh, ParticleSystem, ParticleVFXItem, PassTextureCache, PluginSystem, QCanvasViewer, QText, QTextWrapMode, RENDER_PASS_NAME_PREFIX, RENDER_PREFER_LOOKUP_TEXTURE, RUNTIME_ENV, RandomSetValue, RandomValue, RandomVectorValue, RenderBuffer, RenderFrame, RenderPass, RenderPassAttachmentStorageType, RenderPassDestroyAttachmentType, RenderPassPriorityNormal, RenderPassPriorityPostprocess, RenderPassPriorityPrepare, RenderTargetHandle, RenderTextureFormat, Renderer, SEMANTIC_MAIN_PRE_COLOR_ATTACHMENT_0, SEMANTIC_MAIN_PRE_COLOR_ATTACHMENT_SIZE_0, SEMANTIC_PRE_COLOR_ATTACHMENT_0, SEMANTIC_PRE_COLOR_ATTACHMENT_SIZE_0, SPRITE_VERTEX_STRIDE, SemanticMap, Shader, ShaderCompileResultStatus, ShaderType, SpriteItem, SpriteLoader, SpriteMesh, SpriteVFXItem, StaticValue, TEMPLATE_USE_OFFSCREEN_CANVAS, TEXTURE_UNIFORM_MAP, TextItem, TextLoader, TextMesh, TextVFXItem, Texture, TextureFactory, TextureLoadAction, TextureSourceType, TextureStoreAction, ThreeComposition, ThreeDisplayObject, ThreeMaterial, ThreeTexture, Ticker, TimelineComponent, Transform, VFXItem, ValueGetter, addByOrder, addItem, addItemWithOrder, alphaFrameFrag, alphaMaskFrag, assertExist, asserts, blend, bloomMixVert, bloomThresholdVert, calculateTranslation, cameraMove_frag as cameraMoveFrag, cameraMoveVert, canvasPool, colorGradingFrag, colorStopsFromGradient, colorToArr$1 as colorToArr, combineImageTemplate, combineImageTemplate1, combineImageTemplate1Async, combineImageTemplate2, combineImageTemplate2Async, combineImageTemplateAsync, compatible_frag as compatibleFrag, compatible_vert as compatibleVert, convertAnchor, copyFrag, createCopyShader, createFilter, createFilterShaders, createGLContext, createKeyFrameMeta, createShaderWithMarcos, createShape, createVFXItem, createValueGetter, decimalEqual, deepClone, defaultGlobalVolume, defaultPlugins, delayFrag, deserializeMipmapTexture, distortionFrag, distortionVert, earcut, enlargeBuffer, ensureVec3, filters, findPreviousRenderPass, gaussianDown_frag as gaussianDownFrag, gaussianDownHFrag, gaussianDownVFrag, gaussianUpFrag, generateEmptyTypedArray, generateHalfFloatTexture, getBackgroundImage, getColorFromGradientStops, getConfig, getDefaultTemplateCanvasPool, getDefaultTextureFactory, getGeometryByShape, getGeometryTriangles, getImageItemRenderInfo, getKTXTextureOptions, getKeyFrameMetaByRawValue, getParticleMeshShader, getPixelRatio, getPreMultiAlpha, getStandardComposition, getStandardImage, getStandardItem, getStandardJSON, getTextureSize, glContext, gpuTimer, imageDataFromColor, imageDataFromGradient, initErrors, initGLContext, integrate, interpolateColor, isAlipayMiniApp, isAndroid, isArray, isFunction, isIOS, isObject, isScene, isSimulatorCellPhone, isString, isUniformStruct, isUniformStructArray, isValidFontFamily, isWebGL2, itemFrag, itemFrameFrag, itemVert, loadBinary, loadBlob, loadImage, loadMedia, loadVideo, loadWebPOptional, logger, index as math, maxSpriteMeshItemCount, maxSpriteTextureCount, modifyMaxKeyframeShader, nearestPowerOfTwo, noop, numberToFix, parsePercent$1 as parsePercent, particleFrag, particleOriginTranslateMap, particleUniformTypeMap, particleVert, pluginLoaderMap, pointOnLine, random, registerFilter, registerFilters, registerPlugin, removeItem, requestAsync, rotateVec2, screenMeshVert, setBlendMode, setConfig, setDefaultTextureFactory, setMaskMode, setMaxSpriteMeshItemCount, setRayFromCamera, setSideMode, setSpriteMeshMaxFragmentTextures, setSpriteMeshMaxItemCountByGPU, setUniformValue, sortByOrder, index$1 as spec, spriteMeshShaderFromFilter, spriteMeshShaderFromRenderInfo, spriteMeshShaderIdFromRenderInfo, thresholdFrag, throwDestroyedError, trailVert, translatePoint, trianglesFromRect, unregisterPlugin, valIfUndefined, value, valueDefine, vecAssign, vecFill, vecMulCombine, vecNormalize, version };