-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathbasic.html
120 lines (89 loc) · 3.17 KB
/
basic.html
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
<html>
<head>
<title>SPE: Basic</title>
<link rel="stylesheet" type="text/css" href="./css/style.css">
</head>
<body>
<p class="numParticles"></p>
<script type="text/javascript" src="./js/THREE-r84.js"></script>
<script type="text/javascript" src="./js/Stats.min.js"></script>
<script type="text/javascript" src="../build/SPE.min.js"></script>
<script type="text/javascript">
// variables used in init()
var scene, camera, renderer, stats, stats2, clock;
// Used in initParticles()
var emitter, particleGroup;
// Setup the scene
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 10000);
// camera.position.z = 50;
// camera.lookAt( scene.position );
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor(0x000000);
stats = new Stats();
clock = new THREE.Clock();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0';
document.body.appendChild( renderer.domElement );
document.body.appendChild( stats.domElement );
}
// Create particle group and emitter
function initParticles() {
particleGroup = new SPE.Group({
texture: {
value: THREE.ImageUtils.loadTexture('./img/smokeparticle.png')
}
});
emitter = new SPE.Emitter({
maxAge: {
value: 2
},
position: {
value: new THREE.Vector3(0, 0, -50),
spread: new THREE.Vector3( 0, 0, 0 )
},
acceleration: {
value: new THREE.Vector3(0, -10, 0),
spread: new THREE.Vector3( 10, 0, 10 )
},
velocity: {
value: new THREE.Vector3(0, 25, 0),
spread: new THREE.Vector3(10, 7.5, 10)
},
color: {
value: [ new THREE.Color('white'), new THREE.Color('red') ]
},
size: {
value: 1
},
particleCount: 2000
});
particleGroup.addEmitter( emitter );
scene.add( particleGroup.mesh );
document.querySelector('.numParticles').textContent =
'Total particles: ' + emitter.particleCount;
}
function animate() {
requestAnimationFrame( animate );
render( clock.getDelta() );
stats.update();
}
function render( dt ) {
particleGroup.tick( dt );
renderer.render( scene, camera );
}
window.addEventListener( 'resize', function() {
var w = window.innerWidth,
h = window.innerHeight;
camera.aspect = w / h;
camera.updateProjectionMatrix();
renderer.setSize( w, h );
}, false );
init();
initParticles();
setTimeout(animate, 0);
</script>
</body>
</html>