[Solved :)] using TextureAtlas

Sorry this is a very beginner question but I spent the last night reading tutorials and trying to figure it out and looks like I can’t get it. I have a texture atlas file created but I can’t figure out how to map to it.

if I have an atlas file (atlas.png) how do I set the texture Coordinates of a geometry to map to parts of the atlas file? is there a code example I could see ? I looked into the forum and wiki and there’ s nothing :frowning:

Thanks and sorry for the stupidity of my question.

Goddamit, I was posting the code. It was quoted three times in various jokes… Are you making fun of us?

[java] FloatBuffer buf = (FloatBuffer)geom.getMesh().getBuffer(Type.TexCoord).getData();

buf.put(new float[]{0,0,0,0.5f,0.5f,0.5f,0.5f,0}, 0, 0);


Read here how a mesh works:


1 Like

For some reason when I saw that reply I immediately saw “The angry German Kid” in my head. :wink:


this isn’t directed to anyone, just a good song


its x/y coordinates from 0 to 1, 0.5/0.5 would be the middle of the texture at that vertex.

where am I mapping to the atlas.png file? where in the code do you import or point to “Materials/atlas.png” ???

[java]Material m = new Material (assetManager, "Uncommon/MatDefs/Misc/Unshaded.j3md");

m.setTexture("ColorMap", assetManager.loadTexture("Materials/atlas.png"));



If you had actually read the wiki (no you didn’t, not even I could read it in 10 hours) you might have gotten an idea of the difference between texture, material, texture coordinates and mesh… This way you’re still stabbing in the dark. You have to assume that everything you think you have to do is wrong I am afraid, you try to write “Stairway to Heaven” after you learned your first guitar chord basically…

@wezrule I already tried that!!! and I get

[java]SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

com.jme3.asset.AssetLoadException: The given image cannot be loaded Models/atlas.png (Flipped) (Mipmaped)

at com.jme3.texture.plugins.AWTLoader.load(AWTLoader.java:203)

at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:273)

at com.jme3.asset.DesktopAssetManager.loadTexture(DesktopAssetManager.java:325)

at com.jme3.asset.DesktopAssetManager.loadTexture(DesktopAssetManager.java:344)

at com.jme3.asset.DesktopAssetManager.loadTexture(DesktopAssetManager.java:356)

at mygame.TestTextureAtlas.simpleInitApp(TestTextureAtlas.java:59)

at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:228)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:129)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:205)

at java.lang.Thread.run(Thread.java:619)[/java]

edit: I did and I know the difference. I didn’t know that you wanted to load atlas.png as a regular texture. I thought there’s a special way to import it.

so you have a file called “atlas.png” (all lowercase) in your assets/Models/ folder?

1 Like

yes yes it’s there… could it be corrupted? cz I can’t view it in my 3d editor but if I open it in my IDE I get

[java]<atlas numImages=“5”>

<texture file=“Materials0.png” trans=“false”>

<image name=“podOrangeMaterial” x=“0” y=“0” width=“960” height=“540” trans=“false”/>


<texture file=“Materials1.png” trans=“false”>

<image name=“podGreyMaterial” x=“0” y=“0” width=“960” height=“540” trans=“false”/>


<texture file=“Materials2.png” trans=“false”>

<image name=“podGreenMaterial” x=“0” y=“0” width=“960” height=“540” trans=“false”/>


<texture file=“Materials3.png” trans=“false”>

<image name=“podBlueMaterial” x=“0” y=“0” width=“960” height=“540” trans=“false”/>


<texture file=“Materials4.png” trans=“false”>

<image name=“podBlackMaterial” x=“0” y=“0” width=“960” height=“540” trans=“false”/>





damn looking at it now I think Atlas Maker didn’t do a good job


A texture atlas is an image file looking similar to this:

1 Like

I know Atlas Maker is supposed to fo that automatically 4 u so I dont waste my time on it in Photoshop.

@homsi said:
yes yes it's there... could it be corrupted? cz I can't view it in my 3d editor but if I open it in my IDE I get
damn looking at it now I think Atlas Maker didn't do a good job

Sorry but... WTF is this!? lol

Like I said its x/y coordinates. This topic is not special to jme3, theres lots of information about texture coordinates, UV maps etc. out there.

1 Like
@homsi said:
Ok believe it or not I finallly understand :)

Aren't epiphanies great or what? :P
1 Like

Guys I just wanted to say thank you for everything especially @normen and @madjack, I got it working (FINALLY) and as much as I hate saying it , I read the tutorials and looked like I missed a few, at least the important ones, and I understand it perfectly now. you were right, its much easier than I thought but like normen said, I was trying to do it w/o understanding the basics.

I apologize for the trouble and again thanks a lot!!!

Hope I am not blacklisted for further questions :slight_smile:

Good for you, really. Glad you got it working. Hopefully those shelves can fly around all colored to your liking now. :wink:

Also glad you’ll be able to work tomorrow. Actually, nevermind that, you cheated. You weren’t supposed to go to bed before you were through, but did anyway.

1 Like

oh not I’m not done yet hahaha I wish… according to my personal deadlines, i’m supposed to batch them (BatchNode) before I sleep… hopeflly won’t give me too many issues

then let me make your life easier hahah I think I struggled with this all last week and I posted on the forum but NOT AS MUCH AS U DID lol

PS: literally all my code is from the wiki >>>> I used 0.1% of my brain to write it :slight_smile:


Material materiel = new Material(myApp.getAssetManager(),“Common/MatDefs/Light/Lighting.j3md”);

materiel.setTexture(“DiffuseMap”, myApp.getAssetManager().loadTexture("/Materials/TextureAtlas/Colors.png")); // this is an atlas file

Vector2f[] texCoord = new Vector2f[4];

texCoord[0] = new Vector2f(0, 0);

texCoord[1] = new Vector2f(1,0);

texCoord[2] = new Vector2f(0,1);

texCoord[3] = new Vector2f(1,1);

Geometry geo= (Geometry) spatialToDraw;

geo.getMesh().setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));


geo.setMaterial(materiel );



then whenever you’re ready (loaded all ur material into batch) call:





1 Like