All files / engine/Source/Scene/Model/Extensions/Gpm GltfGpmLocal.js

72.41% Statements 21/29
55.55% Branches 10/18
100% Functions 6/6
72.41% Lines 21/29

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                                                                                                          2x     2x 2x 2x 2x 2x     2x 1x         1x         1x         1x             1x         1x         1x         1x                 1x                   2x                         4x                         4x                           4x                         3x            
import defined from "../../../../Core/defined.js";
import Check from "../../../../Core/Check.js";
import RuntimeError from "../../../../Core/RuntimeError.js";
import StorageType from "./StorageType.js";
 
/**
 * @typedef {object} GltfGpmLocal.ConstructorOptions
 *
 * Initialization options for the GltfGpmLocal constructor
 *
 * @property {string} storageType The storage type.
 * This must be one of the `StorageType` constants, i.e. `Direct` or `Indirect`.
 * @property {AnchorPointIndirect[]|undefined} [anchorPointsIndirect] The indirect anchor points.
 * This must be present if and only if the storage type is `Indirect`.
 * @property {CorrelationGroup[]|undefined} [intraTileCorrelationGroups] The intra-tile correlation groups.
 * This must be present if and only if the storage type is `Indirect`.
 * @property {AnchorPointDirect[]|undefined} [anchorPointsDirect] The direct anchor points.
 * This must be present if and only if the storage type is `Direct`.
 * @property {Matrix3|undefined} [covarianceDirect] The covariance of anchor point parameters.
 * This must be present if and only if the storage type is `Direct`.
 */
 
/**
 * The GPM metadata for a Ground-Space Indirect implementation stored
 * locally (i.e. a tile and/or leaf node).
 *
 * This reflects the root extension object of the {@link https://nsgreg.nga.mil/csmwg.jsp|NGA_gpm_local}
 * glTF extension. When a model that contains this extension was loaded,
 * then an object of this type can be obtained by calling
 * ```
 * const gltfGpmLocal = model.getExtension("NGA_gpm_local");
 * ```
 *
 * The storage type determines the presence of the optional properties:
 * <ul>
 *  <li>
 *   When the storage type is `StorageType.Indirect`, then the
 *   `anchorPointsIndirect` and `intraTileCorrelationGroups`
 *   are present.
 *  </li>
 *  <li>
 *   When the storage type is `StorageType.Direct`, then the
 *   `anchorPointsDirect` and `covarianceDirect` are present.
 *  </li>
 * </ul>
 *
 * @constructor
 * @param {GltfGpmLocal.ConstructorOptions} options An object describing initialization options
 *
 * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy.
 */
function GltfGpmLocal(options) {
  //>>includeStart('debug', pragmas.debug);
  Check.typeOf.string("options.storageType", options.storageType);
  //>>includeEnd('debug');
 
  this._storageType = options.storageType;
  this._anchorPointsIndirect = options.anchorPointsIndirect;
  this._anchorPointsDirect = options.anchorPointsDirect;
  this._intraTileCorrelationGroups = options.intraTileCorrelationGroups;
  this._covarianceDirect = options.covarianceDirect;
 
  //>>includeStart('debug', pragmas.debug);
  if (this.storageType === StorageType.Indirect) {
    Iif (!defined(this.anchorPointsIndirect)) {
      throw new RuntimeError(
        "The anchorPointsIndirect are required for 'Indirect' storage",
      );
    }
    Iif (!defined(this.intraTileCorrelationGroups)) {
      throw new RuntimeError(
        "The intraTileCorrelationGroups are required for 'Indirect' storage",
      );
    }
    Iif (defined(this.anchorPointsDirect)) {
      throw new RuntimeError(
        "The anchorPointsDirect must be omitted for 'Indirect' storage",
      );
    }
    Iif (defined(this.covarianceDirect)) {
      throw new RuntimeError(
        "The covarianceDirect must be omitted for 'Indirect' storage",
      );
    }
  } else {
    // Direct storage
    Iif (!defined(this.anchorPointsDirect)) {
      throw new RuntimeError(
        "The anchorPointsDirect are required for 'Direct' storage",
      );
    }
    Iif (!defined(this.covarianceDirect)) {
      throw new RuntimeError(
        "The covarianceDirect is required for 'Direct' storage",
      );
    }
    Iif (defined(this.anchorPointsIndirect)) {
      throw new RuntimeError(
        "The anchorPointsIndirect must be omitted for 'Direct' storage",
      );
    }
    Iif (defined(this.intraTileCorrelationGroups)) {
      throw new RuntimeError(
        "The intraTileCorrelationGroups must be omitted for 'Direct' storage",
      );
    }
  }
  //>>includeEnd('debug');
}
 
Object.defineProperties(GltfGpmLocal.prototype, {
  /**
   * Specifies if covariance storage is indirect or direct.
   *
   * @memberof GltfGpmLocal.prototype
   * @type {StorageType}
   * @readonly
   */
  storageType: {
    get: function () {
      return this._storageType;
    },
  },
 
  /**
   * Array of stored indirect anchor points
   *
   * @memberof GltfGpmLocal.prototype
   * @type {AnchorPointIndirect[]|undefined}
   * @readonly
   */
  anchorPointsIndirect: {
    get: function () {
      return this._anchorPointsIndirect;
    },
  },
 
  /**
   * Array of stored direct anchor points
   *
   * @memberof GltfGpmLocal.prototype
   * @type {AnchorPointDirect[]|undefined}
   * @readonly
   */
  anchorPointsDirect: {
    get: function () {
      return this._anchorPointsDirect;
    },
  },
 
  /**
   * Metadata identifying parameters using same correlation modeling and
   * associated correlation parameters
   *
   * @memberof GltfGpmLocal.prototype
   * @type {CorrelationGroup[]|undefined}
   * @readonly
   */
  intraTileCorrelationGroups: {
    get: function () {
      return this._intraTileCorrelationGroups;
    },
  },
 
  /**
   * The full covariance of anchor point parameters
   *
   * @memberof GltfGpmLocal.prototype
   * @type {Matrix3|undefined}
   * @readonly
   */
  covarianceDirect: {
    get: function () {
      return this._covarianceDirect;
    },
  },
});
 
export default GltfGpmLocal;