Author Topic: Loading Bones on Android  (Read 69997 times)

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Loading Bones on Android
« on: August 29, 2011, 10:02:52 am »
Assuming this is right (on the desktop app to save the bones file):
Code: [Select]
     private void saveToBones(String outFileName) {
FileOutputStream outStream = null;
try {
     outStream = new FileOutputStream(outFileName);
     BonesIO.saveGroup(animatedGroup, outStream);
     outStream.close();
}
catch (FileNotFoundException e) {System.err.println("File Not Found Problem: "+e.getMessage());}
catch (IOException e) {System.err.println("IO Problem: "+e.getMessage());}
     }

createAnimatedGroup() should look like:
Code: [Select]
protected AnimatedGroup createAnimatedGroup() throws Exception {
AnimatedGroup animatedGroup = BonesIO.loadGroup(getResources().openRawResource(R.raw.andersonbones));

Texture texture = new Texture(getResources().openRawResource(R.raw.andersondiffuse));
TextureManager.getInstance().addTexture("texture", texture);

for (Animated3D o : animatedGroup) {
o.setTexture("texture");
o.build();
o.discardMeshData();
}
return animatedGroup;
}

Right? But this isn't working on my phone. I also tried
Code: [Select]
AnimatedGroup animatedGroup = BonesIO.loadGroup(new FileInputStream(objectFileName));
on the desktop, but it crashes. I should point out that the .bones file looks about right at 2241 KB. I appreciate any insights.

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Loading Bones on Android
« Reply #1 on: August 29, 2011, 10:41:46 am »
post logs and stack trace please

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Loading Bones on Android
« Reply #2 on: August 29, 2011, 06:02:12 pm »
Actually, I got it to a point in which it no longer crashes. But try as I might I can't get the camera to see it.

I've tried NOT calling discardMeshData() and specifically setting each Animated3D instance to setVisibility(true). Nothing works, but it looks a lot like it should. I even called calcNormals() just to be sure and that didn't make it visible either.

But, by the way,    
Code: [Select]
AnimatedGroup animatedGroup = BonesIO.loadGroup(new FileInputStream(objectFileName));
is now working. But the same file still doesn't load on my phone. And the same camera is on both versions (camera should see the same thing but it shows nothing on phone version).
« Last Edit: August 29, 2011, 06:49:04 pm by AGP »

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Loading Bones on Android
« Reply #3 on: August 29, 2011, 08:59:11 pm »
Now, I've also played with the near and far plane. To sum up:
-I'm seeing the "world" (the FrameBuffer's background color is being drawn) but not the model
-It's not crashing
-The file works and is visible on the PC version
-The camera is in the exact same position as the one on the PC version
-Config.maxPolysVisible > number of polys on the model
-near and far planes are very small and very large respectively
I have nothing left to try as far as I can tell (even the normals don't seem to be the problem). Help?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Loading Bones on Android
« Reply #4 on: August 30, 2011, 07:00:19 am »
-Config.maxPolysVisible > number of polys on the model
This isn't related to your problem, but i though i should mention it: This is wasteful. For the Android version, you don't have to reserve that much space, because it doesn't really stand for polygons anymore (but the naming stayed the same for compatibility reasons) but for compiled object parts. An object with 32,000 polygons can very well get away with 4 entries in that structure instead of 32,000.

I'll adjust the docs for this setting.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Loading Bones on Android
« Reply #5 on: August 30, 2011, 07:15:51 am »
Cool, thanks. But I suggest renaming maxPolysVisible. Since I already knew it, I didn't look it up on the AE-specific docs. If it's going to do something potentially counter-productive you should totally just rename it. jpct-AE is too young for you to have grave concerns about backward-compatibility anyway.

Do you have any clue as to what might be causing my problem? I assume if it were memory-related it would be crashing, so it really makes no sense to me.
« Last Edit: August 30, 2011, 07:22:37 am by AGP »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Loading Bones on Android
« Reply #6 on: August 30, 2011, 07:52:30 am »
Have you tried to replace your model with some placeholder (for example from Primitives) to see if that actually appears?

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Loading Bones on Android
« Reply #7 on: August 30, 2011, 05:28:36 pm »
Yes, even an OBJ version of the same model works.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Loading Bones on Android
« Reply #8 on: August 30, 2011, 06:11:04 pm »
Hey, now I'm getting (for the first time!) a "version mismatch" message: "Current version: 3, stream version: 2". That's a jpct message, what does it mean?

No, that was just when I tried replacing my model with Raft's ninja (I guess it was saved with an older version of the exporter).
« Last Edit: August 30, 2011, 07:57:34 pm by AGP »

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Loading Bones on Android
« Reply #9 on: August 30, 2011, 08:34:27 pm »
OK, I narrowed it down to the fact that it crashes just before the following loop ("all's well" is printed before any problem occurs). But again, the file is working (the desktop version of the program loads it nicely). "o is null!" never gets printed.
Code: [Select]
Logger.log("\n\n************************************************************************All's well.\n\n\n");
for (Animated3D o : animatedGroup) {
if (o == null)
Logger.log("****************************************o is null!!!!");
o.setTexture("texture");
o.build();
o.discardMeshData();
}

Someone help me, please.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Loading Bones on Android
« Reply #10 on: August 30, 2011, 11:03:51 pm »
I solved it. I'm not remotely sure as to what changed between yesterday it not crashing to it crashing today. But crashing is far more useful becuase it lets you debug it!

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Loading Bones on Android
« Reply #11 on: September 02, 2011, 08:03:02 am »
you use a Bones file which was serialized by version 2 but you try to open it with version 3.

btw, this is not a log message. this is an exception and you possibly catch print and ignore it.

Hey, now I'm getting (for the first time!) a "version mismatch" message: "Current version: 3, stream version: 2". That's a jpct message, what does it mean?

No, that was just when I tried replacing my model with Raft's ninja (I guess it was saved with an older version of the exporter).

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Loading Bones on Android
« Reply #12 on: September 03, 2011, 08:10:08 am »
On one of my posts I replaced my model with yours. I noticed it was your model that caused that message and edited that post. At one point an exception was being thrown, and then I changed a few things (not very scientific, I know, but I was trying this for the first time and kind of in a hurry to see it working), one of which the model. I had fixed some things but, in replacing my model with yours, had introduced that message. But anyway, I got it working. But my 9300-poly model (+-4500 vertices) is only rendering at a measly 11 fps on a Galaxy S 2, so the test isn't very good.
« Last Edit: September 03, 2011, 08:12:52 am by AGP »

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: Loading Bones on Android
« Reply #13 on: September 03, 2011, 11:12:41 am »
i'm afraid 9300 polys is a bit high for such devices

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Loading Bones on Android
« Reply #14 on: September 03, 2011, 08:07:32 pm »
On Egon's request, I just did a very valid test: didn't call animateSkin or animatePose. Otherwise, it's the same program and the same model. It shot up to 60 frames/second. The same model in Unity runs perfectly, so there is, no doubt (now that we know that it's not the graphics pipeline) a lot of room for optimization for Bones.