Skip to content

Commit

Permalink
fix(visualize): Replace long code with new methods in ladybug_rhino
Browse files Browse the repository at this point in the history
This update is linked to this PR here:

ladybug-tools/ladybug-rhino#354
  • Loading branch information
chriswmackey committed Nov 21, 2024
1 parent dade9a0 commit 84d01e1
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 177 deletions.
Binary file modified honeybee_grasshopper_core/icon/HB Visualize All.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions honeybee_grasshopper_core/json/HB_Visualize_All.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.8.0",
"version": "1.8.1",
"nickname": "VizAll",
"outputs": [
[
Expand All @@ -22,7 +22,7 @@
}
],
"subcategory": "1 :: Visualize",
"code": "\ntry: # import the core honeybee dependencies\n from honeybee.model import Model\n from honeybee.room import Room\n from honeybee.face import Face\n from honeybee.aperture import Aperture\n from honeybee.door import Door\n from honeybee.shade import Shade\n from honeybee.shademesh import ShadeMesh\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry: # import the core ladybug_{{cad}} dependencies\n from ladybug_{{cad}}.config import tolerance\n from ladybug_{{cad}}.fromgeometry import from_face3d, from_mesh3d\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\nimport {{Cad}}.Geometry as rg\n\n\ndef add_shade(shd, shades):\n \"\"\"Add Shade geometry to a shades list.\"\"\"\n shades.append(from_face3d(shd.geometry))\n\ndef add_door(door, geo, shades):\n \"\"\"Add Door geometry to a geo list and shades list.\"\"\"\n geo.append(from_face3d(door.geometry))\n for shd in door.shades:\n add_shade(shd, shades)\n\ndef add_aperture(aperture, geo, shades):\n \"\"\"Add Aperture geometry to a geo and shades list.\"\"\"\n geo.append(from_face3d(aperture.geometry))\n for shd in aperture.shades:\n add_shade(shd, shades)\n\ndef add_face(face, geo, shades):\n \"\"\"Add Face geometry to a geo and shades list.\"\"\"\n geo.append(from_face3d(face.punched_geometry))\n for ap in face.apertures:\n add_aperture(ap, geo, shades)\n for dr in face.doors:\n add_door(dr, geo, shades)\n for shd in face.shades:\n add_shade(shd, shades)\n\ndef add_room(room, geo, shades):\n \"\"\"Add Room geometry to a geo and shades list.\"\"\"\n face_breps = []\n for face in room.faces:\n add_face(face, face_breps, shades)\n for shd in room.shades:\n add_shade(shd, shades)\n geo.extend(rg.Brep.JoinBreps(face_breps, tolerance))\n\ndef add_model(model, geo, shades):\n \"\"\"Add Model geometry to a geo and shades list.\"\"\"\n for room in model.rooms:\n add_room(room, geo, shades)\n for face in model.orphaned_faces:\n add_face(face, geo, shades)\n for ap in model.orphaned_apertures:\n add_aperture(ap, geo, shades)\n for dr in model.orphaned_doors:\n add_door(dr, geo, shades)\n for shd in model.orphaned_shades:\n add_shade(shd, shades)\n for sm in model.shade_meshes:\n shades.append(from_mesh3d(sm.geometry))\n\n\nif all_required_inputs(ghenv.Component):\n # lists of {{cad}} geometry to be filled with content\n geo = []\n shades = []\n\n # loop through all objects and add them\n for hb_obj in _hb_objs:\n if isinstance(hb_obj, Room):\n add_room(hb_obj, geo, shades)\n elif isinstance(hb_obj, Shade):\n add_shade(hb_obj, shades)\n elif isinstance(hb_obj, ShadeMesh):\n shades.append(from_mesh3d(hb_obj.geometry))\n elif isinstance(hb_obj, Face):\n add_face(hb_obj, geo, shades)\n elif isinstance(hb_obj, Aperture):\n add_aperture(hb_obj, geo, shades)\n elif isinstance(hb_obj, Door):\n add_door(hb_obj, geo, shades)\n elif isinstance(hb_obj, Model):\n add_model(hb_obj, geo, shades)\n else:\n raise TypeError(\n 'Unrecognized honeybee object type: {}'.format(type(hb_obj)))\n\n # group the shade geometry with the other objects\n geo.extend(shades)",
"code": "\ntry: # import the core ladybug_{{cad}} dependencies\n from ladybug_{{cad}}.fromhoneybee import from_hb_objects\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\n\n\nif all_required_inputs(ghenv.Component):\n geo = from_hb_objects(_hb_objs)\n",
"category": "Honeybee",
"name": "HB Visualize All",
"description": "Preview any Honeybee geometry object within the Rhino scene, including all\nsub-faces and assigned shades.\n-"
Expand Down
4 changes: 2 additions & 2 deletions honeybee_grasshopper_core/json/HB_Visualize_Wireframe.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.8.0",
"version": "1.8.1",
"nickname": "VizWireF",
"outputs": [
[
Expand All @@ -22,7 +22,7 @@
}
],
"subcategory": "1 :: Visualize",
"code": "\ntry: # import the core honeybee dependencies\n from honeybee.model import Model\n from honeybee.room import Room\n from honeybee.face import Face\n from honeybee.aperture import Aperture\n from honeybee.door import Door\n from honeybee.shade import Shade\n from honeybee.shademesh import ShadeMesh\nexcept ImportError as e:\n raise ImportError('\\nFailed to import honeybee:\\n\\t{}'.format(e))\n\ntry: # import the ladybug_{{cad}} dependencies\n from ladybug_{{cad}}.fromgeometry import from_face3d_to_wireframe, \\\n from_mesh3d_to_wireframe\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\n\ndef add_door(door, geo):\n \"\"\"Add Door geometry to a geo list.\"\"\"\n geo.extend(from_face3d_to_wireframe(door.geometry))\n for shd in door.shades:\n geo.extend(from_face3d_to_wireframe(shd.geometry))\n\ndef add_aperture(aperture, geo):\n \"\"\"Add Aperture geometry to a geo list.\"\"\"\n geo.extend(from_face3d_to_wireframe(aperture.geometry))\n for shd in aperture.shades:\n geo.extend(from_face3d_to_wireframe(shd.geometry))\n\ndef add_face(face, geo):\n \"\"\"Add Face geometry to a geo list.\"\"\"\n geo.extend(from_face3d_to_wireframe(face.geometry))\n for ap in face.apertures:\n add_aperture(ap, geo)\n for dr in face.doors:\n add_door(dr, geo)\n for shd in face.shades:\n geo.extend(from_face3d_to_wireframe(shd.geometry))\n\ndef add_room(room, geo):\n \"\"\"Add Room geometry to a geo list.\"\"\"\n for face in room.faces:\n add_face(face, geo)\n for shd in room.shades:\n geo.extend(from_face3d_to_wireframe(shd.geometry))\n\ndef add_model(model, geo):\n \"\"\"Add Model geometry to a geo list.\"\"\"\n for room in model.rooms:\n add_room(room, geo)\n for face in model.orphaned_faces:\n add_face(face, geo)\n for ap in model.orphaned_apertures:\n add_aperture(ap, geo)\n for dr in model.orphaned_doors:\n add_door(dr, geo)\n for shd in model.orphaned_shades:\n geo.extend(from_face3d_to_wireframe(shd.geometry))\n for sm in model.shade_meshes:\n geo.extend(from_mesh3d_to_wireframe(sm.geometry))\n\n\nif all_required_inputs(ghenv.Component):\n # list of {{cad}} geometry to be filled with content\n geo = []\n \n # loop through all objects and add them\n for hb_obj in _hb_objs:\n if isinstance(hb_obj, Room):\n add_room(hb_obj, geo)\n elif isinstance(hb_obj, Face):\n add_face(hb_obj, geo)\n elif isinstance(hb_obj, Aperture):\n add_aperture(hb_obj, geo)\n elif isinstance(hb_obj, Door):\n add_door(hb_obj, geo)\n elif isinstance(hb_obj, Shade):\n geo.extend(from_face3d_to_wireframe(hb_obj.geometry))\n elif isinstance(hb_obj, ShadeMesh):\n geo.extend(from_mesh3d_to_wireframe(hb_obj.geometry))\n elif isinstance(hb_obj, Model):\n add_model(hb_obj, geo)\n else:\n raise TypeError(\n 'Unrecognized honeybee object type: {}'.format(type(hb_obj)))",
"code": "\ntry: # import the ladybug_{{cad}} dependencies\n from ladybug_{{cad}}.fromhoneybee import from_hb_objects_to_wireframe\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\n\nif all_required_inputs(ghenv.Component):\n geo = from_hb_objects_to_wireframe(_hb_objs)\n",
"category": "Honeybee",
"name": "HB Visualize Wireframe",
"description": "Quickly preview any Honeybee geometry object as a wire frame within the Rhino\nscene, including all sub-faces and assigned shades.\n-"
Expand Down
95 changes: 3 additions & 92 deletions honeybee_grasshopper_core/src/HB Visualize All.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,107 +23,18 @@

