[#18388] PLY Import fails if line ending is not \n
[blender.git] / release / scripts / ply_import.py
index 302e21a0a43167e057819af9497eb6092e3f6259..43129ec01e91dee6766904fcf6cf4d214c546001 100644 (file)
@@ -160,13 +160,16 @@ def read(filename):
        obj_spec = object_spec()
 
        try:
-               file = open(filename, 'rb')
+               file = open(filename, 'rU') # Only for parsing the header, not binary data
                signature = file.readline()
-               if (signature != 'ply\n'):
+               
+               if not signature.startswith('ply'):
                        print 'Signature line was invalid'
                        return None
+               
                while 1:
                        tokens = re.split(r'[ \n]+', file.readline())
+                       
                        if (len(tokens) == 0):
                                continue
                        if (tokens[0] == 'end_header'):
@@ -197,14 +200,22 @@ def read(filename):
                                        obj_spec.specs[-1].properties.append(property_spec(tokens[4], type_specs[tokens[2]], type_specs[tokens[3]]))
                                else:
                                        obj_spec.specs[-1].properties.append(property_spec(tokens[2], None, type_specs[tokens[1]]))
+               
+               if format != 'ascii':
+                       file.close() # was ascii, now binary
+                       file = open(filename, 'rb')
+                       
+                       # skip the header...
+                       while not file.readline().startswith('end_header'):
+                               pass
+               
                obj = obj_spec.load(format_specs[format], file)
-
+               
        except IOError, (errno, strerror):
                try:    file.close()
                except: pass
                
                return None
-
        try:    file.close()
        except: pass