All files / engine/Source/Scene Cesium3DTilesetStatistics.js

100% Statements 104/104
100% Branches 16/16
100% Functions 6/6
100% Lines 101/101

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196                6750x 6750x   6750x 6750x 6750x 6750x 6750x 6750x 6750x   6750x 6750x 6750x 6750x 6750x   6750x 6750x   6750x   6750x 6750x 6750x 6750x     1x 5994x 5994x 5994x 5994x 5994x 5994x 5994x 5994x 5994x 5994x                       1x     7738x 7738x 7738x     7738x 7738x 242x 242x 489x                             1x 1670x 1670x 1670x 1670x       1670x 414x         1256x 1256x   27x 27x 22x 22x   27x         1670x 1670x 107x 107x 209x                             1x 71x 71x 71x 71x       71x 3x           68x 68x 3x 3x 1x 1x 1x   2x         71x 71x 3x 3x 6x         1x 11835x 11835x 11835x 11835x 11835x 11835x 11835x   11835x 11835x 11835x 11835x 11835x 11835x 11835x 11835x 11835x   11835x 11835x 11835x     11835x      
import defined from "../Core/defined.js";
import Model3DTileContent from "./Model/Model3DTileContent.js";
 
/**
 * @private
 */
function Cesium3DTilesetStatistics() {
  // Rendering statistics
  this.selected = 0;
  this.visited = 0;
  // Loading statistics
  this.numberOfCommands = 0;
  this.numberOfAttemptedRequests = 0;
  this.numberOfPendingRequests = 0;
  this.numberOfTilesProcessing = 0;
  this.numberOfTilesWithContentReady = 0; // Number of tiles with content loaded, does not include empty tiles
  this.numberOfTilesTotal = 0; // Number of tiles in tileset JSON (and other tileset JSON files as they are loaded)
  this.numberOfLoadedTilesTotal = 0; // Running total of loaded tiles for the lifetime of the session
  // Features statistics
  this.numberOfFeaturesSelected = 0; // Number of features rendered
  this.numberOfFeaturesLoaded = 0; // Number of features in memory
  this.numberOfPointsSelected = 0;
  this.numberOfPointsLoaded = 0;
  this.numberOfTrianglesSelected = 0;
  // Styling statistics
  this.numberOfTilesStyled = 0;
  this.numberOfFeaturesStyled = 0;
  // Optimization statistics
  this.numberOfTilesCulledWithChildrenUnion = 0;
  // Memory statistics
  this.geometryByteLength = 0;
  this.texturesByteLength = 0;
  this.texturesReferenceCounterById = {};
  this.batchTableByteLength = 0; // batch textures and any binary metadata properties not otherwise accounted for
}
 
Cesium3DTilesetStatistics.prototype.clear = function () {
  this.selected = 0;
  this.visited = 0;
  this.numberOfCommands = 0;
  this.numberOfAttemptedRequests = 0;
  this.numberOfFeaturesSelected = 0;
  this.numberOfPointsSelected = 0;
  this.numberOfTrianglesSelected = 0;
  this.numberOfTilesStyled = 0;
  this.numberOfFeaturesStyled = 0;
  this.numberOfTilesCulledWithChildrenUnion = 0;
};
 
/**
 * Increment the counters for the points, triangles, and features
 * that are currently selected for rendering.
 *
 * This will be called recursively for the given content and
 * all its inner contents
 *
 * @param {Cesium3DTileContent} content
 */
Cesium3DTilesetStatistics.prototype.incrementSelectionCounts = function (
  content,
) {
  this.numberOfFeaturesSelected += content.featuresLength;
  this.numberOfPointsSelected += content.pointsLength;
  this.numberOfTrianglesSelected += content.trianglesLength;
 
  // Recursive calls on all inner contents
  const contents = content.innerContents;
  if (defined(contents)) {
    const length = contents.length;
    for (let i = 0; i < length; ++i) {
      this.incrementSelectionCounts(contents[i]);
    }
  }
};
 
/**
 * Increment the counters for the number of features and points that
 * are currently loaded, and the lengths (size in bytes) of the
 * occupied memory.
 *
 * This will be called recursively for the given content and
 * all its inner contents
 *
 * @param {Cesium3DTileContent} content
 */
