diff --git a/viewer/src/utils/python/Makefile b/viewer/src/utils/python/Makefile index 78179ab..457256c 100644 --- a/viewer/src/utils/python/Makefile +++ b/viewer/src/utils/python/Makefile @@ -7,6 +7,9 @@ run-rewrite: uv run rewrite_materials.py ../../../example/hello-wall.ifcx run-calc-properties: uv run calc_properties.py ../../../example/hello-wall.ifcx > out-props.ifcx +run-hack: + clear + uv run hack.py ../../../example/hello-wall.ifcx diff --git a/viewer/src/utils/python/hack.py b/viewer/src/utils/python/hack.py new file mode 100644 index 0000000..5410c8e --- /dev/null +++ b/viewer/src/utils/python/hack.py @@ -0,0 +1,44 @@ +import itertools +import json +import sys +import numpy as np + +# Load file +obj = json.load(open(sys.argv[1])) + +def volume(data): + indices = np.array(data["faceVertexIndices"], dtype=int) + points = np.array(data["points"], dtype=float) + ref = points.mean(axis=0) + vol = 0.0 + for i in range(0, len(indices), 3): + a = points[indices[i ]] - ref + b = points[indices[i + 1]] - ref + c = points[indices[i + 2]] - ref + vol += np.dot(np.cross(a, b), c) / 6.0 + return vol + +def height(data): + points = np.array(data["points"], dtype=float) + return points[:,2].max() - points[:,2].min() + + +# Parents +parents = dict(itertools.chain.from_iterable(([(c, o['path']) for k, c in o['children'].items() if k != 'Void'] for o in obj['data'] if o.get('children')))) + +# Meshes +for d in [d for d in list(obj['data']) if d.get('attributes', {}).get('usd::usdgeom::mesh')]: + mesh = d['attributes']['usd::usdgeom::mesh'] + print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") + print("FACES") + print(mesh['faceVertexIndices']) + print("VERTICES") + print(mesh['points']) + +ostream = None +try: + ostream = open(sys.argv[2], 'w') +except: + ostream = sys.stdout + +#json.dump(obj, ostream, indent=2)