Skip to content

Commit

Permalink
fix speedModifier is not reset after behavior update
Browse files Browse the repository at this point in the history
  • Loading branch information
Alchemist0823 committed Nov 10, 2023
1 parent a523ed6 commit dcb9136
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"scripts": {
"type-check": "tsc --noEmit",
"type-check:watch": "npm run type-check -- --watch",
"dev": "rollup -c -w",
"build:types": "tsc --emitDeclarationOnly",
"build:js": "rollup -c",
"build:production": "npm run build:types && cross-env NODE_ENV=production npm run build:js && cpx ./dist/three.quarks.esm.js ./examples/js/",
Expand Down
3 changes: 3 additions & 0 deletions src/Particle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface IParticle {
}

export interface Particle extends IParticle {
speedModifier: number;
emissionState?: EmissionState;
parentMatrix?: Matrix4;
startSpeed: number;
Expand Down Expand Up @@ -65,6 +66,7 @@ export class SpriteParticle implements Particle {
age = 0;
life = 1;
size = 1;
speedModifier = 1;

// extra
angularVelocity?: number | Quaternion;
Expand Down Expand Up @@ -100,6 +102,7 @@ export class TrailParticle implements Particle {
life = 1;
size = 1;
length = 100;
speedModifier = 1;

// GPU
color: Vector4 = new Vector4();
Expand Down
8 changes: 5 additions & 3 deletions src/ParticleSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ export class ParticleSystem implements IParticleSystem {
}
}
const particle = this.particles[this.particleNum - 1];
particle.speedModifier = 1;
this.startColor.genColor(particle.startColor, this.emissionState.time, {});
particle.color.copy(particle.startColor);
particle.startSpeed = this.startSpeed.genValue(emissionState.time / this.duration);
Expand Down Expand Up @@ -596,7 +597,6 @@ export class ParticleSystem implements IParticleSystem {
trail.length = (this.rendererEmitterSettings as TrailSettings).startLength.genValue(
emissionState.time / this.duration
);
trail.reset();
}

this.emitterShape.initialize(particle);
Expand Down Expand Up @@ -724,8 +724,10 @@ export class ParticleSystem implements IParticleSystem {
this.particles[i].position.applyMatrix4(this.emitter.matrixWorld);
}
} else {
const speedModifier = (this.particles[i] as any).speedModifier ?? 1;
this.particles[i].position.addScaledVector(this.particles[i].velocity, delta * speedModifier);
this.particles[i].position.addScaledVector(
this.particles[i].velocity,
delta * this.particles[i].speedModifier
);
}
this.particles[i].age += delta;
}
Expand Down
4 changes: 2 additions & 2 deletions src/QuarksLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ export class QuarksLoader extends ObjectLoader {
}

// @ts-ignore
parseObject<T extends Object3D<Object3DEventMap>>(
parseObject(
data: any,
geometries: any,
materials: Material[],
textures: Texture[],
animations: AnimationClip[]
): T {
): Object3D {
let object;

function getGeometry(name: any) {
Expand Down
20 changes: 10 additions & 10 deletions test/functions/Gradient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ describe('Gradient', () => {
test('.genColor', () => {
const gradient = new Gradient(
[
[new Vector3(0, 0, 0), 0],
[new Vector3(0, 0, 0), 0.1],
[new Vector3(1, 1, 1), 0.2],
[new Vector3(1, 1, 1), 0.8],
[new Vector3(0, 0, 0), 1],
[new Vector3(0, 0, 0), 0.9],
],
[
[0, 0],
[1, 1],
[0, 0.1],
[1, 0.9],
]
);
const color = new Vector4();
Expand All @@ -37,22 +37,22 @@ describe('Gradient', () => {
expect(color.x).toEqual(1);
expect(color.y).toEqual(1);
expect(color.z).toEqual(1);
expect(color.w).toEqual(0.8);
expect(color.w).toEqual(0.875);
gradient.genColor(color, 0.2);
expect(color.x).toEqual(1);
expect(color.y).toEqual(1);
expect(color.z).toEqual(1);
expect(color.w).toEqual(0.2);
gradient.genColor(color, 0.1);
expect(color.w).toEqual(0.125);
gradient.genColor(color, 0.15);
expect(color.x).toBeCloseTo(0.5);
expect(color.y).toBeCloseTo(0.5);
expect(color.z).toBeCloseTo(0.5);
expect(color.w).toEqual(0.1);
gradient.genColor(color, 0.9);
expect(color.w).toBeCloseTo(0.0625);
gradient.genColor(color, 0.85);
expect(color.x).toBeCloseTo(0.5);
expect(color.y).toBeCloseTo(0.5);
expect(color.z).toBeCloseTo(0.5);
expect(color.w).toEqual(0.9);
expect(color.w).toBeCloseTo(0.9375);
});

test('.toJSON', () => {
Expand Down

0 comments on commit dcb9136

Please sign in to comment.