180 lines
5.0 KiB
Python
180 lines
5.0 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
SUWImpl 快速开始脚本 - 在Blender中使用
|
||
简化版本,仅测试核心功能
|
||
"""
|
||
|
||
print("🚀 SUWImpl 快速开始测试")
|
||
print("=" * 40)
|
||
|
||
# 1. 基本导入测试
|
||
print("\n📝 步骤1: 导入模块")
|
||
try:
|
||
from suw_impl import SUWImpl, Point3d, Vector3d, Transformation
|
||
print("✅ 模块导入成功")
|
||
except Exception as e:
|
||
print(f"❌ 模块导入失败: {e}")
|
||
print("💡 请确认文件路径正确并添加到sys.path")
|
||
exit(1)
|
||
|
||
# 2. 创建实例
|
||
print("\n📝 步骤2: 创建SUWImpl实例")
|
||
try:
|
||
impl = SUWImpl.get_instance()
|
||
print(f"✅ 实例创建成功: {type(impl).__name__}")
|
||
except Exception as e:
|
||
print(f"❌ 实例创建失败: {e}")
|
||
exit(1)
|
||
|
||
# 3. 初始化系统
|
||
print("\n📝 步骤3: 初始化系统")
|
||
try:
|
||
impl.startup()
|
||
print("✅ 系统初始化成功")
|
||
except Exception as e:
|
||
print(f"❌ 系统初始化失败: {e}")
|
||
exit(1)
|
||
|
||
# 4. 测试几何类
|
||
print("\n📝 步骤4: 测试几何类")
|
||
try:
|
||
# Point3d测试
|
||
p1 = Point3d(0, 0, 0)
|
||
p2 = Point3d.parse("10,20,30")
|
||
print(f"✅ Point3d: {p1} → {p2}")
|
||
|
||
# Vector3d测试
|
||
v1 = Vector3d(1, 0, 0)
|
||
v2 = v1.normalize()
|
||
print(f"✅ Vector3d: {v1} → normalized: {v2}")
|
||
|
||
# Transformation测试
|
||
t1 = Transformation(p1, v1, Vector3d(0, 1, 0), Vector3d(0, 0, 1))
|
||
print(f"✅ Transformation: origin={t1.origin}")
|
||
|
||
except Exception as e:
|
||
print(f"❌ 几何类测试失败: {e}")
|
||
|
||
# 5. 测试基本命令
|
||
print("\n📝 步骤5: 测试基本命令")
|
||
try:
|
||
# c00 - 清空选择
|
||
impl.c00({"uid": "quick_test_001"})
|
||
print("✅ c00命令执行成功")
|
||
|
||
# c01 - 单位设置
|
||
impl.c01({
|
||
"uid": "quick_test_001",
|
||
"unit_drawing": "quick_test.dwg",
|
||
"drawing_name": "快速测试"
|
||
})
|
||
print("✅ c01命令执行成功")
|
||
|
||
except Exception as e:
|
||
print(f"❌ 基本命令测试失败: {e}")
|
||
|
||
# 6. 测试材质系统
|
||
print("\n📝 步骤6: 测试材质系统")
|
||
try:
|
||
# 添加测试材质
|
||
impl.add_mat_rgb("quick_test_red", 1.0, 255, 0, 0)
|
||
impl.add_mat_rgb("quick_test_blue", 0.8, 0, 0, 255)
|
||
print("✅ 材质添加成功")
|
||
|
||
# 获取默认材质
|
||
texture = impl.get_texture("mat_normal")
|
||
print(f"✅ 默认材质获取: {texture is not None}")
|
||
|
||
except Exception as e:
|
||
print(f"❌ 材质系统测试失败: {e}")
|
||
|
||
# 7. 检查Blender环境
|
||
print("\n📝 步骤7: 检查Blender环境")
|
||
try:
|
||
import bpy
|
||
print(f"✅ Blender API可用: {bpy.app.version_string}")
|
||
|
||
# 获取当前场景信息
|
||
scene = bpy.context.scene
|
||
print(f"✅ 当前场景: {scene.name}")
|
||
print(f"✅ 对象数量: {len(scene.objects)}")
|
||
|
||
except ImportError:
|
||
print("⚠️ Blender API不可用 (存根模式)")
|
||
except Exception as e:
|
||
print(f"❌ Blender环境检查失败: {e}")
|
||
|
||
# 8. 创建简单测试对象 (仅在Blender中)
|
||
print("\n📝 步骤8: 创建测试对象")
|
||
try:
|
||
import bpy
|
||
|
||
# 删除默认立方体
|
||
if "Cube" in bpy.data.objects:
|
||
bpy.data.objects.remove(bpy.data.objects["Cube"], do_unlink=True)
|
||
|
||
# 创建测试立方体
|
||
bpy.ops.mesh.primitive_cube_add(location=(0, 0, 0), size=2)
|
||
cube = bpy.context.active_object
|
||
cube.name = "SUW_QuickTest_Cube"
|
||
|
||
# 添加材质
|
||
mat = bpy.data.materials.new(name="SUW_QuickTest_Material")
|
||
mat.use_nodes = True
|
||
|
||
# 安全设置材质颜色,兼容不同Blender版本
|
||
try:
|
||
# 尝试找到Principled BSDF节点
|
||
bsdf = None
|
||
for node in mat.node_tree.nodes:
|
||
if "BSDF" in node.type:
|
||
bsdf = node
|
||
break
|
||
|
||
if bsdf and hasattr(bsdf, 'inputs'):
|
||
# 尝试设置基础颜色
|
||
if "Base Color" in bsdf.inputs:
|
||
bsdf.inputs["Base Color"].default_value = (
|
||
0.8, 0.2, 0.8, 1.0) # 紫色
|
||
elif len(bsdf.inputs) > 0:
|
||
bsdf.inputs[0].default_value = (0.8, 0.2, 0.8, 1.0) # 紫色
|
||
except Exception as e:
|
||
print(f"⚠️ 设置材质颜色失败: {e}")
|
||
|
||
cube.data.materials.append(mat)
|
||
|
||
print("✅ 测试对象创建成功")
|
||
|
||
except ImportError:
|
||
print("⚠️ 跳过对象创建 (非Blender环境)")
|
||
except Exception as e:
|
||
print(f"❌ 测试对象创建失败: {e}")
|
||
|
||
# 9. 总结
|
||
print("\n" + "=" * 40)
|
||
print("📊 快速测试完成!")
|
||
print("🎯 如果所有步骤都显示 ✅,说明SUWImpl在Blender中运行正常")
|
||
print("💡 接下来可以:")
|
||
print(" - 运行完整测试: exec(open('blender_test.py').read())")
|
||
print(" - 查看使用指南: BLENDER_TEST_GUIDE.md")
|
||
print(" - 测试具体功能: 使用c03、c04等命令")
|
||
|
||
# 10. 基本使用示例
|
||
print("\n🎯 基本使用示例:")
|
||
print("```python")
|
||
print("# 创建木工零件")
|
||
print("part_data = {")
|
||
print(' "uid": "example_001",')
|
||
print(' "parts": {')
|
||
print(' "p001": {')
|
||
print(' "name": "测试板材",')
|
||
print(' "finals": {"f001": {"typ": 1, "obv": {...}}}')
|
||
print(' }')
|
||
print(' }')
|
||
print("}")
|
||
print("impl.c03(part_data)")
|
||
print("```")
|
||
|
||
print("\n🎉 快速开始测试结束!")
|