Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- import re
- import glob
- import os
- texture_list = []
- vmt_dir='C:/users/patrick/desktop/vmt/'
- png_dir='C:/users/patrick/desktop/materials/'
- qfiles = glob.glob(vmt_dir + "**/*.vmt", recursive=True)
- qfiles2 = glob.glob(png_dir + "**/*.png", recursive=True)
- q3 = glob.glob(vmt_dir + "**/*.vmt", recursive=True)
- for m in bpy.data.materials:
- for l in qfiles:
- if os.path.basename(l)[:-4] == os.path.basename(m.name):
- print('opening vmt: '+l)
- try:
- f=open(l, 'r')
- arr=f.readlines()
- f.close()
- for p in arr:
- try:
- texpath = re.search('basetexture"(.*)', p)
- g = texpath.group(1)
- print('g: '+g)
- try:
- texpath = re.search('"(.*)"', g)
- z = texpath.group(1)
- print('basetexture: '+z)
- m.name = os.path.basename(z)
- except:
- pass
- except:
- pass
- except:
- pass
- for m in bpy.data.materials:
- s = str(m.name).split('.')
- m.name = s[0]
- for q in qfiles2:
- try:
- zz = os.path.basename(q)[:-4]
- if zz == m.name:
- tex = bpy.data.textures.new(m.name, 'IMAGE')
- slot = m.texture_slots.add()
- slot.texture = tex
- img = bpy.data.images.load(q, check_existing=True)
- tex.image = img
- print(q)
- except:
- pass
- for m in bpy.data.materials:
- for q in q3:
- try:
- zz = os.path.basename(q)[:-4]
- if zz.lower() == m.name.lower():
- q = q[:-4]
- q = q+'.png'
- q = str(q).replace('vmt', 'materials')
- tex = bpy.data.textures.new(m.name, 'IMAGE')
- slot = m.texture_slots.add()
- slot.texture = tex
- img = bpy.data.images.load(q, check_existing=True)
- tex.image = img
- print(q)
- except:
- pass
- print('finished')
- for m in bpy.data.images:
- m.use_alpha = False
- for m in bpy.data.materials:
- m.use_shadeless = True
- for m in bpy.data.materials:
- m.texture_slots.clear(1)
- m.texture_slots.clear(2)
- m.texture_slots.clear(3)
- m.texture_slots.clear(4)
- m.texture_slots.clear(5)
- m.texture_slots.clear(6)
- m.texture_slots.clear(7)
- m.texture_slots.clear(8)
- m.texture_slots.clear(9)
- m.texture_slots.clear(10)
- m.texture_slots.clear(11)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement