diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-01-14 03:23:21 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-01-14 03:23:21 +0300 |
commit | 3bf46c57c972598a17a0eddc8bc70ad3b20a95da (patch) | |
tree | 24a30b7c0f1dad6c6bb16b26efc2211417496293 /release/scripts/op | |
parent | ac5b048e99ddcfe94e6722f7703de95239477201 (diff) |
add ply import into the file menu.
Diffstat (limited to 'release/scripts/op')
-rw-r--r-- | release/scripts/op/io_mesh_ply/__init__.py | 31 | ||||
-rw-r--r-- | release/scripts/op/io_mesh_ply/import_ply.py | 21 |
2 files changed, 38 insertions, 14 deletions
diff --git a/release/scripts/op/io_mesh_ply/__init__.py b/release/scripts/op/io_mesh_ply/__init__.py index d004f542ad1..5802dce4c0a 100644 --- a/release/scripts/op/io_mesh_ply/__init__.py +++ b/release/scripts/op/io_mesh_ply/__init__.py @@ -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() diff --git a/release/scripts/op/io_mesh_ply/import_ply.py b/release/scripts/op/io_mesh_ply/import_ply.py index e0963bfaba7..41d13b310a1 100644 --- a/release/scripts/op/io_mesh_ply/import_ply.py +++ b/release/scripts/op/io_mesh_ply/import_ply.py @@ -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'} |