diff --git a/BuildVolume.py b/BuildVolume.py new file mode 100644 index 0000000000..40e5a5667d --- /dev/null +++ b/BuildVolume.py @@ -0,0 +1,73 @@ +from UM.Scene.SceneNode import SceneNode +from UM.Application import Application +from UM.Resources import Resources +from UM.Mesh.MeshData import MeshData + +class BuildVolume(SceneNode): + def __init__(self, parent = None): + super().__init__(parent) + + mesh = MeshData() + + #Front + mesh.addVertexWithNormal( 0.5, 0.5, 0.5, 0, 0, -1) + mesh.addVertexWithNormal(-0.5, -0.5, 0.5, 0, 0, -1) + mesh.addVertexWithNormal(-0.5, 0.5, 0.5, 0, 0, -1) + mesh.addVertexWithNormal( 0.5, 0.5, 0.5, 0, 0, -1) + mesh.addVertexWithNormal( 0.5, -0.5, 0.5, 0, 0, -1) + mesh.addVertexWithNormal(-0.5, -0.5, 0.5, 0, 0, -1) + + #Back + mesh.addVertexWithNormal( 0.5, 0.5, -0.5, 0, 0, 1) + mesh.addVertexWithNormal(-0.5, 0.5, -0.5, 0, 0, 1) + mesh.addVertexWithNormal(-0.5, -0.5, -0.5, 0, 0, 1) + mesh.addVertexWithNormal( 0.5, 0.5, -0.5, 0, 0, 1) + mesh.addVertexWithNormal(-0.5, -0.5, -0.5, 0, 0, 1) + mesh.addVertexWithNormal( 0.5, -0.5, -0.5, 0, 0, 1) + + #Left + mesh.addVertexWithNormal(-0.5, 0.5, 0.5, -1, 0, 0) + mesh.addVertexWithNormal(-0.5, -0.5, -0.5, -1, 0, 0) + mesh.addVertexWithNormal(-0.5, 0.5, -0.5, -1, 0, 0) + mesh.addVertexWithNormal(-0.5, 0.5, 0.5, -1, 0, 0) + mesh.addVertexWithNormal(-0.5, -0.5, 0.5, -1, 0, 0) + mesh.addVertexWithNormal(-0.5, -0.5, -0.5, -1, 0, 0) + + #Right + mesh.addVertexWithNormal( 0.5, 0.5, 0.5, 1, 0, 0) + mesh.addVertexWithNormal( 0.5, -0.5, -0.5, 1, 0, 0) + mesh.addVertexWithNormal( 0.5, -0.5, 0.5, 1, 0, 0) + mesh.addVertexWithNormal( 0.5, 0.5, 0.5, 1, 0, 0) + mesh.addVertexWithNormal( 0.5, 0.5, -0.5, 1, 0, 0) + mesh.addVertexWithNormal( 0.5, -0.5, -0.5, 1, 0, 0) + + #Top + mesh.addVertexWithNormal( 0.5, 0.5, 0.5, 0, -1, 0) + mesh.addVertexWithNormal(-0.5, 0.5, 0.5, 0, -1, 0) + mesh.addVertexWithNormal(-0.5, 0.5, -0.5, 0, -1, 0) + mesh.addVertexWithNormal( 0.5, 0.5, 0.5, 0, -1, 0) + mesh.addVertexWithNormal(-0.5, 0.5, -0.5, 0, -1, 0) + mesh.addVertexWithNormal( 0.5, 0.5, -0.5, 0, -1, 0) + + #Bottom + mesh.addVertexWithNormal( 0.5, -0.5, 0.5, 0, 1, 0) + mesh.addVertexWithNormal(-0.5, -0.5, -0.5, 0, 1, 0) + mesh.addVertexWithNormal(-0.5, -0.5, 0.5, 0, 1, 0) + mesh.addVertexWithNormal( 0.5, -0.5, 0.5, 0, 1, 0) + mesh.addVertexWithNormal( 0.5, -0.5, -0.5, 0, 1, 0) + mesh.addVertexWithNormal(-0.5, -0.5, -0.5, 0, 1, 0) + + self.setMeshData(mesh) + self._material = None + + def render(self, renderer): + if not self._material: + self._material = renderer.createMaterial( + Resources.getPath(Resources.ShadersLocation, 'basic.vert'), + Resources.getPath(Resources.ShadersLocation, 'color.frag') + ) + self._material.setUniformValue('u_color', [0.5, 0.5, 1.0, 0.5]) + + renderer.queueMesh(self.getMeshData(), self.getGlobalTransformation(), material = self._material, transparent = True) + return True + diff --git a/PrinterApplication.py b/PrinterApplication.py index 088dc0d458..2f9accb94a 100644 --- a/PrinterApplication.py +++ b/PrinterApplication.py @@ -10,6 +10,7 @@ from UM.Scene.BoxRenderer import BoxRenderer from UM.Scene.Selection import Selection from PlatformPhysics import PlatformPhysics +from BuildVolume import BuildVolume import os.path @@ -49,7 +50,11 @@ class PrinterApplication(QtApplication): root = controller.getScene().getRoot() platform = Platform(root) - self.getRenderer().setLightPosition(Vector(0, 150, 150)) + volume = BuildVolume(root) + volume.translate(Vector(0, 75.1, 0)) + volume.scale(150.0) + + self.getRenderer().setLightPosition(Vector(0, 150, 0)) camera = Camera('3d', root) camera.translate(Vector(0, 150, 150))