4
4
* @licence: MIT
5
5
*/
6
6
7
+ #include < OvCore/ECS/Components/CMaterialRenderer.h>
8
+
7
9
#include < OvEditor/Rendering/DebugSceneRenderer.h>
8
10
#include < OvEditor/Rendering/PickingRenderPass.h>
9
11
#include < OvEditor/Core/EditorActions.h>
13
15
14
16
#include < OvUI/Plugins/DDTarget.h>
15
17
18
+ namespace
19
+ {
20
+ OvTools::Utils::OptRef<OvCore::ECS::Actor> GetActorFromPickingResult (
21
+ OvEditor::Rendering::PickingRenderPass::PickingResult p_result
22
+ )
23
+ {
24
+ if (p_result)
25
+ {
26
+ if (const auto actor = std::get_if<OvTools::Utils::OptRef<OvCore::ECS::Actor>>(&p_result.value ()))
27
+ {
28
+ return *actor;
29
+ }
30
+ }
31
+
32
+ return std::nullopt;
33
+ }
34
+ }
35
+
16
36
OvEditor::Panels::SceneView::SceneView
17
37
(
18
38
const std::string& p_title,
@@ -31,12 +51,16 @@ OvEditor::Panels::SceneView::SceneView
31
51
32
52
m_image->AddPlugin <OvUI::Plugins::DDTarget<std::pair<std::string, OvUI::Widgets::Layout::Group*>>>(" File" ).DataReceivedEvent += [this ](auto p_data)
33
53
{
34
- std::string path = p_data.first ;
54
+ const std::string path = p_data.first ;
55
+
56
+ using namespace OvTools ::Utils;
57
+ using enum PathParser::EFileType;
35
58
36
- switch (OvTools::Utils:: PathParser::GetFileType (path))
59
+ switch (PathParser::GetFileType (path))
37
60
{
38
- case OvTools::Utils::PathParser::EFileType::SCENE: EDITOR_EXEC (LoadSceneFromDisk (path)); break ;
39
- case OvTools::Utils::PathParser::EFileType::MODEL: EDITOR_EXEC (CreateActorWithModel (path, true )); break ;
61
+ case SCENE: OnSceneDropped (path); break ;
62
+ case MODEL: OnModelDropped (path); break ;
63
+ case MATERIAL: OnMaterialDropped (path); break ;
40
64
}
41
65
};
42
66
@@ -150,20 +174,7 @@ void OvEditor::Panels::SceneView::HandleActorPicking()
150
174
151
175
if (IsHovered () && !IsResizing ())
152
176
{
153
- auto [mouseX, mouseY] = inputManager.GetMousePosition ();
154
- mouseX -= m_position.x ;
155
- mouseY -= m_position.y ;
156
- mouseY = GetSafeSize ().second - mouseY + 25 ;
157
-
158
- auto & scene = *GetScene ();
159
-
160
- auto & actorPickingFeature = m_renderer->GetPass <Rendering::PickingRenderPass>(" Picking" );
161
-
162
- auto pickingResult = actorPickingFeature.ReadbackPickingResult (
163
- scene,
164
- static_cast <uint32_t >(mouseX),
165
- static_cast <uint32_t >(mouseY)
166
- );
177
+ const auto pickingResult = GetPickingResult ();
167
178
168
179
m_highlightedActor = {};
169
180
m_highlightedGizmoDirection = {};
@@ -221,3 +232,49 @@ void OvEditor::Panels::SceneView::HandleActorPicking()
221
232
m_gizmoOperations.ApplyOperation (m_camera.GetViewMatrix (), m_camera.GetProjectionMatrix (), m_camera.GetPosition (), { static_cast <float >(winWidth), static_cast <float >(winHeight) });
222
233
}
223
234
}
235
+
236
+ OvEditor::Rendering::PickingRenderPass::PickingResult OvEditor::Panels::SceneView::GetPickingResult ()
237
+ {
238
+ auto [mouseX, mouseY] = EDITOR_CONTEXT (inputManager)->GetMousePosition ();
239
+ mouseX -= m_position.x ;
240
+ mouseY -= m_position.y ;
241
+ mouseY = GetSafeSize ().second - mouseY + 25 ;
242
+
243
+ auto & scene = *GetScene ();
244
+
245
+ auto & actorPickingFeature = m_renderer->GetPass <OvEditor::Rendering::PickingRenderPass>(" Picking" );
246
+
247
+ return actorPickingFeature.ReadbackPickingResult (
248
+ scene,
249
+ static_cast <uint32_t >(mouseX),
250
+ static_cast <uint32_t >(mouseY)
251
+ );
252
+ }
253
+
254
+ void OvEditor::Panels::SceneView::OnSceneDropped (const std::string& p_path)
255
+ {
256
+ EDITOR_EXEC (LoadSceneFromDisk (p_path));
257
+ }
258
+
259
+ void OvEditor::Panels::SceneView::OnModelDropped (const std::string& p_path)
260
+ {
261
+ EDITOR_EXEC (CreateActorWithModel (p_path, true ));
262
+ }
263
+
264
+ void OvEditor::Panels::SceneView::OnMaterialDropped (const std::string& p_path)
265
+ {
266
+ const auto pickingResult = GetPickingResult ();
267
+
268
+ if (auto actor = GetActorFromPickingResult (pickingResult))
269
+ {
270
+ if (auto materialRenderer = actor->GetComponent <OvCore::ECS::Components::CMaterialRenderer>())
271
+ {
272
+ const auto resourcePath = EDITOR_EXEC (GetResourcePath (p_path));
273
+
274
+ if (const auto material = EDITOR_CONTEXT (materialManager)[resourcePath])
275
+ {
276
+ materialRenderer->SetMaterialAtIndex (0 , *material);
277
+ }
278
+ }
279
+ }
280
+ }
0 commit comments