Skip to content

Single place to convert your 2D floor plans to 3d model (no LLM)

Python
10.3 KB
Raw Blame
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Interior themes</title>
<link rel="stylesheet" href="/web/style.css?v=2">
<style>
  .theme { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-top: 18px; }
  .theme h2 { margin: 0; font-size: 19px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
  .theme > p { margin: 4px 0 10px; }
  .pics { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .pics figure { margin: 0; }
  .pics img, .pics .wait { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; background: var(--bg); }
  .pics .wait { display: grid; place-items: center; color: var(--muted); font-size: 12px; }
  .pics figcaption { font-size: 12px; margin-top: 4px; line-height: 1.3; }
  .pics figcaption b { display: block; font-size: 13px; }
  .dots { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); margin: 10px 0 0; flex-wrap: wrap; }
  .dots i { width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--line); display: inline-block; }
  .acts { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
  #ed { width: min(760px, 94vw); max-height: 90vh; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); padding: 18px 20px; }
  #ed h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 6px; }
  .grid { display: grid; grid-template-columns: 150px 1fr auto; gap: 6px 10px; align-items: center; font-size: 14px; }
  .grid select { width: 100%; }
  .grid .more { margin: 0; font-size: 13px; }
  input[type=color] { width: 40px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }
</style>
</head>
<body class="home">
<main class="wrap" style="max-width:1040px">
  <p class="brand" id="brand"><a href="/" style="color:inherit;text-decoration:none">PlanTo3D</a> · <a href="/">Home</a></p>
  <h1>Interior themes</h1>
  <p class="muted">A theme decides the furniture, decor, colours and floors a house is built with. Pick one for a plan on its
    review page. Make your own from any theme: choose each piece from the library or use your own <code>.glb</code> model
    (modelled with +Y up and its front facing +Z; it is scaled to the piece's place and stood on the floor).</p>
  <p id="state" class="muted" role="status"></p>
  <div id="list"></div>
</main>
<dialog id="ed">
  <form id="edf" method="dialog">
    <h2 id="edh" style="margin:0 0 4px">New theme</h2>
    <div class="grid" style="margin-top:12px"><span>Name</span><input type="text" id="edname" maxlength="40" required><span></span></div>
    <h3>Furniture and decor</h3>
    <div class="grid" id="edslots"></div>
    <label style="display:block;margin-top:8px;font-size:14px"><input type="checkbox" id="edtv"> A TV on the TV unit (off: a mirror above it)</label>
    <h3>Colours</h3>
    <div class="grid" id="edcolours"></div>
    <h3>Floors</h3>
    <div class="grid" id="edfloors"></div>
    <p id="edmsg" class="muted" style="font-size:13px"></p>
    <div class="acts"><button class="btn" id="edsave" value="save">Save theme</button><button class="btn ghost" value="cancel" formnovalidate>Close</button></div>
  </form>
</dialog>
<input type="file" id="file" accept=".glb,model/gltf-binary" hidden>
<script>
const $ = (id) => document.getElementById(id);
if (new URLSearchParams(location.search).has('embed')) $('brand').remove();      // shown inside the review page
const el = (tag, cls, text) => { const e = document.createElement(tag); if (cls) e.className = cls; if (text != null) e.textContent = text; return e; };
const NAMES = { wood: 'Wood', cabinet: 'Kitchen and cabinets', fabric: 'Sofa and upholstery', curtain: 'Curtains', rug: 'Rugs', accent: 'Cushions and throws' };
const ROOMS = ['living', 'dining', 'bedroom', 'kitchen', 'study', 'passage'];
const FIN = { marble: 'Marble', wood: 'Wood', parquet: 'Parquet', tile: 'Tiles', bathtile: 'Bathroom tiles', terracotta: 'Terracotta', concrete: 'Concrete' };
let data, editing = null, uploadSlot = null, tex = {};

async function load() {
  data = await fetch('/api/themes').then((r) => r.json());
  $('state').textContent = data.rendering ? 'Drawing the pictures… (about a minute per theme)' : '';
  $('list').replaceChildren(...data.themes.map(card));
  if (data.rendering) setTimeout(load, 4000);
}
function card(t) {
  const c = el('section', 'theme');
  const h = el('h2', '', t.label);
  h.append(el('span', 'chip' + (t.builtin ? '' : ' ok'), t.builtin ? 'Built-in' : 'Yours'));
  c.append(h, el('p', 'muted', t.about || ''));
  const pics = el('div', 'pics');
  for (const [s, v] of Object.entries(t.slots)) {
    if (!(s in t.pictures) && !data.rendering) continue;
    const f = el('figure');
    if (s in t.pictures) { const im = new Image(); im.src = `/thumbs/${t.id}/${s}.png?v=${t.pictures[s]}`; im.alt = v.label; im.loading = 'lazy'; f.append(im); }
    else f.append(el('div', 'wait', 'Drawing…'));
    const cap = el('figcaption', '', v.label);
    cap.prepend(el('b', '', data.slots[s]));
    f.append(cap);
    pics.append(f);
  }
  c.append(pics);
  const dots = el('p', 'dots');
  for (const [k, hex] of [['Walls', t.wall], ...Object.entries(t.colours).map(([k, v]) => [NAMES[k], v])]) {
    if (!hex) continue;
    const i = el('i'); i.style.background = hex; i.title = k;
    dots.append(i);
  }
  if (dots.children.length) { dots.prepend(el('span', '', 'Colours')); c.append(dots); }
  const acts = el('div', 'acts');
  const copy = el('button', 'btn ghost', t.builtin ? 'Make my own from this' : 'Copy');
  copy.onclick = () => edit(t, true);
  acts.append(copy);
  if (!t.builtin) {
    const e = el('button', 'btn ghost', 'Edit'); e.onclick = () => edit(t, false);
    const d = el('button', 'btn ghost', 'Delete'); d.style.color = 'var(--bad)';
    d.onclick = async () => { if (confirm(`Delete the theme "${t.label}"? Plans that use it are built in Contemporary.`)) { await fetch(`/api/themes/${t.id}`, { method: 'DELETE' }); load(); } };
    acts.append(e, d);
  }
  c.append(acts);
  return c;
}
// the editor: a copy of a theme (new) or one of your own
function edit(t, copy) {
  editing = copy ? null : t.id;
  tex = t.tex || {};                 // the built-in theme's textures stay with its copies
  $('edh').textContent = copy ? `New theme from ${t.label}` : `Edit ${t.label}`;
  $('edname').value = copy ? `My ${t.label.toLowerCase()}` : t.label;
  $('edtv').checked = t.tv;
  $('edmsg').textContent = copy ? 'Save the theme first to use your own models in it.' : '';
  const rows = [];
  for (const [s, label] of Object.entries(data.slots)) {
    const sel = el('select'); sel.dataset.slot = s;
    if (!data.choices[s]['@contemporary']) sel.add(new Option('None', ''));
    for (const [v, l] of Object.entries(data.choices[s])) sel.add(new Option(l, v));
    const cur = t.slots[s]?.value || '';
    if (cur === 'upload') sel.add(new Option('Your own model', 'upload'));
    sel.value = cur;
    const side = el('span');
    if (!copy) {
      const up = el('button', 'more', cur === 'upload' ? 'Replace your model' : 'Use my model');
      up.type = 'button';
      up.onclick = () => { uploadSlot = s; $('file').click(); };
      side.append(up);
      if (cur === 'upload') {
        const back = el('button', 'more', 'Remove'); back.type = 'button';
        back.onclick = async () => { await fetch(`/api/themes/${editing}/model/${s}`, { method: 'DELETE' }); await reopen(); };
        side.append(' · ', back);
      }
    }
    rows.push(el('span', '', label), sel, side);
  }
  $('edslots').replaceChildren(...rows);
  const crow = [];
  for (const [k, l] of [['wall', 'Walls'], ...data.colours.map((k) => [k, NAMES[k]])]) {
    const v = k === 'wall' ? t.wall : t.colours[k];
    const on = el('input'); on.type = 'checkbox'; on.checked = !!v; on.title = 'Use this colour (off: as Contemporary)';
    const c = el('input'); c.type = 'color'; c.value = v || '#d8d0c4'; c.dataset.key = k;
    c.oninput = () => { on.checked = true; };
    on.dataset.key = k;
    crow.push(el('span', '', l), c, on);
  }
  $('edcolours').replaceChildren(...crow);
  const frow = [];
  for (const r of ROOMS) {
    const sel = el('select'); sel.dataset.room = r;
    sel.add(new Option('Auto (by room type)', ''));
    for (const f of data.finishes) sel.add(new Option(FIN[f] || f, f));
    sel.value = t.floors[r] || '';
    frow.push(el('span', '', r[0].toUpperCase() + r.slice(1)), sel, el('span'));
  }
  $('edfloors').replaceChildren(...frow);
  if (!$('ed').open) $('ed').showModal();
}
async function reopen() { await load(); const t = data.themes.find((q) => q.id === editing); if (t) edit(t, false); }
function collect() {
  const slots = {}, colours = {}, floors = {};
  let wall = null;
  for (const s of $('edslots').querySelectorAll('select')) if (s.value) slots[s.dataset.slot] = s.value;
  for (const c of $('edcolours').querySelectorAll('input[type=color]')) {
    if (!$('edcolours').querySelector(`input[type=checkbox][data-key="${c.dataset.key}"]`).checked) continue;
    if (c.dataset.key === 'wall') wall = c.value; else colours[c.dataset.key] = c.value;
  }
  for (const s of $('edfloors').querySelectorAll('select')) if (s.value) floors[s.dataset.room] = s.value;
  return { label: $('edname').value, slots, colours, floors, wall, tv: $('edtv').checked, tex };
}
$('edf').onsubmit = async (e) => {
  if (e.submitter?.value !== 'save') return;
  e.preventDefault();
  const r = await fetch(editing ? `/api/themes/${editing}` : '/api/themes', { method: 'POST', body: JSON.stringify(collect()) });
  const j = await r.json();
  if (!r.ok) { $('edmsg').textContent = j.error; return; }
  editing = j.id;
  await reopen();
  $('edmsg').textContent = 'Saved. Its pictures are drawn again in a minute.';
};
$('file').onchange = async (e) => {
  const file = e.target.files[0];
  e.target.value = '';
  if (!file || !editing) return;
  $('edmsg').textContent = 'Uploading…';
  const r = await fetch(`/api/themes/${editing}/model/${uploadSlot}`, { method: 'POST', body: file });
  if (!r.ok) { $('edmsg').textContent = (await r.json()).error; return; }
  await reopen();
  $('edmsg').textContent = 'Your model is in the theme. Its picture is drawn in a minute.';
};
load();
</script>
</body>
</html>