diff --git a/Specs/Scene/Geometry3DTileContentSpec.js b/Specs/Scene/Geometry3DTileContentSpec.js index dae01c33c3cc..5b6cad6cc43e 100644 --- a/Specs/Scene/Geometry3DTileContentSpec.js +++ b/Specs/Scene/Geometry3DTileContentSpec.js @@ -14,12 +14,14 @@ defineSuite([ 'Core/RectangleGeometry', 'Core/Transforms', 'Renderer/Pass', + 'Renderer/RenderState', 'Scene/Cesium3DTileBatchTable', 'Scene/Cesium3DTileset', 'Scene/Cesium3DTileStyle', 'Scene/ClassificationType', 'Scene/PerInstanceColorAppearance', 'Scene/Primitive', + 'Scene/StencilConstants', 'Specs/Cesium3DTilesTester', 'Specs/createScene' ], function( @@ -38,12 +40,14 @@ defineSuite([ RectangleGeometry, Transforms, Pass, + RenderState, Cesium3DTileBatchTable, Cesium3DTileset, Cesium3DTileStyle, ClassificationType, PerInstanceColorAppearance, Primitive, + StencilConstants, Cesium3DTilesTester, createScene) { 'use strict'; @@ -82,73 +86,101 @@ defineSuite([ var scene; var rectangle; - var depthPrimitive; var tileset; + var globePrimitive; + var tilesetPrimitive; + var reusableGlobePrimitive; + var reusableTilesetPrimitive; + var depthColor; var ellipsoid = Ellipsoid.WGS84; - beforeAll(function() { - scene = createScene(); - }); - - afterAll(function() { - scene.destroyForSpecs(); - }); + function createPrimitive(rectangle, pass) { + var renderState; + if (pass === Pass.CESIUM_3D_TILE) { + renderState = RenderState.fromCache({ + stencilTest : StencilConstants.setCesium3DTileBit(), + stencilMask : StencilConstants.CESIUM_3D_TILE_MASK, + depthTest : { + enabled : true + } + }); + } + var depthColorAttribute = ColorGeometryInstanceAttribute.fromColor(new Color(1.0, 0.0, 0.0, 1.0)); + depthColor = depthColorAttribute.value; + return new Primitive({ + geometryInstances : new GeometryInstance({ + geometry : new RectangleGeometry({ + ellipsoid : Ellipsoid.WGS84, + rectangle : rectangle + }), + id : 'depth rectangle', + attributes : { + color : depthColorAttribute + } + }), + appearance : new PerInstanceColorAppearance({ + translucent : false, + flat : true, + renderState : renderState + }), + asynchronous : false + }); + } - function MockGlobePrimitive(primitive) { + function MockPrimitive(primitive, pass) { this._primitive = primitive; - this.pass = Pass.CESIUM_3D_TILE; + this._pass = pass; + this.show = true; } - MockGlobePrimitive.prototype.update = function(frameState) { + MockPrimitive.prototype.update = function(frameState) { + if (!this.show) { + return; + } + var commandList = frameState.commandList; var startLength = commandList.length; this._primitive.update(frameState); for (var i = startLength; i < commandList.length; ++i) { var command = commandList[i]; - command.pass = this.pass; + command.pass = this._pass; } }; - MockGlobePrimitive.prototype.isDestroyed = function() { + MockPrimitive.prototype.isDestroyed = function() { return false; }; - MockGlobePrimitive.prototype.destroy = function() { - this._primitive.destroy(); + MockPrimitive.prototype.destroy = function() { return destroyObject(this); }; - beforeEach(function() { + beforeAll(function() { + scene = createScene(); + rectangle = Rectangle.fromDegrees(-40.0, -40.0, 40.0, 40.0); + reusableGlobePrimitive = createPrimitive(rectangle, Pass.GLOBE); + reusableTilesetPrimitive = createPrimitive(rectangle, Pass.CESIUM_3D_TILE); + }); - var depthColorAttribute = ColorGeometryInstanceAttribute.fromColor(new Color(1.0, 0.0, 0.0, 1.0)); - var primitive = new Primitive({ - geometryInstances : new GeometryInstance({ - geometry : new RectangleGeometry({ - ellipsoid : ellipsoid, - rectangle : rectangle - }), - id : 'depth rectangle', - attributes : { - color : depthColorAttribute - } - }), - appearance : new PerInstanceColorAppearance({ - translucent : false, - flat : true - }), - asynchronous : false - }); + afterAll(function() { + reusableGlobePrimitive.destroy(); + reusableTilesetPrimitive.destroy(); + scene.destroyForSpecs(); + }); - // wrap rectangle primitive so it gets executed during the globe pass to lay down depth - depthPrimitive = new MockGlobePrimitive(primitive); + beforeEach(function() { + // wrap rectangle primitive so it gets executed during the globe pass and 3D Tiles pass to lay down depth + globePrimitive = new MockPrimitive(reusableGlobePrimitive, Pass.GLOBE); + tilesetPrimitive = new MockPrimitive(reusableTilesetPrimitive, Pass.CESIUM_3D_TILE); }); afterEach(function() { scene.primitives.removeAll(); - depthPrimitive = depthPrimitive && !depthPrimitive.isDestroyed() && depthPrimitive.destroy(); + globePrimitive = globePrimitive && !globePrimitive.isDestroyed() && globePrimitive.destroy(); + tilesetPrimitive = tilesetPrimitive && !tilesetPrimitive.isDestroyed() && tilesetPrimitive.destroy(); tileset = tileset && !tileset.isDestroyed() && tileset.destroy(); }); @@ -236,8 +268,63 @@ defineSuite([ expectRender(scene, [0, 0, 255, 255]); } + it('renders on 3D Tiles', function() { + scene.primitives.add(globePrimitive); + scene.primitives.add(tilesetPrimitive); + tileset = scene.primitives.add(new Cesium3DTileset({ + url : geometryBoxes, + classificationType : ClassificationType.CESIUM_3D_TILE + })); + return loadTileset(tileset).then(function(tileset) { + globePrimitive.show = false; + tilesetPrimitive.show = true; + verifyRender(tileset, scene); + verifyPick(scene); + globePrimitive.show = true; + tilesetPrimitive.show = false; + expect(scene).toRender(depthColor); + }); + }); + + it('renders on globe', function() { + scene.primitives.add(globePrimitive); + scene.primitives.add(tilesetPrimitive); + tileset = scene.primitives.add(new Cesium3DTileset({ + url : geometryBoxes, + classificationType : ClassificationType.TERRAIN + })); + return loadTileset(tileset).then(function(tileset) { + globePrimitive.show = false; + tilesetPrimitive.show = true; + expect(scene).toRender(depthColor); + globePrimitive.show = true; + tilesetPrimitive.show = false; + verifyRender(tileset, scene); + verifyPick(scene); + }); + }); + + it('renders on 3D Tiles and globe', function() { + scene.primitives.add(globePrimitive); + scene.primitives.add(tilesetPrimitive); + tileset = scene.primitives.add(new Cesium3DTileset({ + url : geometryBoxes, + classificationType : ClassificationType.BOTH + })); + return loadTileset(tileset).then(function(tileset) { + globePrimitive.show = false; + tilesetPrimitive.show = true; + verifyRender(tileset, scene); + verifyPick(scene); + globePrimitive.show = true; + tilesetPrimitive.show = false; + verifyRender(tileset, scene); + verifyPick(scene); + }); + }); + it('renders boxes', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryBoxes })); @@ -248,7 +335,7 @@ defineSuite([ }); it('renders batched boxes', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryBoxesBatchedChildren })); @@ -259,7 +346,7 @@ defineSuite([ }); it('renders boxes with a batch table', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryBoxesWithBatchTable })); @@ -270,7 +357,7 @@ defineSuite([ }); it('renders batched boxes with a batch table', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryBoxesBatchedChildrenWithBatchTable })); @@ -281,7 +368,7 @@ defineSuite([ }); it('renders boxes with batch ids', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryBoxesWithBatchIds })); @@ -292,7 +379,7 @@ defineSuite([ }); it('renders cylinders', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryCylinders })); @@ -303,7 +390,7 @@ defineSuite([ }); it('renders batched cylinders', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryCylindersBatchedChildren })); @@ -314,7 +401,7 @@ defineSuite([ }); it('renders cylinders with a batch table', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryCylindersWithBatchTable })); @@ -325,7 +412,7 @@ defineSuite([ }); it('renders batched cylinders with a batch table', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryCylindersBatchedChildrenWithBatchTable })); @@ -336,7 +423,7 @@ defineSuite([ }); it('renders cylinders with batch ids', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryCylindersWithBatchIds })); @@ -347,7 +434,7 @@ defineSuite([ }); it('renders ellipsoids', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryEllipsoids })); @@ -358,7 +445,7 @@ defineSuite([ }); it('renders batched ellipsoids', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryEllipsoidsBatchedChildren })); @@ -369,7 +456,7 @@ defineSuite([ }); it('renders ellipsoids with a batch table', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryEllipsoidsWithBatchTable })); @@ -380,7 +467,7 @@ defineSuite([ }); it('renders batched ellipsoids with a batch table', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryEllipsoidsBatchedChildrenWithBatchTable })); @@ -391,7 +478,7 @@ defineSuite([ }); it('renders ellipsoids with batch ids', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryEllipsoidsWithBatchIds })); @@ -402,7 +489,7 @@ defineSuite([ }); it('renders spheres', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometrySpheres })); @@ -413,7 +500,7 @@ defineSuite([ }); it('renders batched spheres', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometrySpheresBatchedChildren })); @@ -424,7 +511,7 @@ defineSuite([ }); it('renders spheres with a batch table', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometrySpheresWithBatchTable })); @@ -435,7 +522,7 @@ defineSuite([ }); it('renders batched spheres with a batch table', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometrySpheresBatchedChildrenWithBatchTable })); @@ -446,7 +533,7 @@ defineSuite([ }); it('renders spheres with batch ids', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometrySpheresWithBatchIds })); @@ -457,7 +544,7 @@ defineSuite([ }); it('renders all geometries', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryAll })); @@ -468,7 +555,7 @@ defineSuite([ }); it('renders batched all geometries', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryAllBatchedChildren })); @@ -479,7 +566,7 @@ defineSuite([ }); it('renders all geometries with a batch table', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryAllWithBatchTable })); @@ -490,7 +577,7 @@ defineSuite([ }); it('renders batched all geometries with a batch table', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryAllBatchedChildrenWithBatchTable })); @@ -501,7 +588,7 @@ defineSuite([ }); it('renders all geometries with batch ids', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryAllWithBatchIds })); @@ -512,7 +599,7 @@ defineSuite([ }); it('renders all geometries with debug color', function() { - scene.primitives.add(depthPrimitive); + scene.primitives.add(globePrimitive); tileset = scene.primitives.add(new Cesium3DTileset({ url : geometryAllWithBatchTable, debugColorizeTiles : true