I'm trying to import texture wrapped models into Unity 3D.
Unity needs to have the object name the same as the texture name for it to automatically assign the textures.
I'm trying to import texture wrapped models into Unity 3D.
Unity needs to have the object name the same as the texture name for it to automatically assign the textures.
this is for texture name assuming the texture is on the first material :
import bpy
C = bpy.context
D = bpy.data
objects = [obj for obj in D.objects if obj.type == 'MESH']
for obj in objects :
nodes = obj.material_slots[0].material.node_tree.nodes
tex_node = next((node for node in nodes if node.type == 'TEX_IMAGE'), None)
if tex_node :
img_name = tex_node.image.name
img_name = img_name.replace('.jpg','')
obj.name = img_name.replace('.png','')
incase its the material name :
import bpy
C = bpy.context
D = bpy.data
objects = [obj for obj in D.objects if obj.type == 'MESH']
for obj in objects :
obj.name = obj.material_slots[0].material.name
#obj.material_slots[0].material.name = obj.name #if it's the other way