Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
derek-thomas
commited on
Commit
·
8ad27c3
1
Parent(s):
8683ed3
Trying to make it load faster by pre-loading meshes
Browse files- bootstrap.py +1 -1
- disc_golf_simulator.py +4 -3
- utilities/visualize.py +5 -8
bootstrap.py
CHANGED
@@ -3,7 +3,7 @@ import streamlit.web.bootstrap
|
|
3 |
from streamlit import config as _config
|
4 |
|
5 |
proj_dir = Path(__file__).parent
|
6 |
-
filename = proj_dir / "
|
7 |
|
8 |
_config.set_option("server.headless", True)
|
9 |
args = []
|
|
|
3 |
from streamlit import config as _config
|
4 |
|
5 |
proj_dir = Path(__file__).parent
|
6 |
+
filename = proj_dir / "disc_golf_simulator.py"
|
7 |
|
8 |
_config.set_option("server.headless", True)
|
9 |
args = []
|
disc_golf_simulator.py
CHANGED
@@ -4,7 +4,7 @@ from logging import getLogger
|
|
4 |
from pathlib import Path
|
5 |
|
6 |
from shotshaper.projectile import DiscGolfDisc
|
7 |
-
from utilities.visualize import get_plot,
|
8 |
|
9 |
# Define the default values
|
10 |
default_U = 24.2
|
@@ -49,15 +49,16 @@ def main():
|
|
49 |
value=default_pitch,
|
50 |
step=0.1)
|
51 |
|
52 |
-
with st.spinner(text="Calculating
|
53 |
pos = np.array((0, 0, z0))
|
54 |
disc_dict = DiscGolfDisc(disc_name)
|
55 |
|
56 |
-
stl_mesh =
|
57 |
fig = visualize_disc(stl_mesh, nose=nose, roll=roll)
|
58 |
|
59 |
st.markdown("""## Disc Orientation""")
|
60 |
st.plotly_chart(fig)
|
|
|
61 |
st.markdown("""## Flight Path""")
|
62 |
shot = disc_dict.shoot(speed=U, omega=omega, pitch=pitch,
|
63 |
position=pos, nose_angle=nose, roll_angle=roll)
|
|
|
4 |
from pathlib import Path
|
5 |
|
6 |
from shotshaper.projectile import DiscGolfDisc
|
7 |
+
from utilities.visualize import get_plot, get_subplots, visualize_disc, stl_meshes
|
8 |
|
9 |
# Define the default values
|
10 |
default_U = 24.2
|
|
|
49 |
value=default_pitch,
|
50 |
step=0.1)
|
51 |
|
52 |
+
with st.spinner(text="Calculating Disc Orientation..."):
|
53 |
pos = np.array((0, 0, z0))
|
54 |
disc_dict = DiscGolfDisc(disc_name)
|
55 |
|
56 |
+
stl_mesh = stl_meshes[disc_name]
|
57 |
fig = visualize_disc(stl_mesh, nose=nose, roll=roll)
|
58 |
|
59 |
st.markdown("""## Disc Orientation""")
|
60 |
st.plotly_chart(fig)
|
61 |
+
with st.spinner(text="Calculating Flight Path..."):
|
62 |
st.markdown("""## Flight Path""")
|
63 |
shot = disc_dict.shoot(speed=U, omega=omega, pitch=pitch,
|
64 |
position=pos, nose_angle=nose, roll_angle=roll)
|
utilities/visualize.py
CHANGED
@@ -1,26 +1,23 @@
|
|
1 |
import math
|
2 |
-
|
3 |
import numpy as np
|
4 |
import plotly.graph_objects as go
|
|
|
5 |
from plotly.colors import sequential
|
6 |
from stl.mesh import Mesh
|
7 |
|
8 |
from .extrema import find_extrema
|
9 |
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
Taken from https://community.plotly.com/t/view-3d-cad-data/16920/9
|
14 |
-
"""
|
15 |
-
stl_mesh = Mesh.from_file(stl_file)
|
16 |
-
return stl_mesh
|
17 |
|
18 |
|
19 |
def visualize_disc(stl_mesh, nose, roll):
|
20 |
"""
|
21 |
Taken from https://community.plotly.com/t/view-3d-cad-data/16920/9
|
22 |
"""
|
23 |
-
stl_mesh.rotate([1, 0, 0], math.radians(-1*nose))
|
24 |
stl_mesh.rotate([0, 1, 0], math.radians(roll))
|
25 |
# stl_mesh.rotate([0, 0, 1], math.radians(z_angle))
|
26 |
|
|
|
1 |
import math
|
|
|
2 |
import numpy as np
|
3 |
import plotly.graph_objects as go
|
4 |
+
from pathlib import Path
|
5 |
from plotly.colors import sequential
|
6 |
from stl.mesh import Mesh
|
7 |
|
8 |
from .extrema import find_extrema
|
9 |
|
10 |
+
proj_dir = Path(__file__).parents[1]
|
11 |
|
12 |
+
# Taken from https://community.plotly.com/t/view-3d-cad-data/16920/9
|
13 |
+
stl_meshes = {disc.stem: Mesh.from_file(disc) for disc in (proj_dir / 'shotshaper' / 'discs').glob('*.stl')}
|
|
|
|
|
|
|
|
|
14 |
|
15 |
|
16 |
def visualize_disc(stl_mesh, nose, roll):
|
17 |
"""
|
18 |
Taken from https://community.plotly.com/t/view-3d-cad-data/16920/9
|
19 |
"""
|
20 |
+
stl_mesh.rotate([1, 0, 0], math.radians(-1 * nose))
|
21 |
stl_mesh.rotate([0, 1, 0], math.radians(roll))
|
22 |
# stl_mesh.rotate([0, 0, 1], math.radians(z_angle))
|
23 |
|