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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. import Frozen from "../Core/Frozen.js";
  2. import defined from "../Core/defined.js";
  3. import DeveloperError from "../Core/DeveloperError.js";
  4. import Event from "../Core/Event.js";
  5. import createPropertyDescriptor from "./createPropertyDescriptor.js";
  6. import NodeTransformationProperty from "./NodeTransformationProperty.js";
  7. import PropertyBag from "./PropertyBag.js";
  8. function createNodeTransformationProperty(value) {
  9. return new NodeTransformationProperty(value);
  10. }
  11. function createNodeTransformationPropertyBag(value) {
  12. return new PropertyBag(value, createNodeTransformationProperty);
  13. }
  14. function createArticulationStagePropertyBag(value) {
  15. return new PropertyBag(value);
  16. }
  17. function createEnvironmentMapPropertyBag(value) {
  18. return new PropertyBag(value);
  19. }
  20. /**
  21. * @typedef {object} ModelGraphics.ConstructorOptions
  22. *
  23. * Initialization options for the ModelGraphics constructor
  24. *
  25. * @property {Property | boolean} [show=true] A boolean Property specifying the visibility of the model.
  26. * @property {Property | string | Resource} [uri] A string or Resource Property specifying the URI of the glTF asset.
  27. * @property {Property | number} [scale=1.0] A numeric Property specifying a uniform linear scale.
  28. * @property {Property | boolean} [enableVerticalExaggeration=true] A boolean Property specifying if the model is exaggerated along the ellipsoid normal when {@link Scene.verticalExaggeration} is set to a value other than <code>1.0</code>.
  29. * @property {Property | number} [minimumPixelSize=0.0] A numeric Property specifying the approximate minimum pixel size of the model regardless of zoom.
  30. * @property {Property | number} [maximumScale] The maximum scale size of a model. An upper limit for minimumPixelSize.
  31. * @property {Property | boolean} [incrementallyLoadTextures=true] Determine if textures may continue to stream in after the model is loaded.
  32. * @property {Property | boolean} [runAnimations=true] A boolean Property specifying if glTF animations specified in the model should be started.
  33. * @property {Property | boolean} [clampAnimations=true] A boolean Property specifying if glTF animations should hold the last pose for time durations with no keyframes.
  34. * @property {Property | ShadowMode} [shadows=ShadowMode.ENABLED] An enum Property specifying whether the model casts or receives shadows from light sources.
  35. * @property {Property | HeightReference} [heightReference=HeightReference.NONE] A Property specifying what the height is relative to.
  36. * @property {Property | Color} [silhouetteColor=Color.RED] A Property specifying the {@link Color} of the silhouette.
  37. * @property {Property | number} [silhouetteSize=0.0] A numeric Property specifying the size of the silhouette in pixels.
  38. * @property {Property | Color} [color=Color.WHITE] A Property specifying the {@link Color} that blends with the model's rendered color.
  39. * @property {Property | ColorBlendMode} [colorBlendMode=ColorBlendMode.HIGHLIGHT] An enum Property specifying how the color blends with the model.
  40. * @property {Property | number} [colorBlendAmount=0.5] A numeric Property specifying the color strength when the <code>colorBlendMode</code> is <code>MIX</code>. A value of 0.0 results in the model's rendered color while a value of 1.0 results in a solid color, with any value in-between resulting in a mix of the two.
  41. * @property {Property | Cartesian2} [imageBasedLightingFactor=new Cartesian2(1.0, 1.0)] A property specifying the contribution from diffuse and specular image-based lighting.
  42. * @property {PropertyBag | Object<string, *>} [environmentMapOptions] The properties for managing dynamic environment maps on this entity.
  43. * @property {Property | Color} [lightColor] A property specifying the light color when shading the model. When <code>undefined</code> the scene's light color is used instead.
  44. * @property {Property | DistanceDisplayCondition} [distanceDisplayCondition] A Property specifying at what distance from the camera that this model will be displayed.
  45. * @property {PropertyBag | Object<string, TranslationRotationScale>} [nodeTransformations] An object, where keys are names of nodes, and values are {@link TranslationRotationScale} Properties describing the transformation to apply to that node. The transformation is applied after the node's existing transformation as specified in the glTF, and does not replace the node's existing transformation.
  46. * @property {PropertyBag | Object<string, number>} [articulations] An object, where keys are composed of an articulation name, a single space, and a stage name, and the values are numeric properties.
  47. * @property {Property | ClippingPlaneCollection} [clippingPlanes] A property specifying the {@link ClippingPlaneCollection} used to selectively disable rendering the model.
  48. * @property {Property | CustomShader} [customShader] A property specifying the {@link CustomShader} to apply to this model.
  49. */
  50. /**
  51. * A 3D model based on {@link https://github.com/KhronosGroup/glTF|glTF}, the runtime asset format for WebGL, OpenGL ES, and OpenGL.
  52. * The position and orientation of the model is determined by the containing {@link Entity}.
  53. * <p>
  54. * Cesium includes support for glTF geometry, materials, animations, and skinning.
  55. * Cameras and lights are not currently supported.
  56. * </p>
  57. *
  58. * @alias ModelGraphics
  59. * @constructor
  60. *
  61. * @param {ModelGraphics.ConstructorOptions} [options] Object describing initialization options
  62. *
  63. * @demo {@link https://sandcastle.cesium.com/index.html?id=3d-models|Cesium Sandcastle 3D Models Demo}
  64. */
  65. function ModelGraphics(options) {
  66. this._definitionChanged = new Event();
  67. this._show = undefined;
  68. this._showSubscription = undefined;
  69. this._uri = undefined;
  70. this._uriSubscription = undefined;
  71. this._scale = undefined;
  72. this._scaleSubscription = undefined;
  73. this._hasVerticalExaggeration = undefined;
  74. this._hasVerticalExaggerationSubscription = undefined;
  75. this._enableVerticalExaggeration = undefined;
  76. this._enableVerticalExaggerationSubscription = undefined;
  77. this._minimumPixelSize = undefined;
  78. this._minimumPixelSizeSubscription = undefined;
  79. this._maximumScale = undefined;
  80. this._maximumScaleSubscription = undefined;
  81. this._incrementallyLoadTextures = undefined;
  82. this._incrementallyLoadTexturesSubscription = undefined;
  83. this._runAnimations = undefined;
  84. this._runAnimationsSubscription = undefined;
  85. this._clampAnimations = undefined;
  86. this._clampAnimationsSubscription = undefined;
  87. this._shadows = undefined;
  88. this._shadowsSubscription = undefined;
  89. this._heightReference = undefined;
  90. this._heightReferenceSubscription = undefined;
  91. this._silhouetteColor = undefined;
  92. this._silhouetteColorSubscription = undefined;
  93. this._silhouetteSize = undefined;
  94. this._silhouetteSizeSubscription = undefined;
  95. this._color = undefined;
  96. this._colorSubscription = undefined;
  97. this._colorBlendMode = undefined;
  98. this._colorBlendModeSubscription = undefined;
  99. this._colorBlendAmount = undefined;
  100. this._colorBlendAmountSubscription = undefined;
  101. this._imageBasedLightingFactor = undefined;
  102. this._imageBasedLightingFactorSubscription = undefined;
  103. this._environmentMapOptions = undefined;
  104. this._environmentMapOptionsSubscription = undefined;
  105. this._lightColor = undefined;
  106. this._lightColorSubscription = undefined;
  107. this._distanceDisplayCondition = undefined;
  108. this._distanceDisplayConditionSubscription = undefined;
  109. this._nodeTransformations = undefined;
  110. this._nodeTransformationsSubscription = undefined;
  111. this._articulations = undefined;
  112. this._articulationsSubscription = undefined;
  113. this._clippingPlanes = undefined;
  114. this._clippingPlanesSubscription = undefined;
  115. this._customShader = undefined;
  116. this._customShaderSubscription = undefined;
  117. this.merge(options ?? Frozen.EMPTY_OBJECT);
  118. }
  119. Object.defineProperties(ModelGraphics.prototype, {
  120. /**
  121. * Gets the event that is raised whenever a property or sub-property is changed or modified.
  122. * @memberof ModelGraphics.prototype
  123. * @type {Event}
  124. * @readonly
  125. */
  126. definitionChanged: {
  127. get: function () {
  128. return this._definitionChanged;
  129. },
  130. },
  131. /**
  132. * Gets or sets the boolean Property specifying the visibility of the model.
  133. * @memberof ModelGraphics.prototype
  134. * @type {Property|undefined}
  135. * @default true
  136. */
  137. show: createPropertyDescriptor("show"),
  138. /**
  139. * Gets or sets the string Property specifying the URI of the glTF asset.
  140. * @memberof ModelGraphics.prototype
  141. * @type {Property|undefined}
  142. */
  143. uri: createPropertyDescriptor("uri"),
  144. /**
  145. * Gets or sets the numeric Property specifying a uniform linear scale
  146. * for this model. Values greater than 1.0 increase the size of the model while
  147. * values less than 1.0 decrease it.
  148. * @memberof ModelGraphics.prototype
  149. * @type {Property|undefined}
  150. * @default 1.0
  151. */
  152. scale: createPropertyDescriptor("scale"),
  153. /**
  154. * Gets or sets the boolean Property specifying if the model is exaggerated along the ellipsoid normal when {@link Scene.verticalExaggeration} is set to a value other than <code>1.0</code>.
  155. * @memberof ModelGraphics.prototype
  156. * @type {Property|undefined}
  157. * @default true
  158. */
  159. enableVerticalExaggeration: createPropertyDescriptor(
  160. "enableVerticalExaggeration",
  161. ),
  162. /**
  163. * Gets or sets the numeric Property specifying the approximate minimum
  164. * pixel size of the model regardless of zoom. This can be used to ensure that
  165. * a model is visible even when the viewer zooms out. When <code>0.0</code>,
  166. * no minimum size is enforced.
  167. * @memberof ModelGraphics.prototype
  168. * @type {Property|undefined}
  169. * @default 0.0
  170. */
  171. minimumPixelSize: createPropertyDescriptor("minimumPixelSize"),
  172. /**
  173. * Gets or sets the numeric Property specifying the maximum scale
  174. * size of a model. This property is used as an upper limit for
  175. * {@link ModelGraphics#minimumPixelSize}.
  176. * @memberof ModelGraphics.prototype
  177. * @type {Property|undefined}
  178. */
  179. maximumScale: createPropertyDescriptor("maximumScale"),
  180. /**
  181. * Get or sets the boolean Property specifying whether textures
  182. * may continue to stream in after the model is loaded.
  183. * @memberof ModelGraphics.prototype
  184. * @type {Property|undefined}
  185. */
  186. incrementallyLoadTextures: createPropertyDescriptor(
  187. "incrementallyLoadTextures",
  188. ),
  189. /**
  190. * Gets or sets the boolean Property specifying if glTF animations should be run.
  191. * @memberof ModelGraphics.prototype
  192. * @type {Property|undefined}
  193. * @default true
  194. */
  195. runAnimations: createPropertyDescriptor("runAnimations"),
  196. /**
  197. * Gets or sets the boolean Property specifying if glTF animations should hold the last pose for time durations with no keyframes.
  198. * @memberof ModelGraphics.prototype
  199. * @type {Property|undefined}
  200. * @default true
  201. */
  202. clampAnimations: createPropertyDescriptor("clampAnimations"),
  203. /**
  204. * Get or sets the enum Property specifying whether the model
  205. * casts or receives shadows from light sources.
  206. * @memberof ModelGraphics.prototype
  207. * @type {Property|undefined}
  208. * @default ShadowMode.ENABLED
  209. */
  210. shadows: createPropertyDescriptor("shadows"),
  211. /**
  212. * Gets or sets the Property specifying the {@link HeightReference}.
  213. * @memberof ModelGraphics.prototype
  214. * @type {Property|undefined}
  215. * @default HeightReference.NONE
  216. */
  217. heightReference: createPropertyDescriptor("heightReference"),
  218. /**
  219. * Gets or sets the Property specifying the {@link Color} of the silhouette.
  220. * @memberof ModelGraphics.prototype
  221. * @type {Property|undefined}
  222. * @default Color.RED
  223. */
  224. silhouetteColor: createPropertyDescriptor("silhouetteColor"),
  225. /**
  226. * Gets or sets the numeric Property specifying the size of the silhouette in pixels.
  227. * @memberof ModelGraphics.prototype
  228. * @type {Property|undefined}
  229. * @default 0.0
  230. */
  231. silhouetteSize: createPropertyDescriptor("silhouetteSize"),
  232. /**
  233. * Gets or sets the Property specifying the {@link Color} that blends with the model's rendered color.
  234. * @memberof ModelGraphics.prototype
  235. * @type {Property|undefined}
  236. * @default Color.WHITE
  237. */
  238. color: createPropertyDescriptor("color"),
  239. /**
  240. * Gets or sets the enum Property specifying how the color blends with the model.
  241. * @memberof ModelGraphics.prototype
  242. * @type {Property|undefined}
  243. * @default ColorBlendMode.HIGHLIGHT
  244. */
  245. colorBlendMode: createPropertyDescriptor("colorBlendMode"),
  246. /**
  247. * A numeric Property specifying the color strength when the <code>colorBlendMode</code> is MIX.
  248. * A value of 0.0 results in the model's rendered color while a value of 1.0 results in a solid color, with
  249. * any value in-between resulting in a mix of the two.
  250. * @memberof ModelGraphics.prototype
  251. * @type {Property|undefined}
  252. * @default 0.5
  253. */
  254. colorBlendAmount: createPropertyDescriptor("colorBlendAmount"),
  255. /**
  256. * A property specifying the {@link Cartesian2} used to scale the diffuse and specular image-based lighting contribution to the final color.
  257. * @memberof ModelGraphics.prototype
  258. * @type {Property|undefined}
  259. */
  260. imageBasedLightingFactor: createPropertyDescriptor(
  261. "imageBasedLightingFactor",
  262. ),
  263. /**
  264. * Gets or sets the {@link DynamicEnvironmentMapManager.ConstructorOptions} to apply to this model. This is represented as an {@link PropertyBag}.
  265. * @memberof ModelGraphics.prototype
  266. * @type {PropertyBag}
  267. */
  268. environmentMapOptions: createPropertyDescriptor(
  269. "environmentMapOptions",
  270. undefined,
  271. createEnvironmentMapPropertyBag,
  272. ),
  273. /**
  274. * A property specifying the {@link Cartesian3} light color when shading the model. When <code>undefined</code> the scene's light color is used instead.
  275. * @memberOf ModelGraphics.prototype
  276. * @type {Property|undefined}
  277. */
  278. lightColor: createPropertyDescriptor("lightColor"),
  279. /**
  280. * Gets or sets the {@link DistanceDisplayCondition} Property specifying at what distance from the camera that this model will be displayed.
  281. * @memberof ModelGraphics.prototype
  282. * @type {Property|undefined}
  283. */
  284. distanceDisplayCondition: createPropertyDescriptor(
  285. "distanceDisplayCondition",
  286. ),
  287. /**
  288. * Gets or sets the set of node transformations to apply to this model. This is represented as an {@link PropertyBag}, where keys are
  289. * names of nodes, and values are {@link TranslationRotationScale} Properties describing the transformation to apply to that node.
  290. * The transformation is applied after the node's existing transformation as specified in the glTF, and does not replace the node's existing transformation.
  291. * @memberof ModelGraphics.prototype
  292. * @type {PropertyBag}
  293. */
  294. nodeTransformations: createPropertyDescriptor(
  295. "nodeTransformations",
  296. undefined,
  297. createNodeTransformationPropertyBag,
  298. ),
  299. /**
  300. * Gets or sets the set of articulation values to apply to this model. This is represented as an {@link PropertyBag}, where keys are
  301. * composed as the name of the articulation, a single space, and the name of the stage.
  302. * @memberof ModelGraphics.prototype
  303. * @type {PropertyBag}
  304. */
  305. articulations: createPropertyDescriptor(
  306. "articulations",
  307. undefined,
  308. createArticulationStagePropertyBag,
  309. ),
  310. /**
  311. * A property specifying the {@link ClippingPlaneCollection} used to selectively disable rendering the model.
  312. * @memberof ModelGraphics.prototype
  313. * @type {Property|undefined}
  314. */
  315. clippingPlanes: createPropertyDescriptor("clippingPlanes"),
  316. /**
  317. * Gets or sets the {@link CustomShader} to apply to this model. When <code>undefined</code>, no custom shader code is used.
  318. * @memberof ModelGraphics.prototype
  319. * @type {Property|undefined}
  320. */
  321. customShader: createPropertyDescriptor("customShader"),
  322. });
  323. /**
  324. * Duplicates this instance.
  325. *
  326. * @param {ModelGraphics} [result] The object onto which to store the result.
  327. * @returns {ModelGraphics} The modified result parameter or a new instance if one was not provided.
  328. */
  329. ModelGraphics.prototype.clone = function (result) {
  330. if (!defined(result)) {
  331. return new ModelGraphics(this);
  332. }
  333. result.show = this.show;
  334. result.uri = this.uri;
  335. result.scale = this.scale;
  336. result.enableVerticalExaggeration = this.enableVerticalExaggeration;
  337. result.minimumPixelSize = this.minimumPixelSize;
  338. result.maximumScale = this.maximumScale;
  339. result.incrementallyLoadTextures = this.incrementallyLoadTextures;
  340. result.runAnimations = this.runAnimations;
  341. result.clampAnimations = this.clampAnimations;
  342. result.heightReference = this._heightReference;
  343. result.silhouetteColor = this.silhouetteColor;
  344. result.silhouetteSize = this.silhouetteSize;
  345. result.color = this.color;
  346. result.colorBlendMode = this.colorBlendMode;
  347. result.colorBlendAmount = this.colorBlendAmount;
  348. result.imageBasedLightingFactor = this.imageBasedLightingFactor;
  349. result.environmentMapOptions = this.environmentMapOptions;
  350. result.lightColor = this.lightColor;
  351. result.distanceDisplayCondition = this.distanceDisplayCondition;
  352. result.nodeTransformations = this.nodeTransformations;
  353. result.articulations = this.articulations;
  354. result.clippingPlanes = this.clippingPlanes;
  355. result.customShader = this.customShader;
  356. return result;
  357. };
  358. /**
  359. * Assigns each unassigned property on this object to the value
  360. * of the same property on the provided source object.
  361. *
  362. * @param {ModelGraphics} source The object to be merged into this object.
  363. */
  364. ModelGraphics.prototype.merge = function (source) {
  365. //>>includeStart('debug', pragmas.debug);
  366. if (!defined(source)) {
  367. throw new DeveloperError("source is required.");
  368. }
  369. //>>includeEnd('debug');
  370. this.show = this.show ?? source.show;
  371. this.uri = this.uri ?? source.uri;
  372. this.scale = this.scale ?? source.scale;
  373. this.enableVerticalExaggeration =
  374. this.enableVerticalExaggeration ?? source.enableVerticalExaggeration;
  375. this.minimumPixelSize = this.minimumPixelSize ?? source.minimumPixelSize;
  376. this.maximumScale = this.maximumScale ?? source.maximumScale;
  377. this.incrementallyLoadTextures =
  378. this.incrementallyLoadTextures ?? source.incrementallyLoadTextures;
  379. this.runAnimations = this.runAnimations ?? source.runAnimations;
  380. this.clampAnimations = this.clampAnimations ?? source.clampAnimations;
  381. this.shadows = this.shadows ?? source.shadows;
  382. this.heightReference = this.heightReference ?? source.heightReference;
  383. this.silhouetteColor = this.silhouetteColor ?? source.silhouetteColor;
  384. this.silhouetteSize = this.silhouetteSize ?? source.silhouetteSize;
  385. this.color = this.color ?? source.color;
  386. this.colorBlendMode = this.colorBlendMode ?? source.colorBlendMode;
  387. this.colorBlendAmount = this.colorBlendAmount ?? source.colorBlendAmount;
  388. this.imageBasedLightingFactor =
  389. this.imageBasedLightingFactor ?? source.imageBasedLightingFactor;
  390. this.environmentMapOptions =
  391. this.environmentMapOptions ?? source.environmentMapOptions;
  392. this.lightColor = this.lightColor ?? source.lightColor;
  393. this.distanceDisplayCondition =
  394. this.distanceDisplayCondition ?? source.distanceDisplayCondition;
  395. this.clippingPlanes = this.clippingPlanes ?? source.clippingPlanes;
  396. this.customShader = this.customShader ?? source.customShader;
  397. const sourceNodeTransformations = source.nodeTransformations;
  398. if (defined(sourceNodeTransformations)) {
  399. const targetNodeTransformations = this.nodeTransformations;
  400. if (defined(targetNodeTransformations)) {
  401. targetNodeTransformations.merge(sourceNodeTransformations);
  402. } else {
  403. this.nodeTransformations = new PropertyBag(
  404. sourceNodeTransformations,
  405. createNodeTransformationProperty,
  406. );
  407. }
  408. }
  409. const sourceArticulations = source.articulations;
  410. if (defined(sourceArticulations)) {
  411. const targetArticulations = this.articulations;
  412. if (defined(targetArticulations)) {
  413. targetArticulations.merge(sourceArticulations);
  414. } else {
  415. this.articulations = new PropertyBag(sourceArticulations);
  416. }
  417. }
  418. };
  419. export default ModelGraphics;