I've been experimenting with creating 3D text using WebGL
, three.js
, and THREE.TextGeometry
. So far, everything is working smoothly as I'm able to generate a single line of 3D text.
Now, my goal is to produce multiline text resembling a short paragraph. Ideally, I want the text to naturally wrap when it reaches the boundaries of a box or rectangle that contains it. The behavior I'm aiming for is similar to how standard HTML
text wraps within a div, flowing into multiple lines once it hits the edge of its parent container.
Below is an example of how I currently create a single line:
textGeo = new THREE.TextGeometry(
'Hello there. Am I a paragraph? I hope so.',
'size': 30
'height': 2
'font': 'helvetiker'
'weight': 'normal'
'style': 'normal'
bevelThickness: 0.1
bevelSize: 0
bevelEnabled: true
material: 0
extrudeMaterial: 1
)
materialArray = [
new THREE.MeshBasicMaterial( { color: 0xFFFFFF } )
new THREE.MeshBasicMaterial( { color: 0x666666, shading: THREE.SmoothShading } )
]
textMaterial = new THREE.MeshFaceMaterial(materialArray)
textGeo = new THREE.Mesh(textGeo, textMaterial)
textGeo.position.x = -150
textGeo.rotation.y = de2ra(15)
scene.add textGeo
How can I transform this into multiline text? Additionally, how do I enclose this in a square shape for wrapping purposes? What steps are involved in creating the square?