Skip to content

Commit

Permalink
Elevation per polygon for fill extrusions
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmarsden committed Mar 14, 2024
1 parent 2f3a407 commit ceb3d46
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### ✨ Features and improvements
- Improve animation curve when easeTo and flyTo with constraints ([#3793](https://github.com/maplibre/maplibre-gl-js/pull/3793))
- For filled extrusions, calculate the elevation per polygon (see issue [#3313](https://github.com/maplibre/maplibre-gl-js/issues/3313))
- _...Add new stuff here..._

### 🐞 Bug fixes
Expand Down
19 changes: 11 additions & 8 deletions src/data/bucket/fill_extrusion_bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@ export class FillExtrusionBucket implements Bucket {
}

addFeature(feature: BucketFeature, geometry: Array<Array<Point>>, index: number, canonical: CanonicalTileID, imagePositions: {[_: string]: ImagePosition}) {
const centroid = {x: 0, y: 0, vertexCount: 0};
for (const polygon of classifyRings(geometry, EARCUT_MAX_RINGS)) {

const centroid = {x: 0, y: 0, vertexCount: 0};

let numVertices = 0;
for (const ring of polygon) {
numVertices += ring.length;
Expand Down Expand Up @@ -274,15 +276,16 @@ export class FillExtrusionBucket implements Bucket {

segment.primitiveLength += indices.length / 3;
segment.vertexLength += numVertices;
}

// remember polygon centroid to calculate elevation in GPU
for (let i = 0; i < centroid.vertexCount; i++) {
this.centroidVertexArray.emplaceBack(
Math.floor(centroid.x / centroid.vertexCount),
Math.floor(centroid.y / centroid.vertexCount)
);
// remember polygon centroid to calculate elevation in GPU
for (let i = 0; i < centroid.vertexCount; i++) {
const averageX = Math.floor(centroid.x / centroid.vertexCount);
const averageY = Math.floor(centroid.y / centroid.vertexCount);
this.centroidVertexArray.emplaceBack(averageX, averageY);
}

}

this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, imagePositions, canonical);
}
}
Expand Down

0 comments on commit ceb3d46

Please sign in to comment.