How to efficiently use many copies of same mesh in a single view

Software: Away3D 4.x

Dragoola, Newbie
Posted: 16 July 2012 02:59 AM   Total Posts: 16

I am working on a Minecraft similar game that uses a world where buildings are built up from cubes. I want to make the game as efficient as possible but I couldn’t find anywhere information on how to efficiently add many copies of the same mesh(in this case a cube) to the world. Do I have to use a loader for each cube or should I somehow combine multiple cubes to be loaded together. Any advice on how to improve efficiency will be greatly appreciated.

Thanks

   

Babylon, Jr. Member
Posted: 16 July 2012 07:19 AM   Total Posts: 39   [ # 1 ]

I am actually doing the exact same thing. Being a big fan of minecraft and doing an independent study at school for Game Programming in Flash I chose to create a game similar to minecraft. I’m actually in a similar situation to you. Trying to figure out how to draw many cubes to the screen and have it run on my graphically weak laptop (so far nothing much).

So far I look something like this:

var x:int 0;
   var 
y:int 0;
   var 
z:int 0;
   
   for (
050x++){
    
for (01y++){
     
for (050z++){
      mesh 
= new Mesh();
      
//wfs = new WireframeCube(5,5,5,0xFFFFFF, 5);
      //wfs = new WireframeSphere(5, 3, 3, 0xFFFFFF, 1);       //_view.scene.addChild(wfs);       //wfs.positi wfs.positi Vector3D(0 + (cubeG.width * x),0 + (cubeG.height * y),0 + (cubeG.depth * z));       //wfs.positi Vector3D(0 + (cubeG.width * x),0 + (cubeG.height * y),0 + (cubeG.depth * z));
      //wfs.y = terrain.getHeightAt(wfs.x,  wfs.z);
      //wfs.y = wfs.y - (wfs.y % 20);
      //wfs.y = terrain.getHeightAt(body.x,  body.z);
      //wfs.y = body.y - (body.y % 20);
      // mesh = new Mesh();
      
mesh.geometry cubeG;       //mesh.positi Vector3D(15, 15 + 15*i, 15);
             
mesh.positi Vector3D(-1000 + (cubeG.width),  400 - (terrain.getHeightAt(cubeG.width300 + (cubeG.height)-(cubeG.height y)), cubeG.depth)); 

Create the mesh, postion the mesh, add the mesh to the screen. Some things I was thinking about:
How to tell what meshes are actually visible. Say my camera is in the sky looking down, it will draw all the cubes underneath the first visible layer, because they are in the perspective of view but not necessarly visible. I was also thinking about finding out which meshes are closest and then set only those visible to true.

I don’t really know.

   

Richard Olsson, Administrator
Posted: 16 July 2012 09:42 AM   Total Posts: 1192   [ # 2 ]

There are many ways to optimize a situation like this. First of all, make sure you have as few geometry objects as possible. The way that Babylon suggests is indeed the simplest solution to that.

As a second degree of optimization in this same area, investigate merging large portions of the world into a single geometry to get the number of draw calls down. For example, you could split the world up in separate logical areas (on the XZ plane) and when the player moves away from a segment, switch it from a multi-cube representation to a single-geometry representation. As the player moves into a region (and therefor needs to be able to modify/destroy/build geometry) do the opposite and switch from the single-geometry representation to the more easily modified multi-cube representation.

When you merge geometry like this, you will need to employ a texture atlas approach to texturing the geometry, but that should be fine if you’re going for the same low-resolution texture look that Minecraft has.

Finally, implement your own culling logic. The engine will never be as fast at doing (general-purpose) occlusion culling as any bespoke logic that you can implement yourself and that works on a single-purpose principle, such as that cubes that are underneath other cubes can’t possibly be visible. To optimize this, you could create a two-dimensional array (or bitmap) representing the XZ plane and containing the Y heights at which to find the bottom-most cube that does not have a cube on top of it. That way, your logic can very quickly discard all cubes that are underneath that height value for every column, and remove them from the scene.

Essentially, there are a lot of ways to implement and optimize something like this. And there are of course edge cases that will not work with all types of optimization (e.g. water needs to be handled differently.) So my recommendation is that you start out with a very limited set of features that you want to support, and then build from that. Especially if the work is intended as a learning experience, you should not spend too much time up fron trying to come up with solutions to every possible problem or new feature that you might want to introduce down the line.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X