Skip to content

Commit

Permalink
Merge pull request #202 from pro3d-space/features/newSnapshots
Browse files Browse the repository at this point in the history
Features/new snapshots
  • Loading branch information
ThomasOrtner authored Apr 29, 2022
2 parents 1dc8bc6 + 6ea5285 commit 35bacf4
Show file tree
Hide file tree
Showing 20 changed files with 657 additions and 191 deletions.
4 changes: 2 additions & 2 deletions src/PRo3D.2D3DLinking/Linking/LinkingApp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ module LinkingApp =
|> Sg.shader {
do! DefaultSurfaces.stableTrafo
do! DefaultSurfaces.vertexColor
do! DefaultSurfaces.thickLine
do! Shader.ThickLineNew.thickLine
do! DefaultSurfaces.thickLineRoundCaps
}
|> Sg.uniform "LineWidth" (AVal.constant 5.0)
Expand Down Expand Up @@ -303,7 +303,7 @@ module LinkingApp =
[|
frustra
hoverFrustum
|]
|]
|> Sg.ofArray

// scene that is always shown (in both normal 3d and overlay mode)
Expand Down
8 changes: 4 additions & 4 deletions src/PRo3D.Base/OutlineEffect.fs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module OutlineEffect =
|> Sg.shader {
do! DefaultSurfaces.stableTrafo
do! Shader.lines
do! DefaultSurfaces.thickLine
do! Shader.ThickLineNew.thickLine
do! DefaultSurfaces.thickLineRoundCaps
do! DefaultSurfaces.sgColor
}
Expand Down Expand Up @@ -115,7 +115,7 @@ module OutlineEffect =
|> Sg.shader {
do! DefaultSurfaces.stableTrafo
do! DefaultSurfaces.vertexColor
do! DefaultSurfaces.thickLine
do! Shader.ThickLineNew.thickLine
}

let outline =
Expand All @@ -127,7 +127,7 @@ module OutlineEffect =
|> Sg.depthTest (AVal.constant DepthTest.None)
|> Sg.shader {
do! DefaultSurfaces.stableTrafo
do! DefaultSurfaces.thickLine
do! Shader.ThickLineNew.thickLine
do! DefaultSurfaces.thickLineRoundCaps
do! DefaultSurfaces.vertexColor
}
Expand All @@ -147,7 +147,7 @@ module OutlineEffect =
toEffect Shader.ScreenSpaceScale.screenSpaceScale
toEffect DefaultSurfaces.stableTrafo
toEffect Shader.lines
toEffect DefaultSurfaces.thickLine
toEffect Shader.ThickLineNew.thickLine
toEffect DefaultSurfaces.thickLineRoundCaps
//toEffect DefaultSurfaces.constantColor C4f.Red
toEffect DefaultSurfaces.vertexColor
Expand Down
6 changes: 3 additions & 3 deletions src/PRo3D.Base/Utilities.fs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ module Sg =
toEffect Shader.DepthOffset.depthOffsetFS
]

let private drawStableLinesHelper (edges: aval<Line3d[]>) (offset: aval<float>) (color: aval<C4b>) (width: aval<float>) =
let private drawStableLinesHelper (edges: aval<Line3d[]>) (offset: aval<float>) (color: aval<C4b>) (width: aval<float>) =
edges
|> Sg.lines color
|> Sg.noEvents
Expand All @@ -650,7 +650,7 @@ module Sg =
Effect.compose [
toEffect DefaultSurfaces.stableTrafo
toEffect DefaultSurfaces.vertexColor
toEffect DefaultSurfaces.thickLine
toEffect Shader.ThickLineNew.thickLine
]

let drawScaledLines
Expand Down Expand Up @@ -753,7 +753,7 @@ module Sg =
else
pline
|> Sg.trafo trafo

//## POINTS ##
let private sphereSgHelper (color: aval<C4b>) (size: aval<float>) (pos: aval<V3d>) =
Sg.sphere 2 color (AVal.constant 1.0)
Expand Down
8 changes: 5 additions & 3 deletions src/PRo3D.Core/Bookmark-Model.fs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ type SequencedBookmarksAction =
| FlyToSBM of Guid
| RemoveSBM of Guid
| SelectSBM of Guid
| IsVisible of Guid
| MoveUp of Guid
| MoveDown of Guid
| AddSBookmark
Expand All @@ -143,11 +142,11 @@ type SequencedBookmarksAction =
| CancelSnapshots
| ToggleGenerateOnStop
| ToggleRenderStillFrames
| ToggleUseSpeed
| SetResolutionX of Numeric.Action
| SetResolutionY of Numeric.Action
| SetOutputPath of list<string>
| SetFpsSetting of FPSSetting
| CheckSnapshotsProcess of string
| UpdateJson
| ToggleUpdateJsonBeforeRendering

