From 40da83b2414f73704aaed2f890639c30be3d7c98 Mon Sep 17 00:00:00 2001 From: santy-wang Date: Thu, 21 Sep 2023 19:46:41 +0800 Subject: [PATCH] add more module --- cocos/core/curves/gradient.ts | 217 ++++++++----- cocos/particle-2d/particle-system-2d.ts | 84 +++--- cocos/particle/Impl.ts | 42 +-- cocos/particle/curve-range.ts | 28 +- cocos/particle/define.ts | 36 +++ cocos/particle/gradient-range.ts | 285 ++++++++++++------ cocos/particle/modules/box-shape.ts | 46 ++- cocos/particle/modules/color-by-speed.ts | 64 +++- cocos/particle/modules/color-over-lifetime.ts | 5 + cocos/particle/modules/shape.ts | 93 ++++-- cocos/particle/particle-system-module.ts | 41 ++- editor/i18n/en/localization.js | 12 +- editor/i18n/zh/localization.js | 12 +- native/cocos/particle/Define.h | 4 +- native/cocos/particle/GradientRange.cpp | 28 +- native/cocos/particle/GradientRange.h | 65 +++- native/cocos/particle/ParticleSystem.cpp | 16 +- native/cocos/particle/ParticleSystem.h | 18 +- native/cocos/particle/ParticleSystemModule.h | 16 +- native/cocos/particle/modules/BoxShape.cpp | 6 +- native/cocos/particle/modules/BoxShape.h | 6 +- .../cocos/particle/modules/ColorBySpeed.cpp | 6 +- native/cocos/particle/modules/ColorBySpeed.h | 6 +- .../particle/modules/ColorOverLifetime.cpp | 6 +- .../particle/modules/ColorOverLifetime.h | 6 +- .../particle/modules/CurlNoiseOverLifetime.h | 4 +- native/cocos/particle/modules/CustomData.cpp | 8 +- native/cocos/particle/modules/CustomData.h | 8 +- .../particle/modules/DragOverLifetime.cpp | 8 +- .../cocos/particle/modules/DragOverLifetime.h | 8 +- .../particle/modules/EmissionByBurst.cpp | 4 +- .../cocos/particle/modules/EmissionByBurst.h | 4 +- .../cocos/particle/modules/EmissionByEvent.h | 2 +- .../particle/modules/EmissionOverDistance.cpp | 4 +- .../particle/modules/EmissionOverDistance.h | 4 +- .../particle/modules/EmissionOverTime.cpp | 4 +- .../cocos/particle/modules/EmissionOverTime.h | 4 +- native/cocos/particle/modules/EventByDeath.h | 2 +- .../particle/modules/ForceOverLifetime.cpp | 6 +- .../particle/modules/ForceOverLifetime.h | 6 +- .../particle/modules/GravityOverLifetime.cpp | 6 +- .../particle/modules/GravityOverLifetime.h | 6 +- .../particle/modules/InheritStartSpeed.cpp | 4 +- .../particle/modules/InheritStartSpeed.h | 4 +- .../modules/InheritVelocityOverLifetime.cpp | 8 +- .../modules/InheritVelocityOverLifetime.h | 4 +- .../modules/LimitVelocityOverLifetime.cpp | 2 +- .../modules/LimitVelocityOverLifetime.h | 6 +- .../modules/LinearVelocityOverLifetime.cpp | 6 +- .../modules/LinearVelocityOverLifetime.h | 6 +- .../modules/OrbitalVelocityOverLifetime.cpp | 8 +- .../modules/OrbitalVelocityOverLifetime.h | 8 +- .../particle/modules/RotationBySpeed.cpp | 6 +- .../cocos/particle/modules/RotationBySpeed.h | 6 +- .../particle/modules/RotationOverLifetime.cpp | 6 +- .../particle/modules/RotationOverLifetime.h | 6 +- native/cocos/particle/modules/Shape.cpp | 4 +- native/cocos/particle/modules/Shape.h | 60 +++- native/cocos/particle/modules/SizeBySpeed.cpp | 8 +- native/cocos/particle/modules/SizeBySpeed.h | 8 +- .../particle/modules/SizeOverLifetime.cpp | 8 +- .../cocos/particle/modules/SizeOverLifetime.h | 8 +- .../modules/SpeedMultiplierOverLifetime.cpp | 4 +- .../modules/SpeedMultiplierOverLifetime.h | 4 +- native/cocos/particle/modules/StartColor.cpp | 6 +- native/cocos/particle/modules/StartColor.h | 6 +- .../cocos/particle/modules/StartLifetime.cpp | 4 +- native/cocos/particle/modules/StartLifetime.h | 4 +- .../modules/StartLifetimeByEmitterSpeed.cpp | 4 +- .../modules/StartLifetimeByEmitterSpeed.h | 4 +- .../cocos/particle/modules/StartRotation.cpp | 6 +- native/cocos/particle/modules/StartRotation.h | 6 +- native/cocos/particle/modules/StartSize.cpp | 8 +- native/cocos/particle/modules/StartSize.h | 8 +- native/cocos/particle/modules/StartSpeed.cpp | 4 +- native/cocos/particle/modules/StartSpeed.h | 4 +- native/cocos/particle/modules/Trail.h | 2 +- 77 files changed, 1020 insertions(+), 466 deletions(-) diff --git a/cocos/core/curves/gradient.ts b/cocos/core/curves/gradient.ts index 851423317bf..41b21664b31 100644 --- a/cocos/core/curves/gradient.ts +++ b/cocos/core/curves/gradient.ts @@ -23,13 +23,15 @@ */ import { CCClass } from '../data'; -import { Enum } from '../value-types'; -import { Color, lerp, repeat, EPSILON, approx, random, clamp01 } from '../math'; +import { Color, lerp, repeat, EPSILON, approx, random, clamp01, clamp } from '../math'; +import { Enum } from '..'; -const Mode = Enum({ - Blend: 0, - Fixed: 1, -}); +const tempColor = new Color(); + +enum Mode { + BLEND, + FIXED +} export class ColorKey { /** @@ -43,6 +45,15 @@ export class ColorKey { * @zh 时间值。 */ public time = 0; + + constructor (color?: Color, time?: number) { + if (color) { + this.color.set(color); + } + if (time !== undefined) { + this.time = time; + } + } } CCClass.fastDefine('cc.ColorKey', ColorKey, { @@ -64,6 +75,15 @@ export class AlphaKey { * @zh 时间帧。 */ public time = 0; + + constructor (alpha?: number, time?: number) { + if (alpha !== undefined) { + this.alpha = alpha; + } + if (time !== undefined) { + this.time = time; + } + } } CCClass.fastDefine('cc.AlphaKey', AlphaKey, { @@ -74,6 +94,10 @@ CCClass.fastDefine('cc.AlphaKey', AlphaKey, { CCClass.Attr.setClassAttr(AlphaKey, 'alpha', 'visible', true); CCClass.Attr.setClassAttr(AlphaKey, 'time', 'visible', true); +export declare namespace Gradient { + export type Mode = EnumAlias; +} + /** * @en Gradient is a component that has a lot of color keys and alpha keys to get the interpolated color value. * @zh 渐变曲线控件包含了颜色关键帧和透明度关键帧,在关键帧中进行插值渐变返回最终的颜色值。 @@ -89,22 +113,85 @@ export class Gradient { * 混合模式对取到的最近两个颜色帧进行插值计算。 * 固定模式直接取最近的颜色帧返回,不进行插值。 */ - public static Mode = Mode; + public static Mode = Enum(Mode); + /** * @en Array of color key. * @zh 颜色关键帧列表。 */ - public colorKeys: ColorKey[] = []; + public get colorKeys (): ColorKey[] { + const keys: ColorKey[] = []; + for (let i = 0; i < this._colors.length; i++) { + keys.push(new ColorKey(Color.fromUint32(new Color(), this._colors[i]), this._colorTimes[i])); + } + return keys; + } + + public set colorKeys (val) { + if (val.length === 1 || val.length === 0) { + this._colors.length = 2; + this._colorTimes.length = 2; + this._colors[0] = this._colors[1] = val.length === 1 ? Color.toUint32(val[0].color) : 0xFFFFFFFF; + this._colorTimes[0] = 0; + this._colorTimes[1] = 1; + } else { + val.sort((a, b): number => a.time - b.time); + this._colors.length = val.length; + this._colorTimes.length = val.length; + for (let i = 0; i < val.length; i++) { + this._colors[i] = Color.toUint32(val[i].color); + this._colorTimes[i] = val[i].time; + } + } + } + /** * @en Array of alpha key. * @zh 透明度关键帧列表。 */ - public alphaKeys: AlphaKey[] = []; + public get alphaKeys (): AlphaKey[] { + const keys: AlphaKey[] = []; + for (let i = 0; i < this._alphas.length; i++) { + keys.push(new AlphaKey(this._alphas[i], this._alphaTimes[i])); + } + return keys; + } + + public set alphaKeys (val) { + if (val.length === 1 || val.length === 0) { + this._alphas.length = 2; + this._alphas.length = 2; + this._alphas[0] = this._alphas[1] = val.length === 1 ? val[0].alpha : 0xFF; + this._alphaTimes[0] = 0; + this._alphaTimes[1] = 1; + } else { + val.sort((a, b): number => a.time - b.time); + this._alphas.length = val.length; + this._alphaTimes.length = val.length; + for (let i = 0; i < val.length; i++) { + this._alphas[i] = val[i].alpha; + this._alphaTimes[i] = val[i].time; + } + } + } + + public get mode (): Mode { + return this._mode; + } + + public set mode (val) { + this._mode = val; + } + /** * @en Blend mode. * @zh 混合模式。 */ - public mode = Mode.Blend; + private _mode = Mode.BLEND; + private _colors: number[] = [0xFFFFFFFF, 0xFFFFFFFF]; + private _colorTimes: number[] = [0, 1]; + private _alphas: number[] = [255, 255]; + private _alphaTimes: number[] = [0, 1]; /** * @en Set color keys array and alpha keys array. @@ -120,14 +207,10 @@ export class Gradient { /** * @en Sort color keys and alpha keys. * @zh 对颜色和透明度的关键帧进行排序。 + * @deprecated Since v3.8, Sorting will be automatic when setting keyframes, no longer need to call this method manually. */ public sortKeys (): void { - if (this.colorKeys.length > 1) { - this.colorKeys.sort((a, b): number => a.time - b.time); - } - if (this.alphaKeys.length > 1) { - this.alphaKeys.sort((a, b): number => a.time - b.time); - } + // useless } /** @@ -165,6 +248,12 @@ export class Gradient { return this.getRandomColor(new Color()); } + public set (gradient: Readonly): void { + this.colorKeys = gradient.colorKeys; + this.alphaKeys = gradient.alphaKeys; + this.mode = gradient.mode; + } + /** * @en Generates a random color and alpha. * @zh 随机生成颜色和透明度。 @@ -172,86 +261,74 @@ export class Gradient { * @returns @en Randomized color. @zh 随机生成的颜色。 */ public getRandomColor (out: Color): Color { - const c = this.colorKeys[Math.trunc(random() * this.colorKeys.length)]; - const a = this.alphaKeys[Math.trunc(random() * this.alphaKeys.length)]; - out.set(c.color); - out._set_a_unsafe(a.alpha); + const c = this._colors[Math.trunc(random() * this._colors.length)]; + const a = this._alphas[Math.trunc(random() * this._alphas.length)]; + Color.fromUint32(out, c); + out._set_a_unsafe(a); return out; } private getRGB (out: Color, time: number): Color { - const colorKeys = this.colorKeys; - const length = colorKeys.length; + const colors = this._colors; + const colorTimes = this._colorTimes; + const length = colors.length; + Color.copy(out, Color.WHITE); if (length > 1) { - time = clamp01(time); + const lastIndex = length - 1; + clamp(time, colorTimes[0], colorTimes[lastIndex]); + Color.fromUint32(out, colors[lastIndex]); for (let i = 1; i < length; ++i) { - const preTime = colorKeys[i - 1].time; - const curTime = colorKeys[i].time; + const preTime = colorTimes[i - 1]; + const curTime = colorTimes[i]; if (time >= preTime && time < curTime) { - if (this.mode === Mode.Fixed) { - Color.copy(out, colorKeys[i].color); - return out; + if (this.mode === Mode.FIXED) { + Color.fromUint32(out, colors[i]); + } else { + const factor = (time - preTime) / (curTime - preTime); + Color.fromUint32(out, colors[i]); + Color.fromUint32(tempColor, colors[i - 1]); + Color.lerp(out, tempColor, out, factor); } - const factor = (time - preTime) / (curTime - preTime); - Color.lerp(out, colorKeys[i - 1].color, colorKeys[i].color, factor); - return out; + break; } } - const lastIndex = length - 1; - if (approx(time, colorKeys[lastIndex].time, EPSILON)) { - Color.copy(out, colorKeys[lastIndex].color); - } else if (time < colorKeys[0].time) { - Color.lerp(out, Color.BLACK, colorKeys[0].color, time / colorKeys[0].time); - } else if (time > colorKeys[lastIndex].time) { - Color.lerp(out, colorKeys[lastIndex].color, Color.BLACK, (time - colorKeys[lastIndex].time) / (1 - colorKeys[lastIndex].time)); - } - // console.warn('something went wrong. can not get gradient color.'); - } else if (length === 1) { - Color.copy(out, colorKeys[0].color); - } else { - Color.copy(out, Color.WHITE); } return out; } private getAlpha (time: number): number { - const basicAlpha = 0; // default alpha is 0 - const alphaKeys = this.alphaKeys; - const length = alphaKeys.length; + let alpha = 255; + const alphas = this._alphas; + const alphaTimes = this._alphaTimes; + const length = alphas.length; if (length > 1) { - time = repeat(time, 1.0 + EPSILON); + const lastIndex = length - 1; + clamp(time, alphaTimes[0], alphaTimes[lastIndex]); + alpha = alphas[lastIndex]; for (let i = 1; i < length; ++i) { - const preTime = alphaKeys[i - 1].time; - const curTime = alphaKeys[i].time; + const preTime = alphaTimes[i - 1]; + const curTime = alphaTimes[i]; if (time >= preTime && time < curTime) { - if (this.mode === Mode.Fixed) { - return alphaKeys[i].alpha; + if (this.mode === Mode.FIXED) { + alpha = alphas[i]; + } else { + const factor = (time - preTime) / (curTime - preTime); + alpha = lerp(alphas[i - 1], alphas[i], factor); } - const factor = (time - preTime) / (curTime - preTime); - return lerp(alphaKeys[i - 1].alpha, alphaKeys[i].alpha, factor); + break; } } - const lastIndex = length - 1; - if (approx(time, alphaKeys[lastIndex].time, EPSILON)) { - return alphaKeys[lastIndex].alpha; - } else if (time < alphaKeys[0].time) { - return lerp(basicAlpha, alphaKeys[0].alpha, time / alphaKeys[0].time); - } else if (time > alphaKeys[lastIndex].time) { - return lerp(alphaKeys[lastIndex].alpha, basicAlpha, (time - alphaKeys[lastIndex].time) / (1 - alphaKeys[lastIndex].time)); - } - return 255; - } else if (length === 1) { - return alphaKeys[0].alpha; - } else { - return 255; } + return alpha; } } CCClass.fastDefine('cc.Gradient', Gradient, { - colorKeys: [], - alphaKeys: [], - mode: Mode.Blend, + _colors: [], + _colorTimes: [], + _alphas: [], + _alphaTimes: [], + _mode: Mode.BLEND, }); CCClass.Attr.setClassAttr(Gradient, 'colorKeys', 'visible', true); diff --git a/cocos/particle-2d/particle-system-2d.ts b/cocos/particle-2d/particle-system-2d.ts index 2b40985c812..7567f0c9aed 100644 --- a/cocos/particle-2d/particle-system-2d.ts +++ b/cocos/particle-2d/particle-system-2d.ts @@ -183,7 +183,7 @@ export class ParticleSystem2D extends UIRenderer { */ @editable @displayOrder(6) - @tooltip('i18n:particle_system.custom') + @tooltip('i18n:ParticleSystem2D.custom') public get custom (): boolean { return this._custom; } @@ -205,7 +205,7 @@ export class ParticleSystem2D extends UIRenderer { */ @type(ParticleAsset) @displayOrder(5) - @tooltip('i18n:particle_system.file') + @tooltip('i18n:ParticleSystem2D.file') public get file (): ParticleAsset | null { return this._file; } @@ -226,7 +226,7 @@ export class ParticleSystem2D extends UIRenderer { * @zh 用于粒子呈现的 SpriteFrame */ @type(SpriteFrame) - @tooltip('i18n:particle_system.spriteFrame') + @tooltip('i18n:ParticleSystem2D.spriteFrame') public get spriteFrame (): SpriteFrame | null { return this._spriteFrame; } @@ -263,7 +263,7 @@ export class ParticleSystem2D extends UIRenderer { * @zh 粒子最大数量。 */ @editable - @tooltip('i18n:particle_system.totalParticles') + @tooltip('i18n:ParticleSystem2D.totalParticles') public get totalParticles (): number { return this._totalParticles; } @@ -278,7 +278,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.duration') + @tooltip('i18n:ParticleSystem2D.duration') public duration = -1; /** @@ -287,7 +287,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.emissionRate') + @tooltip('i18n:ParticleSystem2D.emissionRate') public emissionRate = 10; /** @@ -296,7 +296,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.life') + @tooltip('i18n:ParticleSystem2D.life') public life = 1; /** @@ -305,7 +305,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.lifeVar') + @tooltip('i18n:ParticleSystem2D.lifeVar') public lifeVar = 0; /** @@ -313,7 +313,7 @@ export class ParticleSystem2D extends UIRenderer { * @zh 粒子初始颜色。 */ @editable - @tooltip('i18n:particle_system.startColor') + @tooltip('i18n:ParticleSystem2D.startColor') public get startColor (): Color { return this._startColor; } @@ -330,7 +330,7 @@ export class ParticleSystem2D extends UIRenderer { * @zh 粒子初始颜色变化范围。 */ @editable - @tooltip('i18n:particle_system.startColorVar') + @tooltip('i18n:ParticleSystem2D.startColorVar') public get startColorVar (): Color { return this._startColorVar; } @@ -356,7 +356,7 @@ export class ParticleSystem2D extends UIRenderer { * @zh 粒子结束颜色。 */ @editable - @tooltip('i18n:particle_system.endColor') + @tooltip('i18n:ParticleSystem2D.endColor') public get endColor (): Color { return this._endColor; } @@ -373,7 +373,7 @@ export class ParticleSystem2D extends UIRenderer { * @zh 粒子结束颜色变化范围。 */ @editable - @tooltip('i18n:particle_system.endColorVar') + @tooltip('i18n:ParticleSystem2D.endColorVar') public get endColorVar (): Color { return this._endColorVar; } @@ -391,7 +391,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.angle') + @tooltip('i18n:ParticleSystem2D.angle') public angle = 90; /** @@ -400,7 +400,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.angleVar') + @tooltip('i18n:ParticleSystem2D.angleVar') public angleVar = 20; /** @@ -409,7 +409,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.startSize') + @tooltip('i18n:ParticleSystem2D.startSize') public startSize = 50; /** @@ -418,7 +418,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.startSizeVar') + @tooltip('i18n:ParticleSystem2D.startSizeVar') public startSizeVar = 0; /** @@ -427,7 +427,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.endSize') + @tooltip('i18n:ParticleSystem2D.endSize') public endSize = 0; /** @@ -436,7 +436,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.endSizeVar') + @tooltip('i18n:ParticleSystem2D.endSizeVar') public endSizeVar = 0; /** @@ -445,7 +445,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.startSpin') + @tooltip('i18n:ParticleSystem2D.startSpin') public startSpin = 0; /** @@ -454,7 +454,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.startSpinVar') + @tooltip('i18n:ParticleSystem2D.startSpinVar') public startSpinVar = 0; /** @@ -463,7 +463,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.endSpin') + @tooltip('i18n:ParticleSystem2D.endSpin') public endSpin = 0; /** @@ -472,7 +472,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.endSpinVar') + @tooltip('i18n:ParticleSystem2D.endSpinVar') public endSpinVar = 0; /** @@ -488,7 +488,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.posVar') + @tooltip('i18n:ParticleSystem2D.posVar') public posVar = Vec2.ZERO.clone(); /** @@ -496,7 +496,7 @@ export class ParticleSystem2D extends UIRenderer { * @zh 粒子位置类型。 */ @type(PositionType) - @tooltip('i18n:particle_system.positionType') + @tooltip('i18n:ParticleSystem2D.positionType') public get positionType (): number { return this._positionType; } @@ -513,7 +513,7 @@ export class ParticleSystem2D extends UIRenderer { */ @editable @displayOrder(2) - @tooltip('i18n:particle_system.preview') + @tooltip('i18n:ParticleSystem2D.preview') public get preview (): boolean { return this._preview; } @@ -530,7 +530,7 @@ export class ParticleSystem2D extends UIRenderer { @serializable @editable @type(EmitterMode) - @tooltip('i18n:particle_system.emitterMode') + @tooltip('i18n:ParticleSystem2D.emitterMode') public emitterMode = EmitterMode.GRAVITY; // GRAVITY MODE @@ -541,7 +541,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.gravity') + @tooltip('i18n:ParticleSystem2D.gravity') public gravity = Vec2.ZERO.clone(); /** @@ -550,7 +550,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.speed') + @tooltip('i18n:ParticleSystem2D.speed') public speed = 180; /** @@ -559,7 +559,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.speedVar') + @tooltip('i18n:ParticleSystem2D.speedVar') public speedVar = 50; /** @@ -568,7 +568,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.tangentialAccel') + @tooltip('i18n:ParticleSystem2D.tangentialAccel') public tangentialAccel = 80; /** @@ -577,7 +577,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.tangentialAccelVar') + @tooltip('i18n:ParticleSystem2D.tangentialAccelVar') public tangentialAccelVar = 0; /** @@ -586,7 +586,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.radialAccel') + @tooltip('i18n:ParticleSystem2D.radialAccel') public radialAccel = 0; /** @@ -595,7 +595,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.radialAccelVar') + @tooltip('i18n:ParticleSystem2D.radialAccelVar') public radialAccelVar = 0; /** @@ -604,7 +604,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.rotationIsDir') + @tooltip('i18n:ParticleSystem2D.rotationIsDir') public rotationIsDir = false; // RADIUS MODE @@ -615,7 +615,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.startRadius') + @tooltip('i18n:ParticleSystem2D.startRadius') public startRadius = 0; /** @@ -624,7 +624,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.startRadiusVar') + @tooltip('i18n:ParticleSystem2D.startRadiusVar') public startRadiusVar = 0; /** @@ -633,7 +633,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.endRadius') + @tooltip('i18n:ParticleSystem2D.endRadius') public endRadius = 0; /** @@ -642,7 +642,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.endRadiusVar') + @tooltip('i18n:ParticleSystem2D.endRadiusVar') public endRadiusVar = 0; /** @@ -651,7 +651,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.rotatePerS') + @tooltip('i18n:ParticleSystem2D.rotatePerS') public rotatePerS = 0; /** @@ -660,7 +660,7 @@ export class ParticleSystem2D extends UIRenderer { */ @serializable @editable - @tooltip('i18n:particle_system.rotatePerSVar') + @tooltip('i18n:ParticleSystem2D.rotatePerSVar') public rotatePerSVar = 0; /** @@ -701,7 +701,7 @@ export class ParticleSystem2D extends UIRenderer { @serializable @editable @displayOrder(3) - @tooltip('i18n:particle_system.playOnLoad') + @tooltip('i18n:ParticleSystem2D.playOnLoad') public playOnLoad = true; /** @@ -711,7 +711,7 @@ export class ParticleSystem2D extends UIRenderer { @serializable @editable @displayOrder(4) - @tooltip('i18n:particle_system.autoRemoveOnFinish') + @tooltip('i18n:ParticleSystem2D.autoRemoveOnFinish') public autoRemoveOnFinish = false; /** diff --git a/cocos/particle/Impl.ts b/cocos/particle/Impl.ts index 8c84b3b5949..fa25bf11a13 100644 --- a/cocos/particle/Impl.ts +++ b/cocos/particle/Impl.ts @@ -1,3 +1,4 @@ +import { CustomDataMode, EmitFrom } from './define'; export declare namespace Impl { export class ParticleSystem { @@ -8,28 +9,41 @@ export declare namespace Impl { } - export class GradientRange { + export class OptimizedGradient { + setMode(mode: number); + setMinTime(minTime: number); + setLength(length: number); + setLUTSize(size: number); + getLUTData(): Uint32Array; + } + export class GradientRange { + setMode(mode: number): void; + setColor(color: number): void + setMinColor(color: number): void + getGradient(): OptimizedGradient; + getMinGradient(): OptimizedGradient; } export class ParticleSystemModule { - setEnable(enable: boolean): void; + setEnabled(enable: boolean): void; + dispose(): void; } export class Shape extends ParticleSystemModule { - - } - - export enum EmitFrom { - VOLUME, - SHELL, - EDGE, + setPosition(x: number, y: number, z: number): void; + setRotation(x: number, y: number, z: number): void; + setScale(x: number, y: number, z: number): void; + setRandomizeDirection(randomizeDirection: number): void; + setSpherizeDirection(spherizeDirection: number): void; + setRandomizePosition(randomizePosition: number): void; + setAlignToDirection(alignToDirection: boolean): void; } export class BoxShape extends Shape { setBoxThickness(x: number, y: number, z: number): void; setEmitFrom(emitFrom: EmitFrom): void; - } + } export class ColorBySpeed extends ParticleSystemModule { getColor(): GradientRange; @@ -40,12 +54,6 @@ export declare namespace Impl { getColor(): GradientRange; } - export enum CustomDataMode { - DISABLE, - VECTOR, - COLOR, - } - export class CustomData extends ParticleSystemModule { getComponent(stream: number, component: number): CurveRange; getColor(stream: number): GradientRange; @@ -62,4 +70,4 @@ export declare namespace Impl { export class Impl { -} \ No newline at end of file +} diff --git a/cocos/particle/curve-range.ts b/cocos/particle/curve-range.ts index 09169ae1a4e..ccf09023e05 100644 --- a/cocos/particle/curve-range.ts +++ b/cocos/particle/curve-range.ts @@ -24,8 +24,8 @@ import { ccclass } from 'cc.decorator'; import { EDITOR } from 'internal:constants'; -import { lerp, RealCurve, CCClass, geometry, Enum, approx, EPSILON } from '../../core'; -import { setPropertyEnumType } from '../../core/internal-index'; +import { lerp, RealCurve, CCClass, geometry, Enum, approx, EPSILON } from '../core'; +import { setPropertyEnumType } from '../core/internal-index'; const setClassAttr = CCClass.Attr.setClassAttr; @@ -34,7 +34,7 @@ const SerializableTable = [ ['mode', 'spline', 'constant'], ['mode', 'splineMin', 'spline', 'constant'], ['mode', 'constantMin', 'constant'], -] as const; +]; /** * @en @@ -120,13 +120,29 @@ export class CurveRange { * @en The spline used when mode is Mode.Curve. * @zh 当 mode 为Curve时,使用的曲线。 */ - public declare spline: RealCurve; + public get spline (): Readonly { + return this.spline; + } + + public set spline (val: Readonly) { + this.spline.copy(val); + } /** * @en The min spline when mode is Mode.TwoCurves. * @zh 当 mode 为TwoCurves时,使用的曲线下限。 */ - public declare splineMin: RealCurve; + public get splineMin (): Readonly { + return this.spline; + } + + public set splineMin (val: Readonly) { + this.spline.copy(val); + } + + public _spline: RealCurve | null = null; + + public _splineMin: RealCurve | null = null; /** * @en Constant value when use constant mode. @@ -200,6 +216,8 @@ export class CurveRange { return lerp(this.splineMin.evaluate(time), this.splineMax.evaluate(time), rndRatio) * this.constant; case Mode.TwoConstants: return lerp(this.constantMin, this.constant, rndRatio); + default: + return this.constant; } } diff --git a/cocos/particle/define.ts b/cocos/particle/define.ts index 7a85a1f5dbb..7b63bfb5fc4 100644 --- a/cocos/particle/define.ts +++ b/cocos/particle/define.ts @@ -30,6 +30,42 @@ export enum CoordinateSpace { WORLD, } +export enum BoxShapeEmitFrom { + VOLUME, + SHELL, + EDGE, +} + +export enum CustomDataMode { + DISABLE, + VECTOR, + COLOR, +} + +/** + * @en + * Gradinet is a component to calculate color value. It contains 5 modes: + * Color is just the color value all the time. + * Two Colors has 2 color values to interpolate the color value. + * Gradient value is generated by many color keys interpolation. + * Two Gradients has 2 gradients. The value is calculated by interpolation of the 2 gradients value. + * Random Color has one gradient. The value is get from color keys of the gradient randomly. + * @zh + * 渐变曲线是用来计算颜色值的控件,它包含五种模式: + * 单色从头到尾只返回一种颜色值。 + * 双色包含两个颜色值,返回两种颜色之间的插值。 + * 渐变曲线包含许多颜色帧,返回颜色帧之间的插值。 + * 双渐变曲线包含两个渐变曲线,对两个渐变曲线返回的颜色值再进行插值。 + * 随机颜色包含一个颜色曲线,从曲线中随机获取颜色值。 + */ +export enum GradientRangeMode { + COLOR, + GRADIENT, + RANDOM_BETWEEN_TWO_COLOR, + RANDOM_BETWEEN_TWO_GRADIENT, + RANDOM_COLOR, +} + /** * @en Particle emitter culling mode * @zh 粒子的剔除模式。 diff --git a/cocos/particle/gradient-range.ts b/cocos/particle/gradient-range.ts index 8a9e79c3cb8..bc84c972bac 100644 --- a/cocos/particle/gradient-range.ts +++ b/cocos/particle/gradient-range.ts @@ -23,44 +23,76 @@ */ import { ccclass, type, serializable, editable } from 'cc.decorator'; -import { EDITOR, EDITOR_NOT_IN_PREVIEW } from 'internal:constants'; -import { Color, Enum, Gradient, AlphaKey, ColorKey } from '../core'; - -const SerializableTable = EDITOR && [ - ['_mode', 'color'], - ['_mode', 'gradient'], - ['_mode', 'colorMin', 'color'], - ['_mode', 'gradientMin', 'gradient'], - ['_mode', 'gradient'], -]; +import { CCClass, Color, Enum, EPSILON, Gradient } from '../core'; +import { Impl } from './Impl'; -/** - * @en - * Gradinet is a component to calculate color value. It contains 5 modes: - * Color is just the color value all the time. - * Two Colors has 2 color values to interpolate the color value. - * Gradient value is generated by many color keys interpolation. - * Two Gradients has 2 gradients. The value is calculated by interpolation of the 2 gradients value. - * Random Color has one gradient. The value is get from color keys of the gradient randomly. - * @zh - * 渐变曲线是用来计算颜色值的控件,它包含五种模式: - * 单色从头到尾只返回一种颜色值。 - * 双色包含两个颜色值,返回两种颜色之间的插值。 - * 渐变曲线包含许多颜色帧,返回颜色帧之间的插值。 - * 双渐变曲线包含两个渐变曲线,对两个渐变曲线返回的颜色值再进行插值。 - * 随机颜色包含一个颜色曲线,从曲线中随机获取颜色值。 - */ -const Mode = Enum({ - Color: 0, - Gradient: 1, - TwoColors: 2, - TwoGradients: 3, - RandomColor: 4, -}); +const SerializableTable = [ + ['_mode', '_color'], + ['_mode', '_gradient', '_bakedGradient'], + ['_mode', '_colorMin', '_color'], + ['_mode', '_gradientMin', '_bakedGradient', '_gradient', '_bakedGradientMin'], + ['_mode', '_gradient', '_bakedGradient'], +]; const tempColor = new Color(); const tempColor2 = new Color(); +export class OptimizedGradient { + public static LUT_INTERVAL = 0.01; + + public get minTime (): number { + return this._minTime; + } + + public get length (): number { + return this._length; + } + + public get lookUpTable (): ReadonlyArray { + return this._lookUpTable; + } + + private _minTime = 0; + private _length = 1; + private _lookUpTable: number[] = [0xFFFFFFFF, 0xFFFFFFFF]; + + public bakeFromGradient (source: Gradient): void { + // Since Gradient already makes allowances for incorrect keyframes, we won't deal with them here. + const colorKeys = source.colorKeys; + const alphaKeys = source.alphaKeys; + const lookUpTable = this._lookUpTable; + if (colorKeys.length === alphaKeys.length + && alphaKeys.length === 2 + && colorKeys[0].time === alphaKeys[0].time + && colorKeys[1].time === alphaKeys[1].time) { + const lastIndex = colorKeys.length - 1; + this._minTime = colorKeys[0].time; + this._length = colorKeys[lastIndex].time - colorKeys[0].time; + Color.copy(tempColor, colorKeys[0].color); + tempColor.a = alphaKeys[0].alpha; + Color.copy(tempColor2, colorKeys[1].color); + tempColor2.a = alphaKeys[1].alpha; + lookUpTable[0] = Color.toUint32(tempColor); + lookUpTable[1] = Color.toUint32(tempColor2); + } else { + const minTime = this._minTime = Math.max(Math.min(colorKeys[0].time, alphaKeys[0].time) - EPSILON, 0); + const length = this._length = Math.min(Math.max(colorKeys[colorKeys.length - 1].time, alphaKeys[alphaKeys.length - 1].time) + EPSILON, 1) - this._minTime; + const lutSize = this._lookUpTable.length = Math.ceil(length / OptimizedGradient.LUT_INTERVAL) + 1; + const interval = length / (lutSize - 1); + for (let i = 0; i < lutSize; i++) { + source.evaluateFast(tempColor, minTime + i * interval); + lookUpTable[i] = Color.toUint32(tempColor); + } + } + } +} + +CCClass.fastDefine('cc.OptimizedGradient', OptimizedGradient, { + _minTime: 0, + _length: 1, + _lookUpTable: [0xFFFFFFFF, 0xFFFFFFFF], +}); + /** * @en * GradientRange is a data structure which contains some constant colors or gradients. @@ -72,96 +104,134 @@ const tempColor2 = new Color(); */ @ccclass('cc.GradientRange') export class GradientRange { + /** + * @en The gradient mode. See [[Mode]]. + * @zh 渐变色类型 参考 [[Mode]]。 + */ + public static Mode = Mode; + /** * @en Gets/Sets color gradient mode to use. See [[Mode]]. * @zh 使用的渐变色类型 参考 [[Mode]]。 */ - @type(Mode) - get mode (): number { + @type(Enum(Mode)) + public get mode (): number { return this._mode; } - set mode (m) { - if (EDITOR_NOT_IN_PREVIEW) { - if (m === Mode.RandomColor) { - if (this.gradient.colorKeys.length === 0) { - this.gradient.colorKeys.push(new ColorKey()); - } - if (this.gradient.alphaKeys.length === 0) { - this.gradient.alphaKeys.push(new AlphaKey()); - } - } - } + public set mode (m) { this._mode = m; } - /** - * @en The gradient mode. See [[Mode]]. - * @zh 渐变色类型 参考 [[Mode]]。 - */ - public static Mode = Mode; - /** * @en Max color value when use TwoColors mode. * @zh 当 mode 为 TwoColors 时的颜色上限。 - * @deprecated + * @deprecated */ public get colorMax (): Readonly { return this.color; } - public set colorMax(val: Readonly) { + public set colorMax (val: Readonly) { this.color.set(val); } /** - * - * @en Gradient max value when use TwoGradients. - * @zh 当 mode 为 TwoGradients 时的颜色渐变上限。 - * @deprecated + * @en Color value when use color mode. + * @zh 当 mode 为 Color 时的颜色。 */ - public get gradientMax (): Readonly { - return this.gradient; + @editable + public get color (): Readonly { + return this._color; } - public set gradientMax(val: Readonly) { - this.gradient.copy(val); + public set color (val: Readonly) { + this._color.set(val); } /** - * @en Color value when use color mode. - * @zh 当 mode 为 Color 时的颜色。 + * @en Min color value when use TwoColors mode. + * @zh 当 mode 为 TwoColors 时的颜色下限。 */ - @serializable @editable - public color = Color.WHITE.clone(); + public get colorMin (): Readonly { + return this._colorMin; + } + + public set colorMin (val: Readonly) { + this._colorMin.set(val); + } /** - * @en Min color value when use TwoColors mode. - * @zh 当 mode 为 TwoColors 时的颜色下限。 + * + * @en Gradient max value when use TwoGradients. + * @zh 当 mode 为 TwoGradients 时的颜色渐变上限。 + * @deprecated Since v3.8.x, use gradient directly */ - @serializable - @editable - public colorMin = Color.WHITE.clone(); + public get gradientMax (): Readonly { + return this.gradient; + } + + public set gradientMax (val: Readonly) { + this.gradient = val; + } /** - * @en Gradient value when use gradient mode. - * @zh 当 mode 为 Gradient 时的颜色渐变。 + * @en The color gradient when mode is Gradient or the upper limit of the color gradient when mode is TwoGradient. + * @zh 当 mode 为 Gradient 时的颜色渐变或 mode 为 TwoGradient 的颜色渐变上限。 */ - @type(Gradient) - public gradient = new Gradient(); + public get gradient (): Readonly { + if (!this._gradient) { + this._gradient = new Gradient(); + this._bakedGradient = new OptimizedGradient(); + } + return this._gradient; + } + + public set gradient (val: Readonly) { + if (!this._gradient) { + this._gradient = new Gradient(); + this._bakedGradient = new OptimizedGradient(); + } + this._gradient.set(val); + this._bakedGradient?.bakeFromGradient(this._gradient); + } /** * @en Gradient min value when use TwoGradients. - * @zh 当mode为TwoGradients时的颜色渐变下限。 + * @zh 当 mode 为 TwoGradients 时的颜色渐变下限。 */ - @type(Gradient) - public gradientMin = new Gradient(); + public get gradientMin (): Readonly { + if (!this._gradientMin) { + this._gradientMin = new Gradient(); + this._bakedGradientMin = new OptimizedGradient(); + } + return this._gradientMin; + } - @type(Mode) - private _mode = Mode.Color; + public set gradientMin (val: Readonly) { + if (!this._gradientMin) { + this._gradientMin = new Gradient(); + this._bakedGradientMin = new OptimizedGradient(); + } + this._gradientMin.set(val); + this._bakedGradientMin?.bakeFromGradient(this._gradientMin); + } + @serializable private _color = Color.WHITE.clone(); + @serializable + private _colorMin = Color.WHITE.clone(); + @serializable + private _gradient: Gradient | null = null; + @serializable + private _bakedGradient: OptimizedGradient | null = null; + @serializable + private _gradientMin: Gradient | null = null; + @serializable + private _bakedGradientMin: OptimizedGradient | null = null; + @serializable + private _mode = Mode.Color; /** * @en Calculate gradient value. @@ -173,21 +243,60 @@ export class GradientRange { * @returns @en Gradient value. @zh 颜色渐变曲线的值。 */ public evaluate (time: number, rndRatio: number): Color { + const color = new Color(); switch (this._mode) { case Mode.Color: - return this.color; + Color.copy(color, this.color); + break; case Mode.TwoColors: - Color.lerp(this._color, this.colorMin, this.colorMax, rndRatio); - return this._color; + Color.lerp(color, this.colorMin, this.colorMax, rndRatio); + break; case Mode.RandomColor: - return this.gradient.getRandomColor(this._color); + this.gradient.evaluateFast(color, rndRatio); + break; case Mode.Gradient: - return this.gradient.evaluateFast(this._color, time); + this.gradient.evaluateFast(color, time); + break; case Mode.TwoGradients: - Color.lerp(this._color, this.gradientMin.evaluateFast(tempColor, time), this.gradientMax.evaluateFast(tempColor2, time), rndRatio); - return this._color; + Color.lerp(color, this.gradientMin.evaluateFast(tempColor, time), this.gradient.evaluateFast(tempColor2, time), rndRatio); + break; default: - return this.color; + break; + } + return color; + } + + public set (gradientRange: Readonly): void { + this.mode = gradientRange.mode; + this.color = gradientRange.color; + this.colorMin = gradientRange.colorMin; + if (this._mode === Mode.Gradient || this._mode === Mode.TwoGradients || this._mode === Mode.RandomColor) { + this.gradient = gradientRange.gradient; + } + if (this._mode === Mode.TwoGradients) { + this.gradientMin = gradientRange.gradientMin; + } + } + + public copyToLowLevelGradientRange (lowLevelGradientRange: Impl.GradientRange): void { + lowLevelGradientRange.setMode(this._mode); + lowLevelGradientRange.setColor(Color.toUint32(this._color)); + lowLevelGradientRange.setMinColor(Color.toUint32(this._colorMin)); + if (this._mode === Mode.Gradient || this._mode === Mode.TwoGradients || this._mode === Mode.RandomColor) { + const optimizedGradient = lowLevelGradientRange.getGradient(); + optimizedGradient.setMode(this.gradient.mode); + optimizedGradient.setMinTime(this._bakedGradient!.minTime); + optimizedGradient.setLength(this._bakedGradient!.length); + optimizedGradient.setLUTSize(this._bakedGradient!.lookUpTable.length); + optimizedGradient.getLUTData().set(this._bakedGradient!.lookUpTable); + } + if (this._mode === Mode.TwoGradients) { + const optimizedGradient = lowLevelGradientRange.getMinGradient(); + optimizedGradient.setMode(this.gradientMin.mode); + optimizedGradient.setMinTime(this._bakedGradientMin!.minTime); + optimizedGradient.setLength(this._bakedGradientMin!.length); + optimizedGradient.setLUTSize(this._bakedGradientMin!.lookUpTable.length); + optimizedGradient.getLUTData().set(this._bakedGradientMin!.lookUpTable); } } diff --git a/cocos/particle/modules/box-shape.ts b/cocos/particle/modules/box-shape.ts index ca860705960..53da2067a39 100644 --- a/cocos/particle/modules/box-shape.ts +++ b/cocos/particle/modules/box-shape.ts @@ -1,7 +1,47 @@ -import { ccclass } from '../../core/data/class-decorator'; -import { ParticleSystemModule } from '../particle-system-module'; +import { Enum } from '../../core'; +import { ccclass, tooltip, type } from '../../core/data/class-decorator'; +import { BoxShapeEmitFrom } from '../define'; +import { Impl } from '../Impl'; +import { Shape } from './shape'; @ccclass('cc.BoxShape') -export class BoxShape extends ParticleSystemModule { +export class BoxShape extends Shape { + /** + * @en Specify the position from which the particles are to be emitted. + * @zh 指定粒子从什么位置发射出来。 + */ + @type(Enum(BoxShapeEmitFrom)) + @tooltip('i18n:ParticleSystem.BoxShape.emitFrom') + public get emitFrom (): BoxShapeEmitFrom { + return this._emitFrom; + } + public set emitFrom (emitFrom: BoxShapeEmitFrom) { + this._emitFrom = emitFrom; + this.impl?.setEmitFrom(emitFrom); + } + + /** + * @engineInternal + */ + public get impl (): Impl.BoxShape | null { + return this._impl as Impl.BoxShape | null; + } + + private _emitFrom: BoxShapeEmitFrom = BoxShapeEmitFrom.VOLUME; + + /** + * @engineInternal + */ + public initialize (): void { + super.initialize(); + this.impl?.setEmitFrom(this._emitFrom); + } + + /** + * @engineInternal + */ + protected createImpl (): Impl.ParticleSystemModule { + return new Impl.BoxShape(); + } } diff --git a/cocos/particle/modules/color-by-speed.ts b/cocos/particle/modules/color-by-speed.ts index a06c46ded88..4ece6e29afb 100644 --- a/cocos/particle/modules/color-by-speed.ts +++ b/cocos/particle/modules/color-by-speed.ts @@ -1,7 +1,69 @@ -import { ccclass } from '../../core/data/class-decorator'; +import { Vec2 } from '../../core'; +import { ccclass, rangeStep, serializable, tooltip, type } from '../../core/data/class-decorator'; +import { rangeMin } from '../../core/data/decorators'; +import { GradientRange } from '../gradient-range'; +import { Impl } from '../Impl'; import { ParticleSystemModule } from '../particle-system-module'; +/** + * @zh 基于每个粒子的速度控制其颜色。 + * @en Controls the color of each particle based on its speed. + */ @ccclass('cc.ColorBySpeed') export class ColorBySpeed extends ParticleSystemModule { + /** + * @zh 基于每个粒子的速度控制其颜色。 + * @en Controls the color of each particle based on its speed. + */ + @type(GradientRange) + @tooltip('i18n:ParticleSystem.ColorBySpeed.color') + public get color (): Readonly { + return this._color; + } + public set color (val) { + this._color.set(val); + if (this.impl) { + this._color.copyToLowLevelGradientRange(this.impl.getColor()); + } + } + + /** + * @zh 在指定的范围内映射粒子的速度为一个颜色。 + * @en Maps the velocity of particles to a color within the specified range. + */ + @type(Vec2) + @rangeMin(0) + @rangeStep(0.01) + public get speedRange (): Readonly { + return this._speedRange; + } + + public set speedRange (speedRange: Readonly) { + this._speedRange.set(speedRange); + this._speedRange.x = Math.max(0, this._speedRange.x); + this._speedRange.y = Math.max(0, this._speedRange.y); + this.impl?.setSpeedRange(this._speedRange.x, this._speedRange.y); + } + + public get impl (): Impl.ColorBySpeed | null { + return this._impl as Impl.ColorBySpeed | null; + } + + @serializable + private _color: GradientRange = new GradientRange(); + @serializable + private _speedRange: Vec2 = new Vec2(0, 1); + + protected createImpl (): Impl.ParticleSystemModule { + return new Impl.ColorBySpeed(); + } + + public initialize (): void { + super.initialize(); + if (this.impl) { + this._color.copyToLowLevelGradientRange(this.impl.getColor()); + this.impl.setSpeedRange(this._speedRange.x, this._speedRange.y); + } + } } diff --git a/cocos/particle/modules/color-over-lifetime.ts b/cocos/particle/modules/color-over-lifetime.ts index dba54b229cb..6bf064fd621 100644 --- a/cocos/particle/modules/color-over-lifetime.ts +++ b/cocos/particle/modules/color-over-lifetime.ts @@ -25,6 +25,7 @@ import { ccclass, type, serializable } from 'cc.decorator'; import { ParticleSystemModule } from '../particle-system-module'; import { GradientRange } from '../gradient-range'; +import { Impl } from '../Impl'; /** * @en @@ -41,4 +42,8 @@ export class ColorOverLifetime extends ParticleSystemModule { @type(GradientRange) @serializable public color = new GradientRange(); + + protected createImpl (): Impl.ParticleSystemModule { + throw new Error('Method not implemented.'); + } } diff --git a/cocos/particle/modules/shape.ts b/cocos/particle/modules/shape.ts index 7600510542e..5240e7f145e 100644 --- a/cocos/particle/modules/shape.ts +++ b/cocos/particle/modules/shape.ts @@ -22,8 +22,9 @@ THE SOFTWARE. */ -import { ccclass, tooltip, displayOrder, serializable } from 'cc.decorator'; -import { Vec3 } from '../../core'; +import { ccclass, tooltip, displayOrder, serializable, range, rangeMin } from 'cc.decorator'; +import { clamp01, Vec3 } from '../../core'; +import { Impl } from '../Impl'; import { ParticleSystemModule } from '../particle-system-module'; /** @@ -40,17 +41,18 @@ import { ParticleSystemModule } from '../particle-system-module'; * 形状的选择会影响可发射粒子的区域,但也会影响粒子的初始方向。 */ @ccclass('cc.Shape') -export class Shape extends ParticleSystemModule { +export abstract class Shape extends ParticleSystemModule { /** * @en Emitter position. * @zh 粒子发射器位置。 */ @tooltip('i18n:shapeModule.position') - get position (): Vec3 { + get position (): Readonly { return this._position; } set position (val) { - this._position = val; + this._position.set(val); + this.impl?.setPosition(val.x, val.y, val.z); } /** @@ -58,11 +60,12 @@ export class Shape extends ParticleSystemModule { * @zh 粒子发射器旋转角度。 */ @tooltip('i18n:shapeModule.rotation') - get rotation (): Vec3 { + get rotation (): Readonly { return this._rotation; } set rotation (val) { - this._rotation = val; + this._rotation.set(val); + this.impl?.setRotation(val.x, val.y, val.z); } /** @@ -74,47 +77,101 @@ export class Shape extends ParticleSystemModule { return this._scale; } set scale (val) { - this._scale = val; + this._scale.set(val); + this.impl?.setScale(val.x, val.y, val.z); } /** * @en Align particle with particle direction. * @zh 根据粒子的初始方向决定粒子的移动方向。 */ - @serializable @tooltip('i18n:shapeModule.alignToDirection') - public alignToDirection = false; + public get alignToDirection (): boolean { + return this._alignToDirection; + } + + public set alignToDirection (val: boolean) { + this._alignToDirection = val; + this.impl?.setAlignToDirection(val); + } /** * @en Particle direction random amount. * @zh 粒子生成方向随机设定。 */ - @serializable @tooltip('i18n:shapeModule.randomDirectionAmount') - public randomDirectionAmount = 0; + @range([0, 1, 0.01]) + public get randomizeDirection (): number { + return this._randomizeDirection; + } + + public set randomizeDirection (val: number) { + val = clamp01(val); + this._randomizeDirection = val; + this.impl?.setRandomizeDirection(val); + } /** * @en Blend particle directions towards a spherical direction, where they travel outwards from the center of their transform. * @zh 表示当前发射方向与当前位置到结点中心连线方向的插值。 */ - @serializable @tooltip('i18n:shapeModule.sphericalDirectionAmount') - public sphericalDirectionAmount = 0; + @range([0, 1, 0.01]) + public get spherizeDirection (): number { + return this._spherizeDirection; + } + + public set spherizeDirection (val: number) { + val = clamp01(val); + this._spherizeDirection = val; + this.impl?.setSpherizeDirection(val); + } /** * @en Particle position random amount. * @zh 粒子生成位置随机设定(设定此值为非 0 会使粒子生成位置超出生成器大小范围)。 */ - @serializable @tooltip('i18n:shapeModule.randomPositionAmount') - public randomPositionAmount = 0; + @range([0, Number.MAX_VALUE, 0.01]) + public get randomizePosition (): number { + return this._randomPosition; + } + + public set randomizePosition (val: number) { + val = Math.max(0, val); + this._randomPosition = val; + this.impl?.setRandomizePosition(val); + } + + public get impl (): Impl.Shape | null { + return this._impl as Impl.Shape | null; + } @serializable private _position = new Vec3(0, 0, 0); - @serializable private _rotation = new Vec3(0, 0, 0); - @serializable private _scale = new Vec3(1, 1, 1); + @serializable + private _alignToDirection = false; + @serializable + private _spherizeDirection = 0; + @serializable + private _randomPosition = 0; + @serializable + private _randomizeDirection = 0; + + public initialize (): void { + super.initialize(); + if (this.impl) { + this.impl.setPosition(this._position.x, this._position.y, this._position.z); + this.impl.setRotation(this._rotation.x, this._rotation.y, this._rotation.z); + this.impl.setScale(this._scale.x, this._scale.y, this._scale.z); + this.impl.setAlignToDirection(this._alignToDirection); + this.impl.setSpherizeDirection(this._spherizeDirection); + this.impl.setRandomizePosition(this._randomPosition); + this.impl.setRandomizeDirection(this._randomizeDirection); + } + } } diff --git a/cocos/particle/particle-system-module.ts b/cocos/particle/particle-system-module.ts index 0190b475091..827218a4c4a 100644 --- a/cocos/particle/particle-system-module.ts +++ b/cocos/particle/particle-system-module.ts @@ -24,17 +24,52 @@ import { serializable } from '../core'; import { ccclass } from '../core/data/class-decorator'; +import { Impl } from './Impl'; @ccclass('cc.ParticleSystemModule') export abstract class ParticleSystemModule { public get enabled (): boolean { - return this._enable; + return this._enabled; } public set enabled (val: boolean) { - this._enable = val; + this._enabled = val; + if (this._impl) { + this._impl.setEnabled(this._enabled); + } + } + + /** + * @engineInternal + */ + public get impl (): Impl.ParticleSystemModule | null { + return this._impl; } @serializable - private _enable = false; + private _enabled = false; + protected _impl: Impl.ParticleSystemModule | null = null; + + /** + * @engineInternal + */ + public initialize (): void { + this._impl = this.createImpl(); + this._impl.setEnabled(this._enabled); + } + + /** + * @engineInternal + */ + public dispose (): void { + if (this._impl) { + this._impl.dispose(); + this._impl = null; + } + } + + /** + * @engineInternal + */ + protected abstract createImpl (): Impl.ParticleSystemModule; } diff --git a/editor/i18n/en/localization.js b/editor/i18n/en/localization.js index c3b05125f0a..84c7853b76d 100755 --- a/editor/i18n/en/localization.js +++ b/editor/i18n/en/localization.js @@ -749,7 +749,7 @@ module.exports = link(mixin({ category: 'Collider component category', mask: 'The collider mask can collide with this collider', }, - particle_system: { + ParticleSystem2D: { preview: 'Play particle in edit mode', custom: 'If set custom to true, then use custom properties instead of read particle file', file: 'The plist file', @@ -784,6 +784,16 @@ module.exports = link(mixin({ startRadius: 'Starting radius and variation of the particles.
Only available in Radius mode', endRadius: 'Ending radius and variation of the particles.
Only available in Radius mode', rotatePerS: 'Number of degrees to rotate a particle around the source pos per second and variation.
Only available in Radius mode', + duration: 'Particle duration', + }, + ParticleSystem: { + BoxShape: { + emitFrom: 'Specify the position from which the particles are to be emitted.', + }, + ColorBySpeed: { + color: 'Controls the color of each particle based on its speed.', + speedRange: 'Maps the velocity of particles to a color within the specified range.', + }, capacity: 'Maximum particle amount that the system can generate', scaleSpace: 'Scale space', startSize3D: 'Set start size of X, Y and Z respectively if true', diff --git a/editor/i18n/zh/localization.js b/editor/i18n/zh/localization.js index cd3a0881867..dbee3c53365 100755 --- a/editor/i18n/zh/localization.js +++ b/editor/i18n/zh/localization.js @@ -726,7 +726,7 @@ module.exports = link(mixin({ category: '碰撞组件所属类别', mask: '可以与碰撞组件相碰撞的组件掩码', }, - particle_system: { + ParticleSystem2D: { preview: '在编辑器模式下预览粒子,启用后选中粒子时,粒子将自动播放', custom: '是否自定义粒子属性', file: 'plist 格式的粒子配置文件', @@ -761,6 +761,16 @@ module.exports = link(mixin({ startRadius: '初始半径及变化范围,表示粒子出生时相对发射器的距离,只有在半径模式下可用', endRadius: '结束半径及变化范围,只有在半径模式下可用', rotatePerS: '粒子每秒围绕起始点的旋转角度及变化范围,只有在半径模式下可用', + duration: '粒子系统运行时间', + }, + ParticleSystem: { + BoxShape: { + emitFrom: '指定粒子从什么位置发射出来。', + }, + ColorBySpeed: { + color: '基于每个粒子的速度控制其颜色。', + speedRange: '在指定的范围内映射粒子的速度为一个颜色。', + }, capacity: '粒子系统能生成的最大粒子数量', scaleSpace: '选择缩放坐标系', startSize3D: '是否分别设置粒子 X, Y 和 Z 轴的初始大小', diff --git a/native/cocos/particle/Define.h b/native/cocos/particle/Define.h index 0aeb5dd411a..f213689babc 100644 --- a/native/cocos/particle/Define.h +++ b/native/cocos/particle/Define.h @@ -46,8 +46,8 @@ enum class GradientRangeMode : uint8_t { }; enum class GradientMode : uint8_t { - FIXED, - BLEND + BLEND, + FIXED }; enum class CoordinateSpace: uint8_t { diff --git a/native/cocos/particle/GradientRange.cpp b/native/cocos/particle/GradientRange.cpp index 7a4ba1b1f43..1a2b4a42013 100644 --- a/native/cocos/particle/GradientRange.cpp +++ b/native/cocos/particle/GradientRange.cpp @@ -7,28 +7,20 @@ namespace cc { template Color OptimizedGradient::evaluate(float time) const { - CC_ASSERT(time > (_minTime - mathutils::EPSILON) && time < (_minTime + _length + mathutils::EPSILON)); Color result{Color::WHITE}; - if (_lookUpTable.size() > 4) { + if (_lookUpTable.size() > 1) { + mathutils::clamp(time, _minTime, _minTime + _length); float relativeTime = time - _minTime; - uint32_t sizeMinusOne = (_lookUpTable.size() >> 2) - 1; + uint32_t sizeMinusOne = _lookUpTable.size() - 1; float index = relativeTime / _length * sizeMinusOne; int32_t prevEntry = static_cast(std::floor(index)); int32_t nextEntry = prevEntry < sizeMinusOne ? prevEntry + 1 : prevEntry; float normalizedTime = index - prevEntry; - int32_t prevR = prevEntry << 2; - int32_t nextR = nextEntry << 2; if constexpr (mode == GradientMode::BLEND) { - result.r = MathUtil::lerp(_lookUpTable[prevR], _lookUpTable[nextR], normalizedTime); - result.g = MathUtil::lerp(_lookUpTable[prevR + 1], _lookUpTable[nextR + 1], normalizedTime); - result.b = MathUtil::lerp(_lookUpTable[prevR + 2], _lookUpTable[nextR + 2], normalizedTime); - result.a = MathUtil::lerp(_lookUpTable[prevR + 3], _lookUpTable[nextR + 3], normalizedTime); + result = Color::lerp(Color(_lookUpTable[prevEntry]), Color(_lookUpTable[nextEntry]), normalizedTime); } else { - result.r = _lookUpTable[nextR]; - result.g = _lookUpTable[nextR + 1]; - result.b = _lookUpTable[nextR + 2]; - result.a = _lookUpTable[nextR + 3]; + result.set(_lookUpTable[nextEntry]); } } return result; @@ -46,7 +38,7 @@ Color GradientRange::evaluateSlow(float time, float alpha) const { if (_mode == GradientRangeMode::COLOR) { return evaluate(time, alpha); } else if (_mode == GradientRangeMode::GRADIENT) { - if (getGradient().getMode() == GradientMode::BLEND) { + if (_gradient->getMode() == GradientMode::BLEND) { return evaluate(time, alpha); } else { return evaluate(time, alpha); @@ -54,21 +46,21 @@ Color GradientRange::evaluateSlow(float time, float alpha) const { } else if (_mode == GradientRangeMode::RANDOM_BETWEEN_TWO_COLORS) { return evaluate(time, alpha); } else if (_mode == GradientRangeMode::RANDOM_BETWEEN_TWO_GRADIENTS) { - if (getGradient().getMode() == GradientMode::BLEND) { - if (getMinGradient().getMode() == GradientMode::BLEND) { + if (_gradient->getMode() == GradientMode::BLEND) { + if (_minGradient->getMode() == GradientMode::BLEND) { return evaluate(time, alpha); } else { return evaluate(time, alpha); } } else { - if (getMinGradient().getMode() == GradientMode::BLEND) { + if (_minGradient->getMode() == GradientMode::BLEND) { return evaluate(time, alpha); } else { return evaluate(time, alpha); } } } else { - if (getGradient().getMode() == GradientMode::BLEND) { + if (_gradient->getMode() == GradientMode::BLEND) { return evaluate(time, alpha); } else { return evaluate(time, alpha); diff --git a/native/cocos/particle/GradientRange.h b/native/cocos/particle/GradientRange.h index 13ffd8b8978..d96af553a92 100644 --- a/native/cocos/particle/GradientRange.h +++ b/native/cocos/particle/GradientRange.h @@ -28,6 +28,35 @@ struct OptimizedGradient { _mode = mode; } + inline float getMinTime() const { + return _minTime; + } + + inline void setMinTime(float minTime) { + _minTime = minTime; + } + + inline float getLength() const { + return _length; + } + + inline void setLength(float length) { + _length = length; + } + + inline size_t getLUTSize() const { + return _lookUpTable.size(); + } + + inline void setLUTSize(size_t size) { + _lookUpTable.reserve(size); + _lookUpTable.resize(size); + } + + inline uint32_t* getLUTData() { + return _lookUpTable.data(); + } + template Color evaluate(float time) const; Color evaluateSlow(float time) const; @@ -35,7 +64,7 @@ struct OptimizedGradient { private: float _minTime{0.F}; float _length{1.F}; - std::vector _lookUpTable{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; + std::vector _lookUpTable{0xFFFFFFFF, 0xFFFFFFFF}; GradientMode _mode{GradientMode::BLEND}; }; @@ -50,30 +79,22 @@ struct GradientRange { inline void setMode(GradientRangeMode mode) { if (_mode == mode) return; if (mode == GradientRangeMode::GRADIENT || mode == GradientRangeMode::RANDOM_COLOR) { - getWritableGradient(); + getGradient(); } else if (mode == GradientRangeMode::RANDOM_BETWEEN_TWO_GRADIENTS) { - getWritableGradient(); - getWritableMinGradient(); + getGradient(); + getMinGradient(); } _mode = mode; } - inline const OptimizedGradient& getGradient() const { - return *_gradient; - } - - inline OptimizedGradient& getWritableGradient() { + inline OptimizedGradient& getGradient() { if (_gradient == nullptr) { _gradient = std::move(std::make_unique()); } return *_gradient; } - inline const OptimizedGradient& getMinGradient() const { - return *_minGradient; - } - - inline OptimizedGradient& getWritableMinGradient() { + inline OptimizedGradient& getMinGradient() { if (_minGradient == nullptr) { _minGradient = std::move(std::make_unique()); } @@ -117,6 +138,22 @@ struct GradientRange { } } + inline Color getColor() const { + return _color; + } + + inline void setColor(uint32_t color) { + _color.set(color); + } + + inline Color getMinColor() const { + return _minColor; + } + + inline void setMinColor(uint32_t color) { + _minColor.set(color); + } + Color evaluateSlow(float time, float alpha) const; private: diff --git a/native/cocos/particle/ParticleSystem.cpp b/native/cocos/particle/ParticleSystem.cpp index 6d2ed662b34..e88585dc749 100644 --- a/native/cocos/particle/ParticleSystem.cpp +++ b/native/cocos/particle/ParticleSystem.cpp @@ -7,7 +7,7 @@ namespace cc { void ParticleSystem::tick(float deltaTime) { - ModuleUpdateContext context{_particles, _emitter, _spawnInfos, _eventInfos, calculateScaledDeltaTime(deltaTime)}; + ParticleSystemContext context{_particles, _emitter, _spawnInfos, _eventInfos, calculateScaledDeltaTime(deltaTime)}; updateEmitterState(context); // update existing particle; @@ -44,7 +44,7 @@ void ParticleSystem::addNewParticle(size_t numToSpawn) { } } -void ParticleSystem::spawnNewParticles(ModuleUpdateContext& context) { +void ParticleSystem::spawnNewParticles(ParticleSystemContext& context) { ParticleVec3Array& position = _particles.getPosition(); ParticleVec3Array& baseVelocity = _particles.getBaseVelocity(); ParticleColorArray& baseColor = _particles.getBaseColor(); @@ -113,7 +113,7 @@ void ParticleSystem::spawnNewParticles(ModuleUpdateContext& context) { } } -void ParticleSystem::updateParticleState(ModuleUpdateContext& context) { +void ParticleSystem::updateParticleState(ParticleSystemContext& context) { ParticleFloatArray& normalizedAge = context.particles.getNormalizedAge(); ParticleFloatArray& invLifetime = context.particles.getInvLifetime(); @@ -140,7 +140,7 @@ void ParticleSystem::updateParticleState(ModuleUpdateContext& context) { } } -void ParticleSystem::updatePreSolveModules(ModuleUpdateContext& context) { +void ParticleSystem::updatePreSolveModules(ParticleSystemContext& context) { if (_forceOverLifetime && _forceOverLifetime->isEnabled()) { _forceOverLifetime->update(context); } @@ -176,7 +176,7 @@ void ParticleSystem::updatePreSolveModules(ModuleUpdateContext& context) { } } -void ParticleSystem::updatePostSolveModules(ModuleUpdateContext& context) { +void ParticleSystem::updatePostSolveModules(ParticleSystemContext& context) { if (_colorOverLifetime && _colorOverLifetime->isEnabled()) { _colorOverLifetime->update(context); } @@ -206,7 +206,7 @@ void ParticleSystem::updatePostSolveModules(ModuleUpdateContext& context) { } } -void ParticleSystem::solveVelocity(ModuleUpdateContext& context) { +void ParticleSystem::solveVelocity(ParticleSystemContext& context) { ParticleVec3Array& position = context.particles.getPosition(); ParticleFloatArray& speedModifier = context.particles.getSpeedMultiplier(); @@ -282,7 +282,7 @@ void ParticleSystem::solveVelocity(ModuleUpdateContext& context) { } } -void ParticleSystem::updateEmitterState(ModuleUpdateContext& context) { +void ParticleSystem::updateEmitterState(ParticleSystemContext& context) { // in first frame, we should initialize some value; if (_emitter.age < context.deltaTime) { _emitter.randomSeed = _emitter.autoRandomSeed ? _emitter.fixedRandomSeed : ParticleSystemManager::getInstance().getRandomSeed(); @@ -318,7 +318,7 @@ void ParticleSystem::updateEmitterState(ModuleUpdateContext& context) { _emitter.normalizedLoopAge = currentTime * invDuration; } -void ParticleSystem::updateEmissionModules(ModuleUpdateContext& context) { +void ParticleSystem::updateEmissionModules(ParticleSystemContext& context) { context.spawnInfos.clear(); if (_emissionOverTime && _emissionOverTime->isEnabled()) { _emissionOverTime->update(context); diff --git a/native/cocos/particle/ParticleSystem.h b/native/cocos/particle/ParticleSystem.h index 2e118d0efbd..60ef56a1a1f 100644 --- a/native/cocos/particle/ParticleSystem.h +++ b/native/cocos/particle/ParticleSystem.h @@ -50,15 +50,15 @@ class ParticleSystem { void addNewParticle(size_t numToSpawn); void tick(float deltaTime); - void updateEmitterState(ModuleUpdateContext& context); - void updateEmissionModules(ModuleUpdateContext& context); - void updateParticleState(ModuleUpdateContext& context); - void solveVelocity(ModuleUpdateContext& context); - void spawnNewParticles(ModuleUpdateContext& context); - void initializeParticles(ModuleUpdateContext& context); - void updatePreSolveModules(ModuleUpdateContext& context); - void updatePostSolveModules(ModuleUpdateContext& context); - void updateRenderer(ModuleUpdateContext& context); + void updateEmitterState(ParticleSystemContext& context); + void updateEmissionModules(ParticleSystemContext& context); + void updateParticleState(ParticleSystemContext& context); + void solveVelocity(ParticleSystemContext& context); + void spawnNewParticles(ParticleSystemContext& context); + void initializeParticles(ParticleSystemContext& context); + void updatePreSolveModules(ParticleSystemContext& context); + void updatePostSolveModules(ParticleSystemContext& context); + void updateRenderer(ParticleSystemContext& context); inline Renderer* getRenderer() { diff --git a/native/cocos/particle/ParticleSystemModule.h b/native/cocos/particle/ParticleSystemModule.h index db6e38fa6f9..9a34137bf9d 100644 --- a/native/cocos/particle/ParticleSystemModule.h +++ b/native/cocos/particle/ParticleSystemModule.h @@ -8,8 +8,7 @@ namespace cc { struct SpawnInfo { - SpawnInfo() = default; - inline SpawnInfo(uint32_t count, float intervalDt, float intervalNormalizedT, float interpStartDt, float interpStartNormalizedT): + explicit inline SpawnInfo(uint32_t count, float intervalDt, float intervalNormalizedT, float interpStartDt, float interpStartNormalizedT) : count(count), intervalDt(intervalDt), intervalNormalizedT(intervalNormalizedT), interpStartDt(interpStartDt), interpStartNormalizedT(interpStartNormalizedT) {} ~SpawnInfo() = default; @@ -38,11 +37,11 @@ struct EventInfo { }; -struct ModuleUpdateContext { - explicit ModuleUpdateContext(Particles& particles, Emitter& emitter, std::vector& spawnInfos, std::unordered_map>& eventInfos, float deltaTime) : particles(particles), +struct ParticleSystemContext { + explicit ParticleSystemContext(Particles& particles, Emitter& emitter, std::vector& spawnInfos, std::unordered_map>& eventInfos, float deltaTime) : particles(particles), emitter(emitter), spawnInfos(spawnInfos), eventInfos(eventInfos), deltaTime(deltaTime) {} - ~ModuleUpdateContext() = default; + ~ParticleSystemContext() = default; Particles& particles; Emitter& emitter; std::vector& spawnInfos; @@ -51,7 +50,6 @@ struct ModuleUpdateContext { size_t toIndex{0}; int32_t spawnGroup{-1}; float deltaTime{0}; - }; class ParticleSystemModule { @@ -67,7 +65,11 @@ class ParticleSystemModule { _enabled = enabled; } - virtual void update(ModuleUpdateContext& context) const = 0; + virtual void update(ParticleSystemContext& context) const = 0; + + inline void dispose() { + delete this; + } private: bool _enabled{false}; diff --git a/native/cocos/particle/modules/BoxShape.cpp b/native/cocos/particle/modules/BoxShape.cpp index fad0d3de04d..f227405a16e 100644 --- a/native/cocos/particle/modules/BoxShape.cpp +++ b/native/cocos/particle/modules/BoxShape.cpp @@ -3,7 +3,7 @@ #include "math/Mat3.h" namespace cc { -void BoxShape::update(ModuleUpdateContext& context) const { +void BoxShape::update(ParticleSystemContext& context) const { if (context.particles.hasStream((uint32_t)OptionalStreams::DIRECTION)) { updateHasDirection(context); } else { @@ -12,7 +12,7 @@ void BoxShape::update(ModuleUpdateContext& context) const { } template -void BoxShape::updateHasDirection(ModuleUpdateContext& context) const { +void BoxShape::updateHasDirection(ParticleSystemContext& context) const { switch (_emitFrom) { case EmitFrom::VOLUME: emitFrom(context); @@ -29,7 +29,7 @@ void BoxShape::updateHasDirection(ModuleUpdateContext& context) const { } template -void BoxShape::emitFrom(ModuleUpdateContext& context) const { +void BoxShape::emitFrom(ParticleSystemContext& context) const { SpawnInfo& spawnInfo = context.spawnInfos[context.spawnGroup]; Mat3 simulationRS, shapeToLocalRS; Mat3::fromMat4(spawnInfo.initialTransform, &simulationRS); diff --git a/native/cocos/particle/modules/BoxShape.h b/native/cocos/particle/modules/BoxShape.h index 8a16acc5b6d..2b92c8d9a53 100644 --- a/native/cocos/particle/modules/BoxShape.h +++ b/native/cocos/particle/modules/BoxShape.h @@ -15,7 +15,7 @@ class BoxShape : public Shape { BoxShape() = default; virtual ~BoxShape() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline Vec3 getBoxThickness() const { return _boxThickness; @@ -35,10 +35,10 @@ class BoxShape : public Shape { private: template - void updateHasDirection(ModuleUpdateContext& context) const; + void updateHasDirection(ParticleSystemContext& context) const; template - void emitFrom(ModuleUpdateContext& context) const; + void emitFrom(ParticleSystemContext& context) const; Vec3 _boxThickness{}; EmitFrom _emitFrom{EmitFrom::VOLUME}; diff --git a/native/cocos/particle/modules/ColorBySpeed.cpp b/native/cocos/particle/modules/ColorBySpeed.cpp index 8e768f7804e..f2d62e95218 100644 --- a/native/cocos/particle/modules/ColorBySpeed.cpp +++ b/native/cocos/particle/modules/ColorBySpeed.cpp @@ -3,7 +3,7 @@ #include "particle/Utils.h" namespace cc { -void ColorBySpeed::update(ModuleUpdateContext& context) const { +void ColorBySpeed::update(ParticleSystemContext& context) const { CC_ASSERT(_color.getMode() == GradientRangeMode::GRADIENT || _color.getMode() == GradientRangeMode::RANDOM_BETWEEN_TWO_GRADIENTS); if (_color.getMode() == GradientRangeMode::GRADIENT) { updateGradient(context); @@ -13,7 +13,7 @@ void ColorBySpeed::update(ModuleUpdateContext& context) const { } template -void ColorBySpeed::updateGradient(ModuleUpdateContext& context) const { +void ColorBySpeed::updateGradient(ParticleSystemContext& context) const { GradientMode maxMode = (mode == GradientRangeMode::COLOR || mode == GradientRangeMode::RANDOM_BETWEEN_TWO_COLORS) ? GradientMode::BLEND : _color.getGradient().getMode(); GradientMode minMode = (mode == GradientRangeMode::RANDOM_BETWEEN_TWO_GRADIENTS) ? _color.getMinGradient().getMode() : GradientMode::BLEND; if (maxMode == GradientMode::BLEND) { @@ -32,7 +32,7 @@ void ColorBySpeed::updateGradient(ModuleUpdateContext& context) const { } template -void ColorBySpeed::updateColor(ModuleUpdateContext& context) const { +void ColorBySpeed::updateColor(ParticleSystemContext& context) const { ParticleColorArray& color = context.particles.getColor(); ParticleVec3Array& velocity = context.particles.getVelocity(); diff --git a/native/cocos/particle/modules/ColorBySpeed.h b/native/cocos/particle/modules/ColorBySpeed.h index c9fd64d3bad..6be74f4c30e 100644 --- a/native/cocos/particle/modules/ColorBySpeed.h +++ b/native/cocos/particle/modules/ColorBySpeed.h @@ -8,7 +8,7 @@ class ColorBySpeed : public ParticleSystemModule { ColorBySpeed() = default; virtual ~ColorBySpeed() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline GradientRange& getColor() { return _color; @@ -24,10 +24,10 @@ class ColorBySpeed : public ParticleSystemModule { private: template - void updateGradient(ModuleUpdateContext& context) const; + void updateGradient(ParticleSystemContext& context) const; template - void updateColor(ModuleUpdateContext& context) const; + void updateColor(ParticleSystemContext& context) const; GradientRange _color{}; Vec2 _speedRange{0.F, 1.F}; diff --git a/native/cocos/particle/modules/ColorOverLifetime.cpp b/native/cocos/particle/modules/ColorOverLifetime.cpp index 93b7a29a11a..016d2fa074a 100644 --- a/native/cocos/particle/modules/ColorOverLifetime.cpp +++ b/native/cocos/particle/modules/ColorOverLifetime.cpp @@ -2,7 +2,7 @@ #include "particle/Utils.h" namespace cc { -void ColorOverLifetime::update(ModuleUpdateContext& context) const { +void ColorOverLifetime::update(ParticleSystemContext& context) const { CC_ASSERT(color.getMode() != GradientRangeMode::COLOR); if (_color.getMode() == GradientRangeMode::GRADIENT) { updateGradient(context); @@ -16,7 +16,7 @@ void ColorOverLifetime::update(ModuleUpdateContext& context) const { } template -void ColorOverLifetime::updateGradient(ModuleUpdateContext& context) const { +void ColorOverLifetime::updateGradient(ParticleSystemContext& context) const { GradientMode maxMode = (mode == GradientRangeMode::COLOR || mode == GradientRangeMode::RANDOM_BETWEEN_TWO_COLORS) ? GradientMode::BLEND : _color.getGradient().getMode(); GradientMode minMode = (mode == GradientRangeMode::RANDOM_BETWEEN_TWO_GRADIENTS) ? _color.getMinGradient().getMode() : GradientMode::BLEND; if (maxMode == GradientMode::BLEND) { @@ -35,7 +35,7 @@ void ColorOverLifetime::updateGradient(ModuleUpdateContext& context) const { } template -void ColorOverLifetime::updateColor(ModuleUpdateContext& context) const { +void ColorOverLifetime::updateColor(ParticleSystemContext& context) const { ParticleColorArray& color = context.particles.getColor(); for (uint32_t i = context.fromIndex; i < context.toIndex; i++) { float time = 1.F, alpha = 1.F; diff --git a/native/cocos/particle/modules/ColorOverLifetime.h b/native/cocos/particle/modules/ColorOverLifetime.h index f731992af56..38962286bc7 100644 --- a/native/cocos/particle/modules/ColorOverLifetime.h +++ b/native/cocos/particle/modules/ColorOverLifetime.h @@ -8,7 +8,7 @@ class ColorOverLifetime : public ParticleSystemModule { ColorOverLifetime() = default; virtual ~ColorOverLifetime() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline GradientRange& getColor() { return _color; @@ -16,10 +16,10 @@ class ColorOverLifetime : public ParticleSystemModule { private: template - void updateGradient(ModuleUpdateContext& context) const; + void updateGradient(ParticleSystemContext& context) const; template - void updateColor(ModuleUpdateContext& context) const; + void updateColor(ParticleSystemContext& context) const; GradientRange _color{}; }; diff --git a/native/cocos/particle/modules/CurlNoiseOverLifetime.h b/native/cocos/particle/modules/CurlNoiseOverLifetime.h index 4f8b29bbe50..bf01451696e 100644 --- a/native/cocos/particle/modules/CurlNoiseOverLifetime.h +++ b/native/cocos/particle/modules/CurlNoiseOverLifetime.h @@ -14,11 +14,11 @@ class CurlNoiseOverLifetime : public ParticleSystemModule { CurlNoiseOverLifetime() = default; virtual ~CurlNoiseOverLifetime() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; private: template - void updateForce(ModuleUpdateContext& context) const; + void updateForce(ParticleSystemContext& context) const; template Vec2 accumulateNoiseSum(Vec3 sample, float frequency) const; diff --git a/native/cocos/particle/modules/CustomData.cpp b/native/cocos/particle/modules/CustomData.cpp index 5c26a517c3d..b82f45862e9 100644 --- a/native/cocos/particle/modules/CustomData.cpp +++ b/native/cocos/particle/modules/CustomData.cpp @@ -2,7 +2,7 @@ #include "particle/Utils.h" namespace cc { -void CustomData::update(ModuleUpdateContext& context) const { +void CustomData::update(ParticleSystemContext& context) const { for (size_t customDataIndex = 0; customDataIndex < MAX_NUM_CUSTOM_STREAM; customDataIndex++) { if (_mode[customDataIndex] == CustomDataMode::VECTOR) { uint32_t randomOffset[MAX_NUM_COMPONENT_PER_STREAM * MAX_NUM_CUSTOM_STREAM]{0x671238, 0xb781a, 0x7781ba, 0xfe7182, 0xdc112, 0x90bc1, 0xc1382, 0x772bc}; @@ -38,7 +38,7 @@ void CustomData::update(ModuleUpdateContext& context) const { } template -void CustomData::updateGradient(const GradientRange& gradientRange, ModuleUpdateContext& context, size_t customDataIndex, uint32_t randomOffset) const { +void CustomData::updateGradient(const GradientRange& gradientRange, ParticleSystemContext& context, size_t customDataIndex, uint32_t randomOffset) const { GradientMode maxMode = (mode == GradientRangeMode::COLOR || mode == GradientRangeMode::RANDOM_BETWEEN_TWO_COLORS) ? GradientMode::BLEND : gradientRange.getGradient().getMode(); GradientMode minMode = (mode == GradientRangeMode::RANDOM_BETWEEN_TWO_GRADIENTS) ? gradientRange.getMinGradient().getMode() : GradientMode::BLEND; if (maxMode == GradientMode::BLEND) { @@ -57,7 +57,7 @@ void CustomData::updateGradient(const GradientRange& gradientRange, ModuleUpdate } template -void CustomData::updateCustomDataComponent(const CurveRange& curveRange, ModuleUpdateContext& context, size_t customDataIndex, size_t componentIndex, uint32_t randomOffset) const { +void CustomData::updateCustomDataComponent(const CurveRange& curveRange, ParticleSystemContext& context, size_t customDataIndex, size_t componentIndex, uint32_t randomOffset) const { ParticleFloatArray& dest = context.particles.getCustomData(customDataIndex)[componentIndex]; for (size_t i = context.fromIndex; i < context.toIndex; i++) { float time = 1.F, alpha = 1.F; @@ -74,7 +74,7 @@ void CustomData::updateCustomDataComponent(const CurveRange& curveRange, ModuleU } template -void CustomData::updateCustomDataColor(const GradientRange& gradientRange, ModuleUpdateContext& context, size_t customDataIndex, uint32_t randomOffset) const { +void CustomData::updateCustomDataColor(const GradientRange& gradientRange, ParticleSystemContext& context, size_t customDataIndex, uint32_t randomOffset) const { ParticleVec4Array& dest = context.particles.getCustomData(customDataIndex); for (size_t i = context.fromIndex; i < context.toIndex; i++) { float time = 1.F, alpha = 1.F; diff --git a/native/cocos/particle/modules/CustomData.h b/native/cocos/particle/modules/CustomData.h index 67fcc96e780..e173514693d 100644 --- a/native/cocos/particle/modules/CustomData.h +++ b/native/cocos/particle/modules/CustomData.h @@ -39,15 +39,15 @@ class CustomData : public ParticleSystemModule { _numComponents[stream] = num; } - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; private: template - void updateGradient(const GradientRange& gradientRange, ModuleUpdateContext& context, size_t customDataIndex, uint32_t randomOffset) const; + void updateGradient(const GradientRange& gradientRange, ParticleSystemContext& context, size_t customDataIndex, uint32_t randomOffset) const; template - void updateCustomDataComponent(const CurveRange& curveRange, ModuleUpdateContext& context, size_t customDataIndex, size_t componentIndex, uint32_t randomOffset) const; + void updateCustomDataComponent(const CurveRange& curveRange, ParticleSystemContext& context, size_t customDataIndex, size_t componentIndex, uint32_t randomOffset) const; template - void updateCustomDataColor(const GradientRange& gradientRange, ModuleUpdateContext& context, size_t customDataIndex, uint32_t randomOffset) const; + void updateCustomDataColor(const GradientRange& gradientRange, ParticleSystemContext& context, size_t customDataIndex, uint32_t randomOffset) const; CurveRange _components[MAX_NUM_CUSTOM_STREAM][MAX_NUM_COMPONENT_PER_STREAM]{}; GradientRange _colors[MAX_NUM_CUSTOM_STREAM]{}; diff --git a/native/cocos/particle/modules/DragOverLifetime.cpp b/native/cocos/particle/modules/DragOverLifetime.cpp index c4e62ca651a..182cc343e61 100644 --- a/native/cocos/particle/modules/DragOverLifetime.cpp +++ b/native/cocos/particle/modules/DragOverLifetime.cpp @@ -3,7 +3,7 @@ #include namespace cc { -void DragOverLifetime::update(ModuleUpdateContext& context) const { +void DragOverLifetime::update(ParticleSystemContext& context) const { if (_multiplyBySize) { updateMultiplySize(context); } else { @@ -12,7 +12,7 @@ void DragOverLifetime::update(ModuleUpdateContext& context) const { } template -void DragOverLifetime::updateMultiplySize(ModuleUpdateContext& context) const { +void DragOverLifetime::updateMultiplySize(ParticleSystemContext& context) const { if (_multiplyByVelocity) { updateMultiplyVelocity(context); } else { @@ -21,7 +21,7 @@ void DragOverLifetime::updateMultiplySize(ModuleUpdateContext& context) const { } template -void DragOverLifetime::updateMultiplyVelocity(ModuleUpdateContext& context) const { +void DragOverLifetime::updateMultiplyVelocity(ParticleSystemContext& context) const { if (_drag.getMode() == CurveRangeMode::CONSTANT) { updateForce(context); } else if (_drag.getMode() == CurveRangeMode::CURVE) { @@ -34,7 +34,7 @@ void DragOverLifetime::updateMultiplyVelocity(ModuleUpdateContext& context) cons } template -void DragOverLifetime::updateForce(ModuleUpdateContext& context) const { +void DragOverLifetime::updateForce(ParticleSystemContext& context) const { ParticleVec3Array& velocity = context.particles.getVelocity(); ParticleVec3Array& baseVelocity = context.particles.getBaseVelocity(); ParticleVec3Array& size = context.particles.getSize(); diff --git a/native/cocos/particle/modules/DragOverLifetime.h b/native/cocos/particle/modules/DragOverLifetime.h index 9f26c24b32a..f998d423f73 100644 --- a/native/cocos/particle/modules/DragOverLifetime.h +++ b/native/cocos/particle/modules/DragOverLifetime.h @@ -8,7 +8,7 @@ class DragOverLifetime : public ParticleSystemModule { DragOverLifetime() = default; virtual ~DragOverLifetime() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline CurveRange& getDrag() { return _drag; @@ -32,13 +32,13 @@ class DragOverLifetime : public ParticleSystemModule { private: template - void updateMultiplySize(ModuleUpdateContext& context) const; + void updateMultiplySize(ParticleSystemContext& context) const; template - void updateMultiplyVelocity(ModuleUpdateContext& context) const; + void updateMultiplyVelocity(ParticleSystemContext& context) const; template - void updateForce(ModuleUpdateContext& context) const; + void updateForce(ParticleSystemContext& context) const; CurveRange _drag{}; bool _multiplyBySize{true}; diff --git a/native/cocos/particle/modules/EmissionByBurst.cpp b/native/cocos/particle/modules/EmissionByBurst.cpp index 5142fa96963..cbcf7ad8d50 100644 --- a/native/cocos/particle/modules/EmissionByBurst.cpp +++ b/native/cocos/particle/modules/EmissionByBurst.cpp @@ -2,7 +2,7 @@ #include "math/MathUtil.h" namespace cc { -void EmissionByBurst::update(ModuleUpdateContext& context) const { +void EmissionByBurst::update(ParticleSystemContext& context) const { if (context.emitter.normalizedLoopAge < 0.F || context.emitter.prevNormalizedLoopAge > 1.F) { return; } @@ -15,7 +15,7 @@ void EmissionByBurst::update(ModuleUpdateContext& context) const { } } -void EmissionByBurst::updateEmissionInfo(ModuleUpdateContext& context, float loopedAge, float prevLoopedAge, float normalizedLoopAge, float prevNormalizedLoopAge, float frameOffset) const { +void EmissionByBurst::updateEmissionInfo(ParticleSystemContext& context, float loopedAge, float prevLoopedAge, float normalizedLoopAge, float prevNormalizedLoopAge, float frameOffset) const { if (loopedAge > context.emitter.duration) { loopedAge = context.emitter.duration; normalizedLoopAge = 1.F; diff --git a/native/cocos/particle/modules/EmissionByBurst.h b/native/cocos/particle/modules/EmissionByBurst.h index df5ce7914d9..55fcdc5fa35 100644 --- a/native/cocos/particle/modules/EmissionByBurst.h +++ b/native/cocos/particle/modules/EmissionByBurst.h @@ -20,7 +20,7 @@ class EmissionByBurst : public ParticleSystemModule { EmissionByBurst() = default; virtual ~EmissionByBurst() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline Burst& getBurst(uint8_t index) { return _bursts[index]; @@ -35,7 +35,7 @@ class EmissionByBurst : public ParticleSystemModule { } private: - void updateEmissionInfo(ModuleUpdateContext& context, float loopedAge, float prevLoopedAge, float normalizedLoopAge, float prevNormalizedLoopAge, float frameOffset = 0.F) const; + void updateEmissionInfo(ParticleSystemContext& context, float loopedAge, float prevLoopedAge, float normalizedLoopAge, float prevNormalizedLoopAge, float frameOffset = 0.F) const; Burst _bursts[MAX_BURST_COUNT]{}; uint8_t _count{0}; diff --git a/native/cocos/particle/modules/EmissionByEvent.h b/native/cocos/particle/modules/EmissionByEvent.h index 82f4de1e211..46bccc72227 100644 --- a/native/cocos/particle/modules/EmissionByEvent.h +++ b/native/cocos/particle/modules/EmissionByEvent.h @@ -22,7 +22,7 @@ class EmissionByEvent : public ParticleSystemModule { EmissionByEvent() = default; virtual ~EmissionByEvent() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; private: EventHandler _eventHandlers[MAX_EVENT_HANDLER_COUNT]{}; diff --git a/native/cocos/particle/modules/EmissionOverDistance.cpp b/native/cocos/particle/modules/EmissionOverDistance.cpp index ddb34703a1b..cc93e20b913 100644 --- a/native/cocos/particle/modules/EmissionOverDistance.cpp +++ b/native/cocos/particle/modules/EmissionOverDistance.cpp @@ -1,7 +1,7 @@ #include "particle/modules/EmissionOverDistance.h" namespace cc { -void EmissionOverDistance::update(ModuleUpdateContext& context) const { +void EmissionOverDistance::update(ParticleSystemContext& context) const { if (context.emitter.normalizedLoopAge < 0.F || context.emitter.prevNormalizedLoopAge > 1.F) { return; } @@ -14,7 +14,7 @@ void EmissionOverDistance::update(ModuleUpdateContext& context) const { } } -void EmissionOverDistance::updateEmissionInfo(ModuleUpdateContext& context, float loopedAge, float prevLoopedAge, float normalizedLoopAge, float prevNormalizedLoopAge, float frameOffset) const { +void EmissionOverDistance::updateEmissionInfo(ParticleSystemContext& context, float loopedAge, float prevLoopedAge, float normalizedLoopAge, float prevNormalizedLoopAge, float frameOffset) const { if (loopedAge > context.emitter.duration) { loopedAge = context.emitter.duration; normalizedLoopAge = 1.F; diff --git a/native/cocos/particle/modules/EmissionOverDistance.h b/native/cocos/particle/modules/EmissionOverDistance.h index cf55e65703e..256ce3cf4cb 100644 --- a/native/cocos/particle/modules/EmissionOverDistance.h +++ b/native/cocos/particle/modules/EmissionOverDistance.h @@ -9,14 +9,14 @@ class EmissionOverDistance : public ParticleSystemModule { EmissionOverDistance() = default; virtual ~EmissionOverDistance() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline CurveRange& getRate() { return _rate; } private: - void updateEmissionInfo(ModuleUpdateContext& context, float loopedAge, float prevLoopedAge, float normalizedLoopAge, float prevNormalizedLoopAge, float frameOffset = 0.F) const; + void updateEmissionInfo(ParticleSystemContext& context, float loopedAge, float prevLoopedAge, float normalizedLoopAge, float prevNormalizedLoopAge, float frameOffset = 0.F) const; CurveRange _rate{0}; }; } // namespace cc diff --git a/native/cocos/particle/modules/EmissionOverTime.cpp b/native/cocos/particle/modules/EmissionOverTime.cpp index c4eb5ae7273..a1ff3cce676 100644 --- a/native/cocos/particle/modules/EmissionOverTime.cpp +++ b/native/cocos/particle/modules/EmissionOverTime.cpp @@ -2,7 +2,7 @@ #include "particle/Utils.h" namespace cc { -void EmissionOverTime::update(ModuleUpdateContext& context) const { +void EmissionOverTime::update(ParticleSystemContext& context) const { if (context.emitter.normalizedLoopAge < 0.F || context.emitter.prevNormalizedLoopAge > 1.F) { return; } @@ -15,7 +15,7 @@ void EmissionOverTime::update(ModuleUpdateContext& context) const { } } -void EmissionOverTime::updateEmissionInfo(ModuleUpdateContext& context, float loopedAge, float prevLoopedAge, float normalizedLoopAge, float prevNormalizedLoopAge, float frameOffset) const { +void EmissionOverTime::updateEmissionInfo(ParticleSystemContext& context, float loopedAge, float prevLoopedAge, float normalizedLoopAge, float prevNormalizedLoopAge, float frameOffset) const { if (loopedAge > context.emitter.duration) { loopedAge = context.emitter.duration; normalizedLoopAge = 1.F; diff --git a/native/cocos/particle/modules/EmissionOverTime.h b/native/cocos/particle/modules/EmissionOverTime.h index e74dbaddeb0..18f604891e9 100644 --- a/native/cocos/particle/modules/EmissionOverTime.h +++ b/native/cocos/particle/modules/EmissionOverTime.h @@ -8,14 +8,14 @@ class EmissionOverTime : public ParticleSystemModule { EmissionOverTime() = default; virtual ~EmissionOverTime() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline CurveRange& getRate() { return _rate; } private: - void updateEmissionInfo(ModuleUpdateContext& context, float loopedAge, float prevLoopedAge, float normalizedLoopAge, float prevNormalizedLoopAge, float frameOffset = 0.F) const; + void updateEmissionInfo(ParticleSystemContext& context, float loopedAge, float prevLoopedAge, float normalizedLoopAge, float prevNormalizedLoopAge, float frameOffset = 0.F) const; CurveRange _rate{10.F}; }; } diff --git a/native/cocos/particle/modules/EventByDeath.h b/native/cocos/particle/modules/EventByDeath.h index 2b90bee4ab1..a6bc01091f3 100644 --- a/native/cocos/particle/modules/EventByDeath.h +++ b/native/cocos/particle/modules/EventByDeath.h @@ -8,6 +8,6 @@ class EventByDeath : public ParticleSystemModule { EventByDeath() = default; virtual ~EventByDeath() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; }; } diff --git a/native/cocos/particle/modules/ForceOverLifetime.cpp b/native/cocos/particle/modules/ForceOverLifetime.cpp index 1657ccc966a..97fe32d75f9 100644 --- a/native/cocos/particle/modules/ForceOverLifetime.cpp +++ b/native/cocos/particle/modules/ForceOverLifetime.cpp @@ -2,7 +2,7 @@ #include "particle/Utils.h" namespace cc { -void ForceOverLifetime::update(ModuleUpdateContext& context) const { +void ForceOverLifetime::update(ParticleSystemContext& context) const { bool needTransform = _space != context.emitter.simulationSpace; if (needTransform) { updateTransform(context); @@ -12,7 +12,7 @@ void ForceOverLifetime::update(ModuleUpdateContext& context) const { } template -void ForceOverLifetime::updateTransform(ModuleUpdateContext& context) const { +void ForceOverLifetime::updateTransform(ParticleSystemContext& context) const { if (_force[0].getMode() == CurveRangeMode::CONSTANT) { updateForce(context); } else if (_force[0].getMode() == CurveRangeMode::CURVE) { @@ -25,7 +25,7 @@ void ForceOverLifetime::updateTransform(ModuleUpdateContext& context) const { } template -void ForceOverLifetime::updateForce(ModuleUpdateContext& context) const { +void ForceOverLifetime::updateForce(ParticleSystemContext& context) const { Mat4 mat{}; if constexpr (transform) { mat = _space == CoordinateSpace::LOCAL ? context.emitter.localToWorldRS : context.emitter.worldToLocalRS; diff --git a/native/cocos/particle/modules/ForceOverLifetime.h b/native/cocos/particle/modules/ForceOverLifetime.h index 670b567701e..288c16926d5 100644 --- a/native/cocos/particle/modules/ForceOverLifetime.h +++ b/native/cocos/particle/modules/ForceOverLifetime.h @@ -9,7 +9,7 @@ class ForceOverLifetime : public ParticleSystemModule { ForceOverLifetime() = default; virtual ~ForceOverLifetime() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline CoordinateSpace getSpace() const { return _space; @@ -41,10 +41,10 @@ class ForceOverLifetime : public ParticleSystemModule { private: template - void updateTransform(ModuleUpdateContext& context) const; + void updateTransform(ParticleSystemContext& context) const; template - void updateForce(ModuleUpdateContext& context) const; + void updateForce(ParticleSystemContext& context) const; CurveRange _force[3]{}; CoordinateSpace _space{CoordinateSpace::LOCAL}; diff --git a/native/cocos/particle/modules/GravityOverLifetime.cpp b/native/cocos/particle/modules/GravityOverLifetime.cpp index 63a46da8788..815b4a45063 100644 --- a/native/cocos/particle/modules/GravityOverLifetime.cpp +++ b/native/cocos/particle/modules/GravityOverLifetime.cpp @@ -2,7 +2,7 @@ #include "particle/Utils.h" namespace cc { -void GravityOverLifetime::update(ModuleUpdateContext& context) const { +void GravityOverLifetime::update(ParticleSystemContext& context) const { bool needTransform = _space != context.emitter.simulationSpace; if (needTransform) { updateTransform(context); @@ -12,7 +12,7 @@ void GravityOverLifetime::update(ModuleUpdateContext& context) const { }; template -void GravityOverLifetime::updateTransform(ModuleUpdateContext& context) const { +void GravityOverLifetime::updateTransform(ParticleSystemContext& context) const { if (_gravity[0].getMode() == CurveRangeMode::CONSTANT) { updateForce(context); } else if (_gravity[0].getMode() == CurveRangeMode::CURVE) { @@ -25,7 +25,7 @@ void GravityOverLifetime::updateTransform(ModuleUpdateContext& context) const { } template -void GravityOverLifetime::updateForce(ModuleUpdateContext& context) const { +void GravityOverLifetime::updateForce(ParticleSystemContext& context) const { Mat4 mat{}; if constexpr (transform) { mat = _space == CoordinateSpace::LOCAL ? context.emitter.localToWorldRS : context.emitter.worldToLocalRS; diff --git a/native/cocos/particle/modules/GravityOverLifetime.h b/native/cocos/particle/modules/GravityOverLifetime.h index bd1170c215c..c8407375e35 100644 --- a/native/cocos/particle/modules/GravityOverLifetime.h +++ b/native/cocos/particle/modules/GravityOverLifetime.h @@ -9,7 +9,7 @@ class GravityOverLifetime : public ParticleSystemModule { GravityOverLifetime() = default; virtual ~GravityOverLifetime() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline CoordinateSpace getSpace() const { return _space; @@ -33,9 +33,9 @@ class GravityOverLifetime : public ParticleSystemModule { private: template - void updateTransform(ModuleUpdateContext& context) const; + void updateTransform(ParticleSystemContext& context) const; template - void updateForce(ModuleUpdateContext& context) const; + void updateForce(ParticleSystemContext& context) const; CurveRange _gravity[3]{}; CoordinateSpace _space{CoordinateSpace::WORLD}; diff --git a/native/cocos/particle/modules/InheritStartSpeed.cpp b/native/cocos/particle/modules/InheritStartSpeed.cpp index bdd5c051475..ea12d84f089 100644 --- a/native/cocos/particle/modules/InheritStartSpeed.cpp +++ b/native/cocos/particle/modules/InheritStartSpeed.cpp @@ -1,7 +1,7 @@ #include "particle/modules/InheritStartSpeed.h" namespace cc { -void InheritStartSpeed::update(ModuleUpdateContext& context) const { +void InheritStartSpeed::update(ParticleSystemContext& context) const { if (_multiplier.getMode() == CurveRangeMode::CONSTANT) { updateBaseVelocity(context); } else if (_multiplier.getMode() == CurveRangeMode::CURVE) { @@ -14,7 +14,7 @@ void InheritStartSpeed::update(ModuleUpdateContext& context) const { } template -void InheritStartSpeed::updateBaseVelocity(ModuleUpdateContext& context) const { +void InheritStartSpeed::updateBaseVelocity(ParticleSystemContext& context) const { ParticleVec3Array& baseVelocity = context.particles.getBaseVelocity(); SpawnInfo& spawnInfo = context.spawnInfos[context.spawnGroup]; Vec3 simulationVelocity = spawnInfo.simulationVelocity; diff --git a/native/cocos/particle/modules/InheritStartSpeed.h b/native/cocos/particle/modules/InheritStartSpeed.h index 2a060e333ad..fa3d859e19a 100644 --- a/native/cocos/particle/modules/InheritStartSpeed.h +++ b/native/cocos/particle/modules/InheritStartSpeed.h @@ -9,7 +9,7 @@ class InheritStartSpeed : public ParticleSystemModule { InheritStartSpeed() = default; virtual ~InheritStartSpeed() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline CurveRange& getMultiplier() { return _multiplier; @@ -17,7 +17,7 @@ class InheritStartSpeed : public ParticleSystemModule { private: template - void updateBaseVelocity(ModuleUpdateContext& context) const; + void updateBaseVelocity(ParticleSystemContext& context) const; CurveRange _multiplier{0.F}; }; diff --git a/native/cocos/particle/modules/InheritVelocityOverLifetime.cpp b/native/cocos/particle/modules/InheritVelocityOverLifetime.cpp index c46e483f667..3419cdb091e 100644 --- a/native/cocos/particle/modules/InheritVelocityOverLifetime.cpp +++ b/native/cocos/particle/modules/InheritVelocityOverLifetime.cpp @@ -1,7 +1,7 @@ #include "particle/modules/InheritVelocityOverLifetime.h" namespace cc { -void InheritVelocityOverLifetime::update(ModuleUpdateContext& context) const { +void InheritVelocityOverLifetime::update(ParticleSystemContext& context) const { if (_multiplier.getMode() == CurveRangeMode::CONSTANT) { updateVelocity(context); } else if (_multiplier.getMode() == CurveRangeMode::CURVE) { @@ -14,10 +14,10 @@ void InheritVelocityOverLifetime::update(ModuleUpdateContext& context) const { } template -void InheritVelocityOverLifetime::updateVelocity(ModuleUpdateContext& context) const { +void InheritVelocityOverLifetime::updateVelocity(ParticleSystemContext& context) const { if (context.emitter.simulationSpace == CoordinateSpace::LOCAL) return; - ParticleVec3Array& dest = context.particles.getVelocity(); + ParticleVec3Array& velocity = context.particles.getVelocity(); Vec3 emitterVelocity = context.emitter.velocity; for (uint32_t i = context.fromIndex; i < context.toIndex; i++) { float alpha{1.F}; @@ -30,7 +30,7 @@ void InheritVelocityOverLifetime::updateVelocity(ModuleUpdateContext& context) c time = context.particles.getNormalizedAge().load(i); }; float scale = _multiplier.evaluate(time, alpha); - dest.store(i, dest.load(i) + emitterVelocity * scale); + velocity.store(i, velocity.load(i) + emitterVelocity * scale); } } } diff --git a/native/cocos/particle/modules/InheritVelocityOverLifetime.h b/native/cocos/particle/modules/InheritVelocityOverLifetime.h index 269a2778476..a0ff8c678ac 100644 --- a/native/cocos/particle/modules/InheritVelocityOverLifetime.h +++ b/native/cocos/particle/modules/InheritVelocityOverLifetime.h @@ -8,11 +8,11 @@ class InheritVelocityOverLifetime : public ParticleSystemModule { public: InheritVelocityOverLifetime() = default; virtual ~InheritVelocityOverLifetime() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; private: template - void updateVelocity(ModuleUpdateContext& context) const; + void updateVelocity(ParticleSystemContext& context) const; CurveRange _multiplier{0}; }; diff --git a/native/cocos/particle/modules/LimitVelocityOverLifetime.cpp b/native/cocos/particle/modules/LimitVelocityOverLifetime.cpp index 737ba10b70a..20e824664ed 100644 --- a/native/cocos/particle/modules/LimitVelocityOverLifetime.cpp +++ b/native/cocos/particle/modules/LimitVelocityOverLifetime.cpp @@ -1,7 +1,7 @@ #include "particle/modules/LimitVelocityOverLifetime.h" namespace cc { -void LimitVelocityOverLifetime::update(ModuleUpdateContext& context) const { +void LimitVelocityOverLifetime::update(ParticleSystemContext& context) const { } } diff --git a/native/cocos/particle/modules/LimitVelocityOverLifetime.h b/native/cocos/particle/modules/LimitVelocityOverLifetime.h index fae3ad9d1f2..1e8676167f6 100644 --- a/native/cocos/particle/modules/LimitVelocityOverLifetime.h +++ b/native/cocos/particle/modules/LimitVelocityOverLifetime.h @@ -7,7 +7,7 @@ class LimitVelocityOverLifetime : public ParticleSystemModule{ public: LimitVelocityOverLifetime() = default; virtual ~LimitVelocityOverLifetime() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline bool getSeparateAxes() const { return _separateAxes; @@ -31,10 +31,10 @@ class LimitVelocityOverLifetime : public ParticleSystemModule{ private: template - void updateVelocity(ModuleUpdateContext& context) const; + void updateVelocity(ParticleSystemContext& context) const; template - void updateVelocityPerAxis(ModuleUpdateContext& context) const; + void updateVelocityPerAxis(ParticleSystemContext& context) const; CurveRange _speed[3]{1.f, 1.f, 1.f}; float dampen{1.F}; diff --git a/native/cocos/particle/modules/LinearVelocityOverLifetime.cpp b/native/cocos/particle/modules/LinearVelocityOverLifetime.cpp index 0b484279bb0..a018c1d70ad 100644 --- a/native/cocos/particle/modules/LinearVelocityOverLifetime.cpp +++ b/native/cocos/particle/modules/LinearVelocityOverLifetime.cpp @@ -2,7 +2,7 @@ #include "particle/Utils.h" namespace cc { -void LinearVelocityOverLifetime::update(ModuleUpdateContext& context) const { +void LinearVelocityOverLifetime::update(ParticleSystemContext& context) const { bool needTransform = _space != context.emitter.simulationSpace; if (needTransform) { updateTransform(context); @@ -12,7 +12,7 @@ void LinearVelocityOverLifetime::update(ModuleUpdateContext& context) const { } template -void LinearVelocityOverLifetime::updateTransform(ModuleUpdateContext& context) const { +void LinearVelocityOverLifetime::updateTransform(ParticleSystemContext& context) const { if (_velocity[0].getMode() == CurveRangeMode::CONSTANT) { updateVelocity(context); } else if (_velocity[0].getMode() == CurveRangeMode::CURVE) { @@ -25,7 +25,7 @@ void LinearVelocityOverLifetime::updateTransform(ModuleUpdateContext& context) c } template -void LinearVelocityOverLifetime::updateVelocity(ModuleUpdateContext& context) const { +void LinearVelocityOverLifetime::updateVelocity(ParticleSystemContext& context) const { Mat4 mat{}; if constexpr (transform) { mat = _space == CoordinateSpace::LOCAL ? context.emitter.localToWorldRS : context.emitter.worldToLocalRS; diff --git a/native/cocos/particle/modules/LinearVelocityOverLifetime.h b/native/cocos/particle/modules/LinearVelocityOverLifetime.h index 6328937f804..7175462be55 100644 --- a/native/cocos/particle/modules/LinearVelocityOverLifetime.h +++ b/native/cocos/particle/modules/LinearVelocityOverLifetime.h @@ -8,7 +8,7 @@ class LinearVelocityOverLifetime : public ParticleSystemModule { LinearVelocityOverLifetime() = default; virtual ~LinearVelocityOverLifetime() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline CurveRange& getVelocityX() { return _velocity[0]; @@ -32,10 +32,10 @@ class LinearVelocityOverLifetime : public ParticleSystemModule { private: template - void updateTransform(ModuleUpdateContext& context) const; + void updateTransform(ParticleSystemContext& context) const; template - void updateVelocity(ModuleUpdateContext& context) const; + void updateVelocity(ParticleSystemContext& context) const; CurveRange _velocity[3]{}; CoordinateSpace _space{CoordinateSpace::LOCAL}; diff --git a/native/cocos/particle/modules/OrbitalVelocityOverLifetime.cpp b/native/cocos/particle/modules/OrbitalVelocityOverLifetime.cpp index b1f85efe427..055a1623a78 100644 --- a/native/cocos/particle/modules/OrbitalVelocityOverLifetime.cpp +++ b/native/cocos/particle/modules/OrbitalVelocityOverLifetime.cpp @@ -1,7 +1,7 @@ #include "particle/modules/OrbitalVelocityOverLifetime.h" namespace cc { -void OrbitalVelocityOverLifetime::update(ModuleUpdateContext& context) const { +void OrbitalVelocityOverLifetime::update(ParticleSystemContext& context) const { if (_orbital[0].getMode() == CurveRangeMode::CONSTANT) { updateOrbital(context); } else if (_orbital[0].getMode() == CurveRangeMode::CURVE) { @@ -14,7 +14,7 @@ void OrbitalVelocityOverLifetime::update(ModuleUpdateContext& context) const { } template -void OrbitalVelocityOverLifetime::updateOrbital(ModuleUpdateContext& context) const { +void OrbitalVelocityOverLifetime::updateOrbital(ParticleSystemContext& context) const { if (_offset[0].getMode() == CurveRangeMode::CONSTANT) { updateOffset(context); } else if (_offset[0].getMode() == CurveRangeMode::CURVE) { @@ -27,7 +27,7 @@ void OrbitalVelocityOverLifetime::updateOrbital(ModuleUpdateContext& context) co } template -void OrbitalVelocityOverLifetime::updateOffset(ModuleUpdateContext& context) const { +void OrbitalVelocityOverLifetime::updateOffset(ParticleSystemContext& context) const { if (_radial.getMode() == CurveRangeMode::CONSTANT) { updateVelocity(context); } else if (_radial.getMode() == CurveRangeMode::CURVE) { @@ -40,7 +40,7 @@ void OrbitalVelocityOverLifetime::updateOffset(ModuleUpdateContext& context) con } template -void OrbitalVelocityOverLifetime::updateVelocity(ModuleUpdateContext& context) const { +void OrbitalVelocityOverLifetime::updateVelocity(ParticleSystemContext& context) const { for (size_t i = context.fromIndex; i < context.toIndex; i++) { Vec3 alpha{}; float time{1.F}; diff --git a/native/cocos/particle/modules/OrbitalVelocityOverLifetime.h b/native/cocos/particle/modules/OrbitalVelocityOverLifetime.h index 23a30c0d919..3a38fb53883 100644 --- a/native/cocos/particle/modules/OrbitalVelocityOverLifetime.h +++ b/native/cocos/particle/modules/OrbitalVelocityOverLifetime.h @@ -9,7 +9,7 @@ class OrbitalVelocityOverLifetime : public ParticleSystemModule { OrbitalVelocityOverLifetime() = default; virtual ~OrbitalVelocityOverLifetime() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline CurveRange& getOrbitalX() { return _orbital[0]; @@ -41,13 +41,13 @@ class OrbitalVelocityOverLifetime : public ParticleSystemModule { private: template - void updateOrbital(ModuleUpdateContext& context) const; + void updateOrbital(ParticleSystemContext& context) const; template - void updateOffset(ModuleUpdateContext& context) const; + void updateOffset(ParticleSystemContext& context) const; template - void updateVelocity(ModuleUpdateContext& context) const; + void updateVelocity(ParticleSystemContext& context) const; void applyOrbitalAndRadialVelocity(size_t index, const Vec3& orbitalVelocity, const Vec3& offset, float radial) const; diff --git a/native/cocos/particle/modules/RotationBySpeed.cpp b/native/cocos/particle/modules/RotationBySpeed.cpp index 89cb8ff530a..4a37f39aa1d 100644 --- a/native/cocos/particle/modules/RotationBySpeed.cpp +++ b/native/cocos/particle/modules/RotationBySpeed.cpp @@ -3,7 +3,7 @@ #include "particle/Utils.h" namespace cc { -void RotationBySpeed::update(ModuleUpdateContext& context) const { +void RotationBySpeed::update(ParticleSystemContext& context) const { if (_separateAxes) { if (_angularVelocity[0].getMode() == CurveRangeMode::CURVE) { updateAngularVelocityPerAxis(context); @@ -20,7 +20,7 @@ void RotationBySpeed::update(ModuleUpdateContext& context) const { } template -void RotationBySpeed::updateAngularVelocity(ModuleUpdateContext& context) const { +void RotationBySpeed::updateAngularVelocity(ParticleSystemContext& context) const { ParticleVec3Array& angularVelocity = context.particles.getAngularVelocity(); ParticleVec3Array& velocity = context.particles.getVelocity(); @@ -37,7 +37,7 @@ void RotationBySpeed::updateAngularVelocity(ModuleUpdateContext& context) const } template -void RotationBySpeed::updateAngularVelocityPerAxis(ModuleUpdateContext& context) const { +void RotationBySpeed::updateAngularVelocityPerAxis(ParticleSystemContext& context) const { ParticleVec3Array& angularVelocity = context.particles.getAngularVelocity(); ParticleVec3Array& velocity = context.particles.getVelocity(); for (size_t i = context.fromIndex; i < context.toIndex; i++) { diff --git a/native/cocos/particle/modules/RotationBySpeed.h b/native/cocos/particle/modules/RotationBySpeed.h index 3e62ec3f28d..3e26074f86d 100644 --- a/native/cocos/particle/modules/RotationBySpeed.h +++ b/native/cocos/particle/modules/RotationBySpeed.h @@ -9,7 +9,7 @@ class RotationBySpeed : public ParticleSystemModule { RotationBySpeed() = default; virtual ~RotationBySpeed() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline bool getSeparateAxes() const { return _separateAxes; @@ -41,10 +41,10 @@ class RotationBySpeed : public ParticleSystemModule { private: template - void updateAngularVelocity(ModuleUpdateContext& context) const; + void updateAngularVelocity(ParticleSystemContext& context) const; template - void updateAngularVelocityPerAxis(ModuleUpdateContext& context) const; + void updateAngularVelocityPerAxis(ParticleSystemContext& context) const; CurveRange _angularVelocity[3]{{1.F, OptimizedCurve::ZERO_TO_ONE}, {1.F, OptimizedCurve::ZERO_TO_ONE}, {1.F, OptimizedCurve::ZERO_TO_ONE}}; Vec2 _speedRange{0, 1}; diff --git a/native/cocos/particle/modules/RotationOverLifetime.cpp b/native/cocos/particle/modules/RotationOverLifetime.cpp index 956530439d6..1bb63ac2bf1 100644 --- a/native/cocos/particle/modules/RotationOverLifetime.cpp +++ b/native/cocos/particle/modules/RotationOverLifetime.cpp @@ -1,7 +1,7 @@ #include "particle/modules/RotationOverLifetime.h" namespace cc { -void RotationOverLifetime::update(ModuleUpdateContext& context) const { +void RotationOverLifetime::update(ParticleSystemContext& context) const { if (_separateAxes) { if (_angularVelocity[0].getMode() == CurveRangeMode::CONSTANT) { updateAngularVelocityPerAxis(context); @@ -26,7 +26,7 @@ void RotationOverLifetime::update(ModuleUpdateContext& context) const { } template -void RotationOverLifetime::updateAngularVelocity(ModuleUpdateContext& context) const{ +void RotationOverLifetime::updateAngularVelocity(ParticleSystemContext& context) const{ ParticleVec3Array& angularVelocity = context.particles.getAngularVelocity(); for (uint32_t i = context.fromIndex; i < context.toIndex; i++) { float alpha{1.F}; @@ -44,7 +44,7 @@ void RotationOverLifetime::updateAngularVelocity(ModuleUpdateContext& context) c } template -void RotationOverLifetime::updateAngularVelocityPerAxis(ModuleUpdateContext& context) const { +void RotationOverLifetime::updateAngularVelocityPerAxis(ParticleSystemContext& context) const { ParticleVec3Array& angularVelocity = context.particles.getAngularVelocity(); for (uint32_t i = context.fromIndex; i < context.toIndex; i++) { Vec3 alpha; diff --git a/native/cocos/particle/modules/RotationOverLifetime.h b/native/cocos/particle/modules/RotationOverLifetime.h index f59874711d9..73d242ca66d 100644 --- a/native/cocos/particle/modules/RotationOverLifetime.h +++ b/native/cocos/particle/modules/RotationOverLifetime.h @@ -9,7 +9,7 @@ class RotationOverLifetime : public ParticleSystemModule { RotationOverLifetime() = default; virtual ~RotationOverLifetime() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline CurveRange& getRotationX() { return _angularVelocity[0]; @@ -25,10 +25,10 @@ class RotationOverLifetime : public ParticleSystemModule { private: template - void updateAngularVelocity(ModuleUpdateContext& context) const; + void updateAngularVelocity(ParticleSystemContext& context) const; template - void updateAngularVelocityPerAxis(ModuleUpdateContext& context) const; + void updateAngularVelocityPerAxis(ParticleSystemContext& context) const; CurveRange _angularVelocity[3]{0, 0, 45}; bool _separateAxes{false}; diff --git a/native/cocos/particle/modules/Shape.cpp b/native/cocos/particle/modules/Shape.cpp index 50ca5bc4e3e..915f7a92190 100644 --- a/native/cocos/particle/modules/Shape.cpp +++ b/native/cocos/particle/modules/Shape.cpp @@ -1,7 +1,7 @@ #include "particle/modules/Shape.h" namespace cc { -void Shape::updatePosition(const ModuleUpdateContext& context, const Mat3& simulationTransformRS, const Mat3& shapeToSimulation, size_t index, Vec3 position) const { +void Shape::updatePosition(const ParticleSystemContext& context, const Mat3& simulationTransformRS, const Mat3& shapeToSimulation, size_t index, Vec3 position) const { if (_randomizePosition > math::EPSILON) { position += Rand(context.emitter.randomSeed, context.particles.getId().load(index), 0xbbc9728).randomUnitVec3() * _randomizePosition; } @@ -13,7 +13,7 @@ void Shape::updatePosition(const ModuleUpdateContext& context, const Mat3& simul context.particles.getPosition().store(index, position); } -void Shape::updateDirection(const ModuleUpdateContext& context, const Mat3& simulationTransformRS, const Mat3& shapeToSimulation, size_t index, Vec3 position, Vec3 normal) const { +void Shape::updateDirection(const ParticleSystemContext& context, const Mat3& simulationTransformRS, const Mat3& shapeToSimulation, size_t index, Vec3 position, Vec3 normal) const { if (_randomizeDirection > math::EPSILON) { normal = normal.lerp(Rand(context.emitter.randomSeed, context.particles.getId().load(index), 0x716ca78).randomUnitVec3(), _randomizeDirection); } diff --git a/native/cocos/particle/modules/Shape.h b/native/cocos/particle/modules/Shape.h index a17a439e730..b0e353b7f44 100644 --- a/native/cocos/particle/modules/Shape.h +++ b/native/cocos/particle/modules/Shape.h @@ -10,6 +10,62 @@ class Shape : public ParticleSystemModule { Shape() = default; virtual ~Shape() override = default; + inline Vec3 getPosition() const { + return _position; + } + + inline void setPosition(float x, float y, float z) { + _position.set(x, y, z); + } + + inline Vec3 getRotation() const { + return _rotation; + } + + inline void setRotation(float x, float y, float z) { + _rotation.set(x, y, z); + } + + inline Vec3 getScale() const { + return _scale; + } + + inline void setScale(float x, float y, float z) { + _scale.set(x, y, z); + } + + inline float getRandomizeDirection() const { + return _randomizeDirection; + } + + inline void setRandomizeDirection(float randomizeDirection) { + _randomizeDirection = randomizeDirection; + } + + inline float getSpherizeDirection() const { + return _spherizeDirection; + } + + inline void setSpherizeDirection(float spherizeDirection) { + _spherizeDirection = spherizeDirection; + } + + inline float getRandomizePosition() const { + return _randomizePosition; + } + + inline void setRandomizePosition(float randomizePosition) { + _randomizePosition = randomizePosition; + } + + inline bool getAlignToDirection() const { + return _alignToDirection; + } + + inline void setAlignToDirection(float alignToDirection) { + _alignToDirection = alignToDirection; + } + protected: Vec3 _position{}; Vec3 _rotation{}; @@ -20,8 +76,8 @@ class Shape : public ParticleSystemModule { float _randomizePosition{0.F}; bool _alignToDirection{false}; - void updatePosition(const ModuleUpdateContext& context, const Mat3& simulationTransformRS, const Mat3& shapeToSimulationRS, size_t index, Vec3 position) const; + void updatePosition(const ParticleSystemContext& context, const Mat3& simulationTransformRS, const Mat3& shapeToSimulationRS, size_t index, Vec3 position) const; - void updateDirection(const ModuleUpdateContext& context, const Mat3& simulationTransformRS, const Mat3& shapeToSimulationRS, size_t index, Vec3 position, Vec3 normal) const; + void updateDirection(const ParticleSystemContext& context, const Mat3& simulationTransformRS, const Mat3& shapeToSimulationRS, size_t index, Vec3 position, Vec3 normal) const; }; } diff --git a/native/cocos/particle/modules/SizeBySpeed.cpp b/native/cocos/particle/modules/SizeBySpeed.cpp index ac2bad03007..6d63ab035ef 100644 --- a/native/cocos/particle/modules/SizeBySpeed.cpp +++ b/native/cocos/particle/modules/SizeBySpeed.cpp @@ -2,7 +2,7 @@ #include "math/Utils.h" namespace cc { -void SizeBySpeed::update(ModuleUpdateContext& context) const { +void SizeBySpeed::update(ParticleSystemContext& context) const { if (_separateAxes) { if (_size[0].getMode() == CurveRangeMode::CURVE) { updateSizePerAxis(context); @@ -19,7 +19,7 @@ void SizeBySpeed::update(ModuleUpdateContext& context) const { } template -void SizeBySpeed::updateUse3DSize(ModuleUpdateContext& context) const { +void SizeBySpeed::updateUse3DSize(ParticleSystemContext& context) const { if (context.particles.getUse3DSize()) { updateSize(context); } else { @@ -28,7 +28,7 @@ void SizeBySpeed::updateUse3DSize(ModuleUpdateContext& context) const { } template -void SizeBySpeed::updateSize(ModuleUpdateContext& context) const { +void SizeBySpeed::updateSize(ParticleSystemContext& context) const { ParticleVec3Array& size = context.particles.getSize(); ParticleVec3Array& velocity = context.particles.getVelocity(); for (size_t i = context.fromIndex; i < context.toIndex; i++) { @@ -47,7 +47,7 @@ void SizeBySpeed::updateSize(ModuleUpdateContext& context) const { } template -void SizeBySpeed::updateSizePerAxis(ModuleUpdateContext& context) const { +void SizeBySpeed::updateSizePerAxis(ParticleSystemContext& context) const { ParticleVec3Array& size = context.particles.getSize(); ParticleVec3Array& velocity = context.particles.getVelocity(); for (size_t i = context.fromIndex; i < context.toIndex; i++) { diff --git a/native/cocos/particle/modules/SizeBySpeed.h b/native/cocos/particle/modules/SizeBySpeed.h index 91636b6c30d..958d37eae9c 100644 --- a/native/cocos/particle/modules/SizeBySpeed.h +++ b/native/cocos/particle/modules/SizeBySpeed.h @@ -11,7 +11,7 @@ class SizeBySpeed : public ParticleSystemModule { SizeBySpeed() = default; virtual ~SizeBySpeed() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline bool getSeparateAxes() const { return _separateAxes; @@ -43,13 +43,13 @@ class SizeBySpeed : public ParticleSystemModule { private: template - void updateUse3DSize(ModuleUpdateContext& context) const; + void updateUse3DSize(ParticleSystemContext& context) const; template - void updateSize(ModuleUpdateContext& context) const; + void updateSize(ParticleSystemContext& context) const; template - void updateSizePerAxis(ModuleUpdateContext& context) const; + void updateSizePerAxis(ParticleSystemContext& context) const; CurveRange _size[3]{{1.F, OptimizedCurve::ZERO_TO_ONE}, {1.F, OptimizedCurve::ZERO_TO_ONE}, {1.F, OptimizedCurve::ZERO_TO_ONE}}; Vec2 _speedRange{0.f, 1.f}; diff --git a/native/cocos/particle/modules/SizeOverLifetime.cpp b/native/cocos/particle/modules/SizeOverLifetime.cpp index 4de5ae6ed20..494887d20f3 100644 --- a/native/cocos/particle/modules/SizeOverLifetime.cpp +++ b/native/cocos/particle/modules/SizeOverLifetime.cpp @@ -1,7 +1,7 @@ #include "particle/modules/SizeOverLifetime.h" namespace cc { -void SizeOverLifetime::update(ModuleUpdateContext& context) const { +void SizeOverLifetime::update(ParticleSystemContext& context) const { if (_separateAxes) { if (_size[0].getMode() == CurveRangeMode::CONSTANT) { updateSizePerAxis(context); @@ -26,7 +26,7 @@ void SizeOverLifetime::update(ModuleUpdateContext& context) const { } template -void SizeOverLifetime::updateUse3DSize(ModuleUpdateContext& context) const { +void SizeOverLifetime::updateUse3DSize(ParticleSystemContext& context) const { if (context.particles.getUse3DSize()) { updateSize(context); } else { @@ -35,7 +35,7 @@ void SizeOverLifetime::updateUse3DSize(ModuleUpdateContext& context) const { } template -void SizeOverLifetime::updateSize(ModuleUpdateContext& context) const { +void SizeOverLifetime::updateSize(ParticleSystemContext& context) const { ParticleVec3Array& size = context.particles.getSize(); for (uint32_t i = context.fromIndex; i < context.toIndex; i++) { float alpha{1.F}; @@ -57,7 +57,7 @@ void SizeOverLifetime::updateSize(ModuleUpdateContext& context) const { } template -void SizeOverLifetime::updateSizePerAxis(ModuleUpdateContext& context) const { +void SizeOverLifetime::updateSizePerAxis(ParticleSystemContext& context) const { ParticleVec3Array& size = context.particles.getSize(); for (uint32_t i = context.fromIndex; i < context.toIndex; i++) { Vec3 alpha; diff --git a/native/cocos/particle/modules/SizeOverLifetime.h b/native/cocos/particle/modules/SizeOverLifetime.h index 89628934f3c..4a2187e09e5 100644 --- a/native/cocos/particle/modules/SizeOverLifetime.h +++ b/native/cocos/particle/modules/SizeOverLifetime.h @@ -7,7 +7,7 @@ class SizeOverLifetime : public ParticleSystemModule { SizeOverLifetime() = default; virtual ~SizeOverLifetime() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline bool getSeparateAxes() const { return _separateAxes; @@ -31,13 +31,13 @@ class SizeOverLifetime : public ParticleSystemModule { private: template - void updateUse3DSize(ModuleUpdateContext& context) const; + void updateUse3DSize(ParticleSystemContext& context) const; template - void updateSize(ModuleUpdateContext& context) const; + void updateSize(ParticleSystemContext& context) const; template - void updateSizePerAxis(ModuleUpdateContext& context) const; + void updateSizePerAxis(ParticleSystemContext& context) const; CurveRange _size[3]{{1.F, OptimizedCurve::ZERO_TO_ONE}, {1.F, OptimizedCurve::ZERO_TO_ONE}, {1.F, OptimizedCurve::ZERO_TO_ONE}}; bool _separateAxes{false}; diff --git a/native/cocos/particle/modules/SpeedMultiplierOverLifetime.cpp b/native/cocos/particle/modules/SpeedMultiplierOverLifetime.cpp index 1b832cbc00c..5e19e47676c 100644 --- a/native/cocos/particle/modules/SpeedMultiplierOverLifetime.cpp +++ b/native/cocos/particle/modules/SpeedMultiplierOverLifetime.cpp @@ -1,7 +1,7 @@ #include "particle/modules/SpeedMultiplierOverLifetime.h" namespace cc { -void SpeedMultiplierOverLifetime::update(ModuleUpdateContext& context) const { +void SpeedMultiplierOverLifetime::update(ParticleSystemContext& context) const { if (_multiplier.getMode() == CurveRangeMode::CONSTANT) { updateMultiplier(context); } else if (_multiplier.getMode() == CurveRangeMode::CURVE) { @@ -14,7 +14,7 @@ void SpeedMultiplierOverLifetime::update(ModuleUpdateContext& context) const { } template -void SpeedMultiplierOverLifetime::updateMultiplier(ModuleUpdateContext& context) const { +void SpeedMultiplierOverLifetime::updateMultiplier(ParticleSystemContext& context) const { ParticleFloatArray& dest = context.particles.getSpeedMultiplier(); for (uint32_t i = context.fromIndex; i < context.toIndex; i++) { float alpha{1.F}; diff --git a/native/cocos/particle/modules/SpeedMultiplierOverLifetime.h b/native/cocos/particle/modules/SpeedMultiplierOverLifetime.h index 82429c72e2c..b6eee9a2c8a 100644 --- a/native/cocos/particle/modules/SpeedMultiplierOverLifetime.h +++ b/native/cocos/particle/modules/SpeedMultiplierOverLifetime.h @@ -9,7 +9,7 @@ class SpeedMultiplierOverLifetime : public ParticleSystemModule { SpeedMultiplierOverLifetime() = default; virtual ~SpeedMultiplierOverLifetime() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline CurveRange& getMultiplier() { return _multiplier; @@ -17,7 +17,7 @@ class SpeedMultiplierOverLifetime : public ParticleSystemModule { private: template - void updateMultiplier(ModuleUpdateContext& context) const; + void updateMultiplier(ParticleSystemContext& context) const; CurveRange _multiplier{1.f}; }; diff --git a/native/cocos/particle/modules/StartColor.cpp b/native/cocos/particle/modules/StartColor.cpp index 22855488b10..91e5f1155fb 100644 --- a/native/cocos/particle/modules/StartColor.cpp +++ b/native/cocos/particle/modules/StartColor.cpp @@ -2,7 +2,7 @@ #include "particle/Utils.h" namespace cc { -void StartColor::update(ModuleUpdateContext& context) const { +void StartColor::update(ParticleSystemContext& context) const { if (_color.getMode() == GradientRangeMode::COLOR) { updateGradient(context); } else if (_color.getMode() == GradientRangeMode::GRADIENT) { @@ -17,7 +17,7 @@ void StartColor::update(ModuleUpdateContext& context) const { } template -void StartColor::updateGradient(ModuleUpdateContext& context) const { +void StartColor::updateGradient(ParticleSystemContext& context) const { GradientMode maxMode = (mode == GradientRangeMode::COLOR || mode == GradientRangeMode::RANDOM_BETWEEN_TWO_COLORS) ? GradientMode::BLEND : _color.getGradient().getMode(); GradientMode minMode = (mode == GradientRangeMode::RANDOM_BETWEEN_TWO_GRADIENTS) ? _color.getMinGradient().getMode() : GradientMode::BLEND; if (maxMode == GradientMode::BLEND) { @@ -36,7 +36,7 @@ void StartColor::updateGradient(ModuleUpdateContext& context) const { } template -void StartColor::updateColor(ModuleUpdateContext& context) const { +void StartColor::updateColor(ParticleSystemContext& context) const { ParticleColorArray& baseColor = context.particles.getBaseColor(); SpawnInfo& spawnInfo = context.spawnInfos[context.spawnGroup]; for (size_t i = context.fromIndex; i < context.toIndex; i++) { diff --git a/native/cocos/particle/modules/StartColor.h b/native/cocos/particle/modules/StartColor.h index 3c2c9208ad2..28088f535f7 100644 --- a/native/cocos/particle/modules/StartColor.h +++ b/native/cocos/particle/modules/StartColor.h @@ -9,7 +9,7 @@ class StartColor : public ParticleSystemModule { StartColor() = default; virtual ~StartColor() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline GradientRange& getColor() { return _color; @@ -17,10 +17,10 @@ class StartColor : public ParticleSystemModule { private: template - void updateGradient(ModuleUpdateContext& context) const; + void updateGradient(ParticleSystemContext& context) const; template - void updateColor(ModuleUpdateContext& context) const; + void updateColor(ParticleSystemContext& context) const; GradientRange _color{}; }; diff --git a/native/cocos/particle/modules/StartLifetime.cpp b/native/cocos/particle/modules/StartLifetime.cpp index 659b5852b21..6e32f7857e9 100644 --- a/native/cocos/particle/modules/StartLifetime.cpp +++ b/native/cocos/particle/modules/StartLifetime.cpp @@ -3,7 +3,7 @@ #include namespace cc { -void StartLifetime::update(ModuleUpdateContext& context) const { +void StartLifetime::update(ParticleSystemContext& context) const { if (_lifetime.getMode() == CurveRangeMode::CONSTANT) { updateLifetime(context); } else if (_lifetime.getMode() == CurveRangeMode::CURVE) { @@ -16,7 +16,7 @@ void StartLifetime::update(ModuleUpdateContext& context) const { } template -void StartLifetime::updateLifetime(ModuleUpdateContext& context) const { +void StartLifetime::updateLifetime(ParticleSystemContext& context) const { ParticleFloatArray& invLifetime = context.particles.getInvLifetime(); SpawnInfo& spawnInfo = context.spawnInfos[context.spawnGroup]; for (uint32_t i = context.fromIndex; i < context.toIndex; i++) { diff --git a/native/cocos/particle/modules/StartLifetime.h b/native/cocos/particle/modules/StartLifetime.h index fd38536ca9a..b2f3c11d7e9 100644 --- a/native/cocos/particle/modules/StartLifetime.h +++ b/native/cocos/particle/modules/StartLifetime.h @@ -9,7 +9,7 @@ class StartLifetime : public ParticleSystemModule { StartLifetime() = default; virtual ~StartLifetime() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline CurveRange& getLifetime() { return _lifetime; @@ -17,7 +17,7 @@ class StartLifetime : public ParticleSystemModule { private: template - void updateLifetime(ModuleUpdateContext& context) const; + void updateLifetime(ParticleSystemContext& context) const; CurveRange _lifetime{5.F}; }; diff --git a/native/cocos/particle/modules/StartLifetimeByEmitterSpeed.cpp b/native/cocos/particle/modules/StartLifetimeByEmitterSpeed.cpp index 69fea268c60..97085f82e14 100644 --- a/native/cocos/particle/modules/StartLifetimeByEmitterSpeed.cpp +++ b/native/cocos/particle/modules/StartLifetimeByEmitterSpeed.cpp @@ -4,7 +4,7 @@ #include namespace cc { -void StartLifetimeByEmitterSpeed::update(ModuleUpdateContext& context) const { +void StartLifetimeByEmitterSpeed::update(ParticleSystemContext& context) const { if (_multiplier.getMode() == CurveRangeMode::CURVE) { updateLifetime(context); } else if (_multiplier.getMode() == CurveRangeMode::RANDOM_BETWEEN_TWO_CURVES) { @@ -13,7 +13,7 @@ void StartLifetimeByEmitterSpeed::update(ModuleUpdateContext& context) const { } template -void StartLifetimeByEmitterSpeed::updateLifetime(ModuleUpdateContext& context) const { +void StartLifetimeByEmitterSpeed::updateLifetime(ParticleSystemContext& context) const { ParticleFloatArray& invLifetime = context.particles.getInvLifetime(); SpawnInfo& spawnInfo = context.spawnInfos[context.spawnGroup]; Vec3 worldVelocity = spawnInfo.worldVelocity; diff --git a/native/cocos/particle/modules/StartLifetimeByEmitterSpeed.h b/native/cocos/particle/modules/StartLifetimeByEmitterSpeed.h index 6a56e473637..21d583d5c7d 100644 --- a/native/cocos/particle/modules/StartLifetimeByEmitterSpeed.h +++ b/native/cocos/particle/modules/StartLifetimeByEmitterSpeed.h @@ -8,7 +8,7 @@ class StartLifetimeByEmitterSpeed : public ParticleSystemModule { StartLifetimeByEmitterSpeed() = default; virtual ~StartLifetimeByEmitterSpeed() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline CurveRange& getMultiplier() { return _multiplier; @@ -24,7 +24,7 @@ class StartLifetimeByEmitterSpeed : public ParticleSystemModule { private: template - void updateLifetime(ModuleUpdateContext& context) const; + void updateLifetime(ParticleSystemContext& context) const; CurveRange _multiplier{1.f, OptimizedCurve::ONE_TO_ZERO}; Vec2 _speedRange{0.F, 1.F}; diff --git a/native/cocos/particle/modules/StartRotation.cpp b/native/cocos/particle/modules/StartRotation.cpp index 135d076fc8c..fc96b1b2bd2 100644 --- a/native/cocos/particle/modules/StartRotation.cpp +++ b/native/cocos/particle/modules/StartRotation.cpp @@ -2,7 +2,7 @@ #include "math/Math.h" namespace cc { -void StartRotation::update(ModuleUpdateContext& context) const { +void StartRotation::update(ParticleSystemContext& context) const { if (getSeparateAxes()) { if (_rotation[2].getMode() == CurveRangeMode::CONSTANT) { updateRotationPerAxis(context); @@ -28,7 +28,7 @@ void StartRotation::update(ModuleUpdateContext& context) const { } template -void StartRotation::updateRotation(ModuleUpdateContext& context) const { +void StartRotation::updateRotation(ParticleSystemContext& context) const { ParticleVec3Array& rotation = context.particles.getRotation(); SpawnInfo& spawnInfo = context.spawnInfos[context.spawnGroup]; for (uint32_t i = context.fromIndex; i < context.toIndex; i++) { @@ -47,7 +47,7 @@ void StartRotation::updateRotation(ModuleUpdateContext& context) const { } template -void StartRotation::updateRotationPerAxis(ModuleUpdateContext& context) const { +void StartRotation::updateRotationPerAxis(ParticleSystemContext& context) const { ParticleVec3Array& rotation = context.particles.getRotation(); SpawnInfo& spawnInfo = context.spawnInfos[context.spawnGroup]; for (uint32_t i = context.fromIndex; i < context.toIndex; i++) { diff --git a/native/cocos/particle/modules/StartRotation.h b/native/cocos/particle/modules/StartRotation.h index 86ead5723cb..ffdcb62db1d 100644 --- a/native/cocos/particle/modules/StartRotation.h +++ b/native/cocos/particle/modules/StartRotation.h @@ -8,7 +8,7 @@ class StartRotation : public ParticleSystemModule { StartRotation() = default; virtual ~StartRotation() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline bool getSeparateAxes() const { return _separateAxes; @@ -32,10 +32,10 @@ class StartRotation : public ParticleSystemModule { private: template - void updateRotation(ModuleUpdateContext& context) const; + void updateRotation(ParticleSystemContext& context) const; template - void updateRotationPerAxis(ModuleUpdateContext& context) const; + void updateRotationPerAxis(ParticleSystemContext& context) const; CurveRange _rotation[3]{0.F, 0.F, 0.F}; bool _separateAxes{false}; diff --git a/native/cocos/particle/modules/StartSize.cpp b/native/cocos/particle/modules/StartSize.cpp index 77056e2d634..ae77199907a 100644 --- a/native/cocos/particle/modules/StartSize.cpp +++ b/native/cocos/particle/modules/StartSize.cpp @@ -1,7 +1,7 @@ #include "particle/modules/StartSize.h" namespace cc { -void StartSize::update(ModuleUpdateContext& context) const { +void StartSize::update(ParticleSystemContext& context) const { if (getSeparateAxes()) { if (_size[0].getMode() == CurveRangeMode::CONSTANT) { updateSizePerAxis(context); @@ -26,7 +26,7 @@ void StartSize::update(ModuleUpdateContext& context) const { } template -void StartSize::updateUse3DSize(ModuleUpdateContext& context) const { +void StartSize::updateUse3DSize(ParticleSystemContext& context) const { if (context.particles.getUse3DSize()) { updateSize(context); } else { @@ -35,7 +35,7 @@ void StartSize::updateUse3DSize(ModuleUpdateContext& context) const { } template -void StartSize::updateSize(ModuleUpdateContext& context) const { +void StartSize::updateSize(ParticleSystemContext& context) const { ParticleVec3Array& baseSize = context.particles.getBaseSize(); SpawnInfo& spawnInfo = context.spawnInfos[context.spawnGroup]; for (uint32_t i = context.fromIndex; i < context.toIndex; i++) { @@ -58,7 +58,7 @@ void StartSize::updateSize(ModuleUpdateContext& context) const { } template -void StartSize::updateSizePerAxis(ModuleUpdateContext& context) const { +void StartSize::updateSizePerAxis(ParticleSystemContext& context) const { ParticleVec3Array& baseSize = context.particles.getBaseSize(); SpawnInfo& spawnInfo = context.spawnInfos[context.spawnGroup]; for (uint32_t i = context.fromIndex; i < context.toIndex; i++) { diff --git a/native/cocos/particle/modules/StartSize.h b/native/cocos/particle/modules/StartSize.h index 6b0e43ca301..f779270d461 100644 --- a/native/cocos/particle/modules/StartSize.h +++ b/native/cocos/particle/modules/StartSize.h @@ -8,7 +8,7 @@ class StartSize : public ParticleSystemModule { StartSize() = default; virtual ~StartSize() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline bool getSeparateAxes() const { return _separateAxes; @@ -32,13 +32,13 @@ class StartSize : public ParticleSystemModule { private: template - void updateSize(ModuleUpdateContext& context) const; + void updateSize(ParticleSystemContext& context) const; template - void updateUse3DSize(ModuleUpdateContext& context) const; + void updateUse3DSize(ParticleSystemContext& context) const; template - void updateSizePerAxis(ModuleUpdateContext& context) const; + void updateSizePerAxis(ParticleSystemContext& context) const; CurveRange _size[3]{1.F, 1.F, 1.F}; bool _separateAxes{false}; diff --git a/native/cocos/particle/modules/StartSpeed.cpp b/native/cocos/particle/modules/StartSpeed.cpp index de4593982dd..37e17b5af83 100644 --- a/native/cocos/particle/modules/StartSpeed.cpp +++ b/native/cocos/particle/modules/StartSpeed.cpp @@ -1,7 +1,7 @@ #include "particle/modules/StartSpeed.h" namespace cc { -void StartSpeed::update(ModuleUpdateContext& context) const { +void StartSpeed::update(ParticleSystemContext& context) const { if (_speed.getMode() == CurveRangeMode::CONSTANT) { updateBaseVelocity(context); } else if (_speed.getMode() == CurveRangeMode::CURVE) { @@ -14,7 +14,7 @@ void StartSpeed::update(ModuleUpdateContext& context) const { } template -void StartSpeed::updateBaseVelocity(ModuleUpdateContext& context) const { +void StartSpeed::updateBaseVelocity(ParticleSystemContext& context) const { ParticleVec3Array& baseVelocity = context.particles.getBaseVelocity(); ParticleVec3Array& direction = context.particles.getDirection(); SpawnInfo& spawnInfo = context.spawnInfos[context.spawnGroup]; diff --git a/native/cocos/particle/modules/StartSpeed.h b/native/cocos/particle/modules/StartSpeed.h index aba0e0dff15..22a10ba5bf4 100644 --- a/native/cocos/particle/modules/StartSpeed.h +++ b/native/cocos/particle/modules/StartSpeed.h @@ -8,7 +8,7 @@ class StartSpeed : public ParticleSystemModule { StartSpeed() = default; virtual ~StartSpeed() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; inline CurveRange& getSpeed() { return _speed; @@ -16,7 +16,7 @@ class StartSpeed : public ParticleSystemModule { private: template - void updateBaseVelocity(ModuleUpdateContext& context) const; + void updateBaseVelocity(ParticleSystemContext& context) const; CurveRange _speed{5.F}; }; diff --git a/native/cocos/particle/modules/Trail.h b/native/cocos/particle/modules/Trail.h index f81e5c43370..05c65b57676 100644 --- a/native/cocos/particle/modules/Trail.h +++ b/native/cocos/particle/modules/Trail.h @@ -8,6 +8,6 @@ class Trail : public ParticleSystemModule { Trail() = default; virtual ~Trail() override = default; - virtual void update(ModuleUpdateContext& context) const override; + virtual void update(ParticleSystemContext& context) const override; }; }