Here are the changes i have made to allow node modifications and texture loading from inside the code.
The new library can be downloaded here: NeoTextureEditor.zip
I have only modified the needed things in the original library.
Additional files needed to work are:
NeoMaterialLoader.java
[java]
package MaterialSystem;
import com.jme3.asset.AssetInfo;
import com.jme3.asset.AssetLoader;
import com.jme3.asset.AssetManager;
import com.mystictri.neotexture.TextureGenerator;
import java.io.IOException;
/**
*
-
@author Michael
/
public class NeoMaterialLoader implements AssetLoader{
public Object load(AssetInfo assetInfo) throws IOException {
TextureGenerator generator=new TextureGenerator();
generator.loadGraph(assetInfo.openStream());
return generator;
}
public static void registerLoader(AssetManager asset){
asset.registerLoader(NeoMaterialLoader.class, "tgr");
}
}
[/java]
and
MaterialHelpers.java
[java]
public class MaterialHelpers {
public static Texture2D getTextureFromIntArray(int[] data,int res){
ByteBuffer buffer=BufferUtils.createByteBuffer(data.length4);
System.out.println(data.length);
buffer.asIntBuffer().put(data).clear();
return (new Texture2D(new Image(Image.Format.RGBA8,res,res,buffer)));
}
public static Texture2D generateTexture(TextureGenerator gen,Channel c, int res){
return(MaterialHelpers.getTextureFromIntArray(gen.getImage_ABGR(res, res, c), res));
}
}
[/java]
So how to use the system?
- Create your NeoTextureMaterial like you always did. You can use the build in editor.
NOTE: You have to set an Export Name on every Node you want to modify later from inside the code or get the output texture.
- In your Application you need to register the loader
[java]assetManager.registerLoader(NeoMaterialLoader.class, "tgr");[/java]
3)Now you can load a TextureGeneratorGraph trough the assetmanager
[java] TextureGenerator material = (TextureGenerator) assetManager.loadAsset("Materials/PlanetMaterials/Rock/moon0.tgr");[/java]
- You can get a specific node with following code (Where the name is the export name set in the TextureEditor
[java]TextureGraphNode cmap = material.getGraphNode("ColorMap");[/java]
- You can generate a texture with following command: (in this example a 2048x2048 texture)
[java]Texture2D tex = MaterialHelpers.generateTexture(material, cmap.getChannel(), 2048);[/java]
or
- Modify a node.
For example the following code adds a red value at the end of a ColorizeNode
java.get().addEntry(new Vector4(1,0,0,1), 1);[/java]
I recommand strongly to look at the source code of the specific nodes to get a parameter list.
With a bit of additional coding you can also modify the connections between nodes, adding new nodes as well as deleting nodes.