Jump to content

Road system for terrain


YouGroove
 Share

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.

wroad.jpg

  • Upvote 4

Stop toying and make games

Link to comment
Share on other sites

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.

  • Upvote 4

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

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.

Stop toying and make games

Link to comment
Share on other sites

You mean like this?

 

rage-pc-005.jpg

Yes and yes. Although I don't know all the details yet, but it will be good. It's one of the benefits of the way I designed the terrain, although we haven't gotten to enjoy it yet.
  • Upvote 7

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • 2 months later...

This will carve roads using pivot childs and splines.

Second terrain layer will be road color.

 

http://www.leadwerks.com/werkspace/page/viewitem_?fileid=404532791

 

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

   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]
       else
           p0, p1, p2, p3 = points[i - 1], points[i], points[i + 1], points[i + 2]
       end    

       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 } )                
           end    
       end

   end    
   return spline
end


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
				    self.terrain=world:GetEntity(i)
				    tolua.cast(self.terrain,"Terrain")
				    break
		    end
 end

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

    while self.terrain == nil
    do
       System:Print("....")
    end

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

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

       x=terrainsize/2+self.entity:GetChild(d):GetPosition(true).x
       y=terrainsize/2+self.entity:GetChild(d):GetPosition(true).z
       h=self.terrain:GetHeight(x,y)

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


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

   for x=1,#colorspline-1,1
   do
       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)
   end

   for x=1,#spline-1,1
   do


       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)
   end
end

  • Upvote 1

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

  • 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.
Note: Your post will require moderator approval before it will be visible.

Guest
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.

 Share

×
×
  • Create New...