SceneTab.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. module INSPECTOR {
  2. export class SceneTab extends Tab {
  3. private _inspector : Inspector;
  4. /** The list of channels/options that can be activated/deactivated */
  5. private _actions : HTMLDivElement;
  6. /** The list of skeleton viewer */
  7. private _skeletonViewers : Array<BABYLON.Debug.SkeletonViewer> = [];
  8. /** The detail of the scene */
  9. private _detailsPanel : DetailPanel;
  10. constructor(tabbar:TabBar, insp:Inspector) {
  11. super(tabbar, 'Scene');
  12. this._inspector = insp;
  13. // Build the properties panel : a div that will contains the tree and the detail panel
  14. this._panel = Helpers.CreateDiv('tab-panel') as HTMLDivElement;
  15. this._actions = Helpers.CreateDiv('scene-actions', this._panel) as HTMLDivElement;
  16. this._detailsPanel = new DetailPanel();
  17. this._panel.appendChild(this._detailsPanel.toHtml());
  18. // build propertiesline
  19. let details = [];
  20. for (let prop of PROPERTIES['Scene'].properties) {
  21. details.push(new PropertyLine(new Property(prop, this._inspector.scene)));
  22. }
  23. this._detailsPanel.details = details;
  24. Split([this._actions, this._detailsPanel.toHtml()], {
  25. sizes:[50, 50],
  26. direction:'vertical'
  27. });
  28. // Build actions
  29. {
  30. // Rendering mode
  31. let title = Helpers.CreateDiv('actions-title', this._actions);
  32. title.textContent = 'Rendering mode';
  33. let point = Helpers.CreateDiv('action-radio', this._actions);
  34. let wireframe = Helpers.CreateDiv('action-radio', this._actions);
  35. let solid = Helpers.CreateDiv('action-radio', this._actions);
  36. point.textContent = 'Point';
  37. wireframe.textContent = 'Wireframe';
  38. solid.textContent = 'Solid';
  39. if (this._inspector.scene.forcePointsCloud) {
  40. point.classList.add('active');
  41. } else if (this._inspector.scene.forceWireframe) {
  42. wireframe.classList.add('active');
  43. } else {
  44. solid.classList.add('active');
  45. }
  46. this._generateRadioAction([point, wireframe, solid]);
  47. point.addEventListener('click', () => {this._inspector.scene.forcePointsCloud = true; this._inspector.scene.forceWireframe = false;});
  48. wireframe.addEventListener('click', () => {this._inspector.scene.forcePointsCloud = false; this._inspector.scene.forceWireframe = true; });
  49. solid.addEventListener('click', () => {this._inspector.scene.forcePointsCloud = false; this._inspector.scene.forceWireframe = false; });
  50. // Textures
  51. title = Helpers.CreateDiv('actions-title', this._actions);
  52. title.textContent = 'Textures channels';
  53. this._generateActionLine('Diffuse Texture', BABYLON.StandardMaterial.DiffuseTextureEnabled, (b:boolean) => {BABYLON.StandardMaterial.DiffuseTextureEnabled = b });
  54. this._generateActionLine('Ambient Texture', BABYLON.StandardMaterial.AmbientTextureEnabled, (b:boolean) => {BABYLON.StandardMaterial.AmbientTextureEnabled = b });
  55. this._generateActionLine('Specular Texture', BABYLON.StandardMaterial.SpecularTextureEnabled, (b:boolean) => {BABYLON.StandardMaterial.SpecularTextureEnabled = b });
  56. this._generateActionLine('Emissive Texture', BABYLON.StandardMaterial.EmissiveTextureEnabled, (b:boolean) => {BABYLON.StandardMaterial.EmissiveTextureEnabled = b });
  57. this._generateActionLine('Bump Texture', BABYLON.StandardMaterial.BumpTextureEnabled, (b:boolean) => {BABYLON.StandardMaterial.BumpTextureEnabled = b });
  58. this._generateActionLine('Opacity Texture', BABYLON.StandardMaterial.OpacityTextureEnabled, (b:boolean) => {BABYLON.StandardMaterial.OpacityTextureEnabled = b });
  59. this._generateActionLine('Reflection Texture', BABYLON.StandardMaterial.ReflectionTextureEnabled, (b:boolean) => {BABYLON.StandardMaterial.ReflectionTextureEnabled = b });
  60. this._generateActionLine('Refraction Texture', BABYLON.StandardMaterial.RefractionTextureEnabled, (b:boolean) => {BABYLON.StandardMaterial.RefractionTextureEnabled = b });
  61. this._generateActionLine('ColorGrading', BABYLON.StandardMaterial.ColorGradingTextureEnabled, (b:boolean) => {BABYLON.StandardMaterial.ColorGradingTextureEnabled = b });
  62. this._generateActionLine('Lightmap Texture', BABYLON.StandardMaterial.LightmapTextureEnabled, (b:boolean) => {BABYLON.StandardMaterial.LightmapTextureEnabled = b });
  63. this._generateActionLine('Fresnel', BABYLON.StandardMaterial.FresnelEnabled, (b:boolean) => {BABYLON.StandardMaterial.FresnelEnabled = b });
  64. // Options
  65. title = Helpers.CreateDiv('actions-title', this._actions);
  66. title.textContent = 'Options';
  67. this._generateActionLine('Animations', this._inspector.scene.animationsEnabled, (b:boolean) => {this._inspector.scene.animationsEnabled = b });
  68. this._generateActionLine('Collisions', this._inspector.scene.collisionsEnabled, (b:boolean) => {this._inspector.scene.collisionsEnabled = b });
  69. this._generateActionLine('Fog', this._inspector.scene.fogEnabled, (b:boolean) => {this._inspector.scene.fogEnabled = b });
  70. this._generateActionLine('Lens flares', this._inspector.scene.lensFlaresEnabled, (b:boolean) => {this._inspector.scene.lensFlaresEnabled = b });
  71. this._generateActionLine('Lights', this._inspector.scene.lightsEnabled, (b:boolean) => {this._inspector.scene.lightsEnabled = b });
  72. this._generateActionLine('Particles', this._inspector.scene.particlesEnabled, (b:boolean) => {this._inspector.scene.particlesEnabled = b });
  73. this._generateActionLine('Post-processes', this._inspector.scene.postProcessesEnabled, (b:boolean) => {this._inspector.scene.postProcessesEnabled = b });
  74. this._generateActionLine('Probes', this._inspector.scene.probesEnabled, (b:boolean) => {this._inspector.scene.probesEnabled = b });
  75. this._generateActionLine('Procedural textures', this._inspector.scene.proceduralTexturesEnabled, (b:boolean) => {this._inspector.scene.proceduralTexturesEnabled = b });
  76. this._generateActionLine('Render targets', this._inspector.scene.renderTargetsEnabled, (b:boolean) => {this._inspector.scene.renderTargetsEnabled = b });
  77. this._generateActionLine('Shadows', this._inspector.scene.shadowsEnabled, (b:boolean) => {this._inspector.scene.shadowsEnabled = b });
  78. this._generateActionLine('Skeletons', this._inspector.scene.skeletonsEnabled, (b:boolean) => {this._inspector.scene.skeletonsEnabled = b });
  79. this._generateActionLine('Sprites', this._inspector.scene.spritesEnabled, (b:boolean) => {this._inspector.scene.spritesEnabled = b });
  80. this._generateActionLine('Textures', this._inspector.scene.texturesEnabled, (b:boolean) => {this._inspector.scene.texturesEnabled = b });
  81. // Audio
  82. title = Helpers.CreateDiv('actions-title', this._actions);
  83. title.textContent = 'Audio';
  84. let headphones = Helpers.CreateDiv('action-radio', this._actions);
  85. let normalSpeaker = Helpers.CreateDiv('action-radio', this._actions);
  86. this._generateActionLine('Disable audio', !this._inspector.scene.audioEnabled, (b:boolean) => {this._inspector.scene.audioEnabled = !b });
  87. headphones.textContent = 'Headphones';
  88. normalSpeaker.textContent = 'Normal speakers';
  89. this._generateRadioAction([headphones, normalSpeaker]);
  90. if (this._inspector.scene.headphone) {
  91. headphones.classList.add('active');
  92. } else {
  93. normalSpeaker.classList.add('active');
  94. }
  95. headphones.addEventListener('click', () => {this._inspector.scene.headphone = true;});
  96. normalSpeaker.addEventListener('click', () => {this._inspector.scene.headphone = false;});
  97. // Viewers
  98. title = Helpers.CreateDiv('actions-title', this._actions);
  99. title.textContent = 'Viewer';
  100. this._generateActionLine('Skeletons', false, (b:boolean) => {
  101. if (b) {
  102. for (var index = 0; index < this._inspector.scene.meshes.length; index++) {
  103. var mesh = this._inspector.scene.meshes[index];
  104. if (mesh.skeleton) {
  105. var found = false;
  106. for (var sIndex = 0; sIndex < this._skeletonViewers.length; sIndex++) {
  107. if (this._skeletonViewers[sIndex].skeleton === mesh.skeleton) {
  108. found = true;
  109. break;
  110. }
  111. }
  112. if (found) {
  113. continue;
  114. }
  115. var viewer = new BABYLON.Debug.SkeletonViewer(mesh.skeleton, mesh, this._inspector.scene);
  116. viewer.isEnabled = true;
  117. this._skeletonViewers.push(viewer);
  118. }
  119. }
  120. } else {
  121. for (var index = 0; index < this._skeletonViewers.length; index++) {
  122. this._skeletonViewers[index].dispose();
  123. }
  124. this._skeletonViewers = [];
  125. }
  126. });
  127. }
  128. }
  129. /** Overrides super.dispose */
  130. public dispose() {
  131. this._detailsPanel.dispose();
  132. }
  133. /** generates a div which correspond to an option that can be activated/deactivated */
  134. private _generateActionLine(name:string, initValue:boolean, action:(b:boolean) => void) {
  135. let div = Helpers.CreateDiv('scene-actions', this._actions);
  136. div.textContent = name;
  137. div.classList.add('action');
  138. if (initValue) {
  139. div.classList.add('active');
  140. }
  141. div.addEventListener('click', (e) => {
  142. div.classList.toggle('active');
  143. let isActivated = div.classList.contains('active');
  144. action(isActivated);
  145. })
  146. }
  147. /**
  148. * Add a click action for all given elements :
  149. * the clicked element is set as active, all others elements are deactivated
  150. */
  151. private _generateRadioAction(arr:Array<HTMLElement>) {
  152. let active = (elem, evt) => {
  153. for (let e of arr) {
  154. e.classList.remove('active');
  155. }
  156. elem.classList.add('active');
  157. }
  158. for (let elem of arr) {
  159. elem.addEventListener('click', active.bind(this, elem));
  160. }
  161. }
  162. }
  163. }