From 6f3ab3eaf69a143b0447173588cdefd8d3badc17 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Sat, 13 Sep 2025 10:34:48 +0200 Subject: [PATCH] Revert "Add multi-level loop indexing with the 'Instance Repeat' node" This reverts commit 112efe88c2002485ebb6b113862d6724cfa3e87b. --- .../messages/portfolio/document_migration.rs | 12 -------- node-graph/gcore/src/context.rs | 28 ++++++++----------- .../gcore/src/vector/algorithms/instance.rs | 10 ++++--- 3 files changed, 18 insertions(+), 32 deletions(-) diff --git a/editor/src/messages/portfolio/document_migration.rs b/editor/src/messages/portfolio/document_migration.rs index 27892fa411..cdbe6b4cec 100644 --- a/editor/src/messages/portfolio/document_migration.rs +++ b/editor/src/messages/portfolio/document_migration.rs @@ -1040,18 +1040,6 @@ fn migrate_node(node_id: &NodeId, node: &DocumentNode, network_path: &[NodeId], } } - // Add the "Depth" parameter to the "Instance Index" node - if reference == "Instance Index" && inputs_count == 0 { - let mut node_template = resolve_document_node_type(reference)?.default_node_template(); - document.network_interface.replace_implementation(node_id, network_path, &mut node_template); - - let mut node_path = network_path.to_vec(); - node_path.push(*node_id); - - document.network_interface.add_import(TaggedValue::None, false, 0, "Primary", "", &node_path); - document.network_interface.add_import(TaggedValue::U32(0), false, 1, "Loop Level", "TODO", &node_path); - } - // Migrate the Transform node to use degrees instead of radians if reference == "Transform" && node.inputs.get(6).is_none() { // Migrate rotation from radians to degrees diff --git a/node-graph/gcore/src/context.rs b/node-graph/gcore/src/context.rs index bbe1c243e2..dedfe705e7 100644 --- a/node-graph/gcore/src/context.rs +++ b/node-graph/gcore/src/context.rs @@ -27,7 +27,7 @@ pub trait ExtractAnimationTime { } pub trait ExtractIndex { - fn try_index(&self) -> Option>; + fn try_index(&self) -> Option; } // Consider returning a slice or something like that @@ -175,7 +175,7 @@ impl ExtractAnimationTime for Option { } } impl ExtractIndex for Option { - fn try_index(&self) -> Option> { + fn try_index(&self) -> Option { self.as_ref().and_then(|x| x.try_index()) } } @@ -212,7 +212,7 @@ impl ExtractAnimationTime for Arc { } } impl ExtractIndex for Arc { - fn try_index(&self) -> Option> { + fn try_index(&self) -> Option { (**self).try_index() } } @@ -268,8 +268,8 @@ impl ExtractRealTime for ContextImpl<'_> { } } impl ExtractIndex for ContextImpl<'_> { - fn try_index(&self) -> Option> { - self.index.clone() + fn try_index(&self) -> Option { + self.index } } impl ExtractVarArgs for ContextImpl<'_> { @@ -304,8 +304,8 @@ impl ExtractAnimationTime for OwnedContextImpl { } } impl ExtractIndex for OwnedContextImpl { - fn try_index(&self) -> Option> { - self.index.clone() + fn try_index(&self) -> Option { + self.index } } impl ExtractVarArgs for OwnedContextImpl { @@ -360,7 +360,7 @@ pub struct OwnedContextImpl { varargs: Option>, parent: Option>, // This could be converted into a single enum to save extra bytes - index: Option>, + index: Option, real_time: Option, animation_time: Option, } @@ -481,11 +481,7 @@ impl OwnedContextImpl { self } pub fn with_index(mut self, index: usize) -> Self { - if let Some(current_index) = &mut self.index { - current_index.push(index); - } else { - self.index = Some(vec![index]); - } + self.index = Some(index); self } pub fn into_context(self) -> Option> { @@ -497,11 +493,12 @@ impl OwnedContextImpl { } } -#[derive(Default, Clone, dyn_any::DynAny)] +#[derive(Default, Clone, Copy, dyn_any::DynAny)] pub struct ContextImpl<'a> { pub(crate) footprint: Option<&'a Footprint>, varargs: Option<&'a [DynRef<'a>]>, - index: Option>, // This could be converted into a single enum to save extra bytes + // This could be converted into a single enum to save extra bytes + index: Option, real_time: Option, } @@ -513,7 +510,6 @@ impl<'a> ContextImpl<'a> { ContextImpl { footprint: Some(new_footprint), varargs: varargs.map(|x| x.borrow()), - index: self.index.clone(), ..*self } } diff --git a/node-graph/gcore/src/vector/algorithms/instance.rs b/node-graph/gcore/src/vector/algorithms/instance.rs index b5586203bf..aaf33659dd 100644 --- a/node-graph/gcore/src/vector/algorithms/instance.rs +++ b/node-graph/gcore/src/vector/algorithms/instance.rs @@ -105,10 +105,12 @@ 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, _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 +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. } #[cfg(test)]