Files
BL/README.md
2025-08-05 19:57:46 +08:00

172 lines
4.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 3D光学系统建模工具
这个项目可以将JSON格式的光学系统数据转换为3D模型使用Blender生成高质量的可视化结果。
## 🚀 功能特色
- **精确几何建模**: 支持平面、抛物面、双曲面等光学面型
- **智能材质系统**: 自动应用金属、透明、发光材质
- **多格式输出**: 生成OBJ、GLB、Blender文件和渲染图像
- **自动场景设置**: 包含相机、灯光和渲染配置
- **错误处理**: 完善的异常处理和日志输出
## 📋 系统要求
- **Blender 3.6+** (推荐 4.0+)
- **Python 3.7+**
- **操作系统**: Windows, macOS, Linux
## 🛠️ 安装
### 1. 安装Blender
从官网下载并安装: https://www.blender.org/download/
### 2. 验证安装
```bash
# 确保可以从命令行访问Blender
blender --version
```
### 3. 准备数据文件
确保您的JSON数据文件格式正确包含以下结构
```json
{
"p": [0.0, 0.0, 0.0],
"q": [1.0, 0.0, 0.0, 0.0],
"name": "",
"children": [
{
"p": [x, y, z],
"q": [w, x, y, z],
"name": "对象名称",
"face_type": "symm",
"face_geometry": "plane|parabola|hyperbola",
"face_f": 1.0,
"face_g": 1.0,
"draw_material": "metal|nothing"
}
]
}
```
## 🎯 使用方法
### 方法1: 使用运行脚本(推荐)
```bash
python run_blender.py -i jsonfile.json
```
### 方法2: 直接运行Blender脚本
```bash
blender --background --python toModel.py
```
### 方法3: 在Blender GUI中运行
1. 打开Blender
2. 切换到Scripting工作区
3. 打开 `toModel.py` 文件
4. 点击运行按钮
## 📁 输出文件
运行成功后,将生成以下文件:
| 文件名 | 格式 | 用途 |
|--------|------|------|
| `optical_system.obj` | OBJ | 通用3D模型格式可在大多数3D软件中打开 |
| `optical_system.glb` | GLB | Web友好格式适合在线展示 |
| `optical_system.blend` | Blender | 完整的Blender工程文件包含所有材质和设置 |
| `optical_system_render.png` | PNG | 高质量渲染图像 |
## ⚙️ 配置选项
### 几何体类型支持
- **plane**: 平面镜/透镜
- **parabola**: 抛物面镜,使用 `face_f` 参数控制焦距
- **hyperbola**: 双曲面镜,使用 `face_f``face_g` 参数
### 材质类型
- **metal**: 金属反射材质(淡蓝色)
- **nothing**: 透明材质10%不透明度)
- **其他**: 发光材质(橙色光)
### 渲染设置
- 分辨率: 1920x1080
- 引擎: Cycles支持高质量材质
- 格式: PNG
## 🔧 自定义
### 修改材质
编辑 `toModel.py` 中的材质创建函数:
```python
def create_metal_material():
# 修改金属材质属性
bsdf.inputs["Base Color"].default_value = (R, G, B, A)
bsdf.inputs["Metallic"].default_value = 0.0-1.0
bsdf.inputs["Roughness"].default_value = 0.0-1.0
```
### 调整几何体精度
修改分辨率参数:
```python
mesh = create_parabolic_surface(face_f, size=2.0, resolution=64) # 更高精度
```
### 修改渲染设置
```python
scene.render.resolution_x = 3840 # 4K分辨率
scene.render.resolution_y = 2160
```
## 🐛 故障排除
### 常见问题
**Q: 找不到Blender**
```
❌ 错误未找到Blender安装
```
A: 确保Blender已正确安装并添加到系统PATH中
**Q: 几何体创建失败**
```
创建几何体时出错: ...
```
A: 检查JSON数据中的 `face_f``face_g` 参数是否为有效数值
**Q: 导出失败**
```
模型导出失败
```
A: 确保有写入权限,检查磁盘空间
### 调试技巧
1. **查看详细日志**: 脚本会输出详细的创建过程
2. **检查JSON数据**: 确保所有必需字段都存在
3. **逐步运行**: 在Blender GUI中逐步执行脚本
## 📈 性能优化
### 大型数据集
- 对于超过100个对象的数据集考虑分批处理
- 降低几何体分辨率以提高性能
- 使用后台模式避免GUI开销
### 内存使用
- 大型模型可能需要8GB+内存
- 监控内存使用必要时重启Blender
## 🤝 贡献
欢迎提交Issue和Pull Request来改进这个工具
## 📄 许可证
本项目采用MIT许可证。
## 🙏 致谢
- Blender Foundation 提供的优秀3D建模软件
- 光学系统设计社区的支持和反馈