index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.debugLayer.show();
  17. this.scene.executeWhenReady(function() {
  18. _this.engine.runRenderLoop(function() {
  19. _this.scene.render();
  20. });
  21. });
  22. };
  23. Test.prototype._initScene = function() {
  24. var scene = new BABYLON.Scene(this.engine);
  25. var canvas = scene.getEngine().getRenderingCanvas();
  26. var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 2, -2), scene);
  27. var camera2 = new BABYLON.ArcRotateCamera("Camera2", 0, 0, 5, new BABYLON.Vector3(0, 0, 0), scene);
  28. var camera3 = new BABYLON.ArcRotateCamera("Camera3", 0, 0, 10, new BABYLON.Vector3(0, 0, 0), scene);
  29. var camera4 = new BABYLON.ArcRotateCamera("Camera4", 0, 0, 15, new BABYLON.Vector3(0, 0, 0), scene);
  30. var camera5 = new BABYLON.ArcRotateCamera("Camera5", 0, 0, 20, new BABYLON.Vector3(0, 0, 0), scene);
  31. var camera6 = new BABYLON.ArcRotateCamera("Camera6", 0, 0, 25, new BABYLON.Vector3(0, 0, 0), scene);
  32. scene.activeCamera = camera2;
  33. camera2.attachControl(canvas);
  34. var sceneRoot = new BABYLON.TransformNode("abstractmesh");
  35. var tn = new BABYLON.TransformNode("transform node");
  36. let DDSTexture = new BABYLON.CubeTexture("test/environment.dds", scene);
  37. let DDSTexture2 = new BABYLON.Texture("test/test_1.dds", scene);
  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 = tn;
  41. let num = 5;
  42. let angStep = 6.283185307 / num;
  43. let rad = 2;
  44. let p = sceneRoot;
  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. let t = 0;
  56. scene.registerBeforeRender(() => {
  57. ground.rotation.y += 0.01;
  58. ground.position.y = Math.cos(t += 0.01);
  59. });
  60. scene.createDefaultCameraOrLight(true);
  61. scene.activeCamera.attachControl(canvas);
  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. }());