diff --git a/editor/src/messages/portfolio/document_migration.rs b/editor/src/messages/portfolio/document_migration.rs index 7d9eac4b..a68547d7 100644 --- a/editor/src/messages/portfolio/document_migration.rs +++ b/editor/src/messages/portfolio/document_migration.rs @@ -969,6 +969,19 @@ 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); + + document.network_interface.add_import(TaggedValue::None, false, 0, "Primary", "", &[*node_id]); + document.network_interface.add_import(TaggedValue::U32(0), false, 1, "Loop Level", "TODO", &[*node_id]); + } + + // ================================== + // PUT ALL MIGRATIONS ABOVE THIS LINE + // ================================== + // Ensure layers are positioned as stacks if they are upstream siblings of another layer document.network_interface.load_structure(); let all_layers = LayerNodeIdentifier::ROOT_PARENT.descendants(document.network_interface.document_metadata()).collect::>(); diff --git a/node-graph/gcore/src/context.rs b/node-graph/gcore/src/context.rs index 4e8854c9..cd2f500f 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 @@ -91,7 +91,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()) } } @@ -122,7 +122,7 @@ impl ExtractAnimationTime for Arc { } } impl ExtractIndex for Arc { - fn try_index(&self) -> Option { + fn try_index(&self) -> Option> { (**self).try_index() } } @@ -170,8 +170,8 @@ impl ExtractTime for ContextImpl<'_> { } } impl ExtractIndex for ContextImpl<'_> { - fn try_index(&self) -> Option { - self.index + fn try_index(&self) -> Option> { + self.index.clone() } } impl ExtractVarArgs for ContextImpl<'_> { @@ -202,8 +202,8 @@ impl ExtractAnimationTime for OwnedContextImpl { } } impl ExtractIndex for OwnedContextImpl { - fn try_index(&self) -> Option { - self.index + fn try_index(&self) -> Option> { + self.index.clone() } } impl ExtractVarArgs for OwnedContextImpl { @@ -244,7 +244,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, } @@ -334,7 +334,11 @@ impl OwnedContextImpl { self } pub fn with_index(mut self, index: usize) -> Self { - self.index = Some(index); + if let Some(current_index) = &mut self.index { + current_index.push(index); + } else { + self.index = Some(vec![index]); + } self } pub fn into_context(self) -> Option> { @@ -346,12 +350,12 @@ impl OwnedContextImpl { } } -#[derive(Default, Clone, Copy, dyn_any::DynAny)] +#[derive(Default, Clone, dyn_any::DynAny)] pub struct ContextImpl<'a> { pub(crate) footprint: Option<&'a Footprint>, varargs: Option<&'a [DynRef<'a>]>, // This could be converted into a single enum to save extra bytes - index: Option, + index: Option>, time: Option, } @@ -363,6 +367,7 @@ 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 c980ece8..2dd23150 100644 --- a/node-graph/gcore/src/vector/algorithms/instance.rs +++ b/node-graph/gcore/src/vector/algorithms/instance.rs @@ -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)]