参数输入输出模型文件
This commit is contained in:
34
toModel.py
34
toModel.py
@@ -3,6 +3,19 @@ import json
|
||||
import mathutils
|
||||
import os
|
||||
import bmesh
|
||||
import sys
|
||||
|
||||
# 获取命令行参数
|
||||
def get_json_path():
|
||||
"""从命令行参数获取JSON文件路径"""
|
||||
if len(sys.argv) > 5: # Blender传递的参数格式: blender --background --python script.py -- json_path
|
||||
# 查找 -- 分隔符后的参数
|
||||
for i, arg in enumerate(sys.argv):
|
||||
if arg == "--" and i + 1 < len(sys.argv):
|
||||
return sys.argv[i + 1]
|
||||
|
||||
# 如果没有找到参数,使用默认路径
|
||||
return "./e8caffb4622e03b1495bbc1ed13fce13.json"
|
||||
|
||||
# 清空场景
|
||||
bpy.ops.wm.read_factory_settings(use_empty=True)
|
||||
@@ -11,12 +24,23 @@ bpy.ops.wm.read_factory_settings(use_empty=True)
|
||||
bpy.context.scene.render.engine = 'CYCLES'
|
||||
|
||||
# 加载 JSON 文件
|
||||
json_path = "./e8caffb4622e03b1495bbc1ed13fce13.json"
|
||||
with open(json_path, 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
json_path = get_json_path()
|
||||
print(f"尝试加载JSON文件:{json_path}")
|
||||
|
||||
print(f"已加载JSON文件:{json_path}")
|
||||
print(f"包含 {len(data['children'])} 个对象")
|
||||
try:
|
||||
with open(json_path, 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
print(f"✅ 成功加载JSON文件:{json_path}")
|
||||
print(f"包含 {len(data['children'])} 个对象")
|
||||
except FileNotFoundError:
|
||||
print(f"❌ 错误:找不到JSON文件 {json_path}")
|
||||
sys.exit(1)
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"❌ 错误:JSON文件格式错误 {e}")
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f"❌ 错误:加载JSON文件时出错 {e}")
|
||||
sys.exit(1)
|
||||
|
||||
# 创建金属材质
|
||||
def create_metal_material():
|
||||
|
||||
Reference in New Issue
Block a user