babylon.debugLayer.ts 33 KB

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