This commit is contained in:
nicomacbookpro
2025-08-28 15:10:09 +08:00
parent bc75e5e298
commit 529384a8e6
13 changed files with 18262 additions and 3 deletions

155
run_light_path.py Normal file
View File

@@ -0,0 +1,155 @@
#!/usr/bin/env python3
"""
运行光路可视化脚本
使用Blender生成光学系统光路模型
使用方法:
1. 确保已安装Blender
2. 运行此脚本: python run_light_path.py
输出文件:
- light_path_model.blend - Blender工程文件
- light_path_model.glb - Web友好格式
- light_path_render.png - 渲染图像
"""
import subprocess
import sys
import os
import platform
def find_blender():
"""查找Blender可执行文件"""
system = platform.system()
common_paths = []
if system == "Windows":
common_paths = [
r"C:\Program Files\Blender Foundation\Blender 3.6\blender.exe",
r"C:\Program Files\Blender Foundation\Blender 4.0\blender.exe",
r"C:\Program Files\Blender Foundation\Blender 4.1\blender.exe",
r"C:\Program Files (x86)\Blender Foundation\Blender 3.6\blender.exe",
]
elif system == "Darwin": # macOS
common_paths = [
"/Applications/Blender.app/Contents/MacOS/Blender",
"/usr/local/bin/blender",
]
elif system == "Linux":
common_paths = [
"/usr/bin/blender",
"/usr/local/bin/blender",
"/snap/bin/blender",
]
# 首先尝试从PATH中找到blender
try:
result = subprocess.run(["which", "blender"], capture_output=True, text=True)
if result.returncode == 0:
return result.stdout.strip()
except:
pass
# 尝试常见路径
for path in common_paths:
if os.path.exists(path):
return path
return None
def run_light_path_script():
"""运行光路可视化Blender脚本"""
blender_path = find_blender()
if not blender_path:
print("❌ 错误未找到Blender安装")
print("\n请确保已安装Blender并且可以从命令行访问")
print("下载地址: https://www.blender.org/download/")
return False
print(f"✅ 找到Blender: {blender_path}")
# 检查必要文件
script_path = os.path.abspath("light_path_blender.py")
if not os.path.exists(script_path):
print(f"❌ 错误:未找到脚本文件 {script_path}")
return False
json_path = os.path.abspath("miao_light_path_tsingtao.json")
if not os.path.exists(json_path):
print(f"❌ 错误:未找到光路数据文件 {json_path}")
return False
print("🚀 开始运行光路可视化脚本...")
print("这可能需要几分钟时间,请耐心等待...")
try:
# 运行Blender脚本
cmd = [
blender_path,
"--background", # 后台运行
"--python", script_path
]
result = subprocess.run(cmd, capture_output=True, text=True, timeout=600) # 10分钟超时
if result.returncode == 0:
print("✅ 光路可视化脚本执行成功!")
print("\n输出信息:")
print(result.stdout)
# 检查生成的文件
expected_files = [
"light_path_model.blend",
"light_path_model.glb",
"light_path_render.png"
]
print("\n📁 生成的文件:")
for filename in expected_files:
if os.path.exists(filename):
size = os.path.getsize(filename)
print(f"{filename} ({size:,} bytes)")
else:
print(f"{filename} (未找到)")
return True
else:
print("❌ 光路可视化脚本执行失败")
print("错误输出:")
print(result.stderr)
if result.stdout:
print("标准输出:")
print(result.stdout)
return False
except subprocess.TimeoutExpired:
print("❌ 脚本执行超时超过10分钟")
return False
except Exception as e:
print(f"❌ 执行时出错: {e}")
return False
def main():
print("🎨 光学系统光路可视化")
print("=" * 40)
print("使用Blender生成3D光路模型")
print()
if run_light_path_script():
print("\n🎉 任务完成!")
print("\n您可以:")
print("1. 使用Blender打开 light_path_model.blend 文件进行编辑")
print("2. 在Web浏览器中查看 light_path_model.glb 文件")
print("3. 查看渲染图像 light_path_render.png")
print("\n光路模型特点:")
print("- 每条光路使用不同颜色区分")
print("- 发光材质效果,更真实的光线表现")
print("- 3D曲线表示支持多角度查看")
print("- 自动调整相机位置以最佳角度展示")
else:
print("\n❌ 任务失败,请检查错误信息")
sys.exit(1)
if __name__ == "__main__":
main()