5e2812a6f3
v6.2.1 — Blender Integration Addon: - 5 files, 1,732 lines: __init__, operators (9 ops), panels (4 panels) - preferences, vde_bridge (subprocess CLI bridge) - Import/Export STEP, primitives, boolean, SDF→Mesh v6.2.2 — .NET/C# Bindings (VdeSharp): - 8 files: NativeMethods (50+ P/Invoke), BrepModel, MeshData, SdfEngine, Assembly - C API extended with 20 new functions (STEP I/O, Boolean, SDF, Assembly) - vde_capi rebuilt as SHARED library - Example: import STEP → boolean → export v6.2.3 — Developer Docs + Plugin System: - 7 docs: architecture, contributing, API overview, building, testing, plugin-system - plugin_system.h/.cpp: PluginInterface, PluginManager, dlopen/LoadLibrary - README.md updated with v6 features - Syntax-check passed (GCC 10.2.1, -Wall -Wextra -Wpedantic)
188 lines
5.9 KiB
Python
188 lines
5.9 KiB
Python
"""
|
||
preferences.py — VDE 插件偏好设置
|
||
==================================
|
||
在 Blender 偏好设置中添加 VDE 配置面板:
|
||
- VDE Python 库路径
|
||
- Python 解释器路径
|
||
- 状态检测与缓存
|
||
"""
|
||
|
||
import bpy
|
||
from bpy.props import StringProperty, BoolProperty, FloatProperty
|
||
|
||
from . import vde_bridge
|
||
|
||
|
||
class VDEAddonPreferences(bpy.types.AddonPreferences):
|
||
"""VDE 插件偏好设置。"""
|
||
bl_idname = __package__
|
||
|
||
# ══ 路径设置 ══
|
||
vde_lib_path: StringProperty(
|
||
name="VDE 库路径",
|
||
description="VDE Python 包的安装目录(包含 vde/__init__.py 的父目录)",
|
||
default="",
|
||
subtype='DIR_PATH',
|
||
)
|
||
|
||
python_path: StringProperty(
|
||
name="Python 解释器",
|
||
description="用于运行 VDE 子进程的 Python 解释器路径(留空使用当前 Blender Python)",
|
||
default="",
|
||
subtype='FILE_PATH',
|
||
)
|
||
|
||
# ══ 网格化参数 ══
|
||
default_deflection: FloatProperty(
|
||
name="默认网格精度",
|
||
description="B-Rep → Mesh 转换的默认弦高偏差",
|
||
default=0.01,
|
||
min=0.001,
|
||
max=1.0,
|
||
precision=4,
|
||
)
|
||
|
||
default_sdf_resolution: bpy.props.IntProperty(
|
||
name="默认 SDF 分辨率",
|
||
description="Marching Cubes 的默认网格分辨率",
|
||
default=64,
|
||
min=16,
|
||
max=512,
|
||
)
|
||
|
||
# ══ 缓存状态(不持久化) ══
|
||
vde_available: BoolProperty(
|
||
name="VDE 可用",
|
||
default=False,
|
||
options={'SKIP_SAVE'},
|
||
)
|
||
vde_status_message: StringProperty(
|
||
name="状态消息",
|
||
default="未检测",
|
||
options={'SKIP_SAVE'},
|
||
)
|
||
|
||
def draw(self, context):
|
||
layout = self.layout
|
||
|
||
# 标题
|
||
box = layout.box()
|
||
box.label(text="ViewDesignEngine (VDE) 设置", icon='SETTINGS')
|
||
|
||
# 路径设置
|
||
col = box.column(align=True)
|
||
col.prop(self, "vde_lib_path")
|
||
col.prop(self, "python_path")
|
||
|
||
# 检测按钮
|
||
row = box.row(align=True)
|
||
row.operator("vde.check_installation",
|
||
text="检测 VDE 安装", icon='CHECKMARK')
|
||
row.operator("vde.open_docs",
|
||
text="在线文档", icon='URL')
|
||
|
||
# 状态
|
||
if self.vde_available:
|
||
box.label(text=f"✓ {self.vde_status_message}", icon='CHECKMARK')
|
||
else:
|
||
row = box.row()
|
||
row.label(text=f"✗ {self.vde_status_message}", icon='ERROR')
|
||
row = box.row()
|
||
row.label(
|
||
text="VDE 库未连接。请确保 VDE Python 包已安装,",
|
||
icon='INFO'
|
||
)
|
||
row = box.row()
|
||
row.label(
|
||
text="并将「VDE 库路径」设为包含 vde/ 的目录。",
|
||
icon='BLANK1'
|
||
)
|
||
|
||
# 默认参数
|
||
box = layout.box()
|
||
box.label(text="默认参数", icon='PREFERENCES')
|
||
box.prop(self, "default_deflection")
|
||
box.prop(self, "default_sdf_resolution")
|
||
|
||
# 关于
|
||
box = layout.box()
|
||
box.label(text="关于", icon='INFO')
|
||
col = box.column()
|
||
col.label(text="ViewDesignEngine v1.0.0")
|
||
col.label(text="高性能 C++ CAD 计算几何引擎")
|
||
col.label(text="B-Rep | SDF | 布尔 | 网格")
|
||
col.label(
|
||
text="文档: github.com/ViewDesignEngine/ViewDesignEngine"
|
||
)
|
||
|
||
|
||
# ═══════════════════════════════════════════════════════════════
|
||
# 辅助操作符
|
||
# ═══════════════════════════════════════════════════════════════
|
||
|
||
class VDE_OT_check_installation(bpy.types.Operator):
|
||
"""检测 VDE Python 库是否可用。"""
|
||
bl_idname = "vde.check_installation"
|
||
bl_label = "检测 VDE 安装"
|
||
bl_description = "检测 VDE Python 库是否配置正确"
|
||
|
||
def execute(self, context):
|
||
prefs = context.preferences.addons[__package__].preferences
|
||
|
||
self.report({'INFO'}, "正在检测 VDE...")
|
||
|
||
try:
|
||
available, message = vde_bridge.check_vde_available(prefs)
|
||
except Exception as e:
|
||
available, message = False, str(e)
|
||
|
||
prefs.vde_available = available
|
||
prefs.vde_status_message = message
|
||
|
||
if available:
|
||
self.report({'INFO'}, f"VDE 检测成功: {message}")
|
||
else:
|
||
self.report({'ERROR'}, f"VDE 检测失败: {message}")
|
||
|
||
# 刷新 UI
|
||
for area in context.screen.areas:
|
||
if area.type == 'PREFERENCES':
|
||
area.tag_redraw()
|
||
return {'FINISHED'}
|
||
|
||
|
||
class VDE_OT_open_docs(bpy.types.Operator):
|
||
"""在浏览器中打开 VDE 文档。"""
|
||
bl_idname = "vde.open_docs"
|
||
bl_label = "打开文档"
|
||
bl_description = "在浏览器中打开 ViewDesignEngine 在线文档"
|
||
|
||
def execute(self, context):
|
||
import webbrowser
|
||
webbrowser.open(
|
||
"https://github.com/ViewDesignEngine/ViewDesignEngine"
|
||
)
|
||
self.report({'INFO'}, "已在浏览器中打开文档页面。")
|
||
return {'FINISHED'}
|
||
|
||
|
||
# ═══════════════════════════════════════════════════════════════
|
||
# 注册/注销
|
||
# ═══════════════════════════════════════════════════════════════
|
||
|
||
CLASSES = [
|
||
VDEAddonPreferences,
|
||
VDE_OT_check_installation,
|
||
VDE_OT_open_docs,
|
||
]
|
||
|
||
|
||
def register():
|
||
for cls in CLASSES:
|
||
bpy.utils.register_class(cls)
|
||
|
||
|
||
def unregister():
|
||
for cls in reversed(CLASSES):
|
||
bpy.utils.unregister_class(cls)
|