ghenv.Component.Name = "HB Visualize All"
ghenv.Component.NickName = 'VizAll'
ghenv.Component.Message = '1.8.0'
ghenv.Component.Message = '1.8.1'
ghenv.Component.Category = 'Honeybee'
ghenv.Component.SubCategory = '1 :: Visualize'
ghenv.Component.AdditionalHelpFromDocStrings = "1"

try: # import the core honeybee dependencies
from honeybee.model import Model
from honeybee.room import Room
from honeybee.face import Face
from honeybee.aperture import Aperture
from honeybee.door import Door
from honeybee.shade import Shade
from honeybee.shademesh import ShadeMesh
except ImportError as e:
raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

try: # import the core ladybug_rhino dependencies
from ladybug_rhino.config import tolerance
from ladybug_rhino.fromgeometry import from_face3d, from_mesh3d
from ladybug_rhino.fromhoneybee import from_hb_objects
from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

import Rhino.Geometry as rg


def add_shade(shd, shades):
"""Add Shade geometry to a shades list."""
shades.append(from_face3d(shd.geometry))

def add_door(door, geo, shades):
"""Add Door geometry to a geo list and shades list."""
geo.append(from_face3d(door.geometry))
for shd in door.shades:
add_shade(shd, shades)

def add_aperture(aperture, geo, shades):
"""Add Aperture geometry to a geo and shades list."""
geo.append(from_face3d(aperture.geometry))
for shd in aperture.shades:
add_shade(shd, shades)

