Skip to content

Commit dd46282

Browse files
committed
Revert webgl_loader_ttf example
1 parent d89bef3 commit dd46282

File tree

2 files changed

+46
-31
lines changed

2 files changed

+46
-31
lines changed
-26 KB
Binary file not shown.

examples/webgl_loader_ttf.html

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,20 @@
2929
import { Font } from 'three/addons/loaders/FontLoader.js';
3030
import { TextGeometry } from 'three/addons/geometries/TextGeometry.js';
3131

32-
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
33-
3432
let container;
3533
let camera, cameraTarget, scene, renderer;
3634
let group, textMesh1, textMesh2, textGeo, material;
3735
let firstLetter = true;
3836

3937
let text = 'three.js';
4038
const depth = 20,
39+
size = 70,
4140
hover = 30,
4241
curveSegments = 4,
4342
bevelThickness = 2,
4443
bevelSize = 1.5;
4544

4645
let font = null;
47-
let size = 50;
48-
let textDirection = 'ltr';
4946
const mirror = true;
5047

5148
let targetRotation = 0;
@@ -84,7 +81,7 @@
8481

8582
const dirLight2 = new THREE.DirectionalLight( 0xffffff, 2 );
8683
dirLight2.position.set( 0, hover, 10 ).normalize();
87-
dirLight2.color.setHSL( 0.5, 1, 0.5, THREE.SRGBColorSpace );
84+
dirLight2.color.setHSL( Math.random(), 1, 0.5, THREE.SRGBColorSpace );
8885
scene.add( dirLight2 );
8986

9087
material = new THREE.MeshPhongMaterial( { color: 0xffffff, flatShading: true } );
@@ -96,7 +93,7 @@
9693

9794
const loader = new TTFLoader();
9895

99-
loader.load( 'fonts/ttf/MPLUSRounded1c/MPLUSRounded1c-Regular.ttf', function ( json ) {
96+
loader.load( 'fonts/ttf/kenpixel.ttf', function ( json ) {
10097

10198
font = new Font( json );
10299
createText();
@@ -124,49 +121,68 @@
124121
container.style.touchAction = 'none';
125122
container.addEventListener( 'pointerdown', onPointerDown );
126123

124+
document.addEventListener( 'keypress', onDocumentKeyPress );
125+
document.addEventListener( 'keydown', onDocumentKeyDown );
126+
127127
window.addEventListener( 'resize', onWindowResize );
128128

129-
// GUI
129+
}
130130

131-
const params = {
132-
changeText: text,
133-
direction: 'ltr',
134-
changeSize: size
135-
};
131+
function onWindowResize() {
136132

137-
const gui = new GUI();
133+
windowHalfX = window.innerWidth / 2;
138134

139-
gui.add( params, 'changeText' ).name( 'Display text' ).onChange( value => {
135+
camera.aspect = window.innerWidth / window.innerHeight;
136+
camera.updateProjectionMatrix();
140137

141-
text = value;
142-
refreshText();
138+
renderer.setSize( window.innerWidth, window.innerHeight );
143139

144-
} );
145-
gui.add( params, 'direction', { LeftToRight: 'ltr', RightToLeft: 'rtl', TopToBottom: 'tb' } ).name( 'Direction' ).onChange( value => {
140+
}
146141

147-
textDirection = value;
148-
refreshText();
142+
function onDocumentKeyDown( event ) {
149143

150-
} );
151-
gui.add( params, 'changeSize' ).name( 'Size' ).onChange( value => {
144+
if ( firstLetter ) {
145+
146+
firstLetter = false;
147+
text = '';
148+
149+
}
150+
151+
const keyCode = event.keyCode;
152152

153-
size = value;
153+
// backspace
154+
155+
if ( keyCode === 8 ) {
156+
157+
event.preventDefault();
158+
159+
text = text.substring( 0, text.length - 1 );
154160
refreshText();
155161

156-
} );
162+
return false;
157163

158-
gui.open();
164+
}
159165

160166
}
161167

162-
function onWindowResize() {
168+
function onDocumentKeyPress( event ) {
163169

164-
windowHalfX = window.innerWidth / 2;
170+
const keyCode = event.which;
165171

166-
camera.aspect = window.innerWidth / window.innerHeight;
167-
camera.updateProjectionMatrix();
172+
// backspace
168173

169-
renderer.setSize( window.innerWidth, window.innerHeight );
174+
if ( keyCode === 8 ) {
175+
176+
event.preventDefault();
177+
178+
} else {
179+
180+
const ch = String.fromCharCode( keyCode );
181+
text += ch;
182+
183+
refreshText();
184+
185+
}
170186

171187
}
172188

@@ -176,7 +192,6 @@
176192

177193
font: font,
178194

179-
direction: textDirection,
180195
size: size,
181196
depth: depth,
182197
curveSegments: curveSegments,

0 commit comments

Comments
 (0)