本文介绍了TextGeometry 未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在试用 TextGeometry.我让它适用于 BoxGeometry,但 TextGeometry 似乎不起作用.
I am trying out TextGeometry. I got it to work for BoxGeometry but TextGeometry does not seem to work.
我尝试使用不同的材料,如 MeshNormalMeterial,但它仍然无法正常工作
I have tried using different material like MeshNormalMeterial but it is still not working
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.getElementById("banner").appendChild( renderer.domElement );
var loader = new THREE.FontLoader();
loader.load( 'https://raw.githubusercontent.com/mrdoob/three.js/master/examples/fonts/helvetiker_bold.typeface.json', function ( font ) {
var geometry = new THREE.TextGeometry( 'Hello three.js!', {
font: font,
size: 80,
height: 5,
curveSegments: 12,
bevelEnabled: true,
bevelThickness: 10,
bevelSize: 8,
bevelOffset: 0,
bevelSegments: 5
} );
var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
var txt = new THREE.Mesh( geometry, material );
scene.add( txt );
function animate() {
requestAnimationFrame( animate );
renderer.render( scene, camera );
txt.rotation.x += 0.01;
txt.rotation.y +=0.01;
}
animate();
} );
camera.position.z = 5;
没有错误信息
推荐答案
将相机的位置和文本几何的参数设置为更负责任的东西.
Set position of the camera and parameters of text geometry to something more responsible.
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 100);
camera.position.z = 75;
var renderer = new THREE.WebGLRenderer({antialias: true});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var loader = new THREE.FontLoader();
loader.load('https://raw.githubusercontent.com/mrdoob/three.js/master/examples/fonts/helvetiker_bold.typeface.json', function(font) {
var geometry = new THREE.TextGeometry('Hello three.js!', {
font: font,
size: 10,
height: 1,
curveSegments: 12,
bevelEnabled: true,
bevelThickness: 0.5,
bevelSize: 0.25,
bevelOffset: 0,
bevelSegments: 5
});
geometry.center();
var material = new THREE.MeshBasicMaterial({
color: 0x00ff00
});
var txt = new THREE.Mesh(geometry, material);
scene.add(txt);
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
txt.rotation.x += 0.01;
txt.rotation.y += 0.01;
}
animate();
});
body {
overflow: hidden;
margin: 0;
}
<script src="https://threejs.org/build/three.min.js"></script>
这篇关于TextGeometry 未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!