/** * 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 } }
/** * Find what terrain patches need normal recalculations and update * their normals; */ protected void fixNormals(BoundingBox affectedArea) { if (children == null) return; // go through the children and see if they collide with the affectedAreaBBox // if they do, then update their normals for (int x = children.size(); --x >= 0;) { Spatial child = children.get(x); if (child instanceof TerrainQuad) { if (affectedArea != null && affectedArea.intersects(((TerrainQuad) child).getWorldBound()) ) ((TerrainQuad) child).fixNormals(affectedArea); } else if (child instanceof TerrainPatch) { if (affectedArea != null && affectedArea.intersects(((TerrainPatch) child).getWorldBound()) ) ((TerrainPatch) child).updateNormals(); // recalculate the patch's normals } } }
/** * 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 } }
/** * Find what terrain patches need normal recalculations and update * their normals; */ protected void fixNormals(BoundingBox affectedArea) { if (children == null) return; // go through the children and see if they collide with the affectedAreaBBox // if they do, then update their normals for (int x = children.size(); --x >= 0;) { Spatial child = children.get(x); if (child instanceof TerrainQuad) { if (affectedArea != null && affectedArea.intersects(((TerrainQuad) child).getWorldBound()) ) ((TerrainQuad) child).fixNormals(affectedArea); } else if (child instanceof TerrainPatch) { if (affectedArea != null && affectedArea.intersects(((TerrainPatch) child).getWorldBound()) ) ((TerrainPatch) child).updateNormals(); // recalculate the patch's normals } } }