0
$\begingroup$

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.

$\endgroup$
2
  • 2
    $\begingroup$ Sounds like a bit of python is in order $\endgroup$
    – gandalf3
    Commented Mar 14, 2015 at 7:02
  • 1
    $\begingroup$ Does this answer provide enough info or do you need more specific help? $\endgroup$
    – sambler
    Commented Mar 14, 2015 at 13:23

1 Answer 1

2
$\begingroup$

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
$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .