first animatable object interface iteration

This commit is contained in:
devZoGok
2021-10-19 19:06:41 +03:00
parent 2ae7f2efdd
commit 53bf4f41bd
19 changed files with 174 additions and 139 deletions
+4 -76
View File
@@ -31,91 +31,19 @@ namespace vb01{
}
void AnimationController::transform(AnimationChannel *channel){
vector<Node*> transformNodes;
if(node)
transformNodes.push_back(node);
for(Bone *channelBone : channel->getBones())
transformNodes.push_back((Node*)channelBone);
Animation *animation = getAnimation(channel->getAnimationName());
for(Node *transformNode : transformNodes){
Vector3 currentPos;
Quaternion currentRot;
Vector3 currentScale;
bool objectNode = node && node->getName() == transformNode->getName();
if(objectNode){
currentPos = transformNode->getPosition();
currentRot = transformNode->getOrientation();
currentScale = transformNode->getScale();
}
else{
Bone *channelBone = (Bone*)transformNode;
currentPos = channelBone->getPosePos();
currentRot = channelBone->getPoseRot();
currentScale = channelBone->getPoseScale();
}
vector<KeyframeChannel> keyframeChannels = animation->getKeyframeChannelsByNode(transformNode);
for(Animatable *animatable : channel->getAnimatables()){
vector<KeyframeChannel> keyframeChannels = animation->getKeyframeChannelsByAnimatable(animatable);
for(KeyframeChannel keyframeChannel : keyframeChannels){
Keyframe pastKeyframe = findKeyframe(channel, keyframeChannel, true);
Keyframe nextKeyframe = findKeyframe(channel, keyframeChannel, false);
int pastFrame = pastKeyframe.frame;
int nextFrame = nextKeyframe.frame;
Keyframe::Interpolation interp = pastKeyframe.interpolation;
float ratio = (float)(max(0, channel->getCurrentFrame() - pastFrame)) / (nextFrame - pastFrame);
Keyframe::Interpolation interp = pastKeyframe.interpolation;
float value = interpolate(pastKeyframe.value, nextKeyframe.value, interp, ratio);
setFrameValue(value, keyframeChannel.type, currentPos, currentRot, currentScale);
animatable->animate(value, keyframeChannel);
}
if(objectNode){
transformNode->setPosition(currentPos);
transformNode->setOrientation(currentRot);
transformNode->setScale(currentScale);
}
else{
Bone *channelBone = (Bone*)transformNode;
channelBone->setPosePos(currentPos);
channelBone->setPoseRot(currentRot);
channelBone->setPoseScale(currentScale);
}
}
}
void AnimationController::setFrameValue(float value, KeyframeChannelType type, Vector3 &currentPos, Quaternion &currentRot, Vector3 &currentScale){
switch(type){
case KeyframeChannel::POS_X:
currentPos.x = value;
break;
case KeyframeChannel::POS_Y:
currentPos.y = value;
break;
case KeyframeChannel::POS_Z:
currentPos.z = value;
break;
case KeyframeChannel::ROT_W:
currentRot.w = value;
break;
case KeyframeChannel::ROT_X:
currentRot.x = value;
break;
case KeyframeChannel::ROT_Y:
currentRot.y = value;
break;
case KeyframeChannel::ROT_Z:
currentRot.z = value;
break;
case KeyframeChannel::SCALE_X:
currentScale.x = value;
break;
case KeyframeChannel::SCALE_Y:
currentScale.y = value;
break;
case KeyframeChannel::SCALE_Z:
currentScale.z = value;
break;
case KeyframeChannel::VALUE:
break;
}
}