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
use crate::{
c::{spBoneData, spTransformConstraintData},
c_interface::{NewFromPtr, SyncPtr},
BoneData,
};
#[cfg(feature = "mint")]
use mint::Vector2;
/// Stores the setup pose for a [`TransformConstraint`](`crate::TransformConstraint`).
///
/// [Spine API Reference](https://esotericsoftware.com/spine-api-reference#TransformConstraintData)
#[derive(Debug)]
pub struct TransformConstraintData {
c_transform_constraint_data: SyncPtr<spTransformConstraintData>,
}
impl NewFromPtr<spTransformConstraintData> for TransformConstraintData {
unsafe fn new_from_ptr(c_slot: *mut spTransformConstraintData) -> Self {
Self {
c_transform_constraint_data: SyncPtr(c_slot),
}
}
}
impl TransformConstraintData {
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_bool!(local, local);
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
/// scale X.
mix_scale_x,
mixScaleX, f32
);
c_accessor!(
/// A percentage (0-1) that controls the mix between the constrained and unconstrained
/// scale Y.
mix_scale_y,
mixScaleY,
f32
);
c_accessor!(
/// A percentage (0-1) that controls the mix between the constrained and unconstrained
/// shear Y.
mix_shear_y,
mixShearY,
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!(
/// An offset added to the constrained bone rotation.
offset_rotation,
offsetRotation,
f32
);
c_accessor!(
/// An offset added to the constrained bone scale X.
offset_scale_x,
offsetScaleX,
f32
);
c_accessor!(
/// An offset added to the constrained bone scale Y.
offset_scale_y,
offsetScaleY,
f32
);
c_accessor!(
///An offset added to the constrained bone shear Y.
offset_shear_y,
offsetShearY,
f32
);
c_accessor!(
/// An offset added to the constrained bone X translation.
offset_x,
offsetX,
f32
);
c_accessor!(
/// An offset added to the constrained bone Y translation.
offset_y,
offsetY,
f32
);
c_accessor_bool!(relative, relative);
c_accessor!(bones_count, bonesCount, usize);
c_accessor_array!(
bones,
bone_at_index,
TransformConstraintData,
BoneData,
spBoneData,
bones,
bones_count
);
c_accessor_tmp_ptr!(
/// The target bone whose world transform will be copied to the constrained bones.
target,
target,
BoneData,
spBoneData
);
c_ptr!(c_transform_constraint_data, spTransformConstraintData);
}
/// Functions available if using the `mint` feature.
#[cfg(feature = "mint")]
impl TransformConstraintData {
#[must_use]
pub fn mix_scale(&self) -> Vector2<f32> {
Vector2 {
x: self.mix_scale_x(),
y: self.mix_scale_y(),
}
}
#[must_use]
pub fn mix(&self) -> Vector2<f32> {
Vector2 {
x: self.mix_x(),
y: self.mix_y(),
}
}
#[must_use]
pub fn offset_scale(&self) -> Vector2<f32> {
Vector2 {
x: self.offset_scale_x(),
y: self.offset_scale_y(),
}
}
#[must_use]
pub fn offset(&self) -> Vector2<f32> {
Vector2 {
x: self.offset_x(),
y: self.offset_y(),
}
}
}