|
|
|
|
|
import sys |
|
import os |
|
import subprocess |
|
import json |
|
|
|
ELEMENTS = ["isBayCedarA1", "isCoral", "isGardeniaA", "isIronwoodA1", "isLavaRocks", "isNaupakaA", |
|
"isPandanusA", "isBeach", "isDunesA", "isHibiscus", "isIronwoodB", "isMountainA", "isPalmDead", |
|
"osOcean", "isCoastline", "isDunesB", "isHibiscusYoung", "isKava", "isMountainB", "isPalmRig"] |
|
|
|
|
|
def readJsonFile(jsonFile): |
|
""" |
|
Wrapper script to import json file as dict. |
|
:param jsonFile: file as string |
|
:return: dict |
|
""" |
|
with open(os.path.abspath(jsonFile), "r") as jf: |
|
jsonDict = json.load(jf) |
|
return jsonDict if jsonDict else {} |
|
|
|
|
|
def getFileSize(objFile): |
|
if os.path.isfile(objFile): |
|
fileStat = os.stat(objFile) |
|
val = fileStat.st_size |
|
for x in ['b', 'KB', 'MB', 'GB']: |
|
if val < 1024.0: |
|
return "%3.1f %s" % (val, x) |
|
val /= 1024.0 |
|
|
|
def getFaceCount(objFile): |
|
|
|
cmd = ["grep", "^f ",objFile] |
|
ps = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
|
output = subprocess.check_output(['wc'], stdin=ps.stdout) |
|
ps.wait() |
|
return output.split()[0] |
|
|
|
|
|
def printPrimitiveInfo(primitive, pDict): |
|
global jsonDir |
|
global element |
|
if pDict["type"] == "archive": |
|
primDict = readJsonFile(os.path.join(jsonDir, element + "_" + primitive + ".json")) |
|
for archive, instances in primDict.iteritems(): |
|
faceCount = getFaceCount(archive) |
|
fileSize = getFileSize(archive) |
|
print '\t'.join([primitive, "primitive archive", archive, fileSize, str(faceCount), "", "", str(len(instances)) ]) |
|
elif pDict["type"] == "curve": |
|
curveDict = readJsonFile(os.path.join(jsonDir, element + "_" + primitive + ".json")) |
|
print '\t'.join([primitive, "primitive curve", "", "", "", str(len(curveDict))]) |
|
elif pDict["type"] == "element": |
|
variantDict = readJsonFile(os.path.join(jsonDir, element + "_" + primitive + ".json")) |
|
for var in pDict["variants"]: |
|
instances = len(variantDict[var]) |
|
print '\t'.join([primitive, "primitive element", "See file info under %s %s" % (pDict["element"], var),"","","", str(instances)]) |
|
|
|
|
|
|
|
def main(): |
|
global jsonDir |
|
global element |
|
|
|
if len(sys.argv) == 1: |
|
print "Please provide element to examine, i.e. isBeach" |
|
return 0 |
|
element = sys.argv[1] |
|
|
|
if element not in ELEMENTS: |
|
print "Please provide a valid element." |
|
return |
|
|
|
jsonDir = os.path.join(os.path.abspath("json"), element) |
|
objDir = os.path.join(os.path.abspath("obj"), element) |
|
|
|
elemDict = readJsonFile(os.path.join(jsonDir, element + ".json")) |
|
|
|
|
|
faceCount = getFaceCount(elemDict["geomObjFile"]) |
|
fileSize = getFileSize(elemDict["geomObjFile"]) |
|
copies = len(elemDict["instancedCopies"]) if "instancedCopies" in elemDict else 1 |
|
|
|
print '\t'.join([element, "main geometry", elemDict["geomObjFile"], fileSize, faceCount]) |
|
|
|
if "instancedPrimitiveJsonFiles" in elemDict: |
|
for primitive, ipDict in elemDict["instancedPrimitiveJsonFiles"].iteritems(): |
|
printPrimitiveInfo(primitive, ipDict) |
|
|
|
|
|
if "variants" in elemDict: |
|
for variant, vDict in elemDict["variants"].iteritems(): |
|
faceCount = getFaceCount(vDict["geomObjFile"]) |
|
fileSize = getFileSize(vDict["geomObjFile"]) |
|
print '\t'.join([variant, "variant geometry", vDict["geomObjFile"], fileSize, faceCount]) |
|
|
|
if "instancedPrimitiveJsonFiles" in vDict: |
|
for vprimitive, vipDict in vDict["instancedPrimitiveJsonFiles"].iteritems(): |
|
printPrimitiveInfo(vprimitive, vipDict) |
|
|
|
|
|
if "instancedCopies" not in elemDict: |
|
print '\t'.join(["Total for %s"%element, "", "", "", "","","","","","","1"]) |
|
else: |
|
print '\t'.join(["Total for %s"%element, "", "", "", "","","","","","",str(len(elemDict["instancedCopies"]))]) |
|
|
|
|
|
if __name__ == "__main__": |
|
if main(): |
|
sys.exit(0) |
|
sys.exit(1) |