Skip to content

Commit

Permalink
tests(MaterialLayer): update tests with the MaterialLayer refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchoqueux committed Feb 16, 2021
1 parent c73fc38 commit 0fa3c06
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 14 deletions.
9 changes: 5 additions & 4 deletions test/unit/dataSourceProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import GeometryLayer from 'Layer/GeometryLayer';
import PlanarLayer from 'Core/Prefab/Planar/PlanarLayer';
import Feature2Mesh from 'Converter/Feature2Mesh';
import LayeredMaterial from 'Renderer/LayeredMaterial';
import { EMPTY_TEXTURE_ZOOM } from 'Renderer/MaterialLayer';
import { EMPTY_TEXTURE_ZOOM } from 'Renderer/RasterTile';

const holes = require('../data/geojson/holesPoints.geojson.json');

Expand Down Expand Up @@ -62,8 +62,9 @@ describe('Provide in Sources', function () {
planarlayer.attach(colorlayer);
planarlayer.attach(elevationlayer);

material.addLayer(colorlayer);
material.addLayer(elevationlayer);
const fakeNode = { material, setBBoxZ: () => {} };
colorlayer.setupRasterNode(fakeNode);
elevationlayer.setupRasterNode(fakeNode);

const nodeLayer = material.getLayer(colorlayer.id);
const nodeLayerElevation = material.getLayer(elevationlayer.id);
Expand Down Expand Up @@ -292,7 +293,7 @@ describe('Provide in Sources', function () {
});
});

