Create a grid mesh from text file

Hi,
In France IGN give for free some .asc files.
https://geoservices.ign.fr/documentation/diffusion/telechargement-donnee...
This is simple .asc files like :
ncols 3
nrows 5
xllcorner 849997.500000000000
yllcorner 6360002.500000000000
cellsize 5.000000000000
NODATA_value -99999.00
133.00 134.00 135.00
133.00 134.00 135.00
133.00 134.00 135.00
133.00 134.00 135.00
133.00 134.00 135.00
Values are separated by spaces.
In reality, ncols =1000 and nrows=1000
(xcorner, ycorner) is the position of the first point (origine).
So I would like to create a mesh grid :
read first line, first value, create a vertex ( or place first vertex of the grid ) at origine with z=first value
read first line, second value, create a vertex ( or place second vertex of the grid ) at origine + cell size with z=second value
(...)
Same for each line.
As there is a lot of data, I would like to be able to skip some values : ncol divided by a value. Same for nrows.
As 3dsmax don't like very big model, I would like to be able to "move" origine value.
I made an ugly UI to give an idea.
Thanks. I think it could help a few people.

Next step is a batch importer, as there can be a lot of files... ;-)

AttachmentSize
request1.jpg91.31 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jahman's picture
titane357's picture

In fact I saw this page

In fact I saw this page already, but I didn't understand really what it is...
The file I want to use is more "easy" as it is a ortho 2d grid with a z value for each point.
My first problem is that I saw tutorials to read value of a text file line, but I don't know how to read one value at a time of each lines.
My second problem is that I'm not very comfortable with arrays :-)
My main problem is that I'm a ass...le in scripting as soon as there is maths...

jahman's picture

.

you can do it the ugly way
1. read all lines
2. split each line by space character into three parts
3. convert each part into float and ensure that result is actually a float value
4. do whatever you need with the values

(
 
	lines_array = (dotNetClass "System.IO.File").ReadAllLines "path_to_file"
 
	for line_of_file in lines_array do
	(
		values = filterString line_of_file " "
 
		if values.count == 3 do
		(
			values[1] = values[1] as float
			values[2] = values[2] as float
			values[3] = values[3] as float
 
			if iskindof values[1] number and iskindof values[2] number and iskindof values[3] number do
			(
				... 
			)
		)
	)
 
)
titane357's picture

Thanks for answer jahman but

Thanks for answer jahman but dotnet... can't even open my file.

jahman's picture

.

... can't even open my file.
then try writing simple importer similar to the example from maxscript reference

titane357's picture

Hi, I succeed with undo off

Hi,
I succeed with undo off to keep memory very low ! :-)
And I added a progress bar ( my first one !)
But the script is too slow, and beyond 500x500, it took forever...

AttachmentSize
ok_1_mem_prog_b.ms 1.43 KB
titane357's picture

I make a script. It don't

I make a script. It don't work with the full IGN file as it is 1000x1000.
But if I overwrite the value to 200x200 it works and create a grid mesh with z values (but it don't make the good mesh as the values are shifted)
Here is the .ms and the original IGN file as text.
I'll continue to invertigate :-)

AttachmentSize
test_ori.txt 6.68 MB
ok_1.ms 1.14 KB
titane357's picture

I succeed to make my grid,

I succeed to make my grid, move my grid vertex, but I can't enter my value in VTX:
polyop.moveVert PL VERT [(COL*CELLSIZE),(ROW*CELLSIZE),TX]
because it is a STRING !!!

It is ok for few rows and columns but with NCOLLO=NROWWO= 1000, 3dsmax eats all memory and freeze...

in_name = "E:/test_only3x3.txt"
in_file = openFile in_name
NCOLLO = 3
NROWWO = 3
NCOLL = (NCOLLO - 1)
NROWW = (NROWWO - 1)
COUNTER = NCOLLO * NROWWO
CELLSIZE = 5
PL = plane()
PL.length = NROWW * CELLSIZE
PL.width= NCOLL * CELLSIZE
PL.lengthsegs = NROWW
PL.widthsegs = NCOLL
ConvertTo PL Editable_Poly
NBVERT = polyop.getNumVerts PL
 
COL = 1
ROW = 1
VERT = 1
for R=1 to NROWWO do
(
	for C=1 to NCOLLO do
	(
	TX= readDelimitedString in_file " "
	polyop.moveVert PL VERT [(COL*CELLSIZE),(ROW*CELLSIZE),TX]
	format "COLONNE :%  LIGNE :% VERTEX :%\n" COL ROW VERT
	COL +=1
	VERT +=1
	)
	ROW +=1
	COL = 1
)
jahman's picture

.

but I can't enter my value in VTX because it is a STRING !!!
convert it like in the example I posted above

titane357's picture

Hi, This is my last try as I

Hi,
This is my last try as I don't know how to optimize it more...
Virtually it works. But as it is too slow, I never see the 1000x1000 mesh.
:-(

AttachmentSize
ok_1_last.ms 1.85 KB
test_ori.txt 6.68 MB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.