Saving and Loading Terrain Block

Hello I am trying to save a terrain block to a file in jme format using BinaryExporter. Then I want to use BinaryImporter to load it later. I am able to do that but the loaded terrain is textureless although I get no "unable to locate" errors from ResourceLocator.



Is it possible achieve what I want using BinaryExporter and BinaryImporter? If so, what possible error causes textures to be lost?

Here is my code for importing:


TerrainBlock localMapNode = (TerrainBlock) BinaryImporter.getInstance().load(mapFile);
 rootNode.attachChild(localMapNode);

Before you saved the file with BinaryExporter did you set your texture objects to store the image data?

myTexture.setStoreTexture(true);


Yes, I did that. Here is my code to generate terrain and to save terrain block.


private void buildTerrain() {


        MidPointHeightMap heightMap = new MidPointHeightMap(64, 1f);
        // Scale the data
        Vector3f terrainScale = new Vector3f(256, 0.0575f, 256);
        // create a terrainblock
        tb = new TerrainBlock("Terrain", heightMap.getSize(), terrainScale,
                heightMap.getHeightMap(), new Vector3f(0, 0, 0));

        tb.setModelBound(new BoundingBox());
        tb.updateModelBound();


        // generate a terrain texture with 2 textures
        ProceduralTextureGenerator pt = new ProceduralTextureGenerator(
                heightMap);
        pt.addTexture(new ImageIcon(TestTerrain.class.getClassLoader().getResource("jmetest/data/texture/grassb.png")), -128, 0, 128);
        pt.addTexture(new ImageIcon(TestTerrain.class.getClassLoader().getResource("jmetest/data/texture/dirt.jpg")), 0, 128, 255);
        pt.addTexture(new ImageIcon(TestTerrain.class.getClassLoader().getResource("jmetest/data/texture/highest.jpg")), 128, 255,
                384);
        pt.createTexture(32);

        // assign the texture to the terrain
        TextureState ts = display.getRenderer().createTextureState();
        Texture t1 = TextureManager.loadTexture(pt.getImageIcon().getImage(),
                Texture.MinificationFilter.Trilinear, Texture.MagnificationFilter.Bilinear, true);
        ts.setTexture(t1, 0);

        //load a detail texture and set the combine modes for the two terrain textures.
        Texture t2 = TextureManager.loadTexture(
                TestTerrain.class.getClassLoader().getResource(
                "jmetest/data/texture/Detail.jpg"),
                Texture.MinificationFilter.Trilinear,
                Texture.MagnificationFilter.Bilinear);

        ts.setTexture(t2, 1);
        t2.setWrap(Texture.WrapMode.Repeat);

        t1.setApply(Texture.ApplyMode.Combine);
        t1.setCombineFuncRGB(Texture.CombinerFunctionRGB.Modulate);
        t1.setCombineSrc0RGB(Texture.CombinerSource.CurrentTexture);
        t1.setCombineOp0RGB(Texture.CombinerOperandRGB.SourceColor);
        t1.setCombineSrc1RGB(Texture.CombinerSource.PrimaryColor);
        t1.setCombineOp1RGB(Texture.CombinerOperandRGB.SourceColor);

        t2.setApply(Texture.ApplyMode.Combine);
        t2.setCombineFuncRGB(Texture.CombinerFunctionRGB.AddSigned);
        t2.setCombineSrc0RGB(Texture.CombinerSource.CurrentTexture);
        t2.setCombineOp0RGB(Texture.CombinerOperandRGB.SourceColor);
        t2.setCombineSrc1RGB(Texture.CombinerSource.Previous);
        t2.setCombineOp1RGB(Texture.CombinerOperandRGB.SourceColor);

        t1.setStoreTexture(true);
        t2.setStoreTexture(true);

        tb.setRenderState(ts);
        //set the detail parameters.
        tb.setDetailTexture(1, 16);
        tb.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
        rootNode.attachChild(tb);


    }


    @Override
    public void simpleSetup() {

        buildTerrain();


        try {
            BinaryExporter.getInstance().save(tb, new File("terrain.jme"));
        } catch (IOException ex) {
            Logger.getLogger(ControlImplementor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }




Do I need to do something else?