1
$\begingroup$

I am currently working on a little script that takes a bunch of obj, imports them into blender with their textures, plugs the textures in the right places of the GLTF Metallic Roughness shader group, and then exports everything into GLTF.

I have arrived to the part where I have to add the GLTF Metallic Roughness Node. As those who use that plugin (https://github.com/KhronosGroup/glTF-Blender-Exporter) know, to access the node and plug your textures manually, you first have to link your blender scene to the GLTF2.blend scene, and especially to the pbr node tree and the Metallic Roughness group there.

I have tried a couple of things... First I tried this:

GLTF = matnodes.new(settings =[{"value" : "byp.data.node_groups['glTF Metallic Roughness']"}], type= "ShaderNodeGroup")

Yet Blender doesn't seem to like this and says that it expects only one argument for the function "matnodes.new()"...

So I have tried this:

GLTF = matnodes.new("ShaderNodeGroup")

There it spawns a gorup shader node, but it is empty and displaying ("Missing Data-Block"... On the menu dropdown, I have tried selecting "glTF Metallic Roughness", and it turns the node into the right node, but in the info console there's no command I can use... Basically I don't know how to do that in Python.

Does anyone have an idea :/?

I haven't put the entire code because I think the rest is kind of irrelevant but don't hesitate to ask if you want to see it.

Thank you all!

$\endgroup$
0
$\begingroup$

Find your node group:

group = bpy.data.node_groups.get('glTF Metallic Roughness')

Assign it to the node:

GLTF = matnodes.new("ShaderNodeGroup")
GLTF.node_tree = group
$\endgroup$
  • $\begingroup$ Hahaha stupid me I answered you by answering my own post! $\endgroup$ – Popi Aug 2 '18 at 8:37
  • $\begingroup$ Thank you so much, it works!! It was quite simple but I'm new to Python in Blender so there's a whole lot of things I don't know very well yet :) Thank you again! mae_lia $\endgroup$ – Popi Aug 2 '18 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.