PointCloudShading.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 based on the sun direction.
  17. *
  18. * @alias PointCloudShading
  19. * @constructor
  20. */
  21. function PointCloudShading(options) {
  22. var 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(pointCloudShading.geometricErrorScale, 1.0);
  35. /**
  36. * Maximum point attenuation in pixels. If undefined, the Cesium3DTileset's maximumScreenSpaceError will be used.
  37. * @type {Number}
  38. */
  39. this.maximumAttenuation = pointCloudShading.maximumAttenuation;
  40. /**
  41. * Average base resolution for the dataset in meters.
  42. * Used in place of geometric error when geometric error is 0.
  43. * If undefined, an approximation will be computed for each tile that has geometric error of 0.
  44. * @type {Number}
  45. */
  46. this.baseResolution = pointCloudShading.baseResolution;
  47. /**
  48. * Use eye dome lighting when drawing with point attenuation
  49. * Requires support for EXT_frag_depth, OES_texture_float, and WEBGL_draw_buffers extensions in WebGL 1.0,
  50. * otherwise eye dome lighting is ignored.
  51. *
  52. * @type {Boolean}
  53. * @default true
  54. */
  55. this.eyeDomeLighting = defaultValue(pointCloudShading.eyeDomeLighting, true);
  56. /**
  57. * Eye dome lighting strength (apparent contrast)
  58. * @type {Number}
  59. * @default 1.0
  60. */
  61. this.eyeDomeLightingStrength = defaultValue(pointCloudShading.eyeDomeLightingStrength, 1.0);
  62. /**
  63. * Thickness of contours from eye dome lighting
  64. * @type {Number}
  65. * @default 1.0
  66. */
  67. this.eyeDomeLightingRadius = defaultValue(pointCloudShading.eyeDomeLightingRadius, 1.0);
  68. /**
  69. * Determines whether back-facing points are hidden.
  70. * This option works only if data has normals included.
  71. *
  72. * @type {Boolean}
  73. * @default false
  74. */
  75. this.backFaceCulling = defaultValue(pointCloudShading.backFaceCulling, false);
  76. /**
  77. * Determines whether a point cloud that contains normals is shaded based on the sun direction.
  78. *
  79. * @type {Boolean}
  80. * @default true
  81. */
  82. this.normalShading = defaultValue(pointCloudShading.normalShading, true);
  83. }
  84. /**
  85. * Determines if point cloud shading is supported.
  86. *
  87. * @param {Scene} scene The scene.
  88. * @returns {Boolean} <code>true</code> if point cloud shading is supported; otherwise, returns <code>false</code>
  89. */
  90. PointCloudShading.isSupported = function(scene) {
  91. return PointCloudEyeDomeLighting.isSupported(scene.context);
  92. };
  93. export default PointCloudShading;