159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/*
259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Copyright (c) 2009-2010 jMonkeyEngine
359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * All rights reserved.
459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Redistribution and use in source and binary forms, with or without
659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * modification, are permitted provided that the following conditions are
759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * met:
859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Redistributions of source code must retain the above copyright
1059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   notice, this list of conditions and the following disclaimer.
1159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
1259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Redistributions in binary form must reproduce the above copyright
1359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   notice, this list of conditions and the following disclaimer in the
1459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   documentation and/or other materials provided with the distribution.
1559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
1659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
1759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   may be used to endorse or promote products derived from this software
1859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   without specific prior written permission.
1959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
2059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
2459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */
3259b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapackage jme3test.terrain;
3359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
3459b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.app.SimpleApplication;
3559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.font.BitmapText;
3659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.KeyInput;
3759b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.controls.ActionListener;
3859b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.input.controls.KeyTrigger;
3959b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.light.DirectionalLight;
4059b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.light.PointLight;
4159b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.material.Material;
4259b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.math.ColorRGBA;
4359b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.math.Vector3f;
4459b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.scene.Geometry;
4559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.terrain.geomipmap.TerrainLodControl;
4659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.terrain.geomipmap.TerrainQuad;
4759b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator;
4859b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.terrain.heightmap.AbstractHeightMap;
4959b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.terrain.heightmap.ImageBasedHeightMap;
5059b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.texture.Texture;
5159b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.texture.Texture.WrapMode;
5259b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.asset.TextureKey;
5359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
5459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/**
5559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Demonstrates how to use terrain.
5659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * The base terrain class it uses is TerrainQuad, which is a quad tree of actual
5759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * meshes called TerainPatches.
5859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * There are a couple options for the terrain in this test:
5959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * The first is wireframe mode. Here you can see the underlying trianglestrip structure.
6059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * You will notice some off lines; these are degenerate triangles and are part of the
6159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * trianglestrip. They are only noticeable in wireframe mode.
6259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Second is Tri-Planar texture mode. Here the textures are rendered on all 3 axes and
6359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * then blended together to reduce distortion and stretching.
6459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Third, which you have to modify the code to see, is Entropy LOD calculations.
6559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * In the constructor for the TerrainQuad, un-comment the final parameter that is
6659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * the LodPerspectiveCalculatorFactory. Then you will see the terrain flicker to start
6759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * while it calculates the entropies. Once it is done, it will pick the best LOD value
6859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * based on entropy. This method reduces "popping" of terrain greatly when LOD levels
6959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * change. It is highly suggested you use it in your app.
7059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
7159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @author bowens
7259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */
7359b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapublic class TerrainTest extends SimpleApplication {
7459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
7559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private TerrainQuad terrain;
7659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    Material matRock;
7759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    Material matWire;
7859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    boolean wireframe = false;
7959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    boolean triPlanar = false;
8059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    protected BitmapText hintText;
8159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    PointLight pl;
8259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    Geometry lightMdl;
8359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private float grassScale = 64;
8459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private float dirtScale = 16;
8559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private float rockScale = 128;
8659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
8759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public static void main(String[] args) {
8859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        TerrainTest app = new TerrainTest();
8959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        app.start();
9059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
9159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
9259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    @Override
9359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public void initialize() {
9459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        super.initialize();
9559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
9659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        loadHintText();
9759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
9859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
9959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    @Override
10059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public void simpleInitApp() {
10159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        setupKeys();
10259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
10359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        // First, we load up our textures and the heightmap texture for the terrain
10459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
10559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        // TERRAIN TEXTURE material
10659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        matRock = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");
10759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        matRock.setBoolean("useTriPlanarMapping", false);
10859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
10959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        // ALPHA map (for splat textures)
11059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        matRock.setTexture("Alpha", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
11159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
11259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        // HEIGHTMAP image (for the terrain heightmap)
11359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
11459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
11559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        // GRASS texture
11659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
11759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        grass.setWrap(WrapMode.Repeat);
11859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        matRock.setTexture("Tex1", grass);
11959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        matRock.setFloat("Tex1Scale", grassScale);
12059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
12159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        // DIRT texture
12259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
12359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        dirt.setWrap(WrapMode.Repeat);
12459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        matRock.setTexture("Tex2", dirt);
12559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        matRock.setFloat("Tex2Scale", dirtScale);
12659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
12759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        // ROCK texture
12859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
12959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        rock.setWrap(WrapMode.Repeat);
13059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        matRock.setTexture("Tex3", rock);
13159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        matRock.setFloat("Tex3Scale", rockScale);
13259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
13359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        // WIREFRAME material
13459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
13559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        matWire.getAdditionalRenderState().setWireframe(true);
13659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        matWire.setColor("Color", ColorRGBA.Green);
13759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
13859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        // CREATE HEIGHTMAP
13959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        AbstractHeightMap heightmap = null;
14059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        try {
14159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            //heightmap = new HillHeightMap(1025, 1000, 50, 100, (byte) 3);
14259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
14359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 1f);
14459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            heightmap.load();
14559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
14659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        } catch (Exception e) {
14759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            e.printStackTrace();
14859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        }
14959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
15059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        /*
15159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta         * Here we create the actual terrain. The tiles will be 65x65, and the total size of the
15259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta         * terrain will be 513x513. It uses the heightmap we created to generate the height values.
15359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta         */
15459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        /**
15559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta         * Optimal terrain patch size is 65 (64x64).
15659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta         * The total size is up to you. At 1025 it ran fine for me (200+FPS), however at
15759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta         * size=2049, it got really slow. But that is a jump from 2 million to 8 million triangles...
15859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta         */
15959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
16059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
16159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        control.setLodCalculator( new DistanceLodCalculator(65, 2.7f) ); // patch size, and a multiplier
16259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        terrain.addControl(control);
16359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        terrain.setMaterial(matRock);
16459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        terrain.setLocalTranslation(0, -100, 0);
16559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        terrain.setLocalScale(2f, 1f, 2f);
16659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        rootNode.attachChild(terrain);
16759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
16859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        DirectionalLight light = new DirectionalLight();
16959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
17059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        rootNode.addLight(light);
17159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
17259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        cam.setLocation(new Vector3f(0, 10, -10));
17359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        cam.lookAtDirection(new Vector3f(0, -1.5f, -1).normalizeLocal(), Vector3f.UNIT_Y);
17459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
17559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
17659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public void loadHintText() {
17759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        hintText = new BitmapText(guiFont, false);
17859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        hintText.setSize(guiFont.getCharSet().getRenderedSize());
17959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        hintText.setLocalTranslation(0, getCamera().getHeight(), 0);
18059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        hintText.setText("Hit T to switch to wireframe,  P to switch to tri-planar texturing");
18159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        guiNode.attachChild(hintText);
18259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
18359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
18459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private void setupKeys() {
18559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        flyCam.setMoveSpeed(50);
18659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
18759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addListener(actionListener, "wireframe");
18859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addMapping("triPlanar", new KeyTrigger(KeyInput.KEY_P));
18959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        inputManager.addListener(actionListener, "triPlanar");
19059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
19159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private ActionListener actionListener = new ActionListener() {
19259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
19359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        public void onAction(String name, boolean pressed, float tpf) {
19459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            if (name.equals("wireframe") && !pressed) {
19559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                wireframe = !wireframe;
19659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                if (!wireframe) {
19759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    terrain.setMaterial(matWire);
19859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                } else {
19959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    terrain.setMaterial(matRock);
20059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                }
20159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            } else if (name.equals("triPlanar") && !pressed) {
20259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                triPlanar = !triPlanar;
20359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                if (triPlanar) {
20459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    matRock.setBoolean("useTriPlanarMapping", true);
20559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    // planar textures don't use the mesh's texture coordinates but real world coordinates,
20659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    // so we need to convert these texture coordinate scales into real world scales so it looks
20759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    // the same when we switch to/from tr-planar mode
20859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    matRock.setFloat("Tex1Scale", 1f / (float) (512f / grassScale));
20959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    matRock.setFloat("Tex2Scale", 1f / (float) (512f / dirtScale));
21059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    matRock.setFloat("Tex3Scale", 1f / (float) (512f / rockScale));
21159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                } else {
21259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    matRock.setBoolean("useTriPlanarMapping", false);
21359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    matRock.setFloat("Tex1Scale", grassScale);
21459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    matRock.setFloat("Tex2Scale", dirtScale);
21559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                    matRock.setFloat("Tex3Scale", rockScale);
21659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                }
21759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            }
21859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        }
21959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    };
22059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta}
221