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 #####
22 "name": "Stanford PLY format",
23 "author": "Bruce Merry, Campbell Barton",
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
39 if "export_ply" in locals():
40 importlib
.reload(export_ply
)
41 if "import_ply" in locals():
42 importlib
.reload(import_ply
)
46 from bpy
.props
import (
52 from bpy_extras
.io_utils
import (
60 class ImportPLY(bpy
.types
.Operator
, ImportHelper
):
61 """Load a PLY geometry file"""
62 bl_idname
= "import_mesh.ply"
63 bl_label
= "Import PLY"
66 files
: CollectionProperty(
69 "File path used for importing "
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",
81 directory
: StringProperty()
84 filter_glob
: StringProperty(default
="*.ply", options
={'HIDDEN'})
86 def execute(self
, context
):
89 paths
= [os
.path
.join(self
.directory
, name
.name
)
90 for name
in self
.files
]
92 paths
.append(self
.filepath
)
94 from . import import_ply
97 import_ply
.load(self
, context
, path
)
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",
116 use_mesh_modifiers
: BoolProperty(
117 name
="Apply Modifiers",
118 description
="Apply Modifiers to the exported mesh",
121 use_normals
: BoolProperty(
124 "Export Normals for smooth and "
126 "(hard shaded faces will be exported "
127 "as individual faces)"
131 use_uv_coords
: BoolProperty(
133 description
="Export the active UV layer",
136 use_colors
: BoolProperty(
137 name
="Vertex Colors",
138 description
="Export the active vertex color layer",
142 global_scale
: FloatProperty(
144 min=0.01, max=1000.0,
148 def execute(self
, context
):
149 from . import export_ply
151 from mathutils
import Matrix
153 keywords
= self
.as_keywords(
162 global_matrix
= axis_conversion(
163 to_forward
=self
.axis_forward
,
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
):
177 class PLY_PT_export_include(bpy
.types
.Panel
):
178 bl_space_type
= 'FILE_BROWSER'
179 bl_region_type
= 'TOOL_PROPS'
181 bl_parent_id
= "FILE_PT_operator"
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
):
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"
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
):
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"
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
):
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)")
265 PLY_PT_export_include
,
266 PLY_PT_export_transform
,
267 PLY_PT_export_geometry
,
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
)
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__":