Skip to content

Commit a05c225

Browse files
committed
PR feedback
1 parent 983585e commit a05c225

11 files changed

+62
-83
lines changed

Source/Core/ClippingPlane.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,20 @@ define([
22
'./Cartesian3',
33
'./Check',
44
'./defined',
5-
'./defineProperties',
6-
'./DeveloperError',
7-
'./Plane'
5+
'./defineProperties'
86
], function(
97
Cartesian3,
108
Check,
119
defined,
12-
defineProperties,
13-
DeveloperError,
14-
Plane
10+
defineProperties
1511
) {
1612
'use strict';
1713

1814
/**
1915
* A Plane in Hessian Normal form to be used with ClippingPlaneCollection.
2016
* Compatible with mathematics functions in Plane.js
2117
*
18+
* @alias ClippingPlane
2219
* @constructor
2320
*
2421
* @param {Cartesian3} normal The plane's normal (normalized).
@@ -108,6 +105,7 @@ define([
108105
* Clones the ClippingPlane without setting its ownership.
109106
* @param {ClippingPlane} clippingPlane The ClippingPlane to be cloned
110107
* @param {ClippingPlane} [result] The object on which to store the cloned parameters.
108+
* @returns {ClippingPlane} a clone of the input ClippingPlane
111109
*/
112110
ClippingPlane.clone = function(clippingPlane, result) {
113111
if (!defined(result)) {

Source/Core/ClippingPlaneCollection.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,15 @@ define([
419419
}
420420
}
421421

422+
function computeTextureResolution(pixelsNeeded, result) {
423+
var maxSize = ContextLimits.maximumTextureSize;
424+
var width = Math.min(pixelsNeeded, maxSize);
425+
var height = Math.ceil(pixelsNeeded / width);
426+
result.x = width;
427+
result.y = height;
428+
return result;
429+
}
430+
422431
var textureResolutionScratch = new Cartesian2();
423432
/**
424433
* Called when {@link Viewer} or {@link CesiumWidget} render the scene to
@@ -637,15 +646,6 @@ define([
637646
return this._unionClippingRegions ? this._planes.length : -this._planes.length;
638647
};
639648

640-
function computeTextureResolution(pixelsNeeded, result) {
641-
var maxSize = ContextLimits.maximumTextureSize;
642-
var width = Math.min(pixelsNeeded, maxSize);
643-
var height = Math.ceil(pixelsNeeded / width);
644-
result.x = width;
645-
result.y = height;
646-
return result;
647-
}
648-
649649
/**
650650
* Sets the owner for the input ClippingPlaneCollection if there wasn't another owner.
651651
* Destroys the owner's previous ClippingPlaneCollection if setting is successful.

Source/Scene/Batched3DModel3DTileContent.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ define([
7171
this._batchIdAttributeName = undefined;
7272
this._diffuseAttributeOrUniformName = {};
7373

74-
/**
75-
* @inheritdoc Cesium3DTileContent#clippingPlanesDirty
76-
*/
77-
this.clippingPlanesDirty = false;
78-
7974
/**
8075
* @inheritdoc Cesium3DTileContent#featurePropertiesDirty
8176
*/
@@ -511,7 +506,7 @@ define([
511506

512507
// Update clipping planes
513508
var tilesetClippingPlanes = this._tileset.clippingPlanes;
514-
if (this.clippingPlanesDirty && defined(tilesetClippingPlanes)) {
509+
if (this._tile.clippingPlanesDirty && defined(tilesetClippingPlanes)) {
515510
// Dereference the clipping planes from the model if they are irrelevant.
516511
// Link/Dereference directly to avoid ownership checks.
517512
// This will also trigger synchronous shader regeneration to remove or add the clipping plane and color blending code.

Source/Scene/Cesium3DTile.js

+25-12
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,16 @@ define([
310310
*/
311311
this._optimChildrenWithinParent = Cesium3DTileOptimizationHint.NOT_COMPUTED;
312312

313+
/**
314+
* Tracks if the tile's relationship with a ClippingPlaneCollection has changed with regards
315+
* to the ClippingPlaneCollection's state.
316+
*
317+
* @type {Boolean}
318+
*
319+
* @private
320+
*/
321+
this.clippingPlanesDirty = false;
322+
313323
// Members that are updated every frame for tree traversal and rendering optimizations:
314324
this._distanceToCamera = 0;
315325
this._visibilityPlaneMask = 0;
@@ -1049,33 +1059,36 @@ define([
10491059
content.update(tileset, frameState);
10501060
}
10511061

1052-
/**
1053-
* Get the draw commands needed to render this tile.
1054-
*
1055-
* @private
1056-
*/
1057-
Cesium3DTile.prototype.update = function(tileset, frameState) {
1062+
function updateClippingPlanes(tile, tileset) {
10581063
// Compute and compare ClippingPlanes state:
10591064
// - enabled-ness - are clipping planes enabled? is this tile clipped?
10601065
// - clipping plane count
10611066
// - clipping function (union v. intersection)
10621067
var clippingPlanes = tileset.clippingPlanes;
10631068
var currentClippingPlanesState = 0;
1064-
if (defined(clippingPlanes) && this._isClipped && clippingPlanes.enabled) {
1069+
if (defined(clippingPlanes) && tile._isClipped && clippingPlanes.enabled) {
10651070
currentClippingPlanesState = clippingPlanes.clippingPlanesState();
10661071
}
1067-
// If clippingPlaneState for this tile changed, mark content as clippingPlanesDirty
1068-
if (currentClippingPlanesState !== this._clippingPlanesState) {
1069-
this._clippingPlanesState = currentClippingPlanesState;
1070-
this._content.clippingPlanesDirty = true;
1072+
// If clippingPlaneState for tile changed, mark clippingPlanesDirty so content can update
1073+
if (currentClippingPlanesState !== tile._clippingPlanesState) {
1074+
tile._clippingPlanesState = currentClippingPlanesState;
1075+
tile.clippingPlanesDirty = true;
10711076
}
1077+
}
10721078

1079+
/**
1080+
* Get the draw commands needed to render this tile.
1081+
*
1082+
* @private
1083+
*/
1084+
Cesium3DTile.prototype.update = function(tileset, frameState) {
10731085
var initCommandLength = frameState.commandList.length;
1086+
updateClippingPlanes(this, tileset);
10741087
applyDebugSettings(this, tileset, frameState);
10751088
updateContent(this, tileset, frameState);
10761089
this._commandsLength = frameState.commandList.length - initCommandLength;
10771090

1078-
this._content.clippingPlanesDirty = false; // reset after content update
1091+
this.clippingPlanesDirty = false; // reset after content update
10791092
};
10801093

10811094
var scratchCommandList = [];

Source/Scene/Cesium3DTileContent.js

-14
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,6 @@ define([
3333
* @private
3434
*/
3535
this.featurePropertiesDirty = false;
36-
37-
/**
38-
* Gets or sets if the tile's relationship with a ClippingPlaneCollection has changed with regards
39-
* to the ClippingPlaneCollection's state.
40-
* <p>
41-
* This is used to implement the <code>Cesium3DTileContent</code> interface, but is
42-
* not part of the public Cesium API.
43-
* </p>
44-
*
45-
* @type {Boolean}
46-
*
47-
* @private
48-
*/
49-
this.clippingPlanesDirty = false;
5036
}
5137

5238
defineProperties(Cesium3DTileContent.prototype, {

Source/Scene/Composite3DTileContent.js

-7
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ define([
4444
this._contents = [];
4545
this._readyPromise = when.defer();
4646

47-
/**
48-
* @inheritdoc Cesium3DTileContent#clippingPlanesDirty
49-
*/
50-
this.clippingPlanesDirty = false;
51-
5247
initialize(this, arrayBuffer, byteOffset, factory);
5348
}
5449

@@ -287,9 +282,7 @@ define([
287282
var contents = this._contents;
288283
var length = contents.length;
289284
for (var i = 0; i < length; ++i) {
290-
contents[i].clippingPlanesDirty = this.clippingPlanesDirty;
291285
contents[i].update(tileset, frameState);
292-
contents[i].clippingPlanesDirty = false;
293286
}
294287
};
295288

Source/Scene/Instanced3DModel3DTileContent.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ define([
8181
this._batchTable = undefined;
8282
this._features = undefined;
8383

84-
/**
85-
* @inheritdoc Cesium3DTileContent#clippingPlanesDirty
86-
*/
87-
this.clippingPlanesDirty = false;
88-
8984
/**
9085
* @inheritdoc Cesium3DTileContent#featurePropertiesDirty
9186
*/
@@ -520,7 +515,7 @@ define([
520515
if (defined(model)) {
521516
// Update for clipping planes
522517
var tilesetClippingPlanes = this._tileset.clippingPlanes;
523-
if (this.clippingPlanesDirty && defined(tilesetClippingPlanes)) {
518+
if (this._tile.clippingPlanesDirty && defined(tilesetClippingPlanes)) {
524519
// Dereference the clipping planes from the model if they are irrelevant - saves on shading
525520
// Link/Dereference directly to avoid ownership checks.
526521
model._clippingPlanes = (tilesetClippingPlanes.enabled && this._tile._isClipped) ? tilesetClippingPlanes : undefined;

Source/Scene/Model.js

+4-16
Original file line numberDiff line numberDiff line change
@@ -514,21 +514,13 @@ define([
514514
*/
515515
this.colorBlendAmount = defaultValue(options.colorBlendAmount, 0.5);
516516

517-
this.colorShadingEnabled = isColorShadingEnabled(this);
517+
this._colorShadingEnabled = isColorShadingEnabled(this);
518518

519519
this._clippingPlanes = undefined;
520520
this.clippingPlanes = options.clippingPlanes;
521521
// Used for checking if shaders need to be regenerated due to clipping plane changes.
522522
this._clippingPlanesState = 0;
523523

524-
/**
525-
* Flag for indicating to ModelInstanceCollection that shaders were changed, necessitating updates.
526-
*
527-
* @type {Boolean}
528-
* @private
529-
*/
530-
this.changedShadersOnLastUpdate = false;
531-
532524
/**
533525
* This property is for debugging only; it is not for production use nor is it optimized.
534526
* <p>
@@ -1914,7 +1906,7 @@ define([
19141906
};
19151907

19161908
CreateProgramJob.prototype.execute = function() {
1917-
createProgram(this.id, this.model, this.context, true);
1909+
createProgram(this.id, this.model, this.context);
19181910
};
19191911

19201912
///////////////////////////////////////////////////////////////////////////
@@ -4087,8 +4079,6 @@ define([
40874079
* @exception {RuntimeError} Failed to load external reference.
40884080
*/
40894081
Model.prototype.update = function(frameState) {
4090-
this.changedShadersOnLastUpdate = false;
4091-
40924082
if (frameState.mode === SceneMode.MORPHING) {
40934083
return;
40944084
}
@@ -4320,8 +4310,8 @@ define([
43204310

43214311
// Regenerate shaders if color shading changed from last update
43224312
var currentlyColorShadingEnabled = isColorShadingEnabled(this);
4323-
if (currentlyColorShadingEnabled !== this.colorShadingEnabled) {
4324-
this.colorShadingEnabled = currentlyColorShadingEnabled;
4313+
if (currentlyColorShadingEnabled !== this._colorShadingEnabled) {
4314+
this._colorShadingEnabled = currentlyColorShadingEnabled;
43254315
shouldRegenerateShaders = true;
43264316
}
43274317

@@ -4442,8 +4432,6 @@ define([
44424432
var cachedRendererResources = model._cachedRendererResources;
44434433
destroyIfNotCached(rendererResources, cachedRendererResources);
44444434

4445-
model.changedShadersOnLastUpdate = true;
4446-
44474435
if (isClippingEnabled(model) || isColorShadingEnabled(model)) {
44484436
rendererResources.programs = {};
44494437
rendererResources.pickPrograms = {};

Source/Scene/ModelInstanceCollection.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,19 @@ define([
871871
};
872872
}
873873

874+
function commandsDirty(model) {
875+
var nodeCommands = model._nodeCommands;
876+
var length = nodeCommands.length;
877+
878+
for (var i = 0; i < length; i++) {
879+
var nc = nodeCommands[i];
880+
if (nc.command.dirty) {
881+
return true;
882+
}
883+
}
884+
return false;
885+
}
886+
874887
function generateModelCommands(modelInstanceCollection, instancingSupported) {
875888
modelInstanceCollection._drawCommands = [];
876889
modelInstanceCollection._pickCommands = [];
@@ -977,7 +990,7 @@ define([
977990
}
978991

979992
// If the model was set to rebuild shaders during update, rebuild instanced commands.
980-
if (model.changedShadersOnLastUpdate) {
993+
if (commandsDirty(model)) {
981994
generateModelCommands(this, instancingSupported);
982995
}
983996

Source/Scene/PointCloud3DTileContent.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,6 @@ define([
153153
*/
154154
this.featurePropertiesDirty = false;
155155

156-
/**
157-
* @inheritdoc Cesium3DTileContent#clippingPlanesDirty
158-
*/
159-
this.clippingPlanesDirty = false;
160-
161156
// Options for geometric error based attenuation
162157
this._attenuation = false;
163158
this._geometricErrorScale = undefined;
@@ -1292,7 +1287,7 @@ define([
12921287
}
12931288

12941289
// update for clipping planes
1295-
if (this.clippingPlanesDirty) {
1290+
if (this._tile.clippingPlanesDirty) {
12961291
createShaders(this, frameState, tileset.style);
12971292
}
12981293

Specs/Scene/ModelInstanceCollectionSpec.js

+3
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ defineSuite([
550550
expect(drawCommand.receiveShadows).toBe(true);
551551
collection.shadows = ShadowMode.DISABLED;
552552
scene.renderForSpecs();
553+
554+
// Expect commands to have been recreated
555+
drawCommand = collection._drawCommands[0];
553556
expect(drawCommand.castShadows).toBe(false);
554557
expect(drawCommand.receiveShadows).toBe(false);
555558
});

0 commit comments

Comments
 (0)