Struct rusty_spine::Bone

source ·
pub struct Bone { /* private fields */ }
Expand description

A bone within the Skeleton hierarchy.

Spine API Reference

Bones can be acquired from a Skeleton and a safe BoneHandle can be obtained using the Bone::handle method to store long-term references to a specific bone.

The hierarchy can be traversed using Bone::parent and Bone::children, and specific bones can be located using Skeleton::find_bone.

Implementations§

source§

impl Bone

source

pub fn set_to_setup_pose(&mut self)

Sets this bone’s local transform to the setup pose.

source

pub fn update(&mut self)

Computes the world transform using the parent bone and this bone’s local applied transform.

source

pub fn update_world_transform(&mut self)

Computes the world transform using the parent bone and this bone’s local transform.

See update_world_transform_with.

source

pub fn update_world_transform_with( &mut self, x: f32, y: f32, rotation: f32, scale_x: f32, scale_y: f32, shear_x: f32, shear_y: f32 )

Computes the world transform using the parent bone and the specified local transform. The applied transform is set to the specified local transform. Child bones are not updated.

See World transforms in the Spine Runtimes Guide.

source

pub fn update_applied_transform(&mut self)

Computes the applied transform values from the world transform.

If the world transform is modified (by a constraint, rotate_world, etc) then this method should be called so the applied transform matches the world transform. The applied transform may be needed by other code (eg to apply another constraint).

Some information is ambiguous in the world transform, such as -1,-1 scale versus 180 rotation. The applied transform after calling this method is equivalent to the local transform used to compute the world transform, but may not be identical.

source

pub fn world_rotation_x(&self) -> f32

The world rotation for the X axis, calculated using a and c.

source

pub fn world_rotation_y(&self) -> f32

The world rotation for the Y axis, calculated using b and d.

source

pub fn world_scale_x(&self) -> f32

The magnitude (always positive) of the world scale X, calculated using a and c.

source

pub fn world_scale_y(&self) -> f32

The magnitude (always positive) of the world scale Y, calculated using b and d.

source

pub fn world_to_local(&self, world_x: f32, world_y: f32) -> (f32, f32)

Transforms a point from world coordinates to the bone’s local coordinates.

source

pub fn local_to_world(&self, local_x: f32, local_y: f32) -> (f32, f32)

Transforms a point from the bone’s local coordinates to world coordinates.

source

pub fn world_to_local_rotation(&self, world_rotation: f32) -> f32

Transforms a world rotation to a local rotation.

source

pub fn local_to_world_rotation(&self, local_rotation: f32) -> f32

Transforms a local rotation to a world rotation.

source

pub fn rotate_world(&self, degrees: f32)

Rotates the world transform the specified amount.

After changes are made to the world transform, update_applied_transform should be called and update will need to be called on any child bones, recursively.

source

pub fn handle(&self) -> BoneHandle

Create a persistent BoneHandle to this Bone.

source

pub fn x(&self) -> f32

The local x translation.

source

pub fn set_x(&mut self, value: f32)

Set the local x translation.

source

pub fn y(&self) -> f32

The local y translation.

source

pub fn set_y(&mut self, value: f32)

Set the local y translation.

source

pub fn rotation(&self) -> f32

The local rotation in degrees, counter clockwise.

source

pub fn set_rotation(&mut self, value: f32)

Set the local rotation in degrees, counter clockwise.

source

pub fn scale_x(&self) -> f32

The local scaleX.

source

pub fn set_scale_x(&mut self, value: f32)

Set the local scaleX.

source

pub fn scale_y(&self) -> f32

The local scaleY.

source

pub fn set_scale_y(&mut self, value: f32)

Set the local scaleY.

source

pub fn shear_x(&self) -> f32

The local shearX.

source

pub fn set_shear_x(&mut self, value: f32)

Set the local shearX.

source

pub fn shear_y(&self) -> f32

The local shearY.

source

pub fn set_shear_y(&mut self, value: f32)

Set the local shearY.

source

pub fn applied_x(&self) -> f32

The applied local x translation.

source

pub fn set_applied_x(&mut self, value: f32)

Set the applied local x translation.

source

pub fn applied_y(&self) -> f32

The applied local y translation.

source

pub fn set_applied_y(&mut self, value: f32)

Set the applied local y translation.

source

pub fn applied_rotation(&self) -> f32

The applied local rotation in degrees, counter clockwise.

source

pub fn set_applied_rotation(&mut self, value: f32)

Set the applied local rotation in degrees, counter clockwise.

source

pub fn applied_scale_x(&self) -> f32

The applied local scaleX.

source

pub fn set_applied_scale_x(&mut self, value: f32)

Set the applied local scaleX.

source

pub fn applied_scale_y(&self) -> f32

The applied local scaleY.

source

pub fn set_applied_scale_y(&mut self, value: f32)

Set the applied local scaleY.

source

pub fn applied_shear_x(&self) -> f32

The applied local shearX.

source

pub fn set_applied_shear_x(&mut self, value: f32)

Set the applied local shearX.

source

pub fn applied_shear_y(&self) -> f32

The applied local shearY.

source

pub fn set_applied_shear_y(&mut self, value: f32)

Set the applied local shearY.

