38#include "RNA_prototypes.hh"
56 const int items_num = node_simulation_items.
size();
62 int last_geometry_index = -1;
63 for (
const int item_i : node_simulation_items.
index_range()) {
69 last_geometry_index = item_i;
71 else if (last_geometry_index != -1) {
88 node.label_or_name(), item.
name);
89 return std::make_shared<AttributeFieldInput>(
90 std::move(attribute_name), type, std::move(socket_inspection_name));
104 std::unique_ptr<bke::bake::BakeItem> *bake_item = zone_state.
items_by_id.lookup_ptr(
106 bake_items.
append(bake_item ? bake_item->get() :
nullptr);
110 bake_items, config, data_block_map, [&](
const int i,
const CPPType &type) {
112 self_object, compute_context, node, node_simulation_items[
i], type);
119 const Object &self_object,
129 bake_items.
append(bake_item ? *bake_item :
nullptr);
133 bake_items, config, data_block_map, [&](
const int i,
const CPPType &type) {
135 self_object, compute_context, node, node_simulation_items[
i], type);
150 for (
const int i : node_simulation_items.
index_range()) {
152 std::unique_ptr<bke::bake::BakeItem> &bake_item = bake_items[
i];
166 C,
"simulation_state_items",
false,
IFACE_(
"Simulation State")))
169 C, panel, ntree, output_node);
172 ntree, output_node, [&](
PointerRNA *item_ptr) {
174 panel->use_property_split_set(
true);
175 panel->use_property_decorate_set(
false);
176 panel->prop(item_ptr,
"socket_type",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
178 panel->prop(item_ptr,
"attribute_domain",
UI_ITEM_NONE, std::nullopt, ICON_NONE);
188 bNode *current_node =
static_cast<bNode *
>(current_node_ptr->
data);
221 row->
label(*bake_state_str, ICON_NONE);
244 output_node_id_ = node_storage(node).output_node_id;
245 const bNode &output_node = *node_tree.node_by_id(output_node_id_);
251 lf_index_by_bsocket[node.output_socket(0).index_in_tree()] =
outputs_.append_and_get_index_as(
254 for (
const int i : simulation_items_.index_range()) {
256 const bNodeSocket &input_bsocket = node.input_socket(
i);
257 const bNodeSocket &output_bsocket = node.output_socket(
i + 1);
259 lf_index_by_bsocket[input_bsocket.index_in_tree()] =
inputs_.append_and_get_index_as(
261 lf_index_by_bsocket[output_bsocket.index_in_tree()] =
outputs_.append_and_get_index_as(
278 std::optional<FoundNestedNodeID> found_id =
find_nested_node_id(user_data, output_node_id_);
283 if (found_id->is_in_loop || found_id->is_in_closure) {
289 if (!zone_behavior) {
294 float delta_time = 0.0f;
295 if (
auto *info = std::get_if<sim_input::OutputCopy>(&input_behavior)) {
296 delta_time = info->delta_time;
300 else if (
auto *info = std::get_if<sim_input::OutputMove>(&input_behavior)) {
301 delta_time = info->delta_time;
305 else if (std::get_if<sim_input::PassThrough>(&input_behavior)) {
312 if (!
params.output_was_set(0)) {
334 for (
const int i : simulation_items_.index_range()) {
335 params.set_output(
i + 1, std::move(output_values[
i]));
346 std::move(zone_state),
351 for (
const int i : simulation_items_.index_range()) {
352 params.set_output(
i + 1, std::move(output_values[
i]));
361 for (
const int i :
inputs_.index_range()) {
364 if (input_value_pointers.
as_span().contains(
nullptr)) {
369 for (
const int i :
inputs_.index_range()) {
370 input_values[
i] = std::move(*input_value_pointers[
i]);
377 simulation_items_, input_values, data_block_map);
384 b.use_custom_socket_order();
385 b.allow_any_socket_order();
388 const bNode *node =
b.node_or_null();
389 const bNodeTree *node_tree =
b.tree_or_null();
390 if (
ELEM(
nullptr, node, node_tree)) {
394 const bNode *output_node = node_tree->node_by_id(node_storage(*node).output_node_id);
401 for (
const int i :
IndexRange(output_storage.items_num)) {
409 auto &input_decl =
b.add_input(socket_type,
name, identifier)
412 auto &output_decl =
b.add_output(socket_type,
name, identifier).align_with_previous();
415 input_decl.supports_field().structure_type(StructureType::Dynamic);
416 output_decl.dependent_field({input_decl.index()});
419 b.add_input<
decl::Extend>(
"",
"__extend__").structure_type(StructureType::Dynamic);
421 .structure_type(StructureType::Dynamic)
422 .align_with_previous();
429 data->output_node_id = 0;
436 const int label_maxncpy)
443 bNode *output_node =
params.ntree.node_by_id(node_storage(
params.node).output_node_id);
455 ntype.
ui_name =
"Simulation Input";
467 "NodeGeometrySimulationInput",
483 int skip_input_index_;
489 int skip_inputs_offset_;
494 int solve_inputs_offset_;
507 const bNodeSocket &skip_bsocket = node.input_socket(0);
508 skip_input_index_ =
inputs_.append_and_get_index_as(
510 lf_index_by_bsocket[skip_bsocket.index_in_tree()] = skip_input_index_;
512 skip_inputs_offset_ =
inputs_.size();
515 for (
const int i : simulation_items_.index_range()) {
520 solve_inputs_offset_ =
inputs_.size();
523 for (
const int i : simulation_items_.index_range()) {
525 const bNodeSocket &input_bsocket = node.input_socket(
i + 1);
526 const bNodeSocket &output_bsocket = node.output_socket(
i);
528 lf_index_by_bsocket[input_bsocket.index_in_tree()] =
inputs_.append_and_get_index_as(
530 lf_index_by_bsocket[output_bsocket.index_in_tree()] =
outputs_.append_and_get_index_as(
539 context.local_user_data);
549 tree_logger->node_warnings.append(
550 *tree_logger->allocator,
552 {NodeWarningType::Error, TIP_(
"Simulation zone is not supported")}});
557 std::optional<FoundNestedNodeID> found_id =
find_nested_node_id(user_data, node_.identifier);
562 if (found_id->is_in_loop || found_id->is_in_closure) {
566 const StringRefNull message =
TIP_(
"Simulation must not be in a loop or closure");
567 tree_logger->node_warnings.append(*tree_logger->allocator,
568 {node_.identifier, {NodeWarningType::Error, message}});
573 SimulationZoneBehavior *zone_behavior = user_data.call_data->simulation_params->get(
575 if (!zone_behavior) {
576 this->set_default_outputs(
params);
580 if (
auto *info = std::get_if<sim_output::ReadSingle>(&output_behavior)) {
581 this->output_cached_state(
params, user_data, zone_behavior->data_block_map, info->state);
583 else if (
auto *info = std::get_if<sim_output::ReadInterpolated>(&output_behavior)) {
584 this->output_mixed_cached_state(
params,
585 zone_behavior->data_block_map,
586 *user_data.call_data->self_object(),
587 *user_data.compute_context,
592 else if (std::get_if<sim_output::PassThrough>(&output_behavior)) {
593 this->pass_through(
params, user_data, zone_behavior->data_block_map);
595 else if (
auto *info = std::get_if<sim_output::StoreNewState>(&output_behavior)) {
596 this->store_new_state(
params, user_data, zone_behavior->data_block_map, *info);
620 for (
const int i : simulation_items_.index_range()) {
621 params.set_output(
i, std::move(output_values[
i]));
627 const Object &self_object,
631 const float mix_factor)
const
634 simulation_items_, prev_state, self_object, compute_context, node_, data_block_map);
637 simulation_items_,
next_state, self_object, compute_context, node_, data_block_map);
638 for (
const int i : simulation_items_.index_range()) {
644 for (
const int i : simulation_items_.index_range()) {
645 params.set_output(
i, std::move(output_values[
i]));
654 params, data_block_map,
true);
661 std::move(*bake_state),
666 for (
const int i : simulation_items_.index_range()) {
667 params.set_output(
i, std::move(output_values[
i]));
678 if (skip_variant ==
nullptr) {
682 const bool skip = skip_variant->
get<
bool>();
688 params, data_block_map, skip);
694 info.
store_fn(std::move(*bake_state));
701 const int params_offset = skip ? skip_inputs_offset_ : solve_inputs_offset_;
703 for (
const int i : simulation_items_.index_range()) {
707 if (input_value_pointers.
as_span().contains(
nullptr)) {
713 for (
const int i : simulation_items_.index_range()) {
714 input_values[
i] = std::move(*input_value_pointers[
i]);
723 b.use_custom_socket_order();
724 b.allow_any_socket_order();
726 "Forward the output of the simulation input node directly to the output node and ignore "
727 "the nodes in the simulation zone");
730 const bNode *node =
b.node_or_null();
731 if (node ==
nullptr) {
745 auto &input_decl =
b.add_input(socket_type,
name, identifier)
748 auto &output_decl =
b.add_output(socket_type,
name, identifier).align_with_previous();
751 input_decl.supports_field().structure_type(StructureType::Dynamic);
752 output_decl.dependent_field({input_decl.index()});
755 b.add_input<
decl::Extend>(
"",
"__extend__").structure_type(StructureType::Dynamic);
757 .structure_type(StructureType::Dynamic)
758 .align_with_previous();
765 data->next_identifier = 0;
770 data->items[0].identifier =
data->next_identifier++;
786 dst_node->
storage = dst_storage;
810 row.
text =
TIP_(
"Cannot bake in zone");
811 row.
icon = ICON_ERROR;
812 params.rows.append(std::move(row));
817 params.rows.append(std::move(row));
830 bNode &input_node =
params.add_node(
"GeometryNodeSimulationInput");
831 bNode &output_node =
params.add_node(
"GeometryNodeSimulationOutput");
846 params.connect_available_socket(output_node,
params.socket.name);
849 params.connect_available_socket(input_node,
params.socket.name);
851 params.node_tree.ensure_topology_cache();
854 input_node.output_socket(1),
856 output_node.input_socket(1));
875 ntype.
ui_name =
"Simulation Output";
908 return std::make_unique<
910 node_tree, node, own_lf_graph_info);
917 return std::make_unique<
919 node, own_lf_graph_info);
927 switch (socket_type) {
942 if (!prev.is_single() || !
next.is_single()) {
947 prev.convert_to_single();
952 void *prev_value = prev.get_single_ptr().get();
956 using T =
decltype(dummy);
958 factor, *
static_cast<T *
>(prev_value), *
static_cast<const T *
>(next_value));
Low-level operations for curves.
#define NODE_CLASS_INTERFACE
#define NODE_STORAGE_FUNCS(StorageT)
#define GEO_NODE_SIMULATION_OUTPUT
#define GEO_NODE_SIMULATION_INPUT
#define BLI_assert_unreachable()
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
void BLO_write_string(BlendWriter *writer, const char *data_ptr)
#define BLT_I18NCONTEXT_ID_NODETREE
#define CTX_IFACE_(context, msgid)
#define ID_IS_EDITABLE(_id)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
BMesh const char void * data
void resize(const int64_t new_size)
Span< T > as_span() const
static const CPPType & get()
const ComputeContextHash & hash() const
constexpr int64_t size() const
constexpr IndexRange index_range() const
void append(const T &value)
void resize(const int64_t new_size)
GPointer get_single_ptr() const
std::optional< int > output_node_id
const bNode * output_node() const
const bNodeTreeZone * get_zone_by_node(const int32_t node_id) const
Vector< Output > outputs_
virtual SimulationZoneBehavior * get(const int zone_id) const =0
void output_mixed_cached_state(lf::Params ¶ms, bke::bake::BakeDataBlockMap *data_block_map, const Object &self_object, const ComputeContext &compute_context, const bke::bake::BakeStateRef &prev_state, const bke::bake::BakeStateRef &next_state, 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)
void set_default_outputs(lf::Params ¶ms) const
void output_cached_state(lf::Params ¶ms, GeoNodesUserData &user_data, bke::bake::BakeDataBlockMap *data_block_map, const bke::bake::BakeStateRef &state) const
std::optional< bke::bake::BakeState > get_bake_state_from_inputs(lf::Params ¶ms, bke::bake::BakeDataBlockMap *data_block_map, const bool skip) const
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
void * MEM_callocN(size_t len, const char *str)
void * MEM_dupallocN(const void *vmemh)
void MEM_freeN(void *vmemh)
void convert_to_static_type(const CPPType &cpp_type, const Func &func)
T mix2(float factor, const T &a, const T &b)
Array< std::unique_ptr< BakeItem > > move_socket_values_to_bake_items(MutableSpan< SocketValueVariant > socket_values, const BakeSocketConfig &config, BakeDataBlockMap *data_block_map)
Vector< SocketValueVariant > copy_bake_items_to_socket_values(Span< const BakeItem * > bake_items, const BakeSocketConfig &config, BakeDataBlockMap *data_block_map, FunctionRef< std::shared_ptr< AttributeFieldInput >(int, const CPPType &)> make_attribute_field)
Vector< SocketValueVariant > move_bake_items_to_socket_values(Span< BakeItem * > bake_items, const BakeSocketConfig &config, BakeDataBlockMap *data_block_map, FunctionRef< std::shared_ptr< AttributeFieldInput >(int socket_index, const CPPType &)> make_attribute_field)
void node_register_type(bNodeType &ntype)
const CPPType * socket_type_to_geo_nodes_base_cpp_type(eNodeSocketDatatype type)
bNodeLink & node_add_link(bNodeTree &ntree, bNode &fromnode, bNodeSocket &fromsock, bNode &tonode, bNodeSocket &tosock)
std::string hash_to_anonymous_attribute_name(Args &&...args)
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))
bke::GeometrySet mix_geometries(bke::GeometrySet a, const bke::GeometrySet &b, 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)
static void node_free_storage(bNode *node)
static void node_register()
static void node_layout_ex(uiLayout *layout, bContext *C, PointerRNA *current_node_ptr)
static std::shared_ptr< AttributeFieldInput > make_attribute_field(const Object &self_object, const ComputeContext &compute_context, const bNode &node, const NodeSimulationItem &item, const CPPType &type)
static void draw_simulation_state(const bContext *C, uiLayout *layout, bNodeTree &ntree, bNode &output_node)
static Vector< SocketValueVariant > copy_simulation_state_to_values(const Span< NodeSimulationItem > node_simulation_items, const bke::bake::BakeStateRef &zone_state, const Object &self_object, const ComputeContext &compute_context, const bNode &node, bke::bake::BakeDataBlockMap *data_block_map)
static bke::bake::BakeState move_values_to_simulation_state(const Span< NodeSimulationItem > node_simulation_items, MutableSpan< SocketValueVariant > input_values, bke::bake::BakeDataBlockMap *data_block_map)
static bke::bake::BakeSocketConfig make_bake_socket_config(const Span< NodeSimulationItem > node_simulation_items)
static Vector< SocketValueVariant > move_simulation_state_to_values(const Span< NodeSimulationItem > node_simulation_items, bke::bake::BakeState zone_state, const Object &self_object, const ComputeContext &compute_context, const bNode &node, bke::bake::BakeDataBlockMap *data_block_map)
std::variant< PassThrough, StoreNewState, ReadSingle, ReadInterpolated, ReadError > Behavior
void make_common_operators()
static void draw_items_list_with_operators(const bContext *C, uiLayout *layout, const bNodeTree &tree, const bNode &node)
static void draw_active_item_props(const bNodeTree &tree, const bNode &node, const FunctionRef< void(PointerRNA *item_ptr)> draw_item)
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)
void mix_baked_data_item(eNodeSocketDatatype socket_type, SocketValueVariant &prev, const SocketValueVariant &next, const float factor)
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)
void draw_data_blocks(const bContext *C, uiLayout *layout, PointerRNA &bake_rna)
std::unique_ptr< LazyFunction > get_simulation_input_lazy_function(const bNodeTree &node_tree, const bNode &node, GeometryNodesLazyFunctionGraphInfo &own_lf_graph_info)
void update_node_declaration_and_sockets(bNodeTree &ntree, bNode &node)
void draw_common_bake_settings(bContext *C, BakeDrawContext &ctx, uiLayout *layout)
void draw_bake_button_row(const BakeDrawContext &ctx, uiLayout *layout, bool is_in_sidebar=false)
std::string make_anonymous_attribute_socket_inspection_string(const bNodeSocket &socket)
std::optional< FoundNestedNodeID > find_nested_node_id(const GeoNodesUserData &user_data, const int node_id)
bool socket_type_supports_fields(const eNodeSocketDatatype socket_type)
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)
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void node_free_standard_storage(bNode *node)
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
NodeSimulationItem * items
NodeBlendWriteFunction blend_write_storage_content
std::string ui_description
NodeBlendDataReadFunction blend_data_read_storage_content
void(* initfunc)(bNodeTree *ntree, bNode *node)
void(* labelfunc)(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
void(* draw_buttons_ex)(uiLayout *, bContext *C, PointerRNA *ptr)
NodeExtraInfoFunction get_extra_info
const char * enum_name_legacy
bool(* insert_link)(NodeInsertLinkParams ¶ms)
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
NodeDeclareFunction declare
void(* register_operators)()
Vector< Vector< int, 1 > > geometries_by_attribute
Vector< StringRef > names
Vector< eNodeSocketDatatype > types
Vector< AttrDomain > domains
Map< int, const BakeItem * > items_by_id
Map< int, std::unique_ptr< BakeItem > > items_by_id
bool is_bakeable_in_current_context
GeoNodesSimulationParams * simulation_params
const Object * self_object() const
geo_eval_log::GeoTreeLogger * 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
bke::bake::BakeDataBlockMap * data_block_map
sim_input::Behavior input
std::function< void(bke::bake::BakeState state)> store_fn
void use_property_decorate_set(bool is_sep)
PanelLayout panel(const bContext *C, blender::StringRef idname, bool default_closed)
void label(blender::StringRef name, int icon)
uiLayout & column(bool align)
void active_set(bool active)
void enabled_set(bool enabled)
void use_property_split_set(bool value)