API Documentation

Module contents

class Camera(fov_y=60.0, aspect=1.778, z_near=0.01, z_far=4.5, x_shift=0.0, y_shift=0.0, ortho_mode=False, **kwargs)

Bases: fruitloop.mixins.PhysicalNode, fruitloop.mixins.Picklable

A convenient object for controlling the scene viewing angle.

Returns a Camera instance, which determines the world-to-screen perspective transformation.

Parameters:
  • fov_y (float) – vertical field of view (degrees)
  • aspect (float) – screen width/height
  • z_near (float) – near clipping distance
  • z_far (float) – far clipping distance
  • x_shift (float) – horizontal lens shift
  • y_shift (float) – vertical lens shift
  • ortho_mode (bool) – Whether to use orthographic projection instead of perpective projection.
Returns:

Camera instance

reset_aspect()

Gets the viewport size, and matches the camera aspect ratio to it.

update()
class Mesh(name, meshdata, uniforms=UniformCollection: {}, drawstyle='fill', visible=True, point_size=4, texture=None, **kwargs)

Bases: fruitloop.mesh.EmptyMesh, fruitloop.mixins.Picklable

Returns a Mesh object, containing the position, rotation, and color info of an OpenGL Mesh.

Meshes have two coordinate system, the “local” and “world” systems, on which the transforms are performed sequentially. This allows them to be placed in the scene while maintaining a relative position to one another.

Note

Meshes are not usually instantiated directly, but from a 3D file, like the WavefrontReader .obj and .mtl files.

Parameters:
  • name (str) – the mesh’s name.
  • vertices – the Nx3 vertex coordinate data
  • normals – the Nx3 normal coordinate data
  • texcoords – the Nx2 texture coordinate data
  • uniforms (list) – a list of all Uniform objects
  • drawstyle (str) – ‘point’: only vertices, ‘line’: points and edges, ‘fill’: points, edges, and faces (full)
  • visible (bool) – whether the Mesh is available to be rendered. To make hidden (invisible), set to False.
  • point_size (int) – How big to draw the points, when drawstyle is ‘point’
Returns:

Mesh instance

drawstyle = {'line': <Mock id='140636315391376'>, 'point': <Mock id='140636315391504'>, 'fill': <Mock id='140636315391248'>}
update()
class MeshData(vertices, face_indices, normals, texcoords=None)

Bases: object

Collects all vertex data for rendering in 3D graphics packages.

Parameters:
  • vertices (list) – Nx3 vertex array
  • face_indices (list) – Nx3 Face index array (0-indexed)
  • normals (list) – Nx3 normals array
  • texture_uv (list) – Nx2 texture_uv array
Returns:

MeshData object

draw(mode)
load()
reindex()
class Material(diffuse=[0.8, 0.8, 0.8], spec_weight=0.0, specular=[0.0, 0.0, 0.0], ambient=[0.0, 0.0, 0.0], opacity=1.0, flat_shading=False, texture_file=None)

Bases: object

class Physical(position=(0.0, 0.0, 0.0), rotation=(0.0, 0.0, 0.0), scale=1.0, *args, **kwargs)

Bases: object

XYZ Position, Scale and XYZEuler Rotation Class.

Parameters:
  • position (list) – (x, y, z) translation values.
  • rotation (list) – (x, y, z) rotation values
  • scale (float) – uniform scale factor. 1 = no scaling.
has_changed()
on_change()

This method fires when object position or geometry changes. Can be overwritten by parent classes to add more actions.

position

xyz local position

rotation

XYZ Euler rotation, in degrees

update()

Calculate model, normal, and view matrices from position, rotation, and scale data.

update_model_and_normal_matrix()
update_model_matrix()
update_view_matrix()
class Scene(meshes=(), camera=None, light=None, bgColor=(0.4, 0.4, 0.4))

Bases: object

Returns a Scene object. Scenes manage rendering of Meshes, Lights, and Cameras.

