MotionTrail vertex issues

Hi again, I’m just wondering if anyone has done any work with motion trails in the past, as I’m trying to get essentially a line that traces the objects previous motion. Here is the code I’ve written:

 self.setting = self.loader.loadModel(modelPath)
        self.setting.reparentTo(self.render)
        self.setting.set_two_sided(True)
        self.setting.setScale(scale[0], scale[1], scale[2])
        trail= MotionTrail("object trail",self.setting)
        trail.register_motion_trail()
        trail.geom_node_path.reparent_to(self.render)
        trail.time_window=3
        trail.add_vertex(Point3(0, 0, 1),None,None)
        trail.add_vertex(Point3(0, 0, -1),None,None)
        trail.set_vertex_color(0, Vec4(1.0, 0.0, 0.0, 1), Vec4(1.0, 0.0, 0.0, 1))
        trail.set_vertex_color(1, Vec4(1.0, 0.0, 0.0, 1), Vec4(1.0, 0.0, 0.0, 1))

        trail.update_vertices()

The program throws an error at trail.add_vertex which says: missing 2 required positional arguments: 'vertex_function' and 'context'

My problem being I have no idea what those arguments are. The reference code I used for this was taken by the person that made the panda3d motion trail sample program. Here is GitHub code link (the code I used was lines 42-46 and 65-68): panda3d/fireball.py at master · panda3d/panda3d · GitHub

If you are on Panda3D version 1.10.13, then you can transfer only one Vec4 or Point3
https://docs.panda3d.org/1.10/python/reference/direct.motiontrail.MotionTrail#direct.motiontrail.MotionTrail.MotionTrail.add_vertex

Yes, update to 1.10.13. It also includes significant performance improvements for motion trails.

In older versions, you had to do this:

trail.add_vertex(0, lambda vtx, id, ctx: ctx, Vec4(0, 0, 1, 1))
trail.add_vertex(1, lambda vtx, id, ctx: ctx, Vec4(0, 0,-1, 1))

Hey thank you so much, the trail itself seems to work, however there seems to be an error in how the motion trail is rendered, as the object itself appears in a different position to the position that is passed in, which I think is why the motion trail isn’t actually connected to the model. Is there a way to offset the motion trail?

or at least somehow centre the object model in panda

Could it be that your object-model has an offset? That is, that it isn’t centred on its local origin?

If so, then you could perhaps use a dummy-node to offset it: simply put, instead of moving your model as you do now, create an empty PandaNode (wrapped in a NodePath, as per usual), reparent your model to that empty PandaNode, apply an offset to the model, and then move the empty node as you currently move the model.

Something like this:

# For the sake of demonstration, assume that the model is offset by
# 1.5 units in the positive x-direction. Adjust as called for to
# a given specific case

# Presume further that the model in question is held in a variable
# called "self.myModel", and that it is parented below a node
# called "self.myParentNode".

# First, create a dummy-node, attached to the relevant parent
self.modelHandleNP = self.myParentNode.attachNewNode(PandaNode("model handle"))

# Then attach the model to it
self.myModel.reparentTo(self.modelHandleNP)

# And finally, position the model to account for its offset.
# Since the model lies 1.5 units in the positive x-direction
# from its origin, we offset it by 1.5 units in the negative
# x-direction
self.myModel.setPos(-1.5, 0, 0)

unfortunately, for my code the final line self.myModel.setPos(-1.5, 0, 0) doesn’t seem to make much of a difference. I tested it with massive numbers to see if any difference was noticeable, and it wasn’t, so I’m not really sure what to do, but thank you for the help. Is there any method to accurately align the centre of the object model to where panda3d thinks the centre of the model is? As this problem arises during scaling. Or using a different file format for my model? Currently my model is a .obj file

If there is such an displacement of the model from its origin, then the simplest place to fix it might be within the modelling package that was used to make the model.

That said, if significant offsets aren’t producing a visual difference, then the problem might lie elsewhere. And as I’m not particularly familiar with the Motion Trail system, I’m going to bow out for now, I think!

That said, just to respond to a few specific points:

Just to clarify: Did those numbers change anything at all? Did the object appear in a different position in the scene, at least?

If not, then that might suggest that something is interfering with the attempted offset–perhaps there’s another piece of code that is reparenting and/or setting the position of the model, and thus overriding the offsetting-code.

What I posted above is pretty much this: given a known displacement from the origin (and noting that (-1.5, 0, 0) was just an example value), it adjusts to compensate for that value.

It seems to me unlikely that the file-format will have much effect. It’s just a representation of what was modelled, and a positional displacement is something that I would expect the vast majority of formats to allow.

Ah ok thank you so much

1 Like