Expand Down Expand Up @@ -209,7 +208,8 @@ type SequencedBookmarks = {
outputPath : string
fpsSetting : FPSSetting
updateJsonBeforeRendering : bool
// snapshotProcess : option<System.Diagnostics.Process>
[<NonAdaptive>]
snapshotThreads : ThreadPool<SequencedBookmarksAction>
}
//} with interface IDisposable with
// member this.Dispose () =
Expand Down Expand Up @@ -331,6 +331,7 @@ module SequencedBookmarks =
orderList = orderList
selectedBookmark = selected
animationThreads = ThreadPool.Empty
snapshotThreads = ThreadPool.Empty
stopAnimation = true
blockingCollection = new HarriSchirchWrongBlockingCollection<_>()
isRecording = false
Expand All @@ -357,6 +358,7 @@ module SequencedBookmarks =
orderList = List.empty
selectedBookmark = None
animationThreads = ThreadPool.Empty
snapshotThreads = ThreadPool.Empty
stopAnimation = true
blockingCollection = new HarriSchirchWrongBlockingCollection<_>()
//delay = initDelay
Expand Down
2 changes: 1 addition & 1 deletion src/PRo3D.Core/Drawing/Drawing-App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ module DrawingApp =
let showPoints =
a.geometry
|> AVal.map(function | Geometry.Point | Geometry.DnS -> true | _ -> false)

let sg = Sg.finishedAnnotationOld a c config view viewport showPoints picked pickingAllowed
sg
)
Expand Down
2 changes: 1 addition & 1 deletion src/PRo3D.Core/Drawing/Drawing.Sg.fs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ module Sg =
anno.thickness.value
config.pickingTolerance
anno.modelTrafo
true
true
pickFunc

let vm = view |> AVal.map (fun v -> (CameraView.viewTrafo v).Forward)
Expand Down
65 changes: 61 additions & 4 deletions src/PRo3D.Core/SequencedBookmarksApp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ module SequencedBookmarksApp =
outerModel, {m with renderStillFrames = not m.renderStillFrames}
| ToggleUpdateJsonBeforeRendering ->
outerModel, {m with updateJsonBeforeRendering = not m.updateJsonBeforeRendering}
| UpdateJson ->
// currently updated in Viewer.fs
outerModel, m
| GenerateSnapshots ->
outerModel, {m with isGenerating = true}
| CancelSnapshots ->
Expand All @@ -522,10 +525,64 @@ module SequencedBookmarksApp =
outerModel, {m with outputPath = str}
| SetFpsSetting setting ->
outerModel, {m with fpsSetting = setting}
|_-> outerModel, m


let threads (m : SequencedBookmarks) = m.animationThreads
| CheckSnapshotsProcess id ->
match snapshotProcess with
| Some p ->
let m =
match p.HasExited , m.isCancelled with
| true, _ ->
Log.warn "[Snapshots] Snapshot generation finished."
//let m = shortFeedback "Snapshot generation finished." m
let m = {m with snapshotThreads = ThreadPool.remove id m.snapshotThreads
isGenerating = false
}

m
| false, false ->
m
| false, true ->
Log.warn "[Snapshots] Snapshot generation cancelled."
p.Kill ()
//let m = shortFeedback "Snapshot generation cancelled." m
let m = {m with snapshotThreads = ThreadPool.remove id m.snapshotThreads
isGenerating = false
isCancelled = false
}
m
outerModel, m
| None ->
outerModel, m

let generateSnapshots m runProcess scenePath =
let jsonPathName = Path.combine [m.outputPath;"batchRendering.json"]
if System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform
(System.Runtime.InteropServices.OSPlatform.Windows) then

