Skip to content

Commit f14bdb2

Browse files
committed
small fixes
1 parent 9013840 commit f14bdb2

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

madcad/primitives.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def fit(self) -> err**2 as float:
4040

4141
from math import sqrt
4242
from .mathutils import *
43+
from .mesh.container import typedlist_to_numpy
4344
from . import settings
4445
from . import mesh
4546

@@ -408,7 +409,7 @@ def __repr__(self):
408409

409410
def display(self, scene):
410411
from .rendering.d3.marker import SplineDisplay
411-
return SplineDisplay(scene, typedlist_to_numpy(self.points), typedlist_to_numpy(self.mesh().points))
412+
return SplineDisplay(scene, typedlist_to_numpy(self.points, np.float32), typedlist_to_numpy(self.mesh().points, np.float32))
412413

413414
class Softened(object):
414415
''' Interpolated curve tangent to each segment midpoint (3rd degree bezier curve)
@@ -458,5 +459,5 @@ def __repr__(self):
458459

459460
def display(self, scene):
460461
from .rendering.d3.marker import SplineDisplay
461-
return SplineDisplay(scene, typedlist_to_numpy(self.points), typedlist_to_numpy(self.mesh().points))
462+
return SplineDisplay(scene, typedlist_to_numpy(self.points, np.float32), typedlist_to_numpy(self.mesh().points, np.float32))
462463

madcad/rendering/base.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ def display(self, obj, former:Display=None) -> Display:
105105
This is the actual function converting objects into displays.
106106
You don't need to call this method if you just want to add an object to the scene, use add() instead
107107
'''
108+
# prevent reference-loop in groups (groups are taken from the execution env, so the user may not want to display it however we are trying to)
108109
ido = id(obj)
109-
assert ido not in self.memo, 'there should not be recursion loops in cascading displays'
110-
self.memo.add(ido)
110+
assert ido not in self._memo, 'there should not be recursion loops in cascading displays'
111+
self._memo.add(ido)
111112

112113
try:
113114
# no refresh if object has not changed
@@ -136,7 +137,7 @@ def display(self, obj, former:Display=None) -> Display:
136137
raise TypeError('the display for {} is not a subclass of Display: {}'.format(type(obj).__name__, type(disp)))
137138

138139
finally:
139-
self.memo.remove(ido)
140+
self._memo.remove(ido)
140141

141142
# keeping a reference of the source object may increas the RAM used but avoid to refresh displays when updating the scene with the same constant value
142143
if self.options['track_source']:
@@ -217,6 +218,8 @@ def render(self, view):
217218

218219
def selection_add(self, display:Display, sub:int=None):
219220
''' select the given display '''
221+
if not hasattr(display, 'selected'):
222+
raise TypeError('{} is not selectable'.format(type(display).__name__))
220223
if isinstance(display.selected, set):
221224
display.selected.add(sub)
222225
display.selected = display.selected
@@ -228,6 +231,8 @@ def selection_add(self, display:Display, sub:int=None):
228231

229232
def selection_remove(self, display:Display, sub:int=None):
230233
''' deselect the given display '''
234+
if not hasattr(display, 'selected'):
235+
raise TypeError('{} is not selectable'.format(type(display).__name__))
231236
if isinstance(display.selected, set):
232237
if sub is None:
233238
display.selected.clear()
@@ -242,6 +247,8 @@ def selection_remove(self, display:Display, sub:int=None):
242247
self.touch()
243248

244249
def selection_toggle(self, display:Display, sub:int=None):
250+
if not hasattr(display, 'selected'):
251+
raise TypeError('{} is not selectable'.format(type(display).__name__))
245252
if isinstance(display.selected, set):
246253
selected = sub in display.selected
247254
else:

madcad/rendering/d3/marker.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,15 @@ class SplineDisplay(Display):
239239
''' display for spline curve, with handles around'''
240240
color: fvec4
241241
box: Box
242+
selected: bool
243+
hovered: bool
242244

243245
def __init__(self, scene, handles, curve, color=None):
244246
self.color = fvec3(color or settings.colors['line'])
247+
self.color_handles = fvec3(settings.colors['annotation'])
245248
self.box = npboundingbox(handles)
249+
self.selected = False
250+
self.hovered = False
246251

247252
ctx = scene.context
248253
vb_handles = ctx.buffer(handles)
@@ -252,7 +257,7 @@ def __init__(self, scene, handles, curve, color=None):
252257
self._va_handles = ctx.vertex_array(shader, [(vb_handles, '3f4', 'v_position')])
253258
self._va_curve = ctx.vertex_array(shader, [(vb_curve, '3f4', 'v_position')], mode=mgl.LINE_STRIP)
254259

255-
shader = scene.share(shader_ident, shader_ident)
260+
shader = scene.share(load_shader_ident, load_shader_ident)
256261
self._va_ident = ctx.vertex_array(shader, [(vb_curve, '3f4', 'v_position')], mode=mgl.LINE_STRIP)
257262

258263
def stack(self, scene):
@@ -268,19 +273,19 @@ def _render(self, view):
268273
view.scene.context.point_size = 4
269274

270275
self._va_handles.program['layer'] = -2e-6
271-
self._va_handles.program['color'].write(self.color_handles if not self.selected else fvec4(settings.display['selection_color'],self.color_handles[3]))
276+
self._va_handles.program['color'].write(fvec4(highlight_color(self, self.color_handles), 0.5))
272277
self._va_handles.render(mgl.POINTS)
273278
self._va_handles.render(mgl.LINE_STRIP)
274279

275280
self._va_curve.program['layer'] = -1e-6
276-
self._va_curve.program['color'].write(self.color if not self.selected else fvec4(settings.display['selection_color'],self.color[3]))
281+
self._va_curve.program['color'].write(fvec4(highlight_color(self, self.color), 1))
277282
self._va_curve.render()
278283

279284
def _identify(self, view):
280-
self.shader_ident['ident'] = view.identstep(1)
281-
self.shader_ident['view'].write(view.uniforms['view'] * self.world)
282-
self.shader_ident['proj'].write(view.uniforms['proj'])
283-
self.va_ident.render()
285+
self._va_ident.program['ident'] = view.identstep(1)
286+
self._va_ident.program['view'].write(view.uniforms['view'] * self.world)
287+
self._va_ident.program['proj'].write(view.uniforms['proj'])
288+
self._va_ident.render()
284289

285290

286291
def digitfit(n):

madcad/settings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
'display_groups': True,
7272
'display_points': False,
7373
'display_wire': False,
74-
'display_grid': True,
7574
'display_annotations': True,
7675
'surface_shading': True,
7776
'kinematic_manipulation': 'joint',

madcad/shaders/solid.frag

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,18 @@ vec4 highlight(vec4 dst, vec4 src) {
4242
void main() {
4343
vec3 nsight = normalize(sight);
4444
vec3 nnormal = normalize(normal);
45-
float diffuse = max(0, dot(nsight, nnormal));
45+
float diffuse = dot(nsight, nnormal);
4646
vec3 tosky = -reflect(nsight, nnormal);
4747
vec3 refl = texture(reflectmap, skybox(tosky)).rgb;
4848

4949
// surface shading
5050
color = vec4(refl * refl_color + mix(min_color, max_color, diffuse), 1);
5151

52+
if (diffuse < 0) {
53+
diffuse = 0.6;
54+
color = vec4(min_color, 1);
55+
}
56+
5257
// highlighting
5358
float margin = 0.1; // control how close to the horizon is the color saturation
5459
float glow = min(margin*(1/max(0,(diffuse-margin)) -1), 1); // produce a glowy highlight

0 commit comments

Comments
 (0)