[Bf-blender-cvs] [770d70127fb] temp-geometry-nodes-fields-prototype: Support fields and anonymous attributes in the raycast node
Hans Goudey
noreply at git.blender.org
Tue Aug 3 05:29:41 CEST 2021
Commit: 770d70127fb19d4c4576c70dccc84ae60955b19d
Author: Hans Goudey
Date: Mon Aug 2 23:29:32 2021 -0400
Branches: temp-geometry-nodes-fields-prototype
https://developer.blender.org/rB770d70127fb19d4c4576c70dccc84ae60955b19d
Support fields and anonymous attributes in the raycast node
===================================================================
M source/blender/makesdna/DNA_node_types.h
M source/blender/makesrna/intern/rna_nodetree.c
M source/blender/nodes/geometry/nodes/node_geo_raycast.cc
===================================================================
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 33d1a92c386..041fd0f443e 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1412,10 +1412,6 @@ typedef struct NodeGeometryAttributeTransfer {
typedef struct NodeGeometryRaycast {
/* GeometryNodeRaycastMapMode. */
uint8_t mapping;
-
- uint8_t input_type_ray_direction;
- uint8_t input_type_ray_length;
- char _pad[1];
} NodeGeometryRaycast;
typedef struct NodeGeometryAttribute {
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index a235c521033..d5bde2c0173 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -10206,16 +10206,6 @@ static void def_geo_raycast(StructRNA *srna)
RNA_def_property_enum_items(prop, mapping_items);
RNA_def_property_ui_text(prop, "Mapping", "Mapping from the target geometry to hit points");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
-
- prop = RNA_def_property(srna, "input_type_ray_direction", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_items(prop, rna_node_geometry_attribute_input_type_items_vector);
- RNA_def_property_ui_text(prop, "Input Type Ray Direction", "");
- RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
-
- prop = RNA_def_property(srna, "input_type_ray_length", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_items(prop, rna_node_geometry_attribute_input_type_items_float);
- RNA_def_property_ui_text(prop, "Input Type Ray Length", "");
- RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
}
static void def_geo_attribute(StructRNA *srna)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc
index 0c1d8645411..bc607d00511 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_raycast.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_raycast.cc
@@ -27,21 +27,19 @@
static bNodeSocketTemplate geo_node_raycast_in[] = {
{SOCK_GEOMETRY, N_("Geometry")},
{SOCK_GEOMETRY, N_("Target Geometry")},
- {SOCK_STRING, N_("Ray Direction")},
{SOCK_VECTOR, N_("Ray Direction"), 0.0, 0.0, 1.0, 0.0, -FLT_MAX, FLT_MAX},
- {SOCK_STRING, N_("Ray Length")},
{SOCK_FLOAT, N_("Ray Length"), 100.0, 0.0, 0.0, 0.0, 0.0f, FLT_MAX, PROP_DISTANCE},
{SOCK_STRING, N_("Target Attribute")},
- {SOCK_STRING, N_("Is Hit")},
- {SOCK_STRING, N_("Hit Position")},
- {SOCK_STRING, N_("Hit Normal")},
- {SOCK_STRING, N_("Hit Distance")},
{SOCK_STRING, N_("Hit Attribute")},
{-1, ""},
};
static bNodeSocketTemplate geo_node_raycast_out[] = {
{SOCK_GEOMETRY, N_("Geometry")},
+ {SOCK_BOOLEAN, N_("Is Hit")},
+ {SOCK_VECTOR, N_("Hit Position")},
+ {SOCK_VECTOR, N_("Hit Normal")},
+ {SOCK_FLOAT, N_("Hit Distance")},
{-1, ""},
};
@@ -50,30 +48,15 @@ static void geo_node_raycast_layout(uiLayout *layout, bContext *UNUSED(C), Point
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
uiItemR(layout, ptr, "mapping", 0, IFACE_("Mapping"), ICON_NONE);
- uiItemR(layout, ptr, "input_type_ray_direction", 0, IFACE_("Ray Direction"), ICON_NONE);
- uiItemR(layout, ptr, "input_type_ray_length", 0, IFACE_("Ray Length"), ICON_NONE);
}
static void geo_node_raycast_init(bNodeTree *UNUSED(tree), bNode *node)
{
NodeGeometryRaycast *data = (NodeGeometryRaycast *)MEM_callocN(sizeof(NodeGeometryRaycast),
__func__);
- data->input_type_ray_direction = GEO_NODE_ATTRIBUTE_INPUT_VECTOR;
- data->input_type_ray_length = GEO_NODE_ATTRIBUTE_INPUT_FLOAT;
node->storage = data;
}
-static void geo_node_raycast_update(bNodeTree *UNUSED(ntree), bNode *node)
-{
- NodeGeometryRaycast *node_storage = (NodeGeometryRaycast *)node->storage;
- blender::nodes::update_attribute_input_socket_availabilities(
- *node,
- "Ray Direction",
- (GeometryNodeAttributeInputMode)node_storage->input_type_ray_direction);
- blender::nodes::update_attribute_input_socket_availabilities(
- *node, "Ray Length", (GeometryNodeAttributeInputMode)node_storage->input_type_ray_length);
-}
-
namespace blender::nodes {
static void raycast_to_mesh(const Mesh *mesh,
@@ -168,10 +151,10 @@ static bke::mesh_surface_sample::eAttributeMapMode get_map_mode(
static void raycast_from_points(const GeoNodeExecParams ¶ms,
const GeometrySet &src_geometry,
GeometryComponent &dst_component,
- const StringRef hit_name,
- const StringRef hit_position_name,
- const StringRef hit_normal_name,
- const StringRef hit_distance_name,
+ const AnonymousCustomDataLayerID *hit_id,
+ const AnonymousCustomDataLayerID *hit_position_id,
+ const AnonymousCustomDataLayerID *hit_normal_id,
+ const AnonymousCustomDataLayerID *hit_distance_id,
const Span<std::string> hit_attribute_names,
const Span<std::string> hit_attribute_output_names)
{
@@ -196,41 +179,66 @@ static void raycast_from_points(const GeoNodeExecParams ¶ms,
GVArray_Typed<float3> ray_origins = dst_component.attribute_get_for_read<float3>(
"position", result_domain, {0, 0, 0});
- GVArray_Typed<float3> ray_directions = params.get_input_attribute<float3>(
- "Ray Direction", dst_component, result_domain, {0, 0, 0});
- GVArray_Typed<float> ray_lengths = params.get_input_attribute<float>(
- "Ray Length", dst_component, result_domain, 0);
-
- OutputAttribute_Typed<bool> hit_attribute =
- dst_component.attribute_try_get_for_output_only<bool>(hit_name, result_domain);
- OutputAttribute_Typed<float3> hit_position_attribute =
- dst_component.attribute_try_get_for_output_only<float3>(hit_position_name, result_domain);
- OutputAttribute_Typed<float3> hit_normal_attribute =
- dst_component.attribute_try_get_for_output_only<float3>(hit_normal_name, result_domain);
- OutputAttribute_Typed<float> hit_distance_attribute =
- dst_component.attribute_try_get_for_output_only<float>(hit_distance_name, result_domain);
-
- /* Positions and looptri indices are always needed for interpolation,
- * so create temporary arrays if no output attribute is given.
- */
- Array<int> hit_indices;
+
+ bke::FieldRef<float3> direction_field = params.get_input_field<float3>("Ray Direction");
+ bke::FieldInputs direction_field_inputs = direction_field->prepare_inputs();
+ Vector<std::unique_ptr<bke::FieldInputValue>> direction_field_input_values;
+ prepare_field_inputs(
+ direction_field_inputs, dst_component, ATTR_DOMAIN_POINT, direction_field_input_values);
+ bke::FieldOutput direction_field_output = direction_field->evaluate(
+ IndexRange(ray_origins->size()), direction_field_inputs);
+ GVArray_Typed<float3> ray_directions{direction_field_output.varray_ref()};
+
+ bke::FieldRef<float> ray_length_field = params.get_input_field<float>("Ray Length");
+ bke::FieldInputs ray_length_field_inputs = ray_length_field->prepare_inputs();
+ Vector<std::unique_ptr<bke::FieldInputValue>> ray_length_field_input_values;
+ prepare_field_inputs(
+ ray_length_field_inputs, dst_component, ATTR_DOMAIN_POINT, ray_length_field_input_values);
+ bke::FieldOutput ray_length_field_output = ray_length_field->evaluate(
+ IndexRange(ray_origins->size()), ray_length_field_inputs);
+ GVArray_Typed<float> ray_lengths{ray_length_field_output.varray_ref()};
+
+ MutableSpan<bool> is_hit{};
+ if (hit_id != nullptr) {
+ dst_component.attribute_try_create_anonymous(
+ *hit_id, ATTR_DOMAIN_POINT, CD_PROP_BOOL, AttributeInitDefault());
+ WriteAttributeLookup attribute = dst_component.attribute_try_get_anonymous_for_write(*hit_id);
+ is_hit = attribute.varray->get_internal_span().typed<bool>();
+ }
Array<float3> hit_positions_internal;
+ MutableSpan<float3> hit_positions{};
+ if (hit_position_id != nullptr) {
+ dst_component.attribute_try_create_anonymous(
+ *hit_position_id, ATTR_DOMAIN_POINT, CD_PROP_FLOAT3, AttributeInitDefault());
+ WriteAttributeLookup attribute = dst_component.attribute_try_get_anonymous_for_write(
+ *hit_position_id);
+ hit_positions = attribute.varray->get_internal_span().typed<float3>();
+ }
+ else {
+ hit_positions_internal.reinitialize(ray_origins->size());
+ hit_positions = hit_positions_internal;
+ }
+ MutableSpan<float3> hit_normals{};
+ if (hit_normal_id != nullptr) {
+ dst_component.attribute_try_create_anonymous(
+ *hit_normal_id, ATTR_DOMAIN_POINT, CD_PROP_FLOAT3, AttributeInitDefault());
+ WriteAttributeLookup attribute = dst_component.attribute_try_get_anonymous_for_write(
+ *hit_normal_id);
+ hit_normals = attribute.varray->get_internal_span().typed<float3>();
+ }
+ MutableSpan<float> hit_distances{};
+ if (hit_distance_id != nullptr) {
+ dst_component.attribute_try_create_anonymous(
+ *hit_distance_id, ATTR_DOMAIN_POINT, CD_PROP_FLOAT, AttributeInitDefault());
+ WriteAttributeLookup attribute = dst_component.attribute_try_get_anonymous_for_write(
+ *hit_distance_id);
+ hit_distances = attribute.varray->get_internal_span().typed<float>();
+ }
+
+ Array<int> hit_indices;
if (!hit_attribute_names.is_empty()) {
hit_indices.reinitialize(ray_origins->size());
-
- if (!hit_position_attribute) {
- hit_positions_internal.reinitialize(ray_origins->size());
- }
}
- const MutableSpan<bool> is_hit = hit_attribute ? hit_attribute.as_span() : MutableSpan<bool>();
- const MutableSpan<float3> hit_positions = hit_position_attribute ?
- hit_position_attribute.as_span() :
- hit_positions_internal;
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list