Im loading a glTF shirt object. I want to wrap text around the sleeve and for that i have created a mesh on top of the sleeve using blender. Now i have created a canvas texture on that mesh and tried to render text but it does not seem to be working. It gives the following error.
Here's my code.
loadModel(model, callback) {
this.loader = new GLTFLoader();
this.loader.setCrossOrigin('anonymous');
this.loader.load(model, (gltf) => {
if (typeof callback === 'function') {
callback(gltf.scene);
}
this.scene.add(gltf.scene);
});
}
loadModel() {
this.isLoaded = false;
this.scene.loadModel('model10/V Shirt text.gltf', (model) => {
model.name = 'shirt';
// Iterator through the model's children
model.traverse((child) => {
if (child instanceof THREE.Mesh) {
// reset original material
child.material.map = null;
if (child.name = 'Text') {
let canvas = document.createElement('canvas');
canvas.height = 100;
canvas.width = 100;
let context = canvas.getContext('2d');
context.fillStyle = 'black'
context.font = '100pt Helvetica'
context.fillText('Hello', 10, 90);
const texture = new THREE.CanvasTexture(context);
const material = new THREE.MeshBasicMaterial({
map: texture
})
child.material.map = texture;
child.material.map.needsUpdate = true;
}
// create wireframes
// this.createWireframe({ mesh: child });
// console.log(child)
// push to local array
this.objects.push(child);
}
});
