forked from Alchemist0823/three.quarks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abe4978
commit d85f405
Showing
9 changed files
with
420 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
import { | ||
Group, | ||
DoubleSide, | ||
Mesh, | ||
Vector4, | ||
Vector3, | ||
Color, | ||
AdditiveBlending, | ||
NormalBlending, | ||
TextureLoader, | ||
MeshBasicMaterial, | ||
} from 'three'; | ||
import { | ||
GridEmitter, | ||
SphereEmitter, | ||
CircleEmitter, | ||
ConeEmitter, | ||
HemisphereEmitter, | ||
ConstantValue, | ||
IntervalValue, | ||
DonutEmitter, | ||
PointEmitter, | ||
RandomColor, | ||
RenderMode, | ||
ParticleSystem, | ||
ParticleEmitter, | ||
BatchedParticleRenderer, | ||
} from 'three.quarks'; | ||
import {Demo} from './demo.js'; | ||
|
||
export class EmitterShapeDemo extends Demo { | ||
name = 'Different Emitter Shapes'; | ||
refreshTime = 10; | ||
initParticleSystem() { | ||
return new ParticleSystem({ | ||
duration: 5, | ||
looping: true, | ||
startLife: new IntervalValue(1.0, 1.0), | ||
startSpeed: new IntervalValue(1, 1), | ||
startSize: new IntervalValue(0.1, 0.1), | ||
startColor: new RandomColor(new Vector4(1, 0.91, 0.51, 1), new Vector4(1, 0.44, 0.16, 1)), | ||
worldSpace: true, | ||
|
||
maxParticle: 1000, | ||
emissionOverTime: new ConstantValue(1000), | ||
emissionBursts: [ | ||
/*{ | ||
time: 0, | ||
count: new ConstantValue(100), | ||
cycle: 1, | ||
interval: 0.01, | ||
probability: 1, | ||
},*/ | ||
], | ||
|
||
shape: new PointEmitter(), | ||
material: new MeshBasicMaterial({ | ||
map: this.texture, | ||
blending: AdditiveBlending, | ||
transparent: true, | ||
side: DoubleSide, | ||
}), | ||
startTileIndex: new ConstantValue(0), | ||
uTileCount: 10, | ||
vTileCount: 10, | ||
renderMode: RenderMode.BillBoard, | ||
renderOrder: 1, | ||
}); | ||
} | ||
|
||
initScene() { | ||
this.scene = super.initScene(); | ||
this.batchRenderer = new BatchedParticleRenderer(); | ||
this.scene.add(this.batchRenderer); | ||
|
||
this.texture = new TextureLoader().load('textures/texture1.png', (texture) => { | ||
this.texture.name = 'textures/texture1.png'; | ||
|
||
let particles = this.initParticleSystem(); | ||
particles.emitterShape = new PointEmitter(); | ||
particles.emitter.name = 'point'; | ||
//particles.emitter.rotation.y = Math.PI / 2; | ||
particles.emitter.position.set(-5, -5, 2); | ||
this.batchRenderer.addSystem(particles); | ||
this.scene.add(particles.emitter); | ||
this.groups.push(particles.emitter); | ||
|
||
particles = this.initParticleSystem(); | ||
particles.emitterShape = new SphereEmitter({ | ||
radius: 1, | ||
thickness: 0.2, | ||
arc: Math.PI * 2, | ||
}); | ||
particles.emitter.name = 'Sphere'; | ||
//particles.emitter.rotation.y = Math.PI / 2; | ||
particles.emitter.position.set(-5, 0, 2); | ||
this.batchRenderer.addSystem(particles); | ||
this.scene.add(particles.emitter); | ||
this.groups.push(particles.emitter); | ||
|
||
particles = this.initParticleSystem(); | ||
particles.emitterShape = new HemisphereEmitter({ | ||
radius: 1, | ||
thickness: 0.2, | ||
arc: Math.PI * 2, | ||
}); | ||
particles.emitter.name = 'Hemisphere'; | ||
particles.emitter.rotation.x = -Math.PI / 2; | ||
particles.emitter.position.set(-5, 5, 2); | ||
this.batchRenderer.addSystem(particles); | ||
this.scene.add(particles.emitter); | ||
this.groups.push(particles.emitter); | ||
|
||
particles = this.initParticleSystem(); | ||
particles.emitterShape = new ConeEmitter({ | ||
radius: 1, | ||
thickness: 1, | ||
arc: Math.PI * 2, | ||
angle: Math.PI / 4, | ||
}); | ||
particles.emitter.name = 'Cone'; | ||
particles.emitter.position.set(0, -5, 2); | ||
this.batchRenderer.addSystem(particles); | ||
this.scene.add(particles.emitter); | ||
this.groups.push(particles.emitter); | ||
|
||
particles = this.initParticleSystem(); | ||
particles.emitterShape = new CircleEmitter({ | ||
radius: 1, | ||
thickness: 0.2, | ||
arc: Math.PI * 2, | ||
}); | ||
particles.emitter.name = 'Circle'; | ||
//particles.emitter.rotation.y = Math.PI / 2; | ||
particles.emitter.position.set(0, 0, 2); | ||
this.batchRenderer.addSystem(particles); | ||
this.scene.add(particles.emitter); | ||
this.groups.push(particles.emitter); | ||
|
||
particles = this.initParticleSystem(); | ||
particles.emitterShape = new DonutEmitter({ | ||
radius: 2, | ||
thickness: 1, | ||
arc: Math.PI * 2, | ||
donutRadius: 0.2, | ||
}); | ||
particles.emitter.name = 'Donut'; | ||
//particles.emitter.rotation.y = Math.PI / 2; | ||
particles.emitter.position.set(0, 5, 2); | ||
this.batchRenderer.addSystem(particles); | ||
this.scene.add(particles.emitter); | ||
this.groups.push(particles.emitter); | ||
|
||
particles = this.initParticleSystem(); | ||
particles.emitterShape = new GridEmitter({ | ||
width: 2, | ||
height: 2, | ||
rows: 10, | ||
columns: 10, | ||
}); | ||
particles.emitter.name = 'Grid'; | ||
//particles.emitter.rotation.y = Math.PI / 2; | ||
particles.emitter.position.set(5, -5, 2); | ||
this.batchRenderer.addSystem(particles); | ||
this.scene.add(particles.emitter); | ||
this.groups.push(particles.emitter); | ||
}); | ||
return this.scene; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import {EmitterShape, ShapeJSON} from './EmitterShape'; | ||
import {Particle} from '../Particle'; | ||
import {MathUtils} from 'three'; | ||
|
||
export interface CircleEmitterParameters { | ||
radius?: number; | ||
arc?: number; | ||
thickness?: number; | ||
} | ||
|
||
export class CircleEmitter implements EmitterShape { | ||
type = 'circle'; | ||
radius: number; | ||
arc: number; // [0, Math.PI * 2] | ||
thickness: number; // [0, 1] | ||
|
||
constructor(parameters: CircleEmitterParameters = {}) { | ||
this.radius = parameters.radius ?? 10; | ||
this.arc = parameters.arc ?? 2.0 * Math.PI; | ||
this.thickness = parameters.thickness ?? 1; | ||
} | ||
|
||
initialize(p: Particle) { | ||
const u = Math.random(); | ||
const r = MathUtils.lerp(1 - this.thickness, 1, Math.random()); | ||
const theta = u * this.arc; | ||
p.position.x = Math.cos(theta); | ||
p.position.y = Math.sin(theta); | ||
p.position.z = 0; | ||
p.velocity.copy(p.position).multiplyScalar(p.startSpeed); | ||
//const v = Math.random(); | ||
p.position.multiplyScalar(this.radius * r); | ||
} | ||
|
||
toJSON(): ShapeJSON { | ||
return { | ||
type: 'circle', | ||
radius: this.radius, | ||
arc: this.arc, | ||
thickness: this.thickness, | ||
}; | ||
} | ||
|
||
static fromJSON(json: any): CircleEmitter { | ||
return new CircleEmitter(json); | ||
} | ||
|
||
clone(): EmitterShape { | ||
return new CircleEmitter({ | ||
radius: this.radius, | ||
arc: this.arc, | ||
thickness: this.thickness, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.