-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH SceneObject for RigidBody, RobotModel and RobotCell
- Loading branch information
Showing
9 changed files
with
432 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
|
||
from compas_ghpython.drawing import draw_mesh | ||
from compas_rhino.conversions import transformation_to_rhino | ||
|
||
from compas_ghpython.scene import GHSceneObject as compas_ghpython_GHSceneObject | ||
|
||
from compas import IPY | ||
|
||
if not IPY: | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing import Optional # noqa: F401 | ||
from typing import List # noqa: F401 | ||
|
||
from compas.datastructures import Mesh # noqa: F401 | ||
from compas.geometry import Transformation # noqa: F401 | ||
|
||
|
||
class GHSceneObject(compas_ghpython_GHSceneObject): | ||
"""Base class for all GH scene objects.""" | ||
|
||
def _transform(self, native_mesh, transformation): | ||
# type: (object, Transformation) -> object | ||
T = transformation_to_rhino(transformation) | ||
native_mesh.Transform(T) | ||
return native_mesh | ||
|
||
def _create_geometry(self, geometry, name=None, color=None): | ||
# type: (Mesh, Optional[str], Optional[List[int]]) -> object | ||
"""Create the scene object representing one mesh geometry. | ||
Parameters | ||
---------- | ||
geometry : :class:`~compas.datastructures.Mesh` | ||
Instance of a mesh data structure | ||
name : str, optional | ||
The name of the mesh to draw. | ||
color : :class:`~compas.colors.Color` | ||
The color of the object.` | ||
Returns | ||
------- | ||
:rhino:`Rhino.Geometry.Mesh` | ||
""" | ||
mesh = geometry # type: Mesh | ||
color = color.rgba255 if color else None | ||
|
||
vertices, faces = geometry.to_vertices_and_faces(triangulated=False) | ||
mesh = draw_mesh(vertices, faces, color=color) | ||
|
||
# Try to fix invalid meshes | ||
if not mesh.IsValid: | ||
mesh.FillHoles() | ||
|
||
return mesh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,30 @@ | ||
# from compas.colors import ColorMap | ||
# from compas.scene import SceneObject | ||
from compas_ghpython.scene import GHSceneObject | ||
from compas.scene import SceneObject | ||
from compas_fab.scene import BaseRobotCellObject | ||
from .robot_model_object import RobotModelObject | ||
from .rigid_body_object import RigidBodyObject | ||
|
||
|
||
class RobotCellObject(BaseRobotCellObject, GHSceneObject): | ||
"""Scene object for drawing a RobotCell.""" | ||
class RobotCellObject(BaseRobotCellObject): | ||
"""Scene object for drawing a RobotCell in GHPython.""" | ||
|
||
pass | ||
def __init__(self, *args, **kwargs): | ||
super(RobotCellObject, self).__init__(*args, **kwargs) | ||
|
||
# Native Geometry handles | ||
self.robot_model_scene_object = None # type: RobotModelObject | ||
self.robot_model_scene_object = SceneObject( | ||
item=self.robot_cell.robot_model, | ||
sceneobject_type=RobotModelObject, | ||
) | ||
|
||
self.rigid_body_scene_objects = {} # type: dict[str, RigidBodyObject] | ||
for id, rigid_body in self.robot_cell.rigid_body_models.items(): | ||
self.rigid_body_scene_objects[id] = SceneObject( | ||
item=rigid_body, | ||
sceneobject_type=RigidBodyObject, | ||
) | ||
|
||
# self.tool_scene_objects = {} # type: dict[str, BaseToolObject] | ||
# for id, tool in self.robot_cell.tool_models.items(): | ||
# self.tool_scene_objects[id] = SceneObject(item=tool) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# from compas.colors import ColorMap | ||
# from compas.scene import SceneObject | ||
from .gh_scene_object import GHSceneObject | ||
from compas_fab.scene import BaseRobotModelObject | ||
|
||
|
||
# Overrides the RobotModelObject in compas_robot | ||
class RobotModelObject(GHSceneObject, BaseRobotModelObject): | ||
"""Scene object for drawing a Robot Model in GHPython.""" | ||
|
||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.