index.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 sceneRoot = new BABYLON.AbstractMesh("SceneRoot");
  38. // Our built-in 'ground' shape. Params: name, width, depth, subdivs, scene
  39. var ground = BABYLON.Mesh.CreateGround("node_damagedHelmet_-6514", 6, 6, 2, scene);
  40. ground.parent = sceneRoot;
  41. let num = 5;
  42. let angStep = 6.283185307 / num;
  43. let rad = 2;
  44. let p = ground;
  45. for (let i = 0; i < num; i++) {
  46. // Our built-in 'sphere' shape. Params: name, subdivs, size, scene
  47. let sphere = BABYLON.Mesh.CreateSphere(`sphere${i}`, 16, 2, scene);
  48. // Move the sphere upward 1/2 its height
  49. sphere.position.y = 0.2;
  50. sphere.position.x = Math.sin(i * angStep) * rad;
  51. sphere.position.z = Math.cos(i * angStep) * rad;
  52. sphere.parent = p;
  53. p = sphere;
  54. }
  55. scene.createDefaultCameraOrLight(true);
  56. scene.activeCamera.attachControl(canvas);
  57. this.scene = scene;
  58. };
  59. return Test;
  60. }());