[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2049] trunk/py/scripts/addons/ io_mesh_ply/import_ply.py: fix [#27691] PLY importer does not support float based vertex colors
Campbell Barton
ideasman42 at gmail.com
Tue Jun 21 06:39:20 CEST 2011
Revision: 2049
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2049
Author: campbellbarton
Date: 2011-06-21 04:39:18 +0000 (Tue, 21 Jun 2011)
Log Message:
-----------
fix [#27691] PLY importer does not support float based vertex colors
Modified Paths:
--------------
trunk/py/scripts/addons/io_mesh_ply/import_ply.py
Modified: trunk/py/scripts/addons/io_mesh_ply/import_ply.py
===================================================================
--- trunk/py/scripts/addons/io_mesh_ply/import_ply.py 2011-06-21 04:10:09 UTC (rev 2048)
+++ trunk/py/scripts/addons/io_mesh_ply/import_ply.py 2011-06-21 04:39:18 UTC (rev 2049)
@@ -199,6 +199,8 @@
obj = obj_spec.load(format_specs[format], file)
+ file.close()
+
return obj_spec, obj
@@ -217,19 +219,24 @@
return
uvindices = colindices = None
+ colmultiply = None
+
# noindices = None # Ignore normals
for el in obj_spec.specs:
if el.name == b'vertex':
- vindices = vindices_x, vindices_y, vindices_z = (el.index(b'x'), el.index(b'y'), el.index(b'z'))
+ vindices = vindices_x, vindices_y, vindices_z = el.index(b'x'), el.index(b'y'), el.index(b'z')
# noindices = (el.index('nx'), el.index('ny'), el.index('nz'))
# if -1 in noindices: noindices = None
uvindices = (el.index(b's'), el.index(b't'))
if -1 in uvindices:
uvindices = None
- colindices = (el.index(b'red'), el.index(b'green'), el.index(b'blue'))
+ colindices = el.index(b'red'), el.index(b'green'), el.index(b'blue')
if -1 in colindices:
colindices = None
+ else: # if not a float assume uchar
+ colmultiply = [1.0 if el.properties[i].numeric_type in ('f', 'd') else (1.0 / 256.0) for i in colindices]
+
elif el.name == b'face':
findex = el.index(b'vertex_indices')
@@ -242,7 +249,10 @@
if uvindices:
mesh_uvs.append([(vertices[index][uvindices[0]], 1.0 - vertices[index][uvindices[1]]) for index in indices])
if colindices:
- mesh_colors.append([(vertices[index][colindices[0]] / 255.0, vertices[index][colindices[1]] / 255.0, vertices[index][colindices[2]] / 255.0) for index in indices])
+ mesh_colors.append([(vertices[index][colindices[0]] * colmultiply[0],
+ vertices[index][colindices[1]] * colmultiply[1],
+ vertices[index][colindices[2]] * colmultiply[2],
+ ) for index in indices])
if uvindices or colindices:
# If we have Cols or UVs then we need to check the face order.
More information about the Bf-extensions-cvs
mailing list