You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.5 KiB
56 lines
1.5 KiB
8 months ago
|
import re
|
||
|
|
||
|
# 读取输入文件
|
||
|
with open("PMCases/PolyDifPolyThickFace/entDataZJU_Des.txt", "r") as file:
|
||
|
data = file.read()
|
||
|
|
||
|
# 使用正则表达式提取vertexInfo和indexInfo
|
||
|
vertex_info_match = re.findall(r"vertexInfo:\s*([\d\.\-,;\s]+)", data)
|
||
|
index_info_match = re.findall(r"indexInfo:\s*([\d,;\s]+)", data)
|
||
|
face_info_match = re.findall(r"faceInfo:\s*([\d;,;\s]+)", data)
|
||
|
|
||
|
if not vertex_info_match or not index_info_match or not face_info_match:
|
||
|
raise ValueError("Input data format is incorrect")
|
||
|
|
||
|
# 合并所有匹配到的vertexInfo
|
||
|
vertex_info = []
|
||
|
for match in vertex_info_match:
|
||
|
vertex_info.extend(match.split(";"))
|
||
|
|
||
|
# 合并所有匹配到的indexInfo
|
||
|
index_info = []
|
||
|
for match in index_info_match:
|
||
|
index_info.extend(match.split(","))
|
||
|
|
||
|
# 合并所有匹配到的faceInfo
|
||
|
face_info = []
|
||
|
for match in face_info_match:
|
||
|
face_info.extend(match.split(";"))
|
||
|
|
||
|
# 转换vertexInfo为uvector3格式
|
||
|
vertex_list = [
|
||
|
f"uvector3{{{', '.join(v.split(','))}}}" for v in vertex_info if v.strip()
|
||
|
]
|
||
|
|
||
|
# 转换indexInfo为整数列表
|
||
|
index_list = [str(i) for i in index_info if i.strip()]
|
||
|
|
||
|
# 转换faceInfo为uvector2i格式
|
||
|
face_list = [f"uvector2i{{{', '.join(f.split(','))}}}" for f in face_info if f.strip()]
|
||
|
|
||
|
# 生成C++代码
|
||
|
cpp_code = f"""primitiveDescriptions[0] = std::make_shared<MeshDesc>(MeshDesc(
|
||
|
{{
|
||
|
{', '.join(vertex_list)}
|
||
|
}},
|
||
|
{{{','.join(index_list)}}},
|
||
|
{{{', '.join(face_list)}}}
|
||
|
));"""
|
||
|
|
||
|
# 输出结果
|
||
|
print(cpp_code)
|
||
|
|
||
|
# 将结果写入文件
|
||
|
with open("output.cpp", "w") as file:
|
||
|
file.write(cpp_code)
|