Blender Import/Export Addon (kompatibel bis Blender 2.79, aktuelle Version 0.5.3 - Alphatest)

Willkommen in der Transport Fever Community

Wir begrüßen euch in der Fan-Community zu den Spielen Transport Fever und Train Fever, den Wirtschaftssimulatoren von Urban Games. Die Community steht euch kostenlos zur Verfügung damit ihr euch über das Spiel austauschen und informieren könnt. Wir pflegen hier einen freundlichen und sachlichen Umgang untereinander und unser Team steht euch in allen Fragen gerne beiseite.

 

Die Registrierung und Nutzung ist selbstverständlich kostenlos.

 

Wir wünschen euch viel Spaß und hoffen auf rege Beteiligung.

Das Team der Transport-Fever Community


  • Thank you eis_os for permission and thanks Yoshi for poking Merk :) I now have permission from all previous authors to release Version 0.6.0 of the plugin under a CC BY-NC-SA 2.0 License (https://creativecommons.org/licenses/by-nc-sa/2.0/)!


    io_mesh_mdl_0.6.0.zip


    I guess releasing this to the community makes it a beta version. I should point out that my own internal testing really only tested one workflow (import a stock TpF2 loco -> export it -> view in TpF2 Model Viewer or game, all with Blender 2.77a), so other workflows may well be very buggy. The intent was that the following workflows would remain functional:

    • Import TF model -> edit -> export for TF
    • Import TpF model -> edit -> export for TpF

    ...but I didn't explicitly test that these still work, so it is entirely possible that they don't. If you find that they don't, please reply with a bug report (suggested format below) and I will see whether I can fix the issue. Cross-game workflows (TF->Blender->TpF2) wasn't a design goal.


    Some notes on configuration:

    1. You need to set two additional directories under "Blender/User Preferences/Import-Export: Train Fever ..." They are:
      1. Transport Fever 2 Directory (for many users this will be C:\Program Files (x86)\Steam\steamapps\common\Transport Fever 2\)
      2. Temporary File Directory. This is a kind of blunt workaround for the fact that res/models is zipped in TpF2; whenever an import relies on a file contained within the .zip file, it checks whether that file exists in this temporary file directory, and if it doesn't, it exports the file from the .zip to the temporary directory. The script never deletes anything from this directory, but you can manually (or you can leave it, so that subsequent imports will go faster). The reason for not getting python to read directly from the .zip is that it would require more extensive script changes and would (as far as I can tell) be significantly slower
    2. When importing, remember to indicate which game's files you are trying to import. It tweaks some settings
    3. When exporting, you now have to indicate which game's files you are trying to export. I also added a new option "prefix" to the exporter. If you enter a text string into this box when exporting, every file that gets exported will have that prefix prepended to it (the file references within the output files are also changed, so they still all reference one another). The reason for this features is I kept importing and exporting stock models for testing purposes, and I wanted a way to get the output into the game without replacing the stock models (which is how mods normally work) so that I could compare original and processed models in-game. You might find this handy if you want to re-mod an existing mod or model. I went with a prefix rather than a suffix so that the prefixed files would all be sorted together in my file browser and be easy to delete during testing.

    I also changed some settings (like how spacing is inserted in exported files) so that the output files look more similar to the originals in TpF2.


    Important Notes:

    • I know a lot more about programming than I do about Blender - I'm open to bug reports, but you may have to explain your Blender workflow to me in really basic terms
    • If you know as little about Blender as I do, you may be interested to know that those @#$ error messages that flash up when the script errors out are actually recorded somewhere. You can see the whole log of the python script if you enlarge any Info bar (e.g. drag down on the bottom of the menu bar in the default Blender configuration)

    Bug Reports:


    Please follow the following format:


    Steps to reproduce:

    1. Open Blender 2.77a (default configuration).
    2. Load [stock model] with the following load settings...
    3. Click Menu/Menu Entry and then...

    Expected Behavior: [describe]

    Actual Behavior: [describe]


    Vague bug reports will be ignored. Remember that I know more about programming than about Blender


    Known Issues:

    • Lane import/export (e.g. in station buildings) is not yet supported for TpF2.
    • DDS normal map import does not work because the image doesn't have 4 channels (or something). Some models will be exported without normal maps when the originals are DDS
    • DDS textures need to be flipped in Blender. I could not get the flip_image function within image_util.py to work like I expected (it was extremely slow and didn't actually change the way that the texture was applied to the model), so I instead flipped the UV mapping ( v = 1 - v ) on import if the texture is DDS. This means exported models can't just reference the stock textures (unless you flip the v coordinate back manually).
    • The import/export process changes textures a bit - I think that this may just be a result of Blender re-calculating normals (confirmed in TpF2 Model editor that import/export via this tool changes the normals)
    • Not compatible with Blender 2.80 or later (making it work with these versions would be way more work - you can try it yourself if you want to prove me wrong!)

    Feature Requests:


    I am unlikely to entertain these unless they seem like core features which I've overlooked, but anyone is welcome to advance the project themselves under CC-BY-NC-SA 2.0.

  • Hello


    Thx for your work i just testet it and found a bug and a suggestion:

    The format of the zip file is wrong. Blender expects for an automatic installation from a zip, what is a folder in the zip and then the plugin in this folder.


    As you thought about the textures, it doesn't make sense for a modder, you need the UVW flipped for export and if I have like 120 mesh on a steam locomotive then I don't feel like doing that by hand. I don't care that the textures are upside down, I don't need them.

    So please make a option to flip the UVW again during the export or include an option for the import so that the UVW does not flip during import.

    As it is now, I would not (want to) use the plugin.

  • Didn't yet time to test you changes.


    As you mentioned flip image, my local fork I touched last year uses this:

    Code: image_util.py
    def flip_image_fast(image):
        width = image.size[0]
        height = image.size[1]
        new_pixels = list()
        old_pixels = list(image.pixels[:])
        for i in range(height-1, -1, -1):
            new_pixels += old_pixels[4*i*width:4*(i+1)*width]
        image.pixels = new_pixels

    Not sure if it really is faster on all systems, technical with older blender versions the list function was faster in my tests.


    About dds textures, my fork converts the dds textures to tga while importing or using the tga texture if it's found.
    But the plugin constantly crashed on linux in the plugin system so I stopped development, not sure if this helps:




    The general idea was, that importing was only done once, and tga being the base. So it flips the temporary tga image. I guess this isn't the best for all modders but that it's how I tried to solve this problem :)

  • Schau mal in mesh_util.py Zeile 275, mit # auskommentieren sollte helfen:


    Python: mesh_util.py
                    if material_diffuse_texture and (material_diffuse_texture.name[-3:] == "dds" or ".dds." in material_diffuse_texture.name): # DDS images are flipped because reasons
                        uvmap[uv[0]].data[face_index].uv1.y = 1 - uvmap[uv[0]].data[face_index].uv1.y
                        uvmap[uv[0]].data[face_index].uv2.y = 1 - uvmap[uv[0]].data[face_index].uv2.y
                        uvmap[uv[0]].data[face_index].uv3.y = 1 - uvmap[uv[0]].data[face_index].uv3.y
  • The format of the zip file is wrong. Blender expects for an automatic installation from a zip, what is a folder in the zip and then the plugin in this folder.


    As you thought about the textures, it doesn't make sense for a modder, you need the UVW flipped for export and if I have like 120 mesh on a steam locomotive then I don't feel like doing that by hand. I don't care that the textures are upside down, I don't need them.

    So please make a option to flip the UVW again during the export or include an option for the import so that the UVW does not flip during import.

    As it is now, I would not (want to) use the plugin.

    Hi Maik,


    Thanks for the note about the .zip file. I think that I have fixed it.


    Regarding the textures, the plugin can export them for you too. So if you've prepared texture A.dds and you import it then the import will flip it, but when you export it will produce a new A.tga which is a flipped version of the original A.dds that you can keep working on... or, that's how I thought it worked.


    The idea of allowing un-flipping the uvs on export is a good one. I don't have much time to play with it right now but I think I might add something like that in future.

  • If I remember correctly, it just means that he cannot export + render the UI image because a texture cannot be found. Unfortunately he just do nothing then. But if you set "Textures" to "No textures" while exporting, the error does not appear, but no textures are exported either and no ui pic is created (which is usually not necessary anyway).

  • I finally got around to making a version 0.6.1 which incorporates a "Flip V Coordinate" option at export. V coordinates therefore work as follows:

    1. For .dds textures, the V coordinate is flipped automatically on import. For all other textures, the V coordinate in Blender matches that in Transport Fever 2
    2. When exporting, you have to manually set the "Flip V Coordinate" option. You should enable this if you imported a model with .DDS textures (like a stock model) and disable it otherwise

    This weird handling is necessary because:

    • DDS textures need to be flipped in Blender. I could not get the flip_image function within image_util.py to work like I expected (it was extremely slow and didn't actually change the way that the texture was applied to the model), so I instead flipped the UV mapping ( v = 1 - v ) on import if the texture is DDS.
  • I was working with version 0.6.1 and I noticed that Blender was always flipping the V coordinate on output, regardless of what I asked it to do. After a bit of digging, I've found that there seems to be a bug in version 0.6.1 - the wrong property is read at export and it always evaluates to "true" regardless of whether you've asked for V to be flipped. Version 0.6.2 (attached) fixes this bug.

BlueBrixx