@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.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: v2.3.0-beta.2
6
+ * Version: v2.3.0
7
7
  */
8
8
 
9
9
  import * as THREE from 'three';
@@ -25519,9 +25519,12 @@ var TextComponentBase = /*#__PURE__*/ function() {
25519
25519
  this.textStyle = new TextStyle(options);
25520
25520
  this.textLayout = new TextLayout(options);
25521
25521
  this.text = options.text.toString();
25522
+ this.lineCount = this.getLineCount(options.text, true);
25522
25523
  };
25523
- _proto.getLineCount = function getLineCount(text, context) {
25524
+ _proto.getLineCount = function getLineCount(text, init) {
25525
+ var context = this.context;
25524
25526
  var _this_textLayout = this.textLayout, letterSpace = _this_textLayout.letterSpace, overflow = _this_textLayout.overflow;
25527
+ var fontScale = init ? this.textStyle.fontSize / 10 : 1 / this.textStyle.fontScale;
25525
25528
  var width = this.textLayout.width + this.textStyle.fontOffset;
25526
25529
  var lineCount = 1;
25527
25530
  var x = 0;
@@ -25529,7 +25532,7 @@ var TextComponentBase = /*#__PURE__*/ function() {
25529
25532
  var _context_measureText;
25530
25533
  var str = text[i];
25531
25534
  var _context_measureText_width;
25532
- 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;
25535
+ 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;
25533
25536
  // 和浏览器行为保持一致
25534
25537
  x += letterSpace;
25535
25538
  // 处理文本结束行为
@@ -25599,6 +25602,7 @@ var TextComponentBase = /*#__PURE__*/ function() {
25599
25602
  return;
25600
25603
  }
25601
25604
  this.text = value.toString();
25605
+ this.lineCount = this.getLineCount(value, false);
25602
25606
  this.isDirty = true;
25603
25607
  };
25604
25608
  /**
@@ -25759,35 +25763,32 @@ var TextComponentBase = /*#__PURE__*/ function() {
25759
25763
  var layout = this.textLayout;
25760
25764
  var fontScale = style.fontScale;
25761
25765
  var width = (layout.width + style.fontOffset) * fontScale;
25766
+ var finalHeight = layout.lineHeight * this.lineCount;
25762
25767
  var fontSize = style.fontSize * fontScale;
25763
25768
  var lineHeight = layout.lineHeight * fontScale;
25764
25769
  style.fontDesc = this.getFontDesc(fontSize);
25765
25770
  this.char = (this.text || "").split("");
25766
25771
  this.canvas.width = width;
25767
- var height = this.canvas.height;
25768
- context.font = style.fontDesc;
25769
- this.lineCount = this.getLineCount(this.text, context);
25770
- var finalHeight = layout.lineHeight * this.lineCount;
25771
25772
  if (layout.autoWidth) {
25772
25773
  this.canvas.height = finalHeight * fontScale;
25773
25774
  this.item.transform.size.set(1, finalHeight / layout.height);
25774
25775
  } else {
25775
25776
  this.canvas.height = layout.height * fontScale;
25776
25777
  }
25778
+ var height = this.canvas.height;
25779
+ // fix bug 1/255
25780
+ context.fillStyle = "rgba(255, 255, 255, 0.0039)";
25781
+ if (!flipY) {
25782
+ context.translate(0, height);
25783
+ context.scale(1, -1);
25784
+ }
25777
25785
  // canvas size 变化后重新刷新 context
25778
25786
  if (this.maxLineWidth > width && layout.overflow === TextOverflow.display) {
25779
25787
  context.font = this.getFontDesc(fontSize * width / this.maxLineWidth);
25780
25788
  } else {
25781
25789
  context.font = style.fontDesc;
25782
25790
  }
25783
- // fix bug 1/255
25784
- context.fillStyle = "rgba(255, 255, 255, 0.0039)";
25785
25791
  context.clearRect(0, 0, width, height);
25786
- if (!flipY) {
25787
- context.translate(0, height);
25788
- context.scale(1, -1);
25789
- }
25790
- context.fillRect(0, 0, width, height);
25791
25792
  if (style.hasShadow) {
25792
25793
  this.setupShadow();
25793
25794
  }
@@ -25859,9 +25860,9 @@ var TextComponentBase = /*#__PURE__*/ function() {
25859
25860
  this.material.setTexture("_MainTex", texture);
25860
25861
  this.isDirty = false;
25861
25862
  };
25862
- _proto.getFontDesc = function getFontDesc(fontSize) {
25863
- var _this_textStyle = this.textStyle, fontFamily = _this_textStyle.fontFamily, textWeight = _this_textStyle.textWeight, fontStyle = _this_textStyle.fontStyle;
25864
- var fontDesc = "" + fontSize.toString() + "px ";
25863
+ _proto.getFontDesc = function getFontDesc(size) {
25864
+ 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;
25865
+ var fontDesc = "" + (size || fontSize * fontScale).toString() + "px ";
25865
25866
  if (!DEFAULT_FONTS.includes(fontFamily)) {
25866
25867
  fontDesc += '"' + fontFamily + '"';
25867
25868
  } else {
@@ -32076,7 +32077,7 @@ registerPlugin("sprite", SpriteLoader, VFXItem);
32076
32077
  registerPlugin("particle", ParticleLoader, VFXItem);
32077
32078
  registerPlugin("cal", CalculateLoader, VFXItem);
32078
32079
  registerPlugin("interact", InteractLoader, VFXItem);
32079
- var version$1 = "2.3.0-beta.2";
32080
+ var version$1 = "2.3.0";
32080
32081
  logger.info("Core version: " + version$1 + ".");
32081
32082
 
32082
32083
  var _obj;
@@ -33336,6 +33337,7 @@ var ThreeRenderer = /*#__PURE__*/ function(Renderer) {
33336
33337
  _this.baseCompositionIndex = 0;
33337
33338
  var width = options.width, height = options.height, camera = options.camera;
33338
33339
  _this.renderer = new ThreeRenderer(context);
33340
+ _this.assetService = new AssetService(_this.renderer.engine);
33339
33341
  _this.width = width;
33340
33342
  _this.height = height;
33341
33343
  _this.camera = camera;
@@ -33345,63 +33347,109 @@ var ThreeRenderer = /*#__PURE__*/ function(Renderer) {
33345
33347
  _proto.loadScene = function loadScene(scene, options) {
33346
33348
  var _this = this;
33347
33349
  return _async_to_generator(function() {
33348
- var composition, baseOrder;
33350
+ var last, scenes, compositions, _options_autoplay, autoplay, baseOrder, _scenes, i, compositionNames, firstFrameTime, _iterator, _step, composition;
33349
33351
  return __generator(this, function(_state) {
33350
33352
  switch(_state.label){
33351
33353
  case 0:
33354
+ assertExist(_this.renderer, "Renderer is not exist, maybe the Player has been disabled or in gl 'debug-disable' mode.");
33355
+ last = performance.now();
33356
+ scenes = [];
33357
+ compositions = [];
33358
+ autoplay = (_options_autoplay = options == null ? void 0 : options.autoplay) != null ? _options_autoplay : true;
33352
33359
  baseOrder = _this.baseCompositionIndex;
33353
- if (!isArray(scene)) return [
33354
- 3,
33355
- 2
33356
- ];
33357
- _this.baseCompositionIndex += scene.length;
33360
+ if (isArray(scene)) {
33361
+ (_scenes = scenes).push.apply(_scenes, [].concat(scene));
33362
+ } else {
33363
+ scenes.push(scene);
33364
+ }
33358
33365
  return [
33359
33366
  4,
33360
- Promise.all(scene.map(/*#__PURE__*/ _async_to_generator(function(scn, index) {
33361
- var res;
33367
+ Promise.all(scenes.map(/*#__PURE__*/ _async_to_generator(function(url, index) {
33368
+ var _this_assetService_assembleSceneLoadOptions, source, opts, assetManager, _$scene, composition;
33362
33369
  return __generator(this, function(_state) {
33363
33370
  switch(_state.label){
33364
33371
  case 0:
33372
+ _this_assetService_assembleSceneLoadOptions = _this.assetService.assembleSceneLoadOptions(url, _extends({
33373
+ autoplay: autoplay
33374
+ }, options)), source = _this_assetService_assembleSceneLoadOptions.source, opts = _this_assetService_assembleSceneLoadOptions.options;
33375
+ assetManager = new AssetManager(opts);
33365
33376
  return [
33366
33377
  4,
33367
- _this.createComposition(scn, options)
33378
+ assetManager.loadScene(source, _this.renderer, {
33379
+ env: _this.env
33380
+ })
33368
33381
  ];
33369
33382
  case 1:
33370
- res = _state.sent();
33371
- res.setIndex(baseOrder + index);
33383
+ _$scene = _state.sent();
33384
+ _this.assetService.prepareAssets(_$scene, assetManager.getAssets());
33385
+ _this.assetService.updateTextVariables(_$scene, assetManager.options.variables);
33386
+ _this.assetService.initializeTexture(_$scene);
33387
+ _$scene.pluginSystem.precompile(_$scene.jsonScene.compositions, _this.renderer, options);
33388
+ composition = _this.createComposition(_$scene, opts);
33389
+ _this.baseCompositionIndex += 1;
33390
+ composition.setIndex(baseOrder + index);
33391
+ compositions[index] = composition;
33372
33392
  return [
33373
- 2,
33374
- res
33393
+ 2
33375
33394
  ];
33376
33395
  }
33377
33396
  });
33378
33397
  })))
33379
33398
  ];
33380
33399
  case 1:
33381
- composition = _state.sent();
33382
- return [
33383
- 3,
33384
- 4
33385
- ];
33386
- case 2:
33387
- _this.baseCompositionIndex += 1;
33388
- return [
33389
- 4,
33390
- _this.createComposition(scene, options)
33391
- ];
33392
- case 3:
33393
- composition = _state.sent();
33394
- composition.setIndex(baseOrder);
33395
- _state.label = 4;
33396
- case 4:
33400
+ _state.sent();
33401
+ for(i = 0; i < compositions.length; i++){
33402
+ if (autoplay) {
33403
+ compositions[i].play();
33404
+ } else {
33405
+ compositions[i].pause();
33406
+ }
33407
+ }
33408
+ compositionNames = compositions.map(function(composition) {
33409
+ return composition.name;
33410
+ });
33411
+ firstFrameTime = performance.now() - last;
33412
+ for(_iterator = _create_for_of_iterator_helper_loose(compositions); !(_step = _iterator()).done;){
33413
+ composition = _step.value;
33414
+ composition.statistic.firstFrameTime = firstFrameTime;
33415
+ }
33416
+ logger.info("First frame [" + compositionNames + "]: " + firstFrameTime.toFixed(4) + "ms.");
33397
33417
  return [
33398
33418
  2,
33399
- composition
33419
+ isArray(scene) ? compositions : compositions[0]
33400
33420
  ];
33401
33421
  }
33402
33422
  });
33403
33423
  })();
33404
33424
  };
33425
+ _proto.createComposition = function createComposition(scene, options) {
33426
+ var _this = this;
33427
+ if (options === void 0) options = {};
33428
+ var composition = new ThreeComposition(_extends({}, options, {
33429
+ width: this.width,
33430
+ height: this.height,
33431
+ renderer: this.renderer,
33432
+ handleItemMessage: function(message) {
33433
+ _this.dispatchEvent({
33434
+ type: "message",
33435
+ message: message
33436
+ });
33437
+ }
33438
+ }), scene);
33439
+ composition.on("end", function() {
33440
+ _this.dispatchEvent({
33441
+ type: "end",
33442
+ composition: composition
33443
+ });
33444
+ });
33445
+ this.renderer.engine.setOptions({
33446
+ threeCamera: this.camera,
33447
+ threeGroup: this,
33448
+ composition: composition
33449
+ });
33450
+ this.compositions.push(composition);
33451
+ return composition;
33452
+ };
33405
33453
  _proto.pause = function pause() {
33406
33454
  this.dispatchEvent({
33407
33455
  type: "pause"
@@ -33415,99 +33463,6 @@ var ThreeRenderer = /*#__PURE__*/ function(Renderer) {
33415
33463
  composition.resume();
33416
33464
  });
33417
33465
  };
33418
- _proto.createComposition = function createComposition(url, options) {
33419
- if (options === void 0) options = {};
33420
- var _this = this;
33421
- return _async_to_generator(function() {
33422
- var last, opts, source, scene, engine, i, composition, firstFrameTime;
33423
- return __generator(this, function(_state) {
33424
- switch(_state.label){
33425
- case 0:
33426
- last = performance.now();
33427
- opts = _extends({
33428
- autoplay: true
33429
- }, options);
33430
- source = url;
33431
- if (Scene.isURL(url)) {
33432
- if (!Scene.isJSONObject(url)) {
33433
- source = url.url;
33434
- }
33435
- if (Scene.isWithOptions(url)) {
33436
- opts = _extends({}, opts, url.options || {});
33437
- }
33438
- }
33439
- if (_this.assetManager) {
33440
- _this.assetManager.updateOptions(opts);
33441
- } else {
33442
- _this.assetManager = new AssetManager(opts);
33443
- }
33444
- return [
33445
- 4,
33446
- _this.assetManager.loadScene(source, _this.renderer, {
33447
- env: _this.env
33448
- })
33449
- ];
33450
- case 1:
33451
- scene = _state.sent();
33452
- engine = _this.renderer.engine;
33453
- // TODO 多 json 之间目前不共用资源,如果后续需要多 json 共用,这边缓存机制需要额外处理
33454
- engine.clearResources();
33455
- engine.addPackageDatas(scene);
33456
- for(i = 0; i < scene.textureOptions.length; i++){
33457
- scene.textureOptions[i] = engine.assetLoader.loadGUID(scene.textureOptions[i].id);
33458
- scene.textureOptions[i].initialize();
33459
- }
33460
- if (!engine.database) return [
33461
- 3,
33462
- 3
33463
- ];
33464
- return [
33465
- 4,
33466
- engine.createVFXItems(scene)
33467
- ];
33468
- case 2:
33469
- _state.sent();
33470
- _state.label = 3;
33471
- case 3:
33472
- composition = new ThreeComposition(_extends({}, opts, {
33473
- width: _this.width,
33474
- height: _this.height,
33475
- renderer: _this.renderer,
33476
- handleItemMessage: function(message) {
33477
- _this.dispatchEvent({
33478
- type: "message",
33479
- message: message
33480
- });
33481
- }
33482
- }), scene);
33483
- composition.on("end", function() {
33484
- _this.dispatchEvent({
33485
- type: "end",
33486
- composition: composition
33487
- });
33488
- });
33489
- _this.renderer.engine.setOptions({
33490
- threeCamera: _this.camera,
33491
- threeGroup: _this,
33492
- composition: composition
33493
- });
33494
- if (opts.autoplay) {
33495
- composition.play();
33496
- } else {
33497
- composition.pause();
33498
- }
33499
- firstFrameTime = performance.now() - last + composition.statistic.loadTime;
33500
- composition.statistic.firstFrameTime = firstFrameTime;
33501
- logger.info("First frame: [" + composition.name + "]" + firstFrameTime.toFixed(4) + "ms.");
33502
- _this.compositions.push(composition);
33503
- return [
33504
- 2,
33505
- composition
33506
- ];
33507
- }
33508
- });
33509
- })();
33510
- };
33511
33466
  /**
33512
33467
  *
33513
33468
  * @param delta
@@ -33722,7 +33677,7 @@ setMaxSpriteMeshItemCount(8);
33722
33677
  */ Mesh.create = function(engine, props) {
33723
33678
  return new ThreeMesh(engine, props);
33724
33679
  };
33725
- var version = "2.3.0-beta.2";
33680
+ var version = "2.3.0";
33726
33681
  logger.info("THREEJS plugin version: " + version + ".");
33727
33682
 
33728
33683
  export { AbstractPlugin, ActivationPlayable, ActivationPlayableAsset, ActivationTrack, AnimationClip, AnimationClipPlayable, Asset, AssetLoader, AssetManager, AssetService, BYTES_TYPE_MAP, BaseRenderComponent, Behaviour, BezierCurve, BezierCurvePath, BezierCurveQuat, BinaryAsset, 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, CalculateLoader, Camera, CameraController, CameraVFXItemLoader, ColorCurve, ColorPropertyPlayableAsset, ColorPropertyTrack, Component, Composition, CompositionComponent, CompositionSourceManager, DEFAULT_FONTS, DEFAULT_FPS, Database, DestroyOptions, Downloader, EFFECTS_COPY_MESH_NAME, EVENT_TYPE_CLICK, EVENT_TYPE_TOUCH_END, EVENT_TYPE_TOUCH_MOVE, EVENT_TYPE_TOUCH_START, EffectComponent, EffectsObject, EffectsPackage, Engine, EventEmitter, EventSystem, Fake3DAnimationMode, Fake3DComponent, FilterMode, Float16ArrayWrapper, FloatPropertyPlayableAsset, FloatPropertyTrack, Framebuffer, GLSLVersion, GPUCapability, Geometry, GlobalUniforms, GradientValue, HELP_LINK, HitTestType, InteractComponent, InteractLoader, InteractMesh, Item, KTXTexture, LineSegments, LinearValue, Material, MaterialDataBlock, MaterialRenderType, MaterialTrack, Mesh, MeshCollider, ObjectBindingTrack, OrderType, PLAYER_OPTIONS_ENV_EDITOR, POST_PROCESS_SETTINGS, ParticleBehaviourPlayable, ParticleBehaviourPlayableAsset, ParticleLoader, ParticleMesh, ParticleSystem, ParticleSystemRenderer, ParticleTrack, PassTextureCache, PathSegments, PluginSystem, PostProcessVolume, PropertyTrack, RENDER_PASS_NAME_PREFIX, RENDER_PREFER_LOOKUP_TEXTURE, RUNTIME_ENV, RandomSetValue, RandomValue, RandomVectorValue, RenderFrame, RenderPass, RenderPassAttachmentStorageType, RenderPassDestroyAttachmentType, RenderPassPriorityNormal, RenderPassPriorityPostprocess, RenderPassPriorityPrepare, RenderTargetHandle, RenderTextureFormat, Renderbuffer, Renderer, RendererComponent, RuntimeClip, 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, Scene, SemanticMap, SerializationHelper, Shader, ShaderCompileResultStatus, ShaderFactory, ShaderType, ShaderVariant, ShapeComponent, SpriteColorPlayableAsset, SpriteColorTrack, SpriteComponent, SpriteLoader, StaticValue, SubCompositionPlayableAsset, SubCompositionTrack, TEMPLATE_USE_OFFSCREEN_CANVAS, TEXTURE_UNIFORM_MAP, TextComponent, TextComponentBase, TextLayout, TextLoader, TextStyle, Texture, TextureFactory, TextureLoadAction, TextureSourceType, TextureStoreAction, ThreeComposition, ThreeDisplayObject, ThreeEngine, ThreeMaterial, ThreeSpriteComponent, ThreeTextComponent, ThreeTexture, Ticker, TimelineAsset, TimelineClip, TimelinePlayable, TrackAsset, TrackSortWrapper, TrackType, Transform, TransformAnimationPlayable, TransformPlayableAsset, TransformTrack, VFXItem, ValueGetter, Vector2Curve, Vector2PropertyPlayableAsset, Vector2PropertyTrack, Vector4Curve, Vector4PropertyPlayableAsset, Vector4PropertyTrack, addByOrder, addItem, addItemWithOrder, applyMixins, assertExist, asserts, base64ToFile, blend, calculateTranslation, canvasPool, colorGradingFrag, colorStopsFromGradient, colorToArr$1 as colorToArr, combineImageTemplate, createCopyShader, createGLContext, createKeyFrameMeta, createShape, createValueGetter, decimalEqual, defaultPlugins, deserializeMipmapTexture, earcut, effectsClass, effectsClassStore, enlargeBuffer, ensureFixedNumber, ensureVec3, findPreviousRenderPass, gaussianDown_frag as gaussianDownFrag, gaussianDownHFrag, gaussianDownVFrag, gaussianUpFrag, generateEmptyTypedArray, generateGUID, generateHalfFloatTexture, generateTransparentTexture, generateWhiteTexture, getBackgroundImage, getColorFromGradientStops, getConfig, getDefaultTextureFactory, getGeometryByShape, getGeometryTriangles, getImageItemRenderInfo, getKTXTextureOptions, getKeyFrameMetaByRawValue, getMergedStore, getParticleMeshShader, getPixelRatio, getPreMultiAlpha, getStandardComposition, getStandardImage, getStandardItem, getStandardJSON, getTextureSize, glContext, glType2VertexFormatType, gpuTimer, imageDataFromColor, imageDataFromGradient, initErrors, initGLContext, integrate, interpolateColor, isAlipayMiniApp, isAndroid, isArray, isCanvas, isFunction, isIOS, isIOSByUA, isMiniProgram, isObject, isSimulatorCellPhone, isString, isUniformStruct, isUniformStructArray, isValidFontFamily, isWebGL2, isWechatMiniApp, itemFrag, itemFrameFrag, itemVert, loadAVIFOptional, loadBinary, loadBlob, loadImage, loadMedia, loadVideo, loadWebPOptional, logger, index as math, maxSpriteMeshItemCount, modifyMaxKeyframeShader, nearestPowerOfTwo, noop, normalizeColor, numberToFix, parsePercent$1 as parsePercent, particleFrag, particleOriginTranslateMap$1 as particleOriginTranslateMap, particleUniformTypeMap, particleVert, passRenderLevel, pluginLoaderMap, randomInRange, registerPlugin, removeItem, rotateVec2, screenMeshVert, serialize, setBlendMode, setConfig, setDefaultTextureFactory, setMaskMode, setMaxSpriteMeshItemCount, setRayFromCamera, setSideMode, setSpriteMeshMaxItemCountByGPU, setUniformValue, sortByOrder, index$1 as spec, spriteMeshShaderFromFilter, spriteMeshShaderFromRenderInfo, spriteMeshShaderIdFromRenderInfo, thresholdFrag, throwDestroyedError, trailVert, translatePoint, trianglesFromRect, unregisterPlugin, valIfUndefined, value, valueDefine, vecFill, vecMulCombine, version, vertexFormatType2GLType };