-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Component Visualizer sub-documents
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
2021-08-26_12:32:42 | ||
|
||
# Component Visualizer - Handle input | ||
|
||
There is `HandleInputDelta` and `HandleInputKey`. | ||
When you have determined that a change is going to happen (all checks passed) then call `Modify` on the edited object, do the change, and then call `NotifyPropertyModified` and `GEditor->RedrawLevelEditingViewports`. | ||
|
||
```cpp | ||
bool FMyVisualizer::HandleInputDelta( | ||
FEditorViewportClient* ViewportClient, | ||
FViewport* Viewport, | ||
FVector& DeltaTranslate, | ||
FRotator& DeltaRotate, | ||
FVector& DeltaScale) | ||
{ | ||
UMyComponent* My = GetSelectedMy(); | ||
if (My == nullptr) | ||
{ | ||
return false; | ||
} | ||
if (DeltaTranslate.IsZero()) | ||
{ | ||
return true; | ||
} | ||
My->Modify(); | ||
My->MyProperty += DeltaRotate; | ||
NotifyPropertyModified( | ||
My, | ||
FindFProperty<FProperty>( | ||
Class, GET_MEMBER_NAME_CHECKED(UMyComponent, MyProperty) | ||
) | ||
); | ||
GEditor->RedrawLevelEditingViewports() | ||
} | ||
``` | ||
Getting the edited Component is complicated. | ||
The strategy I've seen uses Hit Proxies that store a pointer to the Component and a Hit Proxy callback on the Visualizer that read that pointer and remembers it for use in `HandleInputDelta`. | ||
[[2020-08-06_18:48:41]] [Component visualizer](./Component%20visualizer.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
2021-08-26_12:47:43 | ||
|
||
# Component Visualizer - Hit Proxies | ||
|
||
[[2020-08-06_18:48:41]] [Component visualizer](./Component%20visualizer.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
2021-08-26_08:50:46 | ||
|
||
# Component Visualizer - Widget location | ||
|
||
Unreal Editor uses a Transform Widget to let the user transform objects. | ||
The transformed object can be an Actor in the level, a Component in an Actor, or a custom attribute of a Component. | ||
By "attribute" I mean anything that a Component might have, often a UProperty. | ||
For example one of the control points of a spline. | ||
|
||
![A transformation widget on a spline control point](Images/ComponentVisualiser_WidgetLocation_example.png) | ||
|
||
The editor provide code for transforming Actors and Components, but custom attributes require custom code. | ||
The custom code lives in the Component Visualizer associated with the Component type. | ||
The Component Visualizer has three virtual methods that deal with interactive transformations: | ||
- `GetWidgetLocation` | ||
- `HandleInputDelta` | ||
- `IsVisualizingArchetype` | ||
|
||
These functions are called by Unreal Editor from `FEditorViewportClient::Draw`. | ||
There is also `ISCSEditorCustomization` which seem related but I know nothing about it. | ||
|
||
`GetWidgetLocation` should provide the location, in world space, where the transformation widget should be placed. | ||
|
||
```cpp | ||
bool FMyVisualizer::GetWidgetLocation( | ||
const FEditorViewportClient* ViewportClient, FVector& OutLocation) const | ||
{ | ||
UMyComponent* MyComponent = GetEditedMy(); | ||
if (MyComponent == nullptr) | ||
{ | ||
return false; | ||
} | ||
OutLocation = MyComponent->MyVectorUProperty; | ||
return true; | ||
} | ||
``` | ||
Getting the edited Component is complicated. | ||
The strategy I've seen uses Hit Proxies that store a pointer to the Component and a Hit Proxy callback on the Visualizer that read that pointer and remembers it for use in `GetWidgetLocation`. | ||
[[2020-08-06_18:48:41]] [Component visualizer](./Component%20visualizer.md) |