Difference between revisions of "Blender2P3D/FSX"
|Line 11:||Line 11:|
| FS2020 = unknown
| FS2020 = unknown
| FSXI = false
| FSXI = false
| P3D4 = true
| P3D4 = true
| P3D3 = true
| P3D3 = true
Latest revision as of 18:15, 29 June 2020
The Blender2P3D/FSX toolset is an addon for Blender. This addon is a continuation of the Blender2FSX Toolset manual and it incorporates compatibility with the latest API for Blender version 2.8x and above. The new toolset also features full support of PBR materials for Lockheed Martin's Prepar3D v4.4 and above, as well as some changes to the interface and file structure of the addon. This wiki will help you install and use the new toolset.
- 1 Installation
- 2 Using the Tools
- 2.1 Overview
- 2.2 Setting up your scene
- 2.3 Scenery properties
- 2.4 Animations
- 2.5 Attachpoints
- 2.6 Material parameters
- 3 Exporting to .X/.MDL
- 4 Credits and license
- Windows 10 or 8.x
- Microsoft Flight Simulator X SDK including updates to SP2 or Acceleration or
- Lockheed Martin Prepar3D SDK v1.x, v2.x, v3.x, & v4.x
- Blender (version: v2.8 or above)
After downloading the addon, open Blender 2.8x and open the Preferences (Edit->Preferences). Navigate to the "Add-ons" tab and click on "Install...". In the file manager, navigate to the Blender2P3DFSX.zip file, select it and click on "Install Add-on". This will extract the content of the zip file to your Blender script folder (by default under: %APPDATA%\Blender Foundation\Blender\<version number>\scripts\addons). Next, you need to activate the addon by clicking on the check-mark next to "3DView: P3D/FSX Toolset". That should enable the addon and the various panels and properties. Close the Preferences window.
To ensure that the addon was correctly installed, press "N" on your keyboard while the mouse pointer is in one of the main viewports. This should open the main panels of the addon under the tab named "P3D/FSX".
Using the Tools
Once installed, the Blender2P3D/FSX toolset will append the list of toolkit panels in your viewport. Press "N" to open or close the list of tools. There will be a new entry named "P3D/FSX", which gives access to the tools of this addon. The different tools are organized in different panels, which are grouped by function. The addon adds object properties to the scene. These properties are for instance the references to the various SDKs you can utilize or object properties like attached animations or scenery properties. Furthermore, the addon will append the material parameters by P3D or FSX specific parameters. Lastly, the addon extends the exporter capabilities and allows you to export your scene to an x-file format and from there calls XToMdl.exe to generate a Prapar3D/Flight Simulator X compatible 3d model.
Setting up your scene
To ensure that your 3d asset export properly to Prepar3D or Flight Simulator X, you must make sure to prepare and configure the Blender scene. To get started, open the toolset panels by pressing "N" on your keyboard with the main viewport being in focus. This will open a list of panel you have currently activated in your Blender configuration. Click on the tab "P3D/FSX" to bring up the panels of the Blender2P3D/FSX toolset.
Configure the SDK
Firstly, go to the P3D/FSX Toolset Settings and select which SDK you would like to utilize. If "Auto Detect SDK path" is enabled, simply click on "Initialize the SDK". The addon will then lookup the file paths of the SDK in the Windows registry. This method should work in 99% of the cases, however if the Addon cannot find the file paths, you can also use the Manually Find ModelDef file option to set up the path. Please note that it is necessary to initialize the SDK every time you restart Blender, or load a new scene. This way you ensure that all entries of the modeldef.xml are properly loaded into Blender.
Configure the scene
In order for your 3d asset to export properly, you have to ensure that both a GUID and a friendly name are assigned to your scene. To do so, open the P3D/FSX File Properties panel and type the friendly name in the first edit box. You can use the button Generate GUID to automatically generate a valid GUID for your scene. Alternatively, you can generate the GUID externally and copy and paste the string into the GUID edit box.
[feel free to enter the information here.]
With the latest update of the toolkit you'll be able to quicksave the location data of your scene. To do so, go to the Load/Save scenery data section, enter a location name and click on Add Location. This will save all settings of latitude, longitude, etc. into a XML file on your hard drive. To recall any of those previously saved datasets, click on Load Location, to open a list of names of previously saved locations. Select the location you wish to load and click on LOAD. This will populate all fields of the Scenery Tools with those from the XML file.
Note that there is currently no interface to remove entries from the list. But if you'd like to edit or update your quick-save list, you can find the XML file in the following location: %APPDATA%\Blender Foundation\Blender\<version number>\config\p3d_locations.xml
The addon will try to load the XML file whenever you initialize the SDK (see [Setting up your scene]). There will be a warning message in the system console of Blender if the file wasn't found on your harddrive. You can safely ignore this warning if you don't use this feature of the toolset.
To register an animation for a P3D/FSX asset, open the P3D/FSX Animation Tool panel. You will be presented with a list of animations, as found in the modeldef.xml file. To assign an animation to a selected object, choose it from the list and click on Assign. You can use the search function to filter the list for certain keywords, click on the little arrow on the bottom of the list to expose the search bar.
Once an animation has been assigned, make sure to enter an animation length in the object's properties as well. Open the objects properties panel and scroll to the P3D/FSX Properties section. Here, you'll find the properties of the attached animation as well as a list of all utilized attachpoints for that object.
You can also delete an animation by clicking on the Clear button.
Open the Attach Tool to access the various options for attachpoints. You can activate or deactivate a number of different functions by clicking on the corresponding buttons in the list. The buttons turn blue when active. Don't forget to assign the selected attachpoint and its parameters to an object by selecting the object in the scene and clicking on Attach on the bottom of the panel. To see what attachpoints are active for any given object in the scene, select the object and open the object properties. Under P3D/FSX Properties, you'll find a list of all attachpoints under the animation properties for the selected object.
To attach an effect to an object in your scene, click on the Effect button in the P3D/FSX Attach Tool panel. This will extend the panel and allow you to specify the parameters of the effect you'd like to attach.
- Name: set an attachpoint name for the object.
- Effect: type the filename of the effect you would like to attach to the object.
- Param: define paramters for the effect. Those can be, for instance, conditions for the effect to trigger. Refer to the P3D/FSX SDK for more information on valid syntax for this field.
Add a visibility tag to the selected object by clicking on Visibility on the P3D/FSX Attach Tool panel. This will open a list of available visibility tags, which you can attach to a selected object in the scene using the "Attach" button.
To add a mouserect to the selected object in the scene, click on Mouse Rect. This will reveal a dropdown list of all available mouse rects, as defined in the modeldef.xml file.
You can define an object as a "platform" by activating Platform in the P3D/FSX Attach Tool panel. Make sure to select a surface property for the platform in the dropdown list.
Enable the no crash flag for the selected object in the scene by clicking on No Crash in the P3D/FSX Attach Tool panel.
You can also attach an empty attachpoint to an object in the scene by clicking on Empty in the P3D/FSX Attach Tool panel. This will enable you to assign a name for the attachpoint. These empty attachpoints can be used for instance to create the various equipment for aircraft carriers. Simply assign one of the keywords to the object to trigger the wanted behavior of the object. Valid names are:
The P3D/FSX Blender toolset will extend the material properties to include flight simulator specific parameters. Make sure to carefully go through the list of properties to make sure that your material is ready for export. The most fundamental parameter is the main material mode. You can choose between "PBR Material", "Specular Material" and "Disabled". Note that any material with the mode being set to "disabled" will be skipped during the export process. Also note that the PBR material is only available for models used in Prepar3D version 4.4 or higher. Therefore, if you are preparing a model for FSX or older versions of Prepar3d, make sure to have the material mode set to the Specular workflow.
The P3D/FSX Blender toolset is making use of Blender's node tree and as a result it is important that your materials comply with the conventions of the addon's exporter. Whenever you change between different material modes, a script will automatically replace the current node tree with one that is compatible with the chosen material mode. This means that currently you will have to re-assign all textures every time you change the material mode!
Version 0.98.21 introduces an easier way to assign your textures to the materials. Directly under the material mode selection, you'll find a list of available texture slots which you can use to populate the node tree. The different texture slots are directly linked with the node tree so that all textures assigned in the material ui will be passed on to the appropriate texture node.
When assigning a new texture to any of the slots, a script will check if the texture is of the DDS format and if so, set up the node tree with a WYSIWYG representation of the simulator's shader. To do this, the addon will perform these two steps: 1. vertically flipping the uv for the texture node 2. reversing the red-in-alpha action for the normal map, meaning you can input a P3D/FSX conform normal map and it'll show up correctly in Blender.
The new material handling also incorporates the detail map in the node tree and synchronizes the scaling of the detail map with the settings made in the Blender2P3D/FSX material panel.
When exporting your scene, the exporter will run an analysis on all materials to extract the texture information. This is done in two ways, by checking what texture nodes connect to the relevant input nodes and by looking for specific node names. This way, it is possible to modify the node tree in Blender while retaining the ability to export the materials properly. The texture paths are searched for in the following manner: 1. Check if the (new) texture slots in the material panel are populated and use those if found. 2. If not, check the relevant input socket of the BSDF Principled shader node 3. follow all the links from that node and create a list of texture image nodes 4. if there are more than one texture image nodes directly or indirectly connected to the input socket, check the name of both and see if it matches 5. if there are NO texture image nodes connected to the input socket, search through ALL the texture image nodes of the graph, check if the name matches.
On creation of the node tree, the texture image nodes will be given their corresponding names. Those are: "diffuse" for the diffuse/albedo texture "specular" for the specular texture "metallic" for the metallic/smoothness/ao texture "emissive" for the emissive/lightmap texture "normal" for the normal/bump map texture
I suggest not to delete any of those texture nodes, in case you'll need them at a later stage. If you don't want a certain texture map to show up on your model, just disconnect the corresponding link.
By default, the emissive image texture is not connected to anything. If you want to see the effects of your lightmap on the model in Blender, simply link the texture node with the input socket labeled "Emission"/"Emissive Color". Note that the emissive map doesn't have to be linked with the base shader node in order for the lightmap texture being found by the exporter!
PBR Material mode
When you switch to the PBR Material mode, the node tree will be populated with a "BSDF Principled" node and a number of nodes that are linked up with the principled's input sockets. You can revise the material at any point by removing nodes or links. You can also add logic blocks between existing links and observe the effects in the viewport. Keep in mind however, that those type of changes will have no effect on the model when you export it to Prepar3D.
The Albedo/Diffuse map uses the "Base Color" input socket of the BSDF Principled node. By default, the Alpha channel of the texture node is linked with the Alpha input socket of the BSDF node. For all opaque materials this should have no effect, but for transparent materials it is important that the link remains.
It is possible to modify the node tree to display the Ambient Occlusion channel of the metallic texture. To do that, add a "MixRGB" node to the node tree and switch the blend mode to "multiply". Next, connect the Color channel from the albedo texture node to input Color1 of the mixRGB node, and connect the green channel ("G") from the "separate RGB" node of the metallic node to the Color2 input of the mixRGB node. Lastly, connect the output of the mixRGB node to the Base Color input of the BSDF Principled Shader node.
Make sure to disable Ambient occlusion in the scene render settings to not over-saturate the shading.
The metallic texture consists of three channels. The red channel represents the "metallicness" of the material, the alpha channel the "smoothness" and the green channel can contain an ambient occlusion map. Since Blender is using "roughness" rather than "smoothness", it is necessary to invert the alpha channel of the metallic texture before plugging it into the BSDF Principled node. This is already done for you when you set up the material for PBR.
Please note that the color space of the metallic node should be changed to "non-color", once you assigned a texture to the node.
By default, the AO map is omitted, see above if you want to display it in your scene.
Note that for Prepar3Dv5, you can provide a reflection map in the blue channel of the metallic map, however this channel won't be displayed in Blender. If you use the reflective channel, make sure to tick the "Metallic map has reflection" in the Metallic properties of the material.
Specular Material mode
If you select "Specular Material" as the P3D/FSX material mode, the current node tree is removed and replaced. The main shader node will now be an "Eevee Specular" node. The node tree will be populated in a way that most closely represents the shader mechanics of FSX/P3D and all you need to do is adding your texture files to the various texture image nodes. As with the PBR node tree, you can modify the Specular node tree in any way you wish - as long as the original Texture image nodes and the Eevee Specular node remain, the exporter will be able to pick up the correct texture paths.
Please note that since it is a node specifically designed for the Eevee render engine, material created in this way won't render properly if you switch the viewport render mode to "Cycles".
Normal maps for PBR and Specular material
[NEW] Prepar3D and FSX use a non-standard approach to rendering normal maps and we took the approach on board when developing the node tree for the P3D/FSX material. If you're using non-DDS files (.PSD, .tga, .png, etc), the shader is set up in a industry standard way, with the color node of the normal texture node being plugged in directly to the normal map node of the graph. However, if you're using DDS files, the addon will change the node tree in a way that reflects the sim as closely as possible by reversing the mandatory red-in-alpha.
Please note that the color space of the normal map will now automatically be changed to "non-color", once you assigned a texture to the normal map slot.
Oppose to P3D, Blender is using a global reflection map in conjunction with reflective materials. Depending on your requirements, it might be necessary for you to utilize different reflection maps for different materials. To accommodate this, you can link any reflection map to any material, using the Parameter "Reflection map" under the P3D/FSX material properties. However, any change to the file or file-path will not change anything about how reflections are presented in Blender. If you would like to get an idea of how your reflection map works with your other material settings, you can manually change Blender's global reflection map. To do so, open the "World Properties" and under "Surface->Color", select "Environment Texture" as a new source for the world reflection map and navigate to your texture. Don't forget to change the render mode to "Viewport Shading". Please note that changes to the world properties won't be taken into account when exporting your model to .X or .MDL.
If you're working with PBR material, switching your material to transparent is simple. In the P3D/FSX material settings change the "Render mode" to "Masked". The transparency value is taken from the Alpha channel of the Albedo texture node and will be visualized in the viewport. Note that switching from "Opaque" to "Masked" will also enable Backface culling by default, this is simply done for your convenience, but you can switch it off at any time with no effect to the P3D/FSX model itself.
Transparency for Specular material is currently not automated in this way, so any changes to the "Framebuffer Blend" properties of the material will have no effect on how the model is displayed in Blender. These values are, however, taken into consideration when you export your model and should work as expected.
Exporting to .X/.MDL
An essential element of the Blender2P3D/FSX toolset is the ability to export a Blender scene directly into the .mdl format. You can access the exporter by clicking on File->Export->DirectX for P3D/FSX (.X/.MDL). This will open the export dialog. On the right side of the window you can choose various options for the export. Don't forget to enter a valid filename on the bottom of the screen before pressing "Export P3D/FSX .X file".
Note: I recommend opening the Blender console before starting the export process. At the moment the exporter won't give you any visual feedback whether it's running or not, so checking on the console helps to make sure that everything is working smoothly. The console can be accessed through Window->Toggle System Console.
Export only current selection
If this option is active, only the elements of your scene that are currently selected will be exported. This can be useful if you want to quickly check certain parts of the scene, without exporting everything at once.
Apply all modifiers
If this option is selected, every object in the scene will have their modifiers applied before being encoded into the .X file. It is important to have this option enabled, otherwise your model might not be displayed correctly in the sim.
Export animations and LOD
To make sure that the animations and LODs are being exported, this option should be enabled.
If there are any skinned meshes in you scene, make sure to enable this option. Otherwise the skinned mesh animations are being omitted.
If this option is selected, the exporter will automatically call the XToMdl.exe converter once the .x file is written. Enable this option to export directly into the Prapar3D/FSX compatible 3d model format.
Create XML Scenery placement for this MDL
If this option is selected, the exporter will create an XML file which has all the scenery export information such as coordinates (latitude, longitude, altitude, pitch, bank, heading) and the scenery complexity of the scenery objects/model to be exported (by default Scenery Complexity = Normal). Then, it will convert the created .MDL format file into .BGL format file which then can be used directly in the simulator.
Create Sample XML Scenery Placement
If this option is selected, the exporter will create a SAMPLE XML file to show the developer how the scenery xml file should be written. Remember to only select this option if you wish to create the .BGL file manually/by your own.
If this option is checked, a log file will be generated in the same folder you export your scene to. The log file is a simple text file with the friendly name of the model [ex. Hangar_(date)_(time)_log.txt]. It can contain valuable information on the export progress if something goes wrong.
If selected, all texture filenames will be changed to <filename>.bmp.
The exporter will generate an .X file and - if selected - a .xanim file, which will hold the geometric information of your model, as well as the specs of your materials. Some of the properties of the model will be taken directly from the Blender scene, whereas some properties come from the custom properties that the Blender2P3D/FSX addon adds to objects and materials.
The following list describes the operation of the exporter step-by-step.
- Collecting object Information
The exporter will first go through the hierarchy of the scene and generate a list of exportable objects. Those objects are: meshes, bones and empty object if they have anything attached to it. The exporter will also check if the SDK was initialized, a modeldef.xml was found and if the scene contains a valid GUID and friendly name. If "Export Animations" was enabled in the export dialog, a list will be generated that contains information on every part that has an animation tag assigned to it.
- Writing the header
The header of the .x file contains templates for mesh and material information. Since P3D and FSX models differ slightly, the templates are being written depending on the selected SDK.
- Outline of the scene's hierarchy
The exporter will write a quick outline of the scene's objects into the .X file. This outline has no function, but is informative to any one who needs to debug any errors during the export.
- Writing scene information
Next, the exporter will go through the list of eligible objects and encode the geometric information. This includes the position of the vertices, a list of polygons, mesh normals for each vertex, and UV coordinates.
- Analyzing mesh materials
For each material, the exporter will analise the node tree to find the relevant image texture nodes. If a image texture node cannot be found, or if the filename is empty, the corresponding texture type will be skipped by the exporter.
- Writing mesh material
Once all data is collected, the material properties are being encoded in the .x file.
- Analyzing mesh materials
- Writing Animations
If "Export animations and LODs" has been selected in the exporter window, a .xanim file is being generated, which contains the animation data for all animated objects.
- Converting to MDL
If "Export MDL" has been selected in the exporter window, the exporter will execute the XToMdl.exe of the selected SDK. The Blender system console will show the progress during this step of the export, however note that the output is currently not logged in the log file that is generated by the exporter. If there is an issue with the .X file, or if the XToMdl.exe couldn't be found, an error will be shown in the Blender window.
- Export BGL
BGL is a scenery file format that is being used in Flight Simulator. If "Create XML Scenery placement for this MDL" has been selected in the exporter window, the created .MDL format file will run through an application called bglcomp [which is an in-build application comes with the Software Development (Kit)] to create the Flight Simulator use .BGL format file. This BGL format file can be used directly in the simulator later.
If the export was successful, you'll find the .X and the .MDL file in the selected folder, ready to be imported into P3D/FSX.
Please note that the exporter currently does not optimize your model! If you want to improve on the performance of your 3d asset, it is recommended to join all parts that share a material but don't have an animation or attachpoint assigned to it. Also note that the export process takes a long time to complete, please have the system console open to check up on the progress of the export.
Credits and license
The addon in its current version is the hard work of many members of the fsdeveloper.com forum. The original FSX2Blender addon was developed by: Felix Owono-Ateba, Ron Haertel, Kris Pyatt (2017) and Manochvarma Raman (2018) This current incarnation of the addon uses most of the original algorithms, but with an updated UI and compatibility for Blender 2.8x. Parts of the original exporter script have been re-written to accommodate Blender's new material workflow and to add PBR support to the addon (P3D v4.4+ only). This work was done 2019/2020 by Otmar Nitsche. Further additions to the material workflow were added by David Hoeffgen in 2020.
The software is licensed under GNU General Public License (GNU-GPL-3). Feel free to use it as you see fit, both for freeware and commercial projects. If you have suggestions for changes, use the support thread in the forum. If you would like to get involved in the development of the addon, contact any of the authors mentioned above to coordinate the effort.