2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2020-04-20 10:58:43 +02:00
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
#include "node_geometry_util.hh"
|
2020-04-20 10:58:43 +02:00
|
|
|
#include "node_util.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 "DNA_mesh_types.h"
|
|
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
|
|
2023-03-12 22:29:15 +01:00
|
|
|
#include "BKE_mesh.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 "BKE_mesh_runtime.h"
|
|
|
|
|
#include "BKE_pointcloud.h"
|
|
|
|
|
|
2023-02-20 19:17:03 +01:00
|
|
|
#include "NOD_add_node_search.hh"
|
2021-12-15 09:51:57 -06:00
|
|
|
#include "NOD_socket_search_link.hh"
|
|
|
|
|
|
2020-12-09 16:20:48 +01:00
|
|
|
namespace blender::nodes {
|
|
|
|
|
|
2022-06-01 14:38:06 +10:00
|
|
|
std::optional<eCustomDataType> node_data_type_to_custom_data_type(const eNodeSocketDatatype type)
|
2021-12-15 09:51:57 -06:00
|
|
|
{
|
|
|
|
|
switch (type) {
|
|
|
|
|
case SOCK_FLOAT:
|
|
|
|
|
return CD_PROP_FLOAT;
|
|
|
|
|
case SOCK_VECTOR:
|
|
|
|
|
return CD_PROP_FLOAT3;
|
|
|
|
|
case SOCK_RGBA:
|
|
|
|
|
return CD_PROP_COLOR;
|
|
|
|
|
case SOCK_BOOLEAN:
|
|
|
|
|
return CD_PROP_BOOL;
|
|
|
|
|
case SOCK_INT:
|
|
|
|
|
return CD_PROP_INT32;
|
|
|
|
|
case SOCK_STRING:
|
|
|
|
|
return CD_PROP_STRING;
|
|
|
|
|
default:
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-01 14:38:06 +10:00
|
|
|
std::optional<eCustomDataType> node_socket_to_custom_data_type(const bNodeSocket &socket)
|
2021-12-15 09:51:57 -06:00
|
|
|
{
|
2022-09-25 17:39:45 +02:00
|
|
|
return node_data_type_to_custom_data_type(eNodeSocketDatatype(socket.type));
|
2021-12-15 09:51:57 -06:00
|
|
|
}
|
|
|
|
|
|
2020-12-09 16:20:48 +01:00
|
|
|
} // namespace blender::nodes
|
|
|
|
|
|
2022-12-28 20:15:41 -05:00
|
|
|
bool geo_node_poll_default(const bNodeType * /*ntype*/,
|
|
|
|
|
const bNodeTree *ntree,
|
|
|
|
|
const char **r_disabled_hint)
|
2020-04-20 10:58:43 +02:00
|
|
|
{
|
2021-04-12 18:43:23 +02:00
|
|
|
if (!STREQ(ntree->idname, "GeometryNodeTree")) {
|
2021-12-01 21:55:04 -05:00
|
|
|
*r_disabled_hint = TIP_("Not a geometry node tree");
|
2021-04-12 18:43:23 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2020-04-20 10:58:43 +02:00
|
|
|
}
|
|
|
|
|
|
2022-01-03 19:32:33 -05:00
|
|
|
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
|
2020-04-20 10:58:43 +02:00
|
|
|
{
|
2022-01-03 19:32:33 -05:00
|
|
|
node_type_base(ntype, type, name, nclass);
|
2020-12-02 13:25:25 +01:00
|
|
|
ntype->poll = geo_node_poll_default;
|
2020-12-02 16:31:06 +01:00
|
|
|
ntype->insert_link = node_insert_link_default;
|
2021-12-15 09:51:57 -06:00
|
|
|
ntype->gather_link_search_ops = blender::nodes::search_link_ops_for_basic_node;
|
2023-02-20 19:17:03 +01:00
|
|
|
ntype->gather_add_node_search_ops = blender::nodes::search_node_add_ops_for_basic_node;
|
2020-04-20 10:58:43 +02:00
|
|
|
}
|