0

I have the following simple script that draws a cube and color it in red.

import bpy

Create a red material

newMat = bpy.data.materials.new(name = "Material") newMat.use_nodes = True nodes = newMat.node_tree.nodes material_output = nodes.get("Material Output") node_emission = nodes.new(type="ShaderNodeBsdfDiffuse") node_emission.inputs[0].default_value = (1,0,0,1) links = newMat.node_tree.links newLink = links.new(node_emission.outputs[0], material_output.inputs[0])

Create a cube and add the red material to it

bpy.ops.mesh.primitive_cube_add(location=[0,0,0], scale=[10,10,10]) bpy.context.object.data.materials.append(newMat)

When I export this to FBX with Path Mode = Copy and Embed Textures = True, I get an FBX that shows the uncolored cube; together with an error message in the console that says:

FBX export starting... 'Z:\\Workspace\\red-cube.fbx'
NO NODES!
export finished in 0.0000 sec.

I have read many other posts about the issue but being a novice in Blender I could not make much sense of them. It seems that the issue is related to "Principled BSDF" that is apparently missing from the above script.

How would I fix this script so that it exports both mesh and color?

  • No, nothing is missing from your material. You used a readymade Diffuse BSDF rather than the ultra-tuneable Principled BSDF, which is fine, however code wise IDK why you named it “node_emission” since it’s not an emission node. I am unfamiliar with the last operator that adds the material to the cube, and the FBX exporter at this level, so I don’t think I can say any more at the moment. – TheLabCat May 09 '22 at 09:12
  • https://blender.stackexchange.com/questions/57531/fbx-export-why-there-are-no-materials-or-textures – Duarte Farrajota Ramos May 09 '22 at 11:31

1 Answers1

0

I am no expert, but perhaps Blender cannot export materials as defined in my code.

My workaround is to apply colors using textures instead of generating the colors through Blender. So basically, I create a file "red.png" that contains a solid red square (e.g. in MS Paint) and apply it to the object.

import bpy

Create a red material from texture

newMat = bpy.data.materials.new(name="Material") newMat.use_nodes = True bsdf = newMat.node_tree.nodes["Principled BSDF"] texImage = newMat.node_tree.nodes.new('ShaderNodeTexImage') texImage.image = bpy.data.images.load("Z:/Workspace/textures/colors/red.png") newMat.node_tree.links.new(bsdf.inputs['Base Color'], texImage.outputs['Color'])

Create a cube and add the red material to it

bpy.ops.mesh.primitive_cube_add(location=[0,0,0], scale=[10,10,10]) bpy.context.object.data.materials.append(newMat)

Now I can export to FBX and the colors show fine.

This is not exactly a solution to the problem, but is good enough for me to work with.