Texture Atlas creation

A forum for discussing development work on Ardor3D add-ons and extensions. Basically, anything that is Ardor3D that is not in the ardor3d-core module.
Forum rules
Developer discussions only. Newbie questions belong in the HELP! forum. This is a forum for discussing development work on Ardor3D add-ons and extensions. Basically, anything that is Ardor3D that is not in the ardor3d-core module.

Re: Texture Atlas creation

Postby MrCoder » Fri Dec 31, 2010 3:46 pm

done!
Destroy, Erase, Improve
User avatar
MrCoder
Site Admin
 
Posts: 755
Joined: Mon Nov 03, 2008 8:56 am
Location: Stockholm, Sweden

Re: Texture Atlas creation

Postby tduindam » Fri Jan 07, 2011 7:30 am

Hi guys,

I'm trying to use the texture atlas as well. All I get is an index out of bounds exception however.
Code: Select all
Exception in thread "main" java.lang.IndexOutOfBoundsException: 174776
   at java.nio.DirectByteBuffer.get(DirectByteBuffer.java:209)
   at com.ardor3d.extension.atlas.TexturePacker.fillDataBuffer(TexturePacker.java:335)
   at com.ardor3d.extension.atlas.TexturePacker.setDataPixel(TexturePacker.java:327)

The exception is thrown by this part of code. "sourceIndex" gets bigger the capacity of lightData allows.

Code: Select all
dataAsFloatBuffer.put(targetIndex, lightData.get(sourceIndex));
dataAsFloatBuffer.put(targetIndex + 1, lightData.get(sourceIndex + 1));
dataAsFloatBuffer.put(targetIndex + 2, lightData.get(sourceIndex + 2));


Could this maybe have something to do with the type of textures we are using?
tduindam
regular
 
Posts: 60
Joined: Fri Jun 12, 2009 1:06 pm

Re: Texture Atlas creation

Postby MrCoder » Fri Jan 07, 2011 10:10 am

Could very well be! I'll have a look. What types of textures do you have then?
Destroy, Erase, Improve
User avatar
MrCoder
Site Admin
 
Posts: 755
Joined: Mon Nov 03, 2008 8:56 am
Location: Stockholm, Sweden

Re: Texture Atlas creation

Postby tduindam » Fri Jan 07, 2011 11:14 am

What information are you looking for exactly? The result of texture.getTextureStoreFormat() ? In that case there are three types of textures we use: NativeDXT1A, CompressedRGB and RGB8. Also it might be useful to know that we usually have 4 textures per object, for diffuse, specular, illumination and normals.

I'm quite inexperienced when it comes to texturing, so I might not have given the most useful information, just let me know if you need something else.
tduindam
regular
 
Posts: 60
Joined: Fri Jun 12, 2009 1:06 pm

Re: Texture Atlas creation

Postby MrCoder » Fri Jan 07, 2011 4:23 pm

Gotcha, yeah compressed textures won't work since i'm doing the composition of the atlas using the data buffers behind the textures. Should add a check for those formats and fire up a warning. Renanse had an idea on using RTT to compose the atlas instead, which I might try out if i find the time (lets hope so!).

should be possible for you to create atlases for each type of texture you have. issue it once for texture index 0, then once for index 1 etc to create atlases for each of your types (diffuse, specular etc)
Destroy, Erase, Improve
User avatar
MrCoder
Site Admin
 
Posts: 755
Joined: Mon Nov 03, 2008 8:56 am
Location: Stockholm, Sweden

Re: Texture Atlas creation

Postby tduindam » Fri Jan 07, 2011 5:23 pm

Cool. Now I'm making different atlasses for all different types and skipping all compressed formats. Unfortunately I now get a NullPointerException:

Code: Select all
Exception in thread "main" java.lang.NullPointerException
   at com.ardor3d.extension.atlas.TexturePacker.insert(TexturePacker.java:193)
   at com.ardor3d.extension.atlas.TexturePacker.insert(TexturePacker.java:69)


Which corresponds to this line of code:
Code: Select all
final FloatBuffer destination = parameterObject.getTextureCoords();


It seems that all meshes that I use have no texture coordinates set.. I tried calling mesh.updateGeometricState(0) and mesh.updateWorldRenderStates() as I thought it might be an initialization issue but that didn't work. Should I do something else to initialize the texture coordinates?

Thanks!
tduindam
regular
 
Posts: 60
Joined: Fri Jun 12, 2009 1:06 pm

Re: Texture Atlas creation

Postby renanse » Sat Jan 08, 2011 12:59 am

Hmm, 193 is this line in my source...

Code: Select all
            destination.put(i, destination.get(i) * diffX + offsetX);


Either way, I can't really see what could be null? In your line, only parameterObject being null would cause NPE, but it wouldn't get that far if it was null. In the line above it would have to be destination, but again, it couldn't get past the line above it (destination.limit()) if it were null.
Gratitude is a mark of a noble soul and a refined character.
User avatar
renanse
Site Admin
 
Posts: 2955
Joined: Tue Oct 28, 2008 6:49 pm
Location: Austin, TX

Re: Texture Atlas creation

Postby tduindam » Sat Jan 08, 2011 3:47 am

I don't think the parameter object is null, I think it is requesting the texture buffer from the mesh, and that buffer is null.

About the line numbers, I think I might have changed some whitespace around by adding and removing some debug statements. I've reverted and double checked. The error occurs at this line:
Code: Select all
for (int i = 0; i < destination.limit(); i += 2) {


Which I think means that this call returns null:
Code: Select all
final FloatBuffer destination = parameterObject.getTextureCoords();


This is the only thing that function does:
Code: Select all
public FloatBuffer getTextureCoords() {
        return mesh.getMeshData().getTextureBuffer(textureIndex);
    }


Also I was thinking, currently I'm skipping compressed textures so that means that for some objects some textures go into the atlas whereas others don't. Might this lead to errors?
tduindam
regular
 
Posts: 60
Joined: Fri Jun 12, 2009 1:06 pm

Re: Texture Atlas creation

Postby renanse » Sat Jan 08, 2011 10:09 am

What textureIndex are you pointing to? Perhaps there are no tex coords in that channel. Sometimes only channel 0 is setup during import with coords and you need to copy them to the other channels you add textures to.
Gratitude is a mark of a noble soul and a refined character.
User avatar
renanse
Site Admin
 
Posts: 2955
Joined: Tue Oct 28, 2008 6:49 pm
Location: Austin, TX

Re: Texture Atlas creation

Postby MrCoder » Sun Jan 09, 2011 8:26 am

I'll add more error checking, and try to complicate the example a bit more. A question is, if we want it to fail with an exception or instead make it skip meshes without a texture or texturecoord but still work. The latter might feel easier at first, but it's usually better in the long run to force users to use the lib more strictly (only add meshes that they really intend to atlas bake). On the other hand if they use the lib like you do with different types of texture for each index, but some meshes only have a diffuse while others specular etc, then it might be nice to be able to use the same list for the atlas packer and have it automatically skip those that are not valid.
Destroy, Erase, Improve
User avatar
MrCoder
Site Admin
 
Posts: 755
Joined: Mon Nov 03, 2008 8:56 am
Location: Stockholm, Sweden

PreviousNext

Return to Extensions Development Discussions

Who is online

Users browsing this forum: No registered users and 0 guests