[cpp] 4.3 porting WIP

This commit is contained in:
Mario Zechner 2025-06-11 15:21:35 +02:00
parent e3fb50da5b
commit 366291deaf
8 changed files with 96 additions and 33 deletions

View File

@ -38,6 +38,9 @@
namespace spine {
/// Stores a bone's local pose.
class SP_API BoneLocal : public Pose<BoneLocal> {
friend class BoneTimeline1;
friend class RotateTimeline;
RTTI_DECL
protected:

View File

@ -31,8 +31,13 @@
#define Spine_BoneTimeline_h
#include <spine/dll.h>
#include <spine/CurveTimeline.h>
namespace spine {
class Skeleton;
class Event;
class BoneLocal;
/// An interface for timelines which change the property of a bone.
class SP_API BoneTimeline {
public:
@ -42,6 +47,33 @@ namespace spine {
/// The index of the bone in Skeleton::getBones() that will be changed when this timeline is applied.
virtual int getBoneIndex() = 0;
};
/// Base class for timelines that animate a single bone property.
class SP_API BoneTimeline1 : public CurveTimeline1, public BoneTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class AnimationState;
RTTI_DECL
public:
BoneTimeline1(size_t frameCount, size_t bezierCount, int boneIndex, Property property);
virtual void
apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha, MixBlend blend,
MixDirection direction, bool appliedPose) override;
virtual int getBoneIndex() override { return _boneIndex; }
void setBoneIndex(int inValue) { _boneIndex = inValue; }
protected:
/// Applies changes to the pose based on the timeline values.
virtual void apply(BoneLocal &pose, BoneLocal &setup, float time, float alpha, MixBlend blend,
MixDirection direction) = 0;
int _boneIndex;
};
}
#endif

View File

@ -37,6 +37,7 @@ namespace spine {
template<class D, class P, class A>
class SP_API Posed : public SpineObject {
friend class AnimationState;
friend class BoneTimeline1;
friend class RotateTimeline;
friend class IkConstraint;
friend class TransformConstraint;

View File

@ -42,6 +42,24 @@ namespace spine {
class SP_API PosedData : public SpineObject {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class BoneTimeline1;
friend class RotateTimeline;
friend class AttachmentTimeline;
friend class RGBATimeline;
friend class RGBTimeline;
friend class AlphaTimeline;
friend class RGBA2Timeline;
friend class RGB2Timeline;
friend class ScaleTimeline;
friend class ScaleXTimeline;
friend class ScaleYTimeline;
friend class ShearTimeline;
friend class ShearXTimeline;
friend class ShearYTimeline;
friend class TranslateTimeline;
friend class TranslateXTimeline;
friend class TranslateYTimeline;
friend class InheritTimeline;
private:
spine::String _name;

View File

@ -30,10 +30,11 @@
#ifndef Spine_RotateTimeline_h
#define Spine_RotateTimeline_h
#include <spine/CurveTimeline.h>
#include <spine/BoneTimeline.h>
namespace spine {
class SP_API RotateTimeline : public CurveTimeline1 {
/// Changes a bone's local rotation.
class SP_API RotateTimeline : public BoneTimeline1 {
friend class SkeletonBinary;
friend class SkeletonJson;
@ -45,16 +46,9 @@ namespace spine {
public:
explicit RotateTimeline(size_t frameCount, size_t bezierCount, int boneIndex);
virtual void
apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha, MixBlend blend,
MixDirection direction);
int getBoneIndex() { return _boneIndex; }
void setBoneIndex(int inValue) { _boneIndex = inValue; }
private:
int _boneIndex;
protected:
virtual void apply(BoneLocal &pose, BoneLocal &setup, float time, float alpha, MixBlend blend,
MixDirection direction) override;
};
}

View File

@ -107,6 +107,8 @@ namespace spine {
friend class TransformConstraintTimeline;
friend class BoneTimeline1;
friend class RotateTimeline;
friend class TranslateTimeline;

View File

@ -29,10 +29,36 @@
#include <spine/BoneTimeline.h>
#include <spine/Event.h>
#include <spine/Skeleton.h>
#include <spine/Bone.h>
#include <spine/BoneData.h>
#include <spine/BoneLocal.h>
#include <spine/Property.h>
using namespace spine;
BoneTimeline::BoneTimeline() {
}
BoneTimeline::~BoneTimeline() {
}
RTTI_IMPL(BoneTimeline1, CurveTimeline1)
BoneTimeline1::BoneTimeline1(size_t frameCount, size_t bezierCount, int boneIndex, Property property) :
CurveTimeline1(frameCount, bezierCount), _boneIndex(boneIndex) {
PropertyId ids[] = {((PropertyId) property << 32) | boneIndex};
setPropertyIds(ids, 1);
}
void BoneTimeline1::apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha,
MixBlend blend, MixDirection direction, bool appliedPose) {
SP_UNUSED(lastTime);
SP_UNUSED(pEvents);
Bone *bone = skeleton._bones[_boneIndex];
if (bone->isActive()) {
apply(appliedPose ? *bone->_applied : bone->_pose, *bone->_data._setup, time, alpha, blend, direction);
}
}

View File

@ -29,31 +29,18 @@
#include <spine/RotateTimeline.h>
#include <spine/Event.h>
#include <spine/Skeleton.h>
#include <spine/Animation.h>
#include <spine/Bone.h>
#include <spine/BoneData.h>
#include <spine/Property.h>
#include <spine/BoneLocal.h>
using namespace spine;
RTTI_IMPL(RotateTimeline, CurveTimeline1)
RTTI_IMPL(RotateTimeline, BoneTimeline1)
RotateTimeline::RotateTimeline(size_t frameCount, size_t bezierCount, int boneIndex) : CurveTimeline1(frameCount,
bezierCount),
_boneIndex(boneIndex) {
PropertyId ids[] = {((PropertyId) Property_Rotate << 32) | boneIndex};
setPropertyIds(ids, 1);
RotateTimeline::RotateTimeline(size_t frameCount, size_t bezierCount, int boneIndex) :
BoneTimeline1(frameCount, bezierCount, boneIndex, Property_Rotate) {
}
void RotateTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vector<Event *> *pEvents, float alpha,
MixBlend blend, MixDirection direction) {
SP_UNUSED(lastTime);
SP_UNUSED(pEvents);
void RotateTimeline::apply(BoneLocal &pose, BoneLocal &setup, float time, float alpha, MixBlend blend,
MixDirection direction) {
SP_UNUSED(direction);
Bone *bone = skeleton._bones[_boneIndex];
if (bone->isActive()) bone->_rotation = getRelativeValue(time, alpha, blend, bone->_rotation, bone->getData()._rotation);
}
pose._rotation = getRelativeValue(time, alpha, blend, pose._rotation, setup._rotation);
}