Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase max clipping planes using textures #6201

Merged
merged 38 commits into from
Mar 9, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0317622
proof-of-concept oct32 normals and in-shader transform for clipping p…
likangning93 Jan 30, 2018
44a2662
proof-of-concept for sharing ClippingPlaneCollections over b3dm tiles…
likangning93 Feb 1, 2018
3f40dc2
working with i3dm and pts
likangning93 Feb 7, 2018
4b7b0ea
merged in master
likangning93 Feb 7, 2018
15e3a1e
add attenuation to demo
likangning93 Feb 7, 2018
a0a9706
clipping planes working with globe
likangning93 Feb 7, 2018
a5e6ff4
fix problem with globe rendering before clipping planes are updated
likangning93 Feb 7, 2018
a42261a
packed new clipping plane params to fewer uniforms
likangning93 Feb 8, 2018
5d3165e
updated tests, fixed a bug with changing union mode for clippingPlane…
likangning93 Feb 9, 2018
e2fb890
add gallery image and update changes
likangning93 Feb 9, 2018
cf1b6da
move many clipping planes sandcastle to development
likangning93 Feb 9, 2018
f7d078e
fix issue with clipped models still getting picked
likangning93 Feb 14, 2018
8ba4a65
added support for IE/Edge by fixing a bug in windowToEyeCoordinates.glsl
likangning93 Feb 14, 2018
d484bb3
Merge branch 'master' into clippingPlanesByTexture
likangning93 Feb 14, 2018
c917871
Shader style
lilleyse Feb 14, 2018
b61f98f
PR feedback
likangning93 Feb 15, 2018
c699d4b
merged master into clippingPlanesByTexture
likangning93 Feb 15, 2018
2ccd989
added float texture version of clipping planes by texture
likangning93 Feb 16, 2018
fb69f6a
PR comments
likangning93 Feb 16, 2018
f5512d1
consolidate uniforms for clipping planes
likangning93 Feb 16, 2018
c0a71de
PR comments
likangning93 Feb 16, 2018
e19299a
added ClippingPlane class and streamlined ClippingPlaneCollection upd…
likangning93 Feb 19, 2018
ff3f4a5
wrap normal for ClippingPlane to detect member-of-member changes
likangning93 Feb 20, 2018
ea2d45a
pointcloud and globe now rebuild shaders to match clipping plane count
likangning93 Feb 21, 2018
5d953b5
Model and associated tile content now regenerate shaders for clipping…
likangning93 Feb 23, 2018
2ec99dc
clipping plane textures resize as needed
likangning93 Feb 26, 2018
828a9d1
merged in master
likangning93 Feb 26, 2018
fdca291
retain copies of quantized vertex shaders
likangning93 Feb 26, 2018
f9293e4
bypass float texture size test when not supported
likangning93 Feb 26, 2018
e20d1ec
change float packing to do what BatchTable does
likangning93 Mar 1, 2018
c3c10f0
PR comments
likangning93 Mar 7, 2018
bc8b313
propagate clippingPlanesDirty flag through composite tiles
likangning93 Mar 7, 2018
983585e
merged in master
likangning93 Mar 8, 2018
a05c225
PR feedback
likangning93 Mar 8, 2018
4e705de
Style tweak
lilleyse Mar 9, 2018
5185523
fixed clipping plane edge styling in orthographic
likangning93 Mar 9, 2018
0f04e46
merged in master
likangning93 Mar 9, 2018
31c548b
update CHANGES.md
likangning93 Mar 9, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions Apps/Sandcastle/gallery/development/Many Clipping Planes.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@

