Could someone explain how to use an alphamap for the texturesplatt effect?
I have 1 image for the grass texture that should be on the whole terrain and i have a road texture and a .tga file created in photoshop
to use as the alphamap. I have tried to add the images in the texturestate menu but I dont understand how to use the .tga file as alphamap.
Have a look at TestTerrainSplatting and TestIsland
You need to either use a shader or combine modes so that the alphamap is blended with the colormap to produce splatting, see the tests MrCoder mentioned.
I tried to run TestIsland from eclipse and i get this error:
28.okt.2007 01:37:34 class jmetest.terrain.TestIsland start()
SEVERE: Exception in game loop
java.lang.NullPointerException
at jmetest.terrain.TestIsland.createTerrain(Unknown Source)
at jmetest.terrain.TestIsland.simpleInitGame(Unknown Source)
at com.jme.app.BaseSimpleGame.initGame(Unknown Source)
at com.jme.app.SimplePassGame.initGame(Unknown Source)
at com.jme.app.BaseGame.start(Unknown Source)
at jmetest.terrain.TestIsland.main(Unknown Source)
28.okt.2007 01:37:34 com.jme.app.BaseSimpleGame cleanup
INFO: Cleaning up resources.
28.okt.2007 01:37:34 com.jme.app.BaseGame start
INFO: Application ending.
runs ok here… my guess is that eclipse is not setup to copy over the .raw file.
I've noticed I had a slight difference in the code for this test on one of my machines that avoided the same error you report. I've checked that in and hopefully it will now work for you as well.
I reinstalled eclipse and then it suddenly worked. The technique with alphamaps used in TestIsland can be used on a loaded 3d object too right? I have made a terrain in Blender and loading it from a .obj file…
yeah any model…
I tried to create a box and the material then works, but when I use the model that I load from a .obj file it looks like its using
the color of the .obj model and it doesnt show the material i create in jme code.
Maybe theres a way to load the model without any texture or material?
The materials and textures and states are created and applied to the shape/object in a method so the same code is used for the Box as for the loaded .obj file.
Like this: setupTexture(mybox) or setupTexture(loadedModel)
The .obj file is just one of those premade box objects in wings3d otherwise untouched and exported as a .obj file. I have also tried to export a file from blender but theres no difference.
When i'm testing with a Box shape I create it like this:
Box boks = new Box("terrenget",new Vector3f(20,20,20),new Vector3f(1,1,1));
When i'm trying to use the .obj file instead of a Box it's done like this:
URL model=TestHillTerreng.class.getClassLoader().getResource("landskap.obj");
// Create something to convert .obj format to .jme
FormatConverter converter=new ObjToJme();
// This byte array will hold my .jme file
ByteArrayOutputStream BO=new ByteArrayOutputStream();
try {
// Use the format converter to convert .obj to .jme
converter.convert(model.openStream(), BO);
Spatial maggie=(Spatial)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
// shrink this baby down some
maggie.setLocalScale(1f);
maggie.setModelBound(new BoundingSphere());
maggie.updateModelBound();
setupTexture(maggie);
//for testing the Box
//setupTexture(boks);
} catch (IOException e) { // Just in case anything happens
System.out.println("Damn exceptions!" + e);
e.printStackTrace();
System.exit(0);
}
And i'll show you the setupTexture method too:
private void setupTexture(Spatial model) {
// create some interesting texturestates for splatting
TextureState ts1 = createSplatTextureState("baserock.jpg", null);
TextureState ts5 = createSplatTextureState("road.jpg","roadalpha.png");
TextureState ts6 = createLightmapTextureState("lightmap.jpg");
//alpha used for blending the passnodestates together
AlphaState as = display.getRenderer().createAlphaState();
as.setBlendEnabled(true);
as.setSrcFunction(AlphaState.SB_SRC_ALPHA);
as.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
as.setTestEnabled(true);
as.setTestFunction(AlphaState.TF_GREATER);
as.setEnabled(true);
// //////////////////// PASS STUFF START
// try out a passnode to use for splatting
PassNode splattingPassNode = new PassNode("SplatPassNode");
splattingPassNode.attachChild(model);
PassNodeState passNodeState = new PassNodeState();
passNodeState.setPassState(ts1);
splattingPassNode.addPass(passNodeState);
passNodeState = new PassNodeState();
passNodeState.setPassState(ts5);
passNodeState.setPassState(as);
splattingPassNode.addPass(passNodeState);
// lock some things to increase the performance
splattingPassNode.lockBounds();
splattingPassNode.lockTransforms();
splattingPassNode.lockShadows();
splattingPassNode.setRenderState(ts5);
rootNode.attachChild(splattingPassNode);
}