55
66import Rhino
77import Rhino .Geometry as rg
8+ import scriptcontext as sc
89
910from ghpythonlib .componentbase import executingcomponent as component
1011
1112import diffCheck
1213from diffCheck .df_geometries import DFBeam , DFAssembly
14+ import diffCheck .df_transformations
15+
16+ import diffCheck .diffcheck_bindings
17+ import diffCheck .df_cvt_bindings
1318
1419
1520class DFXMLExporter (component ):
@@ -25,29 +30,128 @@ def RunScript(self,
2530 :param i_export_dir: directory to export the xml
2631 :param i_breps: list of breps
2732 """
33+ ################
2834 o_xml = None
2935 o_joints = None
3036 o_sides = None
3137 o_debug = None
38+ ################
39+ ########################################
40+
41+ # TODO: test
42+ o_debug = []
3243
33- # beams
34- beams : typing .List [DFBeam ] = []
44+ # mass_ctrs = []
45+ # crt_brep = i_breps[5]
46+ breps_repaired = []
3547 for brep in i_breps :
36- beam = DFBeam .from_brep (brep )
37- beams .append (beam )
3848
39- # assembly
40- assembly1 = DFAssembly (beams , i_assembly_name )
49+ # convert mesh to brep object
50+ mesh = Rhino .Geometry .Mesh ()
51+ mesh_parts = Rhino .Geometry .Mesh .CreateFromBrep (
52+ brep ,
53+ Rhino .Geometry .MeshingParameters .Coarse )
54+ for mesh_part in mesh_parts : mesh .Append (mesh_part )
55+ mesh .Compact ()
56+ mesh .MergeAllCoplanarFaces (Rhino .RhinoDoc .ActiveDoc .ModelAbsoluteTolerance , True )
57+ # o_debug.append(mesh)
58+
59+ # get the obb
60+ df_mesh = diffCheck .df_cvt_bindings .cvt_rhmesh_2_dfmesh (mesh )
61+ df_cloud = df_mesh .sample_points_uniformly (200 )
62+ df_OBB = df_cloud .get_tight_bounding_box ()
63+ rh_OBB = diffCheck .df_cvt_bindings .cvt_dfOBB_2_rhbrep (df_OBB )
64+
65+ # check if the OBB is closed
66+ # print(f"OBB is closed: {rh_OBB.IsSolid}") # FIXME: brep is not closed
67+ # o_debug.append(rh_OBB)
68+
69+ # get OBB_center
70+ rh_OBB_center = rh_OBB .GetBoundingBox (True ).Center
71+ # o_debug.append(rh_OBB_center)
72+
73+ # local axis system get the longest/shortes edge of the rh_OBB with a lambda function
74+ edges = rh_OBB .Edges
75+ edge_lengths = [edge .GetLength () for edge in edges ]
76+ longest_edge = edges [edge_lengths .index (max (edge_lengths ))]
77+ shortest_edge = edges [edge_lengths .index (min (edge_lengths ))]
78+
79+ # scale the box in the longest edge direction by 1.5 from center on both directions
80+ rh_OBB_zaxis = rg .Vector3d (longest_edge .PointAt (1 ) - longest_edge .PointAt (0 ))
81+ rh_OBB_plane = rg .Plane (rh_OBB_center , rh_OBB_zaxis )
82+ scale_factor = 0.09
83+ xform = rg .Transform .Scale (
84+ rh_OBB_plane ,
85+ 1 - scale_factor ,
86+ 1 - scale_factor ,
87+ 1 + scale_factor
88+ )
89+ rh_OBB .Transform (xform )
90+
91+ # get all the centers of the faces
92+ # face_centers = []
93+ faces = {}
94+ for idx , face in enumerate (brep .Faces ):
95+ face_center = rg .AreaMassProperties .Compute (face ).Centroid
96+ if rh_OBB .IsPointInside (face_center , sc .doc .ModelAbsoluteTolerance , True ):
97+ # face_centers.append(face_center)
98+ faces [idx ] = (face , True )
99+ # o_debug.append(brep.Faces[idx])
100+ else :
101+ faces [idx ] = (face , False )
102+ # o_debug.append(brep.Faces[idx])
103+
104+ face_jointid = {} # face : joint id (int)
105+ joint_counter = 0
106+ for key , value in faces .items ():
107+ # print(f"Face {key} is inside: {value[1]}")
108+ if value [1 ]:
109+ face_jointid [key ] = joint_counter
110+ adjacent_faces = value [0 ].AdjacentFaces ()
111+ for adj_face in adjacent_faces :
112+ if faces [adj_face ][1 ]:
113+ face_jointid [value ] = joint_counter
114+ joint_counter += 1
115+ else :
116+ face_jointid [value ] = None
117+
118+ o_sides = [faces [key ][0 ] for key , value in faces .items () if not value [1 ]]
119+ o_joints = [faces [key ][0 ] for key , value in faces .items () if value [1 ]]
120+
121+
122+
123+
124+ # get the faces that are t
125+
126+
127+ ########################################
128+
129+ # for f in crt_brep.Faces:
130+ # mass_ctr = rg.AreaMassProperties.Compute(f).Centroid
131+ # is_inside : bool = aabb.Contains(mass_ctr, strict=True)
132+ # print(f"Face {f} is inside: {is_inside}")
133+ # if is_inside:
134+ # mass_ctrs.append(mass_ctr)
135+ # o_debug = mass_ctrs
136+
137+ # # beams
138+ # beams: typing.List[DFBeam] = []
139+ # for brep in i_breps:
140+ # beam = DFBeam.from_brep(brep)
141+ # beams.append(beam)
142+
143+ # # assembly
144+ # assembly1 = DFAssembly(beams, i_assembly_name)
41145
42- # dump the xml
43- xml : str = assembly1 .to_xml ()
44- if i_dump :
45- assembly1 .dump_xml (xml , i_export_dir )
46- o_xml = xml
146+ # # dump the xml
147+ # xml: str = assembly1.to_xml()
148+ # if i_dump:
149+ # assembly1.dump_xml(xml, i_export_dir)
150+ # o_xml = xml
47151
48- # show the joint/side faces
49- o_joints = [jf .to_brep () for jf in assembly1 .all_joint_faces ]
50- o_sides = [sf .to_brep () for sf in assembly1 .all_side_faces ]
152+ # # show the joint/side faces
153+ # o_joints = [jf.to_brep() for jf in assembly1.all_joint_faces]
154+ # o_sides = [sf.to_brep() for sf in assembly1.all_side_faces]
51155
52156 return o_xml , o_joints , o_sides , o_debug
53157
0 commit comments