I write a script by referencing this doc and this doc my code is
<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>
i can make cube and other geometry by changing the code slightly. But i cant make 3d text using this script. whats the problem with this code? please help me
3. Three. js—A JavaScript 3D Engine - Programming 3D Applications with HTML5 and WebGL [Book]
Finally, it provides an easy and native way to load our models into our scene. Three. js can be an attractive option as a game development engine if you don't want your users to need to download an app via an app store or have any setup to play your game.
ThreeJS is a library in Javascript, created by Mr. doob, that allows you to manipulate 3D objects directly in the browser. What you have to understand is that ThreeJS, via Javascript, allows you to use WebGL in an HTML5 canvas. WebGL is a Javascript API that allows you to create 2D and 3D graphic rendering.
Objects in three. js exist in a three-dimensional space with x, y, and z axes. Your view of those points is determined by the camera, which also exists in three-dimensional space. This allows a bunch of stuff like zooming past 3D objects, or rotating around them, that we don't need for this 2D visualization.
You need to load a font file using a pattern like so:
var loader = new THREE.FontLoader();
loader.load( 'fonts/helvetiker_regular.typeface.json', function ( font ) {
// your code here
} );
See, for example, this three.js example:
https://threejs.org/examples/webgl_geometry_text.html
Also, I'd advise against assigning the same variable name to both your geometry and your mesh.
three.js r.128
I also wrote this tutorial on creating a 3d font, since I hit a few gotchas that I thought were worth documenting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With