[REL] Blender rFactor2 Export Scripts

Discussion in 'Other' started by Traveller, Oct 8, 2023.

  1. Traveller

    Traveller Member

    Joined:
    Oct 7, 2010
    Messages:
    864
    Likes Received:
    490
    Update release, 9 March 2024
    Link to scripts for Blender 3.1.X to 3.6.X: io_rf2_gmt_release_240309.zip .

    Initial version 30 September 2023.
    Link to scripts for Blender 3.1.X to 3.6.X : io_rf2_gmt_release_230930.zip .

    Unzip and place the, "io_rf2_gmt_release", folder in your (Blender)\(version)\scripts\addons folder.


    Scripts for other versions of Blender not currently available.
     
    Last edited: Mar 10, 2024
    nonamenow, atomed, tuki and 5 others like this.
  2. Traveller

    Traveller Member

    Joined:
    Oct 7, 2010
    Messages:
    864
    Likes Received:
    490
    What began as a simple clean up and spot optimization job with the old scripts (https://forum.studio-397.com/index.php?threads/rfactor2-export-scripts-for-blender-2-80.68007/) in October 2021, became almost a complete re-write of them in 2022. The change in scope began after a voice conversation over Discord with dxp_rlong in December 2021. The ideas he presented as well as some working code he wrote were the catalyst to what is presented today. Thank you to dxp_rlong for his feedback, criticism, input and code contribution to the scripts over the years.


    A summary of the major changes and features follows:


    1. The big one. rF2_Export has been almost completely rewritten. Over 1100 lines of source code were removed. It went from ~1820 source lines down to ~700. The results are the following:

    a. The export should be faster. Blender's bmesh is no longer used as a base for export. Several superfluous copies of the mesh data made with the older scripts no longer take place. This should both speed up export and reduce memory usage.

    b. The vertices of quadrangles are re-referenced in the export. Instead of a quadrangle being split into two triangles with separate vertices (for a total of six vertices), it is now split into two triangles with shared vertices (for a total of four vertices). This means that meshes with quadrangles will result in smaller GMT's than meshes consisting of only triangles. For best results, work only in quadrangles. Mixed meshes of triangles and quadrangles will be exported, but the GMT's they create will be larger than quad-only meshes.

    c. Meshes containing polygons that are not triangles and quadrangles will not be exported. A pop-up message with the name of the mesh will be displayed as well as a message printed to the Console. Again, for best results, work in quadrangles in Blender.

    d. Edges marked "sharp" now correctly show up as sharp edges in the GMT via the use of the Blender API calc_normals_split() routine.

    e. Normal maps should now behave as expected in game.

    f. The textures of muted texture nodes will not be exported, unless they are required for the material being exported. The nodes of required textures will be unmuted as part of the export process.


    2. Under-the-hood, the code to create material Shader Node Trees has been simplified. Node tree creation code is now easier to write, read and maintain. Expect additional node trees to be added as time goes by. The ultimate goal is to have as close to WYSIWYG between Blender and rFactor2 as possible. This is before effects applied by the S397 Material Editor (https://docs.studio-397.com/developers-guide/development-tools/material-editor) are applied. For now, though, the shader node trees are mainly to pass texture file names to the GMT on export. The simplified code has resulted in the following:

    a. IBL shader node trees added. The simplification of the node tree creation code resulted in the addition of the IBL shader node trees into the scripts. The trees have the four UV channels referenced in the S397 documentation (https://docs.studio-397.com/develop...erence/shader-definitions/ibl-standard-shader) as separate nodes visible in the node tree. Current IBL shaders are:
    1. IBL Group/ L2IBLSTANDARD
    2. IBL Group/ L2IBLCARBODY
    3. IBL Group/ L2IBLGLASS

    b. The legacy shaders are:
    1. Diffuse Group/ L2DIFFUSET0
    2. Specular Group/ L2SPECULARMAPT0
    3. Bump Group/ L2BUMPT0
    4. Bump Group/ L2BUMPSPECMAPT0
    5. Bump Group/ L2BUMPCMAPSPECMAPT0
    6. Bump Group/ L2BUMPSPECMAPT0XT1
    7. Bump Group/ L2BUMPSPECMAPT0XT1ALT
    8. Bump Group/ L2BUMPSPECMAPT0LERPALLVERTEXALPHA
    9. Bump Group/ L2BUMPCMAPSPECMAPADDSPECULARREFLECTT0
    10. Cube Group/ L2CMAPT0
    11. Special Group/ L2CARBODYPAINTWITHDAMAGE
    12. Special Group/ L2WINDSCREENINSIDE
    13. Special Group/ L2WINDSCREENOUTSIDE
    14. Special Group/ L2GLASS


    3. ***The remnants of rF2_Shader_Stuff code used in the scripts was removed. Thus, rF2_Shader_Stuff has been completely removed. The remaining code from it that was still in use has been rolled into each material's Shader Node Tree creation code.


    4. ***UV layers have been moved to four individual UV nodes in each shader node tree named UV_A, UV_B, UV_C and UV_D. These match the UV names in the Studio 397 documentation.

    a. UV copy now copies layer for layer unless there are less than four source layers. In that case, the first layer will be copied to fill the the number to four. This is only an issue going from the Legacy shaders from the older scripts. Once the UV's are moved to the four UV nodes, all four UV nodes will be copied from node tree to node tree.


    5. ***The existing "Legacy" shader node trees now have the UV layers added to the node tree via the four UV nodes.


    6. Attempt to maintain texture names when switching between material shader node trees. Texture names will be placed in the new tree matching the function in the old tree as closely as possible. That is, normal map to normal map, specular map to specular map, etc. To be sure, though, verify all texture names are valid textures when changing materials.


    UI Section:

    The UI has undergone a big change. At the suggestion of dxp_rlong, most functions have been moved to the 3D Viewport and Shader Editor N-Panels. This keeps the mouse pointer close to what you are working on while accessing options. It is not nearly as disruptive as moving the pointer toward the upper left corner of the screen to access an option in the rFactor2 Menu. N-panels are available by either pressing "N" while the mouse pointer is inside the appropriate window, or by clicking the small arrow in the top right corner of the window.

    7. rFactor2 Menu. The rFactor2 Menu still remains, but its number of options has been reduced, and it is now dynamic. This is because almost all of the items listed have been moved to the N-Panels. The rFactor2 Menu is being kept for possible future addition of rF2 scene level utilities: SCN/GEN file exporter, CAM file exporter and any other utilities that may be written.

    a. rFactor2 Menu/ SCN and GEN check boxes. Selects which rFactor2 scene type to generate via Start New rFactor2 Scene or if the Auto-detect Scene check box is unchecked for Update Scene.

    b. ** rFactor2 Menu/ Start New rFactor2 Scene was Initiate Scene. This is a destructive procedure. Use Update Scene for a non-destructive version. Which type of scene started is set via the SCN/GEN choice.

    c. rFactor2 Menu/ Auto-detect Scene Type checkbox. Defaults to checked. If checked, update_scene() will set the rFactor2 scene type by size of objects in scene. The current check is if the absolute value of all X, Y and Z coordinates are less then 4.0 units. If not checked, the scene type will be determined by the SCN/GEN checkboxes.

    d. ** rFactor2 Menu/ Utilities/Update Scene. Will upgrade materials and UV's of objects in a scene if required. Progress, actions and results are printed to the console.

    e. rFactor2 Menu/ Utilities/Check Meshes. Counts the number of vertices for each face in every mesh in the scene. Reports which meshes have other than 3 or 4 vertices per face. Sets 3D Viewport/ rFactor2/ rF2 Mesh Properties/ Mesh Type based on result.


    8. 3D Viewport N-Panel: rFactor2 tab added to 3D Viewport N-panel. The rF2 tab is dynamic, with options based on items selected and the state of the scene. Options follow:

    a. ** 3D Viewport/Start New rFactor2 Scene, with SCN and GEN as button selections: one or the other. Available if scene is not yet set up in the rF2 SCN or GEN collections in the Outliner.

    b. 3D Viewport/Export GMT's: Available if only GMT(s) are selected in the Outliner.

    c. 3D Viewport/Add rF2 GMT: Available under multiple conditions. Adds a cube to the scene centered at 0, 0, 0.

    d. 3D Viewport/Show Smooth Groups/ Hide Smooth Groups: Available when a single mesh is selected in the Outliner.

    e. 3D Viewport/rF2 GMT Information: Information block moved from the Properties Panel. Will show information when a single GMT is selected in the Outliner.

    f. 3D Viewport/rF2 Mesh Information: Information block moved from the Properties Panel. Will show information when a single mesh or material is selected in the Outliner.

    g. 3D Viewport/RF2 Bone Settings: Currently disabled. For future use.

    h. 3D Viewport/rF2 Light Settings: Currently disabled. For future use.


    9. Shader Editor N-Panel: rFactor2 tab added to Node Editor N-panel. The rF2 tab is dynamic, with options based on items selected and the state of the scene. Options follow:

    a. ** Shader Editor/Start New rFactor2 Scene, with SCN and GEN as button selections: one or the other. Available if scene is not yet set up in the rF2 SCN or GEN collections in the Outliner.

    b. ** Shader Editor/Update Scene. Available if there is not "rFactor2" editor tab.

    c. Shader Editor/Material Info/ Replace Material: Available when a single selected mesh has an rF2 material associated with it. A value of "Invalid" means the rFactor2 Menu/Blend Update routine should be run on the scene. Replacement Materials are selected via drop-down menu of each major material type. More materials may be added later.

    d. Shader Editor/rF2 Material Info: Information block moved from the Properties Panel. Will show when a single mesh or material is selected in the Outliner.

    e. Shader Editor/rF2 Texture Info: Information block moved from the Properties Panel. Will show when a single texture node is selected in the node editor window.


    10. Vertex Colors and UV Layers still remain in the mesh properties panel.


    ** A planned addition is the setting up of a "rFactor2" editing tab. Can't get it working reliably enough to include in current version of the scripts. Can be set up manually.


    *** The changes above marked with three astericks require the run of update_scene(), a routine located in the rFactor2 Menu on .blends made from the old scripts. This will bring the overall scene, GMT's, meshes, materials, and textures in the old .blends up to the new standard. You should be able to work with and export the modified models with no issues.


    The scripts work with versions of Blender no earlier than 3.1.0 and are currently compiled with 3.6.2.
     
    DJCruicky, DiggerHawk, Mauro and 3 others like this.
  3. Traveller

    Traveller Member

    Joined:
    Oct 7, 2010
    Messages:
    864
    Likes Received:
    490
    2023 rFactor2 Export Scripts Tips

    -For best results run Update Scene on a fresh start of Blender.

    -Work in quadrangles for best results.

    -Check the flags in the named flags section of each element: GMT, mesh, material, texture. Do this instead of checking flags in the All Flags section of the element.

    -For car bodies, be sure to check the Live Mapping flag in the material section.

    -For transparent glass materials: 1) Check the Transparency flag in the material properties, 2) Select "Alpha" Transparency" as the Blend Type in the Blend Information section of the material properties.

    -Don't forget to fill in the Material Properties' Reflective field if needed, with "REFMAP0" et. al.
     
    Last edited: Oct 21, 2023
    DiggerHawk, Mauro, Corti and 2 others like this.
  4. Traveller

    Traveller Member

    Joined:
    Oct 7, 2010
    Messages:
    864
    Likes Received:
    490
    A car straight out of Blender with the current scripts. This is before using the material editor.
     

    Attached Files:

    DJCruicky, DiggerHawk, Mauro and 2 others like this.
  5. DiggerHawk

    DiggerHawk Registered

    Joined:
    Jul 29, 2020
    Messages:
    250
    Likes Received:
    315
    I have only just found this new thread, I was checking the old one for updates. I will download the latest Blender and give this new script a go. Thanks for your hard work.
     
  6. DiggerHawk

    DiggerHawk Registered

    Joined:
    Jul 29, 2020
    Messages:
    250
    Likes Received:
    315
    I am having a little issue with some of the GMT's exported using the plugin with Blender 3.6.5. If I load a race in rF2 (Devmode or Full) it is fine, but if I exit to the main menu and reload the session it will crash to the desktop at about 80-90%. I have narrowed down the issue to GMT's that are exported as Quads. It is not all of my meshes that have an issue but so far mainly but not only the Tires. Once I triangulate the faces they work perfectly. I have looked over the mesh and material attributes and compared them to a working quad mesh but I couldn't find anything that was different. I even created a new rF2 object and merged the old mesh into the new one, it still crashed. Its as if the geometry itself is not compatible although it is a simple mesh.

    As I said it all seems to work perfectly with Tri meshes but as you mentioned they create larger files.
    The normal maps work fully now which is great and the ability to setup the materials is good, although I am still using the JSON override files as it would be too much work going through all the materials. For a project created from scratch it would be beneficial though.

    Thank you for your hard work Traveller.
     
  7. Traveller

    Traveller Member

    Joined:
    Oct 7, 2010
    Messages:
    864
    Likes Received:
    490
    I have in the back of my mind, something about the GMT data being aligned to 64 bits. I cannot find it though, and I can't remember any details. It is possible I dreamed it. However, I'm thinking I read it on the old ISI forums, which explains why I can't find it. If anyone has a link to such info, please provide it.
     
  8. FuNK!

    FuNK! Registered

    Joined:
    May 26, 2013
    Messages:
    626
    Likes Received:
    491
    As far as I know there was a max number of vertices possible per GMT for the games based on older engine versions. The number was like 64000 vertices. Maybe that's what you remember too but confuse with the data limit? Just a wild guess :D
     
  9. gagipro

    gagipro Registered

    Joined:
    Feb 26, 2013
    Messages:
    473
    Likes Received:
    7
    using the official GMT exporter for max2021 here, tried this bender exporter module with Blender 4.0.1, at least it installs, export a GMT.
    Didn't test the GMT in a scene yet.

    Well done for this code update !

    EDIT : retried at home and cannot find anything in export in blender 4.0.1, I must have messed up on the other blender 4.0.1 at work that presented some rfactor tools and export features...
     
    Last edited: Nov 28, 2023
  10. EmperorOfFinland

    EmperorOfFinland Registered

    Joined:
    Jan 26, 2021
    Messages:
    502
    Likes Received:
    1,098
    Okay so the last thing that is required is to somehow be able to make animations on blender unless that is already possible? This would free us from using 3dsmax indie license for good.
     
    Garitt Gibsn likes this.
  11. Traveller

    Traveller Member

    Joined:
    Oct 7, 2010
    Messages:
    864
    Likes Received:
    490
    Concerning Blender 4.X and the scripts... In reading the weekly notes, Blender is undergoing some changes with the 4.X series of releases. Nodes are changing somewhat, for example. Because of the changes, I'm holding off matching the scripts for Blender 4.X until a long term release, which would be 4.2 or even 4.3. Also, I saw in a recent weekly update that they made the switch to Python 3.11. These scripts will fail to load with 3.11, as they are made with Python 3.10. If you want to use them with Blender 4.X, 4.0 might work. I did a quick load and test of the scripts' functions, and they did not immediately crash, so there's that.


    Update to the scripts, 9 March 2024 (link in first post of thread):

    1. In order to mitigate script crashes because of too many vertices in a GMT, I've added a check_gmts() routine, which will count the total number of vertices in a GMT and display a message and print a message to the console. The rFactor2 Menu/ Check Meshes item is now Check Geometry. It will check meshes for polygons with other than 3 or 4 vertices as in the past, and will now perform the GMT vertex count test as well. Both routines are called as part of the export process and will abort the export with the appropriate message(s). See screen shots below.

    2. In order to mitigate issues reported in DiggerHawk's post, I've put separate triangle only exports back in the scripts. It is now the default option on export. The option is exposed via the "Export Packed Quadrangles" option in the Export dialog, see screenshot below. Checking the "Export Packed Quadrangles" option in the Export dialog will export re-referenced vertices as done with the original release version of thes scripts. Export of separate triangles will be the default option unless and until the issue is resolved. You can still work in quadrangles or triangles and quadrangles in Blender.

    3. Car Camera File Generation. A new feature to the scripts is the writing of vehicle (GEN) camera files. This is the initial take, and only location, orientation, field of view, and clip distances are changeable via Blender. The locations of the Blender values are shown in the screenshot below. The long term plan is to open up all rFactor2 car CAM file values in the rFactor2 panel in the Blender 3D Viewport window. Changing values there will change corresponding values in Blender. Track (SCN) cameras are still in the future.
     

    Attached Files:

    FuNK!, Mauro and atomed like this.
  12. nonamenow

    nonamenow Registered

    Joined:
    May 3, 2017
    Messages:
    1,287
    Likes Received:
    570
    Have you taken the latest release down mate? I'm getting a 403. Original is fine.
     
  13. Leonardo1962

    Leonardo1962 Registered

    Joined:
    Feb 12, 2012
    Messages:
    247
    Likes Received:
    69
    me too: no access.

    but thanks for your not giving up :)
     
  14. Traveller

    Traveller Member

    Joined:
    Oct 7, 2010
    Messages:
    864
    Likes Received:
    490
  15. nonamenow

    nonamenow Registered

    Joined:
    May 3, 2017
    Messages:
    1,287
    Likes Received:
    570
    Fixed, thanks mate.
     
    Leonardo1962 likes this.
  16. Leonardo1962

    Leonardo1962 Registered

    Joined:
    Feb 12, 2012
    Messages:
    247
    Likes Received:
    69
    Thanks a lot traveller,

    download and install works fine.
    check meshes did also work. "UV MAP A..D" are generated.
    Export as gmt works, :) (but the export menu item is not shown up frequently)
    If have to learn to use this addon right.

    well done, great work :cool:
    View attachment upload_2024-3-29_9-20-48.png
     
  17. Traveller

    Traveller Member

    Joined:
    Oct 7, 2010
    Messages:
    864
    Likes Received:
    490
    The Export GMT menu item will show up if one or more GMT's are selected, and nothing else.
     

Share This Page