babylon.debugLayer.js 35 KB

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