wgge 0.1.32 → 0.1.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/animation/ProgressValue.js +2 -1
- package/core/particles/ParticleController.js +35 -0
- package/core/particles/ParticleModel.js +68 -0
- package/core/particles/ParticleRenderer.js +53 -0
- package/core/particles/generator/ParticleGeneratorController.js +69 -0
- package/core/particles/generator/ParticleGeneratorModel.js +76 -0
- package/core/particles/generator/ParticleGeneratorRenderer.js +27 -0
- package/core/renderer/canvas/CanvasRenderer.js +0 -11
- package/package.json +1 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export const EASING_FLAT = (x) => x;
|
|
2
|
-
export const EASING_EXPONENTIAL_IN = (x, e = 2) => Math.pow(x,e);
|
|
2
|
+
export const EASING_EXPONENTIAL_IN = (x, e = 2) => Math.pow(x, e);
|
|
3
3
|
export const EASING_EXPONENTIAL_IN_OUT = (x, e = 2) => (x <= 0.5) ? Math.pow(x * 2, e) / 2 : 1 - Math.pow(2 - x * 2, e) / 2;
|
|
4
4
|
export const EASING_QUAD_IN = EASING_EXPONENTIAL_IN;
|
|
5
5
|
export const EASING_QUAD_IN_OUT = EASING_EXPONENTIAL_IN_OUT;
|
|
6
6
|
export const EASING_CUBIC_IN = (x) => EASING_EXPONENTIAL_IN(x, 3);
|
|
7
7
|
export const EASING_CUBIC_IN_OUT = (x) => EASING_EXPONENTIAL_IN_OUT(x, 3);
|
|
8
|
+
export const EASING_LOG_OUT = (v) => Math.log2(v) / 4 + 1;
|
|
8
9
|
|
|
9
10
|
export default class ProgressValue {
|
|
10
11
|
start;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import ControllerBase from "../controller/ControllerBase";
|
|
2
|
+
|
|
3
|
+
export default class ParticleController extends ControllerBase {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @type ParticleModel
|
|
7
|
+
*/
|
|
8
|
+
model;
|
|
9
|
+
|
|
10
|
+
constructor(game, model) {
|
|
11
|
+
super(game, model);
|
|
12
|
+
|
|
13
|
+
this.model = model;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
updateInternal(delta) {
|
|
17
|
+
const deltaSecs = (delta / 1000);
|
|
18
|
+
this.model.lifetime.increase(-deltaSecs);
|
|
19
|
+
if (this.model.lifetime.get() < 0) {
|
|
20
|
+
this.model.removeMyself();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (this.model.fadeOutDuration.get() > 0 && this.model.lifetime.get() < this.model.fadeOutDuration.get()) {
|
|
25
|
+
this.model.opacity.set(this.model.lifetime.get() / this.model.fadeOutDuration.get());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
this.model.position.set(this.model.position.add(this.model.movement.multiply(deltaSecs)));
|
|
29
|
+
this.model.scale.increase(this.model.scaleGrowth.get() * deltaSecs);
|
|
30
|
+
if (this.model.scale.get() < 0) {
|
|
31
|
+
this.model.scale.set(0);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import ObjectModel from "../model/ObjectModel";
|
|
2
|
+
import StringValue from "../model/value/StringValue";
|
|
3
|
+
import FloatValue from "../model/value/FloatValue";
|
|
4
|
+
import Vector3 from "../model/vector/Vector3";
|
|
5
|
+
|
|
6
|
+
export default class ParticleModel extends ObjectModel {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @type StringValue
|
|
10
|
+
*/
|
|
11
|
+
imageUrl;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @type Vector3
|
|
15
|
+
*/
|
|
16
|
+
position;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @type FloatValue
|
|
20
|
+
*/
|
|
21
|
+
scale;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @type FloatValue
|
|
25
|
+
*/
|
|
26
|
+
opacity;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @type Vector3
|
|
30
|
+
*/
|
|
31
|
+
movement;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Remaining lifetime in seconds
|
|
35
|
+
* @type FloatValue
|
|
36
|
+
*/
|
|
37
|
+
lifetime;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Per second
|
|
41
|
+
* @type FloatValue
|
|
42
|
+
*/
|
|
43
|
+
scaleGrowth;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* In seconds
|
|
47
|
+
* @type FloatValue
|
|
48
|
+
*/
|
|
49
|
+
fadeOutDuration;
|
|
50
|
+
|
|
51
|
+
constructor(persistent) {
|
|
52
|
+
super(persistent);
|
|
53
|
+
|
|
54
|
+
this.imageUrl = this.addProperty('imageUrl', new StringValue('img/smoke-white.png'));
|
|
55
|
+
this.position = this.addProperty('position', new Vector3());
|
|
56
|
+
this.scale = this.addProperty('scale', new FloatValue(1));
|
|
57
|
+
this.opacity = this.addProperty('opacity', new FloatValue(1));
|
|
58
|
+
this.movement = this.addProperty('movement', new Vector3());
|
|
59
|
+
this.lifetime = this.addProperty('lifetime', new FloatValue(1));
|
|
60
|
+
this.scaleGrowth = this.addProperty('scaleGrowth', new FloatValue(-0.12));
|
|
61
|
+
this.fadeOutDuration = this.addProperty('fadeOutDuration', new FloatValue(0.3));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getResourcesForPreloadInternal() {
|
|
65
|
+
return [this.imageUrl.get()];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import ThreeRenderer from "../renderer/three/ThreeRenderer";
|
|
3
|
+
|
|
4
|
+
export default class ParticleRenderer extends ThreeRenderer {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @type ParticleModel
|
|
8
|
+
*/
|
|
9
|
+
model;
|
|
10
|
+
|
|
11
|
+
sprite;
|
|
12
|
+
|
|
13
|
+
constructor(game, model, scene) {
|
|
14
|
+
super(game, model, scene);
|
|
15
|
+
|
|
16
|
+
this.model = model;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
activateInternal() {
|
|
20
|
+
this.game.assets.getAsset(
|
|
21
|
+
this.model.imageUrl.get(),
|
|
22
|
+
(img) => {
|
|
23
|
+
const texture = new THREE.Texture();
|
|
24
|
+
texture.image = img;
|
|
25
|
+
texture.needsUpdate = true;
|
|
26
|
+
const material = new THREE.SpriteMaterial({map: texture});
|
|
27
|
+
this.sprite = new THREE.Sprite(material);
|
|
28
|
+
this.scene.add(this.sprite);
|
|
29
|
+
this.renderInternal();
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
deactivateInternal() {
|
|
35
|
+
if (this.sprite) {
|
|
36
|
+
this.sprite.opacity
|
|
37
|
+
this.sprite.removeFromParent();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
renderInternal() {
|
|
42
|
+
if (!this.sprite) return;
|
|
43
|
+
|
|
44
|
+
this.sprite.position.set(this.model.position.x, this.model.position.y, this.model.position.z);
|
|
45
|
+
this.sprite.scale.set(this.model.scale.get(), this.model.scale.get(), this.model.scale.get());
|
|
46
|
+
|
|
47
|
+
if (this.model.opacity.isDirty) {
|
|
48
|
+
this.sprite.material.opacity = this.model.opacity.get();
|
|
49
|
+
this.sprite.material.needsUpdate = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import ParticleController from "../ParticleController";
|
|
2
|
+
import ControllerBase from "../../controller/ControllerBase";
|
|
3
|
+
import Vector3 from "../../model/vector/Vector3";
|
|
4
|
+
|
|
5
|
+
export default class ParticleGeneratorController extends ControllerBase {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @type ParticleGeneratorModel
|
|
9
|
+
*/
|
|
10
|
+
model;
|
|
11
|
+
|
|
12
|
+
constructor(game, model) {
|
|
13
|
+
super(game, model);
|
|
14
|
+
|
|
15
|
+
this.model = model;
|
|
16
|
+
|
|
17
|
+
this.addChild(
|
|
18
|
+
new CollectionController(
|
|
19
|
+
this.game,
|
|
20
|
+
this.model.particles,
|
|
21
|
+
(m) => new ParticleController(this.game, m)
|
|
22
|
+
)
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
activateInternal() {
|
|
27
|
+
this.particleMaxTimeout = (1 / this.model.particlesPerSecond.get()) * 1000;
|
|
28
|
+
this.particleTimeout = Math.random() * this.particleMaxTimeout;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
updateInternal(delta) {
|
|
32
|
+
if (this.model.on.get()) {
|
|
33
|
+
this.particleTimeout -= delta;
|
|
34
|
+
while (this.particleTimeout < 0) {
|
|
35
|
+
this.addParticle();
|
|
36
|
+
this.particleTimeout += this.particleMaxTimeout;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
addParticle() {
|
|
42
|
+
const particle = this.model.particleTemplate.clone();
|
|
43
|
+
|
|
44
|
+
particle.position.set(
|
|
45
|
+
this.model.position.add(
|
|
46
|
+
new Vector3(
|
|
47
|
+
this.model.particlePositionSpread.x * (-0.5 + Math.random()),
|
|
48
|
+
this.model.particlePositionSpread.y * (-0.5 + Math.random()),
|
|
49
|
+
this.model.particlePositionSpread.z * (-0.5 + Math.random())
|
|
50
|
+
)
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
particle.scale.set(this.model.particleTemplate.scale.get() + (this.model.particleScaleSpread.get() * (-0.5 + Math.random())));
|
|
55
|
+
particle.lifetime.set(this.model.particleTemplate.lifetime.get() + (this.model.particleLifetimeSpread.get() * (-0.5 + Math.random())))
|
|
56
|
+
particle.movement.set(
|
|
57
|
+
this.model.particleTemplate.movement.add(
|
|
58
|
+
new Vector3(
|
|
59
|
+
this.model.particleMovementSpread.x * (-0.5 + Math.random()),
|
|
60
|
+
this.model.particleMovementSpread.y * (-0.5 + Math.random()),
|
|
61
|
+
this.model.particleMovementSpread.z * (-0.5 + Math.random())
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
this.model.particles.add(particle);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import ParticleModel from "../ParticleModel";
|
|
2
|
+
import ObjectModel from "../../model/ObjectModel";
|
|
3
|
+
import BoolValue from "../../model/value/BoolValue";
|
|
4
|
+
import FloatValue from "../../model/value/FloatValue";
|
|
5
|
+
import ModelNodeCollection from "../../model/collection/ModelNodeCollection";
|
|
6
|
+
import Vector3 from "../../model/vector/Vector3";
|
|
7
|
+
|
|
8
|
+
export default class ParticleGeneratorModel extends ObjectModel {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @type Vector3
|
|
12
|
+
*/
|
|
13
|
+
position;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @type BoolValue
|
|
17
|
+
*/
|
|
18
|
+
on;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @type ParticleModel
|
|
22
|
+
*/
|
|
23
|
+
particleTemplate;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @type FloatValue
|
|
27
|
+
*/
|
|
28
|
+
particlesPerSecond;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* new particles may be smaller or bigger
|
|
32
|
+
* @type FloatValue
|
|
33
|
+
*/
|
|
34
|
+
particleScaleSpread;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* particles starting point offset
|
|
38
|
+
* @type Vector3
|
|
39
|
+
*/
|
|
40
|
+
particlePositionSpread;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* random movement change per second
|
|
44
|
+
* @type Vector3
|
|
45
|
+
*/
|
|
46
|
+
particleMovementSpread;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @type FloatValue
|
|
50
|
+
*/
|
|
51
|
+
particleLifetimeSpread;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @type ModelNodeCollection
|
|
55
|
+
*/
|
|
56
|
+
particles;
|
|
57
|
+
|
|
58
|
+
constructor(persistent) {
|
|
59
|
+
super(persistent);
|
|
60
|
+
|
|
61
|
+
this.position = this.addProperty('position', new Vector3());
|
|
62
|
+
this.on = this.addProperty('on', new BoolValue(false));
|
|
63
|
+
|
|
64
|
+
this.particleTemplate = this.addProperty('particleTemplate', new ParticleModel());
|
|
65
|
+
|
|
66
|
+
this.particlesPerSecond = this.addProperty('particlesPerSecond', new FloatValue(50));
|
|
67
|
+
|
|
68
|
+
this.particleScaleSpread = this.addProperty('particleScaleSpread', new FloatValue(0.1));
|
|
69
|
+
this.particlePositionSpread = this.addProperty('particlePositionSpread', new Vector3());
|
|
70
|
+
this.particleMovementSpread = this.addProperty('particleMovementSpread', new Vector3(0.1, 0.1, 0.1));
|
|
71
|
+
this.particleLifetimeSpread = this.addProperty('particleLifetimeSpread', new FloatValue(1));
|
|
72
|
+
|
|
73
|
+
this.particles = this.addProperty('particles', new ModelNodeCollection());
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import ParticleRenderer from "../ParticleRenderer";
|
|
2
|
+
import ThreeRenderer from "../../renderer/three/ThreeRenderer";
|
|
3
|
+
import CollectionRenderer from "../../renderer/generic/CollectionRenderer";
|
|
4
|
+
|
|
5
|
+
export default class ParticleGeneratorRenderer extends ThreeRenderer {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @type ParticleGeneratorModel
|
|
9
|
+
*/
|
|
10
|
+
model;
|
|
11
|
+
|
|
12
|
+
constructor(game, model, scene) {
|
|
13
|
+
super(game, model, scene);
|
|
14
|
+
|
|
15
|
+
this.model = model;
|
|
16
|
+
|
|
17
|
+
this.addChild(
|
|
18
|
+
new CollectionRenderer(
|
|
19
|
+
this.game,
|
|
20
|
+
this.model.particles,
|
|
21
|
+
(m) => new ParticleRenderer(this.game, m, this.scene)
|
|
22
|
+
)
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
}
|
|
@@ -117,17 +117,6 @@ export default class CanvasRenderer extends RendererBase {
|
|
|
117
117
|
|
|
118
118
|
if (clear) this.context2d.clearRect(drawStart.x, drawStart.y, drawEnd.x, drawEnd.y);
|
|
119
119
|
this.context2d.globalAlpha = opacity;
|
|
120
|
-
console.log(
|
|
121
|
-
'drawing to canvas',
|
|
122
|
-
imageStart.x,
|
|
123
|
-
imageStart.y,
|
|
124
|
-
imageEnd.x,
|
|
125
|
-
imageEnd.y,
|
|
126
|
-
drawStart.x,
|
|
127
|
-
drawStart.y,
|
|
128
|
-
drawEnd.x,
|
|
129
|
-
drawEnd.y
|
|
130
|
-
);
|
|
131
120
|
this.context2d.drawImage(
|
|
132
121
|
image,
|
|
133
122
|
imageStart.x,
|