mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Speed up the rendering of the solid view by caching support_angle property
This commit is contained in:
parent
9daa78a98f
commit
50ad4e4d4e
2 changed files with 40 additions and 13 deletions
|
@ -1,4 +1,4 @@
|
|||
# Copyright (c) 2015 Ultimaker B.V.
|
||||
# Copyright (c) 2019 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
from UM.View.View import View
|
||||
|
@ -7,7 +7,6 @@ from UM.Scene.Selection import Selection
|
|||
from UM.Resources import Resources
|
||||
from UM.Application import Application
|
||||
from UM.View.RenderBatch import RenderBatch
|
||||
from UM.Settings.Validator import ValidatorState
|
||||
from UM.Math.Color import Color
|
||||
from UM.View.GL.OpenGL import OpenGL
|
||||
|
||||
|
@ -20,9 +19,9 @@ import math
|
|||
class SolidView(View):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
Application.getInstance().getPreferences().addPreference("view/show_overhang", True)
|
||||
|
||||
application = Application.getInstance()
|
||||
application.getPreferences().addPreference("view/show_overhang", True)
|
||||
application.globalContainerStackChanged.connect(self._onGlobalContainerChanged)
|
||||
self._enabled_shader = None
|
||||
self._disabled_shader = None
|
||||
self._non_printing_shader = None
|
||||
|
@ -30,6 +29,38 @@ class SolidView(View):
|
|||
|
||||
self._extruders_model = None
|
||||
self._theme = None
|
||||
self._support_angle = 90
|
||||
|
||||
self._global_stack = None
|
||||
|
||||
Application.getInstance().engineCreatedSignal.connect(self._onGlobalContainerChanged)
|
||||
|
||||
def _onGlobalContainerChanged(self) -> None:
|
||||
if self._global_stack:
|
||||
try:
|
||||
self._global_stack.propertyChanged.disconnect(self._onPropertyChanged)
|
||||
except TypeError:
|
||||
pass
|
||||
for extruder_stack in ExtruderManager.getInstance().getActiveExtruderStacks():
|
||||
extruder_stack.propertyChanged.disconnect(self._onPropertyChanged)
|
||||
|
||||
self._global_stack = Application.getInstance().getGlobalContainerStack()
|
||||
if self._global_stack:
|
||||
self._global_stack.propertyChanged.connect(self._onPropertyChanged)
|
||||
for extruder_stack in ExtruderManager.getInstance().getActiveExtruderStacks():
|
||||
extruder_stack.propertyChanged.connect(self._onPropertyChanged)
|
||||
self._onPropertyChanged("support_angle", "value") # Force an re-evaluation
|
||||
|
||||
def _onPropertyChanged(self, key: str, property_name: str) -> None:
|
||||
if key != "support_angle" or property_name != "value":
|
||||
return
|
||||
# As the rendering is called a *lot* we really, dont want to re-evaluate the property every time. So we store em!
|
||||
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||
if global_container_stack:
|
||||
support_extruder_nr = global_container_stack.getExtruderPositionValueWithDefault("support_extruder_nr")
|
||||
support_angle_stack = Application.getInstance().getExtruderManager().getExtruderStack(support_extruder_nr)
|
||||
if support_angle_stack:
|
||||
self._support_angle = support_angle_stack.getProperty("support_angle", "value")
|
||||
|
||||
def beginRendering(self):
|
||||
scene = self.getController().getScene()
|
||||
|
@ -63,14 +94,10 @@ class SolidView(View):
|
|||
|
||||
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||
if global_container_stack:
|
||||
support_extruder_nr = global_container_stack.getExtruderPositionValueWithDefault("support_extruder_nr")
|
||||
support_angle_stack = Application.getInstance().getExtruderManager().getExtruderStack(support_extruder_nr)
|
||||
|
||||
if support_angle_stack is not None and Application.getInstance().getPreferences().getValue("view/show_overhang"):
|
||||
angle = support_angle_stack.getProperty("support_angle", "value")
|
||||
if Application.getInstance().getPreferences().getValue("view/show_overhang"):
|
||||
# Make sure the overhang angle is valid before passing it to the shader
|
||||
if angle is not None and angle >= 0 and angle <= 90:
|
||||
self._enabled_shader.setUniformValue("u_overhangAngle", math.cos(math.radians(90 - angle)))
|
||||
if self._support_angle is not None and self._support_angle >= 0 and self._support_angle <= 90:
|
||||
self._enabled_shader.setUniformValue("u_overhangAngle", math.cos(math.radians(90 - self._support_angle)))
|
||||
else:
|
||||
self._enabled_shader.setUniformValue("u_overhangAngle", math.cos(math.radians(0))) #Overhang angle of 0 causes no area at all to be marked as overhang.
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue