diff --git a/tools/convert-mesh/bin/convert-mesh.py b/tools/convert-mesh/bin/convert-mesh.py index 1c1922eb..35fac290 100644 --- a/tools/convert-mesh/bin/convert-mesh.py +++ b/tools/convert-mesh/bin/convert-mesh.py @@ -6,8 +6,6 @@ import struct model_name = sys.argv[sys.argv.index('--') + 1] filename = sys.argv[sys.argv.index('--') + 2] -#bpy.ops.object.mode_set(mode = 'OBJECT') - obj = None mesh = None if model_name in bpy.data.objects: @@ -19,13 +17,13 @@ mesh = obj.data colors = None if len(mesh.vertex_colors) > 0: - colors = mesh.vertex_colors.active.data + colors = mesh.vertex_colors[0].data print('Found vertex colors') texcoords = None if len(mesh.uv_layers) > 0: - texcoords = mesh.uv_layers.active.data - print('Found texture coordinates') + texcoords = mesh.uv_layers[0].data + print('Found texture coordinates:', texcoords) armature = None bone_names = None @@ -41,11 +39,11 @@ TEXCOORD_MASK = 8 WEIGHTS_MASK = 16 vertex_format = POSITION_MASK | NORMAL_MASK -if colors: +if colors is not None: vertex_format |= COLOR_MASK -if texcoords: +if texcoords is not None: vertex_format |= TEXCOORD_MASK -if armature: +if armature is not None: vertex_format |= WEIGHTS_MASK print("Using vertex format", format(vertex_format, '05b')) @@ -108,11 +106,11 @@ for p in mesh.loop_triangles: assert (len(indices) % 3) == 0 assert len(vertex_coords) == len(vertex_normals) -if colors: +if colors is not None: assert len(vertex_coords) == len(vertex_colors) -if texcoords: +if texcoords is not None: assert len(vertex_coords) == len(vertex_texcoords) -if armature: +if armature is not None: assert len(vertex_coords) == len(vertex_weights) @@ -127,14 +125,14 @@ class Uint8: return str(self.value) -if colors: +if colors is not None: for i in range(len(vertex_colors)): c = 0 for k in (3, 2, 1, 0): c = (c << 8) | int(max(0, min(255, pow(vertex_colors[i][k], 2.2) * 255))) vertex_colors[i] = c -if armature: +if armature is not None: for i in range(len(vertex_weights)): gs = [] for g, w in vertex_weights[i]: @@ -152,11 +150,11 @@ if armature: vertices = [] for i in range(len(vertex_coords)): attribs = [vertex_coords[i], vertex_normals[i]] - if colors: + if colors is not None: attribs.append(vertex_colors[i]) - if texcoords: + if texcoords is not None: attribs.append(vertex_texcoords[i]) - if armature: + if armature is not None: attribs.append(vertex_weights[i]) vertices.append(tuple(attribs))