Setting a texture

I am trying to put a texture onto an object using the following line

[java]mat3.setTexture("ColorMap", assetManager.loadTexture("Textures/terrain.jpg"));[/java]

It is giving me an error saying that

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

java.lang.IllegalArgumentException: Material parameter is not defined: ColorMap

at com.jme3.material.Material.checkSetParam(Material.java:300)

at com.jme3.material.Material.setTextureParam(Material.java:396)

at com.jme3.material.Material.setTexture(Material.java:439)

at mygame.Main.simpleInitApp(Main.java:56)

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

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

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

at java.lang.Thread.run(Thread.java:662)



Is ColorMap the incorrect material parameter? If it matters, I dragged and dropped the jpg from my desktop into the Textures folder under Project Assets.

what material definition it is? for lighting you use “DiffuseMap” if it is unshaded and it dont work then try “m_ColorMap”

I am just trying to apply the image to a box. not lighting. just the image on the box.

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:materials_overview

I managed to fix it. I was using the wrong .j3md when i was creating the material. now its just too big haha. Any idea how to reduce the size of the texture on the box?

[java]



Box box = new Box(Vector3f.ZERO, 1.0f,1.0f,1.0f);

Spatial mybox = new Geometry(“Box”, box );

Material mymaterial = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

mymaterial.setTexture(“ColorMap”, assetManager.loadTexture(“Textures/mytexture.jpg”));

mybox.setMaterial(mymaterial);

mybox.setLocalTranslation(0.0f,0.0f,0.0f);

rootNode.attachChild(mybox);



[/java]



asking about material definition i mean “Common/MatDefs/Misc/Unshaded.j3md”.



Nice you fix it



to scale texture use:



[java]

box.scaleTextureCoordinates(new Vector2f(2, 2));[/java]

thank you both very much. very helpful.

so i tried using the scaleTextureCoordinates function but this is what I get. The textures edges are just stretched. It seems really odd.

heres the screenshot i took. any idea whats going on?



enable texture repeat.

I’m guessing you scaled your texture down, once then engine gets to the edge of your texture it just stretechs the last row or column of pixels to fill the remaining geometry.



If you wanted to repeat your texture you could try tweaking your texture loading as follows…



[java]

Texture t = assetManager.loadTexture(“Textures/mytexture.jpg”);

t.setWrap(Texture.WrapMode.Repeat);

mymaterial.setTexture(“ColorMap”,t);

[/java]



… i use this in Lighting to get my textures repeating correctly.





Other options for changing how large your texture is appearing would be to change your geometry (make it smaller or further from the camera), or you could padd the edges of your texture (put blank space around the edge of your jpg, but please avoid this if at all possible, it’s a terrible use of resources… I feel dirty for just suggesting it but it may help someone understanding the issue).



If you’re still stuck, try explaining, or drawing, exactly what you’re trying to achieve, to help us answer you more effectively :slight_smile:



Good Luck

James

I think my best option is to either move it away from the camera or change the size of my geometry. It is pretty large right now.