Skip to content

Commit 28795c0

Browse files
WIP materialization Mesh from Thrust Diagram.
1 parent 774e25b commit 28795c0

File tree

2 files changed

+110
-6
lines changed

2 files changed

+110
-6
lines changed
1.44 MB
Loading

gitbook/next-steps/materialization.md

Lines changed: 110 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ The aim of this tutorial is to convert a RhinoVault session (a JSON file with a
1010

1111
## Pattern from RhinoVault Session
1212

13-
Before you start create a folder on your computer where you will store the `rhinovault_session.json` file as well as python example files. Then open Rhino Script Editor by command `ScriptEditor`. And copy-paste the code below that extracts the mesh pattern from the session file.
13+
<figure><img src="../.gitbook/assets/materialization_pattern.gif" alt=""><figcaption></figcaption></figure>
14+
15+
Before you start create a folder on your computer where you will store the `rhinovault_session.json` file as well as python example files. Then open Rhino Script Editor by command `ScriptEditor`. Add a new python file by clicking on the plus sign named `000.pattern.py`. Then copy-paste the code below that extracts the mesh pattern from the session file.
1416

1517
The session file employs the compas.scene data structure for storing: Pattern, FormDiagram, ThrustDiagram, and ForceDiagram. It also stores general settings for drawing and thrust-network analysis. We will use two attributes: Pattern and ThrustDiagram for mesh transformation into solid blocks. The scene also helps to visualize COMPAS items (geometry & data structures).
1618

1719
The first three comments are specific to Python in Rhino, indicating: a) `python3` specifies the language used, b) the code is written in the `brg-csd` environment, and c) `compas_rv` is a library requirement that must be installable from the Python Package Index (PyPI).
1820

1921

20-
<figure><img src="../.gitbook/assets/materialization_pattern.gif" alt=""><figcaption></figcaption></figure>
21-
22-
2322
```python
2423
#! python3
2524
# venv: brg-csd
@@ -46,6 +45,111 @@ scene.add(rv_scene.find_by_name("Pattern").mesh)
4645
scene.draw()
4746
```
4847

49-
## RhinoVault Session - ThrustDiagram
48+
## Mesh from Thrust Diagram
49+
50+
<figure><img src="../.gitbook/assets/materialization_thrust_diagram.png" alt=""><figcaption></figcaption></figure>
51+
52+
Let's create file called `001_thrust_diagram.py` in the script editor. The thrust diagram's mesh attribute is used as the base mesh for materialization. We need to delete mesh faces with the attribute `_is_loaded==False`, marked in red. After deletion, we will split the list of boundary vertices by support vertices and store them in the `borders` attribute. We will also store support points in the `supports` attribute. Be aware that the script does not handle multiple boundaries, and you may need to make your own modifications for other cases if the mesh topology is different. Finally, the mesh is serialized into JSON file called `001_mesh.json`.
53+
54+
In this step we will extract thrust-diagram.
55+
56+
```python
57+
#! python3
58+
# venv: brg-csd
59+
# r: compas_rv
60+
61+
import pathlib
62+
63+
import compas
64+
from compas.datastructures import Mesh
65+
from compas.scene import Scene
66+
from compas_tna.diagrams import FormDiagram
67+
from compas import json_dump
68+
from compas.itertools import pairwise
69+
70+
71+
def break_boundary(mesh: Mesh, breakpoints: list[int]) -> tuple[list[list[int]], list[int]]:
72+
73+
# Get the list of vertices on the boundary (first boundary from the mesh)
74+
boundary: list[int] = mesh.vertices_on_boundaries()[0]
75+
76+
# If the first and last vertices in the boundary are the same, remove the last vertex (close loop)
77+
if boundary[0] == boundary[-1]:
78+
del boundary[-1]
79+
80+
# Sort the breakpoints based on their index in the boundary
81+
breakpoints = sorted(breakpoints, key=lambda s: boundary.index(s))
82+
83+
# Find the starting point in the boundary for the first breakpoint
84+
start = boundary.index(breakpoints[0])
85+
86+
# Rearrange the boundary to start from the first breakpoint
87+
boundary = boundary[start:] + boundary[:start]
88+
89+
# Iterate over pairs of breakpoints and create sub-boundaries from the main boundary
90+
borders = []
91+
92+
for a, b in pairwise(breakpoints):
93+
start = boundary.index(a) # Find index of the first breakpoint in the boundary
94+
end = boundary.index(b) # Find index of the second breakpoint in the boundary
95+
borders.append(boundary[start : end + 1]) # Add the sub-boundary from start to end
96+
97+
# Add the last segment from the last breakpoint to the first one to close the loop
98+
borders.append(boundary[end:] + boundary[:1])
99+
100+
# Return the sub-boundaries and the breakpoints
101+
return borders, breakpoints
102+
103+
104+
# =============================================================================
105+
# Load data
106+
# =============================================================================
107+
108+
IFILE = pathlib.Path(__file__).parent / "rhinovault_session.json"
109+
110+
rv_session = compas.json_load(IFILE)
111+
rv_scene: Scene = rv_session["scene"]
112+
113+
thrustobject = rv_scene.find_by_name("ThrustDiagram")
114+
thrustdiagram: FormDiagram = thrustobject.mesh
115+
116+
# =============================================================================
117+
# Mesh
118+
#
119+
# - make a copy of the thrustdiagram
120+
# - remove the "TNA" faces cooresponding to boundary openings
121+
# - compute the average edge length for remeshing
122+
# =============================================================================
123+
124+
mesh: Mesh = thrustdiagram.copy(cls=Mesh)
125+
126+
# for face in list(mesh.faces_where(_is_loaded=False)):
127+
# mesh.delete_face(face)
128+
129+
# =============================================================================
130+
# Mesh: Borders
131+
# =============================================================================
132+
133+
supports = list(mesh.vertices_where(is_support=True))
134+
borders, supports = break_boundary(mesh, supports)
135+
print(borders)
136+
print(supports)
137+
138+
mesh.attributes["supports"] = supports
139+
mesh.attributes["borders"] = borders
140+
141+
# =============================================================================
142+
# Serialize
143+
# =============================================================================
50144

51-
In this step we will extract thrust-diagram.
145+
json_dump(mesh, pathlib.Path(__file__).parent / "001_mesh.json")
146+
147+
# =============================================================================
148+
# Visualisation
149+
# =============================================================================
150+
151+
scene = Scene()
152+
# scene.clear_context()
153+
scene.add(mesh)
154+
scene.draw()
155+
```

0 commit comments

Comments
 (0)