tornavis/source/blender/depsgraph/intern/depsgraph_type.hh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

162 lines
4.4 KiB
C++
Raw Normal View History

/* SPDX-FileCopyrightText: 2013 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup depsgraph
*
2024-03-27 00:23:54 +01:00
* Data-types for internal use in the Depsgraph
*
2024-03-27 00:23:54 +01:00
* All of these data-types are only really used within the "core" depsgraph.
* In particular, node types declared here form the structure of operations
* in the graph.
*/
#pragma once
#include <functional>
/* TODO(sergey): Ideally we'll just use char* and statically allocated strings
* to avoid any possible overhead caused by string (re)allocation/formatting. */
#include <algorithm>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <vector>
#include "BLI_map.hh"
#include "BLI_set.hh"
#include "BLI_string_ref.hh"
#include "BLI_vector.hh"
#include "BLI_vector_set.hh"
struct Depsgraph;
struct CustomData_MeshMasks;
namespace blender::deg {
/* Commonly used types. */
using std::deque;
using std::optional;
using std::pair;
using std::string;
using std::unique_ptr;
/* Commonly used functions. */
using std::make_pair;
using std::max;
using std::to_string;
/* Function bindings. */
using std::function;
using namespace std::placeholders;
#define function_bind std::bind
/* Source of the dependency graph node update tag.
*
* NOTE: This is a bit mask, so accumulation of sources is possible.
*
* TODO(sergey): Find a better place for this. */
enum eUpdateSource {
/* Update is caused by a time change. */
DEG_UPDATE_SOURCE_TIME = (1 << 0),
/* Update caused by user directly or indirectly influencing the node. */
DEG_UPDATE_SOURCE_USER_EDIT = (1 << 1),
/* Update is happening as a special response for the relations update. */
DEG_UPDATE_SOURCE_RELATIONS = (1 << 2),
/* Update is happening due to visibility change. */
DEG_UPDATE_SOURCE_VISIBILITY = (1 << 3),
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
/**
* Update is happening because some side effect of the reevaluation is necessary. For example,
* baking intermediate geometry nodes happens during normal evaluation but does not actually
* change the final result. For baking we still want to reevaluate it.
*/
DEG_UPDATE_SOURCE_SIDE_EFFECT_REQUEST = (1 << 4),
};
/* C++ wrapper around DNA's CustomData_MeshMasks struct. */
struct DEGCustomDataMeshMasks {
uint64_t vert_mask;
uint64_t edge_mask;
uint64_t face_mask;
uint64_t loop_mask;
uint64_t poly_mask;
DEGCustomDataMeshMasks() : vert_mask(0), edge_mask(0), face_mask(0), loop_mask(0), poly_mask(0)
{
}
explicit DEGCustomDataMeshMasks(const CustomData_MeshMasks *other);
DEGCustomDataMeshMasks &operator|=(const DEGCustomDataMeshMasks &other)
{
this->vert_mask |= other.vert_mask;
this->edge_mask |= other.edge_mask;
this->face_mask |= other.face_mask;
this->loop_mask |= other.loop_mask;
this->poly_mask |= other.poly_mask;
return *this;
}
DEGCustomDataMeshMasks operator|(const DEGCustomDataMeshMasks &other) const
{
DEGCustomDataMeshMasks result;
result.vert_mask = this->vert_mask | other.vert_mask;
result.edge_mask = this->edge_mask | other.edge_mask;
result.face_mask = this->face_mask | other.face_mask;
result.loop_mask = this->loop_mask | other.loop_mask;
result.poly_mask = this->poly_mask | other.poly_mask;
return result;
}
bool operator==(const DEGCustomDataMeshMasks &other) const
{
return (this->vert_mask == other.vert_mask && this->edge_mask == other.edge_mask &&
this->face_mask == other.face_mask && this->loop_mask == other.loop_mask &&
this->poly_mask == other.poly_mask);
}
bool operator!=(const DEGCustomDataMeshMasks &other) const
{
return !(*this == other);
}
static DEGCustomDataMeshMasks MaskVert(const uint64_t vert_mask)
{
DEGCustomDataMeshMasks result;
result.vert_mask = vert_mask;
return result;
}
static DEGCustomDataMeshMasks MaskEdge(const uint64_t edge_mask)
{
DEGCustomDataMeshMasks result;
result.edge_mask = edge_mask;
return result;
}
static DEGCustomDataMeshMasks MaskFace(const uint64_t face_mask)
{
DEGCustomDataMeshMasks result;
result.face_mask = face_mask;
return result;
}
static DEGCustomDataMeshMasks MaskLoop(const uint64_t loop_mask)
{
DEGCustomDataMeshMasks result;
result.loop_mask = loop_mask;
return result;
}
static DEGCustomDataMeshMasks MaskPoly(const uint64_t poly_mask)
{
DEGCustomDataMeshMasks result;
result.poly_mask = poly_mask;
return result;
}
};
} // namespace blender::deg