Skip to content

Instantly share code, notes, and snippets.

@zhangwc
Created November 27, 2013 05:45
Show Gist options
  • Save zhangwc/7671190 to your computer and use it in GitHub Desktop.
Save zhangwc/7671190 to your computer and use it in GitHub Desktop.
use THREE.SpriteMaterial and canvas to create text and image in 3D scene
{
var texture = new THREE.ImageUtils.loadTexture( 'images/img.jpg' );
texture.needsUpdate = true;
var material = new THREE.SpriteMaterial({
map: texture,
useScreenCoordinates: false,
alignment: THREE.SpriteAlignment.center,
transparent: true
});
var sprite = new THREE.Sprite(material);
sprite.scale.set(10, 10, 1);
scene.add(sprite);
}
{
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
context.font = "bold 20px Serif";
context.textAlign = "left";
context.textBaseline = "top";
context.fillStyle = "#ff0000";
context.fillText("Sample Text", 0, 0);
var texture = new THREE.Texture(canvas);
texture.needsUpdate = true;
var material = new THREE.SpriteMaterial({
map: texture,
useScreenCoordinates: false,
alignment: THREE.SpriteAlignment.center,
transparent: true
});
var sprite = new THREE.Sprite(material);
sprite.scale.set(100, 100, 1);
scene.add(sprite);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment