Skip to content

Commit

Permalink
Add programmatic character animation
Browse files Browse the repository at this point in the history
Also update crosscomp to deb822
  • Loading branch information
Ravbug committed Nov 13, 2024
1 parent 6b7f0a2 commit 4a0a263
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 10 deletions.
2 changes: 1 addition & 1 deletion RavEngine
39 changes: 35 additions & 4 deletions Samples/Animation/Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ enum CharAnims {
PoundBegin,
InPound,
PoundEnd,
Wave
Wave,
HeadTurn
};


Expand Down Expand Up @@ -358,24 +359,54 @@ void Character::Create(Ref<MeshCollectionSkinned> mesh, Ref<MeshCollectionStatic
layer->InsertState(pound_end_state);
layer->InsertState(pound_do_state);

// arm wave animation
auto waveLayer = animcomp.AddLayer();
waveLayer->SetWeight(0);
waveLayer->InsertState(waveState);

auto mask = RavEngine::New<SkeletonMask>(skeleton, 0); // we only want to enable the arm on this layer
waveLayer->SetSkeletonMask(mask);
mask->SetMaskForJoint(skeleton->IndexForBone("character:arm_l").value(),1);
auto waveMask = RavEngine::New<SkeletonMask>(skeleton, 0); // we only want to enable the arm on this layer
waveLayer->SetSkeletonMask(waveMask);
waveMask->SetMaskForJoint(skeleton->IndexForBone("character:arm_l").value(),1);

// procedural head animation
struct HeadAnimation : public CustomSkeletonAnimationFunction{
uint16_t headBone;
HeadAnimation(uint16_t headBone) : headBone(headBone){}

bool operator()(BoneTransforms transforms, const ozz::animation::Skeleton* skeleton, float t, float start, float end, bool loop){
auto headTransform = transforms.GetBone(headBone);

headTransform.rotation = vector3{0, std::sin(t * 2) ,0};

transforms.SetBone(headBone, headTransform);

return false;
}
};

auto headBone = skeleton->IndexForBone("character:head").value();
auto headAnimation = New<CustomSkeletonAnimation>(HeadAnimation{headBone});
auto headMask = New<SkeletonMask>(skeleton, 0);
headMask->SetMaskForJoint(headBone, 1);

auto headLayer = animcomp.AddLayer();
headLayer->SetWeight(1);
headLayer->InsertState({CharAnims::HeadTurn,headAnimation});
headLayer->SetSkeletonMask(headMask);


// initialize the state machine
// if an entry state is not set before play, your game will crash.
layer->Goto(CharAnims::Idle, true);
waveLayer->Goto(CharAnims::Wave, true);
headLayer->Goto(CharAnims::HeadTurn, true);

// begin playing the animator controller.
// animator controllers are asynchronous to your other code
// so play and pause simply signal the controller to perform an action
layer->Play();
waveLayer->Play();
headLayer->Play();
animcomp.debugEnabled = true;
}

Expand Down
33 changes: 28 additions & 5 deletions config/crosscomp-sources.list
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ noble main restricted universe
deb [arch=amd64] http://security.ubuntu.com/ubuntu/ noble-security main restricted universe
deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ noble-updates main restricted universe
Types: deb
URIs: http://archive.ubuntu.com/ubuntu/
Suites: noble
Components: main restricted universe
Architectures: amd64

deb [arch=arm64] http://azure.ports.ubuntu.com/ubuntu-ports/ noble main restricted multiverse universe
deb [arch=arm64] http://azure.ports.ubuntu.com/ubuntu-ports/ noble-updates main restricted multiverse universe
Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main restricted universe
Architectures: amd64

Types: deb
URIs: http://archive.ubuntu.com/ubuntu/
Suites: noble-updates
Components: main restricted universe
Architectures: amd64

Types: deb
URIs: http://ports.ubuntu.com/ubuntu-ports/
Suites: noble
Components: main restricted multiverse universe
Architectures: arm64

Types: deb
URIs: http://ports.ubuntu.com/ubuntu-ports/
Suites: noble-updates
Components: main restricted multiverse universe
Architectures: arm64

0 comments on commit 4a0a263

Please sign in to comment.