diff --git a/release/scripts/op/uv.py b/release/scripts/op/uv.py index 7e903c04421..79ce5fe5a1e 100644 --- a/release/scripts/op/uv.py +++ b/release/scripts/op/uv.py @@ -126,27 +126,39 @@ def write_png(fw, mesh_source, image_width, image_height, face_iter): for f in mesh_source.faces: tot_verts += len(f.vertices) + + faces_source = mesh_source.faces + + # get unique UV's incase there are many overlapping which slow down filling. + face_hash_3 = set() + face_hash_4 = set() + for i, uv in face_iter: + material_index = faces_source[i].material_index + if len(uv) == 3: + face_hash_3.add((uv[0][0], uv[0][1], uv[1][0], uv[1][1], uv[2][0], uv[2][1], material_index)) + else: + face_hash_4.add((uv[0][0], uv[0][1], uv[1][0], uv[1][1], uv[2][0], uv[2][1], uv[3][0], uv[3][1], material_index)) + # now set the faces coords and locations # build mesh data mesh_new_vertices = [] mesh_new_materials = [] mesh_new_face_vertices = [] - - - current_vert = 0 - faces_source = mesh_source.faces - for i, uv in face_iter: - if len(uv) == 3: - mesh_new_vertices.extend([uv[0][0], uv[0][1], 0.0, uv[1][0], uv[1][1], 0.0, uv[2][0], uv[2][1], 0.0]) - mesh_new_face_vertices.extend([current_vert, current_vert + 1, current_vert + 2, 0]) - current_vert += 3 - else: - mesh_new_vertices.extend([uv[0][0], uv[0][1], 0.0, uv[1][0], uv[1][1], 0.0, uv[2][0], uv[2][1], 0.0, uv[3][0], uv[3][1], 0.0]) - mesh_new_face_vertices.extend([current_vert, current_vert + 1, current_vert + 2, current_vert + 3]) - current_vert += 4 - mesh_new_materials.append(faces_source[i].material_index) - + + current_vert = 0 + + for face_data in face_hash_3: + mesh_new_vertices.extend([face_data[0], face_data[1], 0.0, face_data[2], face_data[3], 0.0, face_data[4], face_data[5], 0.0]) + mesh_new_face_vertices.extend([current_vert, current_vert + 1, current_vert + 2, 0]) + mesh_new_materials.append(face_data[6]) + current_vert += 3 + for face_data in face_hash_4: + mesh_new_vertices.extend([face_data[0], face_data[1], 0.0, face_data[2], face_data[3], 0.0, face_data[4], face_data[5], 0.0, face_data[6], face_data[7], 0.0]) + mesh_new_face_vertices.extend([current_vert, current_vert + 1, current_vert + 2, current_vert + 3]) + mesh_new_materials.append(face_data[8]) + current_vert += 4 + mesh.vertices.add(len(mesh_new_vertices) // 3) mesh.faces.add(len(mesh_new_face_vertices) // 4)