Page MenuHome
Paste P2654

Expand
ActivePublic

Authored by Johnny Matthews (guitargeek) on Dec 9 2021, 10:50 PM.
/*
* 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_expand_selection_cc {
static void node_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Bool>(N_("Source Selection"))
.supports_field()
.default_value(true)
.description(N_("The selection to be altered"));
b.add_input<decl::Int>(N_("Distance"))
.supports_field()
.default_value(1)
.description(N_("The amount to grow or contract the selection"));
b.add_input<decl::Int>(N_("Selection"))
.supports_field()
.default_value(1)
.description(N_("The points which to consider for alteration"));
b.add_output<decl::Bool>(N_("Selection"))
.field_source()
.description(N_("The altered selection"));
}
class ExpandFieldInput final : public GeometryFieldInput {
private:
Field<bool> source_;
Field<int> distance_;
Field<bool> selection_;
public:
ExpandFieldInput(Field<bool> &source, Field<int> &distance, Field<bool> &selection)
: GeometryFieldInput(CPPType::get<float>(), "Selection Field"),
source_(source),
distance_(distance),
selection_(selection)
{
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);
return {};
}
else if (component.type() == GEO_COMPONENT_TYPE_CURVE) {
const CurveComponent &curve_component = static_cast<const CurveComponent &>(component);
return {};
}
return {};
}
uint64_t hash() const override
{
/* Some random constant hash. */
return get_default_hash_3(source_, distance_, selection_);
}
bool is_equal_to(const fn::FieldNode &other) const override
{
if (const ExpandFieldInput *other_field = dynamic_cast<const ExpandFieldInput *>(&other)) {
return source_ == other_field->source_ && selection_ == other_field->selection_ &&
distance_ == other_field->distance_;
}
return false;
}
};
static void node_geo_exec(GeoNodeExecParams params)
{
Field<bool> main_selection = params.extract_input<Field<bool>>("Source Selection");
Field<int> distance = params.extract_input<Field<int>>("Distance");
Field<bool> selection = params.extract_input<Field<bool>>("Selection");
Field<float> expand_field{
std::make_shared<ExpandFieldInput>(main_selection, distance, selection)};
params.set_output("Selection", std::move(expand_field));
}
} // namespace blender::nodes::node_geo_expand_selection_cc
void register_node_type_geo_expand_selection()
{
namespace file_ns = blender::nodes::node_geo_expand_selection_cc;
static bNodeType ntype;
geo_node_type_base(
&ntype, GEO_NODE_EXPAND_SELECTION, "Expand Selection", NODE_CLASS_GEOMETRY, 0);
ntype.declare = file_ns::node_declare;
ntype.geometry_node_execute = file_ns::node_geo_exec;
nodeRegisterType(&ntype);
}

Event Timeline