Import leak points files.

This commit is contained in:
Bill Currie 2012-09-16 12:57:17 +09:00
parent 4fc9316320
commit 0ed535214e
2 changed files with 37 additions and 0 deletions

View file

@ -244,6 +244,18 @@ class QFECPanel(bpy.types.Panel):
row.prop(scene.qfmap, "script")
row.operator("scene.parse_entity_classes", text="", icon="FILE_REFRESH")
class ImportPoints(bpy.types.Operator, ImportHelper):
'''Load a Quake points File'''
bl_idname = "import_mesh.quake_points"
bl_label = "Import points"
filename_ext = ".pts"
filter_glob = StringProperty(default="*.pts", options={'HIDDEN'})
def execute(self, context):
keywords = self.as_keywords (ignore=("filter_glob",))
return import_map.import_pts(self, context, **keywords)
class ImportMap(bpy.types.Operator, ImportHelper):
'''Load a Quake map File'''
bl_idname = "import_mesh.quake_map"
@ -275,6 +287,7 @@ class ExportMap(bpy.types.Operator, ExportHelper):
def menu_func_import(self, context):
self.layout.operator(ImportMap.bl_idname, text="Quake map (.map)")
self.layout.operator(ImportPoints.bl_idname, text="Quake points (.pts)")
def menu_func_export(self, context):
self.layout.operator(ExportMap.bl_idname, text="Quake map (.map)")

View file

@ -227,3 +227,27 @@ def import_map(operator, context, filepath):
process_entity(ent, wads)
bpy.context.user_preferences.edit.use_global_undo = True
return {'FINISHED'}
def import_pts(operator, context, filepath):
bpy.context.user_preferences.edit.use_global_undo = False
for obj in bpy.context.scene.objects:
obj.select = False
lines = open(filepath, "rt").readlines()
verts = [None] * len(lines)
edges = [None] * (len(lines) - 1)
for i, line in enumerate(lines):
if i:
edges[i - 1] = (i - 1, i)
v = line.split(" ")
verts[i] = tuple(map(lambda x: float(x), v))
mesh = bpy.data.meshes.new("leak points")
mesh.from_pydata(verts, edges, [])
mesh.update()
obj = bpy.data.objects.new("leak points", mesh)
bpy.context.scene.objects.link(obj)
bpy.context.scene.objects.active=obj
obj.select = True
bpy.context.user_preferences.edit.use_global_undo = True
return {'FINISHED'}