35 N_(
"Interpolate the attribute from the corners of the hit face")},
40 N_(
"Use the attribute value of the closest mesh element")},
41 {0,
nullptr, 0,
nullptr,
nullptr},
52 if (
node !=
nullptr) {
55 b.add_input(data_type,
"Attribute"_ustr).hide_value().evaluated_geometry_field();
60 .description(
"Mapping from the target geometry to hit points");
62 const int source_position =
b.add_input<
decl::Vector>(
"Source Position"_ustr)
66 const int ray_direction =
b.add_input<
decl::Vector>(
"Ray Direction"_ustr)
67 .default_value({0.0f, 0.0f, -1.0f})
68 .structure_type(StructureType::Dynamic)
71 .default_value(100.0f)
74 .structure_type(StructureType::Dynamic)
80 .inferred_structure_type(dynamic_inputs)
81 .propagate_references(dynamic_inputs);
83 .inferred_structure_type(dynamic_inputs)
84 .propagate_references(dynamic_inputs);
86 .inferred_structure_type(dynamic_inputs)
87 .propagate_references(dynamic_inputs);
89 .inferred_structure_type(dynamic_inputs)
90 .propagate_references(dynamic_inputs);
92 if (
node !=
nullptr) {
94 b.add_output(data_type,
"Attribute"_ustr)
95 .inferred_structure_type(dynamic_inputs)
96 .propagate_references(dynamic_inputs);
124 node_storage(
node).data_type = *type;
143 mask.foreach_index([&](
const int i) {
145 ray.
origin = ray_origins[i];
149 if (
const std::optional<bke::bvh::RayHit> hit = tree_data.
ray_intersect(ray)) {
155 r_hit_indices[i] = hit->index;
158 r_hit_positions[i] = hit->position(ray);
164 r_hit_distances[i] = hit->distance;
167 r_bary_weights[i] = hit->bary_coord;
175 r_hit_indices[i] = -1;
178 r_hit_positions[i] =
float3(0.0f, 0.0f, 0.0f);
181 r_hit_normals[i] =
float3(0.0f, 0.0f, 0.0f);
184 r_hit_distances[i] = ray_lengths[i];
187 r_bary_weights[i] =
float3(0);
200 target_.ensure_owns_direct_data();
201 static const mf::Signature
signature = []() {
203 mf::SignatureBuilder builder{
"Raycast",
signature};
204 builder.single_input<
float3>(
"Source Position");
205 builder.single_input<
float3>(
"Ray Direction");
206 builder.single_input<
float>(
"Ray Length");
207 builder.single_output<
bool>(
"Is Hit", mf::ParamFlag::SupportsUnusedOutput);
208 builder.single_output<
float3>(
"Hit Position", mf::ParamFlag::SupportsUnusedOutput);
209 builder.single_output<
float3>(
"Hit Normal", mf::ParamFlag::SupportsUnusedOutput);
210 builder.single_output<
float>(
"Distance", mf::ParamFlag::SupportsUnusedOutput);
211 builder.single_output<
int>(
"Triangle Index", mf::ParamFlag::SupportsUnusedOutput);
212 builder.single_output<
float3>(
"Barycentric Weight", mf::ParamFlag::SupportsUnusedOutput);
221 const Mesh &
mesh = *target_.get_mesh();
226 params.readonly_single_input<
float3>(0,
"Source Position"),
227 params.readonly_single_input<
float3>(1,
"Ray Direction"),
228 params.readonly_single_input<
float>(2,
"Ray Length"),
229 params.uninitialized_single_output_if_required<
bool>(3,
"Is Hit"),
230 params.uninitialized_single_output_if_required<
int>(7,
"Triangle Index"),
231 params.uninitialized_single_output_if_required<
float3>(4,
"Hit Position"),
232 params.uninitialized_single_output_if_required<
float3>(5,
"Hit Normal"),
233 params.uninitialized_single_output_if_required<
float>(6,
"Distance"),
234 params.uninitialized_single_output_if_required<
float3>(8,
"Barycentric Weight"));
239 static constexpr int8_t id = 0;
241 hash.add(target_.get_mesh());
266 std::string error_message;
273 "normalize(float3)"_ustr);
276 {&normalized_direction},
305 bary_weight_required ? &bary_weights :
nullptr},
314 params.
set_output(
"Is Hit"_ustr, std::move(is_hit));
315 params.
set_output(
"Hit Position"_ustr, hit_position);
316 params.
set_output(
"Hit Normal"_ustr, std::move(hit_normal));
317 params.
set_output(
"Hit Distance"_ustr, std::move(hit_distance));
319 if (!attribute_required) {
329 std::make_shared<bke::mesh_surface_sample::BaryWeightSampleFn>(std::move(target),
331 {&triangle_index, &bary_weights},
340 params.
set_output(
"Attribute"_ustr, std::move(sampled_atribute));
346 std::make_shared<bke::mesh_surface_sample::NearestCornerFromPositionFn>(target),
347 {&hit_position, &triangle_index_copy},
358 std::make_shared<bke::SampleIndexFunction>(
369 params.
set_output(
"Attribute"_ustr, std::move(sampled_atribute));
380 "Type of data stored in attribute",
394 "Cast rays from the context geometry onto a target geometry, and retrieve information from "
#define NODE_STORAGE_FUNCS(StorageT)
#define NODE_CLASS_GEOMETRY
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
constexpr bool is_empty() const
std::optional< RayHit > ray_intersect(const Ray &ray) const
const Signature & signature() const
void set_signature(const Signature *signature)
const bke::bNodeType & node_type() const
void add_item(std::string socket_name, SocketLinkOperation::LinkSocketFn fn, int weight=0)
const bNodeSocket & other_socket() const
void error_message_add(const NodeWarningType type, StringRef message) const
T extract_input(const UString identifier)
T get_input(const UString identifier) const
GeoNodesUserData * user_data() const
bool output_is_required(const UString identifier) const
void set_default_remaining_outputs()
void set_output(const UString identifier, T &&value)
void update_and_connect_available_socket(bNode &new_node, UString socket_name)
bNode & add_node(UString idname)
Vector< SocketDeclaration * > inputs
Vector< SocketDeclaration * > outputs
StructureType structure_type
void call(const IndexMask &mask, mf::Params params, mf::Context) const override
RaycastFunction(GeometrySet target)
void hash_unique(UniqueHashBytes &hash) const override
void node_register_type(bNodeType &ntype)
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))
std::optional< eCustomDataType > socket_type_to_custom_data_type(eNodeSocketDatatype type)
const MultiFunction & lookup(UString id)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
const EnumPropertyItem * attribute_type_type_with_socket_fn(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
static EnumPropertyItem interpolation_items[]
static void node_geo_exec(GeoNodeExecParams params)
static void node_init(bNodeTree *, bNode *node)
static void node_rna(StructRNA *srna)
static void raycast_to_mesh(const IndexMask &mask, const Mesh &mesh, const VArray< float3 > &ray_origins, const VArray< float3 > &ray_directions, const VArray< float > &ray_lengths, const MutableSpan< bool > r_hit, const MutableSpan< int > r_hit_indices, const MutableSpan< float3 > r_hit_positions, const MutableSpan< float3 > r_hit_normals, const MutableSpan< float > r_hit_distances, const MutableSpan< float3 > r_bary_weights)
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void node_gather_link_searches(GatherLinkSearchOpParams ¶ms)
static void node_register()
static void node_declare(NodeDeclarationBuilder &b)
void search_link_ops_for_declarations(GatherLinkSearchOpParams ¶ms, Span< SocketDeclaration * > declarations)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
bool execute_multi_function_on_value_variant(const MultiFunction &fn, const std::shared_ptr< MultiFunction > &owned_fn, const Span< SocketValueVariant * > input_values, const Span< SocketValueVariant * > output_values, GeoNodesUserData *user_data, std::string &r_error_message)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
GeometryNodeRaycastMapMode
@ GEO_NODE_RAYCAST_NEAREST
@ GEO_NODE_RAYCAST_INTERPOLATED
BMesh const char void * data
const EnumPropertyItem rna_enum_attribute_type_items[]
@ NODE_DEFAULT_INPUT_POSITION_FIELD
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
void node_free_standard_storage(bNode *node)
VecBase< float, 3 > float3
constexpr float ray_length
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
const Mesh * get_mesh() const
static constexpr int _160
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
std::string ui_description
NodeGeometryExecFunction geometry_node_execute
void(*) initfunc(bNodeTree *ntree, bNode *node)
const char * enum_name_legacy
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
NodeDeclareFunction declare
nodes::NodeDeclaration * static_declaration
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)