clear()

Clear Screen and Apply Background Color

draw(shader=<fruitloop.shader.Shader object>, clear=True, send_mesh_uniforms=True, send_camera_uniforms=True, send_light_uniforms=True, userdata={}, gl_states=(<Mock id='140636315417936'>, <Mock id='140636315418064'>, <Mock id='140636315418192'>, <Mock id='140636315418320'>))

Draw each visible mesh in the scene from the perspective of the scene’s camera and lit by its light.

draw360_to_texture(cubetexture, shader=<fruitloop.shader.Shader object>, autoclear=True, userdata={}, gl_states=(<Mock id='140636315418448'>, <Mock id='140636315418576'>, <Mock id='140636315054224'>, <Mock id='140636315054352'>))

Draw each visible mesh in the scene from the perspective of the scene’s camera and lit by its light, and applies it to each face of cubetexture, which should be currently bound to an FBO.

class WavefrontReader(file_name)

Bases: object

Reads Wavefront (.obj) files created in Blender to build fruitloop.graphics Mesh objects.

Parameters:file_name (str) – .obj file to read (assumes an accompanying .mtl file has the same base file name.)
Returns:
Return type:WavefrontReader
get_mesh(mesh_name, **kwargs)

Returns a Mesh object for directly rendering in a scene.

Parameters:
  • mesh_name
  • kwargs – All of Mesh’s keword arguments will be applied to the Mesh, for convenient Mesh creation.
Returns:

Mesh

Return type:

Mesh

get_meshes(mesh_names, **kwargs)

Returns a dictionary of meshes, with kwargs applied to all meshes identically, as in get_mesh()

get_scene(include=[], exclude=[])

Return a Scene object containing the Meshes in the file.

Parameters:
  • include (list) – mesh names to only include.
  • exclude (list) – mesh names to exclude.
Returns:

Scene

Submodules

fruitloop.mesh module

mesh

This module contains the Mesh, MeshData, and Material classes. This documentation was auto-generated from the mesh.py file.

class EmptyMesh(*args, **kwargs)

Bases: fruitloop.mixins.PhysicalNode

class Material(diffuse=[0.8, 0.8, 0.8], spec_weight=0.0, specular=[0.0, 0.0, 0.0], ambient=[0.0, 0.0, 0.0], opacity=1.0, flat_shading=False, texture_file=None)

Bases: object

class Mesh(name, meshdata, uniforms=UniformCollection: {}, drawstyle='fill', visible=True, point_size=4, texture=None, **kwargs)

Bases: fruitloop.mesh.EmptyMesh, fruitloop.mixins.Picklable

Returns a Mesh object, containing the position, rotation, and color info of an OpenGL Mesh.

Meshes have two coordinate system, the “local” and “world” systems, on which the transforms are performed sequentially. This allows them to be placed in the scene while maintaining a relative position to one another.

Note

Meshes are not usually instantiated directly, but from a 3D file, like the WavefrontReader .obj and .mtl files.

Parameters:
  • name (str) – the mesh’s name.
  • vertices – the Nx3 vertex coordinate data
  • normals – the Nx3 normal coordinate data
  • texcoords – the Nx2 texture coordinate data
  • uniforms (list) – a list of all Uniform objects
  • drawstyle (str) – ‘point’: only vertices, ‘line’: points and edges, ‘fill’: points, edges, and faces (full)
  • visible (bool) – whether the Mesh is available to be rendered. To make hidden (invisible), set to False.
  • point_size (int) – How big to draw the points, when drawstyle is ‘point’
Returns:

Mesh instance

drawstyle = {'line': <Mock id='140636315391376'>, 'point': <Mock id='140636315391504'>, 'fill': <Mock id='140636315391248'>}
texture = None

Pyglet texture object for mapping an image file to the vertices (set using Mesh.load_texture())

uniforms = None

