|
@@ -231,7 +231,7 @@ TEMPLATE_FILE_ASCII = """\
|
|
|
"faces" : %(nface)d,
|
|
|
"normals" : %(nnormal)d,
|
|
|
"colors" : %(ncolor)d,
|
|
|
- "uvs" : %(nuv)d,
|
|
|
+ "uvs" : [%(nuvs)s],
|
|
|
"materials" : %(nmaterial)d,
|
|
|
"morphTargets" : %(nmorphTarget)d,
|
|
|
"bones" : %(nbone)d
|
|
@@ -255,7 +255,7 @@ TEMPLATE_MODEL_ASCII = """\
|
|
|
|
|
|
"colors": [%(colors)s],
|
|
|
|
|
|
- "uvs": [[%(uvs)s]],
|
|
|
+ "uvs": [%(uvs)s],
|
|
|
|
|
|
"faces": [%(faces)s],
|
|
|
|
|
@@ -306,9 +306,9 @@ def get_normal_indices(v, normals, mesh):
|
|
|
|
|
|
return n
|
|
|
|
|
|
-def get_uv_indices(face_index, uvs, mesh):
|
|
|
+def get_uv_indices(face_index, uvs, mesh, layer_index):
|
|
|
uv = []
|
|
|
- uv_layer = mesh.tessface_uv_textures.active.data
|
|
|
+ uv_layer = mesh.tessface_uv_textures[layer_index].data
|
|
|
for i in uv_layer[face_index].uv:
|
|
|
uv.append( uvs[veckey2d(i)] )
|
|
|
return uv
|
|
@@ -471,7 +471,7 @@ def setBit(value, position, on):
|
|
|
mask = ~(1 << position)
|
|
|
return (value & mask)
|
|
|
|
|
|
-def generate_faces(normals, uvs, colors, meshes, option_normals, option_colors, option_uv_coords, option_materials, option_faces):
|
|
|
+def generate_faces(normals, uv_layers, colors, meshes, option_normals, option_colors, option_uv_coords, option_materials, option_faces):
|
|
|
|
|
|
if not option_faces:
|
|
|
return "", 0
|
|
@@ -482,8 +482,8 @@ def generate_faces(normals, uvs, colors, meshes, option_normals, option_colors,
|
|
|
chunks = []
|
|
|
for mesh, object in meshes:
|
|
|
|
|
|
- faceUV = (len(mesh.uv_textures) > 0)
|
|
|
- vertexUV = (len(mesh.sticky) > 0)
|
|
|
+ faceUV = len(mesh.uv_textures) > 0
|
|
|
+ vertexUV = len(mesh.sticky) > 0
|
|
|
vertexColors = len(mesh.vertex_colors) > 0
|
|
|
|
|
|
mesh_colors = option_colors and vertexColors
|
|
@@ -500,7 +500,7 @@ def generate_faces(normals, uvs, colors, meshes, option_normals, option_colors,
|
|
|
mesh_extract_colors = False
|
|
|
|
|
|
for i, f in enumerate(get_faces(mesh)):
|
|
|
- face = generate_face(f, i, normals, uvs, colors, mesh, option_normals, mesh_colors, mesh_uvs, option_materials, vertex_offset, material_offset)
|
|
|
+ face = generate_face(f, i, normals, uv_layers, colors, mesh, option_normals, mesh_colors, mesh_uvs, option_materials, vertex_offset, material_offset)
|
|
|
chunks.append(face)
|
|
|
|
|
|
vertex_offset += len(mesh.vertices)
|
|
@@ -513,7 +513,7 @@ def generate_faces(normals, uvs, colors, meshes, option_normals, option_colors,
|
|
|
|
|
|
return ",".join(chunks), len(chunks)
|
|
|
|
|
|
-def generate_face(f, faceIndex, normals, uvs, colors, mesh, option_normals, option_colors, option_uv_coords, option_materials, vertex_offset, material_offset):
|
|
|
+def generate_face(f, faceIndex, normals, uv_layers, colors, mesh, option_normals, option_colors, option_uv_coords, option_materials, vertex_offset, material_offset):
|
|
|
isTriangle = ( len(f.vertices) == 3 )
|
|
|
|
|
|
if isTriangle:
|
|
@@ -567,10 +567,11 @@ def generate_face(f, faceIndex, normals, uvs, colors, mesh, option_normals, opti
|
|
|
faceData.append( index )
|
|
|
|
|
|
if hasFaceVertexUvs:
|
|
|
- uv = get_uv_indices(faceIndex, uvs, mesh)
|
|
|
- for i in range(nVertices):
|
|
|
- index = uv[i]
|
|
|
- faceData.append(index)
|
|
|
+ for layer_index, uvs in enumerate(uv_layers):
|
|
|
+ uv = get_uv_indices(faceIndex, uvs, mesh, layer_index)
|
|
|
+ for i in range(nVertices):
|
|
|
+ index = uv[i]
|
|
|
+ faceData.append(index)
|
|
|
|
|
|
if hasFaceVertexNormals:
|
|
|
n = get_normal_indices(f.vertices, normals, mesh)
|
|
@@ -648,29 +649,46 @@ def generate_vertex_colors(colors, option_colors):
|
|
|
# Model exporter - UVs
|
|
|
# #####################################################
|
|
|
|
|
|
-def extract_uvs(mesh, uvs, count):
|
|
|
- uv_layer = mesh.tessface_uv_textures.active.data
|
|
|
+def extract_uvs(mesh, uv_layers, counts):
|
|
|
+ for index, layer in enumerate(mesh.tessface_uv_textures):
|
|
|
|
|
|
- for face_index, face in enumerate(get_faces(mesh)):
|
|
|
+ if len(uv_layers) <= index:
|
|
|
+ uvs = {}
|
|
|
+ count = 0
|
|
|
+ uv_layers.append(uvs)
|
|
|
+ counts.append(count)
|
|
|
+ else:
|
|
|
+ uvs = uv_layers[index]
|
|
|
+ count = counts[index]
|
|
|
|
|
|
- for uv_index, uv in enumerate(uv_layer[face_index].uv):
|
|
|
+ uv_layer = layer.data
|
|
|
|
|
|
- key = veckey2d(uv)
|
|
|
- if key not in uvs:
|
|
|
- uvs[key] = count
|
|
|
- count += 1
|
|
|
+ for face_index, face in enumerate(get_faces(mesh)):
|
|
|
|
|
|
- return count
|
|
|
+ for uv_index, uv in enumerate(uv_layer[face_index].uv):
|
|
|
+
|
|
|
+ key = veckey2d(uv)
|
|
|
+ if key not in uvs:
|
|
|
+ uvs[key] = count
|
|
|
+ count += 1
|
|
|
|
|
|
-def generate_uvs(uvs, option_uv_coords):
|
|
|
+ counts[index] = count
|
|
|
+
|
|
|
+ return counts
|
|
|
+
|
|
|
+def generate_uvs(uv_layers, option_uv_coords):
|
|
|
if not option_uv_coords:
|
|
|
- return ""
|
|
|
+ return "[]"
|
|
|
|
|
|
- chunks = []
|
|
|
- for key, index in sorted(uvs.items(), key=operator.itemgetter(1)):
|
|
|
- chunks.append(key)
|
|
|
+ layers = []
|
|
|
+ for uvs in uv_layers:
|
|
|
+ chunks = []
|
|
|
+ for key, index in sorted(uvs.items(), key=operator.itemgetter(1)):
|
|
|
+ chunks.append(key)
|
|
|
+ layer = ",".join(generate_uv(n) for n in chunks)
|
|
|
+ layers.append(layer)
|
|
|
|
|
|
- return ",".join(generate_uv(n) for n in chunks)
|
|
|
+ return ",".join("[%s]" % n for n in layers)
|
|
|
|
|
|
# ##############################################################################
|
|
|
# Model exporter - bones
|
|
@@ -1250,16 +1268,16 @@ def generate_ascii_model(meshes, morphs,
|
|
|
ncolor = 0
|
|
|
colors = {}
|
|
|
|
|
|
- nuv = 0
|
|
|
- uvs = {}
|
|
|
+ nuvs = []
|
|
|
+ uv_layers = []
|
|
|
|
|
|
nmaterial = 0
|
|
|
materials = []
|
|
|
|
|
|
for mesh, object in meshes:
|
|
|
|
|
|
- faceUV = (len(mesh.uv_textures) > 0)
|
|
|
- vertexUV = (len(mesh.sticky) > 0)
|
|
|
+ faceUV = len(mesh.uv_textures) > 0
|
|
|
+ vertexUV = len(mesh.sticky) > 0
|
|
|
vertexColors = len(mesh.vertex_colors) > 0
|
|
|
|
|
|
mesh_extract_colors = option_colors and vertexColors
|
|
@@ -1287,7 +1305,7 @@ def generate_ascii_model(meshes, morphs,
|
|
|
ncolor = extract_vertex_colors(mesh, colors, ncolor)
|
|
|
|
|
|
if mesh_extract_uvs:
|
|
|
- nuv = extract_uvs(mesh, uvs, nuv)
|
|
|
+ nuvs = extract_uvs(mesh, uv_layers, nuvs)
|
|
|
|
|
|
if option_materials:
|
|
|
mesh_materials, nmaterial = generate_materials_string(mesh, scene, mesh_extract_colors, object.draw_type, option_copy_textures, filepath, nmaterial)
|
|
@@ -1313,7 +1331,7 @@ def generate_ascii_model(meshes, morphs,
|
|
|
elif align_model == 3:
|
|
|
top(vertices)
|
|
|
|
|
|
- faces_string, nfaces = generate_faces(normals, uvs, colors, meshes, option_normals, option_colors, option_uv_coords, option_materials, option_faces)
|
|
|
+ faces_string, nfaces = generate_faces(normals, uv_layers, colors, meshes, option_normals, option_colors, option_uv_coords, option_materials, option_faces)
|
|
|
|
|
|
bones_string, nbone = generate_bones(option_bones, flipyz)
|
|
|
indices_string, weights_string = generate_indices_and_weights(meshes, option_skinning)
|
|
@@ -1323,7 +1341,7 @@ def generate_ascii_model(meshes, morphs,
|
|
|
model_string = TEMPLATE_MODEL_ASCII % {
|
|
|
"scale" : option_scale,
|
|
|
|
|
|
- "uvs" : generate_uvs(uvs, option_uv_coords),
|
|
|
+ "uvs" : generate_uvs(uv_layers, option_uv_coords),
|
|
|
"normals" : generate_normals(normals, option_normals),
|
|
|
"colors" : generate_vertex_colors(colors, option_colors),
|
|
|
|
|
@@ -1344,7 +1362,7 @@ def generate_ascii_model(meshes, morphs,
|
|
|
text = TEMPLATE_FILE_ASCII % {
|
|
|
"nvertex" : len(vertices),
|
|
|
"nface" : nfaces,
|
|
|
- "nuv" : nuv,
|
|
|
+ "nuvs" : ",".join("%d" % n for n in nuvs),
|
|
|
"nnormal" : nnormal,
|
|
|
"ncolor" : ncolor,
|
|
|
"nmaterial" : nmaterial,
|