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.