babylon.debugLayer.js 33 KB

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