This class is at the core of animation in EnSight. If you want to introduce an animation into EnSight, create a subclass of this object and enable playing on it. Each instance defines a temporal block of animation and it will be dynamically called by EnSight to update itself. The simplest example would be:
def state(self, v):
def update(self, f):
The class has a number of data members:
- description: a string name for the object
- current_frame: the current frame number the object should be displaying. Note: this is a float value as fractional frame numbers are possible, depending on the flags.
- frame_duration: the desired length of a frame in seconds. If this value is 0.0, the current value in: ensight.objs.core.FRAME_DURATION (the default duration) is used.
- num_frames: the number of frames in this animation segment. The total length of this animation segment is this number times the frame_duration.
- playing: a boolean that notes if this object is currently playing or not. Setting it to true inserts it into the currently playing list which can be accessed via the list returned by the attribute: ensight.objs.core.ANIMOBJS.
- next: see prev
- prev: next and prev set up a chain of ens_animobj instances that should be played as a contiguous sequence. When the end of the sequence is reached, play continues at the start of the sequence (or end if playing in reverse).
- flags: there are a number of values that can be or’ed together: ANIMOBJ_FLG_ALLFRAMES: by default, if EnSight cannot keep up with the desired framerate, it will skip frames. Setting this value will force every frame to be played back. ANIMOBJ_FLG_FRACFRAMES: by default, the frame number (while a float) will be integral. If this flag is set, the actual frame number will be an interpolated float. ANIMOBJ_FLG_ONESHOT: if this flag is set, the animation sequence will always be played forward and when the end of the chain is reached, it will not loop to the start. Note: if there are no other references to the chain, the chain will be destroyed on the next garbage collection.
- state(self,v): the value passed will be ANIMOBJ_STATE_PLAYON or ANIMOBJ_STATE_PLAYOFF and it informs the object that it is about to be played or that it is finished playing. All calls to update() will be made between calls to the ON and OFF states. Note: in a chain, OFF is called as animation is about to move to the next (or prev) object in the chain. When global animation is stepping, the sequence of calls will be state(ON),update(),state(OFF) for each step.
- update(self,f): the value is the new frame number. Once the base class update() method is called, current_frame will have this value. Note: delay refresh is in effect while this method is called.
The ensight.objs.core object has a few attributes that control the global operation of animations:
- ANIMATING: can be set to the values: ANIMOBJ_PLAY_STEP_REV, ANIMOBJ_PLAY_REV, ANIMOBJ_PLAY_STOP, ANIMOBJ_PLAY_FWD, ANIMOBJ_PLAY_STEP_FWD. The ‘STOP’ mode will disable all animations (but the active objects are still kept in the list). The ‘FWD’ and ‘REV’ will cause dynamic animation to move forward or backward at the rates the objects define. The ‘STEP’ variants will cause one frame of animation to be moved. The duration of that frame is the minimum of the durations set on the objects and the ensight.objs.core.FRAME_DURATION.
- FRAME_DURATION: the default frame duration for objects that specify it as 0.0
- ANIMOBJS: a list of the objects whose ‘PLAYING’ member is currently set
EnsAnimAttr is a convenience class to animate object attributes along a spline (zero-order or higher). The caller specifies the object, attribute, and control points and the class handles all aspects of animation, including recording. A simple example would be:
from ensight.core.ensanim import EnsAnimAttr
obj = ensight.objs.core
attr = enums.SOLUTIONTIME
times = ensight.objs.core.SOLUTIONTIME_LIMITS
cpts = [[0.0, [times]], [1.0, [times]]]
a = EnsAnimAttr(obj, attr, cpts)
a.num_frames = times - times + 1
This example animation solution time (an attribute on the core object) linearly from the min value to max value. The control points are given in a list, where each control point is of the form [t, [values]]. Animation time runs from t=0.0 to t=1.0.
EnsAttrSync uses callbacks to synchronize attributes between multiple parts. It will monitor a source list of parts for changes to a defined list of attributes, and it will copy these attributes to the given destination parts whenever one of them changes. A simple example would be to synchronize the VALUE attribute on several clips or isosurfaces:
from ensight.core.ensattrutil import EnsAttrSync
from ensight.objs import *
parts = [core.PARTS, core.PARTS]
attrs = [ enums.VALUE ]
s = EnsAttrSync(src=parts, dest=parts, attr=attrs)