智慧水务管理系统 - 精河县供水工程综合管理平台

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. import Frozen from "../Core/Frozen.js";
  2. import defined from "../Core/defined.js";
  3. import VertexFormat from "../Core/VertexFormat.js";
  4. import EllipsoidSurfaceAppearanceFS from "../Shaders/Appearances/EllipsoidSurfaceAppearanceFS.js";
  5. import EllipsoidSurfaceAppearanceVS from "../Shaders/Appearances/EllipsoidSurfaceAppearanceVS.js";
  6. import Appearance from "./Appearance.js";
  7. import Material from "./Material.js";
  8. /**
  9. * An appearance for geometry on the surface of the ellipsoid like {@link PolygonGeometry}
  10. * and {@link RectangleGeometry}, which supports all materials like {@link MaterialAppearance}
  11. * with {@link MaterialAppearance.MaterialSupport.ALL}. However, this appearance requires
  12. * fewer vertex attributes since the fragment shader can procedurally compute <code>normal</code>,
  13. * <code>tangent</code>, and <code>bitangent</code>.
  14. *
  15. * @alias EllipsoidSurfaceAppearance
  16. * @constructor
  17. *
  18. * @param {object} [options] Object with the following properties:
  19. * @param {boolean} [options.flat=false] When <code>true</code>, flat shading is used in the fragment shader, which means lighting is not taking into account.
  20. * @param {boolean} [options.faceForward=options.aboveGround] When <code>true</code>, the fragment shader flips the surface normal as needed to ensure that the normal faces the viewer to avoid dark spots. This is useful when both sides of a geometry should be shaded like {@link WallGeometry}.
  21. * @param {boolean} [options.translucent=true] When <code>true</code>, the geometry is expected to appear translucent so {@link EllipsoidSurfaceAppearance#renderState} has alpha blending enabled.
  22. * @param {boolean} [options.aboveGround=false] When <code>true</code>, the geometry is expected to be on the ellipsoid's surface - not at a constant height above it - so {@link EllipsoidSurfaceAppearance#renderState} has backface culling enabled.
  23. * @param {Material} [options.material=Material.ColorType] The material used to determine the fragment color.
  24. * @param {string} [options.vertexShaderSource] Optional GLSL vertex shader source to override the default vertex shader.
  25. * @param {string} [options.fragmentShaderSource] Optional GLSL fragment shader source to override the default fragment shader.
  26. * @param {object} [options.renderState] Optional render state to override the default render state.
  27. *
  28. * @see {@link https://github.com/CesiumGS/cesium/wiki/Fabric|Fabric}
  29. *
  30. * @example
  31. * const primitive = new Cesium.Primitive({
  32. * geometryInstances : new Cesium.GeometryInstance({
  33. * geometry : new Cesium.PolygonGeometry({
  34. * vertexFormat : Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT,
  35. * // ...
  36. * })
  37. * }),
  38. * appearance : new Cesium.EllipsoidSurfaceAppearance({
  39. * material : Cesium.Material.fromType('Stripe')
  40. * })
  41. * });
  42. */
  43. function EllipsoidSurfaceAppearance(options) {
  44. options = options ?? Frozen.EMPTY_OBJECT;
  45. const translucent = options.translucent ?? true;
  46. const aboveGround = options.aboveGround ?? false;
  47. /**
  48. * The material used to determine the fragment color. Unlike other {@link EllipsoidSurfaceAppearance}
  49. * properties, this is not read-only, so an appearance's material can change on the fly.
  50. *
  51. * @type Material
  52. *
  53. * @default {@link Material.ColorType}
  54. *
  55. * @see {@link https://github.com/CesiumGS/cesium/wiki/Fabric|Fabric}
  56. */
  57. this.material = defined(options.material)
  58. ? options.material
  59. : Material.fromType(Material.ColorType);
  60. /**
  61. * When <code>true</code>, the geometry is expected to appear translucent.
  62. *
  63. * @type {boolean}
  64. *
  65. * @default true
  66. */
  67. this.translucent = options.translucent ?? true;
  68. this._vertexShaderSource =
  69. options.vertexShaderSource ?? EllipsoidSurfaceAppearanceVS;
  70. this._fragmentShaderSource =
  71. options.fragmentShaderSource ?? EllipsoidSurfaceAppearanceFS;
  72. this._renderState = Appearance.getDefaultRenderState(
  73. translucent,
  74. !aboveGround,
  75. options.renderState,
  76. );
  77. this._closed = false;
  78. // Non-derived members
  79. this._flat = options.flat ?? false;
  80. this._faceForward = options.faceForward ?? aboveGround;
  81. this._aboveGround = aboveGround;
  82. }
  83. Object.defineProperties(EllipsoidSurfaceAppearance.prototype, {
  84. /**
  85. * The GLSL source code for the vertex shader.
  86. *
  87. * @memberof EllipsoidSurfaceAppearance.prototype
  88. *
  89. * @type {string}
  90. * @readonly
  91. */
  92. vertexShaderSource: {
  93. get: function () {
  94. return this._vertexShaderSource;
  95. },
  96. },
  97. /**
  98. * The GLSL source code for the fragment shader. The full fragment shader
  99. * source is built procedurally taking into account {@link EllipsoidSurfaceAppearance#material},
  100. * {@link EllipsoidSurfaceAppearance#flat}, and {@link EllipsoidSurfaceAppearance#faceForward}.
  101. * Use {@link EllipsoidSurfaceAppearance#getFragmentShaderSource} to get the full source.
  102. *
  103. * @memberof EllipsoidSurfaceAppearance.prototype
  104. *
  105. * @type {string}
  106. * @readonly
  107. */
  108. fragmentShaderSource: {
  109. get: function () {
  110. return this._fragmentShaderSource;
  111. },
  112. },
  113. /**
  114. * The WebGL fixed-function state to use when rendering the geometry.
  115. * <p>
  116. * The render state can be explicitly defined when constructing a {@link EllipsoidSurfaceAppearance}
  117. * instance, or it is set implicitly via {@link EllipsoidSurfaceAppearance#translucent}
  118. * and {@link EllipsoidSurfaceAppearance#aboveGround}.
  119. * </p>
  120. *
  121. * @memberof EllipsoidSurfaceAppearance.prototype
  122. *
  123. * @type {object}
  124. * @readonly
  125. */
  126. renderState: {
  127. get: function () {
  128. return this._renderState;
  129. },
  130. },
  131. /**
  132. * When <code>true</code>, the geometry is expected to be closed so
  133. * {@link EllipsoidSurfaceAppearance#renderState} has backface culling enabled.
  134. * If the viewer enters the geometry, it will not be visible.
  135. *
  136. * @memberof EllipsoidSurfaceAppearance.prototype
  137. *
  138. * @type {boolean}
  139. * @readonly
  140. *
  141. * @default false
  142. */
  143. closed: {
  144. get: function () {
  145. return this._closed;
  146. },
  147. },
  148. /**
  149. * The {@link VertexFormat} that this appearance instance is compatible with.
  150. * A geometry can have more vertex attributes and still be compatible - at a
  151. * potential performance cost - but it can't have less.
  152. *
  153. * @memberof EllipsoidSurfaceAppearance.prototype
  154. *
  155. * @type VertexFormat
  156. * @readonly
  157. *
  158. * @default {@link EllipsoidSurfaceAppearance.VERTEX_FORMAT}
  159. */
  160. vertexFormat: {
  161. get: function () {
  162. return EllipsoidSurfaceAppearance.VERTEX_FORMAT;
  163. },
  164. },
  165. /**
  166. * When <code>true</code>, flat shading is used in the fragment shader,
  167. * which means lighting is not taking into account.
  168. *
  169. * @memberof EllipsoidSurfaceAppearance.prototype
  170. *
  171. * @type {boolean}
  172. * @readonly
  173. *
  174. * @default false
  175. */
  176. flat: {
  177. get: function () {
  178. return this._flat;
  179. },
  180. },
  181. /**
  182. * When <code>true</code>, the fragment shader flips the surface normal
  183. * as needed to ensure that the normal faces the viewer to avoid
  184. * dark spots. This is useful when both sides of a geometry should be
  185. * shaded like {@link WallGeometry}.
  186. *
  187. * @memberof EllipsoidSurfaceAppearance.prototype
  188. *
  189. * @type {boolean}
  190. * @readonly
  191. *
  192. * @default true
  193. */
  194. faceForward: {
  195. get: function () {
  196. return this._faceForward;
  197. },
  198. },
  199. /**
  200. * When <code>true</code>, the geometry is expected to be on the ellipsoid's
  201. * surface - not at a constant height above it - so {@link EllipsoidSurfaceAppearance#renderState}
  202. * has backface culling enabled.
  203. *
  204. *
  205. * @memberof EllipsoidSurfaceAppearance.prototype
  206. *
  207. * @type {boolean}
  208. * @readonly
  209. *
  210. * @default false
  211. */
  212. aboveGround: {
  213. get: function () {
  214. return this._aboveGround;
  215. },
  216. },
  217. });
  218. /**
  219. * The {@link VertexFormat} that all {@link EllipsoidSurfaceAppearance} instances
  220. * are compatible with, which requires only <code>position</code> and <code>st</code>
  221. * attributes. Other attributes are procedurally computed in the fragment shader.
  222. *
  223. * @type VertexFormat
  224. *
  225. * @constant
  226. */
  227. EllipsoidSurfaceAppearance.VERTEX_FORMAT = VertexFormat.POSITION_AND_ST;
  228. /**
  229. * Procedurally creates the full GLSL fragment shader source. For {@link EllipsoidSurfaceAppearance},
  230. * this is derived from {@link EllipsoidSurfaceAppearance#fragmentShaderSource}, {@link EllipsoidSurfaceAppearance#flat},
  231. * and {@link EllipsoidSurfaceAppearance#faceForward}.
  232. *
  233. * @function
  234. *
  235. * @returns {string} The full GLSL fragment shader source.
  236. */
  237. EllipsoidSurfaceAppearance.prototype.getFragmentShaderSource =
  238. Appearance.prototype.getFragmentShaderSource;
  239. /**
  240. * Determines if the geometry is translucent based on {@link EllipsoidSurfaceAppearance#translucent} and {@link Material#isTranslucent}.
  241. *
  242. * @function
  243. *
  244. * @returns {boolean} <code>true</code> if the appearance is translucent.
  245. */
  246. EllipsoidSurfaceAppearance.prototype.isTranslucent =
  247. Appearance.prototype.isTranslucent;
  248. /**
  249. * Creates a render state. This is not the final render state instance; instead,
  250. * it can contain a subset of render state properties identical to the render state
  251. * created in the context.
  252. *
  253. * @function
  254. *
  255. * @returns {object} The render state.
  256. */
  257. EllipsoidSurfaceAppearance.prototype.getRenderState =
  258. Appearance.prototype.getRenderState;
  259. export default EllipsoidSurfaceAppearance;