2023-08-15 16:20:26 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2020-12-02 13:25:25 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
|
|
|
*/
|
|
|
|
|
Cleanup: fewer iostreams related includes from BLI/BKE headers
Including <iostream> or similar headers is quite expensive, since it
also pulls in things like <locale> and so on. In many BLI headers,
iostreams are only used to implement some sort of "debug print",
or an operator<< for ostream.
Change some of the commonly used places to instead include <iosfwd>,
which is the standard way of forward-declaring iostreams related
classes, and move the actual debug-print / operator<< implementations
into .cc files.
This is not done for templated classes though (it would be possible
to provide explicit operator<< instantiations somewhere in the
source file, but that would lead to hard-to-figure-out linker error
whenever someone would add a different template type). There, where
possible, I changed from full <iostream> include to only the needed
<ostream> part.
For Span<T>, I just removed print_as_lines since it's not used by
anything. It could be moved into a .cc file using a similar approach
as above if needed.
Doing full blender build changes include counts this way:
- <iostream> 1986 -> 978
- <sstream> 2880 -> 925
It does not affect the total build time much though, mostly because
towards the end of it there's just several CPU cores finishing
compiling OpenVDB related source files.
Pull Request: https://projects.blender.org/blender/blender/pulls/111046
2023-08-11 11:27:56 +02:00
|
|
|
#include <iosfwd>
|
Geometry Nodes: new geometry attribute API
Currently, there are two attribute API. The first, defined in `BKE_attribute.h` is
accessible from RNA and C code. The second is implemented with `GeometryComponent`
and is only accessible in C++ code. The second is widely used, but only being
accessible through the `GeometrySet` API makes it awkward to use, and even impossible
for types that don't correspond directly to a geometry component like `CurvesGeometry`.
This patch adds a new attribute API, designed to replace the `GeometryComponent`
attribute API now, and to eventually replace or be the basis of the other one.
The basic idea is that there is an `AttributeAccessor` class that allows code to
interact with a set of attributes owned by some geometry. The accessor itself has
no ownership. `AttributeAccessor` is a simple type that can be passed around by
value. That makes it easy to return it from functions and to store it in containers.
For const-correctness, there is also a `MutableAttributeAccessor` that allows
changing individual and can add or remove attributes.
Currently, `AttributeAccessor` is composed of two pointers. The first is a pointer
to the owner of the attribute data. The second is a pointer to a struct with
function pointers, that is similar to a virtual function table. The functions
know how to access attributes on the owner.
The actual attribute access for geometries is still implemented with the `AttributeProvider`
pattern, which makes it easy to support different sources of attributes on a
geometry and simplifies dealing with built-in attributes.
There are different ways to get an attribute accessor for a geometry:
* `GeometryComponent.attributes()`
* `CurvesGeometry.attributes()`
* `bke::mesh_attributes(const Mesh &)`
* `bke::pointcloud_attributes(const PointCloud &)`
All of these also have a `_for_write` variant that returns a `MutabelAttributeAccessor`.
Differential Revision: https://developer.blender.org/D15280
2022-07-08 16:16:56 +02:00
|
|
|
#include <mutex>
|
2020-12-02 13:25:25 +01:00
|
|
|
|
2023-06-16 14:08:18 +02:00
|
|
|
#include "BLI_bounds_types.hh"
|
2021-09-23 17:50:33 +02:00
|
|
|
#include "BLI_function_ref.hh"
|
2020-12-02 13:25:25 +01:00
|
|
|
#include "BLI_map.hh"
|
2023-08-13 09:50:52 +02:00
|
|
|
#include "BLI_math_vector_types.hh"
|
2020-12-02 13:25:25 +01:00
|
|
|
|
Geometry Nodes: new geometry attribute API
Currently, there are two attribute API. The first, defined in `BKE_attribute.h` is
accessible from RNA and C code. The second is implemented with `GeometryComponent`
and is only accessible in C++ code. The second is widely used, but only being
accessible through the `GeometrySet` API makes it awkward to use, and even impossible
for types that don't correspond directly to a geometry component like `CurvesGeometry`.
This patch adds a new attribute API, designed to replace the `GeometryComponent`
attribute API now, and to eventually replace or be the basis of the other one.
The basic idea is that there is an `AttributeAccessor` class that allows code to
interact with a set of attributes owned by some geometry. The accessor itself has
no ownership. `AttributeAccessor` is a simple type that can be passed around by
value. That makes it easy to return it from functions and to store it in containers.
For const-correctness, there is also a `MutableAttributeAccessor` that allows
changing individual and can add or remove attributes.
Currently, `AttributeAccessor` is composed of two pointers. The first is a pointer
to the owner of the attribute data. The second is a pointer to a struct with
function pointers, that is similar to a virtual function table. The functions
know how to access attributes on the owner.
The actual attribute access for geometries is still implemented with the `AttributeProvider`
pattern, which makes it easy to support different sources of attributes on a
geometry and simplifies dealing with built-in attributes.
There are different ways to get an attribute accessor for a geometry:
* `GeometryComponent.attributes()`
* `CurvesGeometry.attributes()`
* `bke::mesh_attributes(const Mesh &)`
* `bke::pointcloud_attributes(const PointCloud &)`
All of these also have a `_for_write` variant that returns a `MutabelAttributeAccessor`.
Differential Revision: https://developer.blender.org/D15280
2022-07-08 16:16:56 +02:00
|
|
|
#include "BKE_attribute.hh"
|
2020-12-02 13:25:25 +01:00
|
|
|
|
2022-02-28 16:46:34 +01:00
|
|
|
struct Curves;
|
2021-07-16 03:48:54 +02:00
|
|
|
struct Curve;
|
2020-12-02 13:25:25 +01:00
|
|
|
struct Mesh;
|
2020-12-16 06:26:23 +01:00
|
|
|
struct PointCloud;
|
2021-01-21 10:32:42 +01:00
|
|
|
struct Volume;
|
2023-07-26 13:59:37 +02:00
|
|
|
struct GreasePencil;
|
2023-09-19 19:48:48 +02:00
|
|
|
namespace blender::bke {
|
|
|
|
class ComponentAttributeProviders;
|
|
|
|
class CurvesEditHints;
|
|
|
|
class Instances;
|
|
|
|
class GeometryComponent;
|
2023-10-12 15:42:04 +02:00
|
|
|
class GreasePencilEditHints;
|
2023-09-19 19:48:48 +02:00
|
|
|
} // namespace blender::bke
|
2020-12-02 13:25:25 +01:00
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
namespace blender::bke {
|
|
|
|
|
2023-07-26 13:59:37 +02:00
|
|
|
#define GEO_COMPONENT_TYPE_ENUM_SIZE 7
|
2023-06-15 22:18:28 +02:00
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
enum class GeometryOwnershipType {
|
|
|
|
/* The geometry is owned. This implies that it can be changed. */
|
|
|
|
Owned = 0,
|
|
|
|
/* The geometry can be changed, but someone else is responsible for freeing it. */
|
|
|
|
Editable = 1,
|
|
|
|
/* The geometry cannot be changed and someone else is responsible for freeing it. */
|
|
|
|
ReadOnly = 2,
|
|
|
|
};
|
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
using GeometryComponentPtr = ImplicitSharingPtr<GeometryComponent>;
|
BLI: support weak users and version in implicit sharing info
The main goal of these changes is to support checking if some data has
been changed over time. This is used by the WIP simulation nodes during
baking to detect which attributes have to be stored in every frame because
they have changed.
By using a combination of a weak user count and a version counter, it is
possible to detect that an attribute (or any data controlled by implicit
sharing) has not been changed with O(1) memory and time. It's still
possible that the data has been changed multiple times and is the same
in the end and beginning of course. That wouldn't be detected using this
mechanism.
The `ImplicitSharingInfo` struct has a new weak user count. A weak
reference is one that does not keep the referenced data alive, but makes sure
that the `ImplicitSharingInfo` itself is not deleted. If some piece of
data has one strong and multiple weak users, it is still mutable. If the
strong user count goes down to zero, the referenced data is freed.
Remaining weak users can check for this condition using `is_expired`.
This is a bit similar to `std::weak_ptr` but there is an important difference:
a weak user can not become a strong user while one can create a `shared_ptr`
from a `weak_ptr`. This restriction is necessary, because some code might
be changing the referenced data assuming that it is the only owner. If
another thread suddenly adds a new owner, the data would be shared again
and the first thread would not have been allowed to modify the data in
the first place.
There is also a new integer version counter in `ImplicitSharingInfo`.
It is incremented whenever some code wants to modify the referenced data.
Obviously, this can only be done when the data is not shared because then
it would be immutable. By comparing an old and new version number of the
same sharing info, one can check if the data has been modified. One has
to keep a weak reference to the sharing info together with the old version
number to ensure that the new sharing info is still the same as the old one.
Without this, it can happen that the sharing info was freed and a new
one was allocated at the same pointer address. Using a strong reference
for this purpose does not work, because then the data would never be
modified because it's shared.
2023-04-28 12:03:42 +02:00
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
/**
|
2023-03-28 13:57:51 +02:00
|
|
|
* This is the base class for specialized geometry component types. A geometry component uses
|
|
|
|
* implicit sharing to avoid read-only copies. It also integrates with attribute API, which
|
|
|
|
* generalizes storing and modifying generic information on a geometry.
|
2020-12-02 13:25:25 +01:00
|
|
|
*/
|
2023-06-15 22:18:28 +02:00
|
|
|
class GeometryComponent : public ImplicitSharingMixin {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Each geometry component has a specific type. The type determines what kind of data the
|
|
|
|
* component stores. Functions modifying a geometry will usually just modify a subset of the
|
|
|
|
* component types.
|
|
|
|
* \note These values are stored in files, so they should not be reordered.
|
|
|
|
*/
|
|
|
|
enum class Type {
|
|
|
|
Mesh = 0,
|
|
|
|
PointCloud = 1,
|
|
|
|
Instance = 2,
|
|
|
|
Volume = 3,
|
|
|
|
Curve = 4,
|
|
|
|
Edit = 5,
|
2023-07-26 13:59:37 +02:00
|
|
|
GreasePencil = 6,
|
2023-06-15 22:18:28 +02:00
|
|
|
};
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
private:
|
2023-06-15 22:18:28 +02:00
|
|
|
Type type_;
|
2020-12-02 13:25:25 +01:00
|
|
|
|
|
|
|
public:
|
2023-06-15 22:18:28 +02:00
|
|
|
GeometryComponent(Type type);
|
2021-04-08 11:07:12 +02:00
|
|
|
virtual ~GeometryComponent() = default;
|
2023-06-15 22:18:28 +02:00
|
|
|
static GeometryComponentPtr create(Type component_type);
|
2020-12-02 13:25:25 +01:00
|
|
|
|
Geometry Nodes: new geometry attribute API
Currently, there are two attribute API. The first, defined in `BKE_attribute.h` is
accessible from RNA and C code. The second is implemented with `GeometryComponent`
and is only accessible in C++ code. The second is widely used, but only being
accessible through the `GeometrySet` API makes it awkward to use, and even impossible
for types that don't correspond directly to a geometry component like `CurvesGeometry`.
This patch adds a new attribute API, designed to replace the `GeometryComponent`
attribute API now, and to eventually replace or be the basis of the other one.
The basic idea is that there is an `AttributeAccessor` class that allows code to
interact with a set of attributes owned by some geometry. The accessor itself has
no ownership. `AttributeAccessor` is a simple type that can be passed around by
value. That makes it easy to return it from functions and to store it in containers.
For const-correctness, there is also a `MutableAttributeAccessor` that allows
changing individual and can add or remove attributes.
Currently, `AttributeAccessor` is composed of two pointers. The first is a pointer
to the owner of the attribute data. The second is a pointer to a struct with
function pointers, that is similar to a virtual function table. The functions
know how to access attributes on the owner.
The actual attribute access for geometries is still implemented with the `AttributeProvider`
pattern, which makes it easy to support different sources of attributes on a
geometry and simplifies dealing with built-in attributes.
There are different ways to get an attribute accessor for a geometry:
* `GeometryComponent.attributes()`
* `CurvesGeometry.attributes()`
* `bke::mesh_attributes(const Mesh &)`
* `bke::pointcloud_attributes(const PointCloud &)`
All of these also have a `_for_write` variant that returns a `MutabelAttributeAccessor`.
Differential Revision: https://developer.blender.org/D15280
2022-07-08 16:16:56 +02:00
|
|
|
int attribute_domain_size(eAttrDomain domain) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get access to the attributes in this geometry component. May return none if the geometry does
|
|
|
|
* not support the attribute system.
|
|
|
|
*/
|
2023-06-15 22:18:28 +02:00
|
|
|
virtual std::optional<AttributeAccessor> attributes() const;
|
|
|
|
virtual std::optional<MutableAttributeAccessor> attributes_for_write();
|
Geometry Nodes: new geometry attribute API
Currently, there are two attribute API. The first, defined in `BKE_attribute.h` is
accessible from RNA and C code. The second is implemented with `GeometryComponent`
and is only accessible in C++ code. The second is widely used, but only being
accessible through the `GeometrySet` API makes it awkward to use, and even impossible
for types that don't correspond directly to a geometry component like `CurvesGeometry`.
This patch adds a new attribute API, designed to replace the `GeometryComponent`
attribute API now, and to eventually replace or be the basis of the other one.
The basic idea is that there is an `AttributeAccessor` class that allows code to
interact with a set of attributes owned by some geometry. The accessor itself has
no ownership. `AttributeAccessor` is a simple type that can be passed around by
value. That makes it easy to return it from functions and to store it in containers.
For const-correctness, there is also a `MutableAttributeAccessor` that allows
changing individual and can add or remove attributes.
Currently, `AttributeAccessor` is composed of two pointers. The first is a pointer
to the owner of the attribute data. The second is a pointer to a struct with
function pointers, that is similar to a virtual function table. The functions
know how to access attributes on the owner.
The actual attribute access for geometries is still implemented with the `AttributeProvider`
pattern, which makes it easy to support different sources of attributes on a
geometry and simplifies dealing with built-in attributes.
There are different ways to get an attribute accessor for a geometry:
* `GeometryComponent.attributes()`
* `CurvesGeometry.attributes()`
* `bke::mesh_attributes(const Mesh &)`
* `bke::pointcloud_attributes(const PointCloud &)`
All of these also have a `_for_write` variant that returns a `MutabelAttributeAccessor`.
Differential Revision: https://developer.blender.org/D15280
2022-07-08 16:16:56 +02:00
|
|
|
|
2023-12-01 11:23:00 +01:00
|
|
|
/**
|
|
|
|
* Copies the component. The returned component only has a single user and is therefor mutable.
|
|
|
|
*/
|
|
|
|
virtual GeometryComponentPtr copy() const = 0;
|
2020-12-02 13:25:25 +01:00
|
|
|
|
BLI: support weak users and version in implicit sharing info
The main goal of these changes is to support checking if some data has
been changed over time. This is used by the WIP simulation nodes during
baking to detect which attributes have to be stored in every frame because
they have changed.
By using a combination of a weak user count and a version counter, it is
possible to detect that an attribute (or any data controlled by implicit
sharing) has not been changed with O(1) memory and time. It's still
possible that the data has been changed multiple times and is the same
in the end and beginning of course. That wouldn't be detected using this
mechanism.
The `ImplicitSharingInfo` struct has a new weak user count. A weak
reference is one that does not keep the referenced data alive, but makes sure
that the `ImplicitSharingInfo` itself is not deleted. If some piece of
data has one strong and multiple weak users, it is still mutable. If the
strong user count goes down to zero, the referenced data is freed.
Remaining weak users can check for this condition using `is_expired`.
This is a bit similar to `std::weak_ptr` but there is an important difference:
a weak user can not become a strong user while one can create a `shared_ptr`
from a `weak_ptr`. This restriction is necessary, because some code might
be changing the referenced data assuming that it is the only owner. If
another thread suddenly adds a new owner, the data would be shared again
and the first thread would not have been allowed to modify the data in
the first place.
There is also a new integer version counter in `ImplicitSharingInfo`.
It is incremented whenever some code wants to modify the referenced data.
Obviously, this can only be done when the data is not shared because then
it would be immutable. By comparing an old and new version number of the
same sharing info, one can check if the data has been modified. One has
to keep a weak reference to the sharing info together with the old version
number to ensure that the new sharing info is still the same as the old one.
Without this, it can happen that the sharing info was freed and a new
one was allocated at the same pointer address. Using a strong reference
for this purpose does not work, because then the data would never be
modified because it's shared.
2023-04-28 12:03:42 +02:00
|
|
|
/** Remove referenced data from the geometry component. */
|
|
|
|
virtual void clear() = 0;
|
|
|
|
|
2021-04-08 17:35:06 +02:00
|
|
|
/* Direct data is everything except for instances of objects/collections.
|
|
|
|
* If this returns true, the geometry set can be cached and is still valid after e.g. modifier
|
|
|
|
* evaluation ends. Instances can only be valid as long as the data they instance is valid. */
|
|
|
|
virtual bool owns_direct_data() const = 0;
|
|
|
|
virtual void ensure_owns_direct_data() = 0;
|
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
Type type() const;
|
2020-12-02 13:25:25 +01:00
|
|
|
|
|
|
|
virtual bool is_empty() const;
|
2023-03-28 13:57:51 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
void delete_self() override;
|
BLI: support weak users and version in implicit sharing info
The main goal of these changes is to support checking if some data has
been changed over time. This is used by the WIP simulation nodes during
baking to detect which attributes have to be stored in every frame because
they have changed.
By using a combination of a weak user count and a version counter, it is
possible to detect that an attribute (or any data controlled by implicit
sharing) has not been changed with O(1) memory and time. It's still
possible that the data has been changed multiple times and is the same
in the end and beginning of course. That wouldn't be detected using this
mechanism.
The `ImplicitSharingInfo` struct has a new weak user count. A weak
reference is one that does not keep the referenced data alive, but makes sure
that the `ImplicitSharingInfo` itself is not deleted. If some piece of
data has one strong and multiple weak users, it is still mutable. If the
strong user count goes down to zero, the referenced data is freed.
Remaining weak users can check for this condition using `is_expired`.
This is a bit similar to `std::weak_ptr` but there is an important difference:
a weak user can not become a strong user while one can create a `shared_ptr`
from a `weak_ptr`. This restriction is necessary, because some code might
be changing the referenced data assuming that it is the only owner. If
another thread suddenly adds a new owner, the data would be shared again
and the first thread would not have been allowed to modify the data in
the first place.
There is also a new integer version counter in `ImplicitSharingInfo`.
It is incremented whenever some code wants to modify the referenced data.
Obviously, this can only be done when the data is not shared because then
it would be immutable. By comparing an old and new version number of the
same sharing info, one can check if the data has been modified. One has
to keep a weak reference to the sharing info together with the old version
number to ensure that the new sharing info is still the same as the old one.
Without this, it can happen that the sharing info was freed and a new
one was allocated at the same pointer address. Using a strong reference
for this purpose does not work, because then the data would never be
modified because it's shared.
2023-04-28 12:03:42 +02:00
|
|
|
void delete_data_only() override;
|
2020-12-02 13:25:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
inline constexpr bool is_geometry_component_v = std::is_base_of_v<GeometryComponent, T>;
|
|
|
|
|
|
|
|
/**
|
2021-12-07 19:04:32 +01:00
|
|
|
* A geometry set is a container for multiple kinds of geometry. It does not own geometry directly
|
|
|
|
* itself, instead geometry is owned by multiple #GeometryComponents, and the geometry set
|
|
|
|
* increases the user count of each component, so they avoid losing the data. This means
|
|
|
|
* individual components might be shared between multiple geometries and other code. Shared
|
|
|
|
* components are copied automatically when write access is requested.
|
|
|
|
*
|
2021-12-13 06:00:39 +01:00
|
|
|
* The components usually do not store data directly, but keep a reference to a data
|
|
|
|
* structure defined elsewhere. There is at most one component of each type:
|
2021-12-07 19:04:32 +01:00
|
|
|
* - #MeshComponent
|
|
|
|
* - #CurveComponent
|
|
|
|
* - #PointCloudComponent
|
|
|
|
* - #InstancesComponent
|
|
|
|
* - #VolumeComponent
|
2023-07-26 13:59:37 +02:00
|
|
|
* - #GreasePencilComponent
|
2020-12-02 13:25:25 +01:00
|
|
|
*
|
|
|
|
* Copying a geometry set is a relatively cheap operation, because it does not copy the referenced
|
2021-12-07 19:04:32 +01:00
|
|
|
* geometry components, so #GeometrySet can often be passed or moved by value.
|
2020-12-02 13:25:25 +01:00
|
|
|
*/
|
|
|
|
struct GeometrySet {
|
|
|
|
private:
|
2023-06-15 22:18:28 +02:00
|
|
|
/* Indexed by #GeometryComponent::Type. */
|
2021-12-05 15:10:11 +01:00
|
|
|
std::array<GeometryComponentPtr, GEO_COMPONENT_TYPE_ENUM_SIZE> components_;
|
2020-12-02 13:25:25 +01:00
|
|
|
|
|
|
|
public:
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* The methods are defaulted here so that they are not instantiated in every translation unit.
|
|
|
|
*/
|
2021-10-03 16:58:33 +02:00
|
|
|
GeometrySet();
|
|
|
|
GeometrySet(const GeometrySet &other);
|
|
|
|
GeometrySet(GeometrySet &&other);
|
|
|
|
~GeometrySet();
|
|
|
|
GeometrySet &operator=(const GeometrySet &other);
|
|
|
|
GeometrySet &operator=(GeometrySet &&other);
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* This method can only be used when the geometry set is mutable. It returns a mutable geometry
|
|
|
|
* component of the given type.
|
|
|
|
*/
|
2023-06-15 22:18:28 +02:00
|
|
|
GeometryComponent &get_component_for_write(GeometryComponent::Type component_type);
|
2020-12-02 13:25:25 +01:00
|
|
|
template<typename Component> Component &get_component_for_write()
|
|
|
|
{
|
|
|
|
BLI_STATIC_ASSERT(is_geometry_component_v<Component>, "");
|
|
|
|
return static_cast<Component &>(this->get_component_for_write(Component::static_type));
|
|
|
|
}
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Get the component of the given type. Might return null if the component does not exist yet.
|
|
|
|
*/
|
2023-08-03 17:09:18 +02:00
|
|
|
const GeometryComponent *get_component(GeometryComponent::Type component_type) const;
|
|
|
|
template<typename Component> const Component *get_component() const
|
2020-12-02 13:25:25 +01:00
|
|
|
{
|
|
|
|
BLI_STATIC_ASSERT(is_geometry_component_v<Component>, "");
|
2023-08-03 17:09:18 +02:00
|
|
|
return static_cast<const Component *>(get_component(Component::static_type));
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
bool has(const GeometryComponent::Type component_type) const;
|
2020-12-02 13:25:25 +01:00
|
|
|
template<typename Component> bool has() const
|
|
|
|
{
|
|
|
|
BLI_STATIC_ASSERT(is_geometry_component_v<Component>, "");
|
|
|
|
return this->has(Component::static_type);
|
|
|
|
}
|
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
void remove(const GeometryComponent::Type component_type);
|
2020-12-02 13:25:25 +01:00
|
|
|
template<typename Component> void remove()
|
|
|
|
{
|
|
|
|
BLI_STATIC_ASSERT(is_geometry_component_v<Component>, "");
|
|
|
|
return this->remove(Component::static_type);
|
|
|
|
}
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Remove all geometry components with types that are not in the provided list.
|
|
|
|
*/
|
2023-06-15 22:18:28 +02:00
|
|
|
void keep_only(const Span<GeometryComponent::Type> component_types);
|
2022-07-22 15:39:41 +02:00
|
|
|
/**
|
|
|
|
* Keeps the provided geometry types, but also instances and edit data.
|
|
|
|
* Instances must not be removed while using #modify_geometry_sets.
|
|
|
|
*/
|
2023-06-15 22:18:28 +02:00
|
|
|
void keep_only_during_modify(const Span<GeometryComponent::Type> component_types);
|
2022-07-22 15:39:41 +02:00
|
|
|
void remove_geometry_during_modify();
|
2021-09-28 15:52:04 +02:00
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
void add(const GeometryComponent &component);
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Get all geometry components in this geometry set for read-only access.
|
|
|
|
*/
|
2023-08-03 17:09:18 +02:00
|
|
|
Vector<const GeometryComponent *> get_components() const;
|
2021-02-19 12:29:37 +01:00
|
|
|
|
2023-06-16 14:08:18 +02:00
|
|
|
std::optional<Bounds<float3>> compute_boundbox_without_instances() const;
|
2020-12-02 13:25:25 +01:00
|
|
|
|
|
|
|
friend std::ostream &operator<<(std::ostream &stream, const GeometrySet &geometry_set);
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Remove all geometry components from the geometry set.
|
|
|
|
*/
|
2021-03-30 12:34:05 +02:00
|
|
|
void clear();
|
|
|
|
|
2021-09-06 18:22:24 +02:00
|
|
|
bool owns_direct_data() const;
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Make sure that the geometry can be cached. This does not ensure ownership of object/collection
|
2021-12-07 19:04:32 +01:00
|
|
|
* instances. This is necessary because sometimes components only have read-only or editing
|
|
|
|
* access to their data, which might be freed later if this geometry set outlasts the data.
|
2021-12-07 07:19:15 +01:00
|
|
|
*/
|
2021-04-08 17:35:06 +02:00
|
|
|
void ensure_owns_direct_data();
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
/**
|
|
|
|
* Same as #ensure_owns_direct_data but also turns object/collection instances into geometry
|
|
|
|
* instances so that they can be owned.
|
|
|
|
*/
|
|
|
|
void ensure_owns_all_data();
|
2021-04-08 17:35:06 +02:00
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
using AttributeForeachCallback = FunctionRef<void(const AttributeIDRef &attribute_id,
|
|
|
|
const AttributeMetaData &meta_data,
|
|
|
|
const GeometryComponent &component)>;
|
2021-09-23 17:50:33 +02:00
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
void attribute_foreach(Span<GeometryComponent::Type> component_types,
|
2021-09-23 17:50:33 +02:00
|
|
|
bool include_instances,
|
|
|
|
AttributeForeachCallback callback) const;
|
|
|
|
|
2023-10-13 10:08:51 +02:00
|
|
|
static void propagate_attributes_from_layer_to_instances(
|
|
|
|
const AttributeAccessor src_attributes,
|
|
|
|
MutableAttributeAccessor dst_attributes,
|
|
|
|
const AnonymousAttributePropagationInfo &propagation_info);
|
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
void gather_attributes_for_propagation(Span<GeometryComponent::Type> component_types,
|
|
|
|
GeometryComponent::Type dst_component_type,
|
|
|
|
bool include_instances,
|
|
|
|
const AnonymousAttributePropagationInfo &propagation_info,
|
|
|
|
Map<AttributeIDRef, AttributeKind> &r_attributes) const;
|
2021-09-23 17:50:33 +02:00
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
Vector<GeometryComponent::Type> gather_component_types(bool include_instances,
|
|
|
|
bool ignore_empty) const;
|
2021-10-26 20:00:03 +02:00
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
using ForeachSubGeometryCallback = FunctionRef<void(GeometrySet &geometry_set)>;
|
2021-09-27 17:35:26 +02:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Modify every (recursive) instance separately. This is often more efficient than realizing all
|
|
|
|
* instances just to change the same thing on all of them.
|
|
|
|
*/
|
2021-09-27 17:35:26 +02:00
|
|
|
void modify_geometry_sets(ForeachSubGeometryCallback callback);
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
/* Utility methods for creation. */
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Create a new geometry set that only contains the given mesh.
|
|
|
|
*/
|
2023-08-03 17:09:18 +02:00
|
|
|
static GeometrySet from_mesh(Mesh *mesh,
|
|
|
|
GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2022-06-29 17:56:17 +02:00
|
|
|
/**
|
|
|
|
* Create a new geometry set that only contains the given volume.
|
|
|
|
*/
|
2023-08-03 17:09:18 +02:00
|
|
|
static GeometrySet from_volume(Volume *volume,
|
|
|
|
GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Create a new geometry set that only contains the given point cloud.
|
|
|
|
*/
|
2023-08-03 17:09:18 +02:00
|
|
|
static GeometrySet from_pointcloud(
|
2020-12-02 13:25:25 +01:00
|
|
|
PointCloud *pointcloud, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
2022-02-28 16:53:30 +01:00
|
|
|
* Create a new geometry set that only contains the given curves.
|
2021-12-07 07:19:15 +01:00
|
|
|
*/
|
2023-08-03 17:09:18 +02:00
|
|
|
static GeometrySet from_curves(Curves *curves,
|
|
|
|
GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2022-10-17 11:39:40 +02:00
|
|
|
/**
|
|
|
|
* Create a new geometry set that only contains the given instances.
|
|
|
|
*/
|
2023-08-03 17:09:18 +02:00
|
|
|
static GeometrySet from_instances(
|
2023-06-15 22:18:28 +02:00
|
|
|
Instances *instances, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2023-07-26 13:59:37 +02:00
|
|
|
/**
|
|
|
|
* Create a new geometry set that only contains the given Grease Pencil data.
|
|
|
|
*/
|
2023-08-03 17:09:18 +02:00
|
|
|
static GeometrySet from_grease_pencil(
|
2023-07-26 13:59:37 +02:00
|
|
|
GreasePencil *grease_pencil, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2020-12-02 13:25:25 +01:00
|
|
|
|
|
|
|
/* Utility methods for access. */
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Returns true when the geometry set has a mesh component that has a mesh.
|
|
|
|
*/
|
2020-12-02 13:25:25 +01:00
|
|
|
bool has_mesh() const;
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Returns true when the geometry set has a point cloud component that has a point cloud.
|
|
|
|
*/
|
2020-12-02 13:25:25 +01:00
|
|
|
bool has_pointcloud() const;
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Returns true when the geometry set has an instances component that has at least one instance.
|
|
|
|
*/
|
2020-12-02 13:25:25 +01:00
|
|
|
bool has_instances() const;
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Returns true when the geometry set has a volume component that has a volume.
|
|
|
|
*/
|
2021-01-21 10:32:42 +01:00
|
|
|
bool has_volume() const;
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
2022-02-28 16:53:30 +01:00
|
|
|
* Returns true when the geometry set has a curves component that has a curves data-block.
|
2021-12-07 07:19:15 +01:00
|
|
|
*/
|
2022-02-28 16:53:30 +01:00
|
|
|
bool has_curves() const;
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Returns true when the geometry set has any data that is not an instance.
|
|
|
|
*/
|
2021-09-27 10:16:38 +02:00
|
|
|
bool has_realized_data() const;
|
2023-07-26 13:59:37 +02:00
|
|
|
/**
|
|
|
|
* Returns true when the geometry set has a Grease Pencil component that has grease pencil data.
|
|
|
|
*/
|
|
|
|
bool has_grease_pencil() const;
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Return true if the geometry set has any component that isn't empty.
|
|
|
|
*/
|
2021-09-28 18:36:28 +02:00
|
|
|
bool is_empty() const;
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Returns a read-only mesh or null.
|
|
|
|
*/
|
2023-08-03 17:09:18 +02:00
|
|
|
const Mesh *get_mesh() const;
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Returns a read-only point cloud of null.
|
|
|
|
*/
|
2023-08-03 17:09:18 +02:00
|
|
|
const PointCloud *get_pointcloud() const;
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Returns a read-only volume or null.
|
|
|
|
*/
|
2023-08-03 17:09:18 +02:00
|
|
|
const Volume *get_volume() const;
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
2022-02-28 16:53:30 +01:00
|
|
|
* Returns a read-only curves data-block or null.
|
2021-12-07 07:19:15 +01:00
|
|
|
*/
|
2023-08-03 17:09:18 +02:00
|
|
|
const Curves *get_curves() const;
|
2022-10-17 11:39:40 +02:00
|
|
|
/**
|
|
|
|
* Returns read-only instances or null.
|
|
|
|
*/
|
2023-08-03 17:09:18 +02:00
|
|
|
const Instances *get_instances() const;
|
2022-07-22 15:39:41 +02:00
|
|
|
/**
|
|
|
|
* Returns read-only curve edit hints or null.
|
|
|
|
*/
|
2023-08-03 17:09:18 +02:00
|
|
|
const CurvesEditHints *get_curve_edit_hints() const;
|
2023-07-26 13:59:37 +02:00
|
|
|
/**
|
|
|
|
* Returns a read-only Grease Pencil data-block or null.
|
|
|
|
*/
|
2023-08-03 17:09:18 +02:00
|
|
|
const GreasePencil *get_grease_pencil() const;
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Returns a mutable mesh or null. No ownership is transferred.
|
|
|
|
*/
|
2020-12-02 13:25:25 +01:00
|
|
|
Mesh *get_mesh_for_write();
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Returns a mutable point cloud or null. No ownership is transferred.
|
|
|
|
*/
|
2020-12-02 13:25:25 +01:00
|
|
|
PointCloud *get_pointcloud_for_write();
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Returns a mutable volume or null. No ownership is transferred.
|
|
|
|
*/
|
2021-01-21 10:32:42 +01:00
|
|
|
Volume *get_volume_for_write();
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
2022-02-28 16:53:30 +01:00
|
|
|
* Returns a mutable curves data-block or null. No ownership is transferred.
|
2021-12-07 07:19:15 +01:00
|
|
|
*/
|
2022-02-28 16:53:30 +01:00
|
|
|
Curves *get_curves_for_write();
|
2022-10-17 11:39:40 +02:00
|
|
|
/**
|
|
|
|
* Returns mutable instances or null. No ownership is transferred.
|
|
|
|
*/
|
2023-06-15 22:18:28 +02:00
|
|
|
Instances *get_instances_for_write();
|
2022-07-22 15:39:41 +02:00
|
|
|
/**
|
|
|
|
* Returns mutable curve edit hints or null.
|
|
|
|
*/
|
2023-06-15 22:18:28 +02:00
|
|
|
CurvesEditHints *get_curve_edit_hints_for_write();
|
2023-07-26 13:59:37 +02:00
|
|
|
/**
|
|
|
|
* Returns a mutable Grease Pencil data-block or null. No ownership is transferred.
|
|
|
|
*/
|
|
|
|
GreasePencil *get_grease_pencil_for_write();
|
2020-12-02 13:25:25 +01:00
|
|
|
|
|
|
|
/* Utility methods for replacement. */
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Clear the existing mesh and replace it with the given one.
|
|
|
|
*/
|
2020-12-02 13:25:25 +01:00
|
|
|
void replace_mesh(Mesh *mesh, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Clear the existing point cloud and replace with the given one.
|
|
|
|
*/
|
2020-12-02 13:25:25 +01:00
|
|
|
void replace_pointcloud(PointCloud *pointcloud,
|
|
|
|
GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Clear the existing volume and replace with the given one.
|
|
|
|
*/
|
2021-04-26 21:42:03 +02:00
|
|
|
void replace_volume(Volume *volume,
|
|
|
|
GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
2022-02-28 16:53:30 +01:00
|
|
|
* Clear the existing curves data-block and replace it with the given one.
|
2021-12-07 07:19:15 +01:00
|
|
|
*/
|
2022-03-07 23:26:55 +01:00
|
|
|
void replace_curves(Curves *curves,
|
|
|
|
GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2022-10-17 11:39:40 +02:00
|
|
|
/**
|
|
|
|
* Clear the existing instances and replace them with the given one.
|
|
|
|
*/
|
2023-06-15 22:18:28 +02:00
|
|
|
void replace_instances(Instances *instances,
|
2022-10-17 11:39:40 +02:00
|
|
|
GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2023-07-26 13:59:37 +02:00
|
|
|
/**
|
|
|
|
* Clear the existing Grease Pencil data-block and replace it with the given one.
|
|
|
|
*/
|
|
|
|
void replace_grease_pencil(GreasePencil *grease_pencil,
|
|
|
|
GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2021-10-14 19:43:36 +02:00
|
|
|
|
2023-10-07 23:10:43 +02:00
|
|
|
friend bool operator==(const GeometrySet &a, const GeometrySet &b)
|
|
|
|
{
|
|
|
|
/* This compares only the component pointers, not the actual geometry data. */
|
|
|
|
return Span(a.components_) == Span(b.components_);
|
|
|
|
}
|
|
|
|
|
2021-10-14 19:43:36 +02:00
|
|
|
private:
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Retrieve the pointer to a component without creating it if it does not exist,
|
|
|
|
* unlike #get_component_for_write.
|
|
|
|
*/
|
2023-06-15 22:18:28 +02:00
|
|
|
GeometryComponent *get_component_ptr(GeometryComponent::Type type);
|
2021-10-14 19:43:36 +02:00
|
|
|
template<typename Component> Component *get_component_ptr()
|
|
|
|
{
|
|
|
|
BLI_STATIC_ASSERT(is_geometry_component_v<Component>, "");
|
|
|
|
return static_cast<Component *>(get_component_ptr(Component::static_type));
|
|
|
|
}
|
2020-12-02 13:25:25 +01:00
|
|
|
};
|
|
|
|
|
2021-12-07 19:04:32 +01:00
|
|
|
/**
|
2022-05-30 08:59:58 +02:00
|
|
|
* A geometry component that can store a mesh, using the #Mesh data-block.
|
2023-07-05 14:27:03 +02:00
|
|
|
* Attributes are stored on any of the four attribute domains.
|
2021-12-07 19:04:32 +01:00
|
|
|
*/
|
2020-12-02 13:25:25 +01:00
|
|
|
class MeshComponent : public GeometryComponent {
|
|
|
|
private:
|
|
|
|
Mesh *mesh_ = nullptr;
|
|
|
|
GeometryOwnershipType ownership_ = GeometryOwnershipType::Owned;
|
|
|
|
|
|
|
|
public:
|
|
|
|
MeshComponent();
|
|
|
|
~MeshComponent();
|
2023-12-01 11:23:00 +01:00
|
|
|
GeometryComponentPtr copy() const override;
|
2020-12-02 13:25:25 +01:00
|
|
|
|
BLI: support weak users and version in implicit sharing info
The main goal of these changes is to support checking if some data has
been changed over time. This is used by the WIP simulation nodes during
baking to detect which attributes have to be stored in every frame because
they have changed.
By using a combination of a weak user count and a version counter, it is
possible to detect that an attribute (or any data controlled by implicit
sharing) has not been changed with O(1) memory and time. It's still
possible that the data has been changed multiple times and is the same
in the end and beginning of course. That wouldn't be detected using this
mechanism.
The `ImplicitSharingInfo` struct has a new weak user count. A weak
reference is one that does not keep the referenced data alive, but makes sure
that the `ImplicitSharingInfo` itself is not deleted. If some piece of
data has one strong and multiple weak users, it is still mutable. If the
strong user count goes down to zero, the referenced data is freed.
Remaining weak users can check for this condition using `is_expired`.
This is a bit similar to `std::weak_ptr` but there is an important difference:
a weak user can not become a strong user while one can create a `shared_ptr`
from a `weak_ptr`. This restriction is necessary, because some code might
be changing the referenced data assuming that it is the only owner. If
another thread suddenly adds a new owner, the data would be shared again
and the first thread would not have been allowed to modify the data in
the first place.
There is also a new integer version counter in `ImplicitSharingInfo`.
It is incremented whenever some code wants to modify the referenced data.
Obviously, this can only be done when the data is not shared because then
it would be immutable. By comparing an old and new version number of the
same sharing info, one can check if the data has been modified. One has
to keep a weak reference to the sharing info together with the old version
number to ensure that the new sharing info is still the same as the old one.
Without this, it can happen that the sharing info was freed and a new
one was allocated at the same pointer address. Using a strong reference
for this purpose does not work, because then the data would never be
modified because it's shared.
2023-04-28 12:03:42 +02:00
|
|
|
void clear() override;
|
2020-12-02 13:25:25 +01:00
|
|
|
bool has_mesh() const;
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Clear the component and replace it with the new mesh.
|
|
|
|
*/
|
2020-12-02 13:25:25 +01:00
|
|
|
void replace(Mesh *mesh, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Return the mesh and clear the component. The caller takes over responsibility for freeing the
|
|
|
|
* mesh (if the component was responsible before).
|
|
|
|
*/
|
2020-12-02 13:25:25 +01:00
|
|
|
Mesh *release();
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Get the mesh from this component. This method can be used by multiple threads at the same
|
|
|
|
* time. Therefore, the returned mesh should not be modified. No ownership is transferred.
|
|
|
|
*/
|
2023-08-03 17:09:18 +02:00
|
|
|
const Mesh *get() const;
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Get the mesh from this component. This method can only be used when the component is mutable,
|
|
|
|
* i.e. it is not shared. The returned mesh can be modified. No ownership is transferred.
|
|
|
|
*/
|
2020-12-02 13:25:25 +01:00
|
|
|
Mesh *get_for_write();
|
|
|
|
|
|
|
|
bool is_empty() const final;
|
|
|
|
|
2021-04-08 17:35:06 +02:00
|
|
|
bool owns_direct_data() const override;
|
|
|
|
void ensure_owns_direct_data() override;
|
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
static constexpr inline GeometryComponent::Type static_type = Type::Mesh;
|
2021-02-09 11:24:28 +01:00
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
std::optional<AttributeAccessor> attributes() const final;
|
|
|
|
std::optional<MutableAttributeAccessor> attributes_for_write() final;
|
2020-12-02 13:25:25 +01:00
|
|
|
};
|
|
|
|
|
2021-12-07 19:04:32 +01:00
|
|
|
/**
|
|
|
|
* A geometry component that stores a point cloud, corresponding to the #PointCloud data structure.
|
|
|
|
* While a point cloud is technically a subset of a mesh in some respects, it is useful because of
|
|
|
|
* its simplicity, partly on a conceptual level for the user, but also in the code, though partly
|
2021-12-13 06:00:39 +01:00
|
|
|
* for historical reasons. Point clouds can also be rendered in special ways, based on the built-in
|
2021-12-07 19:04:32 +01:00
|
|
|
* `radius` attribute.
|
|
|
|
*
|
|
|
|
* Attributes on point clouds are all stored in contiguous arrays in its #CustomData,
|
|
|
|
* which makes them efficient to process, relative to some legacy built-in mesh attributes.
|
|
|
|
*/
|
2020-12-02 13:25:25 +01:00
|
|
|
class PointCloudComponent : public GeometryComponent {
|
|
|
|
private:
|
|
|
|
PointCloud *pointcloud_ = nullptr;
|
|
|
|
GeometryOwnershipType ownership_ = GeometryOwnershipType::Owned;
|
|
|
|
|
|
|
|
public:
|
|
|
|
PointCloudComponent();
|
|
|
|
~PointCloudComponent();
|
2023-12-01 11:23:00 +01:00
|
|
|
GeometryComponentPtr copy() const override;
|
2020-12-02 13:25:25 +01:00
|
|
|
|
BLI: support weak users and version in implicit sharing info
The main goal of these changes is to support checking if some data has
been changed over time. This is used by the WIP simulation nodes during
baking to detect which attributes have to be stored in every frame because
they have changed.
By using a combination of a weak user count and a version counter, it is
possible to detect that an attribute (or any data controlled by implicit
sharing) has not been changed with O(1) memory and time. It's still
possible that the data has been changed multiple times and is the same
in the end and beginning of course. That wouldn't be detected using this
mechanism.
The `ImplicitSharingInfo` struct has a new weak user count. A weak
reference is one that does not keep the referenced data alive, but makes sure
that the `ImplicitSharingInfo` itself is not deleted. If some piece of
data has one strong and multiple weak users, it is still mutable. If the
strong user count goes down to zero, the referenced data is freed.
Remaining weak users can check for this condition using `is_expired`.
This is a bit similar to `std::weak_ptr` but there is an important difference:
a weak user can not become a strong user while one can create a `shared_ptr`
from a `weak_ptr`. This restriction is necessary, because some code might
be changing the referenced data assuming that it is the only owner. If
another thread suddenly adds a new owner, the data would be shared again
and the first thread would not have been allowed to modify the data in
the first place.
There is also a new integer version counter in `ImplicitSharingInfo`.
It is incremented whenever some code wants to modify the referenced data.
Obviously, this can only be done when the data is not shared because then
it would be immutable. By comparing an old and new version number of the
same sharing info, one can check if the data has been modified. One has
to keep a weak reference to the sharing info together with the old version
number to ensure that the new sharing info is still the same as the old one.
Without this, it can happen that the sharing info was freed and a new
one was allocated at the same pointer address. Using a strong reference
for this purpose does not work, because then the data would never be
modified because it's shared.
2023-04-28 12:03:42 +02:00
|
|
|
void clear() override;
|
2020-12-02 13:25:25 +01:00
|
|
|
bool has_pointcloud() const;
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Clear the component and replace it with the new point cloud.
|
|
|
|
*/
|
2020-12-02 13:25:25 +01:00
|
|
|
void replace(PointCloud *pointcloud,
|
|
|
|
GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Return the point cloud and clear the component. The caller takes over responsibility for
|
|
|
|
* freeing the point cloud (if the component was responsible before).
|
|
|
|
*/
|
2020-12-02 13:25:25 +01:00
|
|
|
PointCloud *release();
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Get the point cloud from this component. This method can be used by multiple threads at the
|
|
|
|
* same time. Therefore, the returned point cloud should not be modified. No ownership is
|
|
|
|
* transferred.
|
|
|
|
*/
|
2023-08-03 17:09:18 +02:00
|
|
|
const PointCloud *get() const;
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Get the point cloud from this component. This method can only be used when the component is
|
|
|
|
* mutable, i.e. it is not shared. The returned point cloud can be modified. No ownership is
|
|
|
|
* transferred.
|
|
|
|
*/
|
2020-12-02 13:25:25 +01:00
|
|
|
PointCloud *get_for_write();
|
|
|
|
|
|
|
|
bool is_empty() const final;
|
|
|
|
|
2021-04-08 17:35:06 +02:00
|
|
|
bool owns_direct_data() const override;
|
|
|
|
void ensure_owns_direct_data() override;
|
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
std::optional<AttributeAccessor> attributes() const final;
|
|
|
|
std::optional<MutableAttributeAccessor> attributes_for_write() final;
|
2021-02-09 11:24:28 +01:00
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
static constexpr inline GeometryComponent::Type static_type = Type::PointCloud;
|
2020-12-02 13:25:25 +01:00
|
|
|
};
|
|
|
|
|
2022-02-28 16:46:34 +01:00
|
|
|
/**
|
2022-09-19 15:46:28 +02:00
|
|
|
* A geometry component that stores a group of curves, corresponding the #Curves data-block
|
2022-08-12 04:38:54 +02:00
|
|
|
* and the #CurvesGeometry type. Attributes are stored on the control point domain and the
|
2022-05-30 08:59:58 +02:00
|
|
|
* curve domain.
|
2022-02-28 16:46:34 +01:00
|
|
|
*/
|
|
|
|
class CurveComponent : public GeometryComponent {
|
|
|
|
private:
|
|
|
|
Curves *curves_ = nullptr;
|
|
|
|
GeometryOwnershipType ownership_ = GeometryOwnershipType::Owned;
|
|
|
|
|
2021-05-27 16:08:40 +02:00
|
|
|
/**
|
2022-09-19 15:46:28 +02:00
|
|
|
* Because rendering #Curves isn't fully working yet, we must provide a #Curve for the render
|
|
|
|
* engine and depsgraph object iterator in some cases. This allows using the old curve rendering
|
|
|
|
* even when the new curve data structure is used.
|
2021-05-27 16:08:40 +02:00
|
|
|
*/
|
|
|
|
mutable Curve *curve_for_render_ = nullptr;
|
|
|
|
mutable std::mutex curve_for_render_mutex_;
|
|
|
|
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
public:
|
|
|
|
CurveComponent();
|
|
|
|
~CurveComponent();
|
2023-12-01 11:23:00 +01:00
|
|
|
GeometryComponentPtr copy() const override;
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
|
BLI: support weak users and version in implicit sharing info
The main goal of these changes is to support checking if some data has
been changed over time. This is used by the WIP simulation nodes during
baking to detect which attributes have to be stored in every frame because
they have changed.
By using a combination of a weak user count and a version counter, it is
possible to detect that an attribute (or any data controlled by implicit
sharing) has not been changed with O(1) memory and time. It's still
possible that the data has been changed multiple times and is the same
in the end and beginning of course. That wouldn't be detected using this
mechanism.
The `ImplicitSharingInfo` struct has a new weak user count. A weak
reference is one that does not keep the referenced data alive, but makes sure
that the `ImplicitSharingInfo` itself is not deleted. If some piece of
data has one strong and multiple weak users, it is still mutable. If the
strong user count goes down to zero, the referenced data is freed.
Remaining weak users can check for this condition using `is_expired`.
This is a bit similar to `std::weak_ptr` but there is an important difference:
a weak user can not become a strong user while one can create a `shared_ptr`
from a `weak_ptr`. This restriction is necessary, because some code might
be changing the referenced data assuming that it is the only owner. If
another thread suddenly adds a new owner, the data would be shared again
and the first thread would not have been allowed to modify the data in
the first place.
There is also a new integer version counter in `ImplicitSharingInfo`.
It is incremented whenever some code wants to modify the referenced data.
Obviously, this can only be done when the data is not shared because then
it would be immutable. By comparing an old and new version number of the
same sharing info, one can check if the data has been modified. One has
to keep a weak reference to the sharing info together with the old version
number to ensure that the new sharing info is still the same as the old one.
Without this, it can happen that the sharing info was freed and a new
one was allocated at the same pointer address. Using a strong reference
for this purpose does not work, because then the data would never be
modified because it's shared.
2023-04-28 12:03:42 +02:00
|
|
|
void clear() override;
|
2022-02-28 16:46:34 +01:00
|
|
|
bool has_curves() const;
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Clear the component and replace it with the new curve.
|
|
|
|
*/
|
2022-02-28 16:46:34 +01:00
|
|
|
void replace(Curves *curve, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
|
|
|
Curves *release();
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
|
2023-08-03 17:09:18 +02:00
|
|
|
const Curves *get() const;
|
2022-02-28 16:46:34 +01:00
|
|
|
Curves *get_for_write();
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
|
|
|
|
bool is_empty() const final;
|
|
|
|
|
|
|
|
bool owns_direct_data() const override;
|
|
|
|
void ensure_owns_direct_data() override;
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Create empty curve data used for rendering the spline's wire edges.
|
|
|
|
* \note See comment on #curve_for_render_ for further explanation.
|
|
|
|
*/
|
2021-05-27 16:08:40 +02:00
|
|
|
const Curve *get_curve_for_render() const;
|
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
std::optional<AttributeAccessor> attributes() const final;
|
|
|
|
std::optional<MutableAttributeAccessor> attributes_for_write() final;
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
static constexpr inline GeometryComponent::Type static_type = Type::Curve;
|
Geometry Nodes: Initial basic curve data support
This patch adds initial curve support to geometry nodes. Currently
there is only one node available, the "Curve to Mesh" node, T87428.
However, the aim of the changes here is larger than just supporting
curve data in nodes-- it also uses the opportunity to add better spline
data structures, intended to replace the existing curve evaluation code.
The curve code in Blender is quite old, and it's generally regarded as
some of the messiest, hardest-to-understand code as well. The classes
in `BKE_spline.hh` aim to be faster, more extensible, and much more
easily understandable. Further explanation can be found in comments in
that file.
Initial builtin spline attributes are supported-- reading and writing
from the `cyclic` and `resolution` attributes works with any of the
attribute nodes. Also, only Z-up normal calculation is implemented
at the moment, and tilts do not apply yet.
**Limitations**
- For now, you must bring curves into the node tree with an "Object
Info" node. Changes to the curve modifier stack will come later.
- Converting to a mesh is necessary to visualize the curve data.
Further progress can be tracked in: T87245
Higher level design document: https://wiki.blender.org/wiki/Modules/Physics_Nodes/Projects/EverythingNodes/CurveNodes
Differential Revision: https://developer.blender.org/D11091
2021-05-03 19:29:17 +02:00
|
|
|
};
|
|
|
|
|
2021-12-07 19:04:32 +01:00
|
|
|
/**
|
2022-10-17 11:39:40 +02:00
|
|
|
* A geometry component that stores #Instances.
|
2021-12-07 19:04:32 +01:00
|
|
|
*/
|
2020-12-02 13:25:25 +01:00
|
|
|
class InstancesComponent : public GeometryComponent {
|
|
|
|
private:
|
2023-06-15 22:18:28 +02:00
|
|
|
Instances *instances_ = nullptr;
|
2022-10-17 11:39:40 +02:00
|
|
|
GeometryOwnershipType ownership_ = GeometryOwnershipType::Owned;
|
2021-11-19 17:53:48 +01:00
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
public:
|
|
|
|
InstancesComponent();
|
2022-10-17 11:39:40 +02:00
|
|
|
~InstancesComponent();
|
2023-12-01 11:23:00 +01:00
|
|
|
GeometryComponentPtr copy() const override;
|
2020-12-02 13:25:25 +01:00
|
|
|
|
BLI: support weak users and version in implicit sharing info
The main goal of these changes is to support checking if some data has
been changed over time. This is used by the WIP simulation nodes during
baking to detect which attributes have to be stored in every frame because
they have changed.
By using a combination of a weak user count and a version counter, it is
possible to detect that an attribute (or any data controlled by implicit
sharing) has not been changed with O(1) memory and time. It's still
possible that the data has been changed multiple times and is the same
in the end and beginning of course. That wouldn't be detected using this
mechanism.
The `ImplicitSharingInfo` struct has a new weak user count. A weak
reference is one that does not keep the referenced data alive, but makes sure
that the `ImplicitSharingInfo` itself is not deleted. If some piece of
data has one strong and multiple weak users, it is still mutable. If the
strong user count goes down to zero, the referenced data is freed.
Remaining weak users can check for this condition using `is_expired`.
This is a bit similar to `std::weak_ptr` but there is an important difference:
a weak user can not become a strong user while one can create a `shared_ptr`
from a `weak_ptr`. This restriction is necessary, because some code might
be changing the referenced data assuming that it is the only owner. If
another thread suddenly adds a new owner, the data would be shared again
and the first thread would not have been allowed to modify the data in
the first place.
There is also a new integer version counter in `ImplicitSharingInfo`.
It is incremented whenever some code wants to modify the referenced data.
Obviously, this can only be done when the data is not shared because then
it would be immutable. By comparing an old and new version number of the
same sharing info, one can check if the data has been modified. One has
to keep a weak reference to the sharing info together with the old version
number to ensure that the new sharing info is still the same as the old one.
Without this, it can happen that the sharing info was freed and a new
one was allocated at the same pointer address. Using a strong reference
for this purpose does not work, because then the data would never be
modified because it's shared.
2023-04-28 12:03:42 +02:00
|
|
|
void clear() override;
|
2021-05-04 10:16:24 +02:00
|
|
|
|
2023-08-03 17:09:18 +02:00
|
|
|
const Instances *get() const;
|
2023-06-15 22:18:28 +02:00
|
|
|
Instances *get_for_write();
|
2021-05-04 10:16:24 +02:00
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
void replace(Instances *instances,
|
2022-10-17 11:39:40 +02:00
|
|
|
GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2021-09-23 17:50:33 +02:00
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
bool is_empty() const final;
|
|
|
|
|
2021-04-08 17:35:06 +02:00
|
|
|
bool owns_direct_data() const override;
|
|
|
|
void ensure_owns_direct_data() override;
|
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
std::optional<AttributeAccessor> attributes() const final;
|
|
|
|
std::optional<MutableAttributeAccessor> attributes_for_write() final;
|
2021-09-20 12:49:11 +02:00
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
static constexpr inline GeometryComponent::Type static_type = Type::Instance;
|
2020-12-02 13:25:25 +01:00
|
|
|
};
|
2021-01-21 10:32:42 +01:00
|
|
|
|
2021-12-07 19:04:32 +01:00
|
|
|
/**
|
|
|
|
* A geometry component that stores volume grids, corresponding to the #Volume data structure.
|
|
|
|
* This component does not implement an attribute API, partly because storage of sparse volume
|
|
|
|
* information in grids is much more complicated than it is for other types
|
|
|
|
*/
|
2021-01-21 10:32:42 +01:00
|
|
|
class VolumeComponent : public GeometryComponent {
|
|
|
|
private:
|
|
|
|
Volume *volume_ = nullptr;
|
|
|
|
GeometryOwnershipType ownership_ = GeometryOwnershipType::Owned;
|
|
|
|
|
|
|
|
public:
|
|
|
|
VolumeComponent();
|
|
|
|
~VolumeComponent();
|
2023-12-01 11:23:00 +01:00
|
|
|
GeometryComponentPtr copy() const override;
|
2021-01-21 10:32:42 +01:00
|
|
|
|
BLI: support weak users and version in implicit sharing info
The main goal of these changes is to support checking if some data has
been changed over time. This is used by the WIP simulation nodes during
baking to detect which attributes have to be stored in every frame because
they have changed.
By using a combination of a weak user count and a version counter, it is
possible to detect that an attribute (or any data controlled by implicit
sharing) has not been changed with O(1) memory and time. It's still
possible that the data has been changed multiple times and is the same
in the end and beginning of course. That wouldn't be detected using this
mechanism.
The `ImplicitSharingInfo` struct has a new weak user count. A weak
reference is one that does not keep the referenced data alive, but makes sure
that the `ImplicitSharingInfo` itself is not deleted. If some piece of
data has one strong and multiple weak users, it is still mutable. If the
strong user count goes down to zero, the referenced data is freed.
Remaining weak users can check for this condition using `is_expired`.
This is a bit similar to `std::weak_ptr` but there is an important difference:
a weak user can not become a strong user while one can create a `shared_ptr`
from a `weak_ptr`. This restriction is necessary, because some code might
be changing the referenced data assuming that it is the only owner. If
another thread suddenly adds a new owner, the data would be shared again
and the first thread would not have been allowed to modify the data in
the first place.
There is also a new integer version counter in `ImplicitSharingInfo`.
It is incremented whenever some code wants to modify the referenced data.
Obviously, this can only be done when the data is not shared because then
it would be immutable. By comparing an old and new version number of the
same sharing info, one can check if the data has been modified. One has
to keep a weak reference to the sharing info together with the old version
number to ensure that the new sharing info is still the same as the old one.
Without this, it can happen that the sharing info was freed and a new
one was allocated at the same pointer address. Using a strong reference
for this purpose does not work, because then the data would never be
modified because it's shared.
2023-04-28 12:03:42 +02:00
|
|
|
void clear() override;
|
2021-01-21 10:32:42 +01:00
|
|
|
bool has_volume() const;
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Clear the component and replace it with the new volume.
|
|
|
|
*/
|
2021-01-21 10:32:42 +01:00
|
|
|
void replace(Volume *volume, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Return the volume and clear the component. The caller takes over responsibility for freeing
|
|
|
|
* the volume (if the component was responsible before).
|
|
|
|
*/
|
2021-01-21 10:32:42 +01:00
|
|
|
Volume *release();
|
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Get the volume from this component. This method can be used by multiple threads at the same
|
|
|
|
* time. Therefore, the returned volume should not be modified. No ownership is transferred.
|
|
|
|
*/
|
2023-08-03 17:09:18 +02:00
|
|
|
const Volume *get() const;
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
|
|
|
* Get the volume from this component. This method can only be used when the component is
|
|
|
|
* mutable, i.e. it is not shared. The returned volume can be modified. No ownership is
|
|
|
|
* transferred.
|
|
|
|
*/
|
2021-01-21 10:32:42 +01:00
|
|
|
Volume *get_for_write();
|
|
|
|
|
2021-04-08 17:35:06 +02:00
|
|
|
bool owns_direct_data() const override;
|
|
|
|
void ensure_owns_direct_data() override;
|
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
static constexpr inline GeometryComponent::Type static_type = Type::Volume;
|
2021-01-21 10:32:42 +01:00
|
|
|
};
|
2022-07-22 15:39:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* When the original data is in some edit mode, we want to propagate some additional information
|
|
|
|
* through object evaluation. This information can be used by edit modes to support working on
|
|
|
|
* evaluated data.
|
|
|
|
*
|
|
|
|
* This component is added at the beginning of modifier evaluation.
|
|
|
|
*/
|
|
|
|
class GeometryComponentEditData final : public GeometryComponent {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Information about how original curves are manipulated during evaluation. This data is used so
|
|
|
|
* that curve sculpt tools can work on evaluated data. It is not stored in #CurveComponent
|
|
|
|
* because the data remains valid even when there is no actual curves geometry anymore, for
|
|
|
|
* example, when the curves have been converted to a mesh.
|
|
|
|
*/
|
2023-06-15 22:18:28 +02:00
|
|
|
std::unique_ptr<CurvesEditHints> curves_edit_hints_;
|
2023-10-12 15:42:04 +02:00
|
|
|
/**
|
|
|
|
* Information about how drawings on the grease pencil layers are manipulated during evaluation.
|
|
|
|
*/
|
|
|
|
std::unique_ptr<GreasePencilEditHints> grease_pencil_edit_hints_;
|
2022-07-22 15:39:41 +02:00
|
|
|
|
|
|
|
GeometryComponentEditData();
|
|
|
|
|
2023-12-01 11:23:00 +01:00
|
|
|
GeometryComponentPtr copy() const final;
|
2022-07-22 15:39:41 +02:00
|
|
|
bool owns_direct_data() const final;
|
|
|
|
void ensure_owns_direct_data() final;
|
|
|
|
|
BLI: support weak users and version in implicit sharing info
The main goal of these changes is to support checking if some data has
been changed over time. This is used by the WIP simulation nodes during
baking to detect which attributes have to be stored in every frame because
they have changed.
By using a combination of a weak user count and a version counter, it is
possible to detect that an attribute (or any data controlled by implicit
sharing) has not been changed with O(1) memory and time. It's still
possible that the data has been changed multiple times and is the same
in the end and beginning of course. That wouldn't be detected using this
mechanism.
The `ImplicitSharingInfo` struct has a new weak user count. A weak
reference is one that does not keep the referenced data alive, but makes sure
that the `ImplicitSharingInfo` itself is not deleted. If some piece of
data has one strong and multiple weak users, it is still mutable. If the
strong user count goes down to zero, the referenced data is freed.
Remaining weak users can check for this condition using `is_expired`.
This is a bit similar to `std::weak_ptr` but there is an important difference:
a weak user can not become a strong user while one can create a `shared_ptr`
from a `weak_ptr`. This restriction is necessary, because some code might
be changing the referenced data assuming that it is the only owner. If
another thread suddenly adds a new owner, the data would be shared again
and the first thread would not have been allowed to modify the data in
the first place.
There is also a new integer version counter in `ImplicitSharingInfo`.
It is incremented whenever some code wants to modify the referenced data.
Obviously, this can only be done when the data is not shared because then
it would be immutable. By comparing an old and new version number of the
same sharing info, one can check if the data has been modified. One has
to keep a weak reference to the sharing info together with the old version
number to ensure that the new sharing info is still the same as the old one.
Without this, it can happen that the sharing info was freed and a new
one was allocated at the same pointer address. Using a strong reference
for this purpose does not work, because then the data would never be
modified because it's shared.
2023-04-28 12:03:42 +02:00
|
|
|
void clear() override;
|
|
|
|
|
2022-07-22 15:39:41 +02:00
|
|
|
/**
|
|
|
|
* The first node that does topology changing operations on curves should store the curve point
|
|
|
|
* positions it retrieved as input. Without this, information about the deformed positions is
|
|
|
|
* lost, which would make curves sculpt mode fall back to using original curve positions instead
|
|
|
|
* of deformed ones.
|
|
|
|
*/
|
2023-10-12 15:42:04 +02:00
|
|
|
static void remember_deformed_positions_if_necessary(GeometrySet &geometry);
|
2022-07-22 15:39:41 +02:00
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
static constexpr inline GeometryComponent::Type static_type = GeometryComponent::Type::Edit;
|
2022-07-22 15:39:41 +02:00
|
|
|
};
|
2023-06-15 22:18:28 +02:00
|
|
|
|
2023-07-26 13:59:37 +02:00
|
|
|
/**
|
|
|
|
* A geometry component that stores #GreasePencil data.
|
2023-10-10 16:49:30 +02:00
|
|
|
* The attributes on this component are only on the layer domain. Each individual layer represents
|
|
|
|
* a #CurvesGeometry with its own curve and point domain. See #CurveComponent.
|
2023-07-26 13:59:37 +02:00
|
|
|
*/
|
|
|
|
class GreasePencilComponent : public GeometryComponent {
|
|
|
|
private:
|
|
|
|
GreasePencil *grease_pencil_ = nullptr;
|
|
|
|
GeometryOwnershipType ownership_ = GeometryOwnershipType::Owned;
|
|
|
|
|
|
|
|
public:
|
|
|
|
GreasePencilComponent();
|
|
|
|
~GreasePencilComponent();
|
2023-12-01 11:23:00 +01:00
|
|
|
GeometryComponentPtr copy() const override;
|
2023-07-26 13:59:37 +02:00
|
|
|
|
|
|
|
void clear() override;
|
|
|
|
bool has_grease_pencil() const;
|
|
|
|
/**
|
|
|
|
* Clear the component and replace it with the new \a grease_pencil data.
|
|
|
|
*/
|
|
|
|
void replace(GreasePencil *grease_pencil,
|
|
|
|
GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
|
|
|
/**
|
|
|
|
* Return the Grease Pencil data and clear the component. The caller takes over responsibility
|
|
|
|
* for freeing the Grease Pencil data (if the component was responsible before).
|
|
|
|
*/
|
|
|
|
GreasePencil *release();
|
|
|
|
|
2023-08-03 17:09:18 +02:00
|
|
|
const GreasePencil *get() const;
|
2023-07-26 13:59:37 +02:00
|
|
|
GreasePencil *get_for_write();
|
|
|
|
|
|
|
|
bool is_empty() const final;
|
|
|
|
|
|
|
|
bool owns_direct_data() const override;
|
|
|
|
void ensure_owns_direct_data() override;
|
|
|
|
|
|
|
|
static constexpr inline GeometryComponent::Type static_type = Type::GreasePencil;
|
2023-10-10 16:49:30 +02:00
|
|
|
|
|
|
|
std::optional<AttributeAccessor> attributes() const final;
|
|
|
|
std::optional<MutableAttributeAccessor> attributes_for_write() final;
|
2023-07-26 13:59:37 +02:00
|
|
|
};
|
|
|
|
|
2023-06-15 22:18:28 +02:00
|
|
|
} // namespace blender::bke
|