forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
canvas_performance.html
138 lines (92 loc) · 3.15 KB
/
canvas_performance.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
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>three.js canvas - performance</title>
<meta charset="utf-8">
<style type="text/css">
body {
font-family: Monospace;
background-color: #f0f0f0;
margin: 0px;
overflow: hidden;
}
</style>
</head>
<body>
<script type="text/javascript" src="../build/Three.js"></script>
<script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
<script type="text/javascript" src="js/Stats.js"></script>
<script type="text/javascript">
var container, stats;
var camera, scene, renderer;
var sphere, plane;
var targetRotation = 0;
var targetRotationOnMouseDown = 0;
var mouseX = 0;
var mouseXOnMouseDown = 0;
var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;
init();
animate();
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
camera = new THREE.Camera( 45, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.z = 1000;
camera.position.y = 1000;
camera.position.z = 1000;
scene = new THREE.Scene();
// Grid
var geometry = new THREE.Geometry();
geometry.vertices.push( new THREE.Vertex( new THREE.Vector3( - 500, 0, 0 ) ) );
geometry.vertices.push( new THREE.Vertex( new THREE.Vector3( 500, 0, 0 ) ) );
var material = new THREE.LineBasicMaterial( { color: 0x000000, opacity: 0.5 } );
for ( var i = 0; i <= 10; i ++ ) {
var line = new THREE.Line( geometry, material );
line.position.z = ( i * 100 ) - 500;
scene.add( line );
var line = new THREE.Line( geometry, material );
line.position.x = ( i * 100 ) - 500;
line.rotation.y = 90 * Math.PI / 180;
scene.add( line );
}
// Spheres
geometry = new THREE.SphereGeometry( 100, 26, 18 );
material = new THREE.MeshLambertMaterial( { color: 0xffffff, shading: THREE.FlatShading, opacity: 1 } );
for ( var i = 0; i < 20; i ++ ) {
sphere = new THREE.Mesh( geometry, material );
sphere.overdraw = true;
sphere.position.x = ( i % 5 ) * 200 - 400;
sphere.position.z = Math.floor( i / 5 ) * 200 - 400;
scene.add( sphere );
}
// Lights
var ambientLight = new THREE.AmbientLight( Math.random() * 0x202020 );
scene.add( ambientLight );
var directionalLight = new THREE.DirectionalLight( Math.random() * 0xffffff );
directionalLight.position.x = 0;
directionalLight.position.y = 1;
directionalLight.position.z = 0;
scene.add( directionalLight );
var pointLight = new THREE.PointLight( 0xff0000, 1, 500 );
scene.add( pointLight );
renderer = new THREE.CanvasRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
container.appendChild(stats.domElement);
}
//
function animate() {
requestAnimationFrame( animate );
render();
stats.update();
}
function render() {
renderer.render( scene, camera );
}
</script>
</body>
</html>