Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion packages/Main/src/Converter/convertToTile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,27 @@
if (parent) {
tile.geoidHeight = parent.geoidHeight;
const geoidHeight = geoidLayerIsVisible(layer) ? tile.geoidHeight : 0;
tile.setBBoxZ({ min: parent.obb.z.min, max: parent.obb.z.max, geoidHeight });
tile.material.setUniform('geoidHeight', geoidHeight);

const parent_uniforms = parent.material.uniforms;
const child_uniforms = tile.material.uniforms;

if (parent.material.uniforms.map.value) {
const extentParent = parent_uniforms.map.value.extent;
child_uniforms.map.value = parent_uniforms.map.value;
child_uniforms.colorOffsetScales.value = tile.extent.offsetToParent(extentParent);

Check warning on line 100 in packages/Main/src/Converter/convertToTile.ts

View workflow job for this annotation

GitHub Actions / Build bundle, check Linter and generate documentation

This line has a length of 102. Maximum allowed is 100
}

if (parent_uniforms.displacementMap.value) {
const extentParent = parent_uniforms.displacementMap.value.extent.toExtent(tile.extent.crs);

Check warning on line 104 in packages/Main/src/Converter/convertToTile.ts

View workflow job for this annotation

GitHub Actions / Build bundle, check Linter and generate documentation

This line has a length of 112. Maximum allowed is 100
child_uniforms.displacementMap.value = parent_uniforms.displacementMap.value;
child_uniforms.elevationOffsetScales.value = tile.extent.offsetToParent(extentParent);

Check warning on line 106 in packages/Main/src/Converter/convertToTile.ts

View workflow job for this annotation

GitHub Actions / Build bundle, check Linter and generate documentation

This line has a length of 106. Maximum allowed is 100
const rasterElevationNode = parent_uniforms.elevationLayer.value;
child_uniforms.elevationLayer.value = rasterElevationNode;
tile.setBBoxZ({ min: rasterElevationNode.min, max: rasterElevationNode.max, scale: rasterElevationNode.layer.scale, geoidHeight });

Check warning on line 109 in packages/Main/src/Converter/convertToTile.ts

View workflow job for this annotation

GitHub Actions / Build bundle, check Linter and generate documentation

This line has a length of 151. Maximum allowed is 100
} else {
tile.setBBoxZ({ min: parent.obb.z.min, max: parent.obb.z.max, geoidHeight });
}
}

return tile;
Expand Down
3 changes: 1 addition & 2 deletions packages/Main/src/Core/Prefab/Globe/GlobeLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ class GlobeLayer extends TiledGeometryLayer {
'EPSG:3857',
];

const uvCount = tileMatrixSets.length;
const builder = new GlobeTileBuilder({ uvCount });
const builder = new GlobeTileBuilder();

