diff --git a/blender/dump.py b/blender/dump.py new file mode 100644 index 0000000..6a70a3b --- /dev/null +++ b/blender/dump.py @@ -0,0 +1,83 @@ +import json + +import bmesh +import bpy + +def main(context): + print(context.object.data) + print(type(context.object.data)) + print(dir(context.object.data)) + + if context.object.mode == 'OBJECT': + bpy.ops.object.mode_set(mode='EDIT') + + m = context.object.data + b = bmesh.from_edit_mesh(m) + + print("info:") + + data = {} + print("verts:") + for vert in b.verts: + print(" ", vert.index, ":", list(vert.co)) + data['vertices'] = [list(vert.co) for vert in b.verts] + + print("edges for vert:") + for vert in b.verts: + print(" ", vert.index, ":", [e.index for e in vert.link_edges]) + print("faces for vert:") + for vert in b.verts: + print(" ", vert.index, ":", [e.index for e in vert.link_faces]) + + print("edges:") + edges = [] + for edge in b.edges: + print(" ", edge.index, ":", [v.index for v in edge.verts]) + edges.append([v.index for v in edge.verts]) + data['edges'] = edges + + print("faces for edge:") + for edge in b.edges: + print(" ", edge.index, ":", [f.index for f in edge.link_faces]) + + + print("faces:") + faces = [] + for face in b.faces: + print(" ", face.index, ":", [v.index for v in face.verts]) + faces.append([v.index for v in face.verts]) + data['faces'] = faces + + print("edges for face:") + for face in b.faces: + print(" ", face.index, ":", [e.index for e in face.edges]) + + + print(json.dumps(data)) + bpy.ops.object.mode_set(mode='OBJECT') + +class DumpMesh(bpy.types.Operator): + '''dump mesh for surfaces''' + bl_idname = 'object.dump_mesh' + bl_label = 'Dump Mesh' + + @classmethod + def poll(cls, context): + return context.active_object is not None + + def execute(self, context): + main(context) + return {'FINISHED'} + + +def register(): + bpy.utils.register_class(DumpMesh) + + +def unregister(): + bpy.utils.unregister_class(DumpMesh) + + +if __name__ == '__main__': + register() + bpy.ops.object.dump_mesh() diff --git a/dump.py b/dump.py deleted file mode 100644 index 6ef71d4..0000000 --- a/dump.py +++ /dev/null @@ -1,50 +0,0 @@ -import bpy -import bmesh -import json - -bpy.data.objects['Cube'].select = True -bpy.ops.object.mode_set(mode='EDIT') - -m = bpy.data.meshes['Cube'] -b = bmesh.from_edit_mesh(m) - -print("info:") - -data = {} -print("verts:") -for vert in b.verts: - print(" ", vert.index, ":", list(vert.co)) -data['vertices'] = [list(vert.co) for vert in b.verts] - -print("edges for vert:") -for vert in b.verts: - print(" ", vert.index, ":", [e.index for e in vert.link_edges]) -print("faces for vert:") -for vert in b.verts: - print(" ", vert.index, ":", [e.index for e in vert.link_faces]) - -print("edges:") -edges = [] -for edge in b.edges: - print(" ", edge.index, ":", [v.index for v in edge.verts]) - edges.append([v.index for v in edge.verts]) -data['edges'] = edges - -print("faces for edge:") -for edge in b.edges: - print(" ", edge.index, ":", [f.index for f in edge.link_faces]) - - -print("faces:") -faces = [] -for face in b.faces: - print(" ", face.index, ":", [v.index for v in face.verts]) - faces.append([v.index for v in face.verts]) -data['faces'] = faces - -print("edges for face:") -for face in b.faces: - print(" ", face.index, ":", [e.index for e in face.edges]) - - -print(json.dumps(data))