direct.motiontrail.MotionTrail

from direct.motiontrail.MotionTrail import MotionTrail, MotionTrailFrame, MotionTrailVertex, remove_task

Inheritance diagram

Inheritance diagram of direct.motiontrail.MotionTrail

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() and set_vertex_color(). When this is done, call update_vertices().

To generate the motion trail, either call register_motion_trail() to have Panda update it automatically, or periodically call the method update_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 if sampling_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, set want-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_geometry_quad(self, v0, v1, v2, v3, c0, c1, c2, c3, t0, t1, t2, t3)[source]
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 or Point3.

attach_motion_trail(self)[source]

Alias of reset_motion_trail().

begin_geometry(self)[source]
begin_motion_trail(self)[source]
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.

delete(self)[source]

Completely cleans up the motion trail object.

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.

end_geometry(self)[source]
end_motion_trail(self)[source]
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(self, task)[source]
motion_trail_task_name = 'motion_trail_task'
notify = <direct.directnotify.Notifier.Notifier object>
pause_motion_trail(self, current_time)[source]
print_matrix(self, matrix)[source]
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.

resume_motion_trail(self, current_time)[source]
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_fade(self, time, current_time)[source]
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.

toggle_pause_motion_trail(self, current_time)[source]
transferVertices(self)[source]
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() and set_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.

class MotionTrailFrame(current_time, transform)[source]

Bases: object

__init__(self, current_time, transform)[source]
class MotionTrailVertex(vertex_id, vertex_function, context)[source]

Bases: object

__init__(self, vertex_id, vertex_function, context)[source]
remove_task()[source]