Add a BuildVolume node to render the build volume

This commit is contained in:
Arjen Hiemstra 2014-12-23 16:38:44 +01:00
parent e7a51b3bd8
commit c7cecb180d
2 changed files with 79 additions and 1 deletions

73
BuildVolume.py Normal file
View file

@ -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

View file

@ -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))