@bitbybit-dev/create-app 1.4.1 → 1.5.0
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/README.md +1 -0
- package/dist/index.js +20 -13
- package/dist/index.js.map +1 -1
- package/dist/scaffold.d.ts.map +1 -1
- package/dist/scaffold.js +16 -8
- package/dist/scaffold.js.map +1 -1
- package/package.json +1 -1
- package/src/index.test.ts +47 -11
- package/src/index.ts +28 -14
- package/src/scaffold.ts +23 -8
- package/templates/apps/drone-assembly/package.json +3 -3
- package/templates/apps/drone-assembly/scripts/smoke.ts +3 -3
- package/templates/apps/drone-assembly/src/parts.ts +3 -3
- package/templates/apps/ifc-house/AGENTS.section.md +19 -0
- package/templates/apps/ifc-house/README.md +36 -0
- package/templates/apps/ifc-house/eslint.config.js +47 -0
- package/templates/apps/ifc-house/index.html +22 -0
- package/templates/apps/ifc-house/package.json +36 -0
- package/templates/apps/ifc-house/public/favicon.ico +0 -0
- package/templates/apps/ifc-house/public/logo.png +0 -0
- package/templates/apps/ifc-house/scripts/smoke.ts +118 -0
- package/templates/apps/ifc-house/src/export/step-export.ts +29 -0
- package/templates/apps/ifc-house/src/house/build-house.ts +194 -0
- package/templates/apps/ifc-house/src/house/details.ts +393 -0
- package/templates/apps/ifc-house/src/house/house-plan.ts +400 -0
- package/templates/apps/ifc-house/src/house/house-types.ts +192 -0
- package/templates/apps/ifc-house/src/main.ts +138 -0
- package/templates/apps/ifc-house/src/scene/draw-house.ts +92 -0
- package/templates/apps/ifc-house/src/scene/scene-types.ts +30 -0
- package/templates/apps/ifc-house/src/scene/stage.ts +64 -0
- package/templates/apps/ifc-house/src/style.css +347 -0
- package/templates/apps/ifc-house/src/ui/panel.ts +144 -0
- package/templates/apps/ifc-house/src/ui/room-labels.ts +75 -0
- package/templates/apps/ifc-house/src/ui/ui-types.ts +14 -0
- package/templates/apps/ifc-house/src/vite-env.d.ts +1 -0
- package/templates/apps/ifc-house/src/workers/ifc.worker.ts +7 -0
- package/templates/apps/ifc-house/src/workers/manifold.worker.ts +16 -0
- package/templates/apps/ifc-house/src/workers/occt.worker.ts +17 -0
- package/templates/apps/ifc-house/tsconfig.json +29 -0
- package/templates/apps/laser-cut-box/package.json +2 -2
- package/templates/apps/laser-cut-box/scripts/smoke.ts +2 -1
- package/templates/apps/laser-cut-box/src/panels.ts +2 -0
- package/templates/apps/product-configurator/package.json +2 -2
- package/templates/apps/product-configurator/scripts/smoke.ts +4 -3
- package/templates/apps/sheet-metal-unfold/backend/package.json +1 -1
- package/templates/apps/sheet-metal-unfold/frontend/package.json +2 -2
- package/templates/apps/sheet-metal-unfold/frontend/scripts/smoke.ts +4 -3
- package/templates/apps/step-to-gltf-cli/package.json +2 -2
- package/templates/apps/step-to-gltf-cli/src/convert.ts +7 -2
- package/templates/cloud/backends/hono-rest/package.json +1 -1
- package/templates/cloud/backends/hono-sdk/package.json +2 -2
- package/templates/cloud/backends/nodejs-rest/package.json +1 -1
- package/templates/cloud/backends/nodejs-sdk/package.json +2 -2
- package/templates/cloud/frontend/package.json +1 -1
- package/templates/vite/babylonjs/typescript/AGENTS.section.md +1 -1
- package/templates/vite/babylonjs/typescript/package.json +2 -2
- package/templates/vite/babylonjs/typescript/scripts/smoke.ts +4 -3
- package/templates/vite/playcanvas/typescript/AGENTS.section.md +1 -1
- package/templates/vite/playcanvas/typescript/package.json +2 -2
- package/templates/vite/playcanvas/typescript/scripts/smoke.ts +4 -3
- package/templates/vite/threejs/typescript/AGENTS.section.md +1 -1
- package/templates/vite/threejs/typescript/package.json +2 -2
- package/templates/vite/threejs/typescript/scripts/smoke.ts +4 -3
package/src/scaffold.ts
CHANGED
|
@@ -21,10 +21,15 @@ export async function listFiles(dir: string): Promise<string[]> {
|
|
|
21
21
|
const out: string[] = [];
|
|
22
22
|
const walk = async (current: string): Promise<void> => {
|
|
23
23
|
for (const entry of await fs.readdir(current, { withFileTypes: true })) {
|
|
24
|
-
if (SKIPPED_DIRS.has(entry.name))
|
|
24
|
+
if (SKIPPED_DIRS.has(entry.name)) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
25
27
|
const full = path.join(current, entry.name);
|
|
26
|
-
if (entry.isDirectory())
|
|
27
|
-
|
|
28
|
+
if (entry.isDirectory()) {
|
|
29
|
+
await walk(full);
|
|
30
|
+
} else {
|
|
31
|
+
out.push(full);
|
|
32
|
+
}
|
|
28
33
|
}
|
|
29
34
|
};
|
|
30
35
|
await walk(dir);
|
|
@@ -41,10 +46,16 @@ export async function restoreTemplateDotfiles(dir: string): Promise<string[]> {
|
|
|
41
46
|
const restored: string[] = [];
|
|
42
47
|
const walk = async (current: string): Promise<void> => {
|
|
43
48
|
for (const entry of await fs.readdir(current, { withFileTypes: true })) {
|
|
44
|
-
if (SKIPPED_DIRS.has(entry.name))
|
|
49
|
+
if (SKIPPED_DIRS.has(entry.name)) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
45
52
|
const from = path.join(current, entry.name);
|
|
46
|
-
if (entry.isDirectory())
|
|
47
|
-
|
|
53
|
+
if (entry.isDirectory()) {
|
|
54
|
+
await walk(from);
|
|
55
|
+
}
|
|
56
|
+
if (!entry.name.startsWith(DOTFILE_PREFIX)) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
48
59
|
const to = path.join(current, `.${entry.name.slice(DOTFILE_PREFIX.length)}`);
|
|
49
60
|
await fs.move(from, to, { overwrite: true });
|
|
50
61
|
restored.push(to);
|
|
@@ -62,7 +73,9 @@ export async function restoreTemplateDotfiles(dir: string): Promise<string[]> {
|
|
|
62
73
|
export async function renderPlaceholders(dir: string, values: PlaceholderValues): Promise<void> {
|
|
63
74
|
const leftovers: string[] = [];
|
|
64
75
|
for (const file of await listFiles(dir)) {
|
|
65
|
-
if (!TEXT_EXTENSIONS.has(path.extname(file)))
|
|
76
|
+
if (!TEXT_EXTENSIONS.has(path.extname(file))) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
66
79
|
const text = await fs.readFile(file, "utf8");
|
|
67
80
|
if (!PLACEHOLDER.test(text)) { PLACEHOLDER.lastIndex = 0; continue; }
|
|
68
81
|
PLACEHOLDER.lastIndex = 0;
|
|
@@ -92,7 +105,9 @@ export async function applyAgentLayer(templatesRoot: string, targetDir: string,
|
|
|
92
105
|
const agents = path.join(targetDir, AGENTS_FILE);
|
|
93
106
|
const text = await fs.readFile(section, "utf8");
|
|
94
107
|
await fs.appendFile(agents, `\n${text.endsWith("\n") ? text : `${text}\n`}`);
|
|
95
|
-
if (section === staged)
|
|
108
|
+
if (section === staged) {
|
|
109
|
+
await fs.remove(staged);
|
|
110
|
+
}
|
|
96
111
|
}
|
|
97
112
|
await restoreTemplateDotfiles(targetDir);
|
|
98
113
|
await renderPlaceholders(targetDir, values);
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
"lint": "eslint . --max-warnings 0"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@bitbybit-dev/base": "1.
|
|
16
|
-
"@bitbybit-dev/threejs": "1.
|
|
15
|
+
"@bitbybit-dev/base": "1.5.0",
|
|
16
|
+
"@bitbybit-dev/threejs": "1.5.0",
|
|
17
17
|
"three": "0.186.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@bitbybit-dev/occt": "1.
|
|
20
|
+
"@bitbybit-dev/occt": "1.5.0",
|
|
21
21
|
"@eslint/js": "10.0.1",
|
|
22
22
|
"@types/node": "22.20.1",
|
|
23
23
|
"@types/three": "0.186.0",
|
|
@@ -67,8 +67,8 @@ for (const part of model.parts) {
|
|
|
67
67
|
if (edges === 0) problems.push(`${part.id} has no edges`);
|
|
68
68
|
} else {
|
|
69
69
|
if (solids.length === 0) problems.push(`${part.id} has no solid`);
|
|
70
|
-
const
|
|
71
|
-
if (!
|
|
70
|
+
const valid = await Promise.all(solids.map((solid) => occt.shapeFix.isValid({ shape: solid })));
|
|
71
|
+
if (!valid.every(Boolean)) problems.push(`${part.id} is not a valid solid`);
|
|
72
72
|
if (!(volume > 0)) problems.push(`${part.id} has no volume`);
|
|
73
73
|
}
|
|
74
74
|
parts[part.id] = { solids: solids.length, faces: (await occt.shapes.face.getFaces({ shape: part.shape })).length, edges, volume: round(volume) };
|
|
@@ -141,7 +141,7 @@ const reloadedSolids = reloadedShape ? (await solidsOf(reloadedShape)).length :
|
|
|
141
141
|
const expectedSolids = expectedPlacements(model).solidsOf((part) => statsOf(part.id).solids);
|
|
142
142
|
if (reloadedSolids !== expectedSolids) problems.push(`the STEP reads back with ${reloadedSolids} solids, not ${expectedSolids}`);
|
|
143
143
|
const origin: [number, number, number] = [0, 0, 0];
|
|
144
|
-
const box = reloadedShape ? await occt.
|
|
144
|
+
const box = reloadedShape ? await occt.analysis.measure.tightBoundingBox({ shape: reloadedShape }) : { min: origin, max: origin };
|
|
145
145
|
const nutTop = model.lift + MOTOR_TOP + 3.5;
|
|
146
146
|
const reach = model.params.armLength + model.params.propDiameter / 2;
|
|
147
147
|
if (Math.abs(box.min[2]) > 0.5) problems.push(`the feet stand at z ${round(box.min[2])} in the Z-up STEP, not on the ground`);
|
|
@@ -93,7 +93,7 @@ export async function plate(occt: Occt): Promise<Shape> {
|
|
|
93
93
|
export async function honeycomb(occt: Occt): Promise<Shape> {
|
|
94
94
|
const h = FRAME.honeycomb;
|
|
95
95
|
const shell = await canopy(occt);
|
|
96
|
-
const centre = await occt.
|
|
96
|
+
const { center: centre } = await occt.analysis.measure.tightBoundingBox({ shape: shell });
|
|
97
97
|
const grown = await occt.transforms.scale3d({ shape: shell, scale: [h.grow, h.grow, h.grow], center: [centre[0], 0, centre[2]] });
|
|
98
98
|
const faces = await occt.shapes.face.getFaces({ shape: grown });
|
|
99
99
|
const areas = await occt.shapes.face.getFacesAreas({ shapes: faces });
|
|
@@ -321,9 +321,9 @@ export async function antenna(occt: Occt): Promise<Shape> {
|
|
|
321
321
|
|
|
322
322
|
export async function logoFaces(occt: Occt, logo: Shape, width: number): Promise<Shape> {
|
|
323
323
|
const mirrored = await occt.transforms.mirrorAlongNormal({ shape: logo, origin: [0, 0, 0], normal: [1, 0, 0] });
|
|
324
|
-
const size = await occt.
|
|
324
|
+
const { size } = await occt.analysis.measure.tightBoundingBox({ shape: mirrored });
|
|
325
325
|
const scaled = await occt.transforms.scale({ shape: mirrored, factor: width / Math.max(size[0], size[2]) });
|
|
326
|
-
const box = await occt.
|
|
326
|
+
const box = await occt.analysis.measure.tightBoundingBox({ shape: scaled });
|
|
327
327
|
return occt.transforms.translate({ shape: scaled, translation: [-box.center[0], -box.min[1], -box.center[2]] });
|
|
328
328
|
}
|
|
329
329
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
## This template: IFC family house
|
|
2
|
+
|
|
3
|
+
A two-storey family house written as an IFC4 building model with `@bitbybit-dev/ifc`, drawn with Manifold and exported to STEP with OpenCascade. Before changing how the house is written, read the IFC guide of the Bitbybit CAD MCP: `get_guide` with the topic `ifc`, then `ifc-order` and `ifc-mistakes`. Every `ifc` method is described there by its dotted path (`describe` with `ifc.walls.add`) and has examples (`get_examples` with `ifc.doors`).
|
|
4
|
+
|
|
5
|
+
- `src/house/house-plan.ts` is the house as data and the place to make most changes. The model is in metres (`lengthUnit` metre), so every length here is in metres; plans are `[x, y]` on a storey with Z up from its floor, never Y up. `WALL_RUNS` lists the walls run by run with the joins between them, `WINDOWS` and `DOORS` place a type in a wall by its id, `offset` along the wall's axis from its start, `SLABS`, `ROOF`, `CARPORT`, `ROOMS`, `TERRAIN_OUTLINE`, `TREES` and `PROPERTY_SETS` the rest. Every element has an `id` of its own that later entries refer to; ids are unique in the model.
|
|
6
|
+
- `src/house/details.ts` generates the details from the plan: cladding boards cut around each facade's openings and gathered into an assembly per facade (`houseAssemblies`, `userDefined` with an `objectType`), flashings, window surrounds and sills, copings, the solar array, the stair, rainwater pipes, the canopy, the carport frame, glass rails and the study's glazing, all as members and beams with their own materials. A detail is placed in its storey's frame, `[x, y, z]` with z up from the storey's floor.
|
|
7
|
+
- `src/house/build-house.ts` writes the plan into a model in the order IFC needs: the model and storeys, materials and layer sets, walls with their joins, slabs, window and door types and their placements, the roof and the carport, the details and assemblies, the site, rooms, property sets, and quantities last. `HouseAuthor` takes the IFC API itself (`HouseIfc`), so it runs unchanged on `bitbybit.ifc` in the browser and on the in-process library in the smoke. Every call that changes the model assigns the model it returns; a call whose result is dropped changes nothing.
|
|
8
|
+
- `src/scene/draw-house.ts` builds the model's recipe (`ifc.geometry.recipe`) with Manifold (`manifold.recipes.build`, `adjustZtoY` so the Z-up model stands up in Three.js) and draws one mesh per element in the colour of its material, read from the root's `rgba` tag; the root's `globalId` ties a mesh to its element and its layer (a storey, the roof or the garden).
|
|
9
|
+
- `src/export/step-export.ts` starts the OpenCascade worker on the first STEP download only and calls `ifc.geometry.toStep` with `facetedMeshes`, so the trees, which are triangle meshes, are written as faceted solids that every CAD tool opens rather than as tessellated geometry.
|
|
10
|
+
- `src/workers/` holds the three workers. The Manifold and OpenCascade kernels load their WebAssembly from the Bitbybit CDN folder of the installed version; the IFC library needs none.
|
|
11
|
+
- `scripts/smoke.ts` writes the house twice on the in-process library and prints one JSON line: `template`, `schema`, `elements`, `walls`, `windows`, `doors`, `rooms`, `netArea` (square metres), `recipeRoots`, `emptySolids`, `authorMs`, `manifoldMs`, `ifcBytes`, `deterministic`, `stepBytes`, `stepMs` and `problems`. It exits 1 when the house lacks walls, windows, doors, slabs, the roof, members or the site's geographic elements; when an element's geometry cannot be described (`geometry.unsupported`); when the rooms differ from `ROOMS` or one has no area; when Manifold builds nothing for an element; when the two runs write different bytes; or when the STEP export, built on the in-process OpenCascade kernel, lacks its header.
|
|
12
|
+
|
|
13
|
+
Commands:
|
|
14
|
+
|
|
15
|
+
- `npm run dev` serves the viewer at http://localhost:5173
|
|
16
|
+
- `npm run build` typechecks and bundles for production; `npm run typecheck` and `npm run lint` run alone as well
|
|
17
|
+
- `npm run smoke` typechecks, lints, then writes the house headlessly and prints the summary line. The smoke types the in-process IFC library as the same `HouseIfc` the browser code sees, through one `inProcess` cast, and awaits every call, so `HouseAuthor` runs exactly as it does in the browser.
|
|
18
|
+
|
|
19
|
+
To add a room: add an entry to `ROOMS` with its own id, its storey, number, name, outline and height, and run the smoke, whose room count follows `ROOMS`. To add a window: add a window type to `WINDOW_TYPES` if the size is new, then an entry to `WINDOWS` with its own id and name, its wall, its type, its `offset` and its `sill`; the facade's cladding is cut around it on its own. A window or door cuts its own opening in its wall; never add an opening for it as well.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# {{PROJECT_NAME}}
|
|
2
|
+
|
|
3
|
+
A two-storey family house written as an IFC4 building model on the open-source [Bitbybit](https://bitbybit.dev) packages and Three.js. The house is plain data - storeys, layered walls, windows and doors, slabs, a flat roof behind a parapet, a carport, rooms, the garden's terrain and trees - and the IFC library turns it into a real BIM file in your browser: walls that keep their axis, layers and joins, doors and windows placed from shared types and cut into their walls, charred-larch cladding boards gathered into an assembly per facade, U-values and the base quantities of every element. Manifold builds the geometry the model describes and the viewer draws it in its materials; click any part to see its IFC type, name and GlobalId, turn storeys on and off, label the rooms, and download the model as `house.ifc` or, through OpenCascade, as `house.step` nested by site, building, storey and IFC class. Nothing runs on a server: every library runs in the browser, the IFC library as plain TypeScript and the kernels as WebAssembly.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install
|
|
7
|
+
npm run dev # http://localhost:5173
|
|
8
|
+
npm run smoke # typecheck, lint, then the house written headlessly in Node, its geometry and exports checked, a JSON summary
|
|
9
|
+
npm run lint # the lint rules, at error
|
|
10
|
+
npm run build # typecheck and bundle for production
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## How it is put together
|
|
14
|
+
|
|
15
|
+
| File | Role |
|
|
16
|
+
|---|---|
|
|
17
|
+
| `src/house/house-plan.ts` | the house as data: materials and layer sets, door and window types, wall runs, windows and doors, slabs, the roof, rooms, the site and the property sets, in metres |
|
|
18
|
+
| `src/house/details.ts` | the details generated from the plan: cladding boards cut around the openings, flashings, sills, copings, the solar array, the stair, rainwater pipes, the canopy, the carport frame |
|
|
19
|
+
| `src/house/build-house.ts` | `HouseAuthor`, which writes the plan into an IFC model call by call, in the order IFC needs |
|
|
20
|
+
| `src/scene/` | the stage (renderer, camera, light, shadows) and the drawing: Manifold builds the model's recipe and each element is drawn in its material |
|
|
21
|
+
| `src/ui/` | the panel, the room schedule and the room labels |
|
|
22
|
+
| `src/export/step-export.ts` | the STEP download: OpenCascade starts on the first click and builds the model's elements as exact shapes |
|
|
23
|
+
| `src/workers/` | the IFC, Manifold and OpenCascade workers, so authoring and building never block the page |
|
|
24
|
+
| `scripts/smoke.ts` | the headless check an agent or a CI job runs after every change |
|
|
25
|
+
|
|
26
|
+
`HouseAuthor` is written once and runs in two places: in the browser it receives `bitbybit.ifc`, the IFC library in a worker, whose calls return promises; in the smoke it receives the same library in-process.
|
|
27
|
+
|
|
28
|
+
## Make it your house
|
|
29
|
+
|
|
30
|
+
Move a wall in `WALL_RUNS`, add a window to `WINDOWS`, change a layer set's materials or thicknesses in `LAYER_SETS`, or add a room to `ROOMS` in `src/house/house-plan.ts`, then run `npm run smoke`: it writes the house again, checks that every element can be built and tells you what changed. Open the downloaded `house.ifc` in any BIM tool - BIMvision, Bonsai in Blender, Solibri, Archicad or Revit - to see the walls, rooms and properties as a BIM tool reads them.
|
|
31
|
+
|
|
32
|
+
## Working with an AI agent
|
|
33
|
+
|
|
34
|
+
`AGENTS.md` explains the project to a coding agent, and the free Bitbybit CAD MCP server is configured for Claude Code, Cursor and VS Code, so the agent looks the IFC API up instead of guessing it; its IFC guide (`get_guide` with the topic `ifc`) gives the order of calls and the mistakes to avoid. Ask it to add a room or change the facade, then let it run `npm run smoke`.
|
|
35
|
+
|
|
36
|
+
Scaffolded by `@bitbybit-dev/create-app` {{CLI_VERSION}}. [Documentation](https://learn.bitbybit.dev), [the packages](https://github.com/bitbybit-dev/bitbybit), [Discord](https://discord.gg/GSe3VMe).
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { defineConfig, globalIgnores } from "eslint/config";
|
|
2
|
+
import eslint from "@eslint/js";
|
|
3
|
+
import tseslint from "typescript-eslint";
|
|
4
|
+
import noComments from "eslint-plugin-no-comments";
|
|
5
|
+
|
|
6
|
+
const DOUBLE_ASSERTION = ":matches(TSAsExpression, TSTypeAssertion) > :matches(TSAsExpression, TSTypeAssertion).expression[typeAnnotation.type=/^TS(Unknown|Any)Keyword$/]";
|
|
7
|
+
|
|
8
|
+
export default defineConfig([
|
|
9
|
+
globalIgnores(["dist/", "node_modules/", "**/*.d.ts"]),
|
|
10
|
+
{
|
|
11
|
+
files: ["**/*.ts"],
|
|
12
|
+
extends: [eslint.configs.recommended, tseslint.configs.strictTypeChecked, tseslint.configs.stylisticTypeChecked],
|
|
13
|
+
plugins: { "no-comments": noComments },
|
|
14
|
+
languageOptions: { parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname } },
|
|
15
|
+
rules: {
|
|
16
|
+
quotes: ["error", "double", { avoidEscape: true, allowTemplateLiterals: true }],
|
|
17
|
+
semi: ["error", "always"],
|
|
18
|
+
eqeqeq: ["error", "always"],
|
|
19
|
+
curly: ["error", "multi-line"],
|
|
20
|
+
"prefer-const": "error",
|
|
21
|
+
"no-var": "error",
|
|
22
|
+
"max-lines": ["error", { max: 600, skipBlankLines: true, skipComments: true }],
|
|
23
|
+
"no-warning-comments": ["error", { terms: ["todo", "fixme", "hack"], location: "anywhere" }],
|
|
24
|
+
"no-comments/disallowComments": ["error", { allow: ["global", "eslint", "/ <reference"] }],
|
|
25
|
+
"no-restricted-syntax": ["error", { selector: DOUBLE_ASSERTION, message: "A double assertion replaces a type instead of narrowing it: write a type predicate, constrain a generic to the union, or fix the type this is arguing with." }],
|
|
26
|
+
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_", varsIgnorePattern: "^_", caughtErrorsIgnorePattern: "^_", ignoreRestSiblings: true }],
|
|
27
|
+
"@typescript-eslint/no-explicit-any": "error",
|
|
28
|
+
"@typescript-eslint/no-non-null-assertion": "error",
|
|
29
|
+
"@typescript-eslint/explicit-function-return-type": ["error", { allowExpressions: true, allowTypedFunctionExpressions: true, allowHigherOrderFunctions: true, allowDirectConstAssertionInArrowFunctions: true }],
|
|
30
|
+
"@typescript-eslint/consistent-type-imports": ["error", { prefer: "type-imports", fixStyle: "separate-type-imports", disallowTypeAnnotations: false }],
|
|
31
|
+
"@typescript-eslint/restrict-template-expressions": ["error", { allowNumber: true, allowBoolean: true, allowNullish: false, allowRegExp: false }],
|
|
32
|
+
"@typescript-eslint/naming-convention": [
|
|
33
|
+
"error",
|
|
34
|
+
{ selector: "default", format: ["camelCase"], leadingUnderscore: "allow" },
|
|
35
|
+
{ selector: "variable", format: ["camelCase", "UPPER_CASE"], leadingUnderscore: "allow" },
|
|
36
|
+
{ selector: "parameter", format: ["camelCase"], leadingUnderscore: "allow" },
|
|
37
|
+
{ selector: "typeLike", format: ["PascalCase"] },
|
|
38
|
+
{ selector: "property", format: null },
|
|
39
|
+
{ selector: "method", format: ["camelCase"] },
|
|
40
|
+
{ selector: "import", format: null },
|
|
41
|
+
],
|
|
42
|
+
"@typescript-eslint/only-throw-error": "error",
|
|
43
|
+
"@typescript-eslint/unbound-method": ["error", { ignoreStatic: true }],
|
|
44
|
+
"@typescript-eslint/non-nullable-type-assertion-style": "off",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
]);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<link rel="icon" href="/favicon.ico" sizes="48x48" />
|
|
7
|
+
<link rel="icon" type="image/png" href="/logo.png" sizes="150x150" />
|
|
8
|
+
<link rel="apple-touch-icon" href="/logo.png" />
|
|
9
|
+
<title>IFC family house</title>
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<canvas id="three-canvas"></canvas>
|
|
13
|
+
<div id="labels" class="labels"></div>
|
|
14
|
+
<div id="ui"></div>
|
|
15
|
+
<div id="status" class="status">Loading</div>
|
|
16
|
+
<a class="logo" href="https://bitbybit.dev" target="_blank" rel="noopener noreferrer">
|
|
17
|
+
<img src="/logo.png" alt="" />
|
|
18
|
+
<div>geometry by bitbybit.dev</div>
|
|
19
|
+
</a>
|
|
20
|
+
<script type="module" src="/src/main.ts"></script>
|
|
21
|
+
</body>
|
|
22
|
+
</html>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bitbybit-ifc-house",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "npm run typecheck && vite build",
|
|
9
|
+
"preview": "vite preview",
|
|
10
|
+
"smoke": "npm run typecheck && npm run lint && tsx scripts/smoke.ts",
|
|
11
|
+
"typecheck": "tsc --noEmit",
|
|
12
|
+
"lint": "eslint . --max-warnings 0"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@bitbybit-dev/ifc": "1.5.0",
|
|
16
|
+
"@bitbybit-dev/ifc-worker": "1.5.0",
|
|
17
|
+
"@bitbybit-dev/manifold-worker": "1.5.0",
|
|
18
|
+
"@bitbybit-dev/occt": "1.5.0",
|
|
19
|
+
"@bitbybit-dev/occt-worker": "1.5.0",
|
|
20
|
+
"@bitbybit-dev/threejs": "1.5.0",
|
|
21
|
+
"manifold-3d": "3.5.3",
|
|
22
|
+
"three": "0.186.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@bitbybit-dev/manifold": "1.5.0",
|
|
26
|
+
"@eslint/js": "10.0.1",
|
|
27
|
+
"@types/node": "22.20.1",
|
|
28
|
+
"@types/three": "0.186.0",
|
|
29
|
+
"eslint": "10.10.0",
|
|
30
|
+
"eslint-plugin-no-comments": "1.2.1",
|
|
31
|
+
"tsx": "^4.19.0",
|
|
32
|
+
"typescript": "5.9.3",
|
|
33
|
+
"typescript-eslint": "8.70.0",
|
|
34
|
+
"vite": "^6.3.2"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { readdirSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import Module from "manifold-3d";
|
|
5
|
+
import initOpenCascade from "@bitbybit-dev/occt/bitbybit-dev-occt/index.js";
|
|
6
|
+
import { OCCTService, OccHelper, VectorHelperService, ShapesHelperService } from "@bitbybit-dev/occt";
|
|
7
|
+
import { ManifoldService } from "@bitbybit-dev/manifold";
|
|
8
|
+
import { IFCService } from "@bitbybit-dev/ifc";
|
|
9
|
+
import { HouseAuthor } from "../src/house/build-house.ts";
|
|
10
|
+
import { ROOMS } from "../src/house/house-plan.ts";
|
|
11
|
+
import type { HouseIfc, HouseModel } from "../src/house/house-types.ts";
|
|
12
|
+
|
|
13
|
+
const TIME_STAMP = "2026-01-01T12:00:00";
|
|
14
|
+
const STEP_HEADER = "ISO-10303-21";
|
|
15
|
+
const REQUIRED: readonly (readonly [string, number])[] = [["IfcWall", 1], ["IfcWindow", 1], ["IfcDoor", 1], ["IfcSlab", 1], ["IfcRoof", 1], ["IfcMember", 1], ["IfcGeographicElement", 1]];
|
|
16
|
+
|
|
17
|
+
function inProcess(service: object): HouseIfc {
|
|
18
|
+
return service as HouseIfc;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const ifc = inProcess(new IFCService());
|
|
22
|
+
const problems: string[] = [];
|
|
23
|
+
const quiet = (): void => undefined;
|
|
24
|
+
|
|
25
|
+
async function authorHouse(): Promise<HouseModel> {
|
|
26
|
+
return new HouseAuthor(ifc, quiet).build();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function equalBytes(a: Uint8Array, b: Uint8Array): boolean {
|
|
30
|
+
return a.length === b.length && a.every((value, index) => value === b[index]);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const authorStarted = Date.now();
|
|
34
|
+
const house = await authorHouse();
|
|
35
|
+
const authorMs = Date.now() - authorStarted;
|
|
36
|
+
const model = house.model;
|
|
37
|
+
|
|
38
|
+
const summary = await ifc.model.summary({ model });
|
|
39
|
+
const counts = summary.elementCounts;
|
|
40
|
+
for (const [type, least] of REQUIRED) {
|
|
41
|
+
if ((counts[type] ?? 0) < least) {
|
|
42
|
+
problems.push(`the house has ${String(counts[type] ?? 0)} ${type}, expected at least ${String(least)}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const unsupported = await ifc.geometry.unsupported({ model });
|
|
47
|
+
for (const problem of unsupported) {
|
|
48
|
+
problems.push(`${problem.type} ${problem.globalId} has geometry the recipe cannot describe: ${problem.message}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const spaces = await ifc.spaces.list({ model });
|
|
52
|
+
if (spaces.length !== ROOMS.length) {
|
|
53
|
+
problems.push(`the house has ${String(spaces.length)} rooms, the plan ${String(ROOMS.length)}`);
|
|
54
|
+
}
|
|
55
|
+
for (const space of spaces.filter((candidate) => candidate.area <= 0)) {
|
|
56
|
+
problems.push(`room ${space.name} has no area`);
|
|
57
|
+
}
|
|
58
|
+
const netArea = spaces.reduce((sum, space) => sum + space.area, 0);
|
|
59
|
+
|
|
60
|
+
const recipe = await ifc.geometry.recipe({ model });
|
|
61
|
+
const wasm = await Module();
|
|
62
|
+
wasm.setup();
|
|
63
|
+
const manifold = new ManifoldService(wasm);
|
|
64
|
+
const manifoldStarted = Date.now();
|
|
65
|
+
const solids = manifold.recipes.build({ recipe, adjustZtoY: true, emptyWhenFailed: true });
|
|
66
|
+
const manifoldMs = Date.now() - manifoldStarted;
|
|
67
|
+
const empty = recipe.roots.filter((_, index) => solids[index]?.isEmpty() ?? true);
|
|
68
|
+
for (const root of empty) {
|
|
69
|
+
problems.push(`Manifold built nothing for ${String(root.tag["type"])} ${String(root.tag["name"])} (${String(root.tag["globalId"])})`);
|
|
70
|
+
}
|
|
71
|
+
for (const solid of solids) {
|
|
72
|
+
solid.delete();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const ifcBytes = await ifc.model.writeBytes({ model, fileName: "house.ifc", timeStamp: TIME_STAMP });
|
|
76
|
+
const again = await ifc.model.writeBytes({ model: (await authorHouse()).model, fileName: "house.ifc", timeStamp: TIME_STAMP });
|
|
77
|
+
const deterministic = equalBytes(ifcBytes, again);
|
|
78
|
+
if (!deterministic) {
|
|
79
|
+
problems.push("two runs wrote different files: something in the house depends on more than its own plan");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const require = createRequire(import.meta.url);
|
|
83
|
+
const kernelDir = dirname(require.resolve("@bitbybit-dev/occt/bitbybit-dev-occt/index.js"));
|
|
84
|
+
const wasmFile = readdirSync(kernelDir).find((file) => file.endsWith(".wasm"));
|
|
85
|
+
if (!wasmFile) throw new Error(`no OCCT kernel (.wasm) found in ${kernelDir}`);
|
|
86
|
+
const occ = await initOpenCascade({ locateFile: (file: string): string => (file.endsWith(".wasm") ? join(kernelDir, wasmFile) : file), print: (): void => undefined });
|
|
87
|
+
const occt = new OCCTService(occ, new OccHelper(new VectorHelperService(), new ShapesHelperService(), occ));
|
|
88
|
+
const stepStarted = Date.now();
|
|
89
|
+
const document = occt.recipes.buildDocument({ recipe, name: "Family house", facetedMeshes: true });
|
|
90
|
+
const step = occt.assembly.manager.exportDocumentToStep({ document, fileName: "house.step" });
|
|
91
|
+
document.delete();
|
|
92
|
+
const stepMs = Date.now() - stepStarted;
|
|
93
|
+
if (!new TextDecoder().decode(step.subarray(0, STEP_HEADER.length)).startsWith(STEP_HEADER)) {
|
|
94
|
+
problems.push("the STEP export does not start with a STEP header");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
console.log(JSON.stringify({
|
|
98
|
+
template: "ifc-house",
|
|
99
|
+
schema: summary.schema,
|
|
100
|
+
elements: Object.values(counts).reduce((sum, count) => sum + count, 0),
|
|
101
|
+
walls: counts["IfcWall"] ?? 0,
|
|
102
|
+
windows: counts["IfcWindow"] ?? 0,
|
|
103
|
+
doors: counts["IfcDoor"] ?? 0,
|
|
104
|
+
rooms: spaces.length,
|
|
105
|
+
netArea: Math.round(netArea * 10) / 10,
|
|
106
|
+
recipeRoots: recipe.roots.length,
|
|
107
|
+
emptySolids: empty.length,
|
|
108
|
+
authorMs,
|
|
109
|
+
manifoldMs,
|
|
110
|
+
ifcBytes: ifcBytes.length,
|
|
111
|
+
deterministic,
|
|
112
|
+
stepBytes: step.length,
|
|
113
|
+
stepMs,
|
|
114
|
+
problems,
|
|
115
|
+
}));
|
|
116
|
+
if (problems.length) {
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { OccStateEnum } from "@bitbybit-dev/occt-worker";
|
|
2
|
+
import type { BitByBitBase, Inputs } from "@bitbybit-dev/threejs";
|
|
3
|
+
|
|
4
|
+
let starting: Promise<void> | undefined;
|
|
5
|
+
|
|
6
|
+
function startOpenCascade(bitbybit: BitByBitBase): Promise<void> {
|
|
7
|
+
starting ??= new Promise<void>((resolve, reject) => {
|
|
8
|
+
const manager = bitbybit.occtWorkerManager;
|
|
9
|
+
const subscription = manager.occWorkerState$.subscribe((info) => {
|
|
10
|
+
if (info.state === OccStateEnum.initialised) {
|
|
11
|
+
subscription.unsubscribe();
|
|
12
|
+
resolve();
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
const worker = new Worker(new URL("../workers/occt.worker.ts", import.meta.url), { name: "OCC_WORKER", type: "module" });
|
|
16
|
+
worker.addEventListener("error", (event) => {
|
|
17
|
+
subscription.unsubscribe();
|
|
18
|
+
starting = undefined;
|
|
19
|
+
reject(new Error(`OpenCascade could not start: ${event.message}`));
|
|
20
|
+
});
|
|
21
|
+
manager.setOccWorker(worker);
|
|
22
|
+
});
|
|
23
|
+
return starting;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function houseStep(bitbybit: BitByBitBase, model: Inputs.IFC.IfcModelPointer): Promise<Uint8Array> {
|
|
27
|
+
await startOpenCascade(bitbybit);
|
|
28
|
+
return bitbybit.ifc.geometry.toStep({ model, name: "Family house", fileName: "house.step", facetedMeshes: true });
|
|
29
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { IFC, type Base } from "@bitbybit-dev/ifc/lib/api/inputs";
|
|
2
|
+
import {
|
|
3
|
+
CARPORT, CARPORT_DECK_BOTTOM, DOOR_TYPES, DOORS, FIRST_FLOOR_ELEVATION, HARD_SURFACES, LAYER_SETS, MATERIALS, PASSAGES, PROPERTY_SETS, ROOF, ROOMS, SLABS, TERRAIN_OUTLINE, TREES, WALL_RUNS, WINDOW_TYPES, WINDOWS, rect,
|
|
4
|
+
} from "./house-plan";
|
|
5
|
+
import { houseAssemblies, houseDetails } from "./details";
|
|
6
|
+
import type { DetailSpec, HouseIfc, HouseModel, Layer } from "./house-types";
|
|
7
|
+
|
|
8
|
+
type Model = IFC.IfcModelPointer;
|
|
9
|
+
|
|
10
|
+
const FRAME = { frameMaterial: "Anthracite aluminium", glassMaterial: "Clear glass", frameThickness: 0.07, frameDepth: 0.09, glassThickness: 0.03 };
|
|
11
|
+
const LINING = { liningThickness: 0.06, liningDepth: 0.12, panelThickness: 0.05 };
|
|
12
|
+
|
|
13
|
+
export class HouseAuthor {
|
|
14
|
+
private model!: Model;
|
|
15
|
+
private readonly layers = new Map<string, Layer>();
|
|
16
|
+
private readonly ifc: HouseIfc;
|
|
17
|
+
private readonly progress: (message: string) => void;
|
|
18
|
+
|
|
19
|
+
constructor(ifc: HouseIfc, progress: (message: string) => void) {
|
|
20
|
+
this.ifc = ifc;
|
|
21
|
+
this.progress = progress;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async build(): Promise<HouseModel> {
|
|
25
|
+
const ifc = this.ifc;
|
|
26
|
+
this.progress("Setting up the project");
|
|
27
|
+
this.model = await ifc.model.create({ name: "Family house", lengthUnit: IFC.lengthUnitEnum.metre, seed: "ifc-family-house" });
|
|
28
|
+
this.model = await ifc.spatial.addStorey({ model: this.model, id: "ground", name: "Ground floor", elevation: 0 });
|
|
29
|
+
this.model = await ifc.spatial.addStorey({ model: this.model, id: "first", name: "First floor", elevation: FIRST_FLOOR_ELEVATION });
|
|
30
|
+
await this.addMaterials();
|
|
31
|
+
this.progress("Raising the walls");
|
|
32
|
+
await this.addWalls();
|
|
33
|
+
this.progress("Laying the floors");
|
|
34
|
+
await this.addSlabs();
|
|
35
|
+
this.progress("Fitting windows and doors");
|
|
36
|
+
await this.addWindowsAndDoors();
|
|
37
|
+
this.progress("Roofing and the carport");
|
|
38
|
+
await this.addRoof();
|
|
39
|
+
await this.addCarport();
|
|
40
|
+
this.progress("Cladding, flashings, the stair and the solar array");
|
|
41
|
+
const details = houseDetails();
|
|
42
|
+
await this.addDetails(details);
|
|
43
|
+
await this.addAssemblies(details);
|
|
44
|
+
this.progress("Shaping the garden");
|
|
45
|
+
await this.addSite();
|
|
46
|
+
this.progress("Naming the rooms");
|
|
47
|
+
await this.addRooms();
|
|
48
|
+
await this.addProperties();
|
|
49
|
+
this.progress("Measuring quantities");
|
|
50
|
+
this.model = await ifc.quantities.compute({ model: this.model });
|
|
51
|
+
return { model: this.model, layers: await this.layersByGlobalId(), rooms: ROOMS };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private remember(id: string, layer: Layer): string {
|
|
55
|
+
this.layers.set(id, layer);
|
|
56
|
+
return id;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private async layersByGlobalId(): Promise<Map<string, Layer>> {
|
|
60
|
+
const entries = await Promise.all([...this.layers].map(async ([id, layer]) => [await this.ifc.model.globalIdOf({ model: this.model, id }), layer] as const));
|
|
61
|
+
return new Map(entries);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private async addMaterials(): Promise<void> {
|
|
65
|
+
const ifc = this.ifc;
|
|
66
|
+
for (const material of MATERIALS) {
|
|
67
|
+
this.model = await ifc.materials.add({ model: this.model, ...material });
|
|
68
|
+
}
|
|
69
|
+
for (const layerSet of LAYER_SETS) {
|
|
70
|
+
this.model = await ifc.materials.addLayerSet({ model: this.model, ...layerSet });
|
|
71
|
+
}
|
|
72
|
+
for (const type of WINDOW_TYPES) {
|
|
73
|
+
this.model = await ifc.windows.addType({ model: this.model, ...type, ...FRAME });
|
|
74
|
+
}
|
|
75
|
+
for (const type of DOOR_TYPES) {
|
|
76
|
+
this.model = await ifc.doors.addType({
|
|
77
|
+
model: this.model, id: type.id, name: type.name, width: type.width, height: type.height, ...LINING, operation: type.operation,
|
|
78
|
+
liningMaterial: type.lining, panelMaterial: type.panel, handle: type.handle, handleMaterial: type.handleMaterial,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private async addWalls(): Promise<void> {
|
|
84
|
+
const ifc = this.ifc;
|
|
85
|
+
for (const run of WALL_RUNS) {
|
|
86
|
+
const layer: Layer = run.storey === "ground" ? "ground" : "first";
|
|
87
|
+
for (const wall of run.walls) {
|
|
88
|
+
this.model = await ifc.walls.add({
|
|
89
|
+
model: this.model, storey: run.storey, id: this.remember(wall.id, layer), name: wall.name, start: wall.start, end: wall.end,
|
|
90
|
+
height: wall.height ?? run.height, baseOffset: run.baseOffset, layerSet: run.layerSet, alignment: run.alignment,
|
|
91
|
+
predefinedType: run.external ? IFC.wallPredefinedTypeEnum.standard : IFC.wallPredefinedTypeEnum.partitioning,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
for (const [wall, other] of run.joins) {
|
|
95
|
+
this.model = await ifc.walls.connect({ model: this.model, wall, other });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private async addSlabs(): Promise<void> {
|
|
101
|
+
for (const slab of SLABS) {
|
|
102
|
+
this.model = await this.ifc.slabs.add({
|
|
103
|
+
model: this.model, storey: slab.storey, id: this.remember(slab.id, slab.layer), name: slab.name,
|
|
104
|
+
outline: slab.outline, holes: slab.holes, layerSet: slab.layerSet, topOffset: slab.topOffset, predefinedType: slab.kind,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private layerOfWall(wall: string): Layer {
|
|
110
|
+
return this.layers.get(wall) ?? "ground";
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private async addWindowsAndDoors(): Promise<void> {
|
|
114
|
+
const ifc = this.ifc;
|
|
115
|
+
for (const window of WINDOWS) {
|
|
116
|
+
this.model = await ifc.windows.add({ model: this.model, wall: window.wall, windowType: window.type, id: this.remember(window.id, this.layerOfWall(window.wall)), name: window.name, offset: window.offset, sill: window.sill });
|
|
117
|
+
}
|
|
118
|
+
for (const door of DOORS) {
|
|
119
|
+
this.model = await ifc.doors.add({ model: this.model, wall: door.wall, doorType: door.type, id: this.remember(door.id, this.layerOfWall(door.wall)), name: door.name, offset: door.offset, sill: door.sill });
|
|
120
|
+
}
|
|
121
|
+
for (const passage of PASSAGES) {
|
|
122
|
+
this.model = await ifc.openings.add({ model: this.model, wall: passage.wall, id: passage.id, name: passage.name, offset: passage.offset, sill: 0, width: passage.width, height: passage.height });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private async addRoof(): Promise<void> {
|
|
127
|
+
this.model = await this.ifc.roofs.add({
|
|
128
|
+
model: this.model, storey: "first", id: this.remember(ROOF.id, "roof"), name: ROOF.name,
|
|
129
|
+
outline: ROOF.outline, kind: IFC.roofKindEnum.flat, layerSet: ROOF.layerSet, baseOffset: ROOF.baseOffset,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private async addCarport(): Promise<void> {
|
|
134
|
+
const ifc = this.ifc;
|
|
135
|
+
const { x0, x1, y0, y1, beam, post } = CARPORT;
|
|
136
|
+
this.model = await ifc.roofs.add({
|
|
137
|
+
model: this.model, storey: "ground", id: this.remember("carport-roof", "garden"), name: "Carport roof",
|
|
138
|
+
outline: rect(x0 + beam.width, y0 + beam.width, x1, y1 - beam.width), kind: IFC.roofKindEnum.flat, layerSet: "Carport roof", baseOffset: CARPORT_DECK_BOTTOM,
|
|
139
|
+
});
|
|
140
|
+
const corners: Base.Point2[] = [[x0 + post / 2, y0 + post / 2], [x0 + post / 2, y1 - post / 2]];
|
|
141
|
+
for (const [index, position] of corners.entries()) {
|
|
142
|
+
this.model = await ifc.columns.add({
|
|
143
|
+
model: this.model, storey: "ground", id: this.remember(`carport-post-${index + 1}`, "garden"), name: "Carport post",
|
|
144
|
+
position, height: CARPORT.clearance, width: post, depth: post, material: "Blackened steel",
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private async addDetails(details: DetailSpec[]): Promise<void> {
|
|
150
|
+
const { profileKindEnum, memberPredefinedTypeEnum } = IFC;
|
|
151
|
+
for (const detail of details) {
|
|
152
|
+
const common = {
|
|
153
|
+
model: this.model, storey: detail.storey, id: this.remember(detail.id, detail.layer), name: detail.name, start: detail.start, end: detail.end, material: detail.material,
|
|
154
|
+
profile: detail.radius === undefined ? profileKindEnum.rectangle : profileKindEnum.circle, width: detail.width, depth: detail.depth, radius: detail.radius, rotation: detail.rotation ?? 0,
|
|
155
|
+
};
|
|
156
|
+
this.model = detail.beam
|
|
157
|
+
? await this.ifc.beams.add(common)
|
|
158
|
+
: await this.ifc.members.add({ ...common, predefinedType: detail.kind ?? memberPredefinedTypeEnum.member });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private async addAssemblies(details: DetailSpec[]): Promise<void> {
|
|
163
|
+
const { elementAssemblyPredefinedTypeEnum } = IFC;
|
|
164
|
+
for (const assembly of houseAssemblies()) {
|
|
165
|
+
this.model = await this.ifc.assemblies.add({
|
|
166
|
+
model: this.model, id: assembly.id, name: assembly.name, parts: details.filter((detail) => detail.assembly === assembly.id).map((detail) => detail.id),
|
|
167
|
+
predefinedType: elementAssemblyPredefinedTypeEnum.userDefined, objectType: assembly.objectType,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
private async addSite(): Promise<void> {
|
|
173
|
+
const site = this.ifc.site;
|
|
174
|
+
this.model = await site.addTerrain({ model: this.model, id: this.remember("terrain", "garden"), name: "Garden", outline: TERRAIN_OUTLINE, holes: [HARD_SURFACES], material: "Lawn" });
|
|
175
|
+
for (const tree of TREES) {
|
|
176
|
+
this.model = await site.addTree({
|
|
177
|
+
model: this.model, id: this.remember(tree.id, "garden"), name: tree.species, species: tree.species, position: tree.position,
|
|
178
|
+
height: tree.height, crownRadius: tree.crown, trunkRadius: tree.trunk, crownMaterial: tree.foliage, trunkMaterial: tree.bark,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
private async addRooms(): Promise<void> {
|
|
184
|
+
for (const room of ROOMS) {
|
|
185
|
+
this.model = await this.ifc.spaces.add({ model: this.model, storey: room.storey, id: room.id, name: room.number, longName: room.name, outline: room.outline, height: room.height });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
private async addProperties(): Promise<void> {
|
|
190
|
+
for (const set of PROPERTY_SETS) {
|
|
191
|
+
this.model = await this.ifc.properties.addSet({ model: this.model, elements: set.elements, name: set.name, properties: set.properties });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|