[Bf-python] [Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3035] trunk/py/scripts/addons/ io_mesh_uv_layout: Updated io_mesh_uv_layout addon to work with bmesh.
Bastien Montagne
montagne29 at wanadoo.fr
Tue Feb 28 16:49:22 CET 2012
Fix [#30311] Export UV Layout fails in Blender 2.62 r44340 from SVN.
Le 28/02/2012 16:35, Bastien Montagne a écrit :
> Revision: 3035
> http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3035
> Author: mont29
> Date: 2012-02-28 15:35:49 +0000 (Tue, 28 Feb 2012)
> Log Message:
> -----------
> 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...
>
> Modified Paths:
> --------------
> trunk/py/scripts/addons/io_mesh_uv_layout/__init__.py
> trunk/py/scripts/addons/io_mesh_uv_layout/export_uv_eps.py
> trunk/py/scripts/addons/io_mesh_uv_layout/export_uv_png.py
> trunk/py/scripts/addons/io_mesh_uv_layout/export_uv_svg.py
>
> Modified: trunk/py/scripts/addons/io_mesh_uv_layout/__init__.py
> ===================================================================
> --- trunk/py/scripts/addons/io_mesh_uv_layout/__init__.py 2012-02-28 07:18:13 UTC (rev 3034)
> +++ trunk/py/scripts/addons/io_mesh_uv_layout/__init__.py 2012-02-28 15:35:49 UTC (rev 3035)
> @@ -21,8 +21,8 @@
> bl_info = {
> "name": "UV Layout",
> "author": "Campbell Barton, Matt Ebb",
> - "version": (1, 0),
> - "blender": (2, 5, 8),
> + "version": (1, 1),
> + "blender": (2, 6, 2),
> "location": "Image-Window> UVs> Export UV Layout",
> "description": "Export the UV layout as a 2D graphic",
> "warning": "",
> @@ -103,6 +103,12 @@
> min=0.0, max=1.0,
> default=0.25,
> )
> + tesselated = BoolProperty(
> + name="Tesselated UVs",
> + description="Export tesselated UVs instead of polygons ones",
> + default=False,
> + options={'HIDDEN'}, # As not working currently :/
> + )
>
> @classmethod
> def poll(cls, context):
> @@ -131,12 +137,12 @@
>
> return image_width, image_height
>
> - def _face_uv_iter(self, context, mesh):
> - uv_layer = mesh.uv_textures.active.data
> - uv_layer_len = len(uv_layer)
> + def _face_uv_iter(self, context, mesh, tesselated):
> + uv_layer = mesh.uv_loop_layers.active.data
> + polys = mesh.polygons
>
> if not self.export_all:
> -
> + uv_tex = mesh.uv_textures.active.data
> local_image = Ellipsis
>
> if context.tool_settings.show_uv_local_view:
> @@ -144,23 +150,27 @@
> if space_data:
> local_image = space_data.image
>
> - faces = mesh.faces
> -
> - for i in range(uv_layer_len):
> - uv_elem = uv_layer[i]
> + for i, p in enumerate(polys):
> # context checks
> - if faces[i].select and (local_image is Ellipsis or
> - local_image == uv_elem.image):
> + if polys[i].select and local_image in {Ellipsis,
> + uv_tex[i].image}:
> + start = p.loop_start
> + end = start + p.loop_total
> + uvs = tuple((uv.uv[0], uv.uv[1])
> + for uv in uv_layer[start:end])
> #~ uv = uv_elem.uv
> #~ if False not in uv_elem.select_uv[:len(uv)]:
> #~ yield (i, uv)
>
> # just write what we see.
> - yield (i, uv_layer[i].uv)
> + yield (i, uvs)
> else:
> # all, simple
> - for i in range(uv_layer_len):
> - yield (i, uv_layer[i].uv)
> + for i, p in enumerate(polys):
> + start = p.loop_start
> + end = start + p.loop_total
> + uvs = tuple((uv.uv[0], uv.uv[1]) for uv in uv_layer[start:end])
> + yield (i, uvs)
>
> def execute(self, context):
>
> @@ -192,7 +202,8 @@
> mesh = obj.data
>
> func(fw, mesh, self.size[0], self.size[1], self.opacity,
> - lambda: self._face_uv_iter(context, mesh))
> +# self.tesselated,
> + lambda: self._face_uv_iter(context, mesh, self.tesselated))
>
> if self.modified:
> bpy.data.meshes.remove(mesh)
>
> Modified: trunk/py/scripts/addons/io_mesh_uv_layout/export_uv_eps.py
> ===================================================================
> --- trunk/py/scripts/addons/io_mesh_uv_layout/export_uv_eps.py 2012-02-28 07:18:13 UTC (rev 3034)
> +++ trunk/py/scripts/addons/io_mesh_uv_layout/export_uv_eps.py 2012-02-28 15:35:49 UTC (rev 3035)
> @@ -39,7 +39,7 @@
> fw("1 setlinejoin\n")
> fw("1 setlinecap\n")
>
> - faces = mesh.faces
> + polys = mesh.polygons
>
> if opacity> 0.0:
> for i, mat in enumerate(mesh.materials if mesh.materials else [None]):
> @@ -67,7 +67,7 @@
> fw("%.5f %.5f lineto\n" % uv_scale)
>
> fw("closepath\n")
> - fw("DRAW_%d\n" % faces[i].material_index)
> + fw("DRAW_%d\n" % polys[i].material_index)
>
> # stroke only
> for i, uvs in face_iter_func():
>
> Modified: trunk/py/scripts/addons/io_mesh_uv_layout/export_uv_png.py
> ===================================================================
> --- trunk/py/scripts/addons/io_mesh_uv_layout/export_uv_png.py 2012-02-28 07:18:13 UTC (rev 3034)
> +++ trunk/py/scripts/addons/io_mesh_uv_layout/export_uv_png.py 2012-02-28 15:35:49 UTC (rev 3035)
> @@ -35,60 +35,44 @@
> 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)
> + polys_source = mesh_source.polygons
>
> - faces_source = mesh_source.faces
> -
> # 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
> + 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(len(mesh_new_vertices) // 3)
> - mesh.faces.add(len(mesh_new_face_vertices) // 4)
> + 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)
>
>
> Modified: trunk/py/scripts/addons/io_mesh_uv_layout/export_uv_svg.py
> ===================================================================
> --- trunk/py/scripts/addons/io_mesh_uv_layout/export_uv_svg.py 2012-02-28 07:18:13 UTC (rev 3034)
> +++ trunk/py/scripts/addons/io_mesh_uv_layout/export_uv_svg.py 2012-02-28 15:35:49 UTC (rev 3035)
> @@ -47,10 +47,10 @@
> else:
> fill_settings.append(fill_default)
>
> - faces = mesh.faces
> + polys = mesh.polygons
> for i, uvs in face_iter_func():
> try: # rare cases material index is invalid.
> - fill = fill_settings[faces[i].material_index]
> + fill = fill_settings[polys[i].material_index]
> except IndexError:
> fill = fill_default
>
>
> _______________________________________________
> Bf-extensions-cvs mailing list
> Bf-extensions-cvs at blender.org
> http://lists.blender.org/mailman/listinfo/bf-extensions-cvs
>
More information about the Bf-python
mailing list