add ply import into the file menu.

This commit is contained in:
Campbell Barton 2011-01-14 00:23:21 +00:00
parent ac5b048e99
commit 3bf46c57c9
2 changed files with 38 additions and 14 deletions

@ -23,16 +23,31 @@ if "bpy" in locals():
import imp
if "export_ply" in locals():
imp.reload(export_ply)
if "import_ply" in locals():
imp.reload(import_ply)
import bpy
from bpy.props import *
from io_utils import ExportHelper
from io_utils import ImportHelper, ExportHelper
class ImportPLY(bpy.types.Operator, ImportHelper):
'''Load a BVH motion capture file'''
bl_idname = "import_mesh.ply"
bl_label = "Import PLY"
filename_ext = ".ply"
filter_glob = StringProperty(default="*.ply", options={'HIDDEN'})
def execute(self, context):
from . import import_ply
return import_ply.load(self, context, **self.as_keywords(ignore=("filter_glob",)))
class ExportPLY(bpy.types.Operator, ExportHelper):
'''Export a single object as a stanford PLY with normals, colours and texture coordinates.'''
bl_idname = "export.ply"
bl_idname = "export_mesh.ply"
bl_label = "Export PLY"
filename_ext = ".ply"
@ -64,16 +79,22 @@ class ExportPLY(bpy.types.Operator, ExportHelper):
row.prop(self, "use_colors")
def menu_func(self, context):
def menu_func_import(self, context):
self.layout.operator(ImportPLY.bl_idname, text="Stanford (.ply)")
def menu_func_export(self, context):
self.layout.operator(ExportPLY.bl_idname, text="Stanford (.ply)")
def register():
bpy.types.INFO_MT_file_export.append(menu_func)
bpy.types.INFO_MT_file_import.append(menu_func_import)
bpy.types.INFO_MT_file_export.append(menu_func_export)
def unregister():
bpy.types.INFO_MT_file_export.remove(menu_func)
bpy.types.INFO_MT_file_import.remove(menu_func_import)
bpy.types.INFO_MT_file_export.remove(menu_func_export)
if __name__ == "__main__":
register()

@ -302,13 +302,17 @@ def load_ply(filepath):
uv[:] = ply_uv[j]
if colindices:
# XXX25 TODO
'''
faces = obj['face']
for i, f in enumerate(vcol_lay.data):
# XXX, colors dont come in right, needs further investigation.
ply_col = mesh_colors[i]
for j, col in enumerate(f.col):
if len(faces[i]) == 4:
f_col = f.color1, f.color2, f.color3, f.color4
else:
f_col = f.color1, f.color2, f.color3
for j, col in enumerate(f_col):
col.r, col.g, col.b = ply_col[j]
'''
mesh.update()
@ -318,12 +322,11 @@ def load_ply(filepath):
obj = bpy.data.objects.new(ply_name, mesh)
scn.objects.link(obj)
scn.objects.active = obj
obj.select = True
print('\nSuccessfully imported %r in %.3f sec' % (filepath, time.time() - t))
def main():
load_ply("/fe/ply/shark.ply")
if __name__ == '__main__':
main()
def load(operator, context, filepath=""):
load_ply(filepath)
return {'FINISHED'}