Hi, I’m trying to generate mesh data for rebuild mesh in Godot.
According to Godot manual [link], I need to get data of indices, verts, uvs, and normals.
I try to generate code and easily paste it into Godot.
When the shape is simple, it works fine but when the shape becomes more complex, I start to get the wrong shape in Godot. How can I fix it?
import bpy
import os
obj = bpy.context.active_object
mesh = obj.data
normals = []
indices = []
verts = []
verts_temp = []
uvs = []
for vert in mesh.vertices:
verts_temp.append(vert.co.xyz)
for face in mesh.polygons:
indices.append(face.vertices[0])
indices.append(face.vertices[1])
indices.append(face.vertices[2])
for i in range(len(face.vertices)):
v = mesh.vertices[face.vertices[i]]
normals.append([v.normal[0],v.normal[1],v.normal[2]])
for uv_layer in mesh.uv_layers:
for x in range(len(uv_layer.data)):
uvs.append(uv_layer.data[x].uv)
for i in indices:
verts.append(verts_temp[i])
print("#___________________indices___________________")
for i in indices:
print(" indices.push_back(" + str(i) + ")")
print("#___________________verts___________________")
for a in verts:
print(" vertices.push_back(Vector3" + str(a).replace("<Vector ", "").replace(">", "") + ")")
print("#___________________uvs___________________")
for b in uvs:
print(" uvs.push_back(Vector2" + str(b).replace("<Vector ", "").replace(">", "") + ")")
print("#___________________normals___________________")
for k in normals:
# print(" normals.push_back(Vector3(" + str(k).replace("[", "").replace("]", "") + "))")
print(" normals.push_back(Vector3.FORWARD)")
Hi, thanks for the reply! I follow your advice that converts all the meshes from quad to triangle but still the same.
I also try ico sphere and the shape is still not complete.
Hmm the tetrahedron in the (very small) first image gave me the idea. The new objects in the (bigger) image not only seems to lack some polgons the also seem to have another orientaton… too unfamilar with godot her (wanna change this…)
but on the other side, this was my post with the most spelling errors i ever had so far here on BA… so i was in a hurry (double checked on this one )
So next time: just go on telling after one or two days so someone else could pick this up. (And i also wanted to have a deeper look into godot yet.)