Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2012-02-28 19:35:49 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2012-02-28 19:35:49 +0400
commite3f5cd8fd462d54961a6d87400b3b67a92f734d6 (patch)
treebd62335724c14ebd70d65dfd92bc63dc2937f1e0 /io_mesh_uv_layout/export_uv_png.py
parent55d1a5020af9fa652dd2af9bea4e01986284ef9c (diff)
Updated io_mesh_uv_layout addon to work with bmesh.
Note: would have loved to add an option to export tesselated layout (instead of ngon one), but currently I often get mesh without tesselation, and seems there is no way to call ensure_tesselated from python...
Diffstat (limited to 'io_mesh_uv_layout/export_uv_png.py')
-rw-r--r--io_mesh_uv_layout/export_uv_png.py66
1 files changed, 25 insertions, 41 deletions
diff --git a/io_mesh_uv_layout/export_uv_png.py b/io_mesh_uv_layout/export_uv_png.py
index fa67042e..423ad33a 100644
--- a/io_mesh_uv_layout/export_uv_png.py
+++ b/io_mesh_uv_layout/export_uv_png.py
@@ -35,60 +35,44 @@ def write(fw, mesh_source, image_width, image_height, opacity, face_iter_func):
for mat_solid in material_solids:
mesh.materials.append(mat_solid)
- tot_verts = 0
- for f in mesh_source.faces:
- tot_verts += len(f.vertices)
-
- faces_source = mesh_source.faces
+ polys_source = mesh_source.polygons
# get unique UV's in case there are many overlapping
# which slow down filling.
- face_hash_3 = set()
- face_hash_4 = set()
- for i, uv in face_iter_func():
- 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))
+ face_hash = {(uvs, polys_source[i].material_index)
+ for i, uvs in face_iter_func()}
# now set the faces coords and locations
# build mesh data
mesh_new_vertices = []
mesh_new_materials = []
- mesh_new_face_vertices = []
+ mesh_new_polys_startloop = []
+ mesh_new_polys_totloop = []
+ mesh_new_loops_vertices = []
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)
+ for uvs, mat_idx in face_hash:
+ num_verts = len(uvs)
+ dummy = (0.0,) * num_verts
+ for uv in uvs:
+ mesh_new_vertices += (uv[0], uv[1], 0.0)
+ mesh_new_polys_startloop.append(current_vert)
+ mesh_new_polys_totloop.append(num_verts)
+ mesh_new_loops_vertices += range(current_vert,
+ current_vert + num_verts)
+ mesh_new_materials.append(mat_idx)
+ current_vert += num_verts
+
+ mesh.vertices.add(current_vert)
+ mesh.loops.add(current_vert)
+ mesh.polygons.add(len(mesh_new_polys_startloop))
mesh.vertices.foreach_set("co", mesh_new_vertices)
- mesh.faces.foreach_set("vertices_raw", mesh_new_face_vertices)
- mesh.faces.foreach_set("material_index", mesh_new_materials)
+ mesh.loops.foreach_set("vertex_index", mesh_new_loops_vertices)
+ mesh.polygons.foreach_set("loop_start", mesh_new_polys_startloop)
+ mesh.polygons.foreach_set("loop_total", mesh_new_polys_totloop)
+ mesh.polygons.foreach_set("material_index", mesh_new_materials)
mesh.update(calc_edges=True)