| 
									
										
										
										
											2007-12-05 20:21:25 +00:00
										 |  |  | import bpy | 
					
						
							| 
									
										
										
										
											2006-01-12 21:33:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | __author__ = "Bruce Merry" | 
					
						
							| 
									
										
										
										
											2008-08-11 03:52:21 +00:00
										 |  |  | __version__ = "0.93" | 
					
						
							| 
									
										
										
										
											2006-01-12 21:33:42 +00:00
										 |  |  | __bpydoc__ = """\
 | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | This script exports Stanford PLY files from Blender. It supports normals,  | 
					
						
							|  |  |  | colours, and texture coordinates per face or per vertex. | 
					
						
							|  |  |  | Only one mesh can be exported at a time. | 
					
						
							| 
									
										
										
										
											2006-01-12 21:33:42 +00:00
										 |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Copyright (C) 2004, 2005: Bruce Merry, bmerry@cs.uct.ac.za | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  | # modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  | # as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  | # of the License, or (at your option) any later version. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | # GNU General Public License for more details. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | # along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  | # Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. | 
					
						
							| 
									
										
										
										
											2006-07-03 03:22:48 +00:00
										 |  |  | # Vector rounding se we can use as keys | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2008-08-11 03:52:21 +00:00
										 |  |  | # Updated on Aug 11, 2008 by Campbell Barton | 
					
						
							|  |  |  | #    - added 'comment' prefix to comments - Needed to comply with the PLY spec. | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # Updated on Jan 1, 2007 by Gabe Ghearing | 
					
						
							|  |  |  | #    - fixed normals so they are correctly smooth/flat | 
					
						
							|  |  |  | #    - fixed crash when the model doesn't have uv coords or vertex colors | 
					
						
							|  |  |  | #    - fixed crash when the model has vertex colors but doesn't have uv coords | 
					
						
							|  |  |  | #    - changed float32 to float and uint8 to uchar for compatibility | 
					
						
							|  |  |  | # Errata/Notes as of Jan 1, 2007 | 
					
						
							|  |  |  | #    - script exports texture coords if they exist even if TexFace isn't selected (not a big deal to me) | 
					
						
							|  |  |  | #    - ST(R) should probably be renamed UV(T) like in most PLY files (importer needs to be updated to take either) | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Updated on Jan 3, 2007 by Gabe Ghearing | 
					
						
							|  |  |  | #    - fixed "sticky" vertex UV exporting | 
					
						
							|  |  |  | #    - added pupmenu to enable/disable exporting normals, uv coords, and colors | 
					
						
							|  |  |  | # Errata/Notes as of Jan 3, 2007 | 
					
						
							|  |  |  | #    - ST(R) coords should probably be renamed UV(T) like in most PLY files (importer needs to be updated to take either) | 
					
						
							|  |  |  | #    - edges should be exported since PLY files support them | 
					
						
							|  |  |  | #    - code is getting spaghettish, it should be refactored... | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def rvec3d(v):	return round(v[0], 6), round(v[1], 6), round(v[2], 6) | 
					
						
							|  |  |  | def rvec2d(v):	return round(v[0], 6), round(v[1], 6) | 
					
						
							| 
									
										
										
										
											2006-01-12 21:33:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | def write(filename, scene, ob, \ | 
					
						
							|  |  |  | 		EXPORT_APPLY_MODIFIERS= True,\ | 
					
						
							|  |  |  | 		EXPORT_NORMALS= True,\ | 
					
						
							|  |  |  | 		EXPORT_UV= True,\ | 
					
						
							|  |  |  | 		EXPORT_COLORS= True\ | 
					
						
							|  |  |  | 	): | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-07-03 03:22:48 +00:00
										 |  |  | 	if not filename.lower().endswith('.ply'): | 
					
						
							|  |  |  | 		filename += '.ply' | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 	if not ob: | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 		raise Exception("Error, Select 1 active object") | 
					
						
							| 
									
										
										
										
											2006-07-03 03:22:48 +00:00
										 |  |  | 		return | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 	file = open(filename, 'w') | 
					
						
							| 
									
										
										
										
											2006-07-03 20:17:40 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 	#EXPORT_EDGES = Draw.Create(0) | 
					
						
							|  |  |  | 	"""
 | 
					
						
							| 
									
										
										
										
											2007-12-05 20:21:25 +00:00
										 |  |  | 	is_editmode = Blender.Window.EditMode() | 
					
						
							|  |  |  | 	if is_editmode: | 
					
						
							|  |  |  | 		Blender.Window.EditMode(0, '', 0) | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 	Window.WaitCursor(1) | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 	"""
 | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 	#mesh = BPyMesh.getMeshFromObject(ob, None, EXPORT_APPLY_MODIFIERS, False, scn) # XXX | 
					
						
							|  |  |  | 	if EXPORT_APPLY_MODIFIERS: | 
					
						
							|  |  |  | 		mesh = ob.create_mesh(True, 'PREVIEW') | 
					
						
							|  |  |  | 	else: | 
					
						
							|  |  |  | 		mesh = ob.data | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-07-03 03:22:48 +00:00
										 |  |  | 	if not mesh: | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 		raise ("Error, could not get mesh data from active object") | 
					
						
							| 
									
										
										
										
											2006-07-03 03:22:48 +00:00
										 |  |  | 		return | 
					
						
							| 
									
										
										
										
											2006-07-03 20:17:40 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 	# mesh.transform(ob.matrixWorld) # XXX | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 	faceUV = len(mesh.uv_textures) > 0 | 
					
						
							|  |  |  | 	vertexUV = len(mesh.sticky) > 0 | 
					
						
							|  |  |  | 	vertexColors = len(mesh.vertex_colors) > 0 | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 	if (not faceUV) and (not vertexUV):	EXPORT_UV = False | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 	if not vertexColors:					EXPORT_COLORS = False | 
					
						
							| 
									
										
										
										
											2006-07-03 20:17:40 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 	if not EXPORT_UV:						faceUV = vertexUV = False | 
					
						
							|  |  |  | 	if not EXPORT_COLORS:					vertexColors = False | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 	if faceUV: | 
					
						
							|  |  |  | 		active_uv_layer = None | 
					
						
							|  |  |  | 		for lay in mesh.uv_textures: | 
					
						
							|  |  |  | 			if lay.active: | 
					
						
							|  |  |  | 				active_uv_layer= lay.data | 
					
						
							|  |  |  | 				break | 
					
						
							|  |  |  | 		if not active_uv_layer: | 
					
						
							|  |  |  | 			EXPORT_UV = False | 
					
						
							|  |  |  | 			faceUV = None | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if vertexColors: | 
					
						
							|  |  |  | 		active_col_layer = None | 
					
						
							|  |  |  | 		for lay in mesh.vertex_colors: | 
					
						
							|  |  |  | 			if lay.active: | 
					
						
							|  |  |  | 				active_col_layer= lay.data | 
					
						
							|  |  |  | 		if not active_col_layer: | 
					
						
							|  |  |  | 			EXPORT_COLORS = False | 
					
						
							|  |  |  | 			vertexColors = None | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	# incase | 
					
						
							|  |  |  | 	color = uvcoord = uvcoord_key = normal = normal_key = None | 
					
						
							| 
									
										
										
										
											2006-07-03 20:17:40 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 	mesh_verts = mesh.verts # save a lookup | 
					
						
							|  |  |  | 	ply_verts = [] # list of dictionaries | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 	# vdict = {} # (index, normal, uv) -> new index | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 	vdict = [{} for i in range(len(mesh_verts))] | 
					
						
							|  |  |  | 	ply_faces = [[] for f in range(len(mesh.faces))] | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 	vert_count = 0 | 
					
						
							| 
									
										
										
										
											2006-07-03 03:22:48 +00:00
										 |  |  | 	for i, f in enumerate(mesh.faces): | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 		smooth = f.smooth | 
					
						
							|  |  |  | 		if not smooth: | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 			normal = tuple(f.normal) | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 			normal_key = rvec3d(normal) | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		if faceUV: | 
					
						
							|  |  |  | 			uv = active_uv_layer[i] | 
					
						
							|  |  |  | 			uv = uv.uv1, uv.uv2, uv.uv3, uv.uv4 # XXX - crufty :/ | 
					
						
							|  |  |  | 		if vertexColors: | 
					
						
							|  |  |  | 			col = active_col_layer[i] | 
					
						
							|  |  |  | 			col = col.color1, col.color2, col.color3, col.color4 | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		f_verts= f.verts | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		pf= ply_faces[i] | 
					
						
							|  |  |  | 		for j, vidx in enumerate(f_verts): | 
					
						
							|  |  |  | 			v = mesh_verts[vidx] | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | 			if smooth: | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 				normal=		tuple(v.normal) | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 				normal_key = rvec3d(normal) | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			if faceUV: | 
					
						
							| 
									
										
										
										
											2008-10-20 13:36:18 +00:00
										 |  |  | 				uvcoord=	uv[j][0], 1.0-uv[j][1] | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 				uvcoord_key = rvec2d(uvcoord) | 
					
						
							|  |  |  | 			elif vertexUV: | 
					
						
							| 
									
										
										
										
											2008-10-20 13:36:18 +00:00
										 |  |  | 				uvcoord=	v.uvco[0], 1.0-v.uvco[1] | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 				uvcoord_key = rvec2d(uvcoord) | 
					
						
							| 
									
										
										
										
											2006-07-03 03:22:48 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 			if vertexColors: | 
					
						
							|  |  |  | 				color=		col[j] | 
					
						
							|  |  |  | 				color= int(color[0]*255.0), int(color[1]*255.0), int(color[2]*255.0) | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			key = normal_key, uvcoord_key, color | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 			vdict_local = vdict[vidx] | 
					
						
							|  |  |  | 			pf_vidx = vdict_local.get(key) # Will be None initially | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 			if pf_vidx == None: # same as vdict_local.has_key(key) | 
					
						
							|  |  |  | 				pf_vidx = vdict_local[key] = vert_count; | 
					
						
							|  |  |  | 				ply_verts.append((vidx, normal, uvcoord, color)) | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 				vert_count += 1 | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | 			pf.append(pf_vidx) | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-07-03 03:22:48 +00:00
										 |  |  | 	file.write('ply\n') | 
					
						
							|  |  |  | 	file.write('format ascii 1.0\n') | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 	version = "2.5" # Blender.Get('version') | 
					
						
							|  |  |  | 	file.write('comment Created by Blender3D %s - www.blender.org, source file: %s\n' % (version, bpy.data.filename.split('/')[-1].split('\\')[-1] )) | 
					
						
							| 
									
										
										
										
											2006-07-03 03:22:48 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 	file.write('element vertex %d\n' % len(ply_verts)) | 
					
						
							| 
									
										
										
										
											2006-07-03 03:22:48 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 	file.write('property float x\n') | 
					
						
							|  |  |  | 	file.write('property float y\n') | 
					
						
							|  |  |  | 	file.write('property float z\n') | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	# XXX  | 
					
						
							|  |  |  | 	"""
 | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 	if EXPORT_NORMALS: | 
					
						
							|  |  |  | 		file.write('property float nx\n') | 
					
						
							|  |  |  | 		file.write('property float ny\n') | 
					
						
							|  |  |  | 		file.write('property float nz\n') | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 	"""
 | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 	if EXPORT_UV: | 
					
						
							|  |  |  | 		file.write('property float s\n') | 
					
						
							|  |  |  | 		file.write('property float t\n') | 
					
						
							|  |  |  | 	if EXPORT_COLORS: | 
					
						
							|  |  |  | 		file.write('property uchar red\n') | 
					
						
							|  |  |  | 		file.write('property uchar green\n') | 
					
						
							|  |  |  | 		file.write('property uchar blue\n') | 
					
						
							| 
									
										
										
										
											2006-07-03 03:22:48 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	file.write('element face %d\n' % len(mesh.faces)) | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 	file.write('property list uchar uint vertex_indices\n') | 
					
						
							| 
									
										
										
										
											2006-07-03 03:22:48 +00:00
										 |  |  | 	file.write('end_header\n') | 
					
						
							| 
									
										
										
										
											2006-01-12 21:33:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 	for i, v in enumerate(ply_verts): | 
					
						
							|  |  |  | 		file.write('%.6f %.6f %.6f ' % tuple(mesh_verts[v[0]].co)) # co | 
					
						
							|  |  |  | 		"""
 | 
					
						
							| 
									
										
										
										
											2007-01-09 16:01:38 +00:00
										 |  |  | 		if EXPORT_NORMALS: | 
					
						
							|  |  |  | 			file.write('%.6f %.6f %.6f ' % v[1]) # no | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 		"""
 | 
					
						
							|  |  |  | 		if EXPORT_UV:			file.write('%.6f %.6f ' % v[2]) # uv | 
					
						
							|  |  |  | 		if EXPORT_COLORS:		file.write('%u %u %u' % v[3]) # col | 
					
						
							| 
									
										
										
										
											2006-07-03 03:22:48 +00:00
										 |  |  | 		file.write('\n') | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 	for pf in ply_faces: | 
					
						
							|  |  |  | 		if len(pf)==3:		file.write('3 %d %d %d\n' % tuple(pf)) | 
					
						
							|  |  |  | 		else:				file.write('4 %d %d %d %d\n' % tuple(pf)) | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-01-12 21:33:42 +00:00
										 |  |  | 	file.close() | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 	print("writing", filename, "done") | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if EXPORT_APPLY_MODIFIERS: | 
					
						
							|  |  |  | 		bpy.data.remove_mesh(mesh) | 
					
						
							| 
									
										
										
										
											2007-12-05 20:21:25 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 	# XXX | 
					
						
							|  |  |  | 	"""
 | 
					
						
							| 
									
										
										
										
											2007-12-05 20:21:25 +00:00
										 |  |  | 	if is_editmode: | 
					
						
							|  |  |  | 		Blender.Window.EditMode(1, '', 0) | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | 	"""
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class EXPORT_OT_ply(bpy.types.Operator): | 
					
						
							|  |  |  | 	'''Export a single object as a stanford PLY with normals, colours and texture coordinates.''' | 
					
						
							|  |  |  | 	__idname__ = "export.ply" | 
					
						
							|  |  |  | 	__label__ = "Export PLY" | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	# List of operator properties, the attributes will be assigned | 
					
						
							|  |  |  | 	# to the class instance from the operator settings before calling. | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	__props__ = [ | 
					
						
							|  |  |  | 		bpy.props.StringProperty(attr="path", name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= ""), | 
					
						
							|  |  |  | 		bpy.props.BoolProperty(attr="use_modifiers", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True), | 
					
						
							|  |  |  | 		bpy.props.BoolProperty(attr="use_normals", name="Export Normals", description="Export Normals for smooth and hard shaded faces", default= True), | 
					
						
							|  |  |  | 		bpy.props.BoolProperty(attr="use_uvs", name="Export UVs", description="Exort the active UV layer", default= True), | 
					
						
							|  |  |  | 		bpy.props.BoolProperty(attr="use_colors", name="Export Vertex Colors", description="Exort the active vertex color layer", default= True) | 
					
						
							|  |  |  | 	] | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	def poll(self, context): | 
					
						
							|  |  |  | 		return context.active_object != None | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	def execute(self, context): | 
					
						
							|  |  |  | 		# print("Selected: " + context.active_object.name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if not self.path: | 
					
						
							|  |  |  | 			raise Exception("filename not set") | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 		write(self.path, context.scene, context.active_object,\ | 
					
						
							|  |  |  | 			EXPORT_APPLY_MODIFIERS = self.use_modifiers, | 
					
						
							|  |  |  | 			EXPORT_NORMALS = self.use_normals, | 
					
						
							|  |  |  | 			EXPORT_UV = self.use_uvs, | 
					
						
							|  |  |  | 			EXPORT_COLORS = self.use_colors, | 
					
						
							|  |  |  | 		) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return ('FINISHED',) | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	def invoke(self, context, event):	 | 
					
						
							|  |  |  | 		wm = context.manager | 
					
						
							|  |  |  | 		wm.add_fileselect(self.__operator__) | 
					
						
							|  |  |  | 		return ('RUNNING_MODAL',) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bpy.ops.add(EXPORT_OT_ply) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												- add torus back from 2.4x as an operator
  bpy.ops.mesh.primitive_torus_add(major_radius=1, minor_radius=0.25, major_segments=48, minor_segments=16)
- experemental dynamic menus, used for INFO_MT_file, INFO_MT_file_import, INFO_MT_file_export and INFO_MT_mesh_add. these can have items added from python.
eg.
- removed OBJECT_OT_mesh_add, use the python add menu instead.
- made mesh primitive ops -  MESH_OT_primitive_plane_add, ...cube_add, etc. work in object mode.
- RNA scene.active_object wrapped
- bugfix [#19466] 2.5: Tweak menu only available for mesh objects added within Edit Mode
  ED_object_exit_editmode was always doing an undo push, made this optional using the existing flag - EM_DO_UNDO, called everywhere except when adding primitives.
											
										 
											2009-10-10 21:23:20 +00:00
										 |  |  | import dynamic_menu | 
					
						
							|  |  |  | menu_func = lambda self, context: self.layout.itemO("export.ply", text="Stanford (.ply)...") | 
					
						
							|  |  |  | menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-29 15:27:00 +00:00
										 |  |  | if __name__ == "__main__": | 
					
						
							|  |  |  | 	bpy.ops.EXPORT_OT_ply(path="/tmp/test.ply") |