animation keyframe channels now use animatable names

This commit is contained in:
devZoGok
2022-03-11 10:17:00 +02:00
parent a19547782b
commit fa1d0d277c
14 changed files with 32 additions and 37 deletions
+2 -2
View File
@@ -17,7 +17,7 @@ set(MATH quaternion.cpp vector.cpp matrix.cpp ray.cpp)
set(RENDER lineRenderer.cpp particleEmitter.cpp camera.cpp light.cpp material.cpp mesh.cpp model.cpp node.cpp quad.cpp box.cpp root.cpp shader.cpp texture.cpp)
set(ANIM animationController.cpp animationChannel.cpp animation.cpp animatable.cpp keyframeChannel.cpp driver.cpp)
set(ARMATURE skeleton.cpp bone.cpp ikSolver.cpp)
set(ASSET_READERS abstractAssetReader.cpp imageReader.cpp fontReader.cpp modelReader.cpp assimpModelReader.cpp vbModelReader.cpp xmlModelReader.cpp)
set(ASSET_READERS abstractAssetReader.cpp imageReader.cpp fontReader.cpp modelReader.cpp assimpModelReader.cpp xmlModelReader.cpp)
set(ASSET_MANAGER assetManager.cpp textAsset.h imageAsset.h modelAsset.h fontAsset.h)
set(LIB_SRC ${RENDER} ${MATH} ${UTILS} ${GUI} ${ARMATURE} ${ASSET_MANAGER} ${ASSET_READERS} ${ANIM})
@@ -77,7 +77,7 @@ if(BUILD_TESTS)
set(ARMATURE_TEST boneTest.cpp ikSolverTest.cpp)
set(MODEL_TEST vbModelReaderTest.cpp)
set(ANIMATION_TEST animationChannelTest.cpp)
set(TEST_SRC main.cpp ${LIB_SRC} ${RENDER_TEST} ${ARMATURE_TEST} ${MODEL_TEST} ${ANIMATION_TEST})
set(TEST_SRC main.cpp ${LIB_SRC} ${RENDER_TEST} ${ARMATURE_TEST} ${ANIMATION_TEST})
add_executable(vb01Tests ${TEST_SRC})
target_link_libraries(vb01Tests ${LIB_NAME} ${DEPS} cppunit)
+2 -2
View File
@@ -7,7 +7,7 @@ namespace vb01{
this->name = name;
}
KeyframeChannel* Animation::getKeyframeChannel(Animatable *animatable, KeyframeChannelType type){
KeyframeChannel* Animation::getKeyframeChannel(string animatable, KeyframeChannelType type){
KeyframeChannel *k = nullptr;
for(KeyframeChannel &channel : keyframeChannels)
@@ -19,7 +19,7 @@ namespace vb01{
return k;
}
vector<KeyframeChannel> Animation::getKeyframeChannelsByAnimatable(Animatable *animatable){
vector<KeyframeChannel> Animation::getKeyframeChannelsByAnimatable(string animatable){
vector<KeyframeChannel> channels;
for(KeyframeChannel channel : keyframeChannels)
+2 -2
View File
@@ -13,8 +13,8 @@ namespace vb01{
public:
Animation(std::string);
~Animation(){}
KeyframeChannel* getKeyframeChannel(Animatable*, KeyframeChannel::Type);
std::vector<KeyframeChannel> getKeyframeChannelsByAnimatable(Animatable*);
KeyframeChannel* getKeyframeChannel(std::string, KeyframeChannel::Type);
std::vector<KeyframeChannel> getKeyframeChannelsByAnimatable(std::string);
inline void addKeyframeChannels(std::vector<KeyframeChannel> keyframeChannels){this->keyframeChannels.assign(keyframeChannels.begin(), keyframeChannels.end());}
inline void addKeyframeChannel(KeyframeChannel channel){keyframeChannels.push_back(channel);}
inline std::string getName(){return name;}
+1 -1
View File
@@ -22,7 +22,7 @@ namespace vb01{
KeyframeChannel kc;
kc.type = KeyframeChannel::Type::POS_X;
kc.keyframes = vector<Keyframe>({k1, k2});
kc.animatable = bone;
kc.animatable = bone->getName();
Animation *anim = new Animation("anim");
anim->addKeyframeChannel(kc);
+1 -1
View File
@@ -25,7 +25,7 @@ namespace vb01{
Animation *animation = getAnimation(channel->getAnimationName());
for(Animatable *animatable : channel->getAnimatables()){
vector<KeyframeChannel> keyframeChannels = animation->getKeyframeChannelsByAnimatable(animatable);
vector<KeyframeChannel> keyframeChannels = animation->getKeyframeChannelsByAnimatable(animatable->getName());
for(KeyframeChannel keyframeChannel : keyframeChannels){
int currentFrame = channel->getCurrentFrame();
+6 -2
View File
@@ -6,7 +6,8 @@
using namespace std;
namespace vb01{
Driver::Driver(KeyframeChannel keyframeChannel, VariableType type){
Driver::Driver(Animatable *animatable, KeyframeChannel keyframeChannel, VariableType type){
this->animatable = animatable;
this->keyframeChannel = keyframeChannel;
this->type = type;
}
@@ -18,16 +19,18 @@ namespace vb01{
float nextFrame = nextKeyframe.frame;
float ratio = (float)(driverValue - pastFrame) / (nextFrame - pastFrame);
if(ratio < 0)
ratio = 0;
Keyframe::Interpolation interp = pastKeyframe.interpolation;
float value = KeyframeChannel::interpolate(pastKeyframe, nextKeyframe, ratio);
keyframeChannel.animatable->animate(value, keyframeChannel);
animatable->animate(value, keyframeChannel);
}
Driver::VariableType Driver::getDriverVariableType(string typeString){
VariableType type;
if(typeString == "LOC_X")
type = Driver::POS_X;
else if(typeString == "LOC_Y")
@@ -48,6 +51,7 @@ namespace vb01{
type = Driver::SCALE_Y;
else if(typeString == "SCALE_Z")
type = Driver::SCALE_Z;
return type;
}
}
+3 -1
View File
@@ -23,14 +23,16 @@ namespace vb01{
SCALE_Z
};
Driver(KeyframeChannel, VariableType);
Driver(Animatable*, KeyframeChannel, VariableType);
void drive(float);
static VariableType getDriverVariableType(std::string);
inline VariableType getType(){return type;}
inline KeyframeChannel& getKeyframeChannel(){return keyframeChannel;}
inline Animatable* getAnimatable(){return animatable;}
private:
VariableType type;
KeyframeChannel keyframeChannel;
Animatable *animatable = nullptr;
};
}
+5 -5
View File
@@ -82,7 +82,7 @@ int main(){
* and frame number.
*/
KeyframeChannel kcL;
kcL.animatable = leftMat->getUniform("diffuseColor");
kcL.animatable = leftMat->getUniform("diffuseColor")->getName();
kcL.type = KeyframeChannel::UNIFORM_1;
kcL.keyframes = vector<Keyframe>({
KeyframeChannel::createKeyframe(Keyframe::LINEAR, 1, 0),
@@ -90,7 +90,7 @@ int main(){
});
KeyframeChannel kcR;
kcR.animatable = rightNode;
kcR.animatable = rightNode->getName();
kcR.type = KeyframeChannel::SCALE_Z;
kcR.keyframes = vector<Keyframe>({
KeyframeChannel::createKeyframe(Keyframe::LINEAR, 1, 0),
@@ -98,7 +98,7 @@ int main(){
});
KeyframeChannel kcD;
kcD.animatable = driver;
kcD.animatable = driver->getName();
kcD.type = KeyframeChannel::POS_Y;
kcD.keyframes = vector<Keyframe>({
KeyframeChannel::createKeyframe(Keyframe::LINEAR, 0, 0),
@@ -110,8 +110,8 @@ int main(){
* A Driver class is given a transform component, e.g, y coordinate of the position
* and uses it to play the Keyframe.
*/
driver->addDriver(new Driver(kcL, Driver::POS_Y));
driver->addDriver(new Driver(kcR, Driver::POS_Y));
driver->addDriver(new Driver(leftMat->getUniform("diffuseColor"), kcL, Driver::POS_Y));
driver->addDriver(new Driver(rightNode, kcR, Driver::POS_Y));
Animation *anim = new Animation("anim");
anim->addKeyframeChannel(kcD);
+1 -1
View File
@@ -121,7 +121,7 @@ namespace vb01{
return keyframe;
}
KeyframeChannel KeyframeChannel::createKeyframeChannel(KeyframeChannelType type, Animatable *animatable, vector<Keyframe> keyframes){
KeyframeChannel KeyframeChannel::createKeyframeChannel(KeyframeChannelType type, string animatable, vector<Keyframe> keyframes){
KeyframeChannel keyframeChannel;
keyframeChannel.type = type;
keyframeChannel.animatable = animatable;
+2 -2
View File
@@ -64,7 +64,7 @@ namespace vb01{
};
Type type;
Animatable *animatable = nullptr;
std::string animatable = "";
std::vector<Keyframe> keyframes;
static float interpolateBezier(std::vector<float>, float);
@@ -73,7 +73,7 @@ namespace vb01{
static float interpolate(Keyframe, Keyframe, float);
static Keyframe findKeyframe(float, KeyframeChannel, bool);
static Keyframe createKeyframe(Keyframe::Interpolation, float, float, float = 0, float = 0, float = 0, float = 0);
static KeyframeChannel createKeyframeChannel(KeyframeChannel::Type, Animatable*, std::vector<Keyframe>);
static KeyframeChannel createKeyframeChannel(KeyframeChannel::Type, std::string, std::vector<Keyframe>);
};
typedef KeyframeChannel::Type KeyframeChannelType;
+2 -2
View File
@@ -87,7 +87,7 @@ int main(){
* and frame number.
*/
KeyframeChannel kcA;
kcA.animatable = light;
kcA.animatable = light->getName();
kcA.type = KeyframeChannel::SPOTLIGHT_OUTER_ANGLE;
kcA.keyframes = vector<Keyframe>({
KeyframeChannel::createKeyframe(Keyframe::LINEAR, .1, 1),
@@ -96,7 +96,7 @@ int main(){
});
KeyframeChannel kcB;
kcA.animatable = light;
kcA.animatable = light->getName();
kcA.type = KeyframeChannel::SPOTLIGHT_INNER_ANGLE;
kcA.keyframes = vector<Keyframe>({
KeyframeChannel::createKeyframe(Keyframe::LINEAR, .1, 1),
-3
View File
@@ -7,7 +7,6 @@
#include "root.h"
#include "skeleton.h"
#include "animation.h"
#include "vbModelReader.h"
#include "xmlModelReader.h"
#include "assimpModelReader.h"
@@ -28,8 +27,6 @@ namespace vb01{
if(extension == "xml")
modelReader = new XmlModelReader(this, path);
else if(extension == "vb")
modelReader = new VbModelReader(this, path);
else
modelReader = new AssimpModelReader(this, path);
}
+3 -3
View File
@@ -83,17 +83,17 @@ int main(){
* and frame number.
*/
KeyframeChannel kcA;
kcA.animatable = texture;
kcA.animatable = texture->getName();
kcA.type = KeyframeChannel::TEXTURE_FRAME_A;
kcA.keyframes = vector<Keyframe>({KeyframeChannel::createKeyframe(Keyframe::CONSTANT, 0, 1)});
KeyframeChannel kcB;
kcB.animatable = texture;
kcB.animatable = texture->getName();
kcB.type = KeyframeChannel::TEXTURE_FRAME_B;
kcB.keyframes = vector<Keyframe>({KeyframeChannel::createKeyframe(Keyframe::CONSTANT, 1, 1)});
KeyframeChannel kcC;
kcC.animatable = texture;
kcC.animatable = texture->getName();
kcC.type = KeyframeChannel::TEXTURE_MIX_RATIO;
kcC.keyframes = vector<Keyframe>({
KeyframeChannel::createKeyframe(Keyframe::LINEAR, 0, 1),
+2 -10
View File
@@ -176,16 +176,8 @@ namespace vb01{
string typeStr = channelEl->Attribute("type");
KeyframeChannel::Type type = KeyframeChannel::getKeyframeChannelType(typeStr);
Animatable *animatable;
string name = channelEl->Attribute("name");
for(Animatable *an : animatables)
if(an->getName() == name){
animatable = an;
break;
}
KeyframeChannel channel = KeyframeChannel::createKeyframeChannel(type, animatable, keyframes);
string channelName = channelEl->Attribute("name");
KeyframeChannel channel = KeyframeChannel::createKeyframeChannel(type, channelName, keyframes);
animation->addKeyframeChannel(channel);
}