Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_float_to_int.cc
- This file was added.
| /* | |||||
| * 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 <math.h> | |||||
| #include "UI_interface.h" | |||||
| #include "UI_resources.h" | |||||
| #include "node_geometry_util.hh" | |||||
| static bNodeSocketTemplate geo_node_float_to_int_in[] = { | |||||
| {SOCK_FLOAT, N_("Float"), 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, PROP_FACTOR}, | |||||
| {-1, ""}, | |||||
| }; | |||||
| static bNodeSocketTemplate geo_node_float_to_int_out[] = { | |||||
| {SOCK_INT, N_("Integer"), 1, 0, 0, 0, 0, 6}, | |||||
| {-1, ""}, | |||||
| }; | |||||
| static void geo_node_float_to_int_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) | |||||
| { | |||||
| uiItemR(layout, ptr, "roundingmode", 0, "", ICON_NONE); | |||||
| } | |||||
| static void geo_node_float_to_int_init(bNodeTree *UNUSED(ntree), bNode *node) | |||||
| { | |||||
| node->custom1 = GEO_NODE_FLOAT_TO_INT_ROUND; | |||||
| } | |||||
| namespace blender::nodes { | |||||
| static void geo_node_float_to_int_exec(GeoNodeExecParams params) | |||||
HooglyBoogly: Comments should start with a `/*`, and end with a period. | |||||
| { | |||||
| float input_value = params.extract_input<float>("Float"); | |||||
| int rounded_value; | |||||
| GeometryNodeFloatToIntRoundingMode roundingmode = | |||||
| static_cast<GeometryNodeFloatToIntRoundingMode>(params.node().custom1); | |||||
| switch(roundingmode) | |||||
| { | |||||
| case GEO_NODE_FLOAT_TO_INT_ROUND: | |||||
Not Done Inline Actionsroundingmode -> rounding_mode HooglyBoogly: `roundingmode` -> `rounding_mode` | |||||
| rounded_value = round(input_value); | |||||
| case GEO_NODE_FLOAT_TO_INT_FLOOR: | |||||
| rounded_value = floor(input_value); | |||||
| case GEO_NODE_FLOAT_TO_INT_CEIL: | |||||
| rounded_value = ceil(input_value); | |||||
| case GEO_NODE_FLOAT_TO_INT_TRUNCATE: | |||||
| rounded_value = trunc(input_value); | |||||
| default: | |||||
| rounded_value = 0; | |||||
| } | |||||
| params.set_output("Integer", rounded_value); | |||||
| } | |||||
| } // namespace blender::nodes | |||||
| void register_node_type_geo_float_to_int() | |||||
| { | |||||
| static bNodeType ntype; | |||||
| geo_node_type_base(&ntype, GEO_NODE_FLOAT_TO_INT, "Float to Int", NODE_CLASS_GEOMETRY, 0); | |||||
| node_type_socket_templates(&ntype, geo_node_float_to_int_in, geo_node_float_to_int_out); | |||||
| node_type_init(&ntype, geo_node_float_to_int_init); | |||||
| ntype.geometry_node_execute = blender::nodes::geo_node_float_to_int_exec; | |||||
| ntype.draw_buttons = geo_node_float_to_int_layout; | |||||
| nodeRegisterType(&ntype); | |||||
| } | |||||
Comments should start with a /*, and end with a period.