thread of python hacks to make life easier

General discussion about TexGen.

Moderators: Martin, Developers

Post Reply
wr
Contributor
Posts: 35
Joined: Tue Aug 28, 2007 8:33 am
Location: Ringkoebing, DK

thread of python hacks to make life easier

Post by wr »

Dear forum viewers,

Why not post some of the things that make life with TexGen easier, I'll start, this script takes an archive (.tar) of tg3 files or a single tg3 and renders it to a png file, it's handy if you run loads of models and need pics from a consistent viewing angle:

Code: Select all

#! /usr/bin/env python2.5
from TexGen.Core import *
from TexGen.Renderer import *
import sys
import tarfile 
import os 

files = []

cleanup = False
for arg in sys.argv:
	if arg.endswith('.tg3'):
		files.append(arg)	
	if arg.endswith('.tar'):
		cleanup = True
		archive = tarfile.open(arg)
		files = []
		for i in archive:
			archive.extract(i)
		 	files.append(i.name)	
for file in files:
	print file
	ReadFromXML(file)
	textile = GetTextiles().values()[0]
	AddTextile(textile)
	renderer = CTexGenRenderer()
	renderer.RenderTextile()
	renderer.SetBackgroundColor(COLOR(255,255,255))
	renderer.ResetCamera(XYZ(-1,-1,-0.5))
	renderer.Start(False, 640*1,480*1)
	renderer.TakeScreenShot(file.replace('tg3','png'),4)
	if cleanup:
		os.remove(file)
	DeleteTextiles()
Cheers
W
Post Reply