Welcome to mirror list, hosted at ThFree Co, Russian Federation.

node_geo_attribute_domain_size.cc « nodes « geometry « nodes « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d6662e4e637cdcce5c3640b3fbd6f241b08e0b5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
 * 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 "UI_interface.h"
#include "UI_resources.h"

#include "node_geometry_util.hh"

namespace blender::nodes::node_geo_attribute_domain_size_cc {

static void node_declare(NodeDeclarationBuilder &b)
{
  b.add_input<decl::Geometry>("Geometry");
  b.add_output<decl::Int>("Point Count").make_available([](bNode &node) {
    node.custom1 = GEO_COMPONENT_TYPE_MESH;
  });
  b.add_output<decl::Int>("Edge Count").make_available([](bNode &node) {
    node.custom1 = GEO_COMPONENT_TYPE_MESH;
  });
  b.add_output<decl::Int>("Face Count").make_available([](bNode &node) {
    node.custom1 = GEO_COMPONENT_TYPE_MESH;
  });
  b.add_output<decl::Int>("Face Corner Count").make_available([](bNode &node) {
    node.custom1 = GEO_COMPONENT_TYPE_MESH;
  });
  b.add_output<decl::Int>("Spline Count").make_available([](bNode &node) {
    node.custom1 = GEO_COMPONENT_TYPE_CURVE;
  });
  b.add_output<decl::Int>("Instance Count").make_available([](bNode &node) {
    node.custom1 = GEO_COMPONENT_TYPE_INSTANCES;
  });
}

static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
  uiItemR(layout, ptr, "component", 0, "", ICON_NONE);
}

static void node_init(bNodeTree *UNUSED(tree), bNode *node)
{
  node->custom1 = GEO_COMPONENT_TYPE_MESH;
}

static void node_update(bNodeTree *ntree, bNode *node)
{
  bNodeSocket *point_socket = (bNodeSocket *)node->outputs.first;
  bNodeSocket *edge_socket = point_socket->next;
  bNodeSocket *face_socket = edge_socket->next;
  bNodeSocket *face_corner_socket = face_socket->next;
  bNodeSocket *spline_socket = face_corner_socket->next;
  bNodeSocket *instances_socket = spline_socket->next;

  nodeSetSocketAvailability(ntree,
                            point_socket,
                            ELEM(node->custom1,
                                 GEO_COMPONENT_TYPE_MESH,
                                 GEO_COMPONENT_TYPE_CURVE,
                                 GEO_COMPONENT_TYPE_POINT_CLOUD));
  nodeSetSocketAvailability(ntree, edge_socket, node->custom1 == GEO_COMPONENT_TYPE_MESH);
  nodeSetSocketAvailability(ntree, face_socket, node->custom1 == GEO_COMPONENT_TYPE_MESH);
  nodeSetSocketAvailability(ntree, face_corner_socket, node->custom1 == GEO_COMPONENT_TYPE_MESH);
  nodeSetSocketAvailability(ntree, spline_socket, node->custom1 == GEO_COMPONENT_TYPE_CURVE);
  nodeSetSocketAvailability(
      ntree, instances_socket, node->custom1 == GEO_COMPONENT_TYPE_INSTANCES);
}

static void node_geo_exec(GeoNodeExecParams params)
{
  GeometryComponentType component = (GeometryComponentType)params.node().custom1;
  GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");

  switch (component) {
    case GEO_COMPONENT_TYPE_MESH: {
      if (geometry_set.has_mesh()) {
        const MeshComponent *component = geometry_set.get_component_for_read<MeshComponent>();
        params.set_output("Point Count", component->attribute_domain_size(ATTR_DOMAIN_POINT));
        params.set_output("Edge Count", component->attribute_domain_size(ATTR_DOMAIN_EDGE));
        params.set_output("Face Count", component->attribute_domain_size(ATTR_DOMAIN_FACE));
        params.set_output("Face Corner Count",
                          component->attribute_domain_size(ATTR_DOMAIN_CORNER));
      }
      else {
        params.set_default_remaining_outputs();
      }
      break;
    }
    case GEO_COMPONENT_TYPE_CURVE: {
      if (geometry_set.has_curve()) {
        const CurveComponent *component = geometry_set.get_component_for_read<CurveComponent>();
        params.set_output("Point Count", component->attribute_domain_size(ATTR_DOMAIN_POINT));
        params.set_output("Spline Count", component->attribute_domain_size(ATTR_DOMAIN_CURVE));
      }
      else {
        params.set_default_remaining_outputs();
      }
      break;
    }
    case GEO_COMPONENT_TYPE_POINT_CLOUD: {
      if (geometry_set.has_pointcloud()) {
        const PointCloudComponent *component =
            geometry_set.get_component_for_read<PointCloudComponent>();
        params.set_output("Point Count", component->attribute_domain_size(ATTR_DOMAIN_POINT));
      }
      else {
        params.set_default_remaining_outputs();
      }
      break;
    }
    case GEO_COMPONENT_TYPE_INSTANCES: {
      if (geometry_set.has_instances()) {
        const InstancesComponent *component =
            geometry_set.get_component_for_read<InstancesComponent>();
        params.set_output("Instance Count",
                          component->attribute_domain_size(ATTR_DOMAIN_INSTANCE));
      }
      else {
        params.set_default_remaining_outputs();
      }
      break;
    }
    default:
      BLI_assert_unreachable();
  }
}

}  // namespace blender::nodes::node_geo_attribute_domain_size_cc

void register_node_type_geo_attribute_domain_size()
{
  namespace file_ns = blender::nodes::node_geo_attribute_domain_size_cc;

  static bNodeType ntype;
  geo_node_type_base(
      &ntype, GEO_NODE_ATTRIBUTE_DOMAIN_SIZE, "Domain Size", NODE_CLASS_ATTRIBUTE, 0);
  ntype.geometry_node_execute = file_ns::node_geo_exec;
  ntype.declare = file_ns::node_declare;
  ntype.draw_buttons = file_ns::node_layout;
  node_type_init(&ntype, file_ns::node_init);
  ntype.updatefunc = file_ns::node_update;

  nodeRegisterType(&ntype);
}