About Store Forum Documentation Contact



Post Reply 
Vanishing Terrain
Author Message
Pherael Offline
Member

Post: #1
Vanishing Terrain
I have this problem, and I don't know what is the cause. When I create terrain in game and try to explore it, terrain is vanishing depending on camera angle, as you can see in video below. Everything is fine when I load world created from Esenthel Editor.





Code for creating world:
Code:
Map<VecI2, Heightmap> heightmaps(Compare);

Memx<Game.WorldManager.AreaState> areas;

class Generator
{
  
   void generate()
   {
    
      Game.World.del(true);
      heightmaps.del();
      areas.clear();
  
      Game.World.New (UID(3562142987, 1197192856, 3702846878, 3555636679));
  
      Game.World.setObjType(Players, OBJ_PLAYER )
            .setObjType(NPCs, OBJ_NPC);
            
      if(Game.World.settings().environment) // if the world has environment settings (like sun, ambient, sky, ..)
         Game.World.settings().environment->set(); // then set them  
  
      Game.World.update(Vec(0, 0));

      int size_x=16;
      int size_y=16;
      
      FREPD(x, size_x)
      FREPD(y, size_y)
      {
      
         Game.WorldManager.AreaState &area = areas.New();
         area.set(VecI2(x, y), Game.AREA_ACTIVE);
         Game.World.areaSetState(areas, false);
    
         Heightmap * heightmap = heightmaps.get(VecI2(x, y));
         Mesh      mesh;
         PhysPart  phys;

    
        UID       grass_id  = UID(1424935208, 1108803486, 3527738024, 4135024667);

      // create heightmap looking for existing  neighbors
      heightmap.create(64, 0, grass_id, false,
      heightmaps.find(VecI2(x-1, y)),
      heightmaps.find(VecI2(x+1, y)),
      heightmaps.find(VecI2(x, y-1)),
      heightmaps.find(VecI2(x, y+1)),
      heightmaps.find(VecI2(x-1, y-1)),
      heightmaps.find(VecI2(x-1, y+1)),
      heightmaps.find(VecI2(x+1, y-1)),  
      heightmaps.find(VecI2(x+1, y+1)) );
      
      FREPD(i, 65)
      FREPD(j, 65)
      {
         flt WallHeigh = 0.01f;
         heightmap.height(i, j, (island.is.pixelF(x*64+i, y*64+j)-100)*WallHeigh);            
      }
      


      // build mesh looking for existing neightbors
      heightmap.build(mesh, 0, 6, true,
      heightmaps.find(VecI2(x-1, y)),
      heightmaps.find(VecI2(x+1, y)),
      heightmaps.find(VecI2(x, y-1)),
      heightmaps.find(VecI2(x, y+1)),
      heightmaps.find(VecI2(x-1, y-1)),
      heightmaps.find(VecI2(x-1, y+1)),
      heightmaps.find(VecI2(x+1, y-1)),  
      heightmaps.find(VecI2(x+1, y+1)) );
      
      // adjust mesh scale and position
      flt scale=128;
      Vec pos  (128*x, 0, 128*y);
      mesh.scaleMove(scale, pos);

      // simplify the mesh
      mesh.setBase  (       ); // set software version needed for simplification and later physical body creation
      mesh.simplify (0.05, 0); // simplify
      mesh.setRender(       ); // set rendering version from software version

   // create physical body
      MeshBase base;
      base.createPhys(mesh);
      base.simplify(0.05, 0); // create a 1 MeshBase from all MeshParts in mesh and simplify it again
  
      phys .createMesh(base); // create physical body from that MeshBase    
    
      mesh.delBase(); // mesh software version is no longer needed

      
      if(Game::World.areaActive(VecI2(x, y)))
         {
         Game::World.areaActive(VecI2(x, y)).getData().mesh.meshes.New().create(mesh);
         Game::World.areaActive(VecI2(x, y)).getData().phys.parts.New().createMesh(base);
      
         Game::World.areaActive(VecI2(x, y)).getData().actor.del();
         Game::World.areaActive(VecI2(x, y)).getData().actor.create(phys).group(AG_TERRAIN);
         }  
      }
   }  
}

Code for game main classes (super basic):

Code:
bool UpdateGame()
{

    if(Kb.bp(KB_ESC))StateMenu.set(1.0); // when escape pressed set 'StateMenu' with 1.0 second smooth fading
    if(Kb.bp(KB_F10  ))
         Renderer.screenShots("Screenshot/","png");

    Cam.transformByMouse(0.1, 10, CAMH_ROT|CAMH_ZOOM);  
    Cam.dist=Max(1.0, Cam.dist*ScaleFactor(Ms.wheel()*-0.1)); // update camera distance according to mouse wheel
    Cam.setSpherical(Players[0].ctrl.center()+Vec(0, 1, 0), Players[0].angle.x, Players[0].angle.y/2.0, 0, Cam.dist);  
  
   bSky.update();
   //UpdateCamera     ();
  
   Water.update(Vec2(0.01, 0.01));
   Game.World.update(Cam.at); // update the world to given position
  
   return true;
}
void Render()
{
   Game.World.draw(); // draw world (this is done outside of 'switch(Renderer())' because world automatically detects active rendering mode)
}

