# Rect Selection
## Issue Tree

``` plantuml
@startuml

skinparam state {
  BackgroundColor<<Release>> Aquamarine
  BackgroundColor<<Active>> NavajoWhite
  BackgroundColor<<Done>> White
  BorderColor<<Done>> Grey
}

'******************************************************************************
'

state RectSelection {
  state TruncatedPrismGenerator
  TruncatedPrismGenerator <<Done>> --> GenerateRect
  GenerateRect <<Done>> --> GenerateExtrusion
  GenerateExtrusion <<Done>> --> TraceRectProjection
  TraceRectProjection --> AddRectSelectionToEditorDemo
  AddRectSelectionToEditorDemo --> AddOrthographicSelection
}



'-----------------------------------------------------------------------------
'-----------------------------------------------------------------------------

'******************************************************************************

@enduml
```
##### Description
A set of tools that allow dragging in vr, onscreen or by code. Dragging causes a rect-selection to occur.

##### Main Branch
 - Name: `rect-selection`
 - ArchInteraction: http://git.pillars.ch:30000/simongloor/ArchInteraction/tree/rect-selection


# Issues  

## Issue Text

##### Issue Tree
 - https://git.raumgleiter.com/simongloor/todo/blob/master/IssueTrees/RectSelection.md

---

## Truncated Prism Generator

##### Project Issues
 - ArchInteraction: http://git.pillars.ch:30000/simongloor/ArchInteraction/issues/295

##### Tasks
 - Create a function `GenerateTruncatedPrism` that applies a procedural mesh to a ProceduralMeshComponent.
 - The mesh has 8 vertices and 6 rects as sides with undefined angles.
 - Flat shading (normals per tri)
 - Optional smooth shading (normals per vert / same values) is a plus, but not actually required.
 - Separate materials for top, sides, bottom.
 - Minimal UV-Mapping per quad (0/0, 0/1, 1/1, 1/0 )
 - ProceduralMeshComponent.TruncatedPrismComponent::SetGeometry(const TArray<FVector>& cVertices)

##### Documentation
 - https://git.raumgleiter.com/Raumgleiter/Raumgleiter_Knowledge/blob/master/R&D/Coding/Maths/VectorMaths.md

##### Clickdummy / Demo
 - http://git.pillars.ch:30000/simongloor/ArchInteraction/blob/develop/Documentation/Complex_Overlaps/RectSelect_in_3D.md

##### Existing Assets/Classes
 - http://git.pillars.ch:30000/simongloor/ArchInteraction/blob/develop/Source/ArchInteraction/Private/Tools/Brush/Arin_Brush_Section_Flat.cpp

---

## Generate Rect

##### Project Issues
 - ArchInteraction: http://git.pillars.ch:30000/simongloor/ArchInteraction/issues/294

##### Tasks
 - Create the new `Arin_CodeLib_Tracing` and add an empty function `GetRectProjectionVolume`.
 - Create a DevLab map in your project (not in the plugin).
 - Create an Actor with a procedural mesh ProceduralMeshComponent
 - Call `GetRectProjectionVolume` with sample values, using the transform of the Actor as Origin_Current and Empty Actors for the other attributes.
 - Move the Blueprint Actors with different sine/cos functions to ensure continuous updates work.
 - Calculate the rect according to:
    > http://git.pillars.ch:30000/simongloor/ArchInteraction/blob/develop/Documentation/Complex_Overlaps/RectSelect_in_3D.md#general-procedure
 - Use the rect for the top and bottom face

##### Documentation
 - none

##### Clickdummy / Demo
 - http://git.pillars.ch:30000/simongloor/ArchInteraction/blob/develop/Documentation/Complex_Overlaps/RectSelect_in_3D.md

##### Existing Assets/Classes
 - none

---

## Generate Extrusion

##### Project Issues
 - ArchInteraction: http://git.pillars.ch:30000/simongloor/ArchInteraction/issues/293

##### Tasks
 - Create two more functions for perspective and ortographic extrusion.
 - Call the functions in `GetRectProjectionVolume`.
 - Create another set of actors in the DevLab Map to test both variants.
 - Implement and test both projections

##### Documentation
 - none

##### Clickdummy / Demo
 - http://git.pillars.ch:30000/simongloor/ArchInteraction/blob/develop/Documentation/Complex_Overlaps/RectSelect_in_3D.md

##### Existing Assets/Classes
 - none

---

