XRayPass.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import os.path
  4. from UM.Application import Application
  5. from UM.PluginRegistry import PluginRegistry
  6. from UM.View.RenderPass import RenderPass
  7. from UM.View.RenderBatch import RenderBatch
  8. from UM.View.GL.OpenGL import OpenGL
  9. from cura.Scene.CuraSceneNode import CuraSceneNode
  10. from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
  11. class XRayPass(RenderPass):
  12. def __init__(self, width, height):
  13. super().__init__("xray", width, height)
  14. self._shader = None
  15. self._gl = OpenGL.getInstance().getBindingsObject()
  16. self._scene = Application.getInstance().getController().getScene()
  17. def render(self):
  18. if not self._shader:
  19. self._shader = OpenGL.getInstance().createShaderProgram(os.path.join(PluginRegistry.getInstance().getPluginPath("XRayView"), "xray.shader"))
  20. batch = RenderBatch(self._shader, type = RenderBatch.RenderType.NoType, backface_cull = False, blend_mode = RenderBatch.BlendMode.Additive)
  21. for node in DepthFirstIterator(self._scene.getRoot()):
  22. if isinstance(node, CuraSceneNode) and node.getMeshData() and node.isVisible():
  23. batch.addItem(node.getWorldTransformation(), node.getMeshData())
  24. self.bind()
  25. self._gl.glDisable(self._gl.GL_DEPTH_TEST)
  26. batch.render(self._scene.getActiveCamera())
  27. self._gl.glEnable(self._gl.GL_DEPTH_TEST)
  28. self.release()