[Bf-extensions-cvs] [227fafdf] blender2.8: Update for removal of tessfaces.

Brecht Van Lommel noreply at git.blender.org
Wed Oct 10 17:53:54 CEST 2018


Commit: 227fafdfcf4fb441ba1b8477331d543d2cf087af
Author: Brecht Van Lommel
Date:   Tue Oct 9 19:08:04 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBA227fafdfcf4fb441ba1b8477331d543d2cf087af

Update for removal of tessfaces.

This ports the already working addons. The disabled x3d, psk, lwo, 3ds,
raw, dxf addons still need to be converted.

===================================================================

M	io_export_pc2.py
M	io_mesh_ply/export_ply.py
M	io_mesh_ply/import_ply.py
M	io_mesh_stl/blender_utils.py
M	io_scene_obj/export_obj.py
M	io_scene_vrml2/export_vrml2.py
M	mesh_extra_tools/mesh_extrude_and_reshape.py
M	mesh_extra_tools/mesh_filletplus.py
M	mesh_extra_tools/mesh_vertex_chamfer.py
M	mesh_looptools.py
M	mesh_snap_utilities_line.py
M	modules/snap_context/mesh_drawing.py
M	object_print3d_utils/mesh_helpers.py
M	oscurart_tools/oscurart_meshes.py
M	render_povray/render.py

===================================================================

diff --git a/io_export_pc2.py b/io_export_pc2.py
index cc1f8d78..2f916d3b 100644
--- a/io_export_pc2.py
+++ b/io_export_pc2.py
@@ -63,7 +63,7 @@ def do_export(context, props, filepath):
     end = props.range_end
     sampling = float(props.sampling)
     apply_modifiers = props.apply_modifiers
-    me = ob.to_mesh(context.depsgraph, apply_modifiers, calc_tessface=False)
+    me = ob.to_mesh(context.depsgraph, apply_modifiers, calc_loop_triangles=False)
     vertCount = len(me.vertices)
     sampletimes = get_sampled_frames(start, end, sampling)
     sampleCount = len(sampletimes)
@@ -80,7 +80,7 @@ def do_export(context, props, filepath):
         # stupid modf() gives decimal part first!
         sc.frame_set(int(frame[1]), subframe=frame[0])
         me = ob.to_mesh(context.depsgraph, apply_modifiers,
-                        calc_tessface=False)
+                        calc_loop_triangles=False)
 
         if len(me.vertices) != vertCount:
             bpy.data.meshes.remove(me, do_unlink=True)
diff --git a/io_mesh_ply/export_ply.py b/io_mesh_ply/export_ply.py
index b6ab8810..b50b6544 100644
--- a/io_mesh_ply/export_ply.py
+++ b/io_mesh_ply/export_ply.py
@@ -44,12 +44,12 @@ def save_mesh(filepath,
     file = open(filepath, "w", encoding="utf8", newline="\n")
     fw = file.write
 
-    # Be sure tessface & co are available!
-    if not mesh.tessfaces and mesh.polygons:
-        mesh.calc_tessface()
+    # Be sure tessellated loop trianlges are available!
+    if not mesh.loop_triangles and mesh.polygons:
+        mesh.calc_loop_triangles()
 
-    has_uv = bool(mesh.tessface_uv_textures)
-    has_vcol = bool(mesh.tessface_vertex_colors)
+    has_uv = bool(mesh.uv_layers)
+    has_vcol = bool(mesh.vertex_colors)
 
     if not has_uv:
         use_uv_coords = False
@@ -62,7 +62,7 @@ def save_mesh(filepath,
         has_vcol = False
 
     if has_uv:
-        active_uv_layer = mesh.tessface_uv_textures.active
+        active_uv_layer = mesh.uv_layers.active
         if not active_uv_layer:
             use_uv_coords = False
             has_uv = False
@@ -70,7 +70,7 @@ def save_mesh(filepath,
             active_uv_layer = active_uv_layer.data
 
     if has_vcol:
-        active_col_layer = mesh.tessface_vertex_colors.active
+        active_col_layer = mesh.vertex_colors.active
         if not active_col_layer:
             use_colors = False
             has_vcol = False
@@ -84,9 +84,9 @@ def save_mesh(filepath,
     ply_verts = []  # list of dictionaries
     # vdict = {} # (index, normal, uv) -> new index
     vdict = [{} for i in range(len(mesh_verts))]
-    ply_faces = [[] for f in range(len(mesh.tessfaces))]
+    ply_faces = [[] for f in range(len(mesh.loop_triangles))]
     vert_count = 0
-    for i, f in enumerate(mesh.tessfaces):
+    for i, f in enumerate(mesh.loop_triangles):
 
         smooth = not use_normals or f.use_smooth
         if not smooth:
@@ -94,11 +94,9 @@ def save_mesh(filepath,
             normal_key = rvec3d(normal)
 
         if has_uv:
-            uv = active_uv_layer[i]
-            uv = uv.uv1, uv.uv2, uv.uv3, uv.uv4
+            uv = [active_uv_layer[l].uv[:] for l in f.loops]
         if has_vcol:
-            col = active_col_layer[i]
-            col = col.color1[:], col.color2[:], col.color3[:], col.color4[:]
+            col = [active_col_layer[l].color[:] for l in f.loops]
 
         pf = ply_faces[i]
         for j, vidx in enumerate(f.vertices):
@@ -156,7 +154,7 @@ def save_mesh(filepath,
            "property uchar blue\n"
            "property uchar alpha\n")
 
-    fw("element face %d\n" % len(mesh.tessfaces))
+    fw("element face %d\n" % len(mesh.loop_triangles))
     fw("property list uchar uint vertex_indices\n")
     fw("end_header\n")
 
diff --git a/io_mesh_ply/import_ply.py b/io_mesh_ply/import_ply.py
index a106f6e4..f05e1caa 100644
--- a/io_mesh_ply/import_ply.py
+++ b/io_mesh_ply/import_ply.py
@@ -263,9 +263,9 @@ def load_ply_mesh(filepath, ply_name):
     def add_face(vertices, indices, uvindices, colindices):
         mesh_faces.append(indices)
         if uvindices:
-            mesh_uvs.append([(vertices[index][uvindices[0]], vertices[index][uvindices[1]]) for index in indices])
+            mesh_uvs.extend([(vertices[index][uvindices[0]], vertices[index][uvindices[1]]) for index in indices])
         if colindices:
-            mesh_colors.append([(vertices[index][colindices[0]] * colmultiply[0],
+            mesh_colors.extend([(vertices[index][colindices[0]] * colmultiply[0],
                                  vertices[index][colindices[1]] * colmultiply[1],
                                  vertices[index][colindices[2]] * colmultiply[2],
                                  vertices[index][colindices[3]] * colmultiply[3],
@@ -317,35 +317,37 @@ def load_ply_mesh(filepath, ply_name):
         mesh.edges.foreach_set("vertices", [a for e in obj[b'edge'] for a in (e[eindex1], e[eindex2])])
 
     if mesh_faces:
-        mesh.tessfaces.add(len(mesh_faces))
-        mesh.tessfaces.foreach_set("vertices_raw", unpack_face_list(mesh_faces))
-
-        if uvindices or colindices:
-            if uvindices:
-                uvlay = mesh.tessface_uv_textures.new()
-            if colindices:
-                vcol_lay = mesh.tessface_vertex_colors.new()
-
-            if uvindices:
-                for i, f in enumerate(uvlay.data):
-                    ply_uv = mesh_uvs[i]
-                    for j, uv in enumerate(f.uv):
-                        uv[0], uv[1] = ply_uv[j]
-
-            if colindices:
-                for i, f in enumerate(vcol_lay.data):
-                    # XXX, colors dont come in right, needs further investigation.
-                    ply_col = mesh_colors[i]
-                    if len(ply_col) == 4:
-                        f_col = f.color1, f.color2, f.color3, f.color4
-                    else:
-                        f_col = f.color1, f.color2, f.color3
+        loops_vert_idx = []
+        faces_loop_start = []
+        faces_loop_total = []
+        lidx = 0
+        for f in mesh_faces:
+            nbr_vidx = len(f)
+            loops_vert_idx.extend(f)
+            faces_loop_start.append(lidx)
+            faces_loop_total.append(nbr_vidx)
+            lidx += nbr_vidx
+
+        mesh.loops.add(len(loops_vert_idx))
+        mesh.polygons.add(len(mesh_faces))
+
+        mesh.loops.foreach_set("vertex_index", loops_vert_idx)
+        mesh.polygons.foreach_set("loop_start", faces_loop_start)
+        mesh.polygons.foreach_set("loop_total", faces_loop_total)
+
+        if uvindices:
+            uv_layer = mesh.uv_layers.new()
+            for i, uv in enumerate(uv_layer.data):
+                uv.uv = mesh_uvs[i]
+
+        if colindices:
+            vcol_lay = mesh.vertex_colors.new()
 
-                    for j, col in enumerate(f_col):
-                        col[0] = ply_col[j][0]
-                        col[1] = ply_col[j][1]
-                        col[2] = ply_col[j][2]
-                        col[3] = ply_col[j][3]
+            for i, col in enumerate(vcol_lay.data):
+                col.color[0] = mesh_colors[i][0]
+                col.color[1] = mesh_colors[i][1]
+                col.color[2] = mesh_colors[i][2]
+                col.color[3] = mesh_colors[i][3]
 
     mesh.update()
     mesh.validate()
diff --git a/io_mesh_stl/blender_utils.py b/io_mesh_stl/blender_utils.py
index 3c895560..ee5cb098 100644
--- a/io_mesh_stl/blender_utils.py
+++ b/io_mesh_stl/blender_utils.py
@@ -63,7 +63,7 @@ def create_and_link_mesh(name, faces, face_nors, points, global_matrix):
     obj.select_set("SELECT")
 
 
-def faces_from_mesh(ob, global_matrix, use_mesh_modifiers=False, triangulate=True):
+def faces_from_mesh(ob, global_matrix, use_mesh_modifiers=False):
     """
     From an object, return a generator over a list of faces.
 
@@ -90,26 +90,11 @@ def faces_from_mesh(ob, global_matrix, use_mesh_modifiers=False, triangulate=Tru
     mesh.transform(mat)
     if mat.is_negative:
         mesh.flip_normals()
-        mesh.calc_tessface()
-
-    if triangulate:
-        # From a list of faces, return the face triangulated if needed.
-        def iter_face_index():
-            for face in mesh.tessfaces:
-                vertices = face.vertices[:]
-                if len(vertices) == 4:
-                    yield vertices[0], vertices[1], vertices[2]
-                    yield vertices[2], vertices[3], vertices[0]
-                else:
-                    yield vertices
-    else:
-        def iter_face_index():
-            for face in mesh.tessfaces:
-                yield face.vertices[:]
+    mesh.calc_loop_triangles()
 
     vertices = mesh.vertices
 
-    for indexes in iter_face_index():
-        yield [vertices[index].co.copy() for index in indexes]
+    for tri in mesh.loop_triangles:
+        yield [vertices[index].co.copy() for index in tri.vertices]
 
     bpy.data.meshes.remove(mesh)
diff --git a/io_scene_obj/export_obj.py b/io_scene_obj/export_obj.py
index 417a54c3..a0f64abf 100644
--- a/io_scene_obj/export_obj.py
+++ b/io_scene_obj/export_obj.py
@@ -349,7 +349,7 @@ def write_file(filepath, objects, depsgraph, scene,
                         # END NURBS
 
                         try:
-                            me = ob.to_mesh(depsgraph, EXPORT_APPLY_MODIFIERS, calc_tessface=False)
+                            me = ob.to_mesh(depsgraph, EXPORT_APPLY_MODIFIERS, calc_loop_triangles=False)
                         except RuntimeError:
                             me = None
 
@@ -377,7 +377,6 @@ def write_file(filepath, objects, depsgraph, scene,
 
                         # Make our own list so it can be sorted to reduce context switching
                         face_index_pairs = [(face, index) for index, face in enumerate(me.polygons)]
-                        # faces = [ f for f in me.tessfaces ]
 
                         if EXPORT_EDGES:
                             edges = me.edges
diff --git a/io_scene_vrml2/export_vrml2.py b/io_scene_vrml2/export_vrml2.py
index 06f79fc1..da09fcbd 100644
--- a/io_scene_vrml2/export_vrml2.py
+++ b/io_scene_vrml2/export_vrml2.py
@@ -163,7 +163,7 @@ def save_object(fw, global_matrix,
         if is_editmode:
   

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list