[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34310] trunk/blender/release/scripts/op/ io_mesh_ply/import_ply.py: pep8 cleanup.
Campbell Barton
ideasman42 at gmail.com
Fri Jan 14 00:31:06 CET 2011
Revision: 34310
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34310
Author: campbellbarton
Date: 2011-01-13 23:31:04 +0000 (Thu, 13 Jan 2011)
Log Message:
-----------
pep8 cleanup.
Modified Paths:
--------------
trunk/blender/release/scripts/op/io_mesh_ply/import_ply.py
Modified: trunk/blender/release/scripts/op/io_mesh_ply/import_ply.py
===================================================================
--- trunk/blender/release/scripts/op/io_mesh_ply/import_ply.py 2011-01-13 23:28:36 UTC (rev 34309)
+++ trunk/blender/release/scripts/op/io_mesh_ply/import_ply.py 2011-01-13 23:31:04 UTC (rev 34310)
@@ -1,354 +1,328 @@
-#!BPY
-
-"""
-Name: 'Stanford PLY (*.ply)...'
-Blender: 248
-Group: 'Import'
-Tip: 'Import a Stanford PLY file'
-"""
-
-__author__ = 'Bruce Merry'
-__version__ = '0.93'
-__bpydoc__ = """\
-This script imports Stanford PLY files into Blender. It supports per-vertex
-normals, and per-face colours and texture coordinates.
-
-Usage:
-
-Run this script from "File->Import" and select the desired PLY file.
-"""
-
-# Copyright (C) 2004, 2005: Bruce Merry, bmerry at cs.uct.ac.za
+# ##### BEGIN GPL LICENSE BLOCK #####
#
-# 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 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.
+# 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.
+# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+# <pep8 compliant>
-# 20th Oct 2008, 0.93 - Updated by Campbell Barton AKA ideasman42, use Mesh rather then NMesh, dont import normals, vcolors work again.
-# Updated by Campbell Barton AKA Ideasman42, 10% faster code.
-
-# Portions of this code are taken from mod_meshtools.py in Blender
-# 2.32.
-
import Blender
try:
- import re, struct
+ import re
+ import struct
except:
- struct= None
+ struct = None
+
class element_spec(object):
- __slots__ = 'name', 'count', 'properties'
- def __init__(self, name, count):
- self.name = name
- self.count = count
- self.properties = []
+ __slots__ = 'name', 'count', 'properties'
- def load(self, format, stream):
- if format == 'ascii':
- stream = re.split('\s+', stream.readline())
- return map(lambda x: x.load(format, stream), self.properties)
+ def __init__(self, name, count):
+ self.name = name
+ self.count = count
+ self.properties = []
- def index(self, name):
- for i, p in enumerate(self.properties):
- if p.name == name: return i
- return -1
+ def load(self, format, stream):
+ if format == 'ascii':
+ stream = re.split('\s+', stream.readline())
+ return map(lambda x: x.load(format, stream), self.properties)
+ def index(self, name):
+ for i, p in enumerate(self.properties):
+ if p.name == name:
+ return i
+ return -1
+
+
class property_spec(object):
- __slots__ = 'name', 'list_type', 'numeric_type'
- def __init__(self, name, list_type, numeric_type):
- self.name = name
- self.list_type = list_type
- self.numeric_type = numeric_type
+ __slots__ = 'name', 'list_type', 'numeric_type'
- def read_format(self, format, count, num_type, stream):
- if format == 'ascii':
- if (num_type == 's'):
- ans = []
- for i in xrange(count):
- s = stream[i]
- if len(s) < 2 or s[0] != '"' or s[-1] != '"':
- print 'Invalid string', s
- print 'Note: ply_import.py does not handle whitespace in strings'
- return None
- ans.append(s[1:-1])
- stream[:count] = []
- return ans
- if (num_type == 'f' or num_type == 'd'):
- mapper = float
- else:
- mapper = int
- ans = map(lambda x: mapper(x), stream[:count])
- stream[:count] = []
- return ans
- else:
- if (num_type == 's'):
- ans = []
- for i in xrange(count):
- fmt = format + 'i'
- data = stream.read(struct.calcsize(fmt))
- length = struct.unpack(fmt, data)[0]
- fmt = '%s%is' % (format, length)
- data = stream.read(struct.calcsize(fmt))
- s = struct.unpack(fmt, data)[0]
- ans.append(s[:-1]) # strip the NULL
- return ans
- else:
- fmt = '%s%i%s' % (format, count, num_type)
- data = stream.read(struct.calcsize(fmt));
- return struct.unpack(fmt, data)
+ def __init__(self, name, list_type, numeric_type):
+ self.name = name
+ self.list_type = list_type
+ self.numeric_type = numeric_type
- def load(self, format, stream):
- if (self.list_type != None):
- count = int(self.read_format(format, 1, self.list_type, stream)[0])
- return self.read_format(format, count, self.numeric_type, stream)
- else:
- return self.read_format(format, 1, self.numeric_type, stream)[0]
+ def read_format(self, format, count, num_type, stream):
+ if format == 'ascii':
+ if (num_type == 's'):
+ ans = []
+ for i in xrange(count):
+ s = stream[i]
+ if len(s) < 2 or s[0] != '"' or s[-1] != '"':
+ print 'Invalid string', s
+ print 'Note: ply_import.py does not handle whitespace in strings'
+ return None
+ ans.append(s[1:-1])
+ stream[:count] = []
+ return ans
+ if (num_type == 'f' or num_type == 'd'):
+ mapper = float
+ else:
+ mapper = int
+ ans = map(lambda x: mapper(x), stream[:count])
+ stream[:count] = []
+ return ans
+ else:
+ if (num_type == 's'):
+ ans = []
+ for i in xrange(count):
+ fmt = format + 'i'
+ data = stream.read(struct.calcsize(fmt))
+ length = struct.unpack(fmt, data)[0]
+ fmt = '%s%is' % (format, length)
+ data = stream.read(struct.calcsize(fmt))
+ s = struct.unpack(fmt, data)[0]
+ ans.append(s[:-1]) # strip the NULL
+ return ans
+ else:
+ fmt = '%s%i%s' % (format, count, num_type)
+ data = stream.read(struct.calcsize(fmt))
+ return struct.unpack(fmt, data)
+ def load(self, format, stream):
+ if (self.list_type != None):
+ count = int(self.read_format(format, 1, self.list_type, stream)[0])
+ return self.read_format(format, count, self.numeric_type, stream)
+ else:
+ return self.read_format(format, 1, self.numeric_type, stream)[0]
+
+
class object_spec(object):
- __slots__ = 'specs'
- 'A list of element_specs'
- def __init__(self):
- self.specs = []
-
- def load(self, format, stream):
- return dict([(i.name,[i.load(format, stream) for j in xrange(i.count) ]) for i in self.specs])
-
- '''
- # Longhand for above LC
- answer = {}
- for i in self.specs:
- answer[i.name] = []
- for j in xrange(i.count):
- if not j % 100 and meshtools.show_progress:
- Blender.Window.DrawProgressBar(float(j) / i.count, 'Loading ' + i.name)
- answer[i.name].append(i.load(format, stream))
- return answer
- '''
-
+ __slots__ = 'specs'
+ 'A list of element_specs'
+ def __init__(self):
+ self.specs = []
+ def load(self, format, stream):
+ return dict([(i.name, [i.load(format, stream) for j in xrange(i.count)]) for i in self.specs])
+
+ '''
+ # Longhand for above LC
+ answer = {}
+ for i in self.specs:
+ answer[i.name] = []
+ for j in xrange(i.count):
+ if not j % 100 and meshtools.show_progress:
+ Blender.Window.DrawProgressBar(float(j) / i.count, 'Loading ' + i.name)
+ answer[i.name].append(i.load(format, stream))
+ return answer
+ '''
+
+
def read(filename):
- format = ''
- version = '1.0'
- format_specs = {'binary_little_endian': '<',
- 'binary_big_endian': '>',
- 'ascii': 'ascii'}
- type_specs = {'char': 'b',
- 'uchar': 'B',
- 'int8': 'b',
- 'uint8': 'B',
- 'int16': 'h',
- 'uint16': 'H',
- 'ushort': 'H',
- 'int': 'i',
- 'int32': 'i',
- 'uint': 'I',
- 'uint32': 'I',
- 'float': 'f',
- 'float32': 'f',
- 'float64': 'd',
- 'double': 'd',
- 'string': 's'}
- obj_spec = object_spec()
+ format = ''
+ version = '1.0'
+ format_specs = {'binary_little_endian': '<',
+ 'binary_big_endian': '>',
+ 'ascii': 'ascii'}
+ type_specs = {'char': 'b',
+ 'uchar': 'B',
+ 'int8': 'b',
+ 'uint8': 'B',
+ 'int16': 'h',
+ 'uint16': 'H',
+ 'ushort': 'H',
+ 'int': 'i',
+ 'int32': 'i',
+ 'uint': 'I',
+ 'uint32': 'I',
+ 'float': 'f',
+ 'float32': 'f',
+ 'float64': 'd',
+ 'double': 'd',
+ 'string': 's'}
+ obj_spec = object_spec()
- try:
- file = open(filename, 'rU') # Only for parsing the header, not binary data
- signature = file.readline()
-
- 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'):
- break
- elif (tokens[0] == 'comment' or tokens[0] == 'obj_info'):
- continue
- elif (tokens[0] == 'format'):
- if (len(tokens) < 3):
- print 'Invalid format line'
- return None
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list