Texture Atlas creation
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.
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.
24 posts
• Page 1 of 3 • 1, 2, 3
Texture Atlas creation
Got some code in for automatic creation of texture atlases, iteration 1. Probably lots of room for improvements to be able to use it in more situations. Currently, you add meshes to the atlas creator and it packs its texture into atlases, assigns the mesh the atlas it was added too and also changes it's texture coordinates to map into the atlas. So, basic usage atm is:
Create a texture packer with an atlas size. When an atlas is full it will move on to a new one. Textures that are bigger than the set size will be skipped.
Add meshes to the packer. (Many options here as well if you want it to use a different texture index source/target)
Finally create all the atlases and apply to all meshes involved
See AtlasExample for an example of using this. One very nice thing except for any performance improvement is that it works very well in combination with the MeshCombiner. If an atlas pack is issued on meshes you want to combine, texturing will now work as well.
(See TestAtlasPacker for a swing test of the actual texture pack algorithm)
Create a texture packer with an atlas size. When an atlas is full it will move on to a new one. Textures that are bigger than the set size will be skipped.
- Code: Select all
final TexturePacker packer = new TexturePacker(256, 256);
Add meshes to the packer. (Many options here as well if you want it to use a different texture index source/target)
- Code: Select all
packer.insert(mesh)
Finally create all the atlases and apply to all meshes involved
- Code: Select all
packer.createAtlases();
See AtlasExample for an example of using this. One very nice thing except for any performance improvement is that it works very well in combination with the MeshCombiner. If an atlas pack is issued on meshes you want to combine, texturing will now work as well.
(See TestAtlasPacker for a swing test of the actual texture pack algorithm)
Destroy, Erase, Improve
-

MrCoder - Site Admin
- Posts: 755
- Joined: Mon Nov 03, 2008 8:56 am
- Location: Stockholm, Sweden
Re: Texture Atlas creation
Thanks 
Things I want(need) to add:
1. More safety checks, error handling
2. User definable border size
3. A way to use this on images in "offline" mode, which packs images from disk into atlases and spits out a file with offsets for each texture into the atlases. I would have a use for this for ArdorCraft for example, for easy atlas creation as part of the pipeline.
Things I want(need) to add:
1. More safety checks, error handling
2. User definable border size
3. A way to use this on images in "offline" mode, which packs images from disk into atlases and spits out a file with offsets for each texture into the atlases. I would have a use for this for ArdorCraft for example, for easy atlas creation as part of the pipeline.
Destroy, Erase, Improve
-

MrCoder - Site Admin
- Posts: 755
- Joined: Mon Nov 03, 2008 8:56 am
- Location: Stockholm, Sweden
Re: Texture Atlas creation
Thanks, that will be of use, but for now with my own code I always get a
java.lang.IndexOutOfBoundsException: 8
at java.nio.DirectFloatBufferU.put(DirectFloatBufferU.java:286)
at com.ardor3d.extension.atlas.TexturePacker.insert(TexturePacker.java:80)
Because in my case in
I happen to have destination.limit = 8 and source.limit = 24 !
For now I did not study texture coordinates a lot (just read what's on wikipedia), I hope I will be able to understand the matter !
Thanks again for sharing this texturePacker, really makes a great combo with meshcombiner !
java.lang.IndexOutOfBoundsException: 8
at java.nio.DirectFloatBufferU.put(DirectFloatBufferU.java:286)
at com.ardor3d.extension.atlas.TexturePacker.insert(TexturePacker.java:80)
Because in my case in
- Code: Select all
final FloatBuffer source = cachedParameter.getTextureCoords();
final FloatBuffer destination = parameterObject.getTextureCoords();
for (int i = 0; i < source.limit(); i++) {
destination.put(i, source.get(i));
}
I happen to have destination.limit = 8 and source.limit = 24 !
For now I did not study texture coordinates a lot (just read what's on wikipedia), I hope I will be able to understand the matter !
Thanks again for sharing this texturePacker, really makes a great combo with meshcombiner !
-

sorcerer - newcomer
- Posts: 16
- Joined: Mon Jan 05, 2009 12:46 pm
Re: Texture Atlas creation
I bet there are more bugs in there than that!
I'll try to fix this right away!
Destroy, Erase, Improve
-

MrCoder - Site Admin
- Posts: 755
- Joined: Mon Nov 03, 2008 8:56 am
- Location: Stockholm, Sweden
Re: Texture Atlas creation
It works now, thanks !
Just a small hint : I call the packer from an initialization method (not from render loop like in your example), so I had to do myNode.updateGeometricState(0) before packIntoAtlas , or else I get a nullpointer in TextureParameter constructor, at mesh.getWorldRenderState(StateType.Texture)).getTexture.
--> After writing this I tried with mesh.getLocalRenderState in TextureParameter constructor and it seems to work ...
Just a small hint : I call the packer from an initialization method (not from render loop like in your example), so I had to do myNode.updateGeometricState(0) before packIntoAtlas , or else I get a nullpointer in TextureParameter constructor, at mesh.getWorldRenderState(StateType.Texture)).getTexture.
--> After writing this I tried with mesh.getLocalRenderState in TextureParameter constructor and it seems to work ...
-

sorcerer - newcomer
- Posts: 16
- Joined: Mon Jan 05, 2009 12:46 pm
Re: Texture Atlas creation
Cool, I just want to make sure it works also for meshes that got their texture from a spatial parent higher up in the tree. I'll find a way to solve it when no update has been run. Thanks again for the feedback!
Destroy, Erase, Improve
-

MrCoder - Site Admin
- Posts: 755
- Joined: Mon Nov 03, 2008 8:56 am
- Location: Stockholm, Sweden
Re: Texture Atlas creation
You might do something like check isDirty and update the world renderstates if needed.
Gratitude is a mark of a noble soul and a refined character.
-

renanse - Site Admin
- Posts: 2955
- Joined: Tue Oct 28, 2008 6:49 pm
- Location: Austin, TX
24 posts
• Page 1 of 3 • 1, 2, 3
Return to Extensions Development Discussions
Who is online
Users browsing this forum: No registered users and 1 guest