Fix invalid profiles after subdividing edges near arcs #4471

This commit is contained in:
Andrej730
2024-03-28 12:36:54 +05:00
parent 813518bcb5
commit 395598d8e3
3 changed files with 24 additions and 18 deletions
@@ -21,6 +21,7 @@ import bmesh
import mathutils
import ifcopenshell
import ifcopenshell.util.unit
import blenderbim.tool as tool
from math import pi, pow
from mathutils import Vector, Matrix, geometry
from typing import Union
@@ -141,13 +142,14 @@ class Helper:
total_groups = 0
is_circle = False
for group_type, group_indices in groups.items():
for group_index in group_indices:
if group_index in vert[deform_layer]:
if group_type == "IFCCIRCLE":
is_circle = True
group_verts[group_type].setdefault(group_index, 0)
group_verts[group_type][group_index] += 1
total_groups += 0
is_special, group_index = tool.Blender.bmesh_check_vertex_in_groups(vert, deform_layer, group_indices)
if not is_special:
continue
if group_type == "IFCCIRCLE":
is_circle = True
group_verts[group_type].setdefault(group_index, 0)
group_verts[group_type][group_index] += 1
total_groups += 0
if total_groups > 1: # A vert can only belong to one group
return (False, "AMBIGUOUS_SPECIAL_VERTEX")
elif is_circle:
@@ -23,6 +23,7 @@ from math import sin, cos, radians
from bpy.types import SpaceView3D
from mathutils import Vector, Matrix
from gpu_extras.batch import batch_for_shader
from typing import Union
ERROR_ELEMENTS_COLOR = (1, 0.2, 0.322, 1) # RED
@@ -35,15 +36,6 @@ def transparent_color(color, alpha=0.1):
return color
def bm_check_vertex_in_groups(vertex, deform_layer, groups):
"""returns tuple boolean (whether vertex is in any of the groups)
and related group index"""
for group_index in vertex[deform_layer].keys():
if group_index in groups:
return True, group_index
return False, None
class ProfileDecorator:
installed = None
@@ -148,12 +140,12 @@ class ProfileDecorator:
# deform_layer is None if there are no verts assigned to vertex groups
# even if there are vertex groups in the obj.vertex_groups
if deform_layer:
is_arc, group_index = bm_check_vertex_in_groups(vertex, deform_layer, arc_groups)
is_arc, group_index = tool.Blender.bmesh_check_vertex_in_groups(vertex, deform_layer, arc_groups)
if is_arc:
arcs.setdefault(group_index, []).append(vertex)
special_vertex_indices[vertex.index] = group_index
is_circle, group_index = bm_check_vertex_in_groups(vertex, deform_layer, circle_groups)
is_circle, group_index = tool.Blender.bmesh_check_vertex_in_groups(vertex, deform_layer, circle_groups)
if is_circle:
circles.setdefault(group_index, []).append(vertex)
special_vertex_indices[vertex.index] = group_index
+12
View File
@@ -569,6 +569,18 @@ class Blender(blenderbim.core.tool.Blender):
return bm_a
@classmethod
def bmesh_check_vertex_in_groups(
cls, vertex: bmesh.types.BMVert, deform_layer: bmesh.types.BMLayerItem, groups: list[int]
) -> Union[tuple[Literal[True], int], tuple[Literal[False], None]]:
"""returns tuple boolean (whether vertex is in any of the groups) and related group index"""
for group_index in vertex[deform_layer].keys():
# ignore vertex groups assignments produced by edge subdivision near arcs
# they usually have weight = 0.5
if group_index in groups and vertex[deform_layer][group_index] == 1.0:
return True, group_index
return False, None
@classmethod
def toggle_edit_mode(cls, context: bpy.types.Context) -> set:
ao = context.active_object