November 25, 2020, 07:41:18 AM

Author Topic: [bb] Create Tiled Terrain by Leon Drake [ 1+ years ago ]  (Read 591 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Create Tiled Terrain by Leon Drake [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Create Tiled Terrain
Author : Leon Drake
Posted : 1+ years ago

Description : This is a code i wrote for my Program to create some water and Terrains. With the ability to use mesh commands like grabbing surfaces and vertexes. I also set it to tile the textures in each grid of the surface. You could also alter this code to create a surface for each tile so you can have multiple textures on this one plane.

Code :
Code: BlitzBasic
  1. ; just some types i use for creating the plane.
  2.  
  3. Type bsurface
  4. Field geohandle,surfacen$,shandle,surf
  5. End Type
  6.  
  7.  
  8. Type btri
  9. Field v1handle,v2handle,v3handle,shandle,thandle,tri
  10. End Type
  11.  
  12.  
  13. Function CreatePlane()
  14. ; lets set how wide and thick each tile will be
  15. ;a width of 30 can make a pretty decent sized plane
  16. local rectbrush_widthw,rectbrush_depthd,rectbrush_ripple,rectbrush_heighth
  17. rectbrush_widthw = 30
  18. rectbrush_depthd = 30
  19. ; i set the height to 0 as it will be a flat plane
  20. rectbrush_heighth = 0
  21. ; i was using this for water but variable here stands for
  22. ;how many segments are in the plane. 6 will do
  23. ; it will create a plane in 6x6 tiles
  24. rectbrush_ripple = 6
  25. mainbrush = CreateMesh()
  26.  
  27. ;i created a type just to make it easier than creating a bunch of vars for creating the plane.
  28.  
  29. xbrush.bsurface = New bsurface
  30. xbrushshandle = Rand(1,1000000)
  31. xbrushsurfacen$ = "myplane"
  32. xbrushsurf = CreateSurface(mainbrush)
  33.  
  34. For tempstuffy = 0 To rectbrush_ripple-1
  35. For tempstuffx = 0 To rectbrush_ripple-1
  36. ;tempstuffx = tempstuffy
  37.  
  38. ttri.btri = New btri
  39. ttrishandle = xbrushshandle
  40. ttri    handle = Rand(1,1000000)
  41. ttriv1handle = AddVertex (xbrushsurf, 0+(rectbrush_widthw*tempstuffx),rectbrush_heighth,rectbrush_depthd+(rectbrush_depthd*tempstuffy), 0 ,1)
  42. ttriv2handle = AddVertex (xbrushsurf, rectbrush_widthw+(rectbrush_widthw*tempstuffx),rectbrush_heighth,0+(rectbrush_depthd*tempstuffy), 1 ,0)
  43. ttriv3handle = AddVertex (xbrushsurf, 0+(rectbrush_widthw*tempstuffx),rectbrush_heighth,0+(rectbrush_depthd*tempstuffy), 0,0)
  44. ttri    ri = AddTriangle (xbrushsurf,ttriv1handle,ttriv2handle,ttriv3handle)
  45. ttri.btri = New btri
  46. ttrishandle = xbrushshandle
  47. ttri    handle = Rand(1,1000000)
  48. ttriv1handle = AddVertex (xbrushsurf, rectbrush_widthw+(rectbrush_widthw*tempstuffx),rectbrush_heighth,rectbrush_depthd+(rectbrush_depthd*tempstuffy), 1 ,1)
  49. ttriv2handle = AddVertex (xbrushsurf, rectbrush_widthw+(rectbrush_widthw*tempstuffx),rectbrush_heighth,0+(rectbrush_depthd*tempstuffy), 1 ,0)
  50. ttriv3handle = AddVertex (xbrushsurf, 0+(rectbrush_widthw*tempstuffx),rectbrush_heighth,rectbrush_depthd+(rectbrush_depthd*tempstuffy), 0,1)
  51. ttri    ri = AddTriangle (xbrushsurf,ttriv2handle,ttriv3handle,ttriv1handle)
  52.  
  53. Next
  54. Next
  55.  
  56. For brush.bsurface = Each bsurface
  57. Delete brush
  58. Next
  59.  
  60. For ttri.btri = Each btri
  61. Delete ttri
  62. Next
  63.  
  64. return mainbrush
  65.  
  66. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal