NeoTexture load/change from code

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.length
    4);

    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?


  1. 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.
  2. 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]
  3. 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]
  4. 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
  5. 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.

Cool, but I don’t quite understand, why didn’t you choose to extend the existing loader and NeoTexture plugin for the SDK?

I have looked at both, but without changing the library (NeoTexture engine) i have not found a way to get access to the parameters of the nodes after loading. And unfortunately in the contribution repo the NeoTextureEngine gets included only as lib.



All needed access function where private or not even existent. I have changes nothing in the original behaviour, so if you do not register the new loader you should have the same functionality as before.



Replacing my version of the library with the one found here, and adding the new loader as alternative loader should make this usable for everyone.

I merged the converter and the loader:

[java]

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");

}



public static Texture2D getTextureFromIntArray(int[] data, int res) {

ByteBuffer buffer = BufferUtils.createByteBuffer(data.length * 4);

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 (NeoMaterialLoader.getTextureFromIntArray(gen.getImage_ABGR(res, res, c), res));

}

}

[/java]

Actually after rethinking, i have modified also the Constructor of the TextureGenerator, now it needs to get instantiated before loading the file. I had to do that because i wanted to have multiple generators running paralell as background task for LOD’ing

can this superior version (im assuming) be exchanged fore thre one that comes standard? i dotn liek mucking aroudn with auto updating systems files… ya kno?