add hack.py

This commit is contained in:
Milovann Yanatchkov 2025-11-22 16:56:14 +01:00
parent 5c01db9103
commit b647237692
2 changed files with 47 additions and 0 deletions

View file

@ -7,6 +7,9 @@ run-rewrite:
uv run rewrite_materials.py ../../../example/hello-wall.ifcx uv run rewrite_materials.py ../../../example/hello-wall.ifcx
run-calc-properties: run-calc-properties:
uv run calc_properties.py ../../../example/hello-wall.ifcx > out-props.ifcx uv run calc_properties.py ../../../example/hello-wall.ifcx > out-props.ifcx
run-hack:
clear
uv run hack.py ../../../example/hello-wall.ifcx

View file

@ -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)