Skip to content

Commit d8aae09

Browse files
committed
refactor: improve thick rendering implementation with better validation and optimization
1 parent 2b7a055 commit d8aae09

File tree

4 files changed

+161
-111
lines changed

4 files changed

+161
-111
lines changed

model/line_2d.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,32 @@ def is_dashed(self):
4949
return self.construction
5050

5151
def update(self):
52+
"""Update the line's visual representation with thick geometry for Vulkan compatibility.
53+
54+
Creates triangle-based geometry for both solid and dashed lines to ensure
55+
consistent visibility across different graphics backends.
56+
"""
5257
if bpy.app.background:
5358
return
5459

55-
p1, p2 = self.p1.location, self.p2.location
60+
try:
61+
p1, p2 = self.p1.location, self.p2.location
5662

57-
if self.is_dashed():
58-
coords, indices = draw_thick_dashed_line_3d(p1, p2, self.line_width)
59-
else:
60-
coords, indices = draw_thick_line_3d(p1, p2, self.line_width)
61-
kwargs = {"pos": coords}
62-
self._batch = batch_for_shader(self._shader, "TRIS", kwargs, indices=indices)
63+
if self.is_dashed():
64+
coords, indices = draw_thick_dashed_line_3d(p1, p2, self.line_width)
65+
else:
66+
coords, indices = draw_thick_line_3d(p1, p2, self.line_width)
67+
68+
if not coords:
69+
logger.warning(f"Failed to create thick line geometry for {self}")
70+
return
6371

64-
self.is_dirty = False
72+
kwargs = {"pos": coords}
73+
self._batch = batch_for_shader(self._shader, "TRIS", kwargs, indices=indices)
74+
self.is_dirty = False
75+
except Exception as e:
76+
logger.error(f"Error updating line {self}: {e}")
77+
self.is_dirty = False
6578

6679
def create_slvs_data(self, solvesys, group=Solver.group_fixed):
6780
handle = solvesys.addLineSegment(self.p1.py_data, self.p2.py_data, group=group)

model/point_2d.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,28 @@ def is_point(cls):
2424
return True
2525

2626
def update(self):
27+
"""Update the point's visual representation with thick geometry for Vulkan compatibility.
28+
29+
Creates a triangle-based quad geometry for better visibility across different
30+
graphics backends, especially Vulkan where traditional point rendering may
31+
result in barely visible 1px points.
32+
"""
2733
if bpy.app.background:
2834
return
2935

30-
coords, indices = draw_thick_point_3d(self.location, self.point_size)
31-
kwargs = {"pos": coords}
32-
self._batch = batch_for_shader(self._shader, "TRIS", kwargs, indices=indices)
33-
34-
self.is_dirty = False
36+
try:
37+
coords, indices = draw_thick_point_3d(self.location, self.point_size)
38+
if not coords:
39+
# Fallback to ensure we have something to render
40+
logger.warning(f"Failed to create thick point geometry for {self}")
41+
return
42+
43+
kwargs = {"pos": coords}
44+
self._batch = batch_for_shader(self._shader, "TRIS", kwargs, indices=indices)
45+
self.is_dirty = False
46+
except Exception as e:
47+
logger.error(f"Error updating point {self}: {e}")
48+
self.is_dirty = False # Prevent infinite update loops
3549

3650
@property
3751
def location(self):

model/workplane.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from ..declarations import Operators
1212
from .. import global_data
13-
from ..utilities.draw import draw_rect_2d, draw_thick_line_3d, draw_thick_dashed_line_3d
13+
from ..utilities.draw import draw_rect_2d, draw_thick_line_3d, draw_thick_dashed_line_3d, WORKPLANE_LINE_SCALE
1414
from ..shaders import Shaders
1515
from ..utilities import preferences
1616
from ..solver import Solver
@@ -49,7 +49,7 @@ def update(self):
4949
rect_coords = [Vector(co) for co in rect_coords]
5050

5151
# Use a much smaller width for workplane edges (accounting for view distance scaling)
52-
line_width = 0.2
52+
line_width = WORKPLANE_LINE_SCALE
5353

5454
all_coords = []
5555
all_indices = []

0 commit comments

Comments
 (0)