Skip to content

Commit

Permalink
add ts module
Browse files Browse the repository at this point in the history
  • Loading branch information
SantyWang committed Oct 9, 2023
1 parent 19bd756 commit 0fae20f
Show file tree
Hide file tree
Showing 37 changed files with 932 additions and 249 deletions.
31 changes: 30 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 } from './define';
import { CustomDataMode, BoxShapeEmitFrom, PlaybackState, NoiseQuality, ConeShapeEmitFrom } from './define';

export declare namespace Impl {
export class ParticleSystem {
Expand Down Expand Up @@ -91,13 +91,42 @@ export declare namespace Impl {
getColor(): GradientRange;
}

export class ConeShape extends DistributableShape {
setRadius(radius: number): void;
setAngle(angle: number): void;
setArc(arc: number): void;
setLength(length: number): void;
setEmitFrom(emitFrom: ConeShapeEmitFrom): void;
}

export class CustomData extends ParticleSystemModule {
getComponent(stream: number, component: number): CurveRange;
getColor(stream: number): GradientRange;
setMode(stream: number, mode: CustomDataMode);
setComponentNum(stream: number, num: number);
}

export class CurlNoiseOverLifetime extends ParticleSystemModule {
setSeparateAxes(separateAxes: boolean): void;
getStrengthX(): CurveRange;
getStrengthY(): CurveRange;
getStrengthZ(): CurveRange;
getScrollSpeed(): CurveRange;
getRemapCurveX(): CurveRange;
getRemapCurveY(): CurveRange;
getRemapCurveZ(): CurveRange;
setOctaves(octave: number): void;
setOctaveMultiplier(octaveMultiplier: number): void;
setOctaveScale(octaveScale: number): void;
setFrequency(frequency: number): void;
setDamping(damping: boolean): void;
setRemap(remap: boolean): void;
setQuality(quality: NoiseQuality): void;
getPositionAmount(): CurveRange;
getRotationAmount(): CurveRange;
getSizeAmount(): CurveRange;
}

export class DragOverLifetime extends ParticleSystemModule {
getDrag(): CurveRange;
setMultiplyBySize(multiplyBySize: boolean): void;
Expand Down
11 changes: 11 additions & 0 deletions cocos/particle/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ export enum PlaybackState {
STOPPED,
}

export enum NoiseQuality {
HIGH,
MEDIUM,
LOW
}

export enum ConeShapeEmitFrom {
BASE,
VOLUME,
}

/**
* @en The way the particles are spawned along the arc.
* @zh 粒子沿着弧的发射方式。
Expand Down
4 changes: 2 additions & 2 deletions cocos/particle/dynamic-buffer-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { meshPosition, meshUv } from './define';
import { js, System } from '../core';
import { Director, director } from '../game/director';

export class VFXDynamicBuffer {
export class SharedDynamicBuffer {
get buffer () {
return this._buffer;
}
Expand Down Expand Up @@ -115,7 +115,7 @@ export class DynamicBufferManager extends System {
private _sharedSpriteIndexBuffer: Buffer | null = null;
private _sharedSpriteVertexCount = 4;
private _sharedSpriteIndexCount = 6;
private _sharedDynamicBufferMap: Record<string, VFXDynamicBuffer> = {};
private _sharedDynamicBufferMap: Record<string, SharedDynamicBuffer> = {};

init (): void {
director.on(Director.EVENT_UPLOAD_DYNAMIC_VBO, this.updateBuffer);
Expand Down
4 changes: 2 additions & 2 deletions cocos/particle/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import { Material, Texture2D } from '../asset/assets';
import { Vec3, cclegacy, Vec4, Vec2, CCBoolean } from '../core';
import { LineModel } from './models/line-model';
import { builtinResMgr } from '../asset/asset-manager';
import CurveRange from './animator/curve-range';
import GradientRange from './animator/gradient-range';
import { CurveRange } from './curve-range';
import { GradientRange } from './gradient-range';
import { ModelRenderer } from '../misc';

const CC_USE_WORLD_SPACE = 'CC_USE_WORLD_SPACE';
Expand Down
4 changes: 2 additions & 2 deletions cocos/particle/models/line-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import { DRAW_INFO_SIZE, Buffer, Attribute, BufferInfo, DrawInfo,
AttributeName, BufferUsageBit, Format, FormatInfos, MemoryUsageBit, PrimitiveMode } from '../../gfx';
import { Vec3 } from '../../core';
import { scene } from '../../render-scene';
import CurveRange from '../animator/curve-range';
import GradientRange from '../animator/gradient-range';
import { CurveRange } from '../curve-range';
import { GradientRange } from '../gradient-range';
import { Material } from '../../asset/assets';

const _vertex_attrs = [
Expand Down
3 changes: 2 additions & 1 deletion cocos/particle/modules/box-shape.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Enum } from '../../core';
import { ccclass, tooltip, type } from '../../core/data/class-decorator';
import { ccclass, serializable, tooltip, type } from '../../core/data/class-decorator';
import { BoxShapeEmitFrom } from '../define';
import { Impl } from '../impl';

Check failure on line 4 in cocos/particle/modules/box-shape.ts

View workflow job for this annotation

GitHub Actions / npm_test

Cannot find module '../impl' or its corresponding type declarations.
import { Shape } from './shape';
Expand Down Expand Up @@ -28,6 +28,7 @@ export class BoxShape extends Shape {
return this._impl as Impl.BoxShape | null;

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

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe return of an `any` typed value

Check failure on line 28 in cocos/particle/modules/box-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 28 in cocos/particle/modules/box-shape.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

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

@serializable
private _emitFrom: BoxShapeEmitFrom = BoxShapeEmitFrom.VOLUME;

/**
Expand Down
56 changes: 53 additions & 3 deletions cocos/particle/modules/circle-shape.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,71 @@
import { ccclass } from '../../core/data/class-decorator';
import { CCFloat, clamp, clamp01 } from '../../core';
import { ccclass, range, rangeStep, serializable, tooltip, type } from '../../core/data/class-decorator';
import { rangeMin } from '../../core/data/decorators';
import { Impl } from '../impl';

Check failure on line 4 in cocos/particle/modules/circle-shape.ts

View workflow job for this annotation

GitHub Actions / npm_test

Cannot find module '../impl' or its corresponding type declarations.
import { Shape } from './shape';
import { DistributableShape } from './distributable-shape';

@ccclass('cc.CircleShape')
export class CircleShape extends Shape {
export class CircleShape extends DistributableShape {
@type(CCFloat)
@tooltip('i18n:ParticleSystem.CircleShape.radius')
@rangeMin(0.0001)
public get radius (): number {
return this._radius;
}

public set radius (radius: number) {
this._radius = Math.max(radius, 0.0001);
this.impl?.setRadius(this._radius);
}

@type(CCFloat)
@tooltip('i18n:ParticleSystem.CircleShape.radiusThickness')
@range([0, 1])
public get radiusThickness (): number {
return this._radiusThickness;
}

public set radiusThickness (radiusThickness: number) {
this._radiusThickness = clamp01(radiusThickness);
this.impl?.setRadiusThickness(this._radiusThickness);
}

@type(CCFloat)
@tooltip('i18n:ParticleSystem.CircleShape.arc')
@range([0, 360])
public get arc (): number {
return this._arc;
}

public set arc (arc: number) {
this._arc = clamp(arc, 0, 360);
this.impl?.setArc(this._arc);
}

/**
* @engineInternal
*/
public get impl (): Impl.CircleShape | null {

Check failure on line 48 in cocos/particle/modules/circle-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.CircleShape | null;

Check failure on line 49 in cocos/particle/modules/circle-shape.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe return of an `any` typed value

Check failure on line 49 in cocos/particle/modules/circle-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
}

@serializable
private _radius = 1;
@serializable
private _radiusThickness = 1;
@serializable
private _arc = 360;

/**
* @engineInternal
*/
public initialize (): void {
super.initialize();
if (this.impl) {
this.impl.setRadius(this._radius);
this.impl.setRadiusThickness(this._radiusThickness);
this.impl.setArc(this._arc);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion cocos/particle/modules/color-by-speed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export class ColorBySpeed extends ParticleSystemModule {
* @en Maps the velocity of particles to a color within the specified range.
*/
@type(Vec2)
@tooltip('i18n:ParticleSystem.ColorBySpeed.speedRange')
@rangeMin(0)
@rangeStep(0.01)
public get speedRange (): Readonly<Vec2> {
return this._speedRange;
}
Expand Down
29 changes: 26 additions & 3 deletions cocos/particle/modules/color-over-lifetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
THE SOFTWARE.
*/

import { ccclass, type, serializable } from 'cc.decorator';
import { ccclass, type, serializable, tooltip } from 'cc.decorator';
import { ParticleSystemModule } from '../particle-system-module';
import { GradientRange } from '../gradient-range';
import { Impl } from '../impl';

Check failure on line 28 in cocos/particle/modules/color-over-lifetime.ts

View workflow job for this annotation

GitHub Actions / npm_test

Cannot find module '../impl' or its corresponding type declarations.
Expand All @@ -40,10 +40,33 @@ export class ColorOverLifetime extends ParticleSystemModule {
* @zh 颜色随时间变化的参数,各个 key 之间线性插值变化。
*/
@type(GradientRange)
@tooltip('i18n:ParticleSystem.ColorOverLifetime.color')
public get color (): Readonly<GradientRange> {
return this._color;
}

public set color (val: Readonly<GradientRange>) {
this._color.set(val);
if (this.impl) {
this._color.copyToLowLevelGradientRange(this.impl.getColor());
}
}

public get impl (): Impl.ColorOverLifetime | null {
return this._impl as Impl.ColorOverLifetime | null;
}

@serializable
public color = new GradientRange();
private _color = new GradientRange();

protected createImpl (): Impl.ParticleSystemModule {
throw new Error('Method not implemented.');
return new Impl.ColorOverLifetime();
}

public initialize (): void {
super.initialize();
if (this.impl) {
this._color.copyToLowLevelGradientRange(this.impl.getColor());
}
}
}
Loading

0 comments on commit 0fae20f

Please sign in to comment.