Jump to content

Batch texture path find replace.


GKM

Recommended Posts

Pyffi has a beautiful tool as part of it called niftoaster, that can do many things, the most useful being optimizing meshes (what Pyffi is famous for) and finding & replacing the texture path on an entire directory of meshes.

 

I needed something else, however. I had one mesh with many textures in several of my mods, so like Shirt.nif would be retexed to ShirtBlack.nif, ShirtYellow.nif and ShirtPink.nif etc. with the speedbuster mod in particular this became overwhelming (though perhaps I'm easily overwhelmed), so I wrote a script, after all I'm a better coder (at least in Python) than I am a modeler.

 

I don't know how useful this will be to people who don't know how to code, but I can try to clean it up. All configuration options are in the script.

 

set niftoaster to the path of python.exe and nifotaster.py

set ORIGIN_FILE to the original nif

set GROUND_MESH to the original ground mesh.

set TEX_FIND to the portion of texture path you want to find (and later replace).

set GROUND_FIND to the portion of the texture path you want to find for ground meshes.

set DESTDIR to location to move files to (something like package/meshes/armor/author/mod_name)

set MESHES to a list of pairs, each item represents a mesh, the first item in the pair is the name of the mesh (minus .nif, the ground mesh will be name_g.nif) and the second item is the name of the texture, if the name of the texture is the same as the name of the nif just put None.

 

so with the current settings:

ground.nif will be copied to DESTDIR/blacksport_g.nif and fancyblack in texture paths will be replaced with blacksport

purplebutterfly5.nif will be copied to DESTDIR/blacksport.nif and purplebutterfly will be replaced with blacksport.

ground.nif will be copied to DESTDIR/bluerain_g.nif and fancyblack in texture paths will be replaced with bluerainb

purplebutterfly5.nif will be copied to DESTDIR/bluerain.nif and purplebutterfly will be replaced with bluerainb

etc.

 

This script is released under a BSD License, so whatever you want with it.

 

 

#!/usr/bin/env python2

import subprocess
import shutil
import os, os.path, sys
import re
niftoaster = (r'C:\Python33\python.exe',r'C:\Python33\Scripts\niftoaster.py')

def tex_replace(filename, find, replace, sep='#'):
	find = re.escape(find)
	replace = re.escape(replace)
	subprocess.check_call(niftoaster + ('--noninteractive', '--overwrite', '-a',
                                            sep+find+sep+replace, 'modify_substitutetexturepath', filename))

DESTDIR=r'package\meshes\clothes\moreundies'

ORIGIN_FILE='purplebutterfly5.nif'
GROUND_MESH='ground.nif'

TEX_FIND = 'purplebutterfly'
GROUND_FIND='fancyblack'


MESHES=(
('blacksport',None),
('bluerain','bluerainb'),
('boringgrey','greybriefs'),
('fancyblack',None),
('fancywhite',None),
('multiflower','fmulti'),
('orangewhite',None),
('PinkCherry',None),
('pinkheart','pinkheart2'),
('pinkhearts1','pinkheart'),
('PinkStripe','pinkstripe'),
('plainwhtie','whitepanty'),
('pnkblack','pinkblack'),
('redblack','redblackl'),
('redflower',None),
('redsatin',None),
('snowflakes',None),
('springflowers','springf'),
('superman',None),
('tulips','floralprog'),
('tweety',None),
('urbancamo','urban'),
('whitebutterfly',None),
('whitered',None),
('woodlandcamo','woodland'))

if not os.path.exists('package'):
	os.makedirs(DESTDIR)

shutil.copy(ORIGIN_FILE, os.path.join(DESTDIR, ORIGIN_FILE))
shutil.copy(GROUND_MESH, os.path.join(DESTDIR, GROUND_MESH))

#gnd_file = os.path.join(DESTDIR,'purplebutterfly_g.nif')
#shutil.copy(GROUND_MESH, gnd_file)
#tex_replace(gnd_file, 'fancyblack', texture)

for mesh, texture in MESHES:
	texture = texture or mesh
	filename = os.path.join(DESTDIR,mesh) + '.nif'
	gnd_file = os.path.join(DESTDIR, mesh) + '_g.nif'
	
	shutil.copy(ORIGIN_FILE, filename)
	shutil.copy(GROUND_MESH, gnd_file)
	
	tex_replace(filename, TEX_FIND, texture)
	tex_replace(gnd_file, GROUND_FIND, texture)

 

 

 

Problems

  • Not very user-friendly, few configuration options (ground meshes on/off, what if 2 find/replaces need to be performed?)
  • Not very robust in terms of error-handling
  • slow... because it calls niftoaster on the command-line instead of importing pyffi and using the libs (though it would probably still be pretty slow)

 

Link to comment

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more information, see our Privacy Policy & Terms of Use