Skip to content

Commit

Permalink
added beam scene object
Browse files Browse the repository at this point in the history
  • Loading branch information
chenkasirer committed Nov 7, 2024
1 parent 727ed30 commit 350deea
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/compas_cadwork/scene/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
from compas.plugins import plugin
from compas.scene import register

from compas_timber.elements import Beam

from .camera import Camera
from .scene import CadworkSceneObject
from .instructionobject import Text3dSceneObject
from .instructionobject import LinearDimensionSceneObject
from .beamobject import BeamSceneObject

__all__ = [
"Camera",
"CadworkSceneObject",
"Text3dSceneObject",
"LinearDimensionSceneObject",
"BeamSceneObject",
]


Expand All @@ -29,6 +33,7 @@ def after_draw(*args, **kwargs):

@plugin(category="factories", requires=[CONTEXT])
def register_scene_objects():
register(Beam, BeamSceneObject, context=CONTEXT)
try:
from compas_monosashi.sequencer import Text3d
from compas_monosashi.sequencer import LinearDimension
Expand Down
40 changes: 40 additions & 0 deletions src/compas_cadwork/scene/beamobject.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from compas_timber.elements import Beam

from compas_cadwork.conversions import point_to_cadwork
from compas_cadwork.conversions import vector_to_cadwork

import element_controller as ec
import attribute_controller as ac

from .scene import CadworkSceneObject


class BeamSceneObject(CadworkSceneObject):
"""Scene object for COMPAS Timber Beam objects.
Parameters
----------
item : :class:`compas_timber.elements.Beam`
The beam object.
"""

def __init__(self, item: Beam, **kwargs) -> None:
super().__init__(item)

def draw(self):
"""Draw the beam object in the scene.
Returns
-------
list
List of drawn element ids.
"""
beam = self._item
origin = point_to_cadwork(beam.frame.point)
xaxis = vector_to_cadwork(beam.frame.xaxis)
zaxis = vector_to_cadwork(beam.frame.normal)
element_id = ec.create_rectangular_beam_vectors(beam.width, beam.height, beam.length, origin, xaxis, zaxis)
beam.attributes["cadwork_id"] = element_id
beam.attributes["name"] = f"beam_{beam.guid}"
ac.set_name([element_id], beam.attributes["name"])
return [element_id]

0 comments on commit 350deea

Please sign in to comment.