Thirupaa Thirupaa - 1 year ago 116
Javascript Question

How to add text into along the object using three.js

I have added text into my object (a shirt model) using a text geometry. Here is my code:

var canvas = document.getElementById('myCanvas');
var ctx = canvas.getContext('2d');
ctx.font = 'italic 18px Arial';
ctx.textAlign = 'center';
ctx. textBaseline = 'middle';
ctx.fillStyle = 'red';
ctx.fillText('Your Text', 150, 50);`

My output looks like this:

enter image description here

The text does not fit into the shirt model. If I rotate the shirt model means text showing irrelevant view. I want to fit the text into the shirt model like this:

enter image description here

How can I fit my dynamic text into the shirt model using three.js.

Answer Source

Simply drawing the text to your 2D canvas will most likely never give you a satisfactory result. You have three possibilities to tackle this issue.

1) Using textures loaded with a THREE.TextureLoader.

2) Using THREE.TextGeometry:

3) Using a CSS3D solution.

Check also the UI example on the THREE.TextGeometry documentation page:

enter image description here