SceneTab.ts 12 KB

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