Aceessing mesh data in TerrainPage

how do u access the mesh data in a TerrainPage, I need to pass the mesh data to the collision Library I use.

u need to get the actual TerrainBlock. just do something like this



for(int i= 0; i < terrain.getQuantity(); i++) {
     if(terrain.getChild(i) instanceof TerrainBlock) {
       // DO ur logic here
     }
}

thank man :slight_smile: nice!

well it didn't work, but that's because the mesh data is lower down the node tree and getQuantity() only seems to return the top most children, in the case of TerrainPage nodes



I plugged this into TestTerrainPage in effort to figure out what I was doing wrong and realized my problem



System.out.println(page.getQuantity());
       
    for (int i= 0; i < page.getQuantity(); i++)
    {
        System.out.println("searching......");
        if(page.getChild(i) instanceof TriMesh )
        {
           
            System.out.println("found");
           
        }
        else
            System.out.println(" no terrain blocks found");
    }



how do search the entire node tree to get the mesh data

You can traverse the tree by a recursive function.

Simply call it on the root page:


public void print(TerrainPage page){
     
     System.out.println(page.getQuantity());
       
    for (int i= 0; i < page.getQuantity(); i++)
    {
        System.out.println("searching......");
        if(page.getChild(i) instanceof TriMesh )
        {
           
            System.out.println("found");
           
        }
        else if(page.getChild(i) instanceof TerrainPage){
           print(page.getChild(i));
       }
    }
}

sry my bad. children of terrain page could also be a terrain page which is y u need to recursively call the method when a terrain page is found. but the general idea is the same.

thank all will give it a go later.