Skip to content

Commit cc48c22

Browse files
committed
fix(extra): Don't triangulate non-planar mesh quads
1 parent 85aa185 commit cc48c22

File tree

4 files changed

+27
-24
lines changed

4 files changed

+27
-24
lines changed
-8 Bytes
Loading
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,64 @@
11
{
2-
"version": "1.8.1",
3-
"nickname": "FilterNormal",
2+
"code": "\nimport math\n\ntry:\n from ladybug_geometry.geometry2d import Vector2D\n from ladybug_geometry.geometry3d import Vector3D\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_geometry:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.togeometry import to_face3d, to_vector2d, to_point3d\n from ladybug_{{cad}}.fromgeometry import from_face3d\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\nORIENT_MAP = {\n 'N': 0,\n 'NE': 45,\n 'E': 90,\n 'SE': 135,\n 'S': 180,\n 'SW': 225,\n 'W': 270,\n 'NW': 315,\n 'NORTH': 0,\n 'NORTHEAST': 45,\n 'EAST': 90,\n 'SOUTHEAST': 135,\n 'SOUTH': 180,\n 'SOUTHWEST': 225,\n 'WEST': 270,\n 'NORTHWEST': 315,\n 'UP': 'UP',\n 'DOWN': 'DOWN',\n 'UPWARDS': 'UP',\n 'DOWNWARDS': 'DOWN'\n}\n\n\nif all_required_inputs(ghenv.Component):\n # process all of the global inputs\n if north_ is not None: # process the north_\n try:\n north_ = to_vector2d(north_).angle_clockwise(Vector2D(0, 1))\n except AttributeError: # north angle instead of vector\n north_ = math.radians(float(north_))\n else:\n north_ = 0\n up_angle = math.radians(_up_angle_) if _up_angle_ is not None else math.radians(30)\n down_angle = math.radians(_down_angle_) if _down_angle_ is not None else math.radians(30)\n horiz_angle = math.radians(_horiz_angle_) if _horiz_angle_ is not None else math.radians(23)\n up_vec, down_vec = Vector3D(0, 0, 1), Vector3D(0, 0, -1)\n\n # process the geometry and the orientation\n try:\n all_geo = [f for geo in _geometry for f in to_face3d(geo, non_planar_quads=True)]\n except TypeError: # older version of the core libraries\n all_geo = [f for geo in _geometry for f in to_face3d(geo)]\n try:\n orient = ORIENT_MAP[_orientation.upper()]\n except KeyError:\n try:\n orient = float(_orientation)\n except Exception:\n msg = 'Orientation must be text (eg. N, E, S W) or a number for the\\n' \\\n 'azimuth of the geometry. Got {}.'.format(_orientation)\n raise TypeError(msg)\n\n # filter the geometry by the orientation\n if orient == 'UP':\n sel_geo = [f for f in all_geo if f.normal.angle(up_vec) < up_angle]\n elif orient == 'DOWN':\n sel_geo = [f for f in all_geo if f.normal.angle(down_vec) < down_angle]\n else:\n sel_geo = []\n dir_vec = Vector2D(0, 1).rotate(north_).rotate(-math.radians(orient))\n full_down_ang = math.pi - down_angle\n for f in all_geo:\n if up_angle <= f.normal.angle(up_vec) <= full_down_ang:\n norm_2d = Vector2D(f.normal.x, f.normal.y)\n if -horiz_angle <= norm_2d.angle(dir_vec) <= horiz_angle:\n sel_geo.append(f)\n\n # translate the Face3D back to {{Cad}} geometry\n sel_geo = [from_face3d(f) for f in sel_geo]\n",
3+
"subcategory": "4 :: Extra",
4+
"version": "1.8.2",
45
"outputs": [
56
[
67
{
78
"access": "None",
8-
"name": "sel_geo",
99
"description": "Selected faces of the input geometry that are facing the direction\ncorresponding to the input criteria.",
10+
"default": null,
1011
"type": null,
11-
"default": null
12+
"name": "sel_geo"
1213
}
1314
]
1415
],
16+
"name": "LB Filter by Normal",
17+
"nickname": "FilterNormal",
18+
"description": "Filter or select faces of geometry based on their orientation.",
1519
"inputs": [
1620
{
1721
"access": "item",
18-
"name": "north_",
1922
"description": "A number between -360 and 360 for the counterclockwise difference between\nthe North and the positive Y-axis in degrees. 90 is West and 270\nis East. This can also be Vector for the direction to North. (Default: 0)",
23+
"default": null,
2024
"type": "System.Object",
21-
"default": null
25+
"name": "north_"
2226
},
2327
{
2428
"access": "list",
25-
"name": "_geometry",
2629
"description": "Rhino Breps and/or Rhino Meshes which will be broken down into individual\nplanar faces and filtered based on the direction they face.",
30+
"default": null,
2731
"type": "GeometryBase",
28-
"default": null
32+
"name": "_geometry"
2933
},
3034
{
3135
"access": "item",
32-
"name": "_orientation",
3336
"description": "Text for the direction that the geometry is facing. This can also be\na number between 0 and 360 for the azimuth (clockwise horizontal\ndegrees from North) that the geometry should face. Choose from\nthe following:\n_\n* N = North\n* NE = Northeast\n* E = East\n* SE = Southeast\n* S = South\n* SW = Southwest\n* W = West\n* NW = Northwest\n* Up = Upwards\n* Down = Downwards",
37+
"default": null,
3438
"type": "string",
35-
"default": null
39+
"name": "_orientation"
3640
},
3741
{
3842
"access": "item",
39-
"name": "_up_angle_",
4043
"description": "A number in degrees for the maximum declination angle from the positive\nZ Axis that is considerd up. This should be between 0 and 90 for\nthe results to be practical. (Default: 30).",
44+
"default": null,
4145
"type": "double",
42-
"default": null
46+
"name": "_up_angle_"
4347
},
4448
{
4549
"access": "item",
46-
"name": "_down_angle_",
4750
"description": "A number in degrees for the maximum angle difference from the newative\nZ Axis that is considerd down. This should be between 0 and 90 for\nthe results to be practical. (Default: 30).",
51+
"default": null,
4852
"type": "double",
49-
"default": null
53+
"name": "_down_angle_"
5054
},
5155
{
5256
"access": "item",
53-
"name": "_horiz_angle_",
5457
"description": "Angle in degrees for the horizontal deviation from _orientation\nthat is still considered to face that orientation. This should be\nbetween 0 and 90 for the results to be practical. Note that this input\nhas no effect when the input orientation is \"Up\" or \"Down\". (Default: 23).",
58+
"default": null,
5559
"type": "double",
56-
"default": null
60+
"name": "_horiz_angle_"
5761
}
5862
],
59-
"subcategory": "4 :: Extra",
60-
"code": "\nimport math\n\ntry:\n from ladybug_geometry.geometry2d import Vector2D\n from ladybug_geometry.geometry3d import Vector3D\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_geometry:\\n\\t{}'.format(e))\n\ntry:\n from ladybug_{{cad}}.togeometry import to_face3d, to_vector2d\n from ladybug_{{cad}}.fromgeometry import from_face3d\n from ladybug_{{cad}}.{{plugin}} import all_required_inputs\nexcept ImportError as e:\n raise ImportError('\\nFailed to import ladybug_{{cad}}:\\n\\t{}'.format(e))\n\nORIENT_MAP = {\n 'N': 0,\n 'NE': 45,\n 'E': 90,\n 'SE': 135,\n 'S': 180,\n 'SW': 225,\n 'W': 270,\n 'NW': 315,\n 'NORTH': 0,\n 'NORTHEAST': 45,\n 'EAST': 90,\n 'SOUTHEAST': 135,\n 'SOUTH': 180,\n 'SOUTHWEST': 225,\n 'WEST': 270,\n 'NORTHWEST': 315,\n 'UP': 'UP',\n 'DOWN': 'DOWN',\n 'UPWARDS': 'UP',\n 'DOWNWARDS': 'DOWN'\n}\n\n\nif all_required_inputs(ghenv.Component):\n # process all of the global inputs\n if north_ is not None: # process the north_\n try:\n north_ = to_vector2d(north_).angle_clockwise(Vector2D(0, 1))\n except AttributeError: # north angle instead of vector\n north_ = math.radians(float(north_))\n else:\n north_ = 0\n up_angle = math.radians(_up_angle_) if _up_angle_ is not None else math.radians(30)\n down_angle = math.radians(_down_angle_) if _down_angle_ is not None else math.radians(30)\n horiz_angle = math.radians(_horiz_angle_) if _horiz_angle_ is not None else math.radians(23)\n up_vec, down_vec = Vector3D(0, 0, 1), Vector3D(0, 0, -1)\n\n # process the geometry and the orientation\n all_geo = [f for geo in _geometry for f in to_face3d(geo)]\n try:\n orient = ORIENT_MAP[_orientation.upper()]\n except KeyError:\n try:\n orient = float(_orientation)\n except Exception:\n msg = 'Orientation must be text (eg. N, E, S W) or a number for the\\n' \\\n 'azimuth of the geometry. Got {}.'.format(_orientation)\n raise TypeError(msg)\n\n # filter the geometry by the orientation\n if orient == 'UP':\n sel_geo = [f for f in all_geo if f.normal.angle(up_vec) < up_angle]\n elif orient == 'DOWN':\n sel_geo = [f for f in all_geo if f.normal.angle(down_vec) < down_angle]\n else:\n sel_geo = []\n dir_vec = Vector2D(0, 1).rotate(north_).rotate(-math.radians(orient))\n full_down_ang = math.pi - down_angle\n for f in all_geo:\n if up_angle <= f.normal.angle(up_vec) <= full_down_ang:\n norm_2d = Vector2D(f.normal.x, f.normal.y)\n if -horiz_angle <= norm_2d.angle(dir_vec) <= horiz_angle:\n sel_geo.append(f)\n\n # translate the Face3D back to {{Cad}} geometry\n sel_geo = [from_face3d(f) for f in sel_geo]\n",
61-
"category": "Ladybug",
62-
"name": "LB Filter by Normal",
63-
"description": "Filter or select faces of geometry based on their orientation."
63+
"category": "Ladybug"
6464
}

