0
$\begingroup$

The addon is used to export .x and .mdl files for use in Microsoft FSX and Lockheed Martin P3D flight simulators.

It is open-source, created and modified by various people over the years. There isn't anyone in that community to contact about fixing the problem.

This addon works in Blender 2.83 up to 2.93.9.

When trying to export in Blender 3.0 and above it throws the following error:

Python: Traceback (most recent call last):
  File "C:\Users\Khun_D\AppData\Roaming\Blender Foundation\Blender\3.1\scripts\addons\Blender2P3DFSX\ui_export.py", line 195, in execute
    Exporter.Export()
  File "C:\Users\Khun_D\AppData\Roaming\Blender Foundation\Blender\3.1\scripts\addons\Blender2P3DFSX\func_export.py", line 268, in Export
    Object.Write()
  File "C:\Users\Khun_D\AppData\Roaming\Blender Foundation\Blender\3.1\scripts\addons\Blender2P3DFSX\li_export.py", line 243, in Write
    self.__WriteMesh(Mesh)
  File "C:\Users\Khun_D\AppData\Roaming\Blender Foundation\Blender\3.1\scripts\addons\Blender2P3DFSX\li_export.py", line 371, in __WriteMesh
    self.__WriteMeshMaterials(Mesh=Mesh)
  File "C:\Users\Khun_D\AppData\Roaming\Blender Foundation\Blender\3.1\scripts\addons\Blender2P3DFSX\li_export.py", line 1044, in __WriteMeshMaterials
    WriteMaterial(self,self.Exporter, Material)
  File "C:\Users\Khun_D\AppData\Roaming\Blender Foundation\Blender\3.1\scripts\addons\Blender2P3DFSX\li_export.py", line 786, in WriteMaterial
    data = AnalyzeMaterial(self,Material)
  File "C:\Users\Khun_D\AppData\Roaming\Blender Foundation\Blender\3.1\scripts\addons\Blender2P3DFSX\li_export.py", line 675, in AnalyzeMaterial
    raise ExportError(msg)
Blender2P3DFSX.li_export.ExportError: EXPORT ERROR! Couldn't find the corresponding shader node for material <cube>. It should be a 'Specular BSDF' for specular material.

location: <unknown location>:-1

But, the shader node that can't be found has been created.

The 3.x version of Blender gives the node a name different from 2.93.9.

This is the node in 2.93.9: enter image description here

This is the Python Data Path for the node in 2.93.9: bpy.data.materials["cube"].node_tree.nodes["Specular"].name

This is the node in 3.1.2: enter image description here

This is the Python Data Path in 3.1.2: bpy.data.materials["cube"].node_tree.nodes["Specular BSDF"].name

The addon hasn't been changed since 2020.

I am a noob at this. What changes with the API in 3.0 have I missed that will let me get this addon working again?

Edit: added info based on comments.

The addon can be downloaded from: https://fsdeveloper.com/forum/resources/blender2p3d-fsx-toolset.251/

The download button is on the upper right side of the page.

On the left side below the name of the addon, there is a link to the wiki for it. One can get an idea of what the addon does and the two material workflows, specular or PBR. I am only working with the specular material, because the simulator I have doesn't use PBR textures.

The addon can be installed in Blender, but it won't export anything because it requires an installed SDK for the simulator. In order to install the SDK, the simulator must be installed. But, one can see the what it adds to the Object Properties tab "P3D/FSX Properties" and the Material Properties tab "P3D/FSX Material Params". In the Material Properties tab P3D/FSX Material Params if you select Specular Material it will create the shader nodes that I am using. The addon also adds a File Export option "DirectX for P3D/FSX(.x/.mdl)".

The error is only thrown for something created in 3.x. If I import a file textured in 2.9.x it exports it without problem.

Blender 2.93.9 is installed on my computer. I am using 3.0 and 3.1.2 from .zip files.

Looking at the file li_export.py, I saw I could uncomment lines 660 and 661 and print the shader nodes for the material to the system console.

From 3.1.2 for the default cube: When in the Material Properties tab I select Specular Material from P3D/FSX Material Params. This is the System Console output:

