PointCloudShading.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import defaultValue from "../Core/defaultValue.js";
  2. import PointCloudEyeDomeLighting from "./PointCloudEyeDomeLighting.js";
  3. /**
  4. * Options for performing point attenuation based on geometric error when rendering
  5. * point clouds using 3D Tiles.
  6. *
  7. * @param {object} [options] Object with the following properties:
  8. * @param {boolean} [options.attenuation=false] Perform point attenuation based on geometric error.
  9. * @param {number} [options.geometricErrorScale=1.0] Scale to be applied to each tile's geometric error.
  10. * @param {number} [options.maximumAttenuation] Maximum attenuation in pixels. Defaults to the Cesium3DTileset's maximumScreenSpaceError.
  11. * @param {number} [options.baseResolution] Average base resolution for the dataset in meters. Substitute for Geometric Error when not available.
  12. * @param {boolean} [options.eyeDomeLighting=true] When true, use eye dome lighting when drawing with point attenuation.
  13. * @param {number} [options.eyeDomeLightingStrength=1.0] Increasing this value increases contrast on slopes and edges.
  14. * @param {number} [options.eyeDomeLightingRadius=1.0] Increase the thickness of contours from eye dome lighting.
  15. * @param {boolean} [options.backFaceCulling=false] Determines whether back-facing points are hidden. This option works only if data has normals included.
  16. * @param {boolean} [options.normalShading=true] Determines whether a point cloud that contains normals is shaded by the scene's light source.
  17. *
  18. * @alias PointCloudShading
  19. * @constructor
  20. */
  21. function PointCloudShading(options) {
  22. const pointCloudShading = defaultValue(options, {});
  23. /**
  24. * Perform point attenuation based on geometric error.
  25. * @type {boolean}
  26. * @default false
  27. */
  28. this.attenuation = defaultValue(pointCloudShading.attenuation, false);
  29. /**
  30. * Scale to be applied to the geometric error before computing attenuation.
  31. * @type {number}
  32. * @default 1.0
  33. */
  34. this.geometricErrorScale = defaultValue(
  35. pointCloudShading.geometricErrorScale,
  36. 1.0
  37. );
  38. /**
  39. * Maximum point attenuation in pixels. If undefined, the Cesium3DTileset's maximumScreenSpaceError will be used.
  40. * @type {number}
  41. */
  42. this.maximumAttenuation = pointCloudShading.maximumAttenuation;
  43. /**
  44. * Average base resolution for the dataset in meters.
  45. * Used in place of geometric error when geometric error is 0.
  46. * If undefined, an approximation will be computed for each tile that has geometric error of 0.
  47. * @type {number}
  48. */
  49. this.baseResolution = pointCloudShading.baseResolution;
  50. /**
  51. * Use eye dome lighting when drawing with point attenuation
  52. * Requires support for EXT_frag_depth, OES_texture_float, and WEBGL_draw_buffers extensions in WebGL 1.0,
  53. * otherwise eye dome lighting is ignored.
  54. *
  55. * @type {boolean}
  56. * @default true
  57. */
  58. this.eyeDomeLighting = defaultValue(pointCloudShading.eyeDomeLighting, true);
  59. /**
  60. * Eye dome lighting strength (apparent contrast)
  61. * @type {number}
  62. * @default 1.0
  63. */
  64. this.eyeDomeLightingStrength = defaultValue(
  65. pointCloudShading.eyeDomeLightingStrength,
  66. 1.0
  67. );
  68. /**
  69. * Thickness of contours from eye dome lighting
  70. * @type {number}
  71. * @default 1.0
  72. */
  73. this.eyeDomeLightingRadius = defaultValue(
  74. pointCloudShading.eyeDomeLightingRadius,
  75. 1.0
  76. );
  77. /**
  78. * Determines whether back-facing points are hidden.
  79. * This option works only if data has normals included.
  80. *
  81. * @type {boolean}
  82. * @default false
  83. */
  84. this.backFaceCulling = defaultValue(pointCloudShading.backFaceCulling, false);
  85. /**
  86. * Determines whether a point cloud that contains normals is shaded by the scene's light source.
  87. *
  88. * @type {boolean}
  89. * @default true
  90. */
  91. this.normalShading = defaultValue(pointCloudShading.normalShading, true);
  92. }
  93. /**
  94. * Determines if point cloud shading is supported.
  95. *
  96. * @param {Scene} scene The scene.
  97. * @returns {boolean} <code>true</code> if point cloud shading is supported; otherwise, returns <code>false</code>
  98. */
  99. PointCloudShading.isSupported = function (scene) {
  100. return PointCloudEyeDomeLighting.isSupported(scene.context);
  101. };
  102. export default PointCloudShading;