var modelUrl = '../../SampleData/models/CesiumAir/Cesium_Air.glb';
var agiHqUrl = Cesium.CesiumIon.createResource(1458, { accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIxYmJiNTAxOC1lOTg5LTQzN2EtODg1OC0zMWJjM2IxNGNlYmMiLCJpZCI6NDQsImFzc2V0cyI6WzE0NThdLCJpYXQiOjE0OTkyNjM4MjB9.1WKijRa-ILkmG6utrhDWX6rDgasjD7dZv-G5ZyCmkKg' });
var instancedUrl = '../../../Specs/Data/Cesium3DTiles/Instanced/InstancedOrientation/';
var instancedUrl = Cesium.CesiumIon.createResource(3876, { accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJjYjNlMTg5Zi1hMzc2LTRmZjktOGEwZC00NGEzNTM0MTAzZGUiLCJpZCI6MjU5LCJpYXQiOjE1MTgxOTE2NTV9.qaP8-_Ej6AihGnv5iB990Hm6lHr8F_rrC3_EPxdT6MQ' });
var pointCloudUrl = Cesium.CesiumIon.createResource(3742, { accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIxOGZjMjlhZC03MDE1LTQ3ZTAtODEyNy05YTU3M2MwYzQ0YmEiLCJpZCI6NDQsImFzc2V0cyI6WzM3NDJdLCJpYXQiOjE1MTcyNDI3NDJ9.TJAJctFXC1UyFMpxkA3cyKVAmnh72cLtfY1yKbaQsyk' });

function loadModel(url) {
Expand Down Expand Up @@ -207,10 +207,12 @@
});
} else if (newValue === clipObjects[3]) {
// i3dm
loadTileset(instancedUrl);
tileset.readyPromise.then(function () {
tileset.clippingPlanes.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(tileset.boundingSphere.center);
});
instancedUrl.then(function(resource) {
return loadTileset(resource);
})
.then(function() {
tileset.clippingPlanes.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(tileset.boundingSphere.center);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually in Cesium code we condense this to:

        instancedUrl.then(function(resource) {
            return loadTileset(resource);
        }).then(function() {
            tileset.clippingPlanes.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(tileset.boundingSphere.center);
        });

} else if (newValue === clipObjects[4]) {
// Terrain
var position = Cesium.Cartesian3.fromRadians(-2.0872979473351286, 0.6596620013036164, 2380.0);
Expand All @@ -234,7 +236,7 @@
viewModel.cylinderRadius = cylinderRadius;
viewer.entities.removeAll();
viewer.scene.primitives.removeAll();
globe.destroyClippingPlanes();
globe.clippingPlanes = undefined; // destroy Globe clipping planes, if any
}

Sandcastle.addToggleButton('union', clippingModeUnion, function(checked) {
Expand Down
Binary file modified Apps/Sandcastle/gallery/development/Many Clipping Planes.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Change Log

### 1.43 - 2018-03-01

##### Deprecated :hourglass_flowing_sand:
* `ClippingPlaneCollection` is now supported in Internet Explorer, so `ClippingPlaneCollection.isSupported` always returns `true`. [#6201](https://github.com/AnalyticalGraphicsInc/cesium/pull/6201)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention that the deprecated function will be removed in 1.43.


##### Additions :tada:
* Added support for a promise to a resource for `CesiumTerrainProvider`, `createTileMapServiceImageryProvider` and `Cesium3DTileset` [#6204](https://github.com/AnalyticalGraphicsInc/cesium/pull/6204)

Expand All @@ -15,7 +18,7 @@ Change Log
* Enable terrain in the `CesiumViewer` demo application [#6198](https://github.com/AnalyticalGraphicsInc/cesium/pull/6198)

##### Additions :tada:
* Increased maximum number of clipping planes from 6 to 2048, added support for Internet Explorer, and removed `ClippingPlaneCollection.isSupported`. [#6201](https://github.com/AnalyticalGraphicsInc/cesium/pull/6201)
* Increased maximum number of clipping planes from 6 to 2048, added support for Internet Explorer. [#6201](https://github.com/AnalyticalGraphicsInc/cesium/pull/6201)

### 1.42.1 - 2018-02-01
_This is an npm-only release to fix an issue with using Cesium in Node.js.__
Expand Down
95 changes: 63 additions & 32 deletions Source/Core/ClippingPlaneCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ define([

/**
* Specifies a set of clipping planes. Clipping planes selectively disable rendering in a region on the
* outside of the specified list of {@link Plane} objects.
* outside of the specified list of {@link Plane} objects for a single gltf model, 3D Tileset, or the globe.
*
* @alias ClippingPlaneCollection
* @constructor
Expand Down Expand Up @@ -107,20 +107,21 @@ define([
this.edgeWidth = defaultValue(options.edgeWidth, 0.0);

/**
* If this ClippingPlaneCollection has an owner, only its owner can destroy it using checkDestroy(object)
* If this ClippingPlaneCollection has an owner, only its owner should update or destroy it.
* This is because in a Cesium3DTileset multiple models may reference the tileset's ClippingPlaneCollection.
* @private
*
* @type {Object}
* @default undefined
*/
this.owner = undefined;
this._owner = undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's an underscored variable you can remove the doc but leave the comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation of the comment is slightly off.


this._testIntersection = undefined;
this._unionClippingRegions = undefined;
this.unionClippingRegions = defaultValue(options.unionClippingRegions, false);

// Avoid wastefully re-uploading textures when the clipping planes don't change between frames
var previousTextureBytes = new ArrayBuffer(ClippingPlaneCollection.TEXTURE_WIDTH * ClippingPlaneCollection.TEXTURE_WIDTH * 4);
previousTextureBytes[0] = 1;
var currentTextureBytes = new ArrayBuffer(ClippingPlaneCollection.TEXTURE_WIDTH * ClippingPlaneCollection.TEXTURE_WIDTH * 4);

this._textureBytes = new Uint8Array(currentTextureBytes);
Expand All @@ -129,9 +130,6 @@ define([
this._previousUint32View = new Uint32Array(previousTextureBytes);
this._currentUint32View = new Uint32Array(currentTextureBytes);

// Avoid wasteful re-upload checks within a frame when a ClippingPlaneCollection is shared by many Models in a Cesium3DTileset
this._planeTextureDirty = true;

this._clippingPlanesTexture = undefined;

// Packed uniform for plane count, denormalization parameters, and clipping union (0 false, 1 true)
Expand Down Expand Up @@ -353,9 +351,10 @@ define([
}

var octEncodeScratch = new Cartesian2();
var rightShift = 1.0 / 256;
var rightShift = 1.0 / 256.0;
/**
* Encodes a normalized vector into 4 SNORM values in the range [0-255] following the 'oct' encoding.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the comment be [0-65535]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's two 16-bit values spread out over 4 8-bit values. I was following the convention in AttributeCompression.js:

    /**
     * Encodes a normalized vector into 2 SNORM values in the range of [0-rangeMax] following the 'oct' encoding.
     * ...
     */
    AttributeCompression.octEncodeInRange = function(vector, rangeMax, result) {
        ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's storing 4 values for precision purposes right? You might want to note that in the comment.

* oct32 precision is higher than the default oct16, hence the additional 2 uint16 values.
*/
function oct32EncodeNormal(vector, result) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this specific to the clipping plane? Or should this be a utility function? Maybe a static function in AttributeCompression?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes a lot of sense, but it seems like we'd also want to rename a bunch of stuff in AttributeCompression to indicate 16-bit-vec2, which seems like it could be a pretty big breaking change.

@lilleyse what do you think? I guess we could also deprecate the current functions over time?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the new function could be called octPackCartesian4. There is already octPackFloat and octPack where are single-channel and double-channel, so adding a new one shouldn't be a problem.

AttributeCompression.octEncodeInRange(vector, 65535, octEncodeScratch);
Expand All @@ -373,7 +372,7 @@ define([
var textureBytes = clippingPlaneCollection._textureBytes;
var planes = clippingPlaneCollection._planes;
var length = planes.length;
var unchanged = true;
var dirty = false;
var byteIndex, uint32Index;

var lengthRangeUnion = clippingPlaneCollection._lengthRangeUnion;
Expand All @@ -396,9 +395,9 @@ define([
textureBytes[byteIndex + 2] = oct32Normal.z;
textureBytes[byteIndex + 3] = oct32Normal.w;

uint32Index = i + i;
unchanged = unchanged && previousUint32View[uint32Index] === currentUint32View[uint32Index];
if (!unchanged) {
uint32Index = i * 2;
dirty = dirty || previousUint32View[uint32Index] !== currentUint32View[uint32Index];
if (dirty) {
previousUint32View[uint32Index] = currentUint32View[uint32Index];
}

Expand All @@ -420,17 +419,17 @@ define([
byteIndex = i * 8 + 4;
insertFloat(textureBytes, normalizedDistance, byteIndex);

uint32Index = i + i + 1;
unchanged = unchanged && previousUint32View[uint32Index] === currentUint32View[uint32Index];
if (!unchanged) {
uint32Index = i * 2 + 1;
dirty = dirty || previousUint32View[uint32Index] !== currentUint32View[uint32Index];
if (dirty) {
previousUint32View[uint32Index] = currentUint32View[uint32Index];
}
}
var lengthRange = clippingPlaneCollection._lengthRange;
lengthRange.x = lengthRangeUnion.x;
lengthRange.y = lengthRangeUnion.y;
lengthRange.z = lengthRangeUnion.z;
return !unchanged;
return dirty;
}

/**
Expand Down Expand Up @@ -458,9 +457,6 @@ define([
});
this._clippingPlanesTexture = clippingPlanesTexture;
}
if (!this._planeTextureDirty) {
return;
}
// pack planes to currentTextureBytes, do a texture update if anything changed.
if (packAndReturnChanged(this)) {
clippingPlanesTexture.copyFrom({
Expand Down Expand Up @@ -556,12 +552,12 @@ define([

/**
* The maximum number of supported clipping planes.
* @private
*
* @see maxClippingPlanes.glsl
* @type {number}
* @constant
*/
ClippingPlaneCollection.MAX_CLIPPING_PLANES = 2048;
ClippingPlaneCollection.MAX_CLIPPING_PLANES = 2048; // See maxClippingPlanes.glsl

/**
* The pixel width of a square, power-of-two RGBA UNSIGNED_BYTE texture
Expand All @@ -574,27 +570,62 @@ define([
*/
ClippingPlaneCollection.TEXTURE_WIDTH = CesiumMath.nextPowerOfTwo(Math.ceil(Math.sqrt(ClippingPlaneCollection.MAX_CLIPPING_PLANES * 2)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be marked @private.

Copy link
Contributor

@lilleyse lilleyse Feb 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump.

Edit: add @private.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would make more sense to make this a 1D texture, at least it would simplify some shader code. I can't seem to load https://webglstats.com/webgl right now but we can check what % of devices support 2048 pixel textures.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might still be better to keep it as a POT though. I think I remember something about those being more efficient for GPU memory or something, although I also vaguely remember someone saying something about how that's not necessarily true anymore...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to use 1D textures for the 3D Tiles batch table, so there is some precedent there. But it doesn't matter much in the end.


/**
* Returns true if this object was destroyed; otherwise, false.
* <br /><br />
* If this object was destroyed, it should not be used; calling any function other than
* <code>isDestroyed</code> will result in a {@link DeveloperError} exception.
*
* @returns {Boolean} <code>true</code> if this object was destroyed; otherwise, <code>false</code>.
*
* @see ClippingPlaneCollection#destroy
*/
ClippingPlaneCollection.prototype.isDestroyed = function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the usual doc above this:

    /**
     * Returns true if this object was destroyed; otherwise, false.
     * <br /><br />
     * If this object was destroyed, it should not be used; calling any function other than
     * <code>isDestroyed</code> will result in a {@link DeveloperError} exception.
     *
     * @returns {Boolean} <code>true</code> if this object was destroyed; otherwise, <code>false</code>.
     *
     * @see ClippingPlaneCollection#destroy
     */

return false;
};

/**
* Destroys this ClippingPlaneCollection if it either has no owner or a reference to the owner is passed in.
* We only expect an owner to be defined if this collection is shared by one Cesium3DTileset
* and a series of Cesium3DTiles with Model content.
* Destroys this ClippingPlaneCollectionand its WebGL resources.
* @private
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc indentation is slightly misaligned.

ClippingPlaneCollection.prototype.destroy = function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round out the doc for this. For example:

    /**
     * Destroys the WebGL resources held by this object.  Destroying an object allows for deterministic
     * release of WebGL resources, instead of relying on the garbage collector to destroy this object.
     * <br /><br />
     * Once an object is destroyed, it should not be used; calling any function other than
     * <code>isDestroyed</code> will result in a {@link DeveloperError} exception.  Therefore,
     * assign the return value (<code>undefined</code>) to the object as done in the example.
     *
     * @returns {undefined}
     *
     * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
     *
     *
     * @example
     * clippingPlanes = clippingPlanes && clippingPlanes .destroy();
     *
     * @see ClippingPlaneCollection#isDestroyed
     */

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also remove @private. See #5615 (comment)

this._clippingPlanesTexture = this._clippingPlanesTexture && this._clippingPlanesTexture.destroy();
return destroyObject(this);
};

/**
* Sets the owner for the input ClippingPlaneCollection if there wasn't another owner.
* Destroys the owner's previous ClippingPlaneCollection if setting is successful.
*
* @param {Object} owner An object to check against this ClippingPlaneCollection's owner object
* @param {ClippingPlaneCollection} [clippingPlaneCollection] A ClippingPlaneCollection (or undefined) being attached to an object
* @param {Object} newOwner An Object that should receive the new ClippingPlaneCollection
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just owner is fine.

* @param {String} key The Key for the Object to reference the ClippingPlaneCollection
* @private
*/
ClippingPlaneCollection.prototype.checkDestroy = function(owner) {
if (defined(this.owner) && owner !== this.owner) {
return this;
ClippingPlaneCollection.setOwnership = function(clippingPlaneCollection, newOwner, key) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Place setOwnership and isSupported above the destroy functions, which are usually last.

// Don't destroy the ClippingPlaneCollection if it is already owned by newOwner
if (clippingPlaneCollection === newOwner[key]) {
return;
}

if (defined(this._clippingPlanesTexture)) {
this._clippingPlanesTexture.destroy();
// Destroy the existing ClippingPlaneCollection, if any
newOwner[key] = newOwner[key] && newOwner[key].destroy();
if (defined(clippingPlaneCollection)) {
if (defined(clippingPlaneCollection._owner)) {
throw new DeveloperError('ClippingPlaneCollection should only be assigned to one object');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap the developer error:

//>>includeStart('debug', pragmas.debug);
if (defined(clippingPlaneCollection._owner)) {
    throw new DeveloperError('ClippingPlaneCollection should only be assigned to one object');
}
//>>includeEnd('debug');

clippingPlaneCollection._owner = newOwner;
newOwner[key] = clippingPlaneCollection;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We often simplify this type of destroy code to this._clippingPlanesTexture = this._clippingPlanesTexture && this._clippingPlanesTexture.destroy();

return destroyObject(this);
};

/**
* Determines if rendering with clipping planes is supported.
*
* @returns {Boolean} <code>true</code> if ClippingPlaneCollections are supported
* @deprecated
*/
ClippingPlaneCollection.isSupported = function() {
return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have a deprecationWarning

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@likangning93 did you add the deprecation warning here?

};

return ClippingPlaneCollection;
Expand Down
6 changes: 3 additions & 3 deletions Source/Scene/Batched3DModel3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,7 @@ define([
pickFragmentShaderLoaded : batchTable.getPickFragmentShaderCallback(),
pickUniformMapLoaded : batchTable.getPickUniformMapCallback(),
addBatchIdToGeneratedShaders : (batchLength > 0), // If the batch table has values in it, generated shaders will need a batchId attribute
pickObject : pickObject,
clippingPlanes : tileset.clippingPlanes
pickObject : pickObject
});
} else {
// This transcodes glTF to an internal representation for geometry so we can take advantage of the re-batching of vector data.
Expand Down Expand Up @@ -494,7 +493,8 @@ define([
var tilesetClippingPlanes = this._tileset.clippingPlanes;
if (defined(tilesetClippingPlanes)) {
// Dereference the clipping planes from the model if they are irrelevant - saves on shading
this._model.clippingPlanes = tilesetClippingPlanes.enabled && this._tile._isClipped ? tilesetClippingPlanes : undefined;
// Link/Dereference directly to avoid ownership checks.
this._model._clippingPlanes = (tilesetClippingPlanes.enabled && this._tile._isClipped) ? tilesetClippingPlanes : undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ultimately I don't think we will need this block. Same note for Instanced3DModel3DTileContent.

It should just be:
this._model._clippingPlanes = this._tileset.clippingPlanes

That plus any of the clippingPlanesState/clippingPlanesDirty state should be all we need.

Copy link
Contributor Author

@likangning93 likangning93 Mar 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight problem, I think a clippingPlanesDirty toggle on model doesn't allow a way to tell the model that clipping should be disabled because it's irrelevant? That was part of the reasoning behind referencing/dereferencing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarified offline, we can have Model.js only update its own _clippingPlaneState when it owns the clipping plane collection, otherwise it'll rely on b3dm and i3dm to do that, hence the need for the clippingPlanesDirty toggle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another chat offline: consensus is that the method where b3dm and i3dm handle more state stuff for Model.js requires more state variables attached to Model prototype. Seems like it should be cleaner to have b3dm and i3dm continue to do their dereference/re-reference thing.

}

this._model.update(frameState);
Expand Down
30 changes: 9 additions & 21 deletions Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ define([
'../Core/Cartesian3',
'../Core/Cartographic',
'../Core/Check',
'../Core/ClippingPlaneCollection',
'../Core/defaultValue',
'../Core/defined',
'../Core/defineProperties',
Expand Down Expand Up @@ -46,6 +47,7 @@ define([
Cartesian3,
Cartographic,
Check,
ClippingPlaneCollection,
defaultValue,
defined,
defineProperties,
Expand Down Expand Up @@ -547,12 +549,8 @@ define([
*/
this.loadSiblings = defaultValue(options.loadSiblings, false);

this._clippingPlanes = options.clippingPlanes;

// Set ownership so no Models created as content will try to delete it
if (defined(options.clippingPlanes)) {
options.clippingPlanes.owner = this;
}
this._clippingPlanes = undefined;
ClippingPlaneCollection.setOwnership(options.clippingPlanes, this, '_clippingPlanes');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to call the setter: this.clippingPlanes = options.clippingPlanes.


/**
* This property is for debugging only; it is not optimized for production use.
Expand Down Expand Up @@ -810,7 +808,7 @@ define([
}
},
/**
* The {@link ClippingPlaneCollection} used to selectively disable rendering the tileset. Clipping planes are not currently supported in Internet Explorer.
* The {@link ClippingPlaneCollection} used to selectively disable rendering the tileset.
*
* @type {ClippingPlaneCollection}
*/
Expand All @@ -819,12 +817,7 @@ define([
return this._clippingPlanes;
},
set : function(value) {
var oldClippingPlanes = this._clippingPlanes;
if (defined(oldClippingPlanes)) {
oldClippingPlanes.checkDestroy(this);
}
this._clippingPlanes = value;
value.owner = this;
ClippingPlaneCollection.setOwnership(value, this, '_clippingPlanes');
}
},

Expand Down Expand Up @@ -1861,10 +1854,8 @@ define([

// Update clipping planes and set them as clean to avoid re-updating the same information from each tile
var clippingPlanes = this._clippingPlanes;
if (defined(clippingPlanes)) {
clippingPlanes._planeTextureDirty = true;
if (defined(clippingPlanes) && clippingPlanes.enabled) {
clippingPlanes.update(frameState);
clippingPlanes._planeTextureDirty = false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be cleaner if Model checks if it owns the clipping plane, and if so call update.


this._timeSinceLoad = Math.max(JulianDate.secondsDifference(frameState.time, this._loadTimestamp) * 1000, 0.0);
Expand Down Expand Up @@ -1941,11 +1932,8 @@ define([
// Destroy debug labels
this._tileDebugLabels = this._tileDebugLabels && this._tileDebugLabels.destroy();

// Destroy clipping plane collection, setting ownership first.
var clippingPlaneCollection = this._clippingPlanes;
if (defined(clippingPlaneCollection)) {
clippingPlaneCollection.checkDestroy(this);
}
// Destroy clipping plane collection
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment and // Destroy debug labels above are not needed.

Just like ++i; // add one to i would not be needed.

this._clippingPlanes = this._clippingPlanes && this._clippingPlanes.destroy();

// Traverse the tree and destroy all tiles
if (defined(this._root)) {
Expand Down
11 changes: 0 additions & 11 deletions Source/Scene/Globe.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,16 +696,5 @@ define([
return destroyObject(this);
};

/**
* Destroys the Globe's ClippingPlaneCollection and frees the associated webgl resources.
*/
Globe.prototype.destroyClippingPlanes = function() {
var clippingPlanes = this._surface.tileProvider.clippingPlanes;
if (defined(clippingPlanes)) {
clippingPlanes.checkDestroy();
}
this._surface.tileProvider.clippingPlanes = undefined;
};

return Globe;
});
Loading