-
Notifications
You must be signed in to change notification settings - Fork 3
/
scene-info.py
executable file
·189 lines (157 loc) · 7.48 KB
/
scene-info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env python
import os
import sys
import json
import locale
import math
from optparse import OptionParser
from clint.textui import indent, puts, puts_err
import cache
locale.setlocale(locale.LC_ALL, '')
def pretty(x):
return locale.format("%d", x, grouping=True)
def humanize_bytes(bytes, precision=1):
abbrevs = (
(1<<50L, 'PB'),
(1<<40L, 'TB'),
(1<<30L, 'GB'),
(1<<20L, 'MB'),
(1<<10L, 'KB'),
(1, 'bytes')
)
if bytes == 1:
return '1 byte'
for factor, suffix in abbrevs:
if math.fabs(bytes) >= factor:
break
return '%.*f %s' % (precision, bytes / factor, suffix)
def main():
parser = OptionParser(usage="Usage: scene-info.py [--missing-to file.txt] scene.json",
description="Prints information about a JSON scene file.")
parser.add_option("-m", "--missing-to", dest="missing_to",
help="Write a list of paths missing progressive info to file", metavar="MISSING_TO")
(options, args) = parser.parse_args()
if len(args) != 1:
parser.print_help()
parser.exit(1, "Wrong number of arguments.\n")
if not os.path.isfile(args[0]):
parser.print_help()
parser.exit(1, "Input file '%s' is not a valid file.\n" % args[0])
missing_to = None
if options.missing_to is not None:
missing_to = open(options.missing_to, 'w')
fname = args[0]
json_data = json.load(open(fname))
total_triangles = 0
total_draw_calls = 0
total_ram_cache = {}
total_mesh_size = {}
total_texture_size = {}
total_base_tris = 0
base_ram_cache = {}
total_base_draw_calls = 0
total_base_mesh_bytes = {}
total_base_texture_bytes = {}
total_base_stream_bytes = {}
total_full_tris = 0
full_ram_cache = {}
total_full_draw_calls = 0
total_texture_sum = {}
missing_progressive = set()
missing_metadata = set()
too_big = set()
for m in json_data:
metadata = cache.get_metadata(m['path'])
if 'progressive' not in metadata['metadata']['types']:
missing_progressive.add(m['path'])
else:
progressive = metadata['metadata']['types']['progressive']
if 'metadata' not in progressive:
missing_metadata.add(m['path'])
else:
total_base_tris += min(progressive['metadata']['num_triangles'], 40000)
total_base_mesh_bytes[m['path']] = progressive['size_gzip']
total_base_stream_bytes[m['path']] = progressive.get('progressive_stream_size_gzip', 0)
total_full_tris += progressive['metadata']['num_triangles']
if progressive['metadata']['num_triangles'] > 40000:
too_big.add(m['path'])
for mapname, mapinfo in progressive['mipmaps'].iteritems():
byte_ranges = mapinfo['byte_ranges']
byte_size = 0
for levelinfo in byte_ranges:
width, height = levelinfo['width'], levelinfo['height']
if width >= 128 or height >= 128:
ram_size = width * height * 4
byte_size = levelinfo['length']
break
base_ram_cache[m['path']] = ram_size
total_base_texture_bytes[m['path']] = byte_size
if len(byte_ranges) > 0:
full_res = byte_ranges[-1]
width, height = full_res['width'], full_res['height']
full_ram_cache[m['path']] = width * height * 4
total_texture_sum[m['path']] = sum([l['length'] for l in byte_ranges])
total_base_draw_calls += progressive['metadata']['num_draw_calls']
total_full_draw_calls += progressive['metadata']['num_draw_calls']
optimized = metadata['metadata']['types']['optimized']
total_triangles += optimized['metadata']['num_triangles']
total_ram_cache[m['path']] = optimized['metadata']['texture_ram_usage']
total_draw_calls += optimized['metadata']['num_draw_calls']
total_mesh_size[m['path']] = optimized['size_gzip']
total_texture_size[m['path']] = sum(optimized['subfile_sizes_gzip'].values())
total_ram = sum(total_ram_cache.values())
total_base_ram = sum(base_ram_cache.values())
total_full_ram = sum(full_ram_cache.values())
total_mesh_size = sum(total_mesh_size.values())
total_texture_size = sum(total_texture_size.values())
total_base_mesh_bytes = sum(total_base_mesh_bytes.values())
total_base_texture_bytes = sum(total_base_texture_bytes.values())
total_base_stream_bytes = sum(total_base_stream_bytes.values())
total_texture_sum = sum(total_texture_sum.values())
for m in missing_progressive:
if missing_to is not None:
puts_err(m, stream=missing_to.write)
else:
puts_err('Warning: missing progressive version for: "%s"' % m)
if missing_to is None and len(missing_progressive) > 0:
puts()
for m in too_big:
metadata = cache.get_metadata(m)
puts_err("Warning '%s' too big at %s triangles %s" % (m, pretty(metadata['metadata']['types']['progressive']['metadata']['num_triangles']), pretty(metadata['metadata']['types']['progressive']['progressive_stream_num_triangles'])))
if len(too_big) > 0:
puts()
for m in missing_metadata:
puts_err("Warning '%s' missing metadata" % m)
if len(missing_metadata) > 0:
puts()
puts('Number of models in the scene: %s' % pretty(len(json_data)))
puts('Number of unique models in the scene: %s' % pretty(len(set(m['path'] for m in json_data))))
puts()
puts("Type 'optimized'")
with indent(4):
puts('Triangles: %s' % pretty(total_triangles))
puts('Texture RAM: %s' % humanize_bytes(total_ram))
puts('Draw Calls: %s' % pretty(total_draw_calls))
puts('Mesh Download Size: %s' % humanize_bytes(total_mesh_size))
puts('Textures Download Size: %s' % humanize_bytes(total_texture_size))
puts('Total Download Size: %s' % humanize_bytes(total_mesh_size + total_texture_size))
puts()
puts("Type 'progressive' base mesh")
with indent(4):
puts('Triangles: %s' % pretty(total_base_tris))
puts('Texture RAM: %s' % humanize_bytes(total_base_ram))
puts('Draw Calls: %s' % pretty(total_base_draw_calls))
puts('Base Mesh Download Size: %s' % humanize_bytes(total_base_mesh_bytes))
puts('Base Texture Download Size: %s' % humanize_bytes(total_base_texture_bytes))
puts('Total Base Download Size: %s' % humanize_bytes(total_base_mesh_bytes + total_base_texture_bytes))
puts()
puts("Type 'progressive' full quality")
with indent(4):
puts('Triangles: %s' % pretty(total_full_tris))
puts('Texture RAM: %s' % humanize_bytes(total_full_ram))
puts('Draw Calls: %s' % pretty(total_full_draw_calls))
puts('Progressive Stream Download Size: %s' % humanize_bytes(total_base_stream_bytes))
puts('All Textures Download Size: %s' % humanize_bytes(total_texture_sum))
puts('Total Download Size : %s' % humanize_bytes(total_base_mesh_bytes + total_base_stream_bytes + total_texture_sum))
if __name__ == '__main__':
main()