Question: How to access UV coordinate data through specific material in Blender 2.8 when using material nodes?
Detailed explanation: When creating custom export addon for Blender, I would like to access objects UV data through material node tree which has been wrapped with bpy_extra function PrincipledBSDFWrapper. I would like to get the name of the UVMap from materials so I would be able to access that specific UVMap data from object.
Object Cube has material which do have Principled BSDF node, Image Texture node (connected to Base Color of BSDF node) and UV Map node (concected to Vector of Image Texture node). In "UV Editing" tab I can see the texture UV mapped correctly on the Cube.
Example code for accessing wrapped material:
This code can be used to access material node data through Blender scripting console. The mat_wrap does have wrapped data of material node (as far as I have understood). myimg gives access to image which is linked to the Principle BSDF node.
from bpy_extras import node_shader_utils mat = bpy.data.objects['Cube'].material_slots.material mat_wrap = node_shader_utils.PrincipledBSDFWrapper(mat) myimg = mat_wrap.diffuse_texture.image
How to get the name of the "UVMap" from mat_wrap structure ? If I have understood correctly, I can then access the UV data of the object with this name through object->mesh->uv_layers.
What I have tested already I have access to the wrapped material like in the code above and I have tried to go through all different properties of the diffuse_texture and image variables. Haven't found the name of the objects UVMap which is connected in material node editor to Images Vector property.
Thanks a lot, -Mika