diff options
author | Jacques Lucke <jacques@blender.org> | 2021-11-23 16:56:01 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-11-23 16:56:01 +0300 |
commit | 1df8abff257030ba79bc23dc321f35494f4d91c5 (patch) | |
tree | 64f10b5d525e819fa4f52a6d7e3edc83cf42079a /source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc | |
parent | 47276b84701727c2f187c77f1ec502b4ca4963bd (diff) |
Geometry Nodes: add namespace for every file
This puts all static functions in geometry node files into a new
namespace. This allows using unity build which can improve
compile times significantly (P2578).
* The name space name is derived from the file name. That makes
it possible to write some tooling that checks the names later on.
The file name extension (`cc`) is added to the namespace name as
well. This also possibly simplifies tooling but also makes it more
obvious that this namespace is specific to a file.
* In the register function of every node, I added a namespace alias
`namespace file_ns = blender::nodes::node_geo_*_cc;`. This avoids
some duplication of the file name and may also simplify tooling,
because this line is easy to detect. The name `file_ns` stands for "file
namespace" and also indicates that this namespace corresponds to
the current file. In the beginning I used `node_ns` but `file_ns` is more
generic which may make it more suitable when we want to use unity
builds outside of the nodes modules in the future.
* Some node files contain code that is actually shared between
different nodes. For now I left that code in the `blender::nodes`
namespace and moved it to the top of the file (couldn't move it to
the bottom in all cases, so I just moved it to the top everywhere).
As a separate cleanup step, this shared code should actually be
moved to a separate file.
Differential Revision: https://developer.blender.org/D13330
Diffstat (limited to 'source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc | 156 |
1 files changed, 81 insertions, 75 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc index fc93f6e72b5..9d30e132e61 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc @@ -29,75 +29,6 @@ namespace blender::nodes { -static void geo_node_mesh_primitive_cone_declare(NodeDeclarationBuilder &b) -{ - b.add_input<decl::Int>(N_("Vertices")) - .default_value(32) - .min(3) - .max(512) - .description(N_("Number of points on the circle at the top and bottom")); - b.add_input<decl::Int>(N_("Side Segments")) - .default_value(1) - .min(1) - .max(512) - .description(N_("The number of edges running vertically along the side of the cone")); - b.add_input<decl::Int>(N_("Fill Segments")) - .default_value(1) - .min(1) - .max(512) - .description(N_("Number of concentric rings used to fill the round face")); - b.add_input<decl::Float>(N_("Radius Top")) - .min(0.0f) - .subtype(PROP_DISTANCE) - .description(N_("Radius of the top circle of the cone")); - b.add_input<decl::Float>(N_("Radius Bottom")) - .default_value(1.0f) - .min(0.0f) - .subtype(PROP_DISTANCE) - .description(N_("Radius of the bottom circle of the cone")); - b.add_input<decl::Float>(N_("Depth")) - .default_value(2.0f) - .min(0.0f) - .subtype(PROP_DISTANCE) - .description(N_("Height of the generated cone")); - b.add_output<decl::Geometry>(N_("Mesh")); - b.add_output<decl::Bool>(N_("Top")).field_source(); - b.add_output<decl::Bool>(N_("Bottom")).field_source(); - b.add_output<decl::Bool>(N_("Side")).field_source(); -} - -static void geo_node_mesh_primitive_cone_init(bNodeTree *UNUSED(ntree), bNode *node) -{ - NodeGeometryMeshCone *node_storage = (NodeGeometryMeshCone *)MEM_callocN( - sizeof(NodeGeometryMeshCone), __func__); - - node_storage->fill_type = GEO_NODE_MESH_CIRCLE_FILL_NGON; - - node->storage = node_storage; -} - -static void geo_node_mesh_primitive_cone_update(bNodeTree *ntree, bNode *node) -{ - bNodeSocket *vertices_socket = (bNodeSocket *)node->inputs.first; - bNodeSocket *rings_socket = vertices_socket->next; - bNodeSocket *fill_subdiv_socket = rings_socket->next; - - const NodeGeometryMeshCone &storage = *(const NodeGeometryMeshCone *)node->storage; - const GeometryNodeMeshCircleFillType fill_type = - static_cast<const GeometryNodeMeshCircleFillType>(storage.fill_type); - const bool has_fill = fill_type != GEO_NODE_MESH_CIRCLE_FILL_NONE; - nodeSetSocketAvailability(ntree, fill_subdiv_socket, has_fill); -} - -static void geo_node_mesh_primitive_cone_layout(uiLayout *layout, - bContext *UNUSED(C), - PointerRNA *ptr) -{ - uiLayoutSetPropSep(layout, true); - uiLayoutSetPropDecorate(layout, false); - uiItemR(layout, ptr, "fill_type", 0, nullptr, ICON_NONE); -} - struct ConeConfig { float radius_top; float radius_bottom; @@ -794,6 +725,79 @@ Mesh *create_cylinder_or_cone_mesh(const float radius_top, return mesh; } +} // namespace blender::nodes + +namespace blender::nodes::node_geo_mesh_primitive_cone_cc { + +static void geo_node_mesh_primitive_cone_declare(NodeDeclarationBuilder &b) +{ + b.add_input<decl::Int>(N_("Vertices")) + .default_value(32) + .min(3) + .max(512) + .description(N_("Number of points on the circle at the top and bottom")); + b.add_input<decl::Int>(N_("Side Segments")) + .default_value(1) + .min(1) + .max(512) + .description(N_("The number of edges running vertically along the side of the cone")); + b.add_input<decl::Int>(N_("Fill Segments")) + .default_value(1) + .min(1) + .max(512) + .description(N_("Number of concentric rings used to fill the round face")); + b.add_input<decl::Float>(N_("Radius Top")) + .min(0.0f) + .subtype(PROP_DISTANCE) + .description(N_("Radius of the top circle of the cone")); + b.add_input<decl::Float>(N_("Radius Bottom")) + .default_value(1.0f) + .min(0.0f) + .subtype(PROP_DISTANCE) + .description(N_("Radius of the bottom circle of the cone")); + b.add_input<decl::Float>(N_("Depth")) + .default_value(2.0f) + .min(0.0f) + .subtype(PROP_DISTANCE) + .description(N_("Height of the generated cone")); + b.add_output<decl::Geometry>(N_("Mesh")); + b.add_output<decl::Bool>(N_("Top")).field_source(); + b.add_output<decl::Bool>(N_("Bottom")).field_source(); + b.add_output<decl::Bool>(N_("Side")).field_source(); +} + +static void geo_node_mesh_primitive_cone_init(bNodeTree *UNUSED(ntree), bNode *node) +{ + NodeGeometryMeshCone *node_storage = (NodeGeometryMeshCone *)MEM_callocN( + sizeof(NodeGeometryMeshCone), __func__); + + node_storage->fill_type = GEO_NODE_MESH_CIRCLE_FILL_NGON; + + node->storage = node_storage; +} + +static void geo_node_mesh_primitive_cone_update(bNodeTree *ntree, bNode *node) +{ + bNodeSocket *vertices_socket = (bNodeSocket *)node->inputs.first; + bNodeSocket *rings_socket = vertices_socket->next; + bNodeSocket *fill_subdiv_socket = rings_socket->next; + + const NodeGeometryMeshCone &storage = *(const NodeGeometryMeshCone *)node->storage; + const GeometryNodeMeshCircleFillType fill_type = + static_cast<const GeometryNodeMeshCircleFillType>(storage.fill_type); + const bool has_fill = fill_type != GEO_NODE_MESH_CIRCLE_FILL_NONE; + nodeSetSocketAvailability(ntree, fill_subdiv_socket, has_fill); +} + +static void geo_node_mesh_primitive_cone_layout(uiLayout *layout, + bContext *UNUSED(C), + PointerRNA *ptr) +{ + uiLayoutSetPropSep(layout, true); + uiLayoutSetPropDecorate(layout, false); + uiItemR(layout, ptr, "fill_type", 0, nullptr, ICON_NONE); +} + static void geo_node_mesh_primitive_cone_exec(GeoNodeExecParams params) { const bNode &node = params.node(); @@ -874,19 +878,21 @@ static void geo_node_mesh_primitive_cone_exec(GeoNodeExecParams params) params.set_output("Mesh", GeometrySet::create_with_mesh(mesh)); } -} // namespace blender::nodes +} // namespace blender::nodes::node_geo_mesh_primitive_cone_cc void register_node_type_geo_mesh_primitive_cone() { + namespace file_ns = blender::nodes::node_geo_mesh_primitive_cone_cc; + static bNodeType ntype; geo_node_type_base(&ntype, GEO_NODE_MESH_PRIMITIVE_CONE, "Cone", NODE_CLASS_GEOMETRY, 0); - node_type_init(&ntype, blender::nodes::geo_node_mesh_primitive_cone_init); - node_type_update(&ntype, blender::nodes::geo_node_mesh_primitive_cone_update); + node_type_init(&ntype, file_ns::geo_node_mesh_primitive_cone_init); + node_type_update(&ntype, file_ns::geo_node_mesh_primitive_cone_update); node_type_storage( &ntype, "NodeGeometryMeshCone", node_free_standard_storage, node_copy_standard_storage); - ntype.geometry_node_execute = blender::nodes::geo_node_mesh_primitive_cone_exec; - ntype.draw_buttons = blender::nodes::geo_node_mesh_primitive_cone_layout; - ntype.declare = blender::nodes::geo_node_mesh_primitive_cone_declare; + ntype.geometry_node_execute = file_ns::geo_node_mesh_primitive_cone_exec; + ntype.draw_buttons = file_ns::geo_node_mesh_primitive_cone_layout; + ntype.declare = file_ns::geo_node_mesh_primitive_cone_declare; nodeRegisterType(&ntype); } |