-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Animation] Improve adaptive sampling for splines
Makes the adaptive sampling scheme for subdividing spline segments more robust against control points that are almost coinciding. Previously, coinciding control points would result in infinite recursion in some cases.
- Loading branch information
Showing
10 changed files
with
342 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<DisableImplicitFSharpCoreReference>True</DisableImplicitFSharpCoreReference> | ||
<AssemblyName>$(MSBuildProjectName.Replace(" ", "_"))</AssemblyName> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<OutputPath>..\..\..\bin\Debug\</OutputPath> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<OutputPath>..\..\..\bin\Release\</OutputPath> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="AssemblyInfo.fs" /> | ||
<Compile Include="Model.fs" /> | ||
<Compile Include="App.fs" /> | ||
<Compile Include="Program.fs" /> | ||
<None Include="App.config" /> | ||
<None Include="paket.references" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\Aardvark.Service\Aardvark.Service.fsproj" /> | ||
<ProjectReference Include="..\..\Aardvark.UI.Primitives\Aardvark.UI.Primitives.fsproj" /> | ||
<ProjectReference Include="..\..\Aardvark.UI\Aardvark.UI.fsproj" /> | ||
</ItemGroup> | ||
<Import Project="..\..\..\.paket\Paket.Restore.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
module SplinesTest.App | ||
|
||
open Aardvark.Base | ||
open Aardvark.Rendering | ||
open Aardvark.Application | ||
open Aardvark.UI | ||
open Aardvark.UI.Animation | ||
open FSharp.Data.Adaptive | ||
open SplinesTest.Model | ||
|
||
[<AutoOpen>] | ||
module PointShaders = | ||
open FShade | ||
|
||
type UniformScope with | ||
member x.PointSize : float = uniform?PointSize | ||
|
||
module Semantic = | ||
let PointSize = Sym.ofString "PointSize" | ||
|
||
module Shader = | ||
type PointVertex = | ||
{ | ||
[<Position>] pos : V4d | ||
[<TexCoord; Interpolation(InterpolationMode.Sample)>] tc : V2d | ||
} | ||
|
||
let pointTransform (v: PointVertex) = | ||
vertex { | ||
return V4d(v.pos.XY * 2.0 - 1.0, 0.0, 1.0) | ||
} | ||
|
||
let camera = | ||
let view = CameraView.look V3d.Zero V3d.YAxis V3d.ZAxis | ||
let frustum = Frustum.perspective 90.0 0.1 100.0 1.0 | ||
AVal.constant <| Camera.create view frustum | ||
|
||
let addTolerance (delta: float) (model: Model) = | ||
{ model with ErrorTolerance = clamp Splines.MinErrorTolerance 0.2 (model.ErrorTolerance + delta) } | ||
|
||
let update (model: Model) (msg: Message) = | ||
match msg with | ||
| Add p -> | ||
{ model with Points = Array.append model.Points [| V2d(p.X, 1.0 - p.Y) |] } | ||
|
||
| OnKeyDown Keys.Delete -> | ||
{ model with Points = [||] } | ||
|
||
| OnKeyDown Keys.Back -> | ||
let n = max 0 (model.Points.Length - 1) | ||
{ model with Points = model.Points |> Array.take n} | ||
|
||
| OnKeyDown Keys.OemPlus -> | ||
model |> addTolerance 0.001 | ||
|
||
| OnKeyDown Keys.OemMinus -> | ||
model |> addTolerance -0.001 | ||
|
||
| OnWheel d-> | ||
model |> addTolerance (0.0001 * signum d.Y) | ||
|
||
| _ -> | ||
model | ||
|
||
let view (model: AdaptiveModel) = | ||
let p0 = RenderPass.main | ||
let p1 = p0 |> RenderPass.after "p1" RenderPassOrder.Arbitrary | ||
let p2 = p1 |> RenderPass.after "p1" RenderPassOrder.Arbitrary | ||
|
||
let renderPoints (pass: RenderPass) (color: C4f) (size: float) (points: aval<V2d[]>) = | ||
let points = | ||
points |> AVal.map(Seq.map v3f >> Seq.toArray) | ||
|
||
Sg.draw IndexedGeometryMode.PointList | ||
|> Sg.vertexAttribute DefaultSemantic.Positions points | ||
|> Sg.uniform' Semantic.PointSize size | ||
|> Sg.shader { | ||
do! Shader.pointTransform | ||
do! DefaultSurfaces.pointSprite | ||
do! DefaultSurfaces.pointSpriteFragment | ||
do! DefaultSurfaces.constantColor color | ||
} | ||
|> Sg.pass pass | ||
|
||
let sg = | ||
let splinePoints = | ||
model.Splines |> AVal.map (fun s -> | ||
s |> Array.collect (fun s -> | ||
let n = int <| s.Length * 512.0 | ||
Array.init n (fun i -> | ||
s.Evaluate <| float i / float (n - 1) | ||
) | ||
) | ||
) | ||
|> renderPoints p0 C4f.DarkRed 4.0 | ||
|
||
let controlPoints = model.Points |> renderPoints p1 C4f.AliceBlue 12.0 | ||
let samplePoints = model.Samples |> renderPoints p2 C4f.VRVisGreen 8.0 | ||
|
||
Sg.ofList [ controlPoints; samplePoints; splinePoints ] | ||
|
||
body [ | ||
style "width: 100%; height: 100%; border: 0; padding: 0; margin: 0; overflow: hidden" | ||
] [ | ||
renderControl camera [ | ||
style "width: 100%; height: 100%; border: 0; padding: 0; margin: 0; overflow: hidden" | ||
onMouseClickRel (fun _ p -> Add p) | ||
onKeyDown OnKeyDown | ||
onWheel OnWheel | ||
] sg | ||
|
||
div [style "position: absolute; left: 10px; top: 10px; color: white; pointer-events: none; font-family: monospace; font-size: larger;"] [ | ||
model.ErrorTolerance | ||
|> AVal.map (fun t -> $"Error tolerance: %.5f{t}") | ||
|> Incremental.text | ||
] | ||
] | ||
|
||
let app : App<_,_,_> = | ||
{ | ||
unpersist = Unpersist.instance | ||
threads = fun _ -> ThreadPool.empty | ||
initial = | ||
{ | ||
Points = [||] | ||
ErrorTolerance = 0.01 | ||
} | ||
update = update | ||
view = view | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
namespace _01___Inc.AssemblyInfo | ||
|
||
open System.Reflection | ||
open System.Runtime.CompilerServices | ||
open System.Runtime.InteropServices | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[<assembly: AssemblyTitle("01 - Inc")>] | ||
[<assembly: AssemblyDescription("")>] | ||
[<assembly: AssemblyConfiguration("")>] | ||
[<assembly: AssemblyCompany("")>] | ||
[<assembly: AssemblyProduct("01 - Inc")>] | ||
[<assembly: AssemblyCopyright("Copyright © 2018")>] | ||
[<assembly: AssemblyTrademark("")>] | ||
[<assembly: AssemblyCulture("")>] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[<assembly: ComVisible(false)>] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[<assembly: Guid("206c17a2-a3a1-4191-8ca3-da92197bb73b")>] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [<assembly: AssemblyVersion("1.0.*")>] | ||
[<assembly: AssemblyVersion("1.0.0.0")>] | ||
[<assembly: AssemblyFileVersion("1.0.0.0")>] | ||
|
||
do | ||
() |
Oops, something went wrong.