Advertisement
julong

fixed bug threejs

Jul 27th, 2014
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. ///<reference path="./three.d.ts"/>
  2.  
  3. class ThreeJSTest {
  4. renderer:THREE.WebGLRenderer;
  5. scene:THREE.Scene;
  6. camera:THREE.Camera;
  7.  
  8. constructor() {
  9. this.renderer = new THREE.WebGLRenderer({ alpha: true });
  10.  
  11. this.renderer.setSize(500, 500);
  12. this.renderer.setClearColor(0xFFFFFF, 1);
  13.  
  14. document.getElementById('content').appendChild(this.renderer.domElement);
  15.  
  16. this.scene = new THREE.Scene();
  17.  
  18. this.camera = new THREE.PerspectiveCamera(75
  19. , 1
  20. , 0.1, 1000);
  21.  
  22. this.camera.position = new THREE.Vector3(10, 0, 10);
  23. this.camera.lookAt(new THREE.Vector3(0, 0, 0));
  24.  
  25.  
  26. // New code begins below
  27. // Create a loader to load in the JSON file
  28. var modelLoader = new THREE.JSONLoader();
  29.  
  30. // Call the load method, passing in the name of our generated JSON file
  31. // and a callback for when loadign is complete.
  32. // Not fat arrow typescript call for proper thisification. AKA, we want
  33. this to be this, not that
  34. // or something else completely
  35. modelLoader.load("robot.jsm", (geometry,materials) => {
  36. // create a mesh using the passed in geometry and textures
  37. var mesh = new THREE.SkinnedMesh(geometry,new THREE.MeshFaceMaterial(
  38. materials));
  39. mesh.position.x = 0; mesh.position.y = mesh.position.z = 0;
  40. // add it to the scene
  41. this.scene.add(mesh);
  42. });
  43.  
  44. this.scene.add(new THREE.AmbientLight(new THREE.Color(0.9,0.9,0.9).
  45. getHex()));
  46. this.renderer.render(this.scene, this.camera);
  47. }
  48.  
  49. render() {
  50. requestAnimationFrame(() => this.render());
  51. this.renderer.render(this.scene, this.camera);
  52. }
  53.  
  54. start() {
  55. this.render();
  56. }
  57. }
  58.  
  59. window.onload = () => {
  60. var three = new ThreeJSTest();
  61. three.start();
  62. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement