Author SHA1 Message Date
que01 f4a4d48e3f fix: correct participant simulation timing and queue key fallbacks
- Align signal phase evaluation with the Cesium simulation clock so speed
  control multipliers keep vehicles and traffic lights in sync
- Clamp long frame gaps instead of freezing all participants; short steps
  keep IDM deceleration clamps effective near stop lines
- Fall back to approachRoadId for lane grouping when movement.fromLaneId
  is missing, preventing side-by-side vehicle overlap on shared lanes
- Guard against a missing toggleVehicles DOM element inside the tick loop
- Use template.id as the pedestrian queue key for consistent Map lookups
- Report participant_route_too_short diagnostics instead of silently
  dropping pedestrian and bicycle templates shorter than 5 m
2026-10-10 16:07:53 +08:00
que01 7ce412e52e feat: add participant runtime simulation with traffic signal scheduling
- Implement deterministic participant simulation in cesium-preview.js with
  fixed-seed arrival, IDM car-following, stop-line constraints, and
  geometric conflict occupancy detection
- Build native traffic simulation participants from road package data
  including signal phase mapping, crosswalk centerlines, and lane routing
- Add participant runtime regression test covering 600 s simulation,
  green-only releases, and 2D bounding box overlap checks
- Update model URI prefix to _preview/ so simulation JSON resolves assets
  relative to area output directory
- Sync Trellis spec and task docs for participant scheduling contract
2026-10-10 16:07:00 +08:00
que01 c1277af16a Fix native island material rendering 2026-09-29 12:04:29 +08:00
que01 b6d30787cd chore: record journal 2026-09-22 14:17:53 +08:00
que01 5125e097af chore(task): archive 09-17-local-build-console 2026-09-22 14:16:31 +08:00
que01 3760650c70 feat: add local build console 2026-09-22 14:15:32 +08:00
que01 4ec4372b35 chore: record Cesium export optimization session 2026-09-17 17:15:43 +08:00
que01 7818e17d18 chore(task): archive 09-17-cesium-export-performance 2026-09-17 17:13:54 +08:00
que01 c6cce44f60 perf: batch Cesium export mesh preparation 2026-09-17 17:12:42 +08:00
que01 a4dfbf884a chore: remove deprecated native compiler commands 2026-08-26 13:24:31 +08:00
que01 82dcb83663 chore: keep ZIP import task active 2026-08-26 13:04:32 +08:00
que01 7e8fcd82ed chore: record ZIP artifact task completion 2026-08-26 12:59:31 +08:00
que01 eaa7c08f6a fix: finalize ZIP preview freshness and parity 2026-08-26 12:58:36 +08:00
que01 113ea54535 feat: import native road packages from ZIP 2026-08-26 12:51:58 +08:00
que01 009fe34f79 chore: record journal 2026-08-26 11:01:54 +08:00
que01 7883a451c5 chore(task): archive 08-25-rc-p3-render-separation 2026-08-26 10:58:41 +08:00
que01 620127031e feat: consume manifest-driven native roads 2026-08-26 10:55:47 +08:00
que01 5704b51315 chore: record journal 2026-08-26 09:32:22 +08:00
que01 969b57106f chore(task): archive 08-25-rc-p2-repo-split 2026-08-26 09:28:33 +08:00
que01 7d4b3b566a docs: specify external road compiler contract 2026-08-26 09:27:09 +08:00
que01 5cde08090e refactor: consume external road compiler 2026-08-26 09:23:46 +08:00
que01 b78cb6e990 chore: record journal 2026-08-25 17:28:26 +08:00
que01 b44c995457 chore(task): archive 08-25-rc-p1-package-boundary 2026-08-25 17:27:53 +08:00
que01 2469cfdbff test: make road compiler fixtures self contained 2026-08-25 17:27:19 +08:00
que01 284d3dbedb chore: remove migrated workbench sources 2026-08-25 17:22:50 +08:00
que01 f542a64924 refactor: move road workbench into compiler package 2026-08-25 17:18:49 +08:00
que01 d5c58b5b0c refactor: move native road checks into package 2026-08-25 17:15:15 +08:00
que01 73707dabbe refactor: move road compiler core into package 2026-08-25 17:12:58 +08:00
que01 5220c6b2a2 chore: record journal 2026-08-25 16:55:17 +08:00
que01 d7c2e13124 chore(task): archive 08-25-rc-p0-contract-baseline 2026-08-25 16:53:04 +08:00
que01 e7bc7f82b1 feat: add native road parity baseline 2026-08-25 16:52:25 +08:00
143 changed files with 5953 additions and 4553 deletions

No files matched your search

