2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2020-12-02 13:25:25 +01:00
|
|
|
|
2022-06-05 21:05:13 +02:00
|
|
|
#include "BLI_bounds.hh"
|
Geometry Nodes: Make instances real on-demand
This commit makes the geometry output of the collection info usable.
The output is the geometry of a collection instance, but this commit
adds a utility to convert the instances to real geometry, used in the
background whenever it is needed, like copy on write.
The recursive nature of the "realize instances" code is essential,
because collection instances in the `InstancesComponent`, might have no
geometry sets of their own containing even more collection instances,
which might then contain object instances, etc.
Another consideration is that currently, every single instance contains
a reference to its data. This is inefficient since most of the time
there are many locations and only a few sets of unique data. So this
commit adds a `GeometryInstanceGroup` to support this future optimization.
The API for instances returns a vector of `GeometryInstanceGroup`.
This may be less efficient when there are many instances, but it makes
more complicated operations like point distribution that need to iterate
over input geometry multiple times much simpler.
Any code that needs to change data, like most of the attribute nodes,
can simply call `geometry_set_realize_instances(geometry_set)`,
which will move any geometry in the `InstancesComponent` to new "real"
geometry components.
Many nodes can support read-only access to instances in order to avoid
making them real, this will be addressed where needed in the near future.
Instances from the existing "dupli" system are not supported yet.
Differential Revision: https://developer.blender.org/D10327
2021-02-12 11:58:15 -06:00
|
|
|
#include "BLI_map.hh"
|
2021-09-28 10:17:00 +02:00
|
|
|
#include "BLI_task.hh"
|
Geometry Nodes: Make instances real on-demand
This commit makes the geometry output of the collection info usable.
The output is the geometry of a collection instance, but this commit
adds a utility to convert the instances to real geometry, used in the
background whenever it is needed, like copy on write.
The recursive nature of the "realize instances" code is essential,
because collection instances in the `InstancesComponent`, might have no
geometry sets of their own containing even more collection instances,
which might then contain object instances, etc.
Another consideration is that currently, every single instance contains
a reference to its data. This is inefficient since most of the time
there are many locations and only a few sets of unique data. So this
commit adds a `GeometryInstanceGroup` to support this future optimization.
The API for instances returns a vector of `GeometryInstanceGroup`.
This may be less efficient when there are many instances, but it makes
more complicated operations like point distribution that need to iterate
over input geometry multiple times much simpler.
Any code that needs to change data, like most of the attribute nodes,
can simply call `geometry_set_realize_instances(geometry_set)`,
which will move any geometry in the `InstancesComponent` to new "real"
geometry components.
Many nodes can support read-only access to instances in order to avoid
making them real, this will be addressed where needed in the near future.
Instances from the existing "dupli" system are not supported yet.
Differential Revision: https://developer.blender.org/D10327
2021-02-12 11:58:15 -06:00
|
|
|
|
2022-01-10 16:41:05 -06:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
Geometry Nodes: Make instances real on-demand
This commit makes the geometry output of the collection info usable.
The output is the geometry of a collection instance, but this commit
adds a utility to convert the instances to real geometry, used in the
background whenever it is needed, like copy on write.
The recursive nature of the "realize instances" code is essential,
because collection instances in the `InstancesComponent`, might have no
geometry sets of their own containing even more collection instances,
which might then contain object instances, etc.
Another consideration is that currently, every single instance contains
a reference to its data. This is inefficient since most of the time
there are many locations and only a few sets of unique data. So this
commit adds a `GeometryInstanceGroup` to support this future optimization.
The API for instances returns a vector of `GeometryInstanceGroup`.
This may be less efficient when there are many instances, but it makes
more complicated operations like point distribution that need to iterate
over input geometry multiple times much simpler.
Any code that needs to change data, like most of the attribute nodes,
can simply call `geometry_set_realize_instances(geometry_set)`,
which will move any geometry in the `InstancesComponent` to new "real"
geometry components.
Many nodes can support read-only access to instances in order to avoid
making them real, this will be addressed where needed in the near future.
Instances from the existing "dupli" system are not supported yet.
Differential Revision: https://developer.blender.org/D10327
2021-02-12 11:58:15 -06:00
|
|
|
#include "BKE_attribute.h"
|
|
|
|
|
#include "BKE_attribute_access.hh"
|
2022-02-28 10:46:34 -05:00
|
|
|
#include "BKE_curves.hh"
|
2022-04-01 08:40:45 -05:00
|
|
|
#include "BKE_geometry_fields.hh"
|
2020-12-02 13:25:25 +01:00
|
|
|
#include "BKE_geometry_set.hh"
|
|
|
|
|
#include "BKE_lib_id.h"
|
|
|
|
|
#include "BKE_mesh.h"
|
|
|
|
|
#include "BKE_mesh_wrapper.h"
|
Geometry Nodes: Make instances real on-demand
This commit makes the geometry output of the collection info usable.
The output is the geometry of a collection instance, but this commit
adds a utility to convert the instances to real geometry, used in the
background whenever it is needed, like copy on write.
The recursive nature of the "realize instances" code is essential,
because collection instances in the `InstancesComponent`, might have no
geometry sets of their own containing even more collection instances,
which might then contain object instances, etc.
Another consideration is that currently, every single instance contains
a reference to its data. This is inefficient since most of the time
there are many locations and only a few sets of unique data. So this
commit adds a `GeometryInstanceGroup` to support this future optimization.
The API for instances returns a vector of `GeometryInstanceGroup`.
This may be less efficient when there are many instances, but it makes
more complicated operations like point distribution that need to iterate
over input geometry multiple times much simpler.
Any code that needs to change data, like most of the attribute nodes,
can simply call `geometry_set_realize_instances(geometry_set)`,
which will move any geometry in the `InstancesComponent` to new "real"
geometry components.
Many nodes can support read-only access to instances in order to avoid
making them real, this will be addressed where needed in the near future.
Instances from the existing "dupli" system are not supported yet.
Differential Revision: https://developer.blender.org/D10327
2021-02-12 11:58:15 -06:00
|
|
|
#include "BKE_modifier.h"
|
2020-12-02 13:25:25 +01:00
|
|
|
#include "BKE_pointcloud.h"
|
2021-01-21 10:32:42 +01:00
|
|
|
#include "BKE_volume.h"
|
2020-12-02 13:25:25 +01:00
|
|
|
|
Geometry Nodes: Make instances real on-demand
This commit makes the geometry output of the collection info usable.
The output is the geometry of a collection instance, but this commit
adds a utility to convert the instances to real geometry, used in the
background whenever it is needed, like copy on write.
The recursive nature of the "realize instances" code is essential,
because collection instances in the `InstancesComponent`, might have no
geometry sets of their own containing even more collection instances,
which might then contain object instances, etc.
Another consideration is that currently, every single instance contains
a reference to its data. This is inefficient since most of the time
there are many locations and only a few sets of unique data. So this
commit adds a `GeometryInstanceGroup` to support this future optimization.
The API for instances returns a vector of `GeometryInstanceGroup`.
This may be less efficient when there are many instances, but it makes
more complicated operations like point distribution that need to iterate
over input geometry multiple times much simpler.
Any code that needs to change data, like most of the attribute nodes,
can simply call `geometry_set_realize_instances(geometry_set)`,
which will move any geometry in the `InstancesComponent` to new "real"
geometry components.
Many nodes can support read-only access to instances in order to avoid
making them real, this will be addressed where needed in the near future.
Instances from the existing "dupli" system are not supported yet.
Differential Revision: https://developer.blender.org/D10327
2021-02-12 11:58:15 -06:00
|
|
|
#include "DNA_collection_types.h"
|
2020-12-02 13:25:25 +01:00
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
|
2021-02-12 17:41:28 +01:00
|
|
|
#include "BLI_rand.hh"
|
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
using blender::float3;
|
2021-01-26 18:21:12 +01:00
|
|
|
using blender::float4x4;
|
Geometry Nodes: Make instances real on-demand
This commit makes the geometry output of the collection info usable.
The output is the geometry of a collection instance, but this commit
adds a utility to convert the instances to real geometry, used in the
background whenever it is needed, like copy on write.
The recursive nature of the "realize instances" code is essential,
because collection instances in the `InstancesComponent`, might have no
geometry sets of their own containing even more collection instances,
which might then contain object instances, etc.
Another consideration is that currently, every single instance contains
a reference to its data. This is inefficient since most of the time
there are many locations and only a few sets of unique data. So this
commit adds a `GeometryInstanceGroup` to support this future optimization.
The API for instances returns a vector of `GeometryInstanceGroup`.
This may be less efficient when there are many instances, but it makes
more complicated operations like point distribution that need to iterate
over input geometry multiple times much simpler.
Any code that needs to change data, like most of the attribute nodes,
can simply call `geometry_set_realize_instances(geometry_set)`,
which will move any geometry in the `InstancesComponent` to new "real"
geometry components.
Many nodes can support read-only access to instances in order to avoid
making them real, this will be addressed where needed in the near future.
Instances from the existing "dupli" system are not supported yet.
Differential Revision: https://developer.blender.org/D10327
2021-02-12 11:58:15 -06:00
|
|
|
using blender::Map;
|
2020-12-02 13:25:25 +01:00
|
|
|
using blender::MutableSpan;
|
|
|
|
|
using blender::Span;
|
|
|
|
|
using blender::StringRef;
|
|
|
|
|
using blender::Vector;
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Geometry Component
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
|
GeometryComponent::GeometryComponent(GeometryComponentType type) : type_(type)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GeometryComponent *GeometryComponent::create(GeometryComponentType component_type)
|
|
|
|
|
{
|
|
|
|
|
switch (component_type) {
|
2021-03-10 11:53:17 +01:00
|
|
|
case GEO_COMPONENT_TYPE_MESH:
|
2020-12-02 13:25:25 +01:00
|
|
|
return new MeshComponent();
|
2021-03-10 11:53:17 +01:00
|
|
|
case GEO_COMPONENT_TYPE_POINT_CLOUD:
|
2020-12-02 13:25:25 +01:00
|
|
|
return new PointCloudComponent();
|
2021-03-10 11:53:17 +01:00
|
|
|
case GEO_COMPONENT_TYPE_INSTANCES:
|
2020-12-02 13:25:25 +01:00
|
|
|
return new InstancesComponent();
|
2021-03-10 11:53:17 +01:00
|
|
|
case GEO_COMPONENT_TYPE_VOLUME:
|
2021-01-21 10:32:42 +01:00
|
|
|
return new VolumeComponent();
|
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
|
|
|
case GEO_COMPONENT_TYPE_CURVE:
|
|
|
|
|
return new CurveComponent();
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
2021-03-23 16:49:47 +01:00
|
|
|
BLI_assert_unreachable();
|
2020-12-02 13:25:25 +01:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GeometryComponent::user_add() const
|
|
|
|
|
{
|
|
|
|
|
users_.fetch_add(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GeometryComponent::user_remove() const
|
|
|
|
|
{
|
|
|
|
|
const int new_users = users_.fetch_sub(1) - 1;
|
|
|
|
|
if (new_users == 0) {
|
|
|
|
|
delete this;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GeometryComponent::is_mutable() const
|
|
|
|
|
{
|
|
|
|
|
/* If the item is shared, it is read-only. */
|
|
|
|
|
/* The user count can be 0, when this is called from the destructor. */
|
|
|
|
|
return users_ <= 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GeometryComponentType GeometryComponent::type() const
|
|
|
|
|
{
|
|
|
|
|
return type_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GeometryComponent::is_empty() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Geometry Set
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2021-10-03 16:58:33 +02:00
|
|
|
GeometrySet::GeometrySet() = default;
|
|
|
|
|
GeometrySet::GeometrySet(const GeometrySet &other) = default;
|
|
|
|
|
GeometrySet::GeometrySet(GeometrySet &&other) = default;
|
|
|
|
|
GeometrySet::~GeometrySet() = default;
|
|
|
|
|
GeometrySet &GeometrySet::operator=(const GeometrySet &other) = default;
|
|
|
|
|
GeometrySet &GeometrySet::operator=(GeometrySet &&other) = default;
|
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
GeometryComponent &GeometrySet::get_component_for_write(GeometryComponentType component_type)
|
|
|
|
|
{
|
2021-12-05 15:10:11 +01:00
|
|
|
GeometryComponentPtr &component_ptr = components_[component_type];
|
|
|
|
|
if (!component_ptr) {
|
|
|
|
|
/* If the component did not exist before, create a new one. */
|
|
|
|
|
component_ptr = GeometryComponent::create(component_type);
|
|
|
|
|
return *component_ptr;
|
|
|
|
|
}
|
|
|
|
|
if (component_ptr->is_mutable()) {
|
|
|
|
|
/* If the referenced component is already mutable, return it directly. */
|
|
|
|
|
return *component_ptr;
|
|
|
|
|
}
|
|
|
|
|
/* If the referenced component is shared, make a copy. The copy is not shared and is
|
|
|
|
|
* therefore mutable. */
|
|
|
|
|
component_ptr = component_ptr->copy();
|
|
|
|
|
return *component_ptr;
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-14 12:43:36 -05:00
|
|
|
GeometryComponent *GeometrySet::get_component_ptr(GeometryComponentType type)
|
|
|
|
|
{
|
2021-10-15 13:39:11 +02:00
|
|
|
if (this->has(type)) {
|
|
|
|
|
return &this->get_component_for_write(type);
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
2021-10-14 12:43:36 -05:00
|
|
|
}
|
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
const GeometryComponent *GeometrySet::get_component_for_read(
|
|
|
|
|
GeometryComponentType component_type) const
|
|
|
|
|
{
|
2021-12-05 15:10:11 +01:00
|
|
|
return components_[component_type].get();
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GeometrySet::has(const GeometryComponentType component_type) const
|
|
|
|
|
{
|
2021-12-05 15:10:11 +01:00
|
|
|
return components_[component_type].has_value();
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GeometrySet::remove(const GeometryComponentType component_type)
|
|
|
|
|
{
|
2021-12-05 15:10:11 +01:00
|
|
|
components_[component_type].reset();
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
2021-09-28 15:52:04 +02:00
|
|
|
void GeometrySet::keep_only(const blender::Span<GeometryComponentType> component_types)
|
|
|
|
|
{
|
2021-12-05 15:10:11 +01:00
|
|
|
for (GeometryComponentPtr &component_ptr : components_) {
|
|
|
|
|
if (component_ptr) {
|
|
|
|
|
if (!component_types.contains(component_ptr->type())) {
|
|
|
|
|
component_ptr.reset();
|
|
|
|
|
}
|
2021-09-28 15:52:04 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
void GeometrySet::add(const GeometryComponent &component)
|
|
|
|
|
{
|
2021-12-05 15:10:11 +01:00
|
|
|
BLI_assert(!components_[component.type()]);
|
2020-12-02 13:25:25 +01:00
|
|
|
component.user_add();
|
2021-12-05 15:10:11 +01:00
|
|
|
components_[component.type()] = const_cast<GeometryComponent *>(&component);
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-19 12:29:37 +01:00
|
|
|
Vector<const GeometryComponent *> GeometrySet::get_components_for_read() const
|
|
|
|
|
{
|
|
|
|
|
Vector<const GeometryComponent *> components;
|
2021-12-05 15:10:11 +01:00
|
|
|
for (const GeometryComponentPtr &component_ptr : components_) {
|
|
|
|
|
if (component_ptr) {
|
|
|
|
|
components.append(component_ptr.get());
|
|
|
|
|
}
|
2021-02-19 12:29:37 +01:00
|
|
|
}
|
|
|
|
|
return components;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-29 12:27:24 -03:00
|
|
|
bool GeometrySet::compute_boundbox_without_instances(float3 *r_min, float3 *r_max) const
|
2020-12-02 13:25:25 +01:00
|
|
|
{
|
2022-06-05 21:05:13 +02:00
|
|
|
using namespace blender;
|
2021-12-29 12:27:24 -03:00
|
|
|
bool have_minmax = false;
|
2022-04-05 16:40:28 -05:00
|
|
|
if (const PointCloud *pointcloud = this->get_pointcloud_for_read()) {
|
2021-12-29 12:27:24 -03:00
|
|
|
have_minmax |= BKE_pointcloud_minmax(pointcloud, *r_min, *r_max);
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
2022-04-05 16:40:28 -05:00
|
|
|
if (const Mesh *mesh = this->get_mesh_for_read()) {
|
2021-12-29 12:27:24 -03:00
|
|
|
have_minmax |= BKE_mesh_wrapper_minmax(mesh, *r_min, *r_max);
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
2022-04-05 16:40:28 -05:00
|
|
|
if (const Volume *volume = this->get_volume_for_read()) {
|
2021-12-29 12:27:24 -03:00
|
|
|
have_minmax |= BKE_volume_min_max(volume, *r_min, *r_max);
|
2021-04-08 14:32:41 -05:00
|
|
|
}
|
2022-06-05 21:05:13 +02:00
|
|
|
if (const Curves *curves_id = this->get_curves_for_read()) {
|
|
|
|
|
const bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry);
|
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
|
|
|
/* Using the evaluated positions is somewhat arbitrary, but it is probably expected. */
|
2022-06-05 21:05:13 +02:00
|
|
|
std::optional<bounds::MinMaxResult<float3>> min_max = bounds::min_max(
|
|
|
|
|
curves.evaluated_positions());
|
|
|
|
|
if (min_max) {
|
|
|
|
|
have_minmax = true;
|
|
|
|
|
*r_min = math::min(*r_min, min_max->min);
|
|
|
|
|
*r_max = math::max(*r_max, min_max->max);
|
|
|
|
|
}
|
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
|
|
|
}
|
2021-12-29 12:27:24 -03:00
|
|
|
return have_minmax;
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::ostream &operator<<(std::ostream &stream, const GeometrySet &geometry_set)
|
|
|
|
|
{
|
|
|
|
|
stream << "<GeometrySet at " << &geometry_set << ", " << geometry_set.components_.size()
|
|
|
|
|
<< " components>";
|
|
|
|
|
return stream;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-30 12:34:05 +02:00
|
|
|
void GeometrySet::clear()
|
|
|
|
|
{
|
2021-12-05 15:10:11 +01:00
|
|
|
for (GeometryComponentPtr &component_ptr : components_) {
|
|
|
|
|
component_ptr.reset();
|
|
|
|
|
}
|
2021-03-30 12:34:05 +02:00
|
|
|
}
|
|
|
|
|
|
2021-04-08 17:35:06 +02:00
|
|
|
void GeometrySet::ensure_owns_direct_data()
|
|
|
|
|
{
|
2021-12-05 15:10:11 +01:00
|
|
|
for (GeometryComponentPtr &component_ptr : components_) {
|
|
|
|
|
if (!component_ptr) {
|
|
|
|
|
continue;
|
2021-04-08 17:35:06 +02:00
|
|
|
}
|
2021-12-05 15:10:11 +01:00
|
|
|
if (component_ptr->owns_direct_data()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
GeometryComponent &component_for_write = this->get_component_for_write(component_ptr->type());
|
|
|
|
|
component_for_write.ensure_owns_direct_data();
|
2021-04-08 17:35:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-06 18:22:24 +02:00
|
|
|
bool GeometrySet::owns_direct_data() const
|
|
|
|
|
{
|
2021-12-05 15:10:11 +01:00
|
|
|
for (const GeometryComponentPtr &component_ptr : components_) {
|
|
|
|
|
if (component_ptr) {
|
|
|
|
|
if (!component_ptr->owns_direct_data()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-09-06 18:22:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
const Mesh *GeometrySet::get_mesh_for_read() const
|
|
|
|
|
{
|
|
|
|
|
const MeshComponent *component = this->get_component_for_read<MeshComponent>();
|
|
|
|
|
return (component == nullptr) ? nullptr : component->get_for_read();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GeometrySet::has_mesh() const
|
|
|
|
|
{
|
|
|
|
|
const MeshComponent *component = this->get_component_for_read<MeshComponent>();
|
|
|
|
|
return component != nullptr && component->has_mesh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const PointCloud *GeometrySet::get_pointcloud_for_read() const
|
|
|
|
|
{
|
|
|
|
|
const PointCloudComponent *component = this->get_component_for_read<PointCloudComponent>();
|
|
|
|
|
return (component == nullptr) ? nullptr : component->get_for_read();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-21 10:32:42 +01:00
|
|
|
const Volume *GeometrySet::get_volume_for_read() const
|
|
|
|
|
{
|
|
|
|
|
const VolumeComponent *component = this->get_component_for_read<VolumeComponent>();
|
|
|
|
|
return (component == nullptr) ? nullptr : component->get_for_read();
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 10:53:30 -05:00
|
|
|
const Curves *GeometrySet::get_curves_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 CurveComponent *component = this->get_component_for_read<CurveComponent>();
|
|
|
|
|
return (component == nullptr) ? nullptr : component->get_for_read();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
bool GeometrySet::has_pointcloud() const
|
|
|
|
|
{
|
|
|
|
|
const PointCloudComponent *component = this->get_component_for_read<PointCloudComponent>();
|
|
|
|
|
return component != nullptr && component->has_pointcloud();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GeometrySet::has_instances() const
|
|
|
|
|
{
|
|
|
|
|
const InstancesComponent *component = this->get_component_for_read<InstancesComponent>();
|
2022-05-11 12:59:58 +10:00
|
|
|
return component != nullptr && component->instances_num() >= 1;
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
2021-01-21 10:32:42 +01:00
|
|
|
bool GeometrySet::has_volume() const
|
|
|
|
|
{
|
|
|
|
|
const VolumeComponent *component = this->get_component_for_read<VolumeComponent>();
|
|
|
|
|
return component != nullptr && component->has_volume();
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 10:53:30 -05:00
|
|
|
bool GeometrySet::has_curves() 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 CurveComponent *component = this->get_component_for_read<CurveComponent>();
|
2022-02-28 10:46:34 -05:00
|
|
|
return component != nullptr && component->has_curves();
|
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
|
|
|
}
|
|
|
|
|
|
2021-09-27 10:16:38 +02:00
|
|
|
bool GeometrySet::has_realized_data() const
|
|
|
|
|
{
|
2021-12-05 15:10:11 +01:00
|
|
|
for (const GeometryComponentPtr &component_ptr : components_) {
|
|
|
|
|
if (component_ptr) {
|
|
|
|
|
if (component_ptr->type() != GEO_COMPONENT_TYPE_INSTANCES) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-27 10:16:38 +02:00
|
|
|
}
|
2021-12-05 15:10:11 +01:00
|
|
|
return false;
|
2021-09-27 10:16:38 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-28 11:36:28 -05:00
|
|
|
bool GeometrySet::is_empty() const
|
|
|
|
|
{
|
2022-02-28 10:53:30 -05:00
|
|
|
return !(this->has_mesh() || this->has_curves() || this->has_pointcloud() ||
|
|
|
|
|
this->has_volume() || this->has_instances());
|
2021-09-28 11:36:28 -05:00
|
|
|
}
|
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
GeometrySet GeometrySet::create_with_mesh(Mesh *mesh, GeometryOwnershipType ownership)
|
|
|
|
|
{
|
|
|
|
|
GeometrySet geometry_set;
|
2021-10-14 12:43:36 -05:00
|
|
|
if (mesh != nullptr) {
|
|
|
|
|
MeshComponent &component = geometry_set.get_component_for_write<MeshComponent>();
|
|
|
|
|
component.replace(mesh, ownership);
|
|
|
|
|
}
|
2020-12-02 13:25:25 +01:00
|
|
|
return geometry_set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GeometrySet GeometrySet::create_with_pointcloud(PointCloud *pointcloud,
|
|
|
|
|
GeometryOwnershipType ownership)
|
|
|
|
|
{
|
|
|
|
|
GeometrySet geometry_set;
|
2021-10-14 12:43:36 -05:00
|
|
|
if (pointcloud != nullptr) {
|
|
|
|
|
PointCloudComponent &component = geometry_set.get_component_for_write<PointCloudComponent>();
|
|
|
|
|
component.replace(pointcloud, ownership);
|
|
|
|
|
}
|
2020-12-02 13:25:25 +01:00
|
|
|
return geometry_set;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 10:53:30 -05:00
|
|
|
GeometrySet GeometrySet::create_with_curves(Curves *curves, GeometryOwnershipType ownership)
|
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
|
|
|
{
|
|
|
|
|
GeometrySet geometry_set;
|
2022-02-28 10:46:34 -05:00
|
|
|
if (curves != nullptr) {
|
2021-10-14 12:43:36 -05:00
|
|
|
CurveComponent &component = geometry_set.get_component_for_write<CurveComponent>();
|
2022-02-28 10:46:34 -05:00
|
|
|
component.replace(curves, ownership);
|
2021-10-14 12:43:36 -05: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
|
|
|
return geometry_set;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
void GeometrySet::replace_mesh(Mesh *mesh, GeometryOwnershipType ownership)
|
|
|
|
|
{
|
2021-10-14 12:43:36 -05:00
|
|
|
if (mesh == nullptr) {
|
|
|
|
|
this->remove<MeshComponent>();
|
2021-12-09 14:34:15 -06:00
|
|
|
return;
|
2021-10-14 12:43:36 -05:00
|
|
|
}
|
2021-12-09 17:43:30 -06:00
|
|
|
if (mesh == this->get_mesh_for_read()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this->remove<MeshComponent>();
|
2021-12-09 14:34:15 -06:00
|
|
|
MeshComponent &component = this->get_component_for_write<MeshComponent>();
|
|
|
|
|
component.replace(mesh, ownership);
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-07 16:26:55 -06:00
|
|
|
void GeometrySet::replace_curves(Curves *curves, GeometryOwnershipType ownership)
|
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
|
|
|
{
|
2022-02-28 10:46:34 -05:00
|
|
|
if (curves == nullptr) {
|
2021-10-14 12:43:36 -05:00
|
|
|
this->remove<CurveComponent>();
|
2021-12-09 14:34:15 -06:00
|
|
|
return;
|
2021-10-14 12:43:36 -05:00
|
|
|
}
|
2022-02-28 10:53:30 -05:00
|
|
|
if (curves == this->get_curves_for_read()) {
|
2021-12-09 17:43:30 -06:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this->remove<CurveComponent>();
|
2021-12-09 14:34:15 -06:00
|
|
|
CurveComponent &component = this->get_component_for_write<CurveComponent>();
|
2022-02-28 10:46:34 -05:00
|
|
|
component.replace(curves, ownership);
|
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
|
|
|
}
|
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
void GeometrySet::replace_pointcloud(PointCloud *pointcloud, GeometryOwnershipType ownership)
|
|
|
|
|
{
|
2021-10-14 12:43:36 -05:00
|
|
|
if (pointcloud == nullptr) {
|
|
|
|
|
this->remove<PointCloudComponent>();
|
2021-12-09 14:34:15 -06:00
|
|
|
return;
|
2021-10-14 12:43:36 -05:00
|
|
|
}
|
2021-12-09 17:43:30 -06:00
|
|
|
if (pointcloud == this->get_pointcloud_for_read()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this->remove<PointCloudComponent>();
|
2021-12-09 14:34:15 -06:00
|
|
|
PointCloudComponent &component = this->get_component_for_write<PointCloudComponent>();
|
|
|
|
|
component.replace(pointcloud, ownership);
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-26 14:42:03 -05:00
|
|
|
void GeometrySet::replace_volume(Volume *volume, GeometryOwnershipType ownership)
|
|
|
|
|
{
|
2021-10-14 12:43:36 -05:00
|
|
|
if (volume == nullptr) {
|
|
|
|
|
this->remove<VolumeComponent>();
|
2021-12-09 14:34:15 -06:00
|
|
|
return;
|
2021-10-14 12:43:36 -05:00
|
|
|
}
|
2021-12-09 17:43:30 -06:00
|
|
|
if (volume == this->get_volume_for_read()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this->remove<VolumeComponent>();
|
2021-12-09 14:34:15 -06:00
|
|
|
VolumeComponent &component = this->get_component_for_write<VolumeComponent>();
|
|
|
|
|
component.replace(volume, ownership);
|
2021-04-26 14:42:03 -05:00
|
|
|
}
|
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
Mesh *GeometrySet::get_mesh_for_write()
|
|
|
|
|
{
|
2021-10-14 12:43:36 -05:00
|
|
|
MeshComponent *component = this->get_component_ptr<MeshComponent>();
|
|
|
|
|
return component == nullptr ? nullptr : component->get_for_write();
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PointCloud *GeometrySet::get_pointcloud_for_write()
|
|
|
|
|
{
|
2021-10-14 12:43:36 -05:00
|
|
|
PointCloudComponent *component = this->get_component_ptr<PointCloudComponent>();
|
|
|
|
|
return component == nullptr ? nullptr : component->get_for_write();
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
2021-01-21 10:32:42 +01:00
|
|
|
Volume *GeometrySet::get_volume_for_write()
|
|
|
|
|
{
|
2021-10-14 12:43:36 -05:00
|
|
|
VolumeComponent *component = this->get_component_ptr<VolumeComponent>();
|
|
|
|
|
return component == nullptr ? nullptr : component->get_for_write();
|
2021-01-21 10:32:42 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-28 10:53:30 -05:00
|
|
|
Curves *GeometrySet::get_curves_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
|
|
|
{
|
2021-10-14 12:43:36 -05:00
|
|
|
CurveComponent *component = this->get_component_ptr<CurveComponent>();
|
|
|
|
|
return component == nullptr ? nullptr : component->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 12:29:17 -05:00
|
|
|
}
|
|
|
|
|
|
2021-09-23 17:50:33 +02:00
|
|
|
void GeometrySet::attribute_foreach(const Span<GeometryComponentType> component_types,
|
|
|
|
|
const bool include_instances,
|
|
|
|
|
const AttributeForeachCallback callback) const
|
|
|
|
|
{
|
|
|
|
|
using namespace blender;
|
|
|
|
|
using namespace blender::bke;
|
|
|
|
|
for (const GeometryComponentType component_type : component_types) {
|
|
|
|
|
if (!this->has(component_type)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
const GeometryComponent &component = *this->get_component_for_read(component_type);
|
|
|
|
|
component.attribute_foreach(
|
|
|
|
|
[&](const AttributeIDRef &attribute_id, const AttributeMetaData &meta_data) {
|
|
|
|
|
callback(attribute_id, meta_data, component);
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (include_instances && this->has_instances()) {
|
|
|
|
|
const InstancesComponent &instances = *this->get_component_for_read<InstancesComponent>();
|
|
|
|
|
instances.foreach_referenced_geometry([&](const GeometrySet &instance_geometry_set) {
|
|
|
|
|
instance_geometry_set.attribute_foreach(component_types, include_instances, callback);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GeometrySet::gather_attributes_for_propagation(
|
|
|
|
|
const Span<GeometryComponentType> component_types,
|
|
|
|
|
const GeometryComponentType dst_component_type,
|
|
|
|
|
bool include_instances,
|
|
|
|
|
blender::Map<blender::bke::AttributeIDRef, AttributeKind> &r_attributes) const
|
|
|
|
|
{
|
|
|
|
|
using namespace blender;
|
|
|
|
|
using namespace blender::bke;
|
|
|
|
|
/* Only needed right now to check if an attribute is built-in on this component type.
|
|
|
|
|
* TODO: Get rid of the dummy component. */
|
|
|
|
|
const GeometryComponent *dummy_component = GeometryComponent::create(dst_component_type);
|
|
|
|
|
this->attribute_foreach(
|
|
|
|
|
component_types,
|
|
|
|
|
include_instances,
|
|
|
|
|
[&](const AttributeIDRef &attribute_id,
|
|
|
|
|
const AttributeMetaData &meta_data,
|
|
|
|
|
const GeometryComponent &component) {
|
|
|
|
|
if (component.attribute_is_builtin(attribute_id)) {
|
|
|
|
|
if (!dummy_component->attribute_is_builtin(attribute_id)) {
|
|
|
|
|
/* Don't propagate built-in attributes that are not built-in on the destination
|
|
|
|
|
* component. */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-20 09:57:54 -05:00
|
|
|
|
|
|
|
|
if (!attribute_id.should_be_kept()) {
|
|
|
|
|
return;
|
2021-09-23 17:50:33 +02:00
|
|
|
}
|
2021-10-20 09:57:54 -05:00
|
|
|
|
2022-06-01 14:38:06 +10:00
|
|
|
eAttrDomain domain = meta_data.domain;
|
Geometry Nodes: support instance attributes when realizing instances
This patch refactors the instance-realization code and adds new functionality.
* Named and anonymous attributes are propagated from instances to the
realized geometry. If the same attribute exists on the geometry and on an
instance, the attribute on the geometry has precedence.
* The id attribute has special handling to avoid creating the same id on many
output points. This is necessary to make e.g. the Random Value node work
as expected afterwards.
Realizing instance attributes has an effect on existing files, especially due to the
id attribute. To avoid breaking existing files, the Realize Instances node now has
a legacy option that is enabled for all already existing Realize Instances nodes.
Removing this legacy behavior does affect some existing files (although not many).
We can decide whether it's worth to remove the old behavior as a separate step.
This refactor also improves performance when realizing instances. That is mainly
due to multi-threading. See D13446 to get the file used for benchmarking. The
curve code is not as optimized as it could be yet. That's mainly because the storage
for these attributes might change soonish and it wasn't worth optimizing for the
current storage format right now.
```
1,000,000 x mesh vertex: 530 ms -> 130 ms
1,000,000 x simple cube: 1290 ms -> 190 ms
1,000,000 x point: 1000 ms -> 150 ms
1,000,000 x curve spiral: 1740 ms -> 330 ms
1,000,000 x curve line: 1110 ms -> 210 ms
10,000 x subdivided cylinder: 170 ms -> 40 ms
10 x subdivided spiral: 180 ms -> 180 ms
```
Differential Revision: https://developer.blender.org/D13446
2021-12-14 15:57:58 +01:00
|
|
|
if (dst_component_type != GEO_COMPONENT_TYPE_INSTANCES && domain == ATTR_DOMAIN_INSTANCE) {
|
|
|
|
|
domain = ATTR_DOMAIN_POINT;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 17:50:33 +02:00
|
|
|
auto add_info = [&](AttributeKind *attribute_kind) {
|
Geometry Nodes: support instance attributes when realizing instances
This patch refactors the instance-realization code and adds new functionality.
* Named and anonymous attributes are propagated from instances to the
realized geometry. If the same attribute exists on the geometry and on an
instance, the attribute on the geometry has precedence.
* The id attribute has special handling to avoid creating the same id on many
output points. This is necessary to make e.g. the Random Value node work
as expected afterwards.
Realizing instance attributes has an effect on existing files, especially due to the
id attribute. To avoid breaking existing files, the Realize Instances node now has
a legacy option that is enabled for all already existing Realize Instances nodes.
Removing this legacy behavior does affect some existing files (although not many).
We can decide whether it's worth to remove the old behavior as a separate step.
This refactor also improves performance when realizing instances. That is mainly
due to multi-threading. See D13446 to get the file used for benchmarking. The
curve code is not as optimized as it could be yet. That's mainly because the storage
for these attributes might change soonish and it wasn't worth optimizing for the
current storage format right now.
```
1,000,000 x mesh vertex: 530 ms -> 130 ms
1,000,000 x simple cube: 1290 ms -> 190 ms
1,000,000 x point: 1000 ms -> 150 ms
1,000,000 x curve spiral: 1740 ms -> 330 ms
1,000,000 x curve line: 1110 ms -> 210 ms
10,000 x subdivided cylinder: 170 ms -> 40 ms
10 x subdivided spiral: 180 ms -> 180 ms
```
Differential Revision: https://developer.blender.org/D13446
2021-12-14 15:57:58 +01:00
|
|
|
attribute_kind->domain = domain;
|
2021-09-23 17:50:33 +02:00
|
|
|
attribute_kind->data_type = meta_data.data_type;
|
|
|
|
|
};
|
|
|
|
|
auto modify_info = [&](AttributeKind *attribute_kind) {
|
|
|
|
|
attribute_kind->domain = bke::attribute_domain_highest_priority(
|
Geometry Nodes: support instance attributes when realizing instances
This patch refactors the instance-realization code and adds new functionality.
* Named and anonymous attributes are propagated from instances to the
realized geometry. If the same attribute exists on the geometry and on an
instance, the attribute on the geometry has precedence.
* The id attribute has special handling to avoid creating the same id on many
output points. This is necessary to make e.g. the Random Value node work
as expected afterwards.
Realizing instance attributes has an effect on existing files, especially due to the
id attribute. To avoid breaking existing files, the Realize Instances node now has
a legacy option that is enabled for all already existing Realize Instances nodes.
Removing this legacy behavior does affect some existing files (although not many).
We can decide whether it's worth to remove the old behavior as a separate step.
This refactor also improves performance when realizing instances. That is mainly
due to multi-threading. See D13446 to get the file used for benchmarking. The
curve code is not as optimized as it could be yet. That's mainly because the storage
for these attributes might change soonish and it wasn't worth optimizing for the
current storage format right now.
```
1,000,000 x mesh vertex: 530 ms -> 130 ms
1,000,000 x simple cube: 1290 ms -> 190 ms
1,000,000 x point: 1000 ms -> 150 ms
1,000,000 x curve spiral: 1740 ms -> 330 ms
1,000,000 x curve line: 1110 ms -> 210 ms
10,000 x subdivided cylinder: 170 ms -> 40 ms
10 x subdivided spiral: 180 ms -> 180 ms
```
Differential Revision: https://developer.blender.org/D13446
2021-12-14 15:57:58 +01:00
|
|
|
{attribute_kind->domain, domain});
|
2021-09-23 17:50:33 +02:00
|
|
|
attribute_kind->data_type = bke::attribute_data_type_highest_complexity(
|
|
|
|
|
{attribute_kind->data_type, meta_data.data_type});
|
|
|
|
|
};
|
|
|
|
|
r_attributes.add_or_modify(attribute_id, add_info, modify_info);
|
|
|
|
|
});
|
|
|
|
|
delete dummy_component;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-26 20:00:03 +02:00
|
|
|
static void gather_component_types_recursive(const GeometrySet &geometry_set,
|
|
|
|
|
const bool include_instances,
|
|
|
|
|
const bool ignore_empty,
|
|
|
|
|
Vector<GeometryComponentType> &r_types)
|
|
|
|
|
{
|
|
|
|
|
for (const GeometryComponent *component : geometry_set.get_components_for_read()) {
|
|
|
|
|
if (ignore_empty) {
|
|
|
|
|
if (component->is_empty()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
r_types.append_non_duplicates(component->type());
|
|
|
|
|
}
|
|
|
|
|
if (!include_instances) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const InstancesComponent *instances = geometry_set.get_component_for_read<InstancesComponent>();
|
|
|
|
|
if (instances == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
instances->foreach_referenced_geometry([&](const GeometrySet &instance_geometry_set) {
|
|
|
|
|
gather_component_types_recursive(
|
|
|
|
|
instance_geometry_set, include_instances, ignore_empty, r_types);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
blender::Vector<GeometryComponentType> GeometrySet::gather_component_types(
|
|
|
|
|
const bool include_instances, bool ignore_empty) const
|
|
|
|
|
{
|
|
|
|
|
Vector<GeometryComponentType> types;
|
|
|
|
|
gather_component_types_recursive(*this, include_instances, ignore_empty, types);
|
|
|
|
|
return types;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-28 10:17:00 +02:00
|
|
|
static void gather_mutable_geometry_sets(GeometrySet &geometry_set,
|
|
|
|
|
Vector<GeometrySet *> &r_geometry_sets)
|
2021-09-27 17:35:26 +02:00
|
|
|
{
|
2021-09-28 10:17:00 +02:00
|
|
|
r_geometry_sets.append(&geometry_set);
|
|
|
|
|
if (!geometry_set.has_instances()) {
|
2021-09-27 17:35:26 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* In the future this can be improved by deduplicating instance references across different
|
|
|
|
|
* instances. */
|
2021-09-28 10:17:00 +02:00
|
|
|
InstancesComponent &instances_component =
|
|
|
|
|
geometry_set.get_component_for_write<InstancesComponent>();
|
2021-09-27 17:35:26 +02:00
|
|
|
instances_component.ensure_geometry_instances();
|
|
|
|
|
for (const int handle : instances_component.references().index_range()) {
|
|
|
|
|
if (instances_component.references()[handle].type() == InstanceReference::Type::GeometrySet) {
|
|
|
|
|
GeometrySet &instance_geometry = instances_component.geometry_set_from_reference(handle);
|
2021-09-28 10:17:00 +02:00
|
|
|
gather_mutable_geometry_sets(instance_geometry, r_geometry_sets);
|
2021-09-27 17:35:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-28 10:17:00 +02:00
|
|
|
void GeometrySet::modify_geometry_sets(ForeachSubGeometryCallback callback)
|
|
|
|
|
{
|
|
|
|
|
Vector<GeometrySet *> geometry_sets;
|
|
|
|
|
gather_mutable_geometry_sets(*this, geometry_sets);
|
2022-04-26 09:24:18 -05:00
|
|
|
if (geometry_sets.size() == 1) {
|
|
|
|
|
/* Avoid possible overhead and a large call stack when multithreading is pointless. */
|
|
|
|
|
callback(*geometry_sets.first());
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
blender::threading::parallel_for_each(
|
|
|
|
|
geometry_sets, [&](GeometrySet *geometry_set) { callback(*geometry_set); });
|
|
|
|
|
}
|
2021-09-28 10:17:00 +02:00
|
|
|
}
|
|
|
|
|
|
2021-01-21 10:32:42 +01:00
|
|
|
/** \} */
|
|
|
|
|
|
2022-01-10 16:41:05 -06:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Mesh and Curve Normals Field Input
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
|
namespace blender::bke {
|
|
|
|
|
|
|
|
|
|
GVArray NormalFieldInput::get_varray_for_context(const GeometryComponent &component,
|
2022-06-01 14:38:06 +10:00
|
|
|
const eAttrDomain domain,
|
2022-01-10 16:41:05 -06:00
|
|
|
IndexMask mask) const
|
|
|
|
|
{
|
|
|
|
|
if (component.type() == GEO_COMPONENT_TYPE_MESH) {
|
|
|
|
|
const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
|
|
|
|
|
if (const Mesh *mesh = mesh_component.get_for_read()) {
|
|
|
|
|
return mesh_normals_varray(mesh_component, *mesh, mask, domain);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (component.type() == GEO_COMPONENT_TYPE_CURVE) {
|
|
|
|
|
const CurveComponent &curve_component = static_cast<const CurveComponent &>(component);
|
|
|
|
|
return curve_normals_varray(curve_component, domain);
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string NormalFieldInput::socket_inspection_name() const
|
|
|
|
|
{
|
|
|
|
|
return TIP_("Normal");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t NormalFieldInput::hash() const
|
|
|
|
|
{
|
|
|
|
|
return 213980475983;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NormalFieldInput::is_equal_to(const fn::FieldNode &other) const
|
|
|
|
|
{
|
|
|
|
|
return dynamic_cast<const NormalFieldInput *>(&other) != nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace blender::bke
|
|
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name C API
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
|
void BKE_geometry_set_free(GeometrySet *geometry_set)
|
|
|
|
|
{
|
|
|
|
|
delete geometry_set;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-06 18:22:24 +02:00
|
|
|
bool BKE_object_has_geometry_set_instances(const Object *ob)
|
2020-12-02 13:25:25 +01:00
|
|
|
{
|
2021-09-06 18:22:24 +02:00
|
|
|
const GeometrySet *geometry_set = ob->runtime.geometry_set_eval;
|
|
|
|
|
if (geometry_set == nullptr) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-11-01 12:00:34 +01:00
|
|
|
for (const GeometryComponent *component : geometry_set->get_components_for_read()) {
|
|
|
|
|
if (component->is_empty()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
const GeometryComponentType type = component->type();
|
|
|
|
|
bool is_instance = false;
|
|
|
|
|
switch (type) {
|
|
|
|
|
case GEO_COMPONENT_TYPE_MESH:
|
|
|
|
|
is_instance = ob->type != OB_MESH;
|
|
|
|
|
break;
|
|
|
|
|
case GEO_COMPONENT_TYPE_POINT_CLOUD:
|
|
|
|
|
is_instance = ob->type != OB_POINTCLOUD;
|
|
|
|
|
break;
|
|
|
|
|
case GEO_COMPONENT_TYPE_INSTANCES:
|
|
|
|
|
is_instance = true;
|
|
|
|
|
break;
|
|
|
|
|
case GEO_COMPONENT_TYPE_VOLUME:
|
|
|
|
|
is_instance = ob->type != OB_VOLUME;
|
|
|
|
|
break;
|
|
|
|
|
case GEO_COMPONENT_TYPE_CURVE:
|
2022-02-18 09:50:29 -06:00
|
|
|
is_instance = !ELEM(ob->type, OB_CURVES_LEGACY, OB_FONT);
|
2021-11-01 12:00:34 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (is_instance) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2021-09-06 18:22:24 +02:00
|
|
|
}
|
|
|
|
|
return false;
|
2020-12-02 13:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|