bimdown-cli 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +708 -137
- package/dist/index.js.map +1 -1
- package/dist/spec/csv-schema/architecture/space.yaml +10 -0
- package/dist/spec/readme.md +3 -3
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -155,7 +155,7 @@ var init_registry = __esm({
|
|
|
155
155
|
mesh: "ms"
|
|
156
156
|
};
|
|
157
157
|
GLOBAL_ONLY_TABLES = /* @__PURE__ */ new Set(["level", "grid", "mesh"]);
|
|
158
|
-
TABLES_WITHOUT_SVG = /* @__PURE__ */ new Set(["level", "grid", "door", "window", "
|
|
158
|
+
TABLES_WITHOUT_SVG = /* @__PURE__ */ new Set(["level", "grid", "door", "window", "mesh"]);
|
|
159
159
|
SVG_FILE_NAMES = Object.fromEntries(
|
|
160
160
|
Object.keys(ID_PREFIXES).filter((k) => !TABLES_WITHOUT_SVG.has(k)).map((k) => [k, k])
|
|
161
161
|
);
|
|
@@ -518,8 +518,8 @@ var hydrate_exports = {};
|
|
|
518
518
|
__export(hydrate_exports, {
|
|
519
519
|
hydrate: () => hydrate
|
|
520
520
|
});
|
|
521
|
-
import { existsSync as
|
|
522
|
-
import { join as
|
|
521
|
+
import { existsSync as existsSync8 } from "fs";
|
|
522
|
+
import { join as join9 } from "path";
|
|
523
523
|
async function hydrate(conn, dir) {
|
|
524
524
|
const registry = buildRegistry(getSpecDir());
|
|
525
525
|
const layout = discoverLayout(dir);
|
|
@@ -531,8 +531,8 @@ async function hydrate(conn, dir) {
|
|
|
531
531
|
for (const [tableName, table] of registry) {
|
|
532
532
|
const csvFiles = [];
|
|
533
533
|
for (const d of allDirs) {
|
|
534
|
-
const csvPath =
|
|
535
|
-
if (
|
|
534
|
+
const csvPath = join9(d.path, `${tableName}.csv`);
|
|
535
|
+
if (existsSync8(csvPath)) {
|
|
536
536
|
csvFiles.push({ dir: d.name, fullPath: csvPath });
|
|
537
537
|
}
|
|
538
538
|
}
|
|
@@ -565,8 +565,8 @@ async function injectGeometry(conn, tableName, dirs) {
|
|
|
565
565
|
const geometries = /* @__PURE__ */ new Map();
|
|
566
566
|
for (const d of dirs) {
|
|
567
567
|
if (d.name === "global") continue;
|
|
568
|
-
const svgPath =
|
|
569
|
-
if (!
|
|
568
|
+
const svgPath = join9(d.path, `${svgName}.svg`);
|
|
569
|
+
if (!existsSync8(svgPath)) continue;
|
|
570
570
|
try {
|
|
571
571
|
const svg = parseSvgFile(svgPath);
|
|
572
572
|
for (const el of svg.elements) {
|
|
@@ -626,8 +626,8 @@ var dehydrate_exports = {};
|
|
|
626
626
|
__export(dehydrate_exports, {
|
|
627
627
|
dehydrate: () => dehydrate
|
|
628
628
|
});
|
|
629
|
-
import { existsSync as
|
|
630
|
-
import { join as
|
|
629
|
+
import { existsSync as existsSync9, mkdirSync } from "fs";
|
|
630
|
+
import { join as join10 } from "path";
|
|
631
631
|
async function dehydrate(conn, dir) {
|
|
632
632
|
const registry = buildRegistry(getSpecDir());
|
|
633
633
|
for (const [tableName, table] of registry) {
|
|
@@ -643,8 +643,8 @@ async function dehydrate(conn, dir) {
|
|
|
643
643
|
);
|
|
644
644
|
for (const partRow of partResult.rows) {
|
|
645
645
|
const partition = String(partRow._partition);
|
|
646
|
-
const outDir =
|
|
647
|
-
if (!
|
|
646
|
+
const outDir = join10(dir, partition);
|
|
647
|
+
if (!existsSync9(outDir)) mkdirSync(outDir, { recursive: true });
|
|
648
648
|
const selectCols = csvHeaders.map((h) => `"${h}"`).join(", ");
|
|
649
649
|
const dataResult = await runQuery(
|
|
650
650
|
conn,
|
|
@@ -661,7 +661,7 @@ async function dehydrate(conn, dir) {
|
|
|
661
661
|
return row;
|
|
662
662
|
})
|
|
663
663
|
};
|
|
664
|
-
writeCsv(
|
|
664
|
+
writeCsv(join10(outDir, `${tableName}.csv`), data);
|
|
665
665
|
}
|
|
666
666
|
}
|
|
667
667
|
}
|
|
@@ -679,8 +679,8 @@ var render_exports = {};
|
|
|
679
679
|
__export(render_exports, {
|
|
680
680
|
renderLevel: () => renderLevel
|
|
681
681
|
});
|
|
682
|
-
import { existsSync as
|
|
683
|
-
import { join as
|
|
682
|
+
import { existsSync as existsSync10 } from "fs";
|
|
683
|
+
import { join as join11 } from "path";
|
|
684
684
|
function elementBounds2(el) {
|
|
685
685
|
switch (el.tag) {
|
|
686
686
|
case "path": {
|
|
@@ -766,8 +766,8 @@ function escapeXml(s) {
|
|
|
766
766
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
767
767
|
}
|
|
768
768
|
function renderHostedElements(levelDir, tableName, wallElements) {
|
|
769
|
-
const csvPath =
|
|
770
|
-
if (!
|
|
769
|
+
const csvPath = join11(levelDir.path, `${tableName}.csv`);
|
|
770
|
+
if (!existsSync10(csvPath)) return [];
|
|
771
771
|
const csv = readCsv(csvPath);
|
|
772
772
|
const color = COLORS[tableName] ?? DEFAULT_COLOR;
|
|
773
773
|
const results = [];
|
|
@@ -822,11 +822,52 @@ function renderHostedElements(levelDir, tableName, wallElements) {
|
|
|
822
822
|
return results;
|
|
823
823
|
}
|
|
824
824
|
function renderSpaces(levelDir) {
|
|
825
|
-
const csvPath =
|
|
826
|
-
if (!
|
|
825
|
+
const csvPath = join11(levelDir.path, "space.csv");
|
|
826
|
+
if (!existsSync10(csvPath)) return [];
|
|
827
827
|
const csv = readCsv(csvPath);
|
|
828
828
|
const color = COLORS.space ?? DEFAULT_COLOR;
|
|
829
829
|
const results = [];
|
|
830
|
+
const nameMap = /* @__PURE__ */ new Map();
|
|
831
|
+
for (const row of csv.rows) {
|
|
832
|
+
nameMap.set(row.id, row.name ?? row.id ?? "");
|
|
833
|
+
}
|
|
834
|
+
const svgPath = join11(levelDir.path, "space.svg");
|
|
835
|
+
if (existsSync10(svgPath)) {
|
|
836
|
+
try {
|
|
837
|
+
const svg = parseSvgFile(svgPath);
|
|
838
|
+
for (const el of svg.elements) {
|
|
839
|
+
if (el.tag !== "polygon") continue;
|
|
840
|
+
const points = (el.attrs.points ?? "").trim().split(/\s+/).map((p) => {
|
|
841
|
+
const [x, y] = p.split(",").map(Number);
|
|
842
|
+
return { x: x ?? 0, y: y ?? 0 };
|
|
843
|
+
});
|
|
844
|
+
if (points.length < 3) continue;
|
|
845
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
846
|
+
let cx = 0, cy = 0;
|
|
847
|
+
for (const p of points) {
|
|
848
|
+
minX = Math.min(minX, p.x);
|
|
849
|
+
minY = Math.min(minY, p.y);
|
|
850
|
+
maxX = Math.max(maxX, p.x);
|
|
851
|
+
maxY = Math.max(maxY, p.y);
|
|
852
|
+
cx += p.x;
|
|
853
|
+
cy += p.y;
|
|
854
|
+
}
|
|
855
|
+
cx /= points.length;
|
|
856
|
+
cy /= points.length;
|
|
857
|
+
const name = nameMap.get(el.id) ?? el.id;
|
|
858
|
+
let markup = ` <polygon id="${el.id}" points="${el.attrs.points}" fill="${color.fill ?? "none"}" stroke="${color.stroke}" stroke-width="0.03" />`;
|
|
859
|
+
markup += `
|
|
860
|
+
<text x="${cx.toFixed(3)}" y="${cy.toFixed(3)}" font-size="0.4" fill="${color.stroke}" text-anchor="middle" dominant-baseline="central" transform="scale(1,-1) translate(0,${(-2 * cy).toFixed(3)})">${escapeXml(name)}</text>`;
|
|
861
|
+
results.push({
|
|
862
|
+
tableName: "space",
|
|
863
|
+
svgMarkup: markup,
|
|
864
|
+
bounds: { minX, minY, maxX, maxY }
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
if (results.length > 0) return results;
|
|
868
|
+
} catch {
|
|
869
|
+
}
|
|
870
|
+
}
|
|
830
871
|
for (const row of csv.rows) {
|
|
831
872
|
const x = parseFloat(row.x ?? "");
|
|
832
873
|
const y = parseFloat(row.y ?? "");
|
|
@@ -858,8 +899,8 @@ function renderLevel(projectDir, levelId) {
|
|
|
858
899
|
if (CSV_ONLY_TABLES.has(tableName)) continue;
|
|
859
900
|
const svgName = SVG_FILE_NAMES[tableName];
|
|
860
901
|
if (!svgName) continue;
|
|
861
|
-
const svgPath =
|
|
862
|
-
if (!
|
|
902
|
+
const svgPath = join11(levelDir.path, svgName + ".svg");
|
|
903
|
+
if (!existsSync10(svgPath)) continue;
|
|
863
904
|
const svg = parseSvgFile(svgPath);
|
|
864
905
|
for (const el of svg.elements) {
|
|
865
906
|
allElements.push({ tableName, el });
|
|
@@ -968,8 +1009,8 @@ var resolve_topology_exports = {};
|
|
|
968
1009
|
__export(resolve_topology_exports, {
|
|
969
1010
|
resolveTopology: () => resolveTopology
|
|
970
1011
|
});
|
|
971
|
-
import { existsSync as
|
|
972
|
-
import { join as
|
|
1012
|
+
import { existsSync as existsSync11, mkdirSync as mkdirSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
1013
|
+
import { join as join12 } from "path";
|
|
973
1014
|
function dist3d(a, b) {
|
|
974
1015
|
const dx = a.x - b.x;
|
|
975
1016
|
const dy = a.y - b.y;
|
|
@@ -978,10 +1019,10 @@ function dist3d(a, b) {
|
|
|
978
1019
|
}
|
|
979
1020
|
function insideBBox(point, node) {
|
|
980
1021
|
const dz = Math.abs(point.z - node.pos.z);
|
|
981
|
-
if (dz >
|
|
1022
|
+
if (dz > TOLERANCE3) return false;
|
|
982
1023
|
const dx = Math.abs(point.x - node.pos.x);
|
|
983
1024
|
const dy = Math.abs(point.y - node.pos.y);
|
|
984
|
-
return dx <= node.halfW +
|
|
1025
|
+
return dx <= node.halfW + TOLERANCE3 && dy <= node.halfH + TOLERANCE3;
|
|
985
1026
|
}
|
|
986
1027
|
function resolveTopology(dir) {
|
|
987
1028
|
buildRegistry(getSpecDir());
|
|
@@ -996,14 +1037,14 @@ function resolveTopology(dir) {
|
|
|
996
1037
|
let skippedStart = 0;
|
|
997
1038
|
let skippedEnd = 0;
|
|
998
1039
|
for (const d of allDirs) {
|
|
999
|
-
if (!
|
|
1040
|
+
if (!existsSync11(d.path)) continue;
|
|
1000
1041
|
const files = listFiles(d.path);
|
|
1001
1042
|
for (const tableName of CURVE_TABLES) {
|
|
1002
1043
|
if (!files.includes(`${tableName}.csv`)) continue;
|
|
1003
1044
|
const svgName = SVG_FILE_NAMES[tableName];
|
|
1004
1045
|
if (!svgName || !files.includes(`${svgName}.svg`)) continue;
|
|
1005
|
-
const csvPath =
|
|
1006
|
-
const svgPath =
|
|
1046
|
+
const csvPath = join12(d.path, `${tableName}.csv`);
|
|
1047
|
+
const svgPath = join12(d.path, `${svgName}.svg`);
|
|
1007
1048
|
const csv = readCsv(csvPath);
|
|
1008
1049
|
const key = `${d.name}/${tableName}`;
|
|
1009
1050
|
curveData.set(key, { csv, path: csvPath });
|
|
@@ -1053,14 +1094,14 @@ function resolveTopology(dir) {
|
|
|
1053
1094
|
}
|
|
1054
1095
|
const nodes = [];
|
|
1055
1096
|
for (const d of allDirs) {
|
|
1056
|
-
if (!
|
|
1097
|
+
if (!existsSync11(d.path)) continue;
|
|
1057
1098
|
const files = listFiles(d.path);
|
|
1058
1099
|
for (const tableName of NODE_TABLES) {
|
|
1059
1100
|
if (!files.includes(`${tableName}.csv`)) continue;
|
|
1060
1101
|
const svgName = SVG_FILE_NAMES[tableName];
|
|
1061
1102
|
if (!svgName || !files.includes(`${svgName}.svg`)) continue;
|
|
1062
|
-
const csvPath =
|
|
1063
|
-
const svgPath =
|
|
1103
|
+
const csvPath = join12(d.path, `${tableName}.csv`);
|
|
1104
|
+
const svgPath = join12(d.path, `${svgName}.svg`);
|
|
1064
1105
|
const csv = readCsv(csvPath);
|
|
1065
1106
|
let svgElements;
|
|
1066
1107
|
try {
|
|
@@ -1115,7 +1156,7 @@ function resolveTopology(dir) {
|
|
|
1115
1156
|
for (const ep of stillFree) {
|
|
1116
1157
|
let found = false;
|
|
1117
1158
|
for (const j of junctions) {
|
|
1118
|
-
if (dist3d(ep.point, j.point) <
|
|
1159
|
+
if (dist3d(ep.point, j.point) < TOLERANCE3) {
|
|
1119
1160
|
j.endpoints.push(ep);
|
|
1120
1161
|
found = true;
|
|
1121
1162
|
break;
|
|
@@ -1155,12 +1196,12 @@ function resolveTopology(dir) {
|
|
|
1155
1196
|
newNodesByLevel.set(j.levelDir, arr);
|
|
1156
1197
|
}
|
|
1157
1198
|
for (const [levelDir, levelJunctions] of newNodesByLevel) {
|
|
1158
|
-
const dirPath = levelDir === "global" ? layout.globalDir :
|
|
1159
|
-
if (!
|
|
1160
|
-
const csvPath =
|
|
1161
|
-
const svgPath =
|
|
1199
|
+
const dirPath = levelDir === "global" ? layout.globalDir : join12(dir, levelDir);
|
|
1200
|
+
if (!existsSync11(dirPath)) mkdirSync2(dirPath, { recursive: true });
|
|
1201
|
+
const csvPath = join12(dirPath, "mep_node.csv");
|
|
1202
|
+
const svgPath = join12(dirPath, "mep_node.svg");
|
|
1162
1203
|
let csv;
|
|
1163
|
-
if (
|
|
1204
|
+
if (existsSync11(csvPath)) {
|
|
1164
1205
|
csv = readCsv(csvPath);
|
|
1165
1206
|
} else {
|
|
1166
1207
|
csv = { headers: ["id", "number", "base_offset", "system_type"], rows: [] };
|
|
@@ -1169,7 +1210,7 @@ function resolveTopology(dir) {
|
|
|
1169
1210
|
if (!csv.headers.includes(h)) csv.headers.push(h);
|
|
1170
1211
|
}
|
|
1171
1212
|
let existingSvgElements = [];
|
|
1172
|
-
if (
|
|
1213
|
+
if (existsSync11(svgPath)) {
|
|
1173
1214
|
try {
|
|
1174
1215
|
existingSvgElements = parseSvgFile(svgPath).elements;
|
|
1175
1216
|
} catch {
|
|
@@ -1222,7 +1263,7 @@ function resolveTopology(dir) {
|
|
|
1222
1263
|
const pad = Math.max(maxX - minX, maxY - minY) * 0.02;
|
|
1223
1264
|
viewBox = `${(minX - pad).toFixed(3)} ${(-(maxY + pad)).toFixed(3)} ${(maxX - minX + pad * 2).toFixed(3)} ${(maxY - minY + pad * 2).toFixed(3)}`;
|
|
1224
1265
|
}
|
|
1225
|
-
|
|
1266
|
+
writeFileSync3(svgPath, [
|
|
1226
1267
|
'<?xml version="1.0" encoding="utf-8"?>',
|
|
1227
1268
|
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="${viewBox}">`,
|
|
1228
1269
|
' <g transform="scale(1,-1)">',
|
|
@@ -1271,7 +1312,7 @@ function resolveTopology(dir) {
|
|
|
1271
1312
|
console.log(`Updated ${updatedRows} curve rows`);
|
|
1272
1313
|
}
|
|
1273
1314
|
}
|
|
1274
|
-
var
|
|
1315
|
+
var TOLERANCE3, CURVE_TABLES, NODE_TABLES;
|
|
1275
1316
|
var init_resolve_topology = __esm({
|
|
1276
1317
|
"src/commands/resolve-topology.ts"() {
|
|
1277
1318
|
"use strict";
|
|
@@ -1279,7 +1320,7 @@ var init_resolve_topology = __esm({
|
|
|
1279
1320
|
init_svg();
|
|
1280
1321
|
init_fs();
|
|
1281
1322
|
init_registry();
|
|
1282
|
-
|
|
1323
|
+
TOLERANCE3 = 0.01;
|
|
1283
1324
|
CURVE_TABLES = ["duct", "pipe", "cable_tray", "conduit"];
|
|
1284
1325
|
NODE_TABLES = ["equipment", "terminal", "mep_node"];
|
|
1285
1326
|
}
|
|
@@ -1290,8 +1331,8 @@ var merge_exports = {};
|
|
|
1290
1331
|
__export(merge_exports, {
|
|
1291
1332
|
merge: () => merge
|
|
1292
1333
|
});
|
|
1293
|
-
import { existsSync as
|
|
1294
|
-
import { join as
|
|
1334
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync3, writeFileSync as writeFileSync4 } from "fs";
|
|
1335
|
+
import { join as join13, basename as basename2 } from "path";
|
|
1295
1336
|
async function merge(dirs, outputDir) {
|
|
1296
1337
|
const registry = buildRegistry(getSpecDir());
|
|
1297
1338
|
console.log(`Scanning ${dirs.length} sources...`);
|
|
@@ -1301,10 +1342,10 @@ async function merge(dirs, outputDir) {
|
|
|
1301
1342
|
const { canonicalGrids, gridRemaps } = deduplicateGrids(sources);
|
|
1302
1343
|
console.log(`Merged grids: ${canonicalGrids.rows.length} unique grids`);
|
|
1303
1344
|
const fullRemaps = buildFullRemaps(sources, levelRemaps, gridRemaps, registry);
|
|
1304
|
-
mkdirSync3(
|
|
1305
|
-
writeCsv(
|
|
1345
|
+
mkdirSync3(join13(outputDir, "global"), { recursive: true });
|
|
1346
|
+
writeCsv(join13(outputDir, "global", "level.csv"), canonicalLevels);
|
|
1306
1347
|
if (canonicalGrids.rows.length > 0) {
|
|
1307
|
-
writeCsv(
|
|
1348
|
+
writeCsv(join13(outputDir, "global", "grid.csv"), canonicalGrids);
|
|
1308
1349
|
}
|
|
1309
1350
|
writeIdMap(outputDir, sources, fullRemaps);
|
|
1310
1351
|
const levelDirMap = buildLevelDirMap(sources, fullRemaps);
|
|
@@ -1315,26 +1356,26 @@ async function merge(dirs, outputDir) {
|
|
|
1315
1356
|
function scanSource(dir, registry) {
|
|
1316
1357
|
const layout = discoverLayout(dir);
|
|
1317
1358
|
const name = basename2(dir);
|
|
1318
|
-
const levelPath =
|
|
1319
|
-
if (!
|
|
1359
|
+
const levelPath = join13(layout.globalDir, "level.csv");
|
|
1360
|
+
if (!existsSync12(levelPath)) {
|
|
1320
1361
|
throw new Error(`Missing level.csv in ${dir}/global/`);
|
|
1321
1362
|
}
|
|
1322
1363
|
const levels = readCsv(levelPath);
|
|
1323
|
-
const gridPath =
|
|
1324
|
-
const grids =
|
|
1325
|
-
const idMapPath =
|
|
1326
|
-
const idMap =
|
|
1364
|
+
const gridPath = join13(layout.globalDir, "grid.csv");
|
|
1365
|
+
const grids = existsSync12(gridPath) ? readCsv(gridPath) : null;
|
|
1366
|
+
const idMapPath = join13(layout.globalDir, "_IdMap.csv");
|
|
1367
|
+
const idMap = existsSync12(idMapPath) ? readCsv(idMapPath) : null;
|
|
1327
1368
|
const globalData = /* @__PURE__ */ new Map();
|
|
1328
|
-
if (
|
|
1369
|
+
if (existsSync12(layout.globalDir)) {
|
|
1329
1370
|
for (const f of listFiles(layout.globalDir)) {
|
|
1330
1371
|
if (!f.endsWith(".csv")) continue;
|
|
1331
1372
|
const tableName = f.replace(".csv", "");
|
|
1332
1373
|
if (tableName === "level" || tableName === "grid" || tableName === "_IdMap") continue;
|
|
1333
1374
|
if (!registry.has(tableName)) continue;
|
|
1334
|
-
const csv = readCsv(
|
|
1375
|
+
const csv = readCsv(join13(layout.globalDir, f));
|
|
1335
1376
|
const svgName = SVG_FILE_NAMES[tableName];
|
|
1336
|
-
const svgFile = svgName ?
|
|
1337
|
-
globalData.set(tableName, { csv, svgFile: svgFile &&
|
|
1377
|
+
const svgFile = svgName ? join13(layout.globalDir, svgName + ".svg") : null;
|
|
1378
|
+
globalData.set(tableName, { csv, svgFile: svgFile && existsSync12(svgFile) ? svgFile : null });
|
|
1338
1379
|
}
|
|
1339
1380
|
}
|
|
1340
1381
|
const levelData = /* @__PURE__ */ new Map();
|
|
@@ -1344,10 +1385,10 @@ function scanSource(dir, registry) {
|
|
|
1344
1385
|
if (!f.endsWith(".csv")) continue;
|
|
1345
1386
|
const tableName = f.replace(".csv", "");
|
|
1346
1387
|
if (!registry.has(tableName)) continue;
|
|
1347
|
-
const csv = readCsv(
|
|
1388
|
+
const csv = readCsv(join13(ld.path, f));
|
|
1348
1389
|
const svgName = SVG_FILE_NAMES[tableName];
|
|
1349
|
-
const svgFile = svgName ?
|
|
1350
|
-
tables.set(tableName, { csv, svgFile: svgFile &&
|
|
1390
|
+
const svgFile = svgName ? join13(ld.path, svgName + ".svg") : null;
|
|
1391
|
+
tables.set(tableName, { csv, svgFile: svgFile && existsSync12(svgFile) ? svgFile : null });
|
|
1351
1392
|
}
|
|
1352
1393
|
if (tables.size > 0) {
|
|
1353
1394
|
levelData.set(ld.name, tables);
|
|
@@ -1534,7 +1575,7 @@ function writeIdMap(outputDir, sources, remaps) {
|
|
|
1534
1575
|
}
|
|
1535
1576
|
}
|
|
1536
1577
|
if (rows.length > 0) {
|
|
1537
|
-
writeCsv(
|
|
1578
|
+
writeCsv(join13(outputDir, "global", "_IdMap.csv"), { headers: ["id", "uuid"], rows });
|
|
1538
1579
|
}
|
|
1539
1580
|
}
|
|
1540
1581
|
function buildLevelDirMap(sources, remaps) {
|
|
@@ -1575,13 +1616,13 @@ function writeGlobalTables(outputDir, sources, remaps, registry) {
|
|
|
1575
1616
|
}
|
|
1576
1617
|
for (const [tableName, entry] of merged) {
|
|
1577
1618
|
if (entry.rows.length > 0) {
|
|
1578
|
-
writeCsv(
|
|
1619
|
+
writeCsv(join13(outputDir, "global", tableName + ".csv"), { headers: entry.headers, rows: entry.rows });
|
|
1579
1620
|
}
|
|
1580
1621
|
if (entry.svgInputs.length > 0) {
|
|
1581
1622
|
const svgName = SVG_FILE_NAMES[tableName];
|
|
1582
1623
|
if (svgName) {
|
|
1583
1624
|
const content = writeMergedSvg(entry.svgInputs);
|
|
1584
|
-
|
|
1625
|
+
writeFileSync4(join13(outputDir, "global", svgName + ".svg"), content, "utf-8");
|
|
1585
1626
|
}
|
|
1586
1627
|
}
|
|
1587
1628
|
}
|
|
@@ -1613,17 +1654,17 @@ function writeLevelTables(outputDir, sources, remaps, levelDirMap, registry) {
|
|
|
1613
1654
|
}
|
|
1614
1655
|
}
|
|
1615
1656
|
for (const [outDirName, tables] of merged) {
|
|
1616
|
-
const dirPath =
|
|
1657
|
+
const dirPath = join13(outputDir, outDirName);
|
|
1617
1658
|
mkdirSync3(dirPath, { recursive: true });
|
|
1618
1659
|
for (const [tableName, entry] of tables) {
|
|
1619
1660
|
if (entry.rows.length > 0) {
|
|
1620
|
-
writeCsv(
|
|
1661
|
+
writeCsv(join13(dirPath, tableName + ".csv"), { headers: entry.headers, rows: entry.rows });
|
|
1621
1662
|
}
|
|
1622
1663
|
if (entry.svgInputs.length > 0) {
|
|
1623
1664
|
const svgName = SVG_FILE_NAMES[tableName];
|
|
1624
1665
|
if (svgName) {
|
|
1625
1666
|
const content = writeMergedSvg(entry.svgInputs);
|
|
1626
|
-
|
|
1667
|
+
writeFileSync4(join13(dirPath, svgName + ".svg"), content, "utf-8");
|
|
1627
1668
|
}
|
|
1628
1669
|
}
|
|
1629
1670
|
}
|
|
@@ -1655,29 +1696,29 @@ var init_exports = {};
|
|
|
1655
1696
|
__export(init_exports, {
|
|
1656
1697
|
initProject: () => initProject
|
|
1657
1698
|
});
|
|
1658
|
-
import { mkdirSync as mkdirSync4, writeFileSync as
|
|
1659
|
-
import { join as
|
|
1699
|
+
import { mkdirSync as mkdirSync4, writeFileSync as writeFileSync5, existsSync as existsSync13 } from "fs";
|
|
1700
|
+
import { join as join14 } from "path";
|
|
1660
1701
|
function initProject(absDir) {
|
|
1661
|
-
if (!
|
|
1702
|
+
if (!existsSync13(absDir)) {
|
|
1662
1703
|
mkdirSync4(absDir, { recursive: true });
|
|
1663
1704
|
}
|
|
1664
|
-
|
|
1665
|
-
const globalDir =
|
|
1666
|
-
if (!
|
|
1705
|
+
writeFileSync5(join14(absDir, ".bimdown"), "", "utf-8");
|
|
1706
|
+
const globalDir = join14(absDir, "global");
|
|
1707
|
+
if (!existsSync13(globalDir)) {
|
|
1667
1708
|
mkdirSync4(globalDir, { recursive: true });
|
|
1668
1709
|
}
|
|
1669
|
-
const levelCsvPath =
|
|
1670
|
-
if (!
|
|
1671
|
-
|
|
1710
|
+
const levelCsvPath = join14(globalDir, "level.csv");
|
|
1711
|
+
if (!existsSync13(levelCsvPath)) {
|
|
1712
|
+
writeFileSync5(levelCsvPath, "id,name,elevation\nlv-1,Level 1,0.0\n", "utf-8");
|
|
1672
1713
|
}
|
|
1673
|
-
const gridCsvPath =
|
|
1674
|
-
if (!
|
|
1714
|
+
const gridCsvPath = join14(globalDir, "grid.csv");
|
|
1715
|
+
if (!existsSync13(gridCsvPath)) {
|
|
1675
1716
|
const gridContent = [
|
|
1676
1717
|
"id,name,role,start_x,start_y,end_x,end_y",
|
|
1677
1718
|
"gr-1,A,primary,-10000,0,10000,0",
|
|
1678
1719
|
"gr-2,1,primary,0,-10000,0,10000"
|
|
1679
1720
|
].join("\n") + "\n";
|
|
1680
|
-
|
|
1721
|
+
writeFileSync5(gridCsvPath, gridContent, "utf-8");
|
|
1681
1722
|
}
|
|
1682
1723
|
console.log(`Initialized empty BimDown project at ${absDir}`);
|
|
1683
1724
|
console.log("Created:");
|
|
@@ -1695,15 +1736,15 @@ var diff_exports = {};
|
|
|
1695
1736
|
__export(diff_exports, {
|
|
1696
1737
|
diffProjects: () => diffProjects
|
|
1697
1738
|
});
|
|
1698
|
-
import { existsSync as
|
|
1699
|
-
import { join as
|
|
1739
|
+
import { existsSync as existsSync14 } from "fs";
|
|
1740
|
+
import { join as join15 } from "path";
|
|
1700
1741
|
function diffProjects(dirA, dirB) {
|
|
1701
|
-
if (!
|
|
1742
|
+
if (!existsSync14(dirA)) {
|
|
1702
1743
|
console.error(`Directory not found: ${dirA}`);
|
|
1703
1744
|
process.exitCode = 1;
|
|
1704
1745
|
return;
|
|
1705
1746
|
}
|
|
1706
|
-
if (!
|
|
1747
|
+
if (!existsSync14(dirB)) {
|
|
1707
1748
|
console.error(`Directory not found: ${dirB}`);
|
|
1708
1749
|
process.exitCode = 1;
|
|
1709
1750
|
return;
|
|
@@ -1722,22 +1763,22 @@ function diffProjects(dirA, dirB) {
|
|
|
1722
1763
|
for (const pathName of allPathNames) {
|
|
1723
1764
|
const dirAAbs = pathsA.find((p) => p.name === pathName)?.abs;
|
|
1724
1765
|
const dirBAbs = pathsB.find((p) => p.name === pathName)?.abs;
|
|
1725
|
-
const filesA = new Set(dirAAbs &&
|
|
1726
|
-
const filesB = new Set(dirBAbs &&
|
|
1766
|
+
const filesA = new Set(dirAAbs && existsSync14(dirAAbs) ? listFiles(dirAAbs).filter((f) => f.endsWith(".csv")) : []);
|
|
1767
|
+
const filesB = new Set(dirBAbs && existsSync14(dirBAbs) ? listFiles(dirBAbs).filter((f) => f.endsWith(".csv")) : []);
|
|
1727
1768
|
const allFiles = /* @__PURE__ */ new Set([...filesA, ...filesB]);
|
|
1728
1769
|
let printedPathHeader = false;
|
|
1729
1770
|
for (const f of allFiles) {
|
|
1730
1771
|
const tableName = f.replace(".csv", "");
|
|
1731
|
-
const pathFileA = dirAAbs ?
|
|
1732
|
-
const pathFileB = dirBAbs ?
|
|
1772
|
+
const pathFileA = dirAAbs ? join15(dirAAbs, f) : null;
|
|
1773
|
+
const pathFileB = dirBAbs ? join15(dirBAbs, f) : null;
|
|
1733
1774
|
const rowsA = {};
|
|
1734
1775
|
const rowsB = {};
|
|
1735
|
-
if (pathFileA &&
|
|
1776
|
+
if (pathFileA && existsSync14(pathFileA)) {
|
|
1736
1777
|
for (const row of readCsv(pathFileA).rows) {
|
|
1737
1778
|
if (row.id) rowsA[String(row.id)] = row;
|
|
1738
1779
|
}
|
|
1739
1780
|
}
|
|
1740
|
-
if (pathFileB &&
|
|
1781
|
+
if (pathFileB && existsSync14(pathFileB)) {
|
|
1741
1782
|
for (const row of readCsv(pathFileB).rows) {
|
|
1742
1783
|
if (row.id) rowsB[String(row.id)] = row;
|
|
1743
1784
|
}
|
|
@@ -1778,16 +1819,98 @@ var init_diff = __esm({
|
|
|
1778
1819
|
}
|
|
1779
1820
|
});
|
|
1780
1821
|
|
|
1822
|
+
// src/commands/publish.ts
|
|
1823
|
+
var publish_exports = {};
|
|
1824
|
+
__export(publish_exports, {
|
|
1825
|
+
publish: () => publish
|
|
1826
|
+
});
|
|
1827
|
+
import { resolve } from "path";
|
|
1828
|
+
import { readFileSync as readFileSync5, existsSync as existsSync15 } from "fs";
|
|
1829
|
+
import { zipSync } from "fflate";
|
|
1830
|
+
async function publish(dir, opts) {
|
|
1831
|
+
const absDir = resolve(dir);
|
|
1832
|
+
if (!existsSync15(absDir)) {
|
|
1833
|
+
console.error(`Directory not found: ${absDir}`);
|
|
1834
|
+
process.exitCode = 1;
|
|
1835
|
+
return;
|
|
1836
|
+
}
|
|
1837
|
+
const apiBase = (opts.api || process.env.BIMCLAW_API || DEFAULT_API).replace(/\/$/, "");
|
|
1838
|
+
const expires = opts.expires || DEFAULT_EXPIRES;
|
|
1839
|
+
const layout = discoverLayout(absDir);
|
|
1840
|
+
const allDirs = [
|
|
1841
|
+
{ prefix: "global", path: layout.globalDir },
|
|
1842
|
+
...layout.levelDirs.map((d) => ({ prefix: d.name, path: d.path }))
|
|
1843
|
+
];
|
|
1844
|
+
const files = {};
|
|
1845
|
+
for (const d of allDirs) {
|
|
1846
|
+
if (!existsSync15(d.path)) continue;
|
|
1847
|
+
for (const f of listFiles(d.path)) {
|
|
1848
|
+
const filePath = `${d.prefix}/${f}`;
|
|
1849
|
+
const content = readFileSync5(resolve(d.path, f));
|
|
1850
|
+
files[filePath] = new Uint8Array(content);
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
const metadataPath = resolve(absDir, "project_metadata.json");
|
|
1854
|
+
if (existsSync15(metadataPath)) {
|
|
1855
|
+
files["project_metadata.json"] = new Uint8Array(readFileSync5(metadataPath));
|
|
1856
|
+
}
|
|
1857
|
+
const fileCount = Object.keys(files).length;
|
|
1858
|
+
if (fileCount === 0) {
|
|
1859
|
+
console.error("No files found in project directory.");
|
|
1860
|
+
process.exitCode = 1;
|
|
1861
|
+
return;
|
|
1862
|
+
}
|
|
1863
|
+
const zipData = zipSync(files);
|
|
1864
|
+
const sizeMB = (zipData.byteLength / 1024 / 1024).toFixed(1);
|
|
1865
|
+
console.log(`Packed ${fileCount} files (${sizeMB} MB)`);
|
|
1866
|
+
const projectName = opts.name || absDir.split("/").pop() || "Untitled";
|
|
1867
|
+
const url = `${apiBase}/api/shares/publish`;
|
|
1868
|
+
const formData = new FormData();
|
|
1869
|
+
formData.append("file", new Blob([zipData], { type: "application/zip" }), `${projectName}.zip`);
|
|
1870
|
+
formData.append("name", projectName);
|
|
1871
|
+
formData.append("expires", expires);
|
|
1872
|
+
try {
|
|
1873
|
+
const resp = await fetch(url, {
|
|
1874
|
+
method: "POST",
|
|
1875
|
+
body: formData
|
|
1876
|
+
});
|
|
1877
|
+
if (!resp.ok) {
|
|
1878
|
+
const body = await resp.text();
|
|
1879
|
+
console.error(`Publish failed (${resp.status}): ${body}`);
|
|
1880
|
+
process.exitCode = 1;
|
|
1881
|
+
return;
|
|
1882
|
+
}
|
|
1883
|
+
const result = await resp.json();
|
|
1884
|
+
console.log(`
|
|
1885
|
+
\u2705 Published: ${result.url}`);
|
|
1886
|
+
if (result.expiresAt) {
|
|
1887
|
+
console.log(` Expires: ${new Date(result.expiresAt).toLocaleString()}`);
|
|
1888
|
+
}
|
|
1889
|
+
} catch (err) {
|
|
1890
|
+
console.error(`Publish failed: ${err.message}`);
|
|
1891
|
+
process.exitCode = 1;
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
var DEFAULT_API, DEFAULT_EXPIRES;
|
|
1895
|
+
var init_publish = __esm({
|
|
1896
|
+
"src/commands/publish.ts"() {
|
|
1897
|
+
"use strict";
|
|
1898
|
+
init_fs();
|
|
1899
|
+
DEFAULT_API = "https://bim-claw.com";
|
|
1900
|
+
DEFAULT_EXPIRES = "7d";
|
|
1901
|
+
}
|
|
1902
|
+
});
|
|
1903
|
+
|
|
1781
1904
|
// src/commands/generate-skill.ts
|
|
1782
1905
|
var generate_skill_exports = {};
|
|
1783
1906
|
__export(generate_skill_exports, {
|
|
1784
1907
|
generateSkill: () => generateSkill
|
|
1785
1908
|
});
|
|
1786
|
-
import { existsSync as
|
|
1787
|
-
import { join as
|
|
1909
|
+
import { existsSync as existsSync16, mkdirSync as mkdirSync5, writeFileSync as writeFileSync6, readFileSync as readFileSync6 } from "fs";
|
|
1910
|
+
import { join as join16, resolve as resolve2 } from "path";
|
|
1788
1911
|
function generateSkill(outputDir) {
|
|
1789
1912
|
const specDir = getSpecDir();
|
|
1790
|
-
const csvSchemaDir =
|
|
1913
|
+
const csvSchemaDir = join16(specDir, "csv-schema");
|
|
1791
1914
|
const registry = buildRegistry(specDir);
|
|
1792
1915
|
const schemas = loadAllSchemas(csvSchemaDir);
|
|
1793
1916
|
const sortedNames = [...registry.keys()].sort();
|
|
@@ -1802,7 +1925,7 @@ function generateSkill(outputDir) {
|
|
|
1802
1925
|
const numericExamples = idExamples.filter((_, i) => !FREEFORM_ID_TABLES.has(Object.keys(ID_PREFIXES)[i]));
|
|
1803
1926
|
const today = /* @__PURE__ */ new Date();
|
|
1804
1927
|
const publishDate = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, "0")}-${String(today.getDate()).padStart(2, "0")}`;
|
|
1805
|
-
const cliVersion = true ? "0.2.
|
|
1928
|
+
const cliVersion = true ? "0.2.2" : "unknown";
|
|
1806
1929
|
let md = `---
|
|
1807
1930
|
name: bimdown
|
|
1808
1931
|
description: Powerful structural and topological manipulation tool for BimDown architectural BIM projects. Use when asked to query building elements, build new structures (CSV+SVG), resolve MEP topologies, or analyze spatial BIM data.
|
|
@@ -1844,7 +1967,7 @@ project/
|
|
|
1844
1967
|
lv-1/ # per-level files
|
|
1845
1968
|
wall.csv + wall.svg # elements with geometry have paired CSV+SVG
|
|
1846
1969
|
door.csv # hosted elements are CSV-only (parametric position on host wall)
|
|
1847
|
-
space.csv # spaces
|
|
1970
|
+
space.csv # spaces: CSV seed point + space.svg boundary (computed by build)
|
|
1848
1971
|
...
|
|
1849
1972
|
lv-2/
|
|
1850
1973
|
...
|
|
@@ -1861,27 +1984,77 @@ project/
|
|
|
1861
1984
|
2. **Write SVG geometry first**: Create the \`.svg\` files (walls, slabs, columns) with correct coordinates. Geometry determines everything else.
|
|
1862
1985
|
3. **Write CSV attributes second**: Create the \`.csv\` files with element properties (material, thickness, etc.). Remember: do NOT include computed fields like \`level_id\`, \`length\`, \`area\`.
|
|
1863
1986
|
4. **Render and visually verify**: Run \`bimdown render <dir> -o render.png\` and **view the PNG image** to confirm the layout is correct. Check that walls connect properly, rooms are enclosed, and doors/windows are in the right positions.
|
|
1864
|
-
5. **
|
|
1865
|
-
6. **Iterate**: If the render shows problems, fix the SVG geometry and re-render until the layout looks right.
|
|
1987
|
+
5. **Build**: Run \`bimdown build <dir>\` to validate schema, check geometry, and compute space boundaries (generates \`space.svg\` from seed points).
|
|
1988
|
+
6. **Iterate**: If the render or build shows problems, fix the SVG geometry and re-render until the layout looks right.
|
|
1989
|
+
7. **Publish**: Run \`bimdown publish <dir>\` to upload the project and get a shareable preview URL for the user to view the 3D model in their browser.
|
|
1866
1990
|
|
|
1867
1991
|
## CLI Tools & Best Practices
|
|
1868
1992
|
|
|
1869
1993
|
1. **\`bimdown query <dir> <sql> --json\`**: Runs DuckDB SQL across all tables, including SVG-derived virtual columns.
|
|
1870
1994
|
- **Example**: \`bimdown query ./proj "SELECT id, length FROM wall WHERE length > 5.0" --json\`
|
|
1871
1995
|
2. **\`bimdown render <dir> [-l level] [-o output.png] [-w width]\`**: Renders a level into a PNG blueprint image (default 2048px wide). Use \`.svg\` extension for SVG output. **Always render after modifying geometry and view the PNG to visually verify the result.**
|
|
1872
|
-
3. **\`bimdown
|
|
1996
|
+
3. **\`bimdown build <dir>\`**: Validates the project, checks geometry (wall connectivity, hosted element bounds), and computes space boundaries (generates \`space.svg\`). **Run this EVERY TIME after modifying CSV or SVG files!** Also available as \`bimdown validate\` (alias).
|
|
1873
1997
|
4. **\`bimdown schema [table]\`**: Prints the full schema for any element type. Use this to look up fields before creating elements.
|
|
1874
1998
|
5. **\`bimdown diff <dirA> <dirB>\`**: Emits a \`+\`, \`-\`, \`~\` structural difference between project snapshots.
|
|
1875
1999
|
6. **\`bimdown init <dir>\`**: Creates a new empty BimDown project with the correct directory structure.
|
|
2000
|
+
7. **\`bimdown publish <dir> [--expires 7d]\`**: Publishes the project to BimClaw and returns a shareable preview URL. Use this to let users view the model in a 3D editor. **Always publish after completing a model so users can preview it.**
|
|
2001
|
+
8. **\`bimdown info <dir>\`**: Prints project summary (levels, element counts).
|
|
2002
|
+
9. **\`bimdown resolve-topology <dir>\`**: Auto-detects coincident endpoints for MEP curves, generates \`mep_nodes\`, and fills connectivity fields.
|
|
2003
|
+
10. **\`bimdown merge <dirs...> -o <output>\`**: Merges multiple project directories into one, resolving ID conflicts.
|
|
2004
|
+
11. **\`bimdown sync <dir>\`**: Hydrates into DuckDB and dehydrates back out to CSV/SVG, applying computed defaults.
|
|
1876
2005
|
|
|
1877
2006
|
## Critical File & Geometry Rules
|
|
1878
2007
|
|
|
1879
2008
|
- **ID format**:
|
|
1880
2009
|
- **Grid and Level** allow any string after prefix: ${freeformExamples.join("; ")}
|
|
1881
2010
|
- **All other elements** use \`{prefix}-{number}\` (digits only): ${numericExamples.slice(0, 6).join(", ")}, ...
|
|
1882
|
-
- **Always run \`bimdown
|
|
2011
|
+
- **Always run \`bimdown build\` to confirm your IDs are compliant.**
|
|
1883
2012
|
- **SVG Coordinate Y-Flip**: All geometry inside \`.svg\` files **MUST** be wrapped in a Y-axis flip group: \`<g transform="scale(1,-1)"> ... </g>\`. This is just a fixed boilerplate \u2014 you do NOT need to do any coordinate conversion. Use normal Cartesian coordinates (X = right, Y = up) directly inside the group.
|
|
1884
2013
|
- **CSV vs Computed Fields**: Only write fields that are NOT marked as computed. Specifically, \`level_id\`, \`length\`, \`area\`, \`start_x/y\`, \`end_x/y\`, \`perimeter\`, \`volume\`, \`bbox_*\` are all auto-computed \u2014 never write them to CSV.
|
|
2014
|
+
- **Vertical positioning** (walls, columns, and other vertical elements):
|
|
2015
|
+
- \`level_id\`: auto-inferred from folder name \u2014 do NOT write to CSV
|
|
2016
|
+
- \`base_offset\`: vertical offset in meters from the element's level. Default 0. Usually leave empty.
|
|
2017
|
+
- \`top_level_id\`: the level where the element's top is constrained. **Leave empty** to default to the next level above. Only set this if the element spans to a non-adjacent level.
|
|
2018
|
+
- \`top_offset\`: vertical offset in meters from the top level. Default 0. Usually leave empty.
|
|
2019
|
+
- \`height\`: auto-computed from level elevations and offsets \u2014 do NOT write to CSV.
|
|
2020
|
+
- **For most single-story walls**: leave \`top_level_id\`, \`top_offset\`, and \`base_offset\` all empty \u2014 the CLI will compute the correct height from level elevations.
|
|
2021
|
+
|
|
2022
|
+
## Generation Tips
|
|
2023
|
+
|
|
2024
|
+
### Typical Values (meters)
|
|
2025
|
+
| Element | Field | Typical Range |
|
|
2026
|
+
|---------|-------|--------------|
|
|
2027
|
+
| Wall (partition) | thickness | 0.1 \u2013 0.15 |
|
|
2028
|
+
| Wall (exterior) | thickness | 0.2 \u2013 0.3 |
|
|
2029
|
+
| Wall (structural) | thickness | 0.3 \u2013 0.6 |
|
|
2030
|
+
| Door (single) | width \xD7 height | 0.9 \xD7 2.1 |
|
|
2031
|
+
| Door (double) | width \xD7 height | 1.8 \xD7 2.1 |
|
|
2032
|
+
| Window | width \xD7 height | 1.2\u20131.8 \xD7 1.5 |
|
|
2033
|
+
| Column | size_x \xD7 size_y | 0.3\u20130.6 \xD7 0.3\u20130.6 |
|
|
2034
|
+
| Slab | thickness | 0.15 \u2013 0.25 |
|
|
2035
|
+
| Level spacing | elevation diff | 3.0 \u2013 4.0 |
|
|
2036
|
+
|
|
2037
|
+
### Room Boundary Connectivity
|
|
2038
|
+
Rooms are enclosed by **walls, curtain walls, columns, and room separators**. For the boundary to close properly:
|
|
2039
|
+
- Line element endpoints (walls, curtain walls, room separators) must meet exactly at shared coordinates
|
|
2040
|
+
- Example: w-1 ends at (10,0) \u2192 w-2 must start at (10,0) for an L-junction
|
|
2041
|
+
- The CLI \`build\` command warns about unconnected endpoints and computes space boundaries from closed loops
|
|
2042
|
+
|
|
2043
|
+
### Door/Window Placement Rules
|
|
2044
|
+
- \`position\` = distance in meters from wall **start point** (the M coordinate in SVG path) to the opening **center**
|
|
2045
|
+
- Must satisfy: \`position - width/2 >= 0\` AND \`position + width/2 <= wall_length\`
|
|
2046
|
+
- Multiple openings on the same wall must not overlap
|
|
2047
|
+
- The CLI \`build\` command warns about out-of-bounds and overlapping placements
|
|
2048
|
+
|
|
2049
|
+
### SVG File Template
|
|
2050
|
+
Always use this structure for SVG files:
|
|
2051
|
+
\`\`\`xml
|
|
2052
|
+
<svg xmlns="http://www.w3.org/2000/svg">
|
|
2053
|
+
<g transform="scale(1,-1)">
|
|
2054
|
+
<!-- elements here, using normal Cartesian coordinates (X=right, Y=up) -->
|
|
2055
|
+
</g>
|
|
2056
|
+
</svg>
|
|
2057
|
+
\`\`\`
|
|
1885
2058
|
|
|
1886
2059
|
## Base Schema Definitions
|
|
1887
2060
|
|
|
@@ -1893,7 +2066,7 @@ These abstract schemas provide common fields for concrete tables below.
|
|
|
1893
2066
|
if (filePath) {
|
|
1894
2067
|
md += `### Base: \`${baseName}\`
|
|
1895
2068
|
\`\`\`yaml
|
|
1896
|
-
${
|
|
2069
|
+
${readFileSync6(filePath, "utf-8").trim()}
|
|
1897
2070
|
\`\`\`
|
|
1898
2071
|
|
|
1899
2072
|
`;
|
|
@@ -1931,7 +2104,7 @@ Below is a curated whitelist of the **most commonly used** core architectural el
|
|
|
1931
2104
|
`;
|
|
1932
2105
|
md += `id_prefix: ${table.prefix}
|
|
1933
2106
|
`;
|
|
1934
|
-
md += `${
|
|
2107
|
+
md += `${readFileSync6(filePath, "utf-8").trim()}
|
|
1935
2108
|
`;
|
|
1936
2109
|
const computedFields = table.allFields.filter((f) => f.computed || f.name === "level_id").map((f) => f.name);
|
|
1937
2110
|
if (computedFields.length > 0) {
|
|
@@ -1944,21 +2117,21 @@ virtual_fields: [${computedFields.join(", ")}]
|
|
|
1944
2117
|
`;
|
|
1945
2118
|
}
|
|
1946
2119
|
}
|
|
1947
|
-
const rootDir = outputDir ?
|
|
1948
|
-
const dirPath =
|
|
1949
|
-
if (!
|
|
1950
|
-
const outPath =
|
|
1951
|
-
|
|
2120
|
+
const rootDir = outputDir ? resolve2(outputDir) : process.cwd();
|
|
2121
|
+
const dirPath = join16(rootDir, "agent-skill");
|
|
2122
|
+
if (!existsSync16(dirPath)) mkdirSync5(dirPath, { recursive: true });
|
|
2123
|
+
const outPath = join16(dirPath, "SKILL.md");
|
|
2124
|
+
writeFileSync6(outPath, md, "utf-8");
|
|
1952
2125
|
console.log(`\u2705 Agent Skill documentation successfully generated at: ${outPath}`);
|
|
1953
2126
|
}
|
|
1954
2127
|
function findSchemaFile(baseDir, schemaName) {
|
|
1955
|
-
const dirs = [baseDir,
|
|
2128
|
+
const dirs = [baseDir, join16(baseDir, "architecture"), join16(baseDir, "mep"), join16(baseDir, "structure"), join16(baseDir, "base")];
|
|
1956
2129
|
for (const d of dirs) {
|
|
1957
|
-
if (!
|
|
1958
|
-
const p1 =
|
|
1959
|
-
if (
|
|
1960
|
-
const p2 =
|
|
1961
|
-
if (
|
|
2130
|
+
if (!existsSync16(d)) continue;
|
|
2131
|
+
const p1 = join16(d, `${schemaName}.yaml`);
|
|
2132
|
+
if (existsSync16(p1)) return p1;
|
|
2133
|
+
const p2 = join16(d, `${schemaName}.yml`);
|
|
2134
|
+
if (existsSync16(p2)) return p2;
|
|
1962
2135
|
}
|
|
1963
2136
|
return null;
|
|
1964
2137
|
}
|
|
@@ -1975,7 +2148,11 @@ var init_generate_skill = __esm({
|
|
|
1975
2148
|
|
|
1976
2149
|
// src/index.ts
|
|
1977
2150
|
import { Command } from "commander";
|
|
1978
|
-
import { resolve as
|
|
2151
|
+
import { resolve as resolve3 } from "path";
|
|
2152
|
+
|
|
2153
|
+
// src/build/index.ts
|
|
2154
|
+
import { existsSync as existsSync7 } from "fs";
|
|
2155
|
+
import { join as join8 } from "path";
|
|
1979
2156
|
|
|
1980
2157
|
// src/validate/index.ts
|
|
1981
2158
|
init_registry();
|
|
@@ -1989,7 +2166,7 @@ init_fs();
|
|
|
1989
2166
|
init_registry();
|
|
1990
2167
|
import { existsSync as existsSync3, readdirSync as readdirSync3, readFileSync as readFileSync3 } from "fs";
|
|
1991
2168
|
import { join as join4, extname } from "path";
|
|
1992
|
-
var OPTIONAL_SVG_TABLES = /* @__PURE__ */ new Set(["opening"]);
|
|
2169
|
+
var OPTIONAL_SVG_TABLES = /* @__PURE__ */ new Set(["opening", "space"]);
|
|
1993
2170
|
var KNOWN_CSV_NAMES = new Set(Object.keys(ID_PREFIXES).map((t) => `${t}.csv`));
|
|
1994
2171
|
var KNOWN_SVG_NAMES = new Set(Object.values(SVG_FILE_NAMES).map((s) => `${s}.svg`));
|
|
1995
2172
|
var KNOWN_GLOBAL_EXTRAS = /* @__PURE__ */ new Set(["_IdMap.csv"]);
|
|
@@ -2289,6 +2466,7 @@ var EXPECTED_TAGS = {
|
|
|
2289
2466
|
roof: /* @__PURE__ */ new Set(["polygon"]),
|
|
2290
2467
|
ceiling: /* @__PURE__ */ new Set(["polygon"]),
|
|
2291
2468
|
structure_slab: /* @__PURE__ */ new Set(["polygon"]),
|
|
2469
|
+
space: /* @__PURE__ */ new Set(["polygon"]),
|
|
2292
2470
|
// Mixed geometry
|
|
2293
2471
|
foundation: /* @__PURE__ */ new Set(["rect", "circle", "path", "polygon"]),
|
|
2294
2472
|
opening: /* @__PURE__ */ new Set(["rect", "polygon"])
|
|
@@ -2475,30 +2653,419 @@ function validate(dir) {
|
|
|
2475
2653
|
return issues;
|
|
2476
2654
|
}
|
|
2477
2655
|
|
|
2656
|
+
// src/build/index.ts
|
|
2657
|
+
init_fs();
|
|
2658
|
+
|
|
2659
|
+
// src/build/space-boundary.ts
|
|
2660
|
+
init_svg();
|
|
2661
|
+
init_csv();
|
|
2662
|
+
import { existsSync as existsSync5, writeFileSync as writeFileSync2 } from "fs";
|
|
2663
|
+
import { join as join6 } from "path";
|
|
2664
|
+
var TOLERANCE = 0.01;
|
|
2665
|
+
var MAX_FACE_EDGES = 1e4;
|
|
2666
|
+
var BOUNDARY_TABLES = ["wall", "structure_wall", "curtain_wall", "room_separator"];
|
|
2667
|
+
function computeSpaceBoundaries(levelDir) {
|
|
2668
|
+
const warnings = [];
|
|
2669
|
+
const spaceCsvPath = join6(levelDir.path, "space.csv");
|
|
2670
|
+
if (!existsSync5(spaceCsvPath)) return { warnings, svgWritten: false };
|
|
2671
|
+
const spaceCsv = readCsv(spaceCsvPath);
|
|
2672
|
+
if (spaceCsv.rows.length === 0) return { warnings, svgWritten: false };
|
|
2673
|
+
const segments = collectBoundarySegments(levelDir.path);
|
|
2674
|
+
if (segments.length === 0) {
|
|
2675
|
+
warnings.push(`${levelDir.name}/ no boundary elements found for space boundary computation`);
|
|
2676
|
+
return { warnings, svgWritten: false };
|
|
2677
|
+
}
|
|
2678
|
+
const { vertices, halfEdges } = buildHalfEdgeStructure(segments);
|
|
2679
|
+
for (const v of vertices) {
|
|
2680
|
+
if (v.outgoing.length === 1) {
|
|
2681
|
+
const he = v.outgoing[0];
|
|
2682
|
+
warnings.push(
|
|
2683
|
+
`[warn] ${levelDir.name}/ ${he.sourceId} endpoint (${v.x.toFixed(3)}, ${v.y.toFixed(3)}) has no connected line element`
|
|
2684
|
+
);
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
const faces = traceFaces(halfEdges);
|
|
2688
|
+
const matchedSpaces = /* @__PURE__ */ new Map();
|
|
2689
|
+
for (const row of spaceCsv.rows) {
|
|
2690
|
+
const seedX = parseFloat(row.x ?? "");
|
|
2691
|
+
const seedY = parseFloat(row.y ?? "");
|
|
2692
|
+
if (isNaN(seedX) || isNaN(seedY)) continue;
|
|
2693
|
+
let bestFace = null;
|
|
2694
|
+
let bestArea = Infinity;
|
|
2695
|
+
for (const face of faces) {
|
|
2696
|
+
if (face.signedArea <= 0) continue;
|
|
2697
|
+
if (face.signedArea < bestArea && pointInPolygon(seedX, seedY, face.polygon)) {
|
|
2698
|
+
bestFace = face;
|
|
2699
|
+
bestArea = face.signedArea;
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
if (bestFace) {
|
|
2703
|
+
matchedSpaces.set(row.id, bestFace);
|
|
2704
|
+
} else {
|
|
2705
|
+
warnings.push(
|
|
2706
|
+
`[warn] ${levelDir.name}/space.csv ${row.id} at (${row.x}, ${row.y}) has no enclosing boundary`
|
|
2707
|
+
);
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
if (matchedSpaces.size === 0) return { warnings, svgWritten: false };
|
|
2711
|
+
writeSvg(levelDir.path, matchedSpaces);
|
|
2712
|
+
return { warnings, svgWritten: true };
|
|
2713
|
+
}
|
|
2714
|
+
function collectBoundarySegments(levelPath) {
|
|
2715
|
+
const segments = [];
|
|
2716
|
+
for (const table of BOUNDARY_TABLES) {
|
|
2717
|
+
const svgPath = join6(levelPath, `${table}.svg`);
|
|
2718
|
+
if (!existsSync5(svgPath)) continue;
|
|
2719
|
+
try {
|
|
2720
|
+
const svg = parseSvgFile(svgPath);
|
|
2721
|
+
for (const el of svg.elements) {
|
|
2722
|
+
if (el.tag !== "path") continue;
|
|
2723
|
+
const geo = extractLineGeometry(el);
|
|
2724
|
+
if (geo.length < TOLERANCE) continue;
|
|
2725
|
+
segments.push({
|
|
2726
|
+
startX: geo.start_x,
|
|
2727
|
+
startY: geo.start_y,
|
|
2728
|
+
endX: geo.end_x,
|
|
2729
|
+
endY: geo.end_y,
|
|
2730
|
+
id: el.id
|
|
2731
|
+
});
|
|
2732
|
+
}
|
|
2733
|
+
} catch {
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
return segments;
|
|
2737
|
+
}
|
|
2738
|
+
function buildHalfEdgeStructure(segments) {
|
|
2739
|
+
const vertices = [];
|
|
2740
|
+
function findOrCreateVertex(x, y) {
|
|
2741
|
+
for (const v2 of vertices) {
|
|
2742
|
+
if (Math.abs(v2.x - x) < TOLERANCE && Math.abs(v2.y - y) < TOLERANCE) {
|
|
2743
|
+
return v2;
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
const v = { x, y, id: vertices.length, outgoing: [] };
|
|
2747
|
+
vertices.push(v);
|
|
2748
|
+
return v;
|
|
2749
|
+
}
|
|
2750
|
+
const halfEdges = [];
|
|
2751
|
+
for (const seg of segments) {
|
|
2752
|
+
const v1 = findOrCreateVertex(seg.startX, seg.startY);
|
|
2753
|
+
const v2 = findOrCreateVertex(seg.endX, seg.endY);
|
|
2754
|
+
if (v1 === v2) continue;
|
|
2755
|
+
const isDuplicate = v1.outgoing.some((he) => he.to === v2);
|
|
2756
|
+
if (isDuplicate) continue;
|
|
2757
|
+
const he1 = { from: v1, to: v2, sourceId: seg.id };
|
|
2758
|
+
const he2 = { from: v2, to: v1, sourceId: seg.id };
|
|
2759
|
+
he1.twin = he2;
|
|
2760
|
+
he2.twin = he1;
|
|
2761
|
+
he1.visited = false;
|
|
2762
|
+
he2.visited = false;
|
|
2763
|
+
v1.outgoing.push(he1);
|
|
2764
|
+
v2.outgoing.push(he2);
|
|
2765
|
+
halfEdges.push(he1, he2);
|
|
2766
|
+
}
|
|
2767
|
+
for (const v of vertices) {
|
|
2768
|
+
v.outgoing.sort((a, b) => {
|
|
2769
|
+
const angleA = Math.atan2(a.to.y - v.y, a.to.x - v.x);
|
|
2770
|
+
const angleB = Math.atan2(b.to.y - v.y, b.to.x - v.x);
|
|
2771
|
+
return angleA - angleB;
|
|
2772
|
+
});
|
|
2773
|
+
}
|
|
2774
|
+
for (const he of halfEdges) {
|
|
2775
|
+
const v = he.to;
|
|
2776
|
+
const twinIdx = v.outgoing.indexOf(he.twin);
|
|
2777
|
+
if (twinIdx === -1) {
|
|
2778
|
+
he.next = he.twin;
|
|
2779
|
+
continue;
|
|
2780
|
+
}
|
|
2781
|
+
const prevIdx = (twinIdx - 1 + v.outgoing.length) % v.outgoing.length;
|
|
2782
|
+
he.next = v.outgoing[prevIdx];
|
|
2783
|
+
}
|
|
2784
|
+
return { vertices, halfEdges };
|
|
2785
|
+
}
|
|
2786
|
+
function traceFaces(halfEdges) {
|
|
2787
|
+
const faces = [];
|
|
2788
|
+
for (const startHe of halfEdges) {
|
|
2789
|
+
if (startHe.visited) continue;
|
|
2790
|
+
const polygon = [];
|
|
2791
|
+
let current = startHe;
|
|
2792
|
+
let count = 0;
|
|
2793
|
+
do {
|
|
2794
|
+
current.visited = true;
|
|
2795
|
+
polygon.push({ x: current.from.x, y: current.from.y });
|
|
2796
|
+
current = current.next;
|
|
2797
|
+
count++;
|
|
2798
|
+
} while (current !== startHe && count < MAX_FACE_EDGES);
|
|
2799
|
+
if (count >= MAX_FACE_EDGES) continue;
|
|
2800
|
+
let signedArea = 0;
|
|
2801
|
+
for (let i = 0; i < polygon.length; i++) {
|
|
2802
|
+
const j = (i + 1) % polygon.length;
|
|
2803
|
+
signedArea += polygon[i].x * polygon[j].y;
|
|
2804
|
+
signedArea -= polygon[j].x * polygon[i].y;
|
|
2805
|
+
}
|
|
2806
|
+
signedArea /= 2;
|
|
2807
|
+
faces.push({ polygon, signedArea });
|
|
2808
|
+
}
|
|
2809
|
+
return faces;
|
|
2810
|
+
}
|
|
2811
|
+
function pointInPolygon(px, py, polygon) {
|
|
2812
|
+
let crossings = 0;
|
|
2813
|
+
for (let i = 0; i < polygon.length; i++) {
|
|
2814
|
+
const j = (i + 1) % polygon.length;
|
|
2815
|
+
const yi = polygon[i].y;
|
|
2816
|
+
const yj = polygon[j].y;
|
|
2817
|
+
const xi = polygon[i].x;
|
|
2818
|
+
const xj = polygon[j].x;
|
|
2819
|
+
if (yi <= py && py < yj || yj <= py && py < yi) {
|
|
2820
|
+
const t = (py - yi) / (yj - yi);
|
|
2821
|
+
const xIntersect = xi + t * (xj - xi);
|
|
2822
|
+
if (px < xIntersect) crossings++;
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
return crossings % 2 === 1;
|
|
2826
|
+
}
|
|
2827
|
+
function writeSvg(levelPath, matchedSpaces) {
|
|
2828
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
2829
|
+
for (const face of matchedSpaces.values()) {
|
|
2830
|
+
for (const p of face.polygon) {
|
|
2831
|
+
minX = Math.min(minX, p.x);
|
|
2832
|
+
minY = Math.min(minY, p.y);
|
|
2833
|
+
maxX = Math.max(maxX, p.x);
|
|
2834
|
+
maxY = Math.max(maxY, p.y);
|
|
2835
|
+
}
|
|
2836
|
+
}
|
|
2837
|
+
const pad = Math.max(maxX - minX, maxY - minY) * 0.02;
|
|
2838
|
+
const vbX = (minX - pad).toFixed(3);
|
|
2839
|
+
const vbY = (-(maxY + pad)).toFixed(3);
|
|
2840
|
+
const vbW = (maxX - minX + pad * 2).toFixed(3);
|
|
2841
|
+
const vbH = (maxY - minY + pad * 2).toFixed(3);
|
|
2842
|
+
const lines = [
|
|
2843
|
+
'<?xml version="1.0" encoding="utf-8"?>',
|
|
2844
|
+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="${vbX} ${vbY} ${vbW} ${vbH}">`,
|
|
2845
|
+
' <g transform="scale(1,-1)">'
|
|
2846
|
+
];
|
|
2847
|
+
for (const [spaceId, face] of matchedSpaces) {
|
|
2848
|
+
const pointsStr = face.polygon.map((p) => `${p.x.toFixed(3)},${p.y.toFixed(3)}`).join(" ");
|
|
2849
|
+
lines.push(` <polygon id="${spaceId}" points="${pointsStr}" />`);
|
|
2850
|
+
}
|
|
2851
|
+
lines.push(" </g>");
|
|
2852
|
+
lines.push("</svg>");
|
|
2853
|
+
writeFileSync2(join6(levelPath, "space.svg"), lines.join("\n"));
|
|
2854
|
+
}
|
|
2855
|
+
|
|
2856
|
+
// src/build/geometry-warnings.ts
|
|
2857
|
+
init_registry();
|
|
2858
|
+
init_fs();
|
|
2859
|
+
init_csv();
|
|
2860
|
+
init_svg();
|
|
2861
|
+
import { existsSync as existsSync6 } from "fs";
|
|
2862
|
+
import { join as join7 } from "path";
|
|
2863
|
+
var TOLERANCE2 = 0.01;
|
|
2864
|
+
var BOUNDARY_TABLES2 = ["wall", "structure_wall", "curtain_wall", "room_separator"];
|
|
2865
|
+
function validateGeometry(dir) {
|
|
2866
|
+
const warnings = [];
|
|
2867
|
+
const registry = buildRegistry(getSpecDir());
|
|
2868
|
+
const layout = discoverLayout(dir);
|
|
2869
|
+
const allDirs = [
|
|
2870
|
+
{ name: "global", path: layout.globalDir },
|
|
2871
|
+
...layout.levelDirs
|
|
2872
|
+
];
|
|
2873
|
+
const wallGeometries = /* @__PURE__ */ new Map();
|
|
2874
|
+
for (const d of allDirs) {
|
|
2875
|
+
if (!existsSync6(d.path)) continue;
|
|
2876
|
+
for (const table of ["wall", "structure_wall", "curtain_wall"]) {
|
|
2877
|
+
const svgPath = join7(d.path, `${table}.svg`);
|
|
2878
|
+
if (!existsSync6(svgPath)) continue;
|
|
2879
|
+
try {
|
|
2880
|
+
const svg = parseSvgFile(svgPath);
|
|
2881
|
+
for (const el of svg.elements) {
|
|
2882
|
+
if (el.tag !== "path") continue;
|
|
2883
|
+
const geo = extractLineGeometry(el);
|
|
2884
|
+
wallGeometries.set(el.id, { length: geo.length });
|
|
2885
|
+
}
|
|
2886
|
+
} catch {
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
for (const d of [...layout.levelDirs]) {
|
|
2891
|
+
if (!existsSync6(d.path)) continue;
|
|
2892
|
+
warnings.push(...validateLineConnectivity(d));
|
|
2893
|
+
warnings.push(...validateHostedBounds(d, wallGeometries));
|
|
2894
|
+
warnings.push(...validateHostedOverlap(d));
|
|
2895
|
+
}
|
|
2896
|
+
return warnings;
|
|
2897
|
+
}
|
|
2898
|
+
function validateLineConnectivity(levelDir) {
|
|
2899
|
+
const warnings = [];
|
|
2900
|
+
const endpoints = [];
|
|
2901
|
+
for (const table of BOUNDARY_TABLES2) {
|
|
2902
|
+
const svgPath = join7(levelDir.path, `${table}.svg`);
|
|
2903
|
+
if (!existsSync6(svgPath)) continue;
|
|
2904
|
+
try {
|
|
2905
|
+
const svg = parseSvgFile(svgPath);
|
|
2906
|
+
for (const el of svg.elements) {
|
|
2907
|
+
if (el.tag !== "path") continue;
|
|
2908
|
+
const geo = extractLineGeometry(el);
|
|
2909
|
+
endpoints.push({ x: geo.start_x, y: geo.start_y, side: "start", elementId: el.id, table });
|
|
2910
|
+
endpoints.push({ x: geo.end_x, y: geo.end_y, side: "end", elementId: el.id, table });
|
|
2911
|
+
}
|
|
2912
|
+
} catch {
|
|
2913
|
+
}
|
|
2914
|
+
}
|
|
2915
|
+
for (const ep of endpoints) {
|
|
2916
|
+
const hasNeighbor = endpoints.some(
|
|
2917
|
+
(other) => other !== ep && !(other.elementId === ep.elementId && other.table === ep.table) && Math.abs(other.x - ep.x) < TOLERANCE2 && Math.abs(other.y - ep.y) < TOLERANCE2
|
|
2918
|
+
);
|
|
2919
|
+
if (!hasNeighbor) {
|
|
2920
|
+
let nearestDist = Infinity;
|
|
2921
|
+
let nearestId = "";
|
|
2922
|
+
let nearestSide = "";
|
|
2923
|
+
for (const other of endpoints) {
|
|
2924
|
+
if (other === ep || other.elementId === ep.elementId && other.table === ep.table) continue;
|
|
2925
|
+
const dx = other.x - ep.x;
|
|
2926
|
+
const dy = other.y - ep.y;
|
|
2927
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
2928
|
+
if (dist < nearestDist) {
|
|
2929
|
+
nearestDist = dist;
|
|
2930
|
+
nearestId = other.elementId;
|
|
2931
|
+
nearestSide = other.side;
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
const nearestInfo = nearestDist < Infinity ? ` (nearest: ${nearestId} ${nearestSide}, distance ${nearestDist.toFixed(3)}m)` : "";
|
|
2935
|
+
warnings.push(
|
|
2936
|
+
`[warn] ${levelDir.name}/${ep.table}.svg ${ep.elementId} ${ep.side} (${ep.x.toFixed(3)}, ${ep.y.toFixed(3)}) has no connected line element${nearestInfo}`
|
|
2937
|
+
);
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
return warnings;
|
|
2941
|
+
}
|
|
2942
|
+
function validateHostedBounds(levelDir, wallGeometries) {
|
|
2943
|
+
const warnings = [];
|
|
2944
|
+
for (const tableName of ["door", "window"]) {
|
|
2945
|
+
const csvPath = join7(levelDir.path, `${tableName}.csv`);
|
|
2946
|
+
if (!existsSync6(csvPath)) continue;
|
|
2947
|
+
const csv = readCsv(csvPath);
|
|
2948
|
+
for (let i = 0; i < csv.rows.length; i++) {
|
|
2949
|
+
const row = csv.rows[i];
|
|
2950
|
+
const hostId = row.host_id;
|
|
2951
|
+
const position = parseFloat(row.position ?? "");
|
|
2952
|
+
const width = parseFloat(row.width ?? "");
|
|
2953
|
+
if (!hostId || isNaN(position) || isNaN(width)) continue;
|
|
2954
|
+
const wallGeo = wallGeometries.get(hostId);
|
|
2955
|
+
if (!wallGeo) continue;
|
|
2956
|
+
const halfWidth = width / 2;
|
|
2957
|
+
if (position - halfWidth < -TOLERANCE2) {
|
|
2958
|
+
warnings.push(
|
|
2959
|
+
`[warn] ${levelDir.name}/${tableName}.csv:${i + 2} ${row.id} extends before host ${hostId} start: position(${position}) - width/2(${halfWidth.toFixed(3)}) = ${(position - halfWidth).toFixed(3)}m`
|
|
2960
|
+
);
|
|
2961
|
+
}
|
|
2962
|
+
if (position + halfWidth > wallGeo.length + TOLERANCE2) {
|
|
2963
|
+
warnings.push(
|
|
2964
|
+
`[warn] ${levelDir.name}/${tableName}.csv:${i + 2} ${row.id} extends past host ${hostId} end: position(${position}) + width/2(${halfWidth.toFixed(3)}) = ${(position + halfWidth).toFixed(3)}m > wall length ${wallGeo.length.toFixed(3)}m`
|
|
2965
|
+
);
|
|
2966
|
+
}
|
|
2967
|
+
}
|
|
2968
|
+
}
|
|
2969
|
+
return warnings;
|
|
2970
|
+
}
|
|
2971
|
+
function validateHostedOverlap(levelDir) {
|
|
2972
|
+
const warnings = [];
|
|
2973
|
+
const entries = [];
|
|
2974
|
+
for (const tableName of ["door", "window", "opening"]) {
|
|
2975
|
+
const csvPath = join7(levelDir.path, `${tableName}.csv`);
|
|
2976
|
+
if (!existsSync6(csvPath)) continue;
|
|
2977
|
+
const csv = readCsv(csvPath);
|
|
2978
|
+
for (let i = 0; i < csv.rows.length; i++) {
|
|
2979
|
+
const row = csv.rows[i];
|
|
2980
|
+
const hostId = row.host_id;
|
|
2981
|
+
const position = parseFloat(row.position ?? "");
|
|
2982
|
+
const width = parseFloat(row.width ?? "");
|
|
2983
|
+
if (!hostId || isNaN(position) || isNaN(width)) continue;
|
|
2984
|
+
entries.push({ id: row.id, hostId, position, width, tableName, row: i + 2 });
|
|
2985
|
+
}
|
|
2986
|
+
}
|
|
2987
|
+
const byHost = /* @__PURE__ */ new Map();
|
|
2988
|
+
for (const entry of entries) {
|
|
2989
|
+
const list = byHost.get(entry.hostId) ?? [];
|
|
2990
|
+
list.push(entry);
|
|
2991
|
+
byHost.set(entry.hostId, list);
|
|
2992
|
+
}
|
|
2993
|
+
for (const [hostId, group] of byHost) {
|
|
2994
|
+
if (group.length < 2) continue;
|
|
2995
|
+
group.sort((a, b) => a.position - b.position);
|
|
2996
|
+
for (let i = 0; i < group.length; i++) {
|
|
2997
|
+
for (let j = i + 1; j < group.length; j++) {
|
|
2998
|
+
const a = group[i];
|
|
2999
|
+
const b = group[j];
|
|
3000
|
+
const aEnd = a.position + a.width / 2;
|
|
3001
|
+
const bStart = b.position - b.width / 2;
|
|
3002
|
+
if (aEnd > bStart + TOLERANCE2) {
|
|
3003
|
+
warnings.push(
|
|
3004
|
+
`[warn] ${levelDir.name}/ ${a.id} and ${b.id} overlap on ${hostId} (${a.id}: ${(a.position - a.width / 2).toFixed(3)}\u2013${aEnd.toFixed(3)}m, ${b.id}: ${bStart.toFixed(3)}\u2013${(b.position + b.width / 2).toFixed(3)}m)`
|
|
3005
|
+
);
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
return warnings;
|
|
3011
|
+
}
|
|
3012
|
+
|
|
3013
|
+
// src/build/index.ts
|
|
3014
|
+
function build(dir) {
|
|
3015
|
+
const issues = validate(dir);
|
|
3016
|
+
const warnings = validateGeometry(dir);
|
|
3017
|
+
const artifacts = [];
|
|
3018
|
+
const layout = discoverLayout(dir);
|
|
3019
|
+
for (const levelDir of layout.levelDirs) {
|
|
3020
|
+
const spaceCsvPath = join8(levelDir.path, "space.csv");
|
|
3021
|
+
if (!existsSync7(spaceCsvPath)) continue;
|
|
3022
|
+
const result = computeSpaceBoundaries(levelDir);
|
|
3023
|
+
warnings.push(...result.warnings);
|
|
3024
|
+
if (result.svgWritten) {
|
|
3025
|
+
artifacts.push(`${levelDir.name}/space.svg`);
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
3028
|
+
return { issues, warnings, artifacts };
|
|
3029
|
+
}
|
|
3030
|
+
|
|
2478
3031
|
// src/index.ts
|
|
2479
3032
|
init_registry();
|
|
2480
3033
|
init_fs();
|
|
2481
3034
|
init_csv();
|
|
2482
|
-
import { existsSync as
|
|
2483
|
-
import { join as
|
|
3035
|
+
import { existsSync as existsSync17, writeFileSync as writeFileSync7 } from "fs";
|
|
3036
|
+
import { join as join17 } from "path";
|
|
2484
3037
|
var program = new Command();
|
|
2485
|
-
program.name("bimdown").description("BimDown CLI \u2014
|
|
2486
|
-
|
|
2487
|
-
const absDir =
|
|
2488
|
-
const
|
|
2489
|
-
if (issues.length
|
|
2490
|
-
|
|
2491
|
-
} else {
|
|
2492
|
-
for (const issue of issues) {
|
|
3038
|
+
program.name("bimdown").description("BimDown CLI \u2014 build, query, and manage BimDown projects").version(true ? "0.2.2" : "0.0.0");
|
|
3039
|
+
function runBuild(dir) {
|
|
3040
|
+
const absDir = resolve3(dir);
|
|
3041
|
+
const result = build(absDir);
|
|
3042
|
+
if (result.issues.length > 0) {
|
|
3043
|
+
for (const issue of result.issues) {
|
|
2493
3044
|
console.log(issue);
|
|
2494
3045
|
}
|
|
2495
3046
|
console.log(`
|
|
2496
|
-
${issues.length} issue(s) found.`);
|
|
3047
|
+
${result.issues.length} issue(s) found.`);
|
|
2497
3048
|
process.exitCode = 1;
|
|
2498
3049
|
}
|
|
2499
|
-
|
|
3050
|
+
if (result.warnings.length > 0) {
|
|
3051
|
+
for (const w of result.warnings) {
|
|
3052
|
+
console.log(w);
|
|
3053
|
+
}
|
|
3054
|
+
console.log(`
|
|
3055
|
+
${result.warnings.length} warning(s).`);
|
|
3056
|
+
}
|
|
3057
|
+
if (result.artifacts.length > 0) {
|
|
3058
|
+
console.log(`
|
|
3059
|
+
Generated: ${result.artifacts.join(", ")}`);
|
|
3060
|
+
}
|
|
3061
|
+
if (result.issues.length === 0 && result.warnings.length === 0) {
|
|
3062
|
+
console.log("Build successful. No issues found.");
|
|
3063
|
+
}
|
|
3064
|
+
}
|
|
3065
|
+
program.command("build").argument("<dir>", "BimDown project directory").description("Build a BimDown project (validate + compute space boundaries)").action((dir) => runBuild(dir));
|
|
3066
|
+
program.command("validate").argument("<dir>", "BimDown project directory").description("Alias for build").action((dir) => runBuild(dir));
|
|
2500
3067
|
program.command("query").argument("<dir>", "BimDown project directory").argument("<sql>", "SQL query to execute").option("--json", "Output results as JSON").description("Hydrate into DuckDB and execute a SQL query").action(async (dir, sql, opts) => {
|
|
2501
|
-
const absDir =
|
|
3068
|
+
const absDir = resolve3(dir);
|
|
2502
3069
|
const { getConnection: getConnection2, runQuery: runQuery2, closeConnection: closeConnection2 } = await Promise.resolve().then(() => (init_engine(), engine_exports));
|
|
2503
3070
|
const { hydrate: hydrate2 } = await Promise.resolve().then(() => (init_hydrate(), hydrate_exports));
|
|
2504
3071
|
const conn = await getConnection2();
|
|
@@ -2515,7 +3082,7 @@ program.command("query").argument("<dir>", "BimDown project directory").argument
|
|
|
2515
3082
|
}
|
|
2516
3083
|
});
|
|
2517
3084
|
program.command("sync").argument("<dir>", "BimDown project directory").description("Hydrate, then dehydrate back (sync DuckDB changes to files)").action(async (dir) => {
|
|
2518
|
-
const absDir =
|
|
3085
|
+
const absDir = resolve3(dir);
|
|
2519
3086
|
const { getConnection: getConnection2, closeConnection: closeConnection2 } = await Promise.resolve().then(() => (init_engine(), engine_exports));
|
|
2520
3087
|
const { hydrate: hydrate2 } = await Promise.resolve().then(() => (init_hydrate(), hydrate_exports));
|
|
2521
3088
|
const { dehydrate: dehydrate2 } = await Promise.resolve().then(() => (init_dehydrate(), dehydrate_exports));
|
|
@@ -2530,12 +3097,12 @@ program.command("sync").argument("<dir>", "BimDown project directory").descripti
|
|
|
2530
3097
|
}
|
|
2531
3098
|
});
|
|
2532
3099
|
program.command("render").argument("<dir>", "BimDown project directory").option("-l, --level <id>", "Level to render (defaults to lv-1)", "lv-1").option("-o, --output <file>", "Output file path (defaults to render.png)", "render.png").option("-w, --width <px>", "Image width in pixels", "2048").description("Renders the BimDown project into a visual blueprint (PNG)").action(async (dir, opts) => {
|
|
2533
|
-
const absDir =
|
|
3100
|
+
const absDir = resolve3(dir);
|
|
2534
3101
|
const { renderLevel: renderLevel2 } = await Promise.resolve().then(() => (init_render(), render_exports));
|
|
2535
3102
|
try {
|
|
2536
3103
|
const svg = renderLevel2(absDir, opts.level);
|
|
2537
3104
|
if (opts.output.endsWith(".svg")) {
|
|
2538
|
-
|
|
3105
|
+
writeFileSync7(opts.output, svg);
|
|
2539
3106
|
} else {
|
|
2540
3107
|
const sharp = (await import("sharp")).default;
|
|
2541
3108
|
const width = parseInt(opts.width, 10) || 2048;
|
|
@@ -2548,11 +3115,11 @@ program.command("render").argument("<dir>", "BimDown project directory").option(
|
|
|
2548
3115
|
}
|
|
2549
3116
|
});
|
|
2550
3117
|
program.command("info").argument("<dir>", "BimDown project directory").description("Print project summary").action((dir) => {
|
|
2551
|
-
const absDir =
|
|
3118
|
+
const absDir = resolve3(dir);
|
|
2552
3119
|
const registry = buildRegistry(getSpecDir());
|
|
2553
3120
|
const layout = discoverLayout(absDir);
|
|
2554
|
-
const levelCsv =
|
|
2555
|
-
if (
|
|
3121
|
+
const levelCsv = join17(layout.globalDir, "level.csv");
|
|
3122
|
+
if (existsSync17(levelCsv)) {
|
|
2556
3123
|
const levels = readCsv(levelCsv);
|
|
2557
3124
|
console.log("Levels:");
|
|
2558
3125
|
for (const row of levels.rows) {
|
|
@@ -2566,14 +3133,14 @@ program.command("info").argument("<dir>", "BimDown project directory").descripti
|
|
|
2566
3133
|
];
|
|
2567
3134
|
const totals = {};
|
|
2568
3135
|
for (const d of allDirs) {
|
|
2569
|
-
if (!
|
|
3136
|
+
if (!existsSync17(d.path)) continue;
|
|
2570
3137
|
const files = listFiles(d.path);
|
|
2571
3138
|
const counts = [];
|
|
2572
3139
|
for (const f of files) {
|
|
2573
3140
|
if (!f.endsWith(".csv")) continue;
|
|
2574
3141
|
const tableName = f.replace(".csv", "");
|
|
2575
3142
|
if (!registry.has(tableName)) continue;
|
|
2576
|
-
const data = readCsv(
|
|
3143
|
+
const data = readCsv(join17(d.path, f));
|
|
2577
3144
|
counts.push(`${tableName}: ${data.rows.length}`);
|
|
2578
3145
|
totals[tableName] = (totals[tableName] ?? 0) + data.rows.length;
|
|
2579
3146
|
}
|
|
@@ -2591,7 +3158,7 @@ program.command("info").argument("<dir>", "BimDown project directory").descripti
|
|
|
2591
3158
|
console.log(` TOTAL: ${grand}`);
|
|
2592
3159
|
});
|
|
2593
3160
|
program.command("resolve-topology").argument("<dir>", "BimDown project directory").description("Auto-resolve MEP topology: detect coincident endpoints, generate mep_nodes, fill connectivity").action(async (dir) => {
|
|
2594
|
-
const absDir =
|
|
3161
|
+
const absDir = resolve3(dir);
|
|
2595
3162
|
const { resolveTopology: resolveTopology2 } = await Promise.resolve().then(() => (init_resolve_topology(), resolve_topology_exports));
|
|
2596
3163
|
resolveTopology2(absDir);
|
|
2597
3164
|
});
|
|
@@ -2601,8 +3168,8 @@ program.command("merge").argument("<dirs...>", "Two or more BimDown project dire
|
|
|
2601
3168
|
process.exitCode = 1;
|
|
2602
3169
|
return;
|
|
2603
3170
|
}
|
|
2604
|
-
const absDirs = dirs.map((d) =>
|
|
2605
|
-
const absOut =
|
|
3171
|
+
const absDirs = dirs.map((d) => resolve3(d));
|
|
3172
|
+
const absOut = resolve3(opts.output);
|
|
2606
3173
|
const { merge: merge2 } = await Promise.resolve().then(() => (init_merge(), merge_exports));
|
|
2607
3174
|
await merge2(absDirs, absOut);
|
|
2608
3175
|
});
|
|
@@ -2639,16 +3206,20 @@ program.command("schema").argument("[table]", "Table name (omit for all tables)"
|
|
|
2639
3206
|
}
|
|
2640
3207
|
});
|
|
2641
3208
|
program.command("init").argument("<dir>", "BimDown project directory").description("Initialize a new BimDown project structure").action(async (dir) => {
|
|
2642
|
-
const absDir =
|
|
3209
|
+
const absDir = resolve3(dir);
|
|
2643
3210
|
const { initProject: initProject2 } = await Promise.resolve().then(() => (init_init(), init_exports));
|
|
2644
3211
|
initProject2(absDir);
|
|
2645
3212
|
});
|
|
2646
3213
|
program.command("diff").argument("<dirA>", "First BimDown project directory").argument("<dirB>", "Second BimDown project directory").description("Show differences between two BimDown projects").action(async (dirA, dirB) => {
|
|
2647
|
-
const absA =
|
|
2648
|
-
const absB =
|
|
3214
|
+
const absA = resolve3(dirA);
|
|
3215
|
+
const absB = resolve3(dirB);
|
|
2649
3216
|
const { diffProjects: diffProjects2 } = await Promise.resolve().then(() => (init_diff(), diff_exports));
|
|
2650
3217
|
diffProjects2(absA, absB);
|
|
2651
3218
|
});
|
|
3219
|
+
program.command("publish").argument("<dir>", "BimDown project directory").option("--expires <duration>", "Expiration time (e.g. 7d, 24h, 30m)", "7d").option("--api <url>", "BimClaw API base URL").option("--name <name>", "Project name").description("Publish a BimDown project to BimClaw for sharing").action(async (dir, opts) => {
|
|
3220
|
+
const { publish: publish2 } = await Promise.resolve().then(() => (init_publish(), publish_exports));
|
|
3221
|
+
await publish2(dir, opts);
|
|
3222
|
+
});
|
|
2652
3223
|
program.command("generate-skill").description("Generate AI Agent SKILL.md documentation from YAML schemas").action(async () => {
|
|
2653
3224
|
const { generateSkill: generateSkill2 } = await Promise.resolve().then(() => (init_generate_skill(), generate_skill_exports));
|
|
2654
3225
|
generateSkill2("..");
|