Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Guetzkow <rjg>2019-04-05 19:14:01 +0300
committerJacques Lucke <mail@jlucke.com>2019-04-05 19:14:01 +0300
commitb9ba95de270f5bffc3b99526a63801f48f3b64bc (patch)
treea40fc5a5ebf18527ce323e60235dbe4b50e5d34a /io_mesh_ply
parent05c959bb20e77df086bb598401dd55e6bc024bfa (diff)
Fix T63227: import vertex colors from .ply file without alpha
Differential Revision: https://developer.blender.org/D4648
Diffstat (limited to 'io_mesh_ply')
-rw-r--r--io_mesh_ply/import_ply.py37
1 files changed, 27 insertions, 10 deletions
diff --git a/io_mesh_ply/import_ply.py b/io_mesh_ply/import_ply.py
index 301d08fd..c03f00a0 100644
--- a/io_mesh_ply/import_ply.py
+++ b/io_mesh_ply/import_ply.py
@@ -249,9 +249,15 @@ def load_ply_mesh(filepath, ply_name):
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'), el.index(b'alpha')
+ # ignore alpha if not present
+ if el.index(b'alpha') == -1:
+ colindices = el.index(b'red'), el.index(b'green'), el.index(b'blue')
+ else:
+ colindices = el.index(b'red'), el.index(b'green'), el.index(b'blue'), el.index(b'alpha')
if -1 in colindices:
colindices = None
+ if any(idx > -1 for idx in colindices):
+ print("Warning: At least one obligatory color channel is missing, ignoring vertex colors.")
else: # if not a float assume uchar
colmultiply = [1.0 if el.properties[i].numeric_type in {'f', 'd'} else (1.0 / 255.0) for i in colindices]
@@ -271,15 +277,26 @@ def load_ply_mesh(filepath, ply_name):
if uvindices:
mesh_uvs.extend([(vertices[index][uvindices[0]], vertices[index][uvindices[1]]) for index in indices])
if colindices:
- mesh_colors.extend([
- (
- vertices[index][colindices[0]] * colmultiply[0],
- vertices[index][colindices[1]] * colmultiply[1],
- vertices[index][colindices[2]] * colmultiply[2],
- vertices[index][colindices[3]] * colmultiply[3],
- )
- for index in indices
- ])
+ if len(colindices) == 3:
+ mesh_colors.extend([
+ (
+ vertices[index][colindices[0]] * colmultiply[0],
+ vertices[index][colindices[1]] * colmultiply[1],
+ vertices[index][colindices[2]] * colmultiply[2],
+ 1.0
+ )
+ for index in indices
+ ])
+ elif len(colindices) == 4:
+ mesh_colors.extend([
+ (
+ vertices[index][colindices[0]] * colmultiply[0],
+ vertices[index][colindices[1]] * colmultiply[1],
+ vertices[index][colindices[2]] * colmultiply[2],
+ vertices[index][colindices[3]] * colmultiply[3],
+ )
+ for index in indices
+ ])
if uvindices or colindices:
# If we have Cols or UVs then we need to check the face order.