babylon.debugLayer.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  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 - 420) + "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. // Add meshes
  141. var sortedArray = this._scene.meshes.slice(0, this._scene.meshes.length);
  142. sortedArray.sort(function (a, b) {
  143. if (a.name === b.name) {
  144. return 0;
  145. }
  146. return (a.name > b.name) ? 1 : -1;
  147. });
  148. for (var index = 0; index < sortedArray.length; index++) {
  149. var mesh = sortedArray[index];
  150. if (!mesh.isEnabled()) {
  151. continue;
  152. }
  153. this._generateAdvancedCheckBox(this._treeSubsetDiv, mesh.name, mesh.getTotalVertices() + " verts", mesh.isVisible, function (element, mesh) {
  154. mesh.isVisible = element.checked;
  155. }, mesh);
  156. }
  157. };
  158. DebugLayer.prototype._renderSingleAxis = function (zero, unit, unitText, label, color) {
  159. this._drawingContext.beginPath();
  160. this._drawingContext.moveTo(zero.x, zero.y);
  161. this._drawingContext.lineTo(unit.x, unit.y);
  162. this._drawingContext.strokeStyle = color;
  163. this._drawingContext.lineWidth = 4;
  164. this._drawingContext.stroke();
  165. this._drawingContext.font = "normal 14px Segoe UI";
  166. this._drawingContext.fillStyle = color;
  167. this._drawingContext.fillText(label, unitText.x, unitText.y);
  168. };
  169. DebugLayer.prototype._renderAxis = function (projectedPosition, mesh, globalViewport) {
  170. var position = mesh.getBoundingInfo().boundingSphere.center;
  171. var worldMatrix = mesh.getWorldMatrix();
  172. 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());
  173. var unit = (unprojectedVector.subtract(position)).length();
  174. var xAxis = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(unit, 0, 0)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
  175. var xAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(unit * 1.5, 0, 0)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
  176. this._renderSingleAxis(projectedPosition, xAxis, xAxisText, "x", "#FF0000");
  177. var yAxis = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, unit, 0)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
  178. var yAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, unit * 1.5, 0)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
  179. this._renderSingleAxis(projectedPosition, yAxis, yAxisText, "y", "#00FF00");
  180. var zAxis = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, 0, unit)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
  181. var zAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, 0, unit * 1.5)), worldMatrix, this._scene.getTransformMatrix(), globalViewport);
  182. this._renderSingleAxis(projectedPosition, zAxis, zAxisText, "z", "#0000FF");
  183. };
  184. DebugLayer.prototype._renderLabel = function (text, projectedPosition, labelOffset, onClick, getFillStyle) {
  185. if (projectedPosition.z > 0 && projectedPosition.z < 1.0) {
  186. this._drawingContext.font = "normal 12px Segoe UI";
  187. var textMetrics = this._drawingContext.measureText(text);
  188. var centerX = projectedPosition.x - textMetrics.width / 2;
  189. var centerY = projectedPosition.y;
  190. if (this._isClickInsideRect(centerX - 5, centerY - labelOffset - 12, textMetrics.width + 10, 17)) {
  191. onClick();
  192. }
  193. this._drawingContext.beginPath();
  194. this._drawingContext.rect(centerX - 5, centerY - labelOffset - 12, textMetrics.width + 10, 17);
  195. this._drawingContext.fillStyle = getFillStyle();
  196. this._drawingContext.globalAlpha = 0.5;
  197. this._drawingContext.fill();
  198. this._drawingContext.globalAlpha = 1.0;
  199. this._drawingContext.strokeStyle = '#FFFFFF';
  200. this._drawingContext.lineWidth = 1;
  201. this._drawingContext.stroke();
  202. this._drawingContext.fillStyle = "#FFFFFF";
  203. this._drawingContext.fillText(text, centerX, centerY - labelOffset);
  204. this._drawingContext.beginPath();
  205. this._drawingContext.arc(projectedPosition.x, centerY, 5, 0, 2 * Math.PI, false);
  206. this._drawingContext.fill();
  207. }
  208. };
  209. DebugLayer.prototype._isClickInsideRect = function (x, y, width, height) {
  210. if (!this._clickPosition) {
  211. return false;
  212. }
  213. if (this._clickPosition.x < x || this._clickPosition.x > x + width) {
  214. return false;
  215. }
  216. if (this._clickPosition.y < y || this._clickPosition.y > y + height) {
  217. return false;
  218. }
  219. return true;
  220. };
  221. DebugLayer.prototype.isVisible = function () {
  222. return this._enabled;
  223. };
  224. DebugLayer.prototype.hide = function () {
  225. if (!this._enabled) {
  226. return;
  227. }
  228. this._enabled = false;
  229. var engine = this._scene.getEngine();
  230. this._scene.unregisterAfterRender(this._syncData);
  231. document.body.removeChild(this._globalDiv);
  232. window.removeEventListener("resize", this._syncPositions);
  233. this._scene.forceShowBoundingBoxes = false;
  234. this._scene.forceWireframe = false;
  235. BABYLON.StandardMaterial.DiffuseTextureEnabled = true;
  236. BABYLON.StandardMaterial.AmbientTextureEnabled = true;
  237. BABYLON.StandardMaterial.SpecularTextureEnabled = true;
  238. BABYLON.StandardMaterial.EmissiveTextureEnabled = true;
  239. BABYLON.StandardMaterial.BumpTextureEnabled = true;
  240. BABYLON.StandardMaterial.OpacityTextureEnabled = true;
  241. BABYLON.StandardMaterial.ReflectionTextureEnabled = true;
  242. this._scene.shadowsEnabled = true;
  243. this._scene.particlesEnabled = true;
  244. this._scene.postProcessesEnabled = true;
  245. this._scene.collisionsEnabled = true;
  246. this._scene.lightsEnabled = true;
  247. this._scene.texturesEnabled = true;
  248. this._scene.lensFlaresEnabled = true;
  249. this._scene.proceduralTexturesEnabled = true;
  250. this._scene.renderTargetsEnabled = true;
  251. engine.getRenderingCanvas().removeEventListener("click", this._onCanvasClick);
  252. };
  253. DebugLayer.prototype.show = function (showUI) {
  254. if (typeof showUI === "undefined") { showUI = true; }
  255. if (this._enabled) {
  256. return;
  257. }
  258. this._enabled = true;
  259. this._showUI = showUI;
  260. var engine = this._scene.getEngine();
  261. this._globalDiv = document.createElement("div");
  262. document.body.appendChild(this._globalDiv);
  263. this._generateDOMelements();
  264. window.addEventListener("resize", this._syncPositions);
  265. engine.getRenderingCanvas().addEventListener("click", this._onCanvasClick);
  266. this._syncPositions();
  267. this._scene.registerAfterRender(this._syncData);
  268. };
  269. DebugLayer.prototype._clearLabels = function () {
  270. this._drawingContext.clearRect(0, 0, this._drawingCanvas.width, this._drawingCanvas.height);
  271. for (var index = 0; index < this._scene.meshes.length; index++) {
  272. var mesh = this._scene.meshes[index];
  273. mesh.renderOverlay = false;
  274. }
  275. };
  276. DebugLayer.prototype._generateheader = function (root, text) {
  277. var header = document.createElement("div");
  278. header.innerHTML = text + "&nbsp;";
  279. header.style.textAlign = "right";
  280. header.style.width = "100%";
  281. header.style.color = "white";
  282. header.style.backgroundColor = "Black";
  283. header.style.padding = "5px 5px 4px 0px";
  284. header.style.marginLeft = "-5px";
  285. root.appendChild(header);
  286. };
  287. DebugLayer.prototype._generateTexBox = function (root, title) {
  288. var label = document.createElement("label");
  289. label.innerHTML = title;
  290. root.appendChild(label);
  291. root.appendChild(document.createElement("br"));
  292. };
  293. DebugLayer.prototype._generateAdvancedCheckBox = function (root, leftTitle, rightTitle, initialState, task, tag) {
  294. if (typeof tag === "undefined") { tag = null; }
  295. var label = document.createElement("label");
  296. var boundingBoxesCheckbox = document.createElement("input");
  297. boundingBoxesCheckbox.type = "checkbox";
  298. boundingBoxesCheckbox.checked = initialState;
  299. boundingBoxesCheckbox.addEventListener("change", function (evt) {
  300. task(evt.target, tag);
  301. });
  302. label.appendChild(boundingBoxesCheckbox);
  303. var container = document.createElement("span");
  304. var leftPart = document.createElement("span");
  305. var rightPart = document.createElement("span");
  306. rightPart.style.cssFloat = "right";
  307. leftPart.innerHTML = leftTitle;
  308. rightPart.innerHTML = rightTitle;
  309. container.appendChild(leftPart);
  310. container.appendChild(rightPart);
  311. label.appendChild(container);
  312. root.appendChild(label);
  313. root.appendChild(document.createElement("br"));
  314. };
  315. DebugLayer.prototype._generateCheckBox = function (root, title, initialState, task, tag) {
  316. if (typeof tag === "undefined") { tag = null; }
  317. var label = document.createElement("label");
  318. var boundingBoxesCheckbox = document.createElement("input");
  319. boundingBoxesCheckbox.type = "checkbox";
  320. boundingBoxesCheckbox.checked = initialState;
  321. boundingBoxesCheckbox.addEventListener("change", function (evt) {
  322. task(evt.target, tag);
  323. });
  324. label.appendChild(boundingBoxesCheckbox);
  325. label.appendChild(document.createTextNode(title));
  326. root.appendChild(label);
  327. root.appendChild(document.createElement("br"));
  328. };
  329. DebugLayer.prototype._generateRadio = function (root, title, name, initialState, task, tag) {
  330. if (typeof tag === "undefined") { tag = null; }
  331. var label = document.createElement("label");
  332. var boundingBoxesRadio = document.createElement("input");
  333. boundingBoxesRadio.type = "radio";
  334. boundingBoxesRadio.name = name;
  335. boundingBoxesRadio.checked = initialState;
  336. boundingBoxesRadio.addEventListener("change", function (evt) {
  337. task(evt.target, tag);
  338. });
  339. label.appendChild(boundingBoxesRadio);
  340. label.appendChild(document.createTextNode(title));
  341. root.appendChild(label);
  342. root.appendChild(document.createElement("br"));
  343. };
  344. DebugLayer.prototype._generateDOMelements = function () {
  345. var _this = this;
  346. this._globalDiv.id = "DebugLayer";
  347. this._globalDiv.style.position = "absolute";
  348. this._globalDiv.style.fontFamily = "Segoe UI, Arial";
  349. this._globalDiv.style.fontSize = "14px";
  350. this._globalDiv.style.color = "white";
  351. // Drawing canvas
  352. this._drawingCanvas = document.createElement("canvas");
  353. this._drawingCanvas.id = "DebugLayerDrawingCanvas";
  354. this._drawingCanvas.style.position = "absolute";
  355. this._drawingCanvas.style.pointerEvents = "none";
  356. this._drawingContext = this._drawingCanvas.getContext("2d");
  357. this._globalDiv.appendChild(this._drawingCanvas);
  358. if (this._showUI) {
  359. var background = "rgba(128, 128, 128, 0.4)";
  360. var border = "rgb(180, 180, 180) solid 1px";
  361. // Stats
  362. this._statsDiv = document.createElement("div");
  363. this._statsDiv.id = "DebugLayerStats";
  364. this._statsDiv.style.border = border;
  365. this._statsDiv.style.position = "absolute";
  366. this._statsDiv.style.background = background;
  367. this._statsDiv.style.padding = "0px 0px 0px 5px";
  368. this._statsDiv.style.pointerEvents = "none";
  369. this._statsDiv.style.overflowY = "auto";
  370. this._generateheader(this._statsDiv, "Statistics");
  371. this._statsSubsetDiv = document.createElement("div");
  372. this._statsSubsetDiv.style.paddingTop = "5px";
  373. this._statsSubsetDiv.style.paddingBottom = "5px";
  374. this._statsDiv.appendChild(this._statsSubsetDiv);
  375. // Tree
  376. this._treeDiv = document.createElement("div");
  377. this._treeDiv.id = "DebugLayerTree";
  378. this._treeDiv.style.border = border;
  379. this._treeDiv.style.position = "absolute";
  380. this._treeDiv.style.background = background;
  381. this._treeDiv.style.padding = "0px 0px 0px 5px";
  382. this._treeDiv.style.display = "none";
  383. this._generateheader(this._treeDiv, "Meshes tree");
  384. this._treeSubsetDiv = document.createElement("div");
  385. this._treeSubsetDiv.style.paddingTop = "5px";
  386. this._treeSubsetDiv.style.paddingRight = "5px";
  387. this._treeSubsetDiv.style.overflowY = "auto";
  388. this._treeSubsetDiv.style.maxHeight = "300px";
  389. this._treeDiv.appendChild(this._treeSubsetDiv);
  390. this._needToRefreshMeshesTree = true;
  391. // Logs
  392. this._logDiv = document.createElement("div");
  393. this._logDiv.style.border = border;
  394. this._logDiv.id = "DebugLayerLogs";
  395. this._logDiv.style.position = "absolute";
  396. this._logDiv.style.background = background;
  397. this._logDiv.style.padding = "0px 0px 0px 5px";
  398. this._logDiv.style.display = "none";
  399. this._generateheader(this._logDiv, "Logs");
  400. this._logSubsetDiv = document.createElement("div");
  401. this._logSubsetDiv.style.height = "127px";
  402. this._logSubsetDiv.style.paddingTop = "5px";
  403. this._logSubsetDiv.style.overflowY = "auto";
  404. this._logSubsetDiv.style.fontSize = "12px";
  405. this._logSubsetDiv.style.fontFamily = "consolas";
  406. this._logSubsetDiv.innerHTML = BABYLON.Tools.LogCache;
  407. this._logDiv.appendChild(this._logSubsetDiv);
  408. BABYLON.Tools.OnNewCacheEntry = function (entry) {
  409. _this._logSubsetDiv.innerHTML = entry + _this._logSubsetDiv.innerHTML;
  410. };
  411. // Options
  412. this._optionsDiv = document.createElement("div");
  413. this._optionsDiv.id = "DebugLayerOptions";
  414. this._optionsDiv.style.border = border;
  415. this._optionsDiv.style.position = "absolute";
  416. this._optionsDiv.style.background = background;
  417. this._optionsDiv.style.padding = "0px 0px 0px 5px";
  418. this._optionsDiv.style.overflowY = "auto";
  419. this._generateheader(this._optionsDiv, "Options");
  420. this._optionsSubsetDiv = document.createElement("div");
  421. this._optionsSubsetDiv.style.paddingTop = "5px";
  422. this._optionsSubsetDiv.style.paddingBottom = "5px";
  423. this._optionsSubsetDiv.style.overflowY = "auto";
  424. this._optionsSubsetDiv.style.maxHeight = "200px";
  425. this._optionsDiv.appendChild(this._optionsSubsetDiv);
  426. this._generateTexBox(this._optionsSubsetDiv, "<b>General:</b>");
  427. this._generateCheckBox(this._optionsSubsetDiv, "Statistics", this._displayStatistics, function (element) {
  428. _this._displayStatistics = element.checked;
  429. });
  430. this._generateCheckBox(this._optionsSubsetDiv, "Logs", this._displayLogs, function (element) {
  431. _this._displayLogs = element.checked;
  432. });
  433. this._generateCheckBox(this._optionsSubsetDiv, "Meshes tree", this._displayTree, function (element) {
  434. _this._displayTree = element.checked;
  435. _this._needToRefreshMeshesTree = true;
  436. });
  437. this._generateCheckBox(this._optionsSubsetDiv, "Bounding boxes", this._scene.forceShowBoundingBoxes, function (element) {
  438. _this._scene.forceShowBoundingBoxes = element.checked;
  439. });
  440. this._generateCheckBox(this._optionsSubsetDiv, "Clickable labels", this._labelsEnabled, function (element) {
  441. _this._labelsEnabled = element.checked;
  442. if (!_this._labelsEnabled) {
  443. _this._clearLabels();
  444. }
  445. });
  446. this._generateCheckBox(this._optionsSubsetDiv, "Generate user marks", BABYLON.Tools.PerformanceLogLevel === BABYLON.Tools.PerformanceUserMarkLogLevel, function (element) {
  447. if (element.checked) {
  448. BABYLON.Tools.PerformanceLogLevel = BABYLON.Tools.PerformanceUserMarkLogLevel;
  449. } else {
  450. BABYLON.Tools.PerformanceLogLevel = BABYLON.Tools.PerformanceNoneLogLevel;
  451. }
  452. });
  453. ;
  454. this._optionsSubsetDiv.appendChild(document.createElement("br"));
  455. this._generateTexBox(this._optionsSubsetDiv, "<b>Rendering mode:</b>");
  456. this._generateRadio(this._optionsSubsetDiv, "Solid", "renderMode", !this._scene.forceWireframe && !this._scene.forcePointsCloud, function (element) {
  457. if (element.checked) {
  458. _this._scene.forceWireframe = false;
  459. _this._scene.forcePointsCloud = false;
  460. }
  461. });
  462. this._generateRadio(this._optionsSubsetDiv, "Wireframe", "renderMode", this._scene.forceWireframe, function (element) {
  463. if (element.checked) {
  464. _this._scene.forceWireframe = true;
  465. _this._scene.forcePointsCloud = false;
  466. }
  467. });
  468. this._generateRadio(this._optionsSubsetDiv, "Point", "renderMode", this._scene.forcePointsCloud, function (element) {
  469. if (element.checked) {
  470. _this._scene.forceWireframe = false;
  471. _this._scene.forcePointsCloud = true;
  472. }
  473. });
  474. this._optionsSubsetDiv.appendChild(document.createElement("br"));
  475. this._generateTexBox(this._optionsSubsetDiv, "<b>Texture channels:</b>");
  476. this._generateCheckBox(this._optionsSubsetDiv, "Diffuse", BABYLON.StandardMaterial.DiffuseTextureEnabled, function (element) {
  477. BABYLON.StandardMaterial.DiffuseTextureEnabled = element.checked;
  478. });
  479. this._generateCheckBox(this._optionsSubsetDiv, "Ambient", BABYLON.StandardMaterial.AmbientTextureEnabled, function (element) {
  480. BABYLON.StandardMaterial.AmbientTextureEnabled = element.checked;
  481. });
  482. this._generateCheckBox(this._optionsSubsetDiv, "Specular", BABYLON.StandardMaterial.SpecularTextureEnabled, function (element) {
  483. BABYLON.StandardMaterial.SpecularTextureEnabled = element.checked;
  484. });
  485. this._generateCheckBox(this._optionsSubsetDiv, "Emissive", BABYLON.StandardMaterial.EmissiveTextureEnabled, function (element) {
  486. BABYLON.StandardMaterial.EmissiveTextureEnabled = element.checked;
  487. });
  488. this._generateCheckBox(this._optionsSubsetDiv, "Bump", BABYLON.StandardMaterial.BumpTextureEnabled, function (element) {
  489. BABYLON.StandardMaterial.BumpTextureEnabled = element.checked;
  490. });
  491. this._generateCheckBox(this._optionsSubsetDiv, "Opacity", BABYLON.StandardMaterial.OpacityTextureEnabled, function (element) {
  492. BABYLON.StandardMaterial.OpacityTextureEnabled = element.checked;
  493. });
  494. this._generateCheckBox(this._optionsSubsetDiv, "Reflection", BABYLON.StandardMaterial.ReflectionTextureEnabled, function (element) {
  495. BABYLON.StandardMaterial.ReflectionTextureEnabled = element.checked;
  496. });
  497. this._generateCheckBox(this._optionsSubsetDiv, "Fresnel", BABYLON.StandardMaterial.FresnelEnabled, function (element) {
  498. BABYLON.StandardMaterial.FresnelEnabled = element.checked;
  499. });
  500. this._optionsSubsetDiv.appendChild(document.createElement("br"));
  501. this._generateTexBox(this._optionsSubsetDiv, "<b>Options:</b>");
  502. this._generateCheckBox(this._optionsSubsetDiv, "Animations", this._scene.animationsEnabled, function (element) {
  503. _this._scene.animationsEnabled = element.checked;
  504. });
  505. this._generateCheckBox(this._optionsSubsetDiv, "Collisions", this._scene.collisionsEnabled, function (element) {
  506. _this._scene.collisionsEnabled = element.checked;
  507. });
  508. this._generateCheckBox(this._optionsSubsetDiv, "Fog", this._scene.fogEnabled, function (element) {
  509. _this._scene.fogEnabled = element.checked;
  510. });
  511. this._generateCheckBox(this._optionsSubsetDiv, "Lens flares", this._scene.lensFlaresEnabled, function (element) {
  512. _this._scene.lensFlaresEnabled = element.checked;
  513. });
  514. this._generateCheckBox(this._optionsSubsetDiv, "Lights", this._scene.lightsEnabled, function (element) {
  515. _this._scene.lightsEnabled = element.checked;
  516. });
  517. this._generateCheckBox(this._optionsSubsetDiv, "Particles", this._scene.particlesEnabled, function (element) {
  518. _this._scene.particlesEnabled = element.checked;
  519. });
  520. this._generateCheckBox(this._optionsSubsetDiv, "Post-processes", this._scene.postProcessesEnabled, function (element) {
  521. _this._scene.postProcessesEnabled = element.checked;
  522. });
  523. this._generateCheckBox(this._optionsSubsetDiv, "Procedural textures", this._scene.proceduralTexturesEnabled, function (element) {
  524. _this._scene.proceduralTexturesEnabled = element.checked;
  525. });
  526. this._generateCheckBox(this._optionsSubsetDiv, "Render targets", this._scene.renderTargetsEnabled, function (element) {
  527. _this._scene.renderTargetsEnabled = element.checked;
  528. });
  529. this._generateCheckBox(this._optionsSubsetDiv, "Shadows", this._scene.shadowsEnabled, function (element) {
  530. _this._scene.shadowsEnabled = element.checked;
  531. });
  532. this._generateCheckBox(this._optionsSubsetDiv, "Skeletons", this._scene.skeletonsEnabled, function (element) {
  533. _this._scene.skeletonsEnabled = element.checked;
  534. });
  535. this._generateCheckBox(this._optionsSubsetDiv, "Textures", this._scene.texturesEnabled, function (element) {
  536. _this._scene.texturesEnabled = element.checked;
  537. });
  538. this._globalDiv.appendChild(this._statsDiv);
  539. this._globalDiv.appendChild(this._logDiv);
  540. this._globalDiv.appendChild(this._optionsDiv);
  541. this._globalDiv.appendChild(this._treeDiv);
  542. }
  543. };
  544. DebugLayer.prototype._displayStats = function () {
  545. var scene = this._scene;
  546. var engine = scene.getEngine();
  547. this._statsSubsetDiv.innerHTML = "Babylon.js v" + BABYLON.Engine.Version + " - <b>" + BABYLON.Tools.Format(BABYLON.Tools.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>";
  548. };
  549. return DebugLayer;
  550. })();
  551. BABYLON.DebugLayer = DebugLayer;
  552. })(BABYLON || (BABYLON = {}));
  553. //# sourceMappingURL=babylon.debugLayer.js.map