+2
View File
@@ -5,3 +5,5 @@ __pycache__/
assets/models/speedtree/
assets/models/lyrog/
inputs/osm
inputs/console/
.build-console/
+28
View File
@@ -307,6 +307,34 @@ npm run build:area -- --config config/areas/<area>.json --stages blender,cesium,
| 直接用 Cesium `Model.getMaterial().setValue()` 改普通 glTF PBR 材质 | 运行时数字仍保持原色,不能实现相位字色 |
| 每个信号灯各自生成 0-19 全套倒计时 mesh | 节点和几何按信号数量线性膨胀;应按两个 phase group 共享 |
## Cesium 导出准备:依赖图更新边界
`export_cesium.py` 的 `prepare_independent_meshes(candidates)` 只优化可证明为对象局部的
准备工作。Blender 的 `bpy.ops` 调用前后会更新 view layer;对约 1,744 个对象逐个调用
选择、修改器及模式切换会重复评估整个场景。实测原导出 173 秒中绝大部分用于更新,
采用以下边界后约 16 秒;不能全局 monkey-patch 或禁用 `_view_layer_update`。
- `select_only(obj)` 用选择数据 API;空修改器栈在改变上下文前直接返回。
- 原有修改器仅允许已证明局部的 `BEVEL` 进入预处理;其他类型保持原顺序回退。
- `batch_triangulate_meshes` 使用真正的 Triangulate 修改器及当前 Blender 默认值,
一次评估后通过 `new_from_object(..., preserve_all_data_layers=True)` 获取结果。
必须先收集所有结果,再替换原网格;替换/删除修改器会使 evaluated 数据失效。
共享、形状键、自定义法线、库链接、fake-user 保留网格不进入这个复制路径。
- `mesh_has_multiple_users` 按 Blender `ID_REAL_USERS` 判断:`users - int(use_fake_user)`。
对多个真实用户的网格,原修改器应用本来就失败,提前跳过保持原拓扑与共享关系。
- 缺 UV 的已准备网格在临时小场景逐对象调用原 `smart_project`,通过 `window.scene`
保持编辑模式上下文一致;有 UV 的模型资产不重展。退出必须恢复窗口场景和 view layer,
删除临时场景。无法满足条件时使用原操作路径。
验证使用 `blender/tools/check_export_preparation.py -- --baseline <original_export_cesium.py>`
在真实 Blender 内比对 control、共享网格、形状键、自定义法线、fake user、Bevel 和
Boolean 依赖回退。真实区域还必须比全部主/分类/动态 GLB 的结构摘要、解码后的索引、
坐标、UV、法线、切线、材质与贴图哈希。不要只用顶点数相同证明视觉一致。
Blender 4.5 的 Triangulate 默认 quad method 是 shortest diagonal,并非 BEAUTY。
直接换成 BMesh BEAUTY 会改变拆面和后续 UV,不能称为等价提速。任何替代算法必须先
核对源码默认值和属性转换路径。详见任务 `09-17-cesium-export-performance/research/`。
## 第三方资产导入的源文件边界
第三方 Blend 只属于一次性入库工具的输入,不能成为 `build:area` 或 Cesium 预览的运行时依赖。
+5
View File
@@ -147,6 +147,11 @@ cp config/examples/template.json config/areas/my-area.json
| `junctionTemplates.clusters[].cornerRadiusMeters` | `12`(4–25) | 仅 `complex-junction-v1`:相邻进口夹角处路缘圆角的半径。圆角切于两侧最外道路边缘,只补齐夹角处的路面,不改变 connector、信号或停止线。 |
| `junctionTemplates.clusters[].outerRadiusExtraMeters` | `18`(18–35) | 仅 `complex-junction-v1`:路口中心到外部进口交接边界的额外半径。用于让圆角包住角部斑马线;未配置时保持原有 18 m。 |
`junctionTemplates.references[*].referenceFile` 与
`junctionTemplates.clusters[*].referenceFile` 是唯一允许相对写法的路径:相对当前
`config/areas/<id>.json` 解析。`readAreaConfig()` 会先将其规范化为绝对路径,再通过
`toRoadCompilerInput()` 传入 road compiler;包内不得自行解析相对路径或读取配置文件。
### `v2xPreview`
这是 Cesium 验证预览的可选实时叠加层,不进入发布的 `package/`。默认值:
+66
View File
@@ -1464,6 +1464,72 @@ parity 校验依赖 stage 的 stdout 标记来判断阶段是否跑到(如 `SC
---
## Native Road Parity
### 1. Scope / Trigger
拆分 native road compiler、移动其模块,或声称 native-road JSON / GeoJSON 未变化时,
用 `scripts/road-parity.js`。它独立于 build stage,只读现有 native-road 输出。
### 2. Signatures
```bash
node scripts/road-parity.js --config config/areas/<area>.json --snapshot <out.json>
node scripts/road-parity.js --config config/areas/<area>.json --compare <baseline.json>
```
`--config` 必填,且 `--snapshot` 与 `--compare` 必须二选一。
### 3. Contracts
- 快照覆盖 `outputs/<area>/native-road/` 下全部文件和同级
`native-traffic-signals.json`。
- 普通 JSON 递归按对象 key 排序后生成 `contentHash`。
- GeoJSON 同时生成排序 feature 的 `contentHash` 与原序 `orderHash`;任一不同都算
parity 失败。
- 绝对路径归一化为 `<repo>/...` 或 `<external>/<basename>`,随机
`native-road-*` staging 名归一化为 `<staging>`。坐标不做容差或舍入。
### 4. Validation & Error Matrix
| 条件 | 结果 |
|---|---|
| 缺 `--config` 或同时/均未传 snapshot、compare | 打印 usage,退出非零 |
| native-road 输出目录不存在 | 抛出 `Native road output not found`,退出非零 |
| baseline 缺文件、出现额外文件或任一 hash/count/bytes 不同 | 每项打印 `ROAD_PARITY_DIFF`,退出非零 |
| 完全一致 | 打印 `ROAD_PARITY_OK`,退出 0 |
### 5. Good/Base/Bad Cases
- Good: 移动编译器前后,两个 hash 均一致。
- Base: 绝对 OSM 输入路径变化但归一化后内容一致。
- Bad: 只比较排序后的 GeoJSON 内容并忽略 `orderHash`,会掩盖输出顺序漂移。
### 6. Tests Required
- `npm run test:road-parity`:相等基线、顺序 hash 变化与缺文件都应被断言。
- `node --check scripts/road-parity.js`。
- 对每个受支持区域运行 `--compare` 对已提交基线自比对。
- 迁移前先连续编译两次;只有 control 实验全绿,基线才可作为 oracle。
### 7. Wrong vs Correct
Wrong:
```js
// Sorting hides a changed feature order.
assert.equal(sortedContentHash, baseline.contentHash);
```
Correct:
```js
assert.equal(contentHash, baseline.contentHash);
assert.equal(orderHash, baseline.orderHash);
```
---
## 反模式
| 反模式 | 后果 |
+3 -2
View File
@@ -18,6 +18,7 @@
| 改复合路口几何(`buildComplexJunctionGeometry`、车道控制避让、人行道转角) | [CLI 与阶段](./cli-and-stages.md#可编辑信号设施与运行时锚点的跨阶段消费) 的复合路口小节 |
| 改预览页生成 | [../preview/](../preview/index.md) |
| 声称"纯重构,产物不变" | [产物一致性指南](../guides/artifact-parity-guide.md) |
| Native road compiler CLI、输入或完成标记 | [编译器契约指针](./native-road-package.md) |
---
@@ -46,8 +47,8 @@ config/areas/<id>.json
│ → 重建 scene.geojson + scene_style.json
│ → _pipeline/stages/reimport.manifest.json
│
├─[blender]───────▶ compile-native-roads.js + Blender + blender/generate_scene.py
│ 默认读 .osm + native-road/
├─[blender]───────▶ native-road ZIP importer + Blender + blender/generate_scene.py
│ 默认读 .osm + validated ZIP cache/
│ → <id>.blend + <id>.png
│ → _pipeline/stages/blender.manifest.json
│
@@ -0,0 +1,62 @@
# Native Road Package Contract
The native-road package is maintained in the private `road-compiler` repository:
`https://git.app.que01.top/que01/road-compiler`
The host consumes a read-only ZIP exported by the private `road-compiler` repository. The host never installs or invokes the compiler. `nativeRoadPackage` is resolved relative to the area config, hashed, validated, and extracted into `_pipeline/native-road-import/<sha256>/` before native consumers start.
The completion marker is `NATIVE_ROAD_COMPILE_DONE <json>`. `build-area.js` validates the marker's count, JSON payload, area id, output path, process status, and signal before starting Blender.
## Scope / Trigger
This contract applies to native-road consumption from `scripts/build-area.js`, diagnostics, parity, Blender, and native preview generation.
## Signatures
```text
road-compiler --input <RoadCompilerInput.json>
```
`RoadCompilerInput` contains `areaId`, absolute `osmFile`, `outDir`, `stagingDir`, `overridesFile`, `trafficSignalsFile`, optional `comparisonDir`, and `options`.
## Contracts
The compiler writes `compiled.json`, `diagnostics.json`, `comparison.json`, signal runtime files, `manifest.json`, and GeoJSON layers under `outDir`. Since `native-road-package/v1.1`, `manifest.json` is required: it declares every GeoJSON source, whether its role is renderable (`surface` / `marking`) or semantic, and the host material slot for renderable layers. The Blender adapter rejects a missing or invalid manifest, a declared/published GeoJSON mismatch, and an unknown material slot. On success stdout contains exactly one marker whose JSON includes `areaId`, `roads`, `endpoints`, `diagnostics`, and `output`.
## Validation & Error Matrix
| Condition | Required result |
|---|---|
| CLI cannot start | throw the spawn error |
| non-zero exit or signal | fail with status/signal |
| zero completion markers | fail |
| multiple completion markers | fail |
| malformed marker JSON | fail |
| marker `areaId` or `output` mismatch | fail |
## Good / Base / Bad Cases
- Good: host writes an absolute input JSON, runs the installed exact-tag CLI, validates one marker, then starts Blender.
- Base: compiler emits deterministic files and no optional comparison source exists.
- Bad: host imports compiler source, reads `config/areas` inside the package, or accepts a missing/duplicate marker.
## Tests Required
- `scripts/test-road-compiler-cli.js` asserts marker success, missing, duplicate, malformed, area mismatch, and output mismatch cases.
- `scripts/road-parity.js` compares `contentHash`, `orderHash`, feature counts, and byte counts for both supported areas.
- `npm run test:road-workbench` asserts the workbench is loaded from the installed package.
## Wrong vs Correct
Wrong:
```js
require("../packages/road-compiler/src/compile/compiler");
```
Correct:
```js
spawnSync(process.execPath, [compilerCli(), "--input", inputFile]);
```
+11
View File
@@ -100,6 +100,17 @@ if (oneway !== "-1") edges.push(makeEdge(way, refs, coords, "forward"));
if (!isOneWay(oneway)) edges.push(makeEdge(way, [...refs].reverse(), [...coords].reverse(), "backward"));
```
## 本地参与者调度校验
`scripts/lib/cesium-preview.js:createParticipantSimulation()` 使用固定种子的间隔到达、IDM 跟驰、
进口停止线约束和几何冲突占用。排队及占用检测仅包含已到达且仍活动的参与者;首次放行必须
同时更新路程和 committed 状态。进入路口后不再服从出口方向的信号灯,但仍让行前方过街者。
行人及自行车仅在配对方向红灯且剩余时间足够完成过街时进入,启动全红不放行过街者。
回归命令:`npm run test:participant-runtime`。可传真实生成数据进行 600 秒的放行、通行完成
及二维包围盒重叠检查:`node scripts/test-participant-runtime.js outputs/fengshu-er-road/_preview/fengshu-er-road-traffic-simulation.json`。
这是展示级调度校验,不代替 GLB 模型实际外形、车身原点和浏览器渲染的检查。
## 信号动态 GLB 契约
`traffic_signals.json` 的 `pose.*` 是 Blender 静态设施、动态灯珠和倒计时共享的锚点。Blender
@@ -184,6 +184,10 @@ registry.list() -> VehicleRecord[]
平滑:用 `Cesium.SampledPositionProperty` 按 `duration` 插值,替代当前的直接赋值跳变。
模型资产闭包:dashboard 的车辆模型已复制到本项目 `assets/models/v2x-vehicles/`,由
`scripts/lib/vehicle-library.js` 构建时复制到输出预览目录。运行时不访问
`/Users/que01/Project/wbza_web`;外部 dashboard 仅作为模型来源与契约参考。
### 4.5 宽松解析(R9)
源项目用 `saferEval`。浏览器端零依赖不能引入该库,也不应引入 `eval`。改为
@@ -59,7 +59,7 @@
### R8 车辆模型命名与资产对齐
- OBU 数据层标记为 `car_obu.glb`,但 dashboard 的实际 `CrossCars` 模板固定渲染 `11.glb`;预览必须遵从该最终渲染契约。目标识别车辆使用 `${type}${subType}.glb`。
- 预览包必须携带 dashboard 实际使用的车辆模型;包内缺少未知车型时回退到 `11.glb`,并在面板提示,不得静默显示错误车型。
- 预览包必须携带已复制到本项目 `assets/models/v2x-vehicles/` 的 dashboard 实际使用车辆模型;构建和运行时不得读取 dashboard 外部路径。包内缺少未知车型时回退到 `11.glb`,并在面板提示,不得静默显示错误车型。
### R9 推送体解析健壮性
- 源项目对两个车辆 socket 使用 `saferEval` 而非 `JSON.parse`,说明载荷不保证严格 JSON。
@@ -0,0 +1 @@
{"_example": "Fill with {\"file\": \"<path>\", \"reason\": \"<why>\"}. Put spec/research files only — no code paths. Run `python3 .trellis/scripts/get_context.py --mode packages` to list available specs. Delete this line once real entries are added."}
@@ -0,0 +1 @@
{"_example": "Fill with {\"file\": \"<path>\", \"reason\": \"<why>\"}. Put spec/research files only — no code paths. Run `python3 .trellis/scripts/get_context.py --mode packages` to list available specs. Delete this line once real entries are added."}
@@ -0,0 +1,96 @@
# 后续计划:drawtonomy 扩展 PoC
前置任务:`08-25-road-compiler-extraction` 的 Phase 0-3 完成并完成验收。
评估依据:父任务归档前的 `design.md` §4 决策记录 D1 / D2 / D3。
## Goal
在**编译器仓库内**实现一个 drawtonomy 扩展:把编译产物注入其浏览器编辑器,
回读快照后走其开源导出器产出 OpenDRIVE / Lanelet2。
定位是 **PoC,不进关键路径**。目的是验证「编译器当 scene generator +
drawtonomy 当编辑器与工业格式后端」这条链路是否值得投入。
## 前提认知(已核实)
必须先明确,否则会做错方向:
- **drawtonomy 编辑器闭源**,克隆仓库只有 SDK / dev-server / mcp-server。
README 卖点里的 topology-aware lanes、lane tool、intersection templates、
Map→lanes 全部不在开源代码内。
- **它不做 raw OSM 推导**。`exporter/osmParser.ts` 是 Lanelet2 解析器
(车道左右边界已显式)。整个 exporter 目录 grep `highway` 命中 1 次且是
车道类型字符串。→ **不能替代本编译器**,只能做下游。
- **junctionTools 不能做成扩展**:无 canvas/overlay 能力、无工具注册、
**无任何 change 事件推送**(`ExtensionClient.handleMessage` 入站只有
`ext:init` / 5 个 `*-response` / `ext:error`,读取全靠轮询)。
→ junction 编辑留在自有 workbench。
- **`drawtonomy-dev-server` 是 drawtonomy.com 的缓存代理**(TTL 1 小时),
非自托管。宿主协议会漂(manifest 有 `minHostVersion`)。→ 不进关键路径。
## Requirements
### R4.1 扩展:编译产物 → 编辑器
- manifest capabilities:`shapes:write`、`ui:panel`、`snapshot:read`、`ui:notify`
- 面板调编译器的本地 HTTP 服务(`road-workbench` 已经是一个 HTTP 服务)取产物
- 车道边界 → `createLaneWithBoundaries(leftPoints, rightPoints, opts)` → `addShapes()`
- 坐标转换:本项目 WGS84/ENU(米)→ drawtonomy 画布像素。
沿用其 `drawtonomy_origin_lat/lon` + `latLonToCanvas` 约定
- ⚠️ **借它的结构,不借它的坐标系**:其 `BaseShape.x/y` 是画布像素
(`z` 注释明确写 "world units — NOT canvas pixels like x/y")。
编译器内部坐标系不得因此改变
### R4.2 回读 → 工业格式导出
- `requestSnapshot()` 取回快照
- 本地跑其开源 `exportToOpenDrive` / `lanelet2`(Apache-2.0)
- 产出 `.xodr` / `.osm`(Lanelet2),用其 `validateOpenDrive` 自校验
- Lanelet2 是 Autoware 的输入格式 —— 对本项目 V2X 方向有实际价值
### R4.3 许可与依赖合规
- drawtonomy SDK 是 Apache-2.0:借用代码需保留 NOTICE / 署名
- 若依赖 drawtonomy.com 托管服务,需查其服务条款(app 非 Apache-2.0)
- ESM/CJS 互操作:SDK 是 ESM+TS,编译器是 CJS。
本阶段可**局部**引入构建步骤,但仅限扩展目录,不得污染编译器核心
(父任务 C2 的边界)
### R4.4 归属
扩展代码放**编译器仓库**,不放宿主 —— 符合父任务「独立维护」目标。
## Acceptance Criteria
- [ ] AC4.1 扩展能把一个区域的编译产物注入 drawtonomy 编辑器并正确显示车道
- [ ] AC4.2 编辑器内手改后回读快照,能导出通过 `validateOpenDrive` 的 `.xodr`
- [ ] AC4.3 能导出 Lanelet2 `.osm`
- [ ] AC4.4 编译器核心未引入构建步骤(构建仅限扩展目录)
- [ ] AC4.5 编译器内部坐标系未因适配画布像素而改变
- [ ] AC4.6 Apache-2.0 署名 / NOTICE 已按要求保留
- [ ] AC4.7 结论记录:这条链路是否值得继续投入,写入任务 `research/`
## 启动条件
- 道路编译器独立化父任务(Phase 0-3)已完成验收。
- 编译器仓库、稳定 CLI 与版本化输出契约已可用。
- 此任务不阻塞道路编译器抽离或渲染分离的交付。
## 明确不做
- junctionTools 做成扩展(API 不支持,见前提认知)
- 把 drawtonomy 放进生产构建链路
- 用 drawtonomy 替代编译器(D1 已否决)
- 自建通用白板编辑器
## 后续可能(不属本阶段)
父任务 design §4 的 D3 列了三项值得从 drawtonomy 借用的东西,
它们与本阶段独立,应各自开任务:
- `odrGeometryFit.ts` 的拟合器 → 替掉手调的
`approachWidthMultiplier=1.45` / `coreRadiusMeters=28`,改为对 `referenceFile`
拟合、残差作质量指标
- validator 的 mutation-proven 方法 → 给现有 31 条诊断规则建触发证明
- validator 的分层命名空间(`xml.*` / `ref.*` / `junction.*` / `geom.*`)
→ 替代当前平铺的 31 条规则
@@ -0,0 +1,28 @@
{
"id": "rc-p4-drawtonomy-ext",
"name": "rc-p4-drawtonomy-ext",
"title": "后续计划:drawtonomy 扩展 PoC",
"description": "道路编译器独立化完成后,评估在编译器仓库内实现 drawtonomy 扩展:编译产物注入编辑器,快照回读后走开源 OpenDRIVE/Lanelet2 导出",
"status": "planning",
"dev_type": null,
"scope": null,
"package": null,
"priority": "P3",
"creator": "dingkang",
"assignee": "dingkang",
"createdAt": "2026-08-25",
"completedAt": null,
"branch": null,
"base_branch": "main",
"worktree_path": null,
"commit": null,
"pr_url": null,
"subtasks": [],
"children": [],
"parent": null,
"relatedFiles": [],
"notes": "不属于道路编译器独立化父任务的完成条件。父任务验收完成后,将此任务作为下一项候选任务提示。",
"meta": {
"follow_up_after": "08-25-road-compiler-extraction"
}
}
@@ -0,0 +1,21 @@
# Native Road Parity Baselines
Generated from commit `25cf82e7c75ea8d881639c4a80648121efbd39f6` on 2026-08-25.
```bash
npm run road:compile -- --config config/areas/fengshu-er-road.json
node scripts/road-parity.js --config config/areas/fengshu-er-road.json \
--snapshot .trellis/tasks/08-25-road-compiler-extraction/baseline/fengshu-er-road.json
npm run road:compile -- --config config/areas/nantaizi-lake-innovation-valley.json
node scripts/road-parity.js --config config/areas/nantaizi-lake-innovation-valley.json \
--snapshot .trellis/tasks/08-25-road-compiler-extraction/baseline/nantaizi-lake-innovation-valley.json
```
Both samples emit all twelve native-road layers. `fengshu-er-road` enables its
configured complex-junction template; `nantaizi-lake-innovation-valley` uses
the default, template-free compiler path. `hanyang-block` is an abandoned area
and deliberately excluded from this corpus.
The snapshot normalizes absolute source paths and random `native-road-*`
staging names. It does not round coordinates or ignore feature ordering.
@@ -0,0 +1,108 @@
{
"contract": "native-road-package/v1",
"areaId": "fengshu-er-road",
"files": {
"../native-traffic-signals.json": {
"contentHash": "88e7f0ef4fc7bdb9ef202af018b3fb3179035ffc8ed5eeba03276c263e1f0476",
"bytes": 5886
},
"comparison.json": {
"contentHash": "651eb4000a44a7521a79c3e1429795b83d20f8899e0c67c4bb25b56cf4a6f75d",
"bytes": 1295
},
"compiled.json": {
"contentHash": "2ab82eafcdab70155078fae3559692ef1fde0645a52c6decbaea762a9ffeb24a",
"bytes": 159230
},
"diagnostics.json": {
"contentHash": "1d9fdae06ddcbc19b5262b797a4a35c494fc30a98a66dbfa111533b12c5fdfc7",
"bytes": 6862
},
"layers/center_lines.geojson": {
"contentHash": "04db66df5821b319d59297b8515502fabcad95faf083cae19edb338be2f6024b",
"orderHash": "04db66df5821b319d59297b8515502fabcad95faf083cae19edb338be2f6024b",
"features": 5,
"bytes": 6909
},
"layers/connectors.geojson": {
"contentHash": "e7979d4642c7c10f33fb23e92721f22533a851ae1a2b4d35f224d50927bf2fe9",
"orderHash": "c327b7b154d4d9ca04cd895523eb0d8ad67c37051ef1d2135b2b46c51e12df58",
"features": 90,
"bytes": 197885
},
"layers/crosswalks.geojson": {
"contentHash": "354cd4d7ed105a11b95904b44848dce567b3a3383f76755936d8c00691fe29af",
"orderHash": "d24376438ac956bde52fcbfa955dd72c2ba31a97995608aaed1c79f6fd3633ab",
"features": 152,
"bytes": 219286
},
"layers/direction_arrows.geojson": {
"contentHash": "7b8362ad4912c997a7661befde55ddfe58757c3c8d139c15867e1938ea8f6918",
"orderHash": "5274e8b433946410a7cdffdaa452c1750e04f53e73a86bf81d034cfb26d4c254",
"features": 686,
"bytes": 1053308
},
"layers/edge_lines.geojson": {
"contentHash": "ad37fe6278e0c7caf3b77c1c5068a56e18a6c87b78ed5a840ee22a0f961ea7a8",
"orderHash": "ad37fe6278e0c7caf3b77c1c5068a56e18a6c87b78ed5a840ee22a0f961ea7a8",
"features": 0,
"bytes": 52
},
"layers/intersection_surface.geojson": {
"contentHash": "b2022ca70339aa470f3be451bf3ba2f55b59c3900645c864538372173811309f",
"orderHash": "b2022ca70339aa470f3be451bf3ba2f55b59c3900645c864538372173811309f",
"features": 5,
"bytes": 13048
},
"layers/lane_centerlines.geojson": {
"contentHash": "19c550c794810c1071de55dee158295235106a56e3877a2ba10da920ee214593",
"orderHash": "67f8e7d33ec578644416e4837dd4aafef62a55aaeb4d438d07ab07eddfbb1df1",
"features": 84,
"bytes": 73294
},
"layers/lane_separators.geojson": {
"contentHash": "02fdf2c7b6e89c2850a60ea2ac72b9f62910259bdb2949681fcaa7e67d2b51f0",
"orderHash": "81782a059c4ff9f69fdf7de9107d20a8d6cf55d34bb0620ec28a9a8c5106c982",
"features": 3596,
"bytes": 4164106
},
"layers/road_surface.geojson": {
"contentHash": "5a2936a705e64338d0d79b395a13d761f1893dd72330a9b9ee4696ae75eab295",
"orderHash": "d8402ae6e772e0778b862b190abfa291de1b02a15537d455f7dcd8596245dfd8",
"features": 30,
"bytes": 49554
},
"layers/sidewalk_surface.geojson": {
"contentHash": "b6f8f876e9f18fd2ef6749125a09d654c73d986e916bd262ceb9967bca1a54c6",
"orderHash": "3fd42a67e18e3b8743fa538428e039ef66a1f44150a6881a7aaa18326607b5cb",
"features": 26,
"bytes": 54997
},
"layers/turn_arrows.geojson": {
"contentHash": "ad37fe6278e0c7caf3b77c1c5068a56e18a6c87b78ed5a840ee22a0f961ea7a8",
"orderHash": "ad37fe6278e0c7caf3b77c1c5068a56e18a6c87b78ed5a840ee22a0f961ea7a8",
"features": 0,
"bytes": 52
},
"layers/vehicle_stop_lines.geojson": {
"contentHash": "cb904550ab8eec011cf33e5edfa81044de6dfca0280dbfe488e77229055ed590",
"orderHash": "8a4b877a17a5af60adc8656465afad6756944736291664139e878d46c5a4f363",
"features": 4,
"bytes": 4191
},
"traffic-signal-assemblies.json": {
"contentHash": "1788026a0c8c531b2fc7dd49628f7fbadd809c7b2f7f8819cffb3ac7d30689ca",
"orderHash": "b409ea6b77b6c8639f63c33a156581f9b184a84fde34d265b5deb05705828251",
"features": 7,
"bytes": 5411
},
"traffic-signals.json": {
"contentHash": "625b79b6eb82b41f2099ba51960717c7f794fdfbd87310eb12e99da966540d89",
"bytes": 15491
}
},
"volatileExcluded": [
"absolute paths -> <repo> or <external>",
"native-road-* staging directory -> <staging>"
]
}
@@ -0,0 +1,108 @@
{
"contract": "native-road-package/v1",
"areaId": "nantaizi-lake-innovation-valley",
"files": {
"../native-traffic-signals.json": {
"contentHash": "36cb9f069fb44a6e24f0af0d130ef8cb5b4a93250dc9fb0891191d1ba039a5b2",
"bytes": 28329
},
"comparison.json": {
"contentHash": "5aa11da443221a48288641ac6950c6e4d75d834713a93110bbf265859202a265",
"bytes": 1153
},
"compiled.json": {
"contentHash": "ea5ae4a04f1259b1ccec9fc1cca7ef8ba81426a77584a447480b6047b37f5e01",
"bytes": 184985
},
"diagnostics.json": {
"contentHash": "7e9327f0424dd612f389c560c114a4cafee1349bbfa36f49b2b4eab846e5ca91",
"bytes": 9755
},
"layers/center_lines.geojson": {
"contentHash": "2b2710fce06e75b0a3e4941c2da6119cea7b8bb7834345607bbee384de20ee6b",
"orderHash": "ea71a8841370689d6fc2b75d0b30ec7104638fb2904da6d707dc82ff3131e065",
"features": 511,
"bytes": 694102
},
"layers/connectors.geojson": {
"contentHash": "901a86bc6c536d38bb73ae4654ec1ce7d1c0790c2d6eba92543c48f584cd15ac",
"orderHash": "4df882ad59b65a97d892df64de0156b35beaf071b04eed671ef7b535e9e2a7b9",
"features": 76,
"bytes": 160866
},
"layers/crosswalks.geojson": {
"contentHash": "53fda76182c0d1db5f9e7ac284337ece62655d7fee8bb446fe170ea26abe8bbc",
"orderHash": "53fda76182c0d1db5f9e7ac284337ece62655d7fee8bb446fe170ea26abe8bbc",
"features": 48,
"bytes": 50536
},
"layers/direction_arrows.geojson": {
"contentHash": "38e80bbfe02d4f12ce40e7d0c8342e3bef6b602c64f81dd320b366b6a6b3d205",
"orderHash": "579aa6c37585bf4edf9d6b6b1e120f976b93ec2d0c303d82a154b75c114a45f5",
"features": 324,
"bytes": 493431
},
"layers/edge_lines.geojson": {
"contentHash": "ad37fe6278e0c7caf3b77c1c5068a56e18a6c87b78ed5a840ee22a0f961ea7a8",
"orderHash": "ad37fe6278e0c7caf3b77c1c5068a56e18a6c87b78ed5a840ee22a0f961ea7a8",
"features": 0,
"bytes": 52
},
"layers/intersection_surface.geojson": {
"contentHash": "7f79e57215e3fd07c5c0f703c71e516873db770cb869efdf18925a3184059ca3",
"orderHash": "d69df8d92d0fce8f7ee172959b978d941fd011e094857e9ab7304b3d1e98bf92",
"features": 12,
"bytes": 38528
},
"layers/lane_centerlines.geojson": {
"contentHash": "3fea4ebfe62e0d720c6977e2289f4e6517ed7b3c5ab361270d03378971aec780",
"orderHash": "69a8ebaa42a74da4f7d5940c5a81bd82ceb104efd3f858723dccfadbae12121e",
"features": 50,
"bytes": 43582
},
"layers/lane_separators.geojson": {
"contentHash": "dc0b50b53da191e65f3dba01162acb7561966d1796a9c0789527cebfd6ed06a4",
"orderHash": "0bfd873e5698869fb4855783fe30bb6db29456958e4d154b7264374a5fdb4a10",
"features": 731,
"bytes": 835933
},
"layers/road_surface.geojson": {
"contentHash": "81af19c71cf6fc8a3884488c00cfb590e1a7fe9ed9e4351fce65825ceadd50fa",
"orderHash": "f2ddec5258411fbdbc050b7ecefbb157b59e00b8226afcc30d2b772e1859e357",
"features": 25,
"bytes": 38275
},
"layers/sidewalk_surface.geojson": {
"contentHash": "bb8f4516e27b16238d753b112d18b8acfa5cfad2cea522a65b7972a609be9563",
"orderHash": "4fa773a6f39c5b6d23551e1338c6d99ef8a5ecd9ebfcafa16154c9765fef8c6e",
"features": 73,
"bytes": 122432
},
"layers/turn_arrows.geojson": {
"contentHash": "a65bb8fe079f27e00bf2e6208148fc6b73d2d07e76d48b1cd1bf8a610d7e2d66",
"orderHash": "66966ac2c65464f9c6715ca9cda5a3620520bf1d066cba2dee36114dc46af936",
"features": 108,
"bytes": 132536
},
"layers/vehicle_stop_lines.geojson": {
"contentHash": "4f45caf3c0bf13bbf10d9cac15fa80b1a9be3969ed84803ba48e56c4a0080992",
"orderHash": "4f45caf3c0bf13bbf10d9cac15fa80b1a9be3969ed84803ba48e56c4a0080992",
"features": 8,
"bytes": 8475
},
"traffic-signal-assemblies.json": {
"contentHash": "9f8d032c00784bb72bb1322238cd7b0a80e621d435b43c728da86f1e77ca352a",
"orderHash": "0b9cae13094dba1994faca4bf1d4d80e8bc5497daa46df5899bf5e6fc7f26d61",
"features": 35,
"bytes": 26398
},
"traffic-signals.json": {
"contentHash": "c4b68cc1cefeb0d393a18eef6c7eb79933fba28630826745165ed433c25779d0",
"bytes": 74151
}
},
"volatileExcluded": [
"absolute paths -> <repo> or <external>",
"native-road-* staging directory -> <staging>"
]
}
@@ -0,0 +1 @@
{"_example": "Fill with {\"file\": \"<path>\", \"reason\": \"<why>\"}. Put spec/research files only — no code paths. Run `python3 .trellis/scripts/get_context.py --mode packages` to list available specs. Delete this line once real entries are added."}
@@ -0,0 +1,294 @@
# 道路编译器独立化 — 技术设计(parent)
本文件是 **契约的权威定义**,供所有子任务引用。
Phase 0 的交付物是把本节内容落成编译器仓库内的正式文档 + 校验脚本,
而不是重新发明契约。
---
## 1. 契约:`native-road-package/v1`
### 1.1 输入契约
现状:`compile-native-roads.js` 接收整个 normalized areaConfig,但**实际只用 9 个字段**。
```
area.id → areaId
area.input → osmFile (OSM XML 路径)
area.nativeRoad.edgeLines → options.edgeLines
area.nativeRoad.junctionTemplates → options.junctionTemplates
area.outputs.nativeRoadOverrides → overridesFile
area.outputs.nativeTrafficSignals → trafficSignalsFile
area.outputs.nativeRoadDir → outDir
area.outputs.pipelineDir → stagingDir
area.outputs.geojsonDir → comparisonDir (见 K2,倾向移除)
```
目标形状:
```js
// RoadCompilerInput —— 编译器唯一入口参数
{
areaId: string,
osmFile: string, // 绝对路径
outDir: string, // native-road/ 的目标位置
stagingDir: string, // 原子提升用的临时目录父级
overridesFile: string,
trafficSignalsFile: string,
options: {
edgeLines: boolean,
junctionTemplates: {
enabled: boolean,
references: [],
clusters: [{ id, template, referenceFile, nodeIds, ...几何参数 }]
}
}
}
```
**宿主侧责任**:`scripts/lib/area-config.js` 把 areaConfig 映射成 `RoadCompilerInput`。
**编译器侧责任**:不认识 areaConfig,不读 `config/areas/*.json`,不推导任何路径。
### 1.2 输出契约
`compiled.json` 顶层键(已核实):
```
schema, areaId, source, model, movements, trafficSignals, diagnostics, layers
```
`source` 含 `{ osm, overrides, trafficSignals }` 三个路径 —— 是 parity 归一化的重点对象。
```
<outDir>/ # 原子提升:先写 staging 再 rename
manifest.json # ← Phase 3 新增,图层自声明
compiled.json # 单一读模型,含 model + movements
diagnostics.json # severity / subject / sourceIds / rule / message / geometry?
comparison.json # ← 见 K2,可能移除
layers/
road_surface.geojson
intersection_surface.geojson
sidewalk_surface.geojson
edge_lines.geojson
lane_separators.geojson
center_lines.geojson
crosswalks.geojson
vehicle_stop_lines.geojson
direction_arrows.geojson
turn_arrows.geojson
lane_centerlines.geojson # 语义层,不渲染
connectors.geojson # 语义层,不渲染
<trafficSignalsFile> # 兄弟文件,不在 outDir 内
```
**stdout 完成标记**(与宿主 `SCENE_DONE` / `CESIUM_EXPORT_DONE` 同约定):
```
NATIVE_ROAD_COMPILE_DONE {"areaId":…,"roads":N,"endpoints":N,"diagnostics":N,"output":…,"comparison":…}
```
### 1.3 消费方式:子进程为主契约
| 方式 | 定位 |
|---|---|
| CLI 子进程 + 读 `outDir` + 解析 stdout 标记 | **主契约**。宿主 pipeline 层本就是唯一能启动外部进程的层 |
| `require()` in-process | 仅作性能优化,不得成为唯一路径 |
选子进程的理由:
1. 语言无关 —— 编译器将来若换 TS/Rust,宿主零改动。
2. 强制文件契约成为真契约,无法偷传对象绕过边界。
3. 与既有 QGIS / GDAL / Blender 调用方式一致。
`build-area.js:7` 现在是 in-process `require`。Phase 2 改为子进程调用。
---
## 2. 模块清单:什么搬、什么留
### 2.1 搬(约 3400 行核心 + workbench)
| 文件 | 行数 | 依赖 |
|---|---|---|
| `scripts/lib/native-road.js` | 1695 | fs, path, turn-lane-arrows, complex-junction |
| `scripts/lib/complex-junction.js` | 474 | fs, gaode-junction-reference |
| `scripts/lib/turn-lane-arrows.js` | 502 | fs, path, lane-geometry |
| `scripts/lib/gaode-junction-reference.js` | 231 | fs |
| `scripts/lib/lane-geometry.js` | 161 | 无(纯函数) |
| `scripts/lib/native-traffic-signals.js` | 49 | osm, traffic-signals ← **见 K1** |
| `scripts/lib/osm.js` | 102 | 无 |
| `scripts/compile-native-roads.js` | — | area-config ← **要换成窄契约** |
| `scripts/check-native-roads.js` | — | area-config ← 同上 |
| `scripts/road-workbench.js` + `scripts/workbench/app.js` | 173 + — | area-config ← 同上 |
| `scripts/test-native-road.js`、`scripts/test-road-workbench.js` | — | fixture ← **见 K5** |
依赖图(已核实,`native-road.js` 对宿主零耦合):
```
native-road.js ──→ turn-lane-arrows ──→ lane-geometry (纯)
└──────────→ complex-junction ──→ gaode-junction-reference
native-traffic-signals ──→ osm.js
└──→ traffic-signals.js ← 共用,需拆
```
### 2.2 留
- `scripts/lib/area-config.js` —— 宿主拥有,新增 `toRoadCompilerInput()` 映射
- `scripts/build-area.js` —— 改为子进程调用编译器
- `scripts/lib/traffic-signals.js` 的 legacy 读取器部分(见 K1)
- `blender/` 全部 —— Phase 3 内部重组,但不搬出仓库
- `scripts/lib/scene-layers.js`、osm2streets / QGIS legacy 链路 —— 完全不动
### 2.3 K1 的拆分建议(Phase 1 需细读确认)
`lib/traffic-signals.js` 当前混了两类东西:
| 类别 | 使用方 | 归属 |
|---|---|---|
| OSM 信号节点提取 + 信号文档 schema | `native-traffic-signals.js` | **随编译器走** —— 编译器生成该文档,就该拥有其契约 |
| `readTrafficSignalFeatures` | `build-osm2streets-qgis.js` | 留宿主 |
| `readTrafficSignals` | `build-area.js` | 留宿主 |
| `buildTrafficSignals` | `test-preview-assets.js` | 待判定 |
拆完后宿主从编译器包 import 信号文档 schema,反向依赖为 0 不受影响
(宿主依赖编译器是允许的方向)。
---
## 3. Phase 3:渲染分离的设计
### 3.1 现状问题
`blender/osmassets/catalog.py:53` 的 `NATIVE_ROAD_LAYERS` 是一张跨仓库重复表:
```python
# 注释自陈:"It is a provider adapter, not a second scene-layer registry."
NATIVE_ROAD_LAYERS = (
{"source": "road_surface", "material_layer": "road_surface"},
{"source": "edge_lines", "material_layer": "lane_separators"},
... 共 10 项
)
```
编译器写 12 个 geojson,这张表只列 10 项 —— `lane_centerlines` / `connectors`
是语义层不参与渲染。**但这个事实只存在于这张表的省略里,编译器侧没有任何声明。**
后果:编译器新增图层 → 必须有人记得去另一个仓库改 `catalog.py` → 忘了就静默少渲染一层。
这正是 `.trellis/spec/pipeline/index.md` 首页警告的「最容易出静默错误」。
### 3.2 目标:编译器自声明图层
`<outDir>/manifest.json`:
```json
{
"contract": "native-road-package/v1",
"areaId": "fengshu-er-road",
"layers": [
{ "source": "road_surface", "role": "surface",
"materialLayer": "road_surface" },
{ "source": "lane_centerlines", "role": "semantic" },
{ "source": "connectors", "role": "semantic" },
{ "source": "center_lines", "role": "marking",
"materialLayer": "center_lines",
"splitBy": { "prop": "color",
"cases": [ { "match": "white", "material": "native_center_line_white" },
{ "default": true, "material": "center_lines" } ] } },
{ "source": "lane_separators", "role": "marking",
"materialLayer": "lane_separators",
"splitBy": { "prop": "color",
"cases": [ { "match": "yellow", "material": "native_lane_separator_yellow" },
{ "default": true, "material": "lane_separators" } ] } }
]
}
```
- `role: "semantic"` 的图层 Blender 直接跳过 —— 把"不渲染"从省略变成显式声明。
- `splitBy` 表达当前 `generate_scene.py:815-819` 里硬编码的
`color != "white"` / `color == "yellow"` 分流逻辑。
- 材质本体(颜色、z 高度、贴图)仍归宿主 `catalog.py::MATERIALS` —— 编译器不懂渲染。
编译器只声明"我有这些图层、它们是什么角色、该用哪个材质槽"。
### 3.3 Blender 侧改造
- `generate_scene.py` 内道路分支抽为 `blender/osmassets/native_roads.py`,读 manifest 遍历。
- 建筑(`handle_building` / `dispatch_ways`)、植被、水体保持原位不动。
- `catalog.NATIVE_ROAD_LAYERS` 删除。
### 3.4 AC5 的验证方法
向编译器加一个 throwaway 图层(例如 `debug_probe.geojson` + manifest 声明),
不改宿主任何代码,跑 blender 阶段,确认它被渲染出来。验证完回滚该图层。
---
## 4. 决策记录
### D1 不用 drawtonomy 替代编译器 ❌
评估结论(2026-08-25):
- 克隆仓库内**没有编辑器本体**。`packages/` 只有 SDK / dev-server / mcp-server;
白板闭源,托管在 drawtonomy.com。README 卖点里的 topology-aware lanes、
lane tool、intersection/roundabout templates、Map→lanes **全部不在开源代码内**。
- **它完全不做 raw OSM 推导**。`exporter/osmParser.ts` 首行自陈是
"Lanelet2 OSM (.osm XML) parser" —— 读的是 Lanelet2(车道左右边界已显式)。
整个 `exporter/` 目录 grep `highway` 命中 1 次,是 `opendrive.ts:685` 的
车道类型字符串,不是 OSM 标签解析。从不读 `highway=*` / `lanes` / `turn:lanes`。
- 本编译器的核心能力恰是"从稀疏有歧义的中国 OSM 标签推导车道几何",方向垂直。
- 语义成熟度对比:本编译器有逐值 provenance
(`tag:lanes:forward` / `inferred:highway-default` / `override:<id>`)+ 31 条语义诊断规则;
drawtonomy SDK 两者皆无,其 25 条校验规则全是 OpenDRIVE 结构/XML 完整性检查。
### D2 drawtonomy 作为**下游后端 + 编辑器**(后续独立 PoC)✅
可用能力(扩展 API,`types.ts:257` 8 个 capability):
`shapes:write` + `ui:panel` 足以把编译产物注入编辑器;
`snapshot:read` 回读后由本地跑其开源 `exportToOpenDrive` / `lanelet2`。
不可用能力(决定 junctionTools 不能做成扩展):
- 无 canvas / overlay 能力,UI 只能是侧栏 iframe
- 无工具注册,画布指针事件完全归宿主
- **无任何 change 事件推送** —— `ExtensionClient.handleMessage` 入站只有
`ext:init` / 按 requestId 匹配的 5 个 `*-response` / `ext:error`,所有读取靠轮询
结论:junctionTools 留在自有 workbench(画布自己的,可任意绘制)。
drawtonomy 承担场景编排 + 工业格式导出。二者是不同的活,不强行合并 UI。
依赖风险记录:`drawtonomy-dev-server` 是 `https://www.drawtonomy.com` 的
**缓存代理**(TTL 1 小时),非自托管。manifest 有 `minHostVersion` 字段,
说明宿主协议会漂。后续 PoC 不把它放进关键路径。
### D3 值得从 drawtonomy 借用的(Apache-2.0,需保留 NOTICE/署名)
| 来源 | 行数 | 用途 | 建议阶段 |
|---|---|---|---|
| `exporter/odrGeometryFit.ts` | 610 | 折线→解析曲线拟合(中位数去噪 + 贪心生长 + 最简原语优先 + 逐拟合回验 + G1 硬不变量)。可替掉手调的 `approachWidthMultiplier=1.45` / `coreRadiusMeters=28`,改为对 `referenceFile` 拟合、残差作质量指标 | 拆分后独立任务 |
| validator 的 mutation-proven 方法 | — | 故意破坏合法输入、断言校验器必须抓到。本编译器 31 条诊断规则目前无任何触发证明 | 拆分后独立任务,成本低 |
| validator 的分层 + 命名空间(`xml.*` → `ref.*` → `junction.*` → `geom.*`) | — | 替代当前 31 条平铺规则 | 同上 |
| OpenDRIVE + Lanelet2 导出器 | 3059 + 869 | 补齐工业格式输出(Lanelet2 是 Autoware 的输入格式) | 后续独立 PoC |
### D4 为什么 Phase 1 与 Phase 2 必须分开
Phase 1 只改"包边界与入口契约",仓库不变 → 若产物变化,成因必在代码改动。
Phase 2 只改"仓库位置与消费方式",代码不变 → 若产物变化,成因必在搬迁。
合并执行则两者混淆,parity oracle 失去诊断价值。
### D5 IR 重构推迟到拆分之后
见 prd.md C1。拆分的正确性完全建立在"产物逐字节不变"上,
同期改 IR 会同时摧毁 oracle 与归因能力。
---
## 5. 回滚形状
| Phase | 回滚方式 |
|---|---|
| 0 | 无代码改动,仅新增文档与基线,无需回滚 |
| 1 | `git revert`;`packages/road-compiler/` 与旧 `scripts/lib/*` 并存过渡期内可切回旧路径 |
| 2 | 宿主依赖回指本仓库内路径(`file:packages/road-compiler`),编译器仓库保留不动 |
| 3 | Blender 侧恢复 `catalog.NATIVE_ROAD_LAYERS`,manifest 保留但不消费 |
@@ -0,0 +1 @@
{"_example": "Fill with {\"file\": \"<path>\", \"reason\": \"<why>\"}. Put spec/research files only — no code paths. Run `python3 .trellis/scripts/get_context.py --mode packages` to list available specs. Delete this line once real entries are added."}
@@ -0,0 +1,139 @@
# 道路编译器独立化(parent)
## Goal
把 native road compiler 从本仓库拆成可独立维护的项目,与本项目通过**版本化文件契约**相辅相成;
同时把道路渲染与 OSM 建筑渲染分离,使二者可各自演进。
本任务是 parent:它拥有源需求、契约定义、子任务地图、跨子任务验收标准和最终集成评审。
**它自身不承担实现工作**,所有可交付物在子任务中完成。
## 背景:为什么现在拆
- `scripts/lib/native-road.js` 已 1695 行,`compileGeometry()` 单函数编排 15+ 个 pass,
顺序依赖只由行号编码,每加一个特性就往既有函数尾部挂位置参数
(`compileLaneMarkings` 已 7 个位置参数)。
- 道路与建筑渲染纠缠在 `blender/generate_scene.py` 一个脚本内,
道路图层表 `NATIVE_ROAD_LAYERS` 硬编码在 `blender/osmassets/catalog.py:53`。
- 道路编译的迭代节奏(几何、路口、标线、V2X 语义)与建筑/植被/水体渲染完全不同,
放在一个仓库里互相牵制。
拆分的可行性前提(已核实):
- `native-road.js` 只 require `fs` / `path` / 两个同族道路模块,**对宿主项目零耦合**。
- 对宿主的唯一耦合是三个 CLI 入口里的 `readAreaConfig`。
- 输出侧 `native-road/` **已经是文件契约**,`blender/generate_scene.py:801` 按图层名读取。
- stdout 标记 `NATIVE_ROAD_COMPILE_DONE` 已存在,与 `SCENE_DONE` / `CESIUM_EXPORT_DONE`
同一约定 —— 子进程边界事实上已预留。
## Requirements
### R1 契约先行
- R1.1 输入输出契约必须在任何代码移动之前写死并版本化为 `native-road-package/v1`,
命名对齐既有 `osm-asset-package/v1` 约定。
- R1.2 契约的权威定义见本任务 `design.md`;Phase 0 负责把它落成仓库内文档 + 校验脚本。
### R2 可证明的等价性
- R2.1 拆分过程中每一步都必须对两个有效区域
(`fengshu-er-road` / `nantaizi-lake-innovation-valley`)
验证产物与基线一致。
- R2.2 任何差异必须逐条书面解释后才可接受,禁止"看起来差不多"。
- R2.3 验证方法沿用既有 `.trellis/spec/guides/artifact-parity-guide.md`。
### R3 独立可维护
- R3.1 拆出的项目必须能脱离宿主自测(自带 fixture,不读宿主 `inputs/` 或 `outputs/`)。
- R3.2 保留 git 历史(`git subtree split` 或 `git filter-repo`)——
1695 行几何逻辑的 blame 是踩坑记录,丢失后无人敢改。
- R3.3 编译器不得反向依赖宿主任何模块、配置或目录布局。
### R4 相辅相成(防漂移)
四个机制缺一不可:
| 机制 | 作用 | 落地于 |
|---|---|---|
| `native-road-package/v1` 版本号 | 破坏性变更必须升版本,宿主主动 opt-in | Phase 0 |
| 编译器自声明图层(layer manifest) | 加图层不需要改宿主代码 | Phase 3 |
| 两区域 parity 基线留在编译器仓库当测试语料 | 编译器无法静默弄坏宿主 | Phase 0 → Phase 2 |
| 宿主锁版本依赖,不用 `latest` | 升级是决定,不是意外 | Phase 2 |
### R5 渲染分离
- R5.1 道路图层表必须从宿主 `catalog.py` 的硬编码变为编译器输出的 manifest。
- R5.2 `blender/generate_scene.py` 内道路渲染分支抽离为独立模块;
建筑 / 植被 / 水体保持原位。
- R5.3 分离后,编译器新增图层不需要修改宿主任何代码即可被渲染。
## Constraints(硬约束)
### C1 不得在拆分过程中重构 IR 🔴
lane graph 提为一等 IR 是正确方向,但**必须在 Phase 2 完成之后作为独立任务**。
理由:拆分的正确性完全依赖"产物逐字节不变"这一 oracle。
一旦同时改 IR,oracle 失效,且无法判断产物变化来自搬迁还是重设计。
未来若做,形式是**新增输出**而非替换 `compiled.json`,
靠"解锁 drawtonomy / OpenDRIVE / Lanelet2 导出"赚取存在理由。
### C2 拆分期不引入构建步骤
编译器保持 CommonJS、无构建步骤,与宿主 pipeline 层运行时一致
(见 `.trellis/spec/pipeline/index.md`)。
TypeScript / ESM 是独立决策;若后续 drawtonomy PoC 需要 SDK 互操作,只能在其独立任务的扩展目录内处理。
### C3 Phase 1 必须先于 Phase 2
"包边界"与"换仓库"分两步做。合并执行时若产物变化,无法区分成因。
## 子任务地图
| Phase | 子任务 | 交付物 | 阻塞后续 |
|---|---|---|---|
| 0 | `08-25-rc-p0-contract-baseline` | 契约文档 + 两区域 checksum 基线 + 校验脚本 | 是 |
| 1 | `08-25-rc-p1-package-boundary` | 本仓库内 `packages/road-compiler/`,窄输入契约 | 是 |
| 2 | `08-25-rc-p2-repo-split` | 独立仓库 + 宿主锁版本消费 | 是 |
| 3 | `08-25-rc-p3-render-separation` | layer manifest + Blender 道路模块抽离 | 否 |
顺序约束:**0 → 1 → 2 必须串行**。3 依赖 2 完成。
## 跨子任务验收标准
- [ ] AC1 Phase 0 基线建立后,两区域每个输出文件的 checksum 已提交进版本控制
- [ ] AC2 Phase 1 结束时,`npm run build:area` 两区域产物对 AC1 基线逐字节一致
- [ ] AC3 Phase 2 结束时,宿主从打包依赖构建,两区域 parity 仍成立
- [ ] AC4 Phase 2 结束时,编译器仓库 `npm test` 在不访问宿主仓库的情况下通过
- [ ] AC5 Phase 3 结束时,向编译器新增一个图层,宿主**零代码改动**即可渲染出来(实测验证)
- [ ] AC6 Phase 3 结束时,`.blend` 结构摘要对基线一致(走 artifact-parity-guide)
- [ ] AC7 全程未修改 `compiled.json` 的结构(C1 未被违反)
- [ ] AC8 编译器仓库对宿主的反向依赖数为 0(grep 验证)
## 已识别风险(跨子任务,逐个必须有归属)
| # | 风险 | 归属 Phase | 处置 |
|---|---|---|---|
| K1 | `lib/traffic-signals.js` 是真共用模块:`reimport-gpkg.js` / `build-osm2streets-qgis.js` / `build-area.js` / `test-preview-assets.js` 都在用,而 `native-traffic-signals.js` 也依赖它 | 1 | 需细读后拆分:信号文档 schema + OSM 信号节点提取随编译器走(编译器生成它就该拥有契约),legacy QGIS/预览读取器留宿主。**全案唯一需要细读再动的地方** |
| K2 | `comparison.json` 依赖宿主产物 —— `compile-native-roads.js:87` 读 `area.outputs.geojsonDir` 里 osm2streets 输出做对比,拆出后摸不到 | 0(决策)/ 1(执行) | osm2streets 已 legacy,倾向直接砍掉,用高德参考 + 规范校验取代。决策需在 Phase 0 定档 |
| K3 | config 内绝对路径指向宿主仓库:`config/areas/fengshu-er-road.json` 的 `referenceFile: "/Users/que01/osm2streets-qgis-workflow/inputs/osm/珠山湖大道(枫树二路)口.geojson"` | 1 | 需定参考文件解析约定(相对 config 目录 / 显式 basePath) |
| K4 | workbench 的 OpenLayers 来自宿主 `node_modules`(design.md 的 import map 方案) | 2 | 新仓库自带依赖 |
| K5 | 测试 fixture 依赖宿主:`test-native-road.js:167` 读 `inputs/osm/枫树二路.osm`,其余为内联合成 OSM | 1 | 该文件(或裁剪版)作为测试数据提交进编译器仓库 |
## Out of Scope
- lane graph IR 重构(见 C1,未来独立任务)
- pass manager / 显式依赖声明重构(同上,属编译器内部演进,不属本次拆分)
- 替换编译器为 drawtonomy 或 osm2streets —— 已评估否决:
drawtonomy 开源部分只读 Lanelet2(显式车道边界),不做 OSM `highway=*` 推导,
与本编译器的核心能力方向垂直
- osm2streets / QGIS legacy 链路的任何改动
- 宿主侧建筑 / 植被 / 水体渲染逻辑的改动(Phase 3 只抽离道路部分)
## Notes
- 评估结论与选型依据见 `design.md` 的「决策记录」一节。
- 时间估计:Phase 0-2 约 3 天(搬家 + 证明没搬坏),Phase 3 约 1-2 天。
拿到"道路与建筑渲染分离、可独立维护"是在 Phase 3 结束。
- 父任务验收完成后,下一项候选任务是独立的
`08-25-rc-p4-drawtonomy-ext`(drawtonomy 扩展 PoC);它不属于本任务完成条件。
@@ -0,0 +1,34 @@
{
"id": "road-compiler-extraction",
"name": "road-compiler-extraction",
"title": "道路编译器独立化(parent)",
"description": "把 native road compiler 拆成可独立维护的项目,并与本项目通过版本化契约相辅相成;同时分离道路与 OSM 建筑渲染",
"status": "planning",
"dev_type": null,
"scope": null,
"package": null,
"priority": "P1",
"creator": "dingkang",
"assignee": "dingkang",
"createdAt": "2026-08-25",
"completedAt": null,
"branch": null,
"base_branch": "main",
"worktree_path": null,
"commit": null,
"pr_url": null,
"subtasks": [],
"children": [
"08-25-rc-p0-contract-baseline",
"08-25-rc-p1-package-boundary",
"08-25-rc-p2-repo-split",
"08-25-rc-p3-render-separation",
"08-26-rc-p5-artifact-consumption"
],
"parent": null,
"relatedFiles": [],
"notes": "P3 已完成。P5 artifact-only parent 已建立,P5A ZIP export 已在 road-compiler v0.3.0 完成;P5B 宿主 ZIP import 待实施。",
"meta": {
"next_task": "08-25-rc-p4-drawtonomy-ext"
}
}
@@ -0,0 +1,3 @@
{"file":".trellis/spec/blender/testing.md","reason":"P3 scene digest parity 是消费迁移的回归门槛。"}
{"file":".trellis/spec/pipeline/native-road-package.md","reason":"验证 ZIP 解压后的 v1.1 contract、areaId 和 source 集合。"}
{"file":".trellis/spec/guides/artifact-parity-guide.md","reason":"验证导入迁移不改变 Blender 产物结构。"}
@@ -0,0 +1,23 @@
# P5 Artifact-Only Road Package Design
P5 replaces the current runtime dependency boundary with a file-only boundary:
```text
road-compiler Web editor
-> deterministic root-flat native-road-package/v1.1 ZIP
-> osmWorkflow config nativeRoadPackage
-> private verified extraction cache
-> Blender / Cesium / preview
```
The road-compiler repository owns export and all editing/compiler internals. osmWorkflow owns ZIP safety,
contract validation, Blender materials and downstream scene construction. Neither repository reads the
other's source, configuration, overrides or runtime implementation.
The ZIP is immutable input and the host's `_pipeline/native-road-import/<sha256>` is disposable cache.
The host rejects unsafe archive topology before writing files, then validates v1.1 `manifest.json` and
area identity before starting Blender. Stage manifests record the ZIP hash and resolved package records.
P5A publishes a fixture/exporter first. P5B uses that fixture to remove compiler CLI installation and
invocation from the host. The migration is intentionally a contract-preserving transport change: rendered
geometry and material behavior must remain at the P3 baseline.
@@ -0,0 +1,3 @@
{"file":".trellis/spec/pipeline/native-road-package.md","reason":"宿主与编译器之间的现有文件契约。"}
{"file":".trellis/spec/pipeline/external-tools.md","reason":"ZIP 导入必须在 Blender 副作用前完成安全校验。"}
{"file":".trellis/spec/guides/cross-layer-thinking-guide.md","reason":"导出、Node 导入、Blender 和 preview 的跨层数据流。"}
@@ -0,0 +1,14 @@
# P5 Integration Plan
1. Complete P5A in `road-compiler`: deterministic Web/CLI ZIP export plus supported-area fixtures and a
tagged compiler release.
2. Complete P5B in `osmWorkflow`: safe importer, config migration, CLI/dependency removal and downstream
descriptor migration.
3. Run the shared end-to-end gate on `fengshu-er-road` and `nantaizi-lake-innovation-valley`:
import ZIP -> Blender -> Cesium -> package -> preview -> area checks.
4. Compare Blender scene digests to P3 control; run negative ZIP tests and legacy provider tests.
5. Record contract docs in both repositories, commit each repository independently, then archive both
children and this integration parent.
Integration rollback: restore the host's previous tagged compiler dependency and compile adapter. ZIP export
is additive and its generated files remain valid standalone artifacts.
@@ -0,0 +1,95 @@
# 道路包导入与纯消费管线
父任务:`.trellis/tasks/08-25-road-compiler-extraction/`
本任务是集成 parent:导出与导入分别在 road-compiler 和宿主仓库实现,只有两个子任务的
端到端 ZIP 契约都通过后才完成。
## Goal
让 road-compiler Web 导出的 `native-road-package/v1.1` 成为 Blender 管线的唯一
native-road 输入。宿主只校验并消费完整道路包,不再安装、调用或理解道路编译器。
用户价值:人工在 road-compiler Web 编辑后,导出道路包即可稳定交给 Blender / Cesium
构建;编辑成果不再通过发布新的编译器代码版本传播。
## Confirmed Facts
- P3 已使 Blender 通过 `manifest.json` 消费 `layers/*.geojson`,并拒绝无效 manifest、
source/file 不一致和未知宿主材质槽。
- 宿主当前仍通过 `scripts/build-area.js` 调用 `scripts/lib/road-compiler-cli.js`;后者安装并
运行 `@osm-asset/road-compiler`,将 `RoadCompilerInput` 写入 `_pipeline/`。
- native Blender 构建当前强制使用 `outputs/<area>/native-road/`,并在每次构建前重新编译;
宿主还持有 `nativeRoad.edgeLines`、`junctionTemplates`、overrides 和 compiler runtime
路径等编译器内部概念。
- `osm2streets` 是显式 legacy/debug provider,应保持现有行为。
- 有效验证区域只有 `fengshu-er-road` 与 `nantaizi-lake-innovation-valley`;
`hanyang-block` 不参与。
## Requirements
### R1 纯产物边界
- native provider 只接收一个完整 `native-road-package/v1.1` 目录。
- 宿主不得依赖 `@osm-asset/road-compiler`,不得调用 compiler CLI,不得写
`RoadCompilerInput`,不得读取或解释 compiler overrides / junction templates。
- 宿主以 manifest 作为道路图层事实源,Blender 不增加 compiler 专用图层表。
### R2 ZIP 导入配置和校验
- 每个 native 区域配置一个道路包 ZIP 路径;路径相对于区域配置文件解析并可指向工作区外的
road-compiler Web 导出文件。
- ZIP 根目录必须直接包含 `manifest.json` 和契约定义的文件;不得接受多余顶层目录、绝对路径、
`..` 路径或符号链接。
- 在启动 Blender 前,宿主将 ZIP 安全解压到其私有 pipeline staging 目录,校验 manifest
契约版本、`areaId` 和当前区域一致,并记录 ZIP hash 和展开文件记录到 stage manifest。
- ZIP 永远只读:宿主不复制、覆盖或修改 road-compiler Web 的导出文件;成功或失败后仅清理
自己的临时解压目录。
- Blender 继续校验 manifest 的图层、source、semantic 角色、材质槽和 splitBy 规则。
### R3 后续阶段
- Cesium、package、preview 和区域诊断从导入道路包读取原生车道中心线、signals 和
其他既有 native-road 输入;不重新编译或复制道路包。
- build stage manifest 将道路包作为外部输入记录,而非宿主输出。
### R4 清理和迁移
- 删除宿主对 compiler npm 包、CLI 封装和编译脚本的生产依赖。
- 删除或替换只测试宿主编译行为的测试;保留 package-contract、Blender 和下游消费测试。
- 更新示例配置、README、pipeline spec 和道路包契约,明确 Web export -> host consume
的单向关系。
## Acceptance Criteria
- [ ] AC1 `package.json` / lockfile 和生产脚本不再引用 `@osm-asset/road-compiler` 或其 CLI。
- [ ] AC2 两个有效区域均可从配置指定的已导出 ZIP 道路包运行 Blender、Cesium、package 和 preview,
构建期间没有 compiler 子进程。
- [ ] AC3 宿主在 Blender 前拒绝缺失包、错误 contract、错误 areaId 和无效 manifest;错误说明
指向导入包和契约,而非 compiler 内部。
- [ ] AC4 Blender scene digest 与 P3 control 基线一致;native semantic 层仍不生成几何。
- [ ] AC5 stage manifest / diagnose / check area 将导入道路包记录为输入并能识别缺失或变更。
- [ ] AC6 `osm2streets` legacy provider 行为未变。
- [ ] AC7 文档和配置将人工编辑传播路径表述为 road-compiler Web export -> host consume。
## Out of Scope
- road-compiler Web 的编辑器功能、认证、部署或 UI 改造。
- 修改道路几何、材质、Blender 建筑/植被/水体渲染。
- 新的 manifest 破坏性版本或 lane graph IR。
- 将道路包上传到远程制品库或实现同步服务。
## Key Decision
- Web 导出的是标准 ZIP;宿主配置直接指向 ZIP 而不是目录。ZIP 是跨仓库的不可变交付物,
宿主只在私有 staging 目录中解压和消费,因而没有导出目录 ownership 或覆盖歧义。
## Subtask Map
| 子任务 | 仓库 | 交付物 | 依赖 |
|---|---|---|---|
| `rc-p5a-zip-export` | road-compiler | Web / CLI 可导出的 root-flat `native-road-package/v1.1` ZIP | 无 |
| `rc-p5b-zip-import` | osmWorkflow | 配置、受控解压、校验和纯消费管线 | p5a 的 ZIP fixture |
跨任务验收:同一个 ZIP fixture 必须被 p5b 的两个有效区域构建消费;宿主不得保留
compiler npm 或 CLI 耦合。
@@ -0,0 +1,29 @@
{
"id": "rc-p5-artifact-consumption",
"name": "rc-p5-artifact-consumption",
"title": "道路包导入与纯消费管线",
"description": "让宿主通过配置指向 road-compiler Web 导出的 ZIP 道路包,只校验和消费该版本化文件契约,不再安装或调用编译器。",
"status": "planning",
"dev_type": null,
"scope": null,
"package": null,
"priority": "P2",
"creator": "dingkang",
"assignee": "dingkang",
"createdAt": "2026-08-26",
"completedAt": null,
"branch": null,
"base_branch": "experiment/road-compiler-rethink",
"worktree_path": null,
"commit": null,
"pr_url": null,
"subtasks": [],
"children": [
"08-26-rc-p5b-zip-import",
"08-26-rc-p5a-zip-export"
],
"parent": "08-25-road-compiler-extraction",
"relatedFiles": [],
"notes": "",
"meta": {}
}
@@ -0,0 +1 @@
{"_example": "Fill with {\"file\": \"<path>\", \"reason\": \"<why>\"}. Put spec/research files only — no code paths. Run `python3 .trellis/scripts/get_context.py --mode packages` to list available specs. Delete this line once real entries are added."}
@@ -0,0 +1,22 @@
# P5A ZIP Export Design
The compiler owns a pure `exportNativeRoadPackage(result, destination)` function. It writes a
temporary root-flat directory from the already compiled Web/CLI state, validates it with the same
manifest/source validator used by compiler output, then writes a deterministic ZIP. The Web download
handler and CLI are thin callers of this function.
ZIP layout:
```text
manifest.json
compiled.json
diagnostics.json
comparison.json
traffic-signal-assemblies.json
traffic-signals.json
layers/<12 declared sources>.geojson
```
`manifest.generator` is informational only. The host accepts solely the `contract`, `areaId`, and
declared files. ZIP creation normalizes entry order and timestamps so the export is hash-stable.
Failure never replaces a chosen output file.
@@ -0,0 +1 @@
{"_example": "Fill with {\"file\": \"<path>\", \"reason\": \"<why>\"}. Put spec/research files only — no code paths. Run `python3 .trellis/scripts/get_context.py --mode packages` to list available specs. Delete this line once real entries are added."}
@@ -0,0 +1,10 @@
# P5A Execution Plan
1. Inspect workbench state ownership and compiler output writer; keep export sourced from the current
compiled state, not host paths.
2. Add deterministic root-flat ZIP writer plus validation and CLI entry point.
3. Add Web download action using the same writer.
4. Add fixtures for root layout, content determinism, manifest/source parity and edited-state export.
5. Export both supported-area fixtures for P5B, run compiler tests, then publish a compiler release.
Rollback: remove the export entry point; no host behavior changes in this subtask.
@@ -0,0 +1,34 @@
# Web 导出原生道路 ZIP 包
## Goal
让 road-compiler Web/CLI 以 root-flat native-road-package/v1.1 ZIP 导出人工编辑后的道路包。
## Requirements
- 从 Web 当前编辑状态导出完整道路包,而不是源代码、npm 包或仅 overrides。
- ZIP 根直接包含 `manifest.json`,并包含全部 manifest 声明的 `layers/<source>.geojson`、
`compiled.json`、`traffic-signals.json` 和 preview 所需的 signal / diagnostics 文档。
- `manifest.json` 的 `contract` 保持 `native-road-package/v1.1`;新增可选 `generator` 元数据
记录应用版本和 revision,但不得让宿主依赖该版本。
- Web 提供用户可见的下载操作;CLI 提供等价、可测试的 ZIP 导出入口。
- ZIP 条目顺序、JSON 序列化和压缩时间戳必须确定性,重复导出未编辑内容的文件 hash 一致。
## Acceptance Criteria
- [x] 从 Web 编辑后的区域可下载一个 root-flat ZIP,且无需宿主或 npm 发布。
- [x] CLI fixture 导出 ZIP 后,解压内容通过 compiler 的 `validatePublishedLayers()`。
- [x] ZIP 具有恰好一份 manifest 声明的 layer source,无额外 compiler source / overrides 文件。
- [ ] 两个有效区域导出的 ZIP 可被 p5b 导入并完成 Blender/Cesium/preview 构建。
- [x] 不修改 `compiled.json` 与 v1.1 manifest 的既有渲染语义。
## Out of Scope
- 远程存储、上传、项目历史或多用户协作。
- 修改道路编辑器交互、几何算法或 manifest 主版本。
## Key Decisions
- ZIP 是单个标准交付物,根目录平铺 package 文件,不包裹 area-id 顶层目录。
- ZIP 面向宿主消费,只携带已编译渲染/预览数据;编辑源、OSM 与 overrides 留在 road-compiler
项目中,不泄露为宿主依赖。
@@ -0,0 +1,26 @@
{
"id": "rc-p5a-zip-export",
"name": "rc-p5a-zip-export",
"title": "Web 导出原生道路 ZIP 包",
"description": "让 road-compiler Web/CLI 以 root-flat native-road-package/v1.1 ZIP 导出人工编辑后的道路包。",
"status": "in_progress",
"dev_type": null,
"scope": null,
"package": null,
"priority": "P2",
"creator": "dingkang",
"assignee": "dingkang",
"createdAt": "2026-08-26",
"completedAt": null,
"branch": null,
"base_branch": "experiment/road-compiler-rethink",
"worktree_path": null,
"commit": null,
"pr_url": null,
"subtasks": [],
"children": [],
"parent": "08-26-rc-p5-artifact-consumption",
"relatedFiles": [],
"notes": "",
"meta": {}
}
@@ -0,0 +1 @@
{"_example": "Fill with {\"file\": \"<path>\", \"reason\": \"<why>\"}. Put spec/research files only — no code paths. Run `python3 .trellis/scripts/get_context.py --mode packages` to list available specs. Delete this line once real entries are added."}
@@ -0,0 +1,19 @@
# P5B ZIP Import Design
`scripts/lib/native-road-package.js` becomes the single host adapter. It resolves the config-relative
ZIP path, hashes it, validates central-directory entry names and metadata, and extracts only accepted
regular files to `_pipeline/native-road-import/<sha256>/`. It validates the unpacked manifest and
returns an immutable package descriptor:
```text
{ zipFile, zipRecord, rootDir, manifest, records }
```
The descriptor replaces `area.outputs.nativeRoadDir` as native input for Blender, native preview traffic,
diagnostics and stage manifests. The configured ZIP and unpacked cache are inputs, never published area
outputs. Cache invalidation is by ZIP SHA-256; cleanup only deletes importer-owned hash directories.
The importer rejects any non-root-flat layout, duplicate path, symlink, unsupported compression/error,
path traversal, invalid manifest, area mismatch or declared/published mismatch before Blender starts.
The native compiler CLI dependency and host-owned `nativeRoad` compilation options are removed. Legacy
`osm2streets` remains an explicit separate provider.
@@ -0,0 +1 @@
{"_example": "Fill with {\"file\": \"<path>\", \"reason\": \"<why>\"}. Put spec/research files only — no code paths. Run `python3 .trellis/scripts/get_context.py --mode packages` to list available specs. Delete this line once real entries are added."}
@@ -0,0 +1,12 @@
# P5B Execution Plan
1. Add config normalization for `nativeRoadPackage`, migrate two supported configs and the template.
2. Add the tested ZIP importer with bounded extraction, root-flat/path/symlink validation, SHA cache and
manifest/area validation.
3. Route Blender, preview traffic, stage manifests and diagnostics through the imported descriptor.
4. Delete compiler CLI/compile production paths and package dependency; replace their tests with ZIP fixture
and negative importer tests.
5. Update docs/specs, run native/legacy unit suites, build two exported packages, then run Blender parity.
Rollback: restore the old compiler dependency and native compile path in one revert; ZIP exports remain
non-destructive standalone files.
@@ -0,0 +1,40 @@
# ZIP 道路包安全导入与纯消费
## Goal
让 osmWorkflow 配置、校验、解压并消费 road-compiler Web 导出的 ZIP 道路包,移除 compiler runtime 耦合。
## Requirements
- 区域配置以 `nativeRoadPackage` 指向 ZIP,路径相对于该区域配置文件;native provider 不再
接受 compiler options、overrides 或输出目录作为输入。
- 宿主在任何 Blender / Cesium 副作用前,验证 ZIP 文件、条目数量/大小、root-flat 文件路径、
无重复路径、无符号链接、无绝对路径与 `..` 路径。
- 仅将已验证的文件解压至 `<area>/_pipeline/native-road-import/<zip-sha256>/`;解压目录是宿主
私有缓存,绝不写回 ZIP 或 road-compiler 导出目录。
- 共享 importer 为 Blender、preview traffic、diagnose/check 和 stage manifest 提供同一包路径与
文件记录;不能让下游自行按字符串拼接另一份 native-road 目录。
- 移除 compiler package、CLI wrapper、compile script、编译器输入配置、以及只覆盖旧调用链的测试。
## Acceptance Criteria
- [ ] 两个有效区域均从 ZIP 完成 `blender,cesium,package,preview`,构建日志没有 compiler CLI。
- [ ] 缺 ZIP、错误 ZIP、nested root、path traversal、symbolic link、错误 contract、错误 areaId 和
manifest/source 不匹配均在启动 Blender 前失败。
- [ ] stage manifest、`diagnose:area` 与 `check:area` 记录 ZIP hash 和已验证的导入目录;ZIP
修改后会被判 stale。
- [ ] `package.json`、lockfile、生产脚本与宿主测试不再引用 `@osm-asset/road-compiler`。
- [ ] Blender digest 对 P3 control 基线一致;legacy `osm2streets` 路径的单元测试不变。
## Out of Scope
- p5a 的 ZIP 生成与 Web 下载实现。
- ZIP 远程下载、解密、签名验证或制品库管理。
- 改道路内容、材质或 legacy QGIS 行为。
## Key Decisions
- ZIP 是只读输入;宿主缓存的生命周期和目录 ownership 完全属于 `_pipeline/`。
- ZIP 解码由明确声明的 Node ZIP 库完成,而不是依赖系统 `unzip`;这使路径/符号链接校验可控并
可在单元测试中覆盖。
- 只有 `native-road-package/v1.1` 可被导入;契约升级必须另开兼容任务。
@@ -0,0 +1,26 @@
{
"id": "rc-p5b-zip-import",
"name": "rc-p5b-zip-import",
"title": "ZIP 道路包安全导入与纯消费",
"description": "让 osmWorkflow 配置、校验、解压并消费 road-compiler Web 导出的 ZIP 道路包,移除 compiler runtime 耦合。",
"status": "in_progress",
"dev_type": null,
"scope": null,
"package": null,
"priority": "P2",
"creator": "dingkang",
"assignee": "dingkang",
"createdAt": "2026-08-26",
"completedAt": null,
"branch": null,
"base_branch": "experiment/road-compiler-rethink",
"worktree_path": null,
"commit": null,
"pr_url": null,
"subtasks": [],
"children": [],
"parent": "08-26-rc-p5-artifact-consumption",
"relatedFiles": [],
"notes": "",
"meta": {}
}
@@ -0,0 +1 @@
{"_example": "Fill with {\"file\": \"<path>\", \"reason\": \"<why>\"}. Put spec/research files only — no code paths. Run `python3 .trellis/scripts/get_context.py --mode packages` to list available specs. Delete this line once real entries are added."}
@@ -0,0 +1,81 @@
# Phase 0 技术设计
契约本体见父任务 `design.md` §1,本文件只补 Phase 0 自身的实现设计。
## 1. 确定性核查的具体做法
编译器的潜在非确定性来源,按可疑度排序:
| 来源 | 表现 | 处置 |
|---|---|---|
| `fs.mkdtempSync(path.join(pipelineDir, "native-road-"))` | staging 目录名随机 | 若名字出现在 `compiled.json` 的 `source` 字段里,需归一化 |
| `compiled.json` 内的绝对路径 | `source.osm` / `source.overrides` / `source.trafficSignals` 是绝对路径 | 归一化为相对 repo root |
| 时间戳 | 未确认是否存在 | 核查 `compile-native-roads.js` 写入的 metadata |
| `Map` / `Set` 迭代顺序 | JS 保证插入序,若插入源本身有序则确定 | 观测两次运行 `orderHash` 是否一致即可暴露 |
| 浮点累加顺序 | 几何坐标末位抖动 | 若出现,说明存在顺序依赖,属真 bug,需修 |
| `crypto` 随机(`traffic-signals.js` require 了 `crypto`) | 信号 ID 可能含随机成分 | 重点核查 —— `native-traffic-signals.json` 是 `loadOrGenerate`,已存在则复用,首次生成可能不确定 |
**核查顺序**:
1. 备份两个有效区域的 `native-road/` 与 `native-traffic-signals.json`
2. 删除 `native-road/`(保留 signals,因为 `loadOrGenerate` 语义是已存在则复用)
3. 跑第一次 → snapshot A
4. 再删 `native-road/`,跑第二次 → snapshot B
5. diff A/B → volatile 字段清单
6. 额外一轮:删掉 signals 文件也重生成一次,确认 signal ID 是否确定
## 2. `scripts/road-parity.js` 设计
```
用法:
node scripts/road-parity.js --config <area-config> --snapshot <out.json>
node scripts/road-parity.js --config <area-config> --compare <baseline.json>
```
### 归一化规则(写死在脚本里,并回写进契约文档)
1. **路径**:任何绝对路径 → 相对 repo root;staging 目录名 → 字面量 `<staging>`
2. **JSON**:递归按 key 排序后 `JSON.stringify`,再 hash
3. **GeoJSON**:
- `contentHash` = features 按 `properties.native_id`(缺失则按几何首坐标)排序后 hash
- `orderHash` = 原序 hash
- 两者都记录;比对时 `contentHash` 不一致 = 语义变化(严重),
仅 `orderHash` 不一致 = 顺序抖动(需解释但可能可接受)
4. **浮点**:不做舍入。坐标变化就是变化,不允许用容差掩盖
(拆分是纯搬迁,任何坐标位移都是 bug)
### 输出形状
```json
{
"contract": "native-road-package/v1",
"areaId": "fengshu-er-road",
"files": {
"compiled.json": { "contentHash": "…", "bytes": 12345 },
"diagnostics.json": { "contentHash": "…", "bytes": 678, "count": 42 },
"layers/road_surface.geojson": {
"contentHash": "…", "orderHash": "…", "features": 128 }
},
"volatileExcluded": ["source.osm", "source.overrides", "<staging>"]
}
```
`count` / `features` 是冗余的人类可读字段 —— hash 变了但计数没变,
说明是内容变化;计数也变了,说明是增删。加速归因。
## 3. 基线目录布局
```
.trellis/tasks/08-25-road-compiler-extraction/baseline/
fengshu-er-road.json
nantaizi-lake-innovation-valley.json
README.md ← 记录生成时的 git commit、命令、volatile 字段清单
```
`README.md` 必须记录生成基线时的 commit hash,否则将来无法判断
"基线是在哪个代码状态下产生的"。
## 4. 为什么校验脚本放宿主而不是直接放未来的编译器仓库
Phase 0 时编译器仓库还不存在。脚本先落宿主 `scripts/`,
Phase 2 随编译器一起搬走,届时宿主保留一个薄封装(或直接调编译器包的 CLI)。
这样 Phase 1 的 parity 验证不需要等仓库拆分。
@@ -0,0 +1 @@
{"_example": "Fill with {\"file\": \"<path>\", \"reason\": \"<why>\"}. Put spec/research files only — no code paths. Run `python3 .trellis/scripts/get_context.py --mode packages` to list available specs. Delete this line once real entries are added."}
@@ -0,0 +1,118 @@
# Phase 0 执行计划
## 前置
- [ ] 分支:`experiment/road-compiler-rethink`(已在)
- [ ] 确认工作区干净(`.trellis/tmp-*.js` 五个未跟踪文件与本任务无关,可先清理或忽略)
- [ ] 阅读父任务 `design.md` §1 契约定义
## Step 1 — 摸清两区域当前状态
```bash
ls config/areas/
for d in outputs/*/native-road/layers; do echo "$d: $(ls $d | wc -l)"; done
```
判定:`hanyang-block` 为废案,不纳入本阶段;只核查两个有效区域的配置与当前产物。
- [x] 逐区域检查 config 的 `nativeRoad.edgeLines` / `junctionTemplates.enabled`
- [x] 将两个有效区域的配置差异记录在基线 README
**门槛**:两个有效区域的图层差异有书面解释。
## Step 2 — 确定性核查
```bash
# 备份
cp -r outputs/<area>/native-road /tmp/rc-baseline-a
# 重编
rm -rf outputs/<area>/native-road
npm run road:compile -- --config config/areas/<area>.json
cp -r outputs/<area>/native-road /tmp/rc-baseline-b
# 比对
diff -r /tmp/rc-baseline-a /tmp/rc-baseline-b
```
- [x] 对两个有效区域各跑一遍
- [x] 记录所有差异字段 → volatile 清单
- [x] 额外一轮:删掉 `native-traffic-signals.json` 重生成,
确认信号 ID 是否确定(`traffic-signals.js` require 了 `crypto`,重点核查)
- [ ] 若发现**几何坐标级**的非确定性 → 停止本阶段,先开 bug 任务修掉
**门槛** 🔴:确定性已证明,或非确定性已定位并修复。这是全案的地基。
## Step 3 — 写 `scripts/road-parity.js`
按 `design.md` §2 实现。
- [x] `--snapshot` 生成归一化 checksum 清单
- [x] `--compare` 比对并逐文件报差异,不一致时非零退出
- [x] GeoJSON 双 hash(`contentHash` 排序后 / `orderHash` 原序)
- [x] volatile 字段按 Step 2 结论归一化
- [x] 自验:同一区域连跑两次 snapshot,`--compare` 必须通过
```bash
node scripts/road-parity.js --config config/areas/fengshu-er-road.json --snapshot /tmp/s1.json
node scripts/road-parity.js --config config/areas/fengshu-er-road.json --compare /tmp/s1.json
echo "exit=$?" # 必须为 0
```
**门槛**:脚本对未改动的代码报告一致。
## Step 4 — 建立两区域基线
```bash
mkdir -p .trellis/tasks/08-25-road-compiler-extraction/baseline
for a in fengshu-er-road nantaizi-lake-innovation-valley; do
rm -rf outputs/$a/native-road
npm run road:compile -- --config config/areas/$a.json
node scripts/road-parity.js --config config/areas/$a.json \
--snapshot .trellis/tasks/08-25-road-compiler-extraction/baseline/$a.json
done
```
- [x] 两个基线 JSON 生成
- [x] 写 `baseline/README.md`:生成时的 git commit、命令、volatile 字段清单、
两个有效区域图层差异的解释
- [x] 反向自验:再跑一次 `--compare` 两个基线全部通过
## Step 5 — K2 决策
- [x] 检查 `comparison.json` 当前是否真被消费(grep 宿主与 workbench)
- [x] 若有 → 方案 B(可选注入),在契约里定义 `comparisonDir` 为 optional
## Step 6 — 落契约文档
- [x] 写 `docs/native-road-package-v1.md`,内容源自父任务 `design.md` §1
- [x] 补入 Step 2 的 volatile 字段清单
- [x] 补入 Step 5 的 K2 决策
- [x] 在 `docs/changelog.md` 记一行
## 验证命令汇总
```bash
# parity 两区域全绿
for a in fengshu-er-road nantaizi-lake-innovation-valley; do
node scripts/road-parity.js --config config/areas/$a.json \
--compare .trellis/tasks/08-25-road-compiler-extraction/baseline/$a.json || echo "FAIL $a"
done
# 既有测试未破
npm run test:native-road
npm run test:road-workbench
# 确认无生产代码改动
git diff --stat -- scripts/lib blender
```
最后一条必须为空输出 —— Phase 0 不碰生产代码。
## Review Gate
全部 AC0.1–AC0.6 打勾后,再进 Phase 1。**基线不可靠时不要前进。**
## Rollback
本阶段纯新增(文档 / 脚本 / 基线数据)。回滚 = 删除新增文件。
唯一例外:Step 2 若发现并修复了非确定性 bug,那部分是真实代码改动,
应拆成独立 commit 并单独保留。
@@ -0,0 +1,84 @@
# Phase 0:冻结契约与 parity 基线
父任务:`.trellis/tasks/08-25-road-compiler-extraction/`
契约权威定义:父任务 `design.md` §1
## Goal
在任何代码移动之前,把 `native-road-package/v1` 契约落成仓库内文档,
并为两个有效区域建立可复跑的逐文件 parity 基线,作为全案唯一 oracle。
**本阶段不移动、不重构任何生产代码。** 只新增文档、基线数据和一个校验脚本。
## Requirements
### R0.1 契约文档
- 把父任务 `design.md` §1(输入契约 / 输出契约 / 消费方式)落成
`docs/native-road-package-v1.md`。
- 文档必须列全 12 个图层名、`compiled.json` 顶层结构、`diagnostics.json` 记录形状、
stdout 标记格式。
- Phase 2 会把该文档搬进编译器仓库,此处先落在宿主。
### R0.2 确定性前置核查 🔴
**基线只有在编译器确定性的前提下才有意义。** 必须先证明这一点。
- 对同一输入连续跑两次 `road:compile`,比较全部输出文件。
- 识别并记录所有 volatile 字段(时间戳、绝对路径、staging 目录名、
任何来自 `mkdtemp` 的随机名、Map/Set 迭代顺序敏感的输出)。
- 校验脚本必须归一化或排除这些字段。
- 若发现真实的非确定性(相同输入产出不同几何),**必须先修掉再继续**,
否则整个拆分没有 oracle。
### R0.3 parity 校验脚本
- 新增 `scripts/road-parity.js`(宿主侧,Phase 2 随编译器搬走)。
- 能力:
- `--snapshot <out.json>` 遍历指定区域的 `native-road/` 全部文件 +
`native-traffic-signals.json`,归一化后输出排序稳定的 checksum 清单
- `--compare <baseline.json>` 与基线比对,差异逐文件报告
- 非零退出码表示不一致
- GeoJSON 需按稳定键排序后再 hash(避免 feature 顺序抖动造成假阳性),
但**顺序本身若变化必须被报告**——用两个 hash:`contentHash`(排序后)
与 `orderHash`(原序),分别报告。
### R0.4 两区域基线
- 区域:`fengshu-er-road`、`nantaizi-lake-innovation-valley`
- 从干净状态跑 `npm run road:compile`,产出基线 JSON 提交进版本控制
- 基线文件位置:`.trellis/tasks/08-25-road-compiler-extraction/baseline/<area>.json`
(Phase 2 搬进编译器仓库当测试语料,见父任务 R4)
`hanyang-block` 是废案,不纳入编译、快照或后续 parity 兼容范围。
### R0.5 K2 决策定档
`comparison.json` 依赖宿主 osm2streets 产物(`compile-native-roads.js:87` 读
`area.outputs.geojsonDir`),拆出后不可达。本阶段必须做出决策并写入契约文档:
- 方案 A:移除 `comparison.json`(osm2streets 已 legacy)
- 方案 B:保留,`comparisonDir` 作为可选输入注入
- 倾向 A。决策写入 `docs/native-road-package-v1.md` 的「已移除能力」一节。
## Acceptance Criteria
- [x] AC0.1 `docs/native-road-package-v1.md` 存在,覆盖输入契约、输出契约、
12 图层清单、stdout 标记、已移除能力
- [x] AC0.2 连续两次编译的 parity 比对通过(确定性已证明),volatile 字段清单已记录在文档内
- [x] AC0.3 `scripts/road-parity.js` 可用,`--snapshot` / `--compare` 均工作,
不一致时非零退出
- [x] AC0.4 两个区域基线 JSON 已提交,且每个都能用 `--compare` 自比对通过
- [x] AC0.5 K2 决策已定档并写入契约文档
- [x] AC0.6 未修改任何生产代码(`git diff` 只含新增文档 / 脚本 / 基线)
## 依赖与顺序
- 无前置依赖,本阶段是全案入口
- **阻塞** Phase 1、2、3、4 —— 没有基线就没有 oracle
## Out of Scope
- 任何生产代码改动(含"顺手修一下")
- 目录结构调整
- `compiled.json` 结构变更
@@ -0,0 +1,26 @@
{
"id": "rc-p0-contract-baseline",
"name": "rc-p0-contract-baseline",
"title": "Phase 0:冻结契约与 parity 基线",
"description": "写死 native-road-package/v1 输入输出契约,并对两个有效区域建立逐文件 checksum 基线作为全案 oracle",
"status": "completed",
"dev_type": null,
"scope": null,
"package": null,
"priority": "P1",
"creator": "dingkang",
"assignee": "dingkang",
"createdAt": "2026-08-25",
"completedAt": "2026-08-25",
"branch": null,
"base_branch": "main",
"worktree_path": null,
"commit": null,
"pr_url": null,
"subtasks": [],
"children": [],
"parent": "08-25-road-compiler-extraction",
"relatedFiles": [],
"notes": "",
"meta": {}
}
@@ -0,0 +1 @@
{"_example": "Fill with {\"file\": \"<path>\", \"reason\": \"<why>\"}. Put spec/research files only — no code paths. Run `python3 .trellis/scripts/get_context.py --mode packages` to list available specs. Delete this line once real entries are added."}
@@ -0,0 +1,53 @@
# Phase 1 Technical Design
## Boundary
`packages/road-compiler/` becomes the single implementation owner for native
road compilation. It is a CommonJS workspace package with explicit public
entrypoints for compiler APIs, traffic-signal schema, turn-lane helpers, OSM
parsing, reference conversion, and CLIs. It never imports `area-config`, reads
`config/areas`, or derives host paths.
The host owns `scripts/lib/area-config.js` and maps normalized configuration to
the v1 `RoadCompilerInput` shape using `toRoadCompilerInput(area)`. During P1,
`build-area.js` calls the package in-process; P2 is the only phase that changes
that call to a child process.
## Source Ownership and Compatibility
The following current `scripts/lib` implementations move into package `src`:
`native-road`, `complex-junction`, `turn-lane-arrows`, `lane-geometry`,
`gaode-junction-reference`, `native-traffic-signals`, and `osm`.
Some moved modules also serve legacy host paths: QGIS uses turn-lane arrows,
vehicle preview and reimport use OSM parsing, and preview tests use lane
geometry. Those consumers import the package entrypoints after the move. This
preserves one implementation while allowing host -> package dependency.
Traffic signal ownership follows the matrix in
`research/traffic-signals-split-matrix.md`: schema, geometry, validation, and
runtime construction move to the package. The host retains only two file-I/O
adapters, `readTrafficSignalFeatures()` and `readTrafficSignals()`, both
delegating to package exports. No duplicated schema code remains.
## Input and Path Handling
The package compiler API accepts only `RoadCompilerInput` from
`docs/native-road-package-v1.md`. Package CLI commands accept an explicit JSON
input file (`--input`) and never load area configuration. The compatibility
host CLI still accepts `--config`, but immediately maps it through
`toRoadCompilerInput()` before entering the package.
`junctionTemplates.*.referenceFile` changes to a path relative to its area
configuration. `readAreaConfig()` resolves it while normalizing configuration;
the package receives an absolute path and does no path resolution.
## Tests and Rollout
The package receives the required Fengshu OSM fixture plus migrated unit tests.
Its `npm test` must run from the package directory without reading host inputs
or outputs. After each source batch, run the two Phase 0 parity baselines. The
existing host command names remain compatibility wrappers through P1.
Rollback is a normal Git revert of the latest batch commit. No module has a
parallel host copy after its batch lands, preventing divergence.
@@ -0,0 +1 @@
{"_example": "Fill with {\"file\": \"<path>\", \"reason\": \"<why>\"}. Put spec/research files only — no code paths. Run `python3 .trellis/scripts/get_context.py --mode packages` to list available specs. Delete this line once real entries are added."}
@@ -0,0 +1,118 @@
# Phase 1 执行计划
分批搬迁,每批后跑 parity。**不要一次性大搬。**
## Step 0 — 前置
```bash
# 基线必须先绿
for a in fengshu-er-road nantaizi-lake-innovation-valley; do
node scripts/road-parity.js --config config/areas/$a.json \
--compare .trellis/tasks/08-25-road-compiler-extraction/baseline/$a.json || echo "FAIL $a"
done
```
- [ ] 两个有效区域基线全绿(否则回 Phase 0)
## Step 1 — K1 矩阵(动代码之前)
- [ ] 读 `scripts/lib/traffic-signals.js` 全文,列出所有 export
- [ ] 对每个 export `grep -rn` 找使用方
- [ ] 产出 `research/traffic-signals-split-matrix.md`:函数 × 使用方 × 归属判定
- [ ] `buildTrafficSignals`(`test-preview-assets.js`)归属定档
**门槛**:矩阵完成,无"待定"项。
## Step 2 — 建包骨架
```
packages/road-compiler/
package.json # CommonJS,无构建步骤(父任务 C2)
src/
bin/
test/fixtures/
docs/
```
- [ ] `package.json` 名称、入口、`test` script
- [ ] 根 `package.json` 加 workspace 或 `file:` 依赖
## Step 3 — 分批搬迁(每批一个 commit + 一次 parity)
**批 1:纯函数,零风险**
- [ ] `lib/lane-geometry.js` → `src/geometry/lane-geometry.js`
- [ ] `lib/gaode-junction-reference.js` → `src/reference/gaode.js`
- [ ] 宿主侧改 require 指向包
- [ ] parity ✓
**批 2:几何模块**
- [ ] `lib/turn-lane-arrows.js`
- [ ] `lib/complex-junction.js`
- [ ] parity ✓
**批 3:信号(K1 执行)**
- [ ] 按 Step 1 矩阵拆 `lib/traffic-signals.js`
- [ ] `lib/native-traffic-signals.js` 与 schema 部分入包
- [ ] `lib/osm.js` 入包
- [ ] 宿主保留 legacy 读取器,从包 import schema
- [ ] parity ✓ + `npm run test:traffic-signals`(若存在)
**批 4:编译器核心**
- [ ] `lib/native-road.js` → `src/compile/native-road.js`
- [ ] parity ✓
**批 5:CLI + 窄契约(R1.2)**
- [ ] `compile-native-roads.js` → `bin/compile.js`,入参改 `RoadCompilerInput`
- [ ] `check-native-roads.js` → `bin/check.js`
- [ ] 宿主 `area-config.js` 加 `toRoadCompilerInput(area)`
- [ ] `build-area.js` 改为传 input 对象
- [ ] K3:`referenceFile` 改为宿主解析后传绝对路径,config 内改相对路径
- [ ] parity ✓
**批 6:workbench**
- [ ] `road-workbench.js` + `workbench/app.js` 入包
- [ ] OpenLayers 依赖暂沿用宿主 `node_modules`(同仓库内可行),记入 Phase 2 K4
- [ ] `npm run test:road-workbench` ✓
**批 7:测试 fixture(R1.5)**
- [ ] `inputs/osm/枫树二路.osm` 复制进 `test/fixtures/`
- [ ] `test-native-road.js` 改读包内 fixture
- [ ] 在包目录内独立跑 `npm test` ✓
## Step 4 — 清理与验证
- [ ] 删除 `scripts/lib/` 下所有搬迁文件的残留(AC1.6)
- [ ] `grep -rn "area-config\|config/areas" packages/road-compiler/` 必须为空(AC1.4)
- [ ] `grep -rn "\.\./\.\./scripts\|osm2streets-qgis-workflow" packages/road-compiler/` 检查反向依赖
## 验证命令汇总
```bash
# parity
for a in fengshu-er-road nantaizi-lake-innovation-valley; do
node scripts/road-parity.js --config config/areas/$a.json \
--compare .trellis/tasks/08-25-road-compiler-extraction/baseline/$a.json || echo "FAIL $a"
done
# 测试
npm run test:native-road
npm run test:road-workbench
(cd packages/road-compiler && npm test)
# 端到端(含 blender / cesium)
npm run build:area -- --config config/areas/fengshu-er-road.json
# 反向依赖为 0
grep -rn "area-config\|config/areas" packages/road-compiler/ && echo "VIOLATION"
```
## Review Gate
AC1.1–AC1.8 全绿。**parity 有任何一项不绿都不得进 Phase 2** —— 那意味着搬迁改变了行为,
而在同一仓库内查因比拆仓库后查因便宜得多。
## Rollback
每批一个 commit,可逐批 `git revert`。
过渡期内若需紧急回退,宿主 require 改回 `scripts/lib/` 旧路径即可
(前提:该批尚未执行 Step 4 清理)。
@@ -0,0 +1,98 @@
# Phase 1:包边界(不换仓库)
父任务:`.trellis/tasks/08-25-road-compiler-extraction/`
技术设计:父任务 `design.md` §2(模块清单 / K1 拆分建议)
## Goal
在**当前仓库内**建立 `packages/road-compiler/`,移入编译器全部模块,
把对 `readAreaConfig` 的耦合换成窄输入契约,产物对 Phase 0 基线逐字节一致。
**本阶段不换仓库。** 目的是把"改坏了编译器"与"拆坏了仓库"分成两个可归因的步骤
(父任务 D4)。
## Requirements
### R1.1 目录与模块搬迁
在 `packages/road-compiler/` 内建立结构,移入父任务 `design.md` §2.1 列出的全部文件
(约 3400 行核心 + workbench)。
搬迁后 `scripts/lib/` 下不应再留下这些文件的副本 —— 并存会导致
"改了一份忘了另一份"的静默不一致。
### R1.2 窄输入契约
- 编译器入口只接受父任务 `design.md` §1.1 定义的 `RoadCompilerInput`
- 编译器内不得出现 `require("area-config")`、不得读 `config/areas/*.json`、
不得从 areaId 推导任何路径
- 宿主 `scripts/lib/area-config.js` 新增 `toRoadCompilerInput(area)` 做映射
- 三个 CLI(`compile` / `check` / `workbench`)改为接受显式参数或 input JSON
### R1.3 K1:`traffic-signals.js` 拆分 🔴
**全案唯一需要细读再动的地方。** 按父任务 `design.md` §2.3:
- 随编译器走:OSM 信号节点提取 + 信号文档 schema
- 留宿主:`readTrafficSignalFeatures`(`build-osm2streets-qgis.js`)、
`readTrafficSignals`(`build-area.js`)
- 待判定:`buildTrafficSignals`(`test-preview-assets.js`)—— 需读代码确认归属
- 拆完后宿主从编译器包 import schema(宿主→编译器是允许方向)
动手前必须先产出一份「函数 × 使用方」矩阵,确认无遗漏。
### R1.4 K3:参考文件路径约定
`config/areas/fengshu-er-road.json` 的
`junctionTemplates.clusters[].referenceFile` 是指向宿主仓库的绝对路径。
- 定义解析约定:相对 config 文件所在目录,或由宿主在 `toRoadCompilerInput()`
中解析为绝对路径后传入
- 倾向后者:**编译器只接受已解析的绝对路径,不做路径推导**(符合 R1.2)
- config 内改为相对路径,宿主负责解析
### R1.5 K5:自带测试 fixture
- `test-native-road.js:167` 读 `inputs/osm/枫树二路.osm`
- 该文件(或裁剪版)复制进 `packages/road-compiler/test/fixtures/`
- 测试改为读包内 fixture,不再访问宿主 `inputs/`
- 目标:编译器包 `npm test` 不依赖宿主任何目录
### R1.6 宿主侧接线保持不变
- `build-area.js` 本阶段继续 in-process `require`(子进程改造留到 Phase 2)
- `npm run road:compile` / `road:check` / `road:workbench` 行为对用户不变
- `blender/` 完全不改
## Acceptance Criteria
- [x] AC1.1 两个有效区域 `road-parity --compare` 对 Phase 0 基线全绿
- [x] AC1.2 `npm run test:native-road`、`npm run test:road-workbench` 通过
- [x] AC1.3 `npm run build:area` 枫树二路完整跑通(含 blender / cesium 阶段)
- [x] AC1.4 `grep -rn "area-config\|config/areas" packages/road-compiler/` 无命中
- [x] AC1.5 `packages/road-compiler/` 内 `npm test` 不访问宿主 `inputs/` 或 `outputs/`
- [x] AC1.6 `scripts/lib/` 下无搬迁文件的残留副本
- [x] AC1.7 K1 的「函数 × 使用方」矩阵已产出并归档到 `research/`
- [x] AC1.8 `compiled.json` 结构未变(父任务 AC7 / C1)
## 依赖与顺序
- **前置**:Phase 0 必须完成且基线可靠
- **阻塞**:Phase 2
- 与 Phase 3、4 无直接依赖,但它们都在 Phase 2 之后
## 风险
| 风险 | 缓解 |
|---|---|
| K1 拆分遗漏某个使用方 → 运行时才炸 | 先做矩阵,再动代码;`grep -rn` 全仓验证 |
| 搬迁过程中相对 require 路径改错 | 分小步 commit,每步跑 parity |
| `workbench/app.js` 的 OpenLayers import map 指向宿主 node_modules | 本阶段仍在同仓库,可暂不处理;记入 Phase 2(K4) |
| 一次性大搬迁难以归因 | 按模块分批:先纯函数(lane-geometry / gaode-reference),再 complex-junction,最后 native-road 与 CLI |
## Out of Scope
- 换仓库(Phase 2)
- layer manifest(Phase 3)
- IR / pass manager 重构(父任务 C1)
- 引入 TypeScript 或构建步骤(父任务 C2)
@@ -0,0 +1,21 @@
# Traffic Signals Split Matrix
Evidence gathered from `scripts/lib/traffic-signals.js` and repository-wide
call-site search on 2026-08-25.
| Export | Current users | Owner after P1 | Migration |
|---|---|---|---|
| `SIGNAL_LAYOUT` | `buildTrafficSignalsFromFeatures` | compiler package | Export from `@osm-asset/road-compiler/traffic-signals` |
| `signalNodeKey` | `buildTrafficSignalsFromFeatures` | compiler package | No host caller today; preserve public export for runtime identity contract |
| `buildTrafficSignalFeatures` | `native-traffic-signals`, `readTrafficSignalFeatures` | compiler package | Host QGIS adapter imports it from the package |
| `validateTrafficSignalFeatures` | `native-traffic-signals`, signal tests | compiler package | Tests import package entrypoint |
| `validateTrafficSignalSourceReferences` | `native-traffic-signals`, `reimport-gpkg`, `readTrafficSignals` | compiler package | Reimport adapter imports package function |
| `buildTrafficSignalsFromFeatures` | `native-traffic-signals`, `readTrafficSignals`, `buildTrafficSignals` | compiler package | Host preview adapter imports package function |
| `buildTrafficSignals` | `test-preview-assets` | compiler package | Test imports package function; it is geometry/schema behavior, not host I/O |
| `readTrafficSignalFeatures` | `build-osm2streets-qgis` | host adapter | Keep a thin file-reading wrapper under `scripts/lib/traffic-signals.js`; it imports package functions |
| `readTrafficSignals` | `build-area` | host adapter | Keep a thin file-reading wrapper under `scripts/lib/traffic-signals.js`; it imports package functions |
`scripts/lib/traffic-signals.js` must not retain a second implementation of
the schema or geometry. Its only P1 responsibility is host file I/O for the
legacy QGIS / preview paths. This preserves the one-way dependency:
host -> compiler package; the package never imports the host.
@@ -0,0 +1,26 @@
{
"id": "rc-p1-package-boundary",
"name": "rc-p1-package-boundary",
"title": "Phase 1:包边界(不换仓库)",
"description": "在本仓库内建 packages/road-compiler,移入编译器模块,用窄输入契约替换 readAreaConfig 耦合,产物对基线逐字节一致",
"status": "completed",
"dev_type": null,
"scope": null,
"package": null,
"priority": "P1",
"creator": "dingkang",
"assignee": "dingkang",
"createdAt": "2026-08-25",
"completedAt": "2026-08-25",
"branch": null,
"base_branch": "main",
"worktree_path": null,
"commit": null,
"pr_url": null,
"subtasks": [],
"children": [],
"parent": "08-25-road-compiler-extraction",
"relatedFiles": [],
"notes": "",
"meta": {}
}
@@ -0,0 +1,4 @@
{"file":".trellis/spec/pipeline/external-tools.md","reason":"检查 CLI 子进程错误、signal 与日志处理是否符合宿主管线约定。"}
{"file":".trellis/spec/pipeline/cli-and-stages.md","reason":"检查编译阶段、完成标记和 stage manifest 的跨层影响。"}
{"file":".trellis/spec/guides/cross-layer-thinking-guide.md","reason":"检查配置、Node pipeline、Blender 消费链的边界没有漂移。"}
{"file":".trellis/spec/guides/artifact-parity-guide.md","reason":"检查两个有效区域的严格基线 parity。"}
@@ -0,0 +1,44 @@
# Phase 2:独立仓库与 CLI 边界设计
## Architecture
P1 已将实现收敛到 `packages/road-compiler/`。P2 把该目录以保留历史的方式导出为独立 package 仓库,保留两个明确方向的边界:
```
宿主 area config
-> scripts/lib/area-config.js
-> RoadCompilerInput JSON(宿主 staging)
-> @osm-asset/road-compiler CLI(子进程)
-> native-road/ + NATIVE_ROAD_COMPILE_DONE
-> build-area.js / Blender / preview
```
编译器不知道区域配置、宿主仓库、Blender 或宿主输出目录约定以外的输入路径。宿主不知道 compiler 内部源文件;它只拥有输入 JSON、CLI 的完成标记和写出的契约文件。
## CLI Contract
- CLI 接收一个 JSON 文件中的 `RoadCompilerInput`,而不是宿主的 area config。
- `comparisonDir` 继续作为可选输入,以维持现有 `comparison.json` 产物和 P0 baseline 的可比性。
- 成功只打印一次 `NATIVE_ROAD_COMPILE_DONE <JSON>`。payload 必须至少含 `areaId`、`output`、`roads`、`endpoints` 和 `diagnostics`。
- `build-area.js` 保持同步批处理模式,子进程日志对用户可见;为了验证标记,输出同时被捕获或 tee。它对启动失败、非零状态、signal、缺失/重复/非法标记和 payload 与当前输入不一致都报错。
- 产物先由 compiler 的现有 staging/atomic promotion 逻辑写入目标 `native-road/`;宿主不接管这一写入过程。
## Repository Contents
独立仓库拥有:compiler source、public API、CLI、check、workbench、fixture、两个 parity baseline、契约文档、README、package lockfile 和 workbench 的 `ol` 依赖。测试和 workbench 均必须在没有宿主 checkout 的环境运行。
宿主保留:area-config 读取/归一化、`RoadCompilerInput` 映射、pipeline 阶段编排、Blender/preview、区域配置、运行产物和一份升级回归 baseline。宿主 spec 仅保留指针,契约正文随 compiler 仓库维护。
## History Extraction
导出只允许 `git subtree split` 或 `git filter-repo`。必须在独立仓库验证 `git log --follow src/compile/native-road.js`;验证的是迁移前的逻辑历史,而非仅 P1 的边界移动提交。导出和验证先在临时分支/clone 完成,外部远端创建和 push 必须使用用户给出的地址和授权范围。
## Dependency and Rollout
初始发布源定为私有 `https://git.app.que01.top/que01/road-compiler.git`。仓库以带注释 tag `v0.1.0` 首发,宿主以该精确 tag 作为依赖并写入 lockfile。开发临时形态可以指向独立 checkout 的本地 `file:` 依赖;它不能成为验收时的唯一消费方式。两个区域 parity 通过后删除 `packages/road-compiler/`;回滚由 revert 宿主消费改造实现,不能让 production host 继续直接 import 该目录。
## Compatibility and Risks
这是位置和调用方式迁移,不改变 compiler 行为。两个区域的 strict content/order hash 是主要 oracle;信号文档的确定性生成仍应通过 parity 覆盖。P2 不处理 `check:area` 的历史 stage-manifest freshness warning,也不把 Blender/Metal 沙箱问题归因为道路产物。
若外部 CLI 无法及时使用,回滚宿主消费 commit 即可;外部仓库历史和 tag 不需要删除。对于完整 Blender 构建,macOS Metal 初始化必须在提权的宿主环境运行。
@@ -0,0 +1,4 @@
{"file":".trellis/spec/pipeline/external-tools.md","reason":"CLI 子进程必须沿用管线的启动、日志和失败状态语义。"}
{"file":".trellis/spec/pipeline/cli-and-stages.md","reason":"编译是 Blender 前的 pipeline 输入阶段,需保持阶段与 stdout 契约。"}
{"file":".trellis/spec/config/index.md","reason":"宿主拥有区域配置归一化及 RoadCompilerInput 映射。"}
{"file":".trellis/spec/guides/artifact-parity-guide.md","reason":"本阶段声称产物不变,必须用严格 parity 验证。"}
@@ -0,0 +1,55 @@
# Phase 2 执行计划
执行前提:用户已在最新 P2 规划摘要后明确批准。发布目标已定为私有 `https://git.app.que01.top/que01/road-compiler.git`,首发 tag 为 `v0.1.0`。
## 1. 导出并核验历史
- [ ] 创建临时 export 分支或临时 clone,使用 `git subtree split --prefix=packages/road-compiler` 或 `git filter-repo --path packages/road-compiler/ --path-rename packages/road-compiler/:` 导出。
- [ ] 在导出仓库验证 `git log --follow src/compile/native-road.js` 包含 2026-08-13 以来的 native compiler 历史。
- [ ] 在私有 `https://git.app.que01.top/que01/road-compiler.git` 创建并推送独立仓库;创建带注释的 `v0.1.0` tag。
## 2. 使编译器仓库自持
- [ ] 将 CLI 作为 package `bin` 入口,接受由宿主写出的 `RoadCompilerInput` JSON,并继续输出唯一的 `NATIVE_ROAD_COMPILE_DONE` JSON 标记。
- [ ] 补全 `package.json`、锁文件和 `ol` 依赖;workbench vendor 文件从自身安装目录提供。
- [ ] 迁入 `docs/native-road-package-v1.md`、两个 baseline 和它们的测试驱动,新增独立 README。
- [ ] 在不含宿主文件的临时 clone 内执行依赖安装、单元测试、两区域 parity 与 workbench 启动测试。
- [ ] grep 验证没有 `area-config`、`config/areas`、宿主项目名或宿主相对路径引用。
## 3. 宿主改为外部 CLI 消费
- [ ] 将 compiler 以精确 git tag `v0.1.0` 安装到宿主并记录 lockfile;禁止范围版本、`latest`、`*` 和裸分支。
- [ ] 将 `toRoadCompilerInput()` 序列化到每个区域的 pipeline staging 目录,传给 compiler CLI。
- [ ] 在 `build-area.js` 的 blender 前置阶段调用 CLI。沿用管线的 `spawnSync` / `runCommand` 失败语义(启动错误、exit status、signal)和直通日志;缓冲或 tee stdout 后,解析恰好一个完成标记并验证其 `areaId`、`output` 与当前区域匹配。
- [ ] 将 host workbench 的 fresh compile 回调切换到同一 CLI,不改变 fresh-process 行为。
- [ ] 把所有 host 对 `packages/road-compiler/**` 的直接 import 替换成已安装包的公开 API 或 CLI;两个区域 parity 均通过后删除 in-host 副本。
- [ ] 将宿主 pipeline spec 改为指向编译器仓库所拥有的契约文档。
## 4. 验证与发布门
新仓库(干净 clone):
```bash
npm ci
npm test
npm run test:road-parity
npm run road:workbench -- --config test/fixtures/fengshu-er-road.input.json --no-compile
```
宿主两个有效区域的逐字节 parity:
```bash
node scripts/road-parity.js --config config/areas/fengshu-er-road.json \
--compare .trellis/tasks/08-25-road-compiler-extraction/baseline/fengshu-er-road.json
node scripts/road-parity.js --config config/areas/nantaizi-lake-innovation-valley.json \
--compare .trellis/tasks/08-25-road-compiler-extraction/baseline/nantaizi-lake-innovation-valley.json
```
- [ ] 为 CLI 标记成功、缺失、重复、非法 JSON、areaId 不匹配和 output 不匹配补测试。
- [ ] 跑 package 单测、宿主 native-road / workbench / traffic signals / turn-lane-arrows 测试,以及两个 parity 检查。
- [ ] 使用 `trellis-check` 做最终跨层检查;Blender 完整构建需以提权方式运行,原因是 macOS Metal 初始化不能在沙箱内启动。
## Rollback
- 外部仓库和已发布 tag 保留不动;在宿主 revert 消费改造即可回到 P1 边界。
- 若按决定临时保留 in-host 副本,可将依赖回指该副本以恢复;该退路不取代 host parity 验证。
@@ -0,0 +1,62 @@
# Phase 2:拆仓库
父任务:`.trellis/tasks/08-25-road-compiler-extraction/`
## Goal
把当前 `packages/road-compiler/` 拆为保留 git 历史、可脱离宿主独立测试和运行的仓库;宿主改为消费一个锁定版本的编译器 CLI。这样道路编译器可以独立演进,宿主依然通过版本化文件契约稳定构建场景。
## Confirmed Facts
- P1 已完成:编译器实现和 workbench 的所有权在 `packages/road-compiler/`;宿主负责将区域配置映射为 `RoadCompilerInput`。
- `git log --follow packages/road-compiler/src/compile/native-road.js` 已能追溯到 2026-08-13 的 native-road compiler 历史。
- 契约为 `native-road-package/v1`,完成标记为 `NATIVE_ROAD_COMPILE_DONE <json>`;`comparisonDir` 是可选输入,继续保留 `comparison.json`。
- 当前宿主远端为内部 Git 服务 `https://git.app.que01.top/que01/osmWorkflow.git`;P2 独立编译器仓库定为私有 `https://git.app.que01.top/que01/road-compiler.git`。
- 可维护范围只有 `fengshu-er-road` 和 `nantaizi-lake-innovation-valley`。`hanyang-block` 是废案,不参与基线、测试、验收或迁移语料。
## Requirements
### R2.1 保留 Git 历史
- 用 `git subtree split` 或 `git filter-repo` 导出,不得以复制目录再 `git init` 替代。
- 新仓库中 `git log --follow src/compile/native-road.js` 必须能追溯到 P1 之前的 native-road compiler 提交。
### R2.2 新仓库可独立运行
- 新仓库拥有 compiler、CLI、check、workbench、其测试 fixture、两个 parity baseline、契约文档和 README。
- 新仓库 own `ol` 及其 workbench 所需的运行依赖;workbench 不得从宿主 `node_modules` 提供浏览器资源。
- 新仓库不得引用宿主的 `area-config`、`config/areas`、`scripts/` 或本仓库绝对路径。
### R2.3 宿主的消费边界
- `scripts/lib/area-config.js` 继续是唯一的区域配置归一化与 `RoadCompilerInput` 映射位置。
- `scripts/build-area.js` 用已安装编译器的 CLI 子进程编译,继承 stdout/stderr,检查启动错误、退出状态和 signal,并解析且校验唯一的 `NATIVE_ROAD_COMPILE_DONE` 标记。
- 宿主只依赖 CLI、写入的文件和版本化输入 JSON;不再以相对路径 import 编译器内部模块。保留的宿主 signal 文件 I/O 适配层改为只调用公开包 API。
- `road-workbench` 保持每次编译均启动新进程的语义,但改为调用已安装 CLI。
### R2.4 版本与迁移
- 宿主依赖必须锁定一个具体编译器版本,禁止 `latest` 或 `*`;包版本与 `native-road-package/v1` 的契约版本独立演进。
- 初始分发使用带注释的 git tag `v0.1.0`;宿主锁定该 tag。完整 parity 验证后移除 `packages/road-compiler/`,不保留 in-host 副本作为正常消费路径。
- 宿主保留两份 baseline,用来验证今后升级编译器版本后没有产物漂移。
## Acceptance Criteria
- [ ] AC2.1 独立仓库的 `git log --follow src/compile/native-road.js` 可见 P1 前的 compiler 历史。
- [ ] AC2.2 在未 clone 宿主的干净目录中,新仓库 `npm ci`(或等价锁文件安装)和 `npm test` 均通过。
- [ ] AC2.3 新仓库的两区域 parity(`fengshu-er-road`、`nantaizi-lake-innovation-valley`)均与迁入 baseline 完全一致。
- [ ] AC2.4 宿主用锁版本依赖运行 CLI;`build-area.js` 成功解析一个有效的 `NATIVE_ROAD_COMPILE_DONE` 标记,缺失、重复或非法标记会失败。
- [ ] AC2.5 宿主的两个区域 parity 均对保留 baseline 全绿。
- [ ] AC2.6 宿主 `package.json` 的 compiler 依赖是具体、可复现版本,不是 `latest`、`*` 或裸分支。
- [ ] AC2.7 编译器仓库对宿主反向依赖为 0,且其 workbench 可独立启动。
## Out of Scope
- 编译器几何、规则或输出内容改动。
- 图层 manifest 和道路/建筑渲染分离(Phase 3)。
- drawtonomy 扩展(Phase 4)。
- `hanyang-block` 修复、迁移或作为验收样本。
## Release Decision
独立仓库为私有 `https://git.app.que01.top/que01/road-compiler.git`。首发以带注释 tag `v0.1.0` 发布,宿主依赖精确锁定该 tag;两个区域 parity 均通过后删除 `packages/road-compiler/`。该决定授权 P2 在该内部远端创建和推送仓库,但不授权发布到 npm 或其他托管平台。
@@ -0,0 +1,26 @@
{
"id": "rc-p2-repo-split",
"name": "rc-p2-repo-split",
"title": "Phase 2:拆仓库",
"description": "保留 git 历史拆出独立仓库,宿主以锁版本依赖消费,子进程为主契约",
"status": "completed",
"dev_type": null,
"scope": null,
"package": null,
"priority": "P1",
"creator": "dingkang",
"assignee": "dingkang",
"createdAt": "2026-08-25",
"completedAt": "2026-08-26",
"branch": null,
"base_branch": "main",
"worktree_path": null,
"commit": null,
"pr_url": null,
"subtasks": [],
"children": [],
"parent": "08-25-road-compiler-extraction",
"relatedFiles": [],
"notes": "",
"meta": {}
}
@@ -0,0 +1,5 @@
{"file":".trellis/spec/blender/module-structure.md","reason":"检查道路 adapter 与建筑/植被/水体模块的边界没有漂移。"}
{"file":".trellis/spec/blender/testing.md","reason":"检查 Blender 结构摘要、纯 Python schema 测试和提权运行要求。"}
{"file":".trellis/spec/pipeline/index.md","reason":"检查 compiler 输出与 Blender 消费的 manifest 数据流。"}
{"file":".trellis/spec/guides/cross-layer-thinking-guide.md","reason":"检查三层契约、材质槽和 source 文件名一致性。"}
{"file":".trellis/spec/guides/artifact-parity-guide.md","reason":"检查两个区域和 throwaway 图层验证后的产物差异。"}
@@ -0,0 +1,61 @@
# Phase 3:Manifest 驱动的道路渲染设计
## Boundary
道路编译器是图层事实源,输出 `<nativeRoadDir>/manifest.json`;Blender 是渲染适配器,读取 manifest 并用宿主 `catalog.MATERIALS` / `ROAD_LAYERS` 完成材质与高度映射。建筑、植被、水体、OSM legacy 图层不改变。
```
compiler CLI
-> native-road/manifest.json + 12 declared GeoJSON sources
-> generate_scene.py
-> osmassets/native_roads.py
-> catalog material/z lookup
-> roads.assemble_geojson_layer
```
## Manifest v1.1
`manifest.json` 顶层包含 `contract: "native-road-package/v1.1"`、`areaId` 和 `layers`。`layers` 必须恰好声明编译器输出的 12 个 source:
- `road_surface`, `intersection_surface`, `sidewalk_surface`, `edge_lines`, `lane_separators`, `center_lines`, `crosswalks`, `vehicle_stop_lines`, `direction_arrows`, `turn_arrows`
- `lane_centerlines`, `connectors`
每项字段:
```json
{
"source": "center_lines",
"role": "marking",
"materialLayer": "center_lines",
"splitBy": {
"prop": "color",
"cases": [
{"match": "white", "material": "native_center_line_white"},
{"default": true, "material": "center_lines"}
]
}
}
```
`role` 为 `surface` 或 `marking` 时必须有 `materialLayer`;`semantic` 不得有材质要求,Blender 必须跳过其 GeoJSON。`splitBy` 只支持精确属性匹配和一个 default 分支,避免把渲染表达式语言复制进编译器。
编译器在原子提升前校验:每个声明 source 都对应 `layers/<source>.geojson`,目录中没有未声明的 GeoJSON;manifest 自身必须是有效 JSON。新增 manifest 不改变已有文件内容。
## Blender Adapter
新建 `blender/osmassets/native_roads.py`,公开一个接收 `native_road_dir`, `projector`, `collection`, `road_mats`, `material_layers` 的装配函数。模块负责读取/校验 manifest、解析 split cases、调用既有 `roads.assemble_geojson_layer`;不拥有图层注册表、不创建材质、不维护场景总计数。
`generate_scene.py` 仅负责 native-road 目录存在性、catalog material lookup、调用 adapter 和合并 `road_counts`。删除 `catalog.NATIVE_ROAD_LAYERS`;保留 `catalog.ROAD_LAYERS` 作为宿主材质和 z 高度事实源。
未知 `materialLayer`、缺少 source 文件、重复/遗漏 source、非法 role 或非法 splitBy 必须抛出 `RuntimeError`,不能静默跳过。semantic 图层必须不读取 GeoJSON、不创建对象、不增加 road count。
## Compatibility and Rollback
编译器契约从 `native-road-package/v1` 增加到 `v1.1`;manifest 是 v1.1 的必需输出。Blender 不提供旧 manifest fallback,因为新消费边界必须尽早暴露旧 compiler;回滚时恢复 `NATIVE_ROAD_LAYERS` 内联分支即可。旧 v1 产物仍可由旧 compiler tag 生成,不被本阶段改写。
## Verification
- 两个支持区域的 native-road 文件 parity:除新增 `manifest.json` 外所有现有 hash、orderHash、bytes 不变。
- Blender 结构摘要和预览图与 Phase 0 基线一致;完整 Blender/Metal 运行需提权。
- 纯 Python schema/manifest 测试覆盖 12 source、semantic skip、splitBy white/yellow、未知材质、缺文件和额外文件。
- throwaway `debug_probe.geojson` + manifest 实测:不改宿主代码即可生成 Blender 几何;验证后删除 probe 并再次跑 parity。
@@ -0,0 +1,5 @@
{"file":".trellis/spec/blender/module-structure.md","reason":"native_roads.py 必须遵守 osmassets 的 bpy 依赖边界和 roads adapter 责任。"}
{"file":".trellis/spec/blender/testing.md","reason":"Blender 层以结构摘要/parity 为主要回归防线,纯 schema 逻辑需可用系统 Python 测试。"}
{"file":".trellis/spec/pipeline/index.md","reason":"native-road manifest 是跨 compiler/Blender 的 pipeline 文件契约。"}
{"file":".trellis/spec/guides/cross-layer-thinking-guide.md","reason":"改动同时触及 compiler JSON、Blender Python 和契约文档。"}
{"file":".trellis/spec/guides/artifact-parity-guide.md","reason":"本阶段必须证明除新增 manifest 外渲染产物不变。"}
@@ -0,0 +1,85 @@
# Phase 3 执行计划
## Step 1 — 枚举现有分流逻辑(定 schema 之前)
- [x] 读 `blender/generate_scene.py:796-834` 全部道路分支
- [x] 列出每个 `source` 的处理方式:直接渲染 / 按属性分流 / 跳过
- [x] 已知分流:
- `center_lines`:`color != "white"` → `center_lines` 材质;
`color == "white"` → `native_center_line_white`
- `lane_separators`:`color != "yellow"` → `lane_separators`;
`color == "yellow"` → `native_lane_separator_yellow`
- [x] 确认 `lane_centerlines` / `connectors` 确实未被消费(→ `role: "semantic"`)
- [x] 产出 `research/native-layer-consumption-matrix.md`
**门槛**:manifest schema 能表达矩阵里的每一行,无"特例硬编码"残留。
## Step 2 — 定 manifest schema 并落契约
- [x] 按父任务 `design.md` §3.2 定稿 schema
- [x] 写入编译器仓库契约文档,版本标为 `native-road-package/v1.1`
- [x] 记录:v1.1 起 `manifest.json` 为必需输出
## Step 3 — 编译器侧:生成 manifest
- [x] 编译器内建立图层注册表(单一事实源),`compileGeometry` 的输出键与之对应
- [x] 写 `manifest.json` 到 outDir
- [x] 编译器自校验:manifest 声明的每个 `source` 都必须有对应 geojson 文件,
反之亦然(缺一即报错,不静默)
- [x] parity:此步只**新增** manifest.json,其余文件应逐字节不变;hanyang-block 不参与
```bash
# 只应多出 manifest.json
node scripts/road-parity.js --config config/areas/fengshu-er-road.json \
--compare .../baseline/fengshu-er-road.json
```
## Step 4 — Blender 侧:抽模块 + 读 manifest
- [x] 新建 `blender/osmassets/native_roads.py`
- [x] 把 `generate_scene.py:796-834` 的道路分支迁入
- [x] 改为读 manifest 遍历;`role == "semantic"` 跳过
- [x] `splitBy` 通用化实现,替掉两处硬编码 lambda
- [x] **加断言**:manifest 里的 `materialLayer` 若不在 `catalog.MATERIALS` /
`ROAD_LAYERS` 中,直接 raise,不静默跳过(风险表第二条)
- [x] 删除 `catalog.NATIVE_ROAD_LAYERS`
- [x] `generate_scene.py` 只保留一行调用
## Step 5 — 验证
```bash
# .blend 结构摘要对基线
npm run build:area -- --config config/areas/fengshu-er-road.json
# 走 artifact-parity-guide 的结构摘要比对
# 两个有效区域跑通(hanyang-block 为废案,不参与)
for a in fengshu-er-road nantaizi-lake-innovation-valley; do
npm run build:area -- --config config/areas/$a.json || echo "FAIL $a"
done
# 建筑/植被/水体未被改动
git diff --stat -- blender/osmassets/ | grep -vE "native_roads|catalog"
```
- [x] 渲染预览图人工对照(结构摘要粒度不足的兜底)
## Step 6 — AC3.4 实测(可扩展性证明)
这一步是整个 Phase 3 的价值证明,不可跳过。
- [x] 编译器加一个 throwaway 图层 `debug_probe.geojson`(复用 road-surface 几何仅验证 wiring)
+ manifest 声明 `role: "marking"`,复用现有材质槽
- [x] **不改宿主任何代码**,跑 blender 阶段
- [x] 确认 Blender 场景中出现该图层几何
- [x] 截图/记录证据到任务 `research/`
- [x] 回滚 throwaway 图层
## Review Gate
AC3.1–AC3.7 全绿,特别是 AC3.4 有实测证据。
## Rollback
- 恢复 `catalog.NATIVE_ROAD_LAYERS`,`generate_scene.py` 恢复内联分支
- `manifest.json` 可保留输出(无消费方时无害)
- 编译器侧图层注册表保留(它本身是改进)
@@ -0,0 +1,90 @@
# Phase 3:道路与建筑渲染分离
父任务:`.trellis/tasks/08-25-road-compiler-extraction/`
技术设计:父任务 `design.md` §3(含 manifest 形状与 Blender 侧改造方案)
## Goal
让编译器自声明图层,Blender 改为读 manifest 而非硬编码表;
道路渲染从 `generate_scene.py` 抽离为独立模块,建筑/植被/水体保持原位。
**这是全案价值最高的一步** —— 它把一张跨仓库重复的表变成生成物,
使"编译器加图层忘了改宿主"这类静默错误在结构上不可能。
## 背景:当前的静默错误风险
`blender/osmassets/catalog.py:53` 的 `NATIVE_ROAD_LAYERS` 有 10 项,
而编译器写 12 个 geojson —— `lane_centerlines` 与 `connectors` 是语义层不参与渲染。
**但这个事实只存在于这张表的省略里,编译器侧没有任何声明。**
拆仓库之后,这张表和它描述的对象分处两个仓库,漂移只是时间问题。
`.trellis/spec/pipeline/index.md` 首页已经把图层表标为「最容易出静默错误」。
## Requirements
### R3.1 编译器输出 layer manifest
`<outDir>/manifest.json`,形状见父任务 `design.md` §3.2。要点:
- 每个图层声明 `source`(geojson 文件名)、`role`、以及渲染角色所需的 `materialLayer`
- `role: "semantic"` 显式标记不渲染的图层 —— 把省略变成声明
- `splitBy` 表达按属性分流到不同材质的逻辑
(当前 `generate_scene.py:815-819` 硬编码的 `color != "white"` / `color == "yellow"`)
- 材质本体(颜色、z 高度、贴图)**仍归宿主** `catalog.py::MATERIALS`;
编译器不懂渲染,只声明"我有哪些图层、什么角色、该用哪个材质槽"
### R3.2 Blender 侧改造
- `generate_scene.py` 内道路分支抽为 `blender/osmassets/native_roads.py`
- 新模块读 manifest 遍历,不再查硬编码表
- 删除 `catalog.NATIVE_ROAD_LAYERS`
- 建筑(`handle_building` / `dispatch_ways`)、植被、水体**保持原位不动**
### R3.3 契约版本处理
新增 `manifest.json` 是**向后兼容的增量**(旧消费方忽略未知文件即可),
但 Blender 改为依赖它之后就成了必需项。
- 契约文档记录:`manifest.json` 自 v1.1 起为必需输出
- 宿主声明所需最低契约版本
### R3.4 跨层一致性检查
按 `.trellis/spec/guides/cross-layer-thinking-guide.md`:
本改动同时触碰 JS(编译器输出)、Python(Blender 消费)、契约文档三层,
必须走该指南的检查清单。
## Acceptance Criteria
- [x] AC3.1 编译器输出 `manifest.json`,两个有效区域(`fengshu-er-road`、`nantaizi-lake-innovation-valley`)均含全部 12 图层声明
- [x] AC3.2 `catalog.NATIVE_ROAD_LAYERS` 已删除,Blender 无硬编码道路图层表
- [x] AC3.3 `.blend` 结构摘要对 Phase 0 基线一致
(走 `.trellis/spec/guides/artifact-parity-guide.md`)
- [x] AC3.4 **实测**:向编译器加一个 throwaway 图层 + manifest 声明,
不改宿主任何代码,跑 blender 阶段确认它被渲染出来;验证后回滚该图层
(父任务 AC5,见 design §3.4)
- [x] AC3.5 `role: "semantic"` 的图层被 Blender 正确跳过(不产生几何)
- [x] AC3.6 `center_lines` 的 white/非 white 与 `lane_separators` 的 yellow/非 yellow
分流行为与改造前一致
- [x] AC3.7 建筑/植被/水体渲染代码未被修改(`git diff` 验证范围)
## 依赖与顺序
- **前置**:Phase 2 完成(编译器已独立,manifest 才有"跨仓库契约"的意义)
- 与 Phase 4 无依赖,可并行
- 完成本阶段后,父任务 Goal 中的「道路与建筑渲染分离」才算达成
## 风险
| 风险 | 缓解 |
|---|---|
| `splitBy` 表达力不足,覆盖不了现有分流逻辑 | 先枚举 `generate_scene.py` 里全部分流分支,再定 manifest schema |
| 材质槽名在两侧漂移 | manifest 里的 `materialLayer` 必须能被宿主校验:Blender 侧加断言,未知材质槽直接报错而非静默跳过 |
| `.blend` 结构摘要对比粒度不够,漏掉几何差异 | 除结构摘要外,加渲染预览图人工对照 |
## Out of Scope
- 材质定义搬去编译器(材质属渲染,归宿主)
- osm2streets legacy 图层表 `ROAD_LAYERS` 的改动
- 建筑/植被/水体渲染逻辑
@@ -0,0 +1,19 @@
# P3 Debug Probe Evidence
Date: 2026-08-26
A temporary, uncommitted compiler registry entry declared `debug_probe` as a
`marking` layer using the existing `road_surface` material slot. Its generated
GeoJSON reused the compiled road-surface collection only for this wiring test.
No host source was changed.
The compiler emitted 13 declared sources. Blender then generated
`/private/tmp/p3-debug-probe.blend`; `SCENE_DONE` reported
`"debug_probe": 30`. The Blender scene digest contains:
```json
{"name":"Road_debug_probe","vertices":274,"polygons":30}
```
The temporary registry entry was removed immediately after the proof. The
standard v0.2.0 compiler was then rerun to restore the normal 12-source output.
@@ -0,0 +1,34 @@
# Native Road 图层消费矩阵
调研日期:2026-08-25
## 证据
- 编译器在 `scripts/compile-native-roads.js:57,65-76` 声明并写出 12 个图层。
- Blender 在 `blender/generate_scene.py:796-834` 遍历
`catalog.NATIVE_ROAD_LAYERS`,只消费其中 10 个图层。
- 当前映射及基础高度来自 `blender/osmassets/catalog.py:53-64` 与 `ROAD_LAYERS`。
## 当前消费与 manifest 目标
| 编译器 source | 当前 Blender 行为 | 当前材质槽 / z 来源 | manifest 目标 |
|---|---|---|---|
| `road_surface` | 直接渲染 | `road_surface` / `ROAD_LAYERS.road_surface` | `role: surface`, `materialLayer: road_surface` |
| `edge_lines` | 直接渲染 | `lane_separators` / `ROAD_LAYERS.lane_separators` | `role: marking`, `materialLayer: lane_separators` |
| `intersection_surface` | 直接渲染 | `intersection_surface` / `ROAD_LAYERS.intersection_surface` | `role: surface`, `materialLayer: intersection_surface` |
| `sidewalk_surface` | 直接渲染 | `sidewalks` / `ROAD_LAYERS.sidewalks` | `role: surface`, `materialLayer: sidewalks` |
| `lane_separators` | 按 `color` 分流 | 非 yellow: `lane_separators`; yellow: `native_lane_separator_yellow`; z 取 `lane_separators` | `role: marking`, `materialLayer: lane_separators`, `splitBy.color`(yellow 特例) |
| `center_lines` | 按 `color` 分流 | 非 white: `center_lines`; white: `native_center_line_white`; z 取 `center_lines` | `role: marking`, `materialLayer: center_lines`, `splitBy.color`(white 特例) |
| `direction_arrows` | 直接渲染 | `lane_arrows_webscale` / `ROAD_LAYERS.lane_arrows_webscale` | `role: marking`, `materialLayer: lane_arrows_webscale` |
| `turn_arrows` | 直接渲染 | `lane_arrows_webscale` / `ROAD_LAYERS.lane_arrows_webscale` | `role: marking`, `materialLayer: lane_arrows_webscale` |
| `crosswalks` | 直接渲染 | `crosswalks` / `ROAD_LAYERS.crosswalks` | `role: marking`, `materialLayer: crosswalks` |
| `vehicle_stop_lines` | 直接渲染 | `vehicle_stop_lines` / `ROAD_LAYERS.vehicle_stop_lines` | `role: marking`, `materialLayer: vehicle_stop_lines` |
| `lane_centerlines` | 不进入 Blender 遍历 | 无 | `role: semantic`,Blender 跳过 |
| `connectors` | 不进入 Blender 遍历 | 无 | `role: semantic`,Blender 跳过 |
## 结论与实施约束
- manifest 必须声明全部 12 个编译器图层,不能再用“未出现在列表中”表达不渲染。
- `role: semantic` 的两个图层不得读取 GeoJSON 或创建 Blender 几何。
- `splitBy` 至少需表达属性 `color` 的精确匹配与默认分支,且分流后沿用同一个基础材质槽的 z 值。
- Blender 消费 manifest 时,未知 `materialLayer`、缺失 source 文件、或 source 未在 manifest 声明都必须报错;不能静默跳过。
@@ -0,0 +1,26 @@
{
"id": "rc-p3-render-separation",
"name": "rc-p3-render-separation",
"title": "Phase 3:道路与建筑渲染分离",
"description": "编译器输出 layer manifest 自声明图层,Blender 改为读 manifest;道路渲染从 generate_scene.py 抽离,消除跨仓库重复图层表",
"status": "completed",
"dev_type": null,
"scope": null,
"package": null,
"priority": "P2",
"creator": "dingkang",
"assignee": "dingkang",
"createdAt": "2026-08-25",
"completedAt": "2026-08-26",
"branch": null,
"base_branch": "main",
"worktree_path": null,
"commit": null,
"pr_url": null,
"subtasks": [],
"children": [],
"parent": "08-25-road-compiler-extraction",
"relatedFiles": [],
"notes": "",
"meta": {}
}
@@ -0,0 +1,4 @@
{"_example": "Fill with {\"file\": \"<path>\", \"reason\": \"<why>\"}. Put spec/research files only — no code paths. Run `python3 .trellis/scripts/get_context.py --mode packages` to list available specs. Delete this line once real entries are added."}
{"file":".trellis/spec/blender/asset-generation.md","reason":"Asset compatibility"}
{"file":".trellis/spec/guides/artifact-parity-guide.md","reason":"Parity acceptance"}
{"file":".trellis/tasks/09-17-cesium-export-performance/research/triangulation-semantics.md","reason":"Source-backed optimization correctness"}
@@ -0,0 +1,15 @@
# Design
## Evidence and theory
Baseline profiler: 179.6 s total, 166 s in 6,917 automatic view-layer updates; all eight exports 4.4 s. Blender `bpy/ops.py` updates the view layer before and after operators. Object-local mesh preparation should not repeatedly evaluate unrelated scene objects. Modifier evaluation may depend on scene relations, so disabling update globally is unacceptable.
A previous direct-BMesh experiment used BEAUTY for quads, unlike Blender's Triangulate modifier SHORTEDGE default. Both use BM_mesh_triangulate. Match parameters and mesh attribute conversion before accepting a direct path; retain original behavior for shared meshes and unsupported custom data. Research official modifier conversion code to explain residual differences.
## Implementation boundaries
Only exporter mesh preparation plus focused verification tools. Early-return for no-op work before selecting objects. Prefer public data APIs for object-local operations; preserve scene evaluation for actual dependent modifiers. Keep original triangulation modifier semantics via batched evaluation if direct BMesh cannot prove equivalence. No monkeypatching Blender internals in production.
## Compatibility and rollback
Same CLI, completion markers, GLB set, ordering, metadata, materials, and source blend. Validation uses temporary output directories. Reject alternatives that alter geometry/UV/normals without an explained contract. Each optimization separately measurable and removable. Existing user changes outside the exporter remain untouched.
@@ -0,0 +1,4 @@
{"_example": "Fill with {\"file\": \"<path>\", \"reason\": \"<why>\"}. Put spec/research files only — no code paths. Run `python3 .trellis/scripts/get_context.py --mode packages` to list available specs. Delete this line once real entries are added."}
{"file":".trellis/spec/blender/asset-generation.md","reason":"Deterministic assets and shared mesh contract"}
{"file":".trellis/spec/guides/artifact-parity-guide.md","reason":"Output parity and control requirements"}
{"file":".trellis/tasks/09-17-cesium-export-performance/research/triangulation-semantics.md","reason":"Official source proof and safe alternatives"}
@@ -0,0 +1,11 @@
# Execution
- [x] Preserve original exporter and repeat unmodified control on Nantaizi without profiler; baseline second real area.
- [x] Record Blender source/API proof for proposed replacement operations, including triangulation defaults and conversion flags.
- [x] Implement exporter optimization through Trellis implement agent; main agent owns measurement and independent artifact comparisons.
- [x] Validate all GLBs against baseline and control; compare decoded geometry/attributes/images when digest is insufficient.
- [x] Run real Blender edge fixtures and existing pure Python tests.
- [x] Run fresh final benchmarks and cross-agent check; fix any findings.
- [x] Record results/spec contracts and report measured gain plus limitations. No automatic commit.
User approval: previous turn proposed preserving assets while eliminating redundant updates/modifier work; current user explicitly approved, with theory required. This records that accepted scope rather than requesting approval again.
@@ -0,0 +1,25 @@
# Cesium 导出性能优化与产物一致性验证
## Goal
将 Cesium 导出阶段从约 150 秒降至接近 15–20 秒,保持全部资产与视觉语义。用户在性能诊断之后明确同意优化,并要求每项操作有理论依据。
## Requirements
- 每项优化对应测量热点、Blender API/源码依据及可证伪的验证。
- 保留主场景、分类资产、三个动态信号资产、材质、贴图、节点与地理锚点。
- 不全局关闭依赖图更新;保留涉及修改器依赖的正确评估。
- 不降低几何精度、不改材质、删资产或修改浏览器流程。
- 不覆盖用户现有工作区修改;性能及 parity 产物写临时目录。
## Acceptance Criteria
- [x] 同一输入、无 profiler 的前后基准,记录实际耗时与提升倍率;接近 10 倍是目标,不能牺牲正确性。
- [x] 全部 GLB 通过既有结构摘要契约;深入检查几何、UV、法线、切线及纹理,不能通过扩大忽略名单隐藏差异。
- [x] 至少两份真实区域输入及针对共享网格、无修改器、既有 UV 的 Blender 验证。
- [x] 未改动代码 control 复测;相关现有测试通过。
- [x] 理论依据、验证结果、限制记录到任务研究与长期规范。
## Results
Nantaizi 173.227 → 15.905 秒(10.89x);Fengshu 36.891–41.396 → 5.638 秒(6.54–7.34x)。全部结构摘要通过。Nantaizi 解码属性零差异;Fengshu 仅树冠切线存在未改代码 control 已复现的一个四位小数舍入步长波动。详见 `research/measurements.md`,未扩展项目忽略名单。
@@ -0,0 +1,74 @@
// Diagnostic: run from repository root with two export directory arguments.
// Strict 1e-6 comparison; known control noise is reported, never suppressed.
const fs = require('fs');
const path = require('path');
const assert = require('assert/strict');
const crypto = require('crypto');
const {digest} = require(path.join(process.cwd(), 'scripts/glb-digest'));
function glb(file) {
const data = fs.readFileSync(file);
let json, bin;
for (let i=12; i<data.length;) {
const len=data.readUInt32LE(i), type=data.readUInt32LE(i+4);
if(type===0x4e4f534a) json=JSON.parse(data.subarray(i+8,i+8+len));
if(type===0x004e4942) bin=data.subarray(i+8,i+8+len);
i+=8+len;
}
function accessor(id) {
const a=json.accessors[id];
assert(!a.sparse, 'sparse accessor unsupported');
const v=json.bufferViews[a.bufferView];
const n={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT4:16}[a.type];
const [bytes,fn]={5120:[1,'readInt8'],5121:[1,'readUInt8'],5122:[2,'readInt16LE'],5123:[2,'readUInt16LE'],5125:[4,'readUInt32LE'],5126:[4,'readFloatLE']}[a.componentType];
const out=[];
for(let i=0;i<a.count;i++) for(let j=0;j<n;j++) {
out.push(bin[fn]((v.byteOffset||0)+(a.byteOffset||0)+i*(v.byteStride||n*bytes)+j*bytes));
}
return out;
}
function imageHash(image) {
const v=json.bufferViews[image.bufferView];
return crypto.createHash('sha256').update(bin.subarray(v.byteOffset||0,(v.byteOffset||0)+v.byteLength)).digest('hex');
}
return {json, accessor, imageHash};
}
const [before,after]=process.argv.slice(2);
let failures=0;
for(const file of fs.readdirSync(before).filter(f=>f.endsWith('.glb')).sort()) {
const issues=[];
try {
const da=digest(path.join(before,file)), db=digest(path.join(after,file));
for(const d of [da,db]) {delete d.fileBytes;delete d.buffers;delete d.counts.accessors;}
try {assert.deepEqual(da,db);} catch {issues.push('structural digest differs');}
const a=glb(path.join(before,file)),b=glb(path.join(after,file));
for(const key of ['nodes','scenes','scene','materials','textures','samplers','animations','skins','extensions','extensionsUsed','extensionsRequired']) {
assert.deepEqual(a.json[key],b.json[key],key);
}
assert.equal(a.json.meshes.length,b.json.meshes.length);
let maxError=0;
for(let m=0;m<a.json.meshes.length;m++) {
const am=a.json.meshes[m],bm=b.json.meshes[m];
assert.equal(am.name,bm.name);
assert.equal(am.primitives.length,bm.primitives.length);
for(let p=0;p<am.primitives.length;p++) {
const ap=am.primitives[p],bp=bm.primitives[p];
assert.equal(ap.material,bp.material);
assert.deepEqual(Object.keys(ap.attributes),Object.keys(bp.attributes));
for(const key of ['indices',...Object.keys(ap.attributes)]) {
const av=a.accessor(key==='indices'?ap.indices:ap.attributes[key]);
const bv=b.accessor(key==='indices'?bp.indices:bp.attributes[key]);
if(av.length!==bv.length) {issues.push(`${am.name}/${p}/${key}: count ${av.length} -> ${bv.length}`);continue;}
let error=0;
for(let i=0;i<av.length;i++) error=Math.max(error,Math.abs(av[i]-bv[i]));
maxError=Math.max(maxError,error);
if(error>(key==='indices'?0:1e-6)) issues.push(`${am.name}/${p}/${key}: max delta ${error}`);
}
}
}
assert.equal(a.json.images?.length||0,b.json.images?.length||0);
for(let i=0;i<(a.json.images||[]).length;i++) assert.equal(a.imageHash(a.json.images[i]),b.imageHash(b.json.images[i]));
console.log(file, issues.length?'FAIL':'PASS', 'max attribute delta',maxError,issues.slice(0,12));
} catch(e) {issues.push(e.message);console.log(file,'ERROR',e.message.slice(0,500));}
if(issues.length) failures++;
}
process.exitCode=failures?1:0;
@@ -0,0 +1,48 @@
# Performance and parity evidence (2026-09-17)
Environment: local Blender 4.5.12, same existing `.blend` per region, serial runs, all outputs in `/private/tmp/cesium-profile.9ODFNa`. Original exporter preserved there as `original_export_cesium.py`. No source scene or existing output overwritten.
## Measurements
| Input / implementation | Export function wall time |
| --- | ---: |
| Nantaizi original cProfile | 179.596 s |
| Nantaizi original control without profiler | 173.227 s |
| Nantaizi initial production candidate | 33.389 s |
| Nantaizi candidate with shared-mesh guards | 15.337 s |
| Nantaizi final fake-user guard correction | 15.905 s |
| Fengshu original | 41.396 s |
| Fengshu original second control | 36.891 s |
| Fengshu optimized | 5.527 s |
| Fengshu final fake-user guard correction | 5.638 s |
Time excludes Blender process startup; `measure.py` uses perf_counter around export() and per-function timing wrappers, no cProfile. Inputs/outputs and eight/seven export calls unchanged. Final Nantaizi speedup 10.89x; Fengshu 6.54–7.34x. Final Nantaizi eight GLBs again pass with zero decoded attribute delta. Both regions' metadata matches after normalizing output directory prefixes.
## Nantaizi parity
Unchanged control compared with original profiler output: all eight GLBs have identical project structural digests (existing unstable fields excluded), decoded indices/positions/UVs/normals/tangents/other attributes, full nodes/scenes/materials/textures/samplers and embedded image hashes. Maximum numeric delta 0. Initial and shared-guard production candidates both pass these exact comparisons.
## Fengshu control noise
All seven project structural digests match. Six GLBs' decoded attributes also match exactly. `vegetation.glb`, mesh `Tree_Natural_Crowns_DarkMesh`, TANGENT values vary by at most 0.00010001659393310547 between two **unmodified** runs. Optimized versus first baseline has the same maximum; versus second baseline 0.00010000169277191162. Positions, UVs, normals, indices, other meshes and embedded images match. This is not a broad tolerance waiver.
Installed `io_scene_gltf2/blender/exp/primitive_extract.py:1507` rounds tangents to `ROUNDING_DIGIT`, defined as 4 in `io/com/constants.py:159`. A 0.0001 difference is one exporter quantization step. Existing project digest ignores accessor/buffer layout noise, but no project ignore list was expanded for this work.
## Edge fixtures
`blender/tools/check_export_preparation.py` passed in real Blender using original exporter as reference and an unchanged control. Includes asymmetric quad/ngon triangle counts, authored UVs, shared meshes, custom normals, shape keys, Bevel, dependent Boolean, and fake retention user. Compares topology/vertex order/UV/normals/material slots/mesh names/custom properties/sharing/remaining modifiers. Uses 1e-6 numerical tolerance.
Independent review moved edit-mode selection into the cleanup try/finally and added an injected UV failure fixture asserting restoration of original scene/view layer/collection links and no scene leak. Expanded fixture passed after review. All 64 existing pure Python tests, Python compilation and `git diff --check` pass. No project Python lint/type-check configuration exists. No UI screenshot claim: visual semantics checked through decoded render attributes and identical image bytes; no browser rendering code changed.
Reproducible strict comparison: from repo root run `node .trellis/tasks/09-17-cesium-export-performance/research/compare-glb.cjs <baseline-directory> <candidate-directory>`. It reports the Fengshu control tangent noise as a failure at 1e-6, deliberately not masking it. Classify that one known result using the unchanged control evidence above; all project structural digest checks pass.
## Source-backed choices
- Public selection data API avoids operator entry/exit graph updates.
- Empty modifier stack returns before any selection/update.
- Same Triangulate modifier is evaluated in a batch; evaluated meshes copied before mutating original data; preserve all data layers. No BMesh approximation.
- Same UV operator runs one object at a time in a small temporary scene, switched through actual window.scene; normal graph updates stay enabled.
- Shared triangulation skipped using `ID_REAL_USERS = users - fake_user`, matching Blender's failure precondition.
- Unknown modifier stacks retain original ordering; no global monkey patch.
Failed temp_override-only UV investigation was stopped because Blender edit-mode poll requires consistent window scene context; production uses a real temporary scene/window switch instead. Diagnostic global update suppression and mismatched direct-BMesh experiment are not in production.
@@ -0,0 +1,82 @@
# Research: Triangulation semantics and output-preserving optimization
- Query: Explain the temporary direct-BMesh experiment's different GLB vertex counts and identify source-backed faster alternatives.
- Scope: mixed (project source, installed exporter, official Blender 4.5.0 source)
- Date: 2026-09-17
## Findings
### Confirmed algorithm mismatch in the experiment
`blender/export_cesium.py:531` creates a Triangulate modifier and only overrides `min_vertices = 4`. The temporary `/private/tmp/cesium-profile.9ODFNa/profile_export.py:42` instead passes `quad_method='BEAUTY', ngon_method='BEAUTY'` to BMesh.
Blender **4.5.0** `source/blender/makesdna/DNA_modifier_defaults.h:643-649` defines the modifier defaults as:
```
flag = 0
quad_method = MOD_TRIANGULATE_QUAD_SHORTEDGE
ngon_method = MOD_TRIANGULATE_NGON_BEAUTY
min_vertices = 4
```
Thus the experiment is not algorithm-equivalent: quads use shortest diagonal in the baseline and beauty in the experiment. This is a concrete reason to correct the experiment, not speculative parameter tuning. Do not rely on older Blender documentation's defaults; read a temporary modifier's RNA properties on the actual running version if supporting multiple Blender versions.
Both routes ultimately call `BM_mesh_triangulate` (official `MOD_triangulate.cc`, `bmo_triangulate.cc:29-44`). The modifier passes `tag_only=false`; the BMesh operator tags its supplied faces and passes `tag_only=true`. Supplying all eligible faces and matching quad/ngon methods aligns the core algorithm.
### Why GLB vertex counts can differ with equal triangles
Installed `/Applications/Blender.app/Contents/Resources/4.5/scripts/addons_core/io_scene_gltf2/blender/exp/primitive_extract.py:336-344` explicitly explains that Blender corner attributes are packed into per-vertex records for glTF. Deduplication at lines 825 and 900-901 uses the attribute record, not position alone. Normals, tangents and UV discontinuities therefore split vertices without changing triangle count. Changing the quad diagonal can change subsequent normals and UV unwrap even when all positions and triangle totals remain unchanged.
Project preparation order (`blender/export_cesium.py:670-676`) is triangulate then unwrap. Hence changing topology before `smart_project` can also change UV islands. Counts alone do not establish visual parity or identify which attribute actually changed in the existing artifacts; inspect decoded attribute arrays per mesh to attribute the observed count difference definitively.
### Remaining BMesh conversion differences
Official `MOD_triangulate.cc` sets `calc_face_normal=true`, `calc_vert_normal=false` and carries original-index custom-data masks through conversion. Python `BMesh.from_mesh` (`bmesh_py_types.cc:1376-1414`) defaults both normal flags to true; pass `face_normals=True, vertex_normals=False` to match the modifier's inputs more closely.
Modifier `flag=0` means **keep_custom_normals is false by default in 4.5.0**. Therefore do not claim custom-normal preservation is the established reason for this scene's discrepancy. If enabled, the modifier explicitly copies evaluated corner normals into a temporary CD_NORMAL layer and restores normalized custom normals after triangulation. Direct BMesh does not reproduce that explicit procedure automatically.
Python `BMesh.to_mesh` (`bmesh_py_types.cc:1201-1240`) uses `BM_mesh_bm_to_me`, updates shape-key indices/object remaps and tags geometry dirty; modifier output uses `BKE_mesh_from_bmesh_for_eval_nomain`. These are distinct conversion paths. Matching triangulation settings does not constitute a proof of byte-identical mesh output, ordering or custom data. Preserve the baseline fallback for multi-user meshes (`modifier_apply` refuses them); do not change shared topology as a performance side effect.
### Strongest semantic route: keep the actual modifier, batch evaluation
For simple single-user meshes without pre-existing modifiers or shape keys, add the same Triangulate modifier through the data API for all eligible objects, evaluate the dependency graph once, then obtain persistent meshes with `bpy.data.meshes.new_from_object(obj.evaluated_get(depsgraph), preserve_all_data_layers=True, depsgraph=depsgraph)`. Stage every result before replacing source data/removing modifiers, because mutation can invalidate evaluated state. This executes the actual modifier implementation instead of duplicating it in Python.
Official `rna_main_api.cc:1103-1123` says an original object produces undeformed geometry while an evaluated object produces final geometry with all modifiers; preserving all data layers requires a dependency graph. Official `rna_ID.cc:2447-2452` says `evaluated_get` only retrieves the **last** evaluation and does **not** ensure the graph is up to date. An explicit graph evaluation barrier after adding modifiers is mandatory; repeated evaluation per object defeats the optimization.
Limit this fast path to proven equivalent cases. Existing modifier stacks, hidden modifiers, failing modifiers, shape keys, shared meshes and inter-object dependencies are not generally equivalent to the current sequential `modifier_apply` loop. Keep the existing operator fallback for those cases until separately justified. New datablocks must preserve material slots, required custom properties and semantic names; parity must detect unintended instance splitting or GLB naming differences.
### Recommended decision
1. Correct the demonstrated quad-method mismatch before drawing conclusions from direct-BMesh measurements.
2. Prefer batched evaluation of the original modifier if exact parity remains the requirement; its geometric semantics have a stronger equivalence basis.
3. Keep graph updates at real dependency boundaries; never ship the temporary global `_view_layer_update` monkey patch.
4. Require decoded triangle attributes and existing project structure parity, including UVs/normals/tangents and dynamic/shared assets. Do not accept matching counts as sufficient evidence.
## Files found
- `blender/export_cesium.py` — preparation order and baseline modifier/UV operations.
- `/private/tmp/cesium-profile.9ODFNa/profile_export.py` — temporary monkey-patch and direct-BMesh experiment.
- `/Applications/Blender.app/Contents/Resources/4.5/scripts/addons_core/io_scene_gltf2/blender/exp/primitive_extract.py` — glTF corner-attribute splitting and deduplication.
## External references
All source references pinned to Blender `v4.5.0`:
- https://github.com/blender/blender/blob/v4.5.0/source/blender/makesdna/DNA_modifier_defaults.h#L643
- https://github.com/blender/blender/blob/v4.5.0/source/blender/modifiers/intern/MOD_triangulate.cc
- https://github.com/blender/blender/blob/v4.5.0/source/blender/bmesh/operators/bmo_triangulate.cc
- https://github.com/blender/blender/blob/v4.5.0/source/blender/python/bmesh/bmesh_py_types.cc#L1376
- https://github.com/blender/blender/blob/v4.5.0/source/blender/makesrna/intern/rna_main_api.cc#L1103
- https://github.com/blender/blender/blob/v4.5.0/source/blender/makesrna/intern/rna_ID.cc#L2447
## Related specs
- `.trellis/spec/blender/index.md` — Blender/standard-Python boundary and parity requirements.
- `.trellis/spec/blender/asset-generation.md` — deterministic geometry, shared meshes and dynamic export assets.
- `.trellis/spec/blender/testing.md` — mathematical expectations and real Blender parity.
## Caveats / Not Found
- Research only: no Blender runs or changes to product code were performed.
- The algorithm mismatch is proven from source; the exact per-attribute cause of every previously observed vertex-count change is not measured here.
- Batch evaluated-mesh conversion is a source-backed candidate, not a claim of verified output parity or measured speedup.
@@ -0,0 +1,26 @@
{
"id": "cesium-export-performance",
"name": "cesium-export-performance",
"title": "Cesium 导出性能优化与产物一致性验证",
"description": "",
"status": "completed",
"dev_type": null,
"scope": null,
"package": null,
"priority": "P2",
"creator": "dingkang",
"assignee": "dingkang",
"createdAt": "2026-09-17",
"completedAt": "2026-09-17",
"branch": null,
"base_branch": "experiment/road-compiler-rethink",
"worktree_path": null,
"commit": null,
"pr_url": null,
"subtasks": [],
"children": [],
"parent": null,
"relatedFiles": [],
"notes": "",
"meta": {}
}
@@ -0,0 +1 @@
{"_example": "Fill with {\"file\": \"<path>\", \"reason\": \"<why>\"}. Put spec/research files only — no code paths. Run `python3 .trellis/scripts/get_context.py --mode packages` to list available specs. Delete this line once real entries are added."}
@@ -0,0 +1,60 @@
# 本地构建控制台设计
## Architecture
新增 `npm run console` 启动的本机控制服务。服务只绑定 `127.0.0.1`,启动后打开默认浏览器;它以 Node 内置 `http` 提供 JSON API、Server-Sent Events(SSE)和无构建的静态 HTML/CSS/JS。首版不引入 React、Vite、Electron 或数据库。
```text
browser UI
│ HTTP / SSE, localhost only
▼
scripts/build-console.js
├─ configs + diagnostics + stage manifests → area/history cards
├─ import OSM/ZIP → inputs/console/<config-key>/ + ownership record
├─ spawn node scripts/build-area.js → streamed build log/job state
├─ serve outputs/<area-dir>/ as read-only preview assets
└─ validated cleanup target → macOS Trash
```
`build-area.js` continues to own all pipeline stages. The console does not import it in-process or duplicate its business logic; it starts it as a child process with `--config` and optional `--stages`, collecting stdout/stderr for the UI.
## Data and ownership
At startup the service enumerates `config/areas/*.json`, calls the existing `readAreaConfig()` / diagnostics APIs, and reads stage manifests. Those files are the history source of truth.
The import form copies selected OSM and ZIP files into `inputs/console/<config-key>/`. A local ignored ownership record under `.build-console/areas/<config-key>.json` records the configuration filename, managed input paths, ZIP hash, and output directory. It exists only to prove which files the console may clean; ordinary historical configs with external paths remain usable but do not grant deletion authority over those sources.
The ZIP `areaId` is immutable and becomes configuration `id`. Because an explicit Save As must not collide with its source config or generated output, the user-facing configuration key is a separate filesystem-safe slug; a saved copy gets a distinct config filename and explicit `outputs.areaDir` / `fileStem` derived from that key. The package contract keeps the original ZIP `areaId`.
## User flow
1. **Welcome / readiness**: display a short three-step guide and checks for Node, Blender, writable managed input directory, and existing areas. Explain that OSM supplies buildings/landscape while ZIP supplies authoritative roads.
2. **History**: show every `config/areas/*.json` as a card with input locations, tree style, output health, last successful stage and links to preview/package when present.
3. **Import / Save As**: choose OSM and ZIP, inspect ZIP contract and locked `areaId`, choose tree style, select a config key, then copy inputs and atomically write a new config. Existing config edits default to Save As; overwrite requires a typed/explicit confirmation.
4. **Build**: choose standard full build or individual existing stages. At most one build job may run; SSE reports stdout/stderr, named stage progression, completion marker and a concise actionable error summary.
5. **Preview**: link to a read-only `/artifacts/<config-key>/...` route that serves the generated preview HTML and its package-relative assets. Vehicle selection stays in the existing preview runtime, rather than changing build artifacts.
6. **Cleanup**: cards and multi-select provide (a) Clear build outputs and (b) Remove area. A confirmation screen lists regions, file counts and byte totals. Targets must be canonically located under allowed project roots. macOS Finder moves them to Trash; it never calls recursive shell deletion.
## API boundary
- `GET /api/health`, `/api/areas`, `/api/options`: readiness, history cards and supported tree styles.
- `POST /api/import/inspect`: multipart/selected file validation without promoting files; verifies ZIP root/contract/areaId via the shared native package validator.
- `POST /api/areas`: copy managed inputs, write ownership record and new config atomically.
- `POST /api/areas/:key/build`: create one build job; `GET /api/jobs/:id/events` streams SSE logs and terminal state.
- `POST /api/cleanup/preview` and `/api/cleanup/confirm`: separate target computation from confirmation, avoiding a stale/hidden destructive scope.
- `GET /artifacts/:key/*`: safely serve only the selected area output root; reject traversal and arbitrary filesystem paths.
Requests are same-origin, localhost-only and JSON validated. File names are normalized to generated safe names; filesystem writes use staging plus rename. Cleanup uses `realpath` containment checks immediately before moving targets to Trash.
## Compatibility and rollout
- Existing commands and hand-authored configurations remain unchanged.
- Existing configs are visible even when their input paths are external; they are never copied or marked owned until a user explicitly imports/saves a console-managed version.
- The console's new local state and managed imports are gitignored. Normal area config files remain reviewable JSON.
- Rollback is deleting the new console-specific files and npm script; it never changes pipeline output contracts.
## Validation strategy
- Unit tests for config/history discovery, ZIP inspection, ownership classification, safe path rejection, Save As collision handling, cleanup plan creation and destructive-target containment.
- HTTP tests for localhost binding, API validation, SSE job lifecycle and artifact traversal rejection.
- Manual smoke test: import OSM+ZIP, save, full build, preview, clear outputs, rebuild, remove area, restore from Trash if needed.
@@ -0,0 +1 @@
{"_example": "Fill with {\"file\": \"<path>\", \"reason\": \"<why>\"}. Put spec/research files only — no code paths. Run `python3 .trellis/scripts/get_context.py --mode packages` to list available specs. Delete this line once real entries are added."}
@@ -0,0 +1,22 @@
# 本地构建控制台实施计划
1. Create a dependency-free console server and static UI shell; add `npm run console`, localhost-only binding, automatic browser launch and environment/readiness endpoint.
2. Extract/reuse small pipeline-facing helpers for area discovery, diagnostics summary, native ZIP inspection and supported tree-style options. Do not import `build-area.js` as a module.
3. Implement history cards and onboarding: config scanning, manifest/status summary, input descriptions, package/preview links and model option selection.
4. Implement safe import and Save As: upload/copy OSM+ZIP into ignored managed storage, inspect ZIP contract/areaId, atomically write a config with collision-safe output overrides, and record ownership.
5. Implement serialized build jobs with child-process log capture, SSE progress, completion/failure states, and links to the existing generated preview.
6. Implement cleanup planning and confirmation. Validate canonical paths, move only allowed targets to macOS Trash, and cover single/batch clear-output versus remove-area paths.
7. Add focused Node HTTP/unit tests, update README with launch/use/troubleshooting guidance, then manually run the actual imported-area build and preview flow.
## Validation commands
- `node --check` for each new Node entry/helper.
- focused console test command added to `package.json`.
- existing `npm run test:native-road-package`, `npm run test:build-stages`, `npm run test:preview-assets`, and `npm run test:package-contract`.
- `npm run console`, import a valid OSM/ZIP fixture, run a full build, open preview, and exercise both cleanup scopes.
## Risk controls and rollback
- Never bind beyond loopback; do not serve arbitrary paths or allow parallel builds.
- Validate cleanup targets after confirmation and immediately before Trash movement; no `rm -rf` implementation.
- If the UI path fails, existing CLI remains the supported fallback. Removing console files/script rolls back the feature without changing existing area data or output contracts.
@@ -0,0 +1,45 @@
# 本地构建控制台
## Goal
提供一个在本机 localhost 运行的图形控制台,使用户无需记忆命令行即可选择或导入道路构建输入、执行现有构建管线、查看进度并打开 Cesium 预览。
## Confirmed facts
- 当前唯一的交互入口是 `scripts/interactive-build.js`:它枚举 `config/areas/*.json`、选择阶段后调用 `scripts/build-area.js`。
- `build-area.js` 是构建、Blender/Cesium 子进程、package 发布和 preview 写入的唯一所有者;控制台必须调用它,不能复制阶段实现。
- native 区域配置通过 `nativeRoadPackage` 引用 `native-road-package/v1.1` ZIP;导入器会验证 ZIP 契约和 `areaId`,并将其安全解压到私有 pipeline cache。
- Blender 与本地文件系统不能由纯静态浏览器页面直接访问,因此入口必须由本机服务配合浏览器 UI 组成。
- 现有配置及其 `outputs/<area>/_pipeline/stages/*.manifest.json` 是历史输入和构建历史的可读取事实源,不能另建会漂移的重复数据库。
## Requirements
- R1: 以 localhost 页面作为首版交付方式;命令行入口继续可用。
- R2: 首页自动枚举并导入 `config/areas/*.json`,以区域卡片呈现可复用配置、输入摘要、最近构建状态、预览与发布包入口。
- R3: 用户可从界面选择 OSM 与 native-road ZIP,读取 ZIP 的 `areaId` 和契约信息,并在构建前给出 OSM/ZIP/区域 ID 的明确校验反馈。
- R3.1: 成功导入的 OSM 与道路 ZIP 复制到项目托管输入目录;新配置引用托管副本,保证可复现且不依赖 `/tmp` 或用户外部路径。
- R4: 保持首版简单:构建前仅可选择项目已有的植被/树木风格;Cesium 预览中可选择车辆模型。两者分别影响静态场景与演示运行时。
- R5: 用户可选构建阶段并启动现有 build-area 管线,看到实时阶段状态、日志、产物链接与可行动的失败说明。
- R6: 对历史配置的修改默认另存为新配置;覆盖已有配置必须是显式确认操作。
- R6.1: 控制台提供单项清理与批量清理,仅处理它创建的托管输入和本项目生成的区域输出;绝不删除用户在项目外选择的原始文件。首版清理统一移入系统废纸篓,保留恢复机会。
- R6.2: 清理范围分为两级,且单项、批量均适用:`清理构建产物` 仅移除区域输出并保留配置和托管输入;`移除区域` 将区域配置、控制台托管输入和区域输出一并移入废纸篓。批量操作必须先展示受影响区域和文件数,再允许确认。
- R7: 产品内置首次使用引导:说明 OSM、道路 ZIP、模型选项、构建阶段、预览入口和 Blender/Node 环境检查,不以外部 README 代替。
## Out of scope
- 改写道路编译器、ZIP 契约、Blender 几何或 Cesium 预览运行时。
- 远程部署、多用户协作、云端构建或将本机文件上传到第三方服务。
- 第一阶段打包为 macOS `.app`;待 localhost 工作流验证后再评估。
## Acceptance criteria
- [ ] 用户可在浏览器中启动、选择历史区域并重新执行一次已有构建,无需手写 CLI 参数。
- [ ] 用户可导入 OSM 与有效道路 ZIP,且在启动 Blender 前看到 ZIP contract / areaId / 文件缺失的校验结果。
- [ ] 用户可保存为新的区域配置而不改变原配置;显式覆盖有确认保护。
- [ ] 页面可展示构建阶段、实时日志、成功后的 preview URL 与 `package/manifest.json`。
- [ ] 首次使用者可仅依照页面引导完成一次输入、构建和预览,并理解失败时下一步怎么做。
## Technical notes
- native-road ZIP 的 `areaId` 与区域配置 `id` 必须相等;控制台应从 ZIP 读取并锁定该 ID,避免提供必然失败的可编辑字段。
- 控制台管理的输入需要有可判定 ownership 的目录/记录,才能安全实施区域级清理;历史配置引用的外部路径始终视为只读、非托管输入。
@@ -0,0 +1,26 @@
{
"id": "local-build-console",
"name": "local-build-console",
"title": "本地构建控制台",
"description": "",
"status": "completed",
"dev_type": null,
"scope": null,
"package": null,
"priority": "P2",
"creator": "dingkang",
"assignee": "dingkang",
"createdAt": "2026-09-17",
"completedAt": "2026-09-22",
"branch": null,
"base_branch": "experiment/road-compiler-rethink",
"worktree_path": null,
"commit": null,
"pr_url": null,
"subtasks": [],
"children": [],
"parent": null,
"relatedFiles": [],
"notes": "",
"meta": {}
}
+9 -3
View File
@@ -8,8 +8,8 @@
<!-- @@@auto:current-status -->
- **Active File**: `journal-1.md`
- **Total Sessions**: 41
- **Last Active**: 2026-08-24
- **Total Sessions**: 47
- **Last Active**: 2026-09-22
<!-- @@@/auto:current-status -->
---
@@ -19,7 +19,7 @@
<!-- @@@auto:active-documents -->
| File | Lines | Status |
|------|-------|--------|
| `journal-1.md` | ~887 | Active |
| `journal-1.md` | ~1022 | Active |
<!-- @@@/auto:active-documents -->
---
@@ -29,6 +29,12 @@
<!-- @@@auto:session-history -->
| # | Date | Title | Commits | Branch |
|---|------|-------|---------|--------|
| 47 | 2026-09-22 | 完成本地构建控制台 | `3760650` | `experiment/road-compiler-rethink` |
| 46 | 2026-09-17 | Cesium 导出性能优化与一致性验证 | `c6cce44` | `experiment/road-compiler-rethink` |
| 45 | 2026-08-26 | Complete manifest-driven native road rendering | `6201270` | `experiment/road-compiler-rethink` |
| 44 | 2026-08-26 | Complete external road compiler split | `5cde080`, `7d4b3b5` | `experiment/road-compiler-rethink` |
| 43 | 2026-08-25 | Extract road compiler package boundary | `73707da`, `d5c58b5`, `f542a64`, `284d3db`, `2469cfd` | `experiment/road-compiler-rethink` |
| 42 | 2026-08-25 | Freeze native road parity baseline | `e7bc7f8` | `experiment/road-compiler-rethink` |
| 41 | 2026-08-24 | Use live V2X vehicle streams only | `b7031f1` | `fengshu-er-road` |
| 40 | 2026-08-24 | Stabilize Fengshu native road compilation | `f1f829c` | `fengshu-er-road` |
| 39 | 2026-08-18 | Complete native-only pipeline replacement | `9e0e25a` | `feature/native-road-compiler` |
+135
View File
@@ -885,3 +885,138 @@ Replaced the Cesium preview's simulated vehicle route with authenticated OBU and
### Status
[OK] **Completed**
## Session 42: Freeze native road parity baseline
**Date**: 2026-08-25
**Task**: Freeze native road parity baseline
**Branch**: `experiment/road-compiler-rethink`
### Summary
Completed and archived Phase 0: documented native-road-package/v1, added strict road parity snapshots and two valid-area baselines, excluded abandoned hanyang-block, and verified deterministic recompilation including signal regeneration.
### Git Commits
| Hash | Message |
|------|---------|
| `e7bc7f8` | (see git log) |
### Status
[OK] **Completed**
## Session 43: Extract road compiler package boundary
**Date**: 2026-08-25
**Task**: Extract road compiler package boundary
**Branch**: `experiment/road-compiler-rethink`
### Summary
Completed and archived Phase 1: moved native road compiler, checks, workbench, signal schema, OSM parser, and fixtures into packages/road-compiler; introduced RoadCompilerInput mapping; verified two-area parity and a privileged full Fengshu build.
### Git Commits
| Hash | Message |
|------|---------|
| `73707da` | (see git log) |
| `d5c58b5` | (see git log) |
| `f542a64` | (see git log) |
| `284d3db` | (see git log) |
| `2469cfd` | (see git log) |
### Status
[OK] **Completed**
## Session 44: Complete external road compiler split
**Date**: 2026-08-26
**Task**: Complete external road compiler split
**Branch**: `experiment/road-compiler-rethink`
### Summary
Split road compiler into private road-compiler repository with history, pushed v0.1.2, migrated host to exact-tag CLI consumption, removed in-host package, passed regression tests and two-area parity.
### Git Commits
| Hash | Message |
|------|---------|
| `5cde080` | (see git log) |
| `7d4b3b5` | (see git log) |
### Status
[OK] **Completed**
## Session 45: Complete manifest-driven native road rendering
**Date**: 2026-08-26
**Task**: Complete manifest-driven native road rendering
**Branch**: `experiment/road-compiler-rethink`
### Summary
Published compiler v0.2.2, switched Blender to validated native-road manifests, proved debug-probe extensibility, and verified Blender parity for fengshu-er-road.
### Git Commits
| Hash | Message |
|------|---------|
| `6201270` | (see git log) |
### Status
[OK] **Completed**
## Session 46: Cesium 导出性能优化与一致性验证
**Date**: 2026-09-17
**Task**: Cesium 导出性能优化与一致性验证
**Branch**: `experiment/road-compiler-rethink`
### Summary
基于 Blender 依赖图机制批量三角化并隔离 UV 操作;南太子湖 173.2→15.9 秒,枫树二路 36.9–41.4→5.6 秒。保留全部资产;任务已归档。
### Git Commits
| Hash | Message |
|------|---------|
| `c6cce44` | (see git log) |
### Testing
- [OK] 64 项 Python 测试、真实 Blender 特殊网格与异常清理测试通过;两区域 GLB 结构一致,南太子湖逐属性零差异;枫树树冠切线 0.0001 波动由未改代码 control 复现。
### Status
[OK] **Completed**
## Session 47: 完成本地构建控制台
**Date**: 2026-09-22
**Task**: 完成本地构建控制台
**Branch**: `experiment/road-compiler-rethink`
### Summary
提交本地构建控制台及预览逻辑改动,归档 09-17-local-build-console;通过 preview-assets 与 native-preview-traffic 测试。
### Git Commits
| Hash | Message |
|------|---------|
| `3760650` | (see git log) |
### Status
[OK] **Completed**
+138 -11
View File
@@ -496,6 +496,14 @@ def make_export_material(material):
return result
def select_only(obj):
"""Change selection without an operator's scene-evaluation barriers."""
for selected in bpy.context.selected_objects:
selected.select_set(False)
obj.select_set(True)
bpy.context.view_layer.objects.active = obj
def unwrap_mesh(obj):
if obj.type != "MESH" or not obj.data.polygons:
return
@@ -504,23 +512,19 @@ def unwrap_mesh(obj):
# meshes arrive without a UV layer, so that is the reliable discriminator.
if obj.data.uv_layers:
return
bpy.ops.object.select_all(action="DESELECT")
obj.select_set(True)
bpy.context.view_layer.objects.active = obj
select_only(obj)
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.select_all(action="SELECT")
try:
bpy.ops.mesh.select_all(action="SELECT")
bpy.ops.uv.smart_project(island_margin=0.025, area_weight=0.0)
finally:
bpy.ops.object.mode_set(mode="OBJECT")
def apply_mesh_modifiers(obj):
if obj.type != "MESH":
if obj.type != "MESH" or not obj.modifiers:
return
bpy.ops.object.select_all(action="DESELECT")
obj.select_set(True)
bpy.context.view_layer.objects.active = obj
select_only(obj)
for modifier in list(obj.modifiers):
try:
bpy.ops.object.modifier_apply(modifier=modifier.name)
@@ -528,6 +532,11 @@ def apply_mesh_modifiers(obj):
pass
def mesh_has_multiple_users(mesh):
# modifier_apply uses ID_REAL_USERS, excluding the fake retention user.
return mesh.users - int(mesh.use_fake_user) > 1
def triangulate_mesh(obj):
"""Split n-gons into triangles ahead of the exporter.
@@ -544,11 +553,14 @@ def triangulate_mesh(obj):
"""
if obj.type != "MESH" or not obj.data.polygons:
return
# modifier_apply rejects multi-user data before evaluating geometry. Avoid
# creating a modifier and evaluating the whole scene only to remove it in
# the failure handler below; keeping this mesh unchanged is intentional.
if mesh_has_multiple_users(obj.data):
return
if all(len(polygon.vertices) <= 3 for polygon in obj.data.polygons):
return
bpy.ops.object.select_all(action="DESELECT")
obj.select_set(True)
bpy.context.view_layer.objects.active = obj
select_only(obj)
modifier = obj.modifiers.new("ExportTriangulate", "TRIANGULATE")
modifier.min_vertices = 4
try:
@@ -559,6 +571,120 @@ def triangulate_mesh(obj):
obj.modifiers.remove(modifier)
def batch_triangulate_meshes(candidates):
"""Evaluate independent Triangulate modifiers in one dependency graph pass.
This uses the actual modifier (including the running Blender version's
defaults), not a BMesh reimplementation. new_from_object on an evaluated
object copies its final geometry; preserve_all_data_layers retains UVs and
other mesh attributes. Stage every result before editing original objects:
assigning data or removing a modifier invalidates evaluated state.
Existing stacks can depend on other objects' unmodified geometry. Leave
their sequential application order untouched, including stacks outside the
export subset. Multi-user meshes, shape keys and custom normals retain the
original operator path, whose restrictions are part of the export behavior.
"""
if any(obj.modifiers for obj in bpy.context.scene.objects):
return
pending = []
for obj in candidates:
mesh = obj.data
if (mesh.users != 1 or mesh.use_fake_user or mesh.shape_keys
or mesh.has_custom_normals or mesh.library or obj.library
or not any(len(p.vertices) > 3 for p in mesh.polygons)):
continue
modifier = obj.modifiers.new("ExportTriangulate", "TRIANGULATE")
modifier.min_vertices = 4
pending.append((obj, mesh, modifier))
if not pending:
return
staged = []
try:
# evaluated_get itself does not update the graph. This explicit barrier
# is required after adding all modifiers, and is intentionally not
# repeated for each object.
depsgraph = bpy.context.evaluated_depsgraph_get()
depsgraph.update()
for obj, source, modifier in pending:
mesh = bpy.data.meshes.new_from_object(
obj.evaluated_get(depsgraph), preserve_all_data_layers=True,
depsgraph=depsgraph)
staged.append((obj, source, modifier, mesh))
for key in source.keys():
mesh[key] = source[key]
except Exception:
for _, _, _, mesh in staged:
bpy.data.meshes.remove(mesh)
for obj, _, modifier in pending:
obj.modifiers.remove(modifier)
raise
for obj, source, modifier, mesh in staged:
name = source.name
obj.data = mesh
obj.modifiers.remove(modifier)
bpy.data.meshes.remove(source)
mesh.name = name
def unwrap_meshes_in_work_scene(candidates):
"""Run the unchanged per-object UV operator against a small scene.
UV projection operates on the original mesh in edit mode, not evaluated
scene geometry. Link the original object into a temporary scene one at a
time so operator barriers do not reevaluate every unrelated scene object.
Switch the window's scene, not just context object overrides: edit-mode
operators require a consistent window/scene/view-layer context.
"""
window = bpy.context.window
if window is None or any(obj.modifiers for obj in bpy.context.scene.objects):
return
# A later fallback triangulation must precede UV projection. Shared meshes
# are also safe here: modifier_apply refuses them, so their topology stays
# unchanged in the original preparation loop.
pending = [obj for obj in candidates if not obj.modifiers
and not obj.data.uv_layers and obj.data.polygons
and (mesh_has_multiple_users(obj.data)
or all(len(p.vertices) <= 3 for p in obj.data.polygons))]
if not pending:
return
original_scene = window.scene
original_layer = window.view_layer
work_scene = bpy.data.scenes.new("Cesium UV work scene")
try:
window.scene = work_scene
for obj in pending:
# Shared mesh UVs are already prepared by their first instance.
if obj.data.uv_layers:
continue
work_scene.collection.objects.link(obj)
try:
unwrap_mesh(obj)
finally:
work_scene.collection.objects.unlink(obj)
finally:
window.scene = original_scene
window.view_layer = original_layer
bpy.data.scenes.remove(work_scene)
def prepare_independent_meshes(candidates):
"""Keep dependency-bearing modifier stacks on the sequential legacy path."""
# Bevel reads this object's geometry and vertex groups. Unlike Boolean,
# Shrinkwrap or Geometry Nodes it cannot read another object's mesh. Apply
# it with the original operator before batching independent triangulation.
# Unknown stack types deliberately keep the original preparation order.
if any(modifier.type != "BEVEL"
for obj in bpy.context.scene.objects for modifier in obj.modifiers):
return
for obj in candidates:
apply_mesh_modifiers(obj)
batch_triangulate_meshes(candidates)
unwrap_meshes_in_work_scene(candidates)
def export_glb(filepath, meshes):
"""Export a prepared object subset without changing authoring visibility."""
bpy.ops.object.select_all(action="DESELECT")
@@ -654,6 +780,7 @@ def export(args):
and not obj.hide_viewport and not obj.hide_render]
total_candidates = max(1, len(candidates))
progress.update("prepare scene", 3, "%d mesh objects" % len(candidates))
prepare_independent_meshes(candidates)
for index, obj in enumerate(candidates, 1):
if any(c.name == "06_TrafficSignalsDynamic" for c in obj.users_collection):
groups = {slot.material.name for slot in obj.material_slots if slot.material}
+6 -24
View File
@@ -57,6 +57,7 @@ from osmassets import fountain as _fountain # noqa: E402
from osmassets import water as _water # noqa: E402
from osmassets import grass as _grass # noqa: E402
from osmassets import roads as _roads # noqa: E402
from osmassets import native_roads as _native_roads # noqa: E402
from osmassets import scrub as _scrub # noqa: E402
from osmassets import tree as _tree # noqa: E402
from osmassets import traffic_signals as _traffic_signals # noqa: E402
@@ -667,6 +668,8 @@ def build(args):
catalog.MATERIALS["native_center_line_white"])
road_mats["native_lane_separator_yellow"] = material_from_spec(
catalog.MATERIALS["native_lane_separator_yellow"])
road_mats["native_island_green"] = material_from_spec(
catalog.MATERIALS["native_island_green"])
traffic_signal_mats = {
"metal": material_from_spec(catalog.MATERIALS["traffic_signal_metal"]),
"housing": material_from_spec(catalog.MATERIALS["traffic_signal_housing"]),
@@ -798,30 +801,9 @@ def build(args):
if native_road_dir:
if not os.path.isdir(native_road_dir):
raise RuntimeError("--native-road directory does not exist: " + native_road_dir)
material_layers = {layer["id"]: layer for layer in catalog.ROAD_LAYERS}
for source in catalog.NATIVE_ROAD_LAYERS:
target = source["material_layer"]
layer = material_layers[target]
source_path = os.path.join(native_road_dir, "layers", source["source"] + ".geojson")
if not os.path.isfile(source_path):
raise RuntimeError("Native road layer is missing: " + source_path)
if source["source"] == "center_lines":
count = _roads.assemble_geojson_layer(
source_path, source["source"], projector, roads_c,
road_mats[target], layer["z"],
lambda props: props.get("color") != "white")
count += _roads.assemble_geojson_layer(
source_path, source["source"] + "_white", projector, roads_c,
road_mats["native_center_line_white"], layer["z"],
lambda props: props.get("color") == "white")
elif source["source"] == "lane_separators":
count = _roads.assemble_geojson_layer(source_path, source["source"], projector, roads_c, road_mats[target], layer["z"], lambda props: props.get("color") != "yellow")
count += _roads.assemble_geojson_layer(source_path, source["source"] + "_yellow", projector, roads_c, road_mats["native_lane_separator_yellow"], layer["z"], lambda props: props.get("color") == "yellow")
else:
count = _roads.assemble_geojson_layer(
source_path, source["source"], projector, roads_c,
road_mats[target], layer["z"])
road_counts[source["source"]] = count
material_layers = {layer["id"]: road_mats.get(layer["id"]) for layer in catalog.ROAD_LAYERS}
material_layers.update({"native_center_line_white": road_mats["native_center_line_white"], "native_lane_separator_yellow": road_mats["native_lane_separator_yellow"], "native_island_green": road_mats["native_island_green"]})
road_counts.update(_native_roads.assemble(native_road_dir, projector, roads_c, material_layers))
elif geojson_dir and os.path.isdir(geojson_dir):
for problem in catalog.check_layers(geojson_dir):
print("Layer catalog warning:", problem)
+5 -14
View File
@@ -50,20 +50,6 @@ SCENE_STYLE_FILE = "osm2streets_scene_style.json"
# Native-road output intentionally maps into existing scene material layers.
# It is a provider adapter, not a second scene-layer registry.
NATIVE_ROAD_LAYERS = (
{"source": "road_surface", "material_layer": "road_surface"},
{"source": "edge_lines", "material_layer": "lane_separators"},
{"source": "intersection_surface", "material_layer": "intersection_surface"},
{"source": "sidewalk_surface", "material_layer": "sidewalks"},
{"source": "lane_separators", "material_layer": "lane_separators"},
{"source": "center_lines", "material_layer": "center_lines"},
{"source": "direction_arrows", "material_layer": "lane_arrows_webscale"},
{"source": "turn_arrows", "material_layer": "lane_arrows_webscale"},
{"source": "crosswalks", "material_layer": "crosswalks"},
{"source": "vehicle_stop_lines", "material_layer": "vehicle_stop_lines"},
)
# Material specs. `kind` selects the builder:
# solid — flat base colour
# textured — Poly Haven diffuse + normal, optionally tinted
@@ -208,6 +194,11 @@ MATERIALS = {
"native_lane_separator_yellow": {"kind": "solid", "name": "Native Lane Separator Yellow",
"color": (0.94, 0.58, 0.06), "roughness": 0.52,
"cesium": {"base_color": (0.94, 0.58, 0.06)}},
# Safety-island planting follows the neutral green-grey map fill and is
# intentionally opaque so it does not blend with the asphalt below.
"native_island_green": {"kind": "solid", "name": "Native Island Green",
"color": (0.0382, 0.4793, 0.1441), "roughness": 0.92,
"cesium": {"base_color": (0.0382, 0.4793, 0.1441)}},
}
+95
View File
@@ -0,0 +1,95 @@
"""Pure-Python validation for native-road package manifests."""
import json
import os
CONTRACT = "native-road-package/v1.1"
RENDERABLE_ROLES = ("surface", "marking")
VALID_ROLES = RENDERABLE_ROLES + ("semantic",)
def _error(message):
raise RuntimeError("Invalid native road manifest: " + message)
def _source_name(value):
return (isinstance(value, str) and value
and value == os.path.basename(value)
and value not in (".", ".."))
def _validate_split(source, split):
if not isinstance(split, dict):
_error("layer '%s' splitBy must be an object" % source)
prop = split.get("prop")
cases = split.get("cases")
if not isinstance(prop, str) or not prop or not isinstance(cases, list) or not cases:
_error("layer '%s' has an invalid splitBy" % source)
matches = set()
defaults = 0
for case in cases:
if not isinstance(case, dict) or not isinstance(case.get("material"), str):
_error("layer '%s' has an invalid splitBy case" % source)
is_default = case.get("default") is True
has_match = "match" in case
if is_default == has_match:
_error("layer '%s' splitBy cases need exactly one of match/default" % source)
if is_default:
defaults += 1
else:
match = case["match"]
if match in matches:
_error("layer '%s' has a duplicate splitBy match" % source)
matches.add(match)
if defaults != 1:
_error("layer '%s' splitBy needs exactly one default case" % source)
def load(native_road_dir):
"""Load a v1.1 manifest and ensure it declares exactly its GeoJSON files."""
manifest_path = os.path.join(native_road_dir, "manifest.json")
if not os.path.isfile(manifest_path):
raise RuntimeError("Native road manifest is missing: " + manifest_path)
try:
with open(manifest_path, "r", encoding="utf-8") as handle:
manifest = json.load(handle)
except (OSError, ValueError) as error:
raise RuntimeError("Could not read native road manifest: " + str(error)) from error
if not isinstance(manifest, dict) or manifest.get("contract") != CONTRACT:
_error("unsupported contract")
layers = manifest.get("layers")
if not isinstance(layers, list) or not layers:
_error("layers must be a non-empty array")
declared = set()
for spec in layers:
if not isinstance(spec, dict):
_error("layer entries must be objects")
source = spec.get("source")
role = spec.get("role")
if not _source_name(source) or source in declared or role not in VALID_ROLES:
_error("layer source or role is invalid")
declared.add(source)
if role in RENDERABLE_ROLES:
if not isinstance(spec.get("materialLayer"), str) or not spec["materialLayer"]:
_error("renderable layer '%s' needs materialLayer" % source)
if "splitBy" in spec:
_validate_split(source, spec["splitBy"])
elif "materialLayer" in spec or "splitBy" in spec:
_error("semantic layer '%s' must not declare rendering" % source)
layers_dir = os.path.join(native_road_dir, "layers")
if not os.path.isdir(layers_dir):
raise RuntimeError("Native road layers directory is missing: " + layers_dir)
published = {
name[:-8] for name in os.listdir(layers_dir)
if name.endswith(".geojson") and os.path.isfile(os.path.join(layers_dir, name))
}
if published != declared:
missing = sorted(declared - published)
extra = sorted(published - declared)
_error("declared GeoJSON mismatch (missing=%s, extra=%s)" % (missing, extra))
return manifest
+55
View File
@@ -0,0 +1,55 @@
"""Manifest-driven native road layer adapter."""
import os
from osmassets import catalog
from osmassets import native_road_manifest
from osmassets import roads
def _material(material_layers, name):
if name not in material_layers:
raise RuntimeError("Native road manifest references unknown materialLayer: " + name)
return material_layers[name]
def _split_filter(split, case):
if not split:
return None
prop = split["prop"]
if "match" in case:
return lambda props: props.get(prop) == case["match"]
matches = {item["match"] for item in split["cases"] if "match" in item}
return lambda props: props.get(prop) not in matches
def assemble(native_road_dir, projector, collection, material_layers):
manifest = native_road_manifest.load(native_road_dir)
z_by_material_layer = {layer["id"]: layer["z"] for layer in catalog.ROAD_LAYERS}
counts = {}
for spec in manifest["layers"]:
source = spec["source"]
role = spec["role"]
source_path = os.path.join(native_road_dir, "layers", source + ".geojson")
if role == "semantic":
continue
material_name = spec["materialLayer"]
if material_name not in z_by_material_layer:
raise RuntimeError("Native road manifest references unknown materialLayer: " + material_name)
_material(material_layers, material_name)
count = 0
split = spec.get("splitBy")
cases = split.get("cases", []) if split else [{"default": True, "material": material_name}]
for case in cases:
case_material_name = case.get("material", material_name)
case_material = _material(material_layers, case_material_name)
suffix = "_" + str(case["match"]) if "match" in case else ""
# Split cases may be inset overlays (for example the green
# planting inside a grey safety-island base). Keep the geometry
# unchanged, but lift matched overlays slightly to avoid z-fighting.
case_z = z_by_material_layer[material_name] + (0.001 if "match" in case else 0.0)
count += roads.assemble_geojson_layer(
source_path, source + suffix, projector, collection, case_material,
case_z, _split_filter(split, case))
counts[source] = count
return counts
+77 -19
View File
@@ -10,6 +10,7 @@ The expected values are derived from the geometry, not captured from the
implementation — a test that just records current output would ratify a bug.
"""
import json
import math
import os
import sys
@@ -30,7 +31,8 @@ from osmassets.geom import (
sample_tree_row,
signed_polygon_area,
)
from osmassets.catalog import NATIVE_ROAD_LAYERS, ROAD_LAYERS
from osmassets.catalog import MATERIALS, ROAD_LAYERS
from osmassets.native_road_manifest import CONTRACT, load as load_native_road_manifest
from osmassets.osm import Projector, parse_height, parse_osm, tags
@@ -38,6 +40,13 @@ SQUARE = [(0.0, 0.0), (10.0, 0.0), (10.0, 10.0), (0.0, 10.0)]
class RoadLayerCatalogTest(unittest.TestCase):
def test_native_island_material_is_registered(self):
material = MATERIALS["native_island_green"]
self.assertEqual(material["kind"], "solid")
self.assertEqual(material["color"], (0.0382, 0.4793, 0.1441))
self.assertGreater(material["color"][1], material["color"][0])
self.assertGreater(material["color"][1], material["color"][2])
def test_intersection_and_road_asphalt_share_the_same_colour(self):
layers = {layer["id"]: layer for layer in ROAD_LAYERS}
self.assertEqual(layers["road_surface"]["color"],
@@ -46,24 +55,6 @@ class RoadLayerCatalogTest(unittest.TestCase):
self.assertNotEqual(layers["road_surface"]["z"],
layers["intersection_surface"]["z"])
def test_native_provider_maps_to_existing_material_layers(self):
layers = {layer["id"] for layer in ROAD_LAYERS}
self.assertEqual(
[(entry["source"], entry["material_layer"])
for entry in NATIVE_ROAD_LAYERS],
[("road_surface", "road_surface"),
("edge_lines", "lane_separators"),
("intersection_surface", "intersection_surface"),
("sidewalk_surface", "sidewalks"),
("lane_separators", "lane_separators"),
("center_lines", "center_lines"),
("direction_arrows", "lane_arrows_webscale"),
("turn_arrows", "lane_arrows_webscale"),
("crosswalks", "crosswalks"),
("vehicle_stop_lines", "vehicle_stop_lines")])
self.assertTrue(all(entry["material_layer"] in layers
for entry in NATIVE_ROAD_LAYERS))
def test_cesium_export_keeps_signal_assets_optional(self):
exporter = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"..", "export_cesium.py")
@@ -72,6 +63,73 @@ class RoadLayerCatalogTest(unittest.TestCase):
self.assertIn('if not args.get(key):\n continue', source)
class NativeRoadManifestTest(unittest.TestCase):
def setUp(self):
self.root = tempfile.TemporaryDirectory()
self.layers_dir = os.path.join(self.root.name, "layers")
os.mkdir(self.layers_dir)
def tearDown(self):
self.root.cleanup()
def write_manifest(self, layers):
with open(os.path.join(self.root.name, "manifest.json"), "w", encoding="utf-8") as handle:
json.dump({"contract": CONTRACT, "areaId": "test", "layers": layers}, handle)
for layer in layers:
with open(os.path.join(self.layers_dir, layer["source"] + ".geojson"), "w",
encoding="utf-8") as handle:
json.dump({"type": "FeatureCollection", "features": []}, handle)
def test_accepts_semantic_and_split_layers(self):
layers = [
{"source": "road_surface", "role": "surface", "materialLayer": "road_surface"},
{"source": "center_lines", "role": "marking", "materialLayer": "center_lines",
"splitBy": {"prop": "color", "cases": [
{"match": "white", "material": "native_center_line_white"},
{"default": True, "material": "center_lines"},
]}},
{"source": "connectors", "role": "semantic"},
]
self.write_manifest(layers)
self.assertEqual(load_native_road_manifest(self.root.name)["layers"], layers)
def test_rejects_undeclared_or_missing_geojson(self):
layers = [{"source": "road_surface", "role": "surface",
"materialLayer": "road_surface"}]
self.write_manifest(layers)
with open(os.path.join(self.layers_dir, "extra.geojson"), "w", encoding="utf-8") as handle:
handle.write("{}")
with self.assertRaisesRegex(RuntimeError, "mismatch"):
load_native_road_manifest(self.root.name)
os.unlink(os.path.join(self.layers_dir, "extra.geojson"))
os.unlink(os.path.join(self.layers_dir, "road_surface.geojson"))
with self.assertRaisesRegex(RuntimeError, "mismatch"):
load_native_road_manifest(self.root.name)
def test_rejects_invalid_semantic_and_split_definitions(self):
self.write_manifest([{"source": "connectors", "role": "semantic",
"materialLayer": "road_surface"}])
with self.assertRaisesRegex(RuntimeError, "semantic"):
load_native_road_manifest(self.root.name)
def test_split_overlay_has_a_separate_z_layer(self):
native_roads = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"..", "osmassets", "native_roads.py")
with open(native_roads, encoding="utf-8") as handle:
source = handle.read()
self.assertIn('0.001 if "match" in case else 0.0', source)
self.write_manifest([{"source": "center_lines", "role": "marking",
"materialLayer": "center_lines", "splitBy": {
"prop": "color", "cases": [
{"match": "white", "material": "native_center_line_white"},
{"default": True, "material": "center_lines"},
{"default": True, "material": "center_lines"},
]}}])
with self.assertRaisesRegex(RuntimeError, "exactly one default"):
load_native_road_manifest(self.root.name)
class GeometryRingsTest(unittest.TestCase):
def test_polygon_keeps_only_the_exterior_ring(self):
geometry = {"type": "Polygon", "coordinates": [["outer"], ["hole"]]}
+177
View File
@@ -0,0 +1,177 @@
"""Compare exporter preparation against a supplied original in real Blender.
blender --background --factory-startup --python this_file.py -- \
--baseline /absolute/path/to/original_export_cesium.py
The fixture combines asymmetric quads, n-gons, authored UVs, shared meshes,
custom normals, shape keys and Bevel. A separate Boolean scenario exercises
the dependency-bearing fallback. Expected triangle totals follow n - 2;
attribute/ordering comparisons use the original exporter as an independent
reference, including an unchanged-code control run.
"""
import argparse
import importlib.util
import math
from pathlib import Path
import sys
import bpy
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
def load_exporter(name, path):
spec = importlib.util.spec_from_file_location(name, path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
def fixture(dependent):
bpy.ops.wm.read_factory_settings(use_empty=True)
material = bpy.data.materials.new("Fixture material")
objects = []
def mesh_object(name, vertices, faces):
mesh = bpy.data.meshes.new(name + " mesh")
mesh.from_pydata(vertices, [], faces)
mesh.materials.append(material)
mesh["fixture_property"] = "preserved"
obj = bpy.data.objects.new(name, mesh)
bpy.context.scene.collection.objects.link(obj)
objects.append(obj)
return obj
quad = [(0, 0, 0), (3, 0, 0), (2, 1, 0), (0, 2, 0)]
mesh_object("quad", quad, [(0, 1, 2, 3)])
mesh_object("ngon", quad + [(-1, 1, 0)], [(0, 1, 2, 3, 4)])
authored = mesh_object("authored", quad, [(0, 1, 2, 3)])
uv = authored.data.uv_layers.new(name="Authored UV")
for loop, value in zip(uv.data, [(0, 0), (.9, .1), (.6, .8), (.1, 1)]):
loop.uv = value
shared = mesh_object("shared", quad, [(0, 1, 2, 3)])
instance = bpy.data.objects.new("shared instance", shared.data)
bpy.context.scene.collection.objects.link(instance)
objects.append(instance)
mesh_object("triangle", quad[:3], [(0, 1, 2)])
custom = mesh_object("custom normals", quad, [(0, 1, 2, 3)])
custom.data.normals_split_custom_set([(0, .2, 1)] * 4)
keyed = mesh_object("shape keys", quad, [(0, 1, 2, 3)])
keyed.shape_key_add(name="Basis")
keyed.shape_key_add(name="Raised").data[0].co.z = .25
bevel = mesh_object("bevel", quad, [(0, 1, 2, 3)])
modifier = bevel.modifiers.new("Fixture bevel", "BEVEL")
modifier.width = .16
modifier.segments = 2
retained = mesh_object("fake user", quad, [(0, 1, 2, 3)])
retained.data.use_fake_user = True
if dependent:
boolean = objects[0].modifiers.new("Dependent Boolean", "BOOLEAN")
boolean.object = authored
return objects
def digest(objects):
return [{
"name": obj.name,
"mesh": obj.data.name,
"users": obj.data.users,
"properties": dict(obj.data.items()),
"vertices": [tuple(v.co) for v in obj.data.vertices],
"polygons": [tuple(p.vertices) for p in obj.data.polygons],
"smooth": [p.use_smooth for p in obj.data.polygons],
"normals": [tuple(n.vector) for n in obj.data.corner_normals],
"uv": {uv.name: [tuple(v.uv) for v in uv.data]
for uv in obj.data.uv_layers},
"materials": [m.name if m else None for m in obj.data.materials],
"modifiers": [(m.name, m.type) for m in obj.modifiers],
"shape_keys": ([key.name for key in obj.data.shape_keys.key_blocks]
if obj.data.shape_keys else []),
} for obj in objects]
def prepare(module, dependent, optimized):
objects = fixture(dependent)
if optimized:
module.prepare_independent_meshes(objects)
seen = set()
for obj in objects:
module.apply_mesh_modifiers(obj)
if obj.data.name not in seen:
seen.add(obj.data.name)
module.triangulate_mesh(obj)
module.unwrap_mesh(obj)
assert objects[3].data is objects[4].data, "shared mesh was split"
if not dependent:
assert len(objects[0].data.polygons) == 2, "quad must give n - 2 triangles"
assert len(objects[1].data.polygons) == 3, "pentagon must give n - 2 triangles"
return digest(objects)
def compare(expected, actual, path="root"):
if isinstance(expected, dict):
assert expected.keys() == actual.keys(), path
for key in expected:
compare(expected[key], actual[key], path + "." + str(key))
elif isinstance(expected, (list, tuple)):
assert len(expected) == len(actual), (path, len(expected), len(actual))
for index, (left, right) in enumerate(zip(expected, actual)):
compare(left, right, path + "[%d]" % index)
elif isinstance(expected, float):
assert math.isclose(expected, actual, rel_tol=0, abs_tol=1e-6), (
path, expected, actual)
else:
assert expected == actual, (path, expected, actual)
def check_work_scene_cleanup(module):
objects = fixture(False)
triangle = objects[5]
original_scene = bpy.context.window.scene
original_layer = bpy.context.window.view_layer
scene_names = set(bpy.data.scenes.keys())
collections = tuple(triangle.users_collection)
unwrap = module.unwrap_mesh
def fail_unwrap(obj):
assert bpy.context.scene != original_scene
assert obj == triangle
raise RuntimeError("fixture UV failure")
module.unwrap_mesh = fail_unwrap
# Remove the Bevel so this specifically exercises the scratch-scene path.
objects[8].modifiers.clear()
try:
try:
module.unwrap_meshes_in_work_scene([triangle])
except RuntimeError as error:
assert str(error) == "fixture UV failure"
else:
raise AssertionError("fixture failure was swallowed")
finally:
module.unwrap_mesh = unwrap
assert bpy.context.window.scene == original_scene
assert bpy.context.window.view_layer == original_layer
assert set(bpy.data.scenes.keys()) == scene_names
assert tuple(triangle.users_collection) == collections
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--baseline", required=True)
args = parser.parse_args(sys.argv[sys.argv.index("--") + 1:])
original = load_exporter("original_exporter", args.baseline)
optimized = load_exporter("optimized_exporter", ROOT / "export_cesium.py")
for dependent in (False, True):
reference = prepare(original, dependent, False)
compare(reference, prepare(original, dependent, False), "control")
compare(reference, prepare(optimized, dependent, True), "optimized")
check_work_scene_cleanup(optimized)
print("EXPORT_PREPARATION_CHECK_OK: control, independent and dependent fixtures")
if __name__ == "__main__":
main()
+1 -25
View File
@@ -1,6 +1,7 @@
{
"id": "fengshu-er-road",
"input": "/Users/que01/osm2streets-qgis-workflow/inputs/osm/枫树二路.osm",
"nativeRoadPackage": "../../inputs/native-road-packages/fengshu-er-road.zip",
"outputRoot": "/Users/que01/osm2streets-qgis-workflow/outputs",
"qgisApp": "/Applications/QGIS.app",
"blenderApp": "/Applications/Blender.app",
@@ -24,31 +25,6 @@
"turnLaneArrows": {
"enabled": false
},
"nativeRoad": {
"edgeLines": false,
"junctionTemplates": {
"enabled": true,
"references": [],
"clusters": [
{
"id": "zhushanhu-fengshu-complex",
"template": "complex-junction-v1",
"referenceFile": "/Users/que01/osm2streets-qgis-workflow/inputs/osm/珠山湖大道(枫树二路)口.geojson",
"approachWidthMultiplier": 1.45,
"approachLengthMeters": 32,
"coreRadiusMeters": 28,
"cornerRadiusMeters": 25,
"outerRadiusExtraMeters": 24,
"nodeIds": [
"8005332807",
"8024512135",
"8024512145",
"8024512147"
]
}
]
}
},
"osm2streets": {
"debug_each_step": false,
"dual_carriageway_experiment": false,
-32
View File
@@ -1,32 +0,0 @@
{
"id": "hanyang-block",
"input": "/Users/que01/Desktop/汉阳区区块.osm",
"outputRoot": "/Users/que01/osm2streets-qgis-workflow/outputs",
"qgisApp": "/Applications/QGIS.app",
"blenderApp": "/Applications/Blender.app",
"stages": {
"intermediates": false,
"blender": true,
"cesium": true
},
"qgis": {
"arrowScale": 0.8,
"clipPad": 0.002,
"canvasPad": 0.001,
"previewPad": 0.0007,
"canvasExtent": null,
"previewExtent": null,
"layerPrefix": "osm2streets"
},
"osm2streets": {
"debug_each_step": false,
"dual_carriageway_experiment": false,
"sidepath_zipping_experiment": false,
"inferred_sidewalks": true,
"osm2lanes": true
},
"blender": {
"treeStyle": "natural",
"officeOverrides": ""
}
}
@@ -1,6 +1,7 @@
{
"id": "nantaizi-lake-innovation-valley",
"input": "/Users/que01/Desktop/南台子湖创新谷OSM.osm",
"nativeRoadPackage": "../../inputs/native-road-packages/nantaizi-lake-innovation-valley.zip",
"outputRoot": "/Users/que01/osm2streets-qgis-workflow/outputs",
"qgisApp": "/Applications/QGIS.app",
"blenderApp": "/Applications/Blender.app",
@@ -24,9 +25,6 @@
"turnLaneArrows": {
"enabled": true
},
"nativeRoad": {
"edgeLines": false
},
"osm2streets": {
"debug_each_step": false,
"dual_carriageway_experiment": false,
+16
View File
@@ -0,0 +1,16 @@
{
"id": "osm-g5Yjf1",
"input": "/Users/que01/Desktop/南台子湖创新谷OSM.osm",
"nativeRoadPackage": "/tmp/osm-g5Yjf1.native-road.zip",
"outputRoot": "/Users/que01/osm2streets-qgis-workflow/outputs",
"stages": {
"intermediates": false,
"blender": true,
"cesium": true
},
"blender": {
"treeStyle": "natural",
"officeOverrides": "",
"roadProvider": "native"
}
}
+1 -8
View File
@@ -1,6 +1,7 @@
{
"id": "my-area",
"input": "/absolute/path/to/input.osm",
"nativeRoadPackage": "/absolute/path/to/exported-native-road-package.zip",
"outputRoot": "/absolute/path/to/outputs",
"qgisApp": "/Applications/QGIS.app",
"blenderApp": "/Applications/Blender.app",
@@ -24,14 +25,6 @@
"turnLaneArrows": {
"enabled": false
},
"nativeRoad": {
"edgeLines": false,
"junctionTemplates": {
"enabled": false,
"references": [],
"clusters": []
}
},
"osm2streets": {
"debug_each_step": false,
"dual_carriageway_experiment": false,
+10
View File
@@ -1,5 +1,15 @@
# Changelog
## 2026-08-25
- Frozen the `native-road-package/v1` host/compiler contract in
`docs/native-road-package-v1.md`, added `scripts/road-parity.js`, and
committed checksum baselines for `fengshu-er-road` and
`nantaizi-lake-innovation-valley`. The control experiment covers two clean
compiles plus editable signal regeneration for each area; JSON key ordering,
absolute paths, and temporary staging names are normalized while geometry and
GeoJSON feature order remain strict.
## 2026-08-04
- 重构区域构建入口的 preview 实现边界:`build-area.js` 现在只调度阶段、写 preview
+106
View File
@@ -0,0 +1,106 @@
# Native Road Package v1.1
`native-road-package/v1.1` defines the boundary between the host area pipeline
and the native road compiler. The compiler accepts only the input below; it
does not read `config/areas/*.json` or derive host paths.
## Input
```js
{
areaId: string,
osmFile: string,
outDir: string,
stagingDir: string,
overridesFile: string,
trafficSignalsFile: string,
comparisonDir?: string,
options: {
edgeLines: boolean,
junctionTemplates: {
enabled: boolean,
references: [],
clusters: []
}
}
}
```
All paths are absolute at the process boundary. `stagingDir` is the parent for
the compiler's temporary output and `outDir` is promoted atomically only after
all files are written. The host maps normalized area configuration to this
shape and owns all path derivation.
## Output
`outDir` contains these JSON documents:
- `compiled.json`: top-level keys are `schema`, `areaId`, `source`, `model`,
`movements`, `trafficSignals`, `diagnostics`, and `layers`. `source` has
`osm`, `overrides`, and `trafficSignals` paths.
- `diagnostics.json`: `{ schema: "native-road-diagnostics/v1", diagnostics: [] }`.
Each diagnostic has `id`, `severity`, `subjectId`, `sourceIds`, `rule`,
`message`, and `geometry` (a GeoJSON geometry or `null`).
- `comparison.json`: coverage counts for the road workbench.
- `traffic-signal-assemblies.json` and `traffic-signals.json`: compiler-owned
signal assembly and runtime views.
`layers/` always contains these twelve GeoJSON FeatureCollections:
1. `road_surface.geojson`
2. `intersection_surface.geojson`
3. `sidewalk_surface.geojson`
4. `edge_lines.geojson`
5. `lane_separators.geojson`
6. `center_lines.geojson`
7. `crosswalks.geojson`
8. `vehicle_stop_lines.geojson`
9. `direction_arrows.geojson`
10. `turn_arrows.geojson`
11. `lane_centerlines.geojson` (semantic, not rendered)
12. `connectors.geojson` (semantic, not rendered)
`manifest.json` is required. It declares the same twelve sources in published
order using `{ source, role, materialLayer?, splitBy? }`. `surface` and
`marking` layers declare a host material slot; `semantic` layers are published
but Blender must not read or render them. A `splitBy` entry has one exact-match
case or more plus exactly one default case, so the legacy white center-line and
yellow lane-separator material routing remains declarative. Consumers reject a
missing/invalid manifest, a source/file mismatch, and unknown material slots.
The editable signal source at `trafficSignalsFile` is a sibling of `outDir`.
It is included in the parity baseline because regeneration must be stable.
Successful CLI execution prints exactly one completion marker:
```text
NATIVE_ROAD_COMPILE_DONE {"areaId":...,"roads":N,"endpoints":N,"diagnostics":N,"output":...,"comparison":...}
```
Consumers use the CLI process plus files in `outDir` and parse this marker.
An in-process import may be an optimization, never the sole contract.
## Comparison Input Decision
`comparison.json` remains part of v1. The road workbench currently reads it,
so removing it would break a real consumer. `comparisonDir` is therefore an
optional compiler input for a future standalone package: when absent, the
compiler emits native-only counts and marks osm2streets coverage unavailable.
## Parity Rules
`scripts/road-parity.js` snapshots every file below `outDir` plus the sibling
editable signal document. JSON object keys are recursively sorted before
hashing. GeoJSON records both a sorted-feature `contentHash` and original-order
`orderHash`; either difference is reported.
The only normalization is intentional volatility removal:
- absolute paths below this repository become `<repo>/...`;
- other absolute paths become `<external>/<basename>`;
- `native-road-*` temporary directory names become `<staging>`.
No coordinates are rounded and no feature order changes are ignored. Control
experiments on 2026-08-25 compiled `fengshu-er-road` and
`nantaizi-lake-innovation-valley` twice, then regenerated their editable
signal documents. All 18 tracked files per area matched.
Binary file not shown.
+12
View File
@@ -9,6 +9,8 @@
"version": "0.3.0",
"dependencies": {
"@inquirer/prompts": "^8.5.2",
"@osm-asset/road-compiler": "git+https://git.app.que01.top/que01/road-compiler.git#v0.2.2",
"fflate": "0.8.3",
"ol": "^10.10.0",
"osm2streets-js-node": "0.1.4"
}
@@ -341,6 +343,16 @@
}
}
},
"node_modules/@osm-asset/road-compiler": {
"version": "0.2.2",
"resolved": "git+https://git.app.que01.top/que01/road-compiler.git#3b4befb02550c524ae83831e77959423e3bb40bf",
"dependencies": {
"ol": "10.10.0"
},
"bin": {
"road-compiler": "bin/road-compiler.js"
}
},
"node_modules/@petamoriken/float16": {
"version": "3.9.3",
"resolved": "http://172.16.1.86:4873/@petamoriken/float16/-/float16-3.9.3.tgz",
Loaded 100 of 143 files, more files were not shown because too many files have changed in this diff. Show more