19
19
20
20
#include < Volt/Rendering/DebugRenderer.h>
21
21
#include < Volt/Rendering/SceneRenderer.h>
22
+ #include < Volt/Rendering/Camera/Camera.h>
22
23
23
24
#include < NavigationEditor/Tools/NavMeshDebugDrawer.h>
24
25
#include < NavigationEditor/Builder/RecastBuilder.h>
@@ -27,30 +28,30 @@ void Sandbox::RenderSelection(Ref<Volt::Camera> camera)
27
28
{
28
29
VT_PROFILE_FUNCTION ();
29
30
30
- auto & registry = myRuntimeScene->GetRegistry ();
31
-
32
- for (const auto & ent : SelectionManager::GetSelectedEntities ())
31
+ for (const auto & id : SelectionManager::GetSelectedEntities ())
33
32
{
34
- if (!registry.HasComponent <Volt::TransformComponent>(ent))
33
+ Volt::Entity entity{ id, myRuntimeScene };
34
+
35
+ if (!entity.HasComponent <Volt::TransformComponent>())
35
36
{
36
37
continue ;
37
38
}
38
39
39
- auto & transComp = registry .GetComponent <Volt::TransformComponent>(ent );
40
+ auto & transComp = entity .GetComponent <Volt::TransformComponent>();
40
41
41
- if (!transComp.visible || !registry .HasComponent <Volt::MeshComponent>(ent ))
42
+ if (!transComp.visible || !entity .HasComponent <Volt::MeshComponent>())
42
43
{
43
44
continue ;
44
45
}
45
46
46
- auto & meshComp = registry .GetComponent <Volt::MeshComponent>(ent );
47
+ auto & meshComp = entity .GetComponent <Volt::MeshComponent>();
47
48
auto mesh = Volt::AssetManager::GetAsset<Volt::Mesh>(meshComp.handle );
48
49
if (!mesh || !mesh->IsValid ())
49
50
{
50
51
continue ;
51
52
}
52
53
53
- mySceneRenderer->SubmitOutlineMesh (mesh, myRuntimeScene-> GetWorldSpaceTransform (Volt::Entity{ent, myRuntimeScene. get ()} ));
54
+ mySceneRenderer->SubmitOutlineMesh (mesh, entity. GetTransform ( ));
54
55
}
55
56
}
56
57
@@ -65,15 +66,15 @@ void Sandbox::RenderGizmos(Ref<Volt::Scene> scene, Ref<Volt::Camera> camera)
65
66
return ;
66
67
}
67
68
68
- auto & registry = scene->GetRegistry ();
69
-
70
69
Sandbox::Get ().GetSceneRenderer ()->SetHideStaticMeshes (settings.colliderViewMode == ColliderViewMode::AllHideMesh || settings.navMeshViewMode == NavMeshViewMode::Only);
71
70
72
71
if (settings.showEntityGizmos )
73
72
{
74
- registry. ForEach < Volt::TransformComponent>([&](entt::entity id, const Volt::TransformComponent& transformComp)
73
+ myRuntimeScene-> ForEachWithComponents < const Volt::TransformComponent>([&](entt::entity id, const Volt::TransformComponent& transformComp)
75
74
{
76
- if (registry.HasComponent <Volt::CameraComponent>(id) || registry.HasComponent <Volt::PointLightComponent>(id) || registry.HasComponent <Volt::SpotLightComponent>(id))
75
+ Volt::Entity entity{ id, myRuntimeScene };
76
+
77
+ if (entity.HasComponent <Volt::CameraComponent>() || entity.HasComponent <Volt::PointLightComponent>() || entity.HasComponent <Volt::SpotLightComponent>())
77
78
{
78
79
return ;
79
80
}
@@ -83,8 +84,6 @@ void Sandbox::RenderGizmos(Ref<Volt::Scene> scene, Ref<Volt::Camera> camera)
83
84
return ;
84
85
}
85
86
86
- Volt::Entity entity{ id, myRuntimeScene.get () };
87
-
88
87
glm::vec3 p = entity.GetPosition ();
89
88
90
89
const float maxDist = 5000 .f * 5000 .f ;
@@ -103,14 +102,14 @@ void Sandbox::RenderGizmos(Ref<Volt::Scene> scene, Ref<Volt::Camera> camera)
103
102
if (distance < maxDist)
104
103
{
105
104
float scale = glm::max (glm::min (distance / maxDist * 2 .f , maxScale), minScale);
106
- Volt::DebugRenderer::DrawBillboard (EditorResources::GetEditorIcon (EditorIcon::EntityGizmo), p, scale, glm::vec4{ 1 .f , 1 .f , 1 .f , alpha }, id );
105
+ Volt::DebugRenderer::DrawBillboard (EditorResources::GetEditorIcon (EditorIcon::EntityGizmo), p, scale, glm::vec4{ 1 .f , 1 .f , 1 .f , alpha }, entity. GetUIntID () );
107
106
}
108
107
});
109
108
}
110
109
111
110
if (settings.showEntityGizmos || settings.showLightSpheres )
112
111
{
113
- registry. ForEach < Volt::PointLightComponent, Volt::TransformComponent>([&](entt::entity id, const Volt::PointLightComponent& lightComp, const Volt::TransformComponent& transformComp)
112
+ myRuntimeScene-> ForEachWithComponents < const Volt::PointLightComponent, const Volt::TransformComponent>([&](entt::entity id, const Volt::PointLightComponent& lightComp, const Volt::TransformComponent& transformComp)
114
113
{
115
114
if (!transformComp.visible )
116
115
{
@@ -136,11 +135,11 @@ void Sandbox::RenderGizmos(Ref<Volt::Scene> scene, Ref<Volt::Camera> camera)
136
135
if (distance < maxDist)
137
136
{
138
137
float scale = glm::min (distance / maxDist, maxScale);
139
- Volt::DebugRenderer::DrawBillboard (EditorResources::GetEditorIcon (EditorIcon::LightGizmo), p, scale, glm::vec4{ 1 .f , 1 .f , 1 .f , alpha }, id );
138
+ Volt::DebugRenderer::DrawBillboard (EditorResources::GetEditorIcon (EditorIcon::LightGizmo), p, scale, glm::vec4{ 1 .f , 1 .f , 1 .f , alpha }, entity. GetUIntID () );
140
139
}
141
140
});
142
141
143
- registry. ForEach < Volt::SpotLightComponent, Volt::TransformComponent>([&](entt::entity id, const Volt::SpotLightComponent& lightComp, const Volt::TransformComponent& transformComp)
142
+ myRuntimeScene-> ForEachWithComponents < const Volt::SpotLightComponent, const Volt::TransformComponent>([&](entt::entity id, const Volt::SpotLightComponent& lightComp, const Volt::TransformComponent& transformComp)
144
143
{
145
144
if (!transformComp.visible )
146
145
{
@@ -166,13 +165,13 @@ void Sandbox::RenderGizmos(Ref<Volt::Scene> scene, Ref<Volt::Camera> camera)
166
165
if (distance < maxDist)
167
166
{
168
167
float scale = glm::min (distance / maxDist, maxScale);
169
- Volt::DebugRenderer::DrawBillboard (EditorResources::GetEditorIcon (EditorIcon::LightGizmo), p, scale, glm::vec4{ 1 .f , 1 .f , 1 .f , alpha }, id );
168
+ Volt::DebugRenderer::DrawBillboard (EditorResources::GetEditorIcon (EditorIcon::LightGizmo), p, scale, glm::vec4{ 1 .f , 1 .f , 1 .f , alpha }, entity. GetUIntID () );
170
169
}
171
170
});
172
171
173
172
if (settings.showLightSpheres )
174
173
{
175
- registry. ForEach < Volt::PointLightComponent>([&](entt::entity id, const Volt::PointLightComponent& comp)
174
+ myRuntimeScene-> ForEachWithComponents < const Volt::PointLightComponent>([&](entt::entity id, const Volt::PointLightComponent& comp)
176
175
{
177
176
Volt::Entity entity{ id, myRuntimeScene.get () };
178
177
Volt::DebugRenderer::DrawLineSphere (entity.GetPosition (), comp.radius );
@@ -182,7 +181,7 @@ void Sandbox::RenderGizmos(Ref<Volt::Scene> scene, Ref<Volt::Camera> camera)
182
181
// /// Sphere Bounds Visualization /////
183
182
if (settings.showBoundingSpheres )
184
183
{
185
- registry. ForEach < Volt::MeshComponent>([&](entt::entity id, const Volt::MeshComponent& comp)
184
+ myRuntimeScene-> ForEachWithComponents < const Volt::MeshComponent>([&](entt::entity id, const Volt::MeshComponent& comp)
186
185
{
187
186
if (comp.handle == Volt::Asset::Null ())
188
187
{
@@ -198,7 +197,7 @@ void Sandbox::RenderGizmos(Ref<Volt::Scene> scene, Ref<Volt::Camera> camera)
198
197
Volt::Entity entity{ id, myRuntimeScene.get () };
199
198
200
199
const auto & boundingSphere = mesh->GetBoundingSphere ();
201
- const auto transform = myRuntimeScene-> GetWorldSpaceTransform ( entity);
200
+ const auto transform = entity. GetTransform ( );
202
201
203
202
const glm::vec3 globalScale = { glm::length (transform[0 ]), glm::length (transform[1 ]), glm::length (transform[2 ]) };
204
203
const float maxScale = std::max (std::max (globalScale.x , globalScale.y ), globalScale.z );
@@ -226,20 +225,17 @@ void Sandbox::RenderGizmos(Ref<Volt::Scene> scene, Ref<Volt::Camera> camera)
226
225
// Draw NavLinks
227
226
{
228
227
std::vector<Volt::AI::NavLinkConnection> links;
229
- auto entitiesWithNavLink = myRuntimeScene->GetRegistry ().GetComponentView <Volt::NavLinkComponent>();
230
-
231
- for (auto ent : entitiesWithNavLink)
228
+ myRuntimeScene->ForEachWithComponents <const Volt::NavLinkComponent>([&](const entt::entity id, const Volt::NavLinkComponent& comp)
232
229
{
230
+ Volt::Entity entity{ id, myRuntimeScene.get () };
233
231
Volt::AI::NavLinkConnection link ;
234
- auto & transformComp = myRuntimeScene->GetRegistry ().GetComponent <Volt::TransformComponent>(ent);
235
- auto & linkComp = myRuntimeScene->GetRegistry ().GetComponent <Volt::NavLinkComponent>(ent);
236
232
237
- link .start = transformComp. position + linkComp .start ;
238
- link .end = transformComp. position + linkComp .end ;
239
- link .bidirectional = linkComp .bidirectional ;
233
+ link .start = entity. GetPosition () + comp .start ;
234
+ link .end = entity. GetPosition () + comp .end ;
235
+ link .bidirectional = comp .bidirectional ;
240
236
241
237
links.emplace_back (link );
242
- }
238
+ });
243
239
244
240
NavMeshDebugDrawer::DrawLinks (links);
245
241
}
@@ -250,9 +246,11 @@ void Sandbox::RenderGizmos(Ref<Volt::Scene> scene, Ref<Volt::Camera> camera)
250
246
// /////////////////////////////////////
251
247
252
248
// /// Camera Gizmo /////
253
- registry. ForEach <Volt::CameraComponent, Volt::TransformComponent >([&](entt::entity id, const Volt::CameraComponent& cameraComponent, const Volt::TransformComponent& transComp )
249
+ myRuntimeScene-> ForEachWithComponents <Volt::CameraComponent>([&](entt::entity id, const Volt::CameraComponent& cameraComponent)
254
250
{
255
- if (!transComp.visible )
251
+ Volt::Entity entity{ id, myRuntimeScene.get () };
252
+
253
+ if (!entity.IsVisible ())
256
254
{
257
255
return ;
258
256
}
@@ -265,8 +263,7 @@ void Sandbox::RenderGizmos(Ref<Volt::Scene> scene, Ref<Volt::Camera> camera)
265
263
return ;
266
264
}
267
265
268
- const auto transform = myRuntimeScene->GetWorldSpaceTransform (Volt::Entity{ id, myRuntimeScene.get () });
269
- Volt::DebugRenderer::DrawMesh (cameraMesh, material, transform);
266
+ Volt::DebugRenderer::DrawMesh (cameraMesh, material, entity.GetTransform ());
270
267
271
268
// Frustums
272
269
{
@@ -288,43 +285,39 @@ void Sandbox::RenderGizmos(Ref<Volt::Scene> scene, Ref<Volt::Camera> camera)
288
285
case ColliderViewMode::All:
289
286
{
290
287
auto collisionMaterial = Volt::AssetManager::GetAsset<Volt::Material>(" Editor/Materials/M_ColliderDebug.vtmat" );
291
- registry. ForEach < Volt::BoxColliderComponent>([&](entt::entity id, const Volt::BoxColliderComponent& collider)
288
+ myRuntimeScene-> ForEachWithComponents < const Volt::BoxColliderComponent>([&](entt::entity id, const Volt::BoxColliderComponent& collider)
292
289
{
293
290
Volt::Entity entity{ id, myRuntimeScene.get () };
294
- auto transform = myRuntimeScene->GetWorldSpaceTransform (entity);
295
291
296
292
auto cubeMesh = Volt::AssetManager::GetAsset<Volt::Mesh>(" Engine/Meshes/Primitives/SM_Cube.vtmesh" );
297
293
298
294
const glm::mat4 colliderTransform = glm::translate (glm::mat4 (1 .f ), collider.offset ) * glm::scale (glm::mat4 (1 .f ), collider.halfSize * 2 .f * 0 .01f );
299
- Volt::DebugRenderer::DrawMesh (cubeMesh, collisionMaterial, transform * colliderTransform, id );
295
+ Volt::DebugRenderer::DrawMesh (cubeMesh, collisionMaterial, entity. GetTransform () * colliderTransform, entity. GetUIntID () );
300
296
});
301
297
302
- registry. ForEach < Volt::SphereColliderComponent>([&](entt::entity id, const Volt::SphereColliderComponent& collider)
298
+ myRuntimeScene-> ForEachWithComponents < const Volt::SphereColliderComponent>([&](entt::entity id, const Volt::SphereColliderComponent& collider)
303
299
{
304
300
Volt::Entity entity{ id, myRuntimeScene.get () };
305
- auto transform = myRuntimeScene->GetWorldSpaceTransform (entity);
306
301
307
302
auto sphereMesh = Volt::AssetManager::GetAsset<Volt::Mesh>(" Engine/Meshes/Primitives/SM_Sphere.vtmesh" );
308
303
309
304
const glm::mat4 colliderTransform = glm::translate (glm::mat4 (1 .f ), collider.offset ) * glm::scale (glm::mat4 (1 .f ), { collider.radius * 2 .f * 0 .01f });
310
- Volt::DebugRenderer::DrawMesh (sphereMesh, collisionMaterial, transform * colliderTransform, id );
305
+ Volt::DebugRenderer::DrawMesh (sphereMesh, collisionMaterial, entity. GetTransform () * colliderTransform, entity. GetUIntID () );
311
306
});
312
307
313
- registry. ForEach < Volt::CapsuleColliderComponent>([&](entt::entity id, const Volt::CapsuleColliderComponent& collider)
308
+ myRuntimeScene-> ForEachWithComponents < const Volt::CapsuleColliderComponent>([&](entt::entity id, const Volt::CapsuleColliderComponent& collider)
314
309
{
315
310
Volt::Entity entity{ id, myRuntimeScene.get () };
316
- auto transform = myRuntimeScene->GetWorldSpaceTransform (entity);
317
311
318
312
const glm::mat4 colliderTransform = glm::translate (glm::mat4 (1 .f ), collider.offset ) * glm::scale (glm::mat4 (1 .f ), { collider.radius * 2 .f * 0 .01f , collider.height * 0 .01f , collider.radius * 2 .f * 0 .01f });
319
313
auto capsuleMesh = Volt::AssetManager::GetAsset<Volt::Mesh>(" Engine/Meshes/Primitives/SM_Capsule.vtmesh" );
320
314
321
- Volt::DebugRenderer::DrawMesh (capsuleMesh, collisionMaterial, transform * colliderTransform, id );
315
+ Volt::DebugRenderer::DrawMesh (capsuleMesh, collisionMaterial, entity. GetTransform () * colliderTransform, entity. GetUIntID () );
322
316
});
323
317
324
- registry. ForEach < Volt::MeshColliderComponent>([&](entt::entity id, const Volt::MeshColliderComponent& collider)
318
+ myRuntimeScene-> ForEachWithComponents < const Volt::MeshColliderComponent>([&](entt::entity id, const Volt::MeshColliderComponent& collider)
325
319
{
326
320
Volt::Entity entity{ id, myRuntimeScene.get () };
327
- auto transform = myRuntimeScene->GetWorldSpaceTransform (entity);
328
321
329
322
Ref<Volt::Mesh> debugMesh;
330
323
@@ -335,7 +328,7 @@ void Sandbox::RenderGizmos(Ref<Volt::Scene> scene, Ref<Volt::Camera> camera)
335
328
return ;
336
329
}
337
330
338
- Volt::DebugRenderer::DrawMesh (debugMesh, collisionMaterial, transform, id );
331
+ Volt::DebugRenderer::DrawMesh (debugMesh, collisionMaterial, entity. GetTransform (), entity. GetUIntID () );
339
332
});
340
333
341
334
break ;
@@ -352,40 +345,34 @@ void Sandbox::RenderGizmos(Ref<Volt::Scene> scene, Ref<Volt::Camera> camera)
352
345
if (entity.HasComponent <Volt::BoxColliderComponent>())
353
346
{
354
347
const auto & collider = entity.GetComponent <Volt::BoxColliderComponent>();
355
-
356
- auto transform = myRuntimeScene->GetWorldSpaceTransform (entity);
357
348
auto cubeMesh = Volt::AssetManager::GetAsset<Volt::Mesh>(" Engine/Meshes/Primitives/SM_Cube.vtmesh" );
358
349
359
350
const glm::mat4 colliderTransform = glm::translate (glm::mat4 (1 .f ), collider.offset ) * glm::scale (glm::mat4 (1 .f ), collider.halfSize * 2 .f * 0 .01f );
360
- Volt::DebugRenderer::DrawMesh (cubeMesh, collisionMaterial, transform * colliderTransform, id );
351
+ Volt::DebugRenderer::DrawMesh (cubeMesh, collisionMaterial, entity. GetTransform () * colliderTransform, entity. GetUIntID () );
361
352
}
362
353
363
354
if (entity.HasComponent <Volt::SphereColliderComponent>())
364
355
{
365
356
const auto & collider = entity.GetComponent <Volt::SphereColliderComponent>();
366
-
367
- auto transform = myRuntimeScene->GetWorldSpaceTransform (entity);
368
357
auto sphereMesh = Volt::AssetManager::GetAsset<Volt::Mesh>(" Engine/Meshes/Primitives/SM_Sphere.vtmesh" );
369
358
370
359
const glm::mat4 colliderTransform = glm::translate (glm::mat4 (1 .f ), collider.offset ) * glm::scale (glm::mat4 (1 .f ), { collider.radius * 2 .f * 0 .01f });
371
- Volt::DebugRenderer::DrawMesh (sphereMesh, collisionMaterial, transform * colliderTransform, id );
360
+ Volt::DebugRenderer::DrawMesh (sphereMesh, collisionMaterial, entity. GetTransform () * colliderTransform, entity. GetUIntID () );
372
361
}
373
362
374
363
if (entity.HasComponent <Volt::CapsuleColliderComponent>())
375
364
{
376
365
const auto & collider = entity.GetComponent <Volt::CapsuleColliderComponent>();
377
- auto transform = myRuntimeScene->GetWorldSpaceTransform (entity);
378
366
379
367
const glm::mat4 colliderTransform = glm::translate (glm::mat4 (1 .f ), collider.offset ) * glm::scale (glm::mat4 (1 .f ), { collider.radius * 2 .f * 0 .01f , collider.height * 0 .01f , collider.radius * 2 .f * 0 .01f });
380
368
auto capsuleMesh = Volt::AssetManager::GetAsset<Volt::Mesh>(" Engine/Meshes/Primitives/SM_Capsule.vtmesh" );
381
369
382
- Volt::DebugRenderer::DrawMesh (capsuleMesh, collisionMaterial, transform * colliderTransform, id );
370
+ Volt::DebugRenderer::DrawMesh (capsuleMesh, collisionMaterial, entity. GetTransform () * colliderTransform, entity. GetUIntID () );
383
371
}
384
372
385
373
if (entity.HasComponent <Volt::MeshColliderComponent>())
386
374
{
387
375
const auto & collider = entity.GetComponent <Volt::MeshColliderComponent>();
388
- auto transform = myRuntimeScene->GetWorldSpaceTransform (entity);
389
376
390
377
Ref<Volt::Mesh> debugMesh;
391
378
@@ -396,7 +383,7 @@ void Sandbox::RenderGizmos(Ref<Volt::Scene> scene, Ref<Volt::Camera> camera)
396
383
return ;
397
384
}
398
385
399
- Volt::DebugRenderer::DrawMesh (debugMesh, collisionMaterial, transform, id );
386
+ Volt::DebugRenderer::DrawMesh (debugMesh, collisionMaterial, entity. GetTransform (), entity. GetUIntID () );
400
387
}
401
388
}
402
389
0 commit comments