279 lines
5.1 KiB
Markdown
279 lines
5.1 KiB
Markdown
# 光学系统光路可视化
|
||
|
||
本项目提供了多种方式来可视化光学系统的光路数据,使用 Blender 生成高质量的 3D 光路模型。
|
||
|
||
## 文件说明
|
||
|
||
### 数据文件
|
||
|
||
- `miao_light_path_tsingtao.json` - 光路数据文件,包含多条光路的 3D 坐标点
|
||
|
||
### 可视化脚本
|
||
|
||
#### 基础版本
|
||
|
||
- `light_path_blender.py` - 基础版 Blender 光路可视化脚本
|
||
- `run_light_path.py` - 运行基础版脚本的启动器
|
||
|
||
#### 增强版本
|
||
|
||
- `light_path_advanced.py` - 增强版 Blender 光路可视化脚本
|
||
- `run_light_path_advanced.py` - 运行增强版脚本的启动器
|
||
|
||
#### 其他工具
|
||
|
||
- `linemodel.py` - 使用 matplotlib 的 2D/3D 光路可视化脚本
|
||
|
||
## 功能特点
|
||
|
||
### 基础版本功能
|
||
|
||
- ✅ 3D 光路曲线可视化
|
||
- ✅ 不同颜色区分光路
|
||
- ✅ 发光材质效果
|
||
- ✅ 自动相机调整
|
||
- ✅ 导出 GLB 和 Blend 文件
|
||
- ✅ 渲染高质量图像
|
||
|
||
### 增强版本功能
|
||
|
||
- ✅ 所有基础版本功能
|
||
- ✅ 光路起点和终点标记(绿色/红色球体)
|
||
- ✅ 光路密度体积可视化
|
||
- ✅ 更高质量的光照和材质
|
||
- ✅ 更精确的相机控制
|
||
- ✅ 更丰富的渲染选项
|
||
|
||
## 使用方法
|
||
|
||
### 方法 1:使用运行脚本(推荐)
|
||
|
||
#### 基础版本
|
||
|
||
```bash
|
||
python run_light_path.py
|
||
```
|
||
|
||
#### 增强版本
|
||
|
||
```bash
|
||
python run_light_path_advanced.py
|
||
```
|
||
|
||
### 方法 2:直接在 Blender 中运行
|
||
|
||
1. 打开 Blender
|
||
2. 切换到 Scripting 工作区
|
||
3. 打开 `light_path_blender.py` 或 `light_path_advanced.py`
|
||
4. 点击运行脚本
|
||
|
||
### 方法 3:命令行运行
|
||
|
||
```bash
|
||
blender --background --python light_path_blender.py
|
||
# 或
|
||
blender --background --python light_path_advanced.py
|
||
```
|
||
|
||
## 输出文件
|
||
|
||
### 基础版本输出
|
||
|
||
- `light_path_model.blend` - Blender 工程文件
|
||
- `light_path_model.glb` - Web 友好格式(可在浏览器中查看)
|
||
- `light_path_render.png` - 渲染图像
|
||
|
||
### 增强版本输出
|
||
|
||
- `light_path_advanced.blend` - Blender 工程文件
|
||
- `light_path_advanced.glb` - Web 友好格式
|
||
- `light_path_render.png` - 高质量渲染图像
|
||
|
||
## 系统要求
|
||
|
||
### 必需软件
|
||
|
||
- **Blender 3.0+** - 3D 建模和渲染软件
|
||
- 下载地址:https://www.blender.org/download/
|
||
- **Python 3.7+** - 编程语言环境
|
||
|
||
### 推荐配置
|
||
|
||
- **操作系统**: Windows 10+, macOS 10.15+, Ubuntu 18.04+
|
||
- **内存**: 8GB+ RAM
|
||
- **显卡**: 支持 OpenGL 3.3+的显卡
|
||
- **存储**: 至少 2GB 可用空间
|
||
|
||
## 安装步骤
|
||
|
||
1. **安装 Blender**
|
||
|
||
```bash
|
||
# macOS (使用Homebrew)
|
||
brew install --cask blender
|
||
|
||
# Ubuntu/Debian
|
||
sudo apt update
|
||
sudo apt install blender
|
||
|
||
# Windows
|
||
# 从官网下载安装包
|
||
```
|
||
|
||
2. **验证安装**
|
||
|
||
```bash
|
||
blender --version
|
||
```
|
||
|
||
3. **运行脚本**
|
||
```bash
|
||
python run_light_path.py
|
||
```
|
||
|
||
## 故障排除
|
||
|
||
### 常见问题
|
||
|
||
#### 1. 找不到 Blender
|
||
|
||
```
|
||
❌ 错误:未找到Blender安装
|
||
```
|
||
|
||
**解决方案**:
|
||
|
||
- 确保 Blender 已正确安装
|
||
- 将 Blender 添加到系统 PATH
|
||
- 手动指定 Blender 路径
|
||
|
||
#### 2. 找不到数据文件
|
||
|
||
```
|
||
❌ 错误:未找到光路数据文件 miao_light_path_tsingtao.json
|
||
```
|
||
|
||
**解决方案**:
|
||
|
||
- 确保数据文件在当前目录
|
||
- 检查文件名是否正确
|
||
|
||
#### 3. 渲染失败
|
||
|
||
```
|
||
❌ 渲染失败
|
||
```
|
||
|
||
**解决方案**:
|
||
|
||
- 检查显卡驱动是否最新
|
||
- 降低渲染分辨率
|
||
- 使用 Eevee 渲染引擎替代 Cycles
|
||
|
||
#### 4. 内存不足
|
||
|
||
```
|
||
❌ 内存不足错误
|
||
```
|
||
|
||
**解决方案**:
|
||
|
||
- 关闭其他应用程序
|
||
- 减少光路数量(修改脚本)
|
||
- 增加系统虚拟内存
|
||
|
||
### 性能优化
|
||
|
||
#### 提高渲染速度
|
||
|
||
1. 使用 Eevee 渲染引擎
|
||
2. 降低采样数量
|
||
3. 减少光路数量
|
||
4. 使用 GPU 渲染
|
||
|
||
#### 减少内存使用
|
||
|
||
1. 分批处理光路
|
||
2. 简化几何体
|
||
3. 优化材质设置
|
||
|
||
## 自定义配置
|
||
|
||
### 修改光路颜色
|
||
|
||
在脚本中修改 `base_colors` 列表:
|
||
|
||
```python
|
||
base_colors = [
|
||
(1.0, 0.2, 0.2, 1.0), # 红色
|
||
(0.2, 1.0, 0.2, 1.0), # 绿色
|
||
# 添加更多颜色...
|
||
]
|
||
```
|
||
|
||
### 调整光路粗细
|
||
|
||
修改 `thickness` 参数:
|
||
|
||
```python
|
||
obj = create_light_path_curve(path, f"light_path_{i}", thickness=0.05)
|
||
```
|
||
|
||
### 更改渲染质量
|
||
|
||
修改采样数量:
|
||
|
||
```python
|
||
scene.cycles.samples = 256 # 更高的采样数 = 更好的质量
|
||
```
|
||
|
||
## 技术细节
|
||
|
||
### 数据格式
|
||
|
||
光路数据采用 JSON 格式,结构如下:
|
||
|
||
```json
|
||
[
|
||
[
|
||
[x1, y1, z1],
|
||
[x2, y2, z2],
|
||
...
|
||
],
|
||
[
|
||
[x1, y1, z1],
|
||
[x2, y2, z2],
|
||
...
|
||
]
|
||
]
|
||
```
|
||
|
||
### 渲染引擎
|
||
|
||
- **Cycles**: 基于物理的渲染引擎,提供最真实的光照效果
|
||
- **Eevee**: 实时渲染引擎,速度更快但质量稍低
|
||
|
||
### 导出格式
|
||
|
||
- **GLB**: 二进制 GLTF 格式,适合 Web 展示
|
||
- **Blend**: Blender 原生格式,包含完整项目信息
|
||
|
||
## 许可证
|
||
|
||
本项目采用 MIT 许可证,详见 LICENSE 文件。
|
||
|
||
## 贡献
|
||
|
||
欢迎提交 Issue 和 Pull Request 来改进这个项目!
|
||
|
||
## 联系方式
|
||
|
||
如有问题或建议,请通过以下方式联系:
|
||
|
||
- 提交 GitHub Issue
|
||
- 发送邮件至项目维护者
|
||
|
||
---
|
||
|
||
**注意**: 确保在运行脚本前备份重要文件,脚本会生成新的文件并可能覆盖同名文件。
|