Cesium3DTileStyleEngine.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import defined from '../Core/defined.js';
  2. import defineProperties from '../Core/defineProperties.js';
  3. /**
  4. * @private
  5. */
  6. function Cesium3DTileStyleEngine() {
  7. this._style = undefined; // The style provided by the user
  8. this._styleDirty = false; // true when the style is reassigned
  9. this._lastStyleTime = 0; // The "time" when the last style was assigned
  10. }
  11. defineProperties(Cesium3DTileStyleEngine.prototype, {
  12. style : {
  13. get : function() {
  14. return this._style;
  15. },
  16. set : function(value) {
  17. this._style = value;
  18. this._styleDirty = true;
  19. }
  20. }
  21. });
  22. Cesium3DTileStyleEngine.prototype.makeDirty = function() {
  23. this._styleDirty = true;
  24. };
  25. Cesium3DTileStyleEngine.prototype.applyStyle = function(tileset, frameState) {
  26. if (!tileset.ready) {
  27. return;
  28. }
  29. if (defined(this._style) && !this._style.ready) {
  30. return;
  31. }
  32. var styleDirty = this._styleDirty;
  33. if (frameState.passes.render) {
  34. // Don't reset until the color pass, e.g., for mouse-over picking
  35. this._styleDirty = false;
  36. }
  37. if (styleDirty) {
  38. // Increase "time", so the style is applied to all visible tiles
  39. ++this._lastStyleTime;
  40. }
  41. var lastStyleTime = this._lastStyleTime;
  42. var statistics = tileset._statistics;
  43. // If a new style was assigned, loop through all the visible tiles; otherwise, loop through
  44. // only the tiles that are newly visible, i.e., they are visible this frame, but were not
  45. // visible last frame. In many cases, the newly selected tiles list will be short or empty.
  46. var tiles = styleDirty ? tileset._selectedTiles : tileset._selectedTilesToStyle;
  47. // PERFORMANCE_IDEA: does mouse-over picking basically trash this? We need to style on
  48. // pick, for example, because a feature's show may be false.
  49. var length = tiles.length;
  50. for (var i = 0; i < length; ++i) {
  51. var tile = tiles[i];
  52. if (tile.lastStyleTime !== lastStyleTime) {
  53. // Apply the style to this tile if it wasn't already applied because:
  54. // 1) the user assigned a new style to the tileset
  55. // 2) this tile is now visible, but it wasn't visible when the style was first assigned
  56. var content = tile.content;
  57. tile.lastStyleTime = lastStyleTime;
  58. content.applyStyle(this._style);
  59. statistics.numberOfFeaturesStyled += content.featuresLength;
  60. ++statistics.numberOfTilesStyled;
  61. }
  62. }
  63. };
  64. export default Cesium3DTileStyleEngine;