Skip to content

Commit

Permalink
fixed symmetry option causing invalid mesh (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielBoxer committed Jul 26, 2024
1 parent f0c5bfe commit a16a9ae
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def finish(self, unwrap, output, added_edges):
uvvert_to_meshvert[uv_v] = mesh_verts[uv_v_idx]

# the faces will all be separate, so merging by distance joins them
bmesh.ops.remove_doubles(uvbm, verts=uvbm.verts, dist=1e-7)
bmesh.ops.remove_doubles(uvbm, verts=uvbm.verts, dist=0.0001)

# find boundary edges of uv bmesh which are seams of original bmesh
seams = []
Expand Down
7 changes: 1 addition & 6 deletions src/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def finish_unwrap(self, unwrap, invalid_pass=False):

if unwrap.merge_cuts:
bm = new_bmesh(output)
bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=1e-7)
bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=0.0001)
set_bmesh(bm, output)

# automatically add grid material to final object
Expand Down Expand Up @@ -205,11 +205,6 @@ def start_next(self):
)

if self.error_code != 0:
# convert unsigned int
THRESHOLD = 2147483648
ADJUSTMENT = 4294967296
if self.error_code >= THRESHOLD:
self.error_code -= ADJUSTMENT
err_msg = f"An unknown error occurred: {self.error_code}"
msg.append(err_msg)
logger.add_data("errors", err_msg)
Expand Down
28 changes: 4 additions & 24 deletions src/ops/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
calc_center,
check_collection,
cut,
cut_on_axes,
deselect_all,
export_obj,
get_dir_path,
Expand Down Expand Up @@ -286,34 +287,13 @@ def create_jobs(self, context):
obj.select_set(True)

symmetrize_job = None
# bisect if symmetry on
axes = props.sym_axes
if props.use_symmetry:
# bisect if symmetry on
axes = props.sym_axes
apply_transforms(obj)

bm = new_bmesh(obj)
obj_center = calc_center(obj)
symmetrize_job = Symmetrise(1, axes, obj_center, props.sym_merge)
cuts = []
if "X" in axes:
cuts.append((1, 0, 0))
if "Y" in axes:
cuts.append((0, 1, 0))
if "Z" in axes:
cuts.append((0, 0, 1))

for direction in cuts:
bmesh.ops.bisect_plane(
bm,
geom=bm.verts[:] + bm.edges[:] + bm.faces[:],
plane_co=obj_center,
plane_no=direction,
clear_inner=True,
)
# if the object already had vertices down it's center plane
# there will be duplicates
bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=1e-7)
set_bmesh(bm, obj)
cut_on_axes(obj, obj_center, axes)

# separate objects
bpy.ops.mesh.separate(type="LOOSE")
Expand Down
11 changes: 10 additions & 1 deletion src/unwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,17 @@ def poll_folder(self):
# mesh is invalid
msg = ""

# convert unsigned int
THRESHOLD = 2147483648
ADJUSTMENT = 4294967296
if ret_code >= THRESHOLD:
ret_code -= ADJUSTMENT

move_to_invalid = False
if ret_code == 101:
if ret_code == -1:
msg = "Mesh needs cleanup"
move_to_invalid = True
elif ret_code == 101:
msg = "Non Manifold Edges"
move_to_invalid = True
elif ret_code == 102:
Expand Down
24 changes: 24 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,27 @@ def cut(num, center, length, dim, bm):
bmesh.ops.split_edges(
bm, edges=[e for e in cut if isinstance(e, bmesh.types.BMEdge)]
)


def cut_on_axes(obj, obj_center, axes):
bm = new_bmesh(obj)
cuts = []
if "X" in axes:
cuts.append((1, 0, 0))
if "Y" in axes:
cuts.append((0, 1, 0))
if "Z" in axes:
cuts.append((0, 0, 1))

for direction in cuts:
bmesh.ops.bisect_plane(
bm,
geom=bm.verts[:] + bm.edges[:] + bm.faces[:],
plane_co=obj_center,
plane_no=direction,
clear_inner=True,
)
# if the object already had vertices down its center plane
# there will be duplicates
bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=0.0001)
set_bmesh(bm, obj)

0 comments on commit a16a9ae

Please sign in to comment.