Author Topic: Bones joint rotate but mesh doesn`t update  (Read 35344 times)

Offline Carlos Mateo

  • byte
  • *
  • Posts: 16
    • View Profile
Bones joint rotate but mesh doesn`t update
« on: January 27, 2016, 04:54:11 pm »
Hello

I'm working with Bones and I'm using a model with bones I exported from Blender. When I use it in Bones I can see I rotate the bones within the skeletonDebugger. My problem is that the mesh doesn,t update its position.

Thanks in advance

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Bones joint rotate but mesh doesn`t update
« Reply #1 on: January 27, 2016, 05:10:21 pm »
check ProceduralAnimationSample.

possibly you are missing one of the following steps:

Code: [Select]
currentPose.updateTransforms();
skeletonDebugger.update(currentPose); // only for debugging
animatedGroup.applySkeletonPose();
animatedGroup.applyAnimation();

Offline Carlos Mateo

  • byte
  • *
  • Posts: 16
    • View Profile
Re: Bones joint rotate but mesh doesn`t update
« Reply #2 on: January 27, 2016, 05:17:46 pm »
Thanks I have use it, put I have a problem because when I use applySkeletonPose(), the app stops with the following error:

java.lang.ArrayIndexOutOfBoundsException: length=265; index=-1
                                                                            at raft.jpct.bones.Animated3D.applySkeletonPose(Animated3D.java:511)
                                                                            at raft.jpct.bones.AnimatedGroup.applySkeletonPose(AnimatedGroup.java:191)

Why does it appear??

Thanks

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Bones joint rotate but mesh doesn`t update
« Reply #3 on: January 27, 2016, 06:29:17 pm »
are you using last version? I've updated Bones last time at 3 January.

and may there be any chance your skeleton has more than 255 joints?

Offline Carlos Mateo

  • byte
  • *
  • Posts: 16
    • View Profile
Re: Bones joint rotate but mesh doesn`t update
« Reply #4 on: January 28, 2016, 09:51:17 pm »
I'm using the previous version and yes, it has 265 joints. Is it the problem? How can I solve it?

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Bones joint rotate but mesh doesn`t update
« Reply #5 on: January 28, 2016, 10:17:53 pm »
yes unfortunately it's a problem because of jME Ogre loader which Bones uses. it only supports skeletons up to 255 joints. try reducing number of joints in your skeleton.

Offline Carlos Mateo

  • byte
  • *
  • Posts: 16
    • View Profile
Re: Bones joint rotate but mesh doesn`t update
« Reply #6 on: February 01, 2016, 03:02:06 pm »
Ok, the problem is that Im using the program MakeHuman to export the model, and it has all these joints. Is the any possibility to increment the maximun number of joint in the jME loader?

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Bones joint rotate but mesh doesn`t update
« Reply #7 on: February 01, 2016, 04:23:03 pm »
it's in my todo list, but honestly I dont know when. possibly not in a near future. if you would like to do it yourself, be my guest. Bones.zip contains relevant jME sources.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Bones joint rotate but mesh doesn`t update
« Reply #8 on: February 02, 2016, 11:43:00 pm »
Raft, do you actually have a to-do list? If so, do you mind telling me what it is? Another importer (again, fbx would be a game-changer)? Maybe more joints per vertex?

Offline Carlos Mateo

  • byte
  • *
  • Posts: 16
    • View Profile
