-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex6.js
74 lines (57 loc) · 2.18 KB
/
ex6.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
import * as THREE from 'three';
import TWEEN from 'tween';
import { OrbitControls } from 'three-orbitcontrols-ts';
//init
const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000)
const renderer = new THREE.WebGLRenderer()
renderer.setSize(window.innerWidth, window.innerHeight)
document.body.appendChild(renderer.domElement)
//camera
camera.position.set(0,50,150)
camera.lookAt(0,0,0)
//--------------------------------------------------------------------------
const fireGroup = new THREE.Group()
const fireGroup1 = new THREE.Group()
const fireGroup2 = new THREE.Group()
const fireGroup3 = new THREE.Group()
const makeFirework = (gr, col, xcor) => {
for (let i = 0; i < 100; i++) {
let geometry = new THREE.BoxGeometry( 1, 1, 1 )
let material = new THREE.MeshBasicMaterial( { color: col } )
let fireCube = new THREE.Mesh( geometry, material )
fireCube.position.set(xcor,0,0)
gr.add(fireCube)
}
scene.add(gr)
new TWEEN.Tween(gr.position)
.to({
x:0, y: 50, z: 0 }, 4000)
.easing(TWEEN.Easing.Quadratic.Out).onComplete(() => {
ignite(gr, xcor)
}).start()
}
makeFirework(fireGroup1, 0x0000FF, 20)
makeFirework(fireGroup2, 0x00FF00, 40)
makeFirework(fireGroup3, 0xFF0000, 60)
const ignite = (expGroup, xcor) => {
expGroup.children.forEach(mesh => {
new TWEEN.Tween(mesh.position)
.to({
x: THREE.Math.randInt(xcor - 50, xcor + 50 ),
y: THREE.Math.randInt( 0, 100 ),
z: THREE.Math.randInt( -50, 50 )}, 5000).easing(TWEEN.Easing.Quadratic.Out)
.onComplete(() => {
mesh.position.set(xcor,-50,0)
}).start()
})
}
const animate = () => {
requestAnimationFrame( animate )
render()
}
function render() {
TWEEN.update();
renderer.render( scene, camera )
}
animate()