-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathexample37.html
160 lines (126 loc) · 4.72 KB
/
example37.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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html>
<head>
<title>Example 37 - Animation tween</title>
<style>
body{
margin: 0;
overflow: hidden;
}
#stats { /* Align stats top-left */
position: absolute;
left: 0px;
top: 0px;
}
</style>
</head>
<body>
<!-- JavaScript libraries -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/three.js/r67/three.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/stats.js/r11/Stats.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.5/dat.gui.min.js"></script>
<script src="assets/libs/TrackballControls.js"></script>
<script src="assets/libs/PLYLoader.js"></script>
<script src="assets/libs/tween.min.js"></script>
<!-- Javascript code that runs our Three.js examples -->
<script>
// once everything is loaded, we run our Three.js stuff.
$(function () {
var stats = initStats();
// create a scene, that will hold all our elements such as objects, cameras and lights.
var scene = new THREE.Scene();
// create a camera, which defines where we're looking at.
var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
// create a render and set the size
var webGLRenderer = new THREE.WebGLRenderer();
webGLRenderer.setClearColor(new THREE.Color(0x000, 1.0));
webGLRenderer.setSize(window.innerWidth, window.innerHeight);
// position and point the camera to the center of the scene
camera.position.set(10,10,10);
camera.lookAt(new THREE.Vector3(0, -2, 0));
// add spotlight for the shadows
var spotLight = new THREE.SpotLight(0xffffff);
spotLight.position.set(20,20,20);
scene.add(spotLight);
// add the output of the renderer to the html element
$('body').append(webGLRenderer.domElement);
// call the render function
var step = 0;
// setup the control gui
var controls = new function () {};
var particleSystem = new THREE.Object3D();
var loadedGeometry;
var onUpdate = function () {
var count = 0;
var pos = this.pos;
loadedGeometry.vertices.forEach(function (e) {
var newY = ((e.y + 3.22544) * pos) - 3.22544;
particleSystem.geometry.vertices[count++].set(e.x, newY, e.z);
});
particleSystem.sortParticles = true;
};
// create a tween
// http://sole.github.io/tween.js/examples/03_graphs.html
var posSrc = {pos: 1}
var tween = new TWEEN.Tween(posSrc)
.to({pos: 0}, 5000)
.easing(TWEEN.Easing.Sinusoidal.InOut)
.onUpdate(onUpdate);
var tweenBack = new TWEEN.Tween(posSrc)
.to({pos: 1}, 5000)
.easing(TWEEN.Easing.Sinusoidal.InOut)
.onUpdate(onUpdate);
tween.chain(tweenBack);
tweenBack.chain(tween);
var gui = new dat.GUI();
var loader = new THREE.PLYLoader();
loader.load("assets/models/test.ply", function (geometry) {
loadedGeometry = geometry.clone();
var material = new THREE.ParticleBasicMaterial({
color: 0xffffff,
size: 0.4,
opacity: 0.6,
transparent: true,
blending: THREE.AdditiveBlending,
map: generateSprite()
});
particleSystem = new THREE.ParticleSystem(geometry, material);
particleSystem.sortParticles = true;
tween.start();
scene.add(particleSystem);
});
render();
// from THREE.js examples
function generateSprite() {
var canvas = document.createElement('canvas');
canvas.width = 16;
canvas.height = 16;
var context = canvas.getContext('2d');
var gradient = context.createRadialGradient(canvas.width / 2, canvas.height / 2, 0, canvas.width / 2, canvas.height / 2, canvas.width / 2);
gradient.addColorStop(0, 'rgba(255,255,255,1)');
gradient.addColorStop(0.2, 'rgba(0,255,255,1)');
gradient.addColorStop(0.4, 'rgba(0,0,64,1)');
gradient.addColorStop(1, 'rgba(0,0,0,1)');
context.fillStyle = gradient;
context.fillRect(0, 0, canvas.width, canvas.height);
var texture = new THREE.Texture(canvas);
texture.needsUpdate = true;
return texture;
}
function render() {
stats.update();
TWEEN.update();
requestAnimationFrame(render);
webGLRenderer.render(scene, camera);
}
function initStats() {
var stats = new Stats();
stats.setMode(0); // 0: fps, 1: ms
$('body').append(stats.domElement);
return stats;
}
});
</script>
</body>
</html>