Skip to content

Commit 3e0bdf9

Browse files
author
Adrien GIVRY
authored
Merge branch 'develop' into feature/light_3d_icons
2 parents 9fd3805 + 09101fb commit 3e0bdf9

File tree

9 files changed

+157
-51
lines changed

9 files changed

+157
-51
lines changed

Diff for: Sources/Overload/OvEditor/include/OvEditor/Core/GizmoBehaviour.h

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ namespace OvEditor::Core
2727
Y,
2828
Z
2929
};
30+
31+
/**
32+
* Returns true if the snapping behaviour is enabled
33+
*/
34+
bool IsSnappedBehaviourEnabled() const;
3035

3136
/**
3237
* Starts the gizmo picking behaviour for the given target in the given direction

Diff for: Sources/Overload/OvEditor/include/OvEditor/Settings/EditorSettings.h

+3
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,8 @@ namespace OvEditor::Settings
7878
inline static Property<bool> ShowGeometryFrustumCullingInSceneView = { false };
7979
inline static Property<bool> ShowLightFrustumCullingInSceneView = { false };
8080
inline static Property<float> LightBillboardScale = { 0.5f };
81+
inline static Property<float> TranslationSnapUnit = { 1.0f };
82+
inline static Property<float> RotationSnapUnit = { 15.0f };
83+
inline static Property<float> ScalingSnapUnit = { 1.0f };
8184
};
8285
}

Diff for: Sources/Overload/OvEditor/src/OvEditor/Core/CameraController.cpp

+9-28
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ OvEditor::Core::CameraController::CameraController
3535

3636
float GetActorFocusDist(OvCore::ECS::Actor& p_actor)
3737
{
38-
float distance = 5.0f;
38+
float distance = 4.0f;
3939

4040
if (p_actor.IsActive())
4141
{
@@ -80,33 +80,14 @@ float GetActorFocusDist(OvCore::ECS::Actor& p_actor)
8080

8181
if (auto modelRenderer = p_actor.GetComponent<OvCore::ECS::Components::CModelRenderer>())
8282
{
83-
distance = std::max(distance, 10.0f);
84-
}
85-
86-
if (auto ambientBoxLight = p_actor.GetComponent<OvCore::ECS::Components::CAmbientBoxLight>())
87-
{
88-
distance = std::max(distance, std::max
89-
(
90-
std::max
91-
(
92-
ambientBoxLight->GetSize().x,
93-
ambientBoxLight->GetSize().y
94-
),
95-
ambientBoxLight->GetSize().z
96-
) * 1.5f);
97-
}
98-
99-
if (auto ambientSphereLight = p_actor.GetComponent<OvCore::ECS::Components::CAmbientSphereLight>())
100-
{
101-
distance = std::max(distance, std::max
102-
(
103-
std::max
104-
(
105-
ambientSphereLight->GetRadius(),
106-
ambientSphereLight->GetRadius()
107-
),
108-
ambientSphereLight->GetRadius()
109-
) * 1.5f);
83+
const bool hasCustomBoundingSphere = modelRenderer->GetFrustumBehaviour() == OvCore::ECS::Components::CModelRenderer::EFrustumBehaviour::CULL_CUSTOM;
84+
const bool hasModel = modelRenderer->GetModel();
85+
const auto boundingSphere = hasCustomBoundingSphere ? &modelRenderer->GetCustomBoundingSphere() : hasModel ? &modelRenderer->GetModel()->GetBoundingSphere() : nullptr;
86+
const auto& actorPosition = p_actor.transform.GetWorldPosition();
87+
const auto& actorScale = p_actor.transform.GetWorldScale();
88+
const auto scaleFactor = std::max(std::max(actorScale.x, actorScale.y), actorScale.z);
89+
90+
distance = std::max(distance, boundingSphere ? (boundingSphere->radius + OvMaths::FVector3::Length(boundingSphere->position)) * scaleFactor * 2.0f : 10.0f);
11091
}
11192

11293
for (auto child : p_actor.GetChildren())

Diff for: Sources/Overload/OvEditor/src/OvEditor/Core/GizmoBehaviour.cpp

+35-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55
*/
66

