Position a 3D object at a fixed location on the screen/view

Hey again everyone,

I’ve recently been making a sci-vis video, which has resulted in several questions for how I might be able to improve the video.

So my question for today is how to put a 3D object in a fixed location on the animated frame. I’ve previously asked about how to make the update happen on a regular basis,
but this question is different. For now I’m using a pvpython script to generate the animation, so I can just put code in that script to move objects around.

So here’s what I’m doing now:

   compass = FindSource('Transform3')
   camLocation = camera.GetPosition()
   dirVector = tuple(map(operator.sub, camera.GetFocalPoint(), camLocation))
   normDir = dirVector / np.linalg.norm(dirVector)
   newLocation = camLocation + normDir * 20 + [0.0, 0.0, 4.0]
   compass.Transform.Translate = newLocation

In words, I find the location of the camera, create a vector from that location to to focal point, normalize that vector, and then multiply it by a number (20) to push it forward in front of the camera, and then add a vector (0,0,4) to move it to the top of the screen.

And this works reasonably well when the camera isn’t turning much, but when it does turn a lot the object moves all over the place, sometimes out of view.

So even though I’ve looked at the “dir (GetActiveCamera())” for clues without anything obvious jumping out at me, I’m hoping there’s an elegant solution that I’m just not spotting.

Obviously the code above relies on there being a Transform filter attached to the 3D object which is what I connect to.

Not obviously, my camera parameters are not from ParaView’s poor camera animation system (another post entirely), but from a path I create by flying through the scene in VR. I then take the camera data from VR in CSV form and load it into the camera in ParaView on a frame by frame basis. And when doing that I’ve set the ViewUp value to be straight up (0,0,1) which means there’s not usually a 90 degree angle between the forward direction and the ViewUp direction (which may or may not play a role in my object swinging all over the view).

I’m happy to experiment if someone can point me to an operation I’ve overlooked.