Commit Graph

5 Commits

Author SHA1 Message Date
Hans Goudey 1cfe9dd08c Geometry Nodes: Matrix socket type, attribute type, and initial nodes
Implements the design from #116067.
The socket type is called "Matrix" but it is often referred to as "Transform"
when that's what it is semantically. The attribute type is "4x4 Matrix" since
that's a lower level choice. Currently matrix sockets are always passed
around internally as `float4x4`, but that can be optimized in the future
when smaller types would give the same behavior.

A new "Matrix" utilities category has the following set of initial nodes"
- **Combine Transform**
- **Separate Transform**
- **Multiply Matrices**
- **Transform Direction**
- **Transform Vector**
- **Invert Matrix**
- **Transpose Matrix**

The nodes and socket type are behind an experimental flag for now,
which will give us time to make sure it's the right set of initial nodes.
The viewer node overlay doesn't support matrices-- they aren't supported
for rendering in general. They also aren't supported in the modifier interface
currently. But they are supported in the spreadsheet, where the value is
displayed in a tooltip.

Pull Request: https://projects.blender.org/blender/blender/pulls/116166
2024-02-13 18:59:36 +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
Hans Goudey 8d5aa6eed4 Geometry Nodes: Index switch node
Add an "Index Switch" node which is meant as a simpler version of
the "Menu Switch" from #113445 that doesn't allow naming items
or displaying them in a dropdown, but still allows choosing between
an arbitrary number of items, unlike the regular "Switch" node.
Even when the Menu Switch is included (which should be in the
same release as this), it may still be helpful to have explicit mapping
of indices, and a fair amount of the internals can be shared anyway.

Pull Request: https://projects.blender.org/blender/blender/pulls/115250
2023-11-22 16:11:32 +01:00
Jacques Lucke eeb77f3d51 Cleanup: deduplicate more socket items code
This is a continuation of 012289b1e7.
2023-10-04 12:22:32 +02:00
Jacques Lucke 012289b1e7 Geometry Nodes: deduplicate code to deal with dynamic socket amounts
The goal of this refactor is to reduce the amount of boilerplate code that is
necessary to have a dynamic number of sockets on nodes. This is achieved
by making the code more reusable. Currently, only the simulation and repeat
zone nodes make use of this. However, even with just those two, the amount
of code is reduced already. The benefit of this refactor will become even more
significant as more nodes support a dynamic number of sockets. For example,
the bake node and for-each zone will also benefit from this.

We could probably make some of the utility functions non-templates using type
erasure. This could reduce the compilation overhead when the number of nodes
with item arrays increases. The main reason for why everything is templated
now is that it made this refactor easier. Without this patch, all the code was
essentially "manually templated". So the implementations look still similar to
before now, just that concrete types are replaced with template parameters.

No user-visible changes are expected.

Pull Request: https://projects.blender.org/blender/blender/pulls/113114
2023-10-04 11:02:52 +02:00