index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. let DDSTexture = new BABYLON.CubeTexture("test/environment.dds", scene);
  48. let DDSTexture2 = new BABYLON.Texture("test/test_1.dds", scene);
  49. // Our built-in 'ground' shape. Params: name, width, depth, subdivs, scene
  50. var ground = BABYLON.Mesh.CreateGround("node_damagedHelmet_-6514", 6, 6, 2, scene);
  51. ground.parent = tn;
  52. let num = 5;
  53. let angStep = 6.283185307 / num;
  54. let rad = 2;
  55. let p = sceneRoot;
  56. for (let i = 0; i < num; i++) {
  57. // Our built-in 'sphere' shape. Params: name, subdivs, size, scene
  58. let sphere = BABYLON.Mesh.CreateSphere('sphere' + i, 16, 2, scene);
  59. // Move the sphere upward 1/2 its height
  60. sphere.position.y = 0.2;
  61. sphere.position.x = Math.sin(i * angStep) * rad;
  62. sphere.position.z = Math.cos(i * angStep) * rad;
  63. sphere.parent = p;
  64. p = sphere;
  65. }
  66. let t = 0;
  67. scene.registerBeforeRender(() => {
  68. ground.rotation.y += 0.01;
  69. ground.position.y = Math.cos(t += 0.01);
  70. });
  71. scene.createDefaultCameraOrLight(true);
  72. scene.activeCamera.attachControl(canvas);
  73. scene.debugLayer.show();
  74. scene.debugLayer.onPropertyChangedObservable.add((result) => {
  75. console.log(result.object);
  76. console.log("Property : " + result.property);
  77. console.log("New value : " + result.value);
  78. console.log("Old value : " + result.initialValue);
  79. });
  80. this.scene = scene;
  81. };
  82. return Test;
  83. }());