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:
authorCampbell Barton <ideasman42@gmail.com>2017-09-29 11:16:13 +0300
committerCampbell Barton <ideasman42@gmail.com>2017-09-29 11:18:56 +0300
commit1542092295c92adfaff687050a74cd7c34747c22 (patch)
treed623a0f4c9dfdb92bcb13f761e7b0c75066adf06
parent88f0d4f89e03da4b6972c1b17569f668d98b06ea (diff)
I/O script changes for GSoC 2017 Vertex Paint
These are changes to the ply and fbx export functions, and the ply import function, to deal with vertex color alphas as implemented in the GSoC 2017 Vertex Paint project - see T52910 & D2855
-rw-r--r--io_mesh_ply/export_ply.py5
-rw-r--r--io_mesh_ply/import_ply.py8
-rw-r--r--io_scene_fbx/export_fbx.py6
-rw-r--r--io_scene_fbx/export_fbx_bin.py4
4 files changed, 14 insertions, 9 deletions
diff --git a/io_mesh_ply/export_ply.py b/io_mesh_ply/export_ply.py
index d4db5710..8de5d674 100644
--- a/io_mesh_ply/export_ply.py
+++ b/io_mesh_ply/export_ply.py
@@ -154,7 +154,8 @@ def save_mesh(filepath,
if use_colors:
fw("property uchar red\n"
"property uchar green\n"
- "property uchar blue\n")
+ "property uchar blue\n"
+ "property uchar alpha\n")
fw("element face %d\n" % len(mesh.tessfaces))
fw("property list uchar uint vertex_indices\n")
@@ -167,7 +168,7 @@ def save_mesh(filepath,
if use_uv_coords:
fw(" %.6f %.6f" % v[2]) # uv
if use_colors:
- fw(" %u %u %u" % v[3]) # col
+ fw(" %u %u %u %u" % v[3]) # col
fw("\n")
for pf in ply_faces:
diff --git a/io_mesh_ply/import_ply.py b/io_mesh_ply/import_ply.py
index eb097ba9..86fc2e1b 100644
--- a/io_mesh_ply/import_ply.py
+++ b/io_mesh_ply/import_ply.py
@@ -242,7 +242,7 @@ 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')
+ colindices = el.index(b'red'), el.index(b'green'), el.index(b'blue'), el.index(b'alpha')
if -1 in colindices:
colindices = None
else: # if not a float assume uchar
@@ -267,6 +267,7 @@ def load_ply_mesh(filepath, ply_name):
mesh_colors.append([(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:
@@ -340,7 +341,10 @@ def load_ply_mesh(filepath, ply_name):
f_col = f.color1, f.color2, f.color3
for j, col in enumerate(f_col):
- col.r, col.g, col.b = ply_col[j]
+ col[0] = ply_col[j][0]
+ col[1] = ply_col[j][1]
+ col[2] = ply_col[j][2]
+ col[3] = ply_col[j][3]
mesh.validate()
mesh.update()
diff --git a/io_scene_fbx/export_fbx.py b/io_scene_fbx/export_fbx.py
index dc647f71..e62d512d 100644
--- a/io_scene_fbx/export_fbx.py
+++ b/io_scene_fbx/export_fbx.py
@@ -1508,13 +1508,13 @@ def save_single(operator, scene, filepath="",
collayers = []
if len(me.vertex_colors):
collayers = me.vertex_colors
- t_lc = [None] * len(me.loops) * 3
+ t_lc = [None] * len(me.loops) * 4
col2idx = None
_nchunk = 4 # Number of colors per line
_nchunk_idx = 64 # Number of color indices per line
for colindex, collayer in enumerate(collayers):
collayer.data.foreach_get("color", t_lc)
- lc = tuple(zip(*[iter(t_lc)] * 3))
+ lc = tuple(zip(*[iter(t_lc)] * 4))
fw('\n\t\tLayerElementColor: %i {'
'\n\t\t\tVersion: 101'
'\n\t\t\tName: "%s"'
@@ -1523,7 +1523,7 @@ def save_single(operator, scene, filepath="",
'\n\t\t\tColors: ' % (colindex, collayer.name))
col2idx = tuple(set(lc))
- fw(',\n\t\t\t '.join(','.join('%.6f,%.6f,%.6f,1' % c for c in chunk)
+ fw(',\n\t\t\t '.join(','.join('%.6f,%.6f,%.6f,%.06f' % c for c in chunk)
for chunk in grouper_exact(col2idx, _nchunk)))
fw('\n\t\t\tColorIndex: ')
diff --git a/io_scene_fbx/export_fbx_bin.py b/io_scene_fbx/export_fbx_bin.py
index e9e1248e..a630f86b 100644
--- a/io_scene_fbx/export_fbx_bin.py
+++ b/io_scene_fbx/export_fbx_bin.py
@@ -1061,9 +1061,9 @@ def fbx_data_mesh_elements(root, me_obj, scene_data, done_meshes):
vcolnumber = len(me.vertex_colors)
if vcolnumber:
def _coltuples_gen(raw_cols):
- return zip(*(iter(raw_cols),) * 3 + (_infinite_gen(1.0),)) # We need a fake alpha...
+ return zip(*(iter(raw_cols),) * 4)
- t_lc = array.array(data_types.ARRAY_FLOAT64, (0.0,)) * len(me.loops) * 3
+ t_lc = array.array(data_types.ARRAY_FLOAT64, (0.0,)) * len(me.loops) * 4
for colindex, collayer in enumerate(me.vertex_colors):
collayer.data.foreach_get("color", t_lc)
lay_vcol = elem_data_single_int32(geom, b"LayerElementColor", colindex)