Skip to content

Commit

Permalink
impl more modules
Browse files Browse the repository at this point in the history
  • Loading branch information
SantyWang committed Oct 11, 2023
1 parent c5816ca commit 6e58f98
Show file tree
Hide file tree
Showing 32 changed files with 1,315 additions and 818 deletions.
81 changes: 80 additions & 1 deletion cocos/particle/Impl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CustomDataMode, BoxShapeEmitFrom, PlaybackState, NoiseQuality, ConeShapeEmitFrom, CoordinateSpace, CurveRangeMode, GradientRangeMode } from './define';
import { CustomDataMode, BoxShapeEmitFrom, PlaybackState, NoiseQuality, ConeShapeEmitFrom, CoordinateSpace, CurveRangeMode, GradientRangeMode, AnimationMode, TimeMode, RowMode, TextureMode, ScalingMode } from './define';

export declare namespace Impl {
export class ParticleSystem {
Expand All @@ -12,6 +12,17 @@ export declare namespace Impl {
getTime(): number;
getTotalTime(): number;
dispose(): void;
setDuration(duration: number): void;
setLooping(looping: boolean): void;
setPrewarm(prewarm: boolean): void;
getDelay(): CurveRange;
setFlipRotation(flipRotation: number): void;
setSimulationSpace(space: CoordinateSpace): void;
setSimulationSpeed(speed: number): void;
setScalingMode(mode: ScalingMode): void;
setCapacity(capacity: number): void;
setAutoRandomSeed(autoRandomSeed: boolean): void;
setRandomSeed(seed: number): void;
}

export class ParticleSystemManager {
Expand Down Expand Up @@ -255,6 +266,74 @@ export declare namespace Impl {
export class SpeedMultiplierOverLifetime extends ParticleSystemModule {
getMultiplier(): CurveRange;
}

export class SphereShape extends DistributableShape {
setRadius(radius: number): void;
setRadiusThickness(radiusThickness: number): void;
setArc(arc: number): void;
setIsHemisphere(isHemisphere: boolean): void;
}

export class StartColor extends ParticleSystemModule {
getColor(): GradientRange;
}

export class StartLifetime extends ParticleSystemModule {
getLifetime(): CurveRange;
}

export class StartLifetimeByEmitterSpeed extends ParticleSystemModule {
getMultiplier(): CurveRange;
setSpeedRange(min: number, max: number): void;
}

export class StartRotation extends ParticleSystemModule {
setSeparateAxes(separateAxes: boolean): void;
getRotationX(): CurveRange;
getRotationY(): CurveRange;
getRotationZ(): CurveRange;
}

export class StartSize extends ParticleSystemModule {
setSeparateAxes(separateAxes: boolean): void;
getSizeX(): CurveRange;
getSizeY(): CurveRange;
getSizeZ(): CurveRange;
}

export class StartSpeed extends ParticleSystemModule {
getSpeed(): CurveRange;
}

export class TextureSheetAnimation extends ParticleSystemModule {
getFrameOverTime(): CurveRange;
getStartFrame(): CurveRange;
setSpeedRange(min: number, max: number): void;
setFPS(fps: number): void;
setCycles(cycles: number): void;
setTilesX(tilesX: number): void;
setTilesY(tilesY: number): void;
setAnimation(mode: AnimationMode): void;
setTimeMode(mode: TimeMode): void;
setRowMode(mode: RowMode): void;
setRow(index: number): void;
}

export class Trail extends ParticleSystemModule {
getLifetime(): CurveRange;
getWidthOverTrail(): CurveRange;
getColorOverLifetime(): GradientRange;
getColorOverTrail(): GradientRange;
setProbability(probability: number): void;
setMinimumVertexDistance(minimumVertexDistance: number): void;
setDieWithParticles(dieWithParticles: boolean): void;
setSizeAffectsLifetime(sizeAffectsLifetime: boolean): void;
setSizeAffectsWidth(sizeAffectsWidth: boolean): void;
setInheritParticleColor(inheritParticleColor: boolean): void;
setSpace(space: CoordinateSpace): void;
setTextureMode(textureMode: TextureMode): void;
}

}

export class Impl {
Expand Down
3 changes: 2 additions & 1 deletion cocos/particle/curve-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
THE SOFTWARE.
*/

import { ccclass } from 'cc.decorator';
import { lerp, RealCurve, CCClass, geometry, Enum, RealInterpolationMode, ExtrapolationMode, EPSILON, ValueType } from '../core';
import { assertIsTrue, EasingMethod, setPropertyEnumType } from '../core/internal-index';
import { CurveRangeMode } from './define';
Expand Down Expand Up @@ -385,3 +384,5 @@ export const ZERO_TO_ONE = new RealCurve();
ZERO_TO_ONE.assignSorted([0, 1], [0, 1]);
export const NEGATIVE_ONE_TO_ONE = new RealCurve();
NEGATIVE_ONE_TO_ONE.assignSorted([0, 1], [-1, 1]);
export const ONE_TO_ZERO = new RealCurve();
ONE_TO_ZERO.assignSorted([0, 1], [1, 0]);
46 changes: 40 additions & 6 deletions cocos/particle/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ export enum CurveRangeMode {
* @zh 粒子的剔除模式。
* @enum ParticleSystem.CullingMode
*/
export const CullingMode = Enum({
Pause: 0,
PauseAndCatchup: 1,
AlwaysSimulate: 2,
});
export enum CullingMode {
PAUSE,
PAUSE_AND_CATCH_UP,
ALWAYS_SIMULATE
}

/**
* @en Particle emitter alignment space
Expand All @@ -159,7 +159,7 @@ export const AlignmentSpace = Enum({
View: 2,
});

enum RenderMode {
export enum RenderMode {
BILLBOARD,
STRETCHED_BILLBOARD,
HORIZONTAL_BILLBOARD,
Expand All @@ -175,6 +175,40 @@ export enum TextureMode {
REPEAT_PER_SEGMENT,
}

/**
* @en Mode to play texture animation.
* @zh 贴图动画的播放方式。
*/
export enum AnimationMode {
/**
* @en Play whole sheet of texture.
* @zh 播放贴图中的所有帧。
*/
WHOLE_SHEET,
/**
* @en Play just one row of texture.
* @zh 播放贴图中的其中一行动画。
*/
SINGLE_ROW
}

export enum TimeMode {
LIFETIME,
SPEED,
FPS
}

export enum RowMode {
CUSTOM,
RANDOM,
}

export enum ScalingMode {
HIERARCHY,
LOCAL,
SHAPE,
}

export const meshPosition = new Attribute(AttributeName.ATTR_POSITION, Format.RGB32F, false, 0); // mesh position
export const meshUv = new Attribute(AttributeName.ATTR_TEX_COORD, Format.RGB32F, false, 0); // mesh uv
export const meshNormal = new Attribute(AttributeName.ATTR_NORMAL, Format.RGB32F, false, 0); // mesh normal
Expand Down
30 changes: 15 additions & 15 deletions cocos/particle/dynamic-buffer-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import { js, System } from '../core';
import { Director, director } from '../game/director';

export class SharedDynamicBuffer {
get buffer () {
get buffer (): Buffer {
return this._buffer;
}

get floatDataView () {
get floatDataView (): Float32Array {
return this._floatDataView;
}

get uint32DataView () {
get uint32DataView (): Uint32Array {
return this._uint32DataView;
}

get uint16DataView () {
get uint16DataView (): Uint16Array {
return this._uint16DataView;
}

get usedCount () {
get usedCount (): number {
return this._usedCount;
}

Expand All @@ -31,7 +31,7 @@ export class SharedDynamicBuffer {
this._dirty = true;
}

get capacity () {
get capacity (): number {
return this._capacity;
}

Expand Down Expand Up @@ -64,7 +64,7 @@ export class SharedDynamicBuffer {
this._uint16DataView = new Uint16Array(data);
}

private reserve (count: number) {
private reserve (count: number): void {
if (count <= this._capacity) { return; }
let newCapacity = this._capacity;
while (count > newCapacity) {
Expand All @@ -81,18 +81,18 @@ export class SharedDynamicBuffer {
this._floatDataView.set(oldFloatDataView);
}

update () {
update (): void {
if (this._dirty) {
this._buffer.update(this._data);
this._dirty = false;
}
}

reset () {
reset (): void {
this._usedCount = 0;
}

destroy () {
destroy (): void {
this._buffer.destroy();
}
}
Expand All @@ -102,11 +102,11 @@ export class DynamicBufferManager extends System {
return this._sharedSpriteVertexBufferAttributes;
}

get sharedSpriteVertexCount () {
get sharedSpriteVertexCount (): number {
return this._sharedSpriteVertexCount;
}

get sharedSpriteIndexCount () {
get sharedSpriteIndexCount (): number {
return this._sharedSpriteIndexCount;
}

Expand Down Expand Up @@ -170,14 +170,14 @@ export class DynamicBufferManager extends System {
return this._sharedSpriteIndexBuffer;
}

getOrCreateDynamicBuffer (hash: string, streamSize: number, bufferUsageBit: BufferUsageBit) {
getOrCreateDynamicBuffer (hash: string, streamSize: number, bufferUsageBit: BufferUsageBit): SharedDynamicBuffer {
if (!this._sharedDynamicBufferMap[hash]) {
this._sharedDynamicBufferMap[hash] = new VFXDynamicBuffer(
this._sharedDynamicBufferMap[hash] = new SharedDynamicBuffer(
deviceManager.gfxDevice,
streamSize,
bufferUsageBit,
);
}
return this._sharedDynamicBufferMap[hash];
}
}
}
1 change: 1 addition & 0 deletions cocos/particle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { ParticleUtils } from './particle-utils';
import { CurveRange } from './curve-range';
import { GradientRange } from './gradient-range';
import './particle-system-manager';
import './dynamic-buffer-manager';

export * from './modules';
export * from './particle-system-renderer';
Expand Down
2 changes: 1 addition & 1 deletion cocos/particle/modules/curl-noise-over-lifetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class CurlNoiseOverLifetime extends ParticleSystemModule {
return this._octaveScale;
}
public set octaveScale (value: number) {
this._octaveScale = value;
this._octaveScale = clamp(value, 1, 4);
this.impl?.setOctaveScale(this._octaveScale);
}

Expand Down
6 changes: 6 additions & 0 deletions cocos/particle/modules/dampen-over-lifetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export class DampenOverLifetime extends ParticleSystemModule {

public set speedX (val: Readonly<CurveRange>) {
this._speedX.set(val);
this._speedX.scalar = Math.max(this._speedX.scalar, 0);
this._speedX.minScalar = Math.max(this._speedX.minScalar, 0);
if (this.impl) {
this._speedX.copyToLowLevelCurveRange(this.impl.getSpeedX());
}
Expand All @@ -93,6 +95,8 @@ export class DampenOverLifetime extends ParticleSystemModule {

public set speedY (val: Readonly<CurveRange>) {
this._speedY.set(val);
this._speedY.scalar = Math.max(this._speedY.scalar, 0);
this._speedY.minScalar = Math.max(this._speedY.minScalar, 0);
if (this.impl) {
this._speedY.copyToLowLevelCurveRange(this.impl.getSpeedY());
}
Expand All @@ -114,6 +118,8 @@ export class DampenOverLifetime extends ParticleSystemModule {

public set speedZ (val: Readonly<CurveRange>) {
this._speedZ.set(val);
this._speedZ.scalar = Math.max(this._speedZ.scalar, 0);
this._speedZ.minScalar = Math.max(this._speedZ.minScalar, 0);
if (this.impl) {
this._speedZ.copyToLowLevelCurveRange(this.impl.getSpeedZ());
}
Expand Down
2 changes: 2 additions & 0 deletions cocos/particle/modules/drag-over-lifetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export class DragOverLifetime extends ParticleSystemModule {

public set drag (val: Readonly<CurveRange>) {
this._drag.set(val);
this._drag.scalar = Math.max(this._drag.scalar, 0);
this._drag.minScalar = Math.max(this._drag.minScalar, 0);
if (this.impl) {
this._drag.copyToLowLevelCurveRange(this.impl.getDrag());
}
Expand Down
2 changes: 2 additions & 0 deletions cocos/particle/modules/emission-by-burst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export class Burst {

public set count (val: Readonly<CurveRange>) {
this._count.set(val);
this._count.scalar = Math.max(this._count.scalar, 0) | 0;
this._count.minScalar = Math.max(this._count.minScalar, 0) | 0;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions cocos/particle/modules/emission-over-distance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export class EmissionOverDistance extends ParticleSystemModule {

public set rate (val: Readonly<CurveRange>) {
this._rate.set(val);
this._rate.scalar = Math.max(this._rate.scalar, 0);
this._rate.minScalar = Math.max(this._rate.minScalar, 0);
if (this.impl) {
this._rate.copyToLowLevelCurveRange(this.impl.getRate());
}
Expand Down
2 changes: 2 additions & 0 deletions cocos/particle/modules/emission-over-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export class EmissionOverTime extends ParticleSystemModule {

public set rate (val: Readonly<CurveRange>) {
this._rate.set(val);
this._rate.scalar = Math.max(this._rate.scalar, 0);
this._rate.minScalar = Math.max(this._rate.minScalar, 0);
if (this.impl) {
this._rate.copyToLowLevelCurveRange(this.impl.getRate());
}
Expand Down
4 changes: 4 additions & 0 deletions cocos/particle/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ export * from './shape';
export * from './distributable-shape';
export * from './inherit-start-velocity';
export * from './inherit-velocity-over-lifetime';
export * from './sphere-shape';
export * from './start-color';
export * from './start-lifetime-by-emitter-speed';
export * from './start-lifetime';
export * from './start-rotation';
export * from './start-size';
export * from './start-speed';
export * from './texture-sheet-animation';
export * from './trail';
Loading

0 comments on commit 6e58f98

Please sign in to comment.