Geometry Nodes: add utility to access logged primitive values

This commit is contained in:
Jacques Lucke
2024-06-28 12:46:08 +02:00
parent d367b6e4a2
commit dda4a50bf5
2 changed files with 36 additions and 0 deletions

View File

@@ -304,6 +304,23 @@ class GeoTreeLog {
void ensure_debug_messages();
ValueLog *find_socket_value_log(const bNodeSocket &query_socket);
[[nodiscard]] bool try_convert_primitive_socket_value(const GenericValueLog &value_log,
const CPPType &dst_type,
void *dst);
template<typename T>
std::optional<T> find_primitive_socket_value(const bNodeSocket &query_socket)
{
if (auto *value_log = dynamic_cast<GenericValueLog *>(
this->find_socket_value_log(query_socket)))
{
T value;
if (this->try_convert_primitive_socket_value(*value_log, CPPType::get<T>(), &value)) {
return value;
}
}
return std::nullopt;
}
};
/**

View File

@@ -9,6 +9,7 @@
#include "BKE_curves.hh"
#include "BKE_node_runtime.hh"
#include "BKE_node_socket_value.hh"
#include "BKE_type_conversions.hh"
#include "BKE_volume.hh"
#include "BKE_volume_openvdb.hh"
@@ -484,6 +485,24 @@ ValueLog *GeoTreeLog::find_socket_value_log(const bNodeSocket &query_socket)
return nullptr;
}
bool GeoTreeLog::try_convert_primitive_socket_value(const GenericValueLog &value_log,
const CPPType &dst_type,
void *dst)
{
const void *src_value = value_log.value.get();
if (!src_value) {
return false;
}
const bke::DataTypeConversions &conversions = bke::get_implicit_type_conversions();
const CPPType &src_type = *value_log.value.type();
if (!conversions.is_convertible(src_type, dst_type) && src_type != dst_type) {
return false;
}
dst_type.destruct(dst);
conversions.convert_to_uninitialized(src_type, dst_type, src_value, dst);
return true;
}
GeoTreeLogger &GeoModifierLog::get_local_tree_logger(const ComputeContext &compute_context)
{
LocalData &local_data = data_per_thread_.local();