Search in sources :

Example 81 with Terrain

use of com.jme3.terrain.Terrain in project jmonkeyengine by jMonkeyEngine.

the class TerrainLodControl method cloneForSpatial.

@Override
public Control cloneForSpatial(Spatial spatial) {
    if (spatial instanceof Terrain) {
        List<Camera> cameraClone = new ArrayList<Camera>();
        if (cameras != null) {
            for (Camera c : cameras) {
                cameraClone.add(c);
            }
        }
        TerrainLodControl cloned = new TerrainLodControl((Terrain) spatial, cameraClone);
        cloned.setLodCalculator(lodCalculator.clone());
        return cloned;
    }
    return null;
}
Also used : Terrain(com.jme3.terrain.Terrain) ArrayList(java.util.ArrayList) Camera(com.jme3.renderer.Camera)

Example 82 with Terrain

use of com.jme3.terrain.Terrain in project jmonkeyengine by jMonkeyEngine.

the class TerrainPatch method cloneFields.

/**
     *  Called internally by com.jme3.util.clone.Cloner.  Do not call directly.
     */
@Override
public void cloneFields(Cloner cloner, Object original) {
    super.cloneFields(cloner, original);
    this.stepScale = cloner.clone(stepScale);
    this.offset = cloner.clone(offset);
    this.leftNeighbour = null;
    this.topNeighbour = null;
    this.rightNeighbour = null;
    this.bottomNeighbour = null;
    // Don't feel like making geomap cloneable tonight
    // so I'll copy the old logic.
    this.geomap = new LODGeomap(size, geomap.getHeightArray());
    Mesh m = geomap.createMesh(stepScale, Vector2f.UNIT_XY, offset, offsetAmount, totalSize, false);
    this.setMesh(m);
    // In this case, we always clone material even if the cloner is setup
    // not to clone it.  Terrain uses mutable textures and stuff so it's important
    // to clone it.  (At least that's my understanding and is evidenced by the old
    // clone code specifically cloning material.)  -pspeed
    this.material = material.clone();
}
Also used : Mesh(com.jme3.scene.Mesh)

Example 83 with Terrain

use of com.jme3.terrain.Terrain in project jmonkeyengine by jMonkeyEngine.

the class TerrainQuad method createQuadPatch.

/**
     * <code>createQuadPatch</code> creates four child patches from this quad.
     */
protected void createQuadPatch(float[] heightMap) {
    // create 4 terrain patches
    int quarterSize = size >> 2;
    int halfSize = size >> 1;
    int split = (size + 1) >> 1;
    //if (lodCalculator == null)
    //    lodCalculator = createDefaultLodCalculator(); // set a default one
    offsetAmount += quarterSize;
    // 1 lower left
    float[] heightBlock1 = createHeightSubBlock(heightMap, 0, 0, split);
    Vector3f origin1 = new Vector3f(-halfSize * stepScale.x, 0, -halfSize * stepScale.z);
    Vector2f tempOffset1 = new Vector2f();
    tempOffset1.x = offset.x;
    tempOffset1.y = offset.y;
    tempOffset1.x += origin1.x / 2;
    tempOffset1.y += origin1.z / 2;
    TerrainPatch patch1 = new TerrainPatch(getName() + "Patch1", split, stepScale, heightBlock1, origin1, totalSize, tempOffset1, offsetAmount);
    patch1.setQuadrant((short) 1);
    this.attachChild(patch1);
    patch1.setModelBound(new BoundingBox());
    patch1.updateModelBound();
    //patch1.setLodCalculator(lodCalculator);
    //TangentBinormalGenerator.generate(patch1);
    // 2 upper left
    float[] heightBlock2 = createHeightSubBlock(heightMap, 0, split - 1, split);
    Vector3f origin2 = new Vector3f(-halfSize * stepScale.x, 0, 0);
    Vector2f tempOffset2 = new Vector2f();
    tempOffset2.x = offset.x;
    tempOffset2.y = offset.y;
    tempOffset2.x += origin1.x / 2;
    tempOffset2.y += quarterSize * stepScale.z;
    TerrainPatch patch2 = new TerrainPatch(getName() + "Patch2", split, stepScale, heightBlock2, origin2, totalSize, tempOffset2, offsetAmount);
    patch2.setQuadrant((short) 2);
    this.attachChild(patch2);
    patch2.setModelBound(new BoundingBox());
    patch2.updateModelBound();
    //patch2.setLodCalculator(lodCalculator);
    //TangentBinormalGenerator.generate(patch2);
    // 3 lower right
    float[] heightBlock3 = createHeightSubBlock(heightMap, split - 1, 0, split);
    Vector3f origin3 = new Vector3f(0, 0, -halfSize * stepScale.z);
    Vector2f tempOffset3 = new Vector2f();
    tempOffset3.x = offset.x;
    tempOffset3.y = offset.y;
    tempOffset3.x += quarterSize * stepScale.x;
    tempOffset3.y += origin3.z / 2;
    TerrainPatch patch3 = new TerrainPatch(getName() + "Patch3", split, stepScale, heightBlock3, origin3, totalSize, tempOffset3, offsetAmount);
    patch3.setQuadrant((short) 3);
    this.attachChild(patch3);
    patch3.setModelBound(new BoundingBox());
    patch3.updateModelBound();
    //patch3.setLodCalculator(lodCalculator);
    //TangentBinormalGenerator.generate(patch3);
    // 4 upper right
    float[] heightBlock4 = createHeightSubBlock(heightMap, split - 1, split - 1, split);
    Vector3f origin4 = new Vector3f(0, 0, 0);
    Vector2f tempOffset4 = new Vector2f();
    tempOffset4.x = offset.x;
    tempOffset4.y = offset.y;
    tempOffset4.x += quarterSize * stepScale.x;
    tempOffset4.y += quarterSize * stepScale.z;
    TerrainPatch patch4 = new TerrainPatch(getName() + "Patch4", split, stepScale, heightBlock4, origin4, totalSize, tempOffset4, offsetAmount);
    patch4.setQuadrant((short) 4);
    this.attachChild(patch4);
    patch4.setModelBound(new BoundingBox());
    patch4.updateModelBound();
//patch4.setLodCalculator(lodCalculator);
//TangentBinormalGenerator.generate(patch4);
}
Also used : Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) BoundingBox(com.jme3.bounding.BoundingBox)

Aggregations

Material (com.jme3.material.Material)54 Vector3f (com.jme3.math.Vector3f)43 Texture (com.jme3.texture.Texture)38 Geometry (com.jme3.scene.Geometry)32 DirectionalLight (com.jme3.light.DirectionalLight)23 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)21 Box (com.jme3.scene.shape.Box)20 TerrainLodControl (com.jme3.terrain.geomipmap.TerrainLodControl)17 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)15 ImageBasedHeightMap (com.jme3.terrain.heightmap.ImageBasedHeightMap)15 AmbientLight (com.jme3.light.AmbientLight)14 DistanceLodCalculator (com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator)13 Node (com.jme3.scene.Node)12 Sphere (com.jme3.scene.shape.Sphere)11 Vector2f (com.jme3.math.Vector2f)10 Spatial (com.jme3.scene.Spatial)10 ArrayList (java.util.ArrayList)10 TextureKey (com.jme3.asset.TextureKey)9 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)9 ColorRGBA (com.jme3.math.ColorRGBA)8