Search in sources :

Example 31 with TerrainQuad

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

the class TerrainQuad method findPick.

/**
     * Gather the terrain patches that intersect the given ray (toTest).
     * This only tests the bounding boxes
     * @param toTest
     * @param results
     */
public void findPick(Ray toTest, List<TerrainPickData> results) {
    if (getWorldBound() != null) {
        if (getWorldBound().intersects(toTest)) {
            // further checking needed.
            for (int i = 0; i < getQuantity(); i++) {
                if (children.get(i) instanceof TerrainPatch) {
                    TerrainPatch tp = (TerrainPatch) children.get(i);
                    tp.ensurePositiveVolumeBBox();
                    if (tp.getWorldBound().intersects(toTest)) {
                        CollisionResults cr = new CollisionResults();
                        toTest.collideWith(tp.getWorldBound(), cr);
                        if (cr != null && cr.getClosestCollision() != null) {
                            cr.getClosestCollision().getDistance();
                            results.add(new TerrainPickData(tp, cr.getClosestCollision()));
                        }
                    }
                } else if (children.get(i) instanceof TerrainQuad) {
                    ((TerrainQuad) children.get(i)).findPick(toTest, results);
                }
            }
        }
    }
}
Also used : TerrainPickData(com.jme3.terrain.geomipmap.picking.TerrainPickData) CollisionResults(com.jme3.collision.CollisionResults)

Example 32 with TerrainQuad

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

the class TerrainQuad method findMatchingChild.

private QuadrantChild findMatchingChild(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)
                return new QuadrantChild(col, row, spat);
        }
    }
    return null;
}
Also used : Spatial(com.jme3.scene.Spatial)

Example 33 with TerrainQuad

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

the class AssetTileLoader method getTerrainQuadAt.

public TerrainQuad getTerrainQuadAt(Vector3f location) {
    String modelName = assetPath + "/" + name + "_" + Math.round(location.x) + "_" + Math.round(location.y) + "_" + Math.round(location.z) + ".j3o";
    Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Load terrain grid tile: {0}", modelName);
    TerrainQuad quad = null;
    try {
        quad = (TerrainQuad) manager.loadModel(modelName);
    } catch (Exception e) {
    //            e.printStackTrace();
    }
    if (quad == null) {
        Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Could not load terrain grid tile: {0}", modelName);
        quad = createNewQuad(location);
    } else {
        Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Loaded terrain grid tile: {0}", modelName);
    }
    return quad;
}
Also used : TerrainQuad(com.jme3.terrain.geomipmap.TerrainQuad) IOException(java.io.IOException)

Example 34 with TerrainQuad

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

the class FractalTileLoader method getTerrainQuadAt.

public TerrainQuad getTerrainQuadAt(Vector3f location) {
    HeightMap heightMapAt = getHeightMapAt(location);
    TerrainQuad q = new TerrainQuad("Quad" + location, patchSize, quadSize, heightMapAt == null ? null : heightMapAt.getHeightMap());
    return q;
}
Also used : AbstractHeightMap(com.jme3.terrain.heightmap.AbstractHeightMap) HeightMap(com.jme3.terrain.heightmap.HeightMap) TerrainQuad(com.jme3.terrain.geomipmap.TerrainQuad)

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