mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-19 18:41:23 +01:00
refactor: Features module start
This commit is contained in:
parent
ec236d146b
commit
b5fede560b
9 changed files with 315 additions and 160 deletions
|
|
@ -109,3 +109,57 @@ function drawCoastline() {
|
|||
|
||||
TIME && console.timeEnd("drawCoastline");
|
||||
}
|
||||
|
||||
function drawFeatures() {
|
||||
TIME && console.time("drawFeatures");
|
||||
const {vertices, features} = pack;
|
||||
|
||||
const landMask = defs.select("#land");
|
||||
const waterMask = defs.select("#water");
|
||||
const lineGen = d3.line().curve(d3.curveBasisClosed);
|
||||
|
||||
for (const feature of features) {
|
||||
if (!feature || feature.type === "ocean") continue;
|
||||
|
||||
const points = feature.vertices.map(vertex => vertices.p[vertex]);
|
||||
const simplifiedPoints = simplify(points, 0.3);
|
||||
const clippedPoints = clipPoly(simplifiedPoints, 1);
|
||||
const path = round(lineGen(clippedPoints));
|
||||
|
||||
if (feature.type === "lake") {
|
||||
landMask
|
||||
.append("path")
|
||||
.attr("d", path)
|
||||
.attr("fill", "black")
|
||||
.attr("id", "land_" + feature.i);
|
||||
|
||||
lakes
|
||||
.select(`#${feature.group}`)
|
||||
.append("path")
|
||||
.attr("d", path)
|
||||
.attr("id", "lake_" + feature.i)
|
||||
.attr("data-f", feature.i);
|
||||
} else {
|
||||
landMask
|
||||
.append("path")
|
||||
.attr("d", path)
|
||||
.attr("fill", "white")
|
||||
.attr("id", "land_" + feature.i);
|
||||
|
||||
waterMask
|
||||
.append("path")
|
||||
.attr("d", path)
|
||||
.attr("fill", "black")
|
||||
.attr("id", "water_" + feature.i);
|
||||
|
||||
coastline
|
||||
.select(`#${feature.group}`)
|
||||
.append("path")
|
||||
.attr("d", path)
|
||||
.attr("id", "island_" + feature.i)
|
||||
.attr("data-f", feature.i);
|
||||
}
|
||||
}
|
||||
|
||||
TIME && console.timeEnd("drawFeatures");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue