1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
use crate::{
c::{
spBoneData, spPathConstraintData, spPositionMode, spRotateMode, spSlotData, spSpacingMode,
},
c_interface::{NewFromPtr, SyncPtr},
BoneData, SlotData,
};
#[cfg(feature = "mint")]
use mint::Vector2;
/// Stores the setup pose for a [`PathConstraint`](`crate::PathConstraint`).
///
/// [Spine API Reference](https://esotericsoftware.com/spine-api-reference#PathConstraintData)
#[derive(Debug)]
pub struct PathConstraintData {
c_path_constraint_data: SyncPtr<spPathConstraintData>,
}
impl NewFromPtr<spPathConstraintData> for PathConstraintData {
unsafe fn new_from_ptr(c_slot: *mut spPathConstraintData) -> Self {
Self {
c_path_constraint_data: SyncPtr(c_slot),
}
}
}
impl PathConstraintData {
c_accessor_string!(
/// The constraint's name, which is unique across all constraints in the skeleton of the
/// same type.
name,
name
);
c_accessor!(
/// The ordinal of this constraint for the order a skeleton's constraints will be applied by
/// [`Skeleton::update_world_transform`](`crate::Skeleton::update_world_transform`).
order,
order,
i32
);
c_accessor_bool!(
/// When true,
/// [`Skeleton::update_world_transform`](`crate::Skeleton::update_world_transform`) only
/// updates this constraint if the skin contains this constraint.
skin_required,
skinRequired
);
c_accessor_enum!(
/// The mode for positioning the first bone on the path.
position_mode,
positionMode,
PositionMode
);
c_accessor_enum!(
/// The mode for positioning the bones after the first bone on the path.
spacing_mode,
spacingMode,
SpacingMode
);
c_accessor_enum!(
/// The mode for adjusting the rotation of the bones.
rotate_mode,
rotateMode,
RotateMode
);
c_accessor!(
/// An offset added to the constrained bone rotation.
offset_rotation,
offsetRotation,
f32
);
c_accessor!(
/// The position along the path.
position,
position,
f32
);
c_accessor!(
/// The spacing between bones.
spacing,
spacing,
f32
);
c_accessor!(
/// A percentage (0-1) that controls the mix between the constrained and unconstrained rotation.
mix_rotate,
mixRotate,
f32
);
c_accessor!(
/// A percentage (0-1) that controls the mix between the constrained and unconstrained
/// translation X.
mix_x,
mixX,
f32
);
c_accessor!(
/// A percentage (0-1) that controls the mix between the constrained and unconstrained
/// translation Y.
mix_y,
mixY,
f32
);
c_accessor!(bones_count, bonesCount, usize);
c_accessor_array!(
/// The bones that will be modified by this path constraint.
bones,
bone_at_index,
PathConstraintData,
BoneData,
spBoneData,
bones,
bones_count
);
c_accessor_tmp_ptr!(
/// The slot whose path attachment will be used to constrained the bones.
target,
target,
SlotData,
spSlotData
);
c_ptr!(c_path_constraint_data, spPathConstraintData);
}
/// Functions available if using the `mint` feature.
#[cfg(feature = "mint")]
impl PathConstraintData {
#[must_use]
pub fn mix(&self) -> Vector2<f32> {
Vector2 {
x: self.mix_x(),
y: self.mix_y(),
}
}
}
/// Controls how the first bone is positioned along the path.
///
/// [Spine API Reference](https://esotericsoftware.com/spine-api-reference#PositionMode)
pub enum PositionMode {
Fixed = 0,
Percent = 1,
Unknown = 99,
}
impl From<spPositionMode> for PositionMode {
fn from(mode: spPositionMode) -> Self {
match mode {
0 => Self::Fixed,
1 => Self::Percent,
_ => Self::Unknown,
}
}
}
/// Controls how the first bone is positioned along the path.
///
/// [Spine API Reference](https://esotericsoftware.com/spine-api-reference#SpacingMode)
pub enum SpacingMode {
Length = 0,
Fixed = 1,
Percent = 2,
Proportional = 3,
Unknown = 99,
}
impl From<spSpacingMode> for SpacingMode {
fn from(mode: spSpacingMode) -> Self {
match mode {
0 => Self::Length,
1 => Self::Fixed,
2 => Self::Percent,
3 => Self::Proportional,
_ => Self::Unknown,
}
}
}
/// Controls how bones are rotated, translated, and scaled to match the path.
///
/// [Spine API Reference](https://esotericsoftware.com/spine-api-reference#RotateMode)
pub enum RotateMode {
Tangent = 0,
Chain = 1,
ChainScale = 2,
Unknown = 99,
}
impl From<spRotateMode> for RotateMode {
fn from(mode: spRotateMode) -> Self {
match mode {
0 => Self::Tangent,
1 => Self::Chain,
2 => Self::ChainScale,
_ => Self::Unknown,
}
}
}