TextureAtlas - a working example?

can anyone please post a working example of TextureAtlas? there’s already an example in the JavaDoc that shows how to do an atlasBatch with a scene. I am looking for an example where I can create an atlas manually from several textures and then set it on a material. I spent the last few days trying to figure it out with no luck :frowning:



thanks in advance

:facepalm: I told you TextureAtlas class doesn’t help you with your issue… You’re unbelievable.

We have a test class for everything in the code repo

http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/test/jme3test/tools/TestTextureAtlas.java

True but it only shows the makeAtlasBatch case and not creating an atlas manually and using it on object materials

Texture atlas allows one combined mesh to have several separate textures (combined into an atlas). In the end, though, it’s still one giant mesh, one material, and one giant texture.



To switch a face to using a different texture then you would have to somehow change its texture coordinates. I don’t know if the atlas class covers this case.



And anyway, if all you want to do is change colors then using vertex colors is a million times more straight forward.

As I said previously I have pretty much no idea what TextureAtlas does, but the name tells me it should hold an atlas of textures, like minecraft does; among other things.



I guess @homsi sees it the same way and would like to store textures in one and be able to retrieve each one when needed. The thing is, anyway, the way I see it, if you’re to use a texture atlas you should have it “filled” with your own textures/drawing into one big texture, thus I don’t see the point of what he’s trying to do by manually inserting them…



But then again, it could be used in such a way that you could draw spites individually and create an atlas texture from those directly from the disk. You could see this as a utility tool.



I don’t know… Just a stab in the dark here. And also, pardon my ignorance. :wink:

TextureAtlas is for creating atlases in code. You load a texture via the asset manager, add it to the atlas and then you can move the texture coordinates of any mesh that uses one of these textures to the new coordinates so that when you apply a material using the atlas texture it will show up right. If you use geometry that already uses the default textures (Diffuse/ColorMap, NormalMap and SpecularMap) then its easy and you can work with geometry. If you want to compile your own maps you can do that but you have to bring the correct meshes and texture tiles (they are stored by asset key name) together. If your meshes never had any textures in the atlas to begin with there is no point in using the TextureAtlas for them as the textures will not map correctly anyway.

1 Like

Ah, I see.



So, as I see it, this isn’t a texture map that you could use to store sprites or something along that line, to do 2D animation for example. Well, you could I guess if you used a Quad. shrug

If you have a simple even-tiled texture atlas putting your texture coords right on a mesh is a no-brainer, you could even make a Control with nice makeWood() or makeStone() methods if you wanted.



TextureAtlas is for situations where you e.g. want to create procedural terrain (from basic loaded models) and do not know beforehand what textures should best be on the atlas with the compiled scene. It will also help a lot in the SDK, I plan to add an “atlasing tool” that basically allows you to click around a project or scene and “collect” textures for the atlas as well as “apply” them to geometry in a scene, similar to the “optimize” function.

Got it.



All that’s left to know now is what exactly @homsi wants to do with that. :wink:

Guys, first I apologize in advance as I have NO experience at all in game programming and even my Java experience is limited to 2-3 years (just finished reading my first Java book for beginners, reading one a Java for advanced) - So if you don’t want to read my post, I understand perfectly. Normen in particular, I sincerely understand your frustration but bare with me, I want to learn…



Having said that, I have a BatchNode of thousands and thousands of objects (shelves) that I successfully batched into one node and colored them in a red material (with shininness and other effects), the textures are all even-tiled, very simple colors - cool



Now that I move these shelves around in the game, at some point they need to change the color of these shelves. Obviously changing the color of a child in a BatchNode would trigger an error. I was recommended to use TextureAtlas as it’s a Texture parent that holds many sub textures (or parent material that has many sub materials) where i could now simply changing the color of a specific shelf by simply choosing one of the sub materials inside the Parent material (TextureAtlas) and Voila! problem solved.




TextureAtlas is for creating atlases in code.


Great!! thats what I 'm looking for and I thought that's what I was doing by using:

[java]
static TextureAtlas atlas = new TextureAtlas(1024, 1024);
atlas.addTexture(assetManager.loadTexture("Materials/podGreenMaterial.png"), "atlasColorMap");
atlas.addTexture(assetManager.loadTexture("Materials/podBlueMaterial.png"), "atlasColorMap");
atlas.addTexture(assetManager.loadTexture("Materials/podORangeMaterial.png"), "atlasColorMap");[/java]

