[Bf-extensions-cvs] [5a08a2e] master: Fix T47219: OBJ import merges faces incorrectly

Campbell Barton noreply at git.blender.org
Fri Jan 22 07:07:16 CET 2016


Commit: 5a08a2e1856875d99cc99be44b955500faccf339
Author: Campbell Barton
Date:   Fri Jan 22 16:43:49 2016 +1100
Branches: master
https://developer.blender.org/rBA5a08a2e1856875d99cc99be44b955500faccf339

Fix T47219: OBJ import merges faces incorrectly

Invalid triangles were being detected as faces that looped back on themselves and had their edges dissolved.

Now ignore invalid triangles entirely since they will never end up as faces in Blender.

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

M	io_scene_obj/import_obj.py

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

diff --git a/io_scene_obj/import_obj.py b/io_scene_obj/import_obj.py
index e94e32b..7b06582 100644
--- a/io_scene_obj/import_obj.py
+++ b/io_scene_obj/import_obj.py
@@ -566,43 +566,46 @@ def create_mesh(new_objects,
 
             # NGons into triangles
             if face_invalid_blenpoly:
-                from bpy_extras.mesh_utils import ngon_tessellate
-                ngon_face_indices = ngon_tessellate(verts_loc, face_vert_loc_indices)
-                faces.extend([([face_vert_loc_indices[ngon[0]],
-                                face_vert_loc_indices[ngon[1]],
-                                face_vert_loc_indices[ngon[2]],
-                                ],
-                               [face_vert_nor_indices[ngon[0]],
-                                face_vert_nor_indices[ngon[1]],
-                                face_vert_nor_indices[ngon[2]],
-                                ] if face_vert_nor_indices else [],
-                               [face_vert_tex_indices[ngon[0]],
-                                face_vert_tex_indices[ngon[1]],
-                                face_vert_tex_indices[ngon[2]],
-                                ] if face_vert_tex_indices else [],
-                               context_material,
-                               context_smooth_group,
-                               context_object,
-                               [],
-                               )
-                             for ngon in ngon_face_indices]
-                             )
-                tot_loops += 3 * len(ngon_face_indices)
-
-                # edges to make ngons
-                edge_users = set()
-                for ngon in ngon_face_indices:
-                    prev_vidx = face_vert_loc_indices[ngon[-1]]
-                    for ngidx in ngon:
-                        vidx = face_vert_loc_indices[ngidx]
-                        if vidx == prev_vidx:
-                            continue  # broken OBJ... Just skip.
-                        edge_key = (prev_vidx, vidx) if (prev_vidx < vidx) else (vidx, prev_vidx)
-                        prev_vidx = vidx
-                        if edge_key in edge_users:
-                            fgon_edges.add(edge_key)
-                        else:
-                            edge_users.add(edge_key)
+                # ignore triangles with invalid indices
+                if len(face_vert_loc_indices) > 3:
+                    from bpy_extras.mesh_utils import ngon_tessellate
+                    ngon_face_indices = ngon_tessellate(verts_loc, face_vert_loc_indices)
+                    faces.extend([([face_vert_loc_indices[ngon[0]],
+                                    face_vert_loc_indices[ngon[1]],
+                                    face_vert_loc_indices[ngon[2]],
+                                    ],
+                                [face_vert_nor_indices[ngon[0]],
+                                    face_vert_nor_indices[ngon[1]],
+                                    face_vert_nor_indices[ngon[2]],
+                                    ] if face_vert_nor_indices else [],
+                                [face_vert_tex_indices[ngon[0]],
+                                    face_vert_tex_indices[ngon[1]],
+                                    face_vert_tex_indices[ngon[2]],
+                                    ] if face_vert_tex_indices else [],
+                                context_material,
+                                context_smooth_group,
+                                context_object,
+                                [],
+                                )
+                                for ngon in ngon_face_indices]
+                                )
+                    tot_loops += 3 * len(ngon_face_indices)
+
+                    # edges to make ngons
+                    if len(ngon_face_indices) > 1:
+                        edge_users = set()
+                        for ngon in ngon_face_indices:
+                            prev_vidx = face_vert_loc_indices[ngon[-1]]
+                            for ngidx in ngon:
+                                vidx = face_vert_loc_indices[ngidx]
+                                if vidx == prev_vidx:
+                                    continue  # broken OBJ... Just skip.
+                                edge_key = (prev_vidx, vidx) if (prev_vidx < vidx) else (vidx, prev_vidx)
+                                prev_vidx = vidx
+                                if edge_key in edge_users:
+                                    fgon_edges.add(edge_key)
+                                else:
+                                    edge_users.add(edge_key)
 
                 faces.pop(f_idx)
             else:



More information about the Bf-extensions-cvs mailing list