babylon.debugLayer.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. module BABYLON {
  2. // declare INSPECTOR namespace for compilation issue
  3. declare var INSPECTOR: any;
  4. export class DebugLayer {
  5. private _scene: Scene;
  6. // Get protocol used - http or https
  7. public static InspectorURL = window.location.href.split('/')[0] + '//www.babylonjs.com/babylon.inspector.bundle.js';
  8. // The inspector instance
  9. private _inspector: any;
  10. constructor(scene: Scene) {
  11. this._scene = scene;
  12. }
  13. /** Creates the inspector window. */
  14. private _createInspector(config: {
  15. popup?: boolean,
  16. initialTab?: number,
  17. parentElement?: HTMLElement,
  18. newColors?: {
  19. backgroundColor?: string,
  20. backgroundColorLighter?: string,
  21. backgroundColorLighter2?: string,
  22. backgroundColorLighter3?: string,
  23. color?: string,
  24. colorTop?: string,
  25. colorBot?: string
  26. }
  27. } = {}) {
  28. let popup = config.popup || false;
  29. let initialTab = config.initialTab || 0;
  30. let parentElement = config.parentElement || null;
  31. if (!this._inspector) {
  32. this._inspector = new INSPECTOR.Inspector(this._scene, popup, initialTab, parentElement, config.newColors);
  33. } // else nothing to do,; instance is already existing
  34. }
  35. public isVisible(): boolean {
  36. if (!this._inspector) {
  37. return false;
  38. }
  39. return true;
  40. }
  41. public hide() {
  42. if (this._inspector) {
  43. this._inspector.dispose();
  44. this._inspector = null;
  45. }
  46. }
  47. public show(config: {
  48. popup?: boolean,
  49. initialTab?: number,
  50. parentElement?: HTMLElement,
  51. newColors?: {
  52. backgroundColor?: string,
  53. backgroundColorLighter?: string,
  54. backgroundColorLighter2?: string,
  55. backgroundColorLighter3?: string,
  56. color?: string,
  57. colorTop?: string,
  58. colorBot?: string
  59. }
  60. } = {}) {
  61. if (typeof INSPECTOR == 'undefined') {
  62. // Load inspector and add it to the DOM
  63. Tools.LoadScript(DebugLayer.InspectorURL, this._createInspector.bind(this, config));
  64. } else {
  65. // Otherwise creates the inspector
  66. this._createInspector(config);
  67. }
  68. }
  69. }
  70. }