-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSphereGeometry.html
More file actions
155 lines (123 loc) · 3.1 KB
/
SphereGeometry.html
File metadata and controls
155 lines (123 loc) · 3.1 KB
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
<!DOCTYPE html>
<html>
<head>
<!-- 移动相机的位置-->
<meta charset="UTF-8">
<title>webgl SphereGeometry</title>
<script src="js/three.js"></script>
<script src="js/OrbitControls.js"></script>
<script src="js/Stats.js"></script>
<style type="text/css">
div#canvas-frame {
border: none;
cursor: pointer;
width: 100%;
height: 666px;
background-color: #EEEEEE;
}
</style>
<script>
/*
* 围绕某个 x,y,z轴测试
*/
var renderer;
var stats;
function initThree() {
width = document.getElementById('canvas-frame').clientWidth;
height = document.getElementById('canvas-frame').clientHeight;
renderer = new THREE.WebGLRenderer({
antialias : true
});
renderer.setSize(width, height);
document.getElementById('canvas-frame').appendChild(renderer.domElement);
renderer.setClearColor(0xFFFFFF, 1.0);
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.left = '0px';
stats.domElement.style.top = '0px';
document.getElementById('canvas-frame').appendChild(stats.domElement);
}
var camera;
function initCamera() {
camera = new THREE.PerspectiveCamera(45, width / height, 1, 10000);
camera.position.x = 100;
camera.position.y = 300;
camera.position.z = 600;
camera.up.x = 0;
camera.up.y = 1;
camera.up.z = 0;
camera.lookAt({
x : 100,
y : 0,
z : 100
});
}
var controls;
function initControls() {
var controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.addEventListener('change', render);
//旋转的中心点
controls.target.set(0,0,0);
controls.update();
function render() {
renderer.render(scene, camera);
}
}
var scene;
function initScene() {
scene = new THREE.Scene();
scene.add(camera);
}
var light;
function initLight() {
light = new THREE.AmbientLight(0xFFFFFF);
light.position.set(400, 300, 500);
scene.add(light);
}
var cube;
var mesh;
function initObject() {
var geometry = new THREE.SphereGeometry( 100 );
for ( var i = 0; i < geometry.faces.length; i += 2 ) {
var hex = Math.random() * 0xFFFFFF;
geometry.faces[ i ].color.setHex( hex );
geometry.faces[ i + 1 ].color.setHex( hex );
}
var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors} );
mesh = new THREE.Mesh( geometry,material);
mesh.position = new THREE.Vector3(0,0,0);
scene.add(mesh);
}
function initGrid(){
var helper = new THREE.GridHelper( 1000, 50 );
helper.setColors( 0xFF0000, 0x808080 );
scene.add( helper );
}
function threeStart() {
initThree();
initCamera();
initControls();
initScene();
initLight();
initObject();
initGrid();
animation();
}
// 帧循环、游戏循环
function animation()
{
//mesh.rotation.y +=0.01;
//mesh.rotation.x +=0.01;
mesh.rotateY(-0.01);
mesh.rotateX(0.01);
mesh.rotateZ(-0.01);
requestAnimationFrame(animation);
renderer.render(scene, camera);
stats.update();
}
</script>
</head>
<body onload="threeStart();">
<div id="canvas-frame"></div>
</body>
</html>