Panda3D
Loading...
Searching...
No Matches
MotionTrail Class Reference
Inheritance diagram for MotionTrail:
DirectObject

Public Member Functions

 __init__ (self, name, parent_node_path)
 
 add_geometry_quad (self, v0, v1, v2, v3, c0, c1, c2, c3, t0, t1, t2, t3)
 
 add_vertex (self, vertex_id, vertex_function=None, context=None)
 
 attach_motion_trail (self)
 
 begin_geometry (self)
 
 begin_motion_trail (self)
 
 check_for_update (self, current_time)
 
 delete (self)
 
 enable_motion_trail (self, enable)
 
 end_geometry (self)
 
 end_motion_trail (self)
 
 motion_trail_task (self, task)
 
 pause_motion_trail (self, current_time)
 
 print_matrix (self, matrix)
 
 register_motion_trail (self)
 
 reset_motion_trail (self)
 
 reset_motion_trail_geometry (self)
 
 resume_motion_trail (self, current_time)
 
 set_fade (self, time, current_time)
 
 set_texture (self, texture)
 
 set_vertex_color (self, vertex_id, start_color, end_color)
 
 setGlobalEnable (cls, enable)
 
 toggle_pause_motion_trail (self, current_time)
 
 transferVertices (self)
 
 unregister_motion_trail (self)
 
 update_motion_trail (self, current_time, transform)
 
 update_vertices (self)
 
- Public Member Functions inherited from DirectObject
 __init__ (self)
 
 accept (self, event, method, extraArgs=[])
 
 acceptOnce (self, event, method, extraArgs=[])
 
 addTask (self, *args, **kwargs)
 
 detectLeaks (self)
 
 doMethodLater (self, *args, **kwargs)
 
 getAllAccepting (self)
 
 ignore (self, event)
 
 ignoreAll (self)
 
 isAccepting (self, event)
 
 isIgnoring (self, event)
 
 removeAllTasks (self)
 
 removeTask (self, taskOrName)
 

Public Attributes

bool active = True
 
bool calculate_relative_matrix = False
 
 cmotion_trail = CMotionTrail()
 
float color_scale = 1.0
 
 color_writer = GeomVertexWriter(self.vertex_data, "color")
 
bool continuous_motion_trail = True
 
bool enable = True
 
bool fade = False
 
float fade_color_scale = 1.0
 
bool fade_end = False
 
float fade_start_time = 0.0
 
 fade_time = 0.0
 
 format = GeomVertexFormat.getV3c4t2()
 
list frame_list = []
 
 geom_node = GeomNode("motion_trail")
 A .GeomNode object containing the generated geometry.
 
 geom_node_path = self.attachNewNode(self.geom_node)
 
 geometry = Geom(self.vertex_data)
 
float last_update_time = 0.0
 
bool modified_vertices = True
 
 motion_trail_task
 set render states
 
 parent_node_path = parent_node_path
 
bool pause = False
 
float pause_time = 0.0
 
bool playing = False
 
 previous_matrix = None
 
bool relative_to_render = False
 
float resolution_distance = 0.5
 This can be changed to fine-tune the resolution of the NURBS curve.
 
 root_node_path = None
 
float sampling_time = 0.0
 How often the trail updates, in seconds.
 
bool square_t = True
 
 texture = None
 
 texture_writer = GeomVertexWriter(self.vertex_data, "texcoord")
 
float time_window = 1.0
 How long the time window is for which the trail is computed.
 
int total_vertices = 0
 
 triangles = GeomTriangles(Geom.UHStatic)
 
bool use_nurbs = False
 Set this to True to use a NURBS curve to generate a smooth trail, even if the underlying animation or movement is janky.
 
bool use_python_version = True
 
 vertex_data = GeomVertexData("vertices", self.format, Geom.UHStatic)
 
int vertex_index = 0
 
list vertex_list = []
 
 vertex_writer = GeomVertexWriter(self.vertex_data, "vertex")
 

Static Public Attributes

bool global_enable = True
 
list motion_trail_list = []
 
str motion_trail_task_name = "motion_trail_task"
 
 notify = directNotify.newCategory("MotionTrail")
 
bool task_added = False
 
- Static Public Attributes inherited from DirectObject
 accept_once = acceptOnce
 
 add_task = addTask
 
 detect_leaks = detectLeaks
 
 do_method_later = doMethodLater
 
 get_all_accepting = getAllAccepting
 
 ignore_all = ignoreAll
 
 is_accepting = isAccepting
 
 is_ignoring = isIgnoring
 
 remove_all_tasks = removeAllTasks
 
 remove_task = removeTask
 

Additional Inherited Members

- Protected Member Functions inherited from DirectObject
 _addTask (self, task)
 
 _clearTask (self, task)
 
- Protected Attributes inherited from DirectObject
dict _taskList = {}
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
name,
parent_node_path )
Creates the motion trail with the given name and parents it to the
given root node.

Member Function Documentation

