if (spatial instanceof TerrainQuad) { TerrainQuad terrain = (TerrainQuad) spatial; return new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale()); } else if (spatial instanceof TerrainPatch) { TerrainPatch terrain = (TerrainPatch) spatial;
terrain1 = new TerrainQuad("terrain 1", 65, 513, null); terrain1.setMaterial(matTerrain); terrain1.setLocalTranslation(-256, -100, -256); terrain1.setLocalScale(1f, 1f, 1f); this.attachChild(terrain1); terrain2 = new TerrainQuad("terrain 2", 65, 513, null); terrain2.setMaterial(matTerrain); terrain2.setLocalTranslation(-256, -100, 256); terrain2.setLocalScale(1f, 1f, 1f); this.attachChild(terrain2); terrain3 = new TerrainQuad("terrain 3", 65, 513, null); terrain3.setMaterial(matTerrain); terrain3.setLocalTranslation(256, -100, -256); terrain3.setLocalScale(1f, 1f, 1f); this.attachChild(terrain3); terrain4 = new TerrainQuad("terrain 4", 65, 513, null); terrain4.setMaterial(matTerrain); terrain4.setLocalTranslation(256, -100, 256); terrain4.setLocalScale(1f, 1f, 1f); this.attachChild(terrain4); terrain1.setNeighbourFinder(this); terrain2.setNeighbourFinder(this); terrain3.setNeighbourFinder(this); terrain4.setNeighbourFinder(this);
public void tileAttached(Vector3f cell, TerrainQuad quad) { while(quad.getControl(RigidBodyControl.class)!=null){ quad.removeControl(RigidBodyControl.class); } quad.addControl(new RigidBodyControl(new HeightfieldCollisionShape(quad.getHeightMap(), terrain.getLocalScale()), 0)); bulletAppState.getPhysicsSpace().add(quad); }
/** * Get the interpolated height of the terrain at the specified point. * @param xz the location to get the height for * @return Float.NAN if the value does not exist, or the coordinates are outside of the terrain */ public float getHeight(Vector2f xz) { // offset float x = (float)(((xz.x - getWorldTranslation().x) / getWorldScale().x) + (float)(totalSize-1) / 2f); float z = (float)(((xz.y - getWorldTranslation().z) / getWorldScale().z) + (float)(totalSize-1) / 2f); if (!isInside((int)x, (int)z)) return Float.NaN; float height = getHeight((int)x, (int)z, (x%1f), (z%1f)); height *= getWorldScale().y; return height; }
protected float getHeight(int x, int z, float xm, float zm) { QuadrantChild match = findMatchingChild(x,z); if (match != null) { if (match.child instanceof TerrainQuad) { return ((TerrainQuad) match.child).getHeight(match.col, match.row, xm, zm); } else if (match.child instanceof TerrainPatch) { return ((TerrainPatch) match.child).getHeight(match.col, match.row, xm, zm); } } return Float.NaN; }
private void adjustHeight(Vector3f loc, float radius, float height) { // offset it by radius because in the loop we iterate through 2 radii int radiusStepsX = (int) (radius / terrain.getLocalScale().x); int radiusStepsZ = (int) (radius / terrain.getLocalScale().z); float xStepAmount = terrain.getLocalScale().x; float zStepAmount = terrain.getLocalScale().z; long start = System.currentTimeMillis(); List<Vector2f> locs = new ArrayList<Vector2f>(); List<Float> heights = new ArrayList<Float>(); for (int z = -radiusStepsZ; z < radiusStepsZ; z++) { for (int x = -radiusStepsX; x < radiusStepsX; x++) { float locX = loc.x + (x * xStepAmount); float locZ = loc.z + (z * zStepAmount); if (isInRadius(locX - loc.x, locZ - loc.z, radius)) { // see if it is in the radius of the tool float h = calculateHeight(radius, height, locX - loc.x, locZ - loc.z); locs.add(new Vector2f(locX, locZ)); heights.add(h); } } } terrain.adjustHeight(locs, heights); //System.out.println("Modified "+locs.size()+" points, took: " + (System.currentTimeMillis() - start)+" ms"); terrain.updateModelBound(); }
e.printStackTrace(); terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap()); List<Camera> cameras = new ArrayList<Camera>(); cameras.add(getCamera()); TerrainLodControl control = new TerrainLodControl(terrain, cameras); terrain.addControl(control); terrain.setMaterial(matRock); terrain.setLocalScale(new Vector3f(2, 2, 2)); terrain.setLocked(false); // unlock it so we can edit the height terrain.setShadowMode(ShadowMode.CastAndReceive); terrain.addControl(new RigidBodyControl(0)); rootNode.attachChild(terrain); getPhysicsSpace().addAll(terrain);
e.printStackTrace(); TerrainQuad terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap()); List<Camera> cameras = new ArrayList<Camera>(); cameras.add(getCamera()); terrain.setMaterial(matRock); terrain.setLocalScale(new Vector3f(5, 5, 5)); terrain.setLocalTranslation(new Vector3f(0, -30, 0)); terrain.setLocked(false); // unlock it so we can edit the height terrain.setShadowMode(RenderQueue.ShadowMode.Receive); rootNode.attachChild(terrain);
terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());//, new LodPerspectiveCalculatorFactory(getCamera(), 4)); // add this in to see it use entropy for LOD calculations TerrainLodControl control = new TerrainLodControl(terrain, getCamera()); control.setLodCalculator( new DistanceLodCalculator(65, 2.7f) ); terrain.addControl(control); terrain.setMaterial(matTerrain); terrain.setModelBound(new BoundingBox()); terrain.updateModelBound(); terrain.setLocalTranslation(0, -100, 0); terrain.setLocalScale(1f, 1f, 1f); rootNode.attachChild(terrain);
public void randomizeHeightMap() { if(terrain != null) { try { HillHeightMap heightmap = new HillHeightMap(513, 2000, 25, 100, (long)((byte)100 * Math.random())); Material mat = terrain.getMaterial(); Vector3f scale = terrain.getLocalScale(); Vector3f trans = terrain.getLocalTranslation(); rootNode.detachChildNamed("Terrain"); terrain = new TerrainQuad("Terrain", 65, 513, heightmap.getHeightMap()); terrain.setLocalTranslation(trans); terrain.setLocalScale(scale); terrain.setMaterial(mat); terrain.setShadowMode(ShadowMode.Receive); rootNode.attachChild(terrain); } catch(Exception ex) { ex.printStackTrace(); } } }
float[] heightBlock1 = createHeightSubBlock(heightMap, 0, 0, split); TerrainQuad quad1 = new TerrainQuad(getName() + "Quad1", blockSize, split, stepScale, heightBlock1, totalSize, tempOffset, offsetAmount); quad1.setLocalTranslation(origin1); quad1.quadrant = 1; this.attachChild(quad1); float[] heightBlock2 = createHeightSubBlock(heightMap, 0, split - 1, split); TerrainQuad quad2 = new TerrainQuad(getName() + "Quad2", blockSize, split, stepScale, heightBlock2, totalSize, tempOffset, offsetAmount); quad2.setLocalTranslation(origin2); quad2.quadrant = 2; this.attachChild(quad2); float[] heightBlock3 = createHeightSubBlock(heightMap, split - 1, 0, split); TerrainQuad quad3 = new TerrainQuad(getName() + "Quad3", blockSize, split, stepScale, heightBlock3, totalSize, tempOffset, offsetAmount); quad3.setLocalTranslation(origin3); quad3.quadrant = 3; this.attachChild(quad3);
TerrainQuad terrain = new TerrainQuad("JMEHeightMapTerrain", patchSize, gridSize, floatHeightMap); terrain.setMaterial(material); terrain.setLocalScale(localScale);
public void tileAttached(Vector3f cell, TerrainQuad quad) { Texture alpha = null; try { alpha = assetManager.loadTexture("TerrainAlphaTest/alpha_" + (int)cell.x+ "_" + (int)cell.z + ".png"); } catch (Exception e) { alpha = assetManager.loadTexture("TerrainAlphaTest/alpha_default.png"); } quad.getMaterial().setTexture("AlphaMap", alpha); if (usePhysics) { quad.addControl(new RigidBodyControl(new HeightfieldCollisionShape(quad.getHeightMap(), terrain.getLocalScale()), 0)); bulletAppState.getPhysicsSpace().add(quad); } updateMarkerElevations(); }
hm = new float[area]; if (getChildren() != null && !getChildren().isEmpty()) { float[] ul=null, ur=null, bl=null, br=null; if (getChild(0) instanceof TerrainPatch) { for (Spatial s : getChildren()) { if ( ((TerrainPatch)s).getQuadrant() == 1) ul = ((TerrainPatch)s).getHeightMap(); ul = getQuad(1).getHeightMap(); bl = getQuad(2).getHeightMap(); ur = getQuad(3).getHeightMap(); br = getQuad(4).getHeightMap();
q = new TerrainQuad(getName() + "Quad" + quadCell, patchSize, quadSize, heightMapAt == null ? null : heightMapAt.getHeightMap()); q.setMaterial(material.clone()); log.log(Level.FINE, "Loaded TerrainQuad {0} from HeightMapGrid", q.getName()); } else if (gridTileLoader != null) { q = gridTileLoader.getTerrainQuadAt(quadCell); if(q.getMaterial()==null) q.setMaterial(material.clone()); log.log(Level.FINE, "Loaded TerrainQuad {0} from TerrainQuadGrid", q.getName());
TerrainQuad terrain = new TerrainQuad("terrain", b, s, hm); float[] hm2 = terrain.getHeightMap(); boolean failed = false; for (int i = 0; i < s * s; i++) {
wireframe = !wireframe; if (!wireframe) { terrain.setMaterial(matWire); } else { terrain.setMaterial(matTerrain); TerrainLodControl control = terrain.getControl(TerrainLodControl.class); if (control != null) control.detachAndCleanUpControl(); else { control = new TerrainLodControl(terrain, cam); terrain.addControl(control);
private TerrainQuad createNewQuad(Vector3f location) { TerrainQuad q = new TerrainQuad("Quad" + location, patchSize, quadSize, null); return q; }
shape.addChildShape(new HeightfieldCollisionShape(terrain.getHeightMap(), trans.getScale()), trans.getTranslation(), trans.getRotation().toRotationMatrix());
terrain = new TerrainQuad("Terrain", 65, tiles+1, heightmap.getHeightMap()); heightmap.load(); terrain = new TerrainQuad("Terrain", patchsize+1, picsize+1, heightmap.getHeightMap()); terrain.setShadowMode(ShadowMode.Cast); terrain.setShadowMode(ShadowMode.Receive); terrain.setMaterial(mat_terrain);