OBJ/MTL importing #432
-
Is there a way when importing an obj/mtl to add an NPR Diffuse node with the diffuse texture defined in the mtl as the Base texture? Currently all such imported meshes just use the default material with no texture and are thus broken. (I can't fix them by hand, there are too many materials in my use case). I'm willing to do this via scripting, but not too familiar with Blender's scripting API, also Malt being an addon seems to make it more complicated. For example I tried to first start by programmatically creating a new malt material for each selected object (like clicking "New" in the Malt Material settings for an object, and I see the code for it is this which I'm not sure how to replicate within the context of my script. Ideally I would solve this by this scripting approach, since I want to control other properties of that NPR Diffuse node as well or use other Nodes too (and unfortunately Node Groups are not supported in Malt yet so doing something fancier with them is out of the question). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
At import time, I don't think so, but you could setup Malt materials after the import. You need a manually created Malt node tree with an Image parameter node. import bpy
malt_node_tree = bpy.data.node_trees["Your Node Tree"]
image_key = malt_node_tree.nodes["Your Image Node"].inputs["image"].get_source_global_reference()
for material in imported_materials:
imported_image = material.node_tree.nodes["EEVEE auto-generated Image Node"].image
material.malt.shader_nodes = malt_node_tree
material.malt.parameters.override_from_parents[image_key].boolean = True
material.malt.parameters.textures[image_key].texture = imported_image |
Beta Was this translation helpful? Give feedback.
At import time, I don't think so, but you could setup Malt materials after the import.
You need a manually created Malt node tree with an Image parameter node.
Then in a script, you can assign that node tree to the auto-generated materials and set the images to match the auto-generated nodes in the native (ie. EEVEE/Cycles) material node trees.