plane.ifcx
This commit is contained in:
parent
b647237692
commit
492a4b3196
4 changed files with 106 additions and 31 deletions
1
viewer/src/utils/python/.gitignore
vendored
Normal file
1
viewer/src/utils/python/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
*.ifcx
|
||||
|
|
@ -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/
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import itertools
|
|||
import json
|
||||
import sys
|
||||
import numpy as np
|
||||
import uuid
|
||||
|
||||
obj = json.load(open(sys.argv[1]))
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue