[Questions] What is the best way to generate a terrain

Hello,

I got a file with coordinates x,y,z . what is the best way to make a terrain?

Cumps

You will have to provide more than just “I have a file with…”

Without seeing what you have, or at least part of what you have, it would be hard to give any suggestions.

Just a bunch of xyz’s may mean nothing if they are not organized in some form.

Sorry,

My file is a csv file.
Example:

x;y;z
10000;12033;13000

I want to make a terrain with it… My file have gps coordinates too. LAT and LOG

So, you have Cartesian coordinates and Polar coordinates in the same file?

So, first thing is, you need to make sense of your data. Is this point cloud data?

Giving Polar coordinates only works with a radius, or are you assuming something here you are not telling?

I know this is stupid to ask… Post the first 100 lines (or so) of your file here.

Sure:

z X Y long lat
157.44500000000 603995 4165513 -7.82142000000 37.63090000000
158.25500000000 604005 4165513 -7.82130000000 37.63090000000
158.76900000000 604015 4165513 -7.82119000000 37.63090000000
159.02300000000 604025 4165513 -7.82108000000 37.63090000000
159.14900000000 604035 4165513 -7.82096000000 37.63090000000
159.22900000000 604045 4165513 -7.82085000000 37.63090000000
159.30100000000 604055 4165513 -7.82074000000 37.63090000000
159.38600000000 604065 4165513 -7.82062000000 37.63090000000
159.49100000000 604075 4165513 -7.82051000000 37.63090000000
159.61800000000 604085 4165513 -7.82040000000 37.63080000000
159.75000000000 604095 4165513 -7.82028000000 37.63080000000
159.80300000000 604105 4165513 -7.82017000000 37.63080000000
159.84100000000 604115 4165513 -7.82006000000 37.63080000000
159.89100000000 604125 4165513 -7.81994000000 37.63080000000
160.00000000000 604135 4165513 -7.81983000000 37.63080000000
160.08800000000 604145 4165513 -7.81972000000 37.63080000000
160.11300000000 604155 4165513 -7.81960000000 37.63080000000
160.11900000000 604165 4165513 -7.81949000000 37.63080000000
160.24700000000 604175 4165513 -7.81938000000 37.63080000000
160.21900000000 604185 4165513 -7.81926000000 37.63080000000
160.16700000000 604195 4165513 -7.81915000000 37.63080000000
160.13100000000 604205 4165513 -7.81904000000 37.63080000000
159.99900000000 604215 4165513 -7.81892000000 37.63080000000
159.76500000000 604225 4165513 -7.81881000000 37.63080000000
159.55100000000 604235 4165513 -7.81870000000 37.63080000000
159.31500000000 604245 4165513 -7.81858000000 37.63080000000
159.09100000000 604255 4165513 -7.81847000000 37.63080000000
158.89600000000 604265 4165513 -7.81836000000 37.63080000000
158.74900000000 604275 4165513 -7.81824000000 37.63080000000
158.66300000000 604285 4165513 -7.81813000000 37.63080000000
158.66700000000 604295 4165513 -7.81802000000 37.63080000000
158.79900000000 604305 4165513 -7.81790000000 37.63080000000
159.02400000000 604315 4165513 -7.81779000000 37.63080000000
159.06100000000 604325 4165513 -7.81768000000 37.63080000000
158.99500000000 604335 4165513 -7.81756000000 37.63080000000
158.79000000000 604345 4165513 -7.81745000000 37.63080000000
158.33300000000 604355 4165513 -7.81734000000 37.63080000000
157.87200000000 604365 4165513 -7.81722000000 37.63080000000
157.37300000000 604375 4165513 -7.81711000000 37.63080000000
156.72400000000 604385 4165513 -7.81700000000 37.63080000000
155.96500000000 604395 4165513 -7.81688000000 37.63080000000
155.10800000000 604405 4165513 -7.81677000000 37.63080000000
154.17800000000 604415 4165513 -7.81666000000 37.63080000000
153.21000000000 604425 4165513 -7.81654000000 37.63080000000
152.26300000000 604435 4165513 -7.81643000000 37.63080000000
151.39500000000 604445 4165513 -7.81632000000 37.63080000000
150.63700000000 604455 4165513 -7.81620000000 37.63080000000
150.00500000000 604465 4165513 -7.81609000000 37.63080000000
149.50700000000 604475 4165513 -7.81598000000 37.63080000000
149.11400000000 604485 4165513 -7.81586000000 37.63080000000
148.81700000000 604495 4165513 -7.81575000000 37.63080000000
148.60400000000 604505 4165513 -7.81564000000 37.63080000000
148.44300000000 604515 4165513 -7.81552000000 37.63080000000
148.33600000000 604525 4165513 -7.81541000000 37.63080000000
148.27000000000 604535 4165513 -7.81530000000 37.63080000000
148.24900000000 604545 4165513 -7.81518000000 37.63080000000
148.25000000000 604555 4165513 -7.81507000000 37.63080000000
148.27000000000 604565 4165513 -7.81496000000 37.63080000000
148.27600000000 604575 4165513 -7.81484000000 37.63080000000
148.17300000000 604585 4165513 -7.81473000000 37.63080000000
148.00000000000 604595 4165513 -7.81462000000 37.63080000000
147.81900000000 604605 4165513 -7.81450000000 37.63080000000
147.67300000000 604615 4165513 -7.81439000000 37.63080000000
147.56900000000 604625 4165513 -7.81428000000 37.63080000000
147.49500000000 604635 4165513 -7.81416000000 37.63080000000
147.40900000000 604645 4165513 -7.81405000000 37.63080000000
147.25300000000 604655 4165513 -7.81394000000 37.63080000000
146.99400000000 604665 4165513 -7.81382000000 37.63080000000
146.72600000000 604675 4165513 -7.81371000000 37.63080000000
146.40800000000 604685 4165513 -7.81360000000 37.63080000000
145.89600000000 604695 4165513 -7.81348000000 37.63080000000
145.47300000000 604705 4165513 -7.81337000000 37.63080000000
145.20400000000 604715 4165513 -7.81326000000 37.63080000000
145.04000000000 604725 4165513 -7.81314000000 37.63080000000
144.88300000000 604735 4165513 -7.81303000000 37.63080000000
144.68400000000 604745 4165513 -7.81292000000 37.63080000000
144.42700000000 604755 4165513 -7.81280000000 37.63080000000
144.09300000000 604765 4165513 -7.81269000000 37.63080000000
143.64800000000 604775 4165513 -7.81258000000 37.63080000000
143.09500000000 604785 4165513 -7.81246000000 37.63080000000
142.49300000000 604795 4165513 -7.81235000000 37.63080000000
141.90000000000 604805 4165513 -7.81224000000 37.63080000000
141.38100000000 604815 4165513 -7.81212000000 37.63080000000
141.15200000000 604825 4165513 -7.81201000000 37.63080000000
141.06400000000 604835 4165513 -7.81190000000 37.63080000000
141.00900000000 604845 4165513 -7.81178000000 37.63080000000
140.89000000000 604855 4165513 -7.81167000000 37.63080000000
140.58400000000 604865 4165513 -7.81156000000 37.63080000000
139.91200000000 604875 4165513 -7.81144000000 37.63080000000
138.76600000000 604885 4165513 -7.81133000000 37.63080000000
137.83600000000 604895 4165513 -7.81122000000 37.63080000000
137.45400000000 604905 4165513 -7.81110000000 37.63080000000
137.76300000000 604915 4165513 -7.81099000000 37.63080000000
138.45000000000 604925 4165513 -7.81088000000 37.63080000000
139.25700000000 604935 4165513 -7.81076000000 37.63080000000
139.96600000000 604945 4165513 -7.81065000000 37.63080000000
140.30900000000 604955 4165513 -7.81054000000 37.63070000000
140.62000000000 604965 4165513 -7.81042000000 37.63070000000
140.94100000000 604975 4165513 -7.81031000000 37.63070000000
141.27700000000 604985 4165513 -7.81020000000 37.63070000000