void DrawGame()
{
  
   if(BL.draw())return;
   Renderer(Render);
  
   //if(Kb.br(KB_SPACE)) island.generate();
   if(map.is())map.draw(Rect_LD(-D.w(), -D.h(), 0.8, 0.8));
  
   if(Kb.b(KB_V))Physics.draw();
   if(Kb.b(KB_B))Worldpath.draw();
  
   D.text(Vec2(-1.4, 0.8f), S+"Hour: "+(Trunc(bSky.hour)%24)+" : "+(S+(Trunc(bSky.hour*60)%60)));
   D.text(Vec2(-1.4, 0.7f), S+"Fps: "+Time.fps());
  
   D.text(Vec2(-1.4, 0.6f), S+"Size: "+ (flt(island.terrain*4/10000))/100.0f+" km2");
}
01-16-2015 01:18 PM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #2
RE: Vanishing Terrain
Looks like you're area meshes have no (or incorrect) bounding boxes, which is what EE uses to frustum cull them away. Perhaps try calling mesh.setBox(true) to recalculate the mesh's bounding box after creating it and see if that solves the problem.
01-16-2015 11:53 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
RE: Vanishing Terrain
Yes this does look like bounding box issue, I think I see where.

Game::World.areaActive(VecI2(x, y)).getData().mesh.meshes.New().create(mesh);

you're adding a Mesh to a MeshGroup, 'MeshGroup' has its own box, so call Game::World.areaActive(VecI2(x, y)).getData().mesh.setBox..
after adding the mesh.
01-17-2015 04:32 AM
Find all posts by this user Quote this message in a reply
Pherael Offline
Member

Post: #4
RE: Vanishing Terrain
Sadly adding setBox (as in Esenthel suggestion) didn't change anything. But thanks for giving me clue, I'll try something by myself and I'll post the result later.
(This post was last modified: 01-17-2015 09:40 AM by Pherael.)
01-17-2015 09:39 AM
Find all posts by this user Quote this message in a reply
Pherael Offline
Member

Post: #5
RE: Vanishing Terrain
Well, after few hours I couldn't figure it out. Knowing my luck I'm missing something simple. As see in video below, terrain have correct bounding boxes, but the problem still occurs.


01-17-2015 01:29 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
RE: Vanishing Terrain
If you can't figure out what's wrong, could you provide a small reproducible test case (a small *.EsenthelProject). It would be easier to pinpoint the issue.
01-17-2015 11:12 PM
Find all posts by this user Quote this message in a reply
Pherael Offline
Member

Post: #7
RE: Vanishing Terrain
This is small EsenthelProject with my problem. If someone could check, what I doing wrong I will be very grateful.

https://drive.google.com/file/d/0B2UJDG_...sp=sharing
01-18-2015 09:18 PM
Find all posts by this user Quote this message in a reply
georgatos7 Offline
Member

Post: #8
RE: Vanishing Terrain
Did you find a solution to this Pharael cause i've been searching my self and whatever i try has the same disappearing problem.
Let me know if you don't have a solution so i can post a much smaller project that might make it easier for other ppl to check.
(This post was last modified: 01-26-2015 11:54 PM by georgatos7.)
01-26-2015 11:54 PM
Find all posts by this user Quote this message in a reply
Pherael Offline
Member

Post: #9
RE: Vanishing Terrain
Sadly, I didn't find solution for this yet.
01-27-2015 12:05 AM
Find all posts by this user Quote this message in a reply
georgatos7 Offline
Member

Post: #10
RE: Vanishing Terrain
Lolol i found the problem while i was packing the project.
Just make sure you set the world area size (not resolution) to 128 while you create it and it'll work fine. :O

That's how those things make me feel most of the time...
http://9gag.com/gag/aYp2mo2/if-you-ve-ev...sums-it-up
(This post was last modified: 01-27-2015 12:51 AM by georgatos7.)
01-27-2015 12:50 AM
Find all posts by this user Quote this message in a reply
Pherael Offline
Member

Post: #11
RE: Vanishing Terrain
Hahaha, I'm laughing so much smile It's working now.
01-27-2015 01:01 AM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #12
RE: Vanishing Terrain
The world you are loading is using size 64 not 128 like you scale your meshes to, hence why it cuts out early. and only in certain occasions, either change the scale code to 64 or create a new world of size 128. smile


Seems I was a bit late grin
(This post was last modified: 01-27-2015 01:03 AM by Zervox.)
01-27-2015 01:02 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #13
RE: Vanishing Terrain
(01-27-2015 12:50 AM)georgatos7 Wrote:  That's how those things make me feel most of the time...
http://9gag.com/gag/aYp2mo2/if-you-ve-ev...sums-it-up

One of the funniest things I've seen recently lol
01-27-2015 03:36 AM
Find all posts by this user Quote this message in a reply
Pherael Offline
Member

Post: #14
RE: Vanishing Terrain
BTW, where can I get info about Area Size and World Resolution AFTER creation? I mean in Editor, no in code.
01-27-2015 09:01 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #15
RE: Vanishing Terrain
In the Editor you can check the area size using the "cursor position information" and moving the cursor to the edge of an area and investigating the position.
There is no way currently to check the heightmap resolution though, this needs to be done in code.
01-27-2015 09:16 AM
Find all posts by this user Quote this message in a reply
Post Reply