6# include <openvdb/openvdb.h>
7# include <openvdb/tools/Composite.h>
37 static const auto make_available = [](
bNode &
node) {
47 .structure_type(StructureType::Grid);
54 .structure_type(StructureType::Grid);
65 first_grid.available(
false);
68 first_grid.available(
true);
86static std::optional<std::string> validate_sdf_grid(
const openvdb::FloatGrid &grid)
88 if (grid.background() <= 0.0f) {
89 return "SDF background value must be greater than zero";
96 bke::VolumeGrid<float> operand;
97 bke::VolumeTreeAccessToken tree_token;
98 openvdb::FloatGrid &grid;
115 std::optional<ResultData>
result;
123 bke::VolumeTreeAccessToken tree_token;
124 openvdb::FloatGrid &grid = primary.grid_for_write(tree_token);
125 if (std::optional error = validate_sdf_grid(grid)) {
131 result.emplace(ResultData{std::move(primary), std::move(tree_token), grid});
139 bke::VolumeTreeAccessToken tree_token;
140 std::shared_ptr<openvdb::FloatGrid> resampled_storage;
141 openvdb::FloatGrid &grid =
142 result ? geometry::resample_sdf_grid_if_necessary(
143 operand, tree_token,
result->grid.transform(), resampled_storage) :
144 operand.grid_for_write(tree_token);
145 if (std::optional error = validate_sdf_grid(grid)) {
154 openvdb::tools::csgIntersection(
result->grid, grid);
157 openvdb::tools::csgUnion(
result->grid, grid);
160 openvdb::tools::csgDifference(
result->grid, grid);
164 catch (
const openvdb::Exception & ) {
169 result->operand->tag_tree_modified();
174 result.emplace(ResultData{std::move(operand), std::move(tree_token), grid});
196 "Keep the part of the grids that is common between all operands"},
197 {int(
Operation::Union),
"UNION", 0,
"Union",
"Combine grids in an additive way"},
202 "Combine grids in a subtractive way"},
203 {0,
nullptr, 0,
nullptr,
nullptr},
219 ntype.
ui_name =
"SDF Grid Boolean";
220 ntype.
ui_description =
"Cut, subtract, or join multiple SDF volume grid inputs";
#define NODE_CLASS_GEOMETRY
#define GEO_NODE_SDF_GRID_BOOLEAN
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
DBVT_INLINE bool Intersect(const btDbvtAabbMm &a, const btDbvtAabbMm &b)
void error_message_add(const NodeWarningType type, StringRef message) const
T extract_input(const UString identifier)
const bNode & node() const
void set_default_remaining_outputs()
void set_output(const UString identifier, T &&value)
StructureType structure_type
void make_available(bNode &node) const
void node_register_type(bNodeType &ntype)
static void node_rna(StructRNA *srna)
static void node_init(bNodeTree *, bNode *node)
static void node_register()
static void node_geo_exec(GeoNodeExecParams params)
static void node_declare(NodeDeclarationBuilder &b)
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
void node_geo_exec_with_missing_openvdb(GeoNodeExecParams ¶ms)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
std::string ui_description
NodeGeometryExecFunction geometry_node_execute
void(*) initfunc(bNodeTree *ntree, bNode *node)
const char * enum_name_legacy
NodeDeclareFunction declare
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)