diff --git a/Source/Scene/Batched3DModel3DTileContent.js b/Source/Scene/Batched3DModel3DTileContent.js index 2f6f2a350dd0..2bdb88848e36 100644 --- a/Source/Scene/Batched3DModel3DTileContent.js +++ b/Source/Scene/Batched3DModel3DTileContent.js @@ -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 diff --git a/Source/Scene/Instanced3DModel3DTileContent.js b/Source/Scene/Instanced3DModel3DTileContent.js index 01f65513809f..79c1fdf3819c 100644 --- a/Source/Scene/Instanced3DModel3DTileContent.js +++ b/Source/Scene/Instanced3DModel3DTileContent.js @@ -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 diff --git a/Specs/Scene/Batched3DModel3DTileContentSpec.js b/Specs/Scene/Batched3DModel3DTileContentSpec.js index b1ac299a4efb..cb9ebbf4a892 100644 --- a/Specs/Scene/Batched3DModel3DTileContentSpec.js +++ b/Specs/Scene/Batched3DModel3DTileContentSpec.js @@ -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(); diff --git a/Specs/Scene/Instanced3DModel3DTileContentSpec.js b/Specs/Scene/Instanced3DModel3DTileContentSpec.js index c3626c773e57..dbc68181d84c 100644 --- a/Specs/Scene/Instanced3DModel3DTileContentSpec.js +++ b/Specs/Scene/Instanced3DModel3DTileContentSpec.js @@ -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();