jMonkeyEngine SDK: Procedural Textures with NeoTexture
The NeoTextureEditor allows creating tiled textures procedurally using a simple node interface for generating images, blending them, creating normal maps and much more. You can directly load the .tgr files as a material or export the generated images as .png files and use them in a jMonkeyEngine-based game.
Textures usually make up most of the size of a game distribution. This is why NeoTexture is not only an editor, but also a library that generates textures from .tgr files. Use the library to load .tgr files directly in jME3 as a material, without having to export the textures before. This means high-quality textures for your models, but just tiny description files in your distribution.
Creating and Editing a NeoTexture file
assets/Texturesdirectory and choose New… > Other.
In the New File Wizard, choose NeoTexture > Empty NeoTextureFile and click Next.
Give the file a name, for exmaple
A new file
neoMaterial.tgris created in the Textures directory and opens in the NeoTexture Editor.
Edit the .tgr file and create your procedural texture: (Learn more about creating Procedural Textures here)
Drag any pattern from the left bar to the editor area.
Right-click the editor area and paste a NormalMap filter node.
Connect the green output mark of the pattern with the red input mark of the filter. +This generates a Normal Map that can be used as bump map.
Adding the NeoTexture libraries to your project
To use NeoTexture tgr files directly in your application, you have to add the NeoTexture libraries to your project:
Right-click your project and select “Properties”
Go to the “Libraries” section of the properties window
Press “Add Library”..
Select “NeoTexture-Libraries” and press “add”
Loading tgr files as material
We want to use the procedural texture as a material based on
Lighting.j3md (the default). We know that Lighting.j3md supports DiffuseMap, NormalMap, SpecularMap, and ParallaxMap.
Click the Normal Map filter to select it. We want to use it as the Normal Map of the texture.
In the NeoTextures Properties window under
Export name, enter the name of the texture layer as it would appear in a .j3m file, e.g. “NormalMap”.
Click the pattern to select it. We want to (re)use it as Diffuse Map of the texture.
In the NeoTextures Properties window under
Export name, enter the name of the texture layer as it would appear in a .j3m file, e.g. “DiffuseMap”.
Click the Save button in the NeoTextures Editor. The .tgr file is saved with two layers. (We could add SpecularMap and ParallaxMap the same way, if we wanted.)
Let’s assign the newly created texture to a mesh to see what it looks like.
Open your Main.java file.
Choose Window→Palette to open the Palette. You will find two NeoTexture code snippets, one for adding the NeoTexture loader to the assetManager, and one for loading a NeoTexture material.
Drag&Drop one of each into the simpleInitApp() method of your application.
Adjust the .tgr file path names to match the file that we just created: “Materials/neoMaterial.tgr”.
Clean, build and run. You’re ready to load your procedural material!
assetManager.registerLoader(com.jme3.material.plugins.NeoTextureMaterialLoader.class,"tgr"); NeoTextureMaterialKey key = new NeoTextureMaterialKey("Materials/neoMaterial.tgr"); Material mat = assetManager.loadAsset(key); mat.setFloat("Shininess",12); /* Lighting.j3md has non-map parameters too that we can set. */ thing.setMaterial(mat);
The default Material Definition for NeoTextures is
Lighting.j3md, and it’s probably the one you will use most often. In case that you want to use additional texture parameters, other than DiffuseMap, SpecularMap, ParallaxMap, and NormalMap, you can switch to another Material Definition using setMaterialDef(), for instance:
Remember that the layer names in the .tgr file must match the ones declared in the .j3md file. In our example of
ColoredTextured.j3md, the .tgr file must contain a
ColorMap and you need to set a RGBAColor.
Using tgr files like normal textures in j3m files
You can use the .tgr files like normal textures in j3m files, with a syntax like this:
The part between the
? and the suffix is the name of the node you want to load as a texture. If you dont supply a name,
texture is used.
To be able to load these textures, you have to register a Locator and a Loader in the AssetManager, note that you can only register one loader per extension so you cannot load .tgr files as materials and as textures with the same assetManager.
assetManager.registerLocator("/", com.jme3.texture.plugins.NeoTextureLocator.class ); assetManager.registerLoader(com.jme3.texture.plugins.NeoTextureLoader.class,"tgr");