Skip to content

Commit

Permalink
add expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
SantyWang committed Apr 18, 2023
1 parent 07c7419 commit faed948
Show file tree
Hide file tree
Showing 41 changed files with 631 additions and 343 deletions.
11 changes: 6 additions & 5 deletions cocos/vfx/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import { ParticleEmitterParams, ParticleExecContext } from "./particle-base";
import { ParticleDataSet } from "./particle-data-set";
import { ccclass } from '../core/data/decorators';
import { ParticleEmitterParams, ParticleExecContext } from './particle-base';
import { ParticleDataSet } from './particle-data-set';

@ccclass('cc.Expression')
export abstract class Expression {
public abstract tick (particles: ParticleDataSet, params: ParticleEmitterParams, context: ParticleExecContext);
public abstract bind (particles: ParticleDataSet, params: ParticleEmitterParams, context: ParticleExecContext);
public abstract evaluate (index: number);
}
public abstract bind (particles: ParticleDataSet, params: ParticleEmitterParams, context: ParticleExecContext, randomOffset: number);
}
Empty file.
238 changes: 0 additions & 238 deletions cocos/vfx/expression/float-expression.ts

This file was deleted.

File renamed without changes.
45 changes: 45 additions & 0 deletions cocos/vfx/expressions/constant-vec3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { CCFloat, Vec3, serializable } from '../../core';
import { ccclass, type } from '../../core/data/class-decorator';
import { ParticleEmitterParams, ParticleExecContext } from '../particle-base';
import { ParticleDataSet } from '../particle-data-set';
import { RandomStream } from '../random-stream';
import { Vec3Expression } from './vec3';

@ccclass('cc.ConstantVec3')
export class ConstantVec3Expression extends Vec3Expression {
@type(CCFloat)
@serializable
public x = 0;

@type(CCFloat)
@serializable
public y = 0;

@type(CCFloat)
@serializable
public z = 0;

constructor (val: Vec3 = Vec3.ZERO) {
super();
this.x = val.x;
this.y = val.y;
this.z = val.z;
}

public tick (particles: ParticleDataSet, params: ParticleEmitterParams, context: ParticleExecContext) {}
public bind (particles: ParticleDataSet, params: ParticleEmitterParams, context: ParticleExecContext, randomOffset: number) {}

public evaluate (index: number, out: Vec3) {
out.x = this.x;
out.y = this.y;
out.z = this.z;
return out;
}

public evaluateSingle (time: number, randomStream: RandomStream, context: ParticleExecContext, out: Vec3) {
out.x = this.x;
out.y = this.y;
out.z = this.z;
return out;
}
}
53 changes: 53 additions & 0 deletions cocos/vfx/expressions/constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
https://www.cocos.com/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import { CCFloat } from '../../core';
import { ccclass, serializable, type } from '../../core/data/class-decorator';
import { ParticleEmitterParams, ParticleExecContext } from '../particle-base';
import { ParticleDataSet } from '../particle-data-set';
import { RandomStream } from '../random-stream';
import { FloatExpression } from './float';

@ccclass('cc.ConstantExpression')
export class ConstantExpression extends FloatExpression {
@type(CCFloat)
@serializable
public value = 0;

constructor (value = 0) {
super();
this.value = value;
}

public tick (particles: ParticleDataSet, params: ParticleEmitterParams, context: ParticleExecContext) {}
public bind (particles: ParticleDataSet, params: ParticleEmitterParams, context: ParticleExecContext, randomOffset: number) {}

public evaluate (index: number): number {
return this.value;
}

public evaluateSingle (time: number, randomStream: RandomStream, context: ParticleExecContext): number {
return this.value;
}
}
Loading

0 comments on commit faed948

Please sign in to comment.