XRayPass.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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.Resources import Resources
  5. from UM.Application import Application
  6. from UM.PluginRegistry import PluginRegistry
  7. from UM.View.RenderPass import RenderPass
  8. from UM.View.RenderBatch import RenderBatch
  9. from UM.View.GL.OpenGL import OpenGL
  10. from cura.Scene.CuraSceneNode import CuraSceneNode
  11. from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
  12. class XRayPass(RenderPass):
  13. def __init__(self, width, height):
  14. super().__init__("xray", width, height)
  15. self._shader = None
  16. self._gl = OpenGL.getInstance().getBindingsObject()
  17. self._scene = Application.getInstance().getController().getScene()
  18. def render(self):
  19. if not self._shader:
  20. self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "xray.shader"))
  21. batch = RenderBatch(self._shader, type = RenderBatch.RenderType.NoType, backface_cull = False, blend_mode = RenderBatch.BlendMode.Additive)
  22. for node in DepthFirstIterator(self._scene.getRoot()):
  23. if isinstance(node, CuraSceneNode) and node.getMeshData() and node.isVisible():
  24. batch.addItem(node.getWorldTransformation(copy = False), node.getMeshData(), normal_transformation=node.getCachedNormalMatrix())
  25. self.bind()
  26. self._gl.glDisable(self._gl.GL_DEPTH_TEST)
  27. batch.render(self._scene.getActiveCamera())
  28. self._gl.glEnable(self._gl.GL_DEPTH_TEST)
  29. self.release()