Skip to content

Commit

Permalink
Add skline examples
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffder committed May 1, 2023
1 parent 7886391 commit 8243669
Show file tree
Hide file tree
Showing 37 changed files with 188 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ _opam/
_esy/

examples/scads
examples/pngs/incl_*.png
1 change: 1 addition & 0 deletions docs/index.mld
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ should serve as a helpful reference.

{2 Skins and Morphs}
- {{!page-"profile_skinning"} {b Profile skinning}}
- {{!page-"spline_skinning"} {b Continuous skinning with Bézier splines}}
- {{!page-"morphing_sweeps"} {b Morphing sweeps and extrusions}}

{2 Function Plotting}
Expand Down
2 changes: 1 addition & 1 deletion examples/docs/morphing_sweeps.mld
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let () =
V3.[ v 0. 0. 2.; v 0. 20. 20.; v 40. 20. 10.; v 30. 0. 10. ]
|> Path3.quaternion (Quaternion.make (v3 1. 1. 0.) (Float.pi /. -5.))
in
Bezier3.curve ~fn:60 @@ Bezier3.of_path ~size:(`Flat (`Rel 0.3)) control
Bezier3.curve ~fn:80 @@ Bezier3.of_path ~size:(`Flat (`Rel 0.3)) control
and caps =
Mesh.Cap.(capped ~bot:(round @@ circ (`Radius 0.5)) ~top:(round @@ circ (`Radius 0.5)))
and a = Poly2.ring ~fn:5 ~thickness:(v2 2.5 2.5) (v2 6. 6.)
Expand Down
12 changes: 0 additions & 12 deletions examples/docs/profile_skinning.mld
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,3 @@ let () =
<img src="_assets/vaccum_connector.png" style="width:150mm;"/>
</p> %}


{[
let () =
Mesh.skin
~refine:2
~slices:(`Flat 25)
~mapping:(`Flat `Tangent)
Path3.[ circle ~fn:5 4.; translate (v3 0. 0. 3.) @@ circle ~fn:80 2. ]
|> Scad.of_mesh
|> Scad.to_file "tangent_skin_test.scad"
]}

96 changes: 96 additions & 0 deletions examples/docs/spline_skinning.mld
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{0 Bézier Sklines}

{[
open OCADml
open OSCADml
]}

{{!OCADml.Mesh.skline} [Mesh.skline]}, like {{!OCADml.Mesh.skin}
[Mesh.skin]} provides a means of generating a mesh that covers a series of
given profiles, but where [skin] linearly transistions between each profile
independently, [skline] splines through each of the paths formed by the
associated vertices from the first profile to the last (or in a loop).
to generate meshes that cover over series of profiles. However, unlike
[skin] only resampling is made available for mapping vertices between
incomensurate profiles as the point duplication methods (tangent and
distance) can easily lead to edge intersections.

{[
let handle_profiles =
let circ = Path3.circle ~fn:64 5. in
let base = Path3.scale (v3 1.2 1.2 1.) circ
and handle = Path3.scale (v3 0.7 0.7 1.) circ in
Path3.
[ ztrans (-3.) base
; circ
; translate (v3 15. 0. 20.) (yrot (Float.pi /. 2.) handle)
; xtrans 30. (yrot Float.pi circ)
; translate (v3 30. 0. (-3.)) (yrot Float.pi base)
]
]}

A quick look at the points of our profiles we are about to spline over with
alternating colours may help a bit to conceptualize what we are about to
give {{!OCADml.Mesh.skline} [Mesh.skline]} to work with.

{[
let () =
let show i =
let c = if i mod 2 = 0 then Color.Magenta else Color.Aquamarine in
Debug.show_path3 (fun _ -> Scad.(color c @@ sphere 0.2))
in
List.mapi show handle_profiles |> Scad.union |> Scad.to_file "handle_points.scad"
]}

{%html:
<p style="text-align:center;">
<img src="_assets/handle_points.png" style="width:150mm;"/>
</p> %}

Using the [?tangents] parameter of {{!OCADml.Bezier3.of_path}
[Bezier3.of_path]} we can specify the tangents we want for each profile,
rather than leaving them up to the automatically computed derivatives (that
may differ for each edge path tracing between the profiles). Here we
contstrain them to cardinals so we can get a handle that sticks closer to
right angles.

{[
let () =
let up = v3 0. 0. 1. in
let tangents = `Tangents [ up; up; v3 1. 0. 0.; V3.neg up; V3.neg up ] in
Mesh.skline ~fn:200 ~size:(`Flat (`Rel 0.5)) ~tangents handle_profiles
|> Scad.of_mesh
|> Scad.to_file ~incl:true "handle_skline.scad"
]}

{%html:
<p style="text-align:center;">
<img src="_assets/handle_skline.png" style="width:150mm;"/>
</p> %}

As mentioned above, continuous curvature loops are also possible. Here we
morph cyclically through circular and pentagonal profiles by specifying
[~endcaps:`Loop].

{[
let () =
let circ = Path3.circle ~fn:64 5. in
let pent = Path3.(circle ~fn:5 5.) in
let profs =
Path3.
[ circ
; translate (v3 15. 0. 20.) (yrot (Float.pi /. 2.) pent)
; xtrans 30. (yrot Float.pi circ)
; translate (v3 15. 0. (-20.)) (yrot (Float.pi *. 1.5) pent)
]
in
Mesh.skline ~endcaps:`Loop ~fn:200 ~size:(`Flat (`Rel 0.1)) profs
|> Scad.of_mesh
|> Scad.to_file ~incl:true "edgy_loop.scad"
]}

{%html:
<p style="text-align:center;">
<img src="_assets/edgy_loop.png" style="width:150mm;"/>
</p> %}

1 change: 1 addition & 0 deletions examples/dune
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
resampled_path
default_vs_euler_sweeps
profile_skinning
spline_skinning
morphing_sweeps)
(libraries OSCADml OCADml.PolyText))

Expand Down
2 changes: 1 addition & 1 deletion examples/morphing_sweeps.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let () =
V3.[ v 0. 0. 2.; v 0. 20. 20.; v 40. 20. 10.; v 30. 0. 10. ]
|> Path3.quaternion (Quaternion.make (v3 1. 1. 0.) (Float.pi /. -5.))
in
Bezier3.curve ~fn:60 @@ Bezier3.of_path ~size:(`Flat (`Rel 0.3)) control
Bezier3.curve ~fn:80 @@ Bezier3.of_path ~size:(`Flat (`Rel 0.3)) control
and caps =
Mesh.Cap.(capped ~bot:(round @@ circ (`Radius 0.5)) ~top:(round @@ circ (`Radius 0.5)))
and a = Poly2.ring ~fn:5 ~thickness:(v2 2.5 2.5) (v2 6. 6.)
Expand Down
Binary file modified examples/pngs/arc_points_2d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/arc_points_3d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/arc_wedge_2d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/bezier_spline_path.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/cartesian_gravity_well.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/chamfered_loop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/chamfered_square_with_holes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/circular_rounding.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/pngs/edgy_loop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/elbow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/pngs/handle_points.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/pngs/handle_skline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/helix_extrude.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/helix_path_points.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/incl_polar_rose.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/offset_poly.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/polar_rose.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/resampled_path.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/rounded_polyhole_sweep.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/rounded_prism_star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/spiral.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/sweep_path_default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/sweep_path_euler.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/sweep_starburst_default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/sweep_starburst_euler.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/pngs/tangent_morph_sweep.png
Binary file removed examples/pngs/tangent_skin_test.png
Diff not rendered.
Binary file modified examples/pngs/test_hull_3d.png
9 changes: 0 additions & 9 deletions examples/profile_skinning.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,3 @@ let () =
<img src="_assets/vaccum_connector.png" style="width:150mm;"/>
</p> %}
*)

let () =
Mesh.skin
~refine:2
~slices:(`Flat 25)
~mapping:(`Flat `Tangent)
Path3.[ circle ~fn:5 4.; translate (v3 0. 0. 3.) @@ circle ~fn:80 2. ]
|> Scad.of_mesh
|> Scad.to_file "tangent_skin_test.scad"
87 changes: 87 additions & 0 deletions examples/spline_skinning.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
(** {0 Bézier Sklines} *)

open OCADml
open OSCADml

(** {{!OCADml.Mesh.skline} [Mesh.skline]}, like {{!OCADml.Mesh.skin}
[Mesh.skin]} provides a means of generating a mesh that covers a series of
given profiles, but where [skin] linearly transistions between each profile
independently, [skline] splines through each of the paths formed by the
associated vertices from the first profile to the last (or in a loop).
to generate meshes that cover over series of profiles. However, unlike
[skin] only resampling is made available for mapping vertices between
incomensurate profiles as the point duplication methods (tangent and
distance) can easily lead to edge intersections. *)

let handle_profiles =
let circ = Path3.circle ~fn:64 5. in
let base = Path3.scale (v3 1.2 1.2 1.) circ
and handle = Path3.scale (v3 0.7 0.7 1.) circ in
Path3.
[ ztrans (-3.) base
; circ
; translate (v3 15. 0. 20.) (yrot (Float.pi /. 2.) handle)
; xtrans 30. (yrot Float.pi circ)
; translate (v3 30. 0. (-3.)) (yrot Float.pi base)
]

(** A quick look at the points of our profiles we are about to spline over with
alternating colours may help a bit to conceptualize what we are about to
give {{!OCADml.Mesh.skline} [Mesh.skline]} to work with. *)
let () =
let show i =
let c = if i mod 2 = 0 then Color.Magenta else Color.Aquamarine in
Debug.show_path3 (fun _ -> Scad.(color c @@ sphere 0.2))
in
List.mapi show handle_profiles |> Scad.union |> Scad.to_file "handle_points.scad"

(** {%html:
<p style="text-align:center;">
<img src="_assets/handle_points.png" style="width:150mm;"/>
</p> %}
*)

(** Using the [?tangents] parameter of {{!OCADml.Bezier3.of_path}
[Bezier3.of_path]} we can specify the tangents we want for each profile,
rather than leaving them up to the automatically computed derivatives (that
may differ for each edge path tracing between the profiles). Here we
contstrain them to cardinals so we can get a handle that sticks closer to
right angles. *)

let () =
let up = v3 0. 0. 1. in
let tangents = `Tangents [ up; up; v3 1. 0. 0.; V3.neg up; V3.neg up ] in
Mesh.skline ~fn:200 ~size:(`Flat (`Rel 0.5)) ~tangents handle_profiles
|> Scad.of_mesh
|> Scad.to_file ~incl:true "handle_skline.scad"

(** {%html:
<p style="text-align:center;">
<img src="_assets/handle_skline.png" style="width:150mm;"/>
</p> %}
*)

(** As mentioned above, continuous curvature loops are also possible. Here we
morph cyclically through circular and pentagonal profiles by specifying
[~endcaps:`Loop]. *)

let () =
let circ = Path3.circle ~fn:64 5. in
let pent = Path3.(circle ~fn:5 5.) in
let profs =
Path3.
[ circ
; translate (v3 15. 0. 20.) (yrot (Float.pi /. 2.) pent)
; xtrans 30. (yrot Float.pi circ)
; translate (v3 15. 0. (-20.)) (yrot (Float.pi *. 1.5) pent)
]
in
Mesh.skline ~endcaps:`Loop ~fn:200 ~size:(`Flat (`Rel 0.1)) profs
|> Scad.of_mesh
|> Scad.to_file ~incl:true "edgy_loop.scad"

(** {%html:
<p style="text-align:center;">
<img src="_assets/edgy_loop.png" style="width:150mm;"/>
</p> %}
*)

0 comments on commit 8243669

Please sign in to comment.