index.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  2. var Test = (function () {
  3. function Test(canvasId) {
  4. var _this = this;
  5. var canvas = document.getElementById(canvasId);
  6. this.engine = new BABYLON.Engine(canvas, true);
  7. // BABYLONDEVTOOLS.Loader.debugShortcut(this.engine);
  8. this.scene = null;
  9. window.addEventListener("resize", function () {
  10. _this.engine.resize();
  11. });
  12. this._run();
  13. }
  14. Test.prototype._run = function () {
  15. var _this = this;
  16. this._initScene();
  17. // this.scene.debugLayer.show({
  18. // popup: false,
  19. // parentElement: document.getElementById('inspector'),
  20. // newColors: {
  21. // backgroundColor: '#eee',
  22. // backgroundColorLighter: '#fff',
  23. // backgroundColorLighter2: '#fff',
  24. // backgroundColorLighter3: '#fff',
  25. // color: '#333'
  26. // }
  27. // });
  28. this.scene.executeWhenReady(function () {
  29. _this.engine.runRenderLoop(function () {
  30. _this.scene.render();
  31. });
  32. });
  33. };
  34. Test.prototype._initScene = function () {
  35. var scene = new BABYLON.Scene(this.engine);
  36. var canvas = scene.getEngine().getRenderingCanvas();
  37. var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 2, -2), scene);
  38. var camera2 = new BABYLON.ArcRotateCamera("Camera2", 0, 0, 5, new BABYLON.Vector3(0, 0, 0), scene);
  39. var camera3 = new BABYLON.ArcRotateCamera("Camera3", 0, 0, 10, new BABYLON.Vector3(0, 0, 0), scene);
  40. var camera4 = new BABYLON.ArcRotateCamera("Camera4", 0, 0, 15, new BABYLON.Vector3(0, 0, 0), scene);
  41. var camera5 = new BABYLON.ArcRotateCamera("Camera5", 0, 0, 20, new BABYLON.Vector3(0, 0, 0), scene);
  42. var camera6 = new BABYLON.ArcRotateCamera("Camera6", 0, 0, 25, new BABYLON.Vector3(0, 0, 0), scene);
  43. scene.activeCamera = camera2;
  44. camera2.attachControl(canvas);
  45. var sceneRoot = new BABYLON.TransformNode("abstractmesh");
  46. var tn = new BABYLON.TransformNode("transform node");
  47. // Our built-in 'ground' shape. Params: name, width, depth, subdivs, scene
  48. var ground = BABYLON.Mesh.CreateGround("node_damagedHelmet_-6514", 6, 6, 2, scene);
  49. ground.parent = tn;
  50. let num = 5;
  51. let angStep = 6.283185307 / num;
  52. let rad = 2;
  53. let p = sceneRoot;
  54. for (let i = 0; i < num; i++) {
  55. // Our built-in 'sphere' shape. Params: name, subdivs, size, scene
  56. let sphere = BABYLON.Mesh.CreateSphere('sphere' + i, 16, 2, scene);
  57. // Move the sphere upward 1/2 its height
  58. sphere.position.y = 0.2;
  59. sphere.position.x = Math.sin(i * angStep) * rad;
  60. sphere.position.z = Math.cos(i * angStep) * rad;
  61. sphere.parent = p;
  62. p = sphere;
  63. }
  64. let t = 0;
  65. scene.registerBeforeRender(() => {
  66. ground.rotation.y += 0.01;
  67. ground.position.y = Math.cos(t += 0.01);
  68. });
  69. scene.createDefaultCameraOrLight(true);
  70. scene.activeCamera.attachControl(canvas);
  71. scene.debugLayer.show();
  72. this.scene = scene;
  73. };
  74. return Test;
  75. }());