sun_position: fix warning from deleted prop in User Preferences
[blender-addons.git] / io_mesh_ply / __init__.py
blobf99dbffb24e92a9690ae2fd6b0d56f10d6b5508c
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, 1, 0),
25 "blender": (2, 82, 0),
26 "location": "File > Import-Export",
27 "description": "Import-Export PLY mesh data with UVs and vertex colors",
28 "wiki_url": "https://docs.blender.org/manual/en/dev/addons/"
29 "import_export/io_mesh_ply.html",
30 "support": 'OFFICIAL',
31 "category": "Import-Export",
34 # Copyright (C) 2004, 2005: Bruce Merry, bmerry@cs.uct.ac.za
35 # Contributors: Bruce Merry, Campbell Barton
37 if "bpy" in locals():
38 import importlib
39 if "export_ply" in locals():
40 importlib.reload(export_ply)
41 if "import_ply" in locals():
42 importlib.reload(import_ply)
45 import bpy
46 from bpy.props import (
47 CollectionProperty,
48 StringProperty,
49 BoolProperty,
50 FloatProperty,
52 from bpy_extras.io_utils import (
53 ImportHelper,
54 ExportHelper,
55 axis_conversion,
56 orientation_helper
60 class ImportPLY(bpy.types.Operator, ImportHelper):
61 """Load a PLY geometry file"""
62 bl_idname = "import_mesh.ply"
63 bl_label = "Import PLY"
64 bl_options = {'UNDO'}
66 files: CollectionProperty(
67 name="File Path",
68 description=(
69 "File path used for importing "
70 "the PLY file"
72 type=bpy.types.OperatorFileListElement)
74 # Hide opertator properties, rest of this is managed in C. See WM_operator_properties_filesel().
75 hide_props_region: BoolProperty(
76 name="Hide Operator Properties",
77 description="Collapse the region displaying the operator settings",
78 default=True,
81 directory: StringProperty()
83 filename_ext = ".ply"
84 filter_glob: StringProperty(default="*.ply", options={'HIDDEN'})
86 def execute(self, context):
87 import os
89 paths = [os.path.join(self.directory, name.name)
90 for name in self.files]
91 if not paths:
92 paths.append(self.filepath)
94 from . import import_ply
96 for path in paths:
97 import_ply.load(self, context, path)
99 return {'FINISHED'}
102 @orientation_helper(axis_forward='Y', axis_up='Z')
103 class ExportPLY(bpy.types.Operator, ExportHelper):
104 bl_idname = "export_mesh.ply"
105 bl_label = "Export PLY"
106 bl_description = "Export as a Stanford PLY with normals, vertex colors and texture coordinates"
108 filename_ext = ".ply"
109 filter_glob: StringProperty(default="*.ply", options={'HIDDEN'})
111 use_selection: BoolProperty(
112 name="Selection Only",
113 description="Export selected objects only",
114 default=False,
116 use_mesh_modifiers: BoolProperty(
117 name="Apply Modifiers",
118 description="Apply Modifiers to the exported mesh",
119 default=True,
121 use_normals: BoolProperty(
122 name="Normals",
123 description=(
124 "Export Normals for smooth and "
125 "hard shaded faces "
126 "(hard shaded faces will be exported "
127 "as individual faces)"
129 default=True,
131 use_uv_coords: BoolProperty(
132 name="UVs",
133 description="Export the active UV layer",
134 default=True,
136 use_colors: BoolProperty(
137 name="Vertex Colors",
138 description="Export the active vertex color layer",
139 default=True,
142 global_scale: FloatProperty(
143 name="Scale",
144 min=0.01, max=1000.0,
145 default=1.0,
148 def execute(self, context):
149 from . import export_ply
151 from mathutils import Matrix
153 keywords = self.as_keywords(
154 ignore=(
155 "axis_forward",
156 "axis_up",
157 "global_scale",
158 "check_existing",
159 "filter_glob",
162 global_matrix = axis_conversion(
163 to_forward=self.axis_forward,
164 to_up=self.axis_up,
165 ).to_4x4() @ Matrix.Scale(self.global_scale, 4)
166 keywords["global_matrix"] = global_matrix
168 filepath = self.filepath
169 filepath = bpy.path.ensure_ext(filepath, self.filename_ext)
171 return export_ply.save(self, context, **keywords)
173 def draw(self, context):
174 pass
177 class PLY_PT_export_include(bpy.types.Panel):
178 bl_space_type = 'FILE_BROWSER'
179 bl_region_type = 'TOOL_PROPS'
180 bl_label = "Include"
181 bl_parent_id = "FILE_PT_operator"
183 @classmethod
184 def poll(cls, context):
185 sfile = context.space_data
186 operator = sfile.active_operator
188 return operator.bl_idname == "EXPORT_MESH_OT_ply"
190 def draw(self, context):
191 layout = self.layout
192 layout.use_property_split = True
193 layout.use_property_decorate = False # No animation.
195 sfile = context.space_data
196 operator = sfile.active_operator
198 layout.prop(operator, "use_selection")
201 class PLY_PT_export_transform(bpy.types.Panel):
202 bl_space_type = 'FILE_BROWSER'
203 bl_region_type = 'TOOL_PROPS'
204 bl_label = "Transform"
205 bl_parent_id = "FILE_PT_operator"
207 @classmethod
208 def poll(cls, context):
209 sfile = context.space_data
210 operator = sfile.active_operator
212 return operator.bl_idname == "EXPORT_MESH_OT_ply"
214 def draw(self, context):
215 layout = self.layout
216 layout.use_property_split = True
217 layout.use_property_decorate = False # No animation.
219 sfile = context.space_data
220 operator = sfile.active_operator
222 layout.prop(operator, "axis_forward")
223 layout.prop(operator, "axis_up")
224 layout.prop(operator, "global_scale")
227 class PLY_PT_export_geometry(bpy.types.Panel):
228 bl_space_type = 'FILE_BROWSER'
229 bl_region_type = 'TOOL_PROPS'
230 bl_label = "Geometry"
231 bl_parent_id = "FILE_PT_operator"
233 @classmethod
234 def poll(cls, context):
235 sfile = context.space_data
236 operator = sfile.active_operator
238 return operator.bl_idname == "EXPORT_MESH_OT_ply"
240 def draw(self, context):
241 layout = self.layout
242 layout.use_property_split = True
243 layout.use_property_decorate = False # No animation.
245 sfile = context.space_data
246 operator = sfile.active_operator
248 layout.prop(operator, "use_mesh_modifiers")
249 layout.prop(operator, "use_normals")
250 layout.prop(operator, "use_uv_coords")
251 layout.prop(operator, "use_colors")
254 def menu_func_import(self, context):
255 self.layout.operator(ImportPLY.bl_idname, text="Stanford (.ply)")
258 def menu_func_export(self, context):
259 self.layout.operator(ExportPLY.bl_idname, text="Stanford (.ply)")
262 classes = (
263 ImportPLY,
264 ExportPLY,
265 PLY_PT_export_include,
266 PLY_PT_export_transform,
267 PLY_PT_export_geometry,
271 def register():
272 for cls in classes:
273 bpy.utils.register_class(cls)
275 bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
276 bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
279 def unregister():
280 for cls in classes:
281 bpy.utils.unregister_class(cls)
283 bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
284 bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
287 if __name__ == "__main__":
288 register()