WIP: Volume grid attribute support in geometry nodes #110044

Closed
Lukas Tönne wants to merge 130 commits from LukasTonne/blender:geometry-nodes-flip into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
5 changed files with 27 additions and 14 deletions
Showing only changes of commit 1d86f7cdad - Show all commits

View File

@ -62,7 +62,7 @@ template<typename T> struct AttributeGridWriter {
/**
* Grid pointer giving read and write access to the attribute. This may be empty.
*/
volume::Grid<T> grid;
volume::MutableGrid<T> grid;
/**
* Domain where the attribute is stored on the geometry. Also determines the size of the
* virtual array.
@ -121,7 +121,7 @@ struct GAttributeGridReader {
* A generic version of #AttributeWriter.
*/
struct GAttributeGridWriter {
volume::GGrid &grid;
volume::GMutableGrid &grid;
eAttrDomain domain;
std::function<void()> tag_modified_fn;

View File

@ -571,14 +571,14 @@ bool try_capture_field_on_geometry(GeometryComponent &component,
}
if (GAttributeGridWriter dst_attribute = attributes.lookup_grid_for_write(attribute_id)) {
const bke::GeometryFieldContext field_context{component, domain};
fn::VolumeFieldEvaluator evaluator{field_context, domain_size};
fn::VolumeFieldEvaluator evaluator{field_context};
evaluator.add(validator.validate_field_if_necessary(field));
evaluator.set_selection(selection);
evaluator.evaluate();
const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
const volume::GridMask selection = evaluator.get_evaluated_selection_as_mask();
array_utils::copy(evaluator.get_evaluated(0), selection, dst_attribute.span);
dst_attribute.grid.try_copy_masked(evaluator.get_evaluated(0), selection);
dst_attribute.finish();
return true;

View File

@ -145,7 +145,9 @@ class GridMask {
GridMask(const GridMask &other) = default;
GridMask &operator=(const GridMask &other)
{
#ifdef WITH_OPENVDB
grid_ = other.grid_;
#endif
return *this;
}
@ -197,7 +199,9 @@ class GMutableGrid {
operator GGrid() const
{
return {grid_};
#ifdef WITH_OPENVDB
return GGrid{grid_};
#endif
}
/* Create an empty grid with a background value. */
@ -213,7 +217,8 @@ class GMutableGrid {
const void *inactive_value,
const void *active_value);
bool try_assign(const GMutableGrid &other);
bool try_assign(const GGrid &other);
bool try_copy_masked(const GGrid &other, const GridMask &selection);
int64_t voxel_count() const;
bool is_empty() const;

View File

@ -20,6 +20,8 @@ const openvdb::MaskGrid::ConstPtr empty_grid_ = openvdb::MaskGrid::create();
GridMask GridMask::from_bools(const volume::GridMask &full_mask,
const volume::Grid<bool> &selection)
{
BLI_assert_unreachable();
return {};
}
bool GridMask::is_empty() const
@ -110,6 +112,16 @@ GMutableGrid GMutableGrid::create(ResourceScope &scope,
return GMutableGrid{scope.add_value<openvdb::GridBase::Ptr>(std::move(grid))};
}
bool GMutableGrid::try_assign(const GGrid & /*other*/)
{
return false;
}
bool GMutableGrid::try_copy_masked(const GGrid & /*other*/, const GridMask & /*mask*/)
{
return false;
}
template<typename T>
MutableGrid<T> MutableGrid<T>::create(ResourceScope &scope, const T &background_value)
{
@ -214,11 +226,6 @@ GGrid GGrid::create(ResourceScope & /*scope*/,
return GGrid{};
}
bool GGrid::try_assign(const GGrid &other)
{
return false;
}
template<typename T>
Grid<T> Grid<T>::create(ResourceScope & /*scope*/, const T & /*background_value*/)
{

View File

@ -178,8 +178,7 @@ class GFieldRef : public GFieldBase<const FieldNode *> {
namespace detail {
/* Utility class to make #is_field_v work. */
struct TypedFieldBase {
};
struct TypedFieldBase {};
} // namespace detail
/**
@ -525,6 +524,8 @@ class VolumeFieldEvaluator : NonMovable, NonCopyable {
{
}
VolumeFieldEvaluator(const FieldContext &context) : context_(context), mask_(GridMask()) {}
~VolumeFieldEvaluator()
{
/* While this assert isn't strictly necessary, and could be replaced with a warning,