Advertisement
Guest User

Untitled

a guest
Mar 15th, 2018
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.71 KB | None | 0 0
  1. import bpy
  2. import re
  3. import glob
  4. import os
  5. texture_list = []
  6.  
  7. vmt_dir='C:/users/patrick/desktop/vmt/'
  8. png_dir='C:/users/patrick/desktop/materials/'
  9. qfiles = glob.glob(vmt_dir + "**/*.vmt", recursive=True)
  10. qfiles2 = glob.glob(png_dir + "**/*.png", recursive=True)
  11. q3 = glob.glob(vmt_dir + "**/*.vmt", recursive=True)
  12. for m in bpy.data.materials:
  13.     for l in qfiles:
  14.         if os.path.basename(l)[:-4] == os.path.basename(m.name):
  15.             print('opening vmt: '+l)
  16.             try:
  17.                 f=open(l, 'r')
  18.                 arr=f.readlines()
  19.                 f.close()
  20.                 for p in arr:
  21.                     try:
  22.                         texpath = re.search('basetexture"(.*)', p)
  23.                         g = texpath.group(1)
  24.                         print('g: '+g)
  25.                         try:
  26.                             texpath = re.search('"(.*)"', g)
  27.                             z = texpath.group(1)
  28.                             print('basetexture: '+z)
  29.                             m.name = os.path.basename(z)
  30.                         except:
  31.                             pass
  32.                     except:
  33.                         pass
  34.             except:
  35.                 pass
  36.  
  37.  
  38. for m in bpy.data.materials:
  39.     s = str(m.name).split('.')
  40.     m.name = s[0]
  41.     for q in qfiles2:
  42.         try:
  43.             zz = os.path.basename(q)[:-4]
  44.             if zz == m.name:
  45.                 tex = bpy.data.textures.new(m.name, 'IMAGE')
  46.                 slot = m.texture_slots.add()
  47.                 slot.texture = tex
  48.                 img = bpy.data.images.load(q, check_existing=True)
  49.                 tex.image = img
  50.                 print(q)
  51.         except:
  52.             pass
  53.  
  54. for m in bpy.data.materials:
  55.     for q in q3:
  56.         try:
  57.             zz = os.path.basename(q)[:-4]
  58.             if zz.lower() == m.name.lower():
  59.                 q = q[:-4]
  60.                 q = q+'.png'
  61.                 q = str(q).replace('vmt', 'materials')
  62.                 tex = bpy.data.textures.new(m.name, 'IMAGE')
  63.                 slot = m.texture_slots.add()
  64.                 slot.texture = tex
  65.                 img = bpy.data.images.load(q, check_existing=True)
  66.                 tex.image = img
  67.                 print(q)
  68.         except:
  69.             pass
  70. print('finished')
  71.  
  72. for m in bpy.data.images:
  73.     m.use_alpha = False
  74.    
  75. for m in bpy.data.materials:
  76.     m.use_shadeless = True
  77.    
  78. for m in bpy.data.materials:
  79.     m.texture_slots.clear(1)
  80.     m.texture_slots.clear(2)
  81.     m.texture_slots.clear(3)
  82.     m.texture_slots.clear(4)
  83.     m.texture_slots.clear(5)
  84.     m.texture_slots.clear(6)
  85.     m.texture_slots.clear(7)
  86.     m.texture_slots.clear(8)
  87.     m.texture_slots.clear(9)
  88.     m.texture_slots.clear(10)
  89.     m.texture_slots.clear(11)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement