Skip to content

armgit / bygga

Public Imported from GitHub
0

IKEA assembly, step by step: animated, manual-style 3D guides. Scan any paper manual with Together AI.

TypeScript

Add round tops, wall hanging and new kinds to plans

Youssef185832133aa7
diff --git a/src/lib/plan/cabinet.ts b/src/lib/plan/cabinet.ts
index 7c8d842..d07922d 100644
--- a/src/lib/plan/cabinet.ts
+++ b/src/lib/plan/cabinet.ts
@@ -23,6 +23,8 @@ export function buildCabinet(b: PlanBuilder, s: ProductSpec) {
if (p.fronts === "tilt") return tiltCabinet(b, s, p);
const W = s.size.w * 10, H = s.size.h * 10, D = s.size.d * 10;
const t = p.thickness;
+ const wall = !!s.cabinet?.wall;
+ if (wall) p.plinth = false;
const base = p.plinth ? 70 : 0;
const lying = H > 1100;
const f = new FrameKit(b, {
@@ -158,7 +160,8 @@ export function buildCabinet(b: PlanBuilder, s: ProductSpec) {
}
}
- if (H >= 800) f.anchor();
+ if (wall) f.hang();
+ else if (H >= 800) f.anchor();
}
/** Shoe cabinets like BISSA or HEMNES: stacked compartments with fronts that tip open from the bottom. */
diff --git a/src/lib/plan/frame.ts b/src/lib/plan/frame.ts
index 50aa45c..4395b8b 100644
--- a/src/lib/plan/frame.ts
+++ b/src/lib/plan/frame.ts
@@ -337,19 +337,26 @@ export class FrameKit {
anchor(top = this.top, ySurface = this.o.H, tools: ToolId[] = ["drill", "screwdriver", "pencil"]) {
anchorStep(this.b, { W: this.o.W, D: this.o.D, top, y: ySurface, backZ: -this.o.D / 2 - (this.backPanel ? 3 : 0), tools });
}
+
+ /** Wall cabinets and wall shelves: the last step hangs them up. */
+ hang() {
+ anchorStep(this.b, { W: this.o.W, D: this.o.D, top: this.top, y: this.o.H, backZ: -this.o.D / 2 - (this.backPanel ? 3 : 0), tools: ["drill", "screwdriver", "pencil", "level"], hang: true });
+ }
}
export function anchorStep(
b: PlanBuilder,
- o: { W: number; D: number; top: string; y: number; backZ: number; tools?: ToolId[]; severe?: boolean },
+ o: { W: number; D: number; top: string; y: number; backZ: number; tools?: ToolId[]; severe?: boolean; hang?: boolean },
) {
const xs = o.W > 1000 ? [-o.W / 3, o.W / 3] : [0];
b.step(
{
- title: "Fix it to the wall",
- detail: o.severe
- ? "Furniture like this can tip over if it isn't fixed. Wall screws aren't included: pick ones made for your wall."
- : "Wall screws aren't included. Pick ones made for your wall.",
+ title: o.hang ? "Hang it on the wall" : "Fix it to the wall",
+ detail: o.hang
+ ? "Mark the height with a level first. Wall screws aren't included: pick ones made for your wall."
+ : o.severe
+ ? "Furniture like this can tip over if it isn't fixed. Wall screws aren't included: pick ones made for your wall."
+ : "Wall screws aren't included. Pick ones made for your wall.",
tools: o.tools ?? ["drill", "screwdriver", "pencil"],
kind: "anchor",
wall: true,
diff --git a/src/lib/plan/shelf.ts b/src/lib/plan/shelf.ts
index 5854da8..d7d4608 100644
--- a/src/lib/plan/shelf.ts
+++ b/src/lib/plan/shelf.ts
@@ -28,6 +28,7 @@ export function buildShelf(b: PlanBuilder, s: ProductSpec) {
function bookcase(b: PlanBuilder, s: ProductSpec, p: ShelfParams) {
const W = s.size.w * 10, H = s.size.h * 10, D = s.size.d * 10;
const t = p.outer;
+ if (s.shelf?.wall) p.plinth = false;
const base = p.plinth ? 60 : 0;
const lying = H > 1100;
const f = new FrameKit(b, {
@@ -47,7 +48,8 @@ function bookcase(b: PlanBuilder, s: ProductSpec, p: ShelfParams) {
if (p.back) f.backSteps();
if (p.back || lying) f.standUp();
f.shelves(p.shelves);
- if (H >= 900) f.anchor();
+ if (s.shelf?.wall) f.hang();
+ else if (H >= 900) f.anchor();
}
/** Cube shelving: full-width top and bottom, sides between, an inner grid on dowels. Built upright from the bottom. */
diff --git a/src/lib/plan/table.ts b/src/lib/plan/table.ts
index 0406bc2..2ebb803 100644
--- a/src/lib/plan/table.ts
+++ b/src/lib/plan/table.ts
@@ -4,24 +4,28 @@ import { clamp } from "./math";
export function defaultsTable(s: ProductSpec): TableParams {
const p = s.table ?? {};
- return {
+ const out: TableParams = {
topThickness: clamp(p.topThickness ?? 30, 15, 60),
legs: p.legs === "round" ? "round" : "square",
legSize: clamp(p.legSize ?? 50, 25, 90),
shelf: p.shelf ?? false,
attach: p.attach ?? "screw",
};
+ // a round top sits on legs set in under it: no apron rails or lower shelf to square off
+ if (p.round) Object.assign(out, { round: true, shelf: false, attach: out.attach === "apron" ? "plate" : out.attach });
+ return out;
}
export function buildTable(b: PlanBuilder, s: ProductSpec) {
const p = defaultsTable(s);
- const W = s.size.w * 10, D = s.size.d * 10, H = s.size.h * 10;
+ const W = s.size.w * 10, H = s.size.h * 10;
+ const D = p.round ? W : s.size.d * 10;
const tt = p.topThickness, ls = p.legSize;
- const inset = p.attach === "screw" ? 0 : p.attach === "plate" ? 30 : 45;
+ const inset = p.round ? (W / 2) * (1 - 0.78 / Math.SQRT2) - ls / 2 : p.attach === "screw" ? 0 : p.attach === "plate" ? 30 : 45;
const Lh = H - tt;
const big = W > 1000;
- const topT = b.part(s.category.toLowerCase().includes("desk") ? "Desk top" : "Table top", [W, tt, D]);
+ const topT = b.part(s.category.toLowerCase().includes("desk") ? "Desk top" : "Table top", [W, tt, D], p.round ? { shape: "cyl" } : undefined);
const top = b.place(topT, [0, H - tt / 2, 0]);
const legT = b.part("Leg", p.legs === "round" ? [ls, Lh, ls] : [ls, Lh, ls], { shape: p.legs === "round" ? "cyl" : "box", material: "wood" });
const corners: [number, number][] = [
diff --git a/src/lib/products.ts b/src/lib/products.ts
index 6448689..be952a6 100644
--- a/src/lib/products.ts
+++ b/src/lib/products.ts
@@ -24,9 +24,18 @@ export type Kind =
| "stool"
| "bench"
| "sofa"
- | "armchair";
+ | "armchair"
+ // added with the IKEA product data: existing archetypes with other parameters
+ | "wallshelf"
+ | "wallcab"
+ | "kitchen"
+ | "trolley"
+ | "bar"
+ | "console"
+ | "kidstable"
+ | "kidschair";
-type X = {
+export type X = {
rows?: number;
cols?: 1 | 2;
knobs?: "none" | "knob" | "bar";
@@ -43,9 +52,11 @@ type X = {
attach?: "screw" | "plate" | "apron";
shelf?: boolean;
min?: number;
+ round?: boolean;
+ seatH?: number;
};
-type Row = [name: string, kind: Kind, variant: string, w: number, h: number, d: number, x?: X, keywords?: string];
+export type Row = [name: string, kind: Kind, variant: string, w: number, h: number, d: number, x?: X, keywords?: string];
export const ROWS: Row[] = [
// shelving and bookcases
@@ -215,21 +226,26 @@ export const ROWS: Row[] = [
const MIN: Record<Kind, number> = {
cube: 40, bookcase: 50, open: 40, chest: 90, nightstand: 40, desk: 25, coffee: 20, side: 15, dining: 40,
bed: 100, wardrobe: 120, cabinet: 60, sideboard: 80, tv: 60, shoe: 45, chair: 25, stool: 12, bench: 20, sofa: 40, armchair: 30,
+ wallshelf: 25, wallcab: 40, kitchen: 50, trolley: 25, bar: 35, console: 30, kidstable: 15, kidschair: 20,
};
const CATEGORY: Record<Kind, string> = {
cube: "Shelving unit", bookcase: "Bookcase", open: "Shelving unit", chest: "Chest of drawers", nightstand: "Nightstand",
desk: "Desk", coffee: "Coffee table", side: "Side table", dining: "Dining table", bed: "Bed frame", wardrobe: "Wardrobe",
cabinet: "Cabinet", sideboard: "Sideboard", tv: "TV bench", shoe: "Shoe cabinet", chair: "Chair", stool: "Stool",
- bench: "Bench", sofa: "Sofa", armchair: "Armchair",
+ bench: "Bench", sofa: "Sofa", armchair: "Armchair", wallshelf: "Wall shelf", wallcab: "Wall cabinet", kitchen: "Kitchen cabinet",
+ trolley: "Trolley", bar: "Bar table", console: "Console table", kidstable: "Children's table", kidschair: "Children's chair",
};
export const KIND_ARCH: Record<Kind, Archetype> = {
cube: "shelf", bookcase: "shelf", open: "shelf", chest: "drawers", nightstand: "drawers", desk: "table", coffee: "table",
side: "table", dining: "table", bed: "bed", wardrobe: "cabinet", cabinet: "cabinet", sideboard: "cabinet", tv: "cabinet",
- shoe: "cabinet", chair: "seat", stool: "seat", bench: "seat", sofa: "sofa", armchair: "sofa",
+ shoe: "cabinet", chair: "seat", stool: "seat", bench: "seat", sofa: "sofa", armchair: "sofa", wallshelf: "shelf", wallcab: "cabinet",
+ kitchen: "cabinet", trolley: "table", bar: "table", console: "table", kidstable: "table", kidschair: "seat",
};
+const round = (x: X) => (x.round ? { round: true } : {});
+
/** Turn a kind and a size into a full product spec. */
export function specFor(kind: Kind, name: string, variant: string, w: number, h: number, d: number, x: X = {}): Omit<ProductSpec, "source"> {
const big = h > 150 || w > 150;
@@ -256,11 +272,11 @@ export function specFor(kind: Kind, name: string, variant: string, w: number, h:
case "desk":
return { ...base, table: { attach: x.attach ?? "plate", legs: x.legs ?? "round", legSize: x.legs === "square" ? 45 : 34, topThickness: 28, shelf: false } };
case "coffee":
- return { ...base, table: { attach: x.attach ?? "screw", legs: x.legs ?? "square", legSize: 48, topThickness: 40, shelf: x.shelf ?? true } };
+ return { ...base, table: { attach: x.attach ?? "screw", legs: x.legs ?? "square", legSize: 48, topThickness: 40, shelf: x.shelf ?? true, ...round(x) } };
case "side":
- return { ...base, table: { attach: x.attach ?? "screw", legs: "square", legSize: 40, topThickness: 30, shelf: false } };
+ return { ...base, table: { attach: x.attach ?? "screw", legs: "square", legSize: 40, topThickness: 30, shelf: false, ...round(x) } };
case "dining":
- return { ...base, people: w > 140 ? 2 : 1, table: { attach: "apron", legs: x.legs ?? "square", legSize: 55, topThickness: 25, shelf: false } };
+ return { ...base, people: w > 140 ? 2 : 1, table: { attach: "apron", legs: x.legs ?? "square", legSize: 55, topThickness: 25, shelf: false, ...round(x) } };
case "bed":
return { ...base, people: 2, bed: { mattressW: x.m ?? Math.max(80, w - 16), mattressL: x.l ?? 200, headH: h, footH: x.f ?? 38, slats: x.l && x.l < 190 ? 13 : 17, centerBeam: (x.m ?? w) >= 120 } };
case "wardrobe":
@@ -274,7 +290,7 @@ export function specFor(kind: Kind, name: string, variant: string, w: number, h:
case "shoe":
return { ...base, cabinet: { fronts: "tilt", compartments: x.c ?? 2, doors: 0, shelves: 0, rail: false, plinth: false, handles: x.knobs ?? "knob", thickness: 16 } };
case "chair":
- return { ...base, seat: { kind: "chair", seat: "square", seatH: 45, backH: h } };
+ return { ...base, seat: { kind: "chair", seat: "square", seatH: x.seatH ?? 45, backH: h } };
case "stool":
return { ...base, seat: { kind: "stool", seat: "round", seatH: h, splay: true, stretchers: h > 60 } };
case "bench":
@@ -282,6 +298,22 @@ export function specFor(kind: Kind, name: string, variant: string, w: number, h:
case "sofa":
case "armchair":
return { ...base, people: kind === "sofa" ? 2 : 1, sofa: { seats: x.seats ?? (kind === "armchair" ? 1 : Math.max(1, Math.round((w - 30) / 62))), arms: x.arms ?? "wide", legs: "round" } };
+ case "wallshelf":
+ return { ...base, difficulty: 1, people: 1, shelf: { style: "bookcase", shelves: x.shelves ?? Math.max(0, Math.round(h / 35) - 1), fixedShelf: false, back: false, plinth: false, outer: 16, wall: true } };
+ case "wallcab":
+ return { ...base, people: w > 100 ? 2 : 1, cabinet: { doors: x.doors ?? (w > 50 ? 2 : 1), shelves: x.shelves ?? (h > 50 ? 1 : 0), rail: false, plinth: false, handles: x.knobs ?? "knob", thickness: 16, wall: true } };
+ case "kitchen":
+ return { ...base, cabinet: { doors: x.doors ?? (w > 50 ? 2 : 1), shelves: x.shelves ?? Math.max(1, Math.round(h / 45) - 1), rail: false, plinth: true, handles: x.knobs ?? "bar", thickness: 18 } };
+ case "trolley":
+ return { ...base, difficulty: 1, table: { attach: "plate", legs: "round", legSize: 25, topThickness: 20, shelf: true } };
+ case "bar":
+ return { ...base, people: 2, table: { attach: x.attach ?? "apron", legs: x.legs ?? "square", legSize: 50, topThickness: 25, shelf: false, ...round(x) } };
+ case "console":
+ return { ...base, difficulty: 1, table: { attach: "apron", legs: x.legs ?? "square", legSize: 40, topThickness: 22, shelf: x.shelf ?? false } };
+ case "kidstable":
+ return { ...base, difficulty: 1, people: 1, table: { attach: x.attach ?? "screw", legs: x.legs ?? "round", legSize: 40, topThickness: 22, shelf: false, ...round(x) } };
+ case "kidschair":
+ return { ...base, difficulty: 1, seat: { kind: "chair", seat: "square", seatH: x.seatH ?? 31, backH: h } };
}
}
@@ -308,5 +340,6 @@ export const KIND_DEFAULT_SIZE: Record<Kind, [number, number, number]> = {
cube: [77, 77, 39], bookcase: [80, 190, 30], open: [80, 180, 35], chest: [80, 90, 48], nightstand: [42, 55, 40], desk: [120, 74, 60],
coffee: [110, 45, 60], side: [50, 50, 50], dining: [140, 74, 80], bed: [156, 100, 209], wardrobe: [100, 200, 58], cabinet: [80, 120, 40],
sideboard: [140, 85, 45], tv: [150, 50, 42], shoe: [60, 100, 28], chair: [44, 88, 50], stool: [35, 45, 35], bench: [100, 45, 38],
- sofa: [210, 85, 92], armchair: [75, 90, 80],
+ sofa: [210, 85, 92], armchair: [75, 90, 80], wallshelf: [60, 60, 22], wallcab: [60, 60, 35], kitchen: [60, 80, 60], trolley: [50, 80, 40],
+ bar: [120, 105, 60], console: [100, 79, 35], kidstable: [77, 48, 55], kidschair: [34, 60, 34],
};
diff --git a/src/lib/types.ts b/src/lib/types.ts
index 41c4b2c..db8aa21 100644
--- a/src/lib/types.ts
+++ b/src/lib/types.ts
@@ -12,6 +12,7 @@ export interface ShelfParams {
plinth: boolean;
outer: number; // mm panel thickness of frame
inner: number; // mm thickness of inner shelves/dividers
+ wall?: boolean; // hangs on the wall instead of standing on the floor
}
export interface DrawersParams {
@@ -28,6 +29,7 @@ export interface TableParams {
legSize: number;
shelf: boolean;
attach: "screw" | "plate" | "apron";
+ round?: boolean; // round top, size.w is the diameter
}
export interface BedParams {
@@ -48,6 +50,7 @@ export interface CabinetParams {
plinth: boolean;
handles: "knob" | "bar" | "none";
thickness: number;
+ wall?: boolean; // hangs on the wall instead of standing on the floor
}
export interface SeatParams {