-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex24.js
73 lines (66 loc) · 2.31 KB
/
ex24.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
import * as THREE from 'three';
import * as OIMO from 'oimo'
import TWEEN from 'tween';
//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,100)
camera.lookAt(0,0,0)
//--------------------------------------------------------------------------
//OIMO World Setup
const world = new OIMO.World({
timestep: 1/60,
iterations: 8,
broadphase: 2,
worldscale: 1,
random: true,
info: false,
gravity: [0,-9.8,0]
})
let worldMeshs = []
//--------------------------------------------------------------------------
const splashGroup = new THREE.Group()
let easeDone = false
let fireworkGeometry = new THREE.SphereGeometry( 1, 8, 8 )
let fireworkMaterial = new THREE.MeshBasicMaterial( { color: 0x00ff00 } )
for (let i = 0; i < 20; i++) {
let sphere = new THREE.Mesh( fireworkGeometry, fireworkMaterial )
let cx = THREE.Math.randInt( -30, 30 )
let cy = THREE.Math.randInt( 30, 60 )
let cz = THREE.Math.randInt( -30, 30 )
sphere.position.set(0, 30, 0)
new TWEEN.Tween(sphere.position)
.to({
x: cx , y: cy, z: cz }, 2000)
.easing(TWEEN.Easing.Quadratic.Out).onComplete(() => {
easeDone = true
worldMeshs[i] = world.add({type:'sphere', size:[1,1,1], pos:[cx,cy,cz], move:true})
}).start()
splashGroup.add(sphere)
}
scene.add(splashGroup)
let gGeometry = new THREE.BoxGeometry( 65, 1, 65 )
let gMaterial = new THREE.MeshBasicMaterial( { color: 0xffff00 } )
let ground = new THREE.Mesh( gGeometry, gMaterial )
ground.position.set(0, 0, 0)
scene.add(ground)
let boxGround = world.add({
type:'box', size:[65,1,65], pos:[0,0,0], move:false
})
const animate = () => {
requestAnimationFrame( animate )
render()
}
function render() {
TWEEN.update()
world.step()
if (easeDone) {splashGroup.children.forEach((mesh, index) => {
mesh.position.copy(worldMeshs[index].getPosition())
})}
renderer.render( scene, camera )
}
animate()