forked from K0lb3/UnityPy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeshExporter.py
More file actions
59 lines (50 loc) · 1.82 KB
/
Copy pathMeshExporter.py
File metadata and controls
59 lines (50 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
def export_mesh(m_Mesh):
if m_Mesh.m_VertexCount <= 0:
return False
sb = [f"g {m_Mesh.name}\r\n"]
# region Vertices
if not m_Mesh.m_Vertices:
return False
c = 3
if len(m_Mesh.m_Vertices) == m_Mesh.m_VertexCount * 4:
c = 4
for v in range(int(m_Mesh.m_VertexCount)):
sb.append("v {0} {1} {2}\r\n".format(
-m_Mesh.m_Vertices[v * c], m_Mesh.m_Vertices[v * c + 1], m_Mesh.m_Vertices[v * c + 2]))
# endregion
# region UV
if m_Mesh.m_UV0:
if len(m_Mesh.m_UV0) == m_Mesh.m_VertexCount * 2:
c = 2
elif len(m_Mesh.m_UV0) == m_Mesh.m_VertexCount * 3:
c = 3
for v in range(int(m_Mesh.m_VertexCount)):
sb.append("vt {0} {1}\r\n".format(
m_Mesh.m_UV0[v * c], m_Mesh.m_UV0[v * c + 1]))
# endregion
# region Normals
if m_Mesh.m_Normals:
if len(m_Mesh.m_Normals) == m_Mesh.m_VertexCount * 3:
c = 3
elif len(m_Mesh.m_Normals) == m_Mesh.m_VertexCount * 4:
c = 4
for v in range(int(m_Mesh.m_VertexCount)):
sb.append("vn {0} {1} {2}\r\n".format(
-m_Mesh.m_Normals[v * c], m_Mesh.m_Normals[v * c + 1], m_Mesh.m_Normals[v * c + 2]))
# endregion
# region Face
sum = 0
for i in range(len(m_Mesh.m_SubMeshes)):
sb.append(f"g {m_Mesh.name}_{i}\r\n")
indexCount = m_Mesh.m_SubMeshes[i].indexCount
end = sum + indexCount // 3
for f in range(sum, end):
sb.append("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\r\n".format(
m_Mesh.m_Indices[f * 3 + 2] + 1,
m_Mesh.m_Indices[f * 3 + 1] + 1,
m_Mesh.m_Indices[f * 3] + 1)
)
sum = end
# endregion
sb = "".join(sb).replace("NaN", "0").replace("e", "E")
return sb