我通过引用this doc和this doc来编写脚本,我的代码是
<script src="https://raw.github.com/mrdoob/three.js/master/build/three.js"></script>
<script>
var text = "my text",
height = 20,
size = 70,
hover = 30,
curveSegments = 4,
bevelThickness = 2,
bevelSize = 1.5,
bevelSegments = 3,
bevelEnabled = true,
font = "optimer", // helvetiker, optimer, gentilis, droid sans, droid serif
weight = "bold", // normal bold
style = "normal"; // normal italic
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.body.appendChild(renderer.domElement);
var textGeo = new THREE.TextGeometry( text, {
size: size,
height: height,
curveSegments: curveSegments,
font: font,
weight: weight,
style: style,
bevelThickness: bevelThickness,
bevelSize: bevelSize,
bevelEnabled: bevelEnabled,
});
// var geometry = new THREE.CubeGeometry(10,10,1);
var material = new THREE.MeshBasicMaterial({color: 0x11ff00});
var textGeo = new THREE.Mesh(textGeo, material);
scene.add(textGeo);
camera.position.z = 10;
function render() {
requestAnimationFrame(render);
textGeo.rotation.x += 0.01;
textGeo.rotation.y += 0.01;
renderer.render(scene, camera);
}
render();
</script>
我可以通过稍微改变代码来制作立方体和其他几何体。但我不能使用这个脚本制作3D文本。这个代码有什么问题吗?请帮我
您需要使用如下模式加载字体文件:
var loader = new THREE.FontLoader();
loader.load( 'fonts/helvetiker_regular.typeface.json', function ( font ) {
// your code here
} );
例如,请参阅以下三个.js示例:
http://mrdoob.github.com/three.js/examples/webgl_geometry_text.html
另外,我建议不要为几何体和网格分配相同的变量名称。
three.js r.82
我还写了this tutorial创建一个3d字体,因为我遇到了一些我认为值得记录的陷阱。