Skip to content

Commit

Permalink
#314 trafo update, #346, #363, #367
Browse files Browse the repository at this point in the history
  • Loading branch information
LauraFritz14 committed Nov 30, 2023
1 parent f22ae0a commit 1e3587d
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 29 deletions.
3 changes: 2 additions & 1 deletion src/PRo3D.Core/Drawing/Drawing-App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ module DrawingApp =

match model.working with
| Some w when w.points.Count > 0->
{ model with working = Some { w with points = w.points |> IndexList.removeAt (w.points.Count - 1) }}
{ model with working = Some { w with points = w.points |> IndexList.removeAt (w.points.Count - 1);
segments = w.segments |> IndexList.removeAt (w.segments.Count - 1)}}
| Some _ -> { model with working = None }
| None -> model
| SetSegment(segmentIndex,segment), _, _ ->
Expand Down
2 changes: 1 addition & 1 deletion src/PRo3D.Core/GroupsApp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ module GroupsApp =
(fun (x:Node) ->
{ x with subNodes = IndexList.add group x.subNodes })

{ model with rootGroup = updateNodeAt path func model.rootGroup }
{ model with rootGroup = updateNodeAt path func model.rootGroup; lastSelectedItem = SelectedItem.Group }

let union (left : GroupsModel) (right : GroupsModel) : GroupsModel =
if left.rootGroup.key = right.rootGroup.key then
Expand Down
34 changes: 34 additions & 0 deletions src/PRo3D.Core/SceneObjectsApp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type SceneObjectAction =
| PlaceSO of V3d
| TranslationMessage of TransformationApp.Action
| PlaceSceneObject of V3d
| ChangeSOImportDirectories of list<string>


module SceneObjectTransformations =
Expand Down Expand Up @@ -124,6 +125,12 @@ module SceneObjectsUtils =
let sghs =
sceneObject
|> IndexList.toList
|> List.filter(fun (so : SceneObject) ->
let dirExists = File.Exists so.importPath
if dirExists |> not then
Log.error "[SceneObject.Sg] could not find %s" so.importPath
dirExists
)
|> List.map loadSceneObject

let sgSceneObjects =
Expand All @@ -145,6 +152,26 @@ module SceneObjectsApp =
else
None

let changeSOImportDirectories (model:SceneObjectsModel) (selectedPaths:list<string>) =
let sceneObjs =
model.sceneObjects
|> HashMap.map(fun id so ->
let newPath =
selectedPaths
|> List.map(fun p ->
let name = p |> IO.Path.GetFileName
match name = so.name with
| true -> Some p
| false -> None
)
|> List.choose( fun np -> np)
match newPath.IsEmpty with
| true -> so
| false -> { so with importPath = newPath.Head }
)

{ model with sceneObjects = sceneObjs }

let update
(model : SceneObjectsModel)
(act : SceneObjectAction)
Expand Down Expand Up @@ -203,7 +230,14 @@ module SceneObjectsApp =
{ model with sceneObjects = sceneObjs}
| None -> model
| None -> model
| ChangeSOImportDirectories sl ->
match sl with
| [] -> model
| paths ->
let selectedPaths = paths |> List.choose( fun p -> if File.Exists p then Some p else None)
changeSOImportDirectories model selectedPaths
|_-> model



module UI =
Expand Down
26 changes: 6 additions & 20 deletions src/PRo3D.Core/TransformationApp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,18 @@ module TransformationApp =

//translation along north, east, up
let trans = translation |> Trafo3d.Translation
let translationTrafo = refSysRotation.Inverse * trans * refSysRotation

let originTrafo = -pivot |> Trafo3d.Translation
let eulerRotation = Trafo3d.RotationEulerInDegrees(roll, pitch, -yaw)

let yawRotation = Trafo3d.RotationInDegrees(up, -yaw)
let pitchRotation = Trafo3d.RotationInDegrees(east, pitch)
let rollRotation = Trafo3d.RotationInDegrees(north,roll)

