• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

MDL Format

scruffyduck

Administrator
Staff member
FSDevConf team
Resource contributor
Messages
34,981
Country
unitedkingdom
Apologies if I am asking in the wrong place. I am writing a Library Object Manager - basically to do what my API Manager does for FS9 libraries. I have no plans to change GUIDs or re-compile existing libraries but I would like to be abel to extract some data from the mdl files. The main thing I am after at the moment is footprint width and length and scale (is it ever anything other than 1). I notice that Library Creator XML can export a text file for Sbuilder which contains this data. Arno I assume this comes fro mthe MDL?

I would appreciate any pointers on how to decode mdl as it relates to footprint and scale

many thanks in advance
 
Hi Jon,

I "just" read the MDL file (in binary form) till I came across the BBOX section and then I read the size from that section. For my new MDL Tweaker II tool I am working on, I have made a more complex MDL file reader, that actually reads the total MDL file into memory, where I have created an object representation of the MDL file. I can then perform all sorts of operations on that object.

But what are you exactly trying to do? Library Creator XML for example also has an option to write API macros and there the size is also used to set the airport symbol correctly in the API file.

In this Wiki article I have written most I know about the MDL format by now (it is certainly not complete):

http://www.scenerydesign.org/wiki/doku.php?id=tutorials:other:riff_format
 
Thanks Arno.

I wrote a program called API manager which can be used to categorise and manage api macros. Obviously it can't handle mdl type objects. I am working on creating a similar program to catalog library objects. I know that other programs such as your object placer can do this kind of thing as well.

Partly I am writing the program because I think it will be useful for me and partly to help me to learn more about FS9 scenery objects
 
Hi Jon,

OK, I hope the information is useful for you. I don't know in which language your are coding, but if it would help you, I could post the code I use in Library Creator XML to get the bounding box of the MDL object.

I have never seen your API Manager tool, but how do you use it? To sort a big folder full of API files into different categories? Or does it also offer some sort of placement of these files? Just curious what you trying to make easier to do :D.
 
Hi Arno I use Visual Studio - generally Visual Basic but I do use C# and C++ and understand Java and Delphi :) I would really appreciate a view of the code related to reading the footprint data

You can see API Manager at my site www.scruffyduck.plus.com or it is available on AVSIM. It allows users to categorise API macros, identify the author, store the default footprint and scale in the API and check the textures used to make sure you have them all. It also shows the usual thumbnail and you can display the textures. You can also easily open the macro to look at the contents Macros can be filtered by category and author. It does not do any placement since there are plenty of good tools to do that.

My idea for objects is to be able to allow users to categorize objects in a way which is not necessarily the way it is in the libraries without re-compiling the libraries and the issues that might raise. I would then output files for EZ- Scenery, Sbuilder and RWY12 which reflected the 'virtual categorisation' since, as far as I can see it really doesn't matter which library bgl the object is in provided you call the correct GUID. I also want to keep track of which physical library the object is in and what textures it uses. When I create scenery I want to be able to confirm that the correct libraries and textures have been identified and made available.

Also the author of libraries and objects so that they can be easily identified and correctly credited when their objects are used in scenery. I am thinking of adding a 'quick placement facility' so that the selected object can be dropped at the current FS location (to make it easier to get a thumbnail for example) but not to do multiple objects such as Object Placer etc
 
Last edited:
Hi Jon,

Interesting tool. I never used much API macros I did not design myself in my projects, so I never felt a need to organize them. But I can imagine this is a very useful tool if you have collected a lot of 3rd party objects.

Here is my code that reads the size of an MDL object:

Code:
Public Function getMDLSize(mdl As String) As size

    Dim m As String
    
    If InStr(mdl, "..") Then
        m = splitFolderName(Form1.txt_lib.Text) & "\" & mdl
    Else
        m = mdl
    End If
    
    Open m For Binary As #1
    
    Dim s As size
    Dim l As Long
    Dim r As Single
    Dim v As HexSize
    Dim z As String

    z = readString4
    v = readHexSize
    z = readString4
    z = readTill("BBOX")
    l = getSize(readHexSize)
    s.xmin = getReal4
    r = getReal4
    s.ymin = getReal4
    s.xmax = getReal4
    r = getReal4
    s.ymax = getReal4
   
    Close #1
    
    getMDLSize = s

End Function

The functions getReal4, getString4 and readHexSize are functions to read either a string (4 bytes), a single/float (4 bytes) or a long from a file opened as binary file.
 
Thanks Arno - I will have a play around and see where I goet to :)
 
Arno I am managing to decode the mdl fine with your mdl format information and code snippet. Am I correct in assuming that width is x_max - x_min, lenght is Y_max - y_min and height would be z_max - z_min?

Also I am looking at extrating the texture names - I can see them in the TEXT section - have you tried extracting tem yet? I note that you suggest reading the BGL_FP SDK of FS2002

thanks in advance :)
 
Hi Jon,

As you can see in the piece of code, I skip one real (read it, but do nothing with it). This is because in FS the coordinates are given as x, z, y. For the footprint I only need the x and y. The width and length could then indeed be calculated by taking the difference between the max and min values. Please note that the object does not have to be centered around 0,0 for the bounding box, so it depends on the program that uses the footprint info if this is displayed correctly.

Yes, I can already read the texture file information as well. At the moment I can read most things from the MDL files, only animations have not yet been worked on. But for the textures I do not have such a clear piece of code, as that is coded within my MDL reader. I'll see if I can find something for you.
 
Thanks Arno - Any help would be appreciated when you have a moment to spare :)

I am treating the 4byte REAL4 as singles and I see that you have done that in your code as well.

Thanks again - much appreciated
 
Hi Jon,

Yes, they should indeed be seen as a Single.

I don't know if it helps much, but this code reads the texture list. I am reading it from a temp file (called tempFile :)). This temp file contains the TEXT section of the MDL file (without the TEXT header (name and long containing the length).

Code:
    num = hrInt(tempFile)
    If num <> BGLOpcode.TEXTURE_LIST_BEGIN Then
        Err.Raise vbObjectError, "AgSdLib.TextureList", "No valid texture list data in string"
        Exit Sub
    End If
    num = hrInt(tempFile)
    hrLong tempFile
    For i = 1 To num
        Set tx = New texture
        tx.texturetype = hrLong(tempFile)
        tx.color.Bi = hrByte(tempFile)
        tx.color.Ai = hrByte(tempFile)
        tx.color.Ri = hrByte(tempFile)
        tx.color.Gi = hrByte(tempFile)
        hrLong tempFile
        tx.size = hrSingle(tempFile)
        tx.bitmap = hrString(tempFile, 64)
        
        Add tx
        
        Set tx = Nothing
    Next i
 
Thanks Arno - yes that makes sense to me :) I never used VB6 - went straight into VB.Net but they are pretty similar - someof the biggest differences are in file handling. None of the file handle numbers any more :D
 
Back
Top