Re: Bones joint rotate but mesh doesn`t update
« Reply #9 on: February 02, 2016, 11:58:49 pm »
Ok thanks....well finally I have created a reduced version of my model with 15 joints....the problem is still the same....I can see the movement of the skeleton within the skeletonDebugger but the meshes dont update... the code is the following::
Code: [Select]
        SkeletonHelper skeletonHelper=new SkeletonHelper(human);
        Joint j=skeletonHelper.getJoint("Bone.003");;
        totalRad= (float) (totalRad+rad);
        targetJoint(skeletonHelper.pose, j.getIndex(), new SimpleVector(1, 0, 0), new SimpleVector(0, 0, totalRad), totalRad);
        skeletonHelper.pose.updateTransforms();
        skeletonDebugger.update(skeletonHelper.pose);
        human.applySkeletonPose();
        human.applyAnimation();

Being targetJoint the method is took from one of the sample's bones:

Code: [Select]
private void targetJoint(SkeletonPose pose, int jointIndex, SimpleVector bindPoseDirection,
                             SimpleVector targetPos, final float targetStrength) {

        final int parentIndex = pose.getSkeleton().getJoint(jointIndex).getParentIndex();

        // neckBindGlobalTransform is the neck bone -> model space transform. essentially, it is the world transform of
        // the neck bone in bind pose.
        final Matrix jointInverseBindPose = pose.getSkeleton().getJoint(jointIndex).getInverseBindPose();
        final Matrix jointBindPose = jointInverseBindPose.invert();

        // Get a vector representing forward direction in neck space, use inverse to take from world -> neck space.
        SimpleVector forwardDirection = new SimpleVector(bindPoseDirection);
        forwardDirection.rotate(jointInverseBindPose);

        // Get a vector representing a direction to target point in neck space.
        SimpleVector targetDirection = targetPos.calcSub(pose.getGlobal(jointIndex).getTranslation()).normalize();
        targetDirection.rotate(jointInverseBindPose);

        // Calculate a rotation to go from one direction to the other and set that rotation on a blank transform.
        Quaternion quat = new Quaternion();
        quat.fromVectorToVector(forwardDirection, targetDirection);
        quat.slerp(Quaternion.IDENTITY, quat, targetStrength);

        final Matrix subGlobal = quat.getRotationMatrix();

        // now remove the global/world transform of the neck's parent bone, leaving us with just the local transform of
        // neck + rotation.
        subGlobal.matMul(jointBindPose);
        subGlobal.matMul(pose.getSkeleton().getJoint(parentIndex).getInverseBindPose());

        // set that as the neck's transform
        pose.getLocal(jointIndex).setTo(subGlobal);
    }

What am I doing wrong? :S

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Bones joint rotate but mesh doesn`t update
« Reply #10 on: February 03, 2016, 06:22:49 am »
Raft, do you actually have a to-do list? If so, do you mind telling me what it is? Another importer (again, fbx would be a game-changer)? Maybe more joints per vertex?
:) well, not a written list besides TODO comments in the code.

for fbx importer, possibly I wont have time for that.

I believe 4 joints per vertex is more than enough for almost everything.

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Bones joint rotate but mesh doesn`t update
« Reply #11 on: February 03, 2016, 06:28:20 am »
Ok thanks....well finally I have created a reduced version of my model with 15 joints....the problem is still the same....I can see the movement of the skeleton within the skeletonDebugger but the meshes dont update... the code is the following::

..
What am I doing wrong? :S
not sure. it looks okay actually. are you sure that that joint actually affects any vertex? did you try another joint?

Offline Carlos Mateo

  • byte
  • *
  • Posts: 16
    • View Profile
Re: Bones joint rotate but mesh doesn`t update
« Reply #12 on: February 03, 2016, 07:48:20 pm »
Yes but it happens the same...I Blender in Pose Mode if I move some bone, the meshes associated move as well, but when I export it to JPCT only the bones are moved, not the meshes..... Maybe is there some step I forgot when I exported it in Blender??

I attach the model structure in Blender if I'm doing something wrong and I'm not noticed

« Last Edit: February 03, 2016, 08:02:34 pm by Carlos Mateo »

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Bones joint rotate but mesh doesn`t update
« Reply #13 on: February 03, 2016, 08:00:03 pm »
I'm not a Blender user. maybe, since there is no animation to be exported, bone assignments are not exported? please check the mesh.xml file there should be many vertexboneassignment elements. you can compare it to ninja.mesh.xml

Offline Carlos Mateo

  • byte
  • *
  • Posts: 16
    • View Profile
Re: Bones joint rotate but mesh doesn`t update
« Reply #14 on: February 03, 2016, 09:20:44 pm »
Yes It has the same structure than ninja.mesh.xml, I'm trying a new simpler model that is a cylinder only with 3 bones and it happens the same...the meshes doesn't update the location, only the bones.....I don,t know what to do...