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

Fix classification when terrain depth writes are enabled #7422

Merged
merged 16 commits into from
Dec 19, 2018
Merged
Changes from 1 commit
Commits
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
177 changes: 132 additions & 45 deletions Specs/Scene/Vector3DTilePolygonsSpec.js
Original file line number Diff line number Diff line change
@@ -14,10 +14,13 @@ defineSuite([
'Core/RectangleGeometry',
'Core/Transforms',
'Renderer/Pass',
'Renderer/RenderState',
'Scene/Cesium3DTileBatchTable',
'Scene/ClassificationType',
'Scene/ColorBlendMode',
'Scene/PerInstanceColorAppearance',
'Scene/Primitive',
'Scene/StencilConstants',
'Specs/createContext',
'Specs/createScene',
'Specs/pollToPromise'
@@ -37,10 +40,13 @@ defineSuite([
RectangleGeometry,
Transforms,
Pass,
RenderState,
Cesium3DTileBatchTable,
ClassificationType,
ColorBlendMode,
PerInstanceColorAppearance,
Primitive,
StencilConstants,
createContext,
createScene,
pollToPromise) {
@@ -59,19 +65,14 @@ defineSuite([

var scene;
var rectangle;
var depthPrimitive;
var polygons;
var globePrimitive;
var tilesetPrimitive;
var reusableGlobePrimitive;
var reusableTilesetPrimitive;

var ellipsoid = Ellipsoid.WGS84;

beforeAll(function() {
scene = createScene({ contextOptions : contextOptions });
});

afterAll(function() {
scene.destroyForSpecs();
});

var mockTileset = {
_statistics : {
texturesByteLength : 0
@@ -85,61 +86,92 @@ defineSuite([
getFeature : function(id) { return { batchId : id }; }
};

function MockGlobePrimitive(primitive) {
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));
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 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({ contextOptions : contextOptions });

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();
globePrimitive = globePrimitive && !globePrimitive.isDestroyed() && globePrimitive.destroy();
tilesetPrimitive = tilesetPrimitive && !tilesetPrimitive.isDestroyed() && tilesetPrimitive.destroy();
polygons = polygons && !polygons.isDestroyed() && polygons.destroy();
depthPrimitive = depthPrimitive && !depthPrimitive.isDestroyed() && depthPrimitive.destroy();
});

function loadPolygons(polygons) {
@@ -211,7 +243,7 @@ defineSuite([
var batchTable = new Cesium3DTileBatchTable(mockTileset, 1);
batchTable.update(mockTileset, scene.frameState);

scene.primitives.add(depthPrimitive);
scene.primitives.add(globePrimitive);

var center = ellipsoid.cartographicToCartesian(Rectangle.center(rectangle));
polygons = scene.primitives.add(new Vector3DTilePolygons(combine(polygonOptions, {
@@ -256,7 +288,7 @@ defineSuite([
var batchTable = new Cesium3DTileBatchTable(mockTileset, 2);
batchTable.update(mockTileset, scene.frameState);

scene.primitives.add(depthPrimitive);
scene.primitives.add(globePrimitive);

var center = ellipsoid.cartographicToCartesian(Rectangle.center(rectangle));
polygons = scene.primitives.add(new Vector3DTilePolygons({
@@ -316,7 +348,7 @@ defineSuite([
var batchTable = new Cesium3DTileBatchTable(mockTileset, 2);
batchTable.update(mockTileset, scene.frameState);

scene.primitives.add(depthPrimitive);
scene.primitives.add(globePrimitive);

var center = ellipsoid.cartographicToCartesian(Rectangle.center(rectangle));
polygons = scene.primitives.add(new Vector3DTilePolygons({
@@ -377,7 +409,7 @@ defineSuite([
var batchTable = new Cesium3DTileBatchTable(mockTileset, 2);
batchTable.update(mockTileset, scene.frameState);

scene.primitives.add(depthPrimitive);
scene.primitives.add(globePrimitive);

var center = ellipsoid.cartographicToCartesian(Rectangle.center(rectangle));
polygons = scene.primitives.add(new Vector3DTilePolygons({
@@ -424,7 +456,7 @@ defineSuite([
var batchTable = new Cesium3DTileBatchTable(mockTileset, 1);
batchTable.update(mockTileset, scene.frameState);

scene.primitives.add(depthPrimitive);
scene.primitives.add(tilesetPrimitive);

var center = ellipsoid.cartographicToCartesian(Rectangle.center(rectangle));
polygons = scene.primitives.add(new Vector3DTilePolygons(combine(polygonOptions, {
@@ -465,7 +497,7 @@ defineSuite([
var batchTable = new Cesium3DTileBatchTable(mockTileset, 1);
batchTable.update(mockTileset, scene.frameState);

scene.primitives.add(depthPrimitive);
scene.primitives.add(globePrimitive);

var center = ellipsoid.cartographicToCartesian(Rectangle.center(rectangle));
polygons = scene.primitives.add(new Vector3DTilePolygons(combine(polygonOptions, {
@@ -493,13 +525,68 @@ defineSuite([
});
});

it('renders based on classificationType' + webglMessage, function() {
var rectangle = Rectangle.fromDegrees(-1.0, -1.0, 1.0, 1.0);
var polygonOptions = createPolygon(rectangle);

var batchTable = new Cesium3DTileBatchTable(mockTileset, 1);
batchTable.update(mockTileset, scene.frameState);

scene.primitives.add(globePrimitive);
scene.primitives.add(tilesetPrimitive);

var center = ellipsoid.cartographicToCartesian(Rectangle.center(rectangle));
polygons = scene.primitives.add(new Vector3DTilePolygons(combine(polygonOptions, {
minimumHeight : -10000.0,
maximumHeight : 10000.0,
center : center,
rectangle : rectangle,
boundingVolume : new BoundingSphere(center, 10000.0),
batchTable : batchTable,
batchIds : new Uint32Array([0]),
isCartographic : true
})));
return loadPolygons(polygons).then(function() {
scene.camera.setView({
destination : rectangle
});

polygons.classificationType = ClassificationType.CESIUM_3D_TILE;
globePrimitive.show = false;
tilesetPrimitive.show = true;
expect(scene).toRender([255, 255, 255, 255]);
globePrimitive.show = true;
tilesetPrimitive.show = false;
expect(scene).toRender([255, 0, 0, 255]);

polygons.classificationType = ClassificationType.TERRAIN;
globePrimitive.show = false;
tilesetPrimitive.show = true;
expect(scene).toRender([255, 0, 0, 255]);
globePrimitive.show = true;
tilesetPrimitive.show = false;
expect(scene).toRender([255, 255, 255, 255]);

polygons.classificationType = ClassificationType.BOTH;
globePrimitive.show = false;
tilesetPrimitive.show = true;
expect(scene).toRender([255, 255, 255, 255]);
globePrimitive.show = true;
tilesetPrimitive.show = false;
expect(scene).toRender([255, 255, 255, 255]);

globePrimitive.show = true;
tilesetPrimitive.show = true;
});
});

it('picks polygons' + webglMessage, function() {
var rectangle = Rectangle.fromDegrees(-1.0, -1.0, 1.0, 1.0);
var polygonOptions = createPolygon(rectangle);

var batchTable = new Cesium3DTileBatchTable(mockTileset, 1);

scene.primitives.add(depthPrimitive);
scene.primitives.add(globePrimitive);

var center = ellipsoid.cartographicToCartesian(Rectangle.center(rectangle));
polygons = scene.primitives.add(new Vector3DTilePolygons(combine(polygonOptions, {