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 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | 1557x 1556x 1556x 1556x 12357x 12357x 12354x 12354x 3x 3x 3x 3x 3x 3x 3x 3x 3x 12x 12x 12x 12x 12x 12x 3x 3x 3x 3x 3x 3x 3x 3x 3x 12x 12x 3x 3x 3x 3x 3x 3x 3x 3x 12354x 12354x 12354x 12354x 12354x 24718x 24718x 24718x 5x 5x 5x 5x 5x 5x 1x 4x | import Check from "../../Core/Check.js";
import defined from "../../Core/defined.js";
import destroyObject from "../../Core/destroyObject.js";
import DeveloperError from "../../Core/DeveloperError.js";
import ImageryConfiguration from "./ImageryConfiguration.js";
import ModelPrimitiveImagery from "./ModelPrimitiveImagery.js";
/**
* A class managing the draping of imagery on a <code>Model</code>.
*
* An instance of this class is created in the Model constructor. It will
* create the data structures that carry the information that is required
* for mapping imagery textures on model primitives.
*
* It offers two functions for managing the lifecycle of this draping process:
*
* The <code>update</code> function is called from the <code>Model.update</code>
* function in each frame. It will create one <code>ModelPrimitiveImagery</code>
* instance for each primitive that appears in the model, and call the
* <code>update</code> function of these instances, respectively.
*
* The <code>ready</code> getter will be used to determine whether the
* draping computations are done, and the update process of the <code>Model</code>
* can continue, eventually causing the <code>model.ready</code> flag to
* become <code>true</code>. The model imagery counts as "ready" when all
* the imagery layers of the model are <code>ready</code>, and all the
* <code>ModelPrimitiveImagery</code> instances are <code>ready</code>.
*
* @private
*/
class ModelImagery {
/**
* Creates a new instance
*
* @param {Model} model The model
* @throws {DeveloperError} If the model is not defined
*/
constructor(model) {
//>>includeStart('debug', pragmas.debug);
Check.defined("model", model);
//>>includeEnd('debug');
/**
* The model that this instance was created for.
*
* @type {Model}
* @readonly
* @private
*/
this._model = model;
/**
* One <code<ModelPrimitiveImagery</code> for each primitive
* that appears in the model.
*
* Initially, this is <code>undefined</code>. When the <code>update</code>
* function is called and all imagery layers that are associated with the
* model are <code>ready</code>, this is initialized with one instance
* of a <code>ModelPrimitiveImagery</code> per runtime primitive (i.e. one for
* each <code>model.sceneGraph._runtimeNodes[n]._runtimePrimitives[p]</code>)
*
* @type {ModelPrimitiveImagery[]|undefined}
* @private
*/
this._modelPrimitiveImageries = undefined;
/**
* One <code>ImageryConfiguration</code> object for each <code>ImageryLayer</code>
* that is associated with the model.
*
* This is used for determining whether the configuration (relevant property
* values) of an imagery layer has been changed since the previous
* <code>update</code> call, which should cause the draw commands of the
* model to be reset.
*
* @type {ImageryConfiguration[]}
* @private
*/
this._imageryConfigurations = [];
}
/**
* The update function that is called from <code>Model.update</code> in
* each frame.
*
* This checks whether the imagery layer objects that are associated
* with the model are all <code>ready</code>. If they are not yet
* ready, then nothing is done.
*
* Otherwise, this just calls the <code>update</code> function of
* the <code>_modelPrimitiveImageries</code> (creating them if they had
* not been created yet).
*
* @param {FrameState} frameState The frame state
*/
update(frameState) {
//>>includeStart('debug', pragmas.debug);
Check.defined("frameState", frameState);
//>>includeEnd('debug');
if (!this._hasImagery) {
// When there is no imagery, make sure to delete any model primitive
// imageries that may previously have been created
this._deleteModelPrimitiveImageries();
return;
}
Iif (!this._allImageryLayersReady) {
return;
}
Eif (!defined(this._modelPrimitiveImageries)) {
this._modelPrimitiveImageries = this._createModelPrimitiveImageries();
}
this._updateModelPrimitiveImageries(frameState);
this._checkForModifiedImageryConfigurations();
}
/**
* Creates the <code>ModelPrimitiveImagery</code> array that contains
* one <code>ModelPrimitiveImagery</code> for each primitive that is
* contained in the model.
*
* @returns {ModelPrimitiveImagery[]} The model primitive imageries
* @private
*/
_createModelPrimitiveImageries() {
const model = this._model;
const runtimeNodesAndPrimitives = this._collectRuntimeNodesAndPrimitives();
const modelPrimitiveImageries = [];
const length = runtimeNodesAndPrimitives.length;
for (let i = 0; i < length; i++) {
const runtimeNodeAndPrimitive = runtimeNodesAndPrimitives[i];
const runtimeNode = runtimeNodeAndPrimitive.runtimeNode;
const runtimePrimitive = runtimeNodeAndPrimitive.runtimePrimitive;
const modelPrimitiveImagery = new ModelPrimitiveImagery(
model,
runtimeNode,
runtimePrimitive,
);
runtimePrimitive.primitive.modelPrimitiveImagery = modelPrimitiveImagery;
modelPrimitiveImageries.push(modelPrimitiveImagery);
}
return modelPrimitiveImageries;
}
/**
* Computes all runtime nodes and primitives of the model.
*
* This is just the array that contains a
* <code>{ runtimeNode, runtimePrimitive }</code>
* for each
* <code>model.sceneGraph._runtimeNodes[n]._runtimePrimitives[p]</code>.
*
* @returns {object[]} The runtime nodes and primitives
* @private
*/
_collectRuntimeNodesAndPrimitives() {
const model = this._model;
const sceneGraph = model.sceneGraph;
const runtimeNodes = sceneGraph._runtimeNodes;
const runtimeNodesAndPrimitives = [];
for (let i = 0; i < runtimeNodes.length; i++) {
const runtimeNode = runtimeNodes[i];
Iif (!defined(runtimeNode)) {
continue;
}
for (let j = 0; j < runtimeNode.runtimePrimitives.length; j++) {
const runtimePrimitive = runtimeNode.runtimePrimitives[j];
runtimeNodesAndPrimitives.push({
runtimeNode: runtimeNode,
runtimePrimitive: runtimePrimitive,
});
}
}
return runtimeNodesAndPrimitives;
}
/**
* Just calls <code>update</code> on each <code>ModelPrimitiveImagery</code>
* as part of the <code>update</code> of this class.
*
* @private
*/
_updateModelPrimitiveImageries(frameState) {
//>>includeStart('debug', pragmas.debug);
Check.defined("frameState", frameState);
//>>includeEnd('debug');
Iif (!defined(this._modelPrimitiveImageries)) {
throw new DeveloperError(
"The modelPrimitiveImageries have not been created",
);
}
const modelPrimitiveImageries = this._modelPrimitiveImageries;
const length = modelPrimitiveImageries.length;
for (let i = 0; i < length; i++) {
const modelPrimitiveImagery = modelPrimitiveImageries[i];
modelPrimitiveImagery.update(frameState);
}
}
/**
* Destroy and delete all <code>ModelPrimitiveImagery</code> instances
* if they already have been created.
*/
_deleteModelPrimitiveImageries() {
const modelPrimitiveImageries = this._modelPrimitiveImageries;
Eif (!defined(modelPrimitiveImageries)) {
return;
}
const length = modelPrimitiveImageries.length;
for (let i = 0; i < length; i++) {
const modelPrimitiveImagery = modelPrimitiveImageries[i];
modelPrimitiveImagery.destroy();
}
delete this._modelPrimitiveImageries;
this._model.resetDrawCommands();
}
/**
* Returns whether this instance is "ready".
*
* This means that all imagery layers that are associated with the model
* are <code>ready</code>, and all <code>ModelPrimitiveImagery</code>
* instances are <code>ready</code>.
*
* When this is <code>true</code>, then the mapping computations are
* complete and the structures containing the mapping information have
* been initialized. Otherwise, subsequent calls to <code>update</code>
* will perform the necessary computation until this getter eventually
* returns <code>true</code>.
*
* @returns {boolean} Whether this instance is "ready"
*/
get ready() {
Eif (!this._hasImagery) {
return true;
}
if (!this._allImageryLayersReady) {
return false;
}
if (!this._allModelPrimitiveImageriesReady) {
return false;
}
return true;
}
/**
* Returns whether the model has imagery layers associated with it.
*
* @private
*/
get _hasImagery() {
const model = this._model;
const imageryLayers = model.imageryLayers;
return defined(imageryLayers) && imageryLayers.length > 0;
}
/**
* Returns whether all imagery layers that are associated with the
* model are <code>ready</code>.
*
* If the model does not have imagery, then this always returns
* <code>true</code>. Otherwise, it returns whether each imagery
* layer is <code>ready</code>.
*
* @private
*/
get _allImageryLayersReady() {
Iif (!this._hasImagery) {
return true;
}
const imageryLayers = this._model.imageryLayers;
const length = imageryLayers.length;
for (let i = 0; i < length; i++) {
const imageryLayer = imageryLayers.get(i);
if (!imageryLayer.ready) {
return false;
}
}
return true;
}
/**
* Returns whether all <code>ModelPrimitiveImagery</code> instances
* are are <code>ready</code>.
*
* @private
*/
get _allModelPrimitiveImageriesReady() {
const modelPrimitiveImageries = this._modelPrimitiveImageries;
if (!defined(modelPrimitiveImageries)) {
return false;
}
const length = modelPrimitiveImageries.length;
for (let i = 0; i < length; i++) {
const modelPrimitiveImagery = modelPrimitiveImageries[i];
if (!modelPrimitiveImagery.ready) {
return false;
}
}
return true;
}
/**
* Check whether any of the settings of any imagery layer (like alpha
* or hue) has been changed since the last call to the <code>update</code>
* function.
*
* If this is the case, the draw commands of the model will be reset.
*/
_checkForModifiedImageryConfigurations() {
if (this._imageryConfigurationsModified()) {
this._updateImageryConfigurations();
const model = this._model;
model.resetDrawCommands();
}
}
/**
* Returns whether any setting of an imagery layer (like alpha or hue) has
* been changed since the last time the <code>ImageryConfiguration</code>
* objects have been updated.
*
* @returns {boolean} Whether there was a modification
*/
_imageryConfigurationsModified() {
const model = this._model;
const imageryLayers = model.imageryLayers;
const imageryConfigurations = this._imageryConfigurations;
if (imageryLayers.length !== imageryConfigurations.length) {
return true;
}
for (let i = 0; i < imageryLayers.length; i++) {
const imageryLayer = imageryLayers.get(i);
const imageryConfiguration = imageryConfigurations[i];
if (imageryLayer.show !== imageryConfiguration.show) {
return true;
}
if (imageryLayer.alpha !== imageryConfiguration.alpha) {
return true;
}
if (imageryLayer.brightness !== imageryConfiguration.brightness) {
return true;
}
if (imageryLayer.contrast !== imageryConfiguration.contrast) {
return true;
}
if (imageryLayer.hue !== imageryConfiguration.hue) {
return true;
}
if (imageryLayer.saturation !== imageryConfiguration.saturation) {
return true;
}
if (imageryLayer.gamma !== imageryConfiguration.gamma) {
return true;
}
if (imageryLayer.colorToAlpha !== imageryConfiguration.colorToAlpha) {
return true;
}
}
return false;
}
/**
* Create one <code>ImageryConfiguration</code> object for each imagery
* layer that appears in the model, and store them as the
* <code>_imageryConfigurations</code>.
*/
_updateImageryConfigurations() {
const model = this._model;
const imageryLayers = model.imageryLayers;
const imageryConfigurations = this._imageryConfigurations;
imageryConfigurations.length = imageryLayers.length;
for (let i = 0; i < imageryLayers.length; i++) {
const imageryLayer = imageryLayers.get(i);
imageryConfigurations[i] = new ImageryConfiguration(imageryLayer);
}
}
/**
* Returns whether this object was destroyed.
*
* If this object was destroyed, calling any function other than
* <code>isDestroyed</code> will result in a {@link DeveloperError}.
*
* @returns {boolean} Whether this object was destroyed
*/
isDestroyed() {
return false;
}
/**
* Destroys this object and all its resources.
*/
destroy() {
if (this.isDestroyed()) {
return;
}
this._deleteModelPrimitiveImageries();
return destroyObject(this);
}
}
export default ModelImagery;
|