blender 2.63.0 python accessing data with bmesh changes
I’ve just updated my blender to 2.63 and discovered that this uses the new bmesh! Bmesh gives you better control to manipulate your 3d models. For more information take a look at this. Anyway with this big change that means there are more changes to the python api. Which means i have to update my addons again sigh. I’m learning what the new changes are and thought i’d post a little code snippet on how to access some of the usual data through this now. The below code i used just on a simple triangulated cube, it may help point you in the right direction if you are having similar problems as I was.
import bpy
obj = bpy.data.objects['Cube']
mesh = obj.data
normals = []
indices = []
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]])
verts = []
for vert in mesh.vertices:
verts.append(vert.co.xyz)
uvs = []
for uv_layer in mesh.uv_layers:
for x in range(len(uv_layer.data)):
uvs.append(uv_layer.data[x].uv)
print(indices)
print(verts)
print(uvs)
print(normals)
Comments
Comments are currently closed