From c9acc3aef8c655245593df1488e5e572055708a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Chatelain?= Date: Thu, 21 May 2015 15:09:40 +0200 Subject: [PATCH] [#88704468] Adds vertex colors support --- blender-2.5/exporter/osg/osgdata.py | 49 ++++++++++++++------------- blender-2.5/exporter/osg/osgobject.py | 2 +- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/blender-2.5/exporter/osg/osgdata.py b/blender-2.5/exporter/osg/osgdata.py index f14e1e1..983fb8a 100644 --- a/blender-2.5/exporter/osg/osgdata.py +++ b/blender-2.5/exporter/osg/osgdata.py @@ -1406,25 +1406,20 @@ def createGeometryForMaterialIndex(self, material_index, mesh): vertex_colors = mesh.vertex_colors if vertex_colors: - backupColor = None - for colorLayer in vertex_colors: - if colorLayer.active: - backupColor = colorLayer - for colorLayer in vertex_colors: - idx = 0 - colorLayer.active = True - # mesh.update() - color_array = [] - for data in colorLayer.data: - color_array.append(data.color1) - color_array.append(data.color2) - color_array.append(data.color3) - # DW - how to tell if this is a tri or a quad? - if len(faces[idx].vertices) > 3: - color_array.append(data.color4) - idx += 1 - colors[colorLayer.name] = color_array - backupColor.active = True + # We only retrieve the active vertex color layer + colorLayer = vertex_colors.active + colorArray = [] + idx = 0 + # mesh.update() + for data in colorLayer.data: + colorArray.append(data.color1) + colorArray.append(data.color2) + colorArray.append(data.color3) + # DW - how to tell if this is a tri or a quad? + if len(faces[idx].vertices) > 3: + colorArray.append(data.color4) + idx += 1 + colors = colorArray # mesh.update() # uvs = {} @@ -1504,9 +1499,9 @@ def get_vertex_key(index): (truncateFloat(normals[index][0]), truncateFloat(normals[index][1]), truncateFloat(normals[index][2])), - tuple([tuple(truncateVector(uvs[x][index])) for x in uvs.keys()])) - # vertex color not supported - # tuple([tuple(truncateVector(colors[x][index])) for x in colors.keys()])) + tuple([tuple(truncateVector(uvs[x][index])) for x in uvs.keys()]), + tuple([tuple(colors[index]) if colors else ()])) + # Build a dictionary of indexes to all the vertexes that # are equal. @@ -1629,7 +1624,10 @@ def get_vertex_key(index): osg_vertexes = VertexArray() osg_normals = NormalArray() osg_uvs = {} - # osg_colors = {} + + # Get the first vertex color layer (only one supported for now) + osg_colors = ColorArray() if colors else None + for vertex in mapping_vertexes: vindex = vertex[0] coord = vertexes[vindex].co @@ -1638,6 +1636,9 @@ def get_vertex_key(index): ncoord = normals[vindex] osg_normals.getArray().append([ncoord[0], ncoord[1], ncoord[2]]) + if osg_colors is not None: + osg_colors.getArray().append(colors[vindex]) + for name in uvs.keys(): if name not in osg_uvs.keys(): osg_uvs[name] = TexCoordArray() @@ -1712,7 +1713,7 @@ def get_vertex_key(index): primitives.append(quads) geom.uvs = osg_uvs - # geom.colors = osg_colors + geom.colors = osg_colors geom.vertexes = osg_vertexes geom.normals = osg_normals geom.primitives = primitives diff --git a/blender-2.5/exporter/osg/osgobject.py b/blender-2.5/exporter/osg/osgobject.py index 46f3235..7076086 100644 --- a/blender-2.5/exporter/osg/osgobject.py +++ b/blender-2.5/exporter/osg/osgobject.py @@ -930,7 +930,7 @@ def className(self): class ColorArray(VertexAttributeData): def __init__(self, *args, **kwargs): - kwargs["type"] = "Vec4fArray" + kwargs["type"] = "Vec3fArray" kwargs["array"] = kwargs.get("array", []) VertexAttributeData.__init__(self, *args, **kwargs)