Instantly share code, notes, and snippets.

Embed
What would you like to do?
jsdokusho typescript & three.js sample
/// <reference path="../d.ts/DefinitelyTyped/jquery/jquery.d.ts" />
/// <reference path="../d.ts/DefinitelyTyped/threejs/threejs.d.ts" />
class Sample{
camera : THREE.PerspectiveCamera;
scene : THREE.Scene;
renderer : THREE.CanvasRenderer;
geometry : THREE.CubeGeometry;
material : THREE.MeshBasicMaterial;
mesh : THREE.Mesh;
// =========================================================================
// コンストラクタ
// =========================================================================
constructor(){
this.camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 10000 );
this.camera.position.z = 1000;
this.scene = new THREE.Scene();
this.geometry = new THREE.CubeGeometry( 200, 200, 200 );
this.material = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } );
this.mesh = new THREE.Mesh( this.geometry, this.material );
this.scene.add( this.mesh );
this.renderer = new THREE.CanvasRenderer();
this.renderer.setSize( window.innerWidth, window.innerHeight );
$('body').append(this.renderer.domElement);
}
// =========================================================================
// アニメーション
// =========================================================================
animate : Function = ():void=>{
requestAnimationFrame( <any>this.animate );
this.mesh.rotation.x += 0.01;
this.mesh.rotation.y += 0.02;
this.renderer.render( this.scene, this.camera );
};
}
$(()=>{
var sample:Sample = new Sample();
sample.animate();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment