Ai agent 室内设计schema设计

36 阅读7分钟

格式化内容主要包括3部分内容:二维场景输入json schema,家具信息输入json shema,3d场景输出json schema

第一部分:场景输入(2D 平面输入 Schema)

这是输入给模型的“房间结构”数据,用来让模型知道空间边界、门窗点位。


二维 Scene Input Schema(2D输入)

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://example.com/schemas/scene-2d-input.schema.json",
  "title": "二维室内布局输入",
  "description": "定义房间结构与墙体层级关系,用于AI布局推理",
  "type": "object",
  "properties": {
    "name": { "type": "string", "const": "scene" },
    "type": { "type": "string", "const": "scene" },
    "children": {
      "type": "array",
      "items": { "$ref": "#/$defs/wall" }
    }
  },
  "required": ["name", "type", "children"],

  "$defs": {
    "wall": {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "type": { "type": "string", "const": "wall" },
        "startPoint": { "$ref": "#/$defs/vector2" },
        "endPoint": { "$ref": "#/$defs/vector2" },
        "children": {
          "type": "array",
          "items": { "$ref": "#/$defs/opening" }
        }
      },
      "required": ["name", "type", "startPoint", "endPoint"]
    },
    "opening": {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "type": { "enum": ["door", "window"] },
        "startPoint": { "$ref": "#/$defs/vector2" },
        "endPoint": { "$ref": "#/$defs/vector2" }
      },
      "required": ["name", "type", "startPoint", "endPoint"]
    },
    "vector2": {
      "type": "object",
      "properties": {
        "x": { "type": "number" },
        "y": { "type": "number" }
      },
      "required": ["x", "y"]
    }
  }
}

第二部分:家具输入 JSON Schema(Furniture Input Schema)

用来告诉大模型有哪些家具、每个家具的尺寸、锚点、模型资源路径、摆放规则。


家具输入 JSON Schema 定义

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://example.com/schemas/furniture-input.schema.json",
  "title": "家具输入定义",
  "description": "描述每个家具模型的基础信息和布局规则,用于AI布局推理",
  "type": "object",
  "properties": {
    "furnitures": {
      "type": "array",
      "description": "场景中包含的家具清单",
      "items": { "$ref": "#/$defs/furniture" }
    }
  },
  "required": ["furnitures"],

  "$defs": {
    "furniture": {
      "type": "object",
      "description": "单个家具对象的描述",
      "properties": {
        "name": { "type": "string", "description": "家具名称,如 bed_01" },
        "type": {
          "type": "string",
          "description": "家具类型,用于识别规则与摆放逻辑,例如 bed, wardrobe, desk"
        },
        "url": {
          "type": "string",
          "description": "3D模型或2D资源路径(可为本地或CDN URL)"
        },
        "dimensions": {
          "type": "object",
          "description": "家具包围盒尺寸,单位毫米",
          "properties": {
            "w": { "type": "number", "description": "宽度 (X轴方向)" },
            "d": { "type": "number", "description": "深度 (Y轴方向)" },
            "h": { "type": "number", "description": "高度 (Z轴方向)" }
          },
          "required": ["w", "d", "h"]
        },
        "anchor": {
          "type": "string",
          "enum": ["back_bottom_center"],
          "description": "模型锚点,默认背后底部中心,对应模型本地坐标 (0, -d/2, -h/2)"
        },
        "rules": {
          "type": "array",
          "description": "布局限制规则数组,描述当前家具(观察者)与目标家具或场景的空间关系",
          "items": { "$ref": "#/$defs/rule" }
        }
      },
      "required": ["name", "type", "dimensions"]
    },
    "rule": {
      "type": "object",
      "description": "定义两个对象之间的布局限制关系",
      "properties": {
        "target": {
          "type": "array",
          "items": { "type": "string" },
          "description": "目标对象类型或具体名称数组,例如 ['bed', 'window']"
        },
        "relation": {
          "type": "string",
          "description": "关系副词,描述观察者与目标者的空间关系,如 'distance', 'left_of', 'right_of', 'above', 'below', 'facing', 'avoid'"
        },
        "value": {
          "type": "number",
          "description": "关系副词的参数值,如最小距离10cm → 100"
        },
        "weight": {
          "type": "number",
          "description": "规则权重,数值越大优先级越高(可选)"
        },
        "comment": {
          "type": "string",
          "description": "自然语言解释,辅助模型理解该规则的设计意图"
        }
      },
      "required": ["target", "relation"]
    }
  }
}

字段解释(让大模型理解含义)

