CesiumInspector.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. import defined from "../../Core/defined.js";
  2. import destroyObject from "../../Core/destroyObject.js";
  3. import DeveloperError from "../../Core/DeveloperError.js";
  4. import knockout from "../../ThirdParty/knockout.js";
  5. import getElement from "../getElement.js";
  6. import InspectorShared from "../InspectorShared.js";
  7. import CesiumInspectorViewModel from "./CesiumInspectorViewModel.js";
  8. /**
  9. * Inspector widget to aid in debugging
  10. *
  11. * @alias CesiumInspector
  12. * @constructor
  13. *
  14. * @param {Element|String} container The DOM element or ID that will contain the widget.
  15. * @param {Scene} scene The Scene instance to use.
  16. *
  17. * @demo {@link https://sandcastle.cesium.com/index.html?src=Cesium%20Inspector.html|Cesium Sandcastle Cesium Inspector Demo}
  18. */
  19. function CesiumInspector(container, scene) {
  20. //>>includeStart('debug', pragmas.debug);
  21. if (!defined(container)) {
  22. throw new DeveloperError("container is required.");
  23. }
  24. if (!defined(scene)) {
  25. throw new DeveloperError("scene is required.");
  26. }
  27. //>>includeEnd('debug');
  28. container = getElement(container);
  29. var performanceContainer = document.createElement("div");
  30. var viewModel = new CesiumInspectorViewModel(scene, performanceContainer);
  31. this._viewModel = viewModel;
  32. this._container = container;
  33. var element = document.createElement("div");
  34. this._element = element;
  35. var text = document.createElement("div");
  36. text.textContent = "Cesium Inspector";
  37. text.className = "cesium-cesiumInspector-button";
  38. text.setAttribute("data-bind", "click: toggleDropDown");
  39. element.appendChild(text);
  40. element.className = "cesium-cesiumInspector";
  41. element.setAttribute(
  42. "data-bind",
  43. 'css: { "cesium-cesiumInspector-visible" : dropDownVisible, "cesium-cesiumInspector-hidden" : !dropDownVisible }'
  44. );
  45. container.appendChild(this._element);
  46. var panel = document.createElement("div");
  47. this._panel = panel;
  48. panel.className = "cesium-cesiumInspector-dropDown";
  49. element.appendChild(panel);
  50. var createSection = InspectorShared.createSection;
  51. var createCheckbox = InspectorShared.createCheckbox;
  52. // General
  53. var generalSection = createSection(
  54. panel,
  55. "General",
  56. "generalVisible",
  57. "toggleGeneral"
  58. );
  59. var debugShowFrustums = createCheckbox("Show Frustums", "frustums");
  60. var frustumStatistics = document.createElement("div");
  61. frustumStatistics.className = "cesium-cesiumInspector-frustumStatistics";
  62. frustumStatistics.setAttribute(
  63. "data-bind",
  64. "visible: frustums, html: frustumStatisticText"
  65. );
  66. debugShowFrustums.appendChild(frustumStatistics);
  67. generalSection.appendChild(debugShowFrustums);
  68. generalSection.appendChild(
  69. createCheckbox("Show Frustum Planes", "frustumPlanes")
  70. );
  71. generalSection.appendChild(
  72. createCheckbox("Performance Display", "performance")
  73. );
  74. performanceContainer.className = "cesium-cesiumInspector-performanceDisplay";
  75. generalSection.appendChild(performanceContainer);
  76. var shaderCacheDisplay = document.createElement("div");
  77. shaderCacheDisplay.className = "cesium-cesiumInspector-shaderCache";
  78. shaderCacheDisplay.setAttribute("data-bind", "html: shaderCacheText");
  79. generalSection.appendChild(shaderCacheDisplay);
  80. // https://github.com/CesiumGS/cesium/issues/6763
  81. // var globeDepth = createCheckbox('Show globe depth', 'globeDepth');
  82. // generalSection.appendChild(globeDepth);
  83. //
  84. // var globeDepthFrustum = document.createElement('div');
  85. // globeDepth.appendChild(globeDepthFrustum);
  86. //
  87. // generalSection.appendChild(createCheckbox('Show pick depth', 'pickDepth'));
  88. var depthFrustum = document.createElement("div");
  89. generalSection.appendChild(depthFrustum);
  90. // Use a span with HTML binding so that we can indent with non-breaking spaces.
  91. var gLabel = document.createElement("span");
  92. gLabel.setAttribute(
  93. "data-bind",
  94. 'html: "     Frustum:"'
  95. );
  96. depthFrustum.appendChild(gLabel);
  97. var gText = document.createElement("span");
  98. gText.setAttribute("data-bind", "text: depthFrustumText");
  99. depthFrustum.appendChild(gText);
  100. var gMinusButton = document.createElement("input");
  101. gMinusButton.type = "button";
  102. gMinusButton.value = "-";
  103. gMinusButton.className = "cesium-cesiumInspector-pickButton";
  104. gMinusButton.setAttribute("data-bind", "click: decrementDepthFrustum");
  105. depthFrustum.appendChild(gMinusButton);
  106. var gPlusButton = document.createElement("input");
  107. gPlusButton.type = "button";
  108. gPlusButton.value = "+";
  109. gPlusButton.className = "cesium-cesiumInspector-pickButton";
  110. gPlusButton.setAttribute("data-bind", "click: incrementDepthFrustum");
  111. depthFrustum.appendChild(gPlusButton);
  112. // Primitives
  113. var primSection = createSection(
  114. panel,
  115. "Primitives",
  116. "primitivesVisible",
  117. "togglePrimitives"
  118. );
  119. var pickPrimRequired = document.createElement("div");
  120. pickPrimRequired.className = "cesium-cesiumInspector-pickSection";
  121. primSection.appendChild(pickPrimRequired);
  122. var pickPrimitiveButton = document.createElement("input");
  123. pickPrimitiveButton.type = "button";
  124. pickPrimitiveButton.value = "Pick a primitive";
  125. pickPrimitiveButton.className = "cesium-cesiumInspector-pickButton";
  126. pickPrimitiveButton.setAttribute(
  127. "data-bind",
  128. 'css: {"cesium-cesiumInspector-pickButtonHighlight" : pickPrimitiveActive}, click: pickPrimitive'
  129. );
  130. var buttonWrap = document.createElement("div");
  131. buttonWrap.className = "cesium-cesiumInspector-center";
  132. buttonWrap.appendChild(pickPrimitiveButton);
  133. pickPrimRequired.appendChild(buttonWrap);
  134. pickPrimRequired.appendChild(
  135. createCheckbox(
  136. "Show bounding sphere",
  137. "primitiveBoundingSphere",
  138. "hasPickedPrimitive"
  139. )
  140. );
  141. pickPrimRequired.appendChild(
  142. createCheckbox(
  143. "Show reference frame",
  144. "primitiveReferenceFrame",
  145. "hasPickedPrimitive"
  146. )
  147. );
  148. this._primitiveOnly = createCheckbox(
  149. "Show only selected",
  150. "filterPrimitive",
  151. "hasPickedPrimitive"
  152. );
  153. pickPrimRequired.appendChild(this._primitiveOnly);
  154. // Terrain
  155. var terrainSection = createSection(
  156. panel,
  157. "Terrain",
  158. "terrainVisible",
  159. "toggleTerrain"
  160. );
  161. var pickTileRequired = document.createElement("div");
  162. pickTileRequired.className = "cesium-cesiumInspector-pickSection";
  163. terrainSection.appendChild(pickTileRequired);
  164. var pickTileButton = document.createElement("input");
  165. pickTileButton.type = "button";
  166. pickTileButton.value = "Pick a tile";
  167. pickTileButton.className = "cesium-cesiumInspector-pickButton";
  168. pickTileButton.setAttribute(
  169. "data-bind",
  170. 'css: {"cesium-cesiumInspector-pickButtonHighlight" : pickTileActive}, click: pickTile'
  171. );
  172. buttonWrap = document.createElement("div");
  173. buttonWrap.appendChild(pickTileButton);
  174. buttonWrap.className = "cesium-cesiumInspector-center";
  175. pickTileRequired.appendChild(buttonWrap);
  176. var tileInfo = document.createElement("div");
  177. pickTileRequired.appendChild(tileInfo);
  178. var parentTile = document.createElement("input");
  179. parentTile.type = "button";
  180. parentTile.value = "Parent";
  181. parentTile.className = "cesium-cesiumInspector-pickButton";
  182. parentTile.setAttribute("data-bind", "click: selectParent");
  183. var nwTile = document.createElement("input");
  184. nwTile.type = "button";
  185. nwTile.value = "NW";
  186. nwTile.className = "cesium-cesiumInspector-pickButton";
  187. nwTile.setAttribute("data-bind", "click: selectNW");
  188. var neTile = document.createElement("input");
  189. neTile.type = "button";
  190. neTile.value = "NE";
  191. neTile.className = "cesium-cesiumInspector-pickButton";
  192. neTile.setAttribute("data-bind", "click: selectNE");
  193. var swTile = document.createElement("input");
  194. swTile.type = "button";
  195. swTile.value = "SW";
  196. swTile.className = "cesium-cesiumInspector-pickButton";
  197. swTile.setAttribute("data-bind", "click: selectSW");
  198. var seTile = document.createElement("input");
  199. seTile.type = "button";
  200. seTile.value = "SE";
  201. seTile.className = "cesium-cesiumInspector-pickButton";
  202. seTile.setAttribute("data-bind", "click: selectSE");
  203. var tileText = document.createElement("div");
  204. tileText.className = "cesium-cesiumInspector-tileText";
  205. tileInfo.className = "cesium-cesiumInspector-frustumStatistics";
  206. tileInfo.appendChild(tileText);
  207. tileInfo.setAttribute("data-bind", "visible: hasPickedTile");
  208. tileText.setAttribute("data-bind", "html: tileText");
  209. var relativeText = document.createElement("div");
  210. relativeText.className = "cesium-cesiumInspector-relativeText";
  211. relativeText.textContent = "Select relative:";
  212. tileInfo.appendChild(relativeText);
  213. var table = document.createElement("table");
  214. var tr1 = document.createElement("tr");
  215. var tr2 = document.createElement("tr");
  216. var td1 = document.createElement("td");
  217. td1.appendChild(parentTile);
  218. var td2 = document.createElement("td");
  219. td2.appendChild(nwTile);
  220. var td3 = document.createElement("td");
  221. td3.appendChild(neTile);
  222. tr1.appendChild(td1);
  223. tr1.appendChild(td2);
  224. tr1.appendChild(td3);
  225. var td4 = document.createElement("td");
  226. var td5 = document.createElement("td");
  227. td5.appendChild(swTile);
  228. var td6 = document.createElement("td");
  229. td6.appendChild(seTile);
  230. tr2.appendChild(td4);
  231. tr2.appendChild(td5);
  232. tr2.appendChild(td6);
  233. table.appendChild(tr1);
  234. table.appendChild(tr2);
  235. tileInfo.appendChild(table);
  236. pickTileRequired.appendChild(
  237. createCheckbox(
  238. "Show bounding volume",
  239. "tileBoundingSphere",
  240. "hasPickedTile"
  241. )
  242. );
  243. pickTileRequired.appendChild(
  244. createCheckbox("Show only selected", "filterTile", "hasPickedTile")
  245. );
  246. terrainSection.appendChild(createCheckbox("Wireframe", "wireframe"));
  247. terrainSection.appendChild(
  248. createCheckbox("Suspend LOD update", "suspendUpdates")
  249. );
  250. terrainSection.appendChild(
  251. createCheckbox("Show tile coordinates", "tileCoordinates")
  252. );
  253. knockout.applyBindings(viewModel, this._element);
  254. }
  255. Object.defineProperties(CesiumInspector.prototype, {
  256. /**
  257. * Gets the parent container.
  258. * @memberof CesiumInspector.prototype
  259. *
  260. * @type {Element}
  261. */
  262. container: {
  263. get: function () {
  264. return this._container;
  265. },
  266. },
  267. /**
  268. * Gets the view model.
  269. * @memberof CesiumInspector.prototype
  270. *
  271. * @type {CesiumInspectorViewModel}
  272. */
  273. viewModel: {
  274. get: function () {
  275. return this._viewModel;
  276. },
  277. },
  278. });
  279. /**
  280. * @returns {Boolean} true if the object has been destroyed, false otherwise.
  281. */
  282. CesiumInspector.prototype.isDestroyed = function () {
  283. return false;
  284. };
  285. /**
  286. * Destroys the widget. Should be called if permanently
  287. * removing the widget from layout.
  288. */
  289. CesiumInspector.prototype.destroy = function () {
  290. knockout.cleanNode(this._element);
  291. this._container.removeChild(this._element);
  292. this.viewModel.destroy();
  293. return destroyObject(this);
  294. };
  295. export default CesiumInspector;