Nodes: Add vector min/max support to new socket builder API

Also use it to fix an incorrect min and max in the cube mesh
primitive node.
This commit is contained in:
Hans Goudey 2021-09-10 22:48:49 -05:00
parent eab26f1334
commit cb83313863
3 changed files with 17 additions and 1 deletions

View File

@ -102,6 +102,8 @@ class Int : public SocketDeclaration {
class Vector : public SocketDeclaration {
private:
float3 default_value_ = {0, 0, 0};
float soft_min_value_ = -FLT_MAX;
float soft_max_value_ = FLT_MAX;
PropertySubType subtype_ = PROP_NONE;
public:
@ -117,6 +119,18 @@ class Vector : public SocketDeclaration {
return *this;
}
Vector &min(const float min)
{
soft_min_value_ = min;
return *this;
}
Vector &max(const float max)
{
soft_max_value_ = max;
return *this;
}
bNodeSocket &build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out) const override;
bool matches(const bNodeSocket &socket) const override;
bNodeSocket &update_or_build(bNodeTree &ntree, bNode &node, bNodeSocket &socket) const override;

View File

@ -26,7 +26,7 @@ namespace blender::nodes {
static void geo_node_mesh_primitive_cube_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Vector>("Size").default_value({1.0f, 1.0f, 1.0f}).subtype(PROP_TRANSLATION);
b.add_input<decl::Vector>("Size").default_value(float3(1)).min(0.0f).subtype(PROP_TRANSLATION);
b.add_input<decl::Int>("Vertices X").default_value(2).min(2).max(1000);
b.add_input<decl::Int>("Vertices Y").default_value(2).min(2).max(1000);
b.add_input<decl::Int>("Vertices Z").default_value(2).min(2).max(1000);

View File

@ -148,6 +148,8 @@ bNodeSocket &Vector::build(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_ou
&ntree, &node, in_out, SOCK_VECTOR, subtype_, identifier_.c_str(), name_.c_str());
bNodeSocketValueVector &value = *(bNodeSocketValueVector *)socket.default_value;
copy_v3_v3(value.value, default_value_);
value.min = soft_min_value_;
value.max = soft_max_value_;
return socket;
}