let exeName = "PRo3D.Snapshots.exe"
match File.Exists exeName with
| true ->
let args = sprintf "--scn \"%s\" --asnap \"%s\" --out \"%s\" --exitOnFinish"
scenePath jsonPathName m.outputPath
Log.line "[Viewer] Starting snapshot rendering with arguments: %s" args
snapshotProcess <- Some (runProcess exeName args None)
let id = System.Guid.NewGuid () |> string
let proclst =
proclist {
for i in 0..4000 do
do! Proc.Sleep 4000
yield CheckSnapshotsProcess id
}
{m with snapshotThreads = ThreadPool.add id proclst m.snapshotThreads}
| false ->
Log.warn "[Snapshots] Could not find %s" exeName
m
else
Log.warn "[Viewer] This feature is only available for Windows."
m


let threads (m : SequencedBookmarks) =
ThreadPool.union m.snapshotThreads m.animationThreads


module UI =
Expand Down
3 changes: 2 additions & 1 deletion src/PRo3D.SimulatedViews/Snapshots/AppUtils.fs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
namespace Aardvark.UI
namespace SimulatedViews

open System
open System.Threading
open System.Collections.Generic
open Aardvark.Base
open FSharp.Data.Adaptive
open System.Reactive.Subjects
open Aardvark.UI

type private Message<'msg> = { msgs : seq<'msg>; processed : Option<System.Threading.ManualResetEventSlim> }

Expand Down
5 changes: 3 additions & 2 deletions src/PRo3D.SimulatedViews/Snapshots/RenderingUtils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ module Rendering =
with
| e ->
Log.error "%s" e.Message
// Environment.Exit(int ExitCode.REQUEST_RESTART)
None, None
result

Expand Down Expand Up @@ -121,4 +120,6 @@ module Rendering =
//Environment.Exit(int ExitCode.REQUEST_RESTART)
with e ->
Log.error "[SNAPSHOT] Could not save image %s" filename
Log.error "%s" e.Message
Log.error "%s" e.Message


2 changes: 1 addition & 1 deletion src/PRo3D.SimulatedViews/Snapshots/Snapshot-Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module SnapshotUtils =
reraise()
if not started then
failwithf "[Snapshots] Failed to start process %s" filename
printfn "[Snapshots] Started %s with pid %i" p.ProcessName p.Id
Log.line "[Snapshots] Started %s with pid %i" p.ProcessName p.Id
p

let calculateFarPlane (sceneBB : Box3d) (cameraPosition : V3d) =
Expand Down
60 changes: 60 additions & 0 deletions src/PRo3D.SimulatedViews/Snapshots/SnapshotAnimation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ open MBrace.FsPickler.Json

open Aardvark.UI
open Chiron
open PRo3D.Core

[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module SnapshotAnimation =
Expand Down Expand Up @@ -93,6 +94,65 @@ module SnapshotAnimation =
renderMask = renderMask
}

let fromBookmarks (bm : SequencedBookmarks)
(cameraView : CameraView)
(frustum : Frustum)
(nearPlane : float)
(farPlane : float) =


if SequencedBookmarksApp.timestamps.Length > 0 then
let snapshots =
match bm.renderStillFrames with
| false ->
Snapshot.fromViews
SequencedBookmarksApp.collectedViews
None
None
SequencedBookmarksApp.names
None
bm.fpsSetting
| true ->
let stillFrames = SequencedBookmarksApp.calculateNrOfStillFrames bm
Snapshot.fromViews
SequencedBookmarksApp.collectedViews
None
None
SequencedBookmarksApp.names
(stillFrames |> Some)
bm.fpsSetting
let snapshotAnimation =
generate
snapshots
(frustum |> Frustum.horizontalFieldOfViewInDegrees |> Some)
(nearPlane |> Some)
(farPlane |> Some)
(V2i (bm.resolutionX.value, bm.resolutionY.value))
None
snapshotAnimation
//writeToFile snapshotAnimation jsonPathName
else
Log.line "[Viewer] No frames recorded. Saving current frame."
let snapshots =
[{
filename = "CurrentFrame"
camera = cameraView |> Snapshot.toSnapshotCamera
sunPosition = None
lightDirection = None
surfaceUpdates = None
placementParameters = None
renderMask = None
}]
let snapshotAnimation =
generate
snapshots
(frustum |> Frustum.horizontalFieldOfViewInDegrees |> Some)
(nearPlane |> Some)
(farPlane |> Some)
(V2i (bm.resolutionX.value, bm.resolutionY.value))
None
snapshotAnimation

let readTestAnimation () =
try
let foo =
Expand Down
Loading

0 comments on commit 35bacf4

Please sign in to comment.