forked from Alchemist0823/three.quarks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
customPluginDemo.js
146 lines (131 loc) · 4.13 KB
/
customPluginDemo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import {MeshBasicMaterial, Vector4, FrontSide, AdditiveBlending, TextureLoader} from './js/three.module.js';
import {
Bezier,
ColorRange,
ConstantValue,
TurbulenceField,
IntervalValue,
PiecewiseBezier,
ColorOverLife,
RenderMode,
SizeOverLife,
ParticleSystem,
ParticleEmitter,
BatchedParticleRenderer,
GridEmitter,
ValueGeneratorFromJSON,
loadPlugin,
} from './js/three.quarks.esm.js';
import {Demo} from './demo.js';
export class SinWave {
type = 'SinWave';
frequency = 1;
height = 10;
waveSize = 1;
time = 0;
constructor(frequency, height, waveSize) {
this.frequency = frequency;
this.height = height;
this.waveSize = waveSize;
this.time = 0;
}
initialize(particle) {}
update(particle, delta) {
let height = this.height.genValue(particle.age / particle.life);
particle.position.z =
Math.sin(
this.time * this.frequency.genValue(particle.age / particle.life) +
(particle.position.x + particle.position.y) * (1 / this.waveSize)
) *
height -
height / 2;
}
frameUpdate(delta) {
this.time += delta;
}
toJSON() {
return {
type: this.type,
frequency: this.frequency.toJSON(),
height: this.height.toJSON(),
waveSize: this.waveSize,
};
}
static fromJSON(json) {
return new SinWave(ValueGeneratorFromJSON(json.frequency), ValueGeneratorFromJSON(json.height), json.waveSize);
}
clone() {
return new SinWave(this.frequency.clone(), this.height.clone(), this.waveSize);
}
}
export class CustomPluginDemo extends Demo {
name = 'Customized Plugin';
initDemo() {
let plugin = {
id: 'MyPlugin',
initialize: () => {},
emitterShapes: [],
behaviors: [
{
type: 'SinWave',
constructor: SinWave,
params: [
['frequency', 'valueFunc'],
['height', 'valueFunc'],
['waveSize', 'number'],
],
loadJSON: SinWave.fromJSON,
},
],
};
loadPlugin(plugin);
const ps = new ParticleSystem({
duration: 10000,
looping: false,
startLife: new ConstantValue(10000),
startSpeed: new ConstantValue(0),
startSize: new ConstantValue(0.1),
startColor: new ColorRange(new Vector4(1, 1, 1, 1), new Vector4(1, 1, 1, 1)),
worldSpace: false,
emissionOverTime: new ConstantValue(0),
emissionBursts: [
{
time: 0,
count: 2500,
cycle: 1,
interval: 1,
probability: 1,
},
],
shape: new GridEmitter({width: 15, height: 15, column: 50, row: 50}),
material: new MeshBasicMaterial({
map: this.texture,
blending: AdditiveBlending,
transparent: true,
side: FrontSide,
}),
renderMode: RenderMode.BillBoard,
startTileIndex: new ConstantValue(0),
uTileCount: 10,
vTileCount: 10,
renderOrder: 0,
});
ps.emitter.name = 'ps';
ps.addBehavior(new SinWave(new ConstantValue(2), new ConstantValue(5), 5));
//ps.emitter.rotation.x = - Math.PI / 2;
ps.emitter.position.y = 0;
ps.emitter.scale.set(0.8, 0.8, 0.8);
this.batchRenderer.addSystem(ps);
this.scene.add(ps.emitter);
}
initScene() {
super.initScene();
this.texture = new TextureLoader().load('textures/texture1.png', (texture) => {
this.texture.name = 'textures/texture1.png';
this.batchRenderer = new BatchedParticleRenderer();
this.scene.add(this.batchRenderer);
this.initDemo();
});
return this.scene;
}
}