WIP: Volume grid attribute support in geometry nodes #110044
|
@ -19,6 +19,7 @@
|
|||
|
||||
struct Mesh;
|
||||
struct PointCloud;
|
||||
struct VolumeGrid;
|
||||
namespace blender::fn {
|
||||
namespace multi_function {
|
||||
class MultiFunction;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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`.
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue