0
$\begingroup$

within a Python script resp. a frame change handler I need to get the current camera position and do some calculations with it. I do this as follows:

camera_object = bpy.context.scene.objects["Camera1"]

camera_position = camera_object.matrix_world.to_translation()

And then I can read out camera_position.x as well as ...y and ...z.

Works very well.

Now it turned out that I have to use the "Lock Interface" option during rendering the animation since I get crashes of Blender very often. However, when "Lock Interface" is active, I'm not getting the current camera position any more during rendering the animation. It seems that instead I'm receiving the camera position just prior to the start of rendering. I.e. the camera position appears to be frozen, although the camera is actually moving as intended.

What I'm doing wrong here?

Thanks, Mario

$\endgroup$
8
  • $\begingroup$ What sort of calculations do you want to do with the camera and why? What are you trying to achieve in the first place? $\endgroup$ Commented Nov 3, 2022 at 22:23
  • $\begingroup$ I use this to calculate angles of texts in space so that they face the camera in desired angles. I know that it is also possible to face texts directly to a camera (or any other object) with a "track to" constraint. I did not test this out in detail, but I guess I'm not having the needed degrees of freedom there. $\endgroup$
    – Mario
    Commented Nov 3, 2022 at 22:37
  • $\begingroup$ @MartynasŽiemys you know that I did yesterday ask regarding a replacement of the parameter-input via compositor nodes, since I had the very same value-freezing there as well. Here I did also try to activate the interface locking at the beginning of the frame change handler and den deactivate it at the end. I.e. bpy.context.scene.render.use_lock_interface = True and bpy.context.scene.render.use_lock_interface = False. This is not resulting in frozen values, but seems to have no effect with regard to crash reduction. $\endgroup$
    – Mario
    Commented Nov 3, 2022 at 23:27
  • $\begingroup$ I don't have enough Python knowledge here, but handlers seem to have trouble accessing bpy.context in some cases, so maybe don't use it inside the handler. You have the scene passed to the handler(def some_handler(scene): ...) so maybe you should use camera_object = scene.objects["Camera1"]. But if you have no luck with handlers, I cannot imagine any problems with controlling orientation of objects based on the orientation of the camera with constraints and drivers or even with geometry nodes. It might be better to simply do this some other way. $\endgroup$ Commented Nov 3, 2022 at 23:43
  • $\begingroup$ @MartynasŽiemys I did try to get the camera object directly from the scene. Indeed, it's working essentially as well. But the position is also frozen with active Lock Interface. I also read about issues with frame-change handlers. However, when they are not there to evaluate and change objects, what purpose do they serve then??? I also thought about avoiding the handler by implementing the render animation loop directly within the script. I think I'll check whether this is possible and how it can be done. $\endgroup$
    – Mario
    Commented Nov 4, 2022 at 7:48

1 Answer 1

0
$\begingroup$

Just to leave a note how I did deal with that issue in the end....

In fact, I'm not using the "Render Animation" function of Blender anymore but I'm doing the render loop within a script similar to what was been described here: A script to render each frame as image (not render animation) in 2.8

"Lock Interface" is not relevant here. A little downside is that there's no feedback in the Blender GUI anymore (looks like if Blender has crashed) and it seems that the rendering can only be aborted by killing the Blender application. That's not a big deal, however. What is left as feedback are regular reports about the rendered images in the console window as well as the output images.

So far this is working stable over days. There are no crashes of Blender any more - except for out-of-memory conditions or similar "normal" problems.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .