Skip to content

Commit

Permalink
refactor(core): Homogenize all providers as static
Browse files Browse the repository at this point in the history
There is no reason to keep an instance of each provider, and moving them
to static like some other one (PointCloudProvider for example) do no
harm, but homogenize all providers to one structure.

Also note that there are two required functions in a provider:
preprocessDataLayer and executeCommand, that are verified when adding a
provider, in the scheduler.

BREAKING CHANGE: KML_Provider and BuildingBox_Provider have been
removed, as well as getPointOrder from WFS_Provider.
  • Loading branch information
zarov committed Feb 27, 2018
1 parent 84f45ca commit 73f1aac
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 1,073 deletions.
50 changes: 20 additions & 30 deletions src/Core/Scheduler/Providers/3dTiles_Provider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as THREE from 'three';
import Provider from './Provider';
import B3dmLoader from '../../../Renderer/ThreeExtended/B3dmLoader';
import PntsLoader from '../../../Renderer/ThreeExtended/PntsLoader';
import Fetcher from './Fetcher';
Expand All @@ -10,7 +9,6 @@ import Capabilities from '../../System/Capabilities';
import PrecisionQualifier from '../../../Renderer/Shader/Chunk/PrecisionQualifier.glsl';
import { init3dTilesLayer } from '../../../Process/3dTilesProcessing';


function $3dTilesIndex(tileset, baseURL) {
let counter = 0;
this.index = {};
Expand Down Expand Up @@ -63,19 +61,7 @@ function $3dTilesIndex(tileset, baseURL) {
};
}

function $3dTiles_Provider() {
Provider.call(this);
}

$3dTiles_Provider.prototype = Object.create(Provider.prototype);

$3dTiles_Provider.prototype.constructor = $3dTiles_Provider;

$3dTiles_Provider.prototype.removeLayer = function removeLayer() {

};

$3dTiles_Provider.prototype.preprocessDataLayer = function preprocessDataLayer(layer, view, scheduler) {
function preprocessDataLayer(layer, view, scheduler) {
layer.sseThreshold = layer.sseThreshold || 16;
layer.cleanupDelay = layer.cleanupDelay || 1000;

Expand All @@ -87,7 +73,7 @@ $3dTiles_Provider.prototype.preprocessDataLayer = function preprocessDataLayer(l
layer.asset = tileset.asset;
return init3dTilesLayer(view, scheduler, layer, tileset.root);
});
};
}

function getBox(volume, inverseTileTransform) {
if (volume.region) {
Expand Down Expand Up @@ -159,9 +145,11 @@ export function patchMaterialForLogDepthSupport(material) {
};
}

$3dTiles_Provider.prototype.b3dmToMesh = function b3dmToMesh(data, layer, url) {
this._b3dmLoader = this._b3dmLoader || new B3dmLoader();
return this._b3dmLoader.parse(data, layer.asset.gltfUpAxis, url, this._textDecoder).then((result) => {
let b3dmLoader;
let textDecoder;
function b3dmToMesh(data, layer, url) {
b3dmLoader = b3dmLoader || new B3dmLoader();
return b3dmLoader.parse(data, layer.asset.gltfUpAxis, url, textDecoder).then((result) => {
const init = function f_init(mesh) {
mesh.frustumCulled = false;
if (mesh.material) {
Expand Down Expand Up @@ -189,13 +177,13 @@ $3dTiles_Provider.prototype.b3dmToMesh = function b3dmToMesh(data, layer, url) {
const object3d = result.gltf.scene;
return { batchTable, object3d };
});
};
}

$3dTiles_Provider.prototype.pntsParse = function pntsParse(data) {
function pntsParse(data) {
return new Promise((resolve) => {
resolve({ object3d: PntsLoader.parse(data, this._textDecoder).point });
resolve({ object3d: PntsLoader.parse(data, textDecoder).point });
});
};
}

function configureTile(tile, layer, metadata, parent) {
tile.frustumCulled = false;
Expand All @@ -220,14 +208,13 @@ function configureTile(tile, layer, metadata, parent) {
tile.updateMatrixWorld();
}

$3dTiles_Provider.prototype.executeCommand = function executeCommand(command) {
function executeCommand(command) {
const layer = command.layer;
const metadata = command.metadata;
const tile = new THREE.Object3D();
configureTile(tile, layer, metadata, command.requester);
const path = metadata.content ? metadata.content.url : undefined;
this._textDecoder = this._textDecoder || new TextDecoder('utf-8');
const textDecoder = this._textDecoder;
textDecoder = textDecoder || new TextDecoder('utf-8');

const setLayer = (obj) => {
obj.layers.set(layer.threejsLayer);
Expand All @@ -236,8 +223,8 @@ $3dTiles_Provider.prototype.executeCommand = function executeCommand(command) {
// Check if we have relative or absolute url (with tileset's lopocs for example)
const url = path.startsWith('http') ? path : metadata.baseURL + path;
const supportedFormats = {
b3dm: this.b3dmToMesh.bind(this),
pnts: this.pntsParse.bind(this),
b3dm: b3dmToMesh,
pnts: pntsParse,
};
return Fetcher.arrayBuffer(url, layer.networkOptions).then((result) => {
if (result !== undefined) {
Expand Down Expand Up @@ -276,6 +263,9 @@ $3dTiles_Provider.prototype.executeCommand = function executeCommand(command) {
resolve(tile);
});
}
};
}

export default $3dTiles_Provider;
export default {
preprocessDataLayer,
executeCommand,
};
211 changes: 0 additions & 211 deletions src/Core/Scheduler/Providers/BuildingBox_Provider.js

This file was deleted.

Loading

0 comments on commit 73f1aac

Please sign in to comment.