Skip to content

Commit 3bf8775

Browse files
committed
3.1.2 TextGeometry
1 parent 47edaa8 commit 3bf8775

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

Chapter3/3.1.2.html

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2+
<html>
3+
<head>
4+
<script type="text/javascript" src="../lib/three.js"></script>
5+
<script type="text/javascript" src="../lib/helvetiker_regular.typeface.js"></script>
6+
7+
<script type="text/javascript">
8+
function init() {
9+
var renderer = new THREE.WebGLRenderer({
10+
canvas: document.getElementById('mainCanvas')
11+
});
12+
renderer.setClearColor(0x000000);
13+
var scene = new THREE.Scene();
14+
15+
// camera
16+
var camera = new THREE.OrthographicCamera(-2.5, 2.5, 1.875, -1.875, 0.1, 100);
17+
camera.position.set(5, 5, 20);
18+
camera.lookAt(new THREE.Vector3(1, 0, 0));
19+
scene.add(camera);
20+
21+
// draw axes to help you understand the coordinate
22+
drawAxes(scene);
23+
24+
var material = new THREE.MeshLambertMaterial({
25+
color: 0xffff00,
26+
//wireframe: true
27+
});
28+
29+
var mesh = new THREE.Mesh(new THREE.TextGeometry('Hello', {
30+
size: 1,
31+
height: 1
32+
}), material);
33+
scene.add(mesh);
34+
35+
var light = new THREE.DirectionalLight(0xffffff);
36+
light.position.set(-5, 10, 5);
37+
scene.add(light);
38+
39+
// render
40+
renderer.render(scene, camera);
41+
}
42+
43+
function drawAxes(scene) {
44+
// x-axis
45+
var xGeo = new THREE.Geometry();
46+
xGeo.vertices.push(new THREE.Vector3(0, 0, 0));
47+
xGeo.vertices.push(new THREE.Vector3(1, 0, 0));
48+
var xMat = new THREE.LineBasicMaterial({
49+
color: 0xff0000
50+
});
51+
var xAxis = new THREE.Line(xGeo, xMat);
52+
scene.add(xAxis);
53+
54+
// y-axis
55+
var yGeo = new THREE.Geometry();
56+
yGeo.vertices.push(new THREE.Vector3(0, 0, 0));
57+
yGeo.vertices.push(new THREE.Vector3(0, 1, 0));
58+
var yMat = new THREE.LineBasicMaterial({
59+
color: 0x00ff00
60+
});
61+
var yAxis = new THREE.Line(yGeo, yMat);
62+
scene.add(yAxis);
63+
64+
// z-axis
65+
var zGeo = new THREE.Geometry();
66+
zGeo.vertices.push(new THREE.Vector3(0, 0, 0));
67+
zGeo.vertices.push(new THREE.Vector3(0, 0, 1));
68+
var zMat = new THREE.LineBasicMaterial({
69+
color: 0x00ccff
70+
});
71+
var zAxis = new THREE.Line(zGeo, zMat);
72+
scene.add(zAxis);
73+
}
74+
</script>
75+
</head>
76+
77+
<body onload="init()">
78+
<canvas id="mainCanvas" width="400px" height="300px" ></canvas>
79+
</body>
80+
</html>

0 commit comments

Comments
 (0)