forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc_ubiquity_test.html
268 lines (190 loc) · 6.98 KB
/
misc_ubiquity_test.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js misc - ubiquity - test</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
background-color: #ffffff;
margin: 0px;
overflow: hidden;
}
</style>
</head>
<body>
<script src="../build/three.js"></script>
<script src="js/renderers/Projector.js"></script>
<script src="js/renderers/CanvasRenderer.js"></script>
<script src="js/renderers/SVGRenderer.js"></script>
<script src="js/renderers/SoftwareRenderer.js"></script>
<script src="js/libs/stats.min.js"></script>
<script src="obj/Qrcode.js"></script>
<script>
var AMOUNT = 100;
var stats;
var camera, scene;
var canvasRenderer, svgRenderer, softwareRenderer, webglRenderer;
var mesh, group;
init();
animate();
function init() {
var width = window.innerWidth / 2;
var height = window.innerHeight / 2;
camera = new THREE.PerspectiveCamera( 75, width / height, 1, 10000 );
camera.position.z = 500;
scene = new THREE.Scene();
scene.autoUpdate = false;
// QRCODE
mesh = new THREE.Mesh( new Qrcode(), new THREE.MeshLambertMaterial( { /*emissive: 0xff0000,*/ vertexColors: THREE.FaceColors } ) );
mesh.scale.x = mesh.scale.y = mesh.scale.z = 2;
scene.add( mesh );
// CUBES
var cube = new THREE.BoxGeometry( 100, 100, 100 );
mesh = new THREE.Mesh( cube, new THREE.MeshBasicMaterial( { color: 0x0000ff, opacity: 0.5, transparent: true } ) );
mesh.position.x = 500;
mesh.rotation.x = Math.random();
mesh.rotation.y = Math.random();
mesh.scale.x = mesh.scale.y = mesh.scale.z = 2;
scene.add( mesh );
mesh = new THREE.Mesh( cube, new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } ) );
mesh.position.x = 500;
mesh.position.y = 500;
mesh.rotation.x = Math.random();
mesh.rotation.y = Math.random();
mesh.scale.x = mesh.scale.y = mesh.scale.z = 2;
scene.add( mesh );
// PLANE
mesh = new THREE.Mesh( new THREE.PlaneBufferGeometry( 100, 100 ), new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, side: THREE.DoubleSide } ) );
mesh.position.y = -500;
mesh.scale.x = mesh.scale.y = mesh.scale.z = 2;
scene.add( mesh );
// CYLINDER
mesh = new THREE.Mesh( new THREE.CylinderGeometry( 20, 100, 200, 10 ), new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } ) );
mesh.position.x = -500;
mesh.rotation.x = - Math.PI / 2;
mesh.scale.x = mesh.scale.y = mesh.scale.z = 2;
scene.add( mesh );
// POLYFIELD
var geometry = new THREE.Geometry();
var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, side: THREE.DoubleSide } );
for ( var i = 0; i < 100; i ++ ) {
var v = new THREE.Vector3(
Math.random() * 1000 - 500,
Math.random() * 1000 - 500,
Math.random() * 1000 - 500
);
var v0 = new THREE.Vector3(
Math.random() * 100 - 50,
Math.random() * 100 - 50,
Math.random() * 100 - 50
);
var v1 = new THREE.Vector3(
Math.random() * 100 - 50,
Math.random() * 100 - 50,
Math.random() * 100 - 50
);
var v2 = new THREE.Vector3(
Math.random() * 100 - 50,
Math.random() * 100 - 50,
Math.random() * 100 - 50
);
v0.add( v );
v1.add( v );
v2.add( v );
var face = new THREE.Face3(
geometry.vertices.push( v0 ) - 1,
geometry.vertices.push( v1 ) - 1,
geometry.vertices.push( v2 ) - 1,
null,
new THREE.Color( Math.random() * 0xffffff )
);
geometry.faces.push( face );
}
geometry.computeFaceNormals();
group = new THREE.Mesh( geometry, material );
group.scale.set( 2, 2, 2 );
scene.add( group );
// SPRITES
var textureLoader = new THREE.TextureLoader();
textureLoader.load( 'textures/sprite.png', function ( texture ) {
var material = new THREE.SpriteMaterial( { map: texture, transparent: true } );
for ( var i = 0; i < 50; i ++ ) {
var sprite = new THREE.Sprite( material );
sprite.position.x = Math.random() * 1000 - 500;
sprite.position.y = Math.random() * 1000 - 500;
sprite.position.z = Math.random() * 1000 - 500;
sprite.scale.set( 64, 64, 1 );
scene.add( sprite );
}
} );
for ( var i = 0; i < 50; i ++ ) {
var material = new THREE.SpriteMaterial( { color: Math.random() * 0xffffff } );
var sprite = new THREE.Sprite( material );
sprite.position.x = Math.random() * 1000 - 500;
sprite.position.y = Math.random() * 1000 - 500;
sprite.position.z = Math.random() * 1000 - 500;
sprite.scale.set( 64, 64, 1 );
scene.add( sprite );
}
// LIGHTS
var ambient = new THREE.AmbientLight( 0x80ffff );
scene.add( ambient );
var directional = new THREE.DirectionalLight( 0xffff00 );
directional.position.set( - 1, 0.5, 0 );
scene.add( directional );
canvasRenderer = new THREE.CanvasRenderer();
canvasRenderer.setClearColor( 0xf0f0f0 );
canvasRenderer.setPixelRatio( window.devicePixelRatio );
canvasRenderer.setSize( width, height );
document.body.appendChild( canvasRenderer.domElement );
svgRenderer = new THREE.SVGRenderer();
svgRenderer.setClearColor( 0xf0f0f0 );
svgRenderer.setSize( width, height );
svgRenderer.setQuality( 'low' );
document.body.appendChild( svgRenderer.domElement );
softwareRenderer = new THREE.SoftwareRenderer();
softwareRenderer.setClearColor( 0xf0f0f0 );
softwareRenderer.setSize( width, height );
document.body.appendChild( softwareRenderer.domElement );
webglRenderer = new THREE.WebGLRenderer( { antialias: true } );
webglRenderer.setClearColor( 0xf0f0f0 );
webglRenderer.setPixelRatio( window.devicePixelRatio );
webglRenderer.setSize( width, height );
document.body.appendChild( webglRenderer.domElement );
stats = new Stats();
document.body.appendChild( stats.dom );
//
window.addEventListener( 'resize', onWindowResize, false );
}
function onWindowResize() {
var width = window.innerWidth / 2;
var height = window.innerHeight / 2;
camera.aspect = width / height;
camera.updateProjectionMatrix();
canvasRenderer.setSize( width, height );
svgRenderer.setSize( width, height );
softwareRenderer.setSize( width, height );
webglRenderer.setSize( width, height );
}
//
function animate() {
requestAnimationFrame( animate );
render();
stats.update();
}
function render() {
var time = Date.now() * 0.0002;
camera.position.x = Math.sin( time ) * 500;
camera.position.z = Math.cos( time ) * 500;
camera.lookAt( scene.position );
group.rotation.x += 0.01;
scene.updateMatrixWorld();
canvasRenderer.render( scene, camera );
svgRenderer.render( scene, camera );
softwareRenderer.render( scene, camera );
webglRenderer.render( scene, camera );
}
</script>
</body>
</html>