From efdd943f39efac3e844482870c0afcfbb43679be Mon Sep 17 00:00:00 2001 From: Luigi Rosso Date: Tue, 13 Jul 2021 17:41:43 -0700 Subject: [PATCH] Ran generator for constraints. --- example/lib/main.dart | 4 +- lib/rive.dart | 4 +- lib/src/core/core.dart | 15 +- .../constraints/constraint_base.dart | 44 +++ .../constraints/ik_constraint_base.dart | 80 +++++ .../constraints/targeted_constraint_base.dart | 50 ++++ lib/src/generated/rive_core_context.dart | 132 ++++++--- lib/src/rive.dart | 6 +- lib/src/rive_core/animation/animation.dart | 2 +- .../rive_core/animation/animation_state.dart | 3 +- lib/src/rive_core/animation/any_state.dart | 3 +- .../rive_core/animation/blend_animation.dart | 5 +- .../animation/blend_animation_direct.dart | 3 +- lib/src/rive_core/animation/blend_state.dart | 3 +- .../rive_core/animation/blend_state_1d.dart | 3 +- .../animation/blend_state_direct.dart | 2 +- .../animation/blend_state_instance.dart | 2 +- .../animation/blend_state_transition.dart | 3 +- .../animation/cubic_interpolator.dart | 2 +- lib/src/rive_core/animation/entry_state.dart | 3 +- lib/src/rive_core/animation/exit_state.dart | 3 +- lib/src/rive_core/animation/keyed_object.dart | 3 +- .../rive_core/animation/keyed_property.dart | 2 +- lib/src/rive_core/animation/keyframe.dart | 3 +- lib/src/rive_core/animation/layer_state.dart | 3 +- .../rive_core/animation/linear_animation.dart | 3 +- .../rive_core/animation/state_machine.dart | 3 +- .../animation/state_machine_component.dart | 3 +- .../animation/state_machine_input.dart | 3 +- .../animation/state_machine_layer.dart | 5 +- .../rive_core/animation/state_transition.dart | 3 +- .../animation/transition_bool_condition.dart | 4 +- .../animation/transition_condition.dart | 3 +- .../transition_number_condition.dart | 3 +- .../transition_trigger_condition.dart | 3 +- .../animation/transition_value_condition.dart | 3 +- lib/src/rive_core/artboard.dart | 22 +- lib/src/rive_core/bones/bone.dart | 11 + lib/src/rive_core/bones/cubic_weight.dart | 3 +- lib/src/rive_core/bones/skin.dart | 2 +- lib/src/rive_core/bones/tendon.dart | 3 +- lib/src/rive_core/bones/weight.dart | 3 +- lib/src/rive_core/component.dart | 19 +- lib/src/rive_core/constraints/constraint.dart | 26 ++ .../rive_core/constraints/ik_constraint.dart | 275 ++++++++++++++++++ .../constraints/targeted_constraint.dart | 36 +++ lib/src/rive_core/container_component.dart | 2 +- lib/src/rive_core/draw_rules.dart | 3 +- lib/src/rive_core/draw_target.dart | 3 +- lib/src/rive_core/drawable.dart | 3 +- lib/src/rive_core/node.dart | 3 +- lib/src/rive_core/shapes/clipping_shape.dart | 3 +- .../shapes/cubic_asymmetric_vertex.dart | 3 +- .../shapes/cubic_detached_vertex.dart | 3 +- .../shapes/cubic_mirrored_vertex.dart | 3 +- lib/src/rive_core/shapes/cubic_vertex.dart | 3 +- lib/src/rive_core/shapes/ellipse.dart | 2 +- lib/src/rive_core/shapes/paint/fill.dart | 3 +- .../rive_core/shapes/paint/gradient_stop.dart | 2 +- .../shapes/paint/linear_gradient.dart | 3 +- .../rive_core/shapes/paint/shape_paint.dart | 3 +- .../rive_core/shapes/paint/solid_color.dart | 3 +- lib/src/rive_core/shapes/paint/stroke.dart | 3 +- lib/src/rive_core/shapes/paint/trim_path.dart | 2 +- lib/src/rive_core/shapes/parametric_path.dart | 3 +- lib/src/rive_core/shapes/path.dart | 3 +- lib/src/rive_core/shapes/path_vertex.dart | 3 +- lib/src/rive_core/shapes/points_path.dart | 2 +- lib/src/rive_core/shapes/polygon.dart | 7 +- lib/src/rive_core/shapes/rectangle.dart | 3 +- lib/src/rive_core/shapes/shape.dart | 5 +- .../shapes/shape_paint_container.dart | 4 +- lib/src/rive_core/shapes/star.dart | 3 +- lib/src/rive_core/shapes/straight_vertex.dart | 3 +- lib/src/rive_core/shapes/triangle.dart | 2 +- .../rive_core/state_machine_controller.dart | 2 +- lib/src/rive_core/transform_component.dart | 24 +- lib/src/runtime_artboard.dart | 2 +- 78 files changed, 803 insertions(+), 132 deletions(-) create mode 100644 lib/src/generated/constraints/constraint_base.dart create mode 100644 lib/src/generated/constraints/ik_constraint_base.dart create mode 100644 lib/src/generated/constraints/targeted_constraint_base.dart create mode 100644 lib/src/rive_core/constraints/constraint.dart create mode 100644 lib/src/rive_core/constraints/ik_constraint.dart create mode 100644 lib/src/rive_core/constraints/targeted_constraint.dart diff --git a/example/lib/main.dart b/example/lib/main.dart index 9895c30..eeb8dd9 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; import 'package:rive_example/custom_controller.dart'; -import 'package:rive_example/play_one_shot_animation.dart'; -import 'package:rive_example/play_pause_animation.dart'; import 'package:rive_example/example_state_machine.dart'; import 'package:rive_example/liquid_download.dart'; import 'package:rive_example/little_machine.dart'; +import 'package:rive_example/play_one_shot_animation.dart'; +import 'package:rive_example/play_pause_animation.dart'; import 'package:rive_example/simple_animation.dart'; import 'package:rive_example/simple_state_machine.dart'; import 'package:rive_example/state_machine_skills.dart'; diff --git a/lib/rive.dart b/lib/rive.dart index 2fd9fa1..d800373 100644 --- a/lib/rive.dart +++ b/lib/rive.dart @@ -1,7 +1,8 @@ library rive; -export 'package:rive/src/controllers/simple_controller.dart'; export 'package:rive/src/controllers/one_shot_controller.dart'; +export 'package:rive/src/controllers/simple_controller.dart'; +export 'package:rive/src/controllers/state_machine_controller.dart'; export 'package:rive/src/extensions.dart'; export 'package:rive/src/extensions.dart'; export 'package:rive/src/rive.dart'; @@ -21,5 +22,4 @@ export 'package:rive/src/rive_core/shapes/paint/stroke.dart'; export 'package:rive/src/rive_core/shapes/shape.dart'; export 'package:rive/src/rive_file.dart'; export 'package:rive/src/runtime_artboard.dart'; -export 'package:rive/src/controllers/state_machine_controller.dart'; export 'package:rive/src/widgets/rive_animation.dart'; diff --git a/lib/src/core/core.dart b/lib/src/core/core.dart index bac4a1b..1cb62bc 100644 --- a/lib/src/core/core.dart +++ b/lib/src/core/core.dart @@ -2,22 +2,23 @@ import 'dart:collection'; import 'package:flutter/foundation.dart'; import 'package:rive/src/rive_core/runtime/exceptions/rive_format_error_exception.dart'; + export 'package:rive/src/animation_list.dart'; -export 'package:rive/src/state_machine_components.dart'; export 'package:rive/src/blend_animations.dart'; -export 'package:rive/src/state_transition_conditions.dart'; -export 'package:rive/src/state_transitions.dart'; export 'package:rive/src/container_children.dart'; -export 'package:rive/src/runtime_artboard.dart'; -export 'package:rive/src/generated/rive_core_context.dart'; export 'package:rive/src/core/importers/artboard_importer.dart'; -export 'package:rive/src/core/importers/linear_animation_importer.dart'; export 'package:rive/src/core/importers/keyed_object_importer.dart'; export 'package:rive/src/core/importers/keyed_property_importer.dart'; +export 'package:rive/src/core/importers/layer_state_importer.dart'; +export 'package:rive/src/core/importers/linear_animation_importer.dart'; export 'package:rive/src/core/importers/state_machine_importer.dart'; export 'package:rive/src/core/importers/state_machine_layer_importer.dart'; -export 'package:rive/src/core/importers/layer_state_importer.dart'; export 'package:rive/src/core/importers/state_transition_importer.dart'; +export 'package:rive/src/generated/rive_core_context.dart'; +export 'package:rive/src/runtime_artboard.dart'; +export 'package:rive/src/state_machine_components.dart'; +export 'package:rive/src/state_transition_conditions.dart'; +export 'package:rive/src/state_transitions.dart'; typedef PropertyChangeCallback = void Function(dynamic from, dynamic to); typedef BatchAddCallback = void Function(); diff --git a/lib/src/generated/constraints/constraint_base.dart b/lib/src/generated/constraints/constraint_base.dart new file mode 100644 index 0000000..bec92f1 --- /dev/null +++ b/lib/src/generated/constraints/constraint_base.dart @@ -0,0 +1,44 @@ +/// Core automatically generated +/// lib/src/generated/constraints/constraint_base.dart. +/// Do not modify manually. + +import 'package:rive/src/generated/component_base.dart'; +import 'package:rive/src/rive_core/component.dart'; + +abstract class ConstraintBase extends Component { + static const int typeKey = 79; + @override + int get coreType => ConstraintBase.typeKey; + @override + Set get coreTypes => {ConstraintBase.typeKey, ComponentBase.typeKey}; + + /// -------------------------------------------------------------------------- + /// Strength field with key 172. + static const double strengthInitialValue = 1.0; + double _strength = strengthInitialValue; + static const int strengthPropertyKey = 172; + + /// Strength of the constraint. 0 means off. 1 means fully constraining. + double get strength => _strength; + + /// Change the [_strength] field value. + /// [strengthChanged] will be invoked only if the field's value has changed. + set strength(double value) { + if (_strength == value) { + return; + } + double from = _strength; + _strength = value; + if (hasValidated) { + strengthChanged(from, value); + } + } + + void strengthChanged(double from, double to); + + @override + void copy(ConstraintBase source) { + super.copy(source); + _strength = source._strength; + } +} diff --git a/lib/src/generated/constraints/ik_constraint_base.dart b/lib/src/generated/constraints/ik_constraint_base.dart new file mode 100644 index 0000000..bbe7192 --- /dev/null +++ b/lib/src/generated/constraints/ik_constraint_base.dart @@ -0,0 +1,80 @@ +/// Core automatically generated +/// lib/src/generated/constraints/ik_constraint_base.dart. +/// Do not modify manually. + +import 'package:rive/src/generated/component_base.dart'; +import 'package:rive/src/generated/constraints/constraint_base.dart'; +import 'package:rive/src/generated/constraints/targeted_constraint_base.dart'; +import 'package:rive/src/rive_core/constraints/targeted_constraint.dart'; + +abstract class IKConstraintBase extends TargetedConstraint { + static const int typeKey = 81; + @override + int get coreType => IKConstraintBase.typeKey; + @override + Set get coreTypes => { + IKConstraintBase.typeKey, + TargetedConstraintBase.typeKey, + ConstraintBase.typeKey, + ComponentBase.typeKey + }; + + /// -------------------------------------------------------------------------- + /// InvertDirection field with key 174. + static const bool invertDirectionInitialValue = false; + bool _invertDirection = invertDirectionInitialValue; + static const int invertDirectionPropertyKey = 174; + + /// True when the direction taken towards the target should be inverted from + /// the default. + bool get invertDirection => _invertDirection; + + /// Change the [_invertDirection] field value. + /// [invertDirectionChanged] will be invoked only if the field's value has + /// changed. + set invertDirection(bool value) { + if (_invertDirection == value) { + return; + } + bool from = _invertDirection; + _invertDirection = value; + if (hasValidated) { + invertDirectionChanged(from, value); + } + } + + void invertDirectionChanged(bool from, bool to); + + /// -------------------------------------------------------------------------- + /// ParentBoneCount field with key 175. + static const int parentBoneCountInitialValue = 0; + int _parentBoneCount = parentBoneCountInitialValue; + static const int parentBoneCountPropertyKey = 175; + + /// The number of bones above this one that are influenced by this IK + /// constraint. + int get parentBoneCount => _parentBoneCount; + + /// Change the [_parentBoneCount] field value. + /// [parentBoneCountChanged] will be invoked only if the field's value has + /// changed. + set parentBoneCount(int value) { + if (_parentBoneCount == value) { + return; + } + int from = _parentBoneCount; + _parentBoneCount = value; + if (hasValidated) { + parentBoneCountChanged(from, value); + } + } + + void parentBoneCountChanged(int from, int to); + + @override + void copy(IKConstraintBase source) { + super.copy(source); + _invertDirection = source._invertDirection; + _parentBoneCount = source._parentBoneCount; + } +} diff --git a/lib/src/generated/constraints/targeted_constraint_base.dart b/lib/src/generated/constraints/targeted_constraint_base.dart new file mode 100644 index 0000000..e976c2c --- /dev/null +++ b/lib/src/generated/constraints/targeted_constraint_base.dart @@ -0,0 +1,50 @@ +/// Core automatically generated +/// lib/src/generated/constraints/targeted_constraint_base.dart. +/// Do not modify manually. + +import 'package:rive/src/generated/component_base.dart'; +import 'package:rive/src/generated/constraints/constraint_base.dart'; +import 'package:rive/src/rive_core/constraints/constraint.dart'; + +abstract class TargetedConstraintBase extends Constraint { + static const int typeKey = 80; + @override + int get coreType => TargetedConstraintBase.typeKey; + @override + Set get coreTypes => { + TargetedConstraintBase.typeKey, + ConstraintBase.typeKey, + ComponentBase.typeKey + }; + + /// -------------------------------------------------------------------------- + /// TargetId field with key 173. + static const int targetIdInitialValue = -1; + int _targetId = targetIdInitialValue; + static const int targetIdPropertyKey = 173; + + /// Identifier used to track the TransformComponent used as the target for the + /// constraint. + int get targetId => _targetId; + + /// Change the [_targetId] field value. + /// [targetIdChanged] will be invoked only if the field's value has changed. + set targetId(int value) { + if (_targetId == value) { + return; + } + int from = _targetId; + _targetId = value; + if (hasValidated) { + targetIdChanged(from, value); + } + } + + void targetIdChanged(int from, int to); + + @override + void copy(TargetedConstraintBase source) { + super.copy(source); + _targetId = source._targetId; + } +} diff --git a/lib/src/generated/rive_core_context.dart b/lib/src/generated/rive_core_context.dart index 7645d98..201fa46 100644 --- a/lib/src/generated/rive_core_context.dart +++ b/lib/src/generated/rive_core_context.dart @@ -45,6 +45,9 @@ import 'package:rive/src/generated/bones/skin_base.dart'; import 'package:rive/src/generated/bones/tendon_base.dart'; import 'package:rive/src/generated/bones/weight_base.dart'; import 'package:rive/src/generated/component_base.dart'; +import 'package:rive/src/generated/constraints/constraint_base.dart'; +import 'package:rive/src/generated/constraints/ik_constraint_base.dart'; +import 'package:rive/src/generated/constraints/targeted_constraint_base.dart'; import 'package:rive/src/generated/draw_rules_base.dart'; import 'package:rive/src/generated/draw_target_base.dart'; import 'package:rive/src/generated/drawable_base.dart'; @@ -107,6 +110,7 @@ import 'package:rive/src/rive_core/bones/root_bone.dart'; import 'package:rive/src/rive_core/bones/skin.dart'; import 'package:rive/src/rive_core/bones/tendon.dart'; import 'package:rive/src/rive_core/bones/weight.dart'; +import 'package:rive/src/rive_core/constraints/ik_constraint.dart'; import 'package:rive/src/rive_core/draw_rules.dart'; import 'package:rive/src/rive_core/draw_target.dart'; import 'package:rive/src/rive_core/node.dart'; @@ -136,6 +140,8 @@ class RiveCoreContext { switch (typeKey) { case DrawTargetBase.typeKey: return DrawTarget(); + case IKConstraintBase.typeKey: + return IKConstraint(); case AnimationStateBase.typeKey: return AnimationState(); case KeyedObjectBase.typeKey: @@ -273,6 +279,26 @@ class RiveCoreContext { object.placementValue = value; } break; + case ConstraintBase.strengthPropertyKey: + if (object is ConstraintBase && value is double) { + object.strength = value; + } + break; + case TargetedConstraintBase.targetIdPropertyKey: + if (object is TargetedConstraintBase && value is int) { + object.targetId = value; + } + break; + case IKConstraintBase.invertDirectionPropertyKey: + if (object is IKConstraintBase && value is bool) { + object.invertDirection = value; + } + break; + case IKConstraintBase.parentBoneCountPropertyKey: + if (object is IKConstraintBase && value is int) { + object.parentBoneCount = value; + } + break; case AnimationStateBase.animationIdPropertyKey: if (object is AnimationStateBase && value is int) { object.animationId = value; @@ -879,8 +905,8 @@ class RiveCoreContext { static CoreFieldType stringType = CoreStringType(); static CoreFieldType uintType = CoreUintType(); static CoreFieldType doubleType = CoreDoubleType(); - static CoreFieldType colorType = CoreColorType(); static CoreFieldType boolType = CoreBoolType(); + static CoreFieldType colorType = CoreColorType(); static CoreFieldType? coreType(int propertyKey) { switch (propertyKey) { case ComponentBase.namePropertyKey: @@ -890,6 +916,8 @@ class RiveCoreContext { case ComponentBase.parentIdPropertyKey: case DrawTargetBase.drawableIdPropertyKey: case DrawTargetBase.placementValuePropertyKey: + case TargetedConstraintBase.targetIdPropertyKey: + case IKConstraintBase.parentBoneCountPropertyKey: case AnimationStateBase.animationIdPropertyKey: case KeyedObjectBase.objectIdPropertyKey: case BlendAnimationBase.animationIdPropertyKey: @@ -931,6 +959,7 @@ class RiveCoreContext { case DrawRulesBase.drawTargetIdPropertyKey: case TendonBase.boneIdPropertyKey: return uintType; + case ConstraintBase.strengthPropertyKey: case StateMachineNumberBase.valuePropertyKey: case TransitionNumberConditionBase.valuePropertyKey: case CubicInterpolatorBase.x1PropertyKey: @@ -1000,10 +1029,7 @@ class RiveCoreContext { case TendonBase.txPropertyKey: case TendonBase.tyPropertyKey: return doubleType; - case KeyFrameColorBase.valuePropertyKey: - case SolidColorBase.colorValuePropertyKey: - case GradientStopBase.colorValuePropertyKey: - return colorType; + case IKConstraintBase.invertDirectionPropertyKey: case LinearAnimationBase.enableWorkAreaPropertyKey: case StateMachineBoolBase.valuePropertyKey: case ShapePaintBase.isVisiblePropertyKey: @@ -1012,6 +1038,10 @@ class RiveCoreContext { case RectangleBase.linkCornerRadiusPropertyKey: case ClippingShapeBase.isVisiblePropertyKey: return boolType; + case KeyFrameColorBase.valuePropertyKey: + case SolidColorBase.colorValuePropertyKey: + case GradientStopBase.colorValuePropertyKey: + return colorType; default: return null; } @@ -1037,6 +1067,10 @@ class RiveCoreContext { return (object as DrawTargetBase).drawableId; case DrawTargetBase.placementValuePropertyKey: return (object as DrawTargetBase).placementValue; + case TargetedConstraintBase.targetIdPropertyKey: + return (object as TargetedConstraintBase).targetId; + case IKConstraintBase.parentBoneCountPropertyKey: + return (object as IKConstraintBase).parentBoneCount; case AnimationStateBase.animationIdPropertyKey: return (object as AnimationStateBase).animationId; case KeyedObjectBase.objectIdPropertyKey: @@ -1123,6 +1157,8 @@ class RiveCoreContext { static double getDouble(Core object, int propertyKey) { switch (propertyKey) { + case ConstraintBase.strengthPropertyKey: + return (object as ConstraintBase).strength; case StateMachineNumberBase.valuePropertyKey: return (object as StateMachineNumberBase).value; case TransitionNumberConditionBase.valuePropertyKey: @@ -1263,20 +1299,10 @@ class RiveCoreContext { return 0.0; } - static int getColor(Core object, int propertyKey) { - switch (propertyKey) { - case KeyFrameColorBase.valuePropertyKey: - return (object as KeyFrameColorBase).value; - case SolidColorBase.colorValuePropertyKey: - return (object as SolidColorBase).colorValue; - case GradientStopBase.colorValuePropertyKey: - return (object as GradientStopBase).colorValue; - } - return 0; - } - static bool getBool(Core object, int propertyKey) { switch (propertyKey) { + case IKConstraintBase.invertDirectionPropertyKey: + return (object as IKConstraintBase).invertDirection; case LinearAnimationBase.enableWorkAreaPropertyKey: return (object as LinearAnimationBase).enableWorkArea; case StateMachineBoolBase.valuePropertyKey: @@ -1295,6 +1321,18 @@ class RiveCoreContext { return false; } + static int getColor(Core object, int propertyKey) { + switch (propertyKey) { + case KeyFrameColorBase.valuePropertyKey: + return (object as KeyFrameColorBase).value; + case SolidColorBase.colorValuePropertyKey: + return (object as SolidColorBase).colorValue; + case GradientStopBase.colorValuePropertyKey: + return (object as GradientStopBase).colorValue; + } + return 0; + } + static void setString(Core object, int propertyKey, String value) { switch (propertyKey) { case ComponentBase.namePropertyKey: @@ -1332,6 +1370,16 @@ class RiveCoreContext { object.placementValue = value; } break; + case TargetedConstraintBase.targetIdPropertyKey: + if (object is TargetedConstraintBase) { + object.targetId = value; + } + break; + case IKConstraintBase.parentBoneCountPropertyKey: + if (object is IKConstraintBase) { + object.parentBoneCount = value; + } + break; case AnimationStateBase.animationIdPropertyKey: if (object is AnimationStateBase) { object.animationId = value; @@ -1537,6 +1585,11 @@ class RiveCoreContext { static void setDouble(Core object, int propertyKey, double value) { switch (propertyKey) { + case ConstraintBase.strengthPropertyKey: + if (object is ConstraintBase) { + object.strength = value; + } + break; case StateMachineNumberBase.valuePropertyKey: if (object is StateMachineNumberBase) { object.value = value; @@ -1880,28 +1933,13 @@ class RiveCoreContext { } } - static void setColor(Core object, int propertyKey, int value) { - switch (propertyKey) { - case KeyFrameColorBase.valuePropertyKey: - if (object is KeyFrameColorBase) { - object.value = value; - } - break; - case SolidColorBase.colorValuePropertyKey: - if (object is SolidColorBase) { - object.colorValue = value; - } - break; - case GradientStopBase.colorValuePropertyKey: - if (object is GradientStopBase) { - object.colorValue = value; - } - break; - } - } - static void setBool(Core object, int propertyKey, bool value) { switch (propertyKey) { + case IKConstraintBase.invertDirectionPropertyKey: + if (object is IKConstraintBase) { + object.invertDirection = value; + } + break; case LinearAnimationBase.enableWorkAreaPropertyKey: if (object is LinearAnimationBase) { object.enableWorkArea = value; @@ -1939,4 +1977,24 @@ class RiveCoreContext { break; } } + + static void setColor(Core object, int propertyKey, int value) { + switch (propertyKey) { + case KeyFrameColorBase.valuePropertyKey: + if (object is KeyFrameColorBase) { + object.value = value; + } + break; + case SolidColorBase.colorValuePropertyKey: + if (object is SolidColorBase) { + object.colorValue = value; + } + break; + case GradientStopBase.colorValuePropertyKey: + if (object is GradientStopBase) { + object.colorValue = value; + } + break; + } + } } diff --git a/lib/src/rive.dart b/lib/src/rive.dart index 99896ac..7d71ab4 100644 --- a/lib/src/rive.dart +++ b/lib/src/rive.dart @@ -93,7 +93,11 @@ class RiveRenderObject extends RiveRenderBox { markNeedsLayout(); } - void dispose() => _artboard.redraw.removeListener(scheduleRepaint); + @override + void dispose() { + super.dispose(); + _artboard.redraw.removeListener(scheduleRepaint); + } @override AABB get aabb { diff --git a/lib/src/rive_core/animation/animation.dart b/lib/src/rive_core/animation/animation.dart index 0fabb31..a56dbcb 100644 --- a/lib/src/rive_core/animation/animation.dart +++ b/lib/src/rive_core/animation/animation.dart @@ -1,7 +1,7 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/animation_base.dart'; import 'package:rive/src/rive_core/artboard.dart'; -import 'package:rive/src/generated/animation/animation_base.dart'; export 'package:rive/src/generated/animation/animation_base.dart'; class Animation extends AnimationBase { diff --git a/lib/src/rive_core/animation/animation_state.dart b/lib/src/rive_core/animation/animation_state.dart index f0805fa..e6d6303 100644 --- a/lib/src/rive_core/animation/animation_state.dart +++ b/lib/src/rive_core/animation/animation_state.dart @@ -1,9 +1,10 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/animation_state_base.dart'; import 'package:rive/src/rive_core/animation/animation_state_instance.dart'; import 'package:rive/src/rive_core/animation/linear_animation.dart'; import 'package:rive/src/rive_core/animation/state_instance.dart'; import 'package:rive/src/rive_core/artboard.dart'; -import 'package:rive/src/generated/animation/animation_state_base.dart'; + export 'package:rive/src/generated/animation/animation_state_base.dart'; class AnimationState extends AnimationStateBase { diff --git a/lib/src/rive_core/animation/any_state.dart b/lib/src/rive_core/animation/any_state.dart index d1d2376..19fb579 100644 --- a/lib/src/rive_core/animation/any_state.dart +++ b/lib/src/rive_core/animation/any_state.dart @@ -1,5 +1,6 @@ -import 'package:rive/src/rive_core/animation/state_instance.dart'; import 'package:rive/src/generated/animation/any_state_base.dart'; +import 'package:rive/src/rive_core/animation/state_instance.dart'; + export 'package:rive/src/generated/animation/any_state_base.dart'; class AnyState extends AnyStateBase { diff --git a/lib/src/rive_core/animation/blend_animation.dart b/lib/src/rive_core/animation/blend_animation.dart index 3b0fee1..786cf3b 100644 --- a/lib/src/rive_core/animation/blend_animation.dart +++ b/lib/src/rive_core/animation/blend_animation.dart @@ -1,9 +1,10 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/blend_animation_base.dart'; +import 'package:rive/src/generated/artboard_base.dart'; import 'package:rive/src/rive_core/animation/layer_state.dart'; import 'package:rive/src/rive_core/animation/linear_animation.dart'; import 'package:rive/src/rive_core/artboard.dart'; -import 'package:rive/src/generated/animation/blend_animation_base.dart'; -import 'package:rive/src/generated/artboard_base.dart'; + export 'package:rive/src/generated/animation/blend_animation_base.dart'; abstract class BlendAnimation extends BlendAnimationBase { diff --git a/lib/src/rive_core/animation/blend_animation_direct.dart b/lib/src/rive_core/animation/blend_animation_direct.dart index 8fe9e8e..6771a85 100644 --- a/lib/src/rive_core/animation/blend_animation_direct.dart +++ b/lib/src/rive_core/animation/blend_animation_direct.dart @@ -1,7 +1,8 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/blend_animation_direct_base.dart'; import 'package:rive/src/rive_core/animation/state_machine.dart'; import 'package:rive/src/rive_core/animation/state_machine_number.dart'; -import 'package:rive/src/generated/animation/blend_animation_direct_base.dart'; + export 'package:rive/src/generated/animation/blend_animation_direct_base.dart'; class BlendAnimationDirect extends BlendAnimationDirectBase { diff --git a/lib/src/rive_core/animation/blend_state.dart b/lib/src/rive_core/animation/blend_state.dart index 2fe958c..91d74cb 100644 --- a/lib/src/rive_core/animation/blend_state.dart +++ b/lib/src/rive_core/animation/blend_state.dart @@ -1,6 +1,7 @@ import 'package:rive/src/core/core.dart'; -import 'package:rive/src/rive_core/animation/blend_animation.dart'; import 'package:rive/src/generated/animation/blend_state_base.dart'; +import 'package:rive/src/rive_core/animation/blend_animation.dart'; + export 'package:rive/src/generated/animation/blend_state_base.dart'; // diff --git a/lib/src/rive_core/animation/blend_state_1d.dart b/lib/src/rive_core/animation/blend_state_1d.dart index 4ec0589..dce4a42 100644 --- a/lib/src/rive_core/animation/blend_state_1d.dart +++ b/lib/src/rive_core/animation/blend_state_1d.dart @@ -1,9 +1,10 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/blend_state_1d_base.dart'; import 'package:rive/src/rive_core/animation/blend_state_1d_instance.dart'; import 'package:rive/src/rive_core/animation/state_instance.dart'; import 'package:rive/src/rive_core/animation/state_machine.dart'; import 'package:rive/src/rive_core/animation/state_machine_number.dart'; -import 'package:rive/src/generated/animation/blend_state_1d_base.dart'; + export 'package:rive/src/generated/animation/blend_state_1d_base.dart'; class BlendState1D extends BlendState1DBase { diff --git a/lib/src/rive_core/animation/blend_state_direct.dart b/lib/src/rive_core/animation/blend_state_direct.dart index 07c2bdf..4abc4cf 100644 --- a/lib/src/rive_core/animation/blend_state_direct.dart +++ b/lib/src/rive_core/animation/blend_state_direct.dart @@ -1,6 +1,6 @@ +import 'package:rive/src/generated/animation/blend_state_direct_base.dart'; import 'package:rive/src/rive_core/animation/blend_state_direct_instance.dart'; import 'package:rive/src/rive_core/animation/state_instance.dart'; -import 'package:rive/src/generated/animation/blend_state_direct_base.dart'; export 'package:rive/src/generated/animation/blend_state_direct_base.dart'; diff --git a/lib/src/rive_core/animation/blend_state_instance.dart b/lib/src/rive_core/animation/blend_state_instance.dart index 6076f16..d25e594 100644 --- a/lib/src/rive_core/animation/blend_state_instance.dart +++ b/lib/src/rive_core/animation/blend_state_instance.dart @@ -1,7 +1,7 @@ import 'dart:collection'; -import 'package:rive/src/core/core.dart'; import 'package:flutter/foundation.dart'; +import 'package:rive/src/core/core.dart'; import 'package:rive/src/rive_core/animation/blend_animation.dart'; import 'package:rive/src/rive_core/animation/blend_state.dart'; import 'package:rive/src/rive_core/animation/linear_animation_instance.dart'; diff --git a/lib/src/rive_core/animation/blend_state_transition.dart b/lib/src/rive_core/animation/blend_state_transition.dart index 6b76d5c..d76c7d0 100644 --- a/lib/src/rive_core/animation/blend_state_transition.dart +++ b/lib/src/rive_core/animation/blend_state_transition.dart @@ -1,10 +1,11 @@ +import 'package:rive/src/generated/animation/blend_state_transition_base.dart'; import 'package:rive/src/rive_core/animation/blend_animation.dart'; import 'package:rive/src/rive_core/animation/blend_state_instance.dart'; import 'package:rive/src/rive_core/animation/layer_state.dart'; import 'package:rive/src/rive_core/animation/linear_animation.dart'; import 'package:rive/src/rive_core/animation/linear_animation_instance.dart'; import 'package:rive/src/rive_core/animation/state_instance.dart'; -import 'package:rive/src/generated/animation/blend_state_transition_base.dart'; + export 'package:rive/src/generated/animation/blend_state_transition_base.dart'; class BlendStateTransition extends BlendStateTransitionBase { diff --git a/lib/src/rive_core/animation/cubic_interpolator.dart b/lib/src/rive_core/animation/cubic_interpolator.dart index 8216745..0e69d9c 100644 --- a/lib/src/rive_core/animation/cubic_interpolator.dart +++ b/lib/src/rive_core/animation/cubic_interpolator.dart @@ -1,9 +1,9 @@ import 'dart:typed_data'; import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/cubic_interpolator_base.dart'; import 'package:rive/src/rive_core/animation/interpolator.dart'; import 'package:rive/src/rive_core/artboard.dart'; -import 'package:rive/src/generated/animation/cubic_interpolator_base.dart'; const int newtonIterations = 4; diff --git a/lib/src/rive_core/animation/entry_state.dart b/lib/src/rive_core/animation/entry_state.dart index d868ef3..ed64e4f 100644 --- a/lib/src/rive_core/animation/entry_state.dart +++ b/lib/src/rive_core/animation/entry_state.dart @@ -1,5 +1,6 @@ -import 'package:rive/src/rive_core/animation/state_instance.dart'; import 'package:rive/src/generated/animation/entry_state_base.dart'; +import 'package:rive/src/rive_core/animation/state_instance.dart'; + export 'package:rive/src/generated/animation/entry_state_base.dart'; class EntryState extends EntryStateBase { diff --git a/lib/src/rive_core/animation/exit_state.dart b/lib/src/rive_core/animation/exit_state.dart index fabdec2..5e65ef7 100644 --- a/lib/src/rive_core/animation/exit_state.dart +++ b/lib/src/rive_core/animation/exit_state.dart @@ -1,5 +1,6 @@ -import 'package:rive/src/rive_core/animation/state_instance.dart'; import 'package:rive/src/generated/animation/exit_state_base.dart'; +import 'package:rive/src/rive_core/animation/state_instance.dart'; + export 'package:rive/src/generated/animation/exit_state_base.dart'; class ExitState extends ExitStateBase { diff --git a/lib/src/rive_core/animation/keyed_object.dart b/lib/src/rive_core/animation/keyed_object.dart index 5778cf7..05cd148 100644 --- a/lib/src/rive_core/animation/keyed_object.dart +++ b/lib/src/rive_core/animation/keyed_object.dart @@ -1,11 +1,12 @@ import 'dart:collection'; import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/keyed_object_base.dart'; import 'package:rive/src/rive_core/animation/keyed_property.dart'; import 'package:rive/src/rive_core/component.dart'; -import 'package:rive/src/generated/animation/keyed_object_base.dart'; import 'linear_animation.dart'; + export 'package:rive/src/generated/animation/keyed_object_base.dart'; class KeyedObject extends KeyedObjectBase { diff --git a/lib/src/rive_core/animation/keyed_property.dart b/lib/src/rive_core/animation/keyed_property.dart index 13e3f07..ddc315c 100644 --- a/lib/src/rive_core/animation/keyed_property.dart +++ b/lib/src/rive_core/animation/keyed_property.dart @@ -1,8 +1,8 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/keyed_property_base.dart'; import 'package:rive/src/rive_core/animation/keyed_object.dart'; import 'package:rive/src/rive_core/animation/keyframe.dart'; -import 'package:rive/src/generated/animation/keyed_property_base.dart'; export 'package:rive/src/generated/animation/keyed_property_base.dart'; abstract class KeyFrameInterface { diff --git a/lib/src/rive_core/animation/keyframe.dart b/lib/src/rive_core/animation/keyframe.dart index 9d82a62..f777eb4 100644 --- a/lib/src/rive_core/animation/keyframe.dart +++ b/lib/src/rive_core/animation/keyframe.dart @@ -1,11 +1,10 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/keyframe_base.dart'; import 'package:rive/src/rive_core/animation/interpolator.dart'; import 'package:rive/src/rive_core/animation/keyed_property.dart'; import 'package:rive/src/rive_core/animation/keyframe_interpolation.dart'; import 'package:rive/src/rive_core/animation/linear_animation.dart'; -import 'package:rive/src/generated/animation/keyframe_base.dart'; - export 'package:rive/src/generated/animation/keyframe_base.dart'; abstract class KeyFrame extends KeyFrameBase diff --git a/lib/src/rive_core/animation/layer_state.dart b/lib/src/rive_core/animation/layer_state.dart index 7f3a1fb..af59609 100644 --- a/lib/src/rive_core/animation/layer_state.dart +++ b/lib/src/rive_core/animation/layer_state.dart @@ -1,8 +1,9 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/layer_state_base.dart'; import 'package:rive/src/rive_core/animation/state_instance.dart'; import 'package:rive/src/rive_core/animation/state_machine_layer.dart'; import 'package:rive/src/rive_core/animation/state_transition.dart'; -import 'package:rive/src/generated/animation/layer_state_base.dart'; + export 'package:rive/src/generated/animation/layer_state_base.dart'; abstract class LayerState extends LayerStateBase { diff --git a/lib/src/rive_core/animation/linear_animation.dart b/lib/src/rive_core/animation/linear_animation.dart index b774e5e..4593a24 100644 --- a/lib/src/rive_core/animation/linear_animation.dart +++ b/lib/src/rive_core/animation/linear_animation.dart @@ -1,10 +1,11 @@ import 'dart:collection'; import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/linear_animation_base.dart'; import 'package:rive/src/rive_core/animation/keyed_object.dart'; import 'package:rive/src/rive_core/animation/loop.dart'; import 'package:rive/src/rive_core/artboard.dart'; -import 'package:rive/src/generated/animation/linear_animation_base.dart'; + export 'package:rive/src/generated/animation/linear_animation_base.dart'; class LinearAnimation extends LinearAnimationBase { diff --git a/lib/src/rive_core/animation/state_machine.dart b/lib/src/rive_core/animation/state_machine.dart index 9fa71e4..208050b 100644 --- a/lib/src/rive_core/animation/state_machine.dart +++ b/lib/src/rive_core/animation/state_machine.dart @@ -1,8 +1,9 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/state_machine_base.dart'; import 'package:rive/src/rive_core/animation/state_machine_input.dart'; import 'package:rive/src/rive_core/animation/state_machine_layer.dart'; import 'package:rive/src/rive_core/artboard.dart'; -import 'package:rive/src/generated/animation/state_machine_base.dart'; + export 'package:rive/src/generated/animation/state_machine_base.dart'; class StateMachine extends StateMachineBase { diff --git a/lib/src/rive_core/animation/state_machine_component.dart b/lib/src/rive_core/animation/state_machine_component.dart index f98295d..b8a909e 100644 --- a/lib/src/rive_core/animation/state_machine_component.dart +++ b/lib/src/rive_core/animation/state_machine_component.dart @@ -1,8 +1,9 @@ import 'dart:collection'; import 'package:rive/src/core/core.dart'; -import 'package:rive/src/rive_core/animation/state_machine.dart'; import 'package:rive/src/generated/animation/state_machine_component_base.dart'; +import 'package:rive/src/rive_core/animation/state_machine.dart'; + export 'package:rive/src/generated/animation/state_machine_component_base.dart'; /// Implemented by state machine inputs and layers. diff --git a/lib/src/rive_core/animation/state_machine_input.dart b/lib/src/rive_core/animation/state_machine_input.dart index ef801d8..e25a051 100644 --- a/lib/src/rive_core/animation/state_machine_input.dart +++ b/lib/src/rive_core/animation/state_machine_input.dart @@ -1,8 +1,9 @@ import 'dart:collection'; +import 'package:rive/src/generated/animation/state_machine_input_base.dart'; import 'package:rive/src/rive_core/animation/state_machine.dart'; import 'package:rive/src/rive_core/animation/state_machine_component.dart'; -import 'package:rive/src/generated/animation/state_machine_input_base.dart'; + export 'package:rive/src/generated/animation/state_machine_input_base.dart'; abstract class StateMachineInput extends StateMachineInputBase { diff --git a/lib/src/rive_core/animation/state_machine_layer.dart b/lib/src/rive_core/animation/state_machine_layer.dart index c9f93b5..a4e0548 100644 --- a/lib/src/rive_core/animation/state_machine_layer.dart +++ b/lib/src/rive_core/animation/state_machine_layer.dart @@ -1,13 +1,14 @@ import 'dart:collection'; +import 'package:rive/src/generated/animation/any_state_base.dart'; +import 'package:rive/src/generated/animation/state_machine_layer_base.dart'; import 'package:rive/src/rive_core/animation/any_state.dart'; import 'package:rive/src/rive_core/animation/entry_state.dart'; import 'package:rive/src/rive_core/animation/exit_state.dart'; import 'package:rive/src/rive_core/animation/layer_state.dart'; import 'package:rive/src/rive_core/animation/state_machine.dart'; import 'package:rive/src/rive_core/animation/state_machine_component.dart'; -import 'package:rive/src/generated/animation/any_state_base.dart'; -import 'package:rive/src/generated/animation/state_machine_layer_base.dart'; + export 'package:rive/src/generated/animation/state_machine_layer_base.dart'; class StateMachineLayer extends StateMachineLayerBase { diff --git a/lib/src/rive_core/animation/state_transition.dart b/lib/src/rive_core/animation/state_transition.dart index 84775a7..13bfdff 100644 --- a/lib/src/rive_core/animation/state_transition.dart +++ b/lib/src/rive_core/animation/state_transition.dart @@ -1,6 +1,7 @@ import 'dart:collection'; import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/state_transition_base.dart'; import 'package:rive/src/rive_core/animation/animation_state.dart'; import 'package:rive/src/rive_core/animation/animation_state_instance.dart'; import 'package:rive/src/rive_core/animation/layer_state.dart'; @@ -10,8 +11,8 @@ import 'package:rive/src/rive_core/animation/loop.dart'; import 'package:rive/src/rive_core/animation/state_instance.dart'; import 'package:rive/src/rive_core/animation/transition_condition.dart'; import 'package:rive/src/rive_core/animation/transition_trigger_condition.dart'; -import 'package:rive/src/generated/animation/state_transition_base.dart'; import 'package:rive/src/rive_core/state_transition_flags.dart'; + export 'package:rive/src/generated/animation/state_transition_base.dart'; enum AllowTransition { no, waitingForExit, yes } diff --git a/lib/src/rive_core/animation/transition_bool_condition.dart b/lib/src/rive_core/animation/transition_bool_condition.dart index 5e58c47..eeef836 100644 --- a/lib/src/rive_core/animation/transition_bool_condition.dart +++ b/lib/src/rive_core/animation/transition_bool_condition.dart @@ -1,7 +1,9 @@ import 'dart:collection'; + +import 'package:rive/src/generated/animation/transition_bool_condition_base.dart'; import 'package:rive/src/rive_core/animation/state_machine_bool.dart'; import 'package:rive/src/rive_core/animation/transition_condition.dart'; -import 'package:rive/src/generated/animation/transition_bool_condition_base.dart'; + export 'package:rive/src/generated/animation/transition_bool_condition_base.dart'; class TransitionBoolCondition extends TransitionBoolConditionBase { diff --git a/lib/src/rive_core/animation/transition_condition.dart b/lib/src/rive_core/animation/transition_condition.dart index d5f8251..4902a2a 100644 --- a/lib/src/rive_core/animation/transition_condition.dart +++ b/lib/src/rive_core/animation/transition_condition.dart @@ -1,9 +1,10 @@ import 'dart:collection'; import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/animation/transition_condition_base.dart'; import 'package:rive/src/rive_core/animation/state_machine_input.dart'; import 'package:rive/src/rive_core/animation/state_transition.dart'; -import 'package:rive/src/generated/animation/transition_condition_base.dart'; + export 'package:rive/src/generated/animation/transition_condition_base.dart'; enum TransitionConditionOp { diff --git a/lib/src/rive_core/animation/transition_number_condition.dart b/lib/src/rive_core/animation/transition_number_condition.dart index 44a9dc4..49a0a1c 100644 --- a/lib/src/rive_core/animation/transition_number_condition.dart +++ b/lib/src/rive_core/animation/transition_number_condition.dart @@ -1,8 +1,9 @@ import 'dart:collection'; +import 'package:rive/src/generated/animation/transition_number_condition_base.dart'; import 'package:rive/src/rive_core/animation/state_machine_number.dart'; import 'package:rive/src/rive_core/animation/transition_condition.dart'; -import 'package:rive/src/generated/animation/transition_number_condition_base.dart'; + export 'package:rive/src/generated/animation/transition_number_condition_base.dart'; class TransitionNumberCondition extends TransitionNumberConditionBase { diff --git a/lib/src/rive_core/animation/transition_trigger_condition.dart b/lib/src/rive_core/animation/transition_trigger_condition.dart index 124a2e2..2a96349 100644 --- a/lib/src/rive_core/animation/transition_trigger_condition.dart +++ b/lib/src/rive_core/animation/transition_trigger_condition.dart @@ -1,7 +1,8 @@ import 'dart:collection'; -import 'package:rive/src/rive_core/animation/state_machine_trigger.dart'; import 'package:rive/src/generated/animation/transition_trigger_condition_base.dart'; +import 'package:rive/src/rive_core/animation/state_machine_trigger.dart'; + export 'package:rive/src/generated/animation/transition_trigger_condition_base.dart'; class TransitionTriggerCondition extends TransitionTriggerConditionBase { diff --git a/lib/src/rive_core/animation/transition_value_condition.dart b/lib/src/rive_core/animation/transition_value_condition.dart index 2a68b87..62ef412 100644 --- a/lib/src/rive_core/animation/transition_value_condition.dart +++ b/lib/src/rive_core/animation/transition_value_condition.dart @@ -1,5 +1,6 @@ -import 'package:rive/src/rive_core/animation/transition_condition.dart'; import 'package:rive/src/generated/animation/transition_value_condition_base.dart'; +import 'package:rive/src/rive_core/animation/transition_condition.dart'; + export 'package:rive/src/generated/animation/transition_value_condition_base.dart'; abstract class TransitionValueCondition extends TransitionValueConditionBase { diff --git a/lib/src/rive_core/artboard.dart b/lib/src/rive_core/artboard.dart index 24a7fe9..e27fc9b 100644 --- a/lib/src/rive_core/artboard.dart +++ b/lib/src/rive_core/artboard.dart @@ -1,9 +1,10 @@ import 'dart:ui'; import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/artboard_base.dart'; +import 'package:rive/src/rive_core/animation/animation.dart'; import 'package:rive/src/rive_core/animation/linear_animation.dart'; import 'package:rive/src/rive_core/animation/state_machine.dart'; -import 'package:rive/src/rive_core/animation/animation.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/draw_rules.dart'; @@ -16,8 +17,6 @@ import 'package:rive/src/rive_core/shapes/paint/shape_paint_mutator.dart'; import 'package:rive/src/rive_core/shapes/shape_paint_container.dart'; import 'package:rive/src/utilities/dependency_sorter.dart'; -import 'package:rive/src/generated/artboard_base.dart'; - export 'package:rive/src/generated/artboard_base.dart'; class Artboard extends ArtboardBase with ShapePaintContainer { @@ -448,4 +447,21 @@ class Artboard extends ArtboardBase with ShapePaintContainer { throw UnsupportedError( 'Instancing the artboard in the editor isn\'t supported'); } + + // void rebuildDependencies() { + // for (final component in _components) { + // component.dependents.clear(); + // } + // for (final component in _components) { + // component.buildDependencies(); + // } + // for (final component in _components) { + // component.dependentIds = component.dependents + // // Make sure non-core (won't resolve on server) items aren't + // // included + // .where((other) => other.isActive) + // .map((other) => other.id) + // .toList(growable: false); + // } + // } } diff --git a/lib/src/rive_core/bones/bone.dart b/lib/src/rive_core/bones/bone.dart index 57e2885..bd9a0bc 100644 --- a/lib/src/rive_core/bones/bone.dart +++ b/lib/src/rive_core/bones/bone.dart @@ -1,4 +1,7 @@ import 'package:rive/src/generated/bones/bone_base.dart'; +import 'package:rive/src/rive_core/math/mat2d.dart'; +import 'package:rive/src/rive_core/math/vec2d.dart'; + export 'package:rive/src/generated/bones/bone_base.dart'; typedef bool BoneCallback(Bone bone); @@ -59,4 +62,12 @@ class Bone extends BoneBase { // here to make sure we evalute this check only for non-root bones. return super.validate() && (coreType != BoneBase.typeKey || parent is Bone); } + + Vec2D get tipWorldTranslation => getTipWorldTranslation(worldTransform); + + Vec2D getTipWorldTranslation(Mat2D worldTransform) { + var tip = Vec2D(); + Vec2D.transformMat2D(tip, Vec2D.fromValues(length, 0), worldTransform); + return tip; + } } diff --git a/lib/src/rive_core/bones/cubic_weight.dart b/lib/src/rive_core/bones/cubic_weight.dart index 45a0ee0..7cf795c 100644 --- a/lib/src/rive_core/bones/cubic_weight.dart +++ b/lib/src/rive_core/bones/cubic_weight.dart @@ -1,5 +1,6 @@ -import 'package:rive/src/rive_core/math/vec2d.dart'; import 'package:rive/src/generated/bones/cubic_weight_base.dart'; +import 'package:rive/src/rive_core/math/vec2d.dart'; + export 'package:rive/src/generated/bones/cubic_weight_base.dart'; class CubicWeight extends CubicWeightBase { diff --git a/lib/src/rive_core/bones/skin.dart b/lib/src/rive_core/bones/skin.dart index 55dc1fe..24b3062 100644 --- a/lib/src/rive_core/bones/skin.dart +++ b/lib/src/rive_core/bones/skin.dart @@ -1,12 +1,12 @@ import 'dart:typed_data'; +import 'package:rive/src/generated/bones/skin_base.dart'; import 'package:rive/src/rive_core/bones/skinnable.dart'; import 'package:rive/src/rive_core/bones/tendon.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/rive_core/shapes/path_vertex.dart'; -import 'package:rive/src/generated/bones/skin_base.dart'; export 'package:rive/src/generated/bones/skin_base.dart'; /// Represents a skin deformation of either a Path or an Image Mesh connected to diff --git a/lib/src/rive_core/bones/tendon.dart b/lib/src/rive_core/bones/tendon.dart index 84a3d14..71cd818 100644 --- a/lib/src/rive_core/bones/tendon.dart +++ b/lib/src/rive_core/bones/tendon.dart @@ -1,6 +1,7 @@ +import 'package:rive/src/generated/bones/tendon_base.dart'; import 'package:rive/src/rive_core/bones/skeletal_component.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; -import 'package:rive/src/generated/bones/tendon_base.dart'; + export 'package:rive/src/generated/bones/tendon_base.dart'; class Tendon extends TendonBase { diff --git a/lib/src/rive_core/bones/weight.dart b/lib/src/rive_core/bones/weight.dart index af4cb82..8151184 100644 --- a/lib/src/rive_core/bones/weight.dart +++ b/lib/src/rive_core/bones/weight.dart @@ -1,8 +1,9 @@ import 'dart:typed_data'; +import 'package:rive/src/generated/bones/weight_base.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; -import 'package:rive/src/generated/bones/weight_base.dart'; + export 'package:rive/src/generated/bones/weight_base.dart'; class Weight extends WeightBase { diff --git a/lib/src/rive_core/component.dart b/lib/src/rive_core/component.dart index 82e7903..2c131af 100644 --- a/lib/src/rive_core/component.dart +++ b/lib/src/rive_core/component.dart @@ -1,11 +1,11 @@ -import 'package:rive/src/core/core.dart'; import 'package:flutter/foundation.dart'; +import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/component_base.dart'; import 'package:rive/src/rive_core/artboard.dart'; import 'package:rive/src/rive_core/container_component.dart'; - -import 'package:rive/src/generated/component_base.dart'; import 'package:rive/src/utilities/dependency_sorter.dart'; import 'package:rive/src/utilities/tops.dart'; + export 'package:rive/src/generated/component_base.dart'; abstract class Component extends ComponentBase @@ -140,7 +140,11 @@ abstract class Component extends ComponentBase @override Set get dependents => _dependents; - bool addDependent(Component dependent) { + /// Mark [dependent] as a component which must update after this. Provide + /// [via] as the Component registering the dependency when it is not + /// [dependent] itself. At edit time this allows the editor to rebuild both + /// [dependent] and [via] when [dependent] has its dependencies cleared. + bool addDependent(Component dependent, {Component? via}) { assert(artboard == dependent.artboard, 'Components must be in the same artboard.'); @@ -164,16 +168,15 @@ abstract class Component extends ComponentBase } } - @mustCallSuper - void buildDependencies() { + void clearDependencies() { for (final parentDep in _dependsOn) { parentDep._dependents.remove(this); } _dependsOn.clear(); - // by default a component depends on nothing (likely it will depend on the - // parent but we leave that for specific implementations to supply). } + void buildDependencies() {} + /// Something we depend on has been removed. It's important to clear out any /// stored references to that dependency so it can be garbage collected (if /// necessary). diff --git a/lib/src/rive_core/constraints/constraint.dart b/lib/src/rive_core/constraints/constraint.dart new file mode 100644 index 0000000..723c18a --- /dev/null +++ b/lib/src/rive_core/constraints/constraint.dart @@ -0,0 +1,26 @@ +import 'package:rive/src/generated/constraints/constraint_base.dart'; +import 'package:rive/src/rive_core/transform_component.dart'; +export 'package:rive/src/generated/constraints/constraint_base.dart'; + +/// A specialized [Component] which can be parented to any [TransformComponent] +/// providing rules for how to constrain its transform space. +abstract class Constraint extends ConstraintBase { + /// Returns the [TransformComponent] which this [Constraint] is applied to. + // TransformComponent? get constrainedComponent => + // parent is TransformComponent ? parent as TransformComponent : null; + TransformComponent get constrainedComponent => parent as TransformComponent; + + @override + void strengthChanged(double from, double to) => + constrainedComponent.markTransformDirty(); + + @override + bool validate() => super.validate() && parent is TransformComponent; + + void constrain(TransformComponent component); + + @override + void update(int dirt) {} + + void markConstraintDirty() => constrainedComponent.markTransformDirty(); +} diff --git a/lib/src/rive_core/constraints/ik_constraint.dart b/lib/src/rive_core/constraints/ik_constraint.dart new file mode 100644 index 0000000..44c3159 --- /dev/null +++ b/lib/src/rive_core/constraints/ik_constraint.dart @@ -0,0 +1,275 @@ +import 'dart:math'; + +import 'package:rive/src/generated/constraints/ik_constraint_base.dart'; +import 'package:rive/src/rive_core/artboard.dart'; +import 'package:rive/src/rive_core/bones/bone.dart'; +import 'package:rive/src/rive_core/math/mat2d.dart'; +import 'package:rive/src/rive_core/math/transform_components.dart'; +import 'package:rive/src/rive_core/math/vec2d.dart'; +import 'package:rive/src/rive_core/transform_component.dart'; + +export 'package:rive/src/generated/constraints/ik_constraint_base.dart'; + +/// A constraint which rotates its constrained bone and the parentBoneCount +/// bones above it in order to move the tip of the constrained bone towards the +/// target. +class IKConstraint extends IKConstraintBase { + @override + void invertDirectionChanged(bool from, bool to) => markConstraintDirty(); + + @override + void parentBoneCountChanged(int from, int to) {} + + @override + void markConstraintDirty() { + super.markConstraintDirty(); + + // We automatically propagate dirt to the parent constrained bone, but we + // also need to make sure the other bones we influence above it rebuild + // their transforms. + for (int i = 0; i < _fkChain.length - 1; i++) { + _fkChain[i].bone.markTransformDirty(); + } + } + + /// The list of bones in FK order. + final List<_BoneChainLink> _fkChain = []; + @override + void buildDependencies() { + super.buildDependencies(); + + parent!.addDependent(this); + + // Rebuild the FK chain when we update dependencies. + _fkChain.clear(); + var boneCount = parentBoneCount; + var bone = parent as Bone; + var bones = [bone]; + // Get the reverse FK chain of bones (from tip up). + while (bone.parent is Bone && boneCount > 0) { + boneCount--; + bone = bone.parent as Bone; + bones.add(bone); + } + // Now put them in FK order (top to bottom). + for (final bone in bones.reversed) { + _fkChain.add(_BoneChainLink( + index: _fkChain.length, + bone: bone, + )); + } + + // Make sure all of the first level children of each bone depend on the + // tip (constrainedComponent). + var tip = parent as Bone; + for (final bone in bones.skip(1)) { + for (final child in bone.children) { + if (child is TransformComponent && !bones.contains(child)) { + tip.addDependent(child, via: this); + } + } + } + } + + @override + bool validate() => super.validate() && parent is Bone; + + @override + void constrain(TransformComponent component) { + if (target == null) { + return; + } + + var worldTargetTranslation = target!.worldTranslation; + // Decompose the chain. + for (final item in _fkChain) { + var bone = item.bone; + Mat2D parentWorld = _parentWorld(bone); + + Mat2D.invert(item.parentWorldInverse, parentWorld); + + var boneTransform = bone.transform; + Mat2D.multiply( + boneTransform, item.parentWorldInverse, bone.worldTransform); + Mat2D.decompose(boneTransform, item.transformComponents); + } + + switch (_fkChain.length) { + case 1: + solve1(_fkChain.first, worldTargetTranslation); + break; + case 2: + solve2(_fkChain[0], _fkChain[1], worldTargetTranslation); + break; + default: + { + var last = _fkChain.length - 1; + var tip = _fkChain[last]; + for (int i = 0; i < last; i++) { + var item = _fkChain[i]; + solve2(item, tip, worldTargetTranslation); + for (int j = item.index + 1, end = _fkChain.length - 1; + j < end; + j++) { + var fk = _fkChain[j]; + Mat2D.invert(fk.parentWorldInverse, _parentWorld(fk.bone)); + } + } + break; + } + } + + // At the end, mix the FK angle with the IK angle by strength + if (strength != 1.0) { + for (final fk in _fkChain) { + var fromAngle = fk.transformComponents.rotation % (pi * 2); + var toAngle = fk.angle % (pi * 2); + var diff = toAngle - fromAngle; + if (diff > pi) { + diff -= pi * 2; + } else if (diff < -pi) { + diff += pi * 2; + } + var angle = fromAngle + diff * strength; + _constrainRotation(fk, angle); + } + } + } + + void solve1(_BoneChainLink fk1, Vec2D worldTargetTranslation) { + Mat2D iworld = fk1.parentWorldInverse; + var pA = fk1.bone.worldTranslation; + var pBT = Vec2D.clone(worldTargetTranslation); + + // To target in worldspace + var toTarget = Vec2D.subtract(Vec2D(), pBT, pA); + + // Note this is directional, hence not transformMat2d + Vec2D toTargetLocal = Vec2D.transformMat2(Vec2D(), toTarget, iworld); + var r = atan2(toTargetLocal[1], toTargetLocal[0]); + + _constrainRotation(fk1, r); + fk1.angle = r; + } + + void solve2( + _BoneChainLink fk1, _BoneChainLink fk2, Vec2D worldTargetTranslation) { + Bone b1 = fk1.bone; + Bone b2 = fk2.bone; + var firstChild = _fkChain[fk1.index + 1]; + + var iworld = fk1.parentWorldInverse; + + var pA = b1.worldTranslation; + var pC = firstChild.bone.worldTranslation; + var pB = b2.tipWorldTranslation; + var pBT = Vec2D.clone(worldTargetTranslation); + + Vec2D.transformMat2D(pA, pA, iworld); + Vec2D.transformMat2D(pC, pC, iworld); + Vec2D.transformMat2D(pB, pB, iworld); + Vec2D.transformMat2D(pBT, pBT, iworld); + + // http://mathworld.wolfram.com/LawofCosines.html + + var av = Vec2D.subtract(Vec2D(), pB, pC); + var a = Vec2D.length(av); + + var bv = Vec2D.subtract(Vec2D(), pC, pA); + var b = Vec2D.length(bv); + + var cv = Vec2D.subtract(Vec2D(), pBT, pA); + var c = Vec2D.length(cv); + + var A = acos(max(-1, min(1, (-a * a + b * b + c * c) / (2 * b * c)))); + var C = acos(max(-1, min(1, (a * a + b * b - c * c) / (2 * a * b)))); + + double r1, r2; + if (b2.parent != b1) { + var secondChild = _fkChain[fk1.index + 2]; + + var secondChildWorldInverse = secondChild.parentWorldInverse; + + pC = firstChild.bone.worldTranslation; + pB = b2.tipWorldTranslation; + + var avec = Vec2D.subtract(Vec2D(), pB, pC); + + var avLocal = Vec2D.transformMat2(Vec2D(), avec, secondChildWorldInverse); + var angleCorrection = -atan2(avLocal[1], avLocal[0]); + + if (invertDirection) { + r1 = atan2(cv[1], cv[0]) - A; + r2 = -C + pi + angleCorrection; + } else { + r1 = A + atan2(cv[1], cv[0]); + r2 = C - pi + angleCorrection; + } + } else if (invertDirection) { + r1 = atan2(cv[1], cv[0]) - A; + r2 = -C + pi; + } else { + r1 = A + atan2(cv[1], cv[0]); + r2 = C - pi; + } + _constrainRotation(fk1, r1); + _constrainRotation(firstChild, r2); + if (firstChild != fk2) { + var bone = fk2.bone; + Mat2D.multiply(bone.worldTransform, _parentWorld(bone), bone.transform); + } + + // Simple storage, need this for interpolation. + fk1.angle = r1; + firstChild.angle = r2; + } +} + +class _BoneChainLink { + final int index; + final Bone bone; + double angle = 0; + TransformComponents transformComponents = TransformComponents(); + Mat2D parentWorldInverse = Mat2D(); + + _BoneChainLink({ + required this.index, + required this.bone, + }); +} + +void _constrainRotation(_BoneChainLink link, double rotation) { + var bone = link.bone; + Mat2D parentWorld = _parentWorld(bone); + var boneTransform = bone.transform; + if (rotation == 0) { + Mat2D.setIdentity(boneTransform); + } else { + Mat2D.fromRotation(boneTransform, rotation); + } + var c = link.transformComponents; + boneTransform[4] = c.x; + boneTransform[5] = c.y; + var scaleX = c.scaleX; + var scaleY = c.scaleY; + boneTransform[0] *= scaleX; + boneTransform[1] *= scaleX; + boneTransform[2] *= scaleY; + boneTransform[3] *= scaleY; + + var skew = c.skew; + if (skew != 0) { + boneTransform[2] = boneTransform[0] * skew + boneTransform[2]; + boneTransform[3] = boneTransform[1] * skew + boneTransform[3]; + } + Mat2D.multiply(bone.worldTransform, parentWorld, boneTransform); +} + +Mat2D _parentWorld(TransformComponent component) { + var parent = component.parent; + if (parent is Artboard) { + return parent.worldTransform; + } else { + return (parent as TransformComponent).worldTransform; + } +} diff --git a/lib/src/rive_core/constraints/targeted_constraint.dart b/lib/src/rive_core/constraints/targeted_constraint.dart new file mode 100644 index 0000000..95d9bc3 --- /dev/null +++ b/lib/src/rive_core/constraints/targeted_constraint.dart @@ -0,0 +1,36 @@ +import 'package:rive/src/generated/constraints/targeted_constraint_base.dart'; +import 'package:rive/src/rive_core/transform_component.dart'; +export 'package:rive/src/generated/constraints/targeted_constraint_base.dart'; + +/// A [Constraint] which uses an external target to help influence the computed +/// transform. +abstract class TargetedConstraint extends TargetedConstraintBase { + TransformComponent? _target; + TransformComponent? get target => _target; + set target(TransformComponent? value) { + if (_target == value) { + return; + } + + _target = value; + } + + @override + void targetIdChanged(int from, int to) { + target = context.resolve(to); + } + + @override + void buildDependencies() { + super.buildDependencies(); + // Targeted constraints must have their constrainedComponent update after + // the target. + _target?.addDependent(constrainedComponent, via: this); + } + + @override + void onAddedDirty() { + super.onAddedDirty(); + target = context.resolve(targetId); + } +} diff --git a/lib/src/rive_core/container_component.dart b/lib/src/rive_core/container_component.dart index 8d0fb6c..c3d2250 100644 --- a/lib/src/rive_core/container_component.dart +++ b/lib/src/rive_core/container_component.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/container_component_base.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/draw_rules.dart'; import 'package:rive/src/rive_core/drawable.dart'; -import 'package:rive/src/generated/container_component_base.dart'; typedef bool DescentCallback(Component component); diff --git a/lib/src/rive_core/draw_rules.dart b/lib/src/rive_core/draw_rules.dart index 58ef46d..407262d 100644 --- a/lib/src/rive_core/draw_rules.dart +++ b/lib/src/rive_core/draw_rules.dart @@ -1,7 +1,8 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/draw_rules_base.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/draw_target.dart'; -import 'package:rive/src/generated/draw_rules_base.dart'; + export 'package:rive/src/generated/draw_rules_base.dart'; class DrawRules extends DrawRulesBase { diff --git a/lib/src/rive_core/draw_target.dart b/lib/src/rive_core/draw_target.dart index f155339..945e5df 100644 --- a/lib/src/rive_core/draw_target.dart +++ b/lib/src/rive_core/draw_target.dart @@ -1,6 +1,7 @@ import 'package:rive/src/core/core.dart'; -import 'package:rive/src/rive_core/drawable.dart'; import 'package:rive/src/generated/draw_target_base.dart'; +import 'package:rive/src/rive_core/drawable.dart'; + export 'package:rive/src/generated/draw_target_base.dart'; enum DrawTargetPlacement { before, after } diff --git a/lib/src/rive_core/drawable.dart b/lib/src/rive_core/drawable.dart index 2f15f9f..d28c050 100644 --- a/lib/src/rive_core/drawable.dart +++ b/lib/src/rive_core/drawable.dart @@ -1,12 +1,13 @@ import 'dart:ui'; +import 'package:rive/src/generated/drawable_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/component_flags.dart'; import 'package:rive/src/rive_core/container_component.dart'; import 'package:rive/src/rive_core/draw_rules.dart'; import 'package:rive/src/rive_core/shapes/clipping_shape.dart'; -import 'package:rive/src/generated/drawable_base.dart'; import 'package:rive/src/rive_core/transform_component.dart'; + export 'package:rive/src/generated/drawable_base.dart'; abstract class Drawable extends DrawableBase { diff --git a/lib/src/rive_core/node.dart b/lib/src/rive_core/node.dart index 222e777..e16f95b 100644 --- a/lib/src/rive_core/node.dart +++ b/lib/src/rive_core/node.dart @@ -1,6 +1,7 @@ +import 'package:rive/src/generated/node_base.dart'; import 'package:rive/src/rive_core/math/aabb.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; -import 'package:rive/src/generated/node_base.dart'; + export 'package:rive/src/generated/node_base.dart'; class _UnknownNode extends Node {} diff --git a/lib/src/rive_core/shapes/clipping_shape.dart b/lib/src/rive_core/shapes/clipping_shape.dart index ef0da44..1b24fb2 100644 --- a/lib/src/rive_core/shapes/clipping_shape.dart +++ b/lib/src/rive_core/shapes/clipping_shape.dart @@ -1,9 +1,10 @@ import 'dart:ui'; +import 'package:rive/src/generated/shapes/clipping_shape_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/node.dart'; import 'package:rive/src/rive_core/shapes/shape.dart'; -import 'package:rive/src/generated/shapes/clipping_shape_base.dart'; + export 'package:rive/src/generated/shapes/clipping_shape_base.dart'; class ClippingShape extends ClippingShapeBase { diff --git a/lib/src/rive_core/shapes/cubic_asymmetric_vertex.dart b/lib/src/rive_core/shapes/cubic_asymmetric_vertex.dart index d90304a..a20ecea 100644 --- a/lib/src/rive_core/shapes/cubic_asymmetric_vertex.dart +++ b/lib/src/rive_core/shapes/cubic_asymmetric_vertex.dart @@ -1,9 +1,10 @@ import 'dart:math'; import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/shapes/cubic_asymmetric_vertex_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; -import 'package:rive/src/generated/shapes/cubic_asymmetric_vertex_base.dart'; + export 'package:rive/src/generated/shapes/cubic_asymmetric_vertex_base.dart'; class CubicAsymmetricVertex extends CubicAsymmetricVertexBase { diff --git a/lib/src/rive_core/shapes/cubic_detached_vertex.dart b/lib/src/rive_core/shapes/cubic_detached_vertex.dart index 8e8d4c0..48394a1 100644 --- a/lib/src/rive_core/shapes/cubic_detached_vertex.dart +++ b/lib/src/rive_core/shapes/cubic_detached_vertex.dart @@ -1,9 +1,10 @@ import 'dart:math'; import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/shapes/cubic_detached_vertex_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; -import 'package:rive/src/generated/shapes/cubic_detached_vertex_base.dart'; + export 'package:rive/src/generated/shapes/cubic_detached_vertex_base.dart'; class CubicDetachedVertex extends CubicDetachedVertexBase { diff --git a/lib/src/rive_core/shapes/cubic_mirrored_vertex.dart b/lib/src/rive_core/shapes/cubic_mirrored_vertex.dart index 31f5514..fb964ce 100644 --- a/lib/src/rive_core/shapes/cubic_mirrored_vertex.dart +++ b/lib/src/rive_core/shapes/cubic_mirrored_vertex.dart @@ -1,9 +1,10 @@ import 'dart:math'; import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/shapes/cubic_mirrored_vertex_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; -import 'package:rive/src/generated/shapes/cubic_mirrored_vertex_base.dart'; + export 'package:rive/src/generated/shapes/cubic_mirrored_vertex_base.dart'; class CubicMirroredVertex extends CubicMirroredVertexBase { diff --git a/lib/src/rive_core/shapes/cubic_vertex.dart b/lib/src/rive_core/shapes/cubic_vertex.dart index 25d1bb8..e00a74f 100644 --- a/lib/src/rive_core/shapes/cubic_vertex.dart +++ b/lib/src/rive_core/shapes/cubic_vertex.dart @@ -1,9 +1,10 @@ import 'dart:typed_data'; +import 'package:rive/src/generated/shapes/cubic_vertex_base.dart'; import 'package:rive/src/rive_core/bones/weight.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; -import 'package:rive/src/generated/shapes/cubic_vertex_base.dart'; + export 'package:rive/src/generated/shapes/cubic_vertex_base.dart'; abstract class CubicVertex extends CubicVertexBase { diff --git a/lib/src/rive_core/shapes/ellipse.dart b/lib/src/rive_core/shapes/ellipse.dart index 3afdfc7..5febbb0 100644 --- a/lib/src/rive_core/shapes/ellipse.dart +++ b/lib/src/rive_core/shapes/ellipse.dart @@ -1,7 +1,7 @@ +import 'package:rive/src/generated/shapes/ellipse_base.dart'; import 'package:rive/src/rive_core/math/circle_constant.dart'; import 'package:rive/src/rive_core/shapes/cubic_detached_vertex.dart'; import 'package:rive/src/rive_core/shapes/path_vertex.dart'; -import 'package:rive/src/generated/shapes/ellipse_base.dart'; export 'package:rive/src/generated/shapes/ellipse_base.dart'; diff --git a/lib/src/rive_core/shapes/paint/fill.dart b/lib/src/rive_core/shapes/paint/fill.dart index c65f581..00f3058 100644 --- a/lib/src/rive_core/shapes/paint/fill.dart +++ b/lib/src/rive_core/shapes/paint/fill.dart @@ -1,8 +1,9 @@ import 'dart:ui'; +import 'package:rive/src/generated/shapes/paint/fill_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/shapes/shape_paint_container.dart'; -import 'package:rive/src/generated/shapes/paint/fill_base.dart'; + export 'package:rive/src/generated/shapes/paint/fill_base.dart'; /// A fill Shape painter. diff --git a/lib/src/rive_core/shapes/paint/gradient_stop.dart b/lib/src/rive_core/shapes/paint/gradient_stop.dart index 821c32b..1e6b1d5 100644 --- a/lib/src/rive_core/shapes/paint/gradient_stop.dart +++ b/lib/src/rive_core/shapes/paint/gradient_stop.dart @@ -1,7 +1,7 @@ import 'dart:ui' as ui; -import 'package:rive/src/rive_core/container_component.dart'; import 'package:rive/src/generated/shapes/paint/gradient_stop_base.dart'; +import 'package:rive/src/rive_core/container_component.dart'; import 'package:rive/src/rive_core/shapes/paint/linear_gradient.dart'; export 'package:rive/src/generated/shapes/paint/gradient_stop_base.dart'; diff --git a/lib/src/rive_core/shapes/paint/linear_gradient.dart b/lib/src/rive_core/shapes/paint/linear_gradient.dart index 6dea1f0..488409d 100644 --- a/lib/src/rive_core/shapes/paint/linear_gradient.dart +++ b/lib/src/rive_core/shapes/paint/linear_gradient.dart @@ -1,13 +1,14 @@ import 'dart:ui' as ui; import 'package:meta/meta.dart'; +import 'package:rive/src/generated/shapes/paint/linear_gradient_base.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; import 'package:rive/src/rive_core/shapes/paint/gradient_stop.dart'; import 'package:rive/src/rive_core/shapes/paint/shape_paint_mutator.dart'; import 'package:rive/src/rive_core/shapes/shape.dart'; -import 'package:rive/src/generated/shapes/paint/linear_gradient_base.dart'; + export 'package:rive/src/generated/shapes/paint/linear_gradient_base.dart'; /// A core linear gradient. Can be added as a child to a [Shape]'s [Fill] or diff --git a/lib/src/rive_core/shapes/paint/shape_paint.dart b/lib/src/rive_core/shapes/paint/shape_paint.dart index 4c89b7a..b97a0b9 100644 --- a/lib/src/rive_core/shapes/paint/shape_paint.dart +++ b/lib/src/rive_core/shapes/paint/shape_paint.dart @@ -1,13 +1,14 @@ import 'dart:ui'; import 'package:meta/meta.dart'; +import 'package:rive/src/generated/shapes/paint/shape_paint_base.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/container_component.dart'; import 'package:rive/src/rive_core/shapes/paint/shape_paint_mutator.dart'; import 'package:rive/src/rive_core/shapes/shape.dart'; import 'package:rive/src/rive_core/shapes/shape_paint_container.dart'; -import 'package:rive/src/generated/shapes/paint/shape_paint_base.dart'; + export 'package:rive/src/generated/shapes/paint/shape_paint_base.dart'; /// Generic ShapePaint that abstracts Stroke and Fill. Automatically hooks up diff --git a/lib/src/rive_core/shapes/paint/solid_color.dart b/lib/src/rive_core/shapes/paint/solid_color.dart index eb33afa..0bcd170 100644 --- a/lib/src/rive_core/shapes/paint/solid_color.dart +++ b/lib/src/rive_core/shapes/paint/solid_color.dart @@ -1,9 +1,10 @@ import 'dart:ui'; +import 'package:rive/src/generated/shapes/paint/solid_color_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/shapes/paint/shape_paint.dart'; import 'package:rive/src/rive_core/shapes/paint/shape_paint_mutator.dart'; -import 'package:rive/src/generated/shapes/paint/solid_color_base.dart'; + export 'package:rive/src/generated/shapes/paint/solid_color_base.dart'; /// A solid color painter for a shape. Works for both Fill and Stroke. diff --git a/lib/src/rive_core/shapes/paint/stroke.dart b/lib/src/rive_core/shapes/paint/stroke.dart index 01b11a8..7e75869 100644 --- a/lib/src/rive_core/shapes/paint/stroke.dart +++ b/lib/src/rive_core/shapes/paint/stroke.dart @@ -1,9 +1,10 @@ import 'package:flutter/material.dart'; +import 'package:rive/src/generated/shapes/paint/stroke_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/shapes/paint/stroke_effect.dart'; import 'package:rive/src/rive_core/shapes/shape.dart'; import 'package:rive/src/rive_core/shapes/shape_paint_container.dart'; -import 'package:rive/src/generated/shapes/paint/stroke_base.dart'; + export 'package:rive/src/generated/shapes/paint/stroke_base.dart'; /// A stroke Shape painter. diff --git a/lib/src/rive_core/shapes/paint/trim_path.dart b/lib/src/rive_core/shapes/paint/trim_path.dart index a97115e..6a032ec 100644 --- a/lib/src/rive_core/shapes/paint/trim_path.dart +++ b/lib/src/rive_core/shapes/paint/trim_path.dart @@ -1,11 +1,11 @@ import 'dart:ui'; +import 'package:rive/src/generated/shapes/paint/trim_path_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/shapes/paint/stroke.dart'; import 'package:rive/src/rive_core/shapes/paint/stroke_effect.dart'; import 'package:rive/src/rive_core/shapes/paint/trim_path_drawing.dart'; -import 'package:rive/src/generated/shapes/paint/trim_path_base.dart'; export 'package:rive/src/generated/shapes/paint/trim_path_base.dart'; enum TrimPathMode { diff --git a/lib/src/rive_core/shapes/parametric_path.dart b/lib/src/rive_core/shapes/parametric_path.dart index 266e548..4cb0243 100644 --- a/lib/src/rive_core/shapes/parametric_path.dart +++ b/lib/src/rive_core/shapes/parametric_path.dart @@ -1,5 +1,6 @@ -import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/generated/shapes/parametric_path_base.dart'; +import 'package:rive/src/rive_core/math/mat2d.dart'; + export 'package:rive/src/generated/shapes/parametric_path_base.dart'; abstract class ParametricPath extends ParametricPathBase { diff --git a/lib/src/rive_core/shapes/path.dart b/lib/src/rive_core/shapes/path.dart index 26bfe2f..92e3f03 100644 --- a/lib/src/rive_core/shapes/path.dart +++ b/lib/src/rive_core/shapes/path.dart @@ -1,6 +1,7 @@ import 'dart:math'; import 'dart:ui' as ui; +import 'package:rive/src/generated/shapes/path_base.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/component_flags.dart'; @@ -11,7 +12,7 @@ import 'package:rive/src/rive_core/shapes/cubic_vertex.dart'; import 'package:rive/src/rive_core/shapes/path_vertex.dart'; import 'package:rive/src/rive_core/shapes/shape.dart'; import 'package:rive/src/rive_core/shapes/straight_vertex.dart'; -import 'package:rive/src/generated/shapes/path_base.dart'; + export 'package:rive/src/generated/shapes/path_base.dart'; /// An abstract low level path that gets implemented by parametric and point diff --git a/lib/src/rive_core/shapes/path_vertex.dart b/lib/src/rive_core/shapes/path_vertex.dart index d2e9508..02de297 100644 --- a/lib/src/rive_core/shapes/path_vertex.dart +++ b/lib/src/rive_core/shapes/path_vertex.dart @@ -1,11 +1,12 @@ import 'dart:typed_data'; +import 'package:rive/src/generated/shapes/path_vertex_base.dart'; import 'package:rive/src/rive_core/bones/weight.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; import 'package:rive/src/rive_core/shapes/path.dart'; -import 'package:rive/src/generated/shapes/path_vertex_base.dart'; + export 'package:rive/src/generated/shapes/path_vertex_base.dart'; abstract class PathVertex extends PathVertexBase { diff --git a/lib/src/rive_core/shapes/points_path.dart b/lib/src/rive_core/shapes/points_path.dart index be58fde..f8cf887 100644 --- a/lib/src/rive_core/shapes/points_path.dart +++ b/lib/src/rive_core/shapes/points_path.dart @@ -1,9 +1,9 @@ +import 'package:rive/src/generated/shapes/points_path_base.dart'; import 'package:rive/src/rive_core/bones/skinnable.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/rive_core/shapes/path_vertex.dart'; -import 'package:rive/src/generated/shapes/points_path_base.dart'; export 'package:rive/src/generated/shapes/points_path_base.dart'; diff --git a/lib/src/rive_core/shapes/polygon.dart b/lib/src/rive_core/shapes/polygon.dart index fae5c94..9c44226 100644 --- a/lib/src/rive_core/shapes/polygon.dart +++ b/lib/src/rive_core/shapes/polygon.dart @@ -1,9 +1,10 @@ import 'dart:math'; -import 'package:rive/src/rive_core/shapes/path_vertex.dart'; -import 'package:rive/src/rive_core/bones/weight.dart'; -import 'package:rive/src/rive_core/shapes/straight_vertex.dart'; import 'package:rive/src/generated/shapes/polygon_base.dart'; +import 'package:rive/src/rive_core/bones/weight.dart'; +import 'package:rive/src/rive_core/shapes/path_vertex.dart'; +import 'package:rive/src/rive_core/shapes/straight_vertex.dart'; + export 'package:rive/src/generated/shapes/polygon_base.dart'; class Polygon extends PolygonBase { diff --git a/lib/src/rive_core/shapes/rectangle.dart b/lib/src/rive_core/shapes/rectangle.dart index b72149c..a827042 100644 --- a/lib/src/rive_core/shapes/rectangle.dart +++ b/lib/src/rive_core/shapes/rectangle.dart @@ -1,6 +1,7 @@ +import 'package:rive/src/generated/shapes/rectangle_base.dart'; import 'package:rive/src/rive_core/shapes/path_vertex.dart'; import 'package:rive/src/rive_core/shapes/straight_vertex.dart'; -import 'package:rive/src/generated/shapes/rectangle_base.dart'; + export 'package:rive/src/generated/shapes/rectangle_base.dart'; class Rectangle extends RectangleBase { diff --git a/lib/src/rive_core/shapes/shape.dart b/lib/src/rive_core/shapes/shape.dart index b775f91..8c4df11 100644 --- a/lib/src/rive_core/shapes/shape.dart +++ b/lib/src/rive_core/shapes/shape.dart @@ -1,5 +1,7 @@ import 'dart:ui' as ui; +import 'package:collection/collection.dart'; +import 'package:rive/src/generated/shapes/shape_base.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; import 'package:rive/src/rive_core/shapes/paint/linear_gradient.dart' as core; import 'package:rive/src/rive_core/shapes/paint/shape_paint_mutator.dart'; @@ -7,8 +9,7 @@ import 'package:rive/src/rive_core/shapes/paint/stroke.dart'; import 'package:rive/src/rive_core/shapes/path.dart'; import 'package:rive/src/rive_core/shapes/path_composer.dart'; import 'package:rive/src/rive_core/shapes/shape_paint_container.dart'; -import 'package:rive/src/generated/shapes/shape_base.dart'; -import 'package:collection/collection.dart'; + export 'package:rive/src/generated/shapes/shape_base.dart'; class Shape extends ShapeBase with ShapePaintContainer { diff --git a/lib/src/rive_core/shapes/shape_paint_container.dart b/lib/src/rive_core/shapes/shape_paint_container.dart index a570b43..142e9ea 100644 --- a/lib/src/rive_core/shapes/shape_paint_container.dart +++ b/lib/src/rive_core/shapes/shape_paint_container.dart @@ -1,9 +1,9 @@ +import 'package:meta/meta.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; import 'package:rive/src/rive_core/shapes/paint/fill.dart'; -import 'package:meta/meta.dart'; import 'package:rive/src/rive_core/shapes/paint/shape_paint_mutator.dart'; import 'package:rive/src/rive_core/shapes/paint/stroke.dart'; @@ -71,7 +71,7 @@ abstract class ShapePaintContainer { /// ShapePaintContainer to ContainerComponent/Shape/Artboard/etc. bool addDirt(int value, {bool recurse = false}); - bool addDependent(Component dependent); + bool addDependent(Component dependent, {Component? via}); void appendChild(Component child); Mat2D get worldTransform; Vec2D get worldTranslation; diff --git a/lib/src/rive_core/shapes/star.dart b/lib/src/rive_core/shapes/star.dart index 7c69c1d..accf691 100644 --- a/lib/src/rive_core/shapes/star.dart +++ b/lib/src/rive_core/shapes/star.dart @@ -1,9 +1,10 @@ import 'dart:math'; +import 'package:rive/src/generated/shapes/star_base.dart'; import 'package:rive/src/rive_core/bones/weight.dart'; import 'package:rive/src/rive_core/shapes/path_vertex.dart'; import 'package:rive/src/rive_core/shapes/straight_vertex.dart'; -import 'package:rive/src/generated/shapes/star_base.dart'; + export 'package:rive/src/generated/shapes/star_base.dart'; class Star extends StarBase { diff --git a/lib/src/rive_core/shapes/straight_vertex.dart b/lib/src/rive_core/shapes/straight_vertex.dart index 55a130f..c41d40e 100644 --- a/lib/src/rive_core/shapes/straight_vertex.dart +++ b/lib/src/rive_core/shapes/straight_vertex.dart @@ -1,8 +1,9 @@ import 'package:rive/src/core/core.dart'; +import 'package:rive/src/generated/shapes/straight_vertex_base.dart'; import 'package:rive/src/rive_core/bones/weight.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; -import 'package:rive/src/generated/shapes/straight_vertex_base.dart'; + export 'package:rive/src/generated/shapes/straight_vertex_base.dart'; class StraightVertex extends StraightVertexBase { diff --git a/lib/src/rive_core/shapes/triangle.dart b/lib/src/rive_core/shapes/triangle.dart index b218f63..7b21422 100644 --- a/lib/src/rive_core/shapes/triangle.dart +++ b/lib/src/rive_core/shapes/triangle.dart @@ -1,6 +1,6 @@ +import 'package:rive/src/generated/shapes/triangle_base.dart'; import 'package:rive/src/rive_core/shapes/path_vertex.dart'; import 'package:rive/src/rive_core/shapes/straight_vertex.dart'; -import 'package:rive/src/generated/shapes/triangle_base.dart'; /// Export the Base class for external use (e.g. rive.dart) export 'package:rive/src/generated/shapes/triangle_base.dart'; diff --git a/lib/src/rive_core/state_machine_controller.dart b/lib/src/rive_core/state_machine_controller.dart index e5ed34a..5488bf6 100644 --- a/lib/src/rive_core/state_machine_controller.dart +++ b/lib/src/rive_core/state_machine_controller.dart @@ -1,8 +1,8 @@ import 'dart:collection'; -import 'package:rive/src/core/core.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/scheduler.dart'; +import 'package:rive/src/core/core.dart'; import 'package:rive/src/rive_core/animation/animation_state.dart'; import 'package:rive/src/rive_core/animation/animation_state_instance.dart'; import 'package:rive/src/rive_core/animation/any_state.dart'; diff --git a/lib/src/rive_core/transform_component.dart b/lib/src/rive_core/transform_component.dart index b3bc8a2..fe3c490 100644 --- a/lib/src/rive_core/transform_component.dart +++ b/lib/src/rive_core/transform_component.dart @@ -1,14 +1,17 @@ import 'package:flutter/foundation.dart'; +import 'package:rive/src/generated/shapes/clipping_shape_base.dart'; +import 'package:rive/src/generated/transform_component_base.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/component_dirt.dart'; +import 'package:rive/src/rive_core/constraints/constraint.dart'; +import 'package:rive/src/rive_core/constraints/ik_constraint.dart'; import 'package:rive/src/rive_core/container_component.dart'; import 'package:rive/src/rive_core/draw_rules.dart'; import 'package:rive/src/rive_core/drawable.dart'; import 'package:rive/src/rive_core/math/mat2d.dart'; import 'package:rive/src/rive_core/math/vec2d.dart'; import 'package:rive/src/rive_core/shapes/clipping_shape.dart'; -import 'package:rive/src/generated/shapes/clipping_shape_base.dart'; -import 'package:rive/src/generated/transform_component_base.dart'; + export 'package:rive/src/generated/transform_component_base.dart'; abstract class TransformComponent extends TransformComponentBase { @@ -20,6 +23,10 @@ abstract class TransformComponent extends TransformComponentBase { final List _clippingShapes = []; Iterable get clippingShapes => _clippingShapes; + /// Constraints applied to this TransformComponent. + final List _constraints = []; + Iterable get constraints => _constraints; + double _renderOpacity = 0; double get renderOpacity => _renderOpacity; @@ -77,6 +84,12 @@ abstract class TransformComponent extends TransformComponentBase { } else { Mat2D.copy(worldTransform, transform); } + + if (_constraints.isNotEmpty) { + for (final constraint in _constraints) { + constraint.constrain(this); + } + } } void calculateWorldTransform() { @@ -150,6 +163,9 @@ abstract class TransformComponent extends TransformComponentBase { _clippingShapes.add(child as ClippingShape); addDirt(ComponentDirt.clip, recurse: true); + break; + case IKConstraintBase.typeKey: + _constraints.add(child as Constraint); break; } } @@ -168,6 +184,10 @@ abstract class TransformComponent extends TransformComponentBase { _clippingShapes.remove(child as ClippingShape); addDirt(ComponentDirt.clip, recurse: true); } + break; + case IKConstraintBase.typeKey: + _constraints.remove(child as Constraint); + break; } } diff --git a/lib/src/runtime_artboard.dart b/lib/src/runtime_artboard.dart index 5c7b52d..119fafa 100644 --- a/lib/src/runtime_artboard.dart +++ b/lib/src/runtime_artboard.dart @@ -1,9 +1,9 @@ import 'package:flutter/foundation.dart'; import 'package:rive/rive.dart'; +import 'package:rive/src/core/core.dart'; import 'package:rive/src/rive_core/artboard.dart'; import 'package:rive/src/rive_core/component.dart'; import 'package:rive/src/rive_core/event.dart'; -import 'package:rive/src/core/core.dart'; /// Adds getters for linear animations and state machines extension RuntimeArtboardGetters on RuntimeArtboard {