Skip to content
/ itowns Public
forked from iTowns/itowns

Commit

Permalink
refactor: move geometric layers off views
Browse files Browse the repository at this point in the history
Move all contents of `createXXXLayer` in XXXView to XXXLayer in
Prefab/XXX/. This declutters the XXXView files. This change applies for
Globe, Planar and Panorama.

In the same time, GeometryLayer has been extract from Layer and given
some new methods which were repeated through each View.
  • Loading branch information
zarov committed Jul 17, 2018
1 parent 5319066 commit 3af73b0
Show file tree
Hide file tree
Showing 27 changed files with 718 additions and 704 deletions.
10 changes: 4 additions & 6 deletions examples/3dtiles.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@

// Create a new Layer 3d-tiles For DiscreteLOD
// -------------------------------------------
var $3dTilesLayerDiscreteLOD = new itowns.GeometryLayer('3d-tiles-discrete-lod', new itowns.THREE.Group());
var $3dTilesLayerDiscreteLOD = new itowns.GeometryLayer({ id:
'3d-tiles-discrete-lod' }, new itowns.THREE.Group());

$3dTilesLayerDiscreteLOD.preUpdate = preUpdateGeo;
$3dTilesLayerDiscreteLOD.update = itowns.process3dTilesNode(
Expand All @@ -46,15 +47,14 @@
$3dTilesLayerDiscreteLOD.url = 'https://raw.githubusercontent.com/AnalyticalGraphicsInc/3d-tiles-samples/master/tilesets/TilesetWithDiscreteLOD/tileset.json';
$3dTilesLayerDiscreteLOD.protocol = '3d-tiles'
$3dTilesLayerDiscreteLOD.overrideMaterials = true; // custom cesium shaders are not functional
$3dTilesLayerDiscreteLOD.type = 'geometry';
$3dTilesLayerDiscreteLOD.visible = true;

itowns.View.prototype.addLayer.call(view, $3dTilesLayerDiscreteLOD);

// Create a new Layer 3d-tiles For Viewer Request Volume
// -----------------------------------------------------

var $3dTilesLayerRequestVolume = new itowns.GeometryLayer('3d-tiles-request-volume', new itowns.THREE.Group());
var $3dTilesLayerRequestVolume = new itowns.GeometryLayer({ id:
'3d-tiles-request-volume' }, new itowns.THREE.Group());

$3dTilesLayerRequestVolume.preUpdate = preUpdateGeo;
$3dTilesLayerRequestVolume.update = itowns.process3dTilesNode(
Expand All @@ -66,8 +66,6 @@
$3dTilesLayerRequestVolume.url = 'https://raw.githubusercontent.com/AnalyticalGraphicsInc/3d-tiles-samples/master/tilesets/TilesetWithRequestVolume/tileset.json';
$3dTilesLayerRequestVolume.protocol = '3d-tiles'
$3dTilesLayerRequestVolume.overrideMaterials = true; // custom cesium shaders are not functional
$3dTilesLayerRequestVolume.type = 'geometry';
$3dTilesLayerRequestVolume.visible = true;
$3dTilesLayerRequestVolume.sseThreshold = 1;
// add an event for have information when you move your mouse on a building
itowns.View.prototype.addLayer.call(view, $3dTilesLayerRequestVolume).then(function _() { window.addEventListener('mousemove', picking, false); })
Expand Down
197 changes: 0 additions & 197 deletions src/Core/Layer/Layer.js

This file was deleted.

9 changes: 5 additions & 4 deletions src/Core/MainLoop.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { EventDispatcher } from 'three';
import { GeometryLayer, Layer } from './Layer/Layer';
import Layer from '../Layer/Layer';
import GeometryLayer from '../Layer/GeometryLayer';
import Cache from '../Core/Scheduler/Cache';

export const RENDERING_PAUSED = 0;
Expand Down Expand Up @@ -77,7 +78,7 @@ function updateElements(context, geometryLayer, elements) {
}
}
// update attached layers
for (const attachedLayer of geometryLayer._attachedLayers) {
for (const attachedLayer of geometryLayer.attachedLayers) {
if (attachedLayer.ready) {
attachedLayer.update(context, attachedLayer, sub.element, sub.parent);
}
Expand All @@ -90,7 +91,7 @@ function updateElements(context, geometryLayer, elements) {
Must be a THREE.Object and have a THREE.Material`);
}
// update attached layers
for (const attachedLayer of geometryLayer._attachedLayers) {
for (const attachedLayer of geometryLayer.attachedLayers) {
if (attachedLayer.ready) {
attachedLayer.update(context, attachedLayer, sub.elements[i], sub.parent);
}
Expand Down Expand Up @@ -143,7 +144,7 @@ MainLoop.prototype._update = function _update(view, updateSources, dt) {
const srcs = filterChangeSources(updateSources, geometryLayer);
if (srcs.size > 0) {
// `preUpdate` returns an array of elements to update
const elementsToUpdate = geometryLayer.preUpdate(context, geometryLayer, srcs);
const elementsToUpdate = geometryLayer.preUpdate(context, srcs);
// `update` is called in `updateElements`.
updateElements(context, geometryLayer, elementsToUpdate);
// `postUpdate` is called when this geom layer update process is finished
Expand Down
61 changes: 61 additions & 0 deletions src/Core/Prefab/Globe/GlobeLayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import * as THREE from 'three';

import TiledGeometryLayer from '../../../Layer/TiledGeometryLayer';

import { processTiledGeometryNode } from '../../../Process/TiledNodeProcessing';
import { globeCulling, preGlobeUpdate, globeSubdivisionControl, globeSchemeTileWMTS, globeSchemeTile1 } from '../../../Process/GlobeTileProcessing';
import BuilderEllipsoidTile from './BuilderEllipsoidTile';
import Picking from '../../Picking';

class GlobeLayer extends TiledGeometryLayer {
/**
* A geometry layer to be used only with a {@link GlobeView}.
*
* @constructor
*
* @param {Object} config
* @param {THREE.Object3D} config.object3d
* @param {number} [config.maxSubdivisionLevel=18]
* @param {number} [config.sseSubdivisionThreshold=1]
* @param {number} [config.maxDeltaElevationLevel=4]
*/
constructor(config) {
super(config, config.object3d || new THREE.Group());

// Configure tiles
this.schemeTile = globeSchemeTileWMTS(globeSchemeTile1);
this.extent = this.schemeTile[0].clone();
for (let i = 1; i < this.schemeTile.length; i++) {
this.extent.union(this.schemeTile[i]);
}

function subdivision(context, layer, node) {
if (TiledGeometryLayer.hasEnoughTexturesToSubdivide(context, node)) {
return globeSubdivisionControl(2,
config.maxSubdivisionLevel || 18,
config.sseSubdivisionThreshold || 1.0,
config.maxDeltaElevationLevel || 4)(context, layer, node);
}
return false;
}

this.update = processTiledGeometryNode(globeCulling(2), subdivision);
this.builder = new BuilderEllipsoidTile();
}

pickObjectsAt(view, mouse, radius = 5) {
return Picking.pickTilesAt(view, mouse, radius, this);
}

preUpdate(context, changeSources) {
if (__DEBUG__) {
this._latestUpdateStartingLevel = 0;
}

preGlobeUpdate(context, this);

return super.preUpdate(context, changeSources);
}
}

export default GlobeLayer;
Loading

0 comments on commit 3af73b0

Please sign in to comment.