Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Road system for terrain


Recommended Posts

Hi ,


A road system for terrain, whatever is the system, from simple terrain flattening , to polygon terrain system, it would look lot better for people needing to make today roads ( it would help for game cars also).


Without it , it's longer to make and not as good.


Link to post

The road system I implement is going to be awesome because the roads will get baked into the terrain clipmap renders. They will be part of the texture, and not a separate piece of geometry, like in Rage or Quake Wars: Enemy Territory.

Link to post
The road system I implement is going to be awesome because the roads will get baked into the terrain clipmap renders. They will be part of the texture, and not a separate piece of geometry, like in Rage or Quake Wars: Enemy Territory.



you mean like that ?


Will it be possible to make a road crossing another or a road divinding in two roads or two roads joining another one ?

I think about racing games shortcuts and alternative path.

Link to post
  • 2 months later...

This will carve roads using pivot childs and splines.

Second terrain layer will be road color.




function smooth( points, steps )
   if #points < 3 then
       return points

   local steps = steps or 500

   local spline = {}
   local count = #points - 1
   local p0, p1, p2, p3, x, y, h

   for i = 1, count do

       if i == 1 then
           p0, p1, p2, p3 = points[i], points[i], points[i + 1], points[i + 2]
       elseif i == count then
           p0, p1, p2, p3 = points[#points - 2], points[#points - 1], points[#points], points[#points]
           p0, p1, p2, p3 = points[i - 1], points[i], points[i + 1], points[i + 2]

       for t = 0, 1, 1 / steps do
           x = 0.5 * ( ( 2 * p1.x ) + ( p2.x - p0.x ) * t + ( 2 * p0.x - 5 * p1.x + 4 * p2.x - p3.x ) * t * t + ( 3 * p1.x - p0.x - 3 * p2.x + p3.x ) * t * t * t )
           y = 0.5 * ( ( 2 * p1.y ) + ( p2.y - p0.y ) * t + ( 2 * p0.y - 5 * p1.y + 4 * p2.y - p3.y ) * t * t + ( 3 * p1.y - p0.y - 3 * p2.y + p3.y ) * t * t * t )
           h = 0.5 * ( ( 2 * p1.h ) + ( p2.h - p0.h ) * t + ( 2 * p0.h - 5 * p1.h + 4 * p2.h - p3.h ) * t * t + ( 3 * p1.h - p0.h - 3 * p2.h + p3.h ) * t * t * t )

           --prevent duplicate entries
           if not(#spline > 0 and spline[#spline].x == x and spline[#spline].y == y) then
               table.insert( spline , { x = x , y = y, h = h } )                

   return spline

function Script:Start()
   --get world and terrain
   local world=World:GetCurrent()
   for i=0,world:CountEntities()-1 do
		    if world:GetEntity(i):GetClass()==Object.TerrainClass then

    --## Adust this t terrain size
    local terrainsize=256

    while self.terrain == nil

    local points = {  }
    for d=self.entity:CountChildren()-1,0,-1
       local e = self.entity:GetChild(d)
       System:Print( "Pivot Childs:"..e:GetKeyValue("name") )

       if self.entity:GetChild(d)~=nil then


       table.insert( points, {
           } )
       --System:Print(x.." "..y.." "..h)

   local spline = smooth( points )
   local colorspline = smooth( points,100 )

   for x=1,#colorspline-1,1
       self.terrain:SetLayerAlpha(0,colorspline[x].x, colorspline[x].y,1)
       self.terrain:SetLayerAlpha(0,colorspline[x].x+1, colorspline[x].y,1)
       self.terrain:SetLayerAlpha(0,colorspline[x].x-1, colorspline[x].y,1)
       self.terrain:SetLayerAlpha(0,colorspline[x].x+2, colorspline[x].y,1)
       self.terrain:SetLayerAlpha(0,colorspline[x].x-2, colorspline[x].y,1)

       self.terrain:SetLayerAlpha(0,colorspline[x].x, colorspline[x].y+1,1)
       self.terrain:SetLayerAlpha(0,colorspline[x].x+1, colorspline[x].y+1,1)
       self.terrain:SetLayerAlpha(0,colorspline[x].x-1, colorspline[x].y+1,1)
       self.terrain:SetLayerAlpha(0,colorspline[x].x+2, colorspline[x].y+1,1)
       self.terrain:SetLayerAlpha(0,colorspline[x].x-2, colorspline[x].y+1,1)

       self.terrain:SetLayerAlpha(0,colorspline[x].x, colorspline[x].y-1,1)
       self.terrain:SetLayerAlpha(0,colorspline[x].x+1, colorspline[x].y-1,1)
       self.terrain:SetLayerAlpha(0,colorspline[x].x-1, colorspline[x].y-1,1)
       self.terrain:SetLayerAlpha(0,colorspline[x].x+2, colorspline[x].y-1,1)
       self.terrain:SetLayerAlpha(0,colorspline[x].x-2, colorspline[x].y-1,1)

       self.terrain:SetLayerAlpha(0,colorspline[x].x, colorspline[x].y+2,.5)
       self.terrain:SetLayerAlpha(0,colorspline[x].x+1, colorspline[x].y+2,.5)
       self.terrain:SetLayerAlpha(0,colorspline[x].x-1, colorspline[x].y+2,.5)
       self.terrain:SetLayerAlpha(0,colorspline[x].x+2, colorspline[x].y+2,.5)
       self.terrain:SetLayerAlpha(0,colorspline[x].x-2, colorspline[x].y+2,.5)

       self.terrain:SetLayerAlpha(0,colorspline[x].x, colorspline[x].y-2,.5)
       self.terrain:SetLayerAlpha(0,colorspline[x].x+1, colorspline[x].y-2,.5)
       self.terrain:SetLayerAlpha(0,colorspline[x].x-1, colorspline[x].y-2,.5)
       self.terrain:SetLayerAlpha(0,colorspline[x].x+2, colorspline[x].y-2,.5)
       self.terrain:SetLayerAlpha(0,colorspline[x].x-2, colorspline[x].y-2,.5)

   for x=1,#spline-1,1

       self.terrain:SetHeight(spline[x].x, spline[x].y, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x, spline[x].y-1, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x, spline[x].y+1, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x, spline[x].y-2, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x, spline[x].y+2, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x, spline[x].y-3, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x, spline[x].y+3, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x, spline[x].y-4, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x, spline[x].y+4, spline[x].h, false)

       self.terrain:SetHeight(spline[x].x+1, spline[x].y, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+1, spline[x].y-1, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+1, spline[x].y+1, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+1, spline[x].y-2, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+1, spline[x].y+2, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+1, spline[x].y-3, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+1, spline[x].y+3, spline[x].h, false)    
       self.terrain:SetHeight(spline[x].x+1, spline[x].y-4, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+1, spline[x].y+4, spline[x].h, false)    

       self.terrain:SetHeight(spline[x].x-1, spline[x].y, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-1, spline[x].y-1, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-1, spline[x].y+1, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-1, spline[x].y-2, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-1, spline[x].y+2, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-1, spline[x].y-3, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-1, spline[x].y+3, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-1, spline[x].y-4, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-1, spline[x].y+4, spline[x].h, false)

       self.terrain:SetHeight(spline[x].x+2, spline[x].y, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+2, spline[x].y-1, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+2, spline[x].y+1, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+2, spline[x].y-2, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+2, spline[x].y+2, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+2, spline[x].y-3, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+2, spline[x].y+3, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+2, spline[x].y-4, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+2, spline[x].y+4, spline[x].h, false)

       self.terrain:SetHeight(spline[x].x-2, spline[x].y, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-2, spline[x].y-1, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-2, spline[x].y+1, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-2, spline[x].y-2, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-2, spline[x].y+2, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-2, spline[x].y-3, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-2, spline[x].y+3, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-2, spline[x].y-4, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-2, spline[x].y+4, spline[x].h, false)

       self.terrain:SetHeight(spline[x].x+3, spline[x].y, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+3, spline[x].y-1, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+3, spline[x].y+1, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+3, spline[x].y-2, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+3, spline[x].y+2, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+3, spline[x].y-3, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+3, spline[x].y+3, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+3, spline[x].y-4, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+3, spline[x].y+4, spline[x].h, false)

       self.terrain:SetHeight(spline[x].x-3, spline[x].y, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-3, spline[x].y-1, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-3, spline[x].y+1, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-3, spline[x].y-2, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-3, spline[x].y+2, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-3, spline[x].y-3, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-3, spline[x].y+3, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-3, spline[x].y-4, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-3, spline[x].y+4, spline[x].h, false)

       self.terrain:SetHeight(spline[x].x+4, spline[x].y, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+4, spline[x].y-1, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+4, spline[x].y+1, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+4, spline[x].y-2, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+4, spline[x].y+2, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+4, spline[x].y-3, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+4, spline[x].y+3, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+4, spline[x].y-4, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x+4, spline[x].y+4, spline[x].h, false)

       self.terrain:SetHeight(spline[x].x-4, spline[x].y, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-4, spline[x].y-1, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-4, spline[x].y+1, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-4, spline[x].y-2, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-4, spline[x].y+2, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-4, spline[x].y-3, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-4, spline[x].y+3, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-4, spline[x].y-4, spline[x].h, false)
       self.terrain:SetHeight(spline[x].x-4, spline[x].y+4, spline[x].h, false)

Link to post
  • 1 year later...
  • 6 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Facebook Twitter Youtube Github Steam
  • Create New...