If you use geometry that already uses the default textures (Diffuse/ColorMap, NormalMap and SpecularMap) then its easy and you can work with geometry.


I think that's the part that I don't quite get. How would I know? I am simply creating a Box for my test example but in my program I want to import models created previously from Blender (.blend --> .j3o). I don't care about leaving the material from Blender or simply applying one via code - whatever is easier.


Again I apologize for being slow on this, but I am trying to learn this.

Thanks a lot for all the help

This is a much better question than anything I’ve read so far from you. That should’ve been how you posted the problem first. :wink:



What is triggering my curiosity is this:

Having said that, I have a BatchNode of thousands and thousands of objects (shelves)


Why do you need thousands and thousands of shelves!? I have a really hard time with this. Do you intend to draw those on the screen? I hope not because thousands of thousands of shelves wouldn't agree with the engine honestly. It depends on LOD, # of tris, etc, but you might want to rethink that at first glance.

It could be that you're right and you do need this, but I'd like to understand more before going further.

yes, LOD is definitely my 2nd step. But I am working on some sort of an animation rather than a game and I need to see shelves moving around. When zooming out I want to be able to see All of them (number could be as many as 20000 shelves) - so LOD is a must. But I want to figure this out first as batching improved my fps by like 10000x so before proceeding I want to make sure I can change shelves’ colors after batching them

If they all use the same texture you don’t need an atlas at all. Again, notice the difference between a texture atlas (a texture) and the TextureAtlas class (code to create an atlas in-game). All you need to make sure if theres different shelves is that all use one texture where all imagery for shelves is on. Use that texture atlas in your 3d editor and you’re done, all can be batched in one BatchNode as they all use the same texture. If the material is technically not the same that doesn’t matter, create a new one. The texture coordinates are saved in the mesh.

If they all use the same texture you don’t need an atlas at all.


So by that you mean the same texture even if the color (diffuse) was different? from what I understand if they have diff colors that they do not use the same texture therefore, I need to use atlas. Whats wrong with my thinking here? again pardon my ignorance.


Again, notice the difference between a texture atlas (a texture) and the TextureAtlas class (code to create an atlas in-game).


right, and I want to use TextureAtlas to create an atlas (if I need to create one after all) in my code by loading all my possible textures into it. I am trying not to deal with creating the atlas through a 3d editor.
@homsi said:
So by that you mean the same texture even if the color (diffuse) was different? from what I understand if they have diff colors that they do not use the same texture therefore, I need to use atlas. Whats wrong with my thinking here? again pardon my ignorance.

I honestly can't tell you whats wrong with your thinking but its so basic that you can ask questions like "be the same texture even if diffuse was different". The diffuse map is the texture (for color) of the model. Please take the time and do the tutorials and some small applications before you approach things where you need batch nodes and texture atlases.
Edit: Again, to color your meshes you need to change their texture coordinates to another place on the texture (which should best be created in photoshop beforehand, not in code).
I honestly can’t tell you whats wrong with your thinking but its so basic that you can ask questions like “be the same texture even if diffuse was different”. The diffuse map is the texture (for color) of the model.

but i didn't ask that. I know whats a diffuse map, I know what's the diff b/w materials and textures, I think even I'm not clarifying my questions or you r reading half my posts and judging negatively

Edit: Again, to color your meshes you need to change their texture coordinates to another place on the texture (which should best be created in photoshop beforehand, not in code).

but what I am trying to do is import via code Already created .png files of different colors (squares with diff colors) and import them considering them as different textures - and then create a texture atlas via code with these files as sub-textures.
If you have a simple even-tiled texture atlas putting your texture coords right on a mesh is a no-brainer, you could even make a Control with nice makeWood() or makeStone() methods if you wanted.


so I need to do this: create using a 3d editor a atlas file (.png) containing all my textures (colors that I need to use). This leaves me with the question on how to map my uv coordinates? and thats the code example I was looking for.

edit:

just saw this

Edit: Again, to color your meshes you need to change their texture coordinates to another place on the texture (which should best be created in photoshop beforehand, not in code


fine, I already created a file with all the colors, how do I map through it?

Is it just the colors your are changing?

yes the colors of nodes that are already batched in a BatchedNode