let oldOriginTrafo = -oldPivot |> Trafo3d.Translation
let rot = yawRotation * pitchRotation * rollRotation
let rotAndScaleTrafo = originTrafo * rot * Trafo3d.Scale(scale) * originTrafo.Inverse

let newTrafo = refSysRotation.Inverse * trans * refSysRotation * rotAndScaleTrafo //rotAndScaleTrafo *


//if pivotChanged then
// let rotAndScaleTrafo = oldOriginTrafo * rot * Trafo3d.Scale(scale) * oldOriginTrafo.Inverse
// let newPivotTrafo = refSysRotation.Inverse * trans * refSysRotation * rotAndScaleTrafo
// newPivotTrafo
//else
// newTrafo
let rotAndScale = originTrafo * refSysRotation.Inverse * eulerRotation * Trafo3d.Scale(scale) * refSysRotation * originTrafo.Inverse

let newTrafo = translationTrafo * rotAndScale

newTrafo

Expand All @@ -99,6 +90,7 @@ module TransformationApp =
let noP =
Rot3d.Rotation(upP, refsys.noffset.value |> Double.radiansFromDegrees).Transform(northP)
noP, upP


let fullTrafo
(transform : AdaptiveTransformations)
Expand Down Expand Up @@ -168,13 +160,6 @@ module TransformationApp =
else
refSys.northO, refSys.up.value
let east = north.Cross(up).Normalized

let yawRotation = Trafo3d.RotationInDegrees(up, -transform.yaw.value)
let pitchRotation = Trafo3d.RotationInDegrees(east, transform.pitch.value)
let rollRotation = Trafo3d.RotationInDegrees(north,transform.roll.value)

let rot = yawRotation * pitchRotation * rollRotation


let refSysRotation = Trafo3d.FromOrthoNormalBasis(north, east, up)
let trans = translation |> Trafo3d.Translation
Expand Down Expand Up @@ -277,6 +262,7 @@ module TransformationApp =
Html.row "show PivotPoint:" [GuiEx.iconCheckBox model.showPivot TogglePivotVisible ]
Html.row "Pivot Point (m):" [viewPivotPointInput model.pivot |> UI.map SetPivotPoint ]
Html.row "Pivot Size:" [Numeric.view' [InputBox] model.pivotSize |> UI.map SetPivotSize]
//Html.row "Reset Trafos:" [button [clazz "ui button tiny"; onClick (fun _ -> ResetTrafos )] []]
//Html.row "Pivot Point:" [Incremental.text (model.pivot |> AVal.map (fun x -> x.ToString ()))]
]
)
Expand Down
2 changes: 1 addition & 1 deletion src/PRo3D.Viewer/Bookmarks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module Bookmarks =
let groups =
GroupsApp.addLeafToActiveGroup (Leaf.Bookmarks newBm) true bookmarks

outerModel, groups
outerModel, { groups with lastSelectedItem = SelectedItem.Child }
| ImportBookmarks pathList ->
match pathList with
| filepath :: tail ->
Expand Down
2 changes: 2 additions & 0 deletions src/PRo3D.Viewer/Viewer-Model.fs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ type ViewerAction =
| StartDragging of V2i * MouseButtons
| Dragging of V2i
| EndDragging of V2i * MouseButtons
| MouseOut of V2i
| MouseIn of V2i
//| CorrelationPanelMessage of CorrelationPanelsMessage
| MakeSnapshot of int*int*string
| ImportSnapshotData of list<string>
Expand Down
20 changes: 15 additions & 5 deletions src/PRo3D.Viewer/Viewer/Viewer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,12 +1340,20 @@ module ViewerApp =
// | true ->
// Log.line "[Viewer] No shattercone updates found."
// m
| StartDragging _,_,_
| StartDragging _,_,_
| Dragging _,_,_
//| MouseOut _,_,_
| EndDragging _,_,_ ->
match m.multiSelectBox with
| Some x -> { m with multiSelectBox = None }
| None -> m
let m' =
match m.multiSelectBox with
| Some x -> { m with multiSelectBox = None }
| None -> m
m' //{m' with navigation = {m'.navigation with camera = {m'.navigation.camera with pan = false }}}
| MouseIn _,_,_ ->
{m with navigation = {m.navigation with camera = {m.navigation.camera with pan = true }}}
| MouseOut _,_,_ ->
{m with navigation = {m.navigation with camera = {m.navigation.camera with pan = false }}}

// | CorrelationPanelMessage a,_,_ ->
//let blurg =
// match a with
Expand Down Expand Up @@ -1971,7 +1979,9 @@ module ViewerApp =
]

let bodyAttributes : list<Attribute<ViewerAnimationAction>> =
[style "background: #1B1C1E; height:100%; overflow-y:scroll; overflow-x:hidden;" //] //overflow-y : visible
[
style "background: #1B1C1E; height:100%; overflow-y:scroll; overflow-x:hidden;" //] //overflow-y : visible
onMouseUp (fun button pos -> ViewerAnimationAction.ViewerMessage (EndDragging (pos, button)))
]

page (
Expand Down
24 changes: 23 additions & 1 deletion src/PRo3D.Viewer/Viewer/ViewerGUI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -462,12 +462,30 @@ module Gui =
clazz "ui item";
Dialogs.onChooseFiles SurfaceAppAction.ChangeOBJImportDirectories;
clientEvent "onclick" jsLocateOBJDialog
][
] [
text "Locate OBJ Surfaces"
]
}

Incremental.div(AttributeMap.Empty) ui |> UI.map SurfaceActions

let fixAllBrokenSOPaths =
let jsLocateSODialog =
"top.aardvark.dialog.showOpenDialog({title:'Select directory to locate Scene Objects', filters: [{ name: 'OBJ (*.obj)', extensions: ['obj']}, { name: 'DAE (*.dae)', extensions: ['dae']}], properties: ['openFile', 'multiSelections']}).then(result => {top.aardvark.processEvent('__ID__', 'onchoose', result.filePaths);});"

let ui =
alist {
yield
div [
clazz "ui item";
Dialogs.onChooseFiles SceneObjectAction.ChangeSOImportDirectories;
clientEvent "onclick" jsLocateSODialog
] [
text "Locate Scene Objects"
]
}

Incremental.div(AttributeMap.Empty) ui |> UI.map SceneObjectsMessage

let jsOpenAnnotationFileDialog =
"top.aardvark.dialog.showOpenDialog({ title: 'Import Annotations', filters: [{ name: 'Annotations (*.ann)', extensions: ['ann']},], properties: ['openFile']}).then(result => {top.aardvark.processEvent('__ID__', 'onchoose', result.filePaths);});"
Expand Down Expand Up @@ -613,6 +631,8 @@ module Gui =
fixAllBrokenPaths
//fixes all broken obj import paths
fixAllBrokenOBJPaths
//fixes all broken scene obj paths
fixAllBrokenSOPaths

let jsOpenOldAnnotationsFileDialogue = "top.aardvark.dialog.showOpenDialog({title:'Import legacy annotations from PRo3D 1.0' , filters: [{ name: 'Annotations (*.xml)', extensions: ['xml']},], properties: ['openFile']}).then(result => {top.aardvark.processEvent('__ID__', 'onchoose', result.filePaths);});"

Expand Down Expand Up @@ -1126,6 +1146,8 @@ module Gui =
onMouseDown (fun button pos -> StartDragging (pos, button))
// onMouseMove (fun delta -> Dragging delta)
onMouseUp (fun button pos -> EndDragging (pos, button))
//onMouseEnter (fun pos -> (MouseIn pos))
onMouseOut (fun pos -> (MouseOut pos))
] |> List.map (ViewerUtils.mapAttribute ViewerMessage)

body renderViewAttributes [ //[ style "background: #1B1C1E; height:100%; width:100%"] [
Expand Down

0 comments on commit 1e3587d

Please sign in to comment.