pyunity.render module

Classes to aid in rendering in a Scene.

pyunity.render.gen_buffers(mesh)[source]

Create buffers for a mesh.

Parameters:mesh (Mesh) – Mesh to create buffers for
Returns:Tuple containing a vertex buffer object and an index buffer object.
Return type:tuple
pyunity.render.gen_array()[source]

Generate a vertex array object.

Returns:A vertex buffer object of floats. Has 3 elements:
# vertex    # normal    # texcoord
x, y, z,    a, b, c,    u, v
Return type:Any
class pyunity.render.Shader(vertex, frag, name)[source]

Bases: object

compile()[source]

Compiles shader and generates program. Checks for errors.

Notes

This function will not work if there is no active framebuffer.

static fromFolder(path, name)[source]

Create a Shader from a folder. It must contain vertex.glsl and fragment.glsl.

Parameters:
  • path (str) – Path of folder to load
  • name (str) – Name to register this shader to. Used with Camera.SetShader.
setVec3(var, val)[source]

Set a vec3 uniform variable.

Parameters:
  • var (bytes) – Variable name
  • val (Any) – Value of uniform variable
setMat4(var, val)[source]

Set a mat4 uniform variable.

Parameters:
  • var (bytes) – Variable name
  • val (Any) – Value of uniform variable
setInt(var, val)[source]

Set an int uniform variable.

Parameters:
  • var (bytes) – Variable name
  • val (Any) – Value of uniform variable
setFloat(var, val)[source]

Set a float uniform variable.

Parameters:
  • var (bytes) – Variable name
  • val (Any) – Value of uniform variable
use()[source]

Compile shader if it isn’t compiled, and load it into OpenGL.

pyunity.render.compile_shaders()[source]
class pyunity.render.Camera(transform)[source]

Bases: pyunity.core.SingleComponent

Component to hold data about the camera in a scene.

near

Distance of the near plane in the camera frustrum. Defaults to 0.05.

Type:float
far

Distance of the far plane in the camera frustrum. Defaults to 100.

Type:float
clearColor

The clear color of the camera. Defaults to (0, 0, 0).

Type:RGB
setup_buffers()[source]

Creates 2D quad VBO and VAO for GUI.

fov

FOV of camera

orthoSize
Resize(width, height)[source]

Resizes the viewport on screen size change.

Parameters:
  • width (int) – Width of new window
  • height (int) – Height of new window
getMatrix(transform)[source]

Generates model matrix from transform.

get2DMatrix(rectTransform)[source]

Generates model matrix from RectTransform.

getViewMat()[source]

Generates view matrix from Transform of camera.

UseShader(name)[source]

Sets current shader from name.

Render(renderers, lights)[source]

Render specific renderers, taking into account light positions.

Parameters:
  • renderers (List[MeshRenderer]) – Which meshes to render
  • lights (List[Light]) – Lights to load into shader
Render2D(canvases)[source]

Render all Image2D and Text components in specified canvases.

Parameters:canvases (List[Canvas]) – Canvases to process. All processed GameObjects are cached to prevent duplicate rendering.
class pyunity.render.Screen[source]

Bases: object