Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: cool landscape tool

  1. #11
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: cool landscape tool



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


    Bye,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  2. #12
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: cool landscape tool

    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
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  3. #13
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: cool landscape tool



    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 ? ):
    [code=thinbasic]
    '=============================================================================
    '= 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

    [/code]

    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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  4. #14
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: cool landscape tool

    Thanks Petr, will play with this this weekend for sure!!

    Thanks again!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  5. #15
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: cool landscape tool

    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!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  6. #16
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: cool landscape tool

    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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  7. #17
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: cool landscape tool

    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.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  8. #18
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: cool landscape tool

    Wow,

    one hour and 10 minutes
    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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 0
    Last Post: 18-07-2007, 08:37

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •