babylon.debugLayer.ts 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. module BABYLON {
  2. // declare INSPECTOR namespace for compilation issue
  3. declare var INSPECTOR: any;
  4. // load the inspector using require, if not present in the global namespace.
  5. export class DebugLayer {
  6. private _scene: Scene;
  7. public static InspectorURL = 'https://preview.babylonjs.com/inspector/babylon.inspector.bundle.js';
  8. // The inspector instance
  9. private _inspector: any;
  10. private BJSINSPECTOR = typeof INSPECTOR !== 'undefined' ? INSPECTOR : undefined;
  11. constructor(scene: Scene) {
  12. this._scene = scene;
  13. // load inspector using require, if it doesn't exist on the global namespace.
  14. }
  15. /** Creates the inspector window. */
  16. private _createInspector(config: {
  17. popup?: boolean,
  18. initialTab?: number,
  19. parentElement?: HTMLElement,
  20. newColors?: {
  21. backgroundColor?: string,
  22. backgroundColorLighter?: string,
  23. backgroundColorLighter2?: string,
  24. backgroundColorLighter3?: string,
  25. color?: string,
  26. colorTop?: string,
  27. colorBot?: string
  28. }
  29. } = {}) {
  30. let popup = config.popup || false;
  31. let initialTab = config.initialTab || 0;
  32. let parentElement = config.parentElement || null;
  33. if (!this._inspector) {
  34. this.BJSINSPECTOR = this.BJSINSPECTOR || typeof INSPECTOR !== 'undefined' ? INSPECTOR : undefined;
  35. this._inspector = new this.BJSINSPECTOR.Inspector(this._scene, popup, initialTab, parentElement, config.newColors);
  36. } // else nothing to do,; instance is already existing
  37. }
  38. public isVisible(): boolean {
  39. if (!this._inspector) {
  40. return false;
  41. }
  42. return true;
  43. }
  44. public hide() {
  45. if (this._inspector) {
  46. try {
  47. this._inspector.dispose();
  48. } catch (e) {
  49. // If the inspector has been removed directly from the inspector tool
  50. }
  51. this._inspector = null;
  52. }
  53. }
  54. public show(config: {
  55. popup?: boolean,
  56. initialTab?: number,
  57. parentElement?: HTMLElement,
  58. newColors?: {
  59. backgroundColor?: string,
  60. backgroundColorLighter?: string,
  61. backgroundColorLighter2?: string,
  62. backgroundColorLighter3?: string,
  63. color?: string,
  64. colorTop?: string,
  65. colorBot?: string
  66. }
  67. } = {}) {
  68. if (typeof this.BJSINSPECTOR == 'undefined') {
  69. // Load inspector and add it to the DOM
  70. Tools.LoadScript(DebugLayer.InspectorURL, this._createInspector.bind(this, config));
  71. } else {
  72. // Otherwise creates the inspector
  73. this._createInspector(config);
  74. }
  75. }
  76. /**
  77. * Gets the active tab
  78. * @return the index of the active tab or -1 if the inspector is hidden
  79. */
  80. public getActiveTab(): number {
  81. return this._inspector ? this._inspector.getActiveTabIndex() : -1;
  82. }
  83. }
  84. }