1
+ namespace PRo3D.Core
2
+
3
+ open System
4
+ open FSharp.Data .Adaptive
5
+ open Aardvark.Base
6
+ open Aardvark.Rendering
7
+ open Aardvark.Rendering .Text
8
+ open Aardvark.FontProvider
9
+ open Aardvark.SceneGraph
10
+
11
+ open PRo3D.SPICE
12
+
13
+ module Markers =
14
+
15
+ type Font = GoogleFontProvider< " Roboto Mono" >
16
+ let font = Font.Font
17
+
18
+ let markers ( cam : aval < Camera >) ( referenceFrame : aval < string >) ( observer : aval < string >) ( time : aval < DateTime >) =
19
+ let viewProj = cam |> AVal.map Camera.viewProjTrafo
20
+ let aspect = cam |> AVal.map ( fun c -> Frustum.aspect c.frustum)
21
+ let aspectScaling = aspect |> AVal.map ( fun aspect -> Trafo3d.Scale( V3d( 1.0 , aspect, 1.0 )))
22
+ let inNdcBox =
23
+ let box = Box3d.FromPoints( V3d(- 1 ,- 1 ,- 1 ), V3d( 1 , 1 , 1 ))
24
+ fun ( p : V3d ) -> box.Contains p
25
+
26
+ let transformation =
27
+ Rendering.fullTrafo referenceFrame ( AVal.constant " SUN" ) " MARS" ( Some " IAU_MARS" ) observer time
28
+ |> AVal.map ( fun trafo ->
29
+ match trafo with
30
+ | Some trafo -> trafo, true
31
+ | _ ->
32
+ Log.warn " could not get trafo for body %s " " MARS"
33
+ Trafo3d.Identity, false
34
+ )
35
+
36
+ let elems =
37
+ MarsTaggedLocations.taggedLocations
38
+ |> List.choose ( fun ( name , ( lat , lon )) ->
39
+ match CooTransformation.latLon2Xyz " MARS" ( lat, lon, 0.0 ), CooTransformation.latLon2Xyz " MARS" ( lat, lon, 500000.0 ) with
40
+ | Some p0, Some p1 ->
41
+ let text =
42
+ let contents =
43
+ Array.ofList [
44
+ let p =
45
+ AVal.custom ( fun t ->
46
+ let referenceFrame = referenceFrame.GetValue( t)
47
+ let time = time.GetValue( t)
48
+ let marsToGlobal = CooTransformation.getRotationTrafo " IAU_MARS" referenceFrame time |> Option.get
49
+ let bodyPos = marsToGlobal.TransformPos( p1) |> Some
50
+ let vp = viewProj.GetValue t
51
+ let scale = aspectScaling.GetValue t
52
+ match bodyPos with
53
+ | None -> Trafo3d.Scale( 0.0 )
54
+ | Some p ->
55
+ let ndc = vp.Forward.TransformPosProj ( p)
56
+ let scale = if inNdcBox ndc then scale else Trafo3d.Scale( 0.0 )
57
+ Trafo3d.Scale( 0.03 ) * scale * Trafo3d.Translation( ndc.XYZ)
58
+ )
59
+ p, AVal.constant name
60
+ ]
61
+ Sg.texts font C4b.DarkOrange ( ASet.ofArray contents)
62
+
63
+ let global2Local = Trafo3d.Translation( p0)
64
+ let line =
65
+ [|
66
+ Line3d( p0, p1) .Transformed( global2Local.Backward)
67
+ |]
68
+ let line =
69
+ Sg.lines' C4b.DarkOrange line
70
+ |> Sg.trafo' global2Local
71
+ |> Sg.trafo ( transformation |> AVal.map fst)
72
+ //|> Sg.depthTest' DepthTest.None
73
+
74
+ let sg =
75
+ line
76
+ |> Sg.shader {
77
+ do ! DefaultSurfaces.stableTrafo
78
+ do ! DefaultSurfaces.thickLine
79
+ }
80
+ |> Sg.uniform' " LineWidth" 1.5
81
+ |> Sg.uniform' " PointSize" 8.0
82
+
83
+ Some ( sg, text)
84
+
85
+ | _ -> None
86
+ )
87
+
88
+ let texts =
89
+ elems
90
+ |> List.map snd
91
+ |> Sg.ofList
92
+ |> Sg.viewTrafo' Trafo3d.Identity
93
+ |> Sg.projTrafo' Trafo3d.Identity
94
+
95
+ let lines =
96
+ elems
97
+ |> List.map fst
98
+ |> Sg.ofList
99
+
100
+ Sg.ofList [ texts; lines]
0 commit comments