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(); }
if (spatial instanceof TerrainQuad) { TerrainQuad terrain = (TerrainQuad) spatial; return new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale()); } else if (spatial instanceof TerrainPatch) { TerrainPatch terrain = (TerrainPatch) spatial;
if (spatial instanceof TerrainQuad) { TerrainQuad terrain = (TerrainQuad) spatial; return new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale()); } else if (spatial instanceof TerrainPatch) { TerrainPatch terrain = (TerrainPatch) spatial;
/** * This type of collision shape is mesh-accurate and meant for immovable "world objects". * Examples include terrain, houses or whole shooter levels.<br/> * Objects with "mesh" type collision shape will not collide with each other.<br/> * Creates a HeightfieldCollisionShape if the supplied spatial is a TerrainQuad. * @return A MeshCollisionShape or a CompoundCollisionShape with MeshCollisionShapes as children if the supplied spatial is a Node. A HeightieldCollisionShape if a TerrainQuad was supplied. */ public static CollisionShape createMeshShape(Spatial spatial) { if (spatial instanceof TerrainQuad) { TerrainQuad terrain = (TerrainQuad) spatial; return new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale()); } else if (spatial instanceof TerrainPatch) { TerrainPatch terrain = (TerrainPatch) spatial; return new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale()); } else if (spatial instanceof Geometry) { return createSingleMeshShape((Geometry) spatial, spatial); } else if (spatial instanceof Node) { return createMeshCompoundShape((Node) spatial); } else { throw new IllegalArgumentException("Supplied spatial must either be Node or Geometry!"); } }
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(); } } }
if (spatial instanceof TerrainQuad) { TerrainQuad terrain = (TerrainQuad) spatial; return new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale()); } else if (spatial instanceof TerrainPatch) { TerrainPatch terrain = (TerrainPatch) spatial;