PDA

View Full Version : cool landscape tool



kryton9
25-07-2007, 05:39
Here is a neat tool I found tonight. Haven't tried it but looking through the screenshots and taking the tour it looks very promising.
http://www.bundysoft.com/docs/doku.php?id=l3dt:about:tour

Petr Schreiber
25-07-2007, 20:10
Hi,

thanks for the link,
program seems to be very powerful !


Thanks,
Petr

Michael Hartlef
26-07-2007, 06:33
If someone checked it out, please let me know about your experience with it.

Petr Schreiber
26-07-2007, 14:10
Hi,

I did just some basic experiments how to get terrain out of this tool.
I will post the steps how to make it + conversion proggie in next days, here please just check out resulting model.
I think it is quite usable :)

Program itself is quite simple to control, it takes some time to generate terrain, but it is nothing terrible.


Bye,
Petr

kryton9
26-07-2007, 21:45
Petr, that looks superb. Well it will make my test terrain work a lot easier going with this as a base!! Thanks.

kryton9
27-07-2007, 05:07
Petr, what format did you export the heightmap to? I picked directx X format and then tried to import it into blender to export to m15 and Blender couldn't import the file and crashed when I tried. So as amazing as you are, you managed to get it to work, you smart guy you!!

Petr Schreiber
27-07-2007, 08:33
Hi Kent,

no, I used very unsmart but working technique :)

Export heightfield as RAW. Write RAW2M15 proggie.
Make a screen capture of final texture ( can't be exported directly ).
Done :)

Raw2m15 is now quite dirty, I will publish it when it will allow more options not just by modifying source :P


Bye,
Petr

kryton9
27-07-2007, 09:04
Thanks Petr, is raw just a text dump? I will need to look at that this weekend. Thanks for the explanation. I like how you call such a tough task a little program!!

Petr Schreiber
27-07-2007, 09:51
Nothing tough :),

RAW is just ... raw bytes sequence. For example RAW for 4x4 grid terrain:



AABBBACDQWER!"34


Think of it as


AABB
BACD
QWER
!"34


You take just the ASC value of characters and that means the height. This way you have 256 levels of resolution.
There is also RAW which composes value for one ... pixel, height, whatever ( it is universal ) by sequence of 3 bytes ( 256*256*256 = 16,777,216 detail ) and so on.

The proggie needs to scale the values by some factor, reduce complexity of mesh ...
It is easy to do, just need to think of UI :)


Bye,
Petr

kryton9
27-07-2007, 17:41
What? I don't think I got enough sleep... I will come back to this after a good rest and figure it out. It sounds very interesting.
Thanks.

Petr Schreiber
27-07-2007, 18:15
:D

Have a good sleep, and do not bother with RAW, consider it solved.


Bye,
Petr

kryton9
27-07-2007, 23:20
I consider it solved, but was just curious to how it worked so will tinker with it just to learn :) Thanks for your work on it by the way.
One thing this brings up though, since you figured out how to read a raw datafile and take the data use it for heightmap, does this mean
a regular greyscale heightmap routine is close by too? One that we could make in any paint program?

I know you give me your hand and I go for your arm, but they are attached... I can't help it :)

Petr Schreiber
28-07-2007, 22:56
:)

here is little script, which can be used to extract terrain out of mentioned tool.
Just make sure when exporting to set heightfield RAW export settings to:


Raw binary data file (RAW)

Support: Import and/or export only
Mosaic: Yes

Options:
- InvertY: true
- Import
- HeaderSize: 0
- Width: 0
- Height: 0
- ShowOpsOnImport: true
- Export
- AppendSizeToFilename: false
- Mode: BYTE (spanned)

... especially "BYTE (spanned)" is important.

To capture texture, you have to do it via printscreen, as it is not supported by free version.

How to control script ? Just select RAW and answer questions :)
I recommend to start with 256x256 RAWs to test out things out fast.
Level of detail = 1 means 100% quality, 4 for example means 25% of detail...

It is quite basic script, but it can be easily improved to be better/faster ( homework anyone ? :D ):


'=============================================================================
'= RAW 2 M15 Conversion =
'= Petr Schreiber, 2007 =
'= =
'= *Note: Program presumes square shaped RAW ( 128x128, ... ) =
'=============================================================================

uses "UI"
uses "CONSOLE"
uses "FILE"

dim rawFile as string = DIALOG_OPENFILE( 0, "Select RAW file", APP_SOURCEPATH, "RAW file ( *.raw )| *.raw", "raw", %OFN_FILEMUSTEXIST or %OFN_ENABLESIZING)
if len(rawFile) = 0 then stop ' -- No file, no reason to continue

dim m15File as string = file_PathSplit(rawFile, %Path_RootPathProg )+".m15"

