babylon.debugLayer.ts 35 KB

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