it('should get updated MaterialLayer', (done) => {
it('should get updated RasterLayer', (done) => {
colorlayer.source = new WMTSSource({
url: 'http://',
name: 'name',
Expand Down
6 changes: 3 additions & 3 deletions test/unit/demutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import TileMesh from 'Core/TileMesh';
import OBB from 'Renderer/OBB';
import LayerUpdateState from 'Layer/LayerUpdateState';
import DEMUtils from 'Utils/DEMUtils';
import MaterialLayer from 'Renderer/MaterialLayer';
import { RasterElevationTile } from 'Renderer/RasterTile';
import Renderer from './bootstrap';

describe('DemUtils', function () {
Expand Down Expand Up @@ -58,8 +58,8 @@ describe('DemUtils', function () {
it('load elevation texture', (done) => {
const geom = new THREE.BufferGeometry();
geom.OBB = new OBB(new THREE.Vector3(), new THREE.Vector3(1, 1, 1));
const material = { visible: true };
const nodeLayer = new MaterialLayer(material, elevationlayer);
const material = new THREE.Material();
const nodeLayer = new RasterElevationTile(material, elevationlayer);
material.getElevationLayer = () => nodeLayer;
const tile = new TileMesh(geom, material, viewer.tileLayer, extent, 5);
tile.layerUpdateState[elevationlayer.id] = new LayerUpdateState();
Expand Down
6 changes: 3 additions & 3 deletions test/unit/layeredmaterialnodeprocessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import OBB from 'Renderer/OBB';
import Layer from 'Layer/Layer';
import Source from 'Source/Source';
import { STRATEGY_MIN_NETWORK_TRAFFIC } from 'Layer/LayerUpdateStrategy';
import MaterialLayer from 'Renderer/MaterialLayer';
import { RasterColorTile } from 'Renderer/RasterTile';

describe('updateLayeredMaterialNodeImagery', function () {
// Misc var to initialize a TileMesh instance
const geom = new THREE.BufferGeometry();
geom.OBB = new OBB(new THREE.Vector3(), new THREE.Vector3(1, 1, 1));
const extent = new Extent('EPSG:4326', 0, 11.25, 0, 11.25);
const material = {};
const material = new THREE.Material();

// Mock scheduler
const context = {
Expand Down Expand Up @@ -51,7 +51,7 @@ describe('updateLayeredMaterialNodeImagery', function () {
},
});

const nodeLayer = new MaterialLayer(material, layer);
const nodeLayer = new RasterColorTile(material, layer);
material.getLayer = () => nodeLayer;

beforeEach('reset state', function () {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/layerupdatestrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Layer from 'Layer/Layer';
import Source from 'Source/Source';
import { STRATEGY_DICHOTOMY, STRATEGY_PROGRESSIVE, STRATEGY_GROUP, chooseNextLevelToFetch } from 'Layer/LayerUpdateStrategy';
import LayerUpdateState from 'Layer/LayerUpdateState';
import MaterialLayer from 'Renderer/MaterialLayer';
import { RasterColorTile } from 'Renderer/RasterTile';

describe('Handling no data source error', function () {
// Misc var to initialize a TileMesh instance
Expand All @@ -16,7 +16,7 @@ describe('Handling no data source error', function () {

const extent = new Extent('EPSG:4326', 6.227531433105469, 6.227874755859375, 44.93614196777344, 44.936485290527344);
extent.zoom = 19;
const material = {};
const material = new THREE.Material();

// Mock scheduler
const context = {
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('Handling no data source error', function () {
},
});

const nodeLayer = new MaterialLayer(material, layer);
const nodeLayer = new RasterColorTile(material, layer);
nodeLayer.level = 10;

const node = new TileMesh(geom, material, layer, extent, 19);
Expand Down
82 changes: 81 additions & 1 deletion test/unit/tilemesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import assert from 'assert';
import TileMesh from 'Core/TileMesh';
// import PlanarView from 'Core/Prefab/PlanarView';
import PlanarLayer from 'Core/Prefab/Planar/PlanarLayer';
import { globalExtentTMS } from 'Core/Geographic/Extent';
import Extent, { globalExtentTMS } from 'Core/Geographic/Extent';
import TileProvider from 'Provider/TileProvider';
import newTileGeometry from 'Core/Prefab/TileBuilder';
import OBB from 'Renderer/OBB';
import ElevationLayer from 'Layer/ElevationLayer';
import Source from 'Source/Source';

// It is relatively long to create TileMesh on the go (in term of code), so we
// emulate a fake one with the necessary informations in it.
Expand All @@ -19,6 +22,10 @@ FakeTileMesh.prototype.constructor = FakeTileMesh;
FakeTileMesh.prototype.findCommonAncestor = TileMesh.prototype.findCommonAncestor;

describe('TileMesh', function () {
const extent = new Extent('TMS:3857', 5, 10, 10);
const geom = new THREE.BufferGeometry();
geom.OBB = new OBB();

const tree = [
[new FakeTileMesh(0)],
];
Expand Down Expand Up @@ -150,4 +157,77 @@ describe('TileMesh', function () {
done();
});
});

it('throw error if there\'s not extent in constructor', () => {
assert.doesNotThrow(() => {
// eslint-disable-next-line no-unused-vars
const tileMesh = new TileMesh(geom, new THREE.Material(), planarlayer, extent.as('EPSG:3857'), 0);
});
assert.throws(() => {
// eslint-disable-next-line no-unused-vars
const tileMesh = new TileMesh(geom, new THREE.Material(), planarlayer);
});
});

// eslint-disable-next-line no-unused-vars
const elevationLayer = new ElevationLayer('elevation', { crs: 'EPSG:3857', source: new Source({ url: 'node' }) });
elevationLayer.parent = planarlayer;

const material = new THREE.Material();
material.addLayer = () => {};
material.setSequenceElevation = () => {};

it('event updatedElevation RasterElevationTile sets TileMesh bounding box ', () => {
const tileMesh = new TileMesh(geom, material, planarlayer, extent.as('EPSG:3857'), 0);
const rasterNode = elevationLayer.setupRasterNode(tileMesh);
const min = 50;
const max = 500;
rasterNode.min = min;
rasterNode.max = max;
rasterNode.dispatchEvent({ type: 'updatedElevation', node: rasterNode });
assert.equal(tileMesh.obb.z.min, min);
assert.equal(tileMesh.obb.z.max, max);

rasterNode.min = null;
rasterNode.max = null;
rasterNode.dispatchEvent({ type: 'updatedElevation', node: rasterNode });
assert.equal(tileMesh.obb.z.min, min);
assert.equal(tileMesh.obb.z.max, max);
});

it('RasterElevationTile throws error if ElevationLayer.useRgbaTextureElevation is true', () => {
elevationLayer.useRgbaTextureElevation = true;
const tileMesh = new TileMesh(geom, material, planarlayer, extent.as('EPSG:3857'), 0);
assert.throws(() => {
elevationLayer.setupRasterNode(tileMesh);
});
});


it('RasterElevationTile is set if ElevationLayer.useColorTextureElevation is true', () => {
delete elevationLayer.useRgbaTextureElevation;
elevationLayer.useColorTextureElevation = true;
elevationLayer.colorTextureElevationMinZ = 10;
elevationLayer.colorTextureElevationMaxZ = 100;
const tileMesh = new TileMesh(geom, material, planarlayer, extent.as('EPSG:3857'), 0);
const rasterNode = elevationLayer.setupRasterNode(tileMesh);
assert.equal(rasterNode.min, elevationLayer.colorTextureElevationMinZ);
assert.equal(rasterNode.max, elevationLayer.colorTextureElevationMaxZ);
});

it('RasterElevationTile min and max are set by xbil texture', () => {
delete elevationLayer.useColorTextureElevation;
const tileMesh = new TileMesh(geom, material, planarlayer, extent.as('EPSG:3857'), 0);
const rasterNode = elevationLayer.setupRasterNode(tileMesh);
const texture = new THREE.Texture();
texture.extent = new Extent('TMS:3857', 4, 10, 10);
texture.image = {
width: 3,
height: 3,
data: [14.5, 10, 8, 2.3, 10, 14.5, 8, 2.301, 2.3],
};
rasterNode.setTextures([texture], [new THREE.Vector3(0, 0, 1)]);
assert.equal(rasterNode.min, 2.3);
assert.equal(rasterNode.max, 14.5);
});
});

0 comments on commit 0fa3c06

Please # to comment.