protected void removeQuad(TerrainQuad q) { if (q != null && ( (q.getQuadrant() > 0 && q.getQuadrant()<5) || q.getParent() != null) ) { for (TerrainGridListener l : listeners) { l.tileDetached(getTileCell(q.getWorldTranslation()), q); } q.setQuadrant((short)0); this.detachChild(q); cellsLoaded++; // For gridoffset calc., maybe the run() method is a better location for this. } }
protected void prepareTerrain() { TerrainQuad terrain = (TerrainQuad) getSpatial(); // cache the terrain's world transforms so they can be accessed on the separate thread safely terrain.cacheTerrainTransforms(); }
public Object call() throws Exception { if (newQuad.getParent() != null) { attachQuadAt(newQuad, quadrant, quadCell, true); } else { attachQuadAt(newQuad, quadrant, quadCell, false); } return null; } });
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; }
public Vector3f getNormal(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); Vector3f normal = getNormal(x, z, xz); return normal; }
/** * update the normals if there were any height changes recently. * Should only be called on the root quad */ protected void updateNormals() { if (needToRecalculateNormals()) { //TODO background-thread this if it ends up being expensive fixNormals(affectedAreaBBox); // the affected patches fixNormalEdges(affectedAreaBBox); // the edges between the patches setNormalRecalcNeeded(null); // set to false } }
/** * Get the triangle of this geometry at the specified local coordinate. * @param x local to the terrain patch * @param z local to the terrain patch * @return the triangle in world coordinates, or null if the point does intersect this patch on the XZ axis */ public Triangle getTriangle(float x, float z) { return geomap.getTriangleAtPoint(x, z, getWorldScale() , getWorldTranslation()); }
/** * Get the triangles at the specified grid point. Probably only 2 triangles * @param x local to the terrain patch * @param z local to the terrain patch * @return the triangles in world coordinates, or null if the point does intersect this patch on the XZ axis */ public Triangle[] getGridTriangles(float x, float z) { return geomap.getGridTrianglesAtPoint(x, z, getWorldScale() , getWorldTranslation()); }
protected Vector3f getCenterLocation(TerrainPatch terrainPatch) { Vector3f loc = terrainPatch.getWorldTranslationCached(); loc.x += terrainPatch.getSize()*terrainPatch.getWorldScaleCached().x / 2; loc.z += terrainPatch.getSize()*terrainPatch.getWorldScaleCached().z / 2; return loc; }
@Override public void setMaterial(Material mat) { this.material = mat; super.setMaterial(mat); }
public boolean isReIndexNeeded() { if (lodChanged() || isFixEdges()) return true; //if (leftLod != newLod || rightLod != newLod || bottomLod != newLod || topLod != newLod) // return true; return false; }
protected synchronized void reIndexPages(HashMap<String,UpdatedTerrainPatch> updated, boolean usesVariableLod) { if (children != null) { for (int i = children.size(); --i >= 0;) { Spatial child = children.get(i); if (child instanceof TerrainQuad) { ((TerrainQuad) child).reIndexPages(updated, usesVariableLod); } else if (child instanceof TerrainPatch) { ((TerrainPatch) child).reIndexGeometry(updated, usesVariableLod); } } } }
@Override protected UpdateLOD createLodUpdateTask(final List<Vector3f> locations, final LodCalculator lodCalculator) { return new UpdateMultiLOD(locations, lodCalculator); }
/** * Get the terrain tile at the specified XZ cell coordinate (not world coordinate). * @param cellCoordinate integer cell coordinates * @return the terrain tile at that location */ public Terrain getTerrainAtCell(Vector3f cellCoordinate) { return cache.get(cellCoordinate); }
/** * Only uses the first camera right now. * @param terrain to act upon (must be a Spatial) * @param cameras one or more cameras to reference for LOD calc */ public TerrainLodControl(final Terrain terrain, final List<Camera> cameras) { this(terrain); setCameras(cameras); }
public Object call() throws Exception { removeQuad(newQuad); return null; } });
public float[] getLodEntropies(){ if (lodEntropy == null){ generateLodEntropies(); } return lodEntropy; }
@Override protected boolean removeEldestEntry(Map.Entry<K, V> eldest) { return this.size() > LRUCache.this.cacheSize; } };
public TerrainLodControl(final Camera camera) { this(); setCamera(camera); }
public TerrainPatch() { super("TerrainPatch"); setBatchHint(BatchHint.Never); }