Physical, World Mesh coordinates Local Mesh coordinates (Physical type)

update()
visible = None

Bool – if the Mesh is visible for rendering. If false, will not be rendered.

class MeshData(vertices, face_indices, normals, texcoords=None)

Bases: object

Collects all vertex data for rendering in 3D graphics packages.

Parameters:
  • vertices (list) – Nx3 vertex array
  • face_indices (list) – Nx3 Face index array (0-indexed)
  • normals (list) – Nx3 normals array
  • texture_uv (list) – Nx2 texture_uv array
Returns:

MeshData object

draw(mode)
load()
reindex()
class MeshLoader(name, meshdata, material=None)

Bases: object

Creates various types of Meshes from MeshData and Material objects.

load_mesh(**kwargs)

fruitloop.mixins module

class Physical(position=(0.0, 0.0, 0.0), rotation=(0.0, 0.0, 0.0), scale=1.0, *args, **kwargs)

Bases: object

XYZ Position, Scale and XYZEuler Rotation Class.

Parameters:
  • position (list) – (x, y, z) translation values.
  • rotation (list) – (x, y, z) rotation values
  • scale (float) – uniform scale factor. 1 = no scaling.
has_changed()
on_change()

This method fires when object position or geometry changes. Can be overwritten by parent classes to add more actions.

position

xyz local position

rotation

XYZ Euler rotation, in degrees

update()

Calculate model, normal, and view matrices from position, rotation, and scale data.

update_model_and_normal_matrix()
update_model_matrix()
update_view_matrix()
class PhysicalNode(*args, **kwargs)

Bases: fruitloop.mixins.Physical, fruitloop.mixins.SceneNode

Object with xyz position and rotation properties that are relative to its parent.

position_global
update()
class Picklable

Bases: object

classmethod load(filename)

Load the object from a pickle file.

save(filename)

Save the object to a file. Will be Pickled in the process, but can be loaded easily with Class.load()

class SceneNode(parent=None, children=None)

Bases: object

A Node of the Scenegraph. Has children, but no parent.

add_children(children=[])

Adds a list of objects as children in the scene graph.

children
parent

A SceneNode object that is this object’s parent in the scene graph.

remove_children(children)

fruitloop.resources module

gen_fullscreen_quad()

fruitloop.scene module

class Scene(meshes=(), camera=None, light=None, bgColor=(0.4, 0.4, 0.4))

Bases: object

Returns a Scene object. Scenes manage rendering of Meshes, Lights, and Cameras.

clear()

Clear Screen and Apply Background Color

draw(shader=<fruitloop.shader.Shader object>, clear=True, send_mesh_uniforms=True, send_camera_uniforms=True, send_light_uniforms=True, userdata={}, gl_states=(<Mock id='140636315417936'>, <Mock id='140636315418064'>, <Mock id='140636315418192'>, <Mock id='140636315418320'>))

Draw each visible mesh in the scene from the perspective of the scene’s camera and lit by its light.

draw360_to_texture(cubetexture, shader=<fruitloop.shader.Shader object>, autoclear=True, userdata={}, gl_states=(<Mock id='140636315418448'>, <Mock id='140636315418576'>, <Mock id='140636315054224'>, <Mock id='140636315054352'>))

Draw each visible mesh in the scene from the perspective of the scene’s camera and lit by its light, and applies it to each face of cubetexture, which should be currently bound to an FBO.

fruitloop.shader module

class Shader(vert='', frag='', geom='')

Bases: fruitloop.utils.gl.BindingContextMixin, fruitloop.utils.gl.BindNoTargetMixin

GLSL Shader program object for rendering in OpenGL.

Parameters:
  • vert (-) – The vertex shader program string
  • frag (-) – The fragment shader program string
  • geom (-) – The geometry shader program
bindfun
createShader(strings, shadertype)
get_uniform_location(name)

link the program

uniform_matrixf(name, mat, loc=None)