77
#include "OvEditor/Core/GizmoBehaviour.h"
8+
#include "OvEditor/Settings/EditorSettings.h"
9+
10+
float SnapValue(float p_value, float p_step)
11+
{
12+
return p_value - std::fmod(p_value, p_step);
13+
}
14+
15+
bool OvEditor::Core::GizmoBehaviour::IsSnappedBehaviourEnabled() const
16+
{
17+
using namespace OvWindowing::Inputs;
18+
19+
const auto& inputManager = EDITOR_CONTEXT(inputManager);
20+
return inputManager->GetKeyState(EKey::KEY_LEFT_CONTROL) == EKeyState::KEY_DOWN || inputManager->GetKeyState(EKey::KEY_RIGHT_CONTROL) == EKeyState::KEY_DOWN;
21+
}
822

923
void OvEditor::Core::GizmoBehaviour::StartPicking(OvCore::ECS::Actor& p_target, const OvMaths::FVector3& p_cameraPosition, EGizmoOperation p_operation, EDirection p_direction)
1024
{
@@ -101,9 +115,14 @@ void OvEditor::Core::GizmoBehaviour::ApplyTranslation(const OvMaths::FMatrix4& p
101115
auto screenDirection = GetScreenDirection(p_viewMatrix, p_projectionMatrix, p_viewSize);
102116

103117
auto totalDisplacement = m_currentMouse - m_originMouse;
104-
auto translationCoefficient = OvMaths::FVector2::Dot(totalDisplacement, screenDirection);
118+
auto translationCoefficient = OvMaths::FVector2::Dot(totalDisplacement, screenDirection) * unitsPerPixel;
119+
120+
if (IsSnappedBehaviourEnabled())
121+
{
122+
translationCoefficient = SnapValue(translationCoefficient, OvEditor::Settings::EditorSettings::TranslationSnapUnit);
123+
}
105124

106-
m_target->transform.SetLocalPosition(originPosition + GetRealDirection() * translationCoefficient * unitsPerPixel);
125+
m_target->transform.SetLocalPosition(originPosition + GetRealDirection() * translationCoefficient);
107126
}
108127

109128
void OvEditor::Core::GizmoBehaviour::ApplyRotation(const OvMaths::FMatrix4& p_viewMatrix, const OvMaths::FMatrix4& p_projectionMatrix, const OvMaths::FVector2& p_viewSize) const
@@ -115,9 +134,14 @@ void OvEditor::Core::GizmoBehaviour::ApplyRotation(const OvMaths::FMatrix4& p_vi
115134
screenDirection = OvMaths::FVector2(-screenDirection.y, screenDirection.x);
116135

117136
auto totalDisplacement = m_currentMouse - m_originMouse;
118-
auto rotationCoefficient = OvMaths::FVector2::Dot(totalDisplacement, screenDirection);
137+
auto rotationCoefficient = OvMaths::FVector2::Dot(totalDisplacement, screenDirection) * unitsPerPixel;
138+
139+
if (IsSnappedBehaviourEnabled())
140+
{
141+
rotationCoefficient = SnapValue(rotationCoefficient, OvEditor::Settings::EditorSettings::RotationSnapUnit);
142+
}
119143

120-
auto rotationToApply = OvMaths::FQuaternion(OvMaths::FVector3(GetFakeDirection() * rotationCoefficient * unitsPerPixel));
144+
auto rotationToApply = OvMaths::FQuaternion(OvMaths::FVector3(GetFakeDirection() * rotationCoefficient));
121145
m_target->transform.SetLocalRotation(originRotation * rotationToApply);
122146
}
123147

@@ -129,9 +153,14 @@ void OvEditor::Core::GizmoBehaviour::ApplyScale(const OvMaths::FMatrix4& p_viewM
129153
auto screenDirection = GetScreenDirection(p_viewMatrix, p_projectionMatrix, p_viewSize);
130154

131155
auto totalDisplacement = m_currentMouse - m_originMouse;
132-
auto scaleCoefficient = OvMaths::FVector2::Dot(totalDisplacement, screenDirection);
156+
auto scaleCoefficient = OvMaths::FVector2::Dot(totalDisplacement, screenDirection) * unitsPerPixel;
157+
158+
if (IsSnappedBehaviourEnabled())
159+
{
160+
scaleCoefficient = SnapValue(scaleCoefficient, OvEditor::Settings::EditorSettings::ScalingSnapUnit);
161+
}
133162

134-
auto newScale = originScale + GetFakeDirection() * scaleCoefficient * unitsPerPixel;
163+
auto newScale = originScale + GetFakeDirection() * scaleCoefficient;
135164

136165
/* Prevent scale from being negative*/
137166
newScale.x = std::max(newScale.x, 0.0001f);

Diff for: Sources/Overload/OvEditor/src/OvEditor/Panels/Hierarchy.cpp

+88-16
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,90 @@ class HierarchyActorContextualMenu : public OvUI::Plugins::ContextualMenu
174174
OvUI::Widgets::Layout::TreeNode& m_treeNode;
175175
};
176176

177+
void ExpandTreeNode(OvUI::Widgets::Layout::TreeNode& p_toExpand, const OvUI::Widgets::Layout::TreeNode* p_root)
178+
{
179+
p_toExpand.Open();
180+
181+
if (&p_toExpand != p_root && p_toExpand.HasParent())
182+
{
183+
ExpandTreeNode(*static_cast<OvUI::Widgets::Layout::TreeNode*>(p_toExpand.GetParent()), p_root);
184+
}
185+
}
186+
187+
std::vector<OvUI::Widgets::Layout::TreeNode*> nodesToCollapse;
188+
std::vector<OvUI::Widgets::Layout::TreeNode*> founds;
189+
190+
void ExpandTreeNodeAndEnable(OvUI::Widgets::Layout::TreeNode& p_toExpand, const OvUI::Widgets::Layout::TreeNode* p_root)
191+
{
192+
if (!p_toExpand.IsOpened())
193+
{
194+
p_toExpand.Open();
195+
nodesToCollapse.push_back(&p_toExpand);
196+
}
197+
198+
p_toExpand.enabled = true;
199+
200+
if (&p_toExpand != p_root && p_toExpand.HasParent())
201+
{
202+
ExpandTreeNodeAndEnable(*static_cast<OvUI::Widgets::Layout::TreeNode*>(p_toExpand.GetParent()), p_root);
203+
}
204+
}
205+
177206
OvEditor::Panels::Hierarchy::Hierarchy
178207
(
179208
const std::string & p_title,
180209
bool p_opened,
181210
const OvUI::Settings::PanelWindowSettings& p_windowSettings
182211
) : PanelWindow(p_title, p_opened, p_windowSettings)
183212
{
213+
auto& searchBar = CreateWidget<OvUI::Widgets::InputFields::InputText>();
214+
searchBar.ContentChangedEvent += [this](const std::string& p_content)
215+
{
216+
founds.clear();
217+
auto content = p_content;
218+
std::transform(content.begin(), content.end(), content.begin(), ::tolower);
219+
220+
for (auto& [actor, item] : m_widgetActorLink)
221+
{
222+
if (!p_content.empty())
223+
{
224+
auto itemName = item->name;
225+
std::transform(itemName.begin(), itemName.end(), itemName.begin(), ::tolower);
226+
227+
if (itemName.find(content) != std::string::npos)
228+
{
229+
founds.push_back(item);
230+
}
231+
232+
item->enabled = false;
233+
}
234+
else
235+
{
236+
item->enabled = true;
237+
}
238+
}
239+
240+
for (auto node : founds)
241+
{
242+
node->enabled = true;
243+
244+
if (node->HasParent())
245+
{
246+
ExpandTreeNodeAndEnable(*static_cast<OvUI::Widgets::Layout::TreeNode*>(node->GetParent()), m_sceneRoot);
247+
}
248+
}
249+
250+
if (p_content.empty())
251+
{
252+
for (auto node : nodesToCollapse)
253+
{
254+
node->Close();
255+
}
256+
257+
nodesToCollapse.clear();
258+
}
259+
};
260+
184261
m_sceneRoot = &CreateWidget<OvUI::Widgets::Layout::TreeNode>("Root", true);
185262
static_cast<OvUI::Widgets::Layout::TreeNode*>(m_sceneRoot)->Open();
186263
m_sceneRoot->AddPlugin<OvUI::Plugins::DDTarget<std::pair<OvCore::ECS::Actor*, OvUI::Widgets::Layout::TreeNode*>>>("Actor").DataReceivedEvent += [this](std::pair<OvCore::ECS::Actor*, OvUI::Widgets::Layout::TreeNode*> p_element)
@@ -223,16 +300,6 @@ void OvEditor::Panels::Hierarchy::SelectActorByInstance(OvCore::ECS::Actor& p_ac
223300
SelectActorByWidget(*result->second);
224301
}
225302

226-
void ExpandTreeNode(OvUI::Widgets::Layout::TreeNode& p_toExpand, const OvUI::Widgets::Layout::TreeNode* p_root)
227-
{
228-
p_toExpand.Open();
229-
230-
if (&p_toExpand != p_root && p_toExpand.HasParent())
231-
{
232-
ExpandTreeNode(*static_cast<OvUI::Widgets::Layout::TreeNode*>(p_toExpand.GetParent()), p_root);
233-
}
234-
}
235-
236303
void OvEditor::Panels::Hierarchy::SelectActorByWidget(OvUI::Widgets::Layout::TreeNode & p_widget)
237304
{
238305
UnselectActorsWidgets();
@@ -267,15 +334,14 @@ void OvEditor::Panels::Hierarchy::AttachActorToParent(OvCore::ECS::Actor & p_act
267334

268335
void OvEditor::Panels::Hierarchy::DetachFromParent(OvCore::ECS::Actor & p_actor)
269336
{
270-
auto actorWidget = m_widgetActorLink.find(&p_actor);
271-
272-
if (actorWidget != m_widgetActorLink.end())
337+
if (auto actorWidget = m_widgetActorLink.find(&p_actor); actorWidget != m_widgetActorLink.end())
273338
{
274339
if (p_actor.HasParent() && p_actor.GetParent()->GetChildren().size() == 1)
275340
{
276-
auto parentWidget = m_widgetActorLink.at(p_actor.GetParent());
277-
if (parentWidget)
278-
parentWidget->leaf = true;
341+
if (auto parentWidget = m_widgetActorLink.find(p_actor.GetParent()); parentWidget != m_widgetActorLink.end())
342+
{
343+
parentWidget->second->leaf = true;
344+
}
279345
}
280346

281347
auto widget = actorWidget->second;
@@ -290,8 +356,14 @@ void OvEditor::Panels::Hierarchy::DetachFromParent(OvCore::ECS::Actor & p_actor)
290356
void OvEditor::Panels::Hierarchy::DeleteActorByInstance(OvCore::ECS::Actor& p_actor)
291357
{
292358
if (auto result = m_widgetActorLink.find(&p_actor); result != m_widgetActorLink.end())
359+
{
293360
if (result->second)
361+
{
294362
result->second->Destroy();
363+
}
364+
365+
m_widgetActorLink.erase(result);
366+
}
295367
}
296368

297369
void OvEditor::Panels::Hierarchy::AddActorByInstance(OvCore::ECS::Actor & p_actor)

Diff for: Sources/Overload/OvEditor/src/OvEditor/Panels/MenuBar.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <OvUI/Widgets/Visual/Separator.h>
2222
#include <OvUI/Widgets/Sliders/SliderInt.h>
2323
#include <OvUI/Widgets/Sliders/SliderFloat.h>
24+
#include <OvUI/Widgets/Drags/DragFloat.h>
2425
#include <OvUI/Widgets/Selection/ColorEdit.h>
2526

2627
#include "OvEditor/Panels/MenuBar.h"
@@ -206,6 +207,11 @@ void OvEditor::Panels::MenuBar::CreateSettingsMenu()
206207
lightBillboardScaleSlider.ValueChangedEvent += [this](int p_value) { Settings::EditorSettings::LightBillboardScale = p_value / 100.0f; };
207208
lightBillboardScaleSlider.format = "%d %%";
208209

210+
auto& snappingMenu = settingsMenu.CreateWidget<MenuList>("Snapping");
211+
snappingMenu.CreateWidget<Drags::DragFloat>(0.001f, 999999.0f, Settings::EditorSettings::TranslationSnapUnit, 0.05f, "Translation Unit").ValueChangedEvent += [this](float p_value) { Settings::EditorSettings::TranslationSnapUnit = p_value; };
212+
snappingMenu.CreateWidget<Drags::DragFloat>(0.001f, 999999.0f, Settings::EditorSettings::RotationSnapUnit, 1.0f, "Rotation Unit").ValueChangedEvent += [this](float p_value) { Settings::EditorSettings::RotationSnapUnit = p_value; };
213+
snappingMenu.CreateWidget<Drags::DragFloat>(0.001f, 999999.0f, Settings::EditorSettings::ScalingSnapUnit, 0.05f, "Scaling Unit").ValueChangedEvent += [this](float p_value) { Settings::EditorSettings::ScalingSnapUnit = p_value; };
214+
209215
auto& debuggingMenu = settingsMenu.CreateWidget<MenuList>("Debugging");
210216
debuggingMenu.CreateWidget<MenuItem>("Show geometry bounds", "", true, Settings::EditorSettings::ShowGeometryBounds).ValueChangedEvent += [this](bool p_value) { Settings::EditorSettings::ShowGeometryBounds = p_value; };
211217
debuggingMenu.CreateWidget<MenuItem>("Show lights bounds", "", true, Settings::EditorSettings::ShowLightBounds).ValueChangedEvent += [this](bool p_value) { Settings::EditorSettings::ShowLightBounds = p_value; };

Diff for: Sources/Overload/OvRendering/src/OvRendering/Entities/Light.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ OvMaths::FMatrix4 OvRendering::Entities::Light::GenerateMatrix() const
5252
float CalculateLuminosity(float p_constant, float p_linear, float p_quadratic, float p_intensity, float p_distance)
5353
{
5454
auto attenuation = (p_constant + p_linear * p_distance + p_quadratic * (p_distance * p_distance));
55-
return (1.0f / attenuation) * p_intensity;
55+
return (1.0f / attenuation) * std::abs(p_intensity);
5656
}
5757

5858
float CalculatePointLightRadius(float p_constant, float p_linear, float p_quadratic, float p_intensity)

Diff for: Sources/Overload/OvUI/include/OvUI/Widgets/Layout/TreeNode.h

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ namespace OvUI::Widgets::Layout
3838
*/
3939
void Close();
4040

41+
/**
42+
* Returns true if the TreeNode is currently opened
43+
*/
44+
bool IsOpened() const;
45+
4146
protected:
4247
virtual void _Draw_Impl() override;
4348

Diff for: Sources/Overload/OvUI/src/OvUI/Widgets/Layout/TreeNode.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ void OvUI::Widgets::Layout::TreeNode::Close()
2626
m_shouldOpen = false;
2727
}
2828

29+
bool OvUI::Widgets::Layout::TreeNode::IsOpened() const
30+
{
31+
return m_opened;
32+
}
33+
2934
void OvUI::Widgets::Layout::TreeNode::_Draw_Impl()
3035
{
3136
bool prevOpened = m_opened;

0 commit comments

Comments
 (0)