OK, so lets pay attention to the data.

I see the Z and X changing, but I do not see the Y changing, Why is that?

I see that the X changes by about 1000 over the course of your data. This suggests to me that you are using a grid to process your data.

Z seems to fluctuate so I can assume that this is your height data.

OK, so all your Y’s are 4165513

Give me about 10 lines from where it changes from 4165513 to the next number, and 10 more lines from when it changes from that number.

OH, I also want to know how many lines are where the y is 4165513 in that first set.

Give me about 10 lines from where it changes from 4165513 to the next number, and 10 more lines from when it changes from that number.

4165513 → 4165503:

144.22200000000 621685 4165513 -7.62098000000 37.62870000000
144.66300000000 621695 4165513 -7.62087000000 37.62870000000
157.93500000000 603995 4165503 -7.82142000000 37.63080000000
158.82000000000 604005 4165503 -7.82130000000 37.63080000000
159.34200000000 604015 4165503 -7.82119000000 37.63080000000
159.50300000000 604025 4165503 -7.82108000000 37.63080000000
159.55700000000 604035 4165503 -7.82096000000 37.63080000000
159.59200000000 604045 4165503 -7.82085000000 37.63080000000
159.62700000000 604055 4165503 -7.82074000000 37.63080000000
159.67300000000 604065 4165503 -7.82062000000 37.63080000000
159.73700000000 604075 4165503 -7.82051000000 37.63080000000
159.83500000000 604085 4165503 -7.82040000000 37.63080000000
159.99800000000 604095 4165503 -7.82028000000 37.63080000000
160.00000000000 604105 4165503 -7.82017000000 37.63080000000
160.00000000000 604115 4165503 -7.82006000000 37.63080000000
160.00100000000 604125 4165503 -7.81994000000 37.63080000000
160.10800000000 604135 4165503 -7.81983000000 37.63080000000
160.19800000000 604145 4165503 -7.81972000000 37.63080000000

