Noob question about Material and Texture

I am reading the Tutorial, in the Material chapter, I found the Texture use assetManager.loadTexture to load the texture without create an instant like Material. So I tried to change the Material line from:
Material cube1Mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
Material cube1Mat = assetManager.loadMaterial(“Common/MatDefs/Misc/Unshaded.j3md”);

But it didn’t work, so in what situation should I use loadMaterial?

1 Like

loadMaterial() is for .j3m files. It’s a way of defining the material parameters in a file. j3md is a material definition file. It defines the shaders, the parameters that are available, etc. but it doesn’t set any of the parameter values.

new Material() is fine to use. The only thing that the asset manager would give you us caching.

Why Texture does not required new Texture() and use assetManager.loadTexture() directly?

@limwerks said: Why Texture does not required new Texture() and use assetManager.loadTexture() directly?

You can also create a new texture directly if you already have an image… but you have to use one of the concrete subclasses like Texture2D.

You can load Materials, too… but you have to load them from a material file (.j3m). Loading them from a j3md doesn’t really make sense because it wouldn’t have any parameters set. Just like if you create a new Texture2d() from scratch then you have to set everything yourself, also.

…but the bottom line is that a MaterialDef is not the same as a Material. A j3md defines a MaterialDef.

And actually, this is kind of all covered right in the tutorial:

…scroll down to the exercises.

Thanks for the link, I am reading that tutorial.

I cannot figure out why I cannot write in this way for create a Texture.

[java]Texture cube1Tex = new Texture();
cube1Tex = assetManager.loadTexture(“Interface/Logo/Monkey.jpg”);[/java]

Texture is an abstract class. You cannot instantiate it. Nor would you then want to assign it to another instance that you loaded.

I recommend some Java or OOP tutorials to understand the concepts of object oriented languages. You seem to have some confusion at the Java language level.

Ah! Thanks, I feel sorry for my stupid question. I just read the jME3 javadoc and found Texture is abstract.

Yes I need to brush up my Java skill, I haven’t touch Java after J2SE 1.4