From 492a4b3196d9fddcc994dfb7e073e62e136184cd Mon Sep 17 00:00:00 2001 From: milovann Date: Sat, 22 Nov 2025 20:07:19 +0100 Subject: [PATCH] plane.ifcx --- viewer/src/utils/python/.gitignore | 1 + viewer/src/utils/python/Makefile | 4 +- viewer/src/utils/python/calc_properties.py | 1 + viewer/src/utils/python/hack.py | 131 ++++++++++++++++----- 4 files changed, 106 insertions(+), 31 deletions(-) create mode 100644 viewer/src/utils/python/.gitignore diff --git a/viewer/src/utils/python/.gitignore b/viewer/src/utils/python/.gitignore new file mode 100644 index 0000000..742b2ff --- /dev/null +++ b/viewer/src/utils/python/.gitignore @@ -0,0 +1 @@ +*.ifcx diff --git a/viewer/src/utils/python/Makefile b/viewer/src/utils/python/Makefile index 457256c..2f98e11 100644 --- a/viewer/src/utils/python/Makefile +++ b/viewer/src/utils/python/Makefile @@ -9,7 +9,9 @@ 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 + uv run hack.py ../../../example/hello-wall.ifcx > plane.ifcx + #uv run hack.py ../../../example/hello-wall.ifcx + cp plane.ifcx ~/Bureau/test/ diff --git a/viewer/src/utils/python/calc_properties.py b/viewer/src/utils/python/calc_properties.py index 4f95eba..64216b4 100644 --- a/viewer/src/utils/python/calc_properties.py +++ b/viewer/src/utils/python/calc_properties.py @@ -2,6 +2,7 @@ import itertools import json import sys import numpy as np +import uuid obj = json.load(open(sys.argv[1])) diff --git a/viewer/src/utils/python/hack.py b/viewer/src/utils/python/hack.py index 5410c8e..ae8f0d4 100644 --- a/viewer/src/utils/python/hack.py +++ b/viewer/src/utils/python/hack.py @@ -2,43 +2,114 @@ import itertools import json import sys import numpy as np +import uuid + +debug = False # 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 +# New file +model = {} -def height(data): - points = np.array(data["points"], dtype=float) - return points[:,2].max() - points[:,2].min() +def show_nodes(): + for item in obj: + if item == "header": + if debug: print("HEADER") + model["header"] = {} + for data in obj[item]: + if debug: print(" ", data, ":", obj[item][data]) + model["header"][data] = obj[item][data] + elif item == "imports": + if debug: print("IMPORTS") + model["imports"] = {} + lst = [] + for data in obj[item]: + if debug: print(" ", data) + lst.append(obj[item][1]) + model["imports"] = obj[item] + elif item == "schemas": + model["schemas"] = obj[item] + if debug: print("SCHEMAS") + for data in obj[item]: + if debug: print(" ", data) + elif item == "data": + if debug: print("DATA") + for data in obj[item]: + #print(" ", data) + for d in data: + if d == "attributes": + #print(d,data[d]) + pass + else: + print(item) + +def add_site(site_ref): + ref = str(uuid.uuid4()) + site = { + "path" : ref, + "children" : { + "Site" : site_ref + } + } + return site,ref + +def add_plane(): + + ref = str(uuid.uuid4()) + mesh = { + "faceVertexIndices" : [0,1,2,0,2,3], + "points" : [ + [0,0,0], + [10,0,0], + [10,10,0], + [0,10,0], + ] + } + + plane = { + "path" : ref, + "attributes" : { + "usd::usdgeom::mesh": mesh + } + } + + return plane,ref + +def generate(): + ostream = None + try: + ostream = open(sys.argv[2], 'w') + except: + ostream = sys.stdout + + items = [] + + plane, plane_id = add_plane() + items.append(plane) + + site, site_id = add_site(plane_id) + items.append(site) + + model["data"] = items + + json.dump(model, ostream, indent=2) + + if debug: print("MODEL") + if debug: print(model) -# 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')))) +def show_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']) -# 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 +show_nodes() +generate() +#show_meshes() -#json.dump(obj, ostream, indent=2)