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
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?
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
# 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
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.