Skip to content

Commit

Permalink
add check in Model-based 3D Tiles for tileset clipping planes reassig…
Browse files Browse the repository at this point in the history
…nment
  • Loading branch information
likangning93 committed May 23, 2018
1 parent 51bc9c3 commit 8f97a0f
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Source/Scene/Batched3DModel3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,12 @@ define([
this._model._clippingPlanes = (tilesetClippingPlanes.enabled && this._tile._isClipped) ? tilesetClippingPlanes : undefined;
}

// If the model references a destroyed ClippingPlaneCollection due to the tileset's collection being replaced with a
// ClippingPlaneCollection that gives this tile the same clipping status, update the model to use the new ClippingPlaneCollection.
if (defined(tilesetClippingPlanes) && defined(this._model._clippingPlanes) && this._model._clippingPlanes.isDestroyed()) {
this._model._clippingPlanes = tilesetClippingPlanes;
}

this._model.update(frameState);

// If any commands were pushed, add derived commands
Expand Down
6 changes: 6 additions & 0 deletions Source/Scene/Instanced3DModel3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,12 @@ define([
}
}

// If the model references a destroyed ClippingPlaneCollection due to the tileset's collection being replaced with a
// ClippingPlaneCollection that gives this tile the same clipping status, update the model to use the new ClippingPlaneCollection.
if (defined(tilesetClippingPlanes) && defined(model._clippingPlanes) && model._clippingPlanes.isDestroyed()) {
model._clippingPlanes = tilesetClippingPlanes;
}

this._modelInstanceCollection.update(frameState);

// If any commands were pushed, add derived commands
Expand Down
33 changes: 33 additions & 0 deletions Specs/Scene/Batched3DModel3DTileContentSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,39 @@ defineSuite([
});
});

it('Links model to tileset clipping planes if tileset clipping planes are reassigned', function() {
return Cesium3DTilesTester.loadTileset(scene, withBatchTableUrl).then(function(tileset) {
var tile = tileset._root;
var model = tile.content._model;

expect(model.clippingPlanes).toBeUndefined();

var clippingPlaneCollection = new ClippingPlaneCollection({
planes : [
new ClippingPlane(Cartesian3.UNIT_X, 0.0)
]
});
tileset.clippingPlanes = clippingPlaneCollection;
clippingPlaneCollection.update(scene.frameState);
tile.update(tileset, scene.frameState);

expect(model.clippingPlanes).toBeDefined();
expect(model.clippingPlanes).toBe(tileset.clippingPlanes);

var newClippingPlaneCollection = new ClippingPlaneCollection({
planes : [
new ClippingPlane(Cartesian3.UNIT_X, 0.0)
]
});
tileset.clippingPlanes = newClippingPlaneCollection;
newClippingPlaneCollection.update(scene.frameState);
expect(model.clippingPlanes).not.toBe(tileset.clippingPlanes);

tile.update(tileset, scene.frameState);
expect(model.clippingPlanes).toBe(tileset.clippingPlanes);
});
});

it('rebuilds Model shaders when clipping planes change', function() {
spyOn(Model, '_getClippingFunction').and.callThrough();

Expand Down
33 changes: 33 additions & 0 deletions Specs/Scene/Instanced3DModel3DTileContentSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,39 @@ defineSuite([
});
});

it('Links model to tileset clipping planes if tileset clipping planes are reassigned', function() {
return Cesium3DTilesTester.loadTileset(scene, withBatchTableUrl).then(function(tileset) {
var tile = tileset._root;
var model = tile.content._modelInstanceCollection._model;

expect(model.clippingPlanes).toBeUndefined();

var clippingPlaneCollection = new ClippingPlaneCollection({
planes : [
new ClippingPlane(Cartesian3.UNIT_X, 0.0)
]
});
tileset.clippingPlanes = clippingPlaneCollection;
clippingPlaneCollection.update(scene.frameState);
tile.update(tileset, scene.frameState);

expect(model.clippingPlanes).toBeDefined();
expect(model.clippingPlanes).toBe(tileset.clippingPlanes);

var newClippingPlaneCollection = new ClippingPlaneCollection({
planes : [
new ClippingPlane(Cartesian3.UNIT_X, 0.0)
]
});
tileset.clippingPlanes = newClippingPlaneCollection;
newClippingPlaneCollection.update(scene.frameState);
expect(model.clippingPlanes).not.toBe(tileset.clippingPlanes);

tile.update(tileset, scene.frameState);
expect(model.clippingPlanes).toBe(tileset.clippingPlanes);
});
});

it('rebuilds Model shaders when clipping planes change', function() {
spyOn(Model, '_getClippingFunction').and.callThrough();

Expand Down

0 comments on commit 8f97a0f

Please sign in to comment.