source

pub fn a(&self) -> f32

Part of the world transform matrix for the X axis.

source

pub fn set_a(&mut self, value: f32)

Set part of the world transform matrix for the X axis. If changed, update_applied_transform should be called.

source

pub fn b(&self) -> f32

Part of the world transform matrix for the Y axis.

source

pub fn set_b(&mut self, value: f32)

Set part of the world transform matrix for the Y axis. If changed, update_applied_transform should be called.

source

pub fn c(&self) -> f32

Part of the world transform matrix for the X axis.

source

pub fn set_c(&mut self, value: f32)

Set part of the world transform matrix for the X axis. If changed, update_applied_transform should be called.

source

pub fn d(&self) -> f32

Part of the world transform matrix for the Y axis.

source

pub fn set_d(&mut self, value: f32)

Set part of the world transform matrix for the Y axis. If changed, update_applied_transform should be called.

source

pub fn world_x(&self) -> f32

Set the world X position.

source

pub fn set_world_x(&mut self, value: f32)

The world X position. If changed, update_applied_transform should be called.

source

pub fn world_y(&self) -> f32

The world Y position.

source

pub fn set_world_y(&mut self, value: f32)

Set the world Y position. If changed, update_applied_transform should be called.

source

pub fn sorted(&self) -> bool

source

pub fn active(&self) -> bool

source

pub fn data(&self) -> CTmpRef<'_, Self, BoneData>

The bone’s setup pose data.

source

pub fn data_mut(&mut self) -> CTmpMut<'_, Self, BoneData>

The bone’s mutable setup pose data.

source

pub fn parent(&self) -> Option<CTmpRef<'_, Self, Bone>>

source

pub fn parent_mut(&mut self) -> Option<CTmpMut<'_, Self, Bone>>

source

pub fn children_count(&self) -> usize

source

pub fn children(&self) -> CTmpPtrIterator<'_, Bone, Bone, spBone>

An iterator over the children of this bone.

use rusty_spine::{BoneHandle, Skeleton};

fn traverse_bones(
    bone_handle: BoneHandle,
    skeleton: &Skeleton,
    ident: usize,
) {
    if let Some(bone) = bone_handle.get(skeleton) {
        println!(
            "{:ident$}{name}",
            "",
            ident = ident,
            name = bone.data().name()
        );
        for child in bone.children() {
            traverse_bones(child.handle(), skeleton, ident + 2);
        }
    }
}

// Traverse all bones in a skeleton
let root_bone = skeleton.bone_root().handle();
traverse_bones(root_bone, &skeleton, 0);
source

pub fn children_at_index(&self, index: usize) -> Option<CTmpRef<'_, Self, Bone>>

source

pub fn children_mut(&mut self) -> CTmpMutIterator<'_, Bone, Bone, spBone>

source

pub fn children_at_index_mut( &mut self, index: usize ) -> Option<CTmpMut<'_, Self, Bone>>

source

pub fn set_y_down(y_down: bool)

source

pub fn is_y_down() -> bool

source

pub const fn c_ptr(&self) -> *mut spBone

Get a pointer to the underlying spine-c type.

source§

impl Bone

Functions available if using the mint feature.

source

pub fn position(&self) -> Vector2<f32>

The local translation.

source

pub fn set_position(&mut self, position: impl Into<Vector2<f32>>)

Set the local translation.

source

pub fn world_position(&self) -> Vector2<f32>

The world translation.

source

pub fn set_world_position(&mut self, position: impl Into<Vector2<f32>>)

Set the world translation.

source

pub fn applied_position(&self) -> Vector2<f32>

The applied translation.

source

pub fn set_applied_position(&mut self, position: impl Into<Vector2<f32>>)

Set the applied translation.

source

pub fn scale(&self) -> Vector2<f32>

The local scale.

source

pub fn set_scale(&mut self, scale: impl Into<Vector2<f32>>)

Set the local scale.

source

pub fn world_scale(&self) -> Vector2<f32>

The world scale.

source

pub fn applied_scale(&self) -> Vector2<f32>

The applied scale.

source

pub fn set_applied_scale(&mut self, scale: impl Into<Vector2<f32>>)

Set the applied scale.

source

pub fn shear(&self) -> Vector2<f32>

The local shear.

source

pub fn set_shear(&mut self, shear: impl Into<Vector2<f32>>)

Set the local shear.

source

pub fn applied_shear(&self) -> Vector2<f32>

The applied shear.

source

pub fn set_applied_shear(&mut self, shear: impl Into<Vector2<f32>>)

Set the applied shear.

source

pub fn world_rotation(&self) -> Vector2<f32>

source

pub fn update_world_transform_with2( &mut self, position: Vector2<f32>, rotation: f32, scale: Vector2<f32>, shear: Vector2<f32> )

Trait Implementations§

source§

impl Debug for Bone

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl NewFromPtr<spBone> for Bone

source§

unsafe fn new_from_ptr(c_bone: *mut spBone) -> Self

Auto Trait Implementations§

§

impl Freeze for Bone

§

impl RefUnwindSafe for Bone

§

impl Send for Bone

§

impl Sync for Bone

§

impl Unpin for Bone

§

impl UnwindSafe for Bone

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.