plane.ifcx

This commit is contained in:
Milovann Yanatchkov 2025-11-22 20:07:19 +01:00
parent b647237692
commit 492a4b3196
4 changed files with 106 additions and 31 deletions

1
viewer/src/utils/python/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.ifcx

View file

@ -9,7 +9,9 @@ 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: run-hack:
clear 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/

View file

@ -2,6 +2,7 @@ import itertools
import json import json
import sys import sys
import numpy as np import numpy as np
import uuid
obj = json.load(open(sys.argv[1])) obj = json.load(open(sys.argv[1]))

View file

@ -2,31 +2,104 @@ import itertools
import json import json
import sys import sys
import numpy as np import numpy as np
import uuid
debug = False
# Load file # Load file
obj = json.load(open(sys.argv[1])) obj = json.load(open(sys.argv[1]))
def volume(data): # New file
indices = np.array(data["faceVertexIndices"], dtype=int) model = {}
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): def show_nodes():
points = np.array(data["points"], dtype=float) for item in obj:
return points[:,2].max() - points[:,2].min() 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 def show_meshes():
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')]: for d in [d for d in list(obj['data']) if d.get('attributes', {}).get('usd::usdgeom::mesh')]:
mesh = d['attributes']['usd::usdgeom::mesh'] mesh = d['attributes']['usd::usdgeom::mesh']
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
@ -35,10 +108,8 @@ for d in [d for d in list(obj['data']) if d.get('attributes', {}).get('usd::usdg
print("VERTICES") print("VERTICES")
print(mesh['points']) print(mesh['points'])
ostream = None
try:
ostream = open(sys.argv[2], 'w')
except:
ostream = sys.stdout
#json.dump(obj, ostream, indent=2) show_nodes()
generate()
#show_meshes()