2020-04-20 10:58:43 +02: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.
|
|
|
|
|
*/
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
|
|
#include "BKE_mesh.h"
|
|
|
|
|
#include "BKE_mesh_runtime.h"
|
|
|
|
|
#include "BKE_pointcloud.h"
|
|
|
|
|
|
2020-12-09 16:20:48 +01:00
|
|
|
namespace blender::nodes {
|
|
|
|
|
|
2021-02-16 12:07:10 +01:00
|
|
|
using bke::GeometryInstanceGroup;
|
|
|
|
|
|
2020-12-23 16:37:47 +01:00
|
|
|
/**
|
|
|
|
|
* Update the availability of a group of input sockets with the same name,
|
|
|
|
|
* used for switching between attribute inputs or single values.
|
|
|
|
|
*
|
|
|
|
|
* \param mode: Controls which socket of the group to make available.
|
|
|
|
|
* \param name_is_available: If false, make all sockets with this name unavailable.
|
|
|
|
|
*/
|
2021-11-17 11:10:46 +01:00
|
|
|
void update_attribute_input_socket_availabilities(bNodeTree &ntree,
|
|
|
|
|
bNode &node,
|
2020-12-09 16:20:48 +01:00
|
|
|
const StringRef name,
|
2020-12-23 16:37:47 +01:00
|
|
|
const GeometryNodeAttributeInputMode mode,
|
|
|
|
|
const bool name_is_available)
|
2020-12-09 16:20:48 +01:00
|
|
|
{
|
|
|
|
|
const GeometryNodeAttributeInputMode mode_ = (GeometryNodeAttributeInputMode)mode;
|
|
|
|
|
LISTBASE_FOREACH (bNodeSocket *, socket, &node.inputs) {
|
|
|
|
|
if (name == socket->name) {
|
2020-12-23 16:37:47 +01:00
|
|
|
const bool socket_is_available =
|
|
|
|
|
name_is_available &&
|
2020-12-09 16:20:48 +01:00
|
|
|
((socket->type == SOCK_STRING && mode_ == GEO_NODE_ATTRIBUTE_INPUT_ATTRIBUTE) ||
|
|
|
|
|
(socket->type == SOCK_FLOAT && mode_ == GEO_NODE_ATTRIBUTE_INPUT_FLOAT) ||
|
2021-06-15 16:38:28 -05:00
|
|
|
(socket->type == SOCK_INT && mode_ == GEO_NODE_ATTRIBUTE_INPUT_INTEGER) ||
|
2020-12-09 16:20:48 +01:00
|
|
|
(socket->type == SOCK_VECTOR && mode_ == GEO_NODE_ATTRIBUTE_INPUT_VECTOR) ||
|
|
|
|
|
(socket->type == SOCK_RGBA && mode_ == GEO_NODE_ATTRIBUTE_INPUT_COLOR));
|
2021-11-17 11:10:46 +01:00
|
|
|
nodeSetSocketAvailability(&ntree, socket, socket_is_available);
|
2020-12-09 16:20:48 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace blender::nodes
|
|
|
|
|
|
2021-04-12 18:43:23 +02:00
|
|
|
bool geo_node_poll_default(bNodeType *UNUSED(ntype),
|
|
|
|
|
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")) {
|
|
|
|
|
*r_disabled_hint = "Not a geometry node tree";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2020-04-20 10:58:43 +02:00
|
|
|
}
|
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag)
|
2020-04-20 10:58:43 +02:00
|
|
|
{
|
|
|
|
|
node_type_base(ntype, type, name, nclass, flag);
|
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;
|
2020-04-20 10:58:43 +02:00
|
|
|
}
|