Update for changes in Blender's API
[blender-addons.git] / io_mesh_ply / __init__.py
blob77259690b019fdbad0286edb82d1ec6c1fd949a8
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 # <pep8-80 compliant>
21 bl_info = {
22 "name": "Stanford PLY format",
23 "author": "Bruce Merry, Campbell Barton",
24 "version": (1, 0, 0),
25 "blender": (2, 74, 0),
26 "location": "File > Import-Export",
27 "description": "Import-Export PLY mesh data withs UV's and vertex colors",
28 "warning": "",
29 "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
30 "Scripts/Import-Export/Stanford_PLY",
31 "support": 'OFFICIAL',
32 "category": "Import-Export"}
34 # Copyright (C) 2004, 2005: Bruce Merry, bmerry@cs.uct.ac.za
35 # Contributors: Bruce Merry, Campbell Barton
37 # To support reload properly, try to access a package var,
38 # if it's there, reload everything
39 if "bpy" in locals():
40 import importlib
41 if "export_ply" in locals():
42 importlib.reload(export_ply)
43 if "import_ply" in locals():
44 importlib.reload(import_ply)
47 import os
48 import bpy
49 from bpy.props import (
50 CollectionProperty,
51 StringProperty,
52 BoolProperty,
53 EnumProperty,
54 FloatProperty,
56 from bpy_extras.io_utils import (
57 ImportHelper,
58 ExportHelper,
59 orientation_helper_factory,
60 axis_conversion,
64 IOPLYOrientationHelper = orientation_helper_factory("IOPLYOrientationHelper", axis_forward='Y', axis_up='Z')
67 class ImportPLY(bpy.types.Operator, ImportHelper):
68 """Load a PLY geometry file"""
69 bl_idname = "import_mesh.ply"
70 bl_label = "Import PLY"
71 bl_options = {'UNDO'}
73 files = CollectionProperty(name="File Path",
74 description="File path used for importing "
75 "the PLY file",
76 type=bpy.types.OperatorFileListElement)
78 directory = StringProperty()
80 filename_ext = ".ply"
81 filter_glob = StringProperty(default="*.ply", options={'HIDDEN'})
83 def execute(self, context):
84 paths = [os.path.join(self.directory, name.name)
85 for name in self.files]
86 if not paths:
87 paths.append(self.filepath)
89 from . import import_ply
91 for path in paths:
92 import_ply.load(self, context, path)
94 return {'FINISHED'}
97 class ExportPLY(bpy.types.Operator, ExportHelper, IOPLYOrientationHelper):
98 """Export a single object as a Stanford PLY with normals, """ \
99 """colors and texture coordinates"""
100 bl_idname = "export_mesh.ply"
101 bl_label = "Export PLY"
103 filename_ext = ".ply"
104 filter_glob = StringProperty(default="*.ply", options={'HIDDEN'})
106 use_mesh_modifiers = BoolProperty(
107 name="Apply Modifiers",
108 description="Apply Modifiers to the exported mesh",
109 default=True,
111 use_normals = BoolProperty(
112 name="Normals",
113 description="Export Normals for smooth and "
114 "hard shaded faces "
115 "(hard shaded faces will be exported "
116 "as individual faces)",
117 default=True,
119 use_uv_coords = BoolProperty(
120 name="UVs",
121 description="Export the active UV layer",
122 default=True,
124 use_colors = BoolProperty(
125 name="Vertex Colors",
126 description="Export the active vertex color layer",
127 default=True,
130 global_scale = FloatProperty(
131 name="Scale",
132 min=0.01, max=1000.0,
133 default=1.0,
136 @classmethod
137 def poll(cls, context):
138 return context.active_object is not None
140 def execute(self, context):
141 from . import export_ply
143 from mathutils import Matrix
145 keywords = self.as_keywords(ignore=("axis_forward",
146 "axis_up",
147 "global_scale",
148 "check_existing",
149 "filter_glob",
151 global_matrix = axis_conversion(to_forward=self.axis_forward,
152 to_up=self.axis_up,
153 ).to_4x4() * Matrix.Scale(self.global_scale, 4)
154 keywords["global_matrix"] = global_matrix
156 filepath = self.filepath
157 filepath = bpy.path.ensure_ext(filepath, self.filename_ext)
159 return export_ply.save(self, context, **keywords)
161 def draw(self, context):
162 layout = self.layout
164 row = layout.row()
165 row.prop(self, "use_mesh_modifiers")
166 row.prop(self, "use_normals")
167 row = layout.row()
168 row.prop(self, "use_uv_coords")
169 row.prop(self, "use_colors")
171 layout.prop(self, "axis_forward")
172 layout.prop(self, "axis_up")
173 layout.prop(self, "global_scale")
176 def menu_func_import(self, context):
177 self.layout.operator(ImportPLY.bl_idname, text="Stanford (.ply)")
180 def menu_func_export(self, context):
181 self.layout.operator(ExportPLY.bl_idname, text="Stanford (.ply)")
184 classes = (
185 ImportPLY,
186 ExportPLY,
190 def register():
191 for cls in classes:
192 bpy.utils.register_class(cls)
194 bpy.types.INFO_MT_file_import.append(menu_func_import)
195 bpy.types.INFO_MT_file_export.append(menu_func_export)
198 def unregister():
199 for cls in classes:
200 bpy.utils.unregister_class(cls)
202 bpy.types.INFO_MT_file_import.remove(menu_func_import)
203 bpy.types.INFO_MT_file_export.remove(menu_func_export)
205 if __name__ == "__main__":
206 register()