parksangkil / simple-angular4-threejs

:rocket: simple-angular4-threejs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ng new angular-three
cd angular-three
npm install --save three
npm install --save-dev @types/three
import threejs : app.component.ts - top line
import * as THREE from 'three';
get element : app.component.ts - html division
private container : HTMLElement;

@ViewChild('container') elementRef: ElementRef;
this.container = this.elementRef.nativeElement;
screen initialize : app.component.ts - init()
private scene: THREE.Scene;
private camera: THREE.PerspectiveCamera;
private renderer: THREE.WebGLRenderer;

this.scene = new THREE.Scene();
this.camera = new THREE.PerspectiveCamera(view.angle, view.aspect, view. near, view.far);
this.renderer = new THREE.WebGLRenderer();
 
this.renderer.setSize(screen.width, screen.height);
this.container.appendChild(this.renderer.domElement);
animate loop : app.component.ts - render()
this.render();

render(){
  let self: AppComponent = this;
  (function render(){
    requestAnimationFrame(render);
    self.renderer.render(self.scene, self.camera);
    
    self.animate();
  }());
}

animate(){
  console.log('animate');
}

About

:rocket: simple-angular4-threejs


Languages

Language:TypeScript 76.2%Language:JavaScript 19.8%Language:HTML 3.2%Language:CSS 0.8%