Creating a Terrain Mesh Editor
Blitz3D Forums/Blitz3D Programming/Creating a Terrain Mesh Editor
| ||
In My Game, My Terrain is a Specific Level.. So I need an Editor to modify the Mesh Terrain as I see fit. I have some basics going along, I can create a mesh, Selete a vertice to move up or down. What I'd like to do is select a Vertice and depending on my settings select a range of Vertices so I can make mountain tops and such. I Guess checking the distance from my currently selected Vertice might work... but then the problem of how do I make a smooth transition from the center vertice, ourward, like hills and valleys. |
| ||
You need to have the movement amount drop off as you get away from the center of your selection. So the middle vertex is moved with a strength of 100%, the next ones out are at (say) 80%, then 60%, etc. |
| ||
OK that makes sense, Is it really that easy? Now another tricky thing, Any good Ideas for allowing me to know the Points that will be influenced... Maybe a small sphere at each Vertex that will be moved, or a circle. But For a circle, how would I draw a circle on my terrain, to encompass all the verts |
| ||
Try out my terrain editor Total Terrain - version 2.0 is more fully featured. Its sculpting tools create the smooth hills and valleys you asked about. It's freeware too so you've nothing to lose by trying! |
| ||
Yeah, I noticed it, but I Feel that if I don't create my own tools, I won't learn to program... Plus I think there is something to be said in hobby programming, that reinventing the wheel is not such a bad thing. Regards, Eric |
| ||
As a hobby, that's true. But if the hobby changes into something where you'd like to make money, releasing becomes the primary objective. In that situation, looking for pre-existing solutions is the smartest choice. |
| ||
Maybe you could try it out to see if you want to get inspired about your own editor - what you like, what you don't like etc. I always try out other examples of programs similar to mine. |
| ||
This is a bit naff and knocked up quickly but may give you one idea to generate landscapes. Also, have a look at SSwifts Perlin Noise heightmap generator - it's fractal based as I remember. Also, try googling for more info - "random terrains".Graphics 640,480,32,1 Const Size = 256 Const Maxheight=255 Dim Terrain#( Size-1 , Size-1 ) MyTerrain = TERRAINcreate( 427, 500, 100 ) ;show it DrawImage MyTerrain , 0 , 0 Flip MouseWait ;=========================== ;=========================== ;=========================== Function TERRAINcreate( Seed , Passes ,SmallNo ) ;reset values to 0 Dim Terrain( Size, Size ) ;set random seed SeedRnd Seed ;generate terrain For Parts =1 To Passes StartX = Rand( 0 , size ) StartZ = Rand( 0 , size ) SlopeType = Rand( 0 , 1 ) ;Smaller Bits If Parts > ( Passes - SmallNo ) StartY# = Rnd( 4, 8 ) Radius# = Rand( 4,8 ) Else StartY# = Rnd(4,32) Radius# = Rand(4,32) EndIf For z=-radius To radius For x=-radius To radius Distance# = Sqr( x*x + z*z ) If Distance < Radius If SlopeType = 0 py#=Cos( Distance / Radius * 90) * StartY * 2.0 If SlopeType = 1 py#=( 1.0 - Sin( ( Distance / Radius ) *90 ) ) * StartY *3.0 px = WRAP( StartX + X , Size) pz = WRAP( StartZ + Z, Size) NewHeight# = LIMIT( terrain( px, pz) + py , 0, 255 ) Terrain( px , pz ) = NewHeight EndIf Next Next Next ;make heightmap Heightmap = CreateImage( Size , Size ) SetBuffer ImageBuffer( Heightmap ) Color 0,0,0:Rect 0,0,size,size,1 For z =0 To size -1 For x =0 To size -1 c = Terrain( x , z ) Color c,c,c Plot x,z Next Next SetBuffer BackBuffer() Return Heightmap End Function ;=========================== ;=========================== ;=========================== Function WRAP#( q# , hi# , lo#=0 ) If q < lo Then q = hi + (q-lo) If q >= hi Then q = lo + (q-hi) Return q End Function ;=========================== ;=========================== ;=========================== Function LIMIT#( q# , lo# , hi# ) If q < lo q = lo If q > hi q = hi Return q End Function |
| ||
Ok cool little piece of code, but I am staring with a Flat quad.. I think this could be an Option, in my editor to start with a random Terrain and then modify it from there...Hey thanks alot. |
| ||
@Stevie G, Nice functions, I made a little prog...use your own image name, textures- maybe loop it to make a bunch of terrain heightmaps fast! |
| ||
Already do this mate but with my own custom terrains - quite handy if you use red for height, blue for objects and green for land type :) |
| ||
I have a point on my terrain... A Mesh terrain, Not Blitz's.. I have a influence radius of 5 units. I click my mouse, up the terrain goes, but it makes a plateau, because all the verts within a 5 unit radius move the same distance, I want it to make a hill top. does someone have a small algorithm that will make it a smooth hill type fade? (Ie less effect the futher away from the control point) Did that make sense? Eric |
| ||
instead of altering with the same amount on all verts you could use a Value / Distance^2 ( which means xdiff ^2 + ydiff ^2 + zdiff ^2 ) as altering value. ( at least if Distance is always > 1 ... if Distance < 1 then Distance ^2 has to be replaced with 1 / Distance ^2 ) |
| ||
Ok This works, but I't isn't as smooth as I would like.. thanks for the Idea. Regards, Eric |
| ||
You can play with the part which you use to divide basing on a distance value ( I choose Distance ^2 because this prevents the usage of sqrt which slows down the calculations a little, but for a max of 100 height values, it should be no problem to use Value / sqrt( xdiff^2 + zdiff^2 ) or something basing on that |
| ||
What we do at Epic is we have 2 circles on the terrain. One is the inner radius, inside of which all verts move with the same strength. The other one is the outer radius and the verts between the inner and outer radii move with a strength adjusted by a linear falloff. So the closer a vert is to the outer radius edge, the less it moves. |
| ||
Use SIN and COS for smooth rolling hills and valleys. |