Skip to content

Commit

Permalink
Factorize begin
Browse files Browse the repository at this point in the history
  • Loading branch information
Desplandis committed Oct 29, 2023
1 parent 9cf9728 commit 71f8ccf
Showing 1 changed file with 37 additions and 17 deletions.
54 changes: 37 additions & 17 deletions src/Converter/Feature2Mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,18 @@ function addExtrudedPolygonSideFaces(indices, length, offset, count, isClockWise
}

function featureToPoint(feature, options) {
// TODO[QB]: SAME BEGIN
const ptsIn = feature.vertices;
const colors = new Uint8Array(ptsIn.length);
const batchIds = new Uint32Array(ptsIn.length);
const batchId = options.batchId || ((p, id) => id);

const count = ptsIn.length;
const batchIds = new Uint32Array(count);
const batchId = options.batchId || ((p, id) => id);
let featureId = 0;
// TODO[QB]: SAME END

const vertices = new Float32Array(ptsIn);

inverseScale.setFromMatrixScale(context.collection.matrixWorldInverse);
normal.set(0, 0, 1).multiply(inverseScale);
context.globals = { point: true };
Expand Down Expand Up @@ -258,28 +263,30 @@ function featureToPoint(feature, options) {
featureId++;
}

// TODO[QB]: SAME BEGIN
const geom = new THREE.BufferGeometry();
geom.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
geom.setAttribute('color', new THREE.BufferAttribute(colors, 3, true));
geom.setAttribute('batchId', new THREE.BufferAttribute(batchIds, 1));
// TODO[QB]: SAME END

options.pointMaterial.size = feature.style.point.radius;

return new THREE.Points(geom, options.pointMaterial);
}

function featureToLine(feature, options) {
// TODO[QB]: SAME BEGIN
const ptsIn = feature.vertices;
const colors = new Uint8Array(ptsIn.length);
const count = ptsIn.length / 3;

const count = ptsIn.length / 3;
const batchIds = new Uint32Array(count);
const batchId = options.batchId || ((p, id) => id);
let featureId = 0;
// TODO[QB]: SAME END

const vertices = new Float32Array(ptsIn.length);
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;
Expand Down Expand Up @@ -331,24 +338,38 @@ function featureToLine(feature, options) {

featureId++;
}

// TODO[QB]: SAME BEGIN
const geom = new THREE.BufferGeometry();
geom.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
geom.setAttribute('color', new THREE.BufferAttribute(colors, 3, true));
geom.setAttribute('batchId', new THREE.BufferAttribute(batchIds, 1));
// TODO[QB]: SAME END

geom.setIndex(new THREE.BufferAttribute(indices, 1));

return new THREE.LineSegments(geom, options.lineMaterial);
}

function featureToPolygon(feature, options) {
const vertices = new Float32Array(feature.vertices);
const colors = new Uint8Array(feature.vertices.length);
const indices = [];
// TODO[QB]: SAME BEGIN
const ptsIn = feature.vertices;
const colors = new Uint8Array(ptsIn.length);

const batchIds = new Uint32Array(vertices.length / 3);
const count = ptsIn.length / 3;
const batchIds = new Uint32Array(count);
const batchId = options.batchId || ((p, id) => id);
let featureId = 0;
// TODO[QB]: SAME END

const vertices = new Float32Array(ptsIn);

context.globals = { fill: true };

const indices = [];

inverseScale.setFromMatrixScale(context.collection.matrixWorldInverse);
normal.set(0, 0, 1).multiply(inverseScale);
let featureId = 0;

for (const geometry of feature.geometries) {
const start = geometry.indices[0].offset;
Expand Down Expand Up @@ -420,18 +441,17 @@ function area(contour, offset, count) {

function featureToExtrudedPolygon(feature, options) {
const ptsIn = feature.vertices;
const vertices = new Float32Array(ptsIn.length * 2);
const totalVertices = ptsIn.length / 3;

const colors = new Uint8Array(ptsIn.length * 2);

const indices = [];

const batchIds = new Uint32Array(vertices.length / 3);
const batchIds = new Uint32Array(ptsIn.length * 2);
const batchId = options.batchId || ((p, id) => id);

let featureId = 0;

const vertices = new Float32Array(ptsIn.length * 2);
const totalVertices = ptsIn.length / 3;

const indices = [];

context.globals = { fill: true };
inverseScale.setFromMatrixScale(context.collection.matrixWorldInverse);
normal.set(0, 0, 1).multiply(inverseScale);
Expand Down

0 comments on commit 71f8ccf

Please sign in to comment.