Files
test2/source/blender/nodes/function/nodes/node_fn_input_rotation.cc
Bastien Montagne dd168a35c5 Refactor: Replace MEM_cnew with a type-aware template version of MEM_callocN.
The general idea is to keep the 'old', C-style MEM_callocN signature, and slowly
replace most of its usages with the new, C++-style type-safer template version.

* `MEM_cnew<T>` allocation version is renamed to `MEM_callocN<T>`.
* `MEM_cnew_array<T>` allocation version is renamed to `MEM_calloc_arrayN<T>`.
* `MEM_cnew<T>` duplicate version is renamed to `MEM_dupallocN<T>`.

Similar templates type-safe version of `MEM_mallocN` will be added soon
as well.

Following discussions in !134452.

NOTE: For now static type checking in `MEM_callocN` and related are slightly
different for Windows MSVC. This compiler seems to consider structs using the
`DNA_DEFINE_CXX_METHODS` macro as non-trivial (likely because their default
copy constructors are deleted). So using checks on trivially
constructible/destructible instead on this compiler/system.

Pull Request: https://projects.blender.org/blender/blender/pulls/134771
2025-03-05 16:35:09 +01:00

63 lines
2.0 KiB
C++

/* SPDX-FileCopyrightText: 2024 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "BLI_math_euler.hh"
#include "NOD_socket_search_link.hh"
#include "UI_interface.hh"
#include "UI_resources.hh"
#include "node_function_util.hh"
namespace blender::nodes::node_fn_input_rotation_cc {
static void node_declare(NodeDeclarationBuilder &b)
{
b.add_output<decl::Rotation>("Rotation");
}
static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiLayout *col = uiLayoutColumn(layout, true);
uiItemR(col, ptr, "rotation_euler", UI_ITEM_R_EXPAND, "", ICON_NONE);
}
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
{
const bNode &bnode = builder.node();
const NodeInputRotation &node_storage = *static_cast<const NodeInputRotation *>(bnode.storage);
const math::EulerXYZ euler_rotation(node_storage.rotation_euler[0],
node_storage.rotation_euler[1],
node_storage.rotation_euler[2]);
builder.construct_and_set_matching_fn<mf::CustomMF_Constant<math::Quaternion>>(
math::to_quaternion(euler_rotation));
}
static void node_init(bNodeTree * /*tree*/, bNode *node)
{
NodeInputRotation *data = MEM_callocN<NodeInputRotation>(__func__);
node->storage = data;
}
static void node_register()
{
static blender::bke::bNodeType ntype;
fn_node_type_base(&ntype, "FunctionNodeInputRotation", FN_NODE_INPUT_ROTATION);
ntype.ui_name = "Rotation";
ntype.enum_name_legacy = "INPUT_ROTATION";
ntype.nclass = NODE_CLASS_INPUT;
ntype.declare = node_declare;
ntype.initfunc = node_init;
blender::bke::node_type_storage(
ntype, "NodeInputRotation", node_free_standard_storage, node_copy_standard_storage);
ntype.build_multi_function = node_build_multi_function;
ntype.draw_buttons = node_layout;
blender::bke::node_register_type(ntype);
}
NOD_REGISTER_NODE(node_register)
} // namespace blender::nodes::node_fn_input_rotation_cc