This document is for OpenStructure version 1.1, the latest version is 2.8 !

The Scene

The scene is the central registry for graphical objects and manages rendering parameters. Among other parameters, it is used to setup the lighting, fog, background color and the position and viewing direction of the user. The scene is a singleton, meaning that there is only one scene available. The instance can be accessed via gfx.Scene(). Because the scene is so important and commonly used, the scene is also available as the scene variable in the interactive python shell as well as from scripts.

Manipulating the Camera

The users position and orientation in the scene is specified by the camera. The camera is represented by a center, a rotation and an offset from the center. These 3 attributes can be set independently. Manipulation of the camera is done by assigning a new Transform to the Scene.transform attribute.

Orbiting around a Point

The following code example will let the camera orbit around the center of the camera.

# tweakable parameters:
#  - axis of rotation
#  - angular step size. Making it bigger speeds up the rotation
#  - number of frames
axis=geom.Vec3(0, 1, 0)
step_size=0.01
num_frames=100

angle=0.0
for i in range(num_frames):
  angle+=step_size
  if angle>math.pi*2:
    angle-=math.pi*2
  camera=scene.transform
  rot=geom.AxisRotation(axis, angle)
  camera.SetRot(rot)
  camera.SetTrans(geom.Vec3(25.0, 0.0, -50))
  scene.transform=camera
  scene.Export('frame-%03d.png' % i, 500, 500)

It is interesting to note that the offset from center (trans) is given in rotated coordinates. Transforming along z shifts the camera along the viewing direction. Setting x and y to non-zero causes the center of the camera not to be projected onto the center of the screen any longer. For example, setting the value trans to geom.Vec3(50, 0, 0) gives a viewing direction perpendicular to the vector from the camera position to the center.

class ost.gfx.Scene
background

The background color of the scene. By default the background color is transparent black.

Type :Color
center

The center of the scene. Read-write. Changing the center affects the orientation of the camera, but not its position. To change the camera position, use transform. Also available as GetCenter()/SetCenter().

See also CenterOn().

Type :Vec3
transform

The camera transformation. Read-write. For an example usage see Orbiting around a Point. Also available as GetTransform()/SetTransform().

Type :Transform
fov

The field of view angle (in degrees) in vertical direction. Read-write. Also available as GetFOV()/SetFOV().

Type :float.
Add(obj[, replace_existing])

Add an object to the root node of the scene. This means that

  • The object will be rendered on the screen.
  • The object’s bounding box affects the slabbing operations.
Parameters:
  • obj (GfxNode) – The object to be added.
  • replace_existing (bool) – If true, existing objects of the same name are silently replaced. If false (the default), trying to add an object with an existing name will raise a RuntimeError.
AttachObserver(obs)

Attach a scene observer. The new scene observer will get notified when the scene’s state changes or objects get updated.

Parameters:obs (SceneObserver) –
AutoAutoslab(flag)

Enable/disable autoslabbing. If autoslabbing is enabled, the near and far clipping planes will automatically be adjusted to contain all the objects in the scene. This calculation is done before every redraw. Note that, autoslabbing is not rotation invariant. See AutoslabMax() for a rotation-invariant version.

Parameters:flag (bool) –
Autoslab(fast[, force])

Note

This method looks stale. Remove it?

Parameters:
  • fast (bool) –
  • force (bool) –
AutoslabMax()

Adjust the near and far clipping planes in such a way that they contain the bounding sphere of all the objects in the scene. In constrast to AutoSlab() the near/far clipping planes calculated with AutoslabMax() are invariant to rotation.

CenterOn(obj)

Center the camera on the center of the obj. This does not update offset and rotation of the camera. However, since the offset and rotation are applied after the centering, the position and viewing direction are affected by the change of center.

Parameters:obj (str, or GfxNode) – Object, or name of the object
Export(filename, width, height[, transparent])
Export(filename[, transparent])

Renders (exports) the scene into a PNG image.

Parameters:
  • filename (str) – The output filename
  • width (int) – The width of the image. Defaults to the width of the OpenGL window
  • height (int) – The height of the image. Defaults to the height of the OpenGL window.
  • transparent (bool) – If true, and the background color of the scene is transparent, will produce a transparent image. If false, the alpha component will be set to opaque.
ExportPov(filename[, working_dir])

Export the scene to POV-Ray format. The export will generate two files, one containing a general description of the scene, including camera position and materials and a second containing the geometric description of the objects. The first file will be named filename.pov, the second filename.inc.

The files will be placed in working directory

Note

This method is highly experimental and does not work for more complex objects. Stay tuned for updates.

Parameters:
  • filename (str) – The base filename without file extension. .pov and .inc will automatically be appended to te filename.
  • working_dir (str) – The working directory. Defaults to the current directory.
GetFOV()

Get the field of view angle in the y direction (in degrees).

Return type:float
GetRTC()

Note

Looks stale. Remove it?

Return type:Mat4
GetTransform()

See transform

Remove(obj)

Remove the given object from the scene.

Parameters:obj (GfxNode) –
RemoveAll()

Remove all objects from the scene

RenderGL()

Renders the scene.

RequestRedraw()

Request a redraw of the scene.

Resize(width, height)

Resize the OpenGL context.

Parameters:
  • width (int) – The new width
  • height (int) – The new height
SetBackground(color)

See background

Parameters:color (Color) –
SetBlur(arg2)
Parameters:arg2 (int) –
SetFOV(angle)

See fov.

Parameters:angle (float) –
SetFog(arg2)
Parameters:arg2 (bool) –
SetFogColor(arg2)
Parameters:arg2 (Color) –
SetFogOffsets(arg2, arg3)
Parameters:
  • arg2 (float) –
  • arg3 (float) –
SetLightDir(arg2)
Parameters:arg2 (Vec3) –
SetLightProp(arg2, arg3, arg4)
Parameters:
  • arg2 (Color) –
  • arg3 (Color) –
  • arg4 (Color) –
SetNearFar(near, far)

Manually sets the near and far clipping planes to the given values. Before using this method, make sure AutoAutoslab() is disabled.

Parameters:
  • near (float) –
  • far (float) –
UnProject(point[, ignore_vp])

Apply the inverse of the current camera and perspective transformation. This essentially gives the screen (or normalized view coordinates) of a point in global coordinates. The inverse operations is available as Project().

Parameters:
  • point (Vec3) – The point in global coordinates.
  • ignore_vp (bool) – If set to false (the default), also performs the viewport transformation. Points inside the viewing frustum will have x and y coordinates in the range [0, width)x[0, height]. If true, the returned coordinates will be between [-1,1]x[-1,1].
Return type:

Vec3

SetRTC(arg2)
Parameters:arg2 (Mat4) –
SetShadow(arg2)
Parameters:arg2 (bool) –
SetShadowQuality(arg2)
Parameters:arg2 (int) –
SetStereoEye(arg2)
Parameters:arg2 (int) –
SetStereoInverted(arg2)
Parameters:arg2 (bool) –
SetTransform(new_transform)

See transform

Stereo(mode)
Parameters:mode (int) –

Search

Enter search terms or a module, class or function name.

Contents

Documentation is available for the following OpenStructure versions:

dev / 2.8 / 2.7 / 2.6 / 2.5 / 2.4 / 2.3.1 / 2.3 / 2.2 / 2.1 / 2.0 / 1.9 / 1.8 / 1.7.1 / 1.7 / 1.6 / 1.5 / 1.4 / 1.3 / 1.2 / 1.11 / 1.10 / (Currently viewing 1.1)

This documentation is still under heavy development!
If something is missing or if you need the C++ API description in doxygen style, check our old documentation for further information.