Created
November 27, 2013 05:45
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
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