direct.motiontrail.MotionTrail
from direct.motiontrail.MotionTrail import MotionTrail, MotionTrailFrame, MotionTrailVertex, remove_task
Inheritance diagram
- class MotionTrail(name, parent_node_path)[source]
Bases:
NodePath
,DirectObject
Generates smooth geometry-based motion trails behind a moving object.
To use this class, first define the shape of the cross-section polygon that is to be extruded along the motion trail by calling
add_vertex()
andset_vertex_color()
. When this is done, callupdate_vertices()
.To generate the motion trail, either call
register_motion_trail()
to have Panda update it automatically, or periodically call the methodupdate_motion_trail()
with the current time and the new transform.The duration of the sample history is specified by
time_window
. A larger time window creates longer motion trails (given constant speed). Samples that are no longer within the time window are automatically discarded.The
use_nurbs
option can be used to create smooth interpolated curves from the samples. This option is useful for animations that lack sampling to begin with, animations that move very quickly, or low frame rates, or ifsampling_time
is used to artificially slow down the update frequency.By default, the optimized C++ implementation (provided by
CMotionTrail
) is used to generate the motion trails. If for some reason you want to use the pure-Python implementation instead, setwant-python-motion-trails
to true in Config.prc.- __init__(self, name, parent_node_path)[source]
Creates the motion trail with the given name and parents it to the given root node.
- add_vertex(self, vertex_id, vertex_function=None, context=None)[source]
This must be called initially to define the polygon that forms the cross-section of the generated motion trail geometry. The first argument is a user-defined vertex identifier, the second is a function that will be called with three parameters that should return the position of the vertex as a
Vec4
object, and the third is an arbitrary context object that is passed as last argument to the provided function.After calling this, you must call
update_vertices()
before the changes will fully take effect.As of Panda3D 1.10.13, you may alternatively simply pass in a single argument containing the vertex position as a
Vec4
orPoint3
.
- attach_motion_trail(self)[source]
Alias of
reset_motion_trail()
.
- check_for_update(self, current_time)[source]
Returns true if the motion trail is overdue for an update based on the configured
sampling_time
(by default 0.0 to update continuously), and is not currently paused.
- enable_motion_trail(self, enable)[source]
Sets whether the motion trail is currently enabled. Every motion trail starts off as being enabled, passing False to this method prevents it from being updated.
- geom_node
A
GeomNode
object containing the generated geometry. By default parented to the MotionTrail itself, but can be reparented elsewhere if necessary.
- global_enable = True
- motion_trail_list = []
- motion_trail_task_name = 'motion_trail_task'
- notify = <direct.directnotify.Notifier.Notifier object>
- register_motion_trail(self)[source]
Adds this motion trail to the list of trails that are updated automatically every frame. Be careful not to call this twice.
- reset_motion_trail(self)[source]
Call this to have the motion trail restart from nothing on the next update.
- reset_motion_trail_geometry(self)[source]
Destroys the currently generated motion trail geometry immediately. However, it will be fully regenerated on the next call to update, see
reset_motion_trail()
to prevent this.
- resolution_distance
This can be changed to fine-tune the resolution of the NURBS curve.
- sampling_time
How often the trail updates, in seconds. The default is 0.0, which has the trail updated every frame for the smoothest result. Higher values will generate a choppier trail. The
use_nurbs
option can compensate partially for this choppiness, however.
- setGlobalEnable(enable)[source]
Set this to False to have the task stop updating all motion trails. This does not prevent updating them manually using the
update_motion_trail()
method.
- set_texture(self, texture)[source]
Defines the texture that should be applied to the trail geometry. This also enables generation of UV coordinates.
- set_vertex_color(self, vertex_id, start_color, end_color)[source]
Sets the start and end color of the vertex with the given index, which must have been previously added by
add_vertex()
. The motion trail will contain a smooth gradient between these colors. By default, the motion trail fades from white to black (which, with the default additive blending mode, makes it show up as a purely white motion trail that fades out towards the end).
- task_added = False
- time_window
How long the time window is for which the trail is computed. Can be increased to obtain a longer trail, decreased for a shorter trail.
- unregister_motion_trail(self)[source]
Removes this motion trail from the list of trails that are updated automatically every frame. If it is not on that list, does nothing.
- update_motion_trail(self, current_time, transform)[source]
If the trail is overdue for an update based on the given time in seconds, updates it, extracting the new object position from the given transform matrix.
- update_vertices(self)[source]
This must be called after the list of vertices defining the cross-section shape of the motion trail has been defined by
add_vertex()
andset_vertex_color()
.
- use_nurbs
Set this to True to use a NURBS curve to generate a smooth trail, even if the underlying animation or movement is janky.