| Code: |
| import bpy
def writeString(file, string): file.write(bytes(string, 'UTF-8')) filepath = 'D:\JackyFlasche.h' file = open(filepath, "wb") if bpy.app.version[0] < 2 or bpy.app.version[1] < 62: raise Exception("only for Blender 2.62 and above") bpy.ops.object.mode_set(mode='OBJECT') # Can't access cprdinate date in edit mode currently me = bpy.data.meshes[bpy.context.active_object.name] count = 0 for f in me.polygons: for i in f.loop_indices: for j,ul in enumerate(me.uv_layers): count = count + 1 writeString(file, '\n#define kObjectNumberOfVertices %d\n' % ( count )) writeString(file, '\n') writeString(file, '@implmentation %s\n' % ( bpy.context.active_object.name )) writeString(file, '\n') writeString(file, '-(id)init{\n') writeString(file, '\tstatic TexturedVertexData3D ObjectVertexData[] = {\n') for f in me.polygons: for i in f.loop_indices: l = me.loops[i] vert = me.vertices[l.vertex_index] # print(v.co.x, v.co.y, v.co.z) for j,ul in enumerate(me.uv_layers): writeString(file, '\t\t{/*v:*/{%F, %F, %F}, ' % (vert.co.x, vert.co.y, vert.co.z) ) writeString(file, '/*n:*/{%F, %F, %F}, ' % (vert.normal.x, vert.normal.y, vert.normal.z)) writeString(file, '/*t:*/{%F, %F}' % (ul.data[l.index].uv.x, ul.data[l.index].uv.y ) ) writeString(file, '},\n') writeString(file, '\t};\n') writeString(file, '};\n') file.flush() file.close() |
| Code: |
| me = bpy.data.meshes[bpy.context.active_object.name] |
| Code: |
| ob = bpy.context.object
if ob is None or ob.type == 'MESH': print("Need an active Mesh object!") else: me = ob.data |
| Code: |
| ob = bpy.data.objects.get("Cylinder")
if ob is not None and ob.type == 'MESH': print("Object %s - Mesh %s" % (ob.name, ob.data.name)) |
| Code: |
| if bpy.app.version[0] < 2 or bpy.app.version[1] < 62:
raise Exception("only for Blender 2.62 and above") if bpy.app.version < (2,62): ... |
| Code: |
| count = 0
for f in me.polygons: for i in f.loop_indices: for j,ul in enumerate(me.uv_layers): count = count + 1 |
| Code: |
| len(me.loops)
len(me.uv_layers.active.data) |
| Code: |
| for j,ul in enumerate(me.uv_layers): ...
# rather: for ul in me.uv_layers: ... |
| Code: |
| writeString(file, '\t\t{/*v:*/{%F, %F, %F}, ' % (vert.co.x, vert.co.y, vert.co.z) )
writeString(file, '/*n:*/{%F, %F, %F}, ' % (vert.normal.x, vert.normal.y, vert.normal.z)) writeString(file, '/*t:*/{%F, %F}' % (ul.data[l.index].uv.x, ul.data[l.index].uv.y ) ) writeString(file, '\t\t{/*v:*/{%F, %F, %F}, ' % vert.co[:]) writeString(file, '/*n:*/{%F, %F, %F}, ' % vert.normal[:]) writeString(file, '/*t:*/{%F, %F}' % ul.data[l.index].uv[:]) # Special case: Vector objects define __repr__() and __str__(), printing their components #print(v.co) |
| Code: |
| file.flush() # superfluous
file.close() |