1
$\begingroup$

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 setup:

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[0].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

$\endgroup$
  • $\begingroup$ The question needs to be clarified. It is completely unclear what you are trying to atchieve. You should explain the context, what you want to do and how, and what you have tried already and how it fails. What do you want to do with the UV coordinates? $\endgroup$ – Martynas Žiemys Oct 16 '18 at 17:29
  • $\begingroup$ Does the explanation look a bit more better. Something still missing? Thanks for comments $\endgroup$ – Mika Saari Oct 17 '18 at 13:06

Your Answer

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

Browse other questions tagged or ask your own question.