Skip to content

Commit

Permalink
cone mesh creation improved
Browse files Browse the repository at this point in the history
  • Loading branch information
ryichando committed Dec 27, 2024
1 parent 1773ef2 commit cd259c2
Show file tree
Hide file tree
Showing 22 changed files with 258 additions and 21 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/example_cards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ jobs:
- name: 5th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 6th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 7th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 8th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 9th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 10th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: shutdown
if: always()
run: bash $HELPER_PATH delete
15 changes: 15 additions & 0 deletions .github/workflows/example_curtain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ jobs:
- name: 5th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 6th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 7th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 8th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 9th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 10th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: shutdown
if: always()
run: bash $HELPER_PATH delete
15 changes: 15 additions & 0 deletions .github/workflows/example_drape.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ jobs:
- name: 5th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 6th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 7th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 8th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 9th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 10th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: shutdown
if: always()
run: bash $HELPER_PATH delete
15 changes: 15 additions & 0 deletions .github/workflows/example_friction.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ jobs:
- name: 5th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 6th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 7th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 8th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 9th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 10th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: shutdown
if: always()
run: bash $HELPER_PATH delete
15 changes: 15 additions & 0 deletions .github/workflows/example_hang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ jobs:
- name: 5th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 6th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 7th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 8th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 9th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 10th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: shutdown
if: always()
run: bash $HELPER_PATH delete
15 changes: 15 additions & 0 deletions .github/workflows/example_needle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ jobs:
- name: 5th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 6th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 7th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 8th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 9th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 10th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: shutdown
if: always()
run: bash $HELPER_PATH delete
15 changes: 15 additions & 0 deletions .github/workflows/example_stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ jobs:
- name: 5th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 6th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 7th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 8th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 9th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 10th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: shutdown
if: always()
run: bash $HELPER_PATH delete
15 changes: 15 additions & 0 deletions .github/workflows/example_trampoline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ jobs:
- name: 5th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 6th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 7th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 8th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 9th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 10th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: shutdown
if: always()
run: bash $HELPER_PATH delete
15 changes: 15 additions & 0 deletions .github/workflows/example_trapped.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ jobs:
- name: 5th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 6th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 7th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 8th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 9th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 10th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: shutdown
if: always()
run: bash $HELPER_PATH delete
15 changes: 15 additions & 0 deletions .github/workflows/template/example_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ jobs:
- name: 5th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 6th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 7th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 8th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 9th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: 10th run
run: bash $HELPER_PATH run ${EXAMPLE_NAME}.py

- name: shutdown
if: always()
run: bash $HELPER_PATH delete
2 changes: 1 addition & 1 deletion examples/cards.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"for i in reversed(range(n_stack)):\n",
" _x, _y = make_row(i+1, _x, _y)\n",
"\n",
"scene.add(\"sphere\").at(-2,1,0).velocity(2.3,0,0)\n",
"scene.add(\"sphere\").at(-2,1,0).jitter().velocity(2.3,0,0)\n",
"scene.add_invisible_wall([0,0,0],[0,1,0])\n",
"\n",
"fixed = scene.build().report()\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/curtain.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
" obj.direction([0,1,0],[0,0,1])\n",
" obj.pin(obj.grab([0, 1, 0]))\n",
"\n",
"scene.add(\"sphere\").at(-1, 0, 0).pin().move_by([8,0,0],5)\n",
"scene.add(\"sphere\").at(-1, 0, 0).jitter().pin().move_by([8,0,0],5)\n",
"\n",
"fixed = scene.build().report()\n",
"fixed.preview();"
Expand Down
4 changes: 2 additions & 2 deletions examples/drape.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
" # set fiber directions required for Baraff-Witkin\n",
" obj.direction([1, 0, 0], [0, 0, 1])\n",
"\n",
"# add a sphere mesh at a lower position and set it static collider\n",
"scene.add(\"sphere\").at(0, -0.5 - gap, 0).pin()\n",
"# add a sphere mesh at a lower position with jitter and set it static collider\n",
"scene.add(\"sphere\").at(0, -0.5 - gap, 0).jitter().pin()\n",
"\n",
"# compile the scene and report stats\n",
"fixed = scene.build().report()\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/friction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"\n",
"scene = app.scene.create(\"friction\")\n",
"armadillo = scene.add(\"armadillo\")\n",
"armadillo.rotate(180,\"y\").rotate(-90,\"x\").rotate(-30,\"z\").at(-5,3,-0.25)\n",
"armadillo.rotate(180,\"y\").rotate(-90,\"x\").rotate(-30,\"z\").at(-5,3,-0.25).jitter()\n",
"\n",
"deg = 180*np.arctan(0.5)/np.pi\n",
"scene.add(\"slope\").rotate(-deg,\"z\").pin()\n",
Expand Down
81 changes: 78 additions & 3 deletions examples/frontend/_mesh_.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,85 @@ def cylinder(self, r: float = 1, height: float = 2, n: int = 32) -> "TriMesh":

return self._from_o3d(o3d.geometry.TriangleMesh.create_cylinder(r, height, n))

def cone(self, r: float = 1, height: float = 2, n: int = 32) -> "TriMesh":
import open3d as o3d
def cone(
self,
Nr: int = 16,
Ny: int = 16,
Nb: int = 4,
radius: float = 0.5,
height: float = 2,
) -> "TriMesh":
V = [[0, 0, height], [0, 0, 0]]
T = []
ind_btm_center = 0
ind_tip = 1
offset = []
offset_btm = len(V)

for k in reversed(range(Ny)):
if k > 0:
r = k / (Ny - 1)
r = r * r
offset.append(len(V))
for i in range(Nr):
t = 2 * np.pi * i / Nr
x, y = radius * r * np.cos(t), radius * r * np.sin(t)
V.append([x, y, height * r])

for j in offset[0:-1]:
for i in range(Nr):
ind00, ind10 = i, (i + 1) % Nr
ind01, ind11 = ind00 + Nr, ind10 + Nr
if i % 2 == 0:
T.append([ind00 + j, ind01 + j, ind10 + j])
T.append([ind10 + j, ind01 + j, ind11 + j])
else:
T.append([ind00 + j, ind11 + j, ind10 + j])
T.append([ind00 + j, ind01 + j, ind11 + j])

j = offset[-1]
for i in range(Nr):
ind0, ind1 = i, (i + 1) % Nr
T.append([ind0 + j, ind_tip, ind1 + j])

offset = []
for k in reversed(range(Nb)):
if k > 0:
r = k / Nb
offset.append(len(V))
for i in range(Nr):
t = 2 * np.pi * i / Nr
x, y = radius * r * np.cos(t), radius * r * np.sin(t)
V.append([x, y, height])

for j in offset[0:-1]:
for i in range(Nr):
ind00, ind10 = i, (i + 1) % Nr
ind01, ind11 = ind00 + Nr, ind10 + Nr
if i % 2 == 0:
T.append([ind00 + j, ind10 + j, ind01 + j])
T.append([ind10 + j, ind11 + j, ind01 + j])
else:
T.append([ind00 + j, ind10 + j, ind11 + j])
T.append([ind00 + j, ind11 + j, ind01 + j])

j = offset[-1]
for i in range(Nr):
ind0, ind1 = i, (i + 1) % Nr
T.append([ind0 + j, ind1 + j, ind_btm_center])

j0, j1 = offset_btm, offset[0]
for i in range(Nr):
ind00, ind10 = i + j0, (i + 1) % Nr + j0
ind01, ind11 = i + j1, (i + 1) % Nr + j1
if i % 2 == 0:
T.append([ind00, ind10, ind01])
T.append([ind10, ind11, ind01])
else:
T.append([ind00, ind10, ind11])
T.append([ind00, ind11, ind01])

return self._from_o3d(o3d.geometry.TriangleMesh.create_cone(r, height, n))
return TriMesh.create(np.array(V), np.array(T), self._cache_dir)

def torus(self, r: float = 1, R: float = 0.25, n: int = 32) -> "TriMesh":
import open3d as o3d
Expand Down
11 changes: 10 additions & 1 deletion examples/frontend/_scene_.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ def __init__(self, asset: AssetManager, name: str):

def clear(self):
self._param = {}
self._at = [0, 0, 0]
self._at = [0.0, 0.0, 0.0]
self._scale = 1.0
self._rotation = np.eye(3)
self._color = []
Expand Down Expand Up @@ -896,6 +896,15 @@ def at(self, x: float, y: float, z: float) -> "Object":
self._at = [x, y, z]
return self

def jitter(self, r: float = 1e-2) -> "Object":
dx = np.random.random()
dy = np.random.random()
dz = np.random.random()
self._at[0] += r * dx
self._at[1] += r * dy
self._at[2] += r * dz
return self

def atop(self, object: "Object", margin: float = 0.0) -> "Object":
a_bbox, a_center = self.bbox()
b_bbox, b_center = object.bbox()
Expand Down
5 changes: 4 additions & 1 deletion examples/hang.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"jitter_time = 0.1 + 0.5 * random.random()\n",
"\n",
"param = app.session.param().set(\"dt\",0.001)\n",
"param.set(\"strain-limit-eps\", 0.005).set(\"strain-limit-tau\", 0.005)\n",
"param.set(\"frames\",200)\n",
"param.dyn(\"gravity\").time(1).hold().time(1.1).change(9.8).time(2.0).change(-9.8);"
"param.dyn(\"gravity\").time(1).hold().time(1+jitter_time).change(9.8).time(2.0).change(-9.8);"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/headless.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
obj.direction([0, 1, 0], [0, 0, 1])
obj.pin(obj.grab([0, 1, 0]))

scene.add("sphere").at(-1, 0, 0).pin().move_by([8, 0, 0], 5)
scene.add("sphere").at(-1, 0, 0).jitter().pin().move_by([8, 0, 0], 5)
fixed = scene.build()

param = app.session.param()
Expand Down
Loading

0 comments on commit cd259c2

Please sign in to comment.