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