def add_face(face, geo, shades):
"""Add Face geometry to a geo and shades list."""
geo.append(from_face3d(face.punched_geometry))
for ap in face.apertures:
add_aperture(ap, geo, shades)
for dr in face.doors:
add_door(dr, geo, shades)
for shd in face.shades:
add_shade(shd, shades)

def add_room(room, geo, shades):
"""Add Room geometry to a geo and shades list."""
face_breps = []
for face in room.faces:
add_face(face, face_breps, shades)
for shd in room.shades:
add_shade(shd, shades)
geo.extend(rg.Brep.JoinBreps(face_breps, tolerance))

def add_model(model, geo, shades):
"""Add Model geometry to a geo and shades list."""
for room in model.rooms:
add_room(room, geo, shades)
for face in model.orphaned_faces:
add_face(face, geo, shades)
for ap in model.orphaned_apertures:
add_aperture(ap, geo, shades)
for dr in model.orphaned_doors:
add_door(dr, geo, shades)
for shd in model.orphaned_shades:
add_shade(shd, shades)
for sm in model.shade_meshes:
shades.append(from_mesh3d(sm.geometry))


if all_required_inputs(ghenv.Component):
# lists of rhino geometry to be filled with content
geo = []
shades = []

# loop through all objects and add them
for hb_obj in _hb_objs:
if isinstance(hb_obj, Room):
add_room(hb_obj, geo, shades)
elif isinstance(hb_obj, Shade):
add_shade(hb_obj, shades)
elif isinstance(hb_obj, ShadeMesh):
shades.append(from_mesh3d(hb_obj.geometry))
elif isinstance(hb_obj, Face):
add_face(hb_obj, geo, shades)
elif isinstance(hb_obj, Aperture):
add_aperture(hb_obj, geo, shades)
elif isinstance(hb_obj, Door):
add_door(hb_obj, geo, shades)
elif isinstance(hb_obj, Model):
add_model(hb_obj, geo, shades)
else:
raise TypeError(
'Unrecognized honeybee object type: {}'.format(type(hb_obj)))

