- Edited
I'm getting some strange behavior, not sure if it's from the SurfaceTool or the MeshDataTool.
To create a cube, I define 8 vertices, and I feed them into the SurfaceTool in a certain order, and everything seems fine, except when I use SurfaceTool.index()
, instead of the resulting mesh having 24 vertices, it has 26 vertices, according to the MeshDataTool.
I commented the lines that were feeding the vertices from the faces and found out one of the faces is going wrong, but I have no idea why. I'm feeding its vertices in the exact same order for every face. I tried changing the order of those vertices, and most configurations go wrong, except at least one (see the comment on line 25 below).
I'm not sure this is gonna be a problem, but I'd like to understand what's happening here just in case. I'm I missing something, or is the SurfaceTool not indexing properly, or is the MeshDataTool not reading the mesh properly?
# --------------------------------------------------------------------------
# Reference
#
# 010 110 Z
# Vertices A0 ---------- B1 Faces Top -Y
# 011 / | 111 / | | North
# E4 ---------- F5 | | /
# | | | | -X West ----- 0 ----- East X
# | D3 -------|-- C2 / |
# | / 000 | / 100 South |
# H7 ---------- G6 Y Bottom
# 001 101 -Z
# --------------------------------------------------------------------------
var a = Vector3(0, 1, 0)
var b = Vector3(1, 1, 0)
var c = Vector3(1, 0, 0)
var d = Vector3(0, 0, 0)
var e = Vector3(0, 1, 1)
var f = Vector3(1, 1, 1)
var g = Vector3(1, 0, 1)
var h = Vector3(0, 0, 1)
var faces = [
# b,a,d, b,d,c, # N
e,f,g, e,g,h, # S <-- these triangles go wrong (but 'e,f,g, h,e,g' works)
# a,e,h, a,h,d, # W
# f,b,c, f,c,g, # E
# a,b,f, a,f,e, # T
# h,g,c, h,c,d # B
]
surface_tool.begin(Mesh.PRIMITIVE_TRIANGLES)
for v in faces: surface_tool.add_vertex(v)
surface_tool.index()
surface_tool.generate_normals()
var mesh = sft.commit()
mesh_instance.mesh = mesh
mesh_data_tool.create_from_surface(mesh, 0)
# the results are just like if I didn't use SurfaceTool.index():
print("Faces: ", mesh_data_tool.get_face_count()) # 2
print("Edges: ", mesh_data_tool.get_edge_count()) # 6 - should be 5
print("Verts: ", mesh_data_tool.get_vertex_count()) # 6 - should be 4