Mesh exporting script fixes
This commit is contained in:
parent
8d2f244d0d
commit
727ec22fff
1 changed files with 14 additions and 16 deletions
|
|
@ -6,8 +6,6 @@ import struct
|
||||||
model_name = sys.argv[sys.argv.index('--') + 1]
|
model_name = sys.argv[sys.argv.index('--') + 1]
|
||||||
filename = sys.argv[sys.argv.index('--') + 2]
|
filename = sys.argv[sys.argv.index('--') + 2]
|
||||||
|
|
||||||
#bpy.ops.object.mode_set(mode = 'OBJECT')
|
|
||||||
|
|
||||||
obj = None
|
obj = None
|
||||||
mesh = None
|
mesh = None
|
||||||
if model_name in bpy.data.objects:
|
if model_name in bpy.data.objects:
|
||||||
|
|
@ -19,13 +17,13 @@ mesh = obj.data
|
||||||
|
|
||||||
colors = None
|
colors = None
|
||||||
if len(mesh.vertex_colors) > 0:
|
if len(mesh.vertex_colors) > 0:
|
||||||
colors = mesh.vertex_colors.active.data
|
colors = mesh.vertex_colors[0].data
|
||||||
print('Found vertex colors')
|
print('Found vertex colors')
|
||||||
|
|
||||||
texcoords = None
|
texcoords = None
|
||||||
if len(mesh.uv_layers) > 0:
|
if len(mesh.uv_layers) > 0:
|
||||||
texcoords = mesh.uv_layers.active.data
|
texcoords = mesh.uv_layers[0].data
|
||||||
print('Found texture coordinates')
|
print('Found texture coordinates:', texcoords)
|
||||||
|
|
||||||
armature = None
|
armature = None
|
||||||
bone_names = None
|
bone_names = None
|
||||||
|
|
@ -41,11 +39,11 @@ TEXCOORD_MASK = 8
|
||||||
WEIGHTS_MASK = 16
|
WEIGHTS_MASK = 16
|
||||||
|
|
||||||
vertex_format = POSITION_MASK | NORMAL_MASK
|
vertex_format = POSITION_MASK | NORMAL_MASK
|
||||||
if colors:
|
if colors is not None:
|
||||||
vertex_format |= COLOR_MASK
|
vertex_format |= COLOR_MASK
|
||||||
if texcoords:
|
if texcoords is not None:
|
||||||
vertex_format |= TEXCOORD_MASK
|
vertex_format |= TEXCOORD_MASK
|
||||||
if armature:
|
if armature is not None:
|
||||||
vertex_format |= WEIGHTS_MASK
|
vertex_format |= WEIGHTS_MASK
|
||||||
print("Using vertex format", format(vertex_format, '05b'))
|
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(indices) % 3) == 0
|
||||||
assert len(vertex_coords) == len(vertex_normals)
|
assert len(vertex_coords) == len(vertex_normals)
|
||||||
if colors:
|
if colors is not None:
|
||||||
assert len(vertex_coords) == len(vertex_colors)
|
assert len(vertex_coords) == len(vertex_colors)
|
||||||
if texcoords:
|
if texcoords is not None:
|
||||||
assert len(vertex_coords) == len(vertex_texcoords)
|
assert len(vertex_coords) == len(vertex_texcoords)
|
||||||
if armature:
|
if armature is not None:
|
||||||
assert len(vertex_coords) == len(vertex_weights)
|
assert len(vertex_coords) == len(vertex_weights)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -127,14 +125,14 @@ class Uint8:
|
||||||
return str(self.value)
|
return str(self.value)
|
||||||
|
|
||||||
|
|
||||||
if colors:
|
if colors is not None:
|
||||||
for i in range(len(vertex_colors)):
|
for i in range(len(vertex_colors)):
|
||||||
c = 0
|
c = 0
|
||||||
for k in (3, 2, 1, 0):
|
for k in (3, 2, 1, 0):
|
||||||
c = (c << 8) | int(max(0, min(255, pow(vertex_colors[i][k], 2.2) * 255)))
|
c = (c << 8) | int(max(0, min(255, pow(vertex_colors[i][k], 2.2) * 255)))
|
||||||
vertex_colors[i] = c
|
vertex_colors[i] = c
|
||||||
|
|
||||||
if armature:
|
if armature is not None:
|
||||||
for i in range(len(vertex_weights)):
|
for i in range(len(vertex_weights)):
|
||||||
gs = []
|
gs = []
|
||||||
for g, w in vertex_weights[i]:
|
for g, w in vertex_weights[i]:
|
||||||
|
|
@ -152,11 +150,11 @@ if armature:
|
||||||
vertices = []
|
vertices = []
|
||||||
for i in range(len(vertex_coords)):
|
for i in range(len(vertex_coords)):
|
||||||
attribs = [vertex_coords[i], vertex_normals[i]]
|
attribs = [vertex_coords[i], vertex_normals[i]]
|
||||||
if colors:
|
if colors is not None:
|
||||||
attribs.append(vertex_colors[i])
|
attribs.append(vertex_colors[i])
|
||||||
if texcoords:
|
if texcoords is not None:
|
||||||
attribs.append(vertex_texcoords[i])
|
attribs.append(vertex_texcoords[i])
|
||||||
if armature:
|
if armature is not None:
|
||||||
attribs.append(vertex_weights[i])
|
attribs.append(vertex_weights[i])
|
||||||
vertices.append(tuple(attribs))
|
vertices.append(tuple(attribs))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue