37#include "RNA_prototypes.hh"
61 keys.
append({item.identifier, item.socket_type});
64 keys, compute_context, data_block_map);
75 C,
"simulation_state_items",
false,
IFACE_(
"Simulation State")))
77 socket_items::ui::draw_items_list_with_operators<SimulationItemsAccessor>(
78 C, panel, ntree, output_node);
80 socket_items::ui::draw_active_item_props<SimulationItemsAccessor>(
81 ntree, output_node, [&](
PointerRNA *item_ptr) {
84 panel->use_property_split_set(
true);
85 panel->use_property_decorate_set(
false);
86 panel->prop(item_ptr,
"socket_type",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
88 panel->prop(item_ptr,
"attribute_domain",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
98 bNode *current_node =
static_cast<bNode *
>(current_node_ptr->
data);
131 row.
label(*bake_state_str, ICON_NONE);
153 debug_name_ =
"Simulation Input";
154 output_node_id_ = node_storage(
node).output_node_id;
155 const bNode &output_node = *node_tree.node_by_id(output_node_id_);
161 lf_index_by_bsocket[
node.output_socket(0).index_in_tree()] = outputs_.append_and_get_index_as(
164 for (
const int i : simulation_items_.index_range()) {
169 lf_index_by_bsocket[input_bsocket.index_in_tree()] = inputs_.append_and_get_index_as(
171 lf_index_by_bsocket[output_bsocket.index_in_tree()] = outputs_.append_and_get_index_as(
176 void execute_impl(lf::Params ¶ms,
const lf::Context &context)
const final
188 std::optional<FoundNestedNodeID> found_id =
find_nested_node_id(user_data, output_node_id_);
193 if (found_id->is_in_loop || found_id->is_in_closure) {
199 if (!zone_behavior) {
204 float delta_time = 0.0f;
205 if (
auto *info = std::get_if<sim_input::UseCache>(&input_behavior)) {
206 delta_time = info->delta_time;
208 params, user_data, zone_behavior->
data_block_map, std::move(info->values));
210 else if (std::get_if<sim_input::PassThrough>(&input_behavior)) {
217 if (!params.output_was_set(0)) {
233 simulation_items_, *user_data.
compute_context, data_block_map, std::move(bake_values));
234 for (
const int i : simulation_items_.index_range()) {
235 params.set_output(i + 1, std::move(output_values[i]));
247 params, data_block_map);
259 for (
const int i : inputs_.index_range()) {
260 input_value_pointers[i] = params.try_get_input_data_ptr_or_request<
SocketValueVariant>(i);
262 if (input_value_pointers.
as_span().contains(
nullptr)) {
267 for (
const int i : inputs_.index_range()) {
273 input_value.
value = std::move(*input_value_pointers[i]);
281 b.use_custom_socket_order();
282 b.allow_any_socket_order();
286 const bNodeTree *node_tree =
b.tree_or_null();
287 if (
ELEM(
nullptr,
node, node_tree)) {
291 const bNode *output_node = node_tree->node_by_id(node_storage(*node).output_node_id);
298 for (
const int i :
IndexRange(output_storage.items_num)) {
306 auto &input_decl =
b.add_input(socket_type, name, identifier)
309 .structure_type(StructureType::Dynamic);
310 auto &output_decl =
b.add_output(socket_type, name, identifier)
311 .align_with_previous()
312 .propagate_all({input_decl.index()})
313 .inferred_structure_type({input_decl.index()})
314 .structure_type(StructureType::Dynamic);
317 .pass_through_input_index(input_decl.index());
321 .structure_type(StructureType::Dynamic)
322 .custom_draw(socket_items::ui::draw_extend_socket_fn<SimulationItemsAccessor>());
324 .structure_type(StructureType::Dynamic)
325 .align_with_previous();
332 data->output_node_id = 0;
339 const int label_maxncpy)
346 bNode *output_node = params.
ntree.node_by_id(node_storage(params.
node).output_node_id);
358 ntype.
ui_name =
"Simulation Input";
370 "NodeGeometrySimulationInput",
386 int skip_input_index_;
392 int skip_inputs_offset_;
397 int solve_inputs_offset_;
404 debug_name_ =
"Simulation Output";
411 skip_input_index_ = inputs_.append_and_get_index_as(
413 lf_index_by_bsocket[skip_bsocket.index_in_tree()] = skip_input_index_;
415 skip_inputs_offset_ = inputs_.
size();
418 for (
const int i : simulation_items_.index_range()) {
423 solve_inputs_offset_ = inputs_.size();
426 for (
const int i : simulation_items_.index_range()) {
431 lf_index_by_bsocket[input_bsocket.index_in_tree()] = inputs_.append_and_get_index_as(
433 lf_index_by_bsocket[output_bsocket.index_in_tree()] = outputs_.append_and_get_index_as(
438 void execute_impl(lf::Params ¶ms,
const lf::Context &context)
const final
442 context.local_user_data);
450 tree_logger->node_warnings.append(
451 *tree_logger->allocator,
453 {NodeWarningType::Error, TIP_(
"Simulation zone is not supported")}});
458 std::optional<FoundNestedNodeID> found_id =
find_nested_node_id(user_data, node_.identifier);
459 if (!found_id || found_id->is_in_loop || found_id->is_in_closure) {
461 const StringRefNull message =
TIP_(
"Simulation must not be in a loop or closure");
462 tree_logger->node_warnings.append(*tree_logger->allocator,
463 {node_.identifier, {NodeWarningType::Error, message}});
470 if (!zone_behavior) {
471 this->set_default_outputs(params);
475 if (
auto *info = std::get_if<sim_output::ReadSingle>(&output_behavior)) {
476 this->output_cached_state(
477 params, user_data, zone_behavior->
data_block_map, std::move(info->values));
479 else if (
auto *info = std::get_if<sim_output::ReadInterpolated>(&output_behavior)) {
480 this->output_mixed_cached_state(params,
482 *user_data.compute_context,
483 std::move(info->prev_values),
484 std::move(info->next_values),
487 else if (std::get_if<sim_output::PassThrough>(&output_behavior)) {
488 this->pass_through(params, user_data, zone_behavior->
data_block_map);
490 else if (
auto *info = std::get_if<sim_output::StoreNewState>(&output_behavior)) {
491 this->store_new_state(params, user_data, zone_behavior->
data_block_map, *info);
510 keys.
append({item.identifier, item.socket_type});
515 for (
const int i : simulation_items_.index_range()) {
516 params.set_output(i, std::move(output_values[i]));
525 const float mix_factor)
const
528 simulation_items_, compute_context, data_block_map, std::move(prev_bake_values));
530 simulation_items_, compute_context, data_block_map, std::move(next_bake_values));
531 if (mix_factor != 0.0f) {
532 for (
const int i : simulation_items_.index_range()) {
536 for (
const int i : simulation_items_.index_range()) {
537 params.set_output(i, std::move(output_values[i]));
546 params, data_block_map,
true);
552 simulation_items_, *user_data.
compute_context, data_block_map, std::move(*bake_values));
553 for (
const int i : simulation_items_.index_range()) {
554 params.set_output(i, std::move(output_values[i]));
565 if (skip_variant ==
nullptr) {
569 const bool skip = skip_variant->
copy_as<
bool>();
575 params, data_block_map, skip);
588 const int params_offset = skip ? skip_inputs_offset_ : solve_inputs_offset_;
590 for (
const int i : simulation_items_.index_range()) {
591 input_value_pointers[i] = params.try_get_input_data_ptr_or_request<
SocketValueVariant>(
594 if (input_value_pointers.
as_span().contains(
nullptr)) {
600 for (
const int i : simulation_items_.index_range()) {
606 input_value.
value = std::move(*input_value_pointers[i]);
614 b.use_custom_socket_order();
615 b.allow_any_socket_order();
619 "Forward the output of the simulation input node directly to the output node and ignore "
620 "the nodes in the simulation zone");
624 if (
node ==
nullptr) {
638 auto &input_decl =
b.add_input(socket_type, name, identifier)
641 .structure_type(StructureType::Dynamic);
642 auto &output_decl =
b.add_output(socket_type, name, identifier)
643 .align_with_previous()
644 .propagate_all({input_decl.index()})
645 .inferred_structure_type({input_decl.index()})
646 .structure_type(StructureType::Dynamic);
649 .pass_through_input_index(input_decl.index());
653 .structure_type(StructureType::Dynamic)
654 .custom_draw(socket_items::ui::draw_extend_socket_fn<SimulationItemsAccessor>());
656 .structure_type(StructureType::Dynamic)
657 .align_with_previous();
664 data->next_identifier = 0;
666 data->items = MEM_new_array<NodeSimulationItem>(1, __func__);
669 data->items[0].identifier =
data->next_identifier++;
684 auto *dst_storage = MEM_new<NodeGeometrySimulationOutput>(__func__,
686 dst_node->
storage = dst_storage;
710 row.
text =
TIP_(
"Cannot bake in zone");
711 row.
icon = ICON_STATUS_ERROR;
712 params.
rows.append(std::move(row));
717 params.
rows.append(std::move(row));
728 bNode &input_node = params.add_node(
"GeometryNodeSimulationInput"_ustr);
729 bNode &output_node = params.add_node(
"GeometryNodeSimulationOutput"_ustr);
736 const UString name(params.socket.name);
742 params.connect_available_socket(output_node, name);
745 params.connect_available_socket(input_node, name);
747 params.
node_tree.ensure_topology_cache();
750 input_node.output_socket(1),
752 output_node.input_socket(1));
771 ntype.
ui_name =
"Simulation Output";
804 return std::make_unique<
806 node_tree,
node, own_lf_graph_info);
813 return std::make_unique<
815 node, own_lf_graph_info);
837MutableSpan<NodeSimulationItem> NodeGeometrySimulationOutput::items_span()
839 return MutableSpan<NodeSimulationItem>(items, items_num);
Low-level operations for curves.
#define NODE_CLASS_INTERFACE
#define GEO_NODE_SIMULATION_OUTPUT
#define GEO_NODE_SIMULATION_INPUT
#define BLT_I18NCONTEXT_ID_NODETREE
#define CTX_IFACE_(context, msgid)
#define ID_IS_EDITABLE(_id)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define BLI_assert_unreachable()
Span< T > as_span() const
static const CPPType & get()
constexpr IndexRange()=default
constexpr int64_t size() const
const char * c_str() const
void append(const T &value)
std::optional< int > output_node_id
const bNode * output_node() const
const bNodeTreeZone * get_zone_by_node(const int32_t node_id) const
static BakeValues from_runtime_values(Vector< InputValue > runtime_values, BakeDataBlockMap *data_block_map, bool is_for_cache=true)
const bNodeTree & node_tree() const
const bNodeSocket & other_socket() const
void add_item_full_name(std::string name, SocketLinkOperation::LinkSocketFn fn, int weight=0)
eNodeSocketInOut in_out() const
virtual SimulationZoneBehavior * get(const int zone_id) const =0
SocketValueVariant()=default
void output_mixed_cached_state(lf::Params ¶ms, bke::bake::BakeDataBlockMap *data_block_map, const ComputeContext &compute_context, bke::bake::BakeValues &&prev_bake_values, bke::bake::BakeValues &&next_bake_values, const float mix_factor) const
void pass_through(lf::Params ¶ms, GeoNodesUserData &user_data, bke::bake::BakeDataBlockMap *data_block_map) const
void execute_impl(lf::Params ¶ms, const lf::Context &context) const final
void store_new_state(lf::Params ¶ms, GeoNodesUserData &user_data, bke::bake::BakeDataBlockMap *data_block_map, const sim_output::StoreNewState &info) const
LazyFunctionForSimulationOutputNode(const bNode &node, GeometryNodesLazyFunctionGraphInfo &own_lf_graph_info)
std::optional< bke::bake::BakeValues > get_bake_values_from_inputs(lf::Params ¶ms, bke::bake::BakeDataBlockMap *data_block_map, const bool skip) const
void set_default_outputs(lf::Params ¶ms) const
void output_cached_state(lf::Params ¶ms, GeoNodesUserData &user_data, bke::bake::BakeDataBlockMap *data_block_map, bke::bake::BakeValues &&bake_values) const
#define storage(slot, qualifiers)
void node_register_type(bNodeType &ntype)
bNodeLink & node_add_link(bNodeTree &ntree, bNode &fromnode, bNodeSocket &fromsock, bNode &tonode, bNodeSocket &tosock)
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
internal::ShallowDataConstRef< T > shallow_copy(const T &other)
void mix_socket_values(bke::SocketValueVariant &a, const bke::SocketValueVariant &b, const float factor)
static void node_blend_write(const bNodeTree &, const bNode &node, BlendWriter &writer)
static void node_copy_storage(bNodeTree *, bNode *dst_node, const bNode *src_node)
static void node_declare(NodeDeclarationBuilder &b)
static void node_extra_info(NodeExtraInfoParams ¶ms)
static void node_operators()
static void node_init(bNodeTree *, bNode *node)
static bool node_insert_link(bke::NodeInsertLinkParams ¶ms)
static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
static void node_blend_read(bNodeTree &, bNode &node, BlendDataReader &reader)
NODE_STORAGE_FUNCS(NodeGeometrySimulationOutput)
static void node_free_storage(bNode *node)
static void node_register()
static Vector< SocketValueVariant > get_output_values_from_bake_values(const Span< NodeSimulationItem > simulation_items, const ComputeContext &compute_context, bke::bake::BakeDataBlockMap *data_block_map, bke::bake::BakeValues &&bake_values)
static void node_layout_ex(ui::Layout &layout, bContext *C, PointerRNA *current_node_ptr)
static void draw_simulation_state(const bContext *C, ui::Layout &layout, bNodeTree &ntree, bNode &output_node)
std::variant< PassThrough, StoreNewState, ReadSingle, ReadInterpolated, ReadError > Behavior
void make_common_operators()
void blend_write(BlendWriter *writer, const bNode &node)
void destruct_array(bNode &node)
void blend_read_data(BlendDataReader *reader, bNode &node)
void copy_array(const bNode &src_node, bNode &dst_node)
Accessor::ItemT * add_item_with_socket_type_and_name(bNodeTree &ntree, bNode &node, const eNodeSocketDatatype socket_type, const char *name, std::optional< int > dimensions=std::nullopt)
bool try_add_item_via_any_extend_socket(bNodeTree &ntree, bNode &extend_node, bNode &storage_node, bNodeLink &link, const std::optional< StringRef > socket_identifier=std::nullopt, typename Accessor::ItemT **r_new_item=nullptr)
bool get_bake_draw_context(const bContext *C, const bNode &node, BakeDrawContext &r_ctx)
std::unique_ptr< LazyFunction > get_simulation_output_lazy_function(const bNode &node, GeometryNodesLazyFunctionGraphInfo &own_lf_graph_info)
std::unique_ptr< LazyFunction > get_simulation_input_lazy_function(const bNodeTree &node_tree, const bNode &node, GeometryNodesLazyFunctionGraphInfo &own_lf_graph_info)
void draw_bake_button_row(const BakeDrawContext &ctx, ui::Layout &layout, bool is_in_sidebar=false)
void update_node_declaration_and_sockets(bNodeTree &ntree, bNode &node, Main *bmain)
void draw_data_blocks(const bContext *C, ui::Layout &layout, PointerRNA &bake_rna)
bool socket_type_supports_attributes(const eNodeSocketDatatype socket_type)
void draw_common_bake_settings(bContext *C, BakeDrawContext &ctx, ui::Layout &layout)
std::optional< FoundNestedNodeID > find_nested_node_id(const GeoNodesUserData &user_data, const int node_id)
void set_default_remaining_node_outputs(lf::Params ¶ms, const bNode &node)
std::optional< std::string > get_bake_state_string(const BakeDrawContext &ctx)
std::string get_baked_string(const BakeDrawContext &ctx)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
BMesh const char void * data
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
void node_free_standard_storage(bNode *node)
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
void write_string(const char *data)
eNodeSocketDatatype socket_type
NodeBlendWriteFunction blend_write_storage_content
void(*) register_operators()
std::string ui_description
NodeBlendDataReadFunction blend_data_read_storage_content
void(*) labelfunc(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
NodeExtraInfoFunction get_extra_info
void(*) draw_buttons_ex(ui::Layout &, bContext *C, PointerRNA *ptr)
void(*) initfunc(bNodeTree *ntree, bNode *node)
const char * enum_name_legacy
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
NodeDeclareFunction declare
bool(*) insert_link(NodeInsertLinkParams ¶ms)
bool is_bakeable_in_current_context
GeoNodesSimulationParams * simulation_params
const Object * self_object() const
eval_log::NodeTreeLogger * try_get_tree_logger(const GeoNodesUserData &user_data) const
const ComputeContext * compute_context
const GeoNodesCallData * call_data
Array< int > lf_index_by_bsocket
GeometryNodeLazyFunctionGraphMapping mapping
static void blend_read_data_item(BlendDataReader *reader, ItemT &item)
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int)
static std::string socket_identifier_for_item(const NodeSimulationItem &item)
static void blend_write_item(BlendWriter *writer, const ItemT &item)
static StructRNA ** item_srna
sim_output::Behavior output
bke::bake::BakeDataBlockMap * data_block_map
sim_input::Behavior input
std::function< void(bke::bake::BakeValues values)> store_fn
void enabled_set(bool enabled)
void use_property_decorate_set(bool is_decorate)
void use_property_split_set(bool is_sep)
void label(StringRef name, int icon)
PanelLayout panel(const bContext *C, StringRef idname, bool default_closed)
void active_set(bool active)
Layout & column(bool align)