Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to pass more options for meshes #83

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions madcad/displays.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,13 @@ def __init__(self, scene, box, color=None):

class SolidDisplay(Display):
''' Display render Meshes '''
def __init__(self, scene, positions, normals, faces, lines, idents, color=None):
def __init__(self, scene, positions, normals, faces, lines, idents, color=None, options:dict = None):
self.box = npboundingbox(positions)
self.options = scene.options

self.options = scene.options.copy()
self.options.update(options)
# if we can make backward-breaking changes, remove color as parameter, use instead:
# color = options["color"] if options is not None and "color" in options else None

s = settings.display
color = fvec3(color or s['solid_color'])
Expand Down
3 changes: 2 additions & 1 deletion madcad/mesh/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,8 @@ def display(self, scene):
typedlist_to_numpy(m.faces, 'u4'),
typedlist_to_numpy(edges, 'u4'),
typedlist_to_numpy(idents, 'u4'),
color = self.options.get('color'),
self.options.get('color'),
self.options,
)

def __repr__(self):
Expand Down
16 changes: 10 additions & 6 deletions madcad/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ class display:
# shared open gl context, None if not yet initialized
global_context = None

def qt_surface_format():
fmt = QSurfaceFormat()
fmt.setVersion(*opengl_version)
fmt.setProfile(QSurfaceFormat.OpenGLContextProfile.CoreProfile)
fmt.setSamples(4)
return fmt

def show(scene:dict, interest:Box=None, size=uvec2(400,400), projection=None, navigation=None, **options):
'''
Expand All @@ -90,6 +96,8 @@ def show(scene:dict, interest:Box=None, size=uvec2(400,400), projection=None, na
if 'options' in options: options.update(options['options'])
if not isinstance(scene, Scene): scene = Scene(scene, options)

QSurfaceFormat.setDefaultFormat(qt_surface_format())

app = QApplication.instance()
created = False
if not app:
Expand Down Expand Up @@ -764,7 +772,7 @@ def render(self):
# prepare the view uniforms
w, h = self.fb_screen.size
self.uniforms['view'] = view = self.navigation.matrix()
self.uniforms['proj'] = proj = self.projection.matrix(w/h, self.navigation.distance)
self.uniforms['proj'] = proj = self.projection.matrix(w/h if h > 0 else 0, self.navigation.distance)
self.uniforms['projview'] = proj * view
self.fresh.clear()

Expand Down Expand Up @@ -1020,11 +1028,7 @@ class View(ViewCommon, QOpenGLWidget):
def __init__(self, scene, projection=None, navigation=None, parent=None):
# super init
QOpenGLWidget.__init__(self, parent)
fmt = QSurfaceFormat()
fmt.setVersion(*opengl_version)
fmt.setProfile(QSurfaceFormat.CoreProfile)
fmt.setSamples(4)
self.setFormat(fmt)
self.setFormat(qt_surface_format())

# ugly trick to receive interaction events in a different function than QOpenGLWidget.event (that one is locking the GIL during the whole rendering, killing any possibility of having a computing thread aside)
# that event reception should be in the current widget ...
Expand Down