Reference Source

src/viewer/Configs.js

  1. import {math} from "./scene/math/math.js";
  2.  
  3. let maxDataTextureHeight = 1 << 16;
  4. let maxGeometryBatchSize = 5000000
  5.  
  6. /**
  7. * Manages global configurations for all {@link Viewer}s.
  8. *
  9. * ## Example
  10. *
  11. * In the example below, we'll disable xeokit's double-precision support, which gives a performance and memory boost
  12. * on low-power devices, but also means that we can no longer render double-precision models without jittering.
  13. *
  14. * That's OK if we know that we're not going to view models that are geographically vast, or offset far from the World coordinate origin.
  15. *
  16. * [[Run this example](/examples/index.html#Configs_disableDoublePrecisionAndRAF)]
  17. *
  18. * ````javascript
  19. * import {Configs, Viewer, XKTLoaderPlugin} from "https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/xeokit-sdk.es.min.js";
  20. *
  21. * // Access xeoit-sdk global configs.
  22. * // We typically set configs only before we create any Viewers.
  23. * const configs = new Configs();
  24. *
  25. * // Disable 64-bit precision for extra speed.
  26. * // Only set this config once, before you create any Viewers.
  27. * configs.doublePrecisionEnabled = false;
  28. *
  29. * // Create a Viewer, to which our configs apply
  30. * const viewer = new Viewer({
  31. * canvasId: "myCanvas"
  32. * });
  33. *
  34. * viewer.camera.eye = [-3.933, 2.855, 27.018];
  35. * viewer.camera.look = [4.400, 3.724, 8.899];
  36. * viewer.camera.up = [-0.018, 0.999, 0.039];
  37. *
  38. * const xktLoader = new XKTLoaderPlugin(viewer);
  39. *
  40. * const model = xktLoader.load({
  41. * src: "../assets/models/xkt/v8/ifc/Duplex.ifc.xkt"
  42. * });
  43. * ````
  44. */
  45. export class Configs {
  46.  
  47. /**
  48. * Creates a Configs.
  49. */
  50. constructor() {
  51.  
  52. }
  53.  
  54. /**
  55. * Sets whether double precision mode is enabled for Viewers.
  56. *
  57. * When double precision mode is enabled (default), Viewers will accurately render models that contain
  58. * double-precision coordinates, without jittering.
  59. *
  60. * Internally, double precision incurs extra performance and memory overhead, so if we're certain that
  61. * we're not going to render models that rely on double-precision coordinates, then it's a good idea to disable
  62. * it, especially on low-power devices.
  63. *
  64. * This should only be set once, before creating any Viewers.
  65. *
  66. * @returns {Boolean}
  67. */
  68. set doublePrecisionEnabled(doublePrecision) {
  69. math.setDoublePrecisionEnabled(doublePrecision);
  70. }
  71.  
  72. /**
  73. * Gets whether double precision mode is enabled for all Viewers.
  74. *
  75. * @returns {Boolean}
  76. */
  77. get doublePrecisionEnabled() {
  78. return math.getDoublePrecisionEnabled();
  79. }
  80.  
  81. /**
  82. * Sets the maximum data texture height.
  83. *
  84. * Should be a multiple of 1024. Default is 4096, which is the maximum allowed value.
  85. */
  86. set maxDataTextureHeight(value) {
  87. value = Math.ceil(value / 1024) * 1024;
  88. if (value > 4096) {
  89. value = 4096;
  90. } else if (value < 1024) {
  91. value = 1024;
  92. }
  93. maxDataTextureHeight = value;
  94. }
  95.  
  96. /**
  97. * Sets maximum data texture height.
  98. * @returns {*|number}
  99. */
  100. get maxDataTextureHeight() {
  101. return maxDataTextureHeight;
  102. }
  103.  
  104. /**
  105. * Sets the maximum batched geometry VBO size.
  106. *
  107. * Default value is 5000000, which is the maximum size.
  108. *
  109. * Minimum size is 100000.
  110. */
  111. set maxGeometryBatchSize(value) {
  112. if (value < 100000) {
  113. value = 100000;
  114. } else if (value > 5000000) {
  115. value = 5000000;
  116. }
  117. maxGeometryBatchSize = value;
  118. }
  119.  
  120. /**
  121. * Gets the maximum batched geometry VBO size.
  122. */
  123. get maxGeometryBatchSize() {
  124. return maxGeometryBatchSize;
  125. }
  126. }
  127.