Add multi-level loop indexing with the 'Instance Repeat' node

This commit is contained in:
Keavon Chambers
2025-07-14 02:55:44 -07:00
parent be8378309d
commit 112efe88c2
3 changed files with 33 additions and 17 deletions

View File

@@ -88,12 +88,10 @@ async fn instance_position(ctx: impl Ctx + ExtractVarArgs) -> DVec2 {
// TODO: Make this return a u32 instead of an f64, but we ned to improve math-related compatibility with integer types first.
#[node_macro::node(category("Instancing"), path(graphene_core::vector))]
async fn instance_index(ctx: impl Ctx + ExtractIndex) -> f64 {
match ctx.try_index() {
Some(index) => return index as f64,
None => warn!("Extracted value of incorrect type"),
}
0.
async fn instance_index(ctx: impl Ctx + ExtractIndex, _primary: (), loop_level: u32) -> f64 {
ctx.try_index()
.and_then(|indexes| indexes.get(indexes.len().wrapping_sub(1).wrapping_sub(loop_level as usize)).copied())
.unwrap_or_default() as f64
}
#[cfg(test)]