babylon.debugLayer.js 34 KB

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