Skip to content

Commit 6d32bb0

Browse files
committed
fix plane and simplify GeometryObject APIs
1 parent d5d00cc commit 6d32bb0

17 files changed

+58
-139
lines changed

scripts/plane.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from compas.geometry import Plane
2+
from compas_viewer import Viewer
3+
4+
viewer = Viewer()
5+
6+
plane = Plane([0, 0, 1], [0, 1, 1])
7+
8+
viewer.scene.add(plane, show_points=True)
9+
viewer.show()

src/compas_viewer/scene/brepobject.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
from typing import Optional
2-
31
from compas_occ.brep import OCCBrep
42

5-
from compas.datastructures import Mesh
63
from compas.geometry import Line
74
from compas.geometry import Point
85
from compas.scene import GeometryObject
@@ -33,16 +30,16 @@ def __init__(self, **kwargs):
3330
self._viewmesh, self._boundaries = self.geometry.to_tesselation(TOL.lineardeflection)
3431

3532
@property
36-
def points(self) -> Optional[list[Point]]:
33+
def points(self) -> list[Point]:
3734
return self.geometry.points
3835

3936
@property
40-
def lines(self) -> Optional[list[Line]]:
37+
def lines(self) -> list[Line]:
4138
lines = []
4239
for polyline in self._boundaries:
4340
lines += polyline.lines
4441
return lines
4542

4643
@property
47-
def viewmesh(self) -> Mesh:
48-
return self._viewmesh
44+
def viewmesh(self) -> tuple[list[Point], list[list[int]]]:
45+
return self._viewmesh.to_vertices_and_faces(triangulated=True)

src/compas_viewer/scene/circleobject.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Optional
2-
31
from compas.geometry import Circle
42
from compas.geometry import Line
53
from compas.geometry import Point
@@ -17,13 +15,9 @@ def __init__(self, **kwargs):
1715
self.show_lines = True
1816

1917
@property
20-
def points(self) -> Optional[list[Point]]:
18+
def points(self) -> list[Point]:
2119
return [self.geometry.center]
2220

2321
@property
24-
def lines(self) -> Optional[list[Line]]:
22+
def lines(self) -> list[Line]:
2523
return self.geometry.to_polyline(n=self.u).lines
26-
27-
@property
28-
def viewmesh(self):
29-
return None

src/compas_viewer/scene/ellipseobject.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Optional
2-
31
from compas.geometry import Ellipse
42
from compas.geometry import Line
53
from compas.geometry import Point
@@ -17,13 +15,9 @@ def __init__(self, **kwargs):
1715
self.show_lines = True
1816

1917
@property
20-
def points(self) -> Optional[list[Point]]:
18+
def points(self) -> list[Point]:
2119
return [self.geometry.plane.point]
2220

2321
@property
24-
def lines(self) -> Optional[list[Line]]:
22+
def lines(self) -> list[Line]:
2523
return self.geometry.to_polyline(n=self.u).lines
26-
27-
@property
28-
def viewmesh(self):
29-
return None

src/compas_viewer/scene/frameobject.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class FrameObject(ViewerSceneObject):
2828
2929
Attributes
3030
----------
31-
frame : :class:`compas.geometry.Frame`
31+
geometry : :class:`compas.geometry.Frame`
3232
The frame geometry.
3333
dx : float
3434
The size of the grid in the X direction.
@@ -46,16 +46,14 @@ class FrameObject(ViewerSceneObject):
4646
:class:`compas.geometry.Frame`
4747
"""
4848

49+
item: Frame
50+
4951
def __init__(self, size: Optional[float] = 1, **kwargs):
5052
super().__init__(**kwargs)
5153
self.size = size
5254

53-
@property
54-
def frame(self):
55-
return self.item
56-
5755
def _read_lines_data(self) -> ShaderDataType:
58-
trans = Transformation.from_frame_to_frame(Frame.worldXY(), self.frame)
56+
trans = Transformation.from_frame_to_frame(Frame.worldXY(), self.item)
5957

6058
positions = []
6159
colors = []
@@ -83,12 +81,3 @@ def _read_lines_data(self) -> ShaderDataType:
8381
elements.append([4, 5])
8482

8583
return positions, colors, elements
86-
87-
def _read_points_data(self) -> Optional[ShaderDataType]:
88-
return None
89-
90-
def _read_frontfaces_data(self) -> Optional[ShaderDataType]:
91-
return None
92-
93-
def _read_backfaces_data(self) -> Optional[ShaderDataType]:
94-
return None

src/compas_viewer/scene/geometryobject.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1+
from typing import Iterable
12
from typing import Optional
23

34
from compas.colors import Color
4-
from compas.datastructures import Mesh
55
from compas.geometry import Geometry
6-
from compas.geometry import Line
7-
from compas.geometry import Point
86
from compas.itertools import flatten
97
from compas.scene import GeometryObject as BaseGeometryObject
108
from compas.scene.descriptors.color import ColorAttribute
@@ -74,16 +72,16 @@ def facecolor(self, color: Color) -> None:
7472
self.surfacecolor = color
7573

7674
@property
77-
def points(self) -> Optional[list[Point]]:
78-
raise NotImplementedError
75+
def points(self) -> Optional[list[Iterable[float]]]:
76+
return None
7977

8078
@property
81-
def lines(self) -> Optional[list[Line]]:
82-
raise NotImplementedError
79+
def lines(self) -> Optional[list[Iterable[Iterable[float]]]]:
80+
return None
8381

8482
@property
85-
def viewmesh(self) -> Mesh:
86-
raise NotImplementedError
83+
def viewmesh(self) -> Optional[tuple[list[Iterable[float]], list[Iterable[int]]]]:
84+
return None
8785

8886
def _read_points_data(self) -> ShaderDataType:
8987
if self.points is None:
@@ -106,14 +104,14 @@ def _read_lines_data(self) -> ShaderDataType:
106104
def _read_frontfaces_data(self) -> ShaderDataType:
107105
if self.viewmesh is None:
108106
return [], [], []
109-
positions, elements = self.viewmesh.to_vertices_and_faces()
107+
positions, elements = self.viewmesh
110108
colors = [self.facecolor] * len(positions)
111109
return positions, colors, elements # type: ignore
112110

113111
def _read_backfaces_data(self) -> ShaderDataType:
114112
if self.viewmesh is None:
115113
return [], [], []
116-
positions, elements = self.viewmesh.to_vertices_and_faces()
114+
positions, elements = self.viewmesh
117115
for element in elements:
118116
element.reverse()
119117
colors = [self.facecolor] * len(positions)

src/compas_viewer/scene/graphobject.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,3 @@ def _read_lines_data(self) -> ShaderDataType:
3838
elements.append([i + 0, i + 1])
3939
i += 2
4040
return positions, colors, elements
41-
42-
def _read_frontfaces_data(self):
43-
pass
44-
45-
def _read_backfaces_data(self):
46-
pass

src/compas_viewer/scene/lineobject.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,3 @@ def points(self) -> Optional[list[Point]]:
2222
@property
2323
def lines(self) -> Optional[list[Line]]:
2424
return [self.geometry]
25-
26-
@property
27-
def viewmesh(self):
28-
return None

src/compas_viewer/scene/nurbscurveobject.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from typing import Optional
22

3-
from compas.datastructures import Mesh
43
from compas.geometry import Line
54
from compas.geometry import NurbsCurve
65
from compas.geometry import Point
@@ -25,7 +24,3 @@ def lines(self) -> Optional[list[Line]]:
2524
for pair in pairwise(polyline.points):
2625
lines.append(Line(*pair))
2726
return lines
28-
29-
@property
30-
def viewmesh(self) -> Optional[Mesh]:
31-
pass

src/compas_viewer/scene/nurbssurfaceobject.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
from typing import Optional
2-
31
from compas_occ.brep import OCCBrep
42

5-
from compas.datastructures import Mesh
63
from compas.geometry import Line
74
from compas.geometry import NurbsSurface
85
from compas.geometry import Point
@@ -23,11 +20,11 @@ def __init__(self, **kwargs):
2320
self._viewmesh, self._boundaries = self._brep.to_tesselation(TOL.lineardeflection)
2421

2522
@property
26-
def points(self) -> Optional[list[Point]]:
23+
def points(self) -> list[Point]:
2724
return self._brep.points
2825

2926
@property
30-
def lines(self) -> Optional[list[Line]]:
27+
def lines(self) -> list[Line]:
3128
lines = []
3229
for polyline in self._boundaries:
3330
for pair in pairwise(polyline.points):
@@ -36,5 +33,5 @@ def lines(self) -> Optional[list[Line]]:
3633
return lines
3734

3835
@property
39-
def viewmesh(self) -> Mesh:
40-
return self._viewmesh
36+
def viewmesh(self) -> tuple[list[Point], list[list[int]]]:
37+
return self._viewmesh.to_vertices_and_faces(triangulated=True)

0 commit comments

Comments
 (0)