@galacean/effects-threejs 1.5.2 → 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.5.2
6
+ * Version: v1.6.0-beta.1
7
7
  */
8
8
 
9
9
  import * as THREE from 'three';
@@ -10071,10 +10071,23 @@ var EventSystem = /** @class */ (function () {
10071
10071
  var getTouchEventValue = function (event, x, y, dx, dy) {
10072
10072
  if (dx === void 0) { dx = 0; }
10073
10073
  if (dy === void 0) { dy = 0; }
10074
- var _a = _this.target, width = _a.width, height = _a.height;
10075
- var ts = performance.now();
10076
10074
  var vx = 0;
10077
10075
  var vy = 0;
10076
+ var ts = performance.now();
10077
+ if (!_this.target) {
10078
+ logger.error('Trigger TouchEvent after EventSystem is disposed');
10079
+ return {
10080
+ x: x,
10081
+ y: y,
10082
+ vx: 0,
10083
+ vy: vy,
10084
+ dx: dx,
10085
+ dy: dy,
10086
+ ts: ts,
10087
+ width: 0, height: 0, origin: event,
10088
+ };
10089
+ }
10090
+ var _a = _this.target, width = _a.width, height = _a.height;
10078
10091
  if (lastTouch) {
10079
10092
  var dt = ts - lastTouch.ts;
10080
10093
  vx = ((dx - lastTouch.dx) / dt) || 0;
@@ -13505,6 +13518,14 @@ var InteractVFXItem = /** @class */ (function (_super) {
13505
13518
  function InteractVFXItem(props, composition) {
13506
13519
  var _a;
13507
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];
13508
13529
  _this.engine = (_a = _this.composition) === null || _a === void 0 ? void 0 : _a.getEngine();
13509
13530
  return _this;
13510
13531
  }
@@ -13515,8 +13536,23 @@ var InteractVFXItem = /** @class */ (function (_super) {
13515
13536
  enumerable: false,
13516
13537
  configurable: true
13517
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
+ });
13518
13553
  InteractVFXItem.prototype.onConstructed = function (options) {
13519
13554
  this.ui = options.content;
13555
+ this.enabled = true;
13520
13556
  };
13521
13557
  InteractVFXItem.prototype.onLifetimeBegin = function (composition) {
13522
13558
  var _a, _b, _c;
@@ -13535,9 +13571,8 @@ var InteractVFXItem = /** @class */ (function (_super) {
13535
13571
  if (!this.dragEvent || !this.bouncingArg) {
13536
13572
  return;
13537
13573
  }
13538
- var downgrade = 0.95;
13539
- this.bouncingArg.vx *= downgrade;
13540
- this.bouncingArg.vy *= downgrade;
13574
+ this.bouncingArg.vx *= this.downgrade;
13575
+ this.bouncingArg.vy *= this.downgrade;
13541
13576
  this.bouncingArg.dy += this.bouncingArg.vy;
13542
13577
  this.bouncingArg.dx += this.bouncingArg.vx;
13543
13578
  if (shouldIgnoreBouncing(this.bouncingArg)) {
@@ -13573,7 +13608,7 @@ var InteractVFXItem = /** @class */ (function (_super) {
13573
13608
  };
13574
13609
  };
13575
13610
  InteractVFXItem.prototype.getHitTestParams = function () {
13576
- if (!this.clickable) {
13611
+ if (!this.clickable || !this.canInteract()) {
13577
13612
  return;
13578
13613
  }
13579
13614
  var behavior = this.ui.options.behavior;
@@ -13610,6 +13645,9 @@ var InteractVFXItem = /** @class */ (function (_super) {
13610
13645
  var handlerMap = {
13611
13646
  touchstart: function (event) {
13612
13647
  var _a;
13648
+ if (!_this.canInteract()) {
13649
+ return;
13650
+ }
13613
13651
  _this.dragEvent = null;
13614
13652
  _this.bouncingArg = null;
13615
13653
  var camera = (_a = _this.composition) === null || _a === void 0 ? void 0 : _a.camera;
@@ -13627,6 +13665,9 @@ var InteractVFXItem = /** @class */ (function (_super) {
13627
13665
  _this.bouncingArg = event;
13628
13666
  },
13629
13667
  touchend: function (event) {
13668
+ if (!_this.canInteract()) {
13669
+ return;
13670
+ }
13630
13671
  var bouncingArg = _this.bouncingArg;
13631
13672
  if (!shouldIgnoreBouncing(bouncingArg, 3) && bouncingArg) {
13632
13673
  var speed = 5;
@@ -13652,7 +13693,7 @@ var InteractVFXItem = /** @class */ (function (_super) {
13652
13693
  };
13653
13694
  InteractVFXItem.prototype.handleDragMove = function (evt, event) {
13654
13695
  var _a, _b;
13655
- if (!(evt && evt.cameraParam) || !this.composition) {
13696
+ if (!(evt === null || evt === void 0 ? void 0 : evt.cameraParam) || !this.canInteract() || !this.composition) {
13656
13697
  return;
13657
13698
  }
13658
13699
  var options = this.ui.options;
@@ -13663,8 +13704,8 @@ var InteractVFXItem = /** @class */ (function (_super) {
13663
13704
  var sp = Math.tan(fov * Math.PI / 180 / 2) * Math.abs(depth);
13664
13705
  var height = dy * sp;
13665
13706
  var width = dx * sp;
13666
- var nx = position[0] - width;
13667
- var ny = position[1] - height;
13707
+ var nx = position[0] - this.dragRatio[0] * width;
13708
+ var ny = position[1] - this.dragRatio[1] * height;
13668
13709
  if (options.dxRange) {
13669
13710
  var _d = __read$3(options.dxRange, 2), min = _d[0], max = _d[1];
13670
13711
  nx = clamp$1(nx, min, max);
@@ -13681,6 +13722,10 @@ var InteractVFXItem = /** @class */ (function (_super) {
13681
13722
  }
13682
13723
  this.composition.camera.position = new Vector3(nx, ny, depth);
13683
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
+ };
13684
13729
  return InteractVFXItem;
13685
13730
  }(VFXItem));
13686
13731
  function shouldIgnoreBouncing(arg, mul) {
@@ -23986,27 +24031,28 @@ var AssetManager = /** @class */ (function () {
23986
24031
  AssetManager.prototype.loadScene = function (url, renderer, options) {
23987
24032
  var _a, _b, _c;
23988
24033
  return __awaiter(this, void 0, void 0, function () {
23989
- 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;
23990
24035
  var _this = this;
23991
24036
  return __generator(this, function (_d) {
23992
24037
  assetUrl = isString(url) ? url : this.id;
23993
24038
  startTime = performance.now();
23994
- timeInfos = [];
24039
+ timeInfoMessages = [];
23995
24040
  gpuInstance = renderer === null || renderer === void 0 ? void 0 : renderer.engine.gpuCapability;
23996
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;
23997
24042
  compressedTexture = (_c = gpuInstance === null || gpuInstance === void 0 ? void 0 : gpuInstance.detail.compressedTexture) !== null && _c !== void 0 ? _c : 0;
24043
+ timeInfos = {};
23998
24044
  cancelLoading = false;
23999
24045
  waitPromise = new Promise(function (resolve, reject) {
24000
24046
  loadTimer = window.setTimeout(function () {
24001
24047
  cancelLoading = true;
24002
24048
  _this.removeTimer(loadTimer);
24003
24049
  var totalTime = performance.now() - startTime;
24004
- 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));
24005
24051
  }, _this.timeout * 1000);
24006
24052
  _this.timers.push(loadTimer);
24007
24053
  });
24008
24054
  hookTimeInfo = function (label, func) { return __awaiter(_this, void 0, void 0, function () {
24009
- var st, result, e_1;
24055
+ var st, result, time, e_1;
24010
24056
  return __generator(this, function (_a) {
24011
24057
  switch (_a.label) {
24012
24058
  case 0:
@@ -24018,7 +24064,9 @@ var AssetManager = /** @class */ (function () {
24018
24064
  return [4 /*yield*/, func()];
24019
24065
  case 2:
24020
24066
  result = _a.sent();
24021
- 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;
24022
24070
  return [2 /*return*/, result];
24023
24071
  case 3:
24024
24072
  e_1 = _a.sent();
@@ -24077,7 +24125,7 @@ var AssetManager = /** @class */ (function () {
24077
24125
  return [4 /*yield*/, Promise.all([
24078
24126
  hookTimeInfo('processBins', function () { return _this.processBins(bins_1); }),
24079
24127
  hookTimeInfo('processImages', function () { return _this.processImages(images_2, usedImages_1, compressedTexture); }),
24080
- 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); }),
24081
24129
  ])];
24082
24130
  case 8:
24083
24131
  _d = __read$3.apply(void 0, [_e.sent(), 2]), loadedBins_1 = _d[0], loadedImages_1 = _d[1];
@@ -24089,6 +24137,7 @@ var AssetManager = /** @class */ (function () {
24089
24137
  loadedTextures = _e.sent();
24090
24138
  jsonScene_1.compositions = this.updateSceneData(jsonScene_1.compositions);
24091
24139
  scene = {
24140
+ timeInfos: timeInfos,
24092
24141
  url: url,
24093
24142
  renderLevel: this.options.renderLevel,
24094
24143
  storage: {},
@@ -24107,11 +24156,13 @@ var AssetManager = /** @class */ (function () {
24107
24156
  _e.label = 12;
24108
24157
  case 12:
24109
24158
  totalTime = performance.now() - startTime;
24110
- 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));
24111
24160
  window.clearTimeout(loadTimer);
24112
24161
  this.removeTimer(loadTimer);
24113
24162
  scene.totalTime = totalTime;
24114
24163
  scene.startTime = startTime;
24164
+ // 各部分分段时长
24165
+ scene.timeInfos = timeInfos;
24115
24166
  return [2 /*return*/, scene];
24116
24167
  }
24117
24168
  });
@@ -24959,7 +25010,7 @@ var Composition = /** @class */ (function () {
24959
25010
  * @param props - composition 的创建参数
24960
25011
  */
24961
25012
  function Composition(props, scene) {
24962
- var _a;
25013
+ var _a, _b;
24963
25014
  /**
24964
25015
  * 动画播放速度
24965
25016
  */
@@ -24988,7 +25039,7 @@ var Composition = /** @class */ (function () {
24988
25039
  this.paused = false;
24989
25040
  this.lastVideoUpdateTime = 0;
24990
25041
  this.postLoaders = [];
24991
- 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;
24992
25043
  this.compositionSourceManager = new CompositionSourceManager(scene, renderer.engine);
24993
25044
  scene.jsonScene.imgUsage = undefined;
24994
25045
  if (reusable) {
@@ -24996,7 +25047,7 @@ var Composition = /** @class */ (function () {
24996
25047
  scene.textures = undefined;
24997
25048
  scene.consumed = true;
24998
25049
  }
24999
- 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;
25000
25051
  assertExist(sourceContent);
25001
25052
  this.refCompositionProps = refCompositionProps;
25002
25053
  var vfxItem = new CompVFXItem(sourceContent, this);
@@ -25013,7 +25064,7 @@ var Composition = /** @class */ (function () {
25013
25064
  this.renderer = renderer;
25014
25065
  this.texInfo = imageUsage !== null && imageUsage !== void 0 ? imageUsage : {};
25015
25066
  this.event = event;
25016
- 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'] };
25017
25068
  this.reusable = reusable;
25018
25069
  this.speed = speed;
25019
25070
  this.renderLevel = renderLevel;
@@ -25025,6 +25076,7 @@ var Composition = /** @class */ (function () {
25025
25076
  this.camera = new Camera(this.name, __assign$1(__assign$1({}, sourceContent === null || sourceContent === void 0 ? void 0 : sourceContent.camera), { aspect: width / height }));
25026
25077
  this.url = scene.url;
25027
25078
  this.assigned = true;
25079
+ this.interactive = true;
25028
25080
  this.onPlayerPause = onPlayerPause;
25029
25081
  this.onMessageItem = onMessageItem;
25030
25082
  this.onEnd = onEnd;
@@ -25404,7 +25456,7 @@ var Composition = /** @class */ (function () {
25404
25456
  * @param options - 最大求交数和求交时的回调
25405
25457
  */
25406
25458
  Composition.prototype.hitTest = function (x, y, force, options) {
25407
- if (this.isDestroyed) {
25459
+ if (this.isDestroyed || !this.interactive) {
25408
25460
  return [];
25409
25461
  }
25410
25462
  var regions = [];
@@ -27402,7 +27454,7 @@ Geometry.create = function (engine, options) {
27402
27454
  Mesh.create = function (engine, props) {
27403
27455
  return new ThreeMesh(engine, props);
27404
27456
  };
27405
- var version = "1.5.2";
27457
+ var version = "1.6.0-beta.1";
27406
27458
  logger.info('THREEJS plugin version: ' + version);
27407
27459
 
27408
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 };