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 155 additions and 58 deletions
Showing only changes of commit e331fb5298 - Show all commits

View File

@ -19,6 +19,7 @@
struct Mesh;
struct PointCloud;
struct VolumeGrid;
namespace blender::fn {
namespace multi_function {
class MultiFunction;

View File

@ -17,23 +17,81 @@
# include <openvdb/openvdb.h>
#endif
#if 0
struct VolumeGeometryGrid {
public:
VolumeGeometryGrid();
~VolumeGeometryGrid();
namespace blender::bke {
VolumeGridType type() const;
#ifdef WITH_OPENVDB
int64_t active_voxel_num() const;
/**
* Result when looking up an attribute from some geometry with read and write access. After writing
* to the attribute, the #finish method has to be called. This may invalidate caches based on this
* attribute.
*/
template<typename T> struct AttributeGridWriter {
// using GridType =
# ifdef WITH_OPENVDB
openvdb::GridBase::Ptr grid_;
# endif
/**
* Grid pointer giving read and write access to the attribute. This may be empty.
*/
GridT::Ptr VMutableArray<T> varray;
/**
* Domain where the attribute is stored on the geometry. Also determines the size of the virtual
* array.
*/
eAttrDomain domain;
/**
* A function that has to be called after the attribute has been edited. This may be empty.
*/
std::function<void()> tag_modified_fn;
operator bool() const
{
return this->varray;
}
/**
* Has to be called after the attribute has been modified.
*/
void finish()
{
if (this->tag_modified_fn) {
this->tag_modified_fn();
}
}
};
#endif
namespace blender::bke {
/**
* A generic version of #AttributeWriter.
*/
struct GAttributeGridWriter {
VolumeGrid *grid;
eAttrDomain domain;
std::function<void()> tag_modified_fn;
operator bool() const
{
return this->grid;
}
void finish()
{
if (this->tag_modified_fn) {
this->tag_modified_fn();
}
}
template<typename T> AttributeWriter<T> typed() const
{
return {grid.typed<T>(), domain, tag_modified_fn};
}
};
/* OLD CODE
* OLD CODE
* OLD CODE
* OLD CODE
* OLD CODE */
#ifdef WITH_OPENVDB

View File

@ -0,0 +1,67 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
/** \file
* \ingroup bli
*/
#ifdef WITH_OPENVDB
# include <openvdb/openvdb.h>
#endif
namespace blender {
class CPPType;
class ResourceScope;
namespace volume_mask {
/* Mask defined by active voxels of the grid. */
class VolumeMask {
#ifdef WITH_OPENVDB
const openvdb::MaskGrid &grid_;
#endif
public:
bool is_empty() const;
int64_t min_voxel_count() const;
#ifdef WITH_OPENVDB
const openvdb::MaskGrid &grid() const
{
return grid_;
}
#endif
};
} // namespace volume_mask
using volume_mask::VolumeMask;
struct VolumeGrid {
#ifdef WITH_OPENVDB
openvdb::GridBase::Ptr grid_ = nullptr;
#endif
/* Create an empty grid with a background value. */
static VolumeGrid create(ResourceScope &scope,
const CPPType &type,
const void *background_value);
/* Create an empty grid with the type default as background value. */
static VolumeGrid create(ResourceScope &scope, const CPPType &type);
/* Create a grid with the active volume mask voxels. */
static VolumeGrid create(ResourceScope &scope,
const CPPType &type,
const VolumeMask &mask,
const void *inactive_value,
const void *active_value);
int64_t voxel_count() const;
bool is_empty() const;
operator bool() const;
};
} // namespace blender

View File

@ -380,6 +380,7 @@ set(SRC
BLI_vector_set_slots.hh
BLI_virtual_array.hh
BLI_virtual_vector_array.hh
BLI_volume.hh
BLI_voronoi_2d.h
BLI_voxel.h
BLI_winstuff.h
@ -435,6 +436,20 @@ if(WITH_GMP)
)
endif()
if(WITH_OPENVDB)
list(APPEND INC
../../../intern/openvdb
)
list(APPEND INC_SYS
${OPENVDB_INCLUDE_DIRS}
)
list(APPEND LIB
bf_intern_openvdb
${OPENVDB_LIBRARIES}
)
add_definitions(-DWITH_OPENVDB ${OPENVDB_DEFINITIONS})
endif()
if(WIN32)
if(WITH_BLENDER_THUMBNAILER)
# Needed for querying the `thumbnailer .dll` in `winstuff.c`.

View File

@ -14,60 +14,16 @@ namespace blender {
class CPPType;
class ResourceScope;
template<typename T> class VArray;
class VolumeGrid;
class VolumeMask;
namespace fn {
class GFieldRef;
}
} // namespace blender
namespace blender::volume_mask {
/* XXX Placeholder, this will define the grid voxels on which volume fields are evaluated. */
class VolumeMask {
#ifdef WITH_OPENVDB
const openvdb::MaskGrid &grid_;
#endif
public:
bool is_empty() const;
int64_t min_voxel_count() const;
#ifdef WITH_OPENVDB
const openvdb::MaskGrid &grid() const
{
return grid_;
}
#endif
};
} // namespace blender::volume_mask
namespace blender::fn {
using volume_mask::VolumeMask;
struct VolumeGrid {
#ifdef WITH_OPENVDB
openvdb::GridBase::Ptr grid_ = nullptr;
#endif
/* Create an empty grid with a background value. */
static VolumeGrid create(ResourceScope &scope,
const CPPType &type,
const void *background_value);
/* Create an empty grid with the type default as background value. */
static VolumeGrid create(ResourceScope &scope, const CPPType &type);
/* Create a grid with the active volume mask voxels. */
static VolumeGrid create(ResourceScope &scope,
const CPPType &type,
const VolumeMask &mask,
const void *inactive_value,
const void *active_value);
int64_t voxel_count() const;
bool is_empty() const;
operator bool() const;
};
void evaluate_procedure_on_varying_volume_fields(ResourceScope &scope,
const VolumeMask &mask,
const mf::Procedure &procedure,