Last active
August 29, 2015 14:03
-
-
Save jcxavier/a0f3396d40a222a18ac8 to your computer and use it in GitHub Desktop.
Extract images from particles exported by ParticleDesigner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gzip | |
import base64 | |
from xml.dom import minidom | |
import sys | |
import os | |
if len(sys.argv) != 2: | |
print "usage:", sys.argv[0], " <pex-file|plist-file>" | |
exit(1) | |
tmpfile = "___b64.gzip" | |
argfile = sys.argv[1]; | |
xmldoc = minidom.parse(argfile) | |
print "Parsing %s" % argfile | |
if argfile.endswith("pex"): | |
texture = xmldoc.getElementsByTagName('texture')[0] | |
texdata = texture.attributes['data'].value | |
imgname = texture.attributes['name'].value | |
elif argfile.endswith("plist"): | |
stringList = xmldoc.getElementsByTagName('string') | |
if (stringList.length == 1): | |
print "Particle is not embedded, nothing to do here" | |
exit(0) | |
firstString = stringList[0].childNodes[0].data; | |
secondString = stringList[1].childNodes[0].data; | |
if (firstString.endswith(".png")): | |
texdata = secondString | |
imgname = firstString | |
else: | |
texdata = firstString | |
imgname = secondString | |
else: | |
print "File type not supported" | |
exit(1) | |
decoded = base64.decodestring(texdata) | |
f = open(tmpfile, "w") | |
f.write(decoded) | |
f.close() | |
f=gzip.open(tmpfile,'rb') | |
file_content=f.read() | |
f.close() | |
os.remove(tmpfile) | |
f = open(imgname, "w") | |
f.write(file_content) | |
f.close() | |
print "New image: %s. Please check if the output file has the correct image file." % imgname | |
os.system("file %s" % imgname) | |
print "I have not removed the information from the 'data' tag in the original %s file. Don't forget to remove it manually." % argfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment