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.
68 lines
2.0 KiB
68 lines
2.0 KiB
import re
|
|
|
|
# 读取输入文件
|
|
# with open("PMCases/PolyDifFace/entDataZJU_Des.txt", "r") as file:
|
|
# with open("PMCases/PolyDifPoly/entDataZJU_Src.txt", "r") as file:
|
|
with open("PMCases/PolyDifPolyThickFace/entDataZJU_Src.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()
|
|
f"{{{', '.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()
|
|
f"{{{', '.join(f.split(','))}}}" for f in face_info if f.strip()
|
|
]
|
|
|
|
# 生成C++代码
|
|
cpp_code = f"""
|
|
{{
|
|
{', '.join(vertex_list)}
|
|
}},
|
|
{{{','.join(index_list)}}},
|
|
{{{', '.join(face_list)}}}
|
|
"""
|
|
# 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)
|
|
|