Skip to content

Commit a4f47cc

Browse files
committed
Add the 'Index Points' node
1 parent 0932265 commit a4f47cc

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

node-graph/nodes/vector/src/vector_nodes.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,6 +2058,31 @@ async fn count_points(_: impl Ctx, source: Table<Vector>) -> f64 {
20582058
source.into_iter().map(|row| row.element.point_domain.positions().len() as f64).sum()
20592059
}
20602060

2061+
#[node_macro::node(category("Vector"), path(graphene_core::vector))]
2062+
async fn index_points(_: impl Ctx, source: Table<Vector>, index: f64) -> DVec2 {
2063+
let points_count = source.iter().map(|row| row.element.point_domain.positions().len()).sum::<usize>();
2064+
2065+
// Clamp and allow negative indexing from the end
2066+
let index = index as isize;
2067+
let index = if index < 0 {
2068+
(points_count as isize + index).max(0) as usize
2069+
} else {
2070+
(index as usize).min(points_count - 1)
2071+
};
2072+
2073+
// Find the point at the given index across all vector elements
2074+
let mut accumulated = 0;
2075+
for row in source.iter() {
2076+
let row_point_count = row.element.point_domain.positions().len();
2077+
if index - accumulated < row_point_count {
2078+
return row.element.point_domain.positions()[index - accumulated];
2079+
}
2080+
accumulated += row_point_count;
2081+
}
2082+
2083+
DVec2::ZERO
2084+
}
2085+
20612086
#[node_macro::node(category("Vector: Measure"), path(core_types::vector))]
20622087
async fn path_length(_: impl Ctx, source: Table<Vector>) -> f64 {
20632088
source

0 commit comments

Comments
 (0)