Skip to content

Instantly share code, notes, and snippets.

@hurry07
Created March 12, 2013 11:08
Show Gist options
  • Save hurry07/5142063 to your computer and use it in GitHub Desktop.
Save hurry07/5142063 to your computer and use it in GitHub Desktop.
/**
* Created with JetBrains WebStorm.
* User: lijie
* Date: 13-3-12
* Time: 下午6:30
* To change this template use File | Settings | File Templates.
*/
var container, stats;
var camera, scene, renderer;
var start = Date.now();
function initStatsBar(Stats) {
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
container.appendChild(stats.domElement);
}
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
var width = window.innerWidth || 2;
var height = window.innerHeight || 2;
camera = new THREE.OrthographicCamera(-width / 2, width / 2, height / 2, -height / 2, -100, 100);
camera.position.x = 0;
camera.position.y = 0;
camera.position.z = 0;
//camera.lookAt(0, 0, 0);
scene = new THREE.Scene();
scene.position.x = 0;
scene.position.y = 0;
scene.position.z = 0;
//renderer = new THREE.WebGLRenderer();
renderer = new THREE.CanvasRenderer();
renderer.setSize( width, height );
renderer.setClearColorHex(0x000000, 1.0);
container.appendChild( renderer.domElement );
initScene();
initStatsBar(Stats);
window.addEventListener( 'resize', onWindowResize, false );
}
function initScene() {
var sphere = createPlane('pictures/b_close_01.png');
scene.add( sphere );
// var string = 'hello three.js';
// var text3d = new THREE.TextGeometry( string, {
// size: 40,
// height: 20,
// curveSegments: 2,
// font: "helvetiker"
// });
//
// text3d.computeBoundingBox();
// var centerOffset = -0.5 * ( text3d.boundingBox.max.x - text3d.boundingBox.min.x );
// var textMaterial = new THREE.MeshBasicMaterial( { color: Math.random() * 0xff0000, overdraw: true } );
// var text = new THREE.Mesh( text3d, textMaterial );
//
// // Potentially, we can extract the vertices or faces of the text to generate particles too.
// // Geo > Vertices > Position
// text.position.set(centerOffset, 0, 0);
//
// text.rotation.x = 0;
// text.rotation.y = Math.PI * 2;
// scene.add( text );
scene.add(createText('hello three.js'));
}
function onWindowResize() {
camera.left = -window.innerWidth / 2;
camera.right = window.innerWidth / 2;
camera.bottom = -window.innerHeight / 2;
camera.top = window.innerHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
//
function animate() {
requestAnimationFrame( animate );
render();
stats.update();
}
function render() {
var timer = Date.now() - start;
//camera.position.x = Math.cos( timer ) * 500;
//camera.position.y = Math.sin( timer ) * 500;
camera.lookAt( scene.position );
renderer.render(scene, camera);
}
init();
animate();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment