Hi guys,
What is the fastest method to load a texture in Panda? For what i read, I guess TXO or DDS. Is this correct?
I read it is possible to include multiple textures (jpg or png) in a dds or txo file. Where can i find an example of how to read and apply each of these textures to a card for example?
I mean something similar to a simple texture replacement :
tex = loader.loadTexture('mytexture.jpg')
card.setTexture(tex)
Thank you very much!!
TXO is the fastest i have seen. i didn’t test DDS tho.
you can load TXO textures just like jpg or png using the loadTexture method.
creating the TXO is a bit less convenient. you can create them on the fly and have them cached by enabling the config file option for it.
you can also create a EGG file that uses your texture, then run egg2bam with -ctex and maybe -ctexq as parameters. egg2bam will then create a TXO along with the bam file.
i once wrote a small script of mine that crawls a path and all subdirectories and creates a TXO file for every image it found on the way.
from os.path import isfile,abspath,isdir, splitext
from os import listdir
from os import system
def genTxo(filepath):
tempfile = open("eggtxotemp.egg","w")
tempfile.write("<Texture> info {\n\t")
tempfile.write('"'+filepath+'"')
tempfile.write(" <Scalar> minfilter { linear_mipmap_linear }\n}\n<Group> {\n\t<VertexPool> vpool {\n\t<Vertex> 0 {\n\t-0.5 0.5 0\n\t<UV> { 0 1 }\n\t}")
tempfile.write("\n\t<Vertex> 1 {\n\t-0.5 -0.5 0\n\t<UV> { 0 0 }\n\t}\n\t<Vertex> 2 {\n\t0.5 -0.5 0\n\t<UV> { 1 0 }\n\t}\n\t<Vertex> 3 {\n\t0.5 0.5 0\n\t<UV> { 1 1 }")
tempfile.write("\n\t}\n\t}\n\t<Group> info {\n\t<Polygon> {\n\t\t<RGBA> { 1 1 1 1 }\n\t\t<TRef> { info }\n\t\t<VertexRef> { 0 1 2 3 <Ref> { vpool } }\n\t}\n\t}\n}")
tempfile.close()
system("egg2bam -txo -ctex eggtxotemp.egg -o eggtxotemp.bam")
#genTxo("./dot.png")
def scanSubDir(path):
print " entered dir," ,path
files = listdir(path)
#print files
for entry in files:
if isdir(path+"/"+entry):
print "scanning subdir", path+"/"+entry
scanSubDir(path+"/"+entry)
elif splitext(entry)[1].lower() in [".png",".jpg",".jpeg",".tif",".tiff"]:
print "found image",
if splitext(entry)[0]+".txo" in files:
print "skipping as it is present already"
else:
print "converting to txo",abspath(path+"/"+entry)
genTxo(abspath(path+"/"+entry))
basepath = abspath("./")
scanSubDir(basepath)
keep in mind. TXO files are a bit like BAM. they are not neccessarily compatible across panda versions. Oh and generating them at high quality takes quite some time.
but, they load fast!
Thank you Thomas!! and thanks again for the script.
In case i want to have more than one texture in the TXO file, what do i have to do? add more tags?
And then, how can i reference the different textures when i call loadTexture()?
Thanks.