2020-12-02 13:25:25 +01:00
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "BLI_float3.hh"
|
2021-01-26 18:21:12 +01:00
|
|
|
#include "BLI_float4x4.hh"
|
2020-12-02 13:25:25 +01:00
|
|
|
#include "BLI_hash.hh"
|
|
|
|
#include "BLI_map.hh"
|
|
|
|
#include "BLI_set.hh"
|
|
|
|
#include "BLI_user_counter.hh"
|
2021-05-04 10:16:24 +02:00
|
|
|
#include "BLI_vector_set.hh"
|
2020-12-02 13:25:25 +01:00
|
|
|
|
|
|
|
#include "BKE_attribute_access.hh"
|
|
|
|
#include "BKE_geometry_set.h"
|
|
|
|
|
2020-12-16 16:26:23 +11:00
|
|
|
struct Collection;
|
2020-12-02 13:25:25 +01:00
|
|
|
struct Mesh;
|
|
|
|
struct Object;
|
2020-12-16 16:26:23 +11:00
|
|
|
struct PointCloud;
|
2021-01-21 10:32:42 +01:00
|
|
|
struct Volume;
|
2021-05-27 10:08:40 -04:00
|
|
|
struct Curve;
|
2021-05-27 11:00:00 -04:00
|
|
|
struct CurveEval;
|
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,
|
|
|
|
};
|
|
|
|
|
2021-02-09 11:24:28 +01:00
|
|
|
namespace blender::bke {
|
2021-02-09 11:47:49 +01:00
|
|
|
class ComponentAttributeProviders;
|
2021-02-09 11:24:28 +01:00
|
|
|
}
|
|
|
|
|
2021-01-14 15:52:08 +01:00
|
|
|
class GeometryComponent;
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
/**
|
|
|
|
* This is the base class for specialized geometry component types.
|
|
|
|
*/
|
|
|
|
class GeometryComponent {
|
|
|
|
private:
|
|
|
|
/* The reference count has two purposes. When it becomes zero, the component is freed. When it is
|
|
|
|
* larger than one, the component becomes immutable. */
|
|
|
|
mutable std::atomic<int> users_ = 1;
|
|
|
|
GeometryComponentType type_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
GeometryComponent(GeometryComponentType type);
|
2021-04-08 11:07:12 +02:00
|
|
|
virtual ~GeometryComponent() = default;
|
2020-12-02 13:25:25 +01:00
|
|
|
static GeometryComponent *create(GeometryComponentType component_type);
|
|
|
|
|
|
|
|
/* The returned component should be of the same type as the type this is called on. */
|
|
|
|
virtual GeometryComponent *copy() const = 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;
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
void user_add() const;
|
|
|
|
void user_remove() const;
|
|
|
|
bool is_mutable() const;
|
|
|
|
|
|
|
|
GeometryComponentType type() const;
|
|
|
|
|
2020-12-10 10:50:37 -06:00
|
|
|
/* Return true when any attribute with this name exists, including built in attributes. */
|
|
|
|
bool attribute_exists(const blender::StringRef attribute_name) const;
|
|
|
|
|
2021-04-22 08:05:02 -05:00
|
|
|
/* Return the data type and domain of an attribute with the given name if it exists. */
|
|
|
|
std::optional<AttributeMetaData> attribute_get_meta_data(
|
|
|
|
const blender::StringRef attribute_name) const;
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
/* Returns true when the geometry component supports this attribute domain. */
|
2021-02-09 11:24:28 +01:00
|
|
|
bool attribute_domain_supported(const AttributeDomain domain) const;
|
2020-12-02 13:25:25 +01:00
|
|
|
/* Can only be used with supported domain types. */
|
|
|
|
virtual int attribute_domain_size(const AttributeDomain domain) const;
|
|
|
|
|
Geometry Nodes: use virtual arrays in internal attribute api
A virtual array is a data structure that is similar to a normal array
in that its elements can be accessed by an index. However, a virtual
array does not have to be a contiguous array internally. Instead, its
elements can be layed out arbitrarily while element access happens
through a virtual function call. However, the virtual array data
structures are designed so that the virtual function call can be avoided
in cases where it could become a bottleneck.
Most commonly, a virtual array is backed by an actual array/span or
is a single value internally, that is the same for every index.
Besides those, there are many more specialized virtual arrays like the
ones that provides vertex positions based on the `MVert` struct or
vertex group weights.
Not all attributes used by geometry nodes are stored in simple contiguous
arrays. To provide uniform access to all kinds of attributes, the attribute
API has to provide virtual array functionality that hides the implementation
details of attributes.
Before this refactor, the attribute API provided its own virtual array
implementation as part of the `ReadAttribute` and `WriteAttribute` types.
That resulted in unnecessary code duplication with the virtual array system.
Even worse, it bound many algorithms used by geometry nodes to the specifics
of the attribute API, even though they could also use different data sources
(such as data from sockets, default values, later results of expressions, ...).
This refactor removes the `ReadAttribute` and `WriteAttribute` types and
replaces them with `GVArray` and `GVMutableArray` respectively. The `GV`
stands for "generic virtual". The "generic" means that the data type contained
in those virtual arrays is only known at run-time. There are the corresponding
statically typed types `VArray<T>` and `VMutableArray<T>` as well.
No regressions are expected from this refactor. It does come with one
improvement for users. The attribute API can convert the data type
on write now. This is especially useful when writing to builtin attributes
like `material_index` with e.g. the Attribute Math node (which usually
just writes to float attributes, while `material_index` is an integer attribute).
Differential Revision: https://developer.blender.org/D10994
2021-04-17 16:41:03 +02:00
|
|
|
bool attribute_is_builtin(const blender::StringRef attribute_name) const;
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
/* Get read-only access to the highest priority attribute with the given name.
|
|
|
|
* Returns null if the attribute does not exist. */
|
Geometry Nodes: use virtual arrays in internal attribute api
A virtual array is a data structure that is similar to a normal array
in that its elements can be accessed by an index. However, a virtual
array does not have to be a contiguous array internally. Instead, its
elements can be layed out arbitrarily while element access happens
through a virtual function call. However, the virtual array data
structures are designed so that the virtual function call can be avoided
in cases where it could become a bottleneck.
Most commonly, a virtual array is backed by an actual array/span or
is a single value internally, that is the same for every index.
Besides those, there are many more specialized virtual arrays like the
ones that provides vertex positions based on the `MVert` struct or
vertex group weights.
Not all attributes used by geometry nodes are stored in simple contiguous
arrays. To provide uniform access to all kinds of attributes, the attribute
API has to provide virtual array functionality that hides the implementation
details of attributes.
Before this refactor, the attribute API provided its own virtual array
implementation as part of the `ReadAttribute` and `WriteAttribute` types.
That resulted in unnecessary code duplication with the virtual array system.
Even worse, it bound many algorithms used by geometry nodes to the specifics
of the attribute API, even though they could also use different data sources
(such as data from sockets, default values, later results of expressions, ...).
This refactor removes the `ReadAttribute` and `WriteAttribute` types and
replaces them with `GVArray` and `GVMutableArray` respectively. The `GV`
stands for "generic virtual". The "generic" means that the data type contained
in those virtual arrays is only known at run-time. There are the corresponding
statically typed types `VArray<T>` and `VMutableArray<T>` as well.
No regressions are expected from this refactor. It does come with one
improvement for users. The attribute API can convert the data type
on write now. This is especially useful when writing to builtin attributes
like `material_index` with e.g. the Attribute Math node (which usually
just writes to float attributes, while `material_index` is an integer attribute).
Differential Revision: https://developer.blender.org/D10994
2021-04-17 16:41:03 +02:00
|
|
|
blender::bke::ReadAttributeLookup attribute_try_get_for_read(
|
2020-12-02 13:25:25 +01:00
|
|
|
const blender::StringRef attribute_name) const;
|
|
|
|
|
|
|
|
/* Get read and write access to the highest priority attribute with the given name.
|
|
|
|
* Returns null if the attribute does not exist. */
|
Geometry Nodes: use virtual arrays in internal attribute api
A virtual array is a data structure that is similar to a normal array
in that its elements can be accessed by an index. However, a virtual
array does not have to be a contiguous array internally. Instead, its
elements can be layed out arbitrarily while element access happens
through a virtual function call. However, the virtual array data
structures are designed so that the virtual function call can be avoided
in cases where it could become a bottleneck.
Most commonly, a virtual array is backed by an actual array/span or
is a single value internally, that is the same for every index.
Besides those, there are many more specialized virtual arrays like the
ones that provides vertex positions based on the `MVert` struct or
vertex group weights.
Not all attributes used by geometry nodes are stored in simple contiguous
arrays. To provide uniform access to all kinds of attributes, the attribute
API has to provide virtual array functionality that hides the implementation
details of attributes.
Before this refactor, the attribute API provided its own virtual array
implementation as part of the `ReadAttribute` and `WriteAttribute` types.
That resulted in unnecessary code duplication with the virtual array system.
Even worse, it bound many algorithms used by geometry nodes to the specifics
of the attribute API, even though they could also use different data sources
(such as data from sockets, default values, later results of expressions, ...).
This refactor removes the `ReadAttribute` and `WriteAttribute` types and
replaces them with `GVArray` and `GVMutableArray` respectively. The `GV`
stands for "generic virtual". The "generic" means that the data type contained
in those virtual arrays is only known at run-time. There are the corresponding
statically typed types `VArray<T>` and `VMutableArray<T>` as well.
No regressions are expected from this refactor. It does come with one
improvement for users. The attribute API can convert the data type
on write now. This is especially useful when writing to builtin attributes
like `material_index` with e.g. the Attribute Math node (which usually
just writes to float attributes, while `material_index` is an integer attribute).
Differential Revision: https://developer.blender.org/D10994
2021-04-17 16:41:03 +02:00
|
|
|
blender::bke::WriteAttributeLookup attribute_try_get_for_write(
|
2020-12-02 13:25:25 +01:00
|
|
|
const blender::StringRef attribute_name);
|
|
|
|
|
|
|
|
/* Get a read-only attribute for the domain based on the given attribute. This can be used to
|
|
|
|
* interpolate from one domain to another.
|
|
|
|
* Returns null if the interpolation is not implemented. */
|
Geometry Nodes: use virtual arrays in internal attribute api
A virtual array is a data structure that is similar to a normal array
in that its elements can be accessed by an index. However, a virtual
array does not have to be a contiguous array internally. Instead, its
elements can be layed out arbitrarily while element access happens
through a virtual function call. However, the virtual array data
structures are designed so that the virtual function call can be avoided
in cases where it could become a bottleneck.
Most commonly, a virtual array is backed by an actual array/span or
is a single value internally, that is the same for every index.
Besides those, there are many more specialized virtual arrays like the
ones that provides vertex positions based on the `MVert` struct or
vertex group weights.
Not all attributes used by geometry nodes are stored in simple contiguous
arrays. To provide uniform access to all kinds of attributes, the attribute
API has to provide virtual array functionality that hides the implementation
details of attributes.
Before this refactor, the attribute API provided its own virtual array
implementation as part of the `ReadAttribute` and `WriteAttribute` types.
That resulted in unnecessary code duplication with the virtual array system.
Even worse, it bound many algorithms used by geometry nodes to the specifics
of the attribute API, even though they could also use different data sources
(such as data from sockets, default values, later results of expressions, ...).
This refactor removes the `ReadAttribute` and `WriteAttribute` types and
replaces them with `GVArray` and `GVMutableArray` respectively. The `GV`
stands for "generic virtual". The "generic" means that the data type contained
in those virtual arrays is only known at run-time. There are the corresponding
statically typed types `VArray<T>` and `VMutableArray<T>` as well.
No regressions are expected from this refactor. It does come with one
improvement for users. The attribute API can convert the data type
on write now. This is especially useful when writing to builtin attributes
like `material_index` with e.g. the Attribute Math node (which usually
just writes to float attributes, while `material_index` is an integer attribute).
Differential Revision: https://developer.blender.org/D10994
2021-04-17 16:41:03 +02:00
|
|
|
virtual std::unique_ptr<blender::fn::GVArray> attribute_try_adapt_domain(
|
|
|
|
std::unique_ptr<blender::fn::GVArray> varray,
|
|
|
|
const AttributeDomain from_domain,
|
|
|
|
const AttributeDomain to_domain) const;
|
2020-12-02 13:25:25 +01:00
|
|
|
|
|
|
|
/* Returns true when the attribute has been deleted. */
|
2021-02-09 11:24:28 +01:00
|
|
|
bool attribute_try_delete(const blender::StringRef attribute_name);
|
2020-12-02 13:25:25 +01:00
|
|
|
|
|
|
|
/* Returns true when the attribute has been created. */
|
2021-02-09 11:24:28 +01:00
|
|
|
bool attribute_try_create(const blender::StringRef attribute_name,
|
|
|
|
const AttributeDomain domain,
|
2021-04-22 09:20:03 -05:00
|
|
|
const CustomDataType data_type,
|
|
|
|
const AttributeInit &initializer);
|
2020-12-02 13:25:25 +01:00
|
|
|
|
Geometry Nodes: use virtual arrays in internal attribute api
A virtual array is a data structure that is similar to a normal array
in that its elements can be accessed by an index. However, a virtual
array does not have to be a contiguous array internally. Instead, its
elements can be layed out arbitrarily while element access happens
through a virtual function call. However, the virtual array data
structures are designed so that the virtual function call can be avoided
in cases where it could become a bottleneck.
Most commonly, a virtual array is backed by an actual array/span or
is a single value internally, that is the same for every index.
Besides those, there are many more specialized virtual arrays like the
ones that provides vertex positions based on the `MVert` struct or
vertex group weights.
Not all attributes used by geometry nodes are stored in simple contiguous
arrays. To provide uniform access to all kinds of attributes, the attribute
API has to provide virtual array functionality that hides the implementation
details of attributes.
Before this refactor, the attribute API provided its own virtual array
implementation as part of the `ReadAttribute` and `WriteAttribute` types.
That resulted in unnecessary code duplication with the virtual array system.
Even worse, it bound many algorithms used by geometry nodes to the specifics
of the attribute API, even though they could also use different data sources
(such as data from sockets, default values, later results of expressions, ...).
This refactor removes the `ReadAttribute` and `WriteAttribute` types and
replaces them with `GVArray` and `GVMutableArray` respectively. The `GV`
stands for "generic virtual". The "generic" means that the data type contained
in those virtual arrays is only known at run-time. There are the corresponding
statically typed types `VArray<T>` and `VMutableArray<T>` as well.
No regressions are expected from this refactor. It does come with one
improvement for users. The attribute API can convert the data type
on write now. This is especially useful when writing to builtin attributes
like `material_index` with e.g. the Attribute Math node (which usually
just writes to float attributes, while `material_index` is an integer attribute).
Differential Revision: https://developer.blender.org/D10994
2021-04-17 16:41:03 +02:00
|
|
|
/* Try to create the builtin attribute with the given name. No data type or domain has to be
|
|
|
|
* provided, because those are fixed for builtin attributes. */
|
2021-04-22 09:20:03 -05:00
|
|
|
bool attribute_try_create_builtin(const blender::StringRef attribute_name,
|
|
|
|
const AttributeInit &initializer);
|
Geometry Nodes: use virtual arrays in internal attribute api
A virtual array is a data structure that is similar to a normal array
in that its elements can be accessed by an index. However, a virtual
array does not have to be a contiguous array internally. Instead, its
elements can be layed out arbitrarily while element access happens
through a virtual function call. However, the virtual array data
structures are designed so that the virtual function call can be avoided
in cases where it could become a bottleneck.
Most commonly, a virtual array is backed by an actual array/span or
is a single value internally, that is the same for every index.
Besides those, there are many more specialized virtual arrays like the
ones that provides vertex positions based on the `MVert` struct or
vertex group weights.
Not all attributes used by geometry nodes are stored in simple contiguous
arrays. To provide uniform access to all kinds of attributes, the attribute
API has to provide virtual array functionality that hides the implementation
details of attributes.
Before this refactor, the attribute API provided its own virtual array
implementation as part of the `ReadAttribute` and `WriteAttribute` types.
That resulted in unnecessary code duplication with the virtual array system.
Even worse, it bound many algorithms used by geometry nodes to the specifics
of the attribute API, even though they could also use different data sources
(such as data from sockets, default values, later results of expressions, ...).
This refactor removes the `ReadAttribute` and `WriteAttribute` types and
replaces them with `GVArray` and `GVMutableArray` respectively. The `GV`
stands for "generic virtual". The "generic" means that the data type contained
in those virtual arrays is only known at run-time. There are the corresponding
statically typed types `VArray<T>` and `VMutableArray<T>` as well.
No regressions are expected from this refactor. It does come with one
improvement for users. The attribute API can convert the data type
on write now. This is especially useful when writing to builtin attributes
like `material_index` with e.g. the Attribute Math node (which usually
just writes to float attributes, while `material_index` is an integer attribute).
Differential Revision: https://developer.blender.org/D10994
2021-04-17 16:41:03 +02:00
|
|
|
|
2021-02-09 11:24:28 +01:00
|
|
|
blender::Set<std::string> attribute_names() const;
|
2021-04-08 12:19:09 -05:00
|
|
|
bool attribute_foreach(const AttributeForeachCallback callback) const;
|
2021-02-23 15:15:23 +01:00
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
virtual bool is_empty() const;
|
|
|
|
|
Geometry Nodes: use virtual arrays in internal attribute api
A virtual array is a data structure that is similar to a normal array
in that its elements can be accessed by an index. However, a virtual
array does not have to be a contiguous array internally. Instead, its
elements can be layed out arbitrarily while element access happens
through a virtual function call. However, the virtual array data
structures are designed so that the virtual function call can be avoided
in cases where it could become a bottleneck.
Most commonly, a virtual array is backed by an actual array/span or
is a single value internally, that is the same for every index.
Besides those, there are many more specialized virtual arrays like the
ones that provides vertex positions based on the `MVert` struct or
vertex group weights.
Not all attributes used by geometry nodes are stored in simple contiguous
arrays. To provide uniform access to all kinds of attributes, the attribute
API has to provide virtual array functionality that hides the implementation
details of attributes.
Before this refactor, the attribute API provided its own virtual array
implementation as part of the `ReadAttribute` and `WriteAttribute` types.
That resulted in unnecessary code duplication with the virtual array system.
Even worse, it bound many algorithms used by geometry nodes to the specifics
of the attribute API, even though they could also use different data sources
(such as data from sockets, default values, later results of expressions, ...).
This refactor removes the `ReadAttribute` and `WriteAttribute` types and
replaces them with `GVArray` and `GVMutableArray` respectively. The `GV`
stands for "generic virtual". The "generic" means that the data type contained
in those virtual arrays is only known at run-time. There are the corresponding
statically typed types `VArray<T>` and `VMutableArray<T>` as well.
No regressions are expected from this refactor. It does come with one
improvement for users. The attribute API can convert the data type
on write now. This is especially useful when writing to builtin attributes
like `material_index` with e.g. the Attribute Math node (which usually
just writes to float attributes, while `material_index` is an integer attribute).
Differential Revision: https://developer.blender.org/D10994
2021-04-17 16:41:03 +02:00
|
|
|
/* Get a virtual array to read the data of an attribute on the given domain and data type.
|
|
|
|
* Returns null when the attribute does not exist or cannot be converted to the requested domain
|
|
|
|
* and data type. */
|
|
|
|
std::unique_ptr<blender::fn::GVArray> attribute_try_get_for_read(
|
2020-12-02 13:25:25 +01:00
|
|
|
const blender::StringRef attribute_name,
|
|
|
|
const AttributeDomain domain,
|
|
|
|
const CustomDataType data_type) const;
|
|
|
|
|
Geometry Nodes: use virtual arrays in internal attribute api
A virtual array is a data structure that is similar to a normal array
in that its elements can be accessed by an index. However, a virtual
array does not have to be a contiguous array internally. Instead, its
elements can be layed out arbitrarily while element access happens
through a virtual function call. However, the virtual array data
structures are designed so that the virtual function call can be avoided
in cases where it could become a bottleneck.
Most commonly, a virtual array is backed by an actual array/span or
is a single value internally, that is the same for every index.
Besides those, there are many more specialized virtual arrays like the
ones that provides vertex positions based on the `MVert` struct or
vertex group weights.
Not all attributes used by geometry nodes are stored in simple contiguous
arrays. To provide uniform access to all kinds of attributes, the attribute
API has to provide virtual array functionality that hides the implementation
details of attributes.
Before this refactor, the attribute API provided its own virtual array
implementation as part of the `ReadAttribute` and `WriteAttribute` types.
That resulted in unnecessary code duplication with the virtual array system.
Even worse, it bound many algorithms used by geometry nodes to the specifics
of the attribute API, even though they could also use different data sources
(such as data from sockets, default values, later results of expressions, ...).
This refactor removes the `ReadAttribute` and `WriteAttribute` types and
replaces them with `GVArray` and `GVMutableArray` respectively. The `GV`
stands for "generic virtual". The "generic" means that the data type contained
in those virtual arrays is only known at run-time. There are the corresponding
statically typed types `VArray<T>` and `VMutableArray<T>` as well.
No regressions are expected from this refactor. It does come with one
improvement for users. The attribute API can convert the data type
on write now. This is especially useful when writing to builtin attributes
like `material_index` with e.g. the Attribute Math node (which usually
just writes to float attributes, while `material_index` is an integer attribute).
Differential Revision: https://developer.blender.org/D10994
2021-04-17 16:41:03 +02:00
|
|
|
/* Get a virtual array to read the data of an attribute on the given domain. The data type is
|
|
|
|
* left unchanged. Returns null when the attribute does not exist or cannot be adapted to the
|
|
|
|
* requested domain. */
|
|
|
|
std::unique_ptr<blender::fn::GVArray> attribute_try_get_for_read(
|
2020-12-17 07:43:31 -06:00
|
|
|
const blender::StringRef attribute_name, const AttributeDomain domain) const;
|
|
|
|
|
2021-04-21 17:07:00 +02:00
|
|
|
/* Get a virtual array to read data of an attribute with the given data type. The domain is
|
|
|
|
* left unchanged. Returns null when the attribute does not exist or cannot be converted to the
|
|
|
|
* requested data type. */
|
|
|
|
blender::bke::ReadAttributeLookup attribute_try_get_for_read(
|
|
|
|
const blender::StringRef attribute_name, const CustomDataType data_type) const;
|
|
|
|
|
Geometry Nodes: use virtual arrays in internal attribute api
A virtual array is a data structure that is similar to a normal array
in that its elements can be accessed by an index. However, a virtual
array does not have to be a contiguous array internally. Instead, its
elements can be layed out arbitrarily while element access happens
through a virtual function call. However, the virtual array data
structures are designed so that the virtual function call can be avoided
in cases where it could become a bottleneck.
Most commonly, a virtual array is backed by an actual array/span or
is a single value internally, that is the same for every index.
Besides those, there are many more specialized virtual arrays like the
ones that provides vertex positions based on the `MVert` struct or
vertex group weights.
Not all attributes used by geometry nodes are stored in simple contiguous
arrays. To provide uniform access to all kinds of attributes, the attribute
API has to provide virtual array functionality that hides the implementation
details of attributes.
Before this refactor, the attribute API provided its own virtual array
implementation as part of the `ReadAttribute` and `WriteAttribute` types.
That resulted in unnecessary code duplication with the virtual array system.
Even worse, it bound many algorithms used by geometry nodes to the specifics
of the attribute API, even though they could also use different data sources
(such as data from sockets, default values, later results of expressions, ...).
This refactor removes the `ReadAttribute` and `WriteAttribute` types and
replaces them with `GVArray` and `GVMutableArray` respectively. The `GV`
stands for "generic virtual". The "generic" means that the data type contained
in those virtual arrays is only known at run-time. There are the corresponding
statically typed types `VArray<T>` and `VMutableArray<T>` as well.
No regressions are expected from this refactor. It does come with one
improvement for users. The attribute API can convert the data type
on write now. This is especially useful when writing to builtin attributes
like `material_index` with e.g. the Attribute Math node (which usually
just writes to float attributes, while `material_index` is an integer attribute).
Differential Revision: https://developer.blender.org/D10994
2021-04-17 16:41:03 +02:00
|
|
|
/* Get a virtual array to read the data of an attribute. If that is not possible, the returned
|
|
|
|
* virtual array will contain a default value. This never returns null. */
|
|
|
|
std::unique_ptr<blender::fn::GVArray> attribute_get_for_read(
|
2020-12-02 13:25:25 +01:00
|
|
|
const blender::StringRef attribute_name,
|
|
|
|
const AttributeDomain domain,
|
Geometry Nodes: use virtual arrays in internal attribute api
A virtual array is a data structure that is similar to a normal array
in that its elements can be accessed by an index. However, a virtual
array does not have to be a contiguous array internally. Instead, its
elements can be layed out arbitrarily while element access happens
through a virtual function call. However, the virtual array data
structures are designed so that the virtual function call can be avoided
in cases where it could become a bottleneck.
Most commonly, a virtual array is backed by an actual array/span or
is a single value internally, that is the same for every index.
Besides those, there are many more specialized virtual arrays like the
ones that provides vertex positions based on the `MVert` struct or
vertex group weights.
Not all attributes used by geometry nodes are stored in simple contiguous
arrays. To provide uniform access to all kinds of attributes, the attribute
API has to provide virtual array functionality that hides the implementation
details of attributes.
Before this refactor, the attribute API provided its own virtual array
implementation as part of the `ReadAttribute` and `WriteAttribute` types.
That resulted in unnecessary code duplication with the virtual array system.
Even worse, it bound many algorithms used by geometry nodes to the specifics
of the attribute API, even though they could also use different data sources
(such as data from sockets, default values, later results of expressions, ...).
This refactor removes the `ReadAttribute` and `WriteAttribute` types and
replaces them with `GVArray` and `GVMutableArray` respectively. The `GV`
stands for "generic virtual". The "generic" means that the data type contained
in those virtual arrays is only known at run-time. There are the corresponding
statically typed types `VArray<T>` and `VMutableArray<T>` as well.
No regressions are expected from this refactor. It does come with one
improvement for users. The attribute API can convert the data type
on write now. This is especially useful when writing to builtin attributes
like `material_index` with e.g. the Attribute Math node (which usually
just writes to float attributes, while `material_index` is an integer attribute).
Differential Revision: https://developer.blender.org/D10994
2021-04-17 16:41:03 +02:00
|
|
|
const CustomDataType data_type,
|
|
|
|
const void *default_value = nullptr) const;
|
|
|
|
|
|
|
|
/* Should be used instead of the method above when the requested data type is known at compile
|
|
|
|
* time for better type safety. */
|
|
|
|
template<typename T>
|
|
|
|
blender::fn::GVArray_Typed<T> attribute_get_for_read(const blender::StringRef attribute_name,
|
|
|
|
const AttributeDomain domain,
|
|
|
|
const T &default_value) const
|
2020-12-02 13:25:25 +01:00
|
|
|
{
|
|
|
|
const blender::fn::CPPType &cpp_type = blender::fn::CPPType::get<T>();
|
|
|
|
const CustomDataType type = blender::bke::cpp_type_to_custom_data_type(cpp_type);
|
Geometry Nodes: use virtual arrays in internal attribute api
A virtual array is a data structure that is similar to a normal array
in that its elements can be accessed by an index. However, a virtual
array does not have to be a contiguous array internally. Instead, its
elements can be layed out arbitrarily while element access happens
through a virtual function call. However, the virtual array data
structures are designed so that the virtual function call can be avoided
in cases where it could become a bottleneck.
Most commonly, a virtual array is backed by an actual array/span or
is a single value internally, that is the same for every index.
Besides those, there are many more specialized virtual arrays like the
ones that provides vertex positions based on the `MVert` struct or
vertex group weights.
Not all attributes used by geometry nodes are stored in simple contiguous
arrays. To provide uniform access to all kinds of attributes, the attribute
API has to provide virtual array functionality that hides the implementation
details of attributes.
Before this refactor, the attribute API provided its own virtual array
implementation as part of the `ReadAttribute` and `WriteAttribute` types.
That resulted in unnecessary code duplication with the virtual array system.
Even worse, it bound many algorithms used by geometry nodes to the specifics
of the attribute API, even though they could also use different data sources
(such as data from sockets, default values, later results of expressions, ...).
This refactor removes the `ReadAttribute` and `WriteAttribute` types and
replaces them with `GVArray` and `GVMutableArray` respectively. The `GV`
stands for "generic virtual". The "generic" means that the data type contained
in those virtual arrays is only known at run-time. There are the corresponding
statically typed types `VArray<T>` and `VMutableArray<T>` as well.
No regressions are expected from this refactor. It does come with one
improvement for users. The attribute API can convert the data type
on write now. This is especially useful when writing to builtin attributes
like `material_index` with e.g. the Attribute Math node (which usually
just writes to float attributes, while `material_index` is an integer attribute).
Differential Revision: https://developer.blender.org/D10994
2021-04-17 16:41:03 +02:00
|
|
|
std::unique_ptr varray = this->attribute_get_for_read(
|
|
|
|
attribute_name, domain, type, &default_value);
|
|
|
|
return blender::fn::GVArray_Typed<T>(std::move(varray));
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
Geometry Nodes: use virtual arrays in internal attribute api
A virtual array is a data structure that is similar to a normal array
in that its elements can be accessed by an index. However, a virtual
array does not have to be a contiguous array internally. Instead, its
elements can be layed out arbitrarily while element access happens
through a virtual function call. However, the virtual array data
structures are designed so that the virtual function call can be avoided
in cases where it could become a bottleneck.
Most commonly, a virtual array is backed by an actual array/span or
is a single value internally, that is the same for every index.
Besides those, there are many more specialized virtual arrays like the
ones that provides vertex positions based on the `MVert` struct or
vertex group weights.
Not all attributes used by geometry nodes are stored in simple contiguous
arrays. To provide uniform access to all kinds of attributes, the attribute
API has to provide virtual array functionality that hides the implementation
details of attributes.
Before this refactor, the attribute API provided its own virtual array
implementation as part of the `ReadAttribute` and `WriteAttribute` types.
That resulted in unnecessary code duplication with the virtual array system.
Even worse, it bound many algorithms used by geometry nodes to the specifics
of the attribute API, even though they could also use different data sources
(such as data from sockets, default values, later results of expressions, ...).
This refactor removes the `ReadAttribute` and `WriteAttribute` types and
replaces them with `GVArray` and `GVMutableArray` respectively. The `GV`
stands for "generic virtual". The "generic" means that the data type contained
in those virtual arrays is only known at run-time. There are the corresponding
statically typed types `VArray<T>` and `VMutableArray<T>` as well.
No regressions are expected from this refactor. It does come with one
improvement for users. The attribute API can convert the data type
on write now. This is especially useful when writing to builtin attributes
like `material_index` with e.g. the Attribute Math node (which usually
just writes to float attributes, while `material_index` is an integer attribute).
Differential Revision: https://developer.blender.org/D10994
2021-04-17 16:41:03 +02:00
|
|
|
/**
|
|
|
|
* Returns an "output attribute", which is essentially a mutable virtual array with some commonly
|
2021-04-19 23:56:12 +10:00
|
|
|
* used convince features. The returned output attribute might be empty if requested attribute
|
Geometry Nodes: use virtual arrays in internal attribute api
A virtual array is a data structure that is similar to a normal array
in that its elements can be accessed by an index. However, a virtual
array does not have to be a contiguous array internally. Instead, its
elements can be layed out arbitrarily while element access happens
through a virtual function call. However, the virtual array data
structures are designed so that the virtual function call can be avoided
in cases where it could become a bottleneck.
Most commonly, a virtual array is backed by an actual array/span or
is a single value internally, that is the same for every index.
Besides those, there are many more specialized virtual arrays like the
ones that provides vertex positions based on the `MVert` struct or
vertex group weights.
Not all attributes used by geometry nodes are stored in simple contiguous
arrays. To provide uniform access to all kinds of attributes, the attribute
API has to provide virtual array functionality that hides the implementation
details of attributes.
Before this refactor, the attribute API provided its own virtual array
implementation as part of the `ReadAttribute` and `WriteAttribute` types.
That resulted in unnecessary code duplication with the virtual array system.
Even worse, it bound many algorithms used by geometry nodes to the specifics
of the attribute API, even though they could also use different data sources
(such as data from sockets, default values, later results of expressions, ...).
This refactor removes the `ReadAttribute` and `WriteAttribute` types and
replaces them with `GVArray` and `GVMutableArray` respectively. The `GV`
stands for "generic virtual". The "generic" means that the data type contained
in those virtual arrays is only known at run-time. There are the corresponding
statically typed types `VArray<T>` and `VMutableArray<T>` as well.
No regressions are expected from this refactor. It does come with one
improvement for users. The attribute API can convert the data type
on write now. This is especially useful when writing to builtin attributes
like `material_index` with e.g. the Attribute Math node (which usually
just writes to float attributes, while `material_index` is an integer attribute).
Differential Revision: https://developer.blender.org/D10994
2021-04-17 16:41:03 +02:00
|
|
|
* cannot exist on the geometry.
|
|
|
|
*
|
|
|
|
* The included convenience features are:
|
|
|
|
* - Implicit type conversion when writing to builtin attributes.
|
|
|
|
* - If the attribute name exists already, but has a different type/domain, a temporary attribute
|
|
|
|
* is created that will overwrite the existing attribute in the end.
|
|
|
|
*/
|
|
|
|
blender::bke::OutputAttribute attribute_try_get_for_output(
|
|
|
|
const blender::StringRef attribute_name,
|
|
|
|
const AttributeDomain domain,
|
|
|
|
const CustomDataType data_type,
|
|
|
|
const void *default_value = nullptr);
|
2020-12-02 13:25:25 +01:00
|
|
|
|
Geometry Nodes: use virtual arrays in internal attribute api
A virtual array is a data structure that is similar to a normal array
in that its elements can be accessed by an index. However, a virtual
array does not have to be a contiguous array internally. Instead, its
elements can be layed out arbitrarily while element access happens
through a virtual function call. However, the virtual array data
structures are designed so that the virtual function call can be avoided
in cases where it could become a bottleneck.
Most commonly, a virtual array is backed by an actual array/span or
is a single value internally, that is the same for every index.
Besides those, there are many more specialized virtual arrays like the
ones that provides vertex positions based on the `MVert` struct or
vertex group weights.
Not all attributes used by geometry nodes are stored in simple contiguous
arrays. To provide uniform access to all kinds of attributes, the attribute
API has to provide virtual array functionality that hides the implementation
details of attributes.
Before this refactor, the attribute API provided its own virtual array
implementation as part of the `ReadAttribute` and `WriteAttribute` types.
That resulted in unnecessary code duplication with the virtual array system.
Even worse, it bound many algorithms used by geometry nodes to the specifics
of the attribute API, even though they could also use different data sources
(such as data from sockets, default values, later results of expressions, ...).
This refactor removes the `ReadAttribute` and `WriteAttribute` types and
replaces them with `GVArray` and `GVMutableArray` respectively. The `GV`
stands for "generic virtual". The "generic" means that the data type contained
in those virtual arrays is only known at run-time. There are the corresponding
statically typed types `VArray<T>` and `VMutableArray<T>` as well.
No regressions are expected from this refactor. It does come with one
improvement for users. The attribute API can convert the data type
on write now. This is especially useful when writing to builtin attributes
like `material_index` with e.g. the Attribute Math node (which usually
just writes to float attributes, while `material_index` is an integer attribute).
Differential Revision: https://developer.blender.org/D10994
2021-04-17 16:41:03 +02:00
|
|
|
/* Same as attribute_try_get_for_output, but should be used when the original values in the
|
|
|
|
* attributes are not read, i.e. the attribute is used only for output. Since values are not read
|
|
|
|
* from this attribute, no default value is necessary. */
|
|
|
|
blender::bke::OutputAttribute attribute_try_get_for_output_only(
|
|
|
|
const blender::StringRef attribute_name,
|
2020-12-09 16:20:48 +01:00
|
|
|
const AttributeDomain domain,
|
Geometry Nodes: use virtual arrays in internal attribute api
A virtual array is a data structure that is similar to a normal array
in that its elements can be accessed by an index. However, a virtual
array does not have to be a contiguous array internally. Instead, its
elements can be layed out arbitrarily while element access happens
through a virtual function call. However, the virtual array data
structures are designed so that the virtual function call can be avoided
in cases where it could become a bottleneck.
Most commonly, a virtual array is backed by an actual array/span or
is a single value internally, that is the same for every index.
Besides those, there are many more specialized virtual arrays like the
ones that provides vertex positions based on the `MVert` struct or
vertex group weights.
Not all attributes used by geometry nodes are stored in simple contiguous
arrays. To provide uniform access to all kinds of attributes, the attribute
API has to provide virtual array functionality that hides the implementation
details of attributes.
Before this refactor, the attribute API provided its own virtual array
implementation as part of the `ReadAttribute` and `WriteAttribute` types.
That resulted in unnecessary code duplication with the virtual array system.
Even worse, it bound many algorithms used by geometry nodes to the specifics
of the attribute API, even though they could also use different data sources
(such as data from sockets, default values, later results of expressions, ...).
This refactor removes the `ReadAttribute` and `WriteAttribute` types and
replaces them with `GVArray` and `GVMutableArray` respectively. The `GV`
stands for "generic virtual". The "generic" means that the data type contained
in those virtual arrays is only known at run-time. There are the corresponding
statically typed types `VArray<T>` and `VMutableArray<T>` as well.
No regressions are expected from this refactor. It does come with one
improvement for users. The attribute API can convert the data type
on write now. This is especially useful when writing to builtin attributes
like `material_index` with e.g. the Attribute Math node (which usually
just writes to float attributes, while `material_index` is an integer attribute).
Differential Revision: https://developer.blender.org/D10994
2021-04-17 16:41:03 +02:00
|
|
|
const CustomDataType data_type);
|
2020-12-09 16:20:48 +01:00
|
|
|
|
Geometry Nodes: use virtual arrays in internal attribute api
A virtual array is a data structure that is similar to a normal array
in that its elements can be accessed by an index. However, a virtual
array does not have to be a contiguous array internally. Instead, its
elements can be layed out arbitrarily while element access happens
through a virtual function call. However, the virtual array data
structures are designed so that the virtual function call can be avoided
in cases where it could become a bottleneck.
Most commonly, a virtual array is backed by an actual array/span or
is a single value internally, that is the same for every index.
Besides those, there are many more specialized virtual arrays like the
ones that provides vertex positions based on the `MVert` struct or
vertex group weights.
Not all attributes used by geometry nodes are stored in simple contiguous
arrays. To provide uniform access to all kinds of attributes, the attribute
API has to provide virtual array functionality that hides the implementation
details of attributes.
Before this refactor, the attribute API provided its own virtual array
implementation as part of the `ReadAttribute` and `WriteAttribute` types.
That resulted in unnecessary code duplication with the virtual array system.
Even worse, it bound many algorithms used by geometry nodes to the specifics
of the attribute API, even though they could also use different data sources
(such as data from sockets, default values, later results of expressions, ...).
This refactor removes the `ReadAttribute` and `WriteAttribute` types and
replaces them with `GVArray` and `GVMutableArray` respectively. The `GV`
stands for "generic virtual". The "generic" means that the data type contained
in those virtual arrays is only known at run-time. There are the corresponding
statically typed types `VArray<T>` and `VMutableArray<T>` as well.
No regressions are expected from this refactor. It does come with one
improvement for users. The attribute API can convert the data type
on write now. This is especially useful when writing to builtin attributes
like `material_index` with e.g. the Attribute Math node (which usually
just writes to float attributes, while `material_index` is an integer attribute).
Differential Revision: https://developer.blender.org/D10994
2021-04-17 16:41:03 +02:00
|
|
|
/* Statically typed method corresponding to the equally named generic one. */
|
2020-12-02 13:25:25 +01:00
|
|
|
template<typename T>
|
Geometry Nodes: use virtual arrays in internal attribute api
A virtual array is a data structure that is similar to a normal array
in that its elements can be accessed by an index. However, a virtual
array does not have to be a contiguous array internally. Instead, its
elements can be layed out arbitrarily while element access happens
through a virtual function call. However, the virtual array data
structures are designed so that the virtual function call can be avoided
in cases where it could become a bottleneck.
Most commonly, a virtual array is backed by an actual array/span or
is a single value internally, that is the same for every index.
Besides those, there are many more specialized virtual arrays like the
ones that provides vertex positions based on the `MVert` struct or
vertex group weights.
Not all attributes used by geometry nodes are stored in simple contiguous
arrays. To provide uniform access to all kinds of attributes, the attribute
API has to provide virtual array functionality that hides the implementation
details of attributes.
Before this refactor, the attribute API provided its own virtual array
implementation as part of the `ReadAttribute` and `WriteAttribute` types.
That resulted in unnecessary code duplication with the virtual array system.
Even worse, it bound many algorithms used by geometry nodes to the specifics
of the attribute API, even though they could also use different data sources
(such as data from sockets, default values, later results of expressions, ...).
This refactor removes the `ReadAttribute` and `WriteAttribute` types and
replaces them with `GVArray` and `GVMutableArray` respectively. The `GV`
stands for "generic virtual". The "generic" means that the data type contained
in those virtual arrays is only known at run-time. There are the corresponding
statically typed types `VArray<T>` and `VMutableArray<T>` as well.
No regressions are expected from this refactor. It does come with one
improvement for users. The attribute API can convert the data type
on write now. This is especially useful when writing to builtin attributes
like `material_index` with e.g. the Attribute Math node (which usually
just writes to float attributes, while `material_index` is an integer attribute).
Differential Revision: https://developer.blender.org/D10994
2021-04-17 16:41:03 +02:00
|
|
|
blender::bke::OutputAttribute_Typed<T> attribute_try_get_for_output(
|
|
|
|
const blender::StringRef attribute_name, const AttributeDomain domain, const T default_value)
|
2020-12-02 13:25:25 +01:00
|
|
|
{
|
|
|
|
const blender::fn::CPPType &cpp_type = blender::fn::CPPType::get<T>();
|
Geometry Nodes: use virtual arrays in internal attribute api
A virtual array is a data structure that is similar to a normal array
in that its elements can be accessed by an index. However, a virtual
array does not have to be a contiguous array internally. Instead, its
elements can be layed out arbitrarily while element access happens
through a virtual function call. However, the virtual array data
structures are designed so that the virtual function call can be avoided
in cases where it could become a bottleneck.
Most commonly, a virtual array is backed by an actual array/span or
is a single value internally, that is the same for every index.
Besides those, there are many more specialized virtual arrays like the
ones that provides vertex positions based on the `MVert` struct or
vertex group weights.
Not all attributes used by geometry nodes are stored in simple contiguous
arrays. To provide uniform access to all kinds of attributes, the attribute
API has to provide virtual array functionality that hides the implementation
details of attributes.
Before this refactor, the attribute API provided its own virtual array
implementation as part of the `ReadAttribute` and `WriteAttribute` types.
That resulted in unnecessary code duplication with the virtual array system.
Even worse, it bound many algorithms used by geometry nodes to the specifics
of the attribute API, even though they could also use different data sources
(such as data from sockets, default values, later results of expressions, ...).
This refactor removes the `ReadAttribute` and `WriteAttribute` types and
replaces them with `GVArray` and `GVMutableArray` respectively. The `GV`
stands for "generic virtual". The "generic" means that the data type contained
in those virtual arrays is only known at run-time. There are the corresponding
statically typed types `VArray<T>` and `VMutableArray<T>` as well.
No regressions are expected from this refactor. It does come with one
improvement for users. The attribute API can convert the data type
on write now. This is especially useful when writing to builtin attributes
like `material_index` with e.g. the Attribute Math node (which usually
just writes to float attributes, while `material_index` is an integer attribute).
Differential Revision: https://developer.blender.org/D10994
2021-04-17 16:41:03 +02:00
|
|
|
const CustomDataType data_type = blender::bke::cpp_type_to_custom_data_type(cpp_type);
|
|
|
|
return this->attribute_try_get_for_output(attribute_name, domain, data_type, &default_value);
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
Geometry Nodes: use virtual arrays in internal attribute api
A virtual array is a data structure that is similar to a normal array
in that its elements can be accessed by an index. However, a virtual
array does not have to be a contiguous array internally. Instead, its
elements can be layed out arbitrarily while element access happens
through a virtual function call. However, the virtual array data
structures are designed so that the virtual function call can be avoided
in cases where it could become a bottleneck.
Most commonly, a virtual array is backed by an actual array/span or
is a single value internally, that is the same for every index.
Besides those, there are many more specialized virtual arrays like the
ones that provides vertex positions based on the `MVert` struct or
vertex group weights.
Not all attributes used by geometry nodes are stored in simple contiguous
arrays. To provide uniform access to all kinds of attributes, the attribute
API has to provide virtual array functionality that hides the implementation
details of attributes.
Before this refactor, the attribute API provided its own virtual array
implementation as part of the `ReadAttribute` and `WriteAttribute` types.
That resulted in unnecessary code duplication with the virtual array system.
Even worse, it bound many algorithms used by geometry nodes to the specifics
of the attribute API, even though they could also use different data sources
(such as data from sockets, default values, later results of expressions, ...).
This refactor removes the `ReadAttribute` and `WriteAttribute` types and
replaces them with `GVArray` and `GVMutableArray` respectively. The `GV`
stands for "generic virtual". The "generic" means that the data type contained
in those virtual arrays is only known at run-time. There are the corresponding
statically typed types `VArray<T>` and `VMutableArray<T>` as well.
No regressions are expected from this refactor. It does come with one
improvement for users. The attribute API can convert the data type
on write now. This is especially useful when writing to builtin attributes
like `material_index` with e.g. the Attribute Math node (which usually
just writes to float attributes, while `material_index` is an integer attribute).
Differential Revision: https://developer.blender.org/D10994
2021-04-17 16:41:03 +02:00
|
|
|
/* Statically typed method corresponding to the equally named generic one. */
|
|
|
|
template<typename T>
|
|
|
|
blender::bke::OutputAttribute_Typed<T> attribute_try_get_for_output_only(
|
|
|
|
const blender::StringRef attribute_name, const AttributeDomain domain)
|
|
|
|
{
|
|
|
|
const blender::fn::CPPType &cpp_type = blender::fn::CPPType::get<T>();
|
|
|
|
const CustomDataType data_type = blender::bke::cpp_type_to_custom_data_type(cpp_type);
|
|
|
|
return this->attribute_try_get_for_output_only(attribute_name, domain, data_type);
|
|
|
|
}
|
2021-02-09 11:24:28 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
virtual const blender::bke::ComponentAttributeProviders *get_attribute_providers() const;
|
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>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A geometry set contains zero or more geometry components. There is at most one component of each
|
|
|
|
* type. Individual components might be shared between multiple geometries. Shared components are
|
|
|
|
* copied automatically when write access is requested.
|
|
|
|
*
|
|
|
|
* Copying a geometry set is a relatively cheap operation, because it does not copy the referenced
|
|
|
|
* geometry components.
|
|
|
|
*/
|
|
|
|
struct GeometrySet {
|
|
|
|
private:
|
|
|
|
using GeometryComponentPtr = blender::UserCounter<class GeometryComponent>;
|
|
|
|
blender::Map<GeometryComponentType, GeometryComponentPtr> components_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
GeometryComponent &get_component_for_write(GeometryComponentType component_type);
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
const GeometryComponent *get_component_for_read(GeometryComponentType component_type) const;
|
|
|
|
template<typename Component> const Component *get_component_for_read() const
|
|
|
|
{
|
|
|
|
BLI_STATIC_ASSERT(is_geometry_component_v<Component>, "");
|
|
|
|
return static_cast<const Component *>(get_component_for_read(Component::static_type));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool has(const GeometryComponentType component_type) const;
|
|
|
|
template<typename Component> bool has() const
|
|
|
|
{
|
|
|
|
BLI_STATIC_ASSERT(is_geometry_component_v<Component>, "");
|
|
|
|
return this->has(Component::static_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void remove(const GeometryComponentType component_type);
|
|
|
|
template<typename Component> void remove()
|
|
|
|
{
|
|
|
|
BLI_STATIC_ASSERT(is_geometry_component_v<Component>, "");
|
|
|
|
return this->remove(Component::static_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void add(const GeometryComponent &component);
|
|
|
|
|
2021-02-19 12:29:37 +01:00
|
|
|
blender::Vector<const GeometryComponent *> get_components_for_read() const;
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
void compute_boundbox_without_instances(blender::float3 *r_min, blender::float3 *r_max) const;
|
|
|
|
|
|
|
|
friend std::ostream &operator<<(std::ostream &stream, const GeometrySet &geometry_set);
|
|
|
|
friend bool operator==(const GeometrySet &a, const GeometrySet &b);
|
|
|
|
uint64_t hash() const;
|
|
|
|
|
2021-03-30 12:34:05 +02:00
|
|
|
void clear();
|
|
|
|
|
2021-04-08 17:35:06 +02:00
|
|
|
void ensure_owns_direct_data();
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
/* Utility methods for creation. */
|
|
|
|
static GeometrySet create_with_mesh(
|
|
|
|
Mesh *mesh, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
|
|
|
static GeometrySet create_with_pointcloud(
|
|
|
|
PointCloud *pointcloud, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
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 12:29:17 -05:00
|
|
|
static GeometrySet create_with_curve(
|
|
|
|
CurveEval *curve, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2020-12-02 13:25:25 +01:00
|
|
|
|
|
|
|
/* Utility methods for access. */
|
|
|
|
bool has_mesh() const;
|
|
|
|
bool has_pointcloud() const;
|
|
|
|
bool has_instances() const;
|
2021-01-21 10:32:42 +01:00
|
|
|
bool has_volume() 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 12:29:17 -05:00
|
|
|
bool has_curve() const;
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
const Mesh *get_mesh_for_read() const;
|
|
|
|
const PointCloud *get_pointcloud_for_read() const;
|
2021-01-21 10:32:42 +01:00
|
|
|
const Volume *get_volume_for_read() 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 12:29:17 -05:00
|
|
|
const CurveEval *get_curve_for_read() const;
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
Mesh *get_mesh_for_write();
|
|
|
|
PointCloud *get_pointcloud_for_write();
|
2021-01-21 10:32:42 +01:00
|
|
|
Volume *get_volume_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 12:29:17 -05:00
|
|
|
CurveEval *get_curve_for_write();
|
2020-12-02 13:25:25 +01:00
|
|
|
|
|
|
|
/* Utility methods for replacement. */
|
|
|
|
void replace_mesh(Mesh *mesh, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
|
|
|
void replace_pointcloud(PointCloud *pointcloud,
|
|
|
|
GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2021-04-26 14:42:03 -05:00
|
|
|
void replace_volume(Volume *volume,
|
|
|
|
GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
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 12:29:17 -05:00
|
|
|
void replace_curve(CurveEval *curve,
|
|
|
|
GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2020-12-02 13:25:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** A geometry component that can store a mesh. */
|
|
|
|
class MeshComponent : public GeometryComponent {
|
|
|
|
private:
|
|
|
|
Mesh *mesh_ = nullptr;
|
|
|
|
GeometryOwnershipType ownership_ = GeometryOwnershipType::Owned;
|
|
|
|
/* Due to historical design choices, vertex group data is stored in the mesh, but the vertex
|
|
|
|
* group names are stored on an object. Since we don't have an object here, we copy over the
|
|
|
|
* names into this map. */
|
|
|
|
blender::Map<std::string, int> vertex_group_names_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
MeshComponent();
|
|
|
|
~MeshComponent();
|
|
|
|
GeometryComponent *copy() const override;
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
bool has_mesh() const;
|
|
|
|
void replace(Mesh *mesh, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2021-02-02 09:20:54 -06:00
|
|
|
void replace_mesh_but_keep_vertex_group_names(
|
|
|
|
Mesh *mesh, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
2020-12-02 13:25:25 +01:00
|
|
|
Mesh *release();
|
|
|
|
|
|
|
|
void copy_vertex_group_names_from_object(const struct Object &object);
|
2021-02-09 11:24:28 +01:00
|
|
|
const blender::Map<std::string, int> &vertex_group_names() const;
|
|
|
|
blender::Map<std::string, int> &vertex_group_names();
|
2020-12-02 13:25:25 +01:00
|
|
|
|
|
|
|
const Mesh *get_for_read() const;
|
|
|
|
Mesh *get_for_write();
|
|
|
|
|
|
|
|
int attribute_domain_size(const AttributeDomain domain) const final;
|
Geometry Nodes: use virtual arrays in internal attribute api
A virtual array is a data structure that is similar to a normal array
in that its elements can be accessed by an index. However, a virtual
array does not have to be a contiguous array internally. Instead, its
elements can be layed out arbitrarily while element access happens
through a virtual function call. However, the virtual array data
structures are designed so that the virtual function call can be avoided
in cases where it could become a bottleneck.
Most commonly, a virtual array is backed by an actual array/span or
is a single value internally, that is the same for every index.
Besides those, there are many more specialized virtual arrays like the
ones that provides vertex positions based on the `MVert` struct or
vertex group weights.
Not all attributes used by geometry nodes are stored in simple contiguous
arrays. To provide uniform access to all kinds of attributes, the attribute
API has to provide virtual array functionality that hides the implementation
details of attributes.
Before this refactor, the attribute API provided its own virtual array
implementation as part of the `ReadAttribute` and `WriteAttribute` types.
That resulted in unnecessary code duplication with the virtual array system.
Even worse, it bound many algorithms used by geometry nodes to the specifics
of the attribute API, even though they could also use different data sources
(such as data from sockets, default values, later results of expressions, ...).
This refactor removes the `ReadAttribute` and `WriteAttribute` types and
replaces them with `GVArray` and `GVMutableArray` respectively. The `GV`
stands for "generic virtual". The "generic" means that the data type contained
in those virtual arrays is only known at run-time. There are the corresponding
statically typed types `VArray<T>` and `VMutableArray<T>` as well.
No regressions are expected from this refactor. It does come with one
improvement for users. The attribute API can convert the data type
on write now. This is especially useful when writing to builtin attributes
like `material_index` with e.g. the Attribute Math node (which usually
just writes to float attributes, while `material_index` is an integer attribute).
Differential Revision: https://developer.blender.org/D10994
2021-04-17 16:41:03 +02:00
|
|
|
std::unique_ptr<blender::fn::GVArray> attribute_try_adapt_domain(
|
|
|
|
std::unique_ptr<blender::fn::GVArray> varray,
|
|
|
|
const AttributeDomain from_domain,
|
|
|
|
const AttributeDomain to_domain) const final;
|
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;
|
|
|
|
|
2021-03-10 11:53:17 +01:00
|
|
|
static constexpr inline GeometryComponentType static_type = GEO_COMPONENT_TYPE_MESH;
|
2021-02-09 11:24:28 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
const blender::bke::ComponentAttributeProviders *get_attribute_providers() const final;
|
2020-12-02 13:25:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** A geometry component that stores a point cloud. */
|
|
|
|
class PointCloudComponent : public GeometryComponent {
|
|
|
|
private:
|
|
|
|
PointCloud *pointcloud_ = nullptr;
|
|
|
|
GeometryOwnershipType ownership_ = GeometryOwnershipType::Owned;
|
|
|
|
|
|
|
|
public:
|
|
|
|
PointCloudComponent();
|
|
|
|
~PointCloudComponent();
|
|
|
|
GeometryComponent *copy() const override;
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
bool has_pointcloud() const;
|
|
|
|
void replace(PointCloud *pointcloud,
|
|
|
|
GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
|
|
|
PointCloud *release();
|
|
|
|
|
|
|
|
const PointCloud *get_for_read() const;
|
|
|
|
PointCloud *get_for_write();
|
|
|
|
|
|
|
|
int attribute_domain_size(const AttributeDomain domain) const final;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2021-03-10 11:53:17 +01:00
|
|
|
static constexpr inline GeometryComponentType static_type = GEO_COMPONENT_TYPE_POINT_CLOUD;
|
2021-02-09 11:24:28 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
const blender::bke::ComponentAttributeProviders *get_attribute_providers() const final;
|
2020-12-02 13:25:25 +01:00
|
|
|
};
|
|
|
|
|
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 12:29:17 -05:00
|
|
|
/** A geometry component that stores curve data, in other words, a group of splines. */
|
|
|
|
class CurveComponent : public GeometryComponent {
|
|
|
|
private:
|
|
|
|
CurveEval *curve_ = nullptr;
|
|
|
|
GeometryOwnershipType ownership_ = GeometryOwnershipType::Owned;
|
|
|
|
|
2021-05-27 10:08:40 -04:00
|
|
|
/**
|
|
|
|
* Curve data necessary to hold the draw cache for rendering, consistent over multiple redraws.
|
|
|
|
* This is necessary because Blender assumes that objects evaluate to an object data type, and
|
|
|
|
* we use #CurveEval rather than #Curve here. It also allows us to mostly reuse the same
|
|
|
|
* batch cache implementation.
|
|
|
|
*/
|
|
|
|
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 12:29:17 -05:00
|
|
|
public:
|
|
|
|
CurveComponent();
|
|
|
|
~CurveComponent();
|
|
|
|
GeometryComponent *copy() const override;
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
bool has_curve() const;
|
|
|
|
void replace(CurveEval *curve, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
|
|
|
CurveEval *release();
|
|
|
|
|
|
|
|
const CurveEval *get_for_read() const;
|
|
|
|
CurveEval *get_for_write();
|
|
|
|
|
|
|
|
int attribute_domain_size(const AttributeDomain domain) const final;
|
2021-05-26 22:14:59 -04:00
|
|
|
std::unique_ptr<blender::fn::GVArray> attribute_try_adapt_domain(
|
|
|
|
std::unique_ptr<blender::fn::GVArray> varray,
|
|
|
|
const AttributeDomain from_domain,
|
|
|
|
const AttributeDomain to_domain) const 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 12:29:17 -05:00
|
|
|
|
|
|
|
bool is_empty() const final;
|
|
|
|
|
|
|
|
bool owns_direct_data() const override;
|
|
|
|
void ensure_owns_direct_data() override;
|
|
|
|
|
2021-05-27 10:08:40 -04:00
|
|
|
const Curve *get_curve_for_render() 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 12:29:17 -05:00
|
|
|
static constexpr inline GeometryComponentType static_type = GEO_COMPONENT_TYPE_CURVE;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const blender::bke::ComponentAttributeProviders *get_attribute_providers() const final;
|
|
|
|
};
|
|
|
|
|
2021-05-04 10:16:24 +02:00
|
|
|
class InstanceReference {
|
|
|
|
public:
|
|
|
|
enum class Type {
|
|
|
|
/**
|
|
|
|
* An empty instance. This allows an `InstanceReference` to be default constructed without
|
|
|
|
* being in an invalid state. There might also be other use cases that we haven't explored much
|
|
|
|
* yet (such as changing the instance later on, and "disabling" some instances).
|
|
|
|
*/
|
|
|
|
None,
|
|
|
|
Object,
|
|
|
|
Collection,
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
Type type_ = Type::None;
|
|
|
|
/** Depending on the type this is either null, an Object or Collection pointer. */
|
|
|
|
void *data_ = nullptr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
InstanceReference() = default;
|
|
|
|
|
|
|
|
InstanceReference(Object &object) : type_(Type::Object), data_(&object)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
InstanceReference(Collection &collection) : type_(Type::Collection), data_(&collection)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Type type() const
|
|
|
|
{
|
|
|
|
return type_;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object &object() const
|
|
|
|
{
|
|
|
|
BLI_assert(type_ == Type::Object);
|
|
|
|
return *(Object *)data_;
|
|
|
|
}
|
|
|
|
|
|
|
|
Collection &collection() const
|
|
|
|
{
|
|
|
|
BLI_assert(type_ == Type::Collection);
|
|
|
|
return *(Collection *)data_;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t hash() const
|
|
|
|
{
|
|
|
|
return blender::get_default_hash(data_);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator==(const InstanceReference &a, const InstanceReference &b)
|
|
|
|
{
|
|
|
|
return a.data_ == b.data_;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
/** A geometry component that stores instances. */
|
|
|
|
class InstancesComponent : public GeometryComponent {
|
|
|
|
private:
|
2021-05-04 10:16:24 +02:00
|
|
|
/**
|
|
|
|
* Indexed set containing information about the data that is instanced.
|
|
|
|
* Actual instances store an index ("handle") into this set.
|
|
|
|
*/
|
|
|
|
blender::VectorSet<InstanceReference> references_;
|
|
|
|
|
|
|
|
/** Index into `references_`. Determines what data is instanced. */
|
|
|
|
blender::Vector<int> instance_reference_handles_;
|
|
|
|
/** Transformation of the instances. */
|
|
|
|
blender::Vector<blender::float4x4> instance_transforms_;
|
|
|
|
/**
|
|
|
|
* IDs of the instances. They are used for consistency over multiple frames for things like
|
|
|
|
* motion blur.
|
|
|
|
*/
|
|
|
|
blender::Vector<int> instance_ids_;
|
2020-12-02 13:25:25 +01:00
|
|
|
|
2021-02-12 17:41:28 +01:00
|
|
|
/* These almost unique ids are generated based on `ids_`, which might not contain unique ids at
|
|
|
|
* all. They are *almost* unique, because under certain very unlikely circumstances, they are not
|
|
|
|
* unique. Code using these ids should not crash when they are not unique but can generally
|
|
|
|
* expect them to be unique. */
|
|
|
|
mutable std::mutex almost_unique_ids_mutex_;
|
|
|
|
mutable blender::Array<int> almost_unique_ids_;
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
public:
|
|
|
|
InstancesComponent();
|
|
|
|
~InstancesComponent() = default;
|
|
|
|
GeometryComponent *copy() const override;
|
|
|
|
|
|
|
|
void clear();
|
2021-05-04 10:16:24 +02:00
|
|
|
|
|
|
|
void reserve(int min_capacity);
|
2021-05-08 23:57:36 -05:00
|
|
|
void resize(int capacity);
|
2021-05-04 10:16:24 +02:00
|
|
|
|
|
|
|
int add_reference(InstanceReference reference);
|
|
|
|
void add_instance(int instance_handle, const blender::float4x4 &transform, const int id = -1);
|
|
|
|
|
|
|
|
blender::Span<InstanceReference> references() const;
|
|
|
|
|
|
|
|
blender::Span<int> instance_reference_handles() const;
|
2021-05-08 23:57:36 -05:00
|
|
|
blender::MutableSpan<int> instance_reference_handles();
|
2021-05-04 10:16:24 +02:00
|
|
|
blender::MutableSpan<blender::float4x4> instance_transforms();
|
|
|
|
blender::Span<blender::float4x4> instance_transforms() const;
|
|
|
|
blender::MutableSpan<int> instance_ids();
|
|
|
|
blender::Span<int> instance_ids() const;
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
int instances_amount() const;
|
|
|
|
|
2021-02-12 17:41:28 +01:00
|
|
|
blender::Span<int> almost_unique_ids() const;
|
|
|
|
|
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;
|
|
|
|
|
2021-03-10 11:53:17 +01:00
|
|
|
static constexpr inline GeometryComponentType static_type = GEO_COMPONENT_TYPE_INSTANCES;
|
2020-12-02 13:25:25 +01:00
|
|
|
};
|
2021-01-21 10:32:42 +01:00
|
|
|
|
|
|
|
/** A geometry component that stores volume grids. */
|
|
|
|
class VolumeComponent : public GeometryComponent {
|
|
|
|
private:
|
|
|
|
Volume *volume_ = nullptr;
|
|
|
|
GeometryOwnershipType ownership_ = GeometryOwnershipType::Owned;
|
|
|
|
|
|
|
|
public:
|
|
|
|
VolumeComponent();
|
|
|
|
~VolumeComponent();
|
|
|
|
GeometryComponent *copy() const override;
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
bool has_volume() const;
|
|
|
|
void replace(Volume *volume, GeometryOwnershipType ownership = GeometryOwnershipType::Owned);
|
|
|
|
Volume *release();
|
|
|
|
|
|
|
|
const Volume *get_for_read() const;
|
|
|
|
Volume *get_for_write();
|
|
|
|
|
2021-04-08 17:35:06 +02:00
|
|
|
bool owns_direct_data() const override;
|
|
|
|
void ensure_owns_direct_data() override;
|
|
|
|
|
2021-03-10 11:53:17 +01:00
|
|
|
static constexpr inline GeometryComponentType static_type = GEO_COMPONENT_TYPE_VOLUME;
|
2021-01-21 10:32:42 +01:00
|
|
|
};
|