Bones - Skeletal and Pose Animations for jPCT/jPCT-AE > Bones

Bones - Skeletal and Pose animations for jPCT

<< < (49/51) > >>

Babu:
hi raft,

I am back  ;).  I could load the cylinder model with the pose animations in my Android app and I could have all the pose animations working fine.  I see that the skin-animation, "wave" is also working fine. 

But I am facing a problem when I try to have both skin and pose animations working together :(.  I am able see only that animation which I apply last in the code i.e. if I call animatePose() last then I see only pose animation and if I call animateSkin() last then I see only skin animation.  I am not sure if I am doing some wrong  ???.  Below is the code for onDrawFrame().  I am using Ninja Demo as the base for my app.


--- Code: ---                public void onDrawFrame(GL10 gl)
{
if (frameBuffer == null) return;

long now = System.currentTimeMillis();
aggregatedTime += (now - frameTime);
frameTime = now;

if (aggregatedTime > 1000)
{
aggregatedTime = 0;
}

while (aggregatedTime > GRANULARITY)
{
aggregatedTime -= GRANULARITY;
skinAnimateSeconds += GRANULARITY * 0.001f * speed;
poseAnimateSeconds += GRANULARITY * 0.001f * speed;
placeCamera();
}

if (poseAnimation > 0 && rockyCylinder.getPoseClipSequence().getSize() >= poseAnimation)
{
float clipTime = rockyCylinder.getPoseClipSequence().getClip(poseAnimation-1).getTime();
if (poseAnimateSeconds > clipTime)
{
poseAnimateSeconds = 0;
}
float index = poseAnimateSeconds / clipTime;

rockyCylinder.animatePose(index, poseAnimation);
}
else
{
poseAnimateSeconds = 0f;
}

////////////////////////// START BLOCK /////////////////////////////////////////
/////// If I move this block above pose animation then "wave" doesn't happen//////////
if (skinAnimation > 0 && rockyCylinder.getSkinClipSequence().getSize() >= skinAnimation)
{
float clipTime = rockyCylinder.getSkinClipSequence().getClip(skinAnimation-1).getTime();
if (skinAnimateSeconds > clipTime)
{
skinAnimateSeconds = 0;
}
float index = skinAnimateSeconds / clipTime;

rockyCylinder.animateSkin(index, skinAnimation);
}
else
{
skinAnimateSeconds = 0f;
}
////////////////////////// END BLOCK /////////////////////////////////////////

rockyCylinder.applyAnimation();

frameBuffer.clear();
world.renderScene(frameBuffer);
world.draw(frameBuffer);

frameBuffer.display();
}

--- End code ---

raft:
that's because autoApplyAnimation is enabled by default. call AnimatedGroup.setAutoApplyAnimation(false) once after loading group.

first apply pose animations, then skin animation. finally call AnimatedGroup.applyAnimation().

Babu:
thanks, raft.  That worked!!  ;D

panthenol:
usefull piece of info here also !  thanks guys for sharing this  :D

frag-a:
Hi raft, first of all thanks for this great lib. I'm playing around with some 3D game dev stuff, but I don't have much experience...yet :)
It was relatively easy to get into jpct and bones but I suck at math, so I wonder if you could help me here with this attempt to do some IK.
The goal is to have some character to grab or to point to some other object. The below code works fine if the rotation starts from the bind pose.
But if it's not from the bind pose, it just get crazy! Could you please help me figure out whats missing? Thanks in advance.


--- Code: --- private static final void targetJoint(final SimpleVector targetTranslation, final SkeletonPose pose, int handleIndex, int parentIndex) {
final Skeleton skeleton = pose.getSkeleton();
final Joint handleJoint = skeleton.getJoint(handleIndex);
final Joint parentJoint = skeleton.getJoint(parentIndex);
final Matrix parentInverseBindPose = parentJoint.getInverseBindPose();
final Matrix parentBindPose = parentInverseBindPose.invert();

final SimpleVector handleTranslation = pose.getGlobal(handleIndex).getTranslation();
final SimpleVector parentTranslation = pose.getGlobal(parentIndex).getTranslation();

float distance = handleTranslation.distance(targetTranslation);
if (distance > 0.1) {
SimpleVector parentHandleVector = handleTranslation.calcSub(parentTranslation);
parentHandleVector = parentHandleVector.normalize();
parentHandleVector.rotate(parentInverseBindPose);

SimpleVector parentTargetVector = targetTranslation.calcSub(parentTranslation);
parentTargetVector = parentTargetVector.normalize();
parentTargetVector.rotate(parentInverseBindPose);

float angle = parentHandleVector.calcAngle(parentTargetVector);
if (Math.abs(angle) > 0.1f) {
Quaternion quat = new Quaternion().fromVectorToVector(parentHandleVector, parentTargetVector);
final Matrix rotation = quat.getRotationMatrix();
rotation.matMul(parentBindPose);
rotation.matMul(pose.getSkeleton().getJoint(parentJoint.getParentIndex()).getInverseBindPose());
pose.getLocal(parentIndex).setTo(rotation);
}
}
}

--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version