Deleting: Principled BSDF | BSDF_PRINCIPLED
New node of type 'ShaderNodeEeveeSpecular' created for material 'Material'.
New node of type 'ShaderNodeTexImage' created for material 'Material'.
New node of type 'ShaderNodeInvert' created for material 'Material'.
New node of type 'ShaderNodeTexImage' created for material 'Material'.
New node of type 'ShaderNodeTexImage' created for material 'Material'.
New node of type 'ShaderNodeNormalMap' created for material 'Material'.
New node of type 'ShaderNodeSeparateRGB' created for material 'Material'.
New node of type 'ShaderNodeCombineRGB' created for material 'Material'.
New node of type 'ShaderNodeMixRGB' created for material 'Material'.
New node of type 'ShaderNodeTexImage' created for material 'Material'.
New node of type 'ShaderNodeMapping' created for material 'Material'.
New node of type 'ShaderNodeTexImage' created for material 'Material'.
New node of type 'ShaderNodeMapping' created for material 'Material'.
New node of type 'ShaderNodeMixRGB' created for material 'Material'.
New node of type 'ShaderNodeUVMap' created for material 'Material'.
Switched to specular material.

When I try to export the cube, in addition to the Python traceback already shown further above, I get this node information:

Writing geometry information...
Progress: : [--------------------] 0.0%Node Material Output location(300.000000,300.000000)
Node Specular BSDF location(100.000000,250.000000)
Node diffuse location(-1000.000000,400.000000)
Node Invert location(-500.000000,200.000000)
Node specular location(-1000.000000,-100.000000)
Node emissive location(-1000.000000,-350.000000)
Node Normal Map location(-100.000000,-450.000000)
Node Separate RGB location(-700.000000,-550.000000)
Node Combine RGB location(-500.000000,-550.000000)
Node Mix Normals location(-300.000000,-550.000000)
Node normal location(-1000.000000,-600.000000)
Node Bump Scale location(-1300.000000,-600.000000)
Node Detail location(-1000.000000,150.000000)
Node Detail Scale location(-1300.000000,150.000000)
Node Detail Blend location(-500.000000,400.000000)
Node UV location(-2000.000000,0.000000)
EXPORT ERROR! Couldn't find the corresponding shader node for material <Material>. It should be a 'Specular BSDF' for specular material.

I have looked at the addon in VS Code. I tried to find the code creating and naming this Specular BSDF node, but I'm sure I've missed something important and don't know where else to look.

I have found on line 84-86 of environment.py:

elif mat.fsxm_material_mode == 'FSX':
    MaterialUtil.CreateSpecShader(mat)
    print("Switched to specular material.")

In func_material.py line 153:

#Create the specular BSDF shader node:
spec_shader_node = CreateNewNode(Material, 'ShaderNodeEeveeSpecular',location=(100,250))

The links for the node start on line 198.

In li_export.py the code related to the error, lines 663 - 674:

if Material.fsxm_material_mode == 'FSX':
    bsdf_node = Material.node_tree.nodes.get('Specular')
elif Material.fsxm_material_mode == 'PBR':
      bsdf_node = Material.node_tree.nodes.get('Principled BSDF')
if (bsdf_node == None):
    msg = "ERROR"
    if (Material.fsxm_material_mode == 'FSX'):
        msg = format("EXPORT ERROR! Couldn't find the corresponding shader node for material <%s>. It should be a 'Specular BSDF' for specular material."%Material.name)
    else:
        msg = format("EXPORT ERROR! Couldn't find the corresponding shader node for material <%s>. It should be a 'Principled BSDF' for PBR material."%Material.name)
    self.Exporter.log.log(msg,False,True)

Hacking around without a clue I changed line 664 in li_export.py to bsdf_node = Material.node_tree.nodes.get('Specular BSDF'). Then I could export the cube in 3.1.2. But, it won't export something created in 2.9.x.

The console output regarding the shader nodes for the 2.9 export try with my hack is:

