Depsgraph: handle camera switching via markers in context drivers. #110139

Closed
Alexander Gavrilov wants to merge 0 commits from angavrilov:pr-depsgraph-marker-camera into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

Blender supports animating the active camera selection (i.e. the value of scene.camera) by binding cameras to markers in the timeline. The dependency graph was completely ignoring this by not building nodes for these cameras (it is possible to still reference a camera not directly linked in the scene any more), and not taking this into account in driver relations.

This change ensures that all cameras are included in the dependency graph, and any drivers referencing scene.camera get dependencies on all cameras of the timeline, and also time itself to ensure switches are processed.


I also include a commit that tags relations update from Set Active Object As Camera to fix a similar problem with ui actions.


The attached file demonstrates the marker problem: the cube tracks the X coordinate of the active camera via a context driver, and thus should always be centered. However, without the patch:

  • Playing the animation to frames with Camera active the cube is still positioned at Camera.001 X coordinate (problem: no time dependency).
  • Position is not updated even when Camera is moved from UI (problem: no dependency on Camera).
Blender supports animating the active camera selection (i.e. the value of scene.camera) by binding cameras to markers in the timeline. The dependency graph was completely ignoring this by not building nodes for these cameras (it is possible to still reference a camera not directly linked in the scene any more), and not taking this into account in driver relations. This change ensures that all cameras are included in the dependency graph, and any drivers referencing scene.camera get dependencies on all cameras of the timeline, and also time itself to ensure switches are processed. -------- I also include a commit that tags relations update from Set Active Object As Camera to fix a similar problem with ui actions. -------- The attached file demonstrates the marker problem: the cube tracks the X coordinate of the active camera via a context driver, and thus should always be centered. However, without the patch: - Playing the animation to frames with `Camera` active the cube is still positioned at `Camera.001` X coordinate (problem: no time dependency). - Position is not updated even when `Camera` is moved from UI (problem: no dependency on `Camera`).
Alexander Gavrilov added the
Interest
Dependency Graph
label 2023-07-15 17:45:30 +02:00
Alexander Gavrilov requested review from Sergey Sharybin 2023-07-15 17:45:43 +02:00
Alexander Gavrilov added the
Interest
Animation & Rigging
label 2023-07-15 17:46:00 +02:00
Alexander Gavrilov force-pushed pr-depsgraph-marker-camera from e3358744ad to 4b3650965d 2023-07-15 18:19:50 +02:00 Compare
Alexander Gavrilov force-pushed pr-depsgraph-marker-camera from 4b3650965d to 0c6b109eb3 2023-07-16 13:41:34 +02:00 Compare
Sergey Sharybin requested review from Nathan Vegdahl 2023-07-17 09:54:33 +02:00
Sergey Sharybin requested review from Sybren A. Stüvel 2023-07-17 09:54:33 +02:00
Alexander Gavrilov force-pushed pr-depsgraph-marker-camera from 0c6b109eb3 to 37420d72d8 2023-07-19 21:10:59 +02:00 Compare
Member

I'm not familiar enough yet with the dependency graph code to review this on a fine-grained level. But from a cursory look, if I'm understanding this correctly, it looks like it's adding all cameras on the timeline as dependencies for this kind of driver variable. Is that correct?

Speaking somewhat out of ignorance, that seems like a reasonable approach to me. And certainly this issue looks like a good thing to solve if we reasonably can.

I'm not familiar enough yet with the dependency graph code to review this on a fine-grained level. But from a cursory look, if I'm understanding this correctly, it looks like it's adding all cameras on the timeline as dependencies for this kind of driver variable. Is that correct? Speaking somewhat out of ignorance, that seems like a reasonable approach to me. And certainly this issue looks like a good thing to solve if we reasonably can.
Sergey Sharybin requested changes 2023-07-20 16:34:25 +02:00
Sergey Sharybin left a comment
Owner

But from a cursory look, if I'm understanding this correctly, it looks like it's adding all cameras on the timeline as dependencies for this kind of driver variable

The patch adds relations from all cameras used by markers to deriver variables which use scene's camera property. We do not Support dynamically changing relations during playback, so this is the only way to ensure evaluation order which is available.

For the review itself.

It feels that check_is_scene_camera_reference could be improved from the local readability point of view. The best i came up with is get_rna_path_relative_to_scene_camera. It shows the intent much better, and it could still return nullptr if the given property/path is not a scene camera.

The camera linking state seems does not seem to be fully correct. Logically it should be DEG_ID_LINKED_INDIRECTLY as the camera is pulled as a dependency of a data-block and is not pulled in due to being explicitly in the collection hierarchy. It is already incorrect in the build_scene_render, but i think it worth changing to what it is supposed to be (DEG_ID_LINKED_INDIRECTLY) in all places scene->camera or marker->camera is build.

I was testing the patch with some production shots, and did not see any unexpected regression.

> But from a cursory look, if I'm understanding this correctly, it looks like it's adding all cameras on the timeline as dependencies for this kind of driver variable The patch adds relations from all cameras used by markers to deriver variables which use scene's `camera` property. We do not Support dynamically changing relations during playback, so this is the only way to ensure evaluation order which is available. For the review itself. It feels that `check_is_scene_camera_reference` could be improved from the local readability point of view. The best i came up with is `get_rna_path_relative_to_scene_camera`. It shows the intent much better, and it could still return nullptr if the given property/path is not a scene camera. The camera linking state seems does not seem to be fully correct. Logically it should be `DEG_ID_LINKED_INDIRECTLY` as the camera is pulled as a dependency of a data-block and is not pulled in due to being explicitly in the collection hierarchy. It is already incorrect in the `build_scene_render`, but i think it worth changing to what it is supposed to be (`DEG_ID_LINKED_INDIRECTLY`) in all places `scene->camera` or `marker->camera` is build. I was testing the patch with some production shots, and did not see any unexpected regression.
Alexander Gavrilov force-pushed pr-depsgraph-marker-camera from 37420d72d8 to 31010a67a0 2023-07-24 16:34:28 +02:00 Compare
Author
Member

It feels that check_is_scene_camera_reference could be improved from the local readability point of view. The best i came up with is get_rna_path_relative_to_scene_camera. It shows the intent much better, and it could still return nullptr if the given property/path is not a scene camera.

The camera linking state seems does not seem to be fully correct. Logically it should be DEG_ID_LINKED_INDIRECTLY as the camera is pulled as a dependency of a data-block and is not pulled in due to being explicitly in the collection hierarchy.

Fixed these.

> It feels that `check_is_scene_camera_reference` could be improved from the local readability point of view. The best i came up with is `get_rna_path_relative_to_scene_camera`. It shows the intent much better, and it could still return nullptr if the given property/path is not a scene camera. > > The camera linking state seems does not seem to be fully correct. Logically it should be `DEG_ID_LINKED_INDIRECTLY` as the camera is pulled as a dependency of a data-block and is not pulled in due to being explicitly in the collection hierarchy. Fixed these.
Sergey Sharybin approved these changes 2023-07-25 11:42:33 +02:00
Sergey Sharybin left a comment
Owner

Thanks for the update!

The change looks good for me now. Not sure if the animation module people would want to have a look before landing the change.

Thanks for the update! The change looks good for me now. Not sure if the animation module people would want to have a look before landing the change.
Sybren A. Stüvel approved these changes 2023-07-25 12:24:25 +02:00
Sybren A. Stüvel left a comment
Member

Nice improvement, just two small nags that can be addressed when landing the PR.

Nice improvement, just two small nags that can be addressed when landing the PR.
@ -33,6 +35,10 @@ class DepsgraphBuilder {
virtual bool check_pchan_has_bbone_segments(const Object *object, const bPoseChannel *pchan);
virtual bool check_pchan_has_bbone_segments(const Object *object, const char *bone_name);
static const char *get_rna_path_relative_to_scene_camera(const Scene *scene,

IMO this could use some documentation as to what kind of rna_path is expected, and to clarify that the returned pointer is either nullptr or points to a substring of rna_path.

IMO this could use some documentation as to what kind of `rna_path` is expected, and to clarify that the returned pointer is either `nullptr` or points to a substring of `rna_path`.
angavrilov marked this conversation as resolved
@ -1303,0 +1308,4 @@
{
LISTBASE_FOREACH (TimeMarker *, marker, &scene_->markers) {
if (!ELEM(marker->camera, nullptr, scene_->camera)) {
PointerRNA camera_ptr;

This is nesting too deeply. Better to extract this bit into a function of its own, which can then do precondition checks and return early instead.

This is nesting too deeply. Better to extract this bit into a function of its own, which can then do precondition checks and `return` early instead.
Author
Member

I extracted the loop to match the method structure of the relations builder, and added comments to split up the nested ifs better.

I extracted the loop to match the method structure of the relations builder, and added comments to split up the nested ifs better.
@ -2006,0 +1970,4 @@
Scene *scene,
const char *rna_path)
{
/* Add references to all cameras used in the timeline. */

Shouldn't this be the docstring for this function? It doesn't seem like an implementation detail to me.

Shouldn't this be the docstring for this function? It doesn't seem like an implementation detail to me.
Author
Member

None of the other methods here have docstrings, so I made the comment look more like an implementation detail :)

None of the other methods here have docstrings, so I made the comment look more like an implementation detail :)
Alexander Gavrilov force-pushed pr-depsgraph-marker-camera from 31010a67a0 to b248295530 2023-07-25 13:13:02 +02:00 Compare
Alexander Gavrilov deleted branch pr-depsgraph-marker-camera 2023-07-25 13:17:17 +02:00

Pull request closed

Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#110139
No description provided.