Jump to content

[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 comment

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 comment

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 comment

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 comment
  • 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 comment

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 comment
  • 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 comment
×
×
  • Create New...