super(id, object3d || new THREE.Group(), schemeTile, builder, {
tileMatrixSets,
Expand Down
36 changes: 1 addition & 35 deletions packages/Main/src/Core/Prefab/Globe/GlobeTileBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,12 @@ import {
TileBuilderParams,
} from '../TileBuilder';

const PI_OV_FOUR = Math.PI / 4;
const INV_TWO_PI = 1.0 / (Math.PI * 2);
const axisZ = new THREE.Vector3(0, 0, 1);
const axisY = new THREE.Vector3(0, 1, 0);
const quatToAlignLongitude = new THREE.Quaternion();
const quatToAlignLatitude = new THREE.Quaternion();
const quatNormalToZ = new THREE.Quaternion();

/** Transforms a WGS84 latitude into a usable texture offset. */
function WGS84ToOneSubY(latitude: number): number {
return 1.0 - (0.5 - Math.log(Math.tan(
PI_OV_FOUR + THREE.MathUtils.degToRad(latitude) * 0.5,
)) * INV_TWO_PI);
}

type Transform = {
/** Buffers for 2-part coordinate mapping operations. */
coords: [Coordinates, Coordinates];
Expand All @@ -45,27 +36,18 @@ export interface GlobeTileBuilderParams extends TileBuilderParams {
export class GlobeTileBuilder
implements TileBuilder<GlobeTileBuilderParams> {
private static _crs: string = 'EPSG:4978';
private static _computeExtraOffset(params: GlobeTileBuilderParams): number {
const t = WGS84ToOneSubY(params.coordinates.latitude) * params.nbRow;
return (!isFinite(t) ? 0 : t) - params.deltaUV1;
}

/**
* Buffer holding information about the tile/vertex currently being
* processed.
*/
private _transform: Transform;

public computeExtraOffset?: (params: GlobeTileBuilderParams) => number;

public get crs(): string {
return GlobeTileBuilder._crs;
}

public constructor(options: {
/** Number of unaligned texture sets. */
uvCount: number,
}) {
public constructor() {
this._transform = {
coords: [
new Coordinates('EPSG:4326', 0, 0),
Expand All @@ -74,29 +56,13 @@ implements TileBuilder<GlobeTileBuilderParams> {
position: new THREE.Vector3(),
dimension: new THREE.Vector2(),
};

// UV: Normalized coordinates (from degree) on the entire tile
// EPSG:4326
// Offset: Float row coordinate from Pseudo mercator coordinates
// EPSG:3857
if (options.uvCount > 1) {
this.computeExtraOffset = GlobeTileBuilder._computeExtraOffset;
}
}

public prepare(params: TileBuilderParams): GlobeTileBuilderParams {
const nbRow = 2 ** (params.level + 1.0);
let st1 = WGS84ToOneSubY(params.extent.south);

if (!isFinite(st1)) { st1 = 0; }

const sizeTexture = 1.0 / nbRow;

const start = (st1 % (sizeTexture));

const newParams = {
nbRow,
deltaUV1: (st1 - start) * nbRow,
// transformation to align tile's normal to z axis
quatNormalToZ: quatNormalToZ.setFromAxisAngle(
axisY,
Expand Down
4 changes: 0 additions & 4 deletions packages/Main/src/Core/Prefab/Planar/PlanarTileBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ export interface PlanarTileBuilderParams extends TileBuilderParams {
* tile arrangements.
*/
export class PlanarTileBuilder implements TileBuilder<PlanarTileBuilderParams> {
private _uvCount: number;
private _transform: Transform;
private _crs: string;

public constructor(options: {
projection?: string,
crs: string,
uvCount?: number,
}) {
if (options.projection) {
console.warn('PlanarTileBuilder projection parameter is deprecated,'
Expand All @@ -48,8 +46,6 @@ export class PlanarTileBuilder implements TileBuilder<PlanarTileBuilderParams> {
position: new THREE.Vector3(),
normal: new THREE.Vector3(0, 0, 1),
};

this._uvCount = options.uvCount ?? 1;
}

public get uvCount(): number {
Expand Down
12 changes: 3 additions & 9 deletions packages/Main/src/Core/Prefab/TileBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type GpuBufferAttributes = {
index: THREE.BufferAttribute | null;
position: THREE.BufferAttribute;
normal: THREE.BufferAttribute;
uvs: THREE.BufferAttribute[];
uv: THREE.BufferAttribute;
};

/**
Expand Down Expand Up @@ -125,7 +125,7 @@ export function newTileGeometry(

cachedBuffers = {
index: new THREE.BufferAttribute(buffers.index!, 1),
uv: new THREE.BufferAttribute(buffers.uvs[0]!, 2),
uv: new THREE.BufferAttribute(buffers.uv!, 2),
};

// Update cacheBuffer
Expand All @@ -134,13 +134,7 @@ export function newTileGeometry(

const gpuBuffers: GpuBufferAttributes = {
index: cachedBuffers.index,
uvs: [
cachedBuffers.uv,
...(buffers.uvs[1] !== undefined
? [new THREE.BufferAttribute(buffers.uvs[1], 1)]
: []
),
],
uv: cachedBuffers.uv,
position: new THREE.BufferAttribute(buffers.position, 3),
normal: new THREE.BufferAttribute(buffers.normal, 3),
};
Expand Down
56 changes: 7 additions & 49 deletions packages/Main/src/Core/Prefab/computeBufferTileGeometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type Buffers = {
index: IndexArray,
position: Float32Array,
normal: Float32Array,
uvs: [Option<Float32Array>, Option<Float32Array>],
uv: Option<Float32Array>,
};

type BuffersAndSkirt = Buffers & {
Expand Down Expand Up @@ -96,28 +96,7 @@ function allocateBuffers(
skirt,
position: new Float32Array(nVertex * 3),
normal: new Float32Array(nVertex * 3),
// 2 UV set per tile: wgs84 (uv[0]) and pseudo-mercator (pm, uv[1])
// - wgs84: 1 texture per tile because tiles are using wgs84
// projection
// - pm: use multiple textures per tile.
// +-------------------------+
// | |
// | Texture 0 |
// +-------------------------+
// | |
// | Texture 1 |
// +-------------------------+
// | |
// | Texture 2 |
// +-------------------------+
// * u = wgs84.u
// * v = textureid + v in builder texture
uvs: [
cache?.uv ?? new Float32Array(nVertex * 2),
builder.computeExtraOffset !== undefined
? new Float32Array(nVertex)
: undefined,
],
uv: cache?.uv ?? new Float32Array(nVertex * 2),
};
}

Expand All @@ -126,12 +105,7 @@ function computeUv0(uv: Float32Array, id: number, u: number, v: number): void {
uv[id * 2 + 1] = v;
}

function initComputeUv1(value: number): (uv: Float32Array, id: number) => void {
return (uv: Float32Array, id: number): void => { uv[id] = value; };
}

type ComputeUvs =
[typeof computeUv0 | (() => void), ReturnType<typeof initComputeUv1>?];
type ComputeUvs = typeof computeUv0;

interface ComputeBuffersParams extends TileBuilderPrepareParams {
center: THREE.Vector3;
Expand Down Expand Up @@ -172,8 +146,7 @@ export function computeBuffers(
cache,
);

const computeUvs: ComputeUvs =
[cache === undefined ? computeUv0 : () => { }];
const computeUv: ComputeUvs = cache === undefined ? computeUv0 : () => { };

const preparedParams = builder.prepare(params);

Expand All @@ -182,12 +155,6 @@ export function computeBuffers(

preparedParams.coordinates.y = builder.vProject(v, params.extent);

if (builder.computeExtraOffset !== undefined) {
computeUvs[1] = initComputeUv1(
builder.computeExtraOffset(preparedParams) as number,
);
}

for (let x = 0; x <= nSeg; x++) {
const u = x / nSeg;
const id_m3 = (y * nVertex + x) * 3;
Expand All @@ -211,12 +178,7 @@ export function computeBuffers(

vertex.toArray(outBuffers.position, id_m3);
normal.toArray(outBuffers.normal, id_m3);

for (const [index, computeUv] of computeUvs.entries()) {
if (computeUv !== undefined) {
computeUv(outBuffers.uvs[index]!, y * nVertex + x, u, v);
}
}
computeUv(outBuffers.uv, y * nVertex + x, u, v);
}
}

Expand Down Expand Up @@ -325,11 +287,7 @@ export function computeBuffers(
outBuffers.normal[id_m3 + 1] = outBuffers.normal[id2_m3 + 1];
outBuffers.normal[id_m3 + 2] = outBuffers.normal[id2_m3 + 2];

buildSkirt.uv(outBuffers.uvs[0], start + i, id);

if (outBuffers.uvs[1] !== undefined) {
outBuffers.uvs[1][start + i] = outBuffers.uvs[1][id];
}
buildSkirt.uv(outBuffers.uv, start + i, id);

const idf = (i + 1) % outBuffers.skirt!.length;

Expand All @@ -346,7 +304,7 @@ export function computeBuffers(
return {
index: outBuffers.index,
position: outBuffers.position,
uvs: outBuffers.uvs,
uv: outBuffers.uv,
normal: outBuffers.normal,
};
}
18 changes: 4 additions & 14 deletions packages/Main/src/Core/TileGeometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,9 @@ function defaultBuffers(
index: buffers.index
? new THREE.BufferAttribute(buffers.index, 1)
: null,
uvs: [
...(buffers.uvs[0]
? [new THREE.BufferAttribute(buffers.uvs[0], 2)]
: []
),
...(buffers.uvs[1]
? [new THREE.BufferAttribute(buffers.uvs[1], 1)]
: []),
],
uv: buffers.uv
? new THREE.BufferAttribute(buffers.uv, 2)
: null,
position: new THREE.BufferAttribute(buffers.position, 3),
normal: new THREE.BufferAttribute(buffers.normal, 3),
};
Expand Down Expand Up @@ -81,11 +75,7 @@ export class TileGeometry extends THREE.BufferGeometry {
this.setIndex(bufferAttributes.index);
this.setAttribute('position', bufferAttributes.position);
this.setAttribute('normal', bufferAttributes.normal);
this.setAttribute('uv', bufferAttributes.uvs[0]);

for (let i = 1; i < bufferAttributes.uvs.length; i++) {
this.setAttribute(`uv_${i}`, bufferAttributes.uvs[i]);
}
this.setAttribute('uv', bufferAttributes.uv);

this.computeBoundingBox();
this.OBB = null;
Expand Down
2 changes: 1 addition & 1 deletion packages/Main/src/Core/TileMesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class TileMesh extends THREE.Mesh<TileGeometry, LayeredMaterial> {
*/
override onBeforeRender(renderer: THREE.WebGLRenderer) {
if (this.material.layersNeedUpdate) {
this.material.updateLayersUniforms(renderer);
this.material.updateLayersUniforms(renderer, this.extent);
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions packages/Main/src/Process/LayeredMaterialNodeProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ export function updateLayeredMaterialNodeImagery(context, layer, node, parent) {
if (!nodeLayer) {
// Create new raster node
nodeLayer = layer.setupRasterNode(node);

// Init the node by parent
const parentLayer = parent.material?.getTile(layer.id);
nodeLayer.initFromParent(parentLayer, extentsDestination);
}

// Proposed new process, two separate processes:
Expand Down Expand Up @@ -187,9 +183,6 @@ export function updateLayeredMaterialNodeElevation(context, layer, node, parent)
if (node.layerUpdateState[layer.id] === undefined) {
node.layerUpdateState[layer.id] = new LayerUpdateState();

const parentLayer = parent.material?.getTile(layer.id);
nodeLayer.initFromParent(parentLayer, extentsDestination);

if (nodeLayer.level >= layer.source.zoom.min) {
context.view.notifyChange(node, false);
return;
Expand Down
Loading
Loading