Package com.benkyou.client.systems

Source Code of com.benkyou.client.systems.TerrainSystem

/*
* Project Beknyou
* Copyright (c) 2010-2011 Saint Paul College, All Rights Reserved
* Redistributions in source code form must reproduce the above
* Copyright and this condition.
* The contents of this file are subject to the GNU General Public
* License, Version 2 (the "License"); you may not use this file
* except in compliance with the License. A copy of the License is
* available at http://www.opensource.org/licenses/gpl-license.php.
*/
package com.benkyou.client.systems;

/**
*
* @author Adam Hess
*/
import com.jme3.asset.AssetManager;
import com.jme3.material.Material;
import com.jme3.terrain.geomipmap.*;
import com.jme3.terrain.heightmap.*;
import com.jme3.texture.Texture;
import com.jme3.texture.Texture.WrapMode;
import com.jme3.scene.*;
import com.jme3.water.SimpleWaterProcessor;

/**
*
* @author student
*/
public class TerrainSystem {

    private TerrainQuad terrain;
    private Spatial tTerrain;
    private Material mat_terrain;
    private AssetManager mgr;

    /**
     *
     * @param mgr
     */
    public TerrainSystem(AssetManager mgr) {
        this.mgr = mgr;
       // defaultTerrain();
        defaultWorld();
    }

    private void defaultWorld(){
         tTerrain = (Spatial) mgr.loadAsset("Scenes/DefaultWorld.j3o");
    }
    /**
     *
     */
    public void defaultTerrain() {
        tTerrain = (Spatial) mgr.loadAsset("Textures/Terrain/testLand3.j3o");
        //make terrain material and load 4 textures into it
        mat_terrain = new Material(mgr, "Textures/Terrain/Terrain.j3md");
        //add alpha map
        mat_terrain.setTexture("Alpha", mgr.loadTexture("Textures/Terrain/alphamap3.png"));
        //add grass
        Texture grass = mgr.loadTexture("Textures/Terrain/grass.jpg");
        grass.setWrap(WrapMode.Repeat);
        mat_terrain.setTexture("Tex1", grass);
        mat_terrain.setFloat("Tex1Scale", 64f);
        //add the snow
        Texture snow = mgr.loadTexture("Textures/Terrain/snow.jpg");
        snow.setWrap(WrapMode.Repeat);
        mat_terrain.setTexture("Tex2", snow);
        mat_terrain.setFloat("Tex2Scale", 8f);
        //make a dirt road
        Texture dirt = mgr.loadTexture("Textures/Terrain/dirt.jpg");
        dirt.setWrap(WrapMode.Repeat);
        mat_terrain.setTexture("Tex3", dirt);
        mat_terrain.setFloat("Tex3Scale", 128f);
        //create height map
        HillHeightMap heightMap = null;
        try {
            heightMap = new HillHeightMap(513, 200, 25, 100, (byte) 3);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        heightMap.load();


        //create terrainQuad
        //tiles should be 1+ square number. so 64px tile is 65
        //public TerrainQuad(String name, int patchSize, int totalSize, float[] heightMap)
        //terrain = new TerrainQuad("Textures/Terrain/testLand,j3o",  );
        terrain = new TerrainQuad("my terrain", 65, 513, heightMap.getHeightMap());
        //give terrain material, position, scale it, and attach it
        terrain.setMaterial(mat_terrain);
        terrain.setLocalTranslation(0, -10, 0);
        terrain.setLocalScale(2f, 1f, 2f);
        //LOD depends on where camara is
        // List<Camera> camera1 = new ArrayList<Camera>();
        // camera1.add(getCamera());
        // TerrainLodControl lodControl = new TerrainLodControl(terrain, camera1);
        // terrain.addControl(control);

        //water stuff
        SimpleWaterProcessor waterProcessor = new SimpleWaterProcessor(mgr);
        // waterProcessor.setRelfectionScene(mainScene);



    }

    /**
     *
     * @return
     */
    public Spatial getTerrain() {
        return tTerrain;
    }
}
TOP

Related Classes of com.benkyou.client.systems.TerrainSystem

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.