babylon.debugLayer.js 38 KB

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