Commit Graph

5 Commits

Author SHA1 Message Date
Jacques Lucke da540a73de Geometry Nodes: split sharing utility for reading and writing
This makes it more obvious that the sharing information is actually
completely independent for reading and writing currently.
2024-02-02 17:01:20 +01:00
Jacques Lucke 00eaddbd51 Geometry Nodes: new Bake node
This adds a new `Bake` node which allows saving and loading intermediate geometries.
Typical use cases we want address with this currently are:
* Bake some data for use with a render engine.
* Bake parts of the node tree explicitly for better performance.

For now, the format that is written to disk is not considered to be an import/export format.
It's not guaranteed that data written with one Blender version can be read by another
Blender version. For that it's better to use proper interchange formats. Better support for
those will be added eventually as well. We also plan an `Import Bake` node that allows
reading the blender-specific baked data independent of the Bake node and at different frames.

The baking works very similar to the baking in the simulation zone (UI and implementation
wise). Major differences are:
* The Bake node has a `Bake Still` and `Bake Animation` mode.
* The Bake node doesn't do automatic caching.

Implementation details:
* Refactored how we create the Python operators for moving socket items so that it also
  makes sense for non-zones.
* The `ModifierCache` stores an independent map of `SimulationNodeCache` and
  `BakeNodeCache`, but both share a common data structure for the actually baked data.
* For baking, the `Bake` node is added as a side-effect-node in the modifier. This will make
  sure that the node is baked even if it's currently not connected to the output.
* Had to add a new `DEG_id_tag_update_for_side_effect_request` function that is used
  during baking. It's necessary because I want to evaluate the object again even though none
  of its inputs changed. The reevaluation is necessary to create the baked data. Using
  `DEG_id_tag_update` technically works as well, but has the problem that it also uses the
  `DEG_UPDATE_SOURCE_USER_EDIT` flag which (rightly) invalidates simulation caches
  which shouldn't happen here.
* Slightly refactored the timeline drawing so that it can also show the baked ranges of
  Bake nodes. It does not show anything for baked nodes with a in Still mode though.
* The bake operator is refactored to bake a list of `NodeBakeRequest` which makes the
  code easier to follow compared to the previous nested
  `ObjectBakeData > ModifierBakeData > NodeBakeData` data structure.
* The bake operators are disabled when the .blend file is not yet saved. This is technically
  only necessary when the bake path depends on the .blend file path but seems ok to force
  the user anyway (otherwise the bake path may be lost as well if it's set explicitly).
* The same operators are used to bake and delete single bakes in `Bake` nodes and
  `Simulation Zones`. On top of that, there are separate operators of baking and deleting all
  simulation bakes (those ignore bake nodes).
* The `Bake` node remembers which inputs have been fields and thus may be baked as attributes.
  For that it uses an `Is Attribute` flag on the socket item. This is needed because the baked data
  may still contain attribute data, even if the inputs to the bake node are disconnected.
* Similar to simulation zones, the behavior of `Bake` nodes is passed into the geometry nodes
  evaluation from the outside (from the modifier only currently). This is done by providing the
  new `GeoNodesBakeParams` in `GeoNodesCallData` when executing geometry nodes.

Next Steps (mostly because they also involve simulations):
* Visualize nodes that have not been evaluated in the last evaluation.
* Fix issue with seemingly loosing baked data after undo.
* Improve error handling when baked data is not found.
* Show bake node in link drag search.
* Higher level tools for managing bakes.

Pull Request: https://projects.blender.org/blender/blender/pulls/115466
2023-12-18 13:01:06 +01:00
Jacques Lucke 5de86fc4f8 Cleanup: make name more specific for simulations
This is necessary for the bake node (#115466).
2023-12-01 17:13:31 +01:00
Jacques Lucke ad169ba67a Geometry Nodes: support baking individual simulations
Previously, it was only possible to bake all simulations at once. This is great
for simple use-cases that, but in more complex setups one can have independent
simulations that should also be baked independently. This patch allows baking
individual simulation zones.

Furthermore, each simulation zone can now also have its own bake path and
simulation frame range. By default the simulation frame range is the scene frame
range, but it can also be customized on the scene or simulation zone level. The
bake path is generated based on the modifier bake path by default, but can be
set to another absolute or relative (to the .blend file) path.

The timeline drawing has been modified as well to be able to show more information
in the case when some simulations are baked and others are not. Instead of showing
a line for every simulation, it shows a condensed view of the important information
using at most two lines:
Is something baked? Is something valid or invalid? Also see #112232.

Pull Request: https://projects.blender.org/blender/blender/pulls/112723
2023-09-26 20:30:46 +02:00
Jacques Lucke 7d2c854261 Geometry Nodes: generalize modifier simulation cache storage names
The main goal here is to rename things in a way that makes sense for
simulation baking, but also for the upcoming bake node.

This also removes some versioning code from 3.6 which initialized the
default bake path. Baked data from back then can't be loaded anymore
anyway, and the way the default path is generated is different now as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/111845
2023-09-03 16:14:11 +02:00