Skip to content

Commit

Permalink
refactor(Feature2Mesh): add gestion feature with variable size
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Dec 13, 2023
1 parent 40f83b3 commit 4d44cd3
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/Converter/Feature2Mesh.js
Expand Up @@ -191,6 +191,8 @@ function featureToPoint(feature, options) {
const vertices = new Float32Array(ptsIn);
inverseScale.setFromMatrixScale(context.collection.matrixWorldInverse);
normal.set(0, 0, 1).multiply(inverseScale);

const pointMaterialSize = [];
context.globals = { point: true };

for (const geometry of feature.geometries) {
Expand All @@ -207,9 +209,13 @@ function featureToPoint(feature, options) {

coord.copy(context.setLocalCoordinatesFromArray(feature.vertices, v));
const style = feature.style.applyContext(context);
const { base_altitude, color } = style.point;
const { base_altitude, color, radius } = style.point;
coord.z = 0;

if (!pointMaterialSize.includes(radius)) {
pointMaterialSize.push(radius);
}

// populate vertices
base.copy(normal).multiplyScalar(base_altitude).add(coord).toArray(vertices, v);
toColor(color).multiplyScalar(255).toArray(colors, v);
Expand All @@ -223,7 +229,11 @@ function featureToPoint(feature, options) {
geom.setAttribute('color', new THREE.BufferAttribute(colors, 3, true));
geom.setAttribute('batchId', new THREE.BufferAttribute(batchIds, 1));

options.pointMaterial.size = feature.style.point.radius;
options.pointMaterial.size = pointMaterialSize[0];
if (pointMaterialSize.length > 1) {
// TODO CREATE material for each feature
console.warn('Too many differents point.radius, only the first one will be used');
}

return new THREE.Points(geom, options.pointMaterial);
}
Expand All @@ -241,8 +251,7 @@ function featureToLine(feature, options) {
const geom = new THREE.BufferGeometry();
geom.setAttribute('position', new THREE.BufferAttribute(vertices, 3));

// TODO CREATE material for each feature
options.lineMaterial.linewidth = feature.style.stroke.width;
const lineMaterialWidth = [];
context.globals = { stroke: true };

const countIndices = (count - feature.geometries.length) * 2;
Expand Down Expand Up @@ -280,17 +289,25 @@ function featureToLine(feature, options) {

coord.copy(context.setLocalCoordinatesFromArray(feature.vertices, v));
const style = feature.style.applyContext(context);
const { base_altitude, color } = style.stroke;
const { base_altitude, color, width } = style.stroke;
coord.z = 0;

if (!lineMaterialWidth.includes(width)) {
lineMaterialWidth.push(width);
}

// populate geometry buffers
base.copy(normal).multiplyScalar(base_altitude).add(coord).toArray(vertices, v);
toColor(color).multiplyScalar(255).toArray(colors, v);
batchIds[j] = id;
}

featureId++;
}
options.lineMaterial.linewidth = lineMaterialWidth[0];
if (lineMaterialWidth.length > 1) {
// TODO CREATE material for each feature
console.warn('Too many differents stroke.width, only the first one will be used');
}
geom.setAttribute('color', new THREE.BufferAttribute(colors, 3, true));
geom.setAttribute('batchId', new THREE.BufferAttribute(batchIds, 1));
geom.setIndex(new THREE.BufferAttribute(indices, 1));
Expand Down Expand Up @@ -634,7 +651,6 @@ export default {
context.setCollection(collection);

const features = collection.features;

if (!features || features.length == 0) { return; }

const meshes = features.map(feature => featureToMesh(feature, options));
Expand Down

0 comments on commit 4d44cd3

Please sign in to comment.