◆ add_geometry_quad()

add_geometry_quad ( self,
v0,
v1,
v2,
v3,
c0,
c1,
c2,
c3,
t0,
t1,
t2,
t3 )

◆ add_vertex()

add_vertex ( self,
vertex_id,
vertex_function = None,
context = None )
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()

attach_motion_trail ( self)
Alias of `reset_motion_trail()`.

◆ begin_geometry()

begin_geometry ( self)

◆ begin_motion_trail()

begin_motion_trail ( self)

◆ check_for_update()

check_for_update ( self,
current_time )
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()

delete ( self)
Completely cleans up the motion trail object.

◆ enable_motion_trail()

enable_motion_trail ( self,
enable )
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()

end_geometry ( self)

◆ end_motion_trail()

end_motion_trail ( self)

◆ motion_trail_task()

motion_trail_task ( self,
task )

◆ pause_motion_trail()

pause_motion_trail ( self,
current_time )

◆ print_matrix()

print_matrix ( self,
matrix )

◆ register_motion_trail()

register_motion_trail ( self)
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()

reset_motion_trail ( self)
Call this to have the motion trail restart from nothing on the next
update.

◆ reset_motion_trail_geometry()

reset_motion_trail_geometry ( self)
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.

◆ resume_motion_trail()

resume_motion_trail ( self,
current_time )

◆ set_fade()

set_fade ( self,
time,
current_time )

◆ set_texture()

set_texture ( self,
texture )
Defines the texture that should be applied to the trail geometry.
This also enables generation of UV coordinates.

◆ set_vertex_color()

set_vertex_color ( self,
vertex_id,
start_color,
end_color )
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).

◆ setGlobalEnable()

setGlobalEnable ( cls,
enable )
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.

◆ toggle_pause_motion_trail()

toggle_pause_motion_trail ( self,
current_time )

◆ transferVertices()

transferVertices ( self)

◆ unregister_motion_trail()

unregister_motion_trail ( self)
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()

update_motion_trail ( self,
current_time,
transform )
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()

update_vertices ( self)
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()`.

Member Data Documentation

◆ active

bool active = True

◆ calculate_relative_matrix

calculate_relative_matrix = False

◆ cmotion_trail

cmotion_trail = CMotionTrail()

◆ color_scale

float color_scale = 1.0

◆ color_writer

color_writer = GeomVertexWriter(self.vertex_data, "color")

◆ continuous_motion_trail

bool continuous_motion_trail = True

◆ enable

bool enable = True

◆ fade

bool fade = False

◆ fade_color_scale

float fade_color_scale = 1.0

◆ fade_end

bool fade_end = False

◆ fade_start_time

float fade_start_time = 0.0

◆ fade_time

fade_time = 0.0

◆ format

format = GeomVertexFormat.getV3c4t2()

◆ frame_list

frame_list = []

◆ geom_node

geom_node = GeomNode("motion_trail")

A .GeomNode object containing the generated geometry.

By default parented to the MotionTrail itself, but can be reparented elsewhere if necessary.

◆ geom_node_path

geom_node_path = self.attachNewNode(self.geom_node)

◆ geometry

geometry = Geom(self.vertex_data)

◆ global_enable

bool global_enable = True
static

◆ last_update_time

last_update_time = 0.0

◆ modified_vertices

bool modified_vertices = True

◆ motion_trail_list

list motion_trail_list = []
static

◆ motion_trail_task

motion_trail_task

set render states

◆ motion_trail_task_name

str motion_trail_task_name = "motion_trail_task"
static

◆ notify

notify = directNotify.newCategory("MotionTrail")
static

◆ parent_node_path

parent_node_path = parent_node_path

◆ pause

bool pause = False

◆ pause_time

float pause_time = 0.0

◆ playing

bool playing = False

◆ previous_matrix

previous_matrix = None

◆ relative_to_render

bool relative_to_render = False

◆ resolution_distance

resolution_distance = 0.5

This can be changed to fine-tune the resolution of the NURBS curve.

◆ root_node_path

root_node_path = None

◆ sampling_time

sampling_time = 0.0

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.

◆ square_t

bool square_t = True

◆ task_added

bool task_added = False
static

◆ texture

texture = None

◆ texture_writer

texture_writer = GeomVertexWriter(self.vertex_data, "texcoord")

◆ time_window

time_window = 1.0

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.

◆ total_vertices

int total_vertices = 0

◆ triangles

triangles = GeomTriangles(Geom.UHStatic)

◆ use_nurbs

use_nurbs = False

Set this to True to use a NURBS curve to generate a smooth trail, even if the underlying animation or movement is janky.

◆ use_python_version

bool use_python_version = True

◆ vertex_data

vertex_data = GeomVertexData("vertices", self.format, Geom.UHStatic)

◆ vertex_index

int vertex_index = 0

◆ vertex_list

list vertex_list = []

◆ vertex_writer

vertex_writer = GeomVertexWriter(self.vertex_data, "vertex")