www.jpct.net

Bones - Skeletal and Pose Animations for jPCT/jPCT-AE => Bones => Topic started by: Carlos Mateo on January 27, 2016, 04:54:11 pm

Title: Bones joint rotate but mesh doesn`t update
Post by: Carlos Mateo 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
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: raft 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();
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: Carlos Mateo 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
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: raft 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?
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: Carlos Mateo 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?
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: raft 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.
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: Carlos Mateo 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?
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: raft 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.
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: AGP 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?
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: Carlos Mateo 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
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: raft 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.
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: raft 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?
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: Carlos Mateo 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

Title: Re: Bones joint rotate but mesh doesn`t update
Post by: raft 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
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: Carlos Mateo 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...
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: raft on February 03, 2016, 11:05:47 pm
can you please put your model into ProceduralAnimationSample and try there
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: Carlos Mateo on February 04, 2016, 01:59:16 pm
Yes I tried it and I found the error. It works now. Thank you very much
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: raft on February 04, 2016, 02:06:48 pm
and what was it just for curiosity?
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: Carlos Mateo on February 04, 2016, 08:49:51 pm
A silly thing....I took the Android Sample and cloned my main object and add the clone to the world, not the main one...for that reason it doesn,t update :S jaja.

My last question:

With the bones library if I add inverse kinematic to some joint as I did in blender, the rest of joints connected to it also move together...or the inverse Kinematics it isn't exported to bones??

Thanks
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: raft on February 04, 2016, 09:03:03 pm
it happens ;)

no, IK is out of scope of Bones.
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: Carlos Mateo on February 04, 2016, 09:58:33 pm
Ohh...what's a pity...Isn,'t there any way to implement it?
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: raft on February 04, 2016, 10:00:28 pm
no idea. I'm sure it can implemented on top of Bones API, but as I said it's completely outside of Bones' scope
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: AGP on February 06, 2016, 04:05:45 am
Quote
I believe 4 joints per vertex is more than enough for almost everything.

Except that it isn't. Too often Bones simply won't work, even after going through the hoops of exporting to its format. These little exceptions make it very hard to use jpct+bones. This is good software, really (both jpct and bones), and tiny to boot. But sometimes, I'm working on a project for which three models have worked fine, then I run into a fourth one that doesn't. Eventually, there will be other models. I can't re-work every model for every exception. So I switch to Unity, which is a pity because I have a LOT less fun working that way.

Anyway, sorry for distracting this thread.
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: raft on February 06, 2016, 10:23:47 pm
Raft, do you actually have a to-do list? If so, do you mind telling me what it is?
here is a todo list (https://github.com/raftAtGit/Postvayler/blob/master/Postvayler/doc/todo.txt). it's not Bones' list but has higher precedence to me. even cannot create time for that. yeah, I know, possibly because I'm too lazy for that.. ;)
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: raft on February 06, 2016, 10:31:11 pm
Quote
I believe 4 joints per vertex is more than enough for almost everything.

Except that it isn't. Too often Bones simply won't work, even after going through the hoops of exporting to its format. These little exceptions make it very hard to use jpct+bones. This is good software, really (both jpct and bones), and tiny to boot. But sometimes, I'm working on a project for which three models have worked fine, then I run into a fourth one that doesn't. Eventually, there will be other models. I can't re-work every model for every exception. So I switch to Unity, which is a pity because I have a LOT less fun working that way.

Anyway, sorry for distracting this thread.

interesting claim regarding jPCT+Bones and Unity comparaison. to me, it's an unfair comparaison, but anyway, check this please. in short it says Unity has also a constraint of 4 joints per vertex.
http://answers.unity3d.com/questions/9679/is-there-a-limit-to-the-number-of-bones-in-a-model.html
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: AGP on February 07, 2016, 02:42:10 am
I didn't know that. What I do know is that I hardly ever have any trouble replicating my models' animations in Unity. That's not the case with Bones. Too often I have models whose animations distort them bizarrely in Bones. I thought that it was down to the number of joints per vertex, but it must be something else.

Obviously, it's an unfair comparison. Unity is sold product. But at any rate, I do enjoy jpct+bones more. Except that I can never use it professionally. Now, this isn't bitching, it's just been my experience every time I tried.
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: raft on February 08, 2016, 12:28:24 am
instead of throwing such claims into the air with no solid evidence, did you ever consider posting such "non working" models and seek help, or maybe better try to fix the problem yourself and share that? after all that's the point of open source projects, right?
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: AGP on February 08, 2016, 04:19:32 am
First of all, I'm not on trial. I have no reason to lie. As for posting, it happens much too often, and I suppose that I'm a little too impatient, too. And as for fixing it, I wouldn't know where to begin. I could test each case better if I could load models faster, but it takes too long and too many steps per attempt. Again, I'm not bitching, I'm just stating a fact. I wouldn't be opposed to sending you some of the models with which I've had trouble, though.
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: raft on February 08, 2016, 08:59:01 am
yeap, please do so, you have my email if I remember correct
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: AGP on February 09, 2016, 02:43:30 am
Done. I've also posted a job on Freelance.com for anyone who wants to attempt a MaxScript that takes any biped or bones model from Max and directly exports a .bones file. We'll see how that goes, but that would go a very long way towards making Bones more useful.
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: Marchioly on March 08, 2016, 02:15:02 pm
Done. I've also posted a job on Freelance.com for anyone who wants to attempt a MaxScript that takes any biped or bones model from Max and directly exports a .bones file. We'll see how that goes, but that would go a very long way towards making Bones more useful.

The problem with that is that the bones format uses 'ObjectInputStream' from the java.io package. You would need to reimplement the whole object serialization protocol (http://docs.oracle.com/javase/6/docs/platform/serialization/spec/protocol.html)

I havn't really looked too hard into bones, but I forked the code last night and am implementing an actual protocol rather than the object serialization (not too bad so far, the relevant code is commented out in places).

I agree that the conversion process to bones is annoying.
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: AGP on March 14, 2016, 04:00:40 am
Oh, I know. I'm getting as far as a MaxScript that exports skin and bone data. I'm currently creating an intermediate JSON-serialized format. But I do hope to do the Java Serialization from inside 3ds max.

Should we coordinate our efforts?
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: Marchioly on March 15, 2016, 12:10:26 am
Oh, I know. I'm getting as far as a MaxScript that exports skin and bone data. I'm currently creating an intermediate JSON-serialized format. But I do hope to do the Java Serialization from inside 3ds max.

Should we coordinate our efforts?

I would be open to collaborating on it. I am not familiar with maxscript though.

The avenue I took was adding support for the IQM/IQE animation format to some code that was derived from bones.
Format information: http://sauerbraten.org/iqm/

The reason I chose to work with IQM/IQE was because it is a really common format with a lot of importers/exporter script for 3dsmax/maya/blender.

Additionally, the assets from the mmorpg Ryzom, were released with a CC-by-NA license. As a result, I wanted to get those working/take advantage of that.

Link: https://bitbucket.org/ccxvii/ryzom-assets/overview


Edit: Another problem with the bones format/java serialization is that it removes the ability to obfuscate your code/bones lib (assuming you want to).

Edit:Edit: It is worth noting that I have NOT finished implementing the IQE/IQM format in its entirety. I just have the IQE portion done and only the loading of bone information/skeletal animation.

The reason is because my sights are currently set on retargeting the animations from ryzom to my current model skeleton/scale.


Title: Re: Bones joint rotate but mesh doesn`t update
Post by: raft on March 15, 2016, 01:59:06 am
Edit: Another problem with the bones format/java serialization is that it removes the ability to obfuscate your code/bones lib (assuming you want to).
it's interesting that you call that a problem but not a restriction.

anyway, it's not a real restriction, you can exclude Bones' classes from obfuscation so serialized format wont cause a problem.
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: AGP on March 15, 2016, 06:46:12 am
The MaxScript part I can handle. Isn't the point of serialization performance? What if we bypass the bones format altogether and create a JSON-serialized format of our own (and we could--and, indeed, SHOULD--add support for importing other formats, such as the IQM)? We could export to a custom format we could call, say, bonesx (that way we could make our own exporters for Max and Blender spit out the serialized and final file). Regarding JSON, I quote the following article: "The results show that Java serialization is slow for a small number of objects, but good for a large number of objects. Conversely, XML and JSON can outperform Java serialization for a small number of objects, but Java serialization is faster for a large number of objects."

http://java-persistence-performance.blogspot.com.br/2013/08/optimizing-java-serialization-java-vs.html (http://java-persistence-performance.blogspot.com.br/2013/08/optimizing-java-serialization-java-vs.html)
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: Marchioly on March 15, 2016, 12:45:39 pm
Edit: Another problem with the bones format/java serialization is that it removes the ability to obfuscate your code/bones lib (assuming you want to).
it's interesting that you call that a problem but not a restriction.

anyway, it's not a real restriction, you can exclude Bones' classes from obfuscation so serialized format wont cause a problem.

I used the wrong word. A more fitting word would be limitation or shortcoming. Yes, you can remove the classes from obfuscation, but that will just make the process of reverse engineering/deobfuscation that much easier.

The MaxScript part I can handle. Isn't the point of serialization performance? What if we bypass the bones format altogether and create a JSON-serialized format of our own (and we could--and, indeed, SHOULD--add support for importing other formats, such as the IQM)? We could export to a custom format we could call, say, bonesx (that way we could make our own exporters for Max and Blender spit out the serialized and final file). Regarding JSON, I quote the following article: "The results show that Java serialization is slow for a small number of objects, but good for a large number of objects. Conversely, XML and JSON can outperform Java serialization for a small number of objects, but Java serialization is faster for a large number of objects."

http://java-persistence-performance.blogspot.com.br/2013/08/optimizing-java-serialization-java-vs.html (http://java-persistence-performance.blogspot.com.br/2013/08/optimizing-java-serialization-java-vs.html)

I like the idea of json or at least a text based format. Mainly because it makes it easy to check for errors/debug the problems that library users are experiencing.

On the topic of the speed issue, I have not done any benchmarks since around jdk1.6/java6.

I was of the understanding that java serialization/ObjectOutputStream was slower than a binary format. I have only previously compared it with xstream/kryo/gson. I thought that in general gson's serialization was pretty fast. However, it is worth noting that my previous tests were storing integer/string data rather than complex objects.
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: AGP on March 15, 2016, 09:15:59 pm
How do we proceed? Would you like to see the MaxScript as it stands right now? PM me your email address.
Title: Re: Bones joint rotate but mesh doesn`t update
Post by: Marchioly on March 16, 2016, 12:52:17 am
I pmed you earlier today.