Skip to content

Commit 42f3068

Browse files
committed
refacto(TileBuilder): remove useless uv building
1 parent f600ee4 commit 42f3068

5 files changed

Lines changed: 14 additions & 78 deletions

File tree

packages/Main/src/Core/Prefab/Globe/GlobeTileBuilder.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import {
66
TileBuilderParams,
77
} from '../TileBuilder';
88

9-
const PI_OV_FOUR = Math.PI / 4;
10-
const INV_TWO_PI = 1.0 / (Math.PI * 2);
119
const axisZ = new THREE.Vector3(0, 0, 1);
1210
const axisY = new THREE.Vector3(0, 1, 0);
1311
const quatToAlignLongitude = new THREE.Quaternion();

packages/Main/src/Core/Prefab/Planar/PlanarTileBuilder.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ export interface PlanarTileBuilderParams extends TileBuilderParams {
2626
* tile arrangements.
2727
*/
2828
export class PlanarTileBuilder implements TileBuilder<PlanarTileBuilderParams> {
29-
private _uvCount: number;
3029
private _transform: Transform;
3130
private _crs: string;
3231

3332
public constructor(options: {
3433
projection?: string,
3534
crs: string,
36-
uvCount?: number,
3735
}) {
3836
if (options.projection) {
3937
console.warn('PlanarTileBuilder projection parameter is deprecated,'
@@ -48,8 +46,6 @@ export class PlanarTileBuilder implements TileBuilder<PlanarTileBuilderParams> {
4846
position: new THREE.Vector3(),
4947
normal: new THREE.Vector3(0, 0, 1),
5048
};
51-
52-
this._uvCount = options.uvCount ?? 1;
5349
}
5450

5551
public get uvCount(): number {

packages/Main/src/Core/Prefab/TileBuilder.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export type GpuBufferAttributes = {
1616
index: THREE.BufferAttribute | null;
1717
position: THREE.BufferAttribute;
1818
normal: THREE.BufferAttribute;
19-
uvs: THREE.BufferAttribute[];
19+
uv: THREE.BufferAttribute;
2020
};
2121

2222
/**
@@ -125,7 +125,7 @@ export function newTileGeometry(
125125

126126
cachedBuffers = {
127127
index: new THREE.BufferAttribute(buffers.index!, 1),
128-
uv: new THREE.BufferAttribute(buffers.uvs[0]!, 2),
128+
uv: new THREE.BufferAttribute(buffers.uv!, 2),
129129
};
130130

131131
// Update cacheBuffer
@@ -134,13 +134,7 @@ export function newTileGeometry(
134134

135135
const gpuBuffers: GpuBufferAttributes = {
136136
index: cachedBuffers.index,
137-
uvs: [
138-
cachedBuffers.uv,
139-
...(buffers.uvs[1] !== undefined
140-
? [new THREE.BufferAttribute(buffers.uvs[1], 1)]
141-
: []
142-
),
143-
],
137+
uv: cachedBuffers.uv,
144138
position: new THREE.BufferAttribute(buffers.position, 3),
145139
normal: new THREE.BufferAttribute(buffers.normal, 3),
146140
};

packages/Main/src/Core/Prefab/computeBufferTileGeometry.ts

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type Buffers = {
1515
index: IndexArray,
1616
position: Float32Array,
1717
normal: Float32Array,
18-
uvs: [Option<Float32Array>, Option<Float32Array>],
18+
uv: Option<Float32Array>,
1919
};
2020

2121
type BuffersAndSkirt = Buffers & {
@@ -96,28 +96,7 @@ function allocateBuffers(
9696
skirt,
9797
position: new Float32Array(nVertex * 3),
9898
normal: new Float32Array(nVertex * 3),
99-
// 2 UV set per tile: wgs84 (uv[0]) and pseudo-mercator (pm, uv[1])
100-
// - wgs84: 1 texture per tile because tiles are using wgs84
101-
// projection
102-
// - pm: use multiple textures per tile.
103-
// +-------------------------+
104-
// | |
105-
// | Texture 0 |
106-
// +-------------------------+
107-
// | |
108-
// | Texture 1 |
109-
// +-------------------------+
110-
// | |
111-
// | Texture 2 |
112-
// +-------------------------+
113-
// * u = wgs84.u
114-
// * v = textureid + v in builder texture
115-
uvs: [
116-
cache?.uv ?? new Float32Array(nVertex * 2),
117-
builder.computeExtraOffset !== undefined
118-
? new Float32Array(nVertex)
119-
: undefined,
120-
],
99+
uv: cache?.uv ?? new Float32Array(nVertex * 2),
121100
};
122101
}
123102

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

129-
function initComputeUv1(value: number): (uv: Float32Array, id: number) => void {
130-
return (uv: Float32Array, id: number): void => { uv[id] = value; };
131-
}
132-
133-
type ComputeUvs =
134-
[typeof computeUv0 | (() => void), ReturnType<typeof initComputeUv1>?];
108+
type ComputeUvs = typeof computeUv0;
135109

136110
interface ComputeBuffersParams extends TileBuilderPrepareParams {
137111
center: THREE.Vector3;
@@ -172,8 +146,7 @@ export function computeBuffers(
172146
cache,
173147
);
174148

175-
const computeUvs: ComputeUvs =
176-
[cache === undefined ? computeUv0 : () => { }];
149+
const computeUv: ComputeUvs = cache === undefined ? computeUv0 : () => { };
177150

178151
const preparedParams = builder.prepare(params);
179152

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

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

185-
if (builder.computeExtraOffset !== undefined) {
186-
computeUvs[1] = initComputeUv1(
187-
builder.computeExtraOffset(preparedParams) as number,
188-
);
189-
}
190-
191158
for (let x = 0; x <= nSeg; x++) {
192159
const u = x / nSeg;
193160
const id_m3 = (y * nVertex + x) * 3;
@@ -211,12 +178,7 @@ export function computeBuffers(
211178

212179
vertex.toArray(outBuffers.position, id_m3);
213180
normal.toArray(outBuffers.normal, id_m3);
214-
215-
for (const [index, computeUv] of computeUvs.entries()) {
216-
if (computeUv !== undefined) {
217-
computeUv(outBuffers.uvs[index]!, y * nVertex + x, u, v);
218-
}
219-
}
181+
computeUv(outBuffers.uv, y * nVertex + x, u, v);
220182
}
221183
}
222184

@@ -325,11 +287,7 @@ export function computeBuffers(
325287
outBuffers.normal[id_m3 + 1] = outBuffers.normal[id2_m3 + 1];
326288
outBuffers.normal[id_m3 + 2] = outBuffers.normal[id2_m3 + 2];
327289

328-
buildSkirt.uv(outBuffers.uvs[0], start + i, id);
329-
330-
if (outBuffers.uvs[1] !== undefined) {
331-
outBuffers.uvs[1][start + i] = outBuffers.uvs[1][id];
332-
}
290+
buildSkirt.uv(outBuffers.uv, start + i, id);
333291

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

@@ -346,7 +304,7 @@ export function computeBuffers(
346304
return {
347305
index: outBuffers.index,
348306
position: outBuffers.position,
349-
uvs: outBuffers.uvs,
307+
uv: outBuffers.uv,
350308
normal: outBuffers.normal,
351309
};
352310
}

packages/Main/src/Core/TileGeometry.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,9 @@ function defaultBuffers(
3333
index: buffers.index
3434
? new THREE.BufferAttribute(buffers.index, 1)
3535
: null,
36-
uvs: [
37-
...(buffers.uvs[0]
38-
? [new THREE.BufferAttribute(buffers.uvs[0], 2)]
39-
: []
40-
),
41-
...(buffers.uvs[1]
42-
? [new THREE.BufferAttribute(buffers.uvs[1], 1)]
43-
: []),
44-
],
36+
uv: buffers.uv
37+
? new THREE.BufferAttribute(buffers.uv, 2)
38+
: null,
4539
position: new THREE.BufferAttribute(buffers.position, 3),
4640
normal: new THREE.BufferAttribute(buffers.normal, 3),
4741
};
@@ -81,11 +75,7 @@ export class TileGeometry extends THREE.BufferGeometry {
8175
this.setIndex(bufferAttributes.index);
8276
this.setAttribute('position', bufferAttributes.position);
8377
this.setAttribute('normal', bufferAttributes.normal);
84-
this.setAttribute('uv', bufferAttributes.uvs[0]);
85-
86-
for (let i = 1; i < bufferAttributes.uvs.length; i++) {
87-
this.setAttribute(`uv_${i}`, bufferAttributes.uvs[i]);
88-
}
78+
this.setAttribute('uv', bufferAttributes.uv);
8979

9080
this.computeBoundingBox();
9181
this.OBB = null;

0 commit comments

Comments
 (0)