Skip to content

Commit

Permalink
Fix Vector3DTileContent tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Dec 19, 2018
1 parent 2a2cef0 commit 8163a79
Showing 1 changed file with 121 additions and 72 deletions.
193 changes: 121 additions & 72 deletions Specs/Scene/Vector3DTileContentSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -38,12 +40,14 @@ defineSuite([
RectangleGeometry,
Transforms,
Pass,
RenderState,
Cesium3DTileBatchTable,
Cesium3DTileset,
Cesium3DTileStyle,
ClassificationType,
PerInstanceColorAppearance,
Primitive,
StencilConstants,
Cesium3DTilesTester,
createScene) {
'use strict';
Expand Down Expand Up @@ -74,73 +78,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();
});

Expand Down Expand Up @@ -461,7 +493,7 @@ defineSuite([
});

it('renders polygons', function() {
scene.primitives.add(depthPrimitive);
scene.primitives.add(globePrimitive);
tileset = scene.primitives.add(new Cesium3DTileset({
url : vectorPolygons
}));
Expand All @@ -472,7 +504,7 @@ defineSuite([
});

it('renders batched polygons', function() {
scene.primitives.add(depthPrimitive);
scene.primitives.add(globePrimitive);
tileset = scene.primitives.add(new Cesium3DTileset({
url : vectorPolygonsBatchedChildren
}));
Expand All @@ -483,7 +515,7 @@ defineSuite([
});

it('renders polygons with a batch table', function() {
scene.primitives.add(depthPrimitive);
scene.primitives.add(globePrimitive);
tileset = scene.primitives.add(new Cesium3DTileset({
url : vectorPolygonsWithBatchTable
}));
Expand All @@ -494,7 +526,7 @@ defineSuite([
});

it('renders batched polygons with a batch table', function() {
scene.primitives.add(depthPrimitive);
scene.primitives.add(globePrimitive);
tileset = scene.primitives.add(new Cesium3DTileset({
url : vectorPolygonsBatchedChildrenWithBatchTable
}));
Expand All @@ -505,7 +537,7 @@ defineSuite([
});

it('renders polygons with batch ids', function() {
scene.primitives.add(depthPrimitive);
scene.primitives.add(globePrimitive);
tileset = scene.primitives.add(new Cesium3DTileset({
url : vectorPolygonsWithBatchIds
}));
Expand Down Expand Up @@ -561,7 +593,7 @@ defineSuite([
});

it('renders combined tile', function() {
scene.primitives.add(depthPrimitive);
scene.primitives.add(globePrimitive);
tileset = scene.primitives.add(new Cesium3DTileset({
url : vectorCombined
}));
Expand All @@ -571,7 +603,7 @@ defineSuite([
});

it('renders combined tile with batch ids', function() {
scene.primitives.add(depthPrimitive);
scene.primitives.add(globePrimitive);
tileset = scene.primitives.add(new Cesium3DTileset({
url : vectorCombinedWithBatchIds
}));
Expand All @@ -581,7 +613,7 @@ defineSuite([
});

it('renders with debug color', function() {
scene.primitives.add(depthPrimitive);
scene.primitives.add(globePrimitive);
tileset = scene.primitives.add(new Cesium3DTileset({
url : vectorCombined,
debugColorizeTiles : true
Expand All @@ -603,41 +635,58 @@ defineSuite([
});
});

it('renders with different classification types', function() {
scene.primitives.add(depthPrimitive);
it('renders on 3D Tiles', function() {
scene.primitives.add(globePrimitive);
scene.primitives.add(tilesetPrimitive);
tileset = scene.primitives.add(new Cesium3DTileset({
url : vectorPolygonsBatchedChildren,
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 : vectorPolygonsBatchedChildren,
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);
});
});

scene.primitives.remove(tileset);

tileset = scene.primitives.add(new Cesium3DTileset({
url : vectorPolygonsBatchedChildren,
classificationType : ClassificationType.TERRAIN
}));
return loadTileset(tileset).then(function(tileset) {
depthPrimitive.pass = Pass.GLOBE;
verifyRender(tileset, scene);
verifyPick(scene);

scene.primitives.remove(tileset);

tileset = scene.primitives.add(new Cesium3DTileset({
url : vectorPolygonsBatchedChildren,
classificationType : ClassificationType.BOTH
}));
return loadTileset(tileset).then(function(tileset) {
verifyRender(tileset, scene);
verifyPick(scene);
depthPrimitive.pass = Pass.CESIUM_3D_TILE;
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 : vectorPolygonsBatchedChildren,
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);
});
});

Expand Down

0 comments on commit 8163a79

Please sign in to comment.