# group the shade geometry with the other objects
geo.extend(shades)
geo = from_hb_objects(_hb_objs)
84 changes: 3 additions & 81 deletions honeybee_grasshopper_core/src/HB Visualize Wireframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,95 +23,17 @@

ghenv.Component.Name = 'HB Visualize Wireframe'
ghenv.Component.NickName = 'VizWireF'
ghenv.Component.Message = '1.8.0'
ghenv.Component.Message = '1.8.1'
ghenv.Component.Category = 'Honeybee'
ghenv.Component.SubCategory = '1 :: Visualize'
ghenv.Component.AdditionalHelpFromDocStrings = '1'

try: # import the core honeybee dependencies
from honeybee.model import Model
from honeybee.room import Room
from honeybee.face import Face
from honeybee.aperture import Aperture
from honeybee.door import Door
from honeybee.shade import Shade
from honeybee.shademesh import ShadeMesh
except ImportError as e:
raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e))

try: # import the ladybug_rhino dependencies
from ladybug_rhino.fromgeometry import from_face3d_to_wireframe, \
from_mesh3d_to_wireframe
from ladybug_rhino.fromhoneybee import from_hb_objects_to_wireframe
from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))


def add_door(door, geo):
"""Add Door geometry to a geo list."""
geo.extend(from_face3d_to_wireframe(door.geometry))
for shd in door.shades:
geo.extend(from_face3d_to_wireframe(shd.geometry))

def add_aperture(aperture, geo):
"""Add Aperture geometry to a geo list."""
geo.extend(from_face3d_to_wireframe(aperture.geometry))
for shd in aperture.shades:
geo.extend(from_face3d_to_wireframe(shd.geometry))

def add_face(face, geo):
"""Add Face geometry to a geo list."""
geo.extend(from_face3d_to_wireframe(face.geometry))
for ap in face.apertures:
add_aperture(ap, geo)
for dr in face.doors:
add_door(dr, geo)
for shd in face.shades:
geo.extend(from_face3d_to_wireframe(shd.geometry))

def add_room(room, geo):
"""Add Room geometry to a geo list."""
for face in room.faces:
add_face(face, geo)
for shd in room.shades:
geo.extend(from_face3d_to_wireframe(shd.geometry))

def add_model(model, geo):
"""Add Model geometry to a geo list."""
for room in model.rooms:
add_room(room, geo)
for face in model.orphaned_faces:
add_face(face, geo)
for ap in model.orphaned_apertures:
add_aperture(ap, geo)
for dr in model.orphaned_doors:
add_door(dr, geo)
for shd in model.orphaned_shades:
geo.extend(from_face3d_to_wireframe(shd.geometry))
for sm in model.shade_meshes:
geo.extend(from_mesh3d_to_wireframe(sm.geometry))


if all_required_inputs(ghenv.Component):
# list of rhino geometry to be filled with content
geo = []

# loop through all objects and add them
for hb_obj in _hb_objs:
if isinstance(hb_obj, Room):
add_room(hb_obj, geo)
elif isinstance(hb_obj, Face):
add_face(hb_obj, geo)
elif isinstance(hb_obj, Aperture):
add_aperture(hb_obj, geo)
elif isinstance(hb_obj, Door):
add_door(hb_obj, geo)
elif isinstance(hb_obj, Shade):
geo.extend(from_face3d_to_wireframe(hb_obj.geometry))
elif isinstance(hb_obj, ShadeMesh):
geo.extend(from_mesh3d_to_wireframe(hb_obj.geometry))
elif isinstance(hb_obj, Model):
add_model(hb_obj, geo)
else:
raise TypeError(
'Unrecognized honeybee object type: {}'.format(type(hb_obj)))
geo = from_hb_objects_to_wireframe(_hb_objs)
Binary file modified honeybee_grasshopper_core/user_objects/HB Visualize All.ghuser
Binary file not shown.
Binary file not shown.
Binary file modified samples/model_creation_workflows.gh
Binary file not shown.

0 comments on commit 84d01e1

Please sign in to comment.