Problems with tiling AWPRigidBody

Software: Away3D 4.x

chufraise, Newbie
Posted: 11 September 2012 07:26 AM   Total Posts: 6

Hiya all! I’m goofing around with away physics just to get the hang of it, and I’m having some problems with tiling AWPRigidBody. I’ve been modifying the vehicle terrain demo and the reason why I’m tiling is that I want to be able to drive forever without falling off the terrain, hence the wrapping.

But It doesn’t wrap in a correct manner. I’ve created a cloud filtered image in Photoshop, and as you all probably know, it’s tiling perfectly when you make the size power of 2. So I made the heightmap image 256x256. I’m using 4 tiles that I move around depending on where the car is on the current tile.

Here I create the AWPTerrain instance:

var terrain AWPTerrain = new AWPTerrain(bmaterialterrainBMD.bitmapData.clone(), 2000031002000020020030000false); 

and here in the render method I move around the tiles:

var ind2:int 0;
    for 
each(var tBod2:AWPRigidBody in _terrainBodies{
     
var tBodPos:Vector3D _terrainBodies[ind2].position as Vector3D;
     if(
carPosition.<= tBodPos.+ (TILE_WIDTH 2) &&
      
carPosition.>= tBodPos.- (TILE_WIDTH 2) &&
      
carPosition.<= tBodPos.+ (TILE_WIDTH 2) &&
      
carPosition.>= tBodPos.- (TILE_WIDTH 2)) {
      _currentTile 
ind2;
      break;
     
}
     
     ind2
++;
    
}
    
    
    
var terrainBody:AWPRigidBody _terrainBodies[_currentTile] as AWPRigidBody;
    var 
terrainBodyPos:Vector3D terrainBody.position;
    
    
    
    var 
oldCurrentZone:int _currentZone;
    if(
carPosition.<= terrainBodyPos.&&
     
carPosition.>= terrainBodyPos.z{
     _currentZone 
ZONE_NW;
    
}
    
else if(carPosition.>= terrainBodyPos.&&
     
carPosition.>= terrainBodyPos.z{
     _currentZone 
ZONE_NE;
    
}
    
else if(carPosition.<= terrainBodyPos.&&
     
carPosition.<= terrainBodyPos.z{      _currentZ
    }
    
else if(carPosition.>= terrainBodyPos.&&
     
carPosition.<= terrainBodyPos.z{      _currentZ
    }
         
if(_currentZ oldCurrentZone{
     
return;
    
}
    
    
var ind:int = -1;
    var 
tmpArr:Array = [];
    for 
each(var tBod:AWPRigidBody in _terrainBodies{
     ind
++;
     if(
ind == _currentTile{
      
continue;
     
}
     tmpArr
.push(tBod);
     
    
}
    
switch(_currentZone{
     
case ZONE_NW:
      
tmpArr[0].terrainBodyPos.- (TILE_WIDTH);
      
tmpArr[0].terrainBodyPos.z;
      
tmpArr[1].terrainBodyPos.- (TILE_WIDTH);
      
tmpArr[1].terrainBodyPos.+ (TILE_DEPTH);
      
tmpArr[2].terrainBodyPos.x;
      
tmpArr[2].terrainBodyPos.+ (TILE_DEPTH);
      break;
     case 
ZONE_NE:
      
tmpArr[0].terrainBodyPos.+ (TILE_WIDTH);
      
tmpArr[0].terrainBodyPos.z;
      
tmpArr[1].terrainBodyPos.+ (TILE_WIDTH);
      
tmpArr[1].terrainBodyPos.+ (TILE_DEPTH);
      
tmpArr[2].terrainBodyPos.x;
      
tmpArr[2].terrainBodyPos.+ (TILE_DEPTH);
      break;
     case 
ZONE_SW:
      
tmpArr[0].terrainBodyPos.- (TILE_WIDTH);
      
tmpArr[0].terrainBodyPos.z;
      
tmpArr[1].terrainBodyPos.- (TILE_WIDTH);
      
tmpArr[1].terrainBodyPos.- (TILE_DEPTH);
      
tmpArr[2].terrainBodyPos.x;
      
tmpArr[2].terrainBodyPos.- (TILE_DEPTH);
      break;
     case 
ZONE_SE:
      
tmpArr[0].terrainBodyPos.+ (TILE_WIDTH);
      
tmpArr[0].terrainBodyPos.z;
      
tmpArr[1].terrainBodyPos.+ (TILE_WIDTH);
      
tmpArr[1].terrainBodyPos.- (TILE_DEPTH);
      
tmpArr[2].terrainBodyPos.x;
      
tmpArr[2].terrainBodyPos.- (TILE_DEPTH);
      break;
    

And finally here is a screenshot of the mistiling:

 

 

   

Avatar
Dexx, Newbie
Posted: 11 September 2012 11:22 AM   Total Posts: 6   [ # 1 ]

I think this is because the height map can’t be used as is, what you see is exactly what you get,  because your converting bitmap to a triangulated mesh. The sampling of the image introduces a small difference at the edges. You could try a few things:

Make the edge of the tile flat, or at least the direction of change on the ground to be parallel to the edge. E.g.: let’s say these 3 rows are the top of you height map, it should look something like this

0 0 0 1 1 2 2 2 3 2 1 1 0 0
0 0 0 1 1 2 2 2 3 2 1 1 0 0
0 0 1 2 2 3 3 4 4 3 2 1 0 0
...

I think introducing heavy redundancy at the edges will solve your issue. But it won’t look very realistic.

You could also try to increase the number of triangles. With a huge terrain resolution, these differences should become minimal. Having a number of pixels that are a multitude of the numbers of triangles, should also solve your problem as well (depending on how the bitmap is sampled).

I am new to away3d as well so, I don’t really know how you can do these things, just some ideas.

   

chufraise, Newbie
Posted: 12 September 2012 02:27 PM   Total Posts: 6   [ # 2 ]

Yes, you’re right. I increased the resolution (segmentsW, segmentsH) on AWPTerrain instance and it got a lot better! However you can only increase it so much before you hit max vertex buffer size. I guess I can’t get it completely seamless. Even if I make it completly flat around the edges, you can see it if you look closely. And the car gets stuck sometimes.

Well well, anyway it got alot better from your advice!

   

Avatar
Dexx, Newbie
Posted: 12 September 2012 02:35 PM   Total Posts: 6   [ # 3 ]

How about making the edge of the ground go downwards just a bit and placing two tiles a bit closer. This way the tiles will engrave into each other, thus the car will be able to move from one to another easily. It will be visually the ugliest solution, because there will be a small ditch along the edges.

With this solution, if you make the edge fall off good (starting slowly and increasing it up to let’s say 45 degree), you won’t even need to make the edge completely flat.

   

chufraise, Newbie
Posted: 13 September 2012 05:06 AM   Total Posts: 6   [ # 4 ]

Thanks, I tried that. However, as you predicted, it didn’t look very good even though the the physics worked better.

But I think I have got it pretty close to seamless, by just fiddling around with the resolution, and not making the topography too dramatic on the edges.

Also, when I made the ground texture more “busy”, it hid the edges even more.

Thanks for your input!

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X