Manual merge of soc-2009-kazanbas branch:
[blender.git] / release / io / export_ply.py
index 2f10875..8e79c37 100644 (file)
@@ -78,7 +78,7 @@ def write(filename, scene, ob, \
        
        #mesh = BPyMesh.getMeshFromObject(ob, None, EXPORT_APPLY_MODIFIERS, False, scn) # XXX
        if EXPORT_APPLY_MODIFIERS:
-               mesh = ob.create_render_mesh(scene)
+               mesh = ob.create_mesh(True, 'PREVIEW')
        else:
                mesh = ob.data
        
@@ -88,9 +88,9 @@ def write(filename, scene, ob, \
        
        # mesh.transform(ob.matrixWorld) # XXX
        
-       faceUV = len(mesh.uv_layers) > 0
+       faceUV = len(mesh.uv_textures) > 0
        vertexUV = len(mesh.sticky) > 0
-       vertexColors = len(mesh.vcol_layers) > 0
+       vertexColors = len(mesh.vertex_colors) > 0
        
        if (not faceUV) and (not vertexUV):     EXPORT_UV = False
        if not vertexColors:                                    EXPORT_COLORS = False
@@ -100,7 +100,7 @@ def write(filename, scene, ob, \
                
        if faceUV:
                active_uv_layer = None
-               for lay in mesh.uv_layers:
+               for lay in mesh.uv_textures:
                        if lay.active:
                                active_uv_layer= lay.data
                                break
@@ -110,7 +110,7 @@ def write(filename, scene, ob, \
        
        if vertexColors:
                active_col_layer = None
-               for lay in mesh.vcol_layers:
+               for lay in mesh.vertex_colors:
                        if lay.active:
                                active_col_layer= lay.data
                if not active_col_layer:
@@ -141,8 +141,7 @@ def write(filename, scene, ob, \
                        col = active_col_layer[i]
                        col = col.color1, col.color2, col.color3, col.color4
                
-               f_verts= list(f.verts)
-               if not f_verts[3]: f_verts.pop() # XXX face length should be 3/4, not always 4
+               f_verts= f.verts
                
                pf= ply_faces[i]
                for j, vidx in enumerate(f_verts):
@@ -233,9 +232,7 @@ def write(filename, scene, ob, \
        """
 
 class EXPORT_OT_ply(bpy.types.Operator):
-       '''
-       Operator documentation text, will be used for the operator tooltip and python docs.
-       '''
+       '''Export a single object as a stanford PLY with normals, colours and texture coordinates.'''
        __idname__ = "export.ply"
        __label__ = "Export PLY"
        
@@ -243,7 +240,7 @@ class EXPORT_OT_ply(bpy.types.Operator):
        # to the class instance from the operator settings before calling.
        
        __props__ = [
-               bpy.props.StringProperty(attr="filename", name="File Name", description="File name used for exporting the PLY file", maxlen= 1024, default= ""),
+               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),
@@ -251,16 +248,15 @@ class EXPORT_OT_ply(bpy.types.Operator):
        ]
        
        def poll(self, context):
-               print("Poll")
                return context.active_object != None
        
        def execute(self, context):
                # print("Selected: " + context.active_object.name)
 
-               if not self.filename:
+               if not self.path:
                        raise Exception("filename not set")
                        
-               write(self.filename, context.scene, context.active_object,\
+               write(self.path, context.scene, context.active_object,\
                        EXPORT_APPLY_MODIFIERS = self.use_modifiers,
                        EXPORT_NORMALS = self.use_normals,
                        EXPORT_UV = self.use_uvs,
@@ -278,6 +274,6 @@ class EXPORT_OT_ply(bpy.types.Operator):
 bpy.ops.add(EXPORT_OT_ply)
 
 if __name__ == "__main__":
-       bpy.ops.EXPORT_OT_ply(filename="/tmp/test.ply")
+       bpy.ops.EXPORT_OT_ply(path="/tmp/test.ply")