Add the "Rate" multiplier parameter to the Animation Time node (#3685)
This commit is contained in:
parent
568831bd2f
commit
a88342b8da
|
|
@ -1632,6 +1632,20 @@ fn migrate_node(node_id: &NodeId, node: &DocumentNode, network_path: &[NodeId],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Upgrade the "Animation" node to add the "Rate" input
|
||||||
|
if reference == DefinitionIdentifier::ProtoNode(graphene_std::animation::animation_time::IDENTIFIER) && inputs_count < 2 {
|
||||||
|
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 _ = document.network_interface.replace_inputs(node_id, network_path, &mut node_template);
|
||||||
|
|
||||||
|
document
|
||||||
|
.network_interface
|
||||||
|
.set_input(&InputConnector::node(*node_id, 0), NodeInput::value(TaggedValue::None, false), network_path);
|
||||||
|
document
|
||||||
|
.network_interface
|
||||||
|
.set_input(&InputConnector::node(*node_id, 1), NodeInput::value(TaggedValue::F64(1.), false), network_path);
|
||||||
|
}
|
||||||
|
|
||||||
// Migrate from the old source/target "Morph" node to the new vector table based "Morph" node.
|
// Migrate from the old source/target "Morph" node to the new vector table based "Morph" node.
|
||||||
// This doesn't produce exactly equivalent results in cases involving input vector tables with multiple rows.
|
// This doesn't produce exactly equivalent results in cases involving input vector tables with multiple rows.
|
||||||
// The old version would zip the source and target table rows, interpoleating each pair together.
|
// The old version would zip the source and target table rows, interpoleating each pair together.
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,13 @@ fn real_time(
|
||||||
component: RealTimeMode,
|
component: RealTimeMode,
|
||||||
) -> f64 {
|
) -> f64 {
|
||||||
let real_time = ctx.try_real_time().unwrap_or_default();
|
let real_time = ctx.try_real_time().unwrap_or_default();
|
||||||
|
|
||||||
// TODO: Implement proper conversion using and existing time implementation
|
// TODO: Implement proper conversion using and existing time implementation
|
||||||
match component {
|
match component {
|
||||||
RealTimeMode::Utc => real_time,
|
RealTimeMode::Utc => real_time,
|
||||||
RealTimeMode::Year => (real_time / DAY / 365.25).floor() + 1970., // TODO: Factor in a chosen timezone
|
RealTimeMode::Year => (real_time / DAY / 365.25).floor() + 1970., // TODO: Factor in a chosen timezone
|
||||||
RealTimeMode::Hour => (real_time / 1000. / 3600.).floor() % 24., // TODO: Factor in a chosen timezone
|
RealTimeMode::Hour => (real_time / 1000. / 3600.).floor() % 24., // TODO: Factor in a chosen timezone
|
||||||
RealTimeMode::Minute => (real_time / 1000. / 60.).floor() % 60., // TODO: Factor in a chosen timezone
|
RealTimeMode::Minute => (real_time / 1000. / 60.).floor() % 60., // TODO: Factor in a chosen timezone
|
||||||
|
|
||||||
RealTimeMode::Second => (real_time / 1000.).floor() % 60.,
|
RealTimeMode::Second => (real_time / 1000.).floor() % 60.,
|
||||||
RealTimeMode::Millisecond => real_time % 1000.,
|
RealTimeMode::Millisecond => real_time % 1000.,
|
||||||
}
|
}
|
||||||
|
|
@ -44,8 +44,14 @@ fn real_time(
|
||||||
|
|
||||||
/// Produces the time, in seconds on the timeline, since the beginning of animation playback.
|
/// Produces the time, in seconds on the timeline, since the beginning of animation playback.
|
||||||
#[node_macro::node(category("Animation"))]
|
#[node_macro::node(category("Animation"))]
|
||||||
fn animation_time(ctx: impl Ctx + ExtractAnimationTime) -> f64 {
|
fn animation_time(
|
||||||
ctx.try_animation_time().unwrap_or_default()
|
ctx: impl Ctx + ExtractAnimationTime,
|
||||||
|
_primary: (),
|
||||||
|
#[default(1)]
|
||||||
|
#[unit("/sec")]
|
||||||
|
rate: f64,
|
||||||
|
) -> f64 {
|
||||||
|
ctx.try_animation_time().unwrap_or_default() * rate
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Produces the current position of the user's pointer within the document canvas.
|
/// Produces the current position of the user's pointer within the document canvas.
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ use vector_types::GradientStops;
|
||||||
/// This node associates the ID of the network's parent layer to every element of output data.
|
/// This node associates the ID of the network's parent layer to every element of output data.
|
||||||
/// This technical detail may be ignored by users, and will be phased out in the future.
|
/// This technical detail may be ignored by users, and will be phased out in the future.
|
||||||
#[node_macro::node(category(""))]
|
#[node_macro::node(category(""))]
|
||||||
pub async fn source_node_id<I: 'n + Send + Clone>(
|
pub async fn source_node_id<T: 'n + Send + Clone>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Table<Artboard>,
|
Table<Artboard>,
|
||||||
|
|
@ -24,9 +24,9 @@ pub async fn source_node_id<I: 'n + Send + Clone>(
|
||||||
Table<Color>,
|
Table<Color>,
|
||||||
Table<GradientStops>,
|
Table<GradientStops>,
|
||||||
)]
|
)]
|
||||||
content: Table<I>,
|
content: Table<T>,
|
||||||
node_path: Vec<NodeId>,
|
node_path: Vec<NodeId>,
|
||||||
) -> Table<I> {
|
) -> Table<T> {
|
||||||
// Get the penultimate element of the node path, or None if the path is too short
|
// Get the penultimate element of the node path, or None if the path is too short
|
||||||
// This is used to get the ID of the user-facing parent layer node (whose network contains this internal node).
|
// This is used to get the ID of the user-facing parent layer node (whose network contains this internal node).
|
||||||
let source_node_id = node_path.get(node_path.len().wrapping_sub(2)).copied();
|
let source_node_id = node_path.get(node_path.len().wrapping_sub(2)).copied();
|
||||||
|
|
@ -41,16 +41,16 @@ pub async fn source_node_id<I: 'n + Send + Clone>(
|
||||||
|
|
||||||
/// Joins two tables of the same type, extending the base table with the rows of the new table.
|
/// Joins two tables of the same type, extending the base table with the rows of the new table.
|
||||||
#[node_macro::node(category("General"))]
|
#[node_macro::node(category("General"))]
|
||||||
pub async fn extend<I: 'n + Send + Clone>(
|
pub async fn extend<T: 'n + Send + Clone>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
/// The table whose rows will appear at the start of the extended table.
|
/// The table whose rows will appear at the start of the extended table.
|
||||||
#[implementations(Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>, Table<Color>, Table<GradientStops>)]
|
#[implementations(Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>, Table<Color>, Table<GradientStops>)]
|
||||||
base: Table<I>,
|
base: Table<T>,
|
||||||
/// The table whose rows will appear at the end of the extended table.
|
/// The table whose rows will appear at the end of the extended table.
|
||||||
#[expose]
|
#[expose]
|
||||||
#[implementations(Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>, Table<Color>, Table<GradientStops>)]
|
#[implementations(Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>, Table<Color>, Table<GradientStops>)]
|
||||||
new: Table<I>,
|
new: Table<T>,
|
||||||
) -> Table<I> {
|
) -> Table<T> {
|
||||||
let mut base = base;
|
let mut base = base;
|
||||||
base.extend(new);
|
base.extend(new);
|
||||||
|
|
||||||
|
|
@ -61,14 +61,14 @@ pub async fn extend<I: 'n + Send + Clone>(
|
||||||
/// Performs an obsolete function as part of a migration from an older document format.
|
/// Performs an obsolete function as part of a migration from an older document format.
|
||||||
/// Users are advised to delete this node and replace it with a new one.
|
/// Users are advised to delete this node and replace it with a new one.
|
||||||
#[node_macro::node(category(""))]
|
#[node_macro::node(category(""))]
|
||||||
pub async fn legacy_layer_extend<I: 'n + Send + Clone>(
|
pub async fn legacy_layer_extend<T: 'n + Send + Clone>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>, Table<Color>, Table<GradientStops>)] base: Table<I>,
|
#[implementations(Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>, Table<Color>, Table<GradientStops>)] base: Table<T>,
|
||||||
#[expose]
|
#[expose]
|
||||||
#[implementations(Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>, Table<Color>, Table<GradientStops>)]
|
#[implementations(Table<Artboard>, Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>, Table<Color>, Table<GradientStops>)]
|
||||||
new: Table<I>,
|
new: Table<T>,
|
||||||
nested_node_path: Vec<NodeId>,
|
nested_node_path: Vec<NodeId>,
|
||||||
) -> Table<I> {
|
) -> Table<T> {
|
||||||
// Get the penultimate element of the node path, or None if the path is too short
|
// Get the penultimate element of the node path, or None if the path is too short
|
||||||
// This is used to get the ID of the user-facing parent layer-style node (which encapsulates this internal node).
|
// This is used to get the ID of the user-facing parent layer-style node (which encapsulates this internal node).
|
||||||
let source_node_id = nested_node_path.get(nested_node_path.len().wrapping_sub(2)).copied();
|
let source_node_id = nested_node_path.get(nested_node_path.len().wrapping_sub(2)).copied();
|
||||||
|
|
|
||||||
|
|
@ -1226,9 +1226,16 @@ async fn instance_map(ctx: impl Ctx + CloneVarArgs + ExtractAll, content: Table<
|
||||||
}
|
}
|
||||||
|
|
||||||
#[node_macro::node(category("Vector"), path(graphene_core::vector))]
|
#[node_macro::node(category("Vector"), path(graphene_core::vector))]
|
||||||
async fn flatten_path<I: 'n + Send>(_: impl Ctx, #[implementations(Table<Graphic>, Table<Vector>)] content: Table<I>) -> Table<Vector>
|
async fn flatten_path<T: 'n + Send>(
|
||||||
|
_: impl Ctx,
|
||||||
|
#[implementations(
|
||||||
|
Table<Graphic>,
|
||||||
|
Table<Vector>,
|
||||||
|
)]
|
||||||
|
content: Table<T>,
|
||||||
|
) -> Table<Vector>
|
||||||
where
|
where
|
||||||
Graphic: From<Table<I>>,
|
Graphic: From<Table<T>>,
|
||||||
{
|
{
|
||||||
// NOTE(AdamGerhant):
|
// NOTE(AdamGerhant):
|
||||||
// A node-based solution to support passing through vector data could be a network node with a cache node
|
// A node-based solution to support passing through vector data could be a network node with a cache node
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue