diff --git a/src/Process/3dTilesProcessing.js b/src/Process/3dTilesProcessing.js index 44b2352db0..3bce32d607 100644 --- a/src/Process/3dTilesProcessing.js +++ b/src/Process/3dTilesProcessing.js @@ -272,7 +272,6 @@ export function process3dTilesNode(cullingTest = $3dTilesCulling, subdivisionTes return undefined; } - // do proper culling const isVisible = cullingTest ? (!cullingTest(layer, context.camera, node, node.matrixWorld)) : true; node.visible = isVisible; diff --git a/test/unit/3dtileslayerprocess.js b/test/unit/3dtileslayerprocess.js index 339c8c3ac0..a788523c75 100644 --- a/test/unit/3dtileslayerprocess.js +++ b/test/unit/3dtileslayerprocess.js @@ -1,36 +1,68 @@ import assert from 'assert'; +import fs from 'fs'; import C3DTilesLayer from 'Layer/C3DTilesLayer'; import C3DTilesSource from 'Source/C3DTilesSource'; import View from 'Core/View'; import GlobeView from 'Core/Prefab/GlobeView'; import { HttpsProxyAgent } from 'https-proxy-agent'; import Coordinates from 'Core/Geographic/Coordinates'; +import Fetcher from 'Provider/Fetcher'; +import sinon from 'sinon'; import Renderer from './bootstrap'; +import tilesetDiscretLOD from '../data/unitTest/3dTiles/tilesetDiscretLOD.json'; + +const urlDragonLow = 'https://raw.githubusercontent.com/CesiumGS/3d-tiles-samples/master/1.0/TilesetWithDiscreteLOD/dragon_low.b3dm'; +const urlDragonMedium = 'https://raw.githubusercontent.com/CesiumGS/3d-tiles-samples/master/1.0/TilesetWithDiscreteLOD/dragon_medium.b3dm'; + +const dragonLow = fs.readFileSync('./test/data/unitTest/3dTiles/dragon_low.b3dm'); +const dragonMedium = fs.readFileSync('./test/data/unitTest/3dTiles/dragon_medium.b3dm'); + +const resources = new Map([ + [urlDragonLow, dragonLow.buffer], + [urlDragonMedium, dragonMedium.buffer], +]); + describe('3Dtiles layer', function () { - const url3dTilesDiscretLOD = 'test/data/unitTest/3dTiles/tilesetDiscretLOD.json'; + let stubFetcherArrayBuf; + let context; + let viewer; + let threedTilesLayer; + + before(function () { + const stubFetcherJson = sinon.stub(Fetcher, 'json') + .callsFake(() => Promise.resolve(JSON.parse(tilesetDiscretLOD))); + + stubFetcherArrayBuf = sinon.stub(Fetcher, 'arrayBuffer') + .callsFake(url => Promise.resolve(resources.get(url))); - const renderer = new Renderer(); - const p = { coord: new Coordinates('EPSG:4326', -75.6114, 40.03428, 0), heading: 180, range: 4000, tilt: 22 }; - const viewer = new GlobeView(renderer.domElement, p, { renderer, noControls: true }); + const renderer = new Renderer(); + const p = { coord: new Coordinates('EPSG:4326', -75.6114, 40.03428, 0), heading: 180, range: 4000, tilt: 22 }; + viewer = new GlobeView(renderer.domElement, p, { renderer, noControls: true }); - const source = new C3DTilesSource({ - // url: 'https://raw.githubusercontent.com/CesiumGS/3d-tiles-samples/master/1.0/TilesetWithDiscreteLOD/tileset.json', - url: url3dTilesDiscretLOD, - networkOptions: process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {}, + const source = new C3DTilesSource({ + url: 'https://raw.githubusercontent.com/CesiumGS/3d-tiles-samples/master/1.0/TilesetWithDiscreteLOD/tileset.json', + networkOptions: process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {}, + }); + threedTilesLayer = new C3DTilesLayer('3d-tiles-discrete-lod', { + source, + sseThreshold: 0.05, + }, viewer); + + context = { + camera: viewer.camera, + engine: viewer.mainLoop.gfxEngine, + scheduler: viewer.mainLoop.scheduler, + geometryLayer: threedTilesLayer, + view: viewer, + }; + + stubFetcherJson.restore(); + }); + + after(() => { + stubFetcherArrayBuf.restore(); }); - const threedTilesLayer = new C3DTilesLayer('3d-tiles-discrete-lod', { - source, - sseThreshold: 0.05, - }, viewer); - - const context = { - camera: viewer.camera, - engine: viewer.mainLoop.gfxEngine, - scheduler: viewer.mainLoop.scheduler, - geometryLayer: threedTilesLayer, - view: viewer, - }; it('Add 3dtiles layer', function (done) { View.prototype.addLayer.call(viewer, threedTilesLayer) @@ -39,10 +71,12 @@ describe('3Dtiles layer', function () { done(); }).catch(done); }); + it('preUpdate 3dtiles layer', function () { const elements = threedTilesLayer.preUpdate(context, new Set([threedTilesLayer])); assert.equal(elements.length, 1); }); + it('update 3dtiles layer', function () { const node = threedTilesLayer.root; viewer.camera3D.updateMatrixWorld(); diff --git a/test/unit/3dtileslayerprocessbatchtable.js b/test/unit/3dtileslayerprocessbatchtable.js index a1f981a95f..e29a0fec2e 100644 --- a/test/unit/3dtileslayerprocessbatchtable.js +++ b/test/unit/3dtileslayerprocessbatchtable.js @@ -1,4 +1,5 @@ import assert from 'assert'; +import fs from 'fs'; import C3DTilesLayer from 'Layer/C3DTilesLayer'; import C3DTBatchTableHierarchyExtension from 'Core/3DTiles/C3DTBatchTableHierarchyExtension'; import C3DTilesSource from 'Source/C3DTilesSource'; @@ -8,37 +9,58 @@ import View from 'Core/View'; import GlobeView from 'Core/Prefab/GlobeView'; import { HttpsProxyAgent } from 'https-proxy-agent'; import Coordinates from 'Core/Geographic/Coordinates'; +import Fetcher from 'Provider/Fetcher'; +import sinon from 'sinon'; import Renderer from './bootstrap'; +import tilesetBatchTable from '../data/unitTest/3dTiles/tilesetBatchTable.json'; + +const tileBatchTable = fs.readFileSync('./test/data/unitTest/3dTiles/tile.b3dm'); + describe('3Dtiles batch table', function () { - const url3dTilesBatchTable = 'test/data/unitTest/3dTiles/tilesetBatchTable.json'; - - const renderer = new Renderer(); - - const p = { - coord: new Coordinates('EPSG:4326', -75.61349, 40.044259), - range: 200, - tilt: 10, - heading: -145, - }; - const viewer = new GlobeView(renderer.domElement, p, { renderer, noControls: true }); - - // Map the extension name to its manager - const extensions = new C3DTExtensions(); - extensions.registerExtension('3DTILES_batch_table_hierarchy', - { [C3DTilesTypes.batchtable]: + let stubFetcherArrayBuf; + let stubFetcherJson; + let viewer; + let threedTilesLayerBTHierarchy; + + before(function () { + stubFetcherJson = sinon.stub(Fetcher, 'json') + .callsFake(() => Promise.resolve(JSON.parse(tilesetBatchTable))); + + stubFetcherArrayBuf = sinon.stub(Fetcher, 'arrayBuffer') + .callsFake(() => Promise.resolve(tileBatchTable.buffer)); + + const renderer = new Renderer(); + + const p = { + coord: new Coordinates('EPSG:4326', -75.61349, 40.044259), + range: 200, + tilt: 10, + heading: -145, + }; + viewer = new GlobeView(renderer.domElement, p, { renderer, noControls: true }); + + // Map the extension name to its manager + const extensions = new C3DTExtensions(); + extensions.registerExtension('3DTILES_batch_table_hierarchy', + { [C3DTilesTypes.batchtable]: C3DTBatchTableHierarchyExtension }); - const source = new C3DTilesSource({ - // url: 'https://raw.githubusercontent.com/AnalyticalGraphicsInc/cesium/master/Apps/SampleData/Cesium3DTiles/Hierarchy/BatchTableHierarchy/tileset.json', - url: url3dTilesBatchTable, - networkOptions: process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {}, + const source = new C3DTilesSource({ + url: 'https://raw.githubusercontent.com/AnalyticalGraphicsInc/cesium/master/Apps/SampleData/Cesium3DTiles/Hierarchy/BatchTableHierarchy/tileset.json', + networkOptions: process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {}, + }); + threedTilesLayerBTHierarchy = new C3DTilesLayer('3d-tiles-bt-hierarchy', { + name: 'BTHierarchy', + source, + registeredExtensions: extensions, + }, viewer); + }); + + after(() => { + stubFetcherJson.restore(); + stubFetcherArrayBuf.restore(); }); - const threedTilesLayerBTHierarchy = new C3DTilesLayer('3d-tiles-bt-hierarchy', { - name: 'BTHierarchy', - source, - registeredExtensions: extensions, - }, viewer); it('Add 3dtiles layer with batch table', function (done) { View.prototype.addLayer.call(viewer, threedTilesLayerBTHierarchy)