psychopy.tools.gltools.createBox

psychopy.tools.gltools.createBox(size=(1.0, 1.0, 1.0), flipFaces=False)[source]

Create a box mesh.

Create a box mesh by specifying its size in three dimensions (x, y, z), or a single value (float) to create a cube. The resulting box will be centered about the origin. Texture coordinates and normals are automatically generated for each face.

Setting flipFaces=True will make faces and normals point inwards, this allows boxes to be viewed and lit correctly from the inside.

Parameters:
  • size (tuple or float) – Dimensions of the mesh. If a single value is specified, the box will be a cube. Provide a tuple of floats to specify the width, length, and height of the box (eg. size=(0.2, 1.3, 2.1)).

  • flipFaces (bool, optional) – If True, normals and face windings will be set to point inward towards the center of the box. Texture coordinates will remain the same. Default is False.

Returns:

Vertex attribute arrays (position, texture coordinates, and normals) and triangle indices.

Return type:

tuple

Examples

Create a box mesh and draw it:

vertices, textureCoords, normals, faces = gltools.createBox()

vertexVBO = gltools.createVBO(vertices)
texCoordVBO = gltools.createVBO(textureCoords)
normalsVBO = gltools.createVBO(normals)
indexBuffer = gltools.createVBO(
    faces.flatten(),
    target=GL.GL_ELEMENT_ARRAY_BUFFER,
    dataType=GL.GL_UNSIGNED_INT)

vao = gltools.createVAO({0: vertexVBO, 8: texCoordVBO, 2: normalsVBO},
    indexBuffer=indexBuffer)

# in the rendering loop
gltools.drawVAO(vao, GL.GL_TRIANGLES)

Back to top