babylon.debugLayer.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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 ||
  49. context.mozBackingStorePixelRatio ||
  50. context.msBackingStorePixelRatio ||
  51. context.oBackingStorePixelRatio ||
  52. context.backingStorePixelRatio || 1;
  53. _this._ratio = devicePixelRatio / backingStoreRatio;
  54. _this._drawingCanvas.width = engine.getRenderWidth() * _this._ratio;
  55. _this._drawingCanvas.height = engine.getRenderHeight() * _this._ratio;
  56. };
  57. this._onCanvasClick = function (evt) {
  58. _this._clickPosition = {
  59. x: evt.clientX * _this._ratio,
  60. y: evt.clientY * _this._ratio
  61. };
  62. };
  63. this._syncUI = function () {
  64. if (_this._showUI) {
  65. if (_this._displayStatistics) {
  66. _this._displayStats();
  67. _this._statsDiv.style.display = "";
  68. }
  69. else {
  70. _this._statsDiv.style.display = "none";
  71. }
  72. if (_this._displayLogs) {
  73. _this._logDiv.style.display = "";
  74. }
  75. else {
  76. _this._logDiv.style.display = "none";
  77. }
  78. if (_this._displayTree) {
  79. _this._treeDiv.style.display = "";
  80. if (_this._needToRefreshMeshesTree) {
  81. _this._needToRefreshMeshesTree = false;
  82. _this._refreshMeshesTreeContent();
  83. }
  84. }
  85. else {
  86. _this._treeDiv.style.display = "none";
  87. }
  88. }
  89. };
  90. this._syncData = function () {
  91. if (_this._labelsEnabled || !_this._showUI) {
  92. _this._camera.getViewMatrix().multiplyToRef(_this._camera.getProjectionMatrix(), _this._transformationMatrix);
  93. _this._drawingContext.clearRect(0, 0, _this._drawingCanvas.width, _this._drawingCanvas.height);
  94. var engine = _this._scene.getEngine();
  95. var viewport = _this._camera.viewport;
  96. var globalViewport = viewport.toGlobal(engine);
  97. // Meshes
  98. var meshes = _this._camera.getActiveMeshes();
  99. for (var index = 0; index < meshes.length; index++) {
  100. var mesh = meshes.data[index];
  101. var position = mesh.getBoundingInfo().boundingSphere.center;
  102. var projectedPosition = BABYLON.Vector3.Project(position, mesh.getWorldMatrix(), _this._transformationMatrix, globalViewport);
  103. if (mesh.renderOverlay || _this.shouldDisplayAxis && _this.shouldDisplayAxis(mesh)) {
  104. _this._renderAxis(projectedPosition, mesh, globalViewport);
  105. }
  106. if (!_this.shouldDisplayLabel || _this.shouldDisplayLabel(mesh)) {
  107. _this._renderLabel(mesh.name, projectedPosition, 12, function () { mesh.renderOverlay = !mesh.renderOverlay; }, function () { return mesh.renderOverlay ? 'red' : 'black'; });
  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 () { return "purple"; });
  124. }
  125. }
  126. // Lights
  127. var lights = _this._scene.lights;
  128. for (index = 0; index < lights.length; index++) {
  129. var light = lights[index];
  130. if (light.position) {
  131. projectedPosition = BABYLON.Vector3.Project(light.getAbsolutePosition(), _this._identityMatrix, _this._transformationMatrix, globalViewport);
  132. if (!_this.shouldDisplayLabel || _this.shouldDisplayLabel(light)) {
  133. _this._renderLabel(light.name, projectedPosition, -20, function () {
  134. light.setEnabled(!light.isEnabled());
  135. }, function () { return light.isEnabled() ? "orange" : "gray"; });
  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._transformationMatrix);
  180. var unit = (unprojectedVector.subtract(position)).length();
  181. var xAxis = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(unit, 0, 0)), worldMatrix, this._transformationMatrix, globalViewport);
  182. var xAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(unit * 1.5, 0, 0)), worldMatrix, this._transformationMatrix, 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._transformationMatrix, globalViewport);
  185. var yAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, unit * 1.5, 0)), worldMatrix, this._transformationMatrix, 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._transformationMatrix, globalViewport);
  188. var zAxisText = BABYLON.Vector3.Project(position.add(new BABYLON.Vector3(0, 0, unit * 1.5)), worldMatrix, this._transformationMatrix, 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. var clientRect = this._drawingCanvas.getBoundingClientRect();
  198. if (this._showUI && this._isClickInsideRect(clientRect.left * this._ratio + centerX - 5, clientRect.top * this._ratio + centerY - labelOffset - 12, textMetrics.width + 10, 17)) {
  199. onClick();
  200. }
  201. this._drawingContext.beginPath();
  202. this._drawingContext.rect(centerX - 5, centerY - labelOffset - 12, textMetrics.width + 10, 17);
  203. this._drawingContext.fillStyle = getFillStyle();
  204. this._drawingContext.globalAlpha = 0.5;
  205. this._drawingContext.fill();
  206. this._drawingContext.globalAlpha = 1.0;
  207. this._drawingContext.strokeStyle = '#FFFFFF';
  208. this._drawingContext.lineWidth = 1;
  209. this._drawingContext.stroke();
  210. this._drawingContext.fillStyle = "#FFFFFF";
  211. this._drawingContext.fillText(text, centerX, centerY - labelOffset);
  212. this._drawingContext.beginPath();
  213. this._drawingContext.arc(projectedPosition.x, centerY, 5, 0, 2 * Math.PI, false);
  214. this._drawingContext.fill();
  215. }
  216. };
  217. DebugLayer.prototype._isClickInsideRect = function (x, y, width, height) {
  218. if (!this._clickPosition) {
  219. return false;
  220. }
  221. if (this._clickPosition.x < x || this._clickPosition.x > x + width) {
  222. return false;
  223. }
  224. if (this._clickPosition.y < y || this._clickPosition.y > y + height) {
  225. return false;
  226. }
  227. return true;
  228. };
  229. DebugLayer.prototype.isVisible = function () {
  230. return this._enabled;
  231. };
  232. DebugLayer.prototype.hide = function () {
  233. if (!this._enabled) {
  234. return;
  235. }
  236. this._enabled = false;
  237. var engine = this._scene.getEngine();
  238. this._scene.unregisterBeforeRender(this._syncData);
  239. this._scene.unregisterAfterRender(this._syncUI);
  240. document.body.removeChild(this._globalDiv);
  241. window.removeEventListener("resize", this._syncPositions);
  242. this._scene.forceShowBoundingBoxes = false;
  243. this._scene.forceWireframe = false;
  244. BABYLON.StandardMaterial.DiffuseTextureEnabled = true;
  245. BABYLON.StandardMaterial.AmbientTextureEnabled = true;
  246. BABYLON.StandardMaterial.SpecularTextureEnabled = true;
  247. BABYLON.StandardMaterial.EmissiveTextureEnabled = true;
  248. BABYLON.StandardMaterial.BumpTextureEnabled = true;
  249. BABYLON.StandardMaterial.OpacityTextureEnabled = true;
  250. BABYLON.StandardMaterial.ReflectionTextureEnabled = true;
  251. this._scene.shadowsEnabled = true;
  252. this._scene.particlesEnabled = true;
  253. this._scene.postProcessesEnabled = true;
  254. this._scene.collisionsEnabled = true;
  255. this._scene.lightsEnabled = true;
  256. this._scene.texturesEnabled = true;
  257. this._scene.lensFlaresEnabled = true;
  258. this._scene.proceduralTexturesEnabled = true;
  259. this._scene.renderTargetsEnabled = true;
  260. engine.getRenderingCanvas().removeEventListener("click", this._onCanvasClick);
  261. };
  262. DebugLayer.prototype.show = function (showUI, camera) {
  263. if (showUI === void 0) { showUI = true; }
  264. if (camera === void 0) { camera = null; }
  265. if (this._enabled) {
  266. return;
  267. }
  268. this._enabled = true;
  269. if (camera) {
  270. this._camera = camera;
  271. }
  272. else {
  273. this._camera = this._scene.activeCamera;
  274. }
  275. this._showUI = showUI;
  276. var engine = this._scene.getEngine();
  277. this._globalDiv = document.createElement("div");
  278. document.body.appendChild(this._globalDiv);
  279. this._generateDOMelements();
  280. window.addEventListener("resize", this._syncPositions);
  281. engine.getRenderingCanvas().addEventListener("click", this._onCanvasClick);
  282. this._syncPositions();
  283. this._scene.registerBeforeRender(this._syncData);
  284. this._scene.registerAfterRender(this._syncUI);
  285. };
  286. DebugLayer.prototype._clearLabels = function () {
  287. this._drawingContext.clearRect(0, 0, this._drawingCanvas.width, this._drawingCanvas.height);
  288. for (var index = 0; index < this._scene.meshes.length; index++) {
  289. var mesh = this._scene.meshes[index];
  290. mesh.renderOverlay = false;
  291. }
  292. };
  293. DebugLayer.prototype._generateheader = function (root, text) {
  294. var header = document.createElement("div");
  295. header.innerHTML = text + "&nbsp;";
  296. header.style.textAlign = "right";
  297. header.style.width = "100%";
  298. header.style.color = "white";
  299. header.style.backgroundColor = "Black";
  300. header.style.padding = "5px 5px 4px 0px";
  301. header.style.marginLeft = "-5px";
  302. header.style.fontWeight = "bold";
  303. root.appendChild(header);
  304. };
  305. DebugLayer.prototype._generateTexBox = function (root, title, color) {
  306. var label = document.createElement("label");
  307. label.innerHTML = title;
  308. label.style.color = color;
  309. root.appendChild(label);
  310. root.appendChild(document.createElement("br"));
  311. };
  312. DebugLayer.prototype._generateAdvancedCheckBox = function (root, leftTitle, rightTitle, initialState, task, tag) {
  313. if (tag === void 0) { tag = null; }
  314. var label = document.createElement("label");
  315. var boundingBoxesCheckbox = document.createElement("input");
  316. boundingBoxesCheckbox.type = "checkbox";
  317. boundingBoxesCheckbox.checked = initialState;
  318. boundingBoxesCheckbox.addEventListener("change", function (evt) {
  319. task(evt.target, tag);
  320. });
  321. label.appendChild(boundingBoxesCheckbox);
  322. var container = document.createElement("span");
  323. var leftPart = document.createElement("span");
  324. var rightPart = document.createElement("span");
  325. rightPart.style.cssFloat = "right";
  326. leftPart.innerHTML = leftTitle;
  327. rightPart.innerHTML = rightTitle;
  328. rightPart.style.fontSize = "12px";
  329. rightPart.style.maxWidth = "200px";
  330. container.appendChild(leftPart);
  331. container.appendChild(rightPart);
  332. label.appendChild(container);
  333. root.appendChild(label);
  334. root.appendChild(document.createElement("br"));
  335. };
  336. DebugLayer.prototype._generateCheckBox = function (root, title, initialState, task, tag) {
  337. if (tag === void 0) { tag = null; }
  338. var label = document.createElement("label");
  339. var checkBox = document.createElement("input");
  340. checkBox.type = "checkbox";
  341. checkBox.checked = initialState;
  342. checkBox.addEventListener("change", function (evt) {
  343. task(evt.target, tag);
  344. });
  345. label.appendChild(checkBox);
  346. label.appendChild(document.createTextNode(title));
  347. root.appendChild(label);
  348. root.appendChild(document.createElement("br"));
  349. };
  350. DebugLayer.prototype._generateButton = function (root, title, task, tag) {
  351. if (tag === void 0) { tag = null; }
  352. var button = document.createElement("button");
  353. button.innerHTML = title;
  354. button.style.height = "24px";
  355. button.style.color = "#444444";
  356. button.style.border = "1px solid white";
  357. button.className = "debugLayerButton";
  358. button.addEventListener("click", function (evt) {
  359. task(evt.target, tag);
  360. });
  361. root.appendChild(button);
  362. root.appendChild(document.createElement("br"));
  363. };
  364. DebugLayer.prototype._generateRadio = function (root, title, name, initialState, task, tag) {
  365. if (tag === void 0) { tag = null; }
  366. var label = document.createElement("label");
  367. var boundingBoxesRadio = document.createElement("input");
  368. boundingBoxesRadio.type = "radio";
  369. boundingBoxesRadio.name = name;
  370. boundingBoxesRadio.checked = initialState;
  371. boundingBoxesRadio.addEventListener("change", function (evt) {
  372. task(evt.target, tag);
  373. });
  374. label.appendChild(boundingBoxesRadio);
  375. label.appendChild(document.createTextNode(title));
  376. root.appendChild(label);
  377. root.appendChild(document.createElement("br"));
  378. };
  379. DebugLayer.prototype._generateDOMelements = function () {
  380. var _this = this;
  381. this._globalDiv.id = "DebugLayer";
  382. this._globalDiv.style.position = "absolute";
  383. this._globalDiv.style.fontFamily = "Segoe UI, Arial";
  384. this._globalDiv.style.fontSize = "14px";
  385. this._globalDiv.style.color = "white";
  386. // Drawing canvas
  387. this._drawingCanvas = document.createElement("canvas");
  388. this._drawingCanvas.id = "DebugLayerDrawingCanvas";
  389. this._drawingCanvas.style.position = "absolute";
  390. this._drawingCanvas.style.pointerEvents = "none";
  391. this._drawingContext = this._drawingCanvas.getContext("2d");
  392. this._globalDiv.appendChild(this._drawingCanvas);
  393. if (this._showUI) {
  394. var background = "rgba(128, 128, 128, 0.4)";
  395. var border = "rgb(180, 180, 180) solid 1px";
  396. // Stats
  397. this._statsDiv = document.createElement("div");
  398. this._statsDiv.id = "DebugLayerStats";
  399. this._statsDiv.style.border = border;
  400. this._statsDiv.style.position = "absolute";
  401. this._statsDiv.style.background = background;
  402. this._statsDiv.style.padding = "0px 0px 0px 5px";
  403. this._generateheader(this._statsDiv, "STATISTICS");
  404. this._statsSubsetDiv = document.createElement("div");
  405. this._statsSubsetDiv.style.paddingTop = "5px";
  406. this._statsSubsetDiv.style.paddingBottom = "5px";
  407. this._statsSubsetDiv.style.overflowY = "auto";
  408. this._statsDiv.appendChild(this._statsSubsetDiv);
  409. // Tree
  410. this._treeDiv = document.createElement("div");
  411. this._treeDiv.id = "DebugLayerTree";
  412. this._treeDiv.style.border = border;
  413. this._treeDiv.style.position = "absolute";
  414. this._treeDiv.style.background = background;
  415. this._treeDiv.style.padding = "0px 0px 0px 5px";
  416. this._treeDiv.style.display = "none";
  417. this._generateheader(this._treeDiv, "MESHES TREE");
  418. this._treeSubsetDiv = document.createElement("div");
  419. this._treeSubsetDiv.style.paddingTop = "5px";
  420. this._treeSubsetDiv.style.paddingRight = "5px";
  421. this._treeSubsetDiv.style.overflowY = "auto";
  422. this._treeSubsetDiv.style.maxHeight = "300px";
  423. this._treeDiv.appendChild(this._treeSubsetDiv);
  424. this._needToRefreshMeshesTree = true;
  425. // Logs
  426. this._logDiv = document.createElement("div");
  427. this._logDiv.style.border = border;
  428. this._logDiv.id = "DebugLayerLogs";
  429. this._logDiv.style.position = "absolute";
  430. this._logDiv.style.background = background;
  431. this._logDiv.style.padding = "0px 0px 0px 5px";
  432. this._logDiv.style.display = "none";
  433. this._generateheader(this._logDiv, "LOGS");
  434. this._logSubsetDiv = document.createElement("div");
  435. this._logSubsetDiv.style.height = "127px";
  436. this._logSubsetDiv.style.paddingTop = "5px";
  437. this._logSubsetDiv.style.overflowY = "auto";
  438. this._logSubsetDiv.style.fontSize = "12px";
  439. this._logSubsetDiv.style.fontFamily = "consolas";
  440. this._logSubsetDiv.innerHTML = BABYLON.Tools.LogCache;
  441. this._logDiv.appendChild(this._logSubsetDiv);
  442. BABYLON.Tools.OnNewCacheEntry = function (entry) {
  443. _this._logSubsetDiv.innerHTML = entry + _this._logSubsetDiv.innerHTML;
  444. };
  445. // Options
  446. this._optionsDiv = document.createElement("div");
  447. this._optionsDiv.id = "DebugLayerOptions";
  448. this._optionsDiv.style.border = border;
  449. this._optionsDiv.style.position = "absolute";
  450. this._optionsDiv.style.background = background;
  451. this._optionsDiv.style.padding = "0px 0px 0px 5px";
  452. this._optionsDiv.style.overflowY = "auto";
  453. this._generateheader(this._optionsDiv, "OPTIONS");
  454. this._optionsSubsetDiv = document.createElement("div");
  455. this._optionsSubsetDiv.style.paddingTop = "5px";
  456. this._optionsSubsetDiv.style.paddingBottom = "5px";
  457. this._optionsSubsetDiv.style.overflowY = "auto";
  458. this._optionsSubsetDiv.style.maxHeight = "200px";
  459. this._optionsDiv.appendChild(this._optionsSubsetDiv);
  460. this._generateTexBox(this._optionsSubsetDiv, "<b>Windows:</b>", this.accentColor);
  461. this._generateCheckBox(this._optionsSubsetDiv, "Statistics", this._displayStatistics, function (element) { _this._displayStatistics = element.checked; });
  462. this._generateCheckBox(this._optionsSubsetDiv, "Logs", this._displayLogs, function (element) { _this._displayLogs = element.checked; });
  463. this._generateCheckBox(this._optionsSubsetDiv, "Meshes tree", this._displayTree, function (element) {
  464. _this._displayTree = element.checked;
  465. _this._needToRefreshMeshesTree = true;
  466. });
  467. this._optionsSubsetDiv.appendChild(document.createElement("br"));
  468. this._generateTexBox(this._optionsSubsetDiv, "<b>General:</b>", this.accentColor);
  469. this._generateCheckBox(this._optionsSubsetDiv, "Bounding boxes", this._scene.forceShowBoundingBoxes, function (element) { _this._scene.forceShowBoundingBoxes = element.checked; });
  470. this._generateCheckBox(this._optionsSubsetDiv, "Clickable labels", this._labelsEnabled, function (element) {
  471. _this._labelsEnabled = element.checked;
  472. if (!_this._labelsEnabled) {
  473. _this._clearLabels();
  474. }
  475. });
  476. this._generateCheckBox(this._optionsSubsetDiv, "Generate user marks (F12)", BABYLON.Tools.PerformanceLogLevel === BABYLON.Tools.PerformanceUserMarkLogLevel, function (element) {
  477. if (element.checked) {
  478. BABYLON.Tools.PerformanceLogLevel = BABYLON.Tools.PerformanceUserMarkLogLevel;
  479. }
  480. else {
  481. BABYLON.Tools.PerformanceLogLevel = BABYLON.Tools.PerformanceNoneLogLevel;
  482. }
  483. });
  484. ;
  485. this._optionsSubsetDiv.appendChild(document.createElement("br"));
  486. this._generateTexBox(this._optionsSubsetDiv, "<b>Rendering mode:</b>", this.accentColor);
  487. this._generateRadio(this._optionsSubsetDiv, "Solid", "renderMode", !this._scene.forceWireframe && !this._scene.forcePointsCloud, function (element) {
  488. if (element.checked) {
  489. _this._scene.forceWireframe = false;
  490. _this._scene.forcePointsCloud = false;
  491. }
  492. });
  493. this._generateRadio(this._optionsSubsetDiv, "Wireframe", "renderMode", this._scene.forceWireframe, function (element) {
  494. if (element.checked) {
  495. _this._scene.forceWireframe = true;
  496. _this._scene.forcePointsCloud = false;
  497. }
  498. });
  499. this._generateRadio(this._optionsSubsetDiv, "Point", "renderMode", this._scene.forcePointsCloud, function (element) {
  500. if (element.checked) {
  501. _this._scene.forceWireframe = false;
  502. _this._scene.forcePointsCloud = true;
  503. }
  504. });
  505. this._optionsSubsetDiv.appendChild(document.createElement("br"));
  506. this._generateTexBox(this._optionsSubsetDiv, "<b>Texture channels:</b>", this.accentColor);
  507. this._generateCheckBox(this._optionsSubsetDiv, "Diffuse", BABYLON.StandardMaterial.DiffuseTextureEnabled, function (element) { BABYLON.StandardMaterial.DiffuseTextureEnabled = element.checked; });
  508. this._generateCheckBox(this._optionsSubsetDiv, "Ambient", BABYLON.StandardMaterial.AmbientTextureEnabled, function (element) { BABYLON.StandardMaterial.AmbientTextureEnabled = element.checked; });
  509. this._generateCheckBox(this._optionsSubsetDiv, "Specular", BABYLON.StandardMaterial.SpecularTextureEnabled, function (element) { BABYLON.StandardMaterial.SpecularTextureEnabled = element.checked; });
  510. this._generateCheckBox(this._optionsSubsetDiv, "Emissive", BABYLON.StandardMaterial.EmissiveTextureEnabled, function (element) { BABYLON.StandardMaterial.EmissiveTextureEnabled = element.checked; });
  511. this._generateCheckBox(this._optionsSubsetDiv, "Bump", BABYLON.StandardMaterial.BumpTextureEnabled, function (element) { BABYLON.StandardMaterial.BumpTextureEnabled = element.checked; });
  512. this._generateCheckBox(this._optionsSubsetDiv, "Opacity", BABYLON.StandardMaterial.OpacityTextureEnabled, function (element) { BABYLON.StandardMaterial.OpacityTextureEnabled = element.checked; });
  513. this._generateCheckBox(this._optionsSubsetDiv, "Reflection", BABYLON.StandardMaterial.ReflectionTextureEnabled, function (element) { BABYLON.StandardMaterial.ReflectionTextureEnabled = element.checked; });
  514. this._generateCheckBox(this._optionsSubsetDiv, "Fresnel", BABYLON.StandardMaterial.FresnelEnabled, function (element) { BABYLON.StandardMaterial.FresnelEnabled = element.checked; });
  515. this._generateCheckBox(this._optionsSubsetDiv, "Lightmap", BABYLON.StandardMaterial.LightmapEnabled, function (element) { BABYLON.StandardMaterial.LightmapEnabled = element.checked; });
  516. this._optionsSubsetDiv.appendChild(document.createElement("br"));
  517. this._generateTexBox(this._optionsSubsetDiv, "<b>Options:</b>", this.accentColor);
  518. this._generateCheckBox(this._optionsSubsetDiv, "Animations", this._scene.animationsEnabled, function (element) { _this._scene.animationsEnabled = element.checked; });
  519. this._generateCheckBox(this._optionsSubsetDiv, "Collisions", this._scene.collisionsEnabled, function (element) { _this._scene.collisionsEnabled = element.checked; });
  520. this._generateCheckBox(this._optionsSubsetDiv, "Fog", this._scene.fogEnabled, function (element) { _this._scene.fogEnabled = element.checked; });
  521. this._generateCheckBox(this._optionsSubsetDiv, "Lens flares", this._scene.lensFlaresEnabled, function (element) { _this._scene.lensFlaresEnabled = element.checked; });
  522. this._generateCheckBox(this._optionsSubsetDiv, "Lights", this._scene.lightsEnabled, function (element) { _this._scene.lightsEnabled = element.checked; });
  523. this._generateCheckBox(this._optionsSubsetDiv, "Particles", this._scene.particlesEnabled, function (element) { _this._scene.particlesEnabled = element.checked; });
  524. this._generateCheckBox(this._optionsSubsetDiv, "Post-processes", this._scene.postProcessesEnabled, function (element) { _this._scene.postProcessesEnabled = element.checked; });
  525. this._generateCheckBox(this._optionsSubsetDiv, "Procedural textures", this._scene.proceduralTexturesEnabled, function (element) { _this._scene.proceduralTexturesEnabled = element.checked; });
  526. this._generateCheckBox(this._optionsSubsetDiv, "Render targets", this._scene.renderTargetsEnabled, function (element) { _this._scene.renderTargetsEnabled = element.checked; });
  527. this._generateCheckBox(this._optionsSubsetDiv, "Shadows", this._scene.shadowsEnabled, function (element) { _this._scene.shadowsEnabled = element.checked; });
  528. this._generateCheckBox(this._optionsSubsetDiv, "Skeletons", this._scene.skeletonsEnabled, function (element) { _this._scene.skeletonsEnabled = element.checked; });
  529. this._generateCheckBox(this._optionsSubsetDiv, "Sprites", this._scene.spritesEnabled, function (element) { _this._scene.spritesEnabled = element.checked; });
  530. this._generateCheckBox(this._optionsSubsetDiv, "Textures", this._scene.texturesEnabled, function (element) { _this._scene.texturesEnabled = element.checked; });
  531. if (BABYLON.Engine.audioEngine.canUseWebAudio) {
  532. this._optionsSubsetDiv.appendChild(document.createElement("br"));
  533. this._generateTexBox(this._optionsSubsetDiv, "<b>Audio:</b>", this.accentColor);
  534. this._generateRadio(this._optionsSubsetDiv, "Headphones", "panningModel", this._scene.headphone, function (element) {
  535. if (element.checked) {
  536. _this._scene.headphone = true;
  537. }
  538. });
  539. this._generateRadio(this._optionsSubsetDiv, "Normal Speakers", "panningModel", !this._scene.headphone, function (element) {
  540. if (element.checked) {
  541. _this._scene.headphone = false;
  542. }
  543. });
  544. this._generateCheckBox(this._optionsSubsetDiv, "Disable audio", !this._scene.audioEnabled, function (element) {
  545. _this._scene.audioEnabled = !element.checked;
  546. });
  547. }
  548. this._optionsSubsetDiv.appendChild(document.createElement("br"));
  549. this._generateTexBox(this._optionsSubsetDiv, "<b>Tools:</b>", this.accentColor);
  550. this._generateButton(this._optionsSubsetDiv, "Dump rendertargets", function (element) { _this._scene.dumpNextRenderTargets = true; });
  551. this._optionsSubsetDiv.appendChild(document.createElement("br"));
  552. this._globalDiv.appendChild(this._statsDiv);
  553. this._globalDiv.appendChild(this._logDiv);
  554. this._globalDiv.appendChild(this._optionsDiv);
  555. this._globalDiv.appendChild(this._treeDiv);
  556. }
  557. };
  558. DebugLayer.prototype._displayStats = function () {
  559. var scene = this._scene;
  560. var engine = scene.getEngine();
  561. var glInfo = engine.getGlInfo();
  562. this._statsSubsetDiv.innerHTML = "Babylon.js v" + BABYLON.Engine.Version + " - <b>" + BABYLON.Tools.Format(engine.getFps(), 0) + " fps</b><br><br>"
  563. + "<div style='column-count: 2;-moz-column-count:2;-webkit-column-count:2'>"
  564. + "<b>Count</b><br>"
  565. + "Total meshes: " + scene.meshes.length + "<br>"
  566. + "Total vertices: " + scene.getTotalVertices() + "<br>"
  567. + "Total materials: " + scene.materials.length + "<br>"
  568. + "Total textures: " + scene.textures.length + "<br>"
  569. + "Active meshes: " + scene.getActiveMeshes().length + "<br>"
  570. + "Active indices: " + scene.getActiveIndices() + "<br>"
  571. + "Active bones: " + scene.getActiveBones() + "<br>"
  572. + "Active particles: " + scene.getActiveParticles() + "<br>"
  573. + "<b>Draw calls: " + engine.drawCalls + "</b><br><br>"
  574. + "<b>Duration</b><br>"
  575. + "Meshes selection:</i> " + BABYLON.Tools.Format(scene.getEvaluateActiveMeshesDuration()) + " ms<br>"
  576. + "Render Targets: " + BABYLON.Tools.Format(scene.getRenderTargetsDuration()) + " ms<br>"
  577. + "Particles: " + BABYLON.Tools.Format(scene.getParticlesDuration()) + " ms<br>"
  578. + "Sprites: " + BABYLON.Tools.Format(scene.getSpritesDuration()) + " ms<br><br>"
  579. + "Render: <b>" + BABYLON.Tools.Format(scene.getRenderDuration()) + " ms</b><br>"
  580. + "Frame: " + BABYLON.Tools.Format(scene.getLastFrameDuration()) + " ms<br>"
  581. + "Potential FPS: " + BABYLON.Tools.Format(1000.0 / scene.getLastFrameDuration(), 0) + "<br><br>"
  582. + "</div>"
  583. + "<div style='column-count: 2;-moz-column-count:2;-webkit-column-count:2'>"
  584. + "<b>Extensions</b><br>"
  585. + "Std derivatives: " + (engine.getCaps().standardDerivatives ? "Yes" : "No") + "<br>"
  586. + "Compressed textures: " + (engine.getCaps().s3tc ? "Yes" : "No") + "<br>"
  587. + "Hardware instances: " + (engine.getCaps().instancedArrays ? "Yes" : "No") + "<br>"
  588. + "Texture float: " + (engine.getCaps().textureFloat ? "Yes" : "No") + "<br>"
  589. + "32bits indices: " + (engine.getCaps().uintIndices ? "Yes" : "No") + "<br>"
  590. + "<b>Caps.</b><br>"
  591. + "Max textures units: " + engine.getCaps().maxTexturesImageUnits + "<br>"
  592. + "Max textures size: " + engine.getCaps().maxTextureSize + "<br>"
  593. + "Max anisotropy: " + engine.getCaps().maxAnisotropy + "<br><br><br>"
  594. + "</div><br>"
  595. + "<b>Info</b><br>"
  596. + glInfo.version + "<br>"
  597. + glInfo.renderer + "<br>";
  598. if (this.customStatsFunction) {
  599. this._statsSubsetDiv.innerHTML += this._statsSubsetDiv.innerHTML;
  600. }
  601. };
  602. return DebugLayer;
  603. })();
  604. BABYLON.DebugLayer = DebugLayer;
  605. })(BABYLON || (BABYLON = {}));