Skip to content

Commit

Permalink
Initial design
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeicor committed Jun 2, 2024
0 parents commit 9854fef
Show file tree
Hide file tree
Showing 9 changed files with 1,336 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch: { }

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: "write"
pages: "write"
id-token: "write"

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
build-and-deploy:

runs-on: "ubuntu-latest"

environment:
name: "github-pages"
url: "${{ steps.deployment.outputs.page_url }}"

steps:
# Prepare
- uses: "actions/checkout@v4"
with:
lfs: "true"
- run: "pip install poetry"
- uses: "actions/setup-python@v5"
with:
python-version: "3.12"
cache: "poetry"
- run: "poetry install"

# Build
- run: "printf 'YACV_DISABLE_SERVER=True\nexport_yacv=True\nexport_step=True\nexport_stl=True\n' >> $GITHUB_ENV"
- run: "poetry run python main.py"
- run: "final=True poetry run python main.py"
- run: "mkdir export && mv *.glb *.stl *.step export/"

# Deploy
- uses: "actions/configure-pages@v5"
- uses: "actions/upload-pages-artifact@v3"
with:
path: 'export'
- id: "deployment"
uses: "actions/deploy-pages@v4"
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# IDE
/*.iml
/.idea/

# Outputs
/*.stl
/*.step
/*.glb
!/reference.glb

# Python
/venv/
/__pycache__/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Yeicor

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Bike fork cap

You can download the latest builds from the [workflow runs](https://github.com/Yeicor-3d/bike-fork-cap/actions/workflows/main.yml).

You can preview the models in an interactive demo by clicking the URL in the about section of the project.
160 changes: 160 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import os
from math import *

from build123d import *
from build123d import export_stl

# %%

# General parameters
tol = 0.2 * MM # Tolerance for operations
eps = 0.0001 * MM # Epsilon for operations
min_wall = 0.4 * MM # Minimum wall thickness on XY (common for FDM 3D printing)
wall = 3 * min_wall # perimeters on XY

# Bike fork cap parameters
cap_radius = 40.5 / 2 * MM
cap_height = 42 * MM # Including the head
cap_head_radius = 45 / 2 * MM
cap_head_height = 15 * MM
cap_to_support_taper = -5 # degrees
cap_support_top_offset = -4 * MM
cap_support_profile = import_svg('profile.svg', is_inkscape_label=True).wire()
cap_support_length = 2 * CM
cap_support_angle = 30 # degrees
cap_cut_hole_radius = 0 # 4 * MM
cap_cut_hole_offset_xz = (-13 * MM, -(cap_cut_hole_radius + wall) * MM)


def core_filled(offset: float = 0):
with BuildPart() as _core_filled: # Useful to offset a wrapper and to cut the support!
with BuildSketch():
Circle(cap_radius + offset)
shank_height = cap_height - cap_head_height
shank_height_flat = shank_height_tapered = shank_height / 2
extrude(amount=shank_height_flat)
shank_taper_angle = degrees(-atan2(cap_head_radius - cap_radius, shank_height_tapered))
extrude(faces().group_by(Axis.Z)[-1], amount=shank_height_tapered, taper=shank_taper_angle)
extrude(faces().group_by(Axis.Z)[-1], amount=cap_head_height + offset)
split(bisect_by=Plane.YZ, keep=Keep.BOTTOM) # Rectangular support half
extrude(faces().group_by(Axis.X)[-1], amount=cap_head_radius + offset, taper=cap_to_support_taper)
cap_hole_sketch_to_cut = None
if cap_cut_hole_radius > 0:
bb = _core_filled.part.bounding_box()
with BuildSketch(Plane.XZ.shift_origin(
(bb.max.X + cap_cut_hole_offset_xz[0], 0, bb.max.Z + cap_cut_hole_offset_xz[1])).offset(
-(bb.min.Y - wall))) as cap_hole_sketch_to_cut:
Circle(cap_cut_hole_radius)
Rectangle(2 * cap_cut_hole_radius, bb.size.Z, align=(Align.CENTER, Align.MAX))
return _core_filled, cap_hole_sketch_to_cut


with BuildLine() as support_line:
bb = cap_support_profile.bounding_box()
add(cap_support_profile.translate((-bb.min.X, -(bb.max.Y + wall))))
mirror(about=Plane.YZ)
del cap_support_profile

core_filled_base, cap_hole_sketch_to_cut = core_filled()
core_filled_extra = core_filled(wall)[0]
m = core_filled_base.part.bounding_box().max
support_loc = Pos(m.X, 0, m.Z + cap_support_top_offset) * Plane.YZ.location
extrude_dir = Vector(cos(radians(cap_support_angle)), 0, sin(radians(cap_support_angle))).normalized()
extrude_in_length = wall / cos(radians(cap_support_angle))
with BuildPart() as support_cut:
with BuildSketch(support_loc) as sk:
with BuildLine():
add(support_line)
min_x_point = support_line.line.vertices().group_by(Axis.X)[0].group_by(Axis.Z)[0].vertex().center()
max_x_point = support_line.line.vertices().group_by(Axis.X)[-1].group_by(Axis.Z)[0].vertex().center()
min_conn = support_line.line @ 0
max_conn = support_line.line @ 1
Polyline(min_conn,
Vector(min_x_point.X, min_conn.Y, min_x_point.Z),
min_x_point - Vector(0, cap_height, 0),
max_x_point - Vector(0, cap_height, 0),
Vector(max_x_point.X, max_conn.Y, max_x_point.Z),
max_conn)
make_face()
extrude(sk.sketch, amount=extrude_in_length, dir=-extrude_dir, both=True)
del sk

with BuildPart() as support:
with BuildSketch(support_loc) as sk:
with BuildLine():
add(support_line)
inside_wire = Wire(edges())
offset(amount=wall, side=Side.RIGHT) # Make sure this side is the outside...
outside_wire = Wire([e for e in edges() if min([e.distance(e2) for e2 in inside_wire.edges()]) > eps])
make_face()
with BuildLine(): # Round the corners
p1 = outside_wire @ 0
p2 = inside_wire @ 1
t1 = -(outside_wire % 0)
a = JernArc(p1, t1, (p2 - p1).length / 2, 180)
if (a @ 1 - p2).length > eps:
Line(a @ 1, p2)
Line(p2, p1)
make_face()
with BuildLine(): # Round the corners
p1 = inside_wire @ 0
p2 = outside_wire @ 1
t1 = -(inside_wire % 0)
a = JernArc(p1, t1, (p2 - p1).length / 2, 180)
if (a @ 1 - p2).length > eps:
Line(a @ 1, p2)
Line(p2, p1)
make_face()
del inside_wire, outside_wire
extrude(sk.sketch, amount=cap_support_length, dir=extrude_dir)
del sk
loft_base = faces().group_by(Axis.X)[-1].face()
bb = loft_base.bounding_box()
rotate_from = Vector(bb.center().X, bb.center().Y, bb.max.Z)
assert fabs(rotate_from.Y) <= eps, rotate_from
loft_top = loft_base.rotate(Axis(rotate_from, Vector(0, 1, 0)), -cap_support_angle)
loft_top = loft_top.translate( # HACK!
(0, 0, (bb.size.Z - loft_top.bounding_box().size.Z) / 2))
loft([loft_base, loft_top])
del loft_base, loft_top
add(core_filled_base, mode=Mode.SUBTRACT)
del support_line, support_loc

with (BuildPart() as bike_fork_cap):
add(core_filled_extra)
add(core_filled_base, mode=Mode.SUBTRACT) # HACK: alternative to offset that does not crash
del core_filled_extra, core_filled_base
add(support_cut, mode=Mode.SUBTRACT)
del support_cut
bb = bike_fork_cap.part.bounding_box()
cut_from_support = Box(bb.size.X, bb.size.Y, bb.size.Z, align=Align.MAX, mode=Mode.PRIVATE
).translate((bb.max.X, bb.max.Y, bb.min.Z))
add(support.part - cut_from_support)
del support, cut_from_support
if cap_hole_sketch_to_cut is not None:
add(extrude(to_extrude=cap_hole_sketch_to_cut.sketch, amount=-cap_head_radius), mode=Mode.SUBTRACT)
del cap_hole_sketch_to_cut

# -- export/show boilerplate --

if os.getenv('export_stl'):
print('Exporting STL file...')
export_stl(bike_fork_cap.part, 'bike_fork_cap.stl')

if os.getenv('export_step'):
print('Exporting STEP file...')
export_step(bike_fork_cap.part, 'bike_fork_cap.step')

try:
from yacv_server import *

show_all()

with open('reference.glb', 'rb') as f:
show(f.read(), names=['reference'], auto_clear=False)

if os.getenv('export_yacv'):
print('Exporting YACV file...')
export_all('.', lambda name, obj: name == 'bike_fork_cap')
except BaseException as e:
print(f'yacv_server not found or another error happened, skipping visualization: {e}')
Loading

0 comments on commit 9854fef

Please sign in to comment.