Send 4x4 NumPy matrix data as a uniform to the shader, named ‘name’. Shader must be already bound.

uniformf(name, *vals)

Send data as a float uniform, named ‘name’. Shader must be already bound.

uniformf_funs = (<Mock id='140636315303440'>, <Mock id='140636315303568'>, <Mock id='140636315303696'>, <Mock id='140636315303824'>)
uniformi(name, *vals)

Send data as an integer uniform, named ‘name’. Shader must be already bound.

uniformi_funs = (<Mock id='140636315279440'>, <Mock id='140636315279568'>, <Mock id='140636315279696'>, <Mock id='140636315279824'>)
class Uniform(name, *vals)

Bases: object

A fixed-length, fixed-type array with a pre-assigned glUniform function for quick shader data sending.

classmethod from_dict(data_dict)

A factory function that can build multiple uniforms from a name: val dictionary

send_to(shader)

Sends uniform to a currently-bound shader, returning its location (-1 means not sent)

value
class UniformCollection(uniform_dict={})

Bases: object

send_to(shader)

fruitloop.texture module

class BaseTexture

Bases: object

cube_name = 'CubeMap'
int_flag = 0
tex_name = 'TextureMap'
class DepthTexture(id=None, width=1024, height=1024, data=None)

Bases: fruitloop.texture.Texture

2D Color Texture class. Width and height can be set, and will generate a new OpenGL texture if no id is given.

attachment_point
internal_fmt
pixel_fmt
class GrayscaleTexture(id=None, width=1024, height=1024, data=None)

Bases: fruitloop.texture.Texture

2D Color Texture class. Width and height can be set, and will generate a new OpenGL texture if no id is given.

internal_fmt
pixel_fmt
class GrayscaleTextureCube(*args, **kwargs)

Bases: fruitloop.texture.TextureCube

the Color Cube Texture class.

internal_fmt
pixel_fmt
class RenderBuffer(width, height)

Bases: fruitloop.utils.gl.BindingContextMixin, fruitloop.utils.gl.BindTargetMixin

attach_to_fbo()
attachment_point
bindfun
internal_fmt
target
class Texture(id=None, width=1024, height=1024, data=None)

Bases: fruitloop.texture.BaseTexture, fruitloop.utils.gl.BindTargetMixin

2D Color Texture class. Width and height can be set, and will generate a new OpenGL texture if no id is given.

attach_to_fbo()

Attach the texture to a bound FBO object, for rendering to texture.

attachment_point
bindfun
classmethod from_image(img_filename, **kwargs)

Uses Pyglet’s image.load function to generate a Texture from an image file.

int_flag = 1
internal_fmt
pixel_fmt
slot

The texture’s ActiveTexture slot.

target
target0
class TextureCube(*args, **kwargs)

Bases: fruitloop.texture.Texture

the Color Cube Texture class.

attach_to_fbo(face=0)
classmethod from_image(img_filename)
int_flag = 2
target
target0

fruitloop.wavefront module

class WavefrontReader(file_name)

Bases: object

Reads Wavefront (.obj) files created in Blender to build fruitloop.graphics Mesh objects.

Parameters:file_name (str) – .obj file to read (assumes an accompanying .mtl file has the same base file name.)
Returns:
Return type:WavefrontReader
get_mesh(mesh_name, **kwargs)

Returns a Mesh object for directly rendering in a scene.

Parameters:
  • mesh_name
  • kwargs – All of Mesh’s keword arguments will be applied to the Mesh, for convenient Mesh creation.
Returns:

Mesh

Return type:

Mesh

get_meshes(mesh_names, **kwargs)

Returns a dictionary of meshes, with kwargs applied to all meshes identically, as in get_mesh()

get_scene(include=[], exclude=[])

Return a Scene object containing the Meshes in the file.

Parameters:
  • include (list) – mesh names to only include.
  • exclude (list) – mesh names to exclude.
Returns:

Scene