Skip to content

Commit

Permalink
feat(TiledGeometryLayer): layer can now hide skirt
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyGlt committed Mar 7, 2024
1 parent e5810d7 commit 06c7181
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/Converter/convertToTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ export default {
const paramsGeometry = {
extent,
level,
segment: layer.segments || 16,
segments: layer.segments || 16,
disableSkirt: layer.disableSkirt,
hideSkirt: layer.hideSkirt,
};

return newTileGeometry(builder, paramsGeometry).then((result) => {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Prefab/TileBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const cacheTile = new Cache();
export default function newTileGeometry(builder, params) {
const { sharableExtent, quaternion, position } = builder.computeSharableExtent(params.extent);
const south = sharableExtent.south.toFixed(6);
const bufferKey = `${builder.crs}_${params.disableSkirt ? 0 : 1}_${params.segment}`;
const bufferKey = `${builder.crs}_${params.disableSkirt ? 0 : 1}_${params.segments}`;
let promiseGeometry = cacheTile.get(south, params.level, bufferKey);

// build geometry if doesn't exist
Expand Down
16 changes: 10 additions & 6 deletions src/Core/Prefab/computeBufferTileGeometry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import * as THREE from 'three';

export function getBufferIndexSize(segments, noSkirt) {
const triangles = (segments) * (segments) * 2 + (noSkirt ? 0 : 4 * segments * 2);
return triangles * 3;
}

export default function computeBuffers(params) {
// Create output buffers.
const outBuffers = {
Expand All @@ -26,7 +31,7 @@ export default function computeBuffers(params) {
const computeUvs = [];

const builder = params.builder;
const nSeg = params.segment || 8;
const nSeg = params.segments;
// segments count :
// Tile : (nSeg + 1) * (nSeg + 1)
// Skirt : 8 * (nSeg - 1)
Expand All @@ -35,8 +40,6 @@ export default function computeBuffers(params) {
throw new Error('Tile segments count is too big');
}

const triangles = (nSeg) * (nSeg) * 2 + (params.disableSkirt ? 0 : 4 * nSeg * 2);

outBuffers.position = new Float32Array(nVertex * 3);
outBuffers.normal = new Float32Array(nVertex * 3);

Expand All @@ -46,13 +49,14 @@ export default function computeBuffers(params) {
}

computeUvs[0] = () => {};
const bufferIndexSize = getBufferIndexSize(nSeg, params.disableSkirt);
if (params.buildIndexAndUv_0) {
if (nVertex < 2 ** 8) {
outBuffers.index = new Uint8Array(triangles * 3);
outBuffers.index = new Uint8Array(bufferIndexSize);
} else if (nVertex < 2 ** 16) {
outBuffers.index = new Uint16Array(triangles * 3);
outBuffers.index = new Uint16Array(bufferIndexSize);
} else if (nVertex < 2 ** 32) {
outBuffers.index = new Uint32Array(triangles * 3);
outBuffers.index = new Uint32Array(bufferIndexSize);
}
outBuffers.uvs[0] = new Float32Array(nVertex * 2);
computeUvs[0] = (id, u, v) => {
Expand Down
10 changes: 8 additions & 2 deletions src/Core/TileGeometry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as THREE from 'three';
import computeBuffers from 'Core/Prefab/computeBufferTileGeometry';
import computeBuffers, { getBufferIndexSize } from 'Core/Prefab/computeBufferTileGeometry';

function defaultBuffers(params) {
params.buildIndexAndUv_0 = true;
Expand All @@ -20,7 +20,7 @@ class TileGeometry extends THREE.BufferGeometry {
super();
this.center = params.center;
this.extent = params.extent;

this.segments = params.segments;
this.setIndex(buffers.index);
this.setAttribute('position', buffers.position);
this.setAttribute('normal', buffers.normal);
Expand All @@ -31,6 +31,12 @@ class TileGeometry extends THREE.BufferGeometry {

this.computeBoundingBox();
this.OBB = {};
if (params.hideSkirt) {
this.hideSkirt = params.hideSkirt;
}
}
set hideSkirt(value) {
this.setDrawRange(0, getBufferIndexSize(this.segments, value));
}
}

Expand Down
17 changes: 16 additions & 1 deletion src/Layer/TiledGeometryLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const boundingSphereCenter = new THREE.Vector3();
* @property {boolean} isTiledGeometryLayer - Used to checkout whether this
* layer is a TiledGeometryLayer. Default is true. You should not change this,
* as it is used internally for optimisation.
*
* @property {boolean} hideSkirt (default false) - Used to hide the skirt (tile borders).
* Useful when the layer opacity < 1
*/
class TiledGeometryLayer extends GeometryLayer {
/**
Expand Down Expand Up @@ -70,6 +71,7 @@ class TiledGeometryLayer extends GeometryLayer {
this.object3d.geoidHeight = 0;

this.protocol = 'tile';
this._hideSkirt = false;

this.sseSubdivisionThreshold = this.sseSubdivisionThreshold || 1.0;

Expand Down Expand Up @@ -101,6 +103,19 @@ class TiledGeometryLayer extends GeometryLayer {
this.maxScreenSizeNode = this.sseSubdivisionThreshold * (SIZE_DIAGONAL_TEXTURE * 2);
}

get hideSkirt() {
return this._hideSkirt;
}
set hideSkirt(value) {
this._hideSkirt = value;
for (const node of this.level0Nodes) {
node.traverse((obj) => {
if (obj.isTileMesh) {
obj.geometry.hideSkirt = value;
}
});
}
}
/**
* Picking method for this layer. It uses the {@link Picking#pickTilesAt}
* method.
Expand Down
4 changes: 2 additions & 2 deletions src/Renderer/OBB.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ class OBB extends THREE.Object3D {
if (extent.crs == 'EPSG:4326') {
const { sharableExtent, quaternion, position } = builder.computeSharableExtent(extent);
// Compute the minimum count of segment to build tile
const segment = Math.max(Math.floor(sharableExtent.planarDimensions(dimension).x / 90 + 1), 2);
const segments = Math.max(Math.floor(sharableExtent.planarDimensions(dimension).x / 90 + 1), 2);
const paramsGeometry = {
extent: sharableExtent,
level: 0,
segment,
segments,
disableSkirt: true,
builder,
};
Expand Down
2 changes: 1 addition & 1 deletion test/unit/obb.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function assertVerticesAreInOBB(builder, extent) {
extent,
disableSkirt: true,
level: 0,
segment: 1,
segments: 1,
};

return newTileGeometry(builder, params)
Expand Down
8 changes: 4 additions & 4 deletions test/unit/tilemesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('TileMesh', function () {
const paramsGeometry = {
extent: planarlayer.object3d.children[0].extent,
level: 0,
segment: 260,
segments: 260,
disableSkirt: true,
};

Expand All @@ -91,7 +91,7 @@ describe('TileMesh', function () {
const paramsGeometry2 = {
extent: planarlayer.object3d.children[0].extent,
level: 0,
segment: (2 ** 16),
segments: (2 ** 16),
disableSkirt: true,
};

Expand Down Expand Up @@ -130,7 +130,7 @@ describe('TileMesh', function () {
const paramsGeometry = {
extent: planarlayer.object3d.children[0].extent,
level: 0,
segment: 4,
segments: 4,
disableSkirt: true,
};

Expand All @@ -147,7 +147,7 @@ describe('TileMesh', function () {
const paramsGeometry = {
extent: planarlayer.object3d.children[0].extent,
level: 0,
segment: 2,
segments: 2,
disableSkirt: true,
};

Expand Down

0 comments on commit 06c7181

Please sign in to comment.