Added support for vertex colors.
This commit is contained in:
@@ -39,6 +39,7 @@ class ASEGeometryObject(object):
|
||||
self.faces = []
|
||||
self.texture_vertex_faces = []
|
||||
self.face_normals = []
|
||||
self.vertex_colors = []
|
||||
self.vertex_offset = 0
|
||||
self.texture_vertex_offset = 0
|
||||
|
||||
|
||||
@@ -108,6 +108,12 @@ class ASEBuilder(object):
|
||||
geometry_object.texture_vertex_offset + loop_triangle.loops[2]
|
||||
))
|
||||
|
||||
# Vertex Colors
|
||||
if len(mesh_data.vertex_colors) > 0:
|
||||
vertex_colors = mesh_data.vertex_colors.active.data
|
||||
for color in map(lambda x: x.color, vertex_colors):
|
||||
geometry_object.vertex_colors.append(tuple(color[0:3]))
|
||||
|
||||
# Update data offsets for next iteration
|
||||
geometry_object.texture_vertex_offset = len(mesh_data.loops)
|
||||
geometry_object.vertex_offset = len(geometry_object.vertices)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import bpy
|
||||
import bpy_extras
|
||||
from bpy.props import StringProperty, FloatProperty, EnumProperty
|
||||
from bpy.props import StringProperty, FloatProperty, EnumProperty, BoolProperty
|
||||
from .builder import *
|
||||
from .writer import *
|
||||
|
||||
|
||||
@@ -176,6 +176,18 @@ class ASEWriter(object):
|
||||
vertex_normal_node.push_datum(vertex_normal.vertex_index)
|
||||
vertex_normal_node.push_data(list(vertex_normal.normal))
|
||||
|
||||
# Vertex Colors
|
||||
if len(geometry_object.vertex_colors) > 0:
|
||||
mesh_node.push_child('MESH_NUMCVERTEX').push_datum(len(geometry_object.vertex_colors))
|
||||
cvert_list = mesh_node.push_child('MESH_CVERTLIST')
|
||||
for i, vertex_color in enumerate(geometry_object.vertex_colors):
|
||||
cvert_list.push_child('MESH_VERTCOL').push_datum(i).push_data(vertex_color)
|
||||
parent_node.push_child('MESH_NUMCVFACES').push_datum(len(geometry_object.texture_vertex_faces))
|
||||
texture_faces_node = parent_node.push_child('MESH_CFACELIST')
|
||||
for texture_face_index, texture_face in enumerate(geometry_object.texture_vertex_faces):
|
||||
texture_face_node = texture_faces_node.push_child('MESH_CFACE')
|
||||
texture_face_node.push_data([texture_face_index] + list(texture_face))
|
||||
|
||||
geomobject_node.push_child('MATERIAL_REF').push_datum(0)
|
||||
|
||||
return root
|
||||
|
||||
Reference in New Issue
Block a user