diff --git a/src/rhino/gh/cpy/beam_volume/code.py b/src/rhino/gh/cpy/beam_volume/code.py index e09a6451..3025e692 100644 --- a/src/rhino/gh/cpy/beam_volume/code.py +++ b/src/rhino/gh/cpy/beam_volume/code.py @@ -1,61 +1,155 @@ -# from ghpythonlib.componentbase import executingcomponent as component -# import Grasshopper - -# import Rhino -# from Rhino.Geometry import ( -# Point3d, -# Vector3d, -# Polyline, -# Curve, -# Line, -# Plane, -# Brep, -# BoundingBox, -# Interval, -# RTree, -# Transform, -# Rectangle3d, -# ) -# from collections import OrderedDict -# from Grasshopper import DataTree -# from Grasshopper.Kernel.Data import GH_Path -# import math - - -# class MyComponent(component): -# def RunScript( -# self, -# _circles: Grasshopper.DataTree[Rhino.Geometry.Circle], -# _length_of_box: float, -# _distance_tolerance: float, -# _parallel_tolerance: float, -# _cross_or_toptoside: bool, -# _create_pipes: bool, -# ): - - -# input_polylines_segment_radii = [] - -# for i in range(len(input_polylines)): -# input_polyline_segment_radii = [] -# for j in range(len(input_polylines[i].points)): -# input_polyline_segment_radii.append(10) -# input_polylines_segment_radii.append(input_polyline_segment_radii) - -# input_polylines_segment_direction = [] -# for i in range(len(input_polylines)): -# input_polyline_segment_direction = [] -# for j in range(len(input_polylines[i].points)-1): -# input_polyline_segment_direction.append([0, 1, 0]) -# input_polylines_segment_direction.append(input_polyline_segment_direction) - - -# i_polylines, i_polylines_segment, distance, points, volume_pairs, joints_areas, joints_types = beam_volumes( -# input_polylines, -# input_polylines_segment_radii, -# input_polylines_segment_direction, -# input_allowed_types_per_polyline=[-1], -# input_min_distance=20, -# input_volume_length=75, -# input_cross_or_side_to_end=0.91, -# ) +import Rhino +import Grasshopper +import ghpythonlib.treehelpers as th +from ghpythonlib.componentbase import executingcomponent as component +from wood_nano import beam_volumes as wood_nano_beam_volumes +from compas_wood.conversions_rhino import to_point2 +from compas_wood.conversions_rhino import to_vector2 +from compas_wood.conversions_rhino import from_point2 +from compas_wood.conversions_rhino import from_point3 +from wood_nano.conversions_python import to_double2 +from wood_nano.conversions_python import to_int1 +from wood_nano.conversions_python import from_int1 +from wood_nano.conversions_python import from_int2 +from wood_nano.conversions_python import from_double2 +from wood_nano import int1 +from wood_nano import int2 +from wood_nano import double2 +from wood_nano import point2 +from wood_nano import point3 +from wood_nano import cut_type2 + +class BeamVolume(component): + def beam_volumes(self, + input_polyline_axes, + input_polylines_segment_radii, + input_polylines_segment_direction, + input_allowed_types_per_polyline=[1], + input_min_distance=50, + input_volume_length=500, + input_cross_or_side_to_end=0.91, + input_flip_male=1, + input_compute_joints=False, + input_division_distance=150, + input_shift=0.5, + input_output_geometry_type=0, + input_use_eccentricities_to_scale_joints=True, + ): + + index_polylines = int2() + index_polylines_segment = int2() + distance = double2() + point_pairs = point2() + volume_pairs = point3() + joints_areas = point2() + joints_types = int1() + w_output_plines = point3() + w_output_types = cut_type2() + + wood_nano_beam_volumes( + to_point2(input_polyline_axes), + to_double2(input_polylines_segment_radii), + to_vector2(input_polylines_segment_direction), + to_int1(input_allowed_types_per_polyline), + float(input_min_distance), + float(input_volume_length), + float(input_cross_or_side_to_end), + int(input_flip_male), + index_polylines, # out + index_polylines_segment, # out + distance, # out + point_pairs, # out + volume_pairs, # out + joints_areas, # out + joints_types, # out + w_output_plines, # from_point3(w_output_plines) + w_output_types, # from_cut_type2(w_output_types)) + input_compute_joints, + input_division_distance, + input_shift, + input_output_geometry_type, + input_use_eccentricities_to_scale_joints, + ) + + return ( + from_int2(index_polylines), + from_int2(index_polylines_segment), + from_double2(distance), + from_point2(point_pairs), + from_point3(volume_pairs), + from_point2(joints_areas), + from_int1(joints_types), + ) + + def RunScript(self, + _circles: Grasshopper.DataTree[Rhino.Geometry.Circle], + _length_of_box: float, + _distance_tolerance: float, + _cross_or_toptoside: float, + _create_pipes: bool): + + if _circles is None: return + length_of_box = _length_of_box if _length_of_box else 1 + distance_tolerance = _distance_tolerance if _distance_tolerance else 10 + cross_or_top_to_side= _cross_or_toptoside if _cross_or_toptoside else 0.91 + create_pipes = _create_pipes if _create_pipes else False + + # Initialize outputs + input_polylines = [] + input_polylines_segment_radii = [] + input_polylines_segment_direction = [] + _pipes = [] + + # Processing each branch which represents a polyline + for i in range(_circles.BranchCount): + points = [] + radii= [] + normals = [] + parameters = [] + for index, circle in enumerate(_circles.Branch(i)): + points.append(circle.Center) + radii.append(circle.Radius) + normals.append(circle.Plane.YAxis) + parameters.append(index) + # radii.pop() + # normals.pop() + + input_polylines.append(Rhino.Geometry.Polyline(points)) + input_polylines_segment_radii.append(radii) + # input_polylines_segment_direction.append(normals) + + if(create_pipes): + curves = [] + for j in range (_circles.Branch(i).Count): + curves.append(_circles.Branch(i)[j].ToNurbsCurve()) + + brep = Rhino.Geometry.Brep.CreateFromLoft(curves, Rhino.Geometry.Point3d.Unset, Rhino.Geometry.Point3d.Unset, Rhino.Geometry.LoftType.Loose, False)[0] + brep = brep.CapPlanarHoles(Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance) + + faces = [] + for j in range(brep.Faces.Count): + faces.append(brep.Faces[j].DuplicateFace(False)) + + brep = Rhino.Geometry.Brep.JoinBreps( + faces, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance*10 + )[0] + + if brep: + brep.Faces.SplitKinkyFaces(Rhino.RhinoMath.DefaultAngleTolerance, True) + + if (Rhino.Geometry.BrepSolidOrientation.Inward is brep.SolidOrientation): + brep.Flip(); + _pipes.append(brep) + + + _index_polylines, _index_polylines_segment, _distance, _point_pairs, _volume_pairs, _joints_areas, _joints_types = self.beam_volumes( + input_polylines, + input_polylines_segment_radii, + input_polylines_segment_direction, + input_allowed_types_per_polyline=[1], + input_min_distance=distance_tolerance, + input_volume_length=length_of_box, + input_cross_or_side_to_end=cross_or_top_to_side, + ) + + return th.list_to_tree(_index_polylines), th.list_to_tree( _index_polylines_segment), th.list_to_tree(_distance), th.list_to_tree(_point_pairs), th.list_to_tree( _volume_pairs), th.list_to_tree( _joints_areas), th.list_to_tree( _joints_types), th.list_to_tree( _pipes) diff --git a/src/rhino/gh/cpy/beam_volume/metadata.json b/src/rhino/gh/cpy/beam_volume/metadata.json index 41b46d10..cf60fc33 100644 --- a/src/rhino/gh/cpy/beam_volume/metadata.json +++ b/src/rhino/gh/cpy/beam_volume/metadata.json @@ -55,20 +55,6 @@ "reverse": false, "simplify": false }, - { - "name": "_parallel_tolerance", - "nickname": "_parallel_tolerance", - "description": "angle tolerance that defines the detection of end beams", - "optional": true, - "allowTreeAccess": true, - "showTypeHints": true, - "scriptParamAccess": "item", - "wireDisplay": "faint", - "sourceCount": 0, - "typeHintID": "float", - "reverse": false, - "simplify": false - }, { "name": "_cross_or_toptoside", "nickname": "_cross_or_toptoside", @@ -79,7 +65,7 @@ "scriptParamAccess": "item", "wireDisplay": "faint", "sourceCount": 0, - "typeHintID": "bool", + "typeHintID": "float", "reverse": false, "simplify": false }, @@ -101,25 +87,65 @@ ], "outputParameters": [ { - "name": "_volumes", - "nickname": "_volumes", - "description": "pair of rectangles that represent the beam volume around the joint", + "name": "_index_polylines", + "nickname": "_index_polylines", + "description": "indices of polylines axes", "optional": false, "sourceCount": 0, "graft": false }, { - "name": "_pipes", - "nickname": "_pipes", - "description": "if _create_pipes input is set to True the circles are lofted and outputted here", + "name": "_index_polylines_segment", + "nickname": "_index_polylines_segment", + "description": "indices of polylines segements", + "optional": false, + "sourceCount": 0, + "graft": false + }, + { + "name": "_distance", + "nickname": "_distance", + "description": "distance between points", + "optional": false, + "sourceCount": 0, + "graft": false + }, + { + "name": "_point_pairs", + "nickname": "_point_pairs", + "description": "closest point pairs", + "optional": false, + "sourceCount": 0, + "graft": false + }, + { + "name": "_volume_pairs", + "nickname": "_volume_pairs", + "description": "rectangle pairs representing elements", + "optional": false, + "sourceCount": 0, + "graft": false + }, + { + "name": "_joints_areas", + "nickname": "_joints_areas", + "description": "joint areas between volumes", "optional": false, "sourceCount": 0, "graft": false }, { - "name": "_group_id", - "nickname": "_group_id", - "description": "grouping of beam volumes", + "name": "_joints_types", + "nickname": "_joints_types", + "description": "joints types from interface condition", + "optional": false, + "sourceCount": 0, + "graft": false + }, + { + "name": "_pipes", + "nickname": "_pipes", + "description": "if _create_pipes input is set to True the circles are lofted and outputted here", "optional": false, "sourceCount": 0, "graft": false diff --git a/src/rhino/gh/cpy/solver_custom/code.py b/src/rhino/gh/cpy/solver_custom/code.py index ff25cc1c..c083929f 100644 --- a/src/rhino/gh/cpy/solver_custom/code.py +++ b/src/rhino/gh/cpy/solver_custom/code.py @@ -8,6 +8,7 @@ from wood_nano.conversions_python import to_int1 from wood_nano.conversions_python import to_double1 from wood_nano.conversions_python import from_cut_type2 +from compas_wood.conversions_rhino import to_point1 from compas_wood.conversions_rhino import to_point2 from compas_wood.conversions_rhino import to_vector2 from compas_wood.conversions_rhino import from_point3 @@ -34,17 +35,15 @@ def DrawViewportWires(self, args): def get_ClippingBox(self): return self.bbox - def RunScript( - self, - _data, - _joint_p: System.Collections.Generic.List[float], - _scale: System.Collections.Generic.List[float], - _extension: System.Collections.Generic.List[float], - _find: int, - _get: int, - _custom_joints: System.Collections.Generic.List[Rhino.Geometry.Polyline], - _custom_types: System.Collections.Generic.List[int], - ): + def RunScript(self, + _data, + _joint_p: System.Collections.Generic.IList[float], + _scale: System.Collections.Generic.IList[float], + _extension: System.Collections.Generic.IList[float], + _find: int, + _get: int, + _custom_joints: System.Collections.Generic.IList[Rhino.Geometry.Polyline], + _custom_types: System.Collections.Generic.IList[int]): # ============================================================================== # clear input @@ -123,7 +122,8 @@ def RunScript( -69: [], } for i in range(len(_custom_joints)): - custom_joints_dict[_custom_types[i]].append(_custom_joints[i]) + polyline = to_point1(_custom_joints[i]) + custom_joints_dict[_custom_types[i]].append(polyline) for key, value in custom_joints_dict.items(): if key == 9: diff --git a/src/rhino/gh/examples/16_beams_nearest_curve.gh b/src/rhino/gh/examples/16_beams_nearest_curve.gh index 6a04b69d..dd440afa 100644 Binary files a/src/rhino/gh/examples/16_beams_nearest_curve.gh and b/src/rhino/gh/examples/16_beams_nearest_curve.gh differ diff --git a/src/rhino/gh/examples/17_beam_custom_joints.gh b/src/rhino/gh/examples/17_beam_custom_joints.gh index b2d2cc76..d9dee3ce 100644 Binary files a/src/rhino/gh/examples/17_beam_custom_joints.gh and b/src/rhino/gh/examples/17_beam_custom_joints.gh differ