How to make a portion of terrain invisible?


I am trying to find a way to make a portion of Terrain invisible, the delimiter will be a “cube”, it doesn’t have to be precise, and best would be to just not render the polygons inside this cube at all.

If you want to know why… I have a huge very low resolution TerrainQuad, I use it to display the horizon : you can turn the camera in any direction, you will see very far around you. But for close range, I have a TerrainGrid, which loads the detailled version of the same Terrain, so you can watch the terrain closely.

And I want to hide the low resolution Quad where the high resolution Grid is displayed.

Any idea how to do this ?

You can do it through the material, just don’t have any textures painted around that area. But the polygons are still there and will eat up gpu cycles…

You could remove quads and patches without extending terrain quad. You would just get the children of each quad (starting from the root and working down), and if that child is inside the bounding box/cube, then detach it from the parent. TerrainQuad can handle siblings not being there so it should be fine.

Look at fixNormalEdges() in terrain quad, it does something similar but instead of removing children, it just updates their normals.

1 Like

Superb, it works. :slight_smile:

The TerrainPatches are removed when the camera approaches, and reattached when the camera moves away.

I just have a small offset problem (see the screenshot). My Terrains won’t align correctly although they mathematically should.

After a short investigation, the problem comes from a small error in TerrainGrid. It multiplies the Quads location with quadSize.

quadSize is the “size +1”. Although the location should be calculated using “size” (without the +1).

Line 154, getCell() :


final Vector3f v = location.clone().divideLocal(this.getLocalScale().mult(this.quadSize - 1)).add(0.5f, 0, 0.5f);


and Line 173, attachQuadAt() :

[java] q.setLocalTranslation(cam.mult(this.quadSize - 1).add(quadOrigins[quadrant-1]));


I did a big commit earlier today and those lines of code no longer exist.

Fixes in it:

  • no more lag when loading new quads
  • lod seaming fixed
  • quad ordering fixed
  • adjust height fixed

    Try it out and see if I have completely broken everything for you :slight_smile:

Damn, you fixed it ! That one’s on you… no … wait ! You forgot one :wink:

Line 214, getCell() :

[java] final Vector3f v = location.clone().divideLocal(this.getLocalScale().mult(this.quadSize-1)).add(0.5f, 0, 0.5f);


I see you took my overloaded adjustHeight() proposal. You could add the overrideHeight alternative too.

[java]public void adjustHeight(List<Vector2f> xz, List<Float> height, boolean overrideHeight) {


super.adjustHeight( xz, height, overrideHeight );


public void adjustHeight(List<Vector2f> xz, List<Float> height) {

this.adjustHeight(xz, height, false);


I would also really love you if you could “protected” your variables and methods instead of “private” so I can extend your Terrains. I currently need quadSize ( or getQuadSize() ? ) and access to the cache, to force a refresh in some locations (my heightMaps are sometimes modified while the Quad is inside the cache)

Your latest update is fine, but it generates some display artefacts because Quads attachments become unpredictable.

I added two new events to TerrainGridListener :

[java] public void tileAttached( Vector3f cell );

public void tileDetached( Vector3f cell );[/java]

then line 110 :

[java] public Object call() throws Exception {

for (TerrainGridListener l : listeners.values()) {



attachQuadAt(newQuad, quadrant, temp);

return null;



and line 225 :

[java] protected void removeQuad(int idx) {

TerrainQuad q = this.getQuad(idx);

if (q != null) {

if (quadControls != null) {



for (TerrainGridListener l : listeners.values()) {

l.tileDetached( getCell( q.getWorldTranslation() ) );


this.detachChild( q );




Thanks for the addition, it’s already in the svn… this also saves some fps when using grid with physics.

I have extended the parameterlist though, so the user is able add and remove physics control and other stuff to/from the quad that’s being loaded or unloded.

1 Like

okay the methods should all have protected access now.

1 Like