NozzleNode.py 1.8 KB

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