New models; using raft
This commit is contained in:
@@ -195,13 +195,15 @@ struct AnimationNodeStateMachine : AnimationNode {
|
||||
float fade_speed;
|
||||
Ogre::String mCurrentStateName;
|
||||
bool configured;
|
||||
AnimationNodeStateMachine(float fade_speed)
|
||||
bool debug;
|
||||
AnimationNodeStateMachine(float fade_speed, bool debug = false)
|
||||
: AnimationNode()
|
||||
, currentAnim(nullptr)
|
||||
, nextAnim(nullptr)
|
||||
, fade_speed(fade_speed)
|
||||
, mCurrentStateName("")
|
||||
, configured(false)
|
||||
, debug(debug)
|
||||
{
|
||||
m_weight = 1.0f;
|
||||
}
|
||||
@@ -212,21 +214,33 @@ struct AnimationNodeStateMachine : AnimationNode {
|
||||
configure();
|
||||
configured = true;
|
||||
}
|
||||
if (debug) {
|
||||
std::cout<< "state machine addTime" << std::endl;
|
||||
std::cout << "state machine children: " << children.size() << std::endl;
|
||||
}
|
||||
for (i = 0; i < children.size(); i++) {
|
||||
if (debug)
|
||||
std::cout << "child weight: " << i << " "
|
||||
<< children[i]->getWeight()
|
||||
<< std::endl;
|
||||
AnimationNode *child = children[i];
|
||||
if (fade_in.find(child) != fade_in.end()) {
|
||||
Ogre::Real newWeight =
|
||||
child->getWeight() + time * fade_speed;
|
||||
child->setWeight(Ogre::Math::Clamp<Ogre::Real>(
|
||||
newWeight * m_weight, 0, m_weight));
|
||||
if (newWeight >= m_weight)
|
||||
if (debug) {
|
||||
std::cout << "fade in: " << newWeight << std::endl;
|
||||
std::cout << "m_weight: " << m_weight << std::endl;
|
||||
}
|
||||
if (newWeight >= 1)
|
||||
fade_in.erase(child);
|
||||
}
|
||||
if (fade_out.find(child) != fade_out.end()) {
|
||||
Ogre::Real newWeight =
|
||||
child->getWeight() - time * fade_speed;
|
||||
child->setWeight(Ogre::Math::Clamp<Ogre::Real>(
|
||||
newWeight * m_weight, 0, m_weight));
|
||||
newWeight * m_weight, 0, 1));
|
||||
if (newWeight <= 0)
|
||||
fade_out.erase(child);
|
||||
}
|
||||
@@ -237,6 +251,11 @@ struct AnimationNodeStateMachine : AnimationNode {
|
||||
}
|
||||
void setWeight(float weight)
|
||||
{
|
||||
int i;
|
||||
if (weight > m_weight && currentAnim)
|
||||
fade_in.insert(currentAnim);
|
||||
if (weight < m_weight && currentAnim && currentAnim->getWeight() > weight)
|
||||
currentAnim->setWeight(weight);
|
||||
m_weight = weight;
|
||||
bool enabled = weight > 0.001f;
|
||||
/* do not update child state yet */
|
||||
@@ -253,17 +272,18 @@ struct AnimationNodeStateMachine : AnimationNode {
|
||||
void configure()
|
||||
{
|
||||
int i;
|
||||
std::cout << "children: " << children.size() << std::endl;
|
||||
if (debug)
|
||||
std::cout << "children: " << children.size() << std::endl;
|
||||
for (i = 0; i < children.size(); i++)
|
||||
addState(children[i]);
|
||||
std::cout << "configure called" << std::endl;
|
||||
if (debug)
|
||||
std::cout << "configure called" << std::endl;
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < children.size(); i++) {
|
||||
for (i = 0; i < children.size(); i++)
|
||||
children[i]->reset();
|
||||
}
|
||||
}
|
||||
void setAnimation(const Ogre::String &anim_state, bool reset = false)
|
||||
{
|
||||
@@ -273,7 +293,6 @@ struct AnimationNodeStateMachine : AnimationNode {
|
||||
}
|
||||
OgreAssert(stateMap.find(anim_state) != stateMap.end(),
|
||||
"Bad animation state: " + anim_state);
|
||||
std::cout << "STATE: " << anim_state << std::endl;
|
||||
nextAnim = stateMap[anim_state];
|
||||
if (nextAnim == currentAnim)
|
||||
return;
|
||||
@@ -324,8 +343,10 @@ struct AnimationNodeOutput : AnimationNode {
|
||||
};
|
||||
|
||||
struct AnimationSystem : AnimationNode {
|
||||
AnimationSystem()
|
||||
: m_builder(this)
|
||||
bool debug;
|
||||
AnimationSystem(bool debug = false)
|
||||
: debug(debug)
|
||||
, m_builder(this, debug)
|
||||
{
|
||||
}
|
||||
std::unordered_map<Ogre::String, Animation *> animation_list;
|
||||
@@ -347,8 +368,11 @@ struct AnimationSystem : AnimationNode {
|
||||
std::list<AnimationNode *> parent_stack;
|
||||
std::unordered_map<Ogre::String, AnimationNode *> nodeMap;
|
||||
std::vector<AnimationNodeAnimation *> animationNodeList;
|
||||
AnimationSystemBuilder(AnimationSystem *animationSystem)
|
||||
bool debug;
|
||||
AnimationSystemBuilder(AnimationSystem *animationSystem,
|
||||
bool debug = false)
|
||||
: mAnimationSystem(animationSystem)
|
||||
, debug(debug)
|
||||
{
|
||||
}
|
||||
AnimationSystemBuilder *output()
|
||||
@@ -391,7 +415,7 @@ struct AnimationSystem : AnimationNode {
|
||||
{
|
||||
OgreAssert(parent, "bad parent");
|
||||
AnimationNodeStateMachine *onode =
|
||||
new AnimationNodeStateMachine(fade_time);
|
||||
new AnimationNodeStateMachine(fade_time, debug);
|
||||
animation_nodes.push_back(onode);
|
||||
parent->children.push_back(onode);
|
||||
parent_stack.push_back(parent);
|
||||
@@ -429,14 +453,23 @@ struct AnimationSystem : AnimationNode {
|
||||
m_builder.animationNodeList[i];
|
||||
float weight = anim->getWeight();
|
||||
anim->mAnimation->increaseAccWeight(weight);
|
||||
std::cout << i << " weight: " << weight << std::endl;
|
||||
#ifdef VDEBUG
|
||||
if (debug)
|
||||
std::cout << i << " node: "
|
||||
<< anim->mAnimation->getName() << " "
|
||||
<< weight << std::endl;
|
||||
#endif
|
||||
}
|
||||
for (i = 0; i < vanimation_list.size(); i++) {
|
||||
float weight = vanimation_list[i]->getAccWeight();
|
||||
vanimation_list[i]->setWeight(weight);
|
||||
vanimation_list[i]->resetAccWeight();
|
||||
std::cout << i << vanimation_list[i]->getName()
|
||||
<< " acc weight: " << weight << std::endl;
|
||||
#ifdef VDEBUG
|
||||
if (debug)
|
||||
std::cout << i << " animation: "
|
||||
<< vanimation_list[i]->getName()
|
||||
<< " " << weight << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
void setWeight(float weight)
|
||||
@@ -460,24 +493,11 @@ struct AnimationSystem : AnimationNode {
|
||||
};
|
||||
|
||||
struct AnimationControl {
|
||||
// AnimID currentAnim;
|
||||
// AnimID nextAnim;
|
||||
// bool reset;
|
||||
bool configured;
|
||||
// Ogre::AnimationState *mAnims[NUM_ANIMS]; // master animation list
|
||||
// Ogre::Animation *mSkelAnimations[NUM_ANIMS];
|
||||
// bool mFadingIn[NUM_ANIMS]; // which animations are fading in
|
||||
// bool mFadingOut[NUM_ANIMS]; // which animations are fading out
|
||||
// Ogre::NodeAnimationTrack *mHipsTracks[NUM_ANIMS];
|
||||
// Ogre::NodeAnimationTrack *mRootTracks[NUM_ANIMS];
|
||||
// std::vector<AnimationNode *> mAnimations;
|
||||
// AnimationNodeStateMachine *mStateMachine;
|
||||
AnimationSystem *mAnimationSystem;
|
||||
};
|
||||
struct CharacterAnimationModule {
|
||||
CharacterAnimationModule(flecs::world &ecs);
|
||||
// void setAnimation(AnimationControl &anim);
|
||||
// void fadeAnimations(AnimationControl &anim, Ogre::Real deltaTime);
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user