Add an "Index Switch" node which is meant as a simpler version of the "Menu Switch" from #113445 that doesn't allow naming items or displaying them in a dropdown, but still allows choosing between an arbitrary number of items, unlike the regular "Switch" node. Even when the Menu Switch is included (which should be in the same release as this), it may still be helpful to have explicit mapping of indices, and a fair amount of the internals can be shared anyway. Pull Request: https://projects.blender.org/blender/blender/pulls/115250
75 lines
2.6 KiB
C++
75 lines
2.6 KiB
C++
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#include "RNA_prototypes.h"
|
|
|
|
#include "NOD_zone_socket_items.hh"
|
|
|
|
#include "BKE_node.hh"
|
|
|
|
#include "BLO_read_write.hh"
|
|
|
|
namespace blender::nodes {
|
|
|
|
/* Defined here to avoid including the relevant headers in the header. */
|
|
|
|
StructRNA *SimulationItemsAccessor::item_srna = &RNA_SimulationStateItem;
|
|
int SimulationItemsAccessor::node_type = GEO_NODE_SIMULATION_OUTPUT;
|
|
|
|
void SimulationItemsAccessor::blend_write(BlendWriter *writer, const bNode &node)
|
|
{
|
|
const auto &storage = *static_cast<const NodeGeometrySimulationOutput *>(node.storage);
|
|
BLO_write_struct_array(writer, NodeSimulationItem, storage.items_num, storage.items);
|
|
for (const NodeSimulationItem &item : Span(storage.items, storage.items_num)) {
|
|
BLO_write_string(writer, item.name);
|
|
}
|
|
}
|
|
|
|
void SimulationItemsAccessor::blend_read_data(BlendDataReader *reader, bNode &node)
|
|
{
|
|
auto &storage = *static_cast<NodeGeometrySimulationOutput *>(node.storage);
|
|
BLO_read_data_address(reader, &storage.items);
|
|
for (const NodeSimulationItem &item : Span(storage.items, storage.items_num)) {
|
|
BLO_read_data_address(reader, &item.name);
|
|
}
|
|
}
|
|
|
|
StructRNA *RepeatItemsAccessor::item_srna = &RNA_RepeatItem;
|
|
int RepeatItemsAccessor::node_type = GEO_NODE_REPEAT_OUTPUT;
|
|
|
|
void RepeatItemsAccessor::blend_write(BlendWriter *writer, const bNode &node)
|
|
{
|
|
const auto &storage = *static_cast<const NodeGeometryRepeatOutput *>(node.storage);
|
|
BLO_write_struct_array(writer, NodeRepeatItem, storage.items_num, storage.items);
|
|
for (const NodeRepeatItem &item : Span(storage.items, storage.items_num)) {
|
|
BLO_write_string(writer, item.name);
|
|
}
|
|
}
|
|
|
|
void RepeatItemsAccessor::blend_read_data(BlendDataReader *reader, bNode &node)
|
|
{
|
|
auto &storage = *static_cast<NodeGeometryRepeatOutput *>(node.storage);
|
|
BLO_read_data_address(reader, &storage.items);
|
|
for (const NodeRepeatItem &item : Span(storage.items, storage.items_num)) {
|
|
BLO_read_data_address(reader, &item.name);
|
|
}
|
|
}
|
|
|
|
StructRNA *IndexSwitchItemsAccessor ::item_srna = &RNA_IndexSwitchItem;
|
|
int IndexSwitchItemsAccessor::node_type = GEO_NODE_INDEX_SWITCH;
|
|
|
|
void IndexSwitchItemsAccessor::blend_write(BlendWriter *writer, const bNode &node)
|
|
{
|
|
const auto &storage = *static_cast<const NodeIndexSwitch *>(node.storage);
|
|
BLO_write_struct_array(writer, IndexSwitchItem, storage.items_num, storage.items);
|
|
}
|
|
|
|
void IndexSwitchItemsAccessor::blend_read_data(BlendDataReader *reader, bNode &node)
|
|
{
|
|
auto &storage = *static_cast<NodeIndexSwitch *>(node.storage);
|
|
BLO_read_data_address(reader, &storage.items);
|
|
}
|
|
|
|
} // namespace blender::nodes
|