## Trace RectProjection

##### Project Issues
 - ArchInteraction: http://git.pillars.ch:30000/simongloor/ArchInteraction/issues/296

##### Tasks
 - Create a function that can trace a ProceduralMeshComponent.
 - Create a function `TraceRectProjection` that updates a ProceduralMeshComponent and returns the trace results.
 - Test the function in the DevLab.

##### Documentation
 - none

##### Clickdummy / Demo
 - http://git.pillars.ch:30000/simongloor/ArchInteraction/blob/develop/Documentation/Complex_Overlaps/RectSelect_in_3D.md

##### Existing Assets/Classes
 - none

---

## Add RectSelection to Demo Map

##### Project Issues
 - ArchInteraction: http://git.pillars.ch:30000/simongloor/ArchInteraction/issues/305

##### Tasks
 - Adjust the Arin_Equipm_Selection to control the rect selection
 - Add customization attributes:
 ``` plantuml
 @startuml
  class Arin_Equipm_Selection{
    # UMaterial OverrideMaterial_Top = nullptr
    # UMaterial OverrideMaterial_Sides = nullptr
    # UMaterial OverrideMaterial_Bottom = nullptr
    # some more attributes based on the attributes of the involved functionality
  }
 @enduml
 ```
 - ButtonDown creates a preview volume
 - The volume is then updated every frame
 - The preview uses currently a designated material customizable in the material. The default path is: ArchInteraction/Private/Mat/UI/Arin_RectSel_`T/S/B`
 - The default material should be instantiated as dynamic material instance with the parameter "AspectRatio" set to height/width
 - ButtonUp deletes the preview volume
 - ButtonUp enables a trace volume, updates it, uses it for tracing and disables it afterwards.

##### Documentation
 - none

##### Clickdummy / Demo
 - The editor demo map should be used to demonstrate the tool.
 - Be aware that you should first try to select the spheres, as they are only selectable in the selection mode. (The boxes are always selectable as theire actions are set up for this)
 - The rect select will also only be usable in the selection mode as it equips the Arin_Equipm_Selection.

##### Existing Assets/Classes
 - AArin_Equipm_Selection: http://git.pillars.ch:30000/simongloor/ArchInteraction/blob/develop/Source/ArchInteraction/Public/Player/Equipment/Leaf/Arin_Equipm_Selection.h

---

## Add Orthographic Selection

##### Project Issues
 - ArchInteraction: http://git.pillars.ch:30000/simongloor/ArchInteraction/issues/307

##### Tasks
 - Inherit an equipment for the floor selection with customizable properties for inheritance.
 ``` plantuml
 @startuml
  class Arin_Equipm_Selection_Floor{
    # UArin_TruncatedPrismComponent PreviewMesh;
    # UArin_TruncatedPrismComponent TraceMesh;
    # float FloorHeight = 0.0f
    # float RectRotation = 0.0f
    # float TraceDistance_AboveFloor = 500.0f
    # float TraceDistance_BelowFloor = 200.0f
    # float SelectionPreview_Height = 30.0f
    # float SelectionPreview_Thickness = 10.0f
    # UMaterial OverrideMaterial_Top = nullptr
    # UMaterial OverrideMaterial_Sides = nullptr
    # UMaterial OverrideMaterial_Bottom = nullptr
  }
  class Arin_TruncatedPrismComponent{
    + ProjectionDirection
    ---
    + CreateRectProjectionVolume(
        cOrigin,
        cAnchor_First_World,
        cAnchor_Second_World,
        cDistance,
        cPerspective,
        cUpdateExistingMesh,
        cAddCollider);
    # CreateGeometry(
        Points,
        cUpdateExistingMesh,
        cAddCollider)
  }
  class Arin_Equipm_Selection as "Arin_Equipm(_Selection)"
  Arin_Equipm_Selection <|-- Arin_Equipm_Selection_Floor
  Arin_Equipm_Selection_Floor --* Arin_TruncatedPrismComponent : 2
 @enduml
 ```
 - The Equipment traces onto a plane on the height of the ground to determine the location of the anchors using UArin_CodeLib::ProjectTraceToPlane.
 - The orthographic rect trace is executed using these anchors and an origin (stored only in memory, defined by the properties of the class).

##### Documentation
 - none

##### Clickdummy / Demo
 - A new button in the editor demo map should allow to enable the orthographic floor selection mode.

##### Existing Assets/Classes
 - none

---
