NozzleNode.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from UM.Application import Application
  4. from UM.Math.Color import Color
  5. from UM.PluginRegistry import PluginRegistry
  6. from UM.Scene.SceneNode import SceneNode
  7. from UM.View.GL.OpenGL import OpenGL
  8. from UM.Resources import Resources
  9. import os
  10. class NozzleNode(SceneNode):
  11. def __init__(self, parent = None):
  12. super().__init__(parent)
  13. self._shader = None
  14. self.setCalculateBoundingBox(False)
  15. self._createNozzleMesh()
  16. def _createNozzleMesh(self):
  17. mesh_file = "resources/nozzle.stl"
  18. try:
  19. path = os.path.join(PluginRegistry.getInstance().getPluginPath("SimulationView"), mesh_file)
  20. except FileNotFoundError:
  21. path = ""
  22. reader = Application.getInstance().getMeshFileHandler().getReaderForFile(path)
  23. node = reader.read(path)
  24. if node.getMeshData():
  25. self.setMeshData(node.getMeshData())
  26. def render(self, renderer):
  27. # Avoid to render if it is not visible
  28. if not self.isVisible():
  29. return False
  30. if not self._shader:
  31. # We now misuse the platform shader, as it actually supports textures
  32. self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "color.shader"))
  33. self._shader.setUniformValue("u_color", Color(*Application.getInstance().getTheme().getColor("layerview_nozzle").getRgb()))
  34. # Set the opacity to 0, so that the template is in full control.
  35. self._shader.setUniformValue("u_opacity", 0)
  36. if self.getMeshData():
  37. renderer.queueNode(self, shader = self._shader, transparent = True)
  38. return True