Generic way for modifiers to check user-edited flags #108174

Open
opened 2023-05-23 12:02:05 +02:00 by Sergey Sharybin · 0 comments

The simulation modifiers need to take care of invalidating cache when user edits are performed on the modifier itself, or its dependencies.

For the point cache (rigid body simulation, for example) this is done as a dedicated dependency graph node, which is hooked to the rest of the graph via a relation which has RELATION_FLAG_FLUSH_USER_EDIT_ONLY flag. The benefit of such approach is that a generic callback function can be used (without capturing any internal state of the graph). The downside is the more complex routing of relations.

The simulation nodes took a bit different approach: the nodes modifier has a special lambda callback which checks the node and dependency graph state:

modifier_node->evaluate = [](...) {
  if (modifier_node->flag & DEPSOP_FLAG_USER_MODIFIED) {
    ...
  }
}

Such approach allows to access the modification state without extra nodes and relations, but it is not very generic: ideally the modifier-specific logic will be left to the modifier's "apply" callback.

Fortunately, there is a simple modification to the current nodes modifier callback we can do!

General idea: have a generic modifier node callback (for all node types) which will copy the user-modified flag from the modifier dependency graph node to the modifier data. The modifier's "apply" callback then can make decision based on this flag.

Pseudo-code of this proposal goes as following:

modifier_node->evaluate = [modifier_index = ...](::Depsgraph * /*depsgraph*/, ...) {
  ModifierData *md_eval = object_eval->modifiers[modifier_index];
  if (modifier_node->flag & DEPSOP_FLAG_USER_MODIFIED) {
    md_eval-> flag |= MODIFIER_USER_MODIFIED;
  } else {
    md_eval-> flag &= ~MODIFIER_USER_MODIFIED;
  }
}

Use the modifier index since it can be captured at the graph construction time, and will stay available even if the original objects are destroyed (the long-term goal is to allow the depsgraph be fully independent from the original scene after its Copy-On-Write was run). It is a bit annoying to do an index-based lookup in the list, but it is unlikely to show up in a profiler.

The geometry node modifier can immediately use this new flag. In a longer term the rigid body will do the same or be migrated to the new simulation framework :)

The simulation modifiers need to take care of invalidating cache when user edits are performed on the modifier itself, or its dependencies. For the point cache (rigid body simulation, for example) this is done as a dedicated dependency graph node, which is hooked to the rest of the graph via a relation which has `RELATION_FLAG_FLUSH_USER_EDIT_ONLY` flag. The benefit of such approach is that a generic callback function can be used (without capturing any internal state of the graph). The downside is the more complex routing of relations. The simulation nodes took a bit different approach: the nodes modifier has a special lambda callback which checks the node and dependency graph state: ```Cpp modifier_node->evaluate = [](...) { if (modifier_node->flag & DEPSOP_FLAG_USER_MODIFIED) { ... } } ``` Such approach allows to access the modification state without extra nodes and relations, but it is not very generic: ideally the modifier-specific logic will be left to the modifier's "apply" callback. Fortunately, there is a simple modification to the current nodes modifier callback we can do! General idea: have a generic modifier node callback (for all node types) which will copy the user-modified flag from the modifier dependency graph node to the modifier data. The modifier's "apply" callback then can make decision based on this flag. Pseudo-code of this proposal goes as following: ```Cpp modifier_node->evaluate = [modifier_index = ...](::Depsgraph * /*depsgraph*/, ...) { ModifierData *md_eval = object_eval->modifiers[modifier_index]; if (modifier_node->flag & DEPSOP_FLAG_USER_MODIFIED) { md_eval-> flag |= MODIFIER_USER_MODIFIED; } else { md_eval-> flag &= ~MODIFIER_USER_MODIFIED; } } ``` Use the modifier index since it can be captured at the graph construction time, and will stay available even if the original objects are destroyed (the long-term goal is to allow the depsgraph be fully independent from the original scene after its Copy-On-Write was run). It is a bit annoying to do an index-based lookup in the list, but it is unlikely to show up in a profiler. The geometry node modifier can immediately use this new flag. In a longer term the rigid body will do the same or be migrated to the new simulation framework :)
Sergey Sharybin added the
Type
Design
Interest
Dependency Graph
labels 2023-05-23 12:02:05 +02:00
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
1 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#108174
No description provided.