2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02: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"
|
2023-05-03 14:21:14 +02:00
|
|
|
#include "node_util.hh"
|
2020-04-20 10:58:43 +02: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_mesh_types.h"
|
|
|
|
|
#include "DNA_meshdata_types.h"
|
2023-08-04 20:59:04 +02:00
|
|
|
#include "DNA_space_types.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
|
|
|
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_context.hh"
|
2023-03-12 22:29:15 +01:00
|
|
|
#include "BKE_mesh.hh"
|
2023-08-02 22:14:18 +02:00
|
|
|
#include "BKE_mesh_runtime.hh"
|
2023-10-16 19:09:07 +02:00
|
|
|
#include "BKE_node.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_pointcloud.h"
|
|
|
|
|
|
2023-08-29 12:15:40 +02:00
|
|
|
#include "NOD_rna_define.hh"
|
2021-12-15 09:51:57 -06:00
|
|
|
#include "NOD_socket_search_link.hh"
|
|
|
|
|
|
2023-08-29 12:15:40 +02:00
|
|
|
#include "RNA_enum_types.hh"
|
|
|
|
|
|
2020-12-09 16:20:48 +01:00
|
|
|
namespace blender::nodes {
|
|
|
|
|
|
2023-08-04 20:59:04 +02:00
|
|
|
bool check_tool_context_and_error(GeoNodeExecParams ¶ms)
|
|
|
|
|
{
|
2023-11-29 13:22:20 +01:00
|
|
|
if (!params.user_data()->call_data->operator_data) {
|
2023-09-04 16:16:26 +02:00
|
|
|
params.error_message_add(NodeWarningType::Error, TIP_("Node must be run as tool"));
|
2023-08-04 20:59:04 +02:00
|
|
|
params.set_default_remaining_outputs();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void search_link_ops_for_tool_node(GatherLinkSearchOpParams ¶ms)
|
|
|
|
|
{
|
|
|
|
|
if (params.space_node().geometry_nodes_type == SNODE_GEOMETRY_TOOL) {
|
|
|
|
|
search_link_ops_for_basic_node(params);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-29 12:15:40 +02:00
|
|
|
namespace enums {
|
|
|
|
|
|
|
|
|
|
const EnumPropertyItem *attribute_type_type_with_socket_fn(bContext * /*C*/,
|
|
|
|
|
PointerRNA * /*ptr*/,
|
|
|
|
|
PropertyRNA * /*prop*/,
|
|
|
|
|
bool *r_free)
|
|
|
|
|
{
|
|
|
|
|
*r_free = true;
|
|
|
|
|
return enum_items_filter(rna_enum_attribute_type_items,
|
|
|
|
|
[](const EnumPropertyItem &item) -> bool {
|
|
|
|
|
return generic_attribute_type_supported(item) &&
|
|
|
|
|
!ELEM(item.value, CD_PROP_BYTE_COLOR, CD_PROP_FLOAT2);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool generic_attribute_type_supported(const EnumPropertyItem &item)
|
|
|
|
|
{
|
|
|
|
|
return ELEM(item.value,
|
|
|
|
|
CD_PROP_FLOAT,
|
|
|
|
|
CD_PROP_FLOAT2,
|
|
|
|
|
CD_PROP_FLOAT3,
|
|
|
|
|
CD_PROP_COLOR,
|
|
|
|
|
CD_PROP_BOOL,
|
|
|
|
|
CD_PROP_INT32,
|
|
|
|
|
CD_PROP_BYTE_COLOR,
|
|
|
|
|
CD_PROP_QUATERNION);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-10 16:49:30 +02:00
|
|
|
const EnumPropertyItem *domain_experimental_grease_pencil_version3_fn(bContext * /*C*/,
|
|
|
|
|
PointerRNA * /*ptr*/,
|
|
|
|
|
PropertyRNA * /*prop*/,
|
|
|
|
|
bool *r_free)
|
|
|
|
|
{
|
|
|
|
|
*r_free = true;
|
2023-10-12 13:54:32 +02:00
|
|
|
return enum_items_filter(
|
|
|
|
|
rna_enum_attribute_domain_items, [](const EnumPropertyItem &item) -> bool {
|
|
|
|
|
return (item.value == ATTR_DOMAIN_LAYER) ? U.experimental.use_grease_pencil_version3 :
|
|
|
|
|
true;
|
|
|
|
|
});
|
2023-10-10 16:49:30 +02:00
|
|
|
}
|
|
|
|
|
|
2023-11-16 18:29:34 +01:00
|
|
|
const EnumPropertyItem *domain_without_corner_experimental_grease_pencil_version3_fn(
|
|
|
|
|
bContext * /*C*/, PointerRNA * /*ptr*/, PropertyRNA * /*prop*/, bool *r_free)
|
|
|
|
|
{
|
|
|
|
|
*r_free = true;
|
|
|
|
|
return enum_items_filter(
|
|
|
|
|
rna_enum_attribute_domain_without_corner_items, [](const EnumPropertyItem &item) -> bool {
|
|
|
|
|
return (item.value == ATTR_DOMAIN_LAYER) ? U.experimental.use_grease_pencil_version3 :
|
|
|
|
|
true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-29 12:15:40 +02:00
|
|
|
} // namespace enums
|
|
|
|
|
|
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
|
|
|
{
|
2023-05-15 15:14:22 +02:00
|
|
|
blender::bke::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;
|
2020-04-20 10:58:43 +02:00
|
|
|
}
|