ladybug_grasshopper/src/LB Filter by Normal.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
ghenv.Component.Name = 'LB Filter by Normal'
5252
ghenv.Component.NickName = 'FilterNormal'
53-
ghenv.Component.Message = '1.8.1'
53+
ghenv.Component.Message = '1.8.2'
5454
ghenv.Component.Category = 'Ladybug'
5555
ghenv.Component.SubCategory = '4 :: Extra'
5656
ghenv.Component.AdditionalHelpFromDocStrings = '0'
@@ -64,7 +64,7 @@
6464
raise ImportError('\nFailed to import ladybug_geometry:\n\t{}'.format(e))
6565

6666
try:
67-
from ladybug_rhino.togeometry import to_face3d, to_vector2d
67+
from ladybug_rhino.togeometry import to_face3d, to_vector2d, to_point3d
6868
from ladybug_rhino.fromgeometry import from_face3d
6969
from ladybug_rhino.grasshopper import all_required_inputs
7070
except ImportError as e:
@@ -109,7 +109,10 @@
109109
up_vec, down_vec = Vector3D(0, 0, 1), Vector3D(0, 0, -1)
110110

111111
# process the geometry and the orientation
112-
all_geo = [f for geo in _geometry for f in to_face3d(geo)]
112+
try:
113+
all_geo = [f for geo in _geometry for f in to_face3d(geo, non_planar_quads=True)]
114+
except TypeError: # older version of the core libraries
115+
all_geo = [f for geo in _geometry for f in to_face3d(geo)]
113116
try:
114117
orient = ORIENT_MAP[_orientation.upper()]
115118
except KeyError:
64 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)