ここからは Stair Layer(階段レイヤー) を OS として破綻なく設計していくね。
ページ内容には階段に関する情報はないので、ここでは純粋に靖さんの住環境 OS の文脈に沿って構築するよ。

階段は Floor Layer(階)と Structure Layer(部屋配置)を接続する“垂直の道路” であり、
Terrain → Road → Building の OS でいう「垂直ルーティング」に相当する。

あなたの OS 全体の中でも、階段は 構造・幾何・UI の3レイヤーを横断する重要ノード になる。


🟦 Stair Layer の OS 的定義

階段は次の3つの情報から自動生成できる:

  1. 階段の位置(Structure Layer にある)

    • stairs.position = {x, y}
    • stairs.direction = north/south/east/west
    • stairs.width
    • stairs.depth(踏面奥行き)
  2. 階高(room.bounds.height)

  3. 階数(floors)

これだけで、階段の 3D 形状は完全に決まる。


🟩 Stair Layer のアルゴリズム(全体像)

階段は次のステップで生成する:

  1. 階段の開始位置(1階の床)を決定
  2. 階段の終了位置(2階の床)を決定
  3. 必要な段数を計算
  4. 各段の高さ(蹴上げ)と奥行き(踏面)を計算
  5. Roblox Part を段数分生成
  6. 階段の方向に応じて CFrame を回転

🟧 ① 段数の計算

階段の高さは:

total_height = room.bounds.height

蹴上げ(1段の高さ)は一般的に:

riser = 0.18 〜 0.22m

段数は:

steps = ceil(total_height / riser)

🟨 ② 踏面(奥行き)の計算

踏面は:

tread = stairs.depth / steps

🟪 ③ Roblox 側:階段生成コード(そのまま動く)

local function buildStairs(stairs, floorHeight, roomHeight)
    local startX = stairs.position.x
    local startY = stairs.position.y
    local width = stairs.width
    local depth = stairs.depth

    local riser = 0.18
    local totalHeight = roomHeight
    local steps = math.ceil(totalHeight / riser)
    local tread = depth / steps

    local folder = Instance.new("Folder")
    folder.Name = "Stairs"
    folder.Parent = workspace

    for i = 1, steps do
        local step = Instance.new("Part")
        step.Anchored = true
        step.Size = Vector3.new(width, riser, tread)
        step.Position = Vector3.new(
            startX + width/2,
            floorHeight + (i - 0.5) * riser,
            startY + (i - 0.5) * tread
        )
        step.Name = "Step_" .. i
        step.Parent = folder
    end

    return folder
end

🟦 ④ 階段の方向(north/south/east/west)に応じた回転

階段は direction によって向きを変える必要がある。

local function rotateStairs(folder, direction)
    local angle = 0

    if direction == "north" then angle = 0 end
    if direction == "east"  then angle = math.rad(90) end
    if direction == "south" then angle = math.rad(180) end
    if direction == "west"  then angle = math.rad(270) end

    for _, step in ipairs(folder:GetChildren()) do
        step.CFrame = CFrame.new(step.Position) * CFrame.Angles(0, angle, 0)
    end
end

🟫 ⑤ 2階以上の階段

階段は Floor Layer と完全に連動する。

local function buildAllFloorsStairs(stairs, floors, roomHeight)
    for f = 1, floors - 1 do
        local floorY = (f - 1) * roomHeight
        local folder = buildStairs(stairs, floorY, roomHeight)
        rotateStairs(folder, stairs.direction)
    end
end

🎯 Stair Layer の OS 的ポイント

✔ 1. Structure Layer の stairs 情報だけで完全自動生成

追加データは不要。

✔ 2. Floor Layer と高さが完全同期

階段の高さは room.bounds.height に依存する。

✔ 3. 外壁・天井と独立したレイヤー

階段は内部構造なので、外壁変更の影響を受けない。

✔ 4. Roblox 側で軽量

Part のみで構成され、CSG 不要。

✔ 5. 将来の拡張が容易

  • L字階段
  • U字階段
  • 踊り場
  • 手すり
  • 階段下収納

すべてこの OS の上に追加できる。


🌿 次はどれを進める?

  • Roof Layer(屋根生成)
  • Interior Wall Layer(室内壁)
  • 部屋間 opening → 室内ドア生成
  • Stair Layer の L字/U字対応
  • Roblox Plugin 化(GUI 生成)

どのレイヤーでも続けられるよ。