8#define M_PI 3.14159265358979323846
14float degToRad(
float deg) {
return deg *
static_cast<float>(
M_PI / 180.0); }
18 if (!data_)
throw Exception(
"SpineSkeleton: data is null");
19 bones_.resize(
static_cast<size_t>(data_->
getBoneCount()));
20 slotAttachments_.resize(
static_cast<size_t>(data_->
getSlotCount()));
22 if (skinIndex_ < 0) skinIndex_ = 0;
27void SpineSkeleton::checkBone(
int index)
const {
29 throw Exception(
"SpineSkeleton: bone index %d out of range",
index);
31void SpineSkeleton::checkSlot(
int index)
const {
33 throw Exception(
"SpineSkeleton: slot index %d out of range",
index);
41 if (
idx < 0)
return false;
48 const auto &
b = data_->
bone(i);
49 BonePose &
p = bones_[
static_cast<size_t>(i)];
52 p.rotation =
b.rotation;
57 slotAttachments_[
static_cast<size_t>(i)] = data_->
slot(i).
attachment;
62 BonePose &
p = bones_[
static_cast<size_t>(i)];
64 const float rad = degToRad(
p.rotation);
65 const float cos = std::cos(rad);
66 const float sin = std::sin(rad);
67 const float la = cos *
p.scaleX;
68 const float lb = -sin *
p.scaleY;
69 const float lc = sin *
p.scaleX;
70 const float ld = cos *
p.scaleY;
79 p.worldRot =
p.rotation;
83 const BonePose &pp = bones_[
static_cast<size_t>(
parent)];
84 p.worldX = pp.a *
p.x + pp.b *
p.y + pp.worldX;
85 p.worldY = pp.c *
p.x + pp.d *
p.y + pp.worldY;
86 p.a = pp.a * la + pp.b * lc;
87 p.b = pp.a * lb + pp.b * ld;
88 p.c = pp.c * la + pp.d * lc;
89 p.d = pp.c * lb + pp.d * ld;
90 p.worldRot = pp.worldRot +
p.rotation;
91 p.worldSX = pp.worldSX *
p.scaleX;
92 p.worldSY = pp.worldSY *
p.scaleY;
99 return bones_[
static_cast<size_t>(
index)].
x;
103 return bones_[
static_cast<size_t>(
index)].
y;
111 return bones_[
static_cast<size_t>(
index)].scaleX;
115 return bones_[
static_cast<size_t>(
index)].scaleY;
120 bones_[
static_cast<size_t>(
index)].
x =
x;
124 bones_[
static_cast<size_t>(
index)].
y =
y;
132 bones_[
static_cast<size_t>(
index)].scaleX =
sx;
136 bones_[
static_cast<size_t>(
index)].scaleY =
sy;
141 return bones_[
static_cast<size_t>(
index)].worldX;
145 return bones_[
static_cast<size_t>(
index)].worldY;
149 return bones_[
static_cast<size_t>(
index)].worldRot;
153 return bones_[
static_cast<size_t>(
index)].worldSX;
157 return bones_[
static_cast<size_t>(
index)].worldSY;
162 const BonePose &
p = bones_[
static_cast<size_t>(
index)];
170 checkSlot(slotIndex);
171 return slotAttachments_[
static_cast<size_t>(slotIndex)];
175 checkSlot(slotIndex);
176 slotAttachments_[
static_cast<size_t>(slotIndex)] =
name;
180 checkSlot(slotIndex);
181 const std::string &
name = slotAttachments_[
static_cast<size_t>(slotIndex)];
182 if (
name.empty())
return nullptr;
187 if (def >= 0 && def != skinIndex_)
return data_->
findAttachment(def, slotIndex,
name);
std::array< float, 4 > rotation
EVENGINE_API_FOUNDATION public API.
Spine skeleton JSON data (bones / slots / skins / animations).
int findSkin(const std::string &name) const
Finds skin.
const RegionAttachment * findAttachment(int skinIndex, int slotIndex, const std::string &name) const
const SlotData & slot(int i) const
int getBoneCount() const
Returns the bone count.
int getDefaultSkin() const
Returns the default skin.
int getSlotCount() const
Returns the slot count.
const BoneData & bone(int i) const
void setBoneLocalScaleY(int index, float sy)
Sets the bone local scale y.
float getBoneWorldScaleY(int index) const
Returns the bone world scale y.
float getBoneLocalScaleY(int index) const
Returns the bone local scale y.
float getBoneWorldScaleX(int index) const
Returns the bone world scale x.
float getBoneWorldRotation(int index) const
Returns the bone world rotation.
void setBoneLocalScaleX(int index, float sx)
Sets the bone local scale x.
float getBoneLocalScaleX(int index) const
Returns the bone local scale x.
bool setSkin(const std::string &name)
Sets the skin.
void setToSetupPose()
Sets the to setup pose.
SpineSkeleton(SpineSkeletonData *data)
Spine skeleton.
float getBoneLocalX(int index) const
Returns the bone local x.
const SpineSkeletonData::RegionAttachment * getSlotRegion(int slotIndex) const
Returns the slot region.
std::string getSlotAttachmentName(int slotIndex) const
Returns the slot attachment name.
int getSlotCount() const
Returns the slot count.
void getBoneWorldMatrix(int index, float &a, float &b, float &c, float &d) const
World 2x2 matrix columns (a,c) / (b,d) used for local→world offset.
float getBoneLocalRotation(int index) const
Returns the bone local rotation.
void setBoneLocalRotation(int index, float degrees)
Sets the bone local rotation.
int getBoneCount() const
Returns the bone count.
float getBoneWorldY(int index) const
Returns the bone world y.
void setBoneLocalX(int index, float x)
Sets the bone local x.
void updateWorldTransform()
Updates world transform.
void setSlotAttachmentName(int slotIndex, const std::string &name)
Sets the slot attachment name.
float getBoneLocalY(int index) const
Returns the bone local y.
void setBoneLocalY(int index, float y)
Sets the bone local y.
float getBoneWorldX(int index) const
Returns the bone world x.