babylon.debugLayer.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. public onPropertyChangedObservable: BABYLON.Observable<{ object: any, property: string, value: any, initialValue: any }>;
  12. constructor(scene: Scene) {
  13. this._scene = scene;
  14. // load inspector using require, if it doesn't exist on the global namespace.
  15. }
  16. /** Creates the inspector window. */
  17. private _createInspector(config: {
  18. popup?: boolean,
  19. initialTab?: number,
  20. parentElement?: HTMLElement,
  21. newColors?: {
  22. backgroundColor?: string,
  23. backgroundColorLighter?: string,
  24. backgroundColorLighter2?: string,
  25. backgroundColorLighter3?: string,
  26. color?: string,
  27. colorTop?: string,
  28. colorBot?: string
  29. }
  30. } = {}) {
  31. let popup = config.popup || false;
  32. let initialTab = config.initialTab || 0;
  33. let parentElement = config.parentElement || null;
  34. if (!this._inspector) {
  35. this.BJSINSPECTOR = this.BJSINSPECTOR || typeof INSPECTOR !== 'undefined' ? INSPECTOR : undefined;
  36. this._inspector = new this.BJSINSPECTOR.Inspector(this._scene, popup, initialTab, parentElement, config.newColors);
  37. } // else nothing to do,; instance is already existing
  38. }
  39. public isVisible(): boolean {
  40. if (!this._inspector) {
  41. return false;
  42. }
  43. return true;
  44. }
  45. public hide() {
  46. if (this._inspector) {
  47. try {
  48. this._inspector.dispose();
  49. } catch (e) {
  50. // If the inspector has been removed directly from the inspector tool
  51. }
  52. this.onPropertyChangedObservable.clear();
  53. this._inspector = null;
  54. }
  55. }
  56. /**
  57. *
  58. * Launch the debugLayer.
  59. *
  60. * initialTab:
  61. * | Value | Tab Name |
  62. * | --- | --- |
  63. * | 0 | Scene |
  64. * | 1 | Console |
  65. * | 2 | Stats |
  66. * | 3 | Textures |
  67. * | 4 | Mesh |
  68. * | 5 | Light |
  69. * | 6 | Material |
  70. * | 7 | GLTF |
  71. * | 8 | GUI |
  72. * | 9 | Physics |
  73. * | 10 | Camera |
  74. * | 11 | Audio |
  75. *
  76. */
  77. public show(config: {
  78. popup?: boolean,
  79. initialTab?: number,
  80. parentElement?: HTMLElement,
  81. newColors?: {
  82. backgroundColor?: string,
  83. backgroundColorLighter?: string,
  84. backgroundColorLighter2?: string,
  85. backgroundColorLighter3?: string,
  86. color?: string,
  87. colorTop?: string,
  88. colorBot?: string
  89. }
  90. } = {}) {
  91. if (typeof this.BJSINSPECTOR == 'undefined') {
  92. // Load inspector and add it to the DOM
  93. Tools.LoadScript(DebugLayer.InspectorURL, this._createInspector.bind(this, config));
  94. } else {
  95. // Otherwise creates the inspector
  96. this._createInspector(config);
  97. this.onPropertyChangedObservable = new BABYLON.Observable<{ object: any, property: string, value: any, initialValue: any }>();
  98. }
  99. }
  100. /**
  101. * Gets the active tab
  102. * @return the index of the active tab or -1 if the inspector is hidden
  103. */
  104. public getActiveTab(): number {
  105. return this._inspector ? this._inspector.getActiveTabIndex() : -1;
  106. }
  107. }
  108. }