forked from bartvdbraak/blender
Geometry Nodes: Edge Neighbors Node
Creates a new Edge Neighbors node which outputs a field containing the number of faces connected to each edge. Differential Revision: https://developer.blender.org/D13493
This commit is contained in:
parent
9558fa5196
commit
c4cee2e221
@ -150,6 +150,7 @@ def mesh_node_items(context):
|
||||
yield NodeItem("GeometryNodeSubdivisionSurface")
|
||||
yield NodeItem("GeometryNodeTriangulate")
|
||||
yield NodeItemCustom(draw=lambda self, layout, context: layout.separator())
|
||||
yield NodeItem("GeometryNodeInputMeshEdgeNeighbors")
|
||||
yield NodeItem("GeometryNodeInputMeshEdgeVertices")
|
||||
yield NodeItem("GeometryNodeInputMeshFaceArea")
|
||||
yield NodeItem("GeometryNodeInputMeshFaceNeighbors")
|
||||
|
@ -1716,6 +1716,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
|
||||
#define GEO_NODE_INPUT_MESH_FACE_NEIGHBORS 1140
|
||||
#define GEO_NODE_INPUT_MESH_VERTEX_NEIGHBORS 1141
|
||||
#define GEO_NODE_GEOMETRY_TO_INSTANCE 1142
|
||||
#define GEO_NODE_INPUT_MESH_EDGE_NEIGHBORS 1143
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
@ -5807,6 +5807,7 @@ static void registerGeometryNodes()
|
||||
register_node_type_geo_input_index();
|
||||
register_node_type_geo_input_material_index();
|
||||
register_node_type_geo_input_material();
|
||||
register_node_type_geo_input_mesh_edge_neighbors();
|
||||
register_node_type_geo_input_mesh_edge_vertices();
|
||||
register_node_type_geo_input_mesh_face_area();
|
||||
register_node_type_geo_input_mesh_face_neighbors();
|
||||
|
@ -105,6 +105,7 @@ void register_node_type_geo_input_id(void);
|
||||
void register_node_type_geo_input_index(void);
|
||||
void register_node_type_geo_input_material_index(void);
|
||||
void register_node_type_geo_input_material(void);
|
||||
void register_node_type_geo_input_mesh_edge_neighbors(void);
|
||||
void register_node_type_geo_input_mesh_edge_vertices(void);
|
||||
void register_node_type_geo_input_mesh_face_area(void);
|
||||
void register_node_type_geo_input_mesh_face_neighbors(void);
|
||||
|
@ -358,6 +358,7 @@ DefNode(GeometryNode, GEO_NODE_INPUT_ID, 0, "INPUT_ID", InputID, "ID", "")
|
||||
DefNode(GeometryNode, GEO_NODE_INPUT_INDEX, 0, "INDEX", InputIndex, "Index", "")
|
||||
DefNode(GeometryNode, GEO_NODE_INPUT_MATERIAL_INDEX, 0, "INPUT_MATERIAL_INDEX", InputMaterialIndex, "Material Index", "")
|
||||
DefNode(GeometryNode, GEO_NODE_INPUT_MATERIAL, def_geo_input_material, "INPUT_MATERIAL", InputMaterial, "Material", "")
|
||||
DefNode(GeometryNode, GEO_NODE_INPUT_MESH_EDGE_NEIGHBORS, 0, "MESH_EDGE_NEIGHBORS", InputMeshEdgeNeighbors, "Edge Neighbors", "")
|
||||
DefNode(GeometryNode, GEO_NODE_INPUT_MESH_EDGE_VERTICES, 0, "MESH_EDGE_VERTICES", InputMeshEdgeVertices, "Edge Vertices", "")
|
||||
DefNode(GeometryNode, GEO_NODE_INPUT_MESH_FACE_AREA, 0, "MESH_FACE_AREA", InputMeshFaceArea, "Face Area", "")
|
||||
DefNode(GeometryNode, GEO_NODE_INPUT_MESH_FACE_NEIGHBORS, 0, "MESH_FACE_NEIGHBORS", InputMeshFaceNeighbors, "Face Neighbors", "")
|
||||
|
@ -123,6 +123,7 @@ set(SRC
|
||||
nodes/node_geo_input_index.cc
|
||||
nodes/node_geo_input_material_index.cc
|
||||
nodes/node_geo_input_material.cc
|
||||
nodes/node_geo_input_mesh_edge_neighbors.cc
|
||||
nodes/node_geo_input_mesh_edge_vertices.cc
|
||||
nodes/node_geo_input_mesh_face_area.cc
|
||||
nodes/node_geo_input_mesh_face_neighbors.cc
|
||||
|
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
|
||||
#include "BKE_mesh.h"
|
||||
|
||||
#include "node_geometry_util.hh"
|
||||
|
||||
namespace blender::nodes::node_geo_input_mesh_edge_neighbors_cc {
|
||||
|
||||
static void node_declare(NodeDeclarationBuilder &b)
|
||||
{
|
||||
b.add_output<decl::Int>(N_("Face Count"))
|
||||
.field_source()
|
||||
.description(N_("Number of faces that contain the edge"));
|
||||
}
|
||||
|
||||
class EdgeNeighborCountFieldInput final : public GeometryFieldInput {
|
||||
public:
|
||||
EdgeNeighborCountFieldInput()
|
||||
: GeometryFieldInput(CPPType::get<int>(), "Edge Neighbor Count Field")
|
||||
{
|
||||
category_ = Category::Generated;
|
||||
}
|
||||
|
||||
GVArray get_varray_for_context(const GeometryComponent &component,
|
||||
const AttributeDomain domain,
|
||||
IndexMask UNUSED(mask)) const final
|
||||
{
|
||||
if (component.type() == GEO_COMPONENT_TYPE_MESH) {
|
||||
const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
|
||||
const Mesh *mesh = mesh_component.get_for_read();
|
||||
if (mesh == nullptr) {
|
||||
return {};
|
||||
}
|
||||
|
||||
Array<int> face_count(mesh->totedge, 0);
|
||||
for (const int i : IndexRange(mesh->totloop)) {
|
||||
face_count[mesh->mloop[i].e]++;
|
||||
}
|
||||
|
||||
return mesh_component.attribute_try_adapt_domain<int>(
|
||||
VArray<int>::ForContainer(std::move(face_count)), ATTR_DOMAIN_EDGE, domain);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
uint64_t hash() const override
|
||||
{
|
||||
/* Some random constant hash. */
|
||||
return 985671075;
|
||||
}
|
||||
|
||||
bool is_equal_to(const fn::FieldNode &other) const override
|
||||
{
|
||||
return dynamic_cast<const EdgeNeighborCountFieldInput *>(&other) != nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
static void node_geo_exec(GeoNodeExecParams params)
|
||||
{
|
||||
Field<int> neighbor_count_field{std::make_shared<EdgeNeighborCountFieldInput>()};
|
||||
params.set_output("Face Count", std::move(neighbor_count_field));
|
||||
}
|
||||
|
||||
} // namespace blender::nodes::node_geo_input_mesh_edge_neighbors_cc
|
||||
|
||||
void register_node_type_geo_input_mesh_edge_neighbors()
|
||||
{
|
||||
namespace file_ns = blender::nodes::node_geo_input_mesh_edge_neighbors_cc;
|
||||
|
||||
static bNodeType ntype;
|
||||
geo_node_type_base(
|
||||
&ntype, GEO_NODE_INPUT_MESH_EDGE_NEIGHBORS, "Edge Neighbors", NODE_CLASS_INPUT, 0);
|
||||
ntype.declare = file_ns::node_declare;
|
||||
ntype.geometry_node_execute = file_ns::node_geo_exec;
|
||||
nodeRegisterType(&ntype);
|
||||
}
|
Loading…
Reference in New Issue
Block a user