@galacean/effects-core 2.1.0-alpha.1 → 2.1.0-alpha.2

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 core for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v2.1.0-alpha.1
6
+ * Version: v2.1.0-alpha.2
7
7
  */
8
8
 
9
9
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
@@ -8348,7 +8348,7 @@ var seed$8 = 1;
8348
8348
  * 通过 URL 创建 Texture 对象。
8349
8349
  * @param url - 要创建的 Texture URL
8350
8350
  * @since 2.0.0
8351
- */ Texture.fromImage = function fromImage(url, engine) {
8351
+ */ Texture.fromImage = function fromImage(url, engine, options) {
8352
8352
  return _async_to_generator(function() {
8353
8353
  var image, texture;
8354
8354
  return __generator(this, function(_state) {
@@ -8360,12 +8360,13 @@ var seed$8 = 1;
8360
8360
  ];
8361
8361
  case 1:
8362
8362
  image = _state.sent();
8363
- texture = Texture.create(engine, {
8363
+ texture = Texture.create(engine, _extends({
8364
8364
  sourceType: TextureSourceType.image,
8365
8365
  image: image,
8366
+ target: glContext.TEXTURE_2D,
8366
8367
  id: generateGUID(),
8367
8368
  flipY: true
8368
- });
8369
+ }, options));
8369
8370
  texture.initialize();
8370
8371
  return [
8371
8372
  2,
@@ -10297,15 +10298,19 @@ var BezierCurve = /*#__PURE__*/ function(ValueGetter) {
10297
10298
  points: points,
10298
10299
  timeInterval: timeInterval,
10299
10300
  valueInterval: valueInterval,
10300
- curve: curve
10301
+ curve: curve,
10302
+ timeStart: Number(s.x),
10303
+ timeEnd: Number(e.x)
10301
10304
  };
10302
10305
  }
10303
10306
  };
10304
10307
  _proto.getValue = function getValue(time) {
10305
10308
  var result = 0;
10306
10309
  var keyTimeData = Object.keys(this.curveMap);
10307
- var keyTimeStart = Number(keyTimeData[0].split("&")[0]);
10308
- var keyTimeEnd = Number(keyTimeData[keyTimeData.length - 1].split("&")[1]);
10310
+ var keyTimeStart = this.curveMap[keyTimeData[0]].timeStart;
10311
+ var keyTimeEnd = this.curveMap[keyTimeData[keyTimeData.length - 1]].timeEnd;
10312
+ // const keyTimeStart = Number(keyTimeData[0].split('&')[0]);
10313
+ // const keyTimeEnd = Number(keyTimeData[keyTimeData.length - 1].split('&')[1]);
10309
10314
  if (time <= keyTimeStart) {
10310
10315
  return this.getCurveValue(keyTimeData[0], keyTimeStart);
10311
10316
  }
@@ -10313,7 +10318,9 @@ var BezierCurve = /*#__PURE__*/ function(ValueGetter) {
10313
10318
  return this.getCurveValue(keyTimeData[keyTimeData.length - 1], keyTimeEnd);
10314
10319
  }
10315
10320
  for(var i = 0; i < keyTimeData.length; i++){
10316
- var _keyTimeData_i_split = keyTimeData[i].split("&"), xMin = _keyTimeData_i_split[0], xMax = _keyTimeData_i_split[1];
10321
+ var xMin = this.curveMap[keyTimeData[i]].timeStart;
10322
+ var xMax = this.curveMap[keyTimeData[i]].timeEnd;
10323
+ // const [xMin, xMax] = keyTimeData[i].split('&');
10317
10324
  if (time >= Number(xMin) && time < Number(xMax)) {
10318
10325
  result = this.getCurveValue(keyTimeData[i], time);
10319
10326
  break;
@@ -10326,12 +10333,13 @@ var BezierCurve = /*#__PURE__*/ function(ValueGetter) {
10326
10333
  var time = (t1 - t0) / ts;
10327
10334
  var result = 0;
10328
10335
  var keyTimeData = Object.keys(this.curveMap);
10329
- var keyTimeStart = Number(keyTimeData[0].split("&")[0]);
10336
+ var keyTimeStart = this.curveMap[keyTimeData[0]].timeStart;
10330
10337
  if (time <= keyTimeStart) {
10331
10338
  return 0;
10332
10339
  }
10333
10340
  for(var i = 0; i < keyTimeData.length; i++){
10334
- var _keyTimeData_i_split = keyTimeData[i].split("&"), xMin = _keyTimeData_i_split[0], xMax = _keyTimeData_i_split[1];
10341
+ var xMin = this.curveMap[keyTimeData[i]].timeStart;
10342
+ var xMax = this.curveMap[keyTimeData[i]].timeEnd;
10335
10343
  if (time >= Number(xMax)) {
10336
10344
  result += ts * this.getCurveIntegrateValue(keyTimeData[i], Number(xMax));
10337
10345
  }
@@ -17665,6 +17673,12 @@ var particleUniformTypeMap = {
17665
17673
  var ParticleMesh = /*#__PURE__*/ function() {
17666
17674
  function ParticleMesh(engine, props) {
17667
17675
  this.particleCount = 0;
17676
+ this.cachedVelocity = new Vector3();
17677
+ this.cachedRotationVector3 = new Vector3();
17678
+ this.cachedRotationMatrix = new Matrix3();
17679
+ this.cachedLinearMove = new Vector3();
17680
+ this.tempMatrix3 = new Matrix3();
17681
+ this.tempVector3 = new Vector3();
17668
17682
  this.VERT_MAX_KEY_FRAME_COUNT = 0;
17669
17683
  var _engine_renderer;
17670
17684
  var env = ((_engine_renderer = engine.renderer) != null ? _engine_renderer : {}).env;
@@ -18068,39 +18082,40 @@ var ParticleMesh = /*#__PURE__*/ function() {
18068
18082
  // if (!uParams) {
18069
18083
  // return;
18070
18084
  // }
18071
- var localTime = new Float32Array([
18072
- this.time
18073
- ])[0];
18085
+ var localTime = this.time;
18074
18086
  var particleCount = Math.ceil(aPosArray.length / 12);
18075
18087
  // calculate particle translation
18076
18088
  var aTranslationArray = this.geometry.getAttributeData("aTranslation");
18077
18089
  if (aTranslationArray.length < particleCount * 3) {
18078
- aTranslationArray = new Float32Array(particleCount * 3);
18090
+ aTranslationArray = this.expandArray(aTranslationArray, particleCount * 3);
18079
18091
  }
18080
- var velocity = new Vector3(0, 0, 0);
18092
+ var velocity = this.cachedVelocity;
18081
18093
  for(var i = 0; i < particleCount; i++){
18082
18094
  var velOffset = i * 12 + 3;
18083
18095
  velocity.set(aVelArray[velOffset], aVelArray[velOffset + 1], aVelArray[velOffset + 2]);
18084
- var trans = this.calculateTranslation(velocity, aOffsetArray[i * 4 + 2], localTime, aOffsetArray[i * 4 + 3]);
18096
+ this.calculateTranslation(velocity, aOffsetArray[i * 4 + 2], localTime, aOffsetArray[i * 4 + 3]);
18085
18097
  var aTranslationOffset = i * 3;
18086
- aTranslationArray[aTranslationOffset] = trans.x;
18087
- aTranslationArray[aTranslationOffset + 1] = trans.y;
18088
- aTranslationArray[aTranslationOffset + 2] = trans.z;
18098
+ if (aOffsetArray[i * 4 + 2] < localTime) {
18099
+ var translation = velocity.multiply(dt / 1000);
18100
+ aTranslationArray[aTranslationOffset] += translation.x;
18101
+ aTranslationArray[aTranslationOffset + 1] += translation.y;
18102
+ aTranslationArray[aTranslationOffset + 2] += translation.z;
18103
+ }
18089
18104
  }
18090
18105
  this.geometry.setAttributeData("aTranslation", aTranslationArray);
18091
18106
  // calculate particle rotation
18092
18107
  var aRotationArray = this.geometry.getAttributeData("aRotation0");
18093
18108
  if (aRotationArray.length < particleCount * 9) {
18094
- aRotationArray = new Float32Array(particleCount * 9);
18109
+ aRotationArray = this.expandArray(aRotationArray, particleCount * 9);
18095
18110
  }
18096
18111
  for(var i1 = 0; i1 < particleCount; i1++){
18097
18112
  var time = localTime - aOffsetArray[i1 * 4 + 2];
18098
18113
  var duration = aOffsetArray[i1 * 4 + 3];
18099
18114
  var life = clamp$1(time / duration, 0.0, 1.0);
18100
18115
  var aRotOffset = i1 * 8;
18101
- var aRot = new Vector3(aRotArray[aRotOffset], aRotArray[aRotOffset + 1], aRotArray[aRotOffset + 2]);
18116
+ var aRot = this.cachedRotationVector3.set(aRotArray[aRotOffset], aRotArray[aRotOffset + 1], aRotArray[aRotOffset + 2]);
18102
18117
  var aSeed = aSeedArray[i1 * 8 + 3];
18103
- var aRotation = this.transformFromRotation(aRot, life, duration, aSeed);
18118
+ var aRotation = this.transformFromRotation(aRot, life, duration, aSeed, this.cachedRotationMatrix);
18104
18119
  var aRotationOffset = i1 * 9;
18105
18120
  var matrixArray = aRotation.toArray();
18106
18121
  aRotationArray.set(matrixArray, aRotationOffset);
@@ -18109,14 +18124,16 @@ var ParticleMesh = /*#__PURE__*/ function() {
18109
18124
  // calculate linear movement
18110
18125
  var aLinearMoveArray = this.geometry.getAttributeData("aLinearMove");
18111
18126
  if (aLinearMoveArray.length < particleCount * 3) {
18112
- aLinearMoveArray = new Float32Array(particleCount * 3);
18127
+ aLinearMoveArray = this.expandArray(aLinearMoveArray, particleCount * 3);
18113
18128
  }
18129
+ var linearMove = this.cachedLinearMove;
18114
18130
  for(var i2 = 0; i2 < particleCount; i2++){
18115
18131
  var time1 = localTime - aOffsetArray[i2 * 4 + 2];
18116
18132
  var duration1 = aOffsetArray[i2 * 4 + 3];
18117
18133
  // const life = math.clamp(time / duration, 0.0, 1.0);
18118
18134
  var aSeed1 = aSeedArray[i2 * 8 + 3];
18119
- var linearMove = this.calLinearMov(time1, duration1, aSeed1);
18135
+ linearMove.setZero();
18136
+ this.calLinearMov(time1, duration1, aSeed1, linearMove);
18120
18137
  var aLinearMoveOffset = i2 * 3;
18121
18138
  aLinearMoveArray[aLinearMoveOffset] = linearMove.x;
18122
18139
  aLinearMoveArray[aLinearMoveOffset + 1] = linearMove.y;
@@ -18136,29 +18153,23 @@ var ParticleMesh = /*#__PURE__*/ function() {
18136
18153
  var uAcceleration = this.mesh.material.getVector4("uAcceleration");
18137
18154
  var uGravityModifierValue = this.mesh.material.getVector4("uGravityModifierValue");
18138
18155
  if (!uAcceleration || !uGravityModifierValue) {
18139
- return new Vector3();
18156
+ return velocity;
18140
18157
  }
18141
18158
  var dt = t1 - t0; // 相对delay的时间
18142
- var d = this.gravityModifier.getIntegrateByTime(0, dt);
18143
- var acc = [
18144
- uAcceleration.x * d,
18145
- uAcceleration.y * d,
18146
- uAcceleration.z * d
18147
- ];
18148
- // ret.addScaledVector(velData, speedIntegrate);
18149
- // ret.addScaledVector(acc, d);
18159
+ var d = this.gravityModifier.getIntegrateValue(0, dt, duration);
18160
+ var acc = this.tempVector3.set(uAcceleration.x * d, uAcceleration.y * d, uAcceleration.z * d);
18150
18161
  // speedIntegrate = speedOverLifetime.getIntegrateValue(0, time, duration);
18151
18162
  if (this.speedOverLifetime) {
18152
18163
  // dt / dur 归一化
18153
- var speed = this.speedOverLifetime.getIntegrateValue(0, dt, duration);
18154
- return velocity.clone().multiply(speed).add(acc);
18164
+ var speed = this.speedOverLifetime.getValue(dt / duration);
18165
+ return velocity.multiply(speed).add(acc);
18155
18166
  }
18156
- return velocity.clone().multiply(dt).add(acc);
18167
+ return velocity.add(acc);
18157
18168
  };
18158
- _proto.transformFromRotation = function transformFromRotation(rot, life, dur, aSeed) {
18159
- var rotation = rot.clone();
18169
+ _proto.transformFromRotation = function transformFromRotation(rot, life, dur, aSeed, result) {
18170
+ var rotation = rot;
18160
18171
  if (!this.rotationOverLifetime) {
18161
- return new Matrix3();
18172
+ return result.setZero();
18162
18173
  }
18163
18174
  if (this.rotationOverLifetime.asRotation) {
18164
18175
  // Adjust rotation based on the specified lifetime components
@@ -18209,32 +18220,33 @@ var ParticleMesh = /*#__PURE__*/ function() {
18209
18220
  }
18210
18221
  // If the rotation vector is zero, return the identity matrix
18211
18222
  if (rotation.dot(rotation) === 0.0) {
18212
- return new Matrix3().identity();
18223
+ return result.identity();
18213
18224
  }
18214
18225
  // Return the rotation matrix derived from the rotation vector
18215
- return this.mat3FromRotation(rotation);
18226
+ return this.mat3FromRotation(rotation, result);
18216
18227
  };
18217
- _proto.mat3FromRotation = function mat3FromRotation(rotation) {
18228
+ _proto.mat3FromRotation = function mat3FromRotation(rotation, result) {
18218
18229
  var d2r = Math.PI / 180;
18219
- var sinR = rotation.clone().multiply(d2r);
18220
- sinR.x = Math.sin(sinR.x);
18221
- sinR.y = Math.sin(sinR.y);
18222
- sinR.z = Math.sin(sinR.z);
18223
- var cosR = rotation.clone().multiply(d2r);
18224
- cosR.x = Math.cos(cosR.x);
18225
- cosR.y = Math.cos(cosR.y);
18226
- cosR.z = Math.cos(cosR.z);
18227
- var rotZ = new Matrix3(cosR.z, -sinR.z, 0., sinR.z, cosR.z, 0., 0., 0., 1.);
18228
- var rotY = new Matrix3(cosR.y, 0., sinR.y, 0., 1., 0., -sinR.y, 0, cosR.y);
18229
- var rotX = new Matrix3(1., 0., 0., 0, cosR.x, -sinR.x, 0., sinR.x, cosR.x);
18230
- var result = rotZ.multiply(rotY).multiply(rotX);
18230
+ var rotationXD2r = rotation.x * d2r;
18231
+ var rotationYD2r = rotation.y * d2r;
18232
+ var rotationZD2r = rotation.z * d2r;
18233
+ var sinRX = Math.sin(rotationXD2r);
18234
+ var sinRY = Math.sin(rotationYD2r);
18235
+ var sinRZ = Math.sin(rotationZD2r);
18236
+ var cosRX = Math.cos(rotationXD2r);
18237
+ var cosRY = Math.cos(rotationYD2r);
18238
+ var cosRZ = Math.cos(rotationZD2r);
18239
+ // rotZ * rotY * rotX
18240
+ result.set(cosRZ, -sinRZ, 0., sinRZ, cosRZ, 0., 0., 0., 1.); //rotZ
18241
+ result.multiply(this.tempMatrix3.set(cosRY, 0., sinRY, 0., 1., 0., -sinRY, 0, cosRY)); //rotY
18242
+ result.multiply(this.tempMatrix3.set(1., 0., 0., 0, cosRX, -sinRX, 0., sinRX, cosRX)); //rotX
18231
18243
  return result;
18232
18244
  };
18233
- _proto.calLinearMov = function calLinearMov(time, duration, aSeed) {
18234
- var mov = new Vector3();
18245
+ _proto.calLinearMov = function calLinearMov(time, duration, aSeed, result) {
18246
+ var mov = result;
18235
18247
  var lifetime = time / duration;
18236
18248
  if (!this.linearVelOverLifetime || !this.linearVelOverLifetime.enabled) {
18237
- return new Vector3();
18249
+ return mov;
18238
18250
  }
18239
18251
  if (this.linearVelOverLifetime.asMovement) {
18240
18252
  if (this.linearVelOverLifetime.x) {
@@ -18307,7 +18319,8 @@ var ParticleMesh = /*#__PURE__*/ function() {
18307
18319
  var pointData = {
18308
18320
  aPos: new Float32Array(48),
18309
18321
  aRot: new Float32Array(32),
18310
- aOffset: new Float32Array(16)
18322
+ aOffset: new Float32Array(16),
18323
+ aTranslation: new Float32Array(12)
18311
18324
  };
18312
18325
  var useSprite = this.useSprite;
18313
18326
  if (useSprite) {
@@ -18416,6 +18429,11 @@ var ParticleMesh = /*#__PURE__*/ function() {
18416
18429
  geometry.setDrawCount(this.particleCount * 6);
18417
18430
  }
18418
18431
  };
18432
+ _proto.expandArray = function expandArray(array, newSize) {
18433
+ var newArr = new Float32Array(newSize);
18434
+ newArr.set(array);
18435
+ return newArr;
18436
+ };
18419
18437
  return ParticleMesh;
18420
18438
  }();
18421
18439
  var gl2UniformSlots = [
@@ -28066,7 +28084,7 @@ registerPlugin("sprite", SpriteLoader, VFXItem, true);
28066
28084
  registerPlugin("particle", ParticleLoader, VFXItem, true);
28067
28085
  registerPlugin("cal", CalculateLoader, VFXItem, true);
28068
28086
  registerPlugin("interact", InteractLoader, VFXItem, true);
28069
- var version = "2.1.0-alpha.1";
28087
+ var version = "2.1.0-alpha.2";
28070
28088
  logger.info("Core version: " + version + ".");
28071
28089
 
28072
28090
  export { AbstractPlugin, ActivationPlayable, ActivationPlayableAsset, ActivationTrack, AnimationClip, AnimationClipPlayable, AssetLoader, AssetManager, BYTES_TYPE_MAP, Behaviour, BezierCurve, BezierCurvePath, BezierCurveQuat, BinaryAsset, COMPRESSED_TEXTURE, COPY_FRAGMENT_SHADER, COPY_MESH_SHADER_ID, COPY_VERTEX_SHADER, CalculateLoader, Camera, CameraController, CameraVFXItemLoader, 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, FilterMode, Float16ArrayWrapper, Framebuffer, GLSLVersion, GPUCapability, Geometry, GlobalUniforms, GradientValue, HELP_LINK, HitTestType, InteractComponent, InteractLoader, InteractMesh, Item, KTXTexture, LineSegments, LinearValue, Material, MaterialDataBlock, MaterialRenderType, Mesh, ObjectBindingTrack, OrderType, PLAYER_OPTIONS_ENV_EDITOR, POST_PROCESS_SETTINGS, ParticleBehaviourPlayable, ParticleBehaviourPlayableAsset, ParticleLoader, ParticleMesh, ParticleSystem, ParticleSystemRenderer, PassTextureCache, PathSegments, PluginSystem, PostProcessVolume, 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, SemanticMap, SerializationHelper, Shader, ShaderCompileResultStatus, ShaderFactory, ShaderType, ShaderVariant, SpriteColorPlayable, SpriteColorPlayableAsset, SpriteColorTrack, SpriteComponent, SpriteLoader, StaticValue, SubCompositionPlayableAsset, SubCompositionTrack, TEMPLATE_USE_OFFSCREEN_CANVAS, TextComponent, TextComponentBase, TextLayout, TextLoader, TextStyle, Texture, TextureFactory, TextureLoadAction, TextureSourceType, TextureStoreAction, Ticker, TimelineAsset, TimelineClip, TimelinePlayable, TrackAsset, TrackSortWrapper, TrackType, Transform, TransformAnimationPlayable, TransformPlayableAsset, TransformTrack, VFXItem, ValueGetter, addByOrder, addItem, addItemWithOrder, applyMixins, assertExist, asserts, base64ToFile, blend, calculateTranslation, canvasPool, colorGradingFrag, colorStopsFromGradient, colorToArr$1 as colorToArr, combineImageTemplate, createCopyShader, createGLContext, createKeyFrameMeta, createShape, createValueGetter, decimalEqual, defaultGlobalVolume, 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, isSceneJSON, isSceneURL, isSceneWithOptions, 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, pluginLoaderMap, randomInRange, registerPlugin, removeItem, rotateVec2, screenMeshVert, serialize, setBlendMode, setConfig, setDefaultTextureFactory, setMaskMode, setMaxSpriteMeshItemCount, setRayFromCamera, setSideMode, setSpriteMeshMaxItemCountByGPU, sortByOrder, index$1 as spec, spriteMeshShaderFromFilter, spriteMeshShaderFromRenderInfo, spriteMeshShaderIdFromRenderInfo, thresholdFrag, throwDestroyedError, trailVert, translatePoint, trianglesFromRect, unregisterPlugin, valIfUndefined, value, valueDefine, vecFill, vecMulCombine, version, vertexFormatType2GLType };