Pascal Editor 連携
概要
Pascal Editor(pascalorg/editor)は、React Three Fiber と WebGPU で構築されたオープンソースの 3D 建築エディタです。ノードベースのシーングラフ、Zustand による状態管理、そして AI 駆動の建築生成に適したシステムアーキテクチャを備えています。このスキルでは、建築形状の作成、操作、エクスポートを行うためのコア API について説明します。
手順
クイックスタート
npx create-next-app@latest my-building-app
cd my-building-app
npm install @pascal-app/core @pascal-app/ui @react-three/fiber @react-three/drei three zustand
ノード階層
Pascal は型付きノードのツリーを使用します:
Site -> Building -> Level -> Wall -> Opening (door/window)
-> Slab (floor/ceiling)
-> Zone (room boundary)
-> Item (furniture, fixture)
すべてのノードは以下を持ちます:id(UUID)、type、parentId、children(子 ID)、props(型固有)、dirty(再構築のマーク)。
Zustand ストア
import { useScene, useViewer, useEditor } from '@pascal-app/core'
// useScene -- シーングラフ(ノード、リレーション)
const { nodes, createNode, updateNode, deleteNode } = useScene()
// useViewer -- ビューポート状態(カメラ、選択)
const { selectedIds, camera, setSelection } = useViewer()
// useEditor -- ツールモードと UI 状態
const { activeTool, setTool, history } = useEditor()
開口部のある壁の作成
const scene = useScene.getState()
// 外壁:長さ 4.5m、厚さ 200mm、天井高 2.7m
const wall = await scene.createNode({
type: 'wall',
props: {
start: { x: 0, y: 0 }, end: { x: 4.5, y: 0 },
thickness: 0.20, height: 2.7,
isExterior: true, material: 'masonry',
}
}, levelId)
// 窓を追加:幅 1.2m、腰高 900mm
await scene.createNode({
type: 'item',
props: {
itemType: 'window', wallId: wall.id,
offsetFromStart: 1.5, width: 1.2, height: 1.2, sillHeight: 0.9,
}
}, wall.id)
// ドアを追加:幅 900mm
await scene.createNode({
type: 'item',
props: {
itemType: 'door', wallId: wall.id,
offsetFromStart: 3.0, width: 0.9, height: 2.1, sillHeight: 0,
}
}, wall.id)
レベルと部屋の作成
const level = await scene.createNode({
type: 'level',
props: { name: 'Ground Floor', elevation: 0, height: 2.7, index: 0 }
}, buildingId)
// 床スラブ
await scene.createNode({
type: 'slab',
props: {
polygon: [{ x: 0, y: 0 }, { x: 10, y: 0 }, { x: 10, y: 8 }, { x: 0, y: 8 }],
thickness: 0.25, isRoof: false,
}
}, level.id)
// 部屋ゾーン(ラベリングと面積計算用)
await scene.createNode({
type: 'zone',
props: {
name: 'Living Room', roomType: 'living',
polygon: [{ x: 0.1, y: 0.1 }, { x: 5.4, y: 0.1 }, { x: 5.4, y: 7.9 }, { x: 0.1, y: 7.9 }],
}
}, level.id)
シーンを JSON にエクスポート
function exportScene(): BuildingExport {
const { nodes } = useScene.getState()
const allNodes = Object.values(nodes)
const site = allNodes.find(n => n.type === 'site')
const building = allNodes.find(n => n.type === 'building')
const levels = allNodes
.filter(n => n.type === 'level' && n.parentId === building.id)
.sort((a, b) => a.props.elevation - b.props.elevation)
return {
units: 'meters',
site: { width: site.props.width, depth: site.props.depth },
building: {
levels: levels.map(level => ({
name: level.props.name,
elevation: level.props.elevation,
height: level.props.height,
walls: getChildrenByType(level.id, 'wall', allNodes),
rooms: getChildrenByType(level.id, 'zone', allNodes),
}))
}
}
}
React Three Fiber でのレンダリング
import { Canvas } from '@react-three/fiber'
import { PascalScene, PascalCamera, PascalControls } from '@pascal-app/ui'
export function BuildingViewer() {
return (
<Canvas camera={{ position: [0, 20, 20], fov: 45 }}>
<PascalScene />
<PascalCamera />
<PascalControls />
<ambientLight intensity={0.5} />
<directionalLight position={[10, 20, 10]} castShadow />
</Canvas>
)
}
グリッドスナップ
Pascal はデフォルトで 100 mm(0.1 m)グリッドを使用します:
const snapToGrid = (value: number, gridSize = 0.1) =>
Math.round(value / gridSize) * gridSize
例
例 1:10m x 8m の Ground Floor を構築する
外壁、リビングと寝室を分ける内部間仕切り、適切な開口部を持つ完全な Ground Floor を作成します:
- レベルノードを作成(elevation 0、高さ 2.7 m)
- 床スラブを作成:10 m x 8 m のポリゴン、厚さ 0.25 m
- 4 つの外壁を作成(厚さ 0.20 m、masonry):北(10 m)、東(8 m)、南(10 m)、西(8 m)
- x=5.5 に内部間仕切りを追加(厚さ 0.10 m、timber)、奥行き方向に貫通
- 北壁に玄関ドアを追加:1.0 m x 2.1 m、オフセット 3.5 m
- 東壁に窓を追加:2 つ、各 1.2 m x 1.2 m、腰高 0.9 m、オフセット 1.2 m と 4.5 m
- ゾーンを作成:リビングルーム(5.3 m x 7.8 m = 41.3 m2)、ベッドルームエリア(4.3 m x 7.8 m = 33.5 m2)
- JSON にエクスポートし、
architectural-dimensionsルールに対して検証
例 2:カスタム検証システムの登録
壁ノードが変更されるたびに壁の厚さをチェックするシステムを作成します:
import { registerSystem, useScene } from '@pascal-app/core'
registerSystem({
name: 'wall-validator',
nodeTypes: ['wall'],
priority: 100,
process(dirtyNodes) {
for (const node of dirtyNodes) {
const { thickness, isExterior, height } = node.props
if (isExterior && thickness < 0.14)
console.warn(`Wall ${node.id}: exterior ${thickness}m < 0.14m minimum`)
if (height < 2.1)
console.warn(`Wall ${node.id}: height ${height}m < 2.1m minimum`)
}
}
})
これは、壁ノードがダーティとマークされるたびに、ジオメトリシステムがメッシュを再構築する前に自動的に実行されます。
ガイドライン
- すべての寸法はメートル単位 — Pascal は内部でメートル法を使用します
- ノードの CRUD 操作には
useScene、選択/カメラにはuseViewer、ツールにはuseEditorを使用します - 座標は 0.1 m グリッドにスナップしてクリーンなジオメトリにします
- 壁の厚さ:外壁は 0.20 m、内部間仕切りは 0.10 m
- ドアの敷居高さは常に 0(床レベル)。窓の腰高はデフォルトで 0.9 m
- ジオメトリ再構築(優先度 0-50)の前に実行するカスタムシステムは、優先度 > 50 で登録します
- 現実世界の寸法検証には
architectural-dimensionsスキルと組み合わせて使用します - 主要パッケージ:
@pascal-app/core、@pascal-app/ui、@react-three/fiber、three、zustand - GitHub:github.com/pascalorg/editor