4165503 → 4165493
143.23300000000 621685 4165503 -7.62098000000 37.62860000000
143.73400000000 621695 4165503 -7.62087000000 37.62860000000
158.50500000000 603995 4165493 -7.82142000000 37.63070000000
159.43800000000 604005 4165493 -7.82130000000 37.63070000000
159.97900000000 604015 4165493 -7.82119000000 37.63070000000
160.01100000000 604025 4165493 -7.82108000000 37.63070000000
160.00400000000 604035 4165493 -7.82096000000 37.63070000000
160.00200000000 604045 4165493 -7.82085000000 37.63070000000
160.00100000000 604055 4165493 -7.82074000000 37.63070000000
160.00000000000 604065 4165493 -7.82062000000 37.63070000000
160.00000000000 604075 4165493 -7.82051000000 37.63070000000
160.00300000000 604085 4165493 -7.82040000000 37.63070000000
160.14000000000 604095 4165493 -7.82028000000 37.63070000000
160.19000000000 604105 4165493 -7.82017000000 37.63070000000
160.20600000000 604115 4165493 -7.82006000000 37.63070000000
160.22400000000 604125 4165493 -7.81995000000 37.63070000000

Each value have more or less 1700 records

OK, (NOT the) last question…

does the Y 4165513, ever show up again past the first set?

Or better yet, I am looking for a repeating Y… If the first set of Y is

assuming each row has 1700, and you have 1700 x 1700 x 6 … you should have approximately 17340000 rows in the entire file?

My file has 1048576 lines

No, its order… subtract 10 units

ok, so doing some simple work… your file has exactly 1048576 lines… and the square root of that happens to be 1024.

This means that the map is exactly 1024 x 1024.

Now, lets look at the Z value by its self.

Find the minimum and maximum Z value for the entire file. This is your Height range.

Given that your current results are around 140 to 160, I would expect this number to truly be between 0 and 255. (binary)

So, here is your path forward…

The file contains 1 number of use… the Z value, and that value is spread across 1024 x 1024 pixels.

You need to now make a program that converts this data (z only) using this formula:

var f = z / 256;

Then you need to replicate the last value to make it 1025 x 1025. and write all of this to a .raw file. This .raw file is a picture of all the heights.

Once you have the .raw file ready, simply import it onto a Terrain object as a height map.

OK, now, I know all of this because I did quite a bit of work with terrain maps. Check out this simple generator:

http://clarksvillegamedesign.net/terrain/

2 Likes

But after generate the terrain I want to put something on map, like trees, stones etc in specific position.
With heightmap I lost it , right? Image that I want to put one store on position (this line: 144.66300000000 621695 4165513 -7.62087000000 37.62870000000) .

no, you haven’t lost anything… lets say that line is line number 51234 of your file…

var width = 1024;
var i = 51234;
var y = (int)Mathf.Floor(i / width);
var x = i - (y * width);

I: 51234
X: 34
Y: 40

Thank you!

How I generate raw file? OR what is the strucure of raw file? Can I use c# language to generate it? Or I need to use photoshop?

you need c#, Unity will do. You need to read the entire file, split it by line, split each line by spaces and convert those values to floats

Next, you will need to create an array of floats 1025 * 1025.

Next, You will need a pointer that is the current position in the file.

To make it simple, I would create a double loop, y and x (y = 0; y<1024; y++) and every time you reach the end of X (right before you start the next y, add the last value to the array.

Finally, once you are done with the y and x, you should repeat the last row again. This converts 1024 x 1024 to 1025 x 1025.

Write the file out as a .raw file

Can you show me a sample of .raw file?

It’s like that:

1 1 1

goto:

http://clarksvillegamedesign.net/terrain/

Click Generate.

Goto the file tab

Click Save. It saves a raw file.

A raw file is a binary file, so you can’t read it normally.

1 Like

OK, I misspoke…

Raw data is in uint16 format.

This means that the number is an integer between 0 and 65535.

So the formula is:

var f = (uint16) (z * 256);