Search in sources :

Example 26 with TerrainQuad

use of com.jme3.terrain.geomipmap.TerrainQuad in project jmonkeyengine by jMonkeyEngine.

the class NormalRecalcControl method read.

@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule ic = im.getCapsule(this);
    terrain = (TerrainQuad) ic.readSavable("terrain", null);
}
Also used : InputCapsule(com.jme3.export.InputCapsule)

Example 27 with TerrainQuad

use of com.jme3.terrain.geomipmap.TerrainQuad in project jmonkeyengine by jMonkeyEngine.

the class TerrainGrid method attachQuadAt.

/**
     * Runs on the rendering thread
     * @param shifted quads are still attached to the parent and don't need to re-load
     */
protected void attachQuadAt(TerrainQuad q, int quadrant, Vector3f quadCell, boolean shifted) {
    q.setQuadrant((short) quadrant);
    if (!shifted)
        this.attachChild(q);
    // quadrant location handled TerrainQuad automatically now
    Vector3f loc = quadCell.mult(this.quadSize - 1).subtract(quarterSize, 0, quarterSize);
    q.setLocalTranslation(loc);
    if (!shifted) {
        for (TerrainGridListener l : listeners) {
            l.tileAttached(quadCell, q);
        }
    }
    updateModelBound();
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 28 with TerrainQuad

use of com.jme3.terrain.geomipmap.TerrainQuad in project jmonkeyengine by jMonkeyEngine.

the class TerrainQuad method createQuad.

/**
     * Quadrants, world coordinates, and heightmap coordinates (Y-up):
     *
     *         -z
     *      -u |
     *    -v  1|3
     *  -x ----+---- x
     *        2|4 u
     *         | v
     *         z
     * <code>createQuad</code> generates four new quads from this quad.
     * The heightmap's top left (0,0) coordinate is at the bottom, -x,-z
     * coordinate of the terrain, so it grows in the positive x.z direction.
     */
protected void createQuad(int blockSize, float[] heightMap) {
    // create 4 terrain quads
    int quarterSize = size >> 2;
    int split = (size + 1) >> 1;
    Vector2f tempOffset = new Vector2f();
    offsetAmount += quarterSize;
    //if (lodCalculator == null)
    //    lodCalculator = createDefaultLodCalculator(); // set a default one
    // 1 upper left of heightmap, upper left quad
    float[] heightBlock1 = createHeightSubBlock(heightMap, 0, 0, split);
    Vector3f origin1 = new Vector3f(-quarterSize * stepScale.x, 0, -quarterSize * stepScale.z);
    tempOffset.x = offset.x;
    tempOffset.y = offset.y;
    tempOffset.x += origin1.x;
    tempOffset.y += origin1.z;
    TerrainQuad quad1 = new TerrainQuad(getName() + "Quad1", blockSize, split, stepScale, heightBlock1, totalSize, tempOffset, offsetAmount);
    quad1.setLocalTranslation(origin1);
    quad1.quadrant = 1;
    this.attachChild(quad1);
    // 2 lower left of heightmap, lower left quad
    float[] heightBlock2 = createHeightSubBlock(heightMap, 0, split - 1, split);
    Vector3f origin2 = new Vector3f(-quarterSize * stepScale.x, 0, quarterSize * stepScale.z);
    tempOffset = new Vector2f();
    tempOffset.x = offset.x;
    tempOffset.y = offset.y;
    tempOffset.x += origin2.x;
    tempOffset.y += origin2.z;
    TerrainQuad quad2 = new TerrainQuad(getName() + "Quad2", blockSize, split, stepScale, heightBlock2, totalSize, tempOffset, offsetAmount);
    quad2.setLocalTranslation(origin2);
    quad2.quadrant = 2;
    this.attachChild(quad2);
    // 3 upper right of heightmap, upper right quad
    float[] heightBlock3 = createHeightSubBlock(heightMap, split - 1, 0, split);
    Vector3f origin3 = new Vector3f(quarterSize * stepScale.x, 0, -quarterSize * stepScale.z);
    tempOffset = new Vector2f();
    tempOffset.x = offset.x;
    tempOffset.y = offset.y;
    tempOffset.x += origin3.x;
    tempOffset.y += origin3.z;
    TerrainQuad quad3 = new TerrainQuad(getName() + "Quad3", blockSize, split, stepScale, heightBlock3, totalSize, tempOffset, offsetAmount);
    quad3.setLocalTranslation(origin3);
    quad3.quadrant = 3;
    this.attachChild(quad3);
    // 4 lower right of heightmap, lower right quad
    float[] heightBlock4 = createHeightSubBlock(heightMap, split - 1, split - 1, split);
    Vector3f origin4 = new Vector3f(quarterSize * stepScale.x, 0, quarterSize * stepScale.z);
    tempOffset = new Vector2f();
    tempOffset.x = offset.x;
    tempOffset.y = offset.y;
    tempOffset.x += origin4.x;
    tempOffset.y += origin4.z;
    TerrainQuad quad4 = new TerrainQuad(getName() + "Quad4", blockSize, split, stepScale, heightBlock4, totalSize, tempOffset, offsetAmount);
    quad4.setLocalTranslation(origin4);
    quad4.quadrant = 4;
    this.attachChild(quad4);
}
Also used : Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f)

Example 29 with TerrainQuad

use of com.jme3.terrain.geomipmap.TerrainQuad in project jmonkeyengine by jMonkeyEngine.

the class TerrainQuad method read.

@Override
public void read(JmeImporter e) throws IOException {
    super.read(e);
    InputCapsule c = e.getCapsule(this);
    size = c.readInt("size", 0);
    stepScale = (Vector3f) c.readSavable("stepScale", null);
    offset = (Vector2f) c.readSavable("offset", new Vector2f(0, 0));
    offsetAmount = c.readFloat("offsetAmount", 0);
    quadrant = c.readInt("quadrant", 0);
    totalSize = c.readInt("totalSize", 0);
    if (!(getParent() instanceof TerrainQuad)) {
        BoundingBox all = new BoundingBox(getWorldTranslation(), totalSize, totalSize, totalSize);
        affectedAreaBBox = all;
        updateNormals();
    }
}
Also used : InputCapsule(com.jme3.export.InputCapsule) Vector2f(com.jme3.math.Vector2f) BoundingBox(com.jme3.bounding.BoundingBox)

Example 30 with TerrainQuad

use of com.jme3.terrain.geomipmap.TerrainQuad in project jmonkeyengine by jMonkeyEngine.

the class TerrainQuad method getHeightmapHeight.

/**
     * This will just get the heightmap value at the supplied point,
     * not an interpolated (actual) height value.
     */
protected float getHeightmapHeight(int x, int z) {
    int quad = findQuadrant(x, z);
    int split = (size + 1) >> 1;
    if (children != null) {
        for (int i = children.size(); --i >= 0; ) {
            Spatial spat = children.get(i);
            int col = x;
            int row = z;
            boolean match = false;
            // get the childs quadrant
            int childQuadrant = 0;
            if (spat instanceof TerrainQuad) {
                childQuadrant = ((TerrainQuad) spat).getQuadrant();
            } else if (spat instanceof TerrainPatch) {
                childQuadrant = ((TerrainPatch) spat).getQuadrant();
            }
            if (childQuadrant == 1 && (quad & 1) != 0) {
                match = true;
            } else if (childQuadrant == 2 && (quad & 2) != 0) {
                row = z - split + 1;
                match = true;
            } else if (childQuadrant == 3 && (quad & 4) != 0) {
                col = x - split + 1;
                match = true;
            } else if (childQuadrant == 4 && (quad & 8) != 0) {
                col = x - split + 1;
                row = z - split + 1;
                match = true;
            }
            if (match) {
                if (spat instanceof TerrainQuad) {
                    return ((TerrainQuad) spat).getHeightmapHeight(col, row);
                } else if (spat instanceof TerrainPatch) {
                    return ((TerrainPatch) spat).getHeightmapHeight(col, row);
                }
            }
        }
    }
    return Float.NaN;
}
Also used : Spatial(com.jme3.scene.Spatial)

Aggregations

TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)24 Material (com.jme3.material.Material)18 Texture (com.jme3.texture.Texture)18 Vector3f (com.jme3.math.Vector3f)16 TerrainLodControl (com.jme3.terrain.geomipmap.TerrainLodControl)16 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)16 ImageBasedHeightMap (com.jme3.terrain.heightmap.ImageBasedHeightMap)15 DistanceLodCalculator (com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator)12 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)8 ArrayList (java.util.ArrayList)8 DirectionalLight (com.jme3.light.DirectionalLight)7 Camera (com.jme3.renderer.Camera)7 BulletAppState (com.jme3.bullet.BulletAppState)6 CapsuleCollisionShape (com.jme3.bullet.collision.shapes.CapsuleCollisionShape)5 CharacterControl (com.jme3.bullet.control.CharacterControl)5 ColorRGBA (com.jme3.math.ColorRGBA)5 ScreenshotAppState (com.jme3.app.state.ScreenshotAppState)4 BoundingBox (com.jme3.bounding.BoundingBox)4 HeightfieldCollisionShape (com.jme3.bullet.collision.shapes.HeightfieldCollisionShape)4 Spatial (com.jme3.scene.Spatial)4