Skip to content

Commit

Permalink
add more modules
Browse files Browse the repository at this point in the history
  • Loading branch information
SantyWang committed Oct 8, 2023
1 parent 50419bb commit 34f5474
Show file tree
Hide file tree
Showing 21 changed files with 213 additions and 546 deletions.
11 changes: 7 additions & 4 deletions cocos/particle/Impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ export declare namespace Impl {
setEmitFrom(emitFrom: BoxShapeEmitFrom): void;
}

export class CircleShape extends Shape {
export class DistributableShape extends Shape {
setSpread(spread: number): void;
getSpeed(): CurveRange;
setMode(mode: number): void;
}

export class CircleShape extends DistributableShape {
setRadius(radius: number): void;
setRadiusThickness(radius: number): void;
setArc(arc: number): void;
setSpread(spread: number): void;
getSpeed(): CurveRange;
setMode(arcMode: ArcMode): void;
}

export class ColorBySpeed extends ParticleSystemModule {
Expand Down
2 changes: 1 addition & 1 deletion cocos/particle/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export enum PlaybackState {
* @en The way the particles are spawned along the arc.
* @zh 粒子沿着弧的发射方式。
*/
export enum ArcMode {
export enum DistributionMode {
/**
* @en Spawning particles at random arc.
* @zh 在随机弧度生成粒子。
Expand Down
62 changes: 59 additions & 3 deletions cocos/particle/modules/distributable-shape.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,66 @@
import { CurveRange } from '../../../typedoc-index';
import { ccclass } from '../../core/data/class-decorator';
import { Enum } from '../../core';
import { ccclass, serializable, tooltip, type } from '../../core/data/class-decorator';
import { CurveRange } from '../curve-range';
import { DistributionMode } from '../define';
import { Impl } from '../impl';
import { Shape } from './shape';

@ccclass('cc.DistributableShape')
export abstract class DistributableShape extends Shape {

Check failure on line 9 in cocos/particle/modules/distributable-shape.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Block must not be padded by blank lines


Check failure on line 11 in cocos/particle/modules/distributable-shape.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Trailing spaces not allowed

Check failure on line 11 in cocos/particle/modules/distributable-shape.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

More than 1 blank line not allowed
@type(Enum(DistributionMode))
@tooltip('i18n:ParticleSystem.DistributableShape.mode')
public get mode (): DistributionMode {
return this._mode;
}

public set mode (mode: DistributionMode) {
this._mode = mode;
this.impl?.setMode(mode);
}

@type(CurveRange)
@tooltip('i18n:ParticleSystem.DistributableShape.speed')
public get speed (): Readonly<CurveRange> {
return this._speed;
}

Check failure on line 28 in cocos/particle/modules/distributable-shape.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Trailing spaces not allowed
public set speed (speed: Readonly<CurveRange>) {
this._speed.set(speed);
if (this.impl) {
this._speed.copyToLowLevelCurveRange(this.impl.getSpeed());
}
}

@tooltip('i18n:ParticleSystem.DistributableShape.spread')
public get spread (): number {
return this._spread;
}

public set spread (spread: number) {
this._spread = spread;
this.impl?.setSpread(spread);
}


Check failure on line 46 in cocos/particle/modules/distributable-shape.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

More than 1 blank line not allowed
public get impl (): Impl.DistributableShape | null {

Check failure on line 47 in cocos/particle/modules/distributable-shape.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'any' overrides all other types in this union type
return this._impl as Impl.DistributableShape | null;

Check failure on line 48 in cocos/particle/modules/distributable-shape.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe return of an `any` typed value

Check failure on line 48 in cocos/particle/modules/distributable-shape.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 48 in cocos/particle/modules/distributable-shape.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'any' overrides all other types in this union type
}

@serializable
private _spread = 0;
@serializable
private _speed = new CurveRange(1);
private _mode = Dis;
@serializable
private _mode = DistributionMode.RANDOM;

public initialize (): void {
super.initialize();
if (this.impl) {
this.impl.setSpread(this._spread);
this.impl.setMode(this._mode);
this._speed.copyToLowLevelCurveRange(this.impl.getSpeed());
}
}
}
7 changes: 0 additions & 7 deletions native/cocos/particle/Define.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ enum class NoiseQuality : uint8_t {
LOW
};

enum class NoiseAlgorithm : uint8_t {
VALUE,
PERLIN,
SIMPLEX_VALUE,
SIMPLEX,
};

enum class CurveRangeMode: uint8_t {
CONSTANT,
CURVE,
Expand Down
7 changes: 0 additions & 7 deletions native/cocos/particle/ParticleSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@
#include "particle/modules/SizeOverLifetime.h"
#include "particle/modules/TextureSheetAnimation.h"
#include "particle/modules/LegacyTrail.h"
#include "particle/modules/EventByDeath.h"
#include "particle/modules/EventOverLifetime.h"
#include "particle/modules/Renderer.h"
#include "particle/modules/EmissionByEvent.h"

namespace cc {

Expand Down Expand Up @@ -97,13 +94,11 @@ class ParticleSystem {
Emitter _emitter{};
Particles _particles{};
std::vector<SpawnInfo> _spawnInfos{};
std::unordered_map<std::string, std::vector<EventInfo>> _eventInfos{};

// Emission modules
EmissionOverTime* _emissionOverTime{nullptr};
EmissionOverDistance* _emissionOverDistance{nullptr};
EmissionByBurst* _emissionByBurst{nullptr};
EmissionByEvent* _emissionByEvent{nullptr};

// Particle Initialization modules
StartLifetime* _startLifetime{nullptr};
Expand Down Expand Up @@ -135,8 +130,6 @@ class ParticleSystem {
TextureSheetAnimation* _textureSheetAnimation{nullptr};
CustomData* _customData{nullptr};
LegacyTrail* _legacyTrail{nullptr};
EventByDeath* _eventByDeath{nullptr};
EventOverLifetime* _eventOverLifetime{nullptr};

// Renderer
Renderer* _renderer{nullptr};
Expand Down
23 changes: 2 additions & 21 deletions native/cocos/particle/ParticleSystemModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,16 @@ struct SpawnInfo {
float interpStart{0.F};
float interpStartNormalizedT{0.F};
uint32_t count{0};
// initial lifetime
float initialLifetime{1.F};
// initial color
Color initialColor{Color::WHITE};
// initial size
Vec3 initialSize{Vec3::ONE};
// initial rotation
Vec3 initialRotation{Vec3::ZERO};
// initial transform in the simulation space
Mat4 initialTransform{};
// Velocity of the emitter in world space in this spawning.
Vec3 worldVelocity{Vec3::ZERO};
// Velocity of the emitter in simulation space in this spawning.
Vec3 simulationVelocity{Vec3::ZERO};
};

struct EventInfo {

};

struct ParticleSystemContext {
explicit ParticleSystemContext(Particles& particles, Emitter& emitter, std::vector<SpawnInfo>& spawnInfos, std::unordered_map<std::string, std::vector<EventInfo>>& eventInfos, float deltaTime) : particles(particles),
emitter(emitter), spawnInfos(spawnInfos), eventInfos(eventInfos), deltaTime(deltaTime) {}
explicit ParticleSystemContext(Particles& particles, Emitter& emitter, std::vector<SpawnInfo>& spawnInfos, float deltaTime) : particles(particles),
emitter(emitter), spawnInfos(spawnInfos), deltaTime(deltaTime) {}

~ParticleSystemContext() = default;
Particles& particles;
Emitter& emitter;
std::vector<SpawnInfo>& spawnInfos;
std::unordered_map<std::string, std::vector<EventInfo>>& eventInfos;
size_t fromIndex{0};
size_t toIndex{0};
int32_t spawnGroup{-1};
Expand Down
6 changes: 3 additions & 3 deletions native/cocos/particle/modules/BoxShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ void BoxShape::updateHasDirection(ParticleSystemContext& context) const {
case EmitFrom::SHELL:
updateShape<hasDirection, EmitFrom::SHELL>(context);
break;
case EmitFrom::EGDE:
updateShape<hasDirection, EmitFrom::EGDE>(context);
case EmitFrom::EDGE:
updateShape<hasDirection, EmitFrom::EDGE>(context);
break;
default:
break;
Expand All @@ -38,7 +38,7 @@ void BoxShape::updateShape(ParticleSystemContext& context) const {
for (size_t i = context.fromIndex; i < context.toIndex; i++) {
Vec3 r = Rand(context.emitter.randomSeed, context.particles.getId().load(i), 0xba7281).randomVec3();

if constexpr (emitFrom == EmitFrom::SHELL || emitFrom == EmitFrom::EGDE) {
if constexpr (emitFrom == EmitFrom::SHELL || emitFrom == EmitFrom::EDGE) {
int32_t face = Rand(context.emitter.randomSeed, context.particles.getId().load(i), 0x26bfc).randomRangedInt(0, 3);

if constexpr (emitFrom == EmitFrom::SHELL) {
Expand Down
2 changes: 1 addition & 1 deletion native/cocos/particle/modules/BoxShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class BoxShape : public Shape {
enum class EmitFrom : uint8_t {
VOLUME,
SHELL,
EGDE
EDGE
};

BoxShape() = default;
Expand Down
2 changes: 1 addition & 1 deletion native/cocos/particle/modules/ColorBySpeed.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ColorBySpeed.h"
#include "particle/modules/ColorBySpeed.h"
#include "math/Utils.h"
#include "particle/Utils.h"

Expand Down
2 changes: 1 addition & 1 deletion native/cocos/particle/modules/ColorOverLifetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ColorOverLifetime : public ParticleSystemModule {

private:

template <GradientRangeMode rangeMode>
template <GradientRangeMode mode>
void updateColor(ParticleSystemContext& context) const;

GradientRange _color{};
Expand Down
Loading

0 comments on commit 34f5474

Please sign in to comment.