Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
694f18826a | ||
|
|
4fc9397cec | ||
|
|
633f1ee364 | ||
|
|
d93212b685 | ||
|
|
9561ad8530 | ||
|
|
513ef62ab8 | ||
|
|
235314af1a | ||
|
|
d872ca6f32 | ||
|
|
f1ddedf889 | ||
|
|
633c39e5e1 | ||
|
|
5919684888 | ||
|
|
a5c3ad3cf3 | ||
|
|
61e4820a4c | ||
|
|
59a22ea697 |
No files matched your search
@@ -1,14 +1,26 @@
|
|||||||
# OSM GIS Pipeline
|
# OSM Asset Pipeline
|
||||||
|
|
||||||
把 OSM XML 转为 QGIS 工程(osm2streets 风格道路)和可选的 Blender 3D 场景。
|
把单个园区/片区 OSM XML 转为可消费的 Blender 场景和 Cesium GLB。osm2streets GeoJSON、GeoPackage、QGIS 工程和预览图都是中间资产,用来提供道路几何、调试标线效果,以及给 Blender/Cesium 生成提供输入。
|
||||||
|
|
||||||
|
## 目标产物
|
||||||
|
|
||||||
|
每个区域默认输出到 `outputs/<area-id>/`:
|
||||||
|
|
||||||
|
- `<area-id>.blend`:Blender 场景,包含道路、建筑、水体、植被等
|
||||||
|
- `<area-id>.png`:Blender 预览渲染
|
||||||
|
- `<area-id>.glb`:Cesium 可加载的 3D 模型
|
||||||
|
- `<area-id>.json`:Cesium 放置元数据和示例代码
|
||||||
|
- `<area-id>-cesium-preview.html`:Cesium 本地预览页
|
||||||
|
- `osm2streets_web_out/`:osm2streets GeoJSON 中间层
|
||||||
|
- `<area-id>.gpkg` / `<area-id>.qgz` / `<area-id>-preview.png`:QGIS 调试资产
|
||||||
|
|
||||||
## 环境
|
## 环境
|
||||||
|
|
||||||
需要:
|
需要:
|
||||||
|
|
||||||
- macOS QGIS:默认 `/Applications/QGIS.app`
|
- macOS QGIS:默认 `/Applications/QGIS.app`
|
||||||
|
- Blender:默认 `/Applications/Blender.app`
|
||||||
- Node.js / npm
|
- Node.js / npm
|
||||||
- Blender(可选,用于 3D 场景生成)
|
|
||||||
|
|
||||||
首次使用:
|
首次使用:
|
||||||
|
|
||||||
@@ -17,93 +29,111 @@ cd /Users/que01/osm2streets-qgis-workflow
|
|||||||
npm install
|
npm install
|
||||||
```
|
```
|
||||||
|
|
||||||
## QGIS 管线(强依赖 osm2streets)
|
## 主流程
|
||||||
|
|
||||||
使用默认配置:
|
默认构建南台子湖创新谷样例:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd /Users/que01/osm2streets-qgis-workflow
|
|
||||||
npm run build
|
npm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
使用指定配置:
|
指定区域配置:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
node scripts/build-osm2streets-qgis.js --config /path/to/config.json
|
npm run build:area -- --config config/areas/hanyang-block.json
|
||||||
```
|
```
|
||||||
|
|
||||||
命令行参数可以覆盖配置文件:
|
只跑部分阶段:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
node scripts/build-osm2streets-qgis.js \
|
npm run build:area -- --config config/areas/nantaizi-lake-innovation-valley.json --stages intermediates
|
||||||
--input /path/to/osm.xml \
|
npm run build:area -- --config config/areas/nantaizi-lake-innovation-valley.json --stages blender
|
||||||
--out-dir /path/to/out \
|
npm run build:area -- --config config/areas/nantaizi-lake-innovation-valley.json --stages cesium
|
||||||
--gpkg /path/to/output.gpkg \
|
npm run build:area -- --config config/areas/nantaizi-lake-innovation-valley.json --stages preview
|
||||||
--project /path/to/output.qgz \
|
|
||||||
--preview /path/to/output_preview.png
|
|
||||||
```
|
```
|
||||||
|
|
||||||
创建新区域配置可以从模板复制:
|
`intermediates` 会生成 osm2streets GeoJSON、GeoPackage、QGIS 工程和 QGIS 预览图。`blender` 使用 OSM 和 osm2streets GeoJSON 生成 `.blend`/`.png`。`cesium` 从 `.blend` 导出 `.glb`/`.json`,并生成 Cesium 预览 HTML。`preview` 只在已有 `.glb/.json` 时补生成 HTML。
|
||||||
|
|
||||||
|
## 区域配置
|
||||||
|
|
||||||
|
新区域从模板复制:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cp config/examples/template.json config/my-area.json
|
cp config/examples/template.json config/areas/my-area.json
|
||||||
```
|
```
|
||||||
|
|
||||||
### 配置项
|
核心配置:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"qgisApp": "/Applications/QGIS.app",
|
"id": "my-area",
|
||||||
"input": "/absolute/path/to/input.osm",
|
"input": "/absolute/path/to/input.osm",
|
||||||
"outDir": "/absolute/path/to/osm2streets_web_out",
|
"outputRoot": "/absolute/path/to/outputs",
|
||||||
"gpkg": "/absolute/path/to/output.gpkg",
|
"qgisApp": "/Applications/QGIS.app",
|
||||||
"project": "/absolute/path/to/output.qgz",
|
"blenderApp": "/Applications/Blender.app",
|
||||||
"preview": "/absolute/path/to/output_preview.png",
|
"stages": {
|
||||||
"arrowScale": 0.8,
|
"intermediates": true,
|
||||||
"clipPad": 0.002,
|
"blender": true,
|
||||||
"canvasPad": 0.001,
|
"cesium": true
|
||||||
"previewPad": 0.0007,
|
},
|
||||||
"canvasExtent": null,
|
"qgis": {
|
||||||
"previewExtent": null,
|
"arrowScale": 0.8,
|
||||||
"layerPrefix": "osm2streets",
|
"clipPad": 0.002,
|
||||||
"osm2streets": {
|
"canvasPad": 0.001,
|
||||||
"debug_each_step": false,
|
"previewPad": 0.0007,
|
||||||
"dual_carriageway_experiment": false,
|
"canvasExtent": null,
|
||||||
"sidepath_zipping_experiment": false,
|
"previewExtent": null,
|
||||||
"inferred_sidewalks": true,
|
"layerPrefix": "osm2streets"
|
||||||
"osm2lanes": true
|
},
|
||||||
|
"blender": {
|
||||||
|
"treeStyle": "natural",
|
||||||
|
"officeOverrides": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
- `input`:OSM XML 输入文件路径。
|
`scripts/build-area.js` 会按 `id` 自动推导默认输出路径。确实需要定制时,可以增加 `outputs` 覆盖:
|
||||||
- `outDir`:osm2streets GeoJSON 中间产物输出目录。
|
|
||||||
- `gpkg` / `project` / `preview`:最终 GeoPackage、QGIS 工程、预览 PNG 路径。
|
|
||||||
- `layerPrefix`:QGIS 图层显示名称前缀(如 `"osm2streets"` → `"osm2streets road surface"`)。
|
|
||||||
- `arrowScale`:方向箭头几何缩放。
|
|
||||||
- `osm2streets`:osm2streets 引擎选项。
|
|
||||||
|
|
||||||
### 输出图层
|
```json
|
||||||
|
{
|
||||||
|
"outputs": {
|
||||||
|
"areaDir": "/absolute/path/to/custom-area",
|
||||||
|
"blend": "/absolute/path/to/custom.blend",
|
||||||
|
"glb": "/absolute/path/to/custom.glb",
|
||||||
|
"cesiumPreview": "/absolute/path/to/custom-preview.html"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
GeoPackage 内会生成:
|
预览 Cesium 页面时,需要在输出目录启动 HTTP 服务,避免浏览器拦截本地文件请求:
|
||||||
|
|
||||||
- `road_surface`
|
```bash
|
||||||
- `intersection_surface`
|
cd outputs/my-area
|
||||||
- `sidewalks`
|
python3 -m http.server 8765
|
||||||
- `sidewalk_corners`
|
```
|
||||||
- `lane_separators`
|
|
||||||
- `center_lines`
|
|
||||||
- `vehicle_stop_lines`
|
|
||||||
- `lane_arrows_webscale`
|
|
||||||
- `crosswalks`
|
|
||||||
|
|
||||||
QGIS 工程绘制顺序:路面在最底,车道线、斑马线、停止线和箭头在上。
|
然后打开 `http://localhost:8765/my-area-cesium-preview.html`。
|
||||||
|
|
||||||
## Blender 3D 场景(可选)
|
## 实验:车辆巡航
|
||||||
|
|
||||||
osm2streets 道路几何为可选输入;不提供时回退到 OSM highway 折线。
|
`preview` 和 `cesium` 阶段会额外生成 `<area-id>-vehicle-route.json` 和 `<area-id>-vehicle-car.gltf`。路线文件从 OSM bounds 内的可行驶 `highway` way 提取道路中心线,并向右偏移约 1.3 米作为车辆行驶线,避免车辆压道路中心线。Cesium 预览页会加载多条道路段并显示多辆实验车辆循环巡航;`Vehicle` 下拉框决定 `Follow` 跟随哪一辆车。
|
||||||
|
|
||||||
生成场景:
|
这是用于验证高精度巡航可用性的预览层功能,不会改变 Blender/GLB 主资产本身。车辆模型是无 logo 的轻量预览模型,生成在输出目录中。
|
||||||
|
|
||||||
|
## 已沉淀区域
|
||||||
|
|
||||||
|
- `config/areas/nantaizi-lake-innovation-valley.json`
|
||||||
|
- `config/areas/hanyang-block.json`
|
||||||
|
|
||||||
|
## 低层命令
|
||||||
|
|
||||||
|
通常优先使用 `npm run build:area`。如果只想调试旧 QGIS/osm2streets 阶段,可以直接运行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run build:qgis -- --config config/hanyang-block.json
|
||||||
|
```
|
||||||
|
|
||||||
|
Blender 低层命令:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
/Applications/Blender.app/Contents/MacOS/Blender \
|
/Applications/Blender.app/Contents/MacOS/Blender \
|
||||||
@@ -112,70 +142,24 @@ osm2streets 道路几何为可选输入;不提供时回退到 OSM highway 折
|
|||||||
--osm "/path/to/input.osm" \
|
--osm "/path/to/input.osm" \
|
||||||
--geojson "/path/to/osm2streets_web_out" \
|
--geojson "/path/to/osm2streets_web_out" \
|
||||||
--output "/path/to/scene.blend" \
|
--output "/path/to/scene.blend" \
|
||||||
--render "/path/to/preview.png"
|
--render "/path/to/preview.png" \
|
||||||
|
--tree-style natural
|
||||||
```
|
```
|
||||||
|
|
||||||
`--geojson` 为可选参数。使用 `--office-overrides` 指定应渲染为办公楼的 OSM way ID(逗号分隔)。
|
Cesium GLB 低层导出:
|
||||||
|
|
||||||
导出为 Cesium GLB:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
/Applications/Blender.app/Contents/MacOS/Blender \
|
/Applications/Blender.app/Contents/MacOS/Blender \
|
||||||
--background \
|
--background \
|
||||||
--python blender/export_cesium.py -- \
|
--python blender/export_cesium.py -- \
|
||||||
--blend "/path/to/scene.blend" \
|
--blend "/path/to/scene.blend" \
|
||||||
--glb "/path/to/scene_cesium.glb" \
|
--glb "/path/to/scene.glb" \
|
||||||
--metadata "/path/to/scene_cesium.json"
|
--metadata "/path/to/scene.json"
|
||||||
```
|
```
|
||||||
|
|
||||||
详见 [blender/README.md](blender/README.md)。
|
详见 [blender/README.md](blender/README.md)。
|
||||||
|
|
||||||
## 运行示例
|
|
||||||
|
|
||||||
以下命令已在本机验证通过。
|
|
||||||
|
|
||||||
QGIS 管线(使用汉阳区区块 OSM 数据):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
node scripts/build-osm2streets-qgis.js \
|
|
||||||
--config config/hanyang-block.json
|
|
||||||
```
|
|
||||||
|
|
||||||
Blender 场景(含 osm2streets 道路几何):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
/Applications/Blender.app/Contents/MacOS/Blender \
|
|
||||||
--background --factory-startup \
|
|
||||||
--python blender/generate_scene.py -- \
|
|
||||||
--osm "/Users/que01/Desktop/南台子湖创新谷OSM.osm" \
|
|
||||||
--geojson "/Users/que01/osm2streets-qgis-workflow/outputs/nantaizi-lake-innovation-valley/osm2streets_web_out" \
|
|
||||||
--output "/tmp/scene.blend" \
|
|
||||||
--render "/tmp/preview.png"
|
|
||||||
```
|
|
||||||
|
|
||||||
Blender 场景(纯 OSM,无 osm2streets 道路):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
/Applications/Blender.app/Contents/MacOS/Blender \
|
|
||||||
--background --factory-startup \
|
|
||||||
--python blender/generate_scene.py -- \
|
|
||||||
--osm "/Users/que01/Desktop/南台子湖创新谷OSM.osm" \
|
|
||||||
--output "/tmp/scene-nogeojson.blend" \
|
|
||||||
--render "/tmp/preview-nogeojson.png"
|
|
||||||
```
|
|
||||||
|
|
||||||
Cesium GLB 导出:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
/Applications/Blender.app/Contents/MacOS/Blender \
|
|
||||||
--background \
|
|
||||||
--python blender/export_cesium.py -- \
|
|
||||||
--blend "/tmp/scene.blend" \
|
|
||||||
--glb "/tmp/scene.glb" \
|
|
||||||
--metadata "/tmp/scene.json"
|
|
||||||
```
|
|
||||||
|
|
||||||
## 文档
|
## 文档
|
||||||
|
|
||||||
- [docs/input-cases.md](docs/input-cases.md) — 已验证的 OSM 输入案例
|
- [docs/input-cases.md](docs/input-cases.md) - 已验证的 OSM 输入案例
|
||||||
- [docs/changelog.md](docs/changelog.md) — 变更记录
|
- [docs/changelog.md](docs/changelog.md) - 变更记录
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
newmtl None
|
|
||||||
Ka 1.000000 1.000000 1.000000
|
|
||||||
Kd 1.000000 1.000000 1.000000
|
|
||||||
Ks 0.000000 0.000000 0.000000
|
|
||||||
d 1.000000
|
|
||||||
illum 1
|
|
||||||
map_Kd HazelnutBark.png
|
|
||||||
|
|
||||||
newmtl None_Hazelnut.png
|
|
||||||
Ka 1.000000 1.000000 1.000000
|
|
||||||
Kd 1.000000 1.000000 1.000000
|
|
||||||
Ks 0.000000 0.000000 0.000000
|
|
||||||
d 1.000000
|
|
||||||
illum 1
|
|
||||||
map_Kd HazelnutLeaves.png
|
|
||||||
map_d HazelnutLeaves.png
|
|
||||||
File diff suppressed because it is too large.
Load diff
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 5.8 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 187 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 31 KiB |
+15
-4
@@ -2,6 +2,14 @@
|
|||||||
|
|
||||||
该生成器将 OSM 建筑、水体、植被标签,以及可选的 osm2streets GeoJSON 道路图层,组合为 Blender 3D 场景。
|
该生成器将 OSM 建筑、水体、植被标签,以及可选的 osm2streets GeoJSON 道路图层,组合为 Blender 3D 场景。
|
||||||
|
|
||||||
|
项目主入口是根目录的区域管线:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run build:area -- --config config/areas/nantaizi-lake-innovation-valley.json --stages blender,cesium
|
||||||
|
```
|
||||||
|
|
||||||
|
下面的命令适合单独调试 Blender 脚本。
|
||||||
|
|
||||||
## 生成场景
|
## 生成场景
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -11,10 +19,12 @@
|
|||||||
--osm "/path/to/input.osm" \
|
--osm "/path/to/input.osm" \
|
||||||
--geojson "/path/to/osm2streets_web_out" \
|
--geojson "/path/to/osm2streets_web_out" \
|
||||||
--output "/path/to/output.blend" \
|
--output "/path/to/output.blend" \
|
||||||
--render "/path/to/preview.png"
|
--render "/path/to/preview.png" \
|
||||||
|
--tree-style natural
|
||||||
```
|
```
|
||||||
|
|
||||||
`--geojson` 为可选参数。不提供时,道路使用简单的 OSM highway 折线,而非详细 osm2streets 几何。
|
`--geojson` 为可选参数。不提供时,道路使用简单的 OSM highway 折线,而非详细 osm2streets 几何。实际资产生成建议先跑 `intermediates` 阶段,为 Blender 提供 osm2streets 道路面、标线、斑马线和箭头。
|
||||||
|
`--tree-style` 可选 `natural` 或 `procedural`。默认 `natural` 使用低面数树干和多层不规则树冠,形态比球形程序化树冠更自然,渲染也比外部 OBJ 树模型轻;`procedural` 最轻但更卡通。
|
||||||
|
|
||||||
使用 `--office-overrides` 指定一组 OSM way ID(逗号分隔),这些建筑将渲染为办公楼风格,即使其 OSM 标签为 `building=industrial`:
|
使用 `--office-overrides` 指定一组 OSM way ID(逗号分隔),这些建筑将渲染为办公楼风格,即使其 OSM 标签为 `building=industrial`:
|
||||||
|
|
||||||
@@ -25,7 +35,7 @@
|
|||||||
### 说明
|
### 说明
|
||||||
|
|
||||||
- OSM `bounds` 元素定义场景范围(排除远处的地铁等关系成员)
|
- OSM `bounds` 元素定义场景范围(排除远处的地铁等关系成员)
|
||||||
- `natural=tree` 节点 → 独立树木(程序化或模型树冠)
|
- `natural=tree` 节点 → 独立树木(默认低面数自然树冠)
|
||||||
- `natural=tree_row` 路径 → 沿路径均匀分布的树木
|
- `natural=tree_row` 路径 → 沿路径均匀分布的树木
|
||||||
- `landuse=grass` → 绿色地面
|
- `landuse=grass` → 绿色地面
|
||||||
- `natural=scrub` → 低矮灌木丛
|
- `natural=scrub` → 低矮灌木丛
|
||||||
@@ -48,6 +58,7 @@
|
|||||||
|
|
||||||
GLB 使用以 OSM bounds 中心为原点的局部 ENU 坐标系(X 东,Y 北,Z 上)。
|
GLB 使用以 OSM bounds 中心为原点的局部 ENU 坐标系(X 东,Y 北,Z 上)。
|
||||||
使用配套的 JSON 元数据文件将模型放置到 Cesium 中。
|
使用配套的 JSON 元数据文件将模型放置到 Cesium 中。
|
||||||
|
区域管线的 `cesium` 阶段还会在输出目录生成 `<area-id>-cesium-preview.html`。
|
||||||
|
|
||||||
导出脚本会:
|
导出脚本会:
|
||||||
- 应用网格修改器并创建 UV
|
- 应用网格修改器并创建 UV
|
||||||
@@ -63,4 +74,4 @@ GLB 使用以 OSM bounds 中心为原点的局部 ENU 坐标系(X 东,Y 北
|
|||||||
```bash
|
```bash
|
||||||
cd /path/to/output
|
cd /path/to/output
|
||||||
python3 -m http.server 8765
|
python3 -m http.server 8765
|
||||||
```
|
```
|
||||||
@@ -19,6 +19,9 @@ import numpy as np
|
|||||||
|
|
||||||
EXPORT_TINTS = {
|
EXPORT_TINTS = {
|
||||||
"Grass": ((0.12, 0.48, 0.08), 0.72),
|
"Grass": ((0.12, 0.48, 0.08), 0.72),
|
||||||
|
"Tree Crown Dark": ((0.06, 0.22, 0.05), 0.18),
|
||||||
|
"Tree Crown Light": ((0.16, 0.42, 0.09), 0.16),
|
||||||
|
"Scrub Ground Cover": ((0.08, 0.28, 0.07), 0.28),
|
||||||
"Office White Plaster Facade": ((0.92, 0.94, 0.92), 0.38),
|
"Office White Plaster Facade": ((0.92, 0.94, 0.92), 0.38),
|
||||||
"Office White Metal Facade": ((0.92, 0.94, 0.92), 0.68),
|
"Office White Metal Facade": ((0.92, 0.94, 0.92), 0.68),
|
||||||
"Office Light Flat Roof": ((0.82, 0.86, 0.88), 0.35),
|
"Office Light Flat Roof": ((0.82, 0.86, 0.88), 0.35),
|
||||||
@@ -33,12 +36,18 @@ EXPORT_METALLIC_OVERRIDES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EXPORT_BASE_COLOR_OVERRIDES = {
|
EXPORT_BASE_COLOR_OVERRIDES = {
|
||||||
|
"Tree Crown": (0.11, 0.34, 0.075),
|
||||||
|
"Tree Crown Dark": (0.065, 0.24, 0.055),
|
||||||
|
"Tree Crown Light": (0.14, 0.40, 0.085),
|
||||||
"Office White Plaster Facade": (0.93, 0.94, 0.91),
|
"Office White Plaster Facade": (0.93, 0.94, 0.91),
|
||||||
"Office White Metal Facade": (0.93, 0.94, 0.91),
|
"Office White Metal Facade": (0.93, 0.94, 0.91),
|
||||||
"Office Light Flat Roof": (0.88, 0.90, 0.88),
|
"Office Light Flat Roof": (0.88, 0.90, 0.88),
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT_EMISSION_OVERRIDES = {
|
EXPORT_EMISSION_OVERRIDES = {
|
||||||
|
"Tree Crown": ((0.04, 0.11, 0.035), 0.02),
|
||||||
|
"Tree Crown Dark": ((0.025, 0.07, 0.02), 0.015),
|
||||||
|
"Tree Crown Light": ((0.045, 0.12, 0.03), 0.015),
|
||||||
"Office White Plaster Facade": ((0.93, 0.94, 0.91), 0.18),
|
"Office White Plaster Facade": ((0.93, 0.94, 0.91), 0.18),
|
||||||
"Office White Metal Facade": ((0.93, 0.94, 0.91), 0.18),
|
"Office White Metal Facade": ((0.93, 0.94, 0.91), 0.18),
|
||||||
"Office Light Flat Roof": ((0.88, 0.90, 0.88), 0.14),
|
"Office Light Flat Roof": ((0.88, 0.90, 0.88), 0.14),
|
||||||
@@ -85,10 +94,17 @@ def source_color(material):
|
|||||||
return color
|
return color
|
||||||
|
|
||||||
|
|
||||||
def source_principled_value(material, input_name, fallback):
|
def principled_bsdf(material):
|
||||||
if not material.use_nodes:
|
if not material.use_nodes:
|
||||||
return fallback
|
return None
|
||||||
node = material.node_tree.nodes.get("Principled BSDF")
|
for node in material.node_tree.nodes:
|
||||||
|
if node.type == "BSDF_PRINCIPLED":
|
||||||
|
return node
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def source_principled_value(material, input_name, fallback):
|
||||||
|
node = principled_bsdf(material)
|
||||||
if not node or input_name not in node.inputs:
|
if not node or input_name not in node.inputs:
|
||||||
return fallback
|
return fallback
|
||||||
return node.inputs[input_name].default_value
|
return node.inputs[input_name].default_value
|
||||||
@@ -144,8 +160,8 @@ def tree_crown_image():
|
|||||||
np.sin((x * 89.0 + y * 67.0) * np.pi) * 0.07
|
np.sin((x * 89.0 + y * 67.0) * np.pi) * 0.07
|
||||||
)
|
)
|
||||||
noise = np.clip(0.5 + noise, 0.0, 1.0)[..., None]
|
noise = np.clip(0.5 + noise, 0.0, 1.0)[..., None]
|
||||||
dark = np.asarray((0.035, 0.16, 0.045), dtype=np.float32)
|
dark = np.asarray((0.04, 0.17, 0.04), dtype=np.float32)
|
||||||
light = np.asarray((0.12, 0.42, 0.13), dtype=np.float32)
|
light = np.asarray((0.17, 0.46, 0.115), dtype=np.float32)
|
||||||
rgb = dark + (light - dark) * noise
|
rgb = dark + (light - dark) * noise
|
||||||
rgba = np.concatenate(
|
rgba = np.concatenate(
|
||||||
(rgb, np.ones((size, size, 1), dtype=np.float32)), axis=2)
|
(rgb, np.ones((size, size, 1), dtype=np.float32)), axis=2)
|
||||||
@@ -353,4 +369,4 @@ def export(args):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
export(cli_args())
|
export(cli_args())
|
||||||
+135
-194
@@ -27,28 +27,22 @@ import xml.etree.ElementTree as ET
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
from mathutils import Matrix, Vector
|
from mathutils import Vector
|
||||||
|
|
||||||
|
|
||||||
TEXTURE_ROOT = os.path.abspath(os.path.join(
|
TEXTURE_ROOT = os.path.abspath(os.path.join(
|
||||||
os.path.dirname(__file__), "..", "assets", "textures", "polyhaven"
|
os.path.dirname(__file__), "..", "assets", "textures", "polyhaven"
|
||||||
))
|
))
|
||||||
MODEL_ROOT = os.path.abspath(os.path.join(
|
|
||||||
os.path.dirname(__file__), "..", "assets", "models", "polyhaven"
|
|
||||||
))
|
|
||||||
TREE_MODEL_PATH = os.path.join(
|
|
||||||
MODEL_ROOT, "78-hazelnutbush", "Hazelnut.obj"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def cli_args():
|
def cli_args():
|
||||||
values = {"osm": None, "geojson": None, "output": None, "render": None,
|
values = {"osm": None, "geojson": None, "output": None, "render": None,
|
||||||
"office_overrides": ""}
|
"office_overrides": "", "tree_style": "natural"}
|
||||||
argv = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
|
argv = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
|
||||||
i = 0
|
i = 0
|
||||||
while i < len(argv):
|
while i < len(argv):
|
||||||
if argv[i].startswith("--") and i + 1 < len(argv):
|
if argv[i].startswith("--") and i + 1 < len(argv):
|
||||||
values[argv[i][2:]] = argv[i + 1]
|
values[argv[i][2:].replace("-", "_")] = argv[i + 1]
|
||||||
i += 2
|
i += 2
|
||||||
else:
|
else:
|
||||||
i += 1
|
i += 1
|
||||||
@@ -67,6 +61,8 @@ def cli_args():
|
|||||||
values["office_overrides"] = set()
|
values["office_overrides"] = set()
|
||||||
else:
|
else:
|
||||||
values["office_overrides"] = set()
|
values["office_overrides"] = set()
|
||||||
|
if values.get("tree_style") not in {"natural", "procedural"}:
|
||||||
|
raise RuntimeError("--tree-style must be 'natural' or 'procedural'")
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
|
||||||
@@ -145,11 +141,20 @@ def new_collection(name):
|
|||||||
return collection
|
return collection
|
||||||
|
|
||||||
|
|
||||||
|
def principled_bsdf(material):
|
||||||
|
if not material.use_nodes:
|
||||||
|
return None
|
||||||
|
for node in material.node_tree.nodes:
|
||||||
|
if node.type == "BSDF_PRINCIPLED":
|
||||||
|
return node
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def make_material(name, color, roughness=0.8, metallic=0.0):
|
def make_material(name, color, roughness=0.8, metallic=0.0):
|
||||||
material = bpy.data.materials.get(name) or bpy.data.materials.new(name)
|
material = bpy.data.materials.get(name) or bpy.data.materials.new(name)
|
||||||
material.diffuse_color = (*color, 1.0)
|
material.diffuse_color = (*color, 1.0)
|
||||||
material.use_nodes = True
|
material.use_nodes = True
|
||||||
bsdf = material.node_tree.nodes.get("Principled BSDF")
|
bsdf = principled_bsdf(material)
|
||||||
if bsdf:
|
if bsdf:
|
||||||
bsdf.inputs["Base Color"].default_value = (*color, 1.0)
|
bsdf.inputs["Base Color"].default_value = (*color, 1.0)
|
||||||
bsdf.inputs["Roughness"].default_value = roughness
|
bsdf.inputs["Roughness"].default_value = roughness
|
||||||
@@ -160,7 +165,7 @@ def make_material(name, color, roughness=0.8, metallic=0.0):
|
|||||||
def add_procedural_surface(material, colors, scale=2.0, detail=2.0, bump_strength=0.08):
|
def add_procedural_surface(material, colors, scale=2.0, detail=2.0, bump_strength=0.08):
|
||||||
nodes = material.node_tree.nodes
|
nodes = material.node_tree.nodes
|
||||||
links = material.node_tree.links
|
links = material.node_tree.links
|
||||||
bsdf = nodes.get("Principled BSDF")
|
bsdf = principled_bsdf(material)
|
||||||
if not bsdf:
|
if not bsdf:
|
||||||
return
|
return
|
||||||
noise = nodes.new("ShaderNodeTexNoise")
|
noise = nodes.new("ShaderNodeTexNoise")
|
||||||
@@ -192,7 +197,9 @@ def make_textured_material(name, diffuse_file, normal_file, roughness,
|
|||||||
material = make_material(name, (0.5, 0.5, 0.5), roughness, metallic)
|
material = make_material(name, (0.5, 0.5, 0.5), roughness, metallic)
|
||||||
nodes = material.node_tree.nodes
|
nodes = material.node_tree.nodes
|
||||||
links = material.node_tree.links
|
links = material.node_tree.links
|
||||||
bsdf = nodes.get("Principled BSDF")
|
bsdf = principled_bsdf(material)
|
||||||
|
if not bsdf:
|
||||||
|
return material
|
||||||
texcoord = nodes.new("ShaderNodeTexCoord")
|
texcoord = nodes.new("ShaderNodeTexCoord")
|
||||||
mapping = nodes.new("ShaderNodeMapping")
|
mapping = nodes.new("ShaderNodeMapping")
|
||||||
mapping.inputs["Scale"].default_value = (scale, scale, scale)
|
mapping.inputs["Scale"].default_value = (scale, scale, scale)
|
||||||
@@ -231,124 +238,6 @@ def make_textured_material(name, diffuse_file, normal_file, roughness,
|
|||||||
return material
|
return material
|
||||||
|
|
||||||
|
|
||||||
def make_image_material(name, image_path, roughness=0.8, metallic=0.0,
|
|
||||||
alpha_path=None, alpha_clip=0.33,
|
|
||||||
cull_backface=False, tint=None, tint_factor=0.0,
|
|
||||||
saturation=1.0, value=1.0, emission_color=None,
|
|
||||||
emission_strength=0.0):
|
|
||||||
material = make_material(name, (0.5, 0.5, 0.5), roughness, metallic)
|
|
||||||
nodes = material.node_tree.nodes
|
|
||||||
links = material.node_tree.links
|
|
||||||
bsdf = nodes.get("Principled BSDF")
|
|
||||||
if not bsdf or not os.path.exists(image_path):
|
|
||||||
return material
|
|
||||||
|
|
||||||
image = nodes.new("ShaderNodeTexImage")
|
|
||||||
image.image = bpy.data.images.load(image_path, check_existing=True)
|
|
||||||
color_output = image.outputs["Color"]
|
|
||||||
|
|
||||||
if saturation != 1.0 or value != 1.0:
|
|
||||||
hsv = nodes.new("ShaderNodeHueSaturation")
|
|
||||||
hsv.inputs["Saturation"].default_value = saturation
|
|
||||||
hsv.inputs["Value"].default_value = value
|
|
||||||
links.new(color_output, hsv.inputs["Color"])
|
|
||||||
color_output = hsv.outputs["Color"]
|
|
||||||
|
|
||||||
if tint and tint_factor > 0.0:
|
|
||||||
tint_node = nodes.new("ShaderNodeRGB")
|
|
||||||
tint_node.outputs["Color"].default_value = (*tint, 1.0)
|
|
||||||
mix = nodes.new("ShaderNodeMixRGB")
|
|
||||||
mix.blend_type = "MIX"
|
|
||||||
mix.inputs["Fac"].default_value = tint_factor
|
|
||||||
links.new(color_output, mix.inputs[1])
|
|
||||||
links.new(tint_node.outputs["Color"], mix.inputs[2])
|
|
||||||
color_output = mix.outputs["Color"]
|
|
||||||
|
|
||||||
links.new(color_output, bsdf.inputs["Base Color"])
|
|
||||||
if "Specular IOR Level" in bsdf.inputs:
|
|
||||||
bsdf.inputs["Specular IOR Level"].default_value = 0.2
|
|
||||||
elif "Specular" in bsdf.inputs:
|
|
||||||
bsdf.inputs["Specular"].default_value = 0.2
|
|
||||||
|
|
||||||
if emission_color and emission_strength > 0.0:
|
|
||||||
if "Emission Color" in bsdf.inputs:
|
|
||||||
bsdf.inputs["Emission Color"].default_value = (*emission_color, 1.0)
|
|
||||||
elif "Emission" in bsdf.inputs:
|
|
||||||
bsdf.inputs["Emission"].default_value = (*emission_color, 1.0)
|
|
||||||
if "Emission Strength" in bsdf.inputs:
|
|
||||||
bsdf.inputs["Emission Strength"].default_value = emission_strength
|
|
||||||
|
|
||||||
alpha_source = image
|
|
||||||
if alpha_path and os.path.exists(alpha_path):
|
|
||||||
alpha_source = nodes.new("ShaderNodeTexImage")
|
|
||||||
alpha_source.image = bpy.data.images.load(alpha_path, check_existing=True)
|
|
||||||
alpha_source.image.colorspace_settings.name = "Non-Color"
|
|
||||||
|
|
||||||
if "Alpha" in bsdf.inputs:
|
|
||||||
links.new(alpha_source.outputs["Alpha"], bsdf.inputs["Alpha"])
|
|
||||||
|
|
||||||
if hasattr(material, "blend_method"):
|
|
||||||
material.blend_method = "CLIP" if alpha_path else "OPAQUE"
|
|
||||||
if hasattr(material, "shadow_method"):
|
|
||||||
material.shadow_method = "CLIP" if alpha_path else "OPAQUE"
|
|
||||||
if hasattr(material, "alpha_threshold"):
|
|
||||||
material.alpha_threshold = alpha_clip
|
|
||||||
if hasattr(material, "surface_render_method") and alpha_path:
|
|
||||||
material.surface_render_method = "DITHERED"
|
|
||||||
if hasattr(material, "use_backface_culling"):
|
|
||||||
material.use_backface_culling = cull_backface
|
|
||||||
return material
|
|
||||||
|
|
||||||
|
|
||||||
def import_model(filepath):
|
|
||||||
extension = os.path.splitext(filepath)[1].lower()
|
|
||||||
if extension in {".gltf", ".glb"}:
|
|
||||||
bpy.ops.import_scene.gltf(filepath=filepath)
|
|
||||||
return
|
|
||||||
if extension == ".obj":
|
|
||||||
if hasattr(bpy.ops.wm, "obj_import"):
|
|
||||||
bpy.ops.wm.obj_import(filepath=filepath)
|
|
||||||
return
|
|
||||||
bpy.ops.import_scene.obj(filepath=filepath)
|
|
||||||
return
|
|
||||||
raise RuntimeError("Unsupported tree model format: " + extension)
|
|
||||||
|
|
||||||
|
|
||||||
def assign_tree_model_materials(objects):
|
|
||||||
model_dir = os.path.dirname(TREE_MODEL_PATH)
|
|
||||||
bark = make_image_material(
|
|
||||||
"Hazelnut Bark",
|
|
||||||
os.path.join(model_dir, "HazelnutBark.png"),
|
|
||||||
roughness=0.86,
|
|
||||||
)
|
|
||||||
leaves = make_image_material(
|
|
||||||
"Hazelnut Leaves",
|
|
||||||
os.path.join(model_dir, "HazelnutLeaves.png"),
|
|
||||||
roughness=0.82,
|
|
||||||
alpha_path=os.path.join(model_dir, "HazelnutLeavesMask.png"),
|
|
||||||
alpha_clip=0.18,
|
|
||||||
cull_backface=False,
|
|
||||||
tint=(0.25, 0.52, 0.18),
|
|
||||||
tint_factor=0.62,
|
|
||||||
saturation=1.45,
|
|
||||||
value=1.42,
|
|
||||||
emission_color=(0.21, 0.36, 0.15),
|
|
||||||
emission_strength=0.26,
|
|
||||||
)
|
|
||||||
for obj in objects:
|
|
||||||
if obj.type != "MESH":
|
|
||||||
continue
|
|
||||||
obj.data.materials.clear()
|
|
||||||
lowered = obj.name.lower()
|
|
||||||
if "leaf" in lowered:
|
|
||||||
obj.data.materials.append(leaves)
|
|
||||||
else:
|
|
||||||
obj.data.materials.append(bark)
|
|
||||||
for polygon in obj.data.polygons:
|
|
||||||
polygon.material_index = 0
|
|
||||||
polygon.use_smooth = True
|
|
||||||
|
|
||||||
|
|
||||||
class MeshBatch:
|
class MeshBatch:
|
||||||
def __init__(self, name, collection, material):
|
def __init__(self, name, collection, material):
|
||||||
self.name = name
|
self.name = name
|
||||||
@@ -637,66 +526,103 @@ def add_tree_batch(positions, collection, trunk_material, leaf_material):
|
|||||||
leaves.finish()
|
leaves.finish()
|
||||||
|
|
||||||
|
|
||||||
def add_tree_model_instances(positions, collection):
|
def add_natural_tree_instances(positions, collection, trunk_material,
|
||||||
if not positions or not os.path.exists(TREE_MODEL_PATH):
|
leaf_dark_material, leaf_light_material):
|
||||||
return False
|
trunk = MeshBatch("Tree_Natural_Trunks", collection, trunk_material)
|
||||||
|
lower = MeshBatch("Tree_Natural_Crowns_Dark", collection, leaf_dark_material)
|
||||||
|
upper = MeshBatch("Tree_Natural_Crowns_Light", collection, leaf_light_material)
|
||||||
|
trunk_sides = 9
|
||||||
|
crown_sides = 9
|
||||||
|
crown_rings = 5
|
||||||
|
|
||||||
before = set(bpy.data.objects)
|
def add_blob(batch, cx, cy, cz, rx, ry, rz, phase, squash=1.0):
|
||||||
try:
|
start = len(batch.vertices)
|
||||||
import_model(TREE_MODEL_PATH)
|
for ring in range(crown_rings):
|
||||||
except Exception as exc:
|
latitude = -math.pi / 2 + math.pi * ring / (crown_rings - 1)
|
||||||
print("TREE_MODEL_IMPORT_FAILED", exc)
|
ring_radius = math.cos(latitude)
|
||||||
return False
|
for side in range(crown_sides):
|
||||||
|
angle = math.tau * side / crown_sides
|
||||||
template_objects = [obj for obj in bpy.data.objects if obj not in before]
|
wobble = (
|
||||||
template_meshes = [obj for obj in template_objects if obj.type == "MESH"]
|
1.0 +
|
||||||
if not template_meshes:
|
0.14 * math.sin(phase + side * 1.31 + ring * 0.83) +
|
||||||
for obj in template_objects:
|
0.07 * math.sin(phase * 0.7 + side * 2.11)
|
||||||
bpy.data.objects.remove(obj, do_unlink=True)
|
)
|
||||||
return False
|
batch.vertices.append((
|
||||||
|
cx + rx * ring_radius * math.cos(angle) * wobble,
|
||||||
assign_tree_model_materials(template_meshes)
|
cy + ry * ring_radius * math.sin(angle) * wobble,
|
||||||
for obj in template_objects:
|
cz + rz * math.sin(latitude) * squash,
|
||||||
link_object_to_collection(obj, collection)
|
))
|
||||||
|
for ring in range(crown_rings - 1):
|
||||||
min_z = min(
|
for side in range(crown_sides):
|
||||||
(obj.matrix_world @ Vector(corner)).z
|
next_side = (side + 1) % crown_sides
|
||||||
for obj in template_meshes
|
batch.faces.append((
|
||||||
for corner in obj.bound_box
|
start + ring * crown_sides + side,
|
||||||
)
|
start + ring * crown_sides + next_side,
|
||||||
max_z = max(
|
start + (ring + 1) * crown_sides + next_side,
|
||||||
(obj.matrix_world @ Vector(corner)).z
|
start + (ring + 1) * crown_sides + side,
|
||||||
for obj in template_meshes
|
))
|
||||||
for corner in obj.bound_box
|
|
||||||
)
|
|
||||||
source_height = max(0.1, max_z - min_z)
|
|
||||||
|
|
||||||
base_shift = Matrix.Translation((0.0, 0.0, -min_z))
|
|
||||||
for obj in template_objects:
|
|
||||||
obj.matrix_world = base_shift @ obj.matrix_world
|
|
||||||
obj.hide_viewport = True
|
|
||||||
obj.hide_render = True
|
|
||||||
obj.name = "Tree_Template_" + obj.name
|
|
||||||
|
|
||||||
for index, (x, y, height) in enumerate(positions):
|
for index, (x, y, height) in enumerate(positions):
|
||||||
target_height = max(4.6, min(9.2, height * 1.12))
|
target_height = max(4.8, min(8.8, height * 1.08))
|
||||||
scale = target_height / source_height
|
phase = index * 1.61803398875
|
||||||
yaw = Matrix.Rotation((index * 1.61803398875) % math.tau, 4, "Z")
|
trunk_height = target_height * (0.48 + 0.05 * math.sin(phase))
|
||||||
transform = Matrix.Translation((x, y, 0.0)) @ yaw @ Matrix.Diagonal(
|
trunk_radius = max(0.13, target_height * 0.038)
|
||||||
(scale, scale, scale, 1.0)
|
lean_x = math.sin(phase * 1.7) * target_height * 0.025
|
||||||
)
|
lean_y = math.cos(phase * 1.3) * target_height * 0.025
|
||||||
for template in template_objects:
|
|
||||||
inst = template.copy()
|
|
||||||
if template.data:
|
|
||||||
inst.data = template.data
|
|
||||||
inst.animation_data_clear()
|
|
||||||
inst.matrix_world = transform @ template.matrix_world
|
|
||||||
inst.hide_viewport = False
|
|
||||||
inst.hide_render = False
|
|
||||||
inst.name = "Tree_Model_" + str(index)
|
|
||||||
collection.objects.link(inst)
|
|
||||||
|
|
||||||
return True
|
base = len(trunk.vertices)
|
||||||
|
trunk_levels = [
|
||||||
|
(0.0, trunk_radius),
|
||||||
|
(trunk_height * 0.55, trunk_radius * 0.78),
|
||||||
|
(trunk_height, trunk_radius * 0.48),
|
||||||
|
]
|
||||||
|
for level_index, (z, radius) in enumerate(trunk_levels):
|
||||||
|
offset_x = lean_x * level_index / (len(trunk_levels) - 1)
|
||||||
|
offset_y = lean_y * level_index / (len(trunk_levels) - 1)
|
||||||
|
for side in range(trunk_sides):
|
||||||
|
angle = math.tau * side / trunk_sides
|
||||||
|
trunk.vertices.append((
|
||||||
|
x + offset_x + radius * math.cos(angle),
|
||||||
|
y + offset_y + radius * math.sin(angle),
|
||||||
|
z,
|
||||||
|
))
|
||||||
|
trunk.faces.append(tuple(base + i for i in range(trunk_sides - 1, -1, -1)))
|
||||||
|
for level_index in range(len(trunk_levels) - 1):
|
||||||
|
row = base + level_index * trunk_sides
|
||||||
|
next_row = row + trunk_sides
|
||||||
|
for side in range(trunk_sides):
|
||||||
|
next_side = (side + 1) % trunk_sides
|
||||||
|
trunk.faces.append((row + side, row + next_side,
|
||||||
|
next_row + next_side, next_row + side))
|
||||||
|
top_row = base + (len(trunk_levels) - 1) * trunk_sides
|
||||||
|
trunk.faces.append(tuple(top_row + i for i in range(trunk_sides)))
|
||||||
|
|
||||||
|
crown_x = x + lean_x
|
||||||
|
crown_y = y + lean_y
|
||||||
|
crown_z = trunk_height + target_height * 0.22
|
||||||
|
crown_r = target_height * (0.35 + 0.035 * math.sin(phase * 0.9))
|
||||||
|
|
||||||
|
# Dark lower mass gives the canopy volume when viewed obliquely.
|
||||||
|
add_blob(lower, crown_x, crown_y, crown_z - crown_r * 0.08,
|
||||||
|
crown_r * 0.95, crown_r * 0.78, crown_r * 0.52,
|
||||||
|
phase, squash=0.82)
|
||||||
|
add_blob(lower, crown_x - crown_r * 0.46, crown_y + crown_r * 0.05,
|
||||||
|
crown_z - crown_r * 0.02, crown_r * 0.62, crown_r * 0.50,
|
||||||
|
crown_r * 0.42, phase + 0.8, squash=0.80)
|
||||||
|
add_blob(lower, crown_x + crown_r * 0.42, crown_y - crown_r * 0.08,
|
||||||
|
crown_z, crown_r * 0.58, crown_r * 0.48,
|
||||||
|
crown_r * 0.40, phase + 1.9, squash=0.80)
|
||||||
|
|
||||||
|
# Lighter upper clumps break the silhouette without adding heavy geometry.
|
||||||
|
add_blob(upper, crown_x + crown_r * 0.05, crown_y + crown_r * 0.04,
|
||||||
|
crown_z + crown_r * 0.34, crown_r * 0.70,
|
||||||
|
crown_r * 0.58, crown_r * 0.38, phase + 2.7, squash=0.74)
|
||||||
|
add_blob(upper, crown_x - crown_r * 0.24, crown_y - crown_r * 0.22,
|
||||||
|
crown_z + crown_r * 0.23, crown_r * 0.46,
|
||||||
|
crown_r * 0.40, crown_r * 0.30, phase + 3.5, squash=0.72)
|
||||||
|
trunk.finish()
|
||||||
|
lower.finish()
|
||||||
|
upper.finish()
|
||||||
|
|
||||||
|
|
||||||
def polygon_area(ring):
|
def polygon_area(ring):
|
||||||
@@ -741,7 +667,7 @@ def add_scrub_patch(name, ring, material, collection):
|
|||||||
width = max(0.1, xmax - xmin)
|
width = max(0.1, xmax - xmin)
|
||||||
depth = max(0.1, ymax - ymin)
|
depth = max(0.1, ymax - ymin)
|
||||||
area = polygon_area(ring)
|
area = polygon_area(ring)
|
||||||
clump_count = max(8, min(70, int(area / 24.0) + 6))
|
clump_count = max(10, min(90, int(area / 18.0) + 8))
|
||||||
sides = 10
|
sides = 10
|
||||||
rings = 4
|
rings = 4
|
||||||
|
|
||||||
@@ -780,8 +706,8 @@ def add_scrub_patch(name, ring, material, collection):
|
|||||||
if not point_in_polygon((x, y), ring):
|
if not point_in_polygon((x, y), ring):
|
||||||
continue
|
continue
|
||||||
scale = 0.65 + 0.55 * ((attempts * 0.754877666) % 1.0)
|
scale = 0.65 + 0.55 * ((attempts * 0.754877666) % 1.0)
|
||||||
add_dome(x, y, 0.82 * scale, 0.64 * scale,
|
add_dome(x, y, 0.95 * scale, 0.72 * scale,
|
||||||
0.18 + 0.14 * scale, attempts * 0.91)
|
0.34 + 0.28 * scale, attempts * 0.91)
|
||||||
added += 1
|
added += 1
|
||||||
|
|
||||||
obj = batch.finish()
|
obj = batch.finish()
|
||||||
@@ -905,7 +831,7 @@ def build(args):
|
|||||||
scrub_mat = make_textured_material(
|
scrub_mat = make_textured_material(
|
||||||
"Scrub Ground Cover", "leafy_grass_diff_1k.jpg",
|
"Scrub Ground Cover", "leafy_grass_diff_1k.jpg",
|
||||||
"leafy_grass_nor_gl_1k.jpg", roughness=0.96, scale=13.0,
|
"leafy_grass_nor_gl_1k.jpg", roughness=0.96, scale=13.0,
|
||||||
tint=(0.05, 0.34, 0.08), tint_factor=0.42)
|
tint=(0.09, 0.32, 0.07), tint_factor=0.42)
|
||||||
fountain_mats = {
|
fountain_mats = {
|
||||||
"fountain_stone": make_material("Fountain Stone", (0.42, 0.45, 0.43), 0.72),
|
"fountain_stone": make_material("Fountain Stone", (0.42, 0.45, 0.43), 0.72),
|
||||||
"fountain_water": make_material("Fountain Water", (0.03, 0.32, 0.42), 0.16, 0.05),
|
"fountain_water": make_material("Fountain Water", (0.03, 0.32, 0.42), 0.16, 0.05),
|
||||||
@@ -1068,13 +994,28 @@ def build(args):
|
|||||||
trees.extend(row_samples)
|
trees.extend(row_samples)
|
||||||
row_tree_count += len(row_samples)
|
row_tree_count += len(row_samples)
|
||||||
if trees:
|
if trees:
|
||||||
if not add_tree_model_instances(trees, props_c):
|
tree_style = args.get("tree_style")
|
||||||
|
if tree_style == "natural":
|
||||||
tree_trunk = make_textured_material(
|
tree_trunk = make_textured_material(
|
||||||
"Tree Trunk", "bark_brown_01_diff_1k.jpg",
|
"Tree Trunk", "bark_brown_01_diff_1k.jpg",
|
||||||
"bark_brown_01_nor_gl_1k.jpg", roughness=0.92, scale=5.0)
|
"bark_brown_01_nor_gl_1k.jpg", roughness=0.92, scale=5.0)
|
||||||
tree_leaf = make_material("Tree Crown", (0.08, 0.30, 0.09), 0.88)
|
leaf_dark = make_material("Tree Crown Dark", (0.065, 0.25, 0.055), 0.90)
|
||||||
|
add_procedural_surface(leaf_dark,
|
||||||
|
((0.035, 0.14, 0.035), (0.12, 0.36, 0.08)),
|
||||||
|
scale=3.2, detail=3.8, bump_strength=0.08)
|
||||||
|
leaf_light = make_material("Tree Crown Light", (0.13, 0.42, 0.09), 0.88)
|
||||||
|
add_procedural_surface(leaf_light,
|
||||||
|
((0.07, 0.25, 0.05), (0.22, 0.56, 0.13)),
|
||||||
|
scale=3.6, detail=3.4, bump_strength=0.07)
|
||||||
|
add_natural_tree_instances(trees, props_c, tree_trunk,
|
||||||
|
leaf_dark, leaf_light)
|
||||||
|
else:
|
||||||
|
tree_trunk = make_textured_material(
|
||||||
|
"Tree Trunk", "bark_brown_01_diff_1k.jpg",
|
||||||
|
"bark_brown_01_nor_gl_1k.jpg", roughness=0.92, scale=5.0)
|
||||||
|
tree_leaf = make_material("Tree Crown", (0.10, 0.36, 0.08), 0.88)
|
||||||
add_procedural_surface(tree_leaf,
|
add_procedural_surface(tree_leaf,
|
||||||
((0.035, 0.16, 0.045), (0.12, 0.42, 0.13)),
|
((0.04, 0.18, 0.04), (0.18, 0.50, 0.12)),
|
||||||
scale=2.8, detail=3.2, bump_strength=0.10)
|
scale=2.8, detail=3.2, bump_strength=0.10)
|
||||||
add_tree_batch(trees, props_c, tree_trunk, tree_leaf)
|
add_tree_batch(trees, props_c, tree_trunk, tree_leaf)
|
||||||
|
|
||||||
@@ -1165,4 +1106,4 @@ def build(args):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
build(cli_args())
|
build(cli_args())
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"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": true,
|
||||||
|
"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": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"id": "nantaizi-lake-innovation-valley",
|
||||||
|
"input": "/Users/que01/Desktop/南台子湖创新谷OSM.osm",
|
||||||
|
"outputRoot": "/Users/que01/osm2streets-qgis-workflow/outputs",
|
||||||
|
"qgisApp": "/Applications/QGIS.app",
|
||||||
|
"blenderApp": "/Applications/Blender.app",
|
||||||
|
"stages": {
|
||||||
|
"intermediates": true,
|
||||||
|
"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,17 +1,23 @@
|
|||||||
{
|
{
|
||||||
"qgisApp": "/Applications/QGIS.app",
|
"id": "my-area",
|
||||||
"input": "/absolute/path/to/input.osm",
|
"input": "/absolute/path/to/input.osm",
|
||||||
"outDir": "/absolute/path/to/osm2streets_web_out",
|
"outputRoot": "/absolute/path/to/outputs",
|
||||||
"gpkg": "/absolute/path/to/output.gpkg",
|
"qgisApp": "/Applications/QGIS.app",
|
||||||
"project": "/absolute/path/to/output.qgz",
|
"blenderApp": "/Applications/Blender.app",
|
||||||
"preview": "/absolute/path/to/output_preview.png",
|
"stages": {
|
||||||
"arrowScale": 0.8,
|
"intermediates": true,
|
||||||
"clipPad": 0.002,
|
"blender": true,
|
||||||
"canvasPad": 0.001,
|
"cesium": true
|
||||||
"previewPad": 0.0007,
|
},
|
||||||
"canvasExtent": null,
|
"qgis": {
|
||||||
"previewExtent": null,
|
"arrowScale": 0.8,
|
||||||
"layerPrefix": "osm2streets",
|
"clipPad": 0.002,
|
||||||
|
"canvasPad": 0.001,
|
||||||
|
"previewPad": 0.0007,
|
||||||
|
"canvasExtent": null,
|
||||||
|
"previewExtent": null,
|
||||||
|
"layerPrefix": "osm2streets"
|
||||||
|
},
|
||||||
"osm2streets": {
|
"osm2streets": {
|
||||||
"debug_each_step": false,
|
"debug_each_step": false,
|
||||||
"dual_carriageway_experiment": false,
|
"dual_carriageway_experiment": false,
|
||||||
@@ -20,10 +26,7 @@
|
|||||||
"osm2lanes": true
|
"osm2lanes": true
|
||||||
},
|
},
|
||||||
"blender": {
|
"blender": {
|
||||||
"scene": "/absolute/path/to/scene.blend",
|
"treeStyle": "natural",
|
||||||
"render": "/absolute/path/to/preview.png",
|
"officeOverrides": ""
|
||||||
"glb": "/absolute/path/to/cesium.glb",
|
|
||||||
"metadata": "/absolute/path/to/cesium.json",
|
|
||||||
"office_overrides": ""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+12
-1
@@ -1,5 +1,16 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2026-07-27
|
||||||
|
|
||||||
|
- 实验分支新增 Cesium 车辆巡航预览:从 OSM 可行驶 `highway` 提取 bounds 内路线,输出 `<area-id>-vehicle-route.json`,并在预览页中驱动车辆循环移动。
|
||||||
|
- 巡航路线从道路中心线向右偏移约 1.3 米,车辆模型改为无 logo 的轻量预览车。
|
||||||
|
- 车辆巡航预览支持多辆车同时行驶,并通过 `Vehicle` 下拉框选择 Follow 目标。
|
||||||
|
- 将项目主入口重构为区域资产管线:`scripts/build-area.js`。
|
||||||
|
- 新增 `config/areas/nantaizi-lake-innovation-valley.json` 和 `config/areas/hanyang-block.json`,支持按 OSM 输入生成独立输出目录。
|
||||||
|
- `npm run build` 现在默认走区域资产管线;旧 QGIS 管线保留为 `npm run build:qgis`。
|
||||||
|
- `cesium` 阶段会生成 `<area-id>-cesium-preview.html` 本地预览页。
|
||||||
|
- 修复 Blender 脚本对 `--tree-style` 和 `--office-overrides` 这类连字符参数的解析。
|
||||||
|
|
||||||
## 2026-07-24
|
## 2026-07-24
|
||||||
|
|
||||||
- Blender 场景生成器通用化:`generate_nantaizi.py` → `generate_scene.py`
|
- Blender 场景生成器通用化:`generate_nantaizi.py` → `generate_scene.py`
|
||||||
@@ -20,4 +31,4 @@
|
|||||||
- Added [config/hanyang-block.json](/Users/que01/osm2streets-qgis-workflow/config/hanyang-block.json) for `/Users/que01/Desktop/汉阳区区块.osm`.
|
- Added [config/hanyang-block.json](/Users/que01/osm2streets-qgis-workflow/config/hanyang-block.json) for `/Users/que01/Desktop/汉阳区区块.osm`.
|
||||||
- Added [config/examples/template.json](/Users/que01/osm2streets-qgis-workflow/config/examples/template.json) for new areas.
|
- Added [config/examples/template.json](/Users/que01/osm2streets-qgis-workflow/config/examples/template.json) for new areas.
|
||||||
- Updated OSM node coordinate parsing to support both single-quoted and double-quoted XML attributes.
|
- Updated OSM node coordinate parsing to support both single-quoted and double-quoted XML attributes.
|
||||||
- Verified QGIS outputs for both a smaller Overpass-style XML input and a larger JOSM-generated `.osm` input.
|
- Verified QGIS outputs for both a smaller Overpass-style XML input and a larger JOSM-generated `.osm` input.
|
||||||
Generated
+4
-4
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "osm2streets-qgis-workflow",
|
"name": "osm-asset-pipeline",
|
||||||
"version": "0.1.0",
|
"version": "0.3.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "osm2streets-qgis-workflow",
|
"name": "osm-asset-pipeline",
|
||||||
"version": "0.1.0",
|
"version": "0.3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"osm2streets-js-node": "0.1.4"
|
"osm2streets-js-node": "0.1.4"
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-4
@@ -1,12 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "osm-gis-pipeline",
|
"name": "osm-asset-pipeline",
|
||||||
"version": "0.2.0",
|
"version": "0.3.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "commonjs",
|
"type": "commonjs",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "node scripts/build-osm2streets-qgis.js"
|
"build": "node scripts/build-area.js",
|
||||||
|
"build:area": "node scripts/build-area.js",
|
||||||
|
"build:qgis": "node scripts/build-osm2streets-qgis.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"osm2streets-js-node": "0.1.4"
|
"osm2streets-js-node": "0.1.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Executable
+1049
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user