- 新增XCAF转换器,直接从STP到GLB保留完整装配层级 - 修复HTTP API与CLI参数不一致问题 - 修复静默吞没错误的问题,遵循快速失败原则 - 清理旧文件,整理测试文件到tests目录 - 添加URL下载支持,可直接转换远程STP文件 - 更新文档,准确描述XCAF装配保留功能 技术改进: - 使用STEPCAFControl_Reader读取带装配信息的STEP文件 - 通过RWGltf_CafWriter直接导出GLB,无需STL中间格式 - 支持CPU多线程并行三角化 - HTTP API和CLI使用完全一致的转换参数 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
100 lines
3.7 KiB
Python
100 lines
3.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
装配结构分析测试脚本
|
|
验证STP文件的装配层级解析是否正确
|
|
"""
|
|
|
|
import sys
|
|
from core.stp_parser import StpFileParser
|
|
|
|
|
|
def analyze_assembly_structure(stp_path: str):
|
|
"""分析STP文件的装配结构"""
|
|
print(f"=== 装配结构分析: {stp_path} ===\n")
|
|
|
|
parser = StpFileParser()
|
|
|
|
# 进度回调
|
|
def progress_callback(progress, message):
|
|
print(f"[{progress:3d}%] {message}")
|
|
|
|
parser.set_progress_callback(progress_callback)
|
|
|
|
try:
|
|
# 解析STP文件
|
|
components = parser.parse_stp_file(stp_path)
|
|
|
|
# 获取层级信息
|
|
hierarchy_info = parser.get_component_hierarchy_info()
|
|
|
|
print(f"\n📊 装配结构统计:")
|
|
print(f" 总组件数: {hierarchy_info['total_components']}")
|
|
print(f" 根组件数: {hierarchy_info['root_components']}")
|
|
print(f" 装配体数: {hierarchy_info['assemblies']}")
|
|
print(f" 叶组件数: {hierarchy_info['leaf_components']}")
|
|
|
|
# 显示根组件
|
|
root_components = parser.get_root_components()
|
|
print(f"\n🌳 根装配体:")
|
|
for i, root in enumerate(root_components, 1):
|
|
print(f" {i}. {root.name}")
|
|
if root.is_assembly and root.children:
|
|
print(f" └─ 包含 {len(root.children)} 个子组件")
|
|
for child_id in root.children[:3]: # 只显示前3个
|
|
child_name = parser._get_component_name_by_id(child_id)
|
|
print(f" ├─ {child_name}")
|
|
if len(root.children) > 3:
|
|
print(f" └─ ... 还有 {len(root.children) - 3} 个")
|
|
|
|
# 显示装配树
|
|
assembly_tree = parser.get_assembly_tree()
|
|
if assembly_tree:
|
|
print(f"\n🔗 装配关系:")
|
|
for parent, children in list(assembly_tree.items())[:5]: # 只显示前5个
|
|
print(f" {parent}:")
|
|
for child in children[:3]: # 每个父组件只显示前3个子组件
|
|
print(f" └─ {child}")
|
|
if len(children) > 3:
|
|
print(f" └─ ... 还有 {len(children) - 3} 个子组件")
|
|
|
|
# 对比原始解析结果
|
|
print(f"\n🔍 组件类型分布:")
|
|
products = len([c for c in components.values() if c.product_id])
|
|
definitions = len([c for c in components.values() if c.product_definition_id])
|
|
print(f" PRODUCT实体: {products}")
|
|
print(f" PRODUCT_DEFINITION实体: {definitions}")
|
|
print(f" 其他实体: {len(components) - products - definitions}")
|
|
|
|
return hierarchy_info
|
|
|
|
except Exception as e:
|
|
print(f"❌ 装配结构分析失败: {e}")
|
|
return None
|
|
|
|
|
|
def compare_with_geometry_split(stp_path: str):
|
|
"""对比装配结构与几何分离的差异"""
|
|
print(f"\n=== 对比分析 ===")
|
|
|
|
hierarchy_info = analyze_assembly_structure(stp_path)
|
|
|
|
if hierarchy_info:
|
|
print(f"\n📈 预期改进效果:")
|
|
print(f" 装配结构方案: {hierarchy_info['total_components']} 个逻辑组件")
|
|
print(f" 几何分离方案: 可能产生数万个几何片段")
|
|
print(f" 层级准确性: 装配结构保持真实层级关系")
|
|
print(f" 用户体验: 装配结构更符合原始设计意图")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) > 1:
|
|
stp_file = sys.argv[1]
|
|
else:
|
|
stp_file = "overall_top_design_asm.stp"
|
|
|
|
try:
|
|
compare_with_geometry_split(stp_file)
|
|
print(f"\n✓ 装配结构分析完成")
|
|
except Exception as e:
|
|
print(f"\n❌ 分析失败: {e}")
|
|
sys.exit(1) |