Cesium3DTilesetStatistics.prototype.incrementLoadCounts = function (content) {
  this.numberOfFeaturesLoaded += content.featuresLength;
  this.numberOfPointsLoaded += content.pointsLength;
  this.geometryByteLength += content.geometryByteLength;
  this.batchTableByteLength += content.batchTableByteLength;
 
  // When the content is not a `Model3DTileContent`, then its
  // textures byte length is added directly
  if (!(content instanceof Model3DTileContent)) {
    this.texturesByteLength += content.texturesByteLength;
  } else {
    // When the content is a `Model3DTileContent`, then increment the
    // reference counter for all its textures. The byte length of any
    // newly tracked texture to the total textures byte length
    const textureIds = content.getTextureIds();
    for (const textureId of textureIds) {
      const referenceCounter =
        this.texturesReferenceCounterById[textureId] ?? 0;
      if (referenceCounter === 0) {
        const textureByteLength = content.getTextureByteLengthById(textureId);
        this.texturesByteLength += textureByteLength;
      }
      this.texturesReferenceCounterById[textureId] = referenceCounter + 1;
    }
  }
 
  // Recursive calls on all inner contents
  const contents = content.innerContents;
  if (defined(contents)) {
    const length = contents.length;
    for (let i = 0; i < length; ++i) {
      this.incrementLoadCounts(contents[i]);
    }
  }
};
 
/**
 * Decrement the counters for the number of features and points that
 * are currently loaded, and the lengths (size in bytes) of the
 * occupied memory.
 *
 * This will be called recursively for the given content and
 * all its inner contents
 *
 * @param {Cesium3DTileContent} content
 */
Cesium3DTilesetStatistics.prototype.decrementLoadCounts = function (content) {
  this.numberOfFeaturesLoaded -= content.featuresLength;
  this.numberOfPointsLoaded -= content.pointsLength;
  this.geometryByteLength -= content.geometryByteLength;
  this.batchTableByteLength -= content.batchTableByteLength;
 
  // When the content is not a `Model3DTileContent`, then its
  // textures byte length is subtracted directly
  if (!(content instanceof Model3DTileContent)) {
    this.texturesByteLength -= content.texturesByteLength;
  } else {
    // When the content is a `Model3DTileContent`, then decrement the
    // reference counter for all its textures. The byte length of any
    // texture that is no longer references is subtracted from the
    // total textures byte length
    const textureIds = content.getTextureIds();
    for (const textureId of textureIds) {
      const referenceCounter = this.texturesReferenceCounterById[textureId];
      if (referenceCounter === 1) {
        delete this.texturesReferenceCounterById[textureId];
        const textureByteLength = content.getTextureByteLengthById(textureId);
        this.texturesByteLength -= textureByteLength;
      } else {
        this.texturesReferenceCounterById[textureId] = referenceCounter - 1;
      }
    }
  }
  // Recursive calls on all inner contents
  const contents = content.innerContents;
  if (defined(contents)) {
    const length = contents.length;
    for (let i = 0; i < length; ++i) {
      this.decrementLoadCounts(contents[i]);
    }
  }
};
 
Cesium3DTilesetStatistics.clone = function (statistics, result) {
  result.selected = statistics.selected;
  result.visited = statistics.visited;
  result.numberOfCommands = statistics.numberOfCommands;
  result.numberOfAttemptedRequests = statistics.numberOfAttemptedRequests;
  result.numberOfPendingRequests = statistics.numberOfPendingRequests;
  result.numberOfTilesProcessing = statistics.numberOfTilesProcessing;
  result.numberOfTilesWithContentReady =
    statistics.numberOfTilesWithContentReady;
  result.numberOfTilesTotal = statistics.numberOfTilesTotal;
  result.numberOfFeaturesSelected = statistics.numberOfFeaturesSelected;
  result.numberOfFeaturesLoaded = statistics.numberOfFeaturesLoaded;
  result.numberOfPointsSelected = statistics.numberOfPointsSelected;
  result.numberOfPointsLoaded = statistics.numberOfPointsLoaded;
  result.numberOfTrianglesSelected = statistics.numberOfTrianglesSelected;
  result.numberOfTilesStyled = statistics.numberOfTilesStyled;
  result.numberOfFeaturesStyled = statistics.numberOfFeaturesStyled;
  result.numberOfTilesCulledWithChildrenUnion =
    statistics.numberOfTilesCulledWithChildrenUnion;
  result.geometryByteLength = statistics.geometryByteLength;
  result.texturesByteLength = statistics.texturesByteLength;
  result.texturesReferenceCounterById = {
    ...statistics.texturesReferenceCounterById,
  };
  result.batchTableByteLength = statistics.batchTableByteLength;
};
export default Cesium3DTilesetStatistics;