Skip to content

Commit

Permalink
Add unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
peppsac committed Jun 26, 2018
1 parent 1c0ac8b commit ab5d42e
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Process/3dTilesProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ const cameraLocalPosition = new THREE.Vector3();
const worldPosition = new THREE.Vector3();
const boundingVolumeBox = new THREE.Box3();
const boundingVolumeSphere = new THREE.Sphere();
function computeNodeSSE(camera, node) {
export function computeNodeSSE(camera, node) {
node.distance = 0;
if (node.boundingVolume.region) {
worldPosition.setFromMatrixPosition(node.boundingVolume.region.matrixWorld);
Expand Down
4 changes: 2 additions & 2 deletions src/Provider/3dTilesProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Extent from '../Core/Geographic/Extent';
import { init3dTilesLayer } from '../Process/3dTilesProcessing';
import utf8Decoder from '../utils/Utf8Decoder';

function $3dTilesIndex(tileset, baseURL) {
export function $3dTilesIndex(tileset, baseURL) {
let counter = 0;
this.index = {};
const inverseTileTransform = new THREE.Matrix4();
Expand Down Expand Up @@ -134,7 +134,7 @@ function pntsParse(data) {
return PntsParser.parse(data).then(result => ({ object3d: result.point }));
}

function configureTile(tile, layer, metadata, parent) {
export function configureTile(tile, layer, metadata, parent) {
tile.frustumCulled = false;
tile.layer = layer;

Expand Down
165 changes: 165 additions & 0 deletions test/3dtiles_unit_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/* global describe, it */
import proj4 from 'proj4';
import assert from 'assert';
import Camera from '../src/Renderer/Camera';
import { Matrix4, Object3D } from 'three';
import Coordinates from '../src/Core/Geographic/Coordinates';
import Extent from '../src/Core/Geographic/Extent';
import OBB from '../src/Renderer/ThreeExtended/OBB';
import { computeNodeSSE } from '../src/Process/3dTilesProcessing';
import { $3dTilesIndex, configureTile } from '../src/Provider/3dTilesProvider';

function tilesetWithRegion(transformMatrix) {
const tileset = {
root: {
boundingVolume: {
region: [
-0.1, -0.1,
0.1, 0.1,
0, 0],
}
}
};
if (transformMatrix) {
tileset.root.transform = transformMatrix.elements;
}
return tileset;
}

function tilesetWithBox(transformMatrix) {
const tileset = {
root: {
boundingVolume: {
box: [
0, 0, 0,
1, 0, 0,
0, 1, 0,
0, 0, 1],
}
}
};
if (transformMatrix) {
tileset.root.transform = transformMatrix.elements;
}
return tileset;
}

function tilesetWithSphere(transformMatrix) {
const tileset = {
root: {
boundingVolume: {
sphere: [0, 0, 0, 1],
}
}
};
if (transformMatrix) {
tileset.root.transform = transformMatrix.elements;
}
return tileset;
}

describe('Distance computation using boundingVolume.region', function() {
const camera = new Camera('EPSG:4978', 100, 100);
camera.camera3D.position.copy(new Coordinates('EPSG:4326', 0, 0, 10000).as('EPSG:4978').xyz());
camera.camera3D.updateMatrixWorld(true);

xit('should compute distance correctly', function() {
const tileset = tilesetWithRegion();
const tileIndex = new $3dTilesIndex(tileset, '');
const tile = new Object3D();
configureTile(tile, { }, tileIndex.index['0'])

computeNodeSSE(camera, tile);

assert.equal(tile.distance, camera.position().as('EPSG:4326').altitude());
});

xit('should not be affected by transform', function() {
const m = new Matrix4().makeTranslation(0, 0, 10).multiply(
new Matrix4().makeScale(0.01, 0.01, 0.01));
const tileset = tilesetWithRegion(m);
const tileIndex = new $3dTilesIndex(tileset, '');
const tile = new Object3D();
configureTile(tile, { }, tileIndex.index['0'])

computeNodeSSE(camera, tile);

assert.equal(tile.distance, camera.position().as('EPSG:4326').altitude());
});
});

describe('Distance computation using boundingVolume.box', function() {
proj4.defs('EPSG:3946',
'+proj=lcc +lat_1=45.25 +lat_2=46.75 +lat_0=46 +lon_0=3 +x_0=1700000 +y_0=5200000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');

const camera = new Camera('EPSG:3946', 100, 100);
camera.camera3D.position.copy(new Coordinates('EPSG:3946', 0, 0, 100).xyz());
camera.camera3D.updateMatrixWorld(true);

it('should compute distance correctly', function() {
const tileset = tilesetWithBox();
const tileIndex = new $3dTilesIndex(tileset, '');

const tile = new Object3D();
configureTile(tile, { }, tileIndex.index['0'])

computeNodeSSE(camera, tile);

assert.equal(tile.distance, 100 - 1);
});

it('should affected by transform', function() {
const m = new Matrix4().makeTranslation(0, 0, 10).multiply(
new Matrix4().makeScale(0.01, 0.01, 0.01));
const tileset = tilesetWithBox(m);

const tileIndex = new $3dTilesIndex(tileset, '');

const tile = new Object3D();
configureTile(tile, { }, tileIndex.index['0'])

tile.updateMatrixWorld(true);

computeNodeSSE(camera, tile);

assert.equal(tile.distance, 100 - 1 * 0.01 - 10);
});
});

describe('Distance computation using boundingVolume.sphere', function() {
proj4.defs('EPSG:3946',
'+proj=lcc +lat_1=45.25 +lat_2=46.75 +lat_0=46 +lon_0=3 +x_0=1700000 +y_0=5200000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');

const camera = new Camera('EPSG:3946', 100, 100);
camera.camera3D.position.copy(new Coordinates('EPSG:3946', 0, 0, 100).xyz());
camera.camera3D.updateMatrixWorld(true);

it('should compute distance correctly', function() {
const tileset = tilesetWithSphere();
const tileIndex = new $3dTilesIndex(tileset, '');

const tile = new Object3D();
configureTile(tile, { }, tileIndex.index['0'])

computeNodeSSE(camera, tile);

assert.equal(tile.distance, 100 - 1);
});

it('should affected by transform', function() {
const m = new Matrix4().makeTranslation(0, 0, 10).multiply(
new Matrix4().makeScale(0.01, 0.01, 0.01));
const tileset = tilesetWithSphere(m);

const tileIndex = new $3dTilesIndex(tileset, '');

const tile = new Object3D();
configureTile(tile, { }, tileIndex.index['0'])

tile.updateMatrixWorld(true);

computeNodeSSE(camera, tile);

assert.equal(tile.distance, 100 - 1 * 0.01 - 10);
});
});

0 comments on commit ab5d42e

Please sign in to comment.