Skip to content

Commit

Permalink
fix proj on base alti
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Nov 3, 2023
1 parent 6756148 commit 0f0a1a5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
21 changes: 4 additions & 17 deletions src/Converter/Feature2Mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ class FeatureMesh extends THREE.Group {
this.#collection.quaternion.copy(collection.quaternion);
this.#collection.position.copy(collection.position);

if (collection.crs == 'EPSG:4978') {
normal.copy(collection.center.geodesicNormal);
} else {
normal.set(0, 0, 1);
}

normal.multiplyScalar(collection.center.z);
this.#collection.position.sub(normal);

this.#collection.scale.copy(collection.scale);
this.#collection.updateMatrix();

Expand Down Expand Up @@ -208,10 +199,9 @@ function featureToPoint(feature, options) {
coord.copy(context.setLocalCoordinatesFromArray(feature.vertices, v));
const style = feature.style.applyContext(context);
const { base_altitude, color } = style.point;
coord.z = 0;

// populate vertices
base.copy(normal).multiplyScalar(base_altitude).add(coord).toArray(vertices, v);
base.copy(normal).multiplyScalar(base_altitude - coord.z).add(coord).toArray(vertices, v);
toColor(color).multiplyScalar(255).toArray(colors, v);
batchIds[j] = id;
}
Expand Down Expand Up @@ -281,10 +271,9 @@ function featureToLine(feature, options) {
coord.copy(context.setLocalCoordinatesFromArray(feature.vertices, v));
const style = feature.style.applyContext(context);
const { base_altitude, color } = style.stroke;
coord.z = 0;

// populate geometry buffers
base.copy(normal).multiplyScalar(base_altitude).add(coord).toArray(vertices, v);
base.copy(normal).multiplyScalar(base_altitude - coord.z).add(coord).toArray(vertices, v);
toColor(color).multiplyScalar(255).toArray(colors, v);
batchIds[j] = id;
}
Expand Down Expand Up @@ -334,10 +323,9 @@ function featureToPolygon(feature, options) {
coord.copy(context.setLocalCoordinatesFromArray(feature.vertices, i));
const style = feature.style.applyContext(context);
const { base_altitude, color } = style.fill;
coord.z = 0;

// populate geometry buffers
base.copy(normal).multiplyScalar(base_altitude).add(coord).toArray(vertices, i);
base.copy(normal).multiplyScalar(base_altitude - coord.z).add(coord).toArray(vertices, i);
batchIds[b] = id;
toColor(color).multiplyScalar(255).toArray(colors, i);
}
Expand Down Expand Up @@ -420,10 +408,9 @@ function featureToExtrudedPolygon(feature, options) {

const style = feature.style.applyContext(context);
const { base_altitude, extrusion_height, color } = style.fill;
coord.z = 0;

// populate base geometry buffers
base.copy(normal).multiplyScalar(base_altitude).add(coord).toArray(vertices, i);
base.copy(normal).multiplyScalar(base_altitude - coord.z).add(coord).toArray(vertices, i);
batchIds[b] = id;

// populate top geometry buffers
Expand Down
6 changes: 5 additions & 1 deletion src/Core/Style.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const canvas = (typeof document !== 'undefined') ? document.createElement('canva
const style_properties = {};

function base_altitudeDefault(properties, ctx) {
return ctx?.coordinates?.z || ctx?.collection?.center?.z || 0;
return ctx?.localCoordinates?.z || 0;
}

function mapPropertiesFromContext(mainKey, from, to, context) {
Expand Down Expand Up @@ -214,6 +214,10 @@ export class StyleContext {
}
return this.#worldCoord;
}

get localCoordinates() {
return this.#localCoordinates;
}
}

/**
Expand Down

0 comments on commit 0f0a1a5

Please sign in to comment.