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, 74, 0),
26 "location": "File > Import-Export",
27 "description": "Import-Export PLY mesh data withs UV's and vertex colors",
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
41 if "export_ply" in locals():
42 importlib
.reload(export_ply
)
43 if "import_ply" in locals():
44 importlib
.reload(import_ply
)
49 from bpy
.props
import (
56 from bpy_extras
.io_utils
import (
59 orientation_helper_factory
,
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"
73 files
= CollectionProperty(name
="File Path",
74 description
="File path used for importing "
76 type=bpy
.types
.OperatorFileListElement
)
78 directory
= StringProperty()
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
]
87 paths
.append(self
.filepath
)
89 from . import import_ply
92 import_ply
.load(self
, context
, path
)
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",
111 use_normals
= BoolProperty(
113 description
="Export Normals for smooth and "
115 "(hard shaded faces will be exported "
116 "as individual faces)",
119 use_uv_coords
= BoolProperty(
121 description
="Export the active UV layer",
124 use_colors
= BoolProperty(
125 name
="Vertex Colors",
126 description
="Export the active vertex color layer",
130 global_scale
= FloatProperty(
132 min=0.01, max=1000.0,
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",
151 global_matrix
= axis_conversion(to_forward
=self
.axis_forward
,
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
):
165 row
.prop(self
, "use_mesh_modifiers")
166 row
.prop(self
, "use_normals")
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)")
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
)
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__":