H3DAPI Python Interface

From H3D.org

Jump to: navigation, search

This page provides a reference manual over the functionality provided by the Python script engine in H3D API. Some are provided through the H3D package and some through H3DInterface. The simplest thing is to import everything into the global namespace of the script by writing

from H3D import *
from H3DInterface import *

Contents

Global fields

  • time - Python access to Scene::time, which is the current time updated each scene-graph loop.
  • eventSink - Python access to Scene::eventSink, which makes all fields up-to-date what are routed to it once per scene-graph loop

Callbacks

  • traverseSG
  • initialize

Functions

X3D creation functions

Each of the functions below returns a tuple where the first element is the node that has been created and the second argument is a dictionary with all the DEFed nodes in the string/url provided.

  • createX3DFromURL( url )
  • createX3DFromString( string )
  • createX3DNodeFromURL( url )
  • createX3DNodeFromString( string )
  • createVRMLFromURL( url )
  • createVRMLFromString( string )
  • createVRMLNodeFromURL( url )
  • createVRMLNodeFromString( string )

X3D write functions

Each of these functions returns a string which contains the X3D syntax of the argument.

  • writeNodeAsX3D( node )

Bindable nodes access

The following functions return the currently bound node for different bindable node stacks

  • getActiveDeviceInfo()
  • getActiveViewpoint()
  • getActiveNavigationInfo()
  • getActiveStereoInfo()
  • getActiveBackground()
  • getActiveFog()
  • getActiveGlobalSettings()
  • getActiveBindableNode( bindable ) - The string argument bindable specifies the type of bindable node to return.
  • getCurrentScenes() - returns a list of all currently instantiated Scene instances.

Resource resolver

This provides access to the H3D API ResourceResolver

  • resolveURLAsFile( file )

Types

X3D field types

The field types included are:

  • SFields - SFFloat, SFDouble, SFTime, SFInt32, SFVec2f, SFVec2d, SFVec3f, SFVec3d, SFVec4f, SFVec4d, SFBool, SFString, SFColor, SFColorRGBA, SFRotation, SFMatrix3f, SFMatrix4f, SFNode
  • MFields - MFFloat, MFDouble, MFTime, MFInt32, MFVec2f, MFVec2d, MFVec3f, MFVec3d, MFVec4f, MFVec4d, MFBool, MFString, MFColor, MFColorRGBA, MFRotation, MFMatrix3f, MFMatrix4f, MFNode

Field functions

The member functions available in all fields

  • route(field) - set up a new route
  • routeNoEvent(field) - set up a new route without generating an event
  • unroute(field) - remove a route
  • touch() - generate an event from the field
  • getRoutesIn() - returns a list of all fields routed to the field
  • getRoutesOut() - returns a list of all fields the field is routed to

SField specific functions

the member functions for all SFields(i.e. SFFloat, SFDouble, etc) are

  • setValue(value) - set the field to the new value
  • getValue() - returns the current value of the field

MField specific functions

the member functions for all MFields (i.e. MFFloat, MFDouble, etc) are

  • setValue(list) - set the field to the new value
  • getValue() - get the value of the field as a list
  • push_back( element ) - add a new element to the end of the list of values
  • pop_back() - removes the last element
  • empty() - returns 1 if MField is empty, 0 otherwise
  • front() - returns the first element
  • back() - returns the last element
  • clear() - removes all elements
  • erase(element) - removes the first occurence of element

Modifiers

Use these as base type for your field if you want to modify its behaviour.

  • TypedField(Base,Required,Optional) - used for fields where you define the type of all the routes to it. Base is the base type, Required is None, or the type or a list of the types of the required incoming routes, and Optional is a type which can be routed zero or more times to this field.
  • AutoUpdate(Base) - used if you want to add AutoUpdate capabilities to a field, i.e. make it update its value as soon as it receives an event
  • PeriodicUpdate(Base) - used if you want to add PeriodicUpdate capabilities to a field, i.e. make it update its value once per scene-graph loop.

X3D Types

The types included are: Matrix3d, Matrix3f, Matrix4d, Matrix4f, Node, Quaternion, RGB, RGBA, Rotation, Vec2d, Vec2f, Vec3d, Vec3f, Vec4d, Vec4f

Matrix methods

These common for all matrices.

  • setToIdentity()
  • inverse()
  • getRow( row_number )
  • getColumn( column_number )
  • getElement( row, column )
  • setElement( row, column, value )
  • getScalePart() - returns the matrix scale part as a Vec3f/d. With scaling in x,y,z-dimensions.
  • transpose()

Matrix3f/d methods

  • toEulerAngles() - returns the euler angles (yaw, pitch, roll) in a Vec3f/d.

Matrix4f/d methods

  • transformInverse() - returns the inverse of the matrix assuming that the fourth row is 0 0 0 1.
  • getScaleRotationPart() - returns a Matrix3f/d containing the scale and rotation of the Matrix4f/d
  • getRotationPart() - returns a Matrix3f/d containing the rotation of the Matrix4f/d
  • getTranslationPart() - returns a Vec3f/d containing the translation part of the Matrix4f/d

Node methods

  • getFieldList()
  • addField( name, field_type, access_type ) - can only be used with nodes that inherit from H3DDynamicFieldsObject.
  • getField( name )
  • getName()
  • getTypeName()

Quaternion methods

  • toEulerAngles() - returns the euler angles (yaw, pitch, roll) in a Vec3f/d.
  • norm() - returns the quaternion norm.
  • normalize()
  • conjugate()
  • inverse()
  • slerp( quat, t ) - spherical linear interpolation between two quaternions. t is a value between 0 and 1
  • dotProduct( q )

Quaternion members

  • x
  • y
  • z
  • w

RGB members

  • r
  • g
  • b

RGBA members

  • r
  • g
  • b
  • a

Rotation methods

  • toEulerAngles() - returns the euler angles (yaw, pitch, roll) in a Vec3f/d.
  • slerp( rot, t ) - spherical linear interpolation between two rotations. t is a value between 0 and 1

Rotation members

  • x
  • y
  • z
  • angle
  • a - another way of getting the angle.

Vector methods

These are common for all vectors.

  • length()
  • lengthSqr()
  • normalize()
  • normalizeSafe()
  • dotProduct( v )

Vec3f/d and Vec4f/d methods

  • crossProduct( v )

Vector members

Vec2f/d

  • x
  • y

Vec3f/d members

  • x
  • y
  • z

Vec4f/d members

  • x
  • y
  • z
  • w
Personal tools
go to