Progress: : [--------------------] 0.0%Node Specular location(100.000000,250.000000)
Node diffuse location(-1000.000000,400.000000)
Node Invert location(-500.000000,200.000000)
Node specular location(-1000.000000,-100.000000)
Node emissive location(-1000.000000,-350.000000)
Node Normal Map location(-100.000000,-450.000000)
Node Separate RGB location(-700.000000,-550.000000)
Node Combine RGB location(-500.000000,-550.000000)
Node Mix Normals location(-300.000000,-550.000000)
Node normal location(-1000.000000,-600.000000)
Node Bump Scale location(-1300.000000,-600.000000)
Node Detail location(-1000.000000,150.000000)
Node Detail Scale location(-1300.000000,150.000000)
Node Detail Blend location(-500.000000,400.000000)
Node UV location(-2000.000000,0.000000)
Node Material Output location(300.000000,300.000000)
EXPORT ERROR! Couldn't find the corresponding shader node for material <trim_wheel>. It should be a 'Specular BSDF' for specular material.

Without the hack the ouput is almost the same, except it exports:

Progress: : [--------------------] 0.0%Node Specular location(100.000000,250.000000)
Node diffuse location(-1000.000000,400.000000)
Node Invert location(-500.000000,200.000000)
Node specular location(-1000.000000,-100.000000)
Node emissive location(-1000.000000,-350.000000)
Node Normal Map location(-100.000000,-450.000000)
Node Separate RGB location(-700.000000,-550.000000)
Node Combine RGB location(-500.000000,-550.000000)
Node Mix Normals location(-300.000000,-550.000000)
Node normal location(-1000.000000,-600.000000)
Node Bump Scale location(-1300.000000,-600.000000)
Node Detail location(-1000.000000,150.000000)
Node Detail Scale location(-1300.000000,150.000000)
Node Detail Blend location(-500.000000,400.000000)
Node UV location(-2000.000000,0.000000)
Node Material Output location(300.000000,300.000000)
Progress: : [####################] 100% DONE
Finished writing geometry information. Closing file.

I cannot understand how the shader node gets a different name in 3.x vs 2.93 as shown in the images near the top of this post.

$\endgroup$
4
  • 1
    $\begingroup$ +1 to what @DuarteFarrajotaRamos said. Specifically you need to look where this line of the traceback is telling you the error is occurring. File "C:\Users\Khun_D\AppData\Roaming\Blender Foundation\Blender\3.1\scripts\addons\Blender2P3DFSX\li_export.py", line 675, in AnalyzeMaterial raise ExportError(msg) Blender2P3DFSX.li_export.ExportError: EXPORT ERROR! Couldn't find the corresponding shader node for material <cube>. It should be a 'Specular BSDF' for specular material. $\endgroup$
    – Jakemoyo
    Commented May 16, 2022 at 12:10
  • 1
    $\begingroup$ Go to that location on your hard drive, open li_export.py in a text editor, go to line 675 and try to figure out what the code is getting from your blender project and what the code is expecting. $\endgroup$
    – Jakemoyo
    Commented May 16, 2022 at 12:12
  • 1
    $\begingroup$ In order to keep it compatible you could either modify the name assignment in CreateNewNode to still use Specular with explicit assignment of the name or use bpy.app.version in li_export.py to check what version of Blender is being run and decide whether to use Specular or Specular BSDF. $\endgroup$ Commented Nov 2, 2022 at 17:34
  • $\begingroup$ Thank you Robert. It will be a while before I can do anything about it, but I will give your idea a try. $\endgroup$
    – curious_1
    Commented Nov 4, 2022 at 0:16

1 Answer 1

1
$\begingroup$

I've got it working for me.

To get rid of the "can't find corresponding shader node" error, I added an or to the if statement on line 664 of li_export.py.

Originally it was:

if Material.fsxm_material_mode == 'FSX':
    bsdf_node = Material.node_tree.nodes.get('Specular')

I changed it to:

if Material.fsxm_material_mode == 'FSX':
    bsdf_node = Material.node_tree.nodes.get('Specular') or Material.node_tree.nodes.get('Specular BSDF')

Then 3.1.2 threw this error:

TypeError: Scene.frame_set(): error with argument 1, "frame" -  Function.frame expected an int type, not float

The 3.1 Python API release notes say that "Python 3.10 no longer implicitly converts floats to int's (issue linked). This means functions that previously accepted float typed values will raise a type error. Floating point arguments must now be explicitly converted to integers."

line 1396 of li_export.py was:

Frame = KeyFrame.co[0]

I changed it to:

Frame = int(KeyFrame.co[0])
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .