-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtextGeometry.html
More file actions
169 lines (127 loc) · 5.15 KB
/
textGeometry.html
File metadata and controls
169 lines (127 loc) · 5.15 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!DOCTYPE html>
<html>
<head>
<title>Text geometry</title>
<script type="text/javascript" src="./libs/three.js"></script>
<script type="text/javascript" src="./libs/stats.js"></script>
<script type="text/javascript" src="./libs/dat.gui.js"></script>
<script type="text/javascript" src="./libs/fonts/helvetiker_regular.typeface.js"></script>
<script type="text/javascript" src="./libs/fonts/helvetiker_bold.typeface.js"></script>
<script type="text/javascript" src="./libs/fonts/bitstream_vera_sans_mono_roman.typeface.js"></script>
<style>
body {
margin: 0;
overflow: hidden;
}
</style>
</head>
<body>
<div id="Stats-output">
</div>
<!-- 容器 -->
<div id="WebGL-output">
</div>
<script type="text/javascript">
function init() {
var stats = initStats();
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
var webGLRenderer = new THREE.WebGLRenderer();
webGLRenderer.setClearColor(new THREE.Color(0x000000, 1.0));
webGLRenderer.setSize(window.innerWidth, window.innerHeight);
webGLRenderer.shadowMapEnabled = true;
camera.position.x = 100;
camera.position.y = 300;
camera.position.z = 600;
camera.lookAt(new THREE.Vector3(400, 0, -300));
var dirLight = new THREE.DirectionalLight();
dirLight.position.set(25, 23, 15);
scene.add(dirLight);
var dirLight2 = new THREE.DirectionalLight();
dirLight2.position.set(-25, 23, 15);
scene.add(dirLight2);
document.getElementById("WebGL-output").appendChild(webGLRenderer.domElement);
var step = 0;
var text1;
var text2;
var controls = new function () {
this.size = 90;
this.height = 90;
this.bevelThickness = 2;
this.bevelSize = 0.5;
this.bevelEnabled = true;
this.bevelSegments = 3;
this.bevelEnabled = true;
this.curveSegments = 12;
this.steps = 1;
this.font = "helvetiker";
this.weight = "normal";
// this.style = "italics";
this.asGeom = function () {
scene.remove(text1);
scene.remove(text2);
var options = {
size: controls.size,
height: controls.height,
weight: controls.weight,
font: controls.font,
bevelThickness: controls.bevelThickness,
bevelSize: controls.bevelSize,
bevelSegments: controls.bevelSegments,
bevelEnabled: controls.bevelEnabled,
curveSegments: controls.curveSegments,
steps: controls.steps
};
console.log(THREE.FontUtils.faces);
text1 = createMesh(new THREE.TextGeometry("Zou", options));
text1.position.z = -100;
text1.position.y = 100;
scene.add(text1);
text2 = createMesh(new THREE.TextGeometry("yang1230", options));
scene.add(text2);
};
};
controls.asGeom();
var gui = new dat.GUI();
gui.add(controls, 'size', 0, 200).onChange(controls.asGeom);
gui.add(controls, 'height', 0, 200).onChange(controls.asGeom);
gui.add(controls, 'font', ['bitstream vera sans mono', 'helvetiker']).onChange(controls.asGeom);
gui.add(controls, 'bevelThickness', 0, 10).onChange(controls.asGeom);
gui.add(controls, 'bevelSize', 0, 10).onChange(controls.asGeom);
gui.add(controls, 'bevelSegments', 0, 30).step(1).onChange(controls.asGeom);
gui.add(controls, 'bevelEnabled').onChange(controls.asGeom);
gui.add(controls, 'curveSegments', 1, 30).step(1).onChange(controls.asGeom);
gui.add(controls, 'steps', 1, 5).step(1).onChange(controls.asGeom);
render();
function createMesh(geom) {
// var meshMaterial = new THREE.MeshLambertMaterial({color: 0xff5555});
// var meshMaterial = new THREE.MeshNormalMaterial();
var meshMaterial = new THREE.MeshPhongMaterial({
specular: 0xffffff,
color: 0xeeffff,
shininess: 100,
metal: true
});
// meshMaterial.side=THREE.DoubleSide;
var plane = THREE.SceneUtils.createMultiMaterialObject(geom, [meshMaterial]);
return plane;
}
function render() {
stats.update();
requestAnimationFrame(render);
webGLRenderer.render(scene, camera);
}
function initStats() {
var stats = new Stats();
stats.setMode(0);
stats.domElement.style.position = 'absolute';
stats.domElement.style.left = '0px';
stats.domElement.style.top = '0px';
document.getElementById("Stats-output").appendChild(stats.domElement);
return stats;
}
}
window.onload = init;
</script>
</body>
</html>