字段含义示例模型提示说明
name家具名称(唯一ID)"bed_01"模型通过该名称识别具体对象
type家具类型"wardrobe"用于规则匹配与语义推理
url模型资源路径"https://cdn/.../bed.glb"可选,用于渲染
dimensions家具包围盒{w:1600,d:2000,h:600}单位mm,模型的实际大小
anchor锚点类型"back_bottom_center"所有模型统一使用,锚点对应模型背后底部中心点 (0,-d/2,-h/2)
rules规则数组[{"target":["window"],"relation":"distance","value":500}]告诉模型“离窗户保持500mm距离”等逻辑约束
rule.target目标类型或对象名["bed", "wardrobe"]目标可以是类型或特定家具名
rule.relation关系描述"left_of", "distance", "avoid"关系副词控制空间语义
rule.value数值参数300代表距离或角度等限制
rule.weight优先级权重0.8高优先级规则优先满足
rule.comment自然语言注释"床头柜应放在床的右边100mm以内"帮助大模型理解空间意图

  • 输入 schema 是一个嵌套式 scene,包含 walls,每个 wall 下可以有 door、window 等子元素。

  • 输出 schema 需要保留这种层级关系(靠墙 → 墙体子节点,不靠墙 → 顶层元素)。

  • 输出还要包含每个模型的三维放置信息:position、rotation。

  • 锚点规则:所有模型锚点都是“背后底部中心点”(本地坐标 (0, -d/2, -h/2))。

第三部分:三维输出 Schema(Output JSON Schema)

室内布局 Output JSON Schema 定义

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://example.com/schemas/scene-output.schema.json",
  "title": "AI 生成的室内布局 Scene 输出",
  "description": "描述室内场景的层级结构、家具摆放与位置旋转数据",
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "description": "场景名称,例如 scene"
    },
    "type": {
      "const": "scene",
      "description": "顶层类型,恒为 scene"
    },
    "children": {
      "type": "array",
      "description": "场景下的主要元素(墙体、独立家具等)",
      "items": { "$ref": "#/$defs/node" }
    }
  },
  "required": ["name", "type", "children"],

  "$defs": {
    "vector2": {
      "type": "object",
      "description": "二维坐标(用于墙体起止点)",
      "properties": {
        "x": { "type": "number" },
        "y": { "type": "number" }
      },
      "required": ["x", "y"]
    },
    "vector3": {
      "type": "object",
      "description": "三维坐标(模型放置位置)",
      "properties": {
        "x": { "type": "number" },
        "y": { "type": "number" },
        "z": { "type": "number" }
      },
      "required": ["x", "y", "z"]
    },
    "rotation3": {
      "type": "object",
      "description": "三维欧拉角旋转(单位:度)",
      "properties": {
        "x": { "type": "number", "description": "绕X轴旋转角度" },
        "y": { "type": "number", "description": "绕Y轴旋转角度" },
        "z": { "type": "number", "description": "绕Z轴旋转角度" }
      },
      "required": ["x", "y", "z"]
    },
    "node": {
      "type": "object",
      "description": "通用节点(墙体、门窗、家具等)",
      "properties": {
        "name": { "type": "string", "description": "节点名称,如 wall_3224" },
        "type": {
          "type": "string",
          "enum": [
            "wall",
            "door",
            "window",
            "bed",
            "wardrobe",
            "desk",
            "chair",
            "decoration",
            "sofa",
            "scene",
            "other"
          ],
          "description": "节点类型"
        },
        "startPoint": {
          "$ref": "#/$defs/vector2",
          "description": "起点坐标(用于线性对象,如墙体、门、窗)"
        },
        "endPoint": {
          "$ref": "#/$defs/vector2",
          "description": "终点坐标(用于线性对象,如墙体、门、窗)"
        },
        "position": {
          "$ref": "#/$defs/vector3",
          "description": "三维放置位置(场景坐标系下)"
        },
        "rotation": {
          "$ref": "#/$defs/rotation3",
          "description": "三维旋转角度(欧拉角)"
        },
        "dimensions": {
          "type": "object",
          "description": "包围盒尺寸,用于体积对象(家具、装饰物)",
          "properties": {
            "w": { "type": "number", "description": "宽度 X 方向" },
            "d": { "type": "number", "description": "深度 Y 方向" },
            "h": { "type": "number", "description": "高度 Z 方向" }
          },
          "required": ["w", "d", "h"]
        },
        "children": {
          "type": "array",
          "description": "当前节点下的子元素,例如:墙上的门、窗;或靠墙的家具",
          "items": { "$ref": "#/$defs/node" }
        },
        "meta": {
          "type": "object",
          "description": "附加属性,如材质、模型id、风格标签、放置约束等",
          "properties": {
            "modelId": { "type": "string", "description": "3D 模型资源ID" },
            "material": { "type": "string", "description": "材质或贴图名称" },
            "anchor": {
              "type": "string",
              "enum": ["back_bottom_center"],
              "description": "锚点类型,默认背后底部中心"
            },
            "relation": {
              "type": "string",
              "enum": ["against_wall", "free", "corner", "center"],
              "description": "摆放关系"
            },
            "wallRef": {
              "type": "string",
              "description": "如果靠墙摆放,指向所依附墙体的 name"
            }
          }
        }
      },
      "required": ["name", "type"],
      "additionalProperties": false
    }
  }
}

Schema 说明摘要

字段含义示例
name节点名称,唯一标识"bed_01"
type节点类型"wall" / "bed" / "window"
startPoint, endPoint线性节点的起止坐标(2D){x:-5000, y:1000}
position模型在场景坐标系下的放置点(锚点位置){x:1200, y:0, z:0}
rotation欧拉角旋转{x:0, y:90, z:0}
dimensions模型包围盒大小{w:1600, d:2000, h:600}
children子节点数组(如墙上的门、窗)[{type:"window", ...}]
meta.anchor模型锚点类型,固定 "back_bottom_center"约定所有模型一致
meta.relation放置关系(靠墙 / 独立 / 角落)"against_wall"
meta.wallRef若靠墙,指向墙体名称"wall_3224"

输出结构举例(示例)

{
  "name": "scene",
  "type": "scene",
  "children": [
    {
      "name": "wall_3224",
      "type": "wall",
      "startPoint": { "x": -5250, "y": 2392 },
      "endPoint": { "x": 2609, "y": 2392 },
      "children": [
        {
          "name": "window_3244",
          "type": "window",
          "startPoint": { "x": -1913, "y": 2566 },
          "endPoint": { "x": -4413, "y": 2566 }
        },
        {
          "name": "bed_01",
          "type": "bed",
          "position": { "x": -3000, "y": 2200, "z": 0 },
          "rotation": { "x": 0, "y": 180, "z": 0 },
          "dimensions": { "w": 1600, "d": 2000, "h": 600 },
          "meta": {
            "relation": "against_wall",
            "wallRef": "wall_3224",
            "anchor": "back_bottom_center"
          }
        }
      ]
    },
    {
      "name": "sofa_01",
      "type": "sofa",
      "position": { "x": 0, "y": 0, "z": 0 },
      "rotation": { "x": 0, "y": 90, "z": 0 },
      "dimensions": { "w": 2000, "d": 800, "h": 900 },
      "meta": {
        "relation": "free",
        "anchor": "back_bottom_center"
      }
    }
  ]
}

使用方式建议

  1. 校验

    用 ajv(Node.js)或 jsonschema(Python)校验 LLM 输出是否符合该 Schema。

import Ajv from "ajv";
const ajv = new Ajv();
const validate = ajv.compile(sceneSchema);
const valid = validate(sceneOutput);
if (!valid) console.error(validate.errors);
  1. 生成提示词约束

    在系统 Prompt 里明确要求模型:

    请严格输出符合此 JSON Schema 的内容,不要包含 Markdown 或注释。

    所有靠墙家具请放入对应墙体的 children 数组中,未靠墙的放 scene.children 顶层。


第四部分:二维布局输入 + 家具输入限制 + 三维输出 Schema 的嵌入方式(Prompt结构)

在提示词(Prompt)中,建议采用 明确角色 + 多输入块 的结构,让模型“看到”输入与目标输出的语义分区。


推荐的 Prompt 模板结构(可直接嵌入到系统中)

系统提示(system):
你是一名专业的室内空间布局规划师,负责根据房间结构和家具约束生成三维场景布局。
输出必须符合下方 OUTPUT_SCHEMA。
请严格输出 JSON,不要添加额外文字或 Markdown。
所有家具的锚点是背后底部中心 (0, -d/2, -h/2)。

---------------------
INPUT_SCHEMAS:
1.房间结构 (2D Scene Input Schema)
2.家具清单 (Furniture Input Schema)
3.输出场景 (3D Scene Output Schema)
---------------------

任务说明:
根据房间的尺寸、门窗位置以及家具的尺寸与规则,
推理出每个家具的最佳位置(position)和朝向(rotation),
并将靠墙的家具放入对应墙体的 children 中,
未靠墙的家具放在 scene.children 顶层。

---------------------
2D_ROOM_INPUT:
{{room_json}}

FURNITURE_INPUT:
{{furniture_json}}

---------------------
OUTPUT_SCHEMA(你必须遵守):
{{scene_output_schema}}

---------------------
请根据上面的输入与规则,生成符合 OUTPUT_SCHEMA 的三维布局 JSON。

嵌入结构说明

部分内容示例变量
room_json用户提供的二维结构输入你的墙体 + 门窗 JSON
furniture_json家具及约束信息上面定义的 furniture schema 实例
scene_output_schema输出的三维布局定义之前那份 Output Scene JSON Schema

工作逻辑

  1. 输入给模型:

    • room_json → 空间边界
    • furniture_json → 可放置家具及规则
  2. 模型任务:

    • 推理每个家具该放哪儿、面向哪个方向;
    • 靠墙家具 → 放入该墙的 children;
    • 其余家具 → 放在 scene.children;
  3. 输出:

    • 一份完整的、层级化的 scene JSON,带 position 和 rotation。

总结

模块功能Schema 文件
家具输入定义家具信息和规则furniture-input.schema.json
场景输入定义房间墙体/门窗结构scene-2d-input.schema.json
输出场景定义最终布局结果(3D)scene-output.schema.json
Prompt明确角色 + 输入 + 输出Schema用模板拼接生成请求