' -- File contens
dim sBuffer as string = FILE_LOAD(rawFile)
dim sBufferLen as long = len(sBuffer)
dim sideSize as number = sqr(sBufferLen)
dim byteCount as byte = 1

dim divideFactor as number
dim skipFactor as long

dim VertexCount as long = 6*(sBufferLen/byteCount)
if frac(sideSize) <> 0 then
' if frac(sqr(sBufferLen/3)) <> 0 then
msgbox (0, "Current version of the script supports square shaped 1 byte coded RAWs", %MB_OK or %MB_ICONINFORMATION, "Unsupported RAW file")
stop
' else
' sideSize = sqr(sBufferLen/3)
' byteCount = 3
' end if
end if

console_SetTitle( "RAW 2 M15 Conversion")
console_WriteLine("File loaded...")
console_WriteLine($CRLF+repeat$(20, "=")+$CRLF)
console_WriteLine("Total length: "+FORMAT$(sBufferLen, "#,"))
console_WriteLine("Bytes per unit:"+STR$(byteCount))
console_WriteLine("Dimension of map:"+STR$(sideSize))
console_WriteLine($CRLF+repeat$(20, "=")+$CRLF)

while divideFactor <= 0
console_Write("Divide height by number ( default: none ): ")
divideFactor = val(Console_ReadLine())
if divideFactor < 0 then
console_WriteLine("[i] Value must be positive")
elseif divideFactor = 0 then
divideFactor = 1
console_WriteLine("[i] No division..."+$CRLF)
end if
wend

console_Writeline("Converting RAW to M15 would result in mesh counting "+FORMAT$(VertexCount/3, "#,")+" polygons")
while skipFactor <= 0
console_Write("Level of detail ( default: full; 2 = 50% detail and so on ): ")
skipFactor = val(Console_ReadLine())
if skipFactor < 0 then
console_WriteLine("[i] Value must be positive")
elseif skipFactor = 0 then
skipFactor = 1
console_WriteLine("[i] Full detail used..."+$CRLF)
end if
wend

dim useTex as long = -1
while (useTex < 0 or useTex > 1 )
console_Write("Do you wish to use texture for model ?( 1 = yes, 0 = no ): ")
useTex = val(Console_ReadLine())
if useTex < 0 then
console_WriteLine("[i] Value must be positive")
elseif useTex = 0 then
console_WriteLine("[i] No texture, just UVs..."+$CRLF)
end if
wend
if useTex = 1 then useTex = 2 ' -- Uh oh, well m15 has first texture as #2 :)

VertexCount = (VertexCount/skipFactor)/skipFactor

console_WriteLine("Program has collected enough information to start creating M15 mesh"+$CRLF+$CRLF+repeat$(20, "=")+$CRLF+$CRLF)

console_WriteLine("Please wait...")

dim pByte as long value strptr(sBuffer)
decr pByte

dim rawValue as long
dim Counter as long

dim HeightField(sideSize, sideSize) as number
dim posX, posZ as long
dim DotTime as long
posZ = 1

dim fLines(VertexCount) as string * 128
dim fLinesIndex as long

dim u,v,u2,v2 as number ' U,V coords

if byteCount = 1 then
for Counter = 1 to sBufferLen
incr posX
if posX > sideSize then
posX = 1
incr posZ
end if

if DotTime = 0 then console_Write(".")
incr DotTime
if DotTime > 32 then DotTime = 0

HeightField(posX, posZ) = peek(byte, pByte + Counter)/divideFactor
next

console_WriteLine($CRLF+$CRLF+"Values loaded, now prepairing file data..."+$CRLF)

for posX = 1 to sideSize-skipFactor step skipFactor
for posZ = 1 to sideSize-skipFactor step skipFactor

u = posX/sideSize
u2 = (posX+skipFactor)/sideSize
v = 1-posZ/sideSize
v2 = 1-(posZ+skipFactor)/sideSize
incr fLinesIndex
fLines(fLinesIndex) = "POLY,"+FORMAT$(posX, "#.000000")+","+FORMAT$(HeightField(posX,posZ), "#.000000")+","+FORMAT$(posZ, "#.000000")+",0,"+FORMAT$(useTex)+","+ FORMAT$(u)+"," +FORMAT$(v)+",255,255,255,0"

incr fLinesIndex
fLines(fLinesIndex) = "POLY,"+FORMAT$(posX+skipFactor, "#.000000")+","+FORMAT$(HeightField(posX+skipFactor,posZ), "#.000000")+","+FORMAT$(posZ, "#.000000")+",0,"+FORMAT$(useTex)+","+FORMAT$(u2)+"," +FORMAT$(v)+",255,255,255,0"

incr fLinesIndex
fLines(fLinesIndex) = "POLY,"+FORMAT$(posX+skipFactor, "#.000000")+","+FORMAT$(HeightField(posX+skipFactor,posZ+skipFactor), "#.000000")+","+FORMAT$(posZ+skipFactor, "#.000000")+",1,"+FORMAT$(useTex)+","+FORMAT$(u2)+"," +FORMAT$(v2)+",255,255,255,0"

'

incr fLinesIndex
fLines(fLinesIndex) = "POLY,"+FORMAT$(posX+skipFactor, "#.000000")+","+FORMAT$(HeightField(posX+skipFactor,posZ+skipFactor), "#.000000")+","+FORMAT$(posZ+skipFactor, "#.000000")+",0,"+FORMAT$(useTex)+","+FORMAT$(u2)+"," +FORMAT$(v2)+",255,255,255,0"

incr fLinesIndex
fLines(fLinesIndex) = "POLY,"+FORMAT$(posX, "#.000000")+","+FORMAT$(HeightField(posX,posZ+skipFactor), "#.000000")+","+FORMAT$(posZ+skipFactor, "#.000000")+",0,"+FORMAT$(useTex)+","+ FORMAT$(u)+","+FORMAT$(v2)+",255,255,255,0"

incr fLinesIndex
fLines(fLinesIndex) = "POLY,"+FORMAT$(posX, "#.000000")+","+FORMAT$(HeightField(posX,posZ), "#.000000")+","+FORMAT$(posZ, "#.000000")+",1,"+FORMAT$(useTex)+","+ FORMAT$(u)+"," +FORMAT$(v)+",255,255,255,0"
'
if DotTime = 0 then console_Write(".")
incr DotTime
if DotTime > 32 then DotTime = 0

next
next
console_writeLine(str$(fLinesIndex))
end if

console_WriteLine($CRLF+$CRLF+"Strings ready, entering final stage..."+$CRLF)

dim i as long

dim m15Buffer as string

m15Buffer = "VERTEXNUM,"+FORMAT$(VertexCount)+IIF$(useTex = 2, $CRLF+"TEXLIST,"+FILE_PATHSPLIT(m15File, %PATH_FILE)+".bmp", "")+$CRLF
file_save( m15File, m15Buffer )

for i = 1 to VertexCount step 512
m15Buffer = trim$(join$( fLines, $CRLF, "", i, i+512 ))
file_append( m15File, m15Buffer )
console_write(".")
next

console_WriteLine($CRLF+repeat$(20, "=")+$CRLF)

console_WriteLine("Operation completed, file output created as:"+$CRLF+m15File)

console_WriteLine($CRLF+"Press ENTER to quit...")
console_ReadLine
stop



Bye,
Petr

P.S. Kent, as long as your drawing program offers export to RAW, it should work generally ;)
P.P.S. Test data attached

kryton9
28-07-2007, 23:51
Thanks Petr, will play with this this weekend for sure!!

Thanks again!

kryton9
29-07-2007, 08:13
To capture texture, you have to do it via printscreen, as it is not supported by free version.

Petr, I got it to export a texture to a bmp. In the initial wizard, make sure attribute map is selected, then the texture map becomes selectable.

Once generated, just export the Height Field map, and then go to view, map select texture map. Then export and select bmp and you are all set.

Hope I remembered how I did it and it works for you!

Petr Schreiber
29-07-2007, 10:00
Hi Kent,

I get usually message "Sorry, this feature is not present in L3DT Standard edition" or something similar.
But I will try your trick when I will have time.

Thanks,
Petr

kryton9
29-07-2007, 11:07
I had fun playing with it. A warning and Petr mentioned this, but that made me ignore to see what would happen :)

I went with 1024 x 1024 size map and it took over an hour and 10 minutes to convert it with Petr's cool script. But the file it made
crashed both my model viewer and Petr's viewer.

Also in playing around it is a neat program, you can be in 3d view and go to edit and then edit while in 3d. Discovered this by accident
as I never read the help...

One big problem is that any have decent size map is way too many polygons and bog down big time if it even runs.
So it is a cool toy to play with, but not a good idea to use for a game.

Petr Schreiber
29-07-2007, 16:58
Wow,

one hour and 10 minutes :o
I would give up, you are hardcore man...

This is reason why I would like to prepare the TBGL compiled tools as mentioned in other thread. I am now examining how to perform something like "adaptive triangulation". On wide flat or almost flat spaces it would use less triangles than on rich parts. Good about this approach is that it can save lot of polys, bad it will most likely will look desastreous with vertex lighting. Solution then is to use shader for per pixel light or bake shadows to terrain texture.

1024x1024, that means 2,097,152 triangles kryton ! This is about 6 million vertices, each having color, uv, xyz ... lot of RAM needed.

Better would be to stream terrain by parts, or load smaller zones like Fable does.


Bye,
Petr