Skip to content

Commit

Permalink
refactor(Layer): remove Object.assign of config
Browse files Browse the repository at this point in the history
  • Loading branch information
Desplandis committed Jul 22, 2024
1 parent e6bc462 commit ca64d3d
Show file tree
Hide file tree
Showing 20 changed files with 448 additions and 155 deletions.
5 changes: 3 additions & 2 deletions src/Core/Prefab/Globe/Atmosphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const spaceColor = new THREE.Color(0x030508);
const limitAlti = 600000;
const mfogDistance = ellipsoidSizes.x * 160.0;


/**
* @extends GeometryLayer
*/
class Atmosphere extends GeometryLayer {
/**
* It's layer to simulate Globe atmosphere.
Expand All @@ -40,7 +42,6 @@ class Atmosphere extends GeometryLayer {
* * [Accurate Atmospheric Scattering (NVIDIA GPU Gems 2)]{@link https://developer.nvidia.com/gpugems/gpugems2/part-ii-shading-lighting-and-shadows/chapter-16-accurate-atmospheric-scattering}.
*
* @constructor
* @extends GeometryLayer
*
* @param {string} id - The id of the layer Atmosphere.
* @param {Object} [options] - options layer.
Expand Down
27 changes: 19 additions & 8 deletions src/Core/Prefab/Globe/GlobeLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@ const scaledHorizonCullingPoint = new THREE.Vector3();
* @property {boolean} isGlobeLayer - Used to checkout whether this layer is a
* GlobeLayer. Default is true. You should not change this, as it is used
* internally for optimisation.
*
* @extends TiledGeometryLayer
*/
class GlobeLayer extends TiledGeometryLayer {
/**
* A {@link TiledGeometryLayer} to use with a {@link GlobeView}. It has
* specific method for updating and subdivising its grid.
*
* @constructor
* @extends TiledGeometryLayer
*
* @param {string} id - The id of the layer, that should be unique. It is
* not mandatory, but an error will be emitted if this layer is added a
* {@link View} that already has a layer going by that id.
* @param {THREE.Object3d} [object3d=THREE.Group] - The object3d used to
* @param {THREE.Object3D} [object3d=THREE.Group] - The object3d used to
* contain the geometry of the TiledGeometryLayer. It is usually a
* `THREE.Group`, but it can be anything inheriting from a `THREE.Object3d`.
* @param {Object} [config] - Optional configuration, all elements in it
Expand All @@ -50,25 +51,35 @@ class GlobeLayer extends TiledGeometryLayer {
* @throws {Error} `object3d` must be a valid `THREE.Object3d`.
*/
constructor(id, object3d, config = {}) {
const {
minSubdivisionLevel = 2,
maxSubdivisionLevel = 19,
maxDeltaElevationLevel = 4.0,
...tiledConfig
} = config;

// Configure tiles
const scheme = schemeTiles.get(CRS.tms_4326);
const schemeTile = globalExtentTMS.get('EPSG:4326').subdivisionByScheme(scheme);

// Supported tile matrix set for color/elevation layer
config.tileMatrixSets = [
const tileMatrixSets = [
CRS.tms_4326,
CRS.tms_3857,
];
const uvCount = config.tileMatrixSets.length;
const uvCount = tileMatrixSets.length;
const builder = new BuilderEllipsoidTile({ crs: 'EPSG:4978', uvCount });

super(id, object3d || new THREE.Group(), schemeTile, builder, config);
super(id, object3d || new THREE.Group(), schemeTile, builder, {
tileMatrixSets,
...tiledConfig,
});

this.isGlobeLayer = true;
this.options.defaultPickingRadius = 5;
this.minSubdivisionLevel = this.minSubdivisionLevel == undefined ? 2 : this.minSubdivisionLevel;
this.maxSubdivisionLevel = this.maxSubdivisionLevel == undefined ? 19 : this.maxSubdivisionLevel;
this.maxDeltaElevationLevel = this.maxDeltaElevationLevel || 4.0;
this.minSubdivisionLevel = minSubdivisionLevel;
this.maxSubdivisionLevel = maxSubdivisionLevel;
this.maxDeltaElevationLevel = maxDeltaElevationLevel;

this.extent = this.schemeTile[0].clone();

Expand Down
23 changes: 17 additions & 6 deletions src/Core/Prefab/Planar/PlanarLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import PlanarTileBuilder from './PlanarTileBuilder';
* @property {boolean} isPlanarLayer - Used to checkout whether this layer is a
* PlanarLayer. Default is true. You should not change this, as it is used
* internally for optimisation.
* @extends TiledGeometryLayer
*/
class PlanarLayer extends TiledGeometryLayer {
/**
* A {@link TiledGeometryLayer} to use with a {@link PlanarView}. It has
* specific method for updating and subdivising its grid.
*
* @constructor
* @extends TiledGeometryLayer
*
* @param {string} id - The id of the layer, that should be unique. It is
* not mandatory, but an error will be emitted if this layer is added a
Expand All @@ -38,19 +38,30 @@ class PlanarLayer extends TiledGeometryLayer {
* @throws {Error} `object3d` must be a valid `THREE.Object3d`.
*/
constructor(id, extent, object3d, config = {}) {
const {
minSubdivisionLevel = 0,
maxSubdivisionLevel = 5,
maxDeltaElevationLevel = 4.0,
...tiledConfig
} = config;

const tms = CRS.formatToTms(extent.crs);
const tileMatrixSets = [tms];
if (!globalExtentTMS.get(extent.crs)) {
// Add new global extent for this new crs projection.
globalExtentTMS.set(extent.crs, extent);
}
config.tileMatrixSets = tileMatrixSets;
super(id, object3d || new THREE.Group(), [extent], new PlanarTileBuilder({ crs: extent.crs }), config);

const builder = new PlanarTileBuilder({ crs: extent.crs });
super(id, object3d || new THREE.Group(), [extent], builder, {
tileMatrixSets,
...tiledConfig,
});
this.isPlanarLayer = true;
this.extent = extent;
this.minSubdivisionLevel = this.minSubdivisionLevel == undefined ? 0 : this.minSubdivisionLevel;
this.maxSubdivisionLevel = this.maxSubdivisionLevel == undefined ? 5 : this.maxSubdivisionLevel;
this.maxDeltaElevationLevel = this.maxDeltaElevationLevel || 4.0;
this.minSubdivisionLevel = minSubdivisionLevel;
this.maxSubdivisionLevel = maxSubdivisionLevel;
this.maxDeltaElevationLevel = maxDeltaElevationLevel;
}
}

Expand Down
28 changes: 21 additions & 7 deletions src/Layer/ColorLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import { deprecatedColorLayerOptions } from 'Core/Deprecated/Undeprecator';
* * `1`: used to amplify the transparency effect.
* * `2`: unused.
* * `3`: could be used by your own glsl code.
*
* @extends RasterLayer
*/
class ColorLayer extends RasterLayer {
/**
Expand All @@ -52,7 +54,6 @@ class ColorLayer extends RasterLayer {
* roads displayed.
*
* @constructor
* @extends Layer
*
* @param {string} id - The id of the layer, that should be unique. It is
* not mandatory, but an error will be emitted if this layer is added a
Expand All @@ -65,13 +66,13 @@ class ColorLayer extends RasterLayer {
* @param {Source} [config.source] - Description and options of the source.
* @param {number} [config.magFilter] - How the texture is sampled when a texel covers more than one pixel. [see](https://threejs.org/docs/?q=texture#api/en/textures/Texture.magFilter)
* @param {number} [config.minFilter] - How the texture is sampled when a texel covers less than one pixel. [see](https://threejs.org/docs/?q=texture#api/en/textures/Texture.minFilter)
* @param {number} [effect_type=0] - type effect to apply on raster color.
* @param {number} [config.effect_type=0] - type effect to apply on raster color.
* if `effect_type` equals:
* * `0`: no special effect.
* * `1`: light color to invisible effect.
* * `2`: white color to invisible effect.
* * `3`: custom shader effect (defined `ShaderChunk.customBodyColorLayer` and `ShaderChunk.customHeaderColorLayer`).
* @param {number} [effect_parameter=1.0] - amount value used with effect applied on raster color.
* @param {number} [config.effect_parameter=1.0] - amount value used with effect applied on raster color.
*
* @example
* // Create a ColorLayer
Expand All @@ -92,16 +93,29 @@ class ColorLayer extends RasterLayer {
*/
constructor(id, config = {}) {
deprecatedColorLayerOptions(config);
super(id, config);

const {
effect_type = 0,
effect_parameter = 1.0,
transparent,
...rasterConfig
} = config;

super(id, rasterConfig);

/**
* @type {boolean}
* @readonly
*/
this.isColorLayer = true;
this.defineLayerProperty('visible', true);
this.defineLayerProperty('opacity', 1.0);
this.defineLayerProperty('sequence', 0);
this.transparent = config.transparent || (this.opacity < 1.0);
this.transparent = transparent || (this.opacity < 1.0);
this.noTextureParentOutsideLimit = config.source ? config.source.isFileSource : false;

this.effect_type = config.effect_type ?? 0;
this.effect_parameter = config.effect_parameter ?? 1.0;
this.effect_type = effect_type;
this.effect_parameter = effect_parameter;

// Feature options
this.buildExtent = true;
Expand Down
5 changes: 5 additions & 0 deletions src/Layer/CopcLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class CopcLayer extends PointCloudLayer {
*/
constructor(id, config) {
super(id, config);

/**
* @type {boolean}
* @readonly
*/
this.isCopcLayer = true;

const resolve = () => this;
Expand Down
51 changes: 45 additions & 6 deletions src/Layer/ElevationLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ import { RasterElevationTile } from 'Renderer/RasterTile';
* ```
* @property {number} colorTextureElevationMinZ - elevation minimum in `useColorTextureElevation` mode.
* @property {number} colorTextureElevationMaxZ - elevation maximum in `useColorTextureElevation` mode.
*
* @extends RasterLayer
*/
class ElevationLayer extends RasterLayer {
/**
* A simple layer, managing an elevation texture to add some reliefs on the
* plane or globe view for example.
*
* @constructor
* @extends Layer
*
* @param {string} id - The id of the layer, that should be unique. It is
* not mandatory, but an error will be emitted if this layer is added a
Expand Down Expand Up @@ -60,14 +61,52 @@ class ElevationLayer extends RasterLayer {
* view.addLayer(elevation);
*/
constructor(id, config = {}) {
super(id, config);
const {
scale = 1.0,
noDataValue,
clampValues,
useRgbaTextureElevation,
useColorTextureElevation,
colorTextureElevationMinZ,
colorTextureElevationMaxZ,
bias,
mode,
...rasterConfig
} = config;

super(id, rasterConfig);

/**
* @type {boolean}
* @readonly
*/
this.isElevationLayer = true;

this.noDataValue = noDataValue;

if (config.zmin || config.zmax) {
console.warn('Config using zmin and zmax are deprecated, use {clampValues: {min, max}} structure.');
}
this.zmin = config.clampValues?.min ?? config.zmin;
this.zmax = config.clampValues?.max ?? config.zmax;
this.isElevationLayer = true;
this.defineLayerProperty('scale', this.scale || 1.0);

/**
* @type {number | undefined}
*/
this.zmin = clampValues?.min ?? config.zmin;

/**
* @type {number | undefined}
*/
this.zmax = clampValues?.max ?? config.zmax;

this.defineLayerProperty('scale', scale);

this.useRgbaTextureElevation = useRgbaTextureElevation;
this.useColorTextureElevation = useColorTextureElevation;
this.colorTextureElevationMinZ = colorTextureElevationMinZ;
this.colorTextureElevationMaxZ = colorTextureElevationMaxZ;

this.bias = bias;
this.mode = mode;
}

/**
Expand Down
16 changes: 12 additions & 4 deletions src/Layer/EntwinePointTileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ bboxMesh.geometry.boundingBox = box3;
* @property {boolean} isEntwinePointTileLayer - Used to checkout whether this
* layer is a EntwinePointTileLayer. Default is `true`. You should not change
* this, as it is used internally for optimisation.
*
* @extends PointCloudLayer
*/
class EntwinePointTileLayer extends PointCloudLayer {
/**
* Constructs a new instance of Entwine Point Tile layer.
*
* @constructor
* @extends PointCloudLayer
*
* @example
* // Create a new point cloud layer
Expand All @@ -38,15 +39,22 @@ class EntwinePointTileLayer extends PointCloudLayer {
* contains three elements `name, protocol, extent`, these elements will be
* available using `layer.name` or something else depending on the property
* name. See the list of properties to know which one can be specified.
* @param {string} [config.crs=ESPG:4326] - The CRS of the {@link View} this
* @param {string} [config.crs='ESPG:4326'] - The CRS of the {@link View} this
* layer will be attached to. This is used to determine the extent of this
* layer. Default to `EPSG:4326`.
* @param {number} [config.skip=1] - Read one point from every `skip` points
* - see {@link LASParser}.
*/
constructor(id, config) {
super(id, config);

/**
* @type {boolean}
* @readonly
*/
this.isEntwinePointTileLayer = true;

/**
* @type {THREE.Vector3}
*/
this.scale = new THREE.Vector3(1, 1, 1);

const resolve = this.addInitializationStep();
Expand Down
24 changes: 18 additions & 6 deletions src/Layer/FeatureGeometryLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import Feature2Mesh from 'Converter/Feature2Mesh';
* @property {boolean} isFeatureGeometryLayer - Used to checkout whether this layer is
* a FeatureGeometryLayer. Default is true. You should not change this, as it is used
* internally for optimisation.
*
* @extends GeometryLayer
*/
class FeatureGeometryLayer extends GeometryLayer {
/**
* @constructor
* @extends GeometryLayer
*
* @param {string} id - The id of the layer, that should be unique. It is
* not mandatory, but an error will be emitted if this layer is added a
Expand Down Expand Up @@ -46,14 +47,25 @@ class FeatureGeometryLayer extends GeometryLayer {
* **WARNING** If the source is `VectorTilesSource` then `accurate` is always false.
*/
constructor(id, options = {}) {
options.update = FeatureProcessing.update;
options.convert = Feature2Mesh.convert({
batchId: options.batchId,
const {
object3d,
batchId,
onMeshCreated,
accurate = true,
...geometryOptions
} = options;

super(id, object3d || new Group(), geometryOptions);

this.update = FeatureProcessing.update;
this.convert = Feature2Mesh.convert({
batchId,
});
super(id, options.object3d || new Group(), options);

this.onMeshCreated = onMeshCreated;

this.isFeatureGeometryLayer = true;
this.accurate = options.accurate ?? true;
this.accurate = accurate;
this.buildExtent = !this.accurate;
}

Expand Down
Loading

0 comments on commit ca64d3d

Please sign in to comment.