docs: 重做位置俯视模板和素材选择
continuous-integration/drone/push Build is passing
Details
|
|
@ -33,10 +33,13 @@
|
||||||
<button type="button" class="layout-link layout-rotate">旋转</button>
|
<button type="button" class="layout-link layout-rotate">旋转</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="layout-template-row">
|
<div class="layout-template-row">
|
||||||
<label>模板 <select class="layout-template" aria-label="位置模板"></select></label>
|
<button type="button" class="layout-link layout-add" aria-expanded="false" aria-controls="jianwu-layout-catalog">+ 添加模板</button>
|
||||||
<button type="button" class="layout-link layout-add">添加</button>
|
|
||||||
<button type="button" class="layout-link layout-cancel">取消</button>
|
<button type="button" class="layout-link layout-cancel">取消</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="layout-catalog" id="jianwu-layout-catalog" hidden>
|
||||||
|
<div class="layout-categories" role="group" aria-label="模板分类"></div>
|
||||||
|
<div class="layout-tiles"></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section class="layout-list" aria-label="平铺位置" hidden>
|
<section class="layout-list" aria-label="平铺位置" hidden>
|
||||||
|
|
@ -69,11 +72,15 @@
|
||||||
--jw-blue-fill: light-dark(#304fc7,#a4b6ff);
|
--jw-blue-fill: light-dark(#304fc7,#a4b6ff);
|
||||||
--jw-on-blue: light-dark(#fff,#17264f);
|
--jw-on-blue: light-dark(#fff,#17264f);
|
||||||
--jw-rule: light-dark(#d6dfed,#41516c);
|
--jw-rule: light-dark(#d6dfed,#41516c);
|
||||||
--jw-grid: light-dark(#dbe5f4,#344462);
|
--jw-grid: light-dark(#ded8cd,#444c54);
|
||||||
--jw-room: light-dark(#e9efff,#263657);
|
--jw-plan: light-dark(#efebe4,#22272e);
|
||||||
--jw-zone: light-dark(#eff2f7,#282f40);
|
--jw-wall: light-dark(#57564f,#a6a8a0);
|
||||||
--jw-furniture: light-dark(#cce1dc,#28483f);
|
--jw-oak: light-dark(#eee1ca,#454235);
|
||||||
--jw-furniture-line: light-dark(#51756e,#97c9bb);
|
--jw-oak-grain: light-dark(#e1d1b7,#514d40);
|
||||||
|
--jw-tile: light-dark(#eeefea,#3c4544);
|
||||||
|
--jw-tile-joint: light-dark(#d8ded8,#52605e);
|
||||||
|
--jw-soft-floor: light-dark(#e5e0d7,#494745);
|
||||||
|
--jw-label: light-dark(#fffcf5f2,#252a30f5);
|
||||||
--jw-draft: light-dark(#fff0d6,#47371d);
|
--jw-draft: light-dark(#fff0d6,#47371d);
|
||||||
--jw-draft-line: light-dark(#8a5a11,#ebba74);
|
--jw-draft-line: light-dark(#8a5a11,#ebba74);
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
|
|
@ -111,37 +118,54 @@
|
||||||
#jianwu-layout-study .layout-plan-head { min-height: 25px; margin-bottom: 8px; }
|
#jianwu-layout-study .layout-plan-head { min-height: 25px; margin-bottom: 8px; }
|
||||||
#jianwu-layout-study .layout-note, #jianwu-layout-study .layout-list-note { color: var(--jw-muted); font-size: .83em; }
|
#jianwu-layout-study .layout-note, #jianwu-layout-study .layout-list-note { color: var(--jw-muted); font-size: .83em; }
|
||||||
#jianwu-layout-study .layout-canvas {
|
#jianwu-layout-study .layout-canvas {
|
||||||
aspect-ratio: 4/3; position: relative; overflow: hidden; border: 1px solid var(--jw-rule); border-radius: 14px;
|
aspect-ratio: 4/3; position: relative; overflow: hidden; border: 1px solid var(--jw-rule); border-radius: 9px;
|
||||||
background: linear-gradient(var(--jw-grid) 1px,transparent 1px),linear-gradient(90deg,var(--jw-grid) 1px,transparent 1px),var(--jw-paper);
|
background: var(--jw-plan);
|
||||||
|
}
|
||||||
|
#jianwu-layout-study .layout-canvas.is-editing {
|
||||||
|
background-image: linear-gradient(var(--jw-grid) 1px,transparent 1px),linear-gradient(90deg,var(--jw-grid) 1px,transparent 1px);
|
||||||
background-size: 5% 5%; background-position: center center;
|
background-size: 5% 5%; background-position: center center;
|
||||||
}
|
}
|
||||||
|
#jianwu-layout-study .layout-canvas[data-level="2"] { box-shadow: inset 0 0 0 2px var(--jw-wall); }
|
||||||
|
#jianwu-layout-study .layout-floor[data-floor="oak"] {
|
||||||
|
background: repeating-linear-gradient(0deg,var(--jw-oak) 0 10px,var(--jw-oak-grain) 10px 11px);
|
||||||
|
}
|
||||||
|
#jianwu-layout-study .layout-floor[data-floor="tile"] {
|
||||||
|
background: linear-gradient(var(--jw-tile-joint) 1px,transparent 1px),
|
||||||
|
linear-gradient(90deg,var(--jw-tile-joint) 1px,transparent 1px),var(--jw-tile);
|
||||||
|
background-size: 13px 13px;
|
||||||
|
}
|
||||||
|
#jianwu-layout-study .layout-floor[data-floor="soft"] { background: var(--jw-soft-floor); }
|
||||||
#jianwu-layout-study .layout-model {
|
#jianwu-layout-study .layout-model {
|
||||||
position: absolute; display: grid; place-items: center; border: 1.5px solid var(--jw-rule);
|
position: absolute; display: grid; place-items: center; border: 0;
|
||||||
font-weight: 650; border-radius: 5px; background: var(--jw-room); color: var(--jw-text);
|
font-weight: 650; border-radius: 2px; color: var(--jw-text);
|
||||||
padding: 3px; font-size: clamp(11px, 3vw, 14px); letter-spacing: .015em; overflow: visible;
|
padding: 3px; font-size: clamp(11px, 3vw, 13px); overflow: visible;
|
||||||
}
|
}
|
||||||
#jianwu-layout-study .layout-model > span { position: relative; max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
|
#jianwu-layout-study .layout-name {
|
||||||
#jianwu-layout-study .layout-model[data-kind="room"] { border-color: var(--jw-muted); align-items: start; padding-top: 7px; }
|
position: relative; max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
|
||||||
#jianwu-layout-study .layout-model[data-kind="zone"] { background: var(--jw-zone); border-style: dashed; }
|
pointer-events: none;
|
||||||
#jianwu-layout-study .layout-model[data-kind="furniture"] {
|
|
||||||
background: var(--jw-furniture); border-color: var(--jw-furniture-line);
|
|
||||||
}
|
}
|
||||||
#jianwu-layout-study .layout-model[data-mold="sofa"]::before {
|
#jianwu-layout-study .layout-model[data-kind="room"] {
|
||||||
content: ""; position: absolute; inset: 5% 6%; border: solid var(--jw-furniture-line);
|
border: 2px solid var(--jw-wall); justify-items: start; align-items: start; padding: 6px 7px;
|
||||||
border-width: 4px 3px 0; border-radius: 5px;
|
|
||||||
}
|
}
|
||||||
#jianwu-layout-study .layout-model:is([data-mold="wardrobe"],[data-mold="cabinet"],[data-mold="shelf"])::before {
|
#jianwu-layout-study .layout-model[data-kind="zone"] { border: 1px dashed var(--jw-wall); }
|
||||||
content: ""; position: absolute; inset: 10% 8%; border: 1px solid var(--jw-furniture-line);
|
#jianwu-layout-study .layout-model[data-kind="furniture"] { z-index: 2; }
|
||||||
background: linear-gradient(90deg,transparent 48%,var(--jw-furniture-line) 49% 51%,transparent 52%);
|
#jianwu-layout-study .layout-model[data-kind="furniture"] .layout-name {
|
||||||
opacity: .55;
|
position: absolute; bottom: -8px; left: 50%; transform: translateX(-50%);
|
||||||
|
background: var(--jw-label); border-radius: 4px; padding: 2px 5px;
|
||||||
|
font-size: 11px; font-weight: 600;
|
||||||
}
|
}
|
||||||
#jianwu-layout-study .layout-model[data-mold="bed"]::before {
|
#jianwu-layout-study .layout-drawing { position: absolute; inset: 0; container-type: size; pointer-events: none; }
|
||||||
content: ""; position: absolute; inset: 9% 8%; border: 1px solid var(--jw-furniture-line);
|
#jianwu-layout-study .layout-art {
|
||||||
background: linear-gradient(var(--jw-furniture-line) 22%,transparent 23%);
|
position: absolute; left: 50%; top: 50%; width: 100%; height: 100%; object-fit: fill;
|
||||||
opacity: .55; border-radius: 3px;
|
transform: translate(-50%,-50%) rotate(var(--layout-angle,0deg));
|
||||||
}
|
}
|
||||||
#jianwu-layout-study .layout-model[aria-pressed="true"] { outline: 2px solid var(--jw-blue); outline-offset: 1px; }
|
#jianwu-layout-study .layout-model[data-sideways="true"] .layout-art { width: 100cqh; height: 100cqw; }
|
||||||
|
#jianwu-layout-study .layout-model[aria-pressed="true"] {
|
||||||
|
z-index: 1; outline: 2px solid var(--jw-blue); outline-offset: 1px;
|
||||||
|
}
|
||||||
|
#jianwu-layout-study .layout-model[data-kind="furniture"][aria-pressed="true"] { z-index: 3; }
|
||||||
#jianwu-layout-study .layout-model[data-draft="true"] { background: var(--jw-draft); border: 2px dashed var(--jw-draft-line); }
|
#jianwu-layout-study .layout-model[data-draft="true"] { background: var(--jw-draft); border: 2px dashed var(--jw-draft-line); }
|
||||||
|
#jianwu-layout-study .layout-model[data-draft="true"] .layout-art { opacity: .72; }
|
||||||
#jianwu-layout-study .layout-canvas.is-editing .layout-model { cursor: grab; touch-action: none; }
|
#jianwu-layout-study .layout-canvas.is-editing .layout-model { cursor: grab; touch-action: none; }
|
||||||
#jianwu-layout-study .layout-handle {
|
#jianwu-layout-study .layout-handle {
|
||||||
position: absolute; right: -12px; bottom: -12px; width: 24px; height: 24px; cursor: nwse-resize;
|
position: absolute; right: -12px; bottom: -12px; width: 24px; height: 24px; cursor: nwse-resize;
|
||||||
|
|
@ -158,6 +182,32 @@
|
||||||
display: flex; flex-wrap: wrap; gap: 7px 10px; align-items: center;
|
display: flex; flex-wrap: wrap; gap: 7px 10px; align-items: center;
|
||||||
}
|
}
|
||||||
#jianwu-layout-study .layout-selection { flex-basis: 100%; font-weight: 650; }
|
#jianwu-layout-study .layout-selection { flex-basis: 100%; font-weight: 650; }
|
||||||
|
#jianwu-layout-study .layout-template-row { justify-content: space-between; }
|
||||||
|
#jianwu-layout-study .layout-catalog { display: grid; gap: 6px; border-top: 1px solid var(--jw-rule); padding-top: 8px; }
|
||||||
|
#jianwu-layout-study .layout-categories { display: flex; flex-wrap: wrap; gap: 4px; }
|
||||||
|
#jianwu-layout-study .layout-categories [aria-pressed="true"] { background: var(--jw-bg); }
|
||||||
|
#jianwu-layout-study .layout-tiles { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 6px; }
|
||||||
|
#jianwu-layout-study .layout-tile {
|
||||||
|
display: grid; justify-items: stretch; align-content: start; gap: 5px; padding: 6px 4px;
|
||||||
|
background: var(--jw-bg); text-align: center; font-size: .85em;
|
||||||
|
}
|
||||||
|
#jianwu-layout-study .layout-swatch {
|
||||||
|
display: grid; place-items: center; height: 47px; margin: 0 3px; border-radius: 3px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
#jianwu-layout-study .layout-swatch[data-floor] { border: 1px solid var(--jw-wall); }
|
||||||
|
#jianwu-layout-study .layout-swatch[data-floor] img { max-width: 62%; max-height: 83%; }
|
||||||
|
#jianwu-layout-study .layout-swatch[data-template="kitchen"]::after {
|
||||||
|
content: ""; width: 70%; height: 76%; border-radius: 2px;
|
||||||
|
border-top: 9px solid var(--jw-oak-grain); border-left: 9px solid var(--jw-oak-grain);
|
||||||
|
}
|
||||||
|
#jianwu-layout-study .layout-swatch[data-template="bathroom"]::after {
|
||||||
|
content: ""; width: 54%; height: 61%; border-radius: 7px;
|
||||||
|
background: var(--jw-label); border: 2px solid var(--jw-tile-joint);
|
||||||
|
box-shadow: inset 0 0 0 3px var(--jw-paper);
|
||||||
|
}
|
||||||
|
#jianwu-layout-study .layout-swatch[data-template="hallway"] { height: 24px; align-self: center; }
|
||||||
|
#jianwu-layout-study .layout-swatch img { width: 100%; height: 100%; min-height: 0; object-fit: contain; }
|
||||||
#jianwu-layout-study label { color: var(--jw-muted); }
|
#jianwu-layout-study label { color: var(--jw-muted); }
|
||||||
#jianwu-layout-study input, #jianwu-layout-study select, #jianwu-layout-study textarea {
|
#jianwu-layout-study input, #jianwu-layout-study select, #jianwu-layout-study textarea {
|
||||||
border: 1px solid var(--jw-rule); border-radius: 8px; background: var(--jw-bg); padding: 6px;
|
border: 1px solid var(--jw-rule); border-radius: 8px; background: var(--jw-bg); padding: 6px;
|
||||||
|
|
@ -186,7 +236,6 @@
|
||||||
const root = document.getElementById("jianwu-layout-study");
|
const root = document.getElementById("jianwu-layout-study");
|
||||||
const part = (name) => root.querySelector(".layout-" + name);
|
const part = (name) => root.querySelector(".layout-" + name);
|
||||||
const canvas = part("canvas");
|
const canvas = part("canvas");
|
||||||
const template = part("template");
|
|
||||||
const width = part("width");
|
const width = part("width");
|
||||||
const depth = part("depth");
|
const depth = part("depth");
|
||||||
const description = root.querySelector("textarea");
|
const description = root.querySelector("textarea");
|
||||||
|
|
@ -204,18 +253,31 @@
|
||||||
box: ["收纳箱", "furniture", 16, 20], table: ["边几", "furniture", 18, 19],
|
box: ["收纳箱", "furniture", 16, 20], table: ["边几", "furniture", 18, 19],
|
||||||
generic: ["其他", "zone", 20, 20]
|
generic: ["其他", "zone", 20, 20]
|
||||||
};
|
};
|
||||||
|
const artwork = JSON.parse(root.querySelector(".layout-artwork")?.textContent || "{}");
|
||||||
|
const floorByMold = {
|
||||||
|
livingRoom:"oak", bedroom:"oak", study:"oak", kitchen:"tile", bathroom:"tile", storage:"soft",
|
||||||
|
entry:"tile", dining:"oak", balcony:"tile", hallway:"soft", zone:"soft", generic:"soft"
|
||||||
|
};
|
||||||
|
const exampleByRoom = {livingRoom:"sofa",bedroom:"bed",study:"desk",storage:"rack",dining:"table"};
|
||||||
|
const templateGroups = {
|
||||||
|
1: [["房间",["livingRoom","bedroom","study","kitchen","bathroom","storage"]],
|
||||||
|
["区域",["entry","dining","balcony","hallway","zone"]],
|
||||||
|
["家具",["sofa","bed","desk","cabinet","wardrobe","shelf","rack","table","box"]]],
|
||||||
|
2: [["家具与收纳",["wardrobe","cabinet","shelf","rack","box","table","desk","sofa","bed"]],
|
||||||
|
["其他",["generic"]]]
|
||||||
|
};
|
||||||
const node = (id, label, mold, x, y, w, h) => ({id, label, mold, x, y, w, h});
|
const node = (id, label, mold, x, y, w, h) => ({id, label, mold, x, y, w, h});
|
||||||
let boards = {
|
let boards = {
|
||||||
root: [
|
root: [
|
||||||
node("living","客厅","livingRoom",6,7,53,56), node("study","书房","study",62,7,32,45),
|
node("living","客厅","livingRoom",6,7,53,56), node("study","书房","study",59,7,35,45),
|
||||||
node("hall","玄关","entry",6,66,53,15), node("balcony","阳台","balcony",62,55,32,22),
|
node("hall","玄关","entry",6,63,53,17), node("balcony","阳台","balcony",59,53,35,24),
|
||||||
node("sofa","沙发","sofa",18,34,27,15), node("store","储藏室","storage",null,null,null,null)
|
node("sofa","沙发","sofa",17,29,30,28), node("store","储藏室","storage",null,null,null,null)
|
||||||
],
|
],
|
||||||
living: [
|
living: [
|
||||||
node("tv","电视柜","cabinet",25,10,50,15), node("shelf","书架","shelf",77,28,17,48),
|
node("tv","电视柜","cabinet",25,10,50,24), {...node("shelf","书架","shelf",77,30,16,45),turn:1},
|
||||||
node("table","窗边边几","table",10,51,24,20)
|
node("table","窗边边几","table",10,51,19,25)
|
||||||
],
|
],
|
||||||
study: [node("book","书架","shelf",12,12,22,48),node("desk","书桌","desk",43,12,45,25)],
|
study: [{...node("book","书架","shelf",12,12,16,46),turn:1},node("desk","书桌","desk",43,12,45,28)],
|
||||||
sofa: [node("under","沙发下方","box",25,33,50,34)],
|
sofa: [node("under","沙发下方","box",25,33,50,34)],
|
||||||
tv: [node("drawer","左侧抽屉","box",null,null,null,null),node("rack","右侧开放格","box",null,null,null,null)]
|
tv: [node("drawer","左侧抽屉","box",null,null,null,null),node("rack","右侧开放格","box",null,null,null,null)]
|
||||||
};
|
};
|
||||||
|
|
@ -223,7 +285,7 @@
|
||||||
if (saved?.version === 1) boards = saved.boards;
|
if (saved?.version === 1) boards = saved.boards;
|
||||||
const trail = [];
|
const trail = [];
|
||||||
let mode = "plan", editing = false, sorting = false, selected = null, snapshot = null, suggestion = null;
|
let mode = "plan", editing = false, sorting = false, selected = null, snapshot = null, suggestion = null;
|
||||||
let drag = null, suppressClick = false, nextID = Date.now();
|
let drag = null, suppressClick = false, nextID = Date.now(), catalogOpen = false, category = 0;
|
||||||
const level = () => trail.length + 1;
|
const level = () => trail.length + 1;
|
||||||
const key = () => trail.at(-1)?.id || "root";
|
const key = () => trail.at(-1)?.id || "root";
|
||||||
const items = () => boards[key()] ?? (boards[key()] = []);
|
const items = () => boards[key()] ?? (boards[key()] = []);
|
||||||
|
|
@ -250,8 +312,23 @@
|
||||||
el.addEventListener("click", action);
|
el.addEventListener("click", action);
|
||||||
return el;
|
return el;
|
||||||
};
|
};
|
||||||
|
function furnitureArt(mold) {
|
||||||
|
const image = document.createElement("img");
|
||||||
|
image.src = artwork[mold] || "location-models/" + mold + ".png";
|
||||||
|
image.alt = ""; image.draggable = false;
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
function floor(element, mold) {
|
||||||
|
const material = floorByMold[mold];
|
||||||
|
element.classList.toggle("layout-floor", Boolean(material));
|
||||||
|
if (material) element.dataset.floor = material;
|
||||||
|
else delete element.dataset.floor;
|
||||||
|
}
|
||||||
function position(el, item) {
|
function position(el, item) {
|
||||||
Object.assign(el.style, { left: item.x + "%", top: item.y + "%", width: item.w + "%", height: item.h + "%" });
|
Object.assign(el.style, { left: item.x + "%", top: item.y + "%", width: item.w + "%", height: item.h + "%" });
|
||||||
|
const turn = item.turn ?? 0;
|
||||||
|
el.style.setProperty("--layout-angle", (turn * 90) + "deg");
|
||||||
|
el.dataset.sideways = String(turn % 2 === 1);
|
||||||
}
|
}
|
||||||
function open(item) {
|
function open(item) {
|
||||||
trail.push(item); selected = null; suggestion = null;
|
trail.push(item); selected = null; suggestion = null;
|
||||||
|
|
@ -264,6 +341,35 @@
|
||||||
rows.splice(next, 0, rows.splice(index, 1)[0]); render();
|
rows.splice(next, 0, rows.splice(index, 1)[0]); render();
|
||||||
part("rows").children[next].querySelector("button").focus();
|
part("rows").children[next].querySelector("button").focus();
|
||||||
}
|
}
|
||||||
|
function renderCatalog() {
|
||||||
|
part("catalog").hidden = !catalogOpen;
|
||||||
|
part("add").setAttribute("aria-expanded", String(catalogOpen));
|
||||||
|
if (!catalogOpen) return;
|
||||||
|
const groups = templateGroups[level()];
|
||||||
|
part("categories").replaceChildren(...groups.map(([name],index) => {
|
||||||
|
const control = button(name, () => {
|
||||||
|
category = index; renderCatalog();
|
||||||
|
part("categories").children[index].focus();
|
||||||
|
}, "layout-link");
|
||||||
|
control.setAttribute("aria-pressed", String(index === category));
|
||||||
|
return control;
|
||||||
|
}));
|
||||||
|
part("tiles").replaceChildren(...groups[category][1].map((mold) => {
|
||||||
|
const name = molds[mold][0];
|
||||||
|
const tile = button("", () => addModel(mold), "layout-tile");
|
||||||
|
const swatch = document.createElement("span");
|
||||||
|
swatch.className = "layout-swatch";
|
||||||
|
swatch.dataset.template = mold;
|
||||||
|
swatch.setAttribute("aria-hidden","true");
|
||||||
|
if (molds[mold][1] === "furniture") swatch.append(furnitureArt(mold));
|
||||||
|
else {
|
||||||
|
floor(swatch,mold);
|
||||||
|
if (exampleByRoom[mold]) swatch.append(furnitureArt(exampleByRoom[mold]));
|
||||||
|
}
|
||||||
|
tile.append(swatch,name);
|
||||||
|
return tile;
|
||||||
|
}));
|
||||||
|
}
|
||||||
function render() {
|
function render() {
|
||||||
const rows = items();
|
const rows = items();
|
||||||
const place = current();
|
const place = current();
|
||||||
|
|
@ -289,20 +395,9 @@
|
||||||
part("selection").textContent = place?.label || "选择位置以调整";
|
part("selection").textContent = place?.label || "选择位置以调整";
|
||||||
part("rotate").disabled = !place || !located(place);
|
part("rotate").disabled = !place || !located(place);
|
||||||
width.disabled = depth.disabled = !place || !located(place);
|
width.disabled = depth.disabled = !place || !located(place);
|
||||||
width.value = place?.w ?? ""; depth.value = place?.h ?? "";
|
width.value = place?.w == null ? "" : Math.round(place.w);
|
||||||
if (template.dataset.level !== String(level())) {
|
depth.value = place?.h == null ? "" : Math.round(place.h);
|
||||||
const groups = level() === 1
|
renderCatalog();
|
||||||
? [["房间",["livingRoom","bedroom","study","kitchen","bathroom","storage"]],
|
|
||||||
["区域",["entry","dining","balcony","hallway","zone"]],
|
|
||||||
["独立家具",["sofa","bed","desk","cabinet","wardrobe","shelf"]]]
|
|
||||||
: [["家具与收纳",["wardrobe","cabinet","shelf","rack","box","table","desk","sofa","bed"]],["其他",["generic"]]];
|
|
||||||
template.replaceChildren(...groups.map(([group,keys]) => {
|
|
||||||
const options = document.createElement("optgroup");
|
|
||||||
options.label = group; options.append(...keys.map((mold) => new Option(molds[mold][0], mold)));
|
|
||||||
return options;
|
|
||||||
}));
|
|
||||||
template.dataset.level = String(level());
|
|
||||||
}
|
|
||||||
const unplaced = rows.filter((item) => !located(item));
|
const unplaced = rows.filter((item) => !located(item));
|
||||||
const unplacedButton = part("unplaced");
|
const unplacedButton = part("unplaced");
|
||||||
unplacedButton.textContent = "未摆放 " + unplaced.length + " 处";
|
unplacedButton.textContent = "未摆放 " + unplaced.length + " 处";
|
||||||
|
|
@ -311,6 +406,8 @@
|
||||||
part("generate").hidden = Boolean(suggestion);
|
part("generate").hidden = Boolean(suggestion);
|
||||||
part("draft-note").hidden = !suggestion;
|
part("draft-note").hidden = !suggestion;
|
||||||
canvas.classList.toggle("is-editing", editing);
|
canvas.classList.toggle("is-editing", editing);
|
||||||
|
canvas.dataset.level = String(level());
|
||||||
|
floor(canvas, editing ? null : trail.at(-1)?.mold);
|
||||||
canvas.replaceChildren();
|
canvas.replaceChildren();
|
||||||
[...rows, ...(suggestion ? [suggestion] : [])].filter(located)
|
[...rows, ...(suggestion ? [suggestion] : [])].filter(located)
|
||||||
.sort((a,b) => Number(molds[a.mold][1] === "furniture") - Number(molds[b.mold][1] === "furniture"))
|
.sort((a,b) => Number(molds[a.mold][1] === "furniture") - Number(molds[b.mold][1] === "furniture"))
|
||||||
|
|
@ -320,10 +417,18 @@
|
||||||
if (editing) { selected = item.id; render(); }
|
if (editing) { selected = item.id; render(); }
|
||||||
else open(item);
|
else open(item);
|
||||||
}, "layout-model");
|
}, "layout-model");
|
||||||
|
const kind = molds[item.mold][1];
|
||||||
|
if (kind === "furniture") {
|
||||||
|
const drawing = document.createElement("span");
|
||||||
|
drawing.className = "layout-drawing";
|
||||||
|
const image = furnitureArt(item.mold);
|
||||||
|
image.className = "layout-art";
|
||||||
|
drawing.append(image); el.append(drawing);
|
||||||
|
} else { floor(el,item.mold); }
|
||||||
const label = document.createElement("span");
|
const label = document.createElement("span");
|
||||||
label.textContent = item.label;
|
label.className = "layout-name"; label.textContent = item.label;
|
||||||
el.append(label);
|
el.append(label);
|
||||||
el.dataset.id = item.id; el.dataset.mold = item.mold; el.dataset.kind = molds[item.mold][1];
|
el.dataset.id = item.id; el.dataset.mold = item.mold; el.dataset.kind = kind;
|
||||||
if (item === suggestion) { el.dataset.draft = "true"; el.disabled = true; }
|
if (item === suggestion) { el.dataset.draft = "true"; el.disabled = true; }
|
||||||
if (editing) el.setAttribute("aria-pressed", String(item.id === selected));
|
if (editing) el.setAttribute("aria-pressed", String(item.id === selected));
|
||||||
if (editing && item.id === selected) {
|
if (editing && item.id === selected) {
|
||||||
|
|
@ -356,7 +461,8 @@
|
||||||
} else if (canPlan && !located(item)) {
|
} else if (canPlan && !located(item)) {
|
||||||
const placeIt = button("摆放", () => {
|
const placeIt = button("摆放", () => {
|
||||||
startEdit(); mode = "plan"; selected = item.id;
|
startEdit(); mode = "plan"; selected = item.id;
|
||||||
placeInCanvas(item); render();
|
if (!placeInCanvas(item)) tell("画布空位不足,请先调整已有位置。");
|
||||||
|
render();
|
||||||
}, "layout-link");
|
}, "layout-link");
|
||||||
row.append(placeIt);
|
row.append(placeIt);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -370,26 +476,33 @@
|
||||||
empty.textContent = "暂无下级位置"; list.append(empty);
|
empty.textContent = "暂无下级位置"; list.append(empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function startEdit() { snapshot = structuredClone(boards); editing = true; }
|
function startEdit() { snapshot = structuredClone(boards); editing = true; category = 0; }
|
||||||
function cancel() {
|
function cancel() {
|
||||||
if (snapshot) boards = snapshot;
|
if (snapshot) boards = snapshot;
|
||||||
editing = sorting = false; selected = null; snapshot = null; suggestion = null;
|
editing = sorting = catalogOpen = false; selected = null; snapshot = null; suggestion = null;
|
||||||
part("assistant").hidden = true; tell(""); render();
|
part("assistant").hidden = true; tell(""); render();
|
||||||
}
|
}
|
||||||
function placeInCanvas(item) {
|
function clearPlacement(item, w, h, preferred) {
|
||||||
const mold = molds[item.mold];
|
|
||||||
const visible = items().filter((other) => located(other) && other.id !== item.id);
|
const visible = items().filter((other) => located(other) && other.id !== item.id);
|
||||||
function findSpace(w,h) {
|
const fits = (x,y) => x >= 4 && y >= 4 && x + w <= 97 && y + h <= 97 &&
|
||||||
for (let y = 4; y + h <= 97; y += 3) {
|
visible.every((other) => x + w <= other.x || x >= other.x + other.w ||
|
||||||
for (let x = 4; x + w <= 97; x += 3) {
|
y + h <= other.y || y >= other.y + other.h);
|
||||||
if (visible.every((other) => x + w <= other.x || x >= other.x + other.w ||
|
if (preferred && fits(preferred.x,preferred.y)) return {x:preferred.x,y:preferred.y,w,h};
|
||||||
y + h <= other.y || y >= other.y + other.h)) return {x,y,w,h};
|
for (let y = 4; y + h <= 97; y += 2) {
|
||||||
}
|
for (let x = 4; x + w <= 97; x += 2) {
|
||||||
|
if (fits(x,y)) return {x,y,w,h};
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
const position = findSpace(mold[2],mold[3]) || findSpace(Math.max(10,Math.round(mold[2] / 2)),Math.max(10,Math.round(mold[3] / 2)));
|
return null;
|
||||||
Object.assign(item,position || {x:8,y:8,w:mold[2],h:mold[3]});
|
}
|
||||||
|
function placeInCanvas(item, preferred) {
|
||||||
|
const mold = molds[item.mold];
|
||||||
|
const w = item.w ?? mold[2], h = item.h ?? mold[3];
|
||||||
|
const placement = clearPlacement(item,w,h,preferred) ||
|
||||||
|
clearPlacement(item,Math.max(10,Math.round(w / 2)),Math.max(10,Math.round(h / 2)),preferred);
|
||||||
|
if (!placement) return false;
|
||||||
|
Object.assign(item,placement);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
part("back").addEventListener("click", () => {
|
part("back").addEventListener("click", () => {
|
||||||
trail.pop(); selected = null; suggestion = null; mode = level() <= 2 ? "plan" : "list";
|
trail.pop(); selected = null; suggestion = null; mode = level() <= 2 ? "plan" : "list";
|
||||||
|
|
@ -401,7 +514,7 @@
|
||||||
part("action").addEventListener("click", () => {
|
part("action").addEventListener("click", () => {
|
||||||
if (editing || sorting) {
|
if (editing || sorting) {
|
||||||
tell(editing ? "布局已保存" : "同级位置顺序已保存");
|
tell(editing ? "布局已保存" : "同级位置顺序已保存");
|
||||||
editing = sorting = false; selected = null; snapshot = null; remember();
|
editing = sorting = catalogOpen = false; selected = null; snapshot = null; remember();
|
||||||
} else if (mode === "plan") { startEdit(); tell(""); }
|
} else if (mode === "plan") { startEdit(); tell(""); }
|
||||||
else { snapshot = structuredClone(boards); sorting = true; tell(""); }
|
else { snapshot = structuredClone(boards); sorting = true; tell(""); }
|
||||||
render();
|
render();
|
||||||
|
|
@ -410,13 +523,18 @@
|
||||||
part("cancel-order").addEventListener("click",cancel);
|
part("cancel-order").addEventListener("click",cancel);
|
||||||
part("unplaced").addEventListener("click", () => { mode = "list"; render(); });
|
part("unplaced").addEventListener("click", () => { mode = "list"; render(); });
|
||||||
part("add").addEventListener("click", () => {
|
part("add").addEventListener("click", () => {
|
||||||
const mold = template.value;
|
catalogOpen = !catalogOpen; renderCatalog();
|
||||||
|
if (catalogOpen) part("categories").children[category].focus();
|
||||||
|
});
|
||||||
|
function addModel(mold) {
|
||||||
const name = molds[mold][0];
|
const name = molds[mold][0];
|
||||||
let suffix = 1, label = name;
|
let suffix = 1, label = name;
|
||||||
while (items().some((item) => item.label === label)) label = name + " " + (++suffix);
|
while (items().some((item) => item.label === label)) label = name + " " + (++suffix);
|
||||||
const item = node("node-" + (++nextID),label,mold,null,null,null,null);
|
const item = node("node-" + (++nextID),label,mold,null,null,null,null);
|
||||||
placeInCanvas(item); items().push(item); selected = item.id; render();
|
if (!placeInCanvas(item)) tell("画布空位不足,已添加到未摆放。");
|
||||||
});
|
items().push(item); selected = item.id; catalogOpen = false; render();
|
||||||
|
part("add").focus();
|
||||||
|
}
|
||||||
function setSize() {
|
function setSize() {
|
||||||
const place = current();
|
const place = current();
|
||||||
if (!place) return;
|
if (!place) return;
|
||||||
|
|
@ -430,7 +548,11 @@
|
||||||
part("rotate").addEventListener("click", () => {
|
part("rotate").addEventListener("click", () => {
|
||||||
const place = current();
|
const place = current();
|
||||||
if (!place) return;
|
if (!place) return;
|
||||||
[place.w,place.h] = [place.h,place.w];
|
const aspect = canvas.clientWidth / canvas.clientHeight;
|
||||||
|
const w = place.h / aspect, h = place.w * aspect;
|
||||||
|
const scale = Math.min(1,100 / w,100 / h);
|
||||||
|
[place.w,place.h] = [w * scale,h * scale];
|
||||||
|
place.turn = ((place.turn ?? 0) + 1) % 4;
|
||||||
place.x = Math.min(place.x,100 - place.w); place.y = Math.min(place.y,100 - place.h); render();
|
place.x = Math.min(place.x,100 - place.w); place.y = Math.min(place.y,100 - place.h); render();
|
||||||
});
|
});
|
||||||
canvas.addEventListener("pointerdown", (event) => {
|
canvas.addEventListener("pointerdown", (event) => {
|
||||||
|
|
@ -459,7 +581,7 @@
|
||||||
place.y = clamp(Math.round(first.y + dy),0,100 - place.h);
|
place.y = clamp(Math.round(first.y + dy),0,100 - place.h);
|
||||||
}
|
}
|
||||||
position(canvas.querySelector('[aria-pressed="true"]'),place);
|
position(canvas.querySelector('[aria-pressed="true"]'),place);
|
||||||
width.value = place.w; depth.value = place.h;
|
width.value = Math.round(place.w); depth.value = Math.round(place.h);
|
||||||
});
|
});
|
||||||
for (const eventType of ["pointerup","pointercancel","lostpointercapture"]) {
|
for (const eventType of ["pointerup","pointercancel","lostpointercapture"]) {
|
||||||
canvas.addEventListener(eventType, (event) => {
|
canvas.addEventListener(eventType, (event) => {
|
||||||
|
|
@ -477,9 +599,11 @@
|
||||||
if (!description.value.includes(level() === 1 ? "阅读区" : "收纳箱")) {
|
if (!description.value.includes(level() === 1 ? "阅读区" : "收纳箱")) {
|
||||||
tell("此原型用阅读区或收纳箱的示例展示草稿。"); return;
|
tell("此原型用阅读区或收纳箱的示例展示草稿。"); return;
|
||||||
}
|
}
|
||||||
suggestion = level() === 1
|
const proposal = level() === 1
|
||||||
? node("node-" + (++nextID),suggestionLabel(),"zone",65,80,25,17)
|
? node("node-" + (++nextID),suggestionLabel(),"zone",65,80,25,17)
|
||||||
: node("node-" + (++nextID),suggestionLabel(),"box",12,76,23,17);
|
: node("node-" + (++nextID),suggestionLabel(),"box",12,76,23,17);
|
||||||
|
if (!placeInCanvas(proposal,proposal)) { tell("画布空位不足,请先调整已有位置。"); return; }
|
||||||
|
suggestion = proposal;
|
||||||
tell("示例草稿已在图中标出"); render();
|
tell("示例草稿已在图中标出"); render();
|
||||||
});
|
});
|
||||||
part("apply").addEventListener("click", () => {
|
part("apply").addEventListener("click", () => {
|
||||||
|
|
|
||||||
|
|
@ -26,11 +26,11 @@
|
||||||
|
|
||||||
| 种类 | 首版模板 | 画法 |
|
| 种类 | 首版模板 | 画法 |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| 房间 | 客厅、卧室、书房、厨房、卫生间、储藏室 | 矩形轮廓和低对比度填色。名称靠上,适合看布局全貌。 |
|
| 房间 | 客厅、卧室、书房、厨房、卫生间、储藏室 | 用墙线圈定闭合边界。木地板、方砖和素面材质区分用途,名称放在左上。 |
|
||||||
| 开放区域 | 玄关、餐区、阳台、走廊、其他区域 | 虚线边界。可叠在开放式房间的轮廓内。 |
|
| 开放区域 | 玄关、餐区、阳台、走廊、其他区域 | 虚线边界,材质弱于房间。可叠在开放式房间的轮廓内。 |
|
||||||
| 家具与收纳 | 沙发、床、桌、边几、衣柜、电视柜、书架、层架、收纳箱、其他 | 用扶手、柜门或层板区分俯视轮廓。可更改宽深和朝向。 |
|
| 家具与收纳 | 沙发、床、桌、边几、衣柜、电视柜、书架、层架、收纳箱、其他 | 使用透明底俯视素材,保留转角、枕头、柜门和层板等辨认特征。可更改宽深和朝向。 |
|
||||||
|
|
||||||
画布用淡网格衬出位置,层级靠标题和路径表达。路径、标记、手柄和文字适配深色模式及大字号。家具标签空间不足时保留可访问名称,点选后在面板完整显示。
|
查看时突出房间边界和家具形状。进入编辑才显示网格、选中轮廓和手柄。「添加模板」用图片预览,可按房间、区域和家具选择。名称和选中状态独立渲染,家具转动时标签继续正向可读。透明底素材可叠在浅色或深色画布上。 [家具素材与来源](location-models/README.md)
|
||||||
|
|
||||||
## 用描述生成草稿
|
## 用描述生成草稿
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
# 位置俯视素材
|
||||||
|
|
||||||
|
这组透明 PNG 用于位置画布和模板选择。九件家具来自一次内置 ImageGen 生成的透明底图,按对象拆分并缩放。房间边界、铺地材质、名称和选中轮廓由画布绘制,家具图上的朝向随位置几何参数更新。
|
||||||
|
|
||||||
|
| 模板 | 文件 |
|
||||||
|
| --- | --- |
|
||||||
|
| 转角沙发 | [sofa.png](sofa.png) |
|
||||||
|
| 电视柜 | [cabinet.png](cabinet.png) |
|
||||||
|
| 书架 | [shelf.png](shelf.png) |
|
||||||
|
| 双人床 | [bed.png](bed.png) |
|
||||||
|
| 衣柜 | [wardrobe.png](wardrobe.png) |
|
||||||
|
| 书桌 | [desk.png](desk.png) |
|
||||||
|
| 圆边几 | [table.png](table.png) |
|
||||||
|
| 收纳箱 | [box.png](box.png) |
|
||||||
|
| 层架 | [rack.png](rack.png) |
|
||||||
|
|
||||||
|
## 素材生成提示词
|
||||||
|
|
||||||
|
> Use case: product-mockup. Generate one production furniture sprite atlas for an iOS home floor-plan editor. EXACTLY nine isolated furniture top-view cutouts in a very regular 3×3, 9 equal square cells, centered in each cell with 12% air all around, no bleed between cells. Row 1 left to right: contemporary low L-shaped olive-sage fabric sofa with a chaise extending toward the bottom on its right and clearly visible back and 3 cushions; natural white oak low TV media console with long black slim television centred along its back, three separated cabinet doors and no decor; tall rectangular walnut open bookshelf, viewed from dead above as a cabinet with 3 bays and tiny books. Row 2 left to right: contemporary double bed with two ivory pillows at top and a light cream duvet with sage throw at foot; four-door natural white oak wardrobe with subtle door seam division and dark slim handles along its front, wide and not deep; warm walnut writing desk with clean surface, closed notebook and no chair. Row 3 left to right: ONE small round ash-wood side table; ONE closed canvas-covered sand-colored storage bin with visible small inset handle; ONE long narrow open four-bay muted olive metal storage shelf, rims and dividers visible, no loose items. Uniform strict 90-degree orthographic bird's-eye plan view with no horizon or oblique perspective, true geometric footprint suitable for resizable spatial models. Refined Japanese-modern interior catalog and high-end architectural render, realistic subtle wood grain and woven texture. Soft restrained ambient occlusion directly under each item, clean edges, natural olive, pale oak, oatmeal and walnut palette, strongest shape features readable at 40px. Square canvas 3 x 3 mathematically spaced cells with NO visible grid or frames, no labels, numbers, text, logos, rooms, carpets or props, no white background, genuine clean alpha transparency. The nine objects must be distinctly separate.
|
||||||
|
After Width: | Height: | Size: 100 KiB |
|
After Width: | Height: | Size: 128 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 48 KiB |
|
After Width: | Height: | Size: 90 KiB |
|
After Width: | Height: | Size: 118 KiB |
|
After Width: | Height: | Size: 51 KiB |