SceneTab.js 12 KB

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