[SOLVED] setWeight not working?


photo

Recommended Posts

The following script seems to not be blending two animations for us:

 

mesh.setLayer(0);

mesh.setAnimation(xxx);

mesh.setWeight(0.5);

 

mesh.setLayer(1);

mesh.setAnimation(yyy);

mesh.setWeight(0.5);

 

Do I need to apply setBuffer to get it working?

Link to post

Well here's the whole thing:

 

public: void playAnimation(string nAnimation, float nBlend)
{
if (animation_current != nAnimation)
{
animation_current = nAnimation;
if (animations.check(nAnimation))
{
mesh.setLayer(0);
string oldAnimation = mesh.getAnimation();
float oldFrame = mesh.getFrame();
mesh.setAnimation(animations[nAnimation]);
mesh.setFrame(-1);
mesh.setSpeed(30);
mesh.setLoop(1);
if (mesh.isStopped()) mesh.play();
 
mesh.setLayer(1);
mesh.setAnimation(oldAnimation);
mesh.setFrame(oldFrame, -1, -1);
mesh.setSpeed(30);
mesh.setLoop(1);
if (mesh.isStopped()) mesh.play();
 
animation_blendTime = nBlend;
animation_blendTimer = 0;
}
else log.message ("Warning: animation " + nAnimation + " not found \n");
}
}
 
private: void updateAnimation(float dt)
{
if (animation_blendTimer < animation_blendTime)
{
animation_blendTimer = clamp(animation_blendTimer + dt, 0.0f, animation_blendTime);
float nBlendWeight = lerp(0.0f, 1.0f, animation_blendTimer/animation_blendTime);
 
mesh.setLayer(0);
mesh.setWeight(nBlendWeight);
 
mesh.setLayer(1);
mesh.setWeight(1.0f-nBlendWeight);
}
}
 
ps. In general, I found that animation that's not currently active (from setLayer(x)) refuse to play. 
Link to post

Hi,

 

Thanks for the script, but it's really hard to say what part of this code causing such behavior, sorry. It would be more efficient to all of us if you can sent us simple test scene with your *.world, *.cpp, *.smesh and animation files.

 

Thank you!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to post

What email should I send it to?

 

ps. Is it possible that there's some other parameter that set the animation to use only one layer?

Link to post

Well I did use setNumLayers() to set it to 2 layers and double check it with getNumLayers(), everything seems to be correct, but the animation is just not blending.

 

If I can't clear this by tomorrow, I'll try to recreate a sample test scene for it.

Link to post
  • 1 month later...

Hi!

 

Looks like I'm doing some necroposting here but I'm curious is everything ok with that issue? Have you managed to get setWeight code working? Can I close that topic as solved?

Link to post

No, it's not. If you would please look at the project we sent you, you can un-hide all our test blend weight stuff in "scripts/Character.h" to see how it doesn't work...

Link to post
  • 2 weeks later...

Hi Warit,

 

I think I found source of the problem. You can't just set animations and call ObjectMeshSkinned::play, you have to call ObjectMeshSkinned::setFrame for each layer instead. If you look at samples/animation/animation_01 you can notice that code (i've cleaned it up a little bit):

float time = engine.game.getTime();
		
mesh.setLayer(0);
mesh.setFrame(time);
mesh.setWeight(weight);
		
mesh.setLayer(1);
mesh.setFrame(time);
mesh.setWeight(1.0f - weight);
Link to post

Hmmm ok... in order to use animation layers, I have to use setFrame updating each layer every frame?

Link to post