babylon.debugLayer.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var DebugLayer = (function () {
  4. function DebugLayer(scene) {
  5. var _this = this;
  6. this._enabled = false;
  7. this._labelsEnabled = false;
  8. this._displayStatistics = true;
  9. this._displayTree = false;
  10. this._displayLogs = false;
  11. this._identityMatrix = BABYLON.Matrix.Identity();
  12. this.axisRatio = 0.02;
  13. this._scene = scene;
  14. this._syncPositions = function () {
  15. var engine = _this._scene.getEngine();
  16. var canvasRect = engine.getRenderingCanvasClientRect();
  17. if (_this._showUI) {
  18. _this._statsDiv.style.left = (canvasRect.width - 310) + "px";
  19. _this._statsDiv.style.top = (canvasRect.height - 370) + "px";
  20. _this._statsDiv.style.width = "300px";
  21. _this._statsDiv.style.height = "360px";
  22. _this._statsSubsetDiv.style.maxHeight = (canvasRect.height - 60) + "px";
  23. _this._optionsDiv.style.left = "0px";
  24. _this._optionsDiv.style.top = "10px";
  25. _this._optionsDiv.style.width = "200px";
  26. _this._optionsDiv.style.height = "auto";
  27. _this._optionsSubsetDiv.style.maxHeight = (canvasRect.height - 225) + "px";
  28. _this._logDiv.style.left = "0px";
  29. _this._logDiv.style.top = (canvasRect.height - 170) + "px";
  30. _this._logDiv.style.width = "600px";
  31. _this._logDiv.style.height = "160px";
  32. _this._treeDiv.style.left = (canvasRect.width - 310) + "px";
  33. _this._treeDiv.style.top = "10px";
  34. _this._treeDiv.style.width = "300px";
  35. _this._treeDiv.style.height = "auto";
  36. _this._treeSubsetDiv.style.maxHeight = (canvasRect.height - 490) + "px";
  37. }
  38. _this._globalDiv.style.left = canvasRect.left + "px";
  39. _this._globalDiv.style.top = canvasRect.top + "px";
  40. _this._drawingCanvas.style.left = "0px";
  41. _this._drawingCanvas.style.top = "0px";
  42. _this._drawingCanvas.style.width = engine.getRenderWidth() + "px";
  43. _this._drawingCanvas.style.height = engine.getRenderHeight() + "px";
  44. var devicePixelRatio = window.devicePixelRatio || 1;
  45. var context = _this._drawingContext;
  46. var backingStoreRatio = context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio || context.msBackingStorePixelRatio || context.oBackingStorePixelRatio || context.backingStorePixelRatio || 1;
  47. _this._ratio = devicePixelRatio / backingStoreRatio;
  48. _this._drawingCanvas.width = engine.getRenderWidth() * _this._ratio;
  49. _this._drawingCanvas.height = engine.getRenderHeight() * _this._ratio;
  50. };
  51. this._onCanvasClick = function (evt) {
  52. _this._clickPosition = {
  53. x: evt.clientX * _this._ratio,
  54. y: evt.clientY * _this._ratio
  55. };
  56. };
  57. this._syncData = function () {
  58. if (_this._showUI) {
  59. if (_this._displayStatistics) {
  60. _this._displayStats();
  61. _this._statsDiv.style.display = "";
  62. } else {
  63. _this._statsDiv.style.display = "none";
  64. }
  65. if (_this._displayLogs) {
  66. _this._logDiv.style.display = "";
  67. } else {
  68. _this._logDiv.style.display = "none";
  69. }
  70. if (_this._displayTree) {
  71. _this._treeDiv.style.display = "";
  72. if (_this._needToRefreshMeshesTree) {
  73. _this._needToRefreshMeshesTree = false;
  74. _this._refreshMeshesTreeContent();
  75. }
  76. } else {
  77. _this._treeDiv.style.display = "none";
  78. }
  79. }
  80. if (_this._labelsEnabled || !_this._showUI) {
  81. _this._drawingContext.clearRect(0, 0, _this._drawingCanvas.width, _this._drawingCanvas.height);
  82. var engine = _this._scene.getEngine();
  83. var viewport = _this._scene.activeCamera.viewport;
  84. var globalViewport = viewport.toGlobal(engine);
  85. // Meshes
  86. var meshes = _this._scene.getActiveMeshes();
  87. for (var index = 0; index < meshes.length; index++) {
  88. var mesh = meshes.data[index];
  89. var position = mesh.getBoundingInfo().boundingSphere.center;
  90. var projectedPosition = BABYLON.Vector3.Project(position, mesh.getWorldMatrix(), _this._scene.getTransformMatrix(), globalViewport);
  91. if (mesh.renderOverlay || _this.shouldDisplayAxis && _this.shouldDisplayAxis(mesh)) {
  92. _this._renderAxis(projectedPosition, mesh, globalViewport);
  93. }
  94. if (!_this.shouldDisplayLabel || _this.shouldDisplayLabel(mesh)) {
  95. _this._renderLabel(mesh.name, projectedPosition, 12, function () {
  96. mesh.renderOverlay = !mesh.renderOverlay;
  97. }, function () {
  98. return mesh.renderOverlay ? 'red' : 'black';
  99. });
  100. }
  101. }
  102. // Cameras
  103. var cameras = _this._scene.cameras;
  104. for (index = 0; index < cameras.length; index++) {
  105. var camera = cameras[index];
  106. if (camera === _this._scene.activeCamera) {
  107. continue;
  108. }
  109. projectedPosition = BABYLON.Vector3.Project(BABYLON.Vector3.Zero(), camera.getWorldMatrix(), _this._scene.getTransformMatrix(), globalViewport);
  110. if (!_this.shouldDisplayLabel || _this.shouldDisplayLabel(camera)) {
  111. _this._renderLabel(camera.name, projectedPosition, 12, function () {
  112. _this._scene.activeCamera.detachControl(engine.getRenderingCanvas());
  113. _this._scene.activeCamera = camera;
  114. _this._scene.activeCamera.attachControl(engine.getRenderingCanvas());
  115. }, function () {
  116. return "purple";
  117. });
  118. }
  119. }
  120. // Lights
  121. var lights = _this._scene.lights;
  122. for (index = 0; index < lights.length; index++) {
  123. var light = lights[index];
  124. if (light.position) {
  125. projectedPosition = BABYLON.Vector3.Project(light.getAbsolutePosition(), _this._identityMatrix, _this._scene.getTransformMatrix(), globalViewport);
  126. if (!_this.shouldDisplayLabel || _this.shouldDisplayLabel(light)) {
  127. _this._renderLabel(light.name, projectedPosition, -20, function () {
  128. light.setEnabled(!light.isEnabled());
  129. }, function () {
  130. return light.isEnabled() ? "orange" : "gray";
  131. });
  132. }
  133. }
  134. }
  135. }
  136. _this._clickPosition = undefined;
  137. };
  138. }
  139. DebugLayer.prototype._refreshMeshesTreeContent = function () {
  140. while (this._treeSubsetDiv.hasChildNodes()) {
  141. this._treeSubsetDiv.removeChild(this._treeSubsetDiv.lastChild);
  142. }
  143. // Add meshes
  144. var sortedArray = this._scene.meshes.slice(0, this._scene.meshes.length);
  145. sortedArray.sort(function (a, b) {
  146. if (a.name === b.name) {
  147. return 0;
  148. }
  149. return (a.name > b.name) ? 1 : -1;
  150. });
  151. for (var index = 0; index < sortedArray.length; index++) {
  152. var mesh = sortedArray[index];
  153. if (!mesh.isEnabled()) {
  154. continue;
  155. }
  156. this._generateAdvancedCheckBox(this._treeSubsetDiv, mesh.name, mesh.getTotalVertices() + " verts", mesh.isVisible, function (element, mesh) {
  157. mesh.isVisible = element.checked;
  158. }, mesh);
  159. }
  160. };
  161. DebugLayer.prototype._renderSingleAxis = function (zero, unit, unitText, label, color) {
  162. this._drawingContext.beginPath();
  163. this._drawingContext.moveTo(zero.x, zero.y);
  164. this._drawingContext.lineTo(unit.x, unit.y);
  165. this._drawingContext.strokeStyle = color;
  166. this._drawingContext.lineWidth = 4;
  167. this._drawingContext.stroke();
  168. this._drawingContext.font = "normal 14px Segoe UI";
  169. this._drawingContext.fillStyle = color;
  170. this._drawingContext.fillText(label, unitText.x, unitText.y);
  171. };
  172. DebugLayer.prototype._renderAxis = function (projectedPosition, mesh, globalViewport) {
  173. var position = mesh.getBoundingInfo().boundingSphere.center;
  174. var worldMatrix = mesh.getWorldMatrix();
  175. var unprojectedVector = BABYLON.Vector3.UnprojectFromTransform(projectedPosition.add(new BABYLON.Vector3(this._drawingCanvas.width * this.axisRatio, 0, 0)), globalViewport.width, globalViewport.height, worldMatrix, this._scene.getTransformMatrix());
  176. var unit = (unprojectedVector.subtract(position)).length();
  177. var xAxis = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(unit, 0, 0)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
  178. var xAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(unit * 1.5, 0, 0)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
  179. this._renderSingleAxis(projectedPosition, xAxis, xAxisText, "x", "#FF0000");
  180. var yAxis = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, unit, 0)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
  181. var yAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, unit * 1.5, 0)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
  182. this._renderSingleAxis(projectedPosition, yAxis, yAxisText, "y", "#00FF00");
  183. var zAxis = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, 0, unit)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
  184. var zAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, 0, unit * 1.5)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
  185. this._renderSingleAxis(projectedPosition, zAxis, zAxisText, "z", "#0000FF");
  186. };
  187. DebugLayer.prototype._renderLabel = function (text, projectedPosition, labelOffset, onClick, getFillStyle) {
  188. if (projectedPosition.z > 0 && projectedPosition.z < 1.0) {
  189. this._drawingContext.font = "normal 12px Segoe UI";
  190. var textMetrics = this._drawingContext.measureText(text);
  191. var centerX = projectedPosition.x - textMetrics.width / 2;
  192. var centerY = projectedPosition.y;
  193. if (this._isClickInsideRect(centerX - 5, centerY - labelOffset - 12, textMetrics.width + 10, 17)) {
  194. onClick();
  195. }
  196. this._drawingContext.beginPath();
  197. this._drawingContext.rect(centerX - 5, centerY - labelOffset - 12, textMetrics.width + 10, 17);
  198. this._drawingContext.fillStyle = getFillStyle();
  199. this._drawingContext.globalAlpha = 0.5;
  200. this._drawingContext.fill();
  201. this._drawingContext.globalAlpha = 1.0;
  202. this._drawingContext.strokeStyle = '#FFFFFF';
  203. this._drawingContext.lineWidth = 1;
  204. this._drawingContext.stroke();
  205. this._drawingContext.fillStyle = "#FFFFFF";
  206. this._drawingContext.fillText(text, centerX, centerY - labelOffset);
  207. this._drawingContext.beginPath();
  208. this._drawingContext.arc(projectedPosition.x, centerY, 5, 0, 2 * Math.PI, false);
  209. this._drawingContext.fill();
  210. }
  211. };
  212. DebugLayer.prototype._isClickInsideRect = function (x, y, width, height) {
  213. if (!this._clickPosition) {
  214. return false;
  215. }
  216. if (this._clickPosition.x < x || this._clickPosition.x > x + width) {
  217. return false;
  218. }
  219. if (this._clickPosition.y < y || this._clickPosition.y > y + height) {
  220. return false;
  221. }
  222. return true;
  223. };
  224. DebugLayer.prototype.isVisible = function () {
  225. return this._enabled;
  226. };
  227. DebugLayer.prototype.hide = function () {
  228. if (!this._enabled) {
  229. return;
  230. }
  231. this._enabled = false;
  232. var engine = this._scene.getEngine();
  233. this._scene.unregisterAfterRender(this._syncData);
  234. document.body.removeChild(this._globalDiv);
  235. window.removeEventListener("resize", this._syncPositions);
  236. this._scene.forceShowBoundingBoxes = false;
  237. this._scene.forceWireframe = false;
  238. BABYLON.StandardMaterial.DiffuseTextureEnabled = true;
  239. BABYLON.StandardMaterial.AmbientTextureEnabled = true;
  240. BABYLON.StandardMaterial.SpecularTextureEnabled = true;
  241. BABYLON.StandardMaterial.EmissiveTextureEnabled = true;
  242. BABYLON.StandardMaterial.BumpTextureEnabled = true;
  243. BABYLON.StandardMaterial.OpacityTextureEnabled = true;
  244. BABYLON.StandardMaterial.ReflectionTextureEnabled = true;
  245. this._scene.shadowsEnabled = true;
  246. this._scene.particlesEnabled = true;
  247. this._scene.postProcessesEnabled = true;
  248. this._scene.collisionsEnabled = true;
  249. this._scene.lightsEnabled = true;
  250. this._scene.texturesEnabled = true;
  251. this._scene.lensFlaresEnabled = true;
  252. this._scene.proceduralTexturesEnabled = true;
  253. this._scene.renderTargetsEnabled = true;
  254. engine.getRenderingCanvas().removeEventListener("click", this._onCanvasClick);
  255. };
  256. DebugLayer.prototype.show = function (showUI) {
  257. if (typeof showUI === "undefined") { showUI = true; }
  258. if (this._enabled) {
  259. return;
  260. }
  261. this._enabled = true;
  262. this._showUI = showUI;
  263. var engine = this._scene.getEngine();
  264. this._globalDiv = document.createElement("div");
  265. document.body.appendChild(this._globalDiv);
  266. this._generateDOMelements();
  267. window.addEventListener("resize", this._syncPositions);
  268. engine.getRenderingCanvas().addEventListener("click", this._onCanvasClick);
  269. this._syncPositions();
  270. this._scene.registerAfterRender(this._syncData);
  271. };
  272. DebugLayer.prototype._clearLabels = function () {
  273. this._drawingContext.clearRect(0, 0, this._drawingCanvas.width, this._drawingCanvas.height);
  274. for (var index = 0; index < this._scene.meshes.length; index++) {
  275. var mesh = this._scene.meshes[index];
  276. mesh.renderOverlay = false;
  277. }
  278. };
  279. DebugLayer.prototype._generateheader = function (root, text) {
  280. var header = document.createElement("div");
  281. header.innerHTML = text + "&nbsp;";
  282. header.style.textAlign = "right";
  283. header.style.width = "100%";
  284. header.style.color = "white";
  285. header.style.backgroundColor = "Black";
  286. header.style.padding = "5px 5px 4px 0px";
  287. header.style.marginLeft = "-5px";
  288. root.appendChild(header);
  289. };
  290. DebugLayer.prototype._generateTexBox = function (root, title) {
  291. var label = document.createElement("label");
  292. label.innerHTML = title;
  293. root.appendChild(label);
  294. root.appendChild(document.createElement("br"));
  295. };
  296. DebugLayer.prototype._generateAdvancedCheckBox = function (root, leftTitle, rightTitle, initialState, task, tag) {
  297. if (typeof tag === "undefined") { tag = null; }
  298. var label = document.createElement("label");
  299. var boundingBoxesCheckbox = document.createElement("input");
  300. boundingBoxesCheckbox.type = "checkbox";
  301. boundingBoxesCheckbox.checked = initialState;
  302. boundingBoxesCheckbox.addEventListener("change", function (evt) {
  303. task(evt.target, tag);
  304. });
  305. label.appendChild(boundingBoxesCheckbox);
  306. var container = document.createElement("span");
  307. var leftPart = document.createElement("span");
  308. var rightPart = document.createElement("span");
  309. rightPart.style.cssFloat = "right";
  310. leftPart.innerHTML = leftTitle;
  311. rightPart.innerHTML = rightTitle;
  312. rightPart.style.maxWidth = "200px";
  313. container.appendChild(leftPart);
  314. container.appendChild(rightPart);
  315. label.appendChild(container);
  316. root.appendChild(label);
  317. root.appendChild(document.createElement("br"));
  318. };
  319. DebugLayer.prototype._generateCheckBox = function (root, title, initialState, task, tag) {
  320. if (typeof tag === "undefined") { tag = null; }
  321. var label = document.createElement("label");
  322. var boundingBoxesCheckbox = document.createElement("input");
  323. boundingBoxesCheckbox.type = "checkbox";
  324. boundingBoxesCheckbox.checked = initialState;
  325. boundingBoxesCheckbox.addEventListener("change", function (evt) {
  326. task(evt.target, tag);
  327. });
  328. label.appendChild(boundingBoxesCheckbox);
  329. label.appendChild(document.createTextNode(title));
  330. root.appendChild(label);
  331. root.appendChild(document.createElement("br"));
  332. };
  333. DebugLayer.prototype._generateRadio = function (root, title, name, initialState, task, tag) {
  334. if (typeof tag === "undefined") { tag = null; }
  335. var label = document.createElement("label");
  336. var boundingBoxesRadio = document.createElement("input");
  337. boundingBoxesRadio.type = "radio";
  338. boundingBoxesRadio.name = name;
  339. boundingBoxesRadio.checked = initialState;
  340. boundingBoxesRadio.addEventListener("change", function (evt) {
  341. task(evt.target, tag);
  342. });
  343. label.appendChild(boundingBoxesRadio);
  344. label.appendChild(document.createTextNode(title));
  345. root.appendChild(label);
  346. root.appendChild(document.createElement("br"));
  347. };
  348. DebugLayer.prototype._generateDOMelements = function () {
  349. var _this = this;
  350. this._globalDiv.id = "DebugLayer";
  351. this._globalDiv.style.position = "absolute";
  352. this._globalDiv.style.fontFamily = "Segoe UI, Arial";
  353. this._globalDiv.style.fontSize = "14px";
  354. this._globalDiv.style.color = "white";
  355. // Drawing canvas
  356. this._drawingCanvas = document.createElement("canvas");
  357. this._drawingCanvas.id = "DebugLayerDrawingCanvas";
  358. this._drawingCanvas.style.position = "absolute";
  359. this._drawingCanvas.style.pointerEvents = "none";
  360. this._drawingContext = this._drawingCanvas.getContext("2d");
  361. this._globalDiv.appendChild(this._drawingCanvas);
  362. if (this._showUI) {
  363. var background = "rgba(128, 128, 128, 0.4)";
  364. var border = "rgb(180, 180, 180) solid 1px";
  365. // Stats
  366. this._statsDiv = document.createElement("div");
  367. this._statsDiv.id = "DebugLayerStats";
  368. this._statsDiv.style.border = border;
  369. this._statsDiv.style.position = "absolute";
  370. this._statsDiv.style.background = background;
  371. this._statsDiv.style.padding = "0px 0px 0px 5px";
  372. this._statsDiv.style.pointerEvents = "none";
  373. this._statsDiv.style.overflowY = "auto";
  374. this._generateheader(this._statsDiv, "Statistics");
  375. this._statsSubsetDiv = document.createElement("div");
  376. this._statsSubsetDiv.style.paddingTop = "5px";
  377. this._statsSubsetDiv.style.paddingBottom = "5px";
  378. this._statsDiv.appendChild(this._statsSubsetDiv);
  379. // Tree
  380. this._treeDiv = document.createElement("div");
  381. this._treeDiv.id = "DebugLayerTree";
  382. this._treeDiv.style.border = border;
  383. this._treeDiv.style.position = "absolute";
  384. this._treeDiv.style.background = background;
  385. this._treeDiv.style.padding = "0px 0px 0px 5px";
  386. this._treeDiv.style.display = "none";
  387. this._generateheader(this._treeDiv, "Meshes tree");
  388. this._treeSubsetDiv = document.createElement("div");
  389. this._treeSubsetDiv.style.paddingTop = "5px";
  390. this._treeSubsetDiv.style.paddingRight = "5px";
  391. this._treeSubsetDiv.style.overflowY = "auto";
  392. this._treeSubsetDiv.style.maxHeight = "300px";
  393. this._treeDiv.appendChild(this._treeSubsetDiv);
  394. this._needToRefreshMeshesTree = true;
  395. // Logs
  396. this._logDiv = document.createElement("div");
  397. this._logDiv.style.border = border;
  398. this._logDiv.id = "DebugLayerLogs";
  399. this._logDiv.style.position = "absolute";
  400. this._logDiv.style.background = background;
  401. this._logDiv.style.padding = "0px 0px 0px 5px";
  402. this._logDiv.style.display = "none";
  403. this._generateheader(this._logDiv, "Logs");
  404. this._logSubsetDiv = document.createElement("div");
  405. this._logSubsetDiv.style.height = "127px";
  406. this._logSubsetDiv.style.paddingTop = "5px";
  407. this._logSubsetDiv.style.overflowY = "auto";
  408. this._logSubsetDiv.style.fontSize = "12px";
  409. this._logSubsetDiv.style.fontFamily = "consolas";
  410. this._logSubsetDiv.innerHTML = BABYLON.Tools.LogCache;
  411. this._logDiv.appendChild(this._logSubsetDiv);
  412. BABYLON.Tools.OnNewCacheEntry = function (entry) {
  413. _this._logSubsetDiv.innerHTML = entry + _this._logSubsetDiv.innerHTML;
  414. };
  415. // Options
  416. this._optionsDiv = document.createElement("div");
  417. this._optionsDiv.id = "DebugLayerOptions";
  418. this._optionsDiv.style.border = border;
  419. this._optionsDiv.style.position = "absolute";
  420. this._optionsDiv.style.background = background;
  421. this._optionsDiv.style.padding = "0px 0px 0px 5px";
  422. this._optionsDiv.style.overflowY = "auto";
  423. this._generateheader(this._optionsDiv, "Options");
  424. this._optionsSubsetDiv = document.createElement("div");
  425. this._optionsSubsetDiv.style.paddingTop = "5px";
  426. this._optionsSubsetDiv.style.paddingBottom = "5px";
  427. this._optionsSubsetDiv.style.overflowY = "auto";
  428. this._optionsSubsetDiv.style.maxHeight = "200px";
  429. this._optionsDiv.appendChild(this._optionsSubsetDiv);
  430. this._generateTexBox(this._optionsSubsetDiv, "<b>General:</b>");
  431. this._generateCheckBox(this._optionsSubsetDiv, "Statistics", this._displayStatistics, function (element) {
  432. _this._displayStatistics = element.checked;
  433. });
  434. this._generateCheckBox(this._optionsSubsetDiv, "Logs", this._displayLogs, function (element) {
  435. _this._displayLogs = element.checked;
  436. });
  437. this._generateCheckBox(this._optionsSubsetDiv, "Meshes tree", this._displayTree, function (element) {
  438. _this._displayTree = element.checked;
  439. _this._needToRefreshMeshesTree = true;
  440. });
  441. this._generateCheckBox(this._optionsSubsetDiv, "Bounding boxes", this._scene.forceShowBoundingBoxes, function (element) {
  442. _this._scene.forceShowBoundingBoxes = element.checked;
  443. });
  444. this._generateCheckBox(this._optionsSubsetDiv, "Clickable labels", this._labelsEnabled, function (element) {
  445. _this._labelsEnabled = element.checked;
  446. if (!_this._labelsEnabled) {
  447. _this._clearLabels();
  448. }
  449. });
  450. this._generateCheckBox(this._optionsSubsetDiv, "Generate user marks", BABYLON.Tools.PerformanceLogLevel === BABYLON.Tools.PerformanceUserMarkLogLevel, function (element) {
  451. if (element.checked) {
  452. BABYLON.Tools.PerformanceLogLevel = BABYLON.Tools.PerformanceUserMarkLogLevel;
  453. } else {
  454. BABYLON.Tools.PerformanceLogLevel = BABYLON.Tools.PerformanceNoneLogLevel;
  455. }
  456. });
  457. ;
  458. this._optionsSubsetDiv.appendChild(document.createElement("br"));
  459. this._generateTexBox(this._optionsSubsetDiv, "<b>Rendering mode:</b>");
  460. this._generateRadio(this._optionsSubsetDiv, "Solid", "renderMode", !this._scene.forceWireframe && !this._scene.forcePointsCloud, function (element) {
  461. if (element.checked) {
  462. _this._scene.forceWireframe = false;
  463. _this._scene.forcePointsCloud = false;
  464. }
  465. });
  466. this._generateRadio(this._optionsSubsetDiv, "Wireframe", "renderMode", this._scene.forceWireframe, function (element) {
  467. if (element.checked) {
  468. _this._scene.forceWireframe = true;
  469. _this._scene.forcePointsCloud = false;
  470. }
  471. });
  472. this._generateRadio(this._optionsSubsetDiv, "Point", "renderMode", this._scene.forcePointsCloud, function (element) {
  473. if (element.checked) {
  474. _this._scene.forceWireframe = false;
  475. _this._scene.forcePointsCloud = true;
  476. }
  477. });
  478. this._optionsSubsetDiv.appendChild(document.createElement("br"));
  479. this._generateTexBox(this._optionsSubsetDiv, "<b>Texture channels:</b>");
  480. this._generateCheckBox(this._optionsSubsetDiv, "Diffuse", BABYLON.StandardMaterial.DiffuseTextureEnabled, function (element) {
  481. BABYLON.StandardMaterial.DiffuseTextureEnabled = element.checked;
  482. });
  483. this._generateCheckBox(this._optionsSubsetDiv, "Ambient", BABYLON.StandardMaterial.AmbientTextureEnabled, function (element) {
  484. BABYLON.StandardMaterial.AmbientTextureEnabled = element.checked;
  485. });
  486. this._generateCheckBox(this._optionsSubsetDiv, "Specular", BABYLON.StandardMaterial.SpecularTextureEnabled, function (element) {
  487. BABYLON.StandardMaterial.SpecularTextureEnabled = element.checked;
  488. });
  489. this._generateCheckBox(this._optionsSubsetDiv, "Emissive", BABYLON.StandardMaterial.EmissiveTextureEnabled, function (element) {
  490. BABYLON.StandardMaterial.EmissiveTextureEnabled = element.checked;
  491. });
  492. this._generateCheckBox(this._optionsSubsetDiv, "Bump", BABYLON.StandardMaterial.BumpTextureEnabled, function (element) {
  493. BABYLON.StandardMaterial.BumpTextureEnabled = element.checked;
  494. });
  495. this._generateCheckBox(this._optionsSubsetDiv, "Opacity", BABYLON.StandardMaterial.OpacityTextureEnabled, function (element) {
  496. BABYLON.StandardMaterial.OpacityTextureEnabled = element.checked;
  497. });
  498. this._generateCheckBox(this._optionsSubsetDiv, "Reflection", BABYLON.StandardMaterial.ReflectionTextureEnabled, function (element) {
  499. BABYLON.StandardMaterial.ReflectionTextureEnabled = element.checked;
  500. });
  501. this._generateCheckBox(this._optionsSubsetDiv, "Fresnel", BABYLON.StandardMaterial.FresnelEnabled, function (element) {
  502. BABYLON.StandardMaterial.FresnelEnabled = element.checked;
  503. });
  504. this._optionsSubsetDiv.appendChild(document.createElement("br"));
  505. this._generateTexBox(this._optionsSubsetDiv, "<b>Options:</b>");
  506. this._generateCheckBox(this._optionsSubsetDiv, "Animations", this._scene.animationsEnabled, function (element) {
  507. _this._scene.animationsEnabled = element.checked;
  508. });
  509. this._generateCheckBox(this._optionsSubsetDiv, "Collisions", this._scene.collisionsEnabled, function (element) {
  510. _this._scene.collisionsEnabled = element.checked;
  511. });
  512. this._generateCheckBox(this._optionsSubsetDiv, "Fog", this._scene.fogEnabled, function (element) {
  513. _this._scene.fogEnabled = element.checked;
  514. });
  515. this._generateCheckBox(this._optionsSubsetDiv, "Lens flares", this._scene.lensFlaresEnabled, function (element) {
  516. _this._scene.lensFlaresEnabled = element.checked;
  517. });
  518. this._generateCheckBox(this._optionsSubsetDiv, "Lights", this._scene.lightsEnabled, function (element) {
  519. _this._scene.lightsEnabled = element.checked;
  520. });
  521. this._generateCheckBox(this._optionsSubsetDiv, "Particles", this._scene.particlesEnabled, function (element) {
  522. _this._scene.particlesEnabled = element.checked;
  523. });
  524. this._generateCheckBox(this._optionsSubsetDiv, "Post-processes", this._scene.postProcessesEnabled, function (element) {
  525. _this._scene.postProcessesEnabled = element.checked;
  526. });
  527. this._generateCheckBox(this._optionsSubsetDiv, "Procedural textures", this._scene.proceduralTexturesEnabled, function (element) {
  528. _this._scene.proceduralTexturesEnabled = element.checked;
  529. });
  530. this._generateCheckBox(this._optionsSubsetDiv, "Render targets", this._scene.renderTargetsEnabled, function (element) {
  531. _this._scene.renderTargetsEnabled = element.checked;
  532. });
  533. this._generateCheckBox(this._optionsSubsetDiv, "Shadows", this._scene.shadowsEnabled, function (element) {
  534. _this._scene.shadowsEnabled = element.checked;
  535. });
  536. this._generateCheckBox(this._optionsSubsetDiv, "Skeletons", this._scene.skeletonsEnabled, function (element) {
  537. _this._scene.skeletonsEnabled = element.checked;
  538. });
  539. this._generateCheckBox(this._optionsSubsetDiv, "Textures", this._scene.texturesEnabled, function (element) {
  540. _this._scene.texturesEnabled = element.checked;
  541. });
  542. this._globalDiv.appendChild(this._statsDiv);
  543. this._globalDiv.appendChild(this._logDiv);
  544. this._globalDiv.appendChild(this._optionsDiv);
  545. this._globalDiv.appendChild(this._treeDiv);
  546. }
  547. };
  548. DebugLayer.prototype._displayStats = function () {
  549. var scene = this._scene;
  550. var engine = scene.getEngine();
  551. this._statsSubsetDiv.innerHTML = "Babylon.js v" + BABYLON.Engine.Version + " - <b>" + BABYLON.Tools.Format(engine.getFps(), 0) + " fps</b><br><br>" + "Total meshes: " + scene.meshes.length + "<br>" + "Total vertices: " + scene.getTotalVertices() + "<br>" + "Active meshes: " + scene.getActiveMeshes().length + "<br>" + "Active vertices: " + scene.getActiveVertices() + "<br>" + "Active bones: " + scene.getActiveBones() + "<br>" + "Active particles: " + scene.getActiveParticles() + "<br><br>" + "Frame duration: " + BABYLON.Tools.Format(scene.getLastFrameDuration()) + " ms<br>" + "<b>Draw calls: " + engine.drawCalls + "</b><br><br>" + "<i>Evaluate Active Meshes duration:</i> " + BABYLON.Tools.Format(scene.getEvaluateActiveMeshesDuration()) + " ms<br>" + "<i>Render Targets duration:</i> " + BABYLON.Tools.Format(scene.getRenderTargetsDuration()) + " ms<br>" + "<i>Particles duration:</i> " + BABYLON.Tools.Format(scene.getParticlesDuration()) + " ms<br>" + "<i>Sprites duration:</i> " + BABYLON.Tools.Format(scene.getSpritesDuration()) + " ms<br>" + "<i>Render duration:</i> <b>" + BABYLON.Tools.Format(scene.getRenderDuration()) + " ms</b>";
  552. };
  553. return DebugLayer;
  554. })();
  555. BABYLON.DebugLayer = DebugLayer;
  556. })(BABYLON || (BABYLON = {}));
  557. //# sourceMappingURL=babylon.debugLayer.js.map