index.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. this.scene = null;
  8. window.addEventListener("resize", function() {
  9. _this.engine.resize();
  10. });
  11. this._run();
  12. }
  13. Test.prototype._run = function() {
  14. var _this = this;
  15. this._initScene();
  16. this.scene.executeWhenReady(function() {
  17. _this.engine.runRenderLoop(function() {
  18. _this.scene.render();
  19. });
  20. });
  21. };
  22. Test.prototype._initScene = function() {
  23. var scene = new BABYLON.Scene(this.engine);
  24. var canvas = scene.getEngine().getRenderingCanvas();
  25. var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 2, -2), scene);
  26. var camera2 = new BABYLON.ArcRotateCamera("Camera2", 0, 0, 5, new BABYLON.Vector3(0, 0, 0), scene);
  27. var camera3 = new BABYLON.ArcRotateCamera("Camera3", 0, 0, 10, new BABYLON.Vector3(0, 0, 0), scene);
  28. var camera4 = new BABYLON.ArcRotateCamera("Camera4", 0, 0, 15, new BABYLON.Vector3(0, 0, 0), scene);
  29. var camera5 = new BABYLON.ArcRotateCamera("Camera5", 0, 0, 20, new BABYLON.Vector3(0, 0, 0), scene);
  30. var camera6 = new BABYLON.ArcRotateCamera("Camera6", 0, 0, 25, new BABYLON.Vector3(0, 0, 0), scene);
  31. scene.activeCamera = camera2;
  32. camera2.attachControl(canvas);
  33. var sceneRoot = new BABYLON.TransformNode("abstractmesh");
  34. var tn = new BABYLON.TransformNode("transform node");
  35. let DDSTexture = new BABYLON.CubeTexture("test/environment.dds", scene);
  36. let DDSTexture2 = new BABYLON.Texture("test/test_1.dds", scene);
  37. // Our built-in 'ground' shape. Params: name, width, depth, subdivs, scene
  38. var ground = BABYLON.Mesh.CreateGround("node_damagedHelmet_-6514", 6, 6, 2, scene);
  39. ground.parent = tn;
  40. let num = 5;
  41. let angStep = 6.283185307 / num;
  42. let rad = 2;
  43. let p = sceneRoot;
  44. for (let i = 0; i < num; i++) {
  45. // Our built-in 'sphere' shape. Params: name, subdivs, size, scene
  46. let sphere = BABYLON.Mesh.CreateSphere('sphere' + i, 16, 2, scene);
  47. // Move the sphere upward 1/2 its height
  48. sphere.position.y = 0.2;
  49. sphere.position.x = Math.sin(i * angStep) * rad;
  50. sphere.position.z = Math.cos(i * angStep) * rad;
  51. sphere.parent = p;
  52. p = sphere;
  53. }
  54. let t = 0;
  55. scene.registerBeforeRender(() => {
  56. ground.rotation.y += 0.01;
  57. ground.position.y = Math.cos(t += 0.01);
  58. });
  59. scene.createDefaultCameraOrLight(true);
  60. scene.activeCamera.attachControl(canvas);
  61. scene.debugLayer.show({embedMode: true});
  62. //scene.debugLayer.show();
  63. scene.debugLayer.onPropertyChangedObservable.add((result) => {
  64. console.log(result.object);
  65. console.log("Property : " + result.property);
  66. console.log("New value : " + result.value);
  67. console.log("Old value : " + result.initialValue);
  68. });
  69. this.scene = scene;
  70. };
  71. return Test;
  72. }());