Skip to content

Commit

Permalink
Fixed Vector3DTileGeometry tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Dec 19, 2018
1 parent 8163a79 commit 11c9755
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 44 deletions.
6 changes: 6 additions & 0 deletions Specs/Scene/Geometry3DTileContentSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ defineSuite([
globePrimitive.show = true;
tilesetPrimitive.show = false;
expect(scene).toRender(depthColor);
globePrimitive.show = true;
tilesetPrimitive.show = true;
});
});

Expand All @@ -301,6 +303,8 @@ defineSuite([
tilesetPrimitive.show = false;
verifyRender(tileset, scene);
verifyPick(scene);
globePrimitive.show = true;
tilesetPrimitive.show = true;
});
});

Expand All @@ -320,6 +324,8 @@ defineSuite([
tilesetPrimitive.show = false;
verifyRender(tileset, scene);
verifyPick(scene);
globePrimitive.show = true;
tilesetPrimitive.show = true;
});
});

Expand Down
6 changes: 6 additions & 0 deletions Specs/Scene/Vector3DTileContentSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@ defineSuite([
globePrimitive.show = true;
tilesetPrimitive.show = false;
expect(scene).toRender(depthColor);
globePrimitive.show = true;
tilesetPrimitive.show = true;
});
});

Expand All @@ -668,6 +670,8 @@ defineSuite([
tilesetPrimitive.show = false;
verifyRender(tileset, scene);
verifyPick(scene);
globePrimitive.show = true;
tilesetPrimitive.show = true;
});
});

Expand All @@ -687,6 +691,8 @@ defineSuite([
tilesetPrimitive.show = false;
verifyRender(tileset, scene);
verifyPick(scene);
globePrimitive.show = true;
tilesetPrimitive.show = true;
});
});

Expand Down
177 changes: 133 additions & 44 deletions Specs/Scene/Vector3DTileGeometrySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,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'
Expand All @@ -35,10 +38,13 @@ defineSuite([
RectangleGeometry,
Transforms,
Pass,
RenderState,
Cesium3DTileBatchTable,
ClassificationType,
ColorBlendMode,
PerInstanceColorAppearance,
Primitive,
StencilConstants,
createContext,
createScene,
pollToPromise) {
Expand All @@ -57,19 +63,14 @@ defineSuite([

var scene;
var rectangle;
var depthPrimitive;
var geometry;
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
Expand All @@ -83,61 +84,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(-80.0, 20.0, -70.0, 30.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();
geometry = geometry && !geometry.isDestroyed() && geometry.destroy();
depthPrimitive = depthPrimitive && !depthPrimitive.isDestroyed() && depthPrimitive.destroy();
});

function loadGeometries(geometries) {
Expand Down Expand Up @@ -217,7 +249,7 @@ defineSuite([
var batchTable = new Cesium3DTileBatchTable(mockTileset, 1);
batchTable.update(mockTileset, scene.frameState);

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

geometry = scene.primitives.add(new Vector3DTileGeometry(combine(geometryOptions, {
center : center,
Expand Down Expand Up @@ -249,7 +281,7 @@ defineSuite([
var batchTable = new Cesium3DTileBatchTable(mockTileset, length);
batchTable.update(mockTileset, scene.frameState);

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

geometry = scene.primitives.add(new Vector3DTileGeometry(combine(geometryOptions, {
center : center,
Expand Down Expand Up @@ -533,7 +565,7 @@ defineSuite([
var batchTable = new Cesium3DTileBatchTable(mockTileset, length);
batchTable.update(mockTileset, scene.frameState);

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

geometry = scene.primitives.add(new Vector3DTileGeometry({
boxes : boxes,
Expand Down Expand Up @@ -587,7 +619,7 @@ defineSuite([
var batchTable = new Cesium3DTileBatchTable(mockTileset, 1);
batchTable.update(mockTileset, scene.frameState);

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

geometry = scene.primitives.add(new Vector3DTileGeometry({
ellipsoids : ellipsoids,
Expand Down Expand Up @@ -620,7 +652,7 @@ defineSuite([
var batchTable = new Cesium3DTileBatchTable(mockTileset, 1);
batchTable.update(mockTileset, scene.frameState);

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

geometry = scene.primitives.add(new Vector3DTileGeometry({
ellipsoids : packEllipsoids([{
Expand Down Expand Up @@ -648,14 +680,71 @@ defineSuite([
});
});

it('renders based on classificationType' + webglMessage, function() {
var radii = new Cartesian3(100.0, 100.0, 1000.0);
var ellipsoids = packEllipsoids([{
modelMatrix : Matrix4.IDENTITY,
radii : radii
}]);
var ellipsoidBatchIds = new Uint16Array([0]);

var origin = Rectangle.center(rectangle);
var center = ellipsoid.cartographicToCartesian(origin);
var modelMatrix = Transforms.eastNorthUpToFixedFrame(center);

var bv = new BoundingSphere(center, Cartesian3.maximumComponent(radii));

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

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

geometry = scene.primitives.add(new Vector3DTileGeometry({
ellipsoids : ellipsoids,
ellipsoidBatchIds : ellipsoidBatchIds,
boundingVolume : bv,
center : center,
modelMatrix : modelMatrix,
batchTable : batchTable
}));
return loadGeometries(geometry).then(function() {
scene.camera.lookAtTransform(modelMatrix, new Cartesian3(0.0, 0.0, 1.0));

geometry.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]);

geometry.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]);

geometry.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]);
});
});

it('picks geometry' + webglMessage, function() {
var origin = Rectangle.center(rectangle);
var center = ellipsoid.cartographicToCartesian(origin);
var modelMatrix = Transforms.eastNorthUpToFixedFrame(center);

var batchTable = new Cesium3DTileBatchTable(mockTileset, 1);

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

geometry = scene.primitives.add(new Vector3DTileGeometry({
ellipsoids : packEllipsoids([{
Expand Down

0 comments on commit 11c9755

Please sign in to comment.