mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
getSignedDistanceField
This commit is contained in:
parent
845f2e99f5
commit
00189f2185
4 changed files with 60 additions and 52 deletions
|
|
@ -14,7 +14,6 @@
|
|||
lineGen.curve(d3.curveBasisClosed);
|
||||
cells = grid.cells, pointsN = grid.cells.i.length, vertices = grid.vertices;
|
||||
const limits = outline === "random" ? randomizeOutline() : outline.split(",").map(s => +s);
|
||||
markupOcean(limits);
|
||||
|
||||
const chains = [];
|
||||
const opacity = rn(0.4 / limits.length, 2);
|
||||
|
|
@ -33,15 +32,12 @@
|
|||
const relaxed = chain.filter((v, i) => !(i%relax) || vertices.c[v].some(c => c >= pointsN));
|
||||
if (relaxed.length < 4) continue;
|
||||
const points = clipPoly(relaxed.map(v => vertices.p[v]), 1);
|
||||
//const inside = d3.polygonContains(points, grid.points[i]);
|
||||
chains.push([t, points]); //chains.push([t, points, inside]);
|
||||
chains.push([t, points]);
|
||||
}
|
||||
|
||||
//const bbox = `M0,0h${graphWidth}v${graphHeight}h${-graphWidth}Z`;
|
||||
for (const t of limits) {
|
||||
const layer = chains.filter(c => c[0] === t);
|
||||
let path = layer.map(c => round(lineGen(c[1]))).join("");
|
||||
//if (layer.every(c => !c[2])) path = bbox + path; // add outer ring if all segments are outside (works not for all cases)
|
||||
if (path) oceanLayers.append("path").attr("d", path).attr("fill", "#ecf2f9").style("opacity", opacity);
|
||||
}
|
||||
|
||||
|
|
@ -64,16 +60,6 @@
|
|||
return limits;
|
||||
}
|
||||
|
||||
// Define grid ocean cells type based on distance form land
|
||||
function markupOcean(limits) {
|
||||
for (let t = -2; t >= limits[0]-1; t--) {
|
||||
for (let i = 0; i < pointsN; i++) {
|
||||
if (cells.t[i] !== t+1) continue;
|
||||
cells.c[i].forEach(function(e) {if (!cells.t[e]) cells.t[e] = t;});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// connect vertices to chain
|
||||
function connectVertices(start, t) {
|
||||
const chain = []; // vertices chain to form a path
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ const generate = function(changeHeights = true) {
|
|||
cells.conf = new Uint8Array(cells.i.length); // confluences array
|
||||
let riverNext = 1; // first river id is 1
|
||||
|
||||
markupLand();
|
||||
const h = alterHeights();
|
||||
removeStoredLakeData();
|
||||
resolveDepressions(h);
|
||||
|
|
@ -27,16 +26,6 @@ const generate = function(changeHeights = true) {
|
|||
|
||||
TIME && console.timeEnd('generateRivers');
|
||||
|
||||
// build distance field in cells from water (cells.t)
|
||||
function markupLand() {
|
||||
const q = t => cells.i.filter(i => cells.t[i] === t);
|
||||
for (let t = 2, queue = q(t); queue.length; t++, queue = q(t)) {
|
||||
queue.forEach(i => cells.c[i].forEach(c => {
|
||||
if (!cells.t[c]) cells.t[c] = t+1;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
// height with added t value to make map less depressed
|
||||
function alterHeights() {
|
||||
const h = Array.from(cells.h)
|
||||
|
|
|
|||
|
|
@ -169,6 +169,7 @@ function editHeightmap() {
|
|||
|
||||
const change = changeHeights.checked;
|
||||
markFeatures();
|
||||
getSignedDistanceField();
|
||||
if (change) openNearSeaLakes();
|
||||
OceanLayers();
|
||||
calculateTemperatures();
|
||||
|
|
@ -284,6 +285,7 @@ function editHeightmap() {
|
|||
});
|
||||
|
||||
markFeatures();
|
||||
getSignedDistanceField();
|
||||
OceanLayers();
|
||||
calculateTemperatures();
|
||||
generatePrecipitation();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue