Skip to content

Commit

Permalink
ad #261 moved FrustumModel to ViewConfigModel,
Browse files Browse the repository at this point in the history
removed unused duplicate code
  • Loading branch information
RebeccaNowak committed Jun 19, 2023
1 parent 3520b16 commit c07e936
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 275 deletions.
34 changes: 34 additions & 0 deletions src/PRo3D.Base/ChironExt.fs
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,37 @@ type Ext with
json {
return 1
}


// Frustum
static member ToJson1 (ext : Ext, x : Frustum) =
json {
do! Json.write "left" x.left
do! Json.write "right" x.right
do! Json.write "bottom" x.bottom
do! Json.write "top" x.top
do! Json.write "near" x.near
do! Json.write "far" x.far
do! Json.write "isOrtho" x.isOrtho
}

static member FromJson1(_: Ext, _ : Frustum) =
json {
let! left = Json.read "left"
let! right = Json.read "right"
let! bottom = Json.read "bottom"
let! top = Json.read "top"
let! near = Json.read "near"
let! far = Json.read "far"
let! isOrtho = Json.read "isOrtho"

return {
left = left
right = right
bottom = bottom
top = top
near = near
far = far
isOrtho = isOrtho
}
}
96 changes: 95 additions & 1 deletion src/PRo3D.Core/ViewConfigModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,68 @@ open FSharp.Data.Adaptive
open Adaptify
open Aardvark.UI
open Chiron

open PRo3D.Base
open Aardvark.Rendering

#nowarn "0686"

[<ModelType>]
type FrustumModel = {
toggleFocal : bool
focal : NumericInput
oldFrustum : Frustum
frustum : Frustum
}

module FrustumModel =
let focal = {
value = 10.25
min = 10.0
max = 1000.0
step = 0.01
format = "{0:0.00}"
}
let hfov = 2.0 * atan(11.84 /(focal.value*2.0))

let init near far =
{
toggleFocal = true
focal = focal
oldFrustum = Frustum.perspective 60.0 0.1 10000.0 1.0
frustum = Frustum.perspective (hfov.DegreesFromRadians()) near far 1.0 //Frustum.perspective 60.0 0.1 10000.0 1.0
}

type FrustumModel with
static member ToJson (x : FrustumModel) =
json {
do! Json.write "toggleFocal" x.toggleFocal
do! Json.write "focal" x.focal.value
do! Json.writeWith (Ext.toJson<Frustum, Ext>) "frustumOld" x.oldFrustum
do! Json.writeWith (Ext.toJson<Frustum, Ext>) "frustum" x.frustum
}
static member FromJson (x : FrustumModel) =
json {
let! toggleFocal = Json.read "toggleFocal"
let! focal = Json.read "focal"
let! oldFrustum = Json.readWith Ext.fromJson<Frustum, Ext> "frustumOld"
let! frustum = Json.readWith Ext.fromJson<Frustum, Ext> "frustum"

return {
toggleFocal = toggleFocal
focal = {FrustumModel.focal with value = focal}
oldFrustum = oldFrustum
frustum = frustum
}
}

[<ModelType>]
type ViewConfigModel = {
[<NonAdaptive>]
version : int
nearPlane : NumericInput
farPlane : NumericInput
frustumModel : FrustumModel
navigationSensitivity : NumericInput
importTriangleSize : NumericInput
arrowLength : NumericInput
Expand Down Expand Up @@ -98,12 +150,13 @@ module ViewConfigModel =
format = "{0:0.000}"
}

let current = 2
let current = 4

let initial = {
version = current
nearPlane = initNearPlane
farPlane = initFarPlane
frustumModel = FrustumModel.init 0.1 10000.0
navigationSensitivity = initNavSens
arrowLength = initArrowLength
arrowThickness = initArrowThickness
Expand Down Expand Up @@ -137,6 +190,7 @@ module ViewConfigModel =
version = current
nearPlane = nearPlane
farPlane = farPlane
frustumModel = FrustumModel.init 0.1 10000.0
navigationSensitivity = navigationSensitivity
arrowLength = arrowLength
arrowThickness = arrowThickness
Expand Down Expand Up @@ -170,6 +224,7 @@ module ViewConfigModel =
version = current
nearPlane = nearPlane
farPlane = farPlane
frustumModel = FrustumModel.init 0.1 10000.0
navigationSensitivity = navigationSensitivity
arrowLength = arrowLength
arrowThickness = arrowThickness
Expand Down Expand Up @@ -205,6 +260,7 @@ module ViewConfigModel =
version = current
nearPlane = nearPlane
farPlane = farPlane
frustumModel = FrustumModel.init 0.1 10000.0
navigationSensitivity = navigationSensitivity
arrowLength = arrowLength
arrowThickness = arrowThickness
Expand Down Expand Up @@ -238,6 +294,42 @@ module ViewConfigModel =
version = current
nearPlane = nearPlane
farPlane = farPlane
frustumModel = FrustumModel.init 0.1 10000.0
navigationSensitivity = navigationSensitivity
arrowLength = arrowLength
arrowThickness = arrowThickness
dnsPlaneSize = dnsPlaneSize
lodColoring = lodColoring
importTriangleSize = importTriangleSize
drawOrientationCube = drawOrientationCube
offset = depthoffset
pickingTolerance = initPickingTolerance
filterTexture = filterTexture
showExplorationPointGui = true
}
}

module V4 = //moved Frustum model to ViewConfigModel for screen space scaling with focal length
let read =
json {
let! nearPlane = Json.readWith Ext.fromJson<NumericInput,Ext> "nearPlane"
let! farPlane = Json.readWith Ext.fromJson<NumericInput,Ext> "farPlane"
let! frustumModel = Json.read "frustumModel"
let! navigationSensitivity = Json.readWith Ext.fromJson<NumericInput,Ext> "navigationSensitivity"
let! arrowLength = Json.readWith Ext.fromJson<NumericInput,Ext> "arrowLength"
let! arrowThickness = Json.readWith Ext.fromJson<NumericInput,Ext> "arrowThickness"
let! dnsPlaneSize = Json.readWith Ext.fromJson<NumericInput,Ext> "dnsPlaneSize"
let! (lodColoring : bool) = Json.read "lodColoring"
let! importTriangleSize = Json.readWith Ext.fromJson<NumericInput,Ext> "importTriangleSize"
let! (drawOrientationCube : bool) = Json.read "drawOrientationCube"
let! depthoffset = Json.readWith Ext.fromJson<NumericInput,Ext> "depthOffset"
let! (filterTexture : bool) = Json.read "filterTexture"

return {
version = current
nearPlane = nearPlane
farPlane = farPlane
frustumModel = frustumModel
navigationSensitivity = navigationSensitivity
arrowLength = arrowLength
arrowThickness = arrowThickness
Expand All @@ -261,6 +353,7 @@ type ViewConfigModel with
| 1 -> return! ViewConfigModel.V1.read
| 2 -> return! ViewConfigModel.V2.read
| 3 -> return! ViewConfigModel.V3.read
| 4 -> return! ViewConfigModel.V4.read
| _ -> return! v |> sprintf "don't know version %A of ViewConfigModel" |> Json.error
}
static member ToJson (x : ViewConfigModel) =
Expand All @@ -274,6 +367,7 @@ type ViewConfigModel with
do! Json.writeWith (Ext.toJson<NumericInput,Ext>) "navigationSensitivity" x.navigationSensitivity
do! Json.writeWith (Ext.toJson<NumericInput,Ext>) "farPlane" x.farPlane
do! Json.writeWith (Ext.toJson<NumericInput,Ext>) "nearPlane" x.nearPlane
do! Json.write "frustumModel" x.frustumModel
do! Json.writeWith (Ext.toJson<NumericInput,Ext>) "offset" x.offset
do! Json.writeWith (Ext.toJson<NumericInput,Ext>) "depthOffset" x.offset
do! Json.writeWith (Ext.toJson<NumericInput,Ext>) "pickingTolerance" x.pickingTolerance
Expand Down
1 change: 0 additions & 1 deletion src/PRo3D.Viewer/InitialViewerModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ module Viewer =
snapshotThreads = ThreadPool.empty
showExplorationPoint = startupArgs.showExplorationPoint
heighValidation = HeightValidatorModel.init()
frustumModel = FrustumModel.init 0.1 10000.0

filterTexture = false

Expand Down
Loading

0 comments on commit c07e936

Please sign in to comment.