Author Topic: Bones - Skeletal and Pose animations for jPCT  (Read 241552 times)

Offline Babu

  • int
  • **
  • Posts: 71
    • View Profile
Re: Bones - Skeletal and Pose animations for jPCT
« Reply #150 on: March 31, 2011, 12:01:54 pm »
Hi,

I am developing an Android app that needs some 3D skeletal animations.  As I am new to 3D graphics programming, I was delighted to come across JPCT & Bones and hope these fantastic APIs can bail me out.  Thanks a ton to all the people involved!!

I was able to run the Ninja example in my Android emulator and my Android phone (of course using the intermediate release of JPCT that addresses the .rotate issue).  Now I am trying to load some of our own models.  Our artist is using Maya and he has used Ogre3D exporter to generate two files (one for the model and another for the texture).

1. mesh_2_new.ma.mesh (the model)
2. mesh_2_new.ma.material (the texture)

So, I decided to use the BonesImporter to get them to native Bones format.
However, when I analyzed the "OgreSample.java" and "JMEOgreImporter.java", the model file is ".xml" and texture is ".jpg".  I am currently struck here.

I think we're missing something.  Can you please help me out with this?

- Thanks in advance

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Bones - Skeletal and Pose animations for jPCT
« Reply #151 on: March 31, 2011, 12:40:04 pm »
Ogre has two equivalent formats: binary and xml. Bones neeed the xml format. Most possibly there is an option in your Maya exporter to export as xml files. if not, ogre has command line tools (OgreXMLConverter) to convert into either formats.

note, for use with Bones, you also need skeleton file in same directory with mesh file.

Bones does not support complex materials but simple textures. nevermind about material file, tell your artist to provide you the texture (png, jpg, gif whatever) and assign it to Animated3D's as in Ninja demo.

Offline Babu

  • int
  • **
  • Posts: 71
    • View Profile
Re: Bones - Skeletal and Pose animations for jPCT
« Reply #152 on: March 31, 2011, 12:58:10 pm »
raft, thanks a lot for your guidance.  I'll try that out and get back to you.  :)

Offline Babu

  • int
  • **
  • Posts: 71
    • View Profile
Re: Bones - Skeletal and Pose animations for jPCT
« Reply #153 on: April 03, 2011, 02:47:02 pm »
Hi raft,

I got the .xml files from our artist.  However, when I tried to convert them to .bones format, I got the following exception.

bash jmeOgre2Bones.sh -in body/body.skeleton.xml body/body.mesh.xml -out fm.group.bones
Exception in thread "main" com.jmex.model.ModelFormatException: Input XML file does not have required root element 'mesh'
   at com.jmex.model.XMLUtil.loadDocument(XMLUtil.java:113)
   at com.jmex.model.ogrexml.OgreLoader.loadModel(OgreLoader.java:225)
   at com.jmex.model.ogrexml.OgreLoader.loadModel(OgreLoader.java:177)
   at raft.jpct.bones.util.JMEOgreImporter.loadGroup(JMEOgreImporter.java:91)
   at raft.jpct.bones.util.JMEOgreImporter.loadGroup(JMEOgreImporter.java:81)
   at raft.jpct.bones.util.JMEOgreImporter.run(JMEOgreImporter.java:58)
   at raft.jpct.bones.util.JMEOgreImporter.main(JMEOgreImporter.java:147)

But the file has the <mesh> root element.  I am not sure what's going wrong.  Can you please help me with this?

The xml files can be obtained from:
https://docs.google.com/leaf?id=0B85w3AW2-YdVYzY1YmZjM2UtNTQzZC00NDE0LWFmNmQtZTkyMDQxNTM4ZDc1&hl=en

- Thanks

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Bones - Skeletal and Pose animations for jPCT
« Reply #154 on: April 04, 2011, 12:02:24 am »
dont mention about skeloton.xml to script. it's automatically located in same file in mesh.xml

Code: [Select]
jmeOgre2Bones.sh -in body/body.mesh.xml -out fm.group.bones

Offline Babu

  • int
  • **
  • Posts: 71
    • View Profile
Re: Bones - Skeletal and Pose animations for jPCT
« Reply #155 on: April 04, 2011, 05:15:29 am »
hi raft,
The previous exception doesn't come anymore.  Thanks :)

However, I got the following exception.

Exception in thread "main" java.lang.IllegalArgumentException: No controller found in OgreEntityNode. Means there is no skeleton or pose animation!
   at raft.jpct.bones.BonesImporter.importOgre(BonesImporter.java:131)
   at raft.jpct.bones.util.JMEOgreImporter.loadGroup(JMEOgreImporter.java:93)
   at raft.jpct.bones.util.JMEOgreImporter.loadGroup(JMEOgreImporter.java:81)
   at raft.jpct.bones.util.JMEOgreImporter.run(JMEOgreImporter.java:58)
   at raft.jpct.bones.util.JMEOgreImporter.main(JMEOgreImporter.java:147)

Is there something wrong with the .xml file?  Should I go back to our artist?

Also I got several of the following warnings.

Apr 4, 2011 8:20:56 AM com.jmex.model.ogrexml.anim.SkeletonLoader loadSkeleton
WARNING: Rotation axis not normalized

Sorry for troubling you with lot of basic stuff  :-[

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Bones - Skeletal and Pose animations for jPCT
« Reply #156 on: April 04, 2011, 11:35:41 am »
this happens because there is no animation in your skeleton file. tell your artist export at least one animation.

nevermind about the warnings. jME checks if length of rotation axis is exactly 1.0 and if not prints that warning. due to rounding issues, length cannot be exactly 1.0 most of the time.

Offline pages

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Bones - Skeletal and Pose animations for jPCT
« Reply #157 on: April 04, 2011, 10:02:52 pm »
Hi back again :)
I am just wondering about the OrgeLoaderSample.java

If you have two objects both of .mesh.xml and want them to display i presume the code
Code: [Select]

for (Animated3D o : animatedGroup) {
o.setTexture("ninja");
o.build();
o.discardMeshData();
}
return animatedGroup;
Would have to be edited to allow two animated objects but i dont really see how this would be possible in an infinite loop which can only return 1 thing ??
Or is there some way of combining the 2 exports into 1 mesh.xml file ?

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Bones - Skeletal and Pose animations for jPCT
« Reply #158 on: April 04, 2011, 10:16:09 pm »
well, as the name suggests AnimatedGroup is group of animated objects (Animated3D's).

and yes, many objects can be exported to same mesh.xml file. typically they are attached to same skeleton and animated together. have a look at Ogre sample. the ninja model consists of two objects, the sword and the body. they are in the same mesh.xml file.

Code: [Select]
for (Animated3D o : animatedGroup) {
  //..
}

btw, this not an infinite loop. it just iterates over all Animted3D's in the AnimatedGroup

Offline Babu

  • int
  • **
  • Posts: 71
    • View Profile
Re: Bones - Skeletal and Pose animations for jPCT
« Reply #159 on: April 05, 2011, 12:10:01 pm »
this happens because there is no animation in your skeleton file. tell your artist export at least one animation.

is it not possible to load a model with animation?  Just like the default view of Ninja, before selecting an animation from the options menu?

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Bones - Skeletal and Pose animations for jPCT
« Reply #160 on: April 05, 2011, 01:22:20 pm »
no, not possible. this is simply because Bones is not a model loader but an animation library.

Offline pages

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Bones - Skeletal and Pose animations for jPCT
« Reply #161 on: April 08, 2011, 05:01:34 pm »
Just trying to alter the code of this to suit my own needs but i am facing trouble with getting the camera to center on the main target .
I presume in CameraOrbitController.java you set the camera position to look at the x,y,z center of the 'world' through 
Code: [Select]
cameraTarget = new SimpleVector(0, 0, 0);
The only problem is for the NinjaDemoActivity you have it arranged for the circle of 8 ninjas to appear around the (0,0,0) center , now for my project i only require 1 model to appear.
So i guess i need to either
  • So what i need to do is make the mesh appear on 0,0,0
  • Get the camera to alter make it focus and rotate around the Mesh imported 
Would you know how to set it this way ?


Also as an aside --
for some reason my models load upside down :)
I'm guessing if i use the
Code: [Select]
jmeOgre2Bones.sh|bat -in ./tmp/Model.mesh.xml -out ./tmp/Model1.group.bones -rotation x180,y0,z0

Would that essentially 'Flip my model around ??

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Bones - Skeletal and Pose animations for jPCT
« Reply #162 on: April 08, 2011, 06:17:24 pm »
Ninja demo translates each Ninja to a predifened position with the call
Code: [Select]
ninja.getRoot().translate(..)remove that call. if your model is at origin (0, 0, 0) in 3d editor, it will also be in jPCT.

right, CameraOrbitController positions camera such that camera looks at camera target.

your model looks upside down due to difference in coordinate systems of jPCT and 3d editor app. as yoi said, if you pass
Code: [Select]
-rotation x180
to import scripts model and skeleton will be rotated 180 degrees around X axis. no need to specify Y and Z rotation if they are zero.

Offline pages

  • byte
  • *
  • Posts: 6
    • View Profile
Re: Bones - Skeletal and Pose animations for jPCT
« Reply #163 on: April 08, 2011, 11:54:11 pm »
your model looks upside down due to difference in coordinate systems of jPCT and 3d editor app. as yoi said, if you pass
Code: [Select]
-rotation x180
to import scripts model and skeleton will be rotated 180 degrees around X axis. no need to specify Y and Z rotation if they are zero.

Cheers that worked perfect just couldn't use the -rotation as the last argument as it fails for some reason ( just in case others try it , use it as the first parameter seemed to work fine for me)

On the second problem of the positioning of the mesh , My model is at x,y,z 0,0,0 in the editor but it still appearing off center . As a test i used the ninja model which you give out but that also appears in the exact same location on start up





What might be different is in AndroidManifest.xml i used
Code: [Select]
android:screenOrientation="user"As i want to be able to have a more up close view of the models to fit more of the screen  , could this be the source of the problem ?

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Bones - Skeletal and Pose animations for jPCT
« Reply #164 on: April 09, 2011, 12:10:13 am »
Quote
just couldn't use the -rotation as the last argument as it fails for some reason
ah right, forgot to mention that. -in .. parameter must be last parameter as there may be many in files.

Quote
What might be different is in AndroidManifest.xml i used
Code: [Select]
android:screenOrientation="user"As i want to be able to have a more up close view of the models to fit more of the screen  , could this be the source of the problem ?
no, this cant be. jPCT automatically adjusts aspect ratio.

looking at the screenshot, if you didnt translate ninja to somewhere (NinjaDemoActivity does that), camera is located somewhere where x > 0. maybe there is a call to
Code: [Select]
cameraController.cameraAngle = <angle>in somewhere in your code where angle is non zero. check that please

if cannot find, print ninja's translation and camera position, that might give you a clue