Merge pull request #7373 from fieldOfView/fix_xray_in_solid_view into my PR

Fix xray in solid view
This commit is contained in:
Tim Kuipers 2020-03-31 11:51:23 +02:00 committed by GitHub
commit 2a1423d7b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 20 deletions

View file

@ -25,8 +25,6 @@ from UM.View.GL.OpenGL import OpenGL
from UM.i18n import i18nCatalog
from cura.CuraApplication import CuraApplication
from cura.Settings.ExtruderManager import ExtruderManager
from cura import XRayPass
@ -69,14 +67,14 @@ class SolidView(View):
self._next_xray_checking_time = time.time()
self._xray_checking_update_time = 1.0 # seconds
self._xray_warning_cooldown = 60 * 10 # reshow Model error message every 10 minutes
self._xray_warning_message = Message(catalog.i18nc("@info:status", "Your model is not manifold. The highlighted areas indicate either missing or extraneous surfaces.")
, lifetime = 60 * 5 # leave message for 5 minutes
, title = catalog.i18nc("@info:title", "Model errors"),
option_text = catalog.i18nc("@info:option_text", "Do not show this message again"), option_state = False)
self._xray_warning_message.optionToggled.connect(self._onDontAskMeAgain)
CuraApplication.getInstance().getPreferences().addPreference(self._show_xray_warning_preference, True)
self._xray_warning_message = Message(
catalog.i18nc("@info:status", "Your model is not manifold. The highlighted areas indicate either missing or extraneous surfaces."),
lifetime = 60 * 5, # leave message for 5 minutes
title = catalog.i18nc("@info:title", "Model errors"),
)
application.getPreferences().addPreference(self._show_xray_warning_preference, True)
Application.getInstance().engineCreatedSignal.connect(self._onGlobalContainerChanged)
application.engineCreatedSignal.connect(self._onGlobalContainerChanged)
def _onGlobalContainerChanged(self) -> None:
if self._global_stack:
@ -135,7 +133,7 @@ class SolidView(View):
self._support_mesh_shader.setUniformValue("u_vertical_stripes", True)
self._support_mesh_shader.setUniformValue("u_width", 5.0)
if not CuraApplication.getInstance().getPreferences().getValue(self._show_xray_warning_preference):
if not Application.getInstance().getPreferences().getValue(self._show_xray_warning_preference):
self._xray_error_image = None
self._xray_shader = None
self._xray_composite_shader = None
@ -270,7 +268,7 @@ class SolidView(View):
def endRendering(self):
# check whether the xray overlay is showing badness
if time.time() > self._next_xray_checking_time\
and CuraApplication.getInstance().getPreferences().getValue(self._show_xray_warning_preference):
and Application.getInstance().getPreferences().getValue(self._show_xray_warning_preference):
self._next_xray_checking_time = time.time() + self._xray_checking_update_time
xray_img = self._xray_pass.getOutput()
@ -304,9 +302,6 @@ class SolidView(View):
self._xray_warning_message.show()
Logger.log("i", "X-Ray overlay found non-manifold pixels.")
def _onDontAskMeAgain(self, checked: bool) -> None:
CuraApplication.getInstance().getPreferences().setValue(self._show_xray_warning_preference, not checked)
def event(self, event):
if event.type == Event.ViewActivateEvent:
# FIX: on Max OS X, somehow QOpenGLContext.currentContext() can become None during View switching.
@ -323,7 +318,7 @@ class SolidView(View):
if Platform.isOSX():
if QOpenGLContext.currentContext() is None:
Logger.log("d", "current context of OpenGL is empty on Mac OS X, will try to create shaders later")
CuraApplication.getInstance().callLater(lambda e = event: self.event(e))
Application.getInstance().callLater(lambda e = event: self.event(e))
return

View file

@ -86,8 +86,10 @@ UM.PreferencesPage
prefixJobNameCheckbox.checked = boolCheck(UM.Preferences.getValue("cura/jobname_prefix"))
UM.Preferences.resetPreference("view/show_overhang");
showOverhangCheckbox.checked = boolCheck(UM.Preferences.getValue("view/show_overhang"))
UM.Preferences.resetPreference("view/show_xray_error");
showXrayErrorCheckbox.checked = boolCheck(UM.Preferences.getValue("view/show_xray_error"))
UM.Preferences.resetPreference("view/show_xray_warning");
showXrayErrorCheckbox.checked = boolCheck(UM.Preferences.getValue("view/show_warning"))
UM.Preferences.resetPreference("view/show_xray_warning_message");
showXrayErrorMessageCheckbox.checked = boolCheck(UM.Preferences.getValue("view/show_warning_message"))
UM.Preferences.resetPreference("view/center_on_select");
centerOnSelectCheckbox.checked = boolCheck(UM.Preferences.getValue("view/center_on_select"))
UM.Preferences.resetPreference("view/invert_zoom");
@ -358,6 +360,24 @@ UM.PreferencesPage
}
}
UM.TooltipArea
{
width: childrenRect.width;
height: childrenRect.height;
text: catalog.i18nc("@info:tooltip", "Highlight missing or extraneous surfaces of the model using warning signs. The toolpaths will often be missing parts of the intended geometry.")
CheckBox
{
id: showXrayErrorMessageCheckbox
checked: boolCheck(UM.Preferences.getValue("view/show_xray_warning_message"))
onClicked: UM.Preferences.setValue("view/show_xray_warning_message", checked)
text: catalog.i18nc("@option:check", "Display model errors");
}
}
UM.TooltipArea
{
width: childrenRect.width;

View file

@ -12,6 +12,13 @@ vertex =
}
fragment =
#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif // GL_FRAGMENT_PRECISION_HIGH
#endif // GL_ES
uniform vec4 u_color;
void main()

View file

@ -52,11 +52,11 @@ fragment =
result = layer0 * layer0.a + result * (1.0 - layer0.a);
float intersection_count = texture2D(u_layer2, v_uvs).r * 51; // (1 / .02) + 1 (+1 magically fixes issues with high intersection count models)
float intersection_count = texture2D(u_layer2, v_uvs).r * 51.0; // (1 / .02) + 1 (+1 magically fixes issues with high intersection count models)
float rest = mod(intersection_count + .01, 2.0);
if (rest > 1.0 && rest < 1.5 && intersection_count < 49)
if (rest > 1.0 && rest < 1.5 && intersection_count < 49.0)
{
result = result * (1.0 - u_xray_error_strength) + u_xray_error_strength * texture(u_xray_error, v_uvs * u_xray_error_scale);
result = result * (1.0 - u_xray_error_strength) + u_xray_error_strength * texture2D(u_xray_error, v_uvs * u_xray_error_scale);
}
vec4 sum = vec4(0.0);