@@ -159,41 +159,42 @@ void OvEditor::Core::EditorRenderer::RenderSceneForActorPicking(OvRendering::Dat
159159 for (auto modelRenderer : scene.GetFastAccessComponents ().modelRenderers )
160160 {
161161 auto & actor = modelRenderer->owner ;
162- const auto & position = actor.transform .GetWorldPosition ();
163- const auto & scale = actor.transform .GetWorldScale ();
164162
165163 if (actor.IsActive ())
166164 {
167165 if (auto model = modelRenderer->GetModel ())
168166 {
169- if (!p_frustum || p_frustum-> SphereInFrustum (position. x , position. y , position. z , model-> GetBoundingSphere (). radius * std::max ( std::max ( std::max (scale. x , scale. y ), scale. z ), 0 . 0f ) ))
167+ if (auto materialRenderer = modelRenderer-> owner . GetComponent <OvCore::ECS::Components::CMaterialRenderer>( ))
170168 {
171- if (auto materialRenderer = modelRenderer-> owner . GetComponent <OvCore::ECS::Components::CMaterialRenderer>( ))
169+ if (!p_frustum || p_frustum-> BoundingSphereInFrustum (model-> GetBoundingSphere (), actor. transform . GetFTransform () ))
172170 {
173171 const OvCore::ECS::Components::CMaterialRenderer::MaterialList& materials = materialRenderer->GetMaterials ();
174172 auto modelMatrix = actor.transform .GetWorldMatrix ();
175173 PreparePickingMaterial (actor);
176174
177175 for (auto mesh : model->GetMeshes ())
178176 {
179- OvCore::Resources::Material* material = nullptr ;
180-
181- if (mesh->GetMaterialIndex () < MAX_MATERIAL_COUNT)
177+ if (!p_frustum || p_frustum->BoundingSphereInFrustum (mesh->GetBoundingSphere (), actor.transform .GetFTransform ()))
182178 {
183- material = materials.at (mesh->GetMaterialIndex ());
184- if (!material || !material->GetShader ())
185- material = &m_emptyMaterial;
186- }
187-
188- if (material)
189- {
190- m_actorPickingMaterial.SetBackfaceCulling (material->HasBackfaceCulling ());
191- m_actorPickingMaterial.SetFrontfaceCulling (material->HasFrontfaceCulling ());
192- m_actorPickingMaterial.SetColorWriting (material->HasColorWriting ());
193- m_actorPickingMaterial.SetDepthTest (material->HasDepthTest ());
194- m_actorPickingMaterial.SetDepthWriting (material->HasDepthWriting ());
195-
196- m_context.renderer ->DrawMesh (*mesh, m_actorPickingMaterial, &modelMatrix);
179+ OvCore::Resources::Material* material = nullptr ;
180+
181+ if (mesh->GetMaterialIndex () < MAX_MATERIAL_COUNT)
182+ {
183+ material = materials.at (mesh->GetMaterialIndex ());
184+ if (!material || !material->GetShader ())
185+ material = &m_emptyMaterial;
186+ }
187+
188+ if (material)
189+ {
190+ m_actorPickingMaterial.SetBackfaceCulling (material->HasBackfaceCulling ());
191+ m_actorPickingMaterial.SetFrontfaceCulling (material->HasFrontfaceCulling ());
192+ m_actorPickingMaterial.SetColorWriting (material->HasColorWriting ());
193+ m_actorPickingMaterial.SetDepthTest (material->HasDepthTest ());
194+ m_actorPickingMaterial.SetDepthWriting (material->HasDepthWriting ());
195+
196+ m_context.renderer ->DrawMesh (*mesh, m_actorPickingMaterial, &modelMatrix);
197+ }
197198 }
198199 }
199200 }
@@ -294,13 +295,15 @@ void OvEditor::Core::EditorRenderer::RenderActorAsSelected(OvCore::ECS::Actor& p
294295{
295296 if (p_actor.IsActive ())
296297 {
297- /* Render static mesh outline */
298+ /* Render static mesh outline and bounding spheres */
298299 if (auto modelRenderer = p_actor.GetComponent <OvCore::ECS::Components::CModelRenderer>(); modelRenderer && modelRenderer->GetModel ())
299300 {
300301 if (p_toStencil)
301302 RenderModelToStencil (p_actor.transform .GetWorldMatrix (), *modelRenderer->GetModel ());
302303 else
303304 RenderModelOutline (p_actor.transform .GetWorldMatrix (), *modelRenderer->GetModel ());
305+
306+ RenderBoundingSpheres (*modelRenderer, false );
304307 }
305308
306309 /* Render camera component outline */
@@ -476,6 +479,62 @@ void OvEditor::Core::EditorRenderer::RenderAmbientSphereVolume(OvCore::ECS::Comp
476479 m_context.renderer ->SetCapability (OvRendering::Settings::ERenderingCapability::DEPTH_TEST, depthTestBackup);
477480}
478481
482+ void OvEditor::Core::EditorRenderer::RenderBoundingSpheres (OvCore::ECS::Components::CModelRenderer& p_modelRenderer, bool p_perMesh)
483+ {
484+ using namespace OvCore ::ECS::Components;
485+ using namespace OvPhysics ::Entities;
486+
487+ bool depthTestBackup = m_context.renderer ->GetCapability (OvRendering::Settings::ERenderingCapability::DEPTH_TEST);
488+ m_context.renderer ->SetCapability (OvRendering::Settings::ERenderingCapability::DEPTH_TEST, false );
489+
490+ /* Draw the sphere collider if any */
491+ if (auto model = p_modelRenderer.GetModel ())
492+ {
493+ auto & actor = p_modelRenderer.owner ;
494+
495+ OvMaths::FVector3 actorScale = actor.transform .GetWorldScale ();
496+ OvMaths::FQuaternion actorRotation = actor.transform .GetWorldRotation ();
497+ OvMaths::FVector3 actorPosition = actor.transform .GetWorldPosition ();
498+
499+ if (p_perMesh)
500+ {
501+ for (auto mesh : model->GetMeshes ())
502+ {
503+ float radiusScale = std::max (std::max (std::max (actorScale.x , actorScale.y ), actorScale.z ), 0 .0f );
504+ float scaledRadius = mesh->GetBoundingSphere ().radius * radiusScale;
505+ auto sphereOffset = OvMaths::FQuaternion::RotatePoint (mesh->GetBoundingSphere ().position , actorRotation) * radiusScale;
506+
507+ OvMaths::FVector3 boundingSphereCenter = actorPosition + sphereOffset;
508+
509+ for (float i = 0 ; i <= 360 .0f ; i += 10 .0f )
510+ {
511+ m_context.shapeDrawer ->DrawLine (boundingSphereCenter + actorRotation * (OvMaths::FVector3{ cos (i * (3 .14f / 180 .0f )), sin (i * (3 .14f / 180 .0f )), 0 .f } *scaledRadius), boundingSphereCenter + actorRotation * (OvMaths::FVector3{ cos ((i + 10 .0f ) * (3 .14f / 180 .0f )), sin ((i + 10 .0f ) * (3 .14f / 180 .0f )), 0 .f } *scaledRadius), OvMaths::FVector3{ 1 .f , 0 .f , 0 .f }, 1 .f );
512+ m_context.shapeDrawer ->DrawLine (boundingSphereCenter + actorRotation * (OvMaths::FVector3{ 0 .f , sin (i * (3 .14f / 180 .0f )), cos (i * (3 .14f / 180 .0f )) } *scaledRadius), boundingSphereCenter + actorRotation * (OvMaths::FVector3{ 0 .f , sin ((i + 10 .0f ) * (3 .14f / 180 .0f )), cos ((i + 10 .0f ) * (3 .14f / 180 .0f )) } *scaledRadius), OvMaths::FVector3{ 1 .f , 0 .f , 0 .f }, 1 .f );
513+ m_context.shapeDrawer ->DrawLine (boundingSphereCenter + actorRotation * (OvMaths::FVector3{ cos (i * (3 .14f / 180 .0f )), 0 .f , sin (i * (3 .14f / 180 .0f )) } *scaledRadius), boundingSphereCenter + actorRotation * (OvMaths::FVector3{ cos ((i + 10 .0f ) * (3 .14f / 180 .0f )), 0 .f , sin ((i + 10 .0f ) * (3 .14f / 180 .0f )) } *scaledRadius), OvMaths::FVector3{ 1 .f , 0 .f , 0 .f }, 1 .f );
514+ }
515+ }
516+ }
517+ else
518+ {
519+ float radiusScale = std::max (std::max (std::max (actorScale.x , actorScale.y ), actorScale.z ), 0 .0f );
520+ float scaledRadius = model->GetBoundingSphere ().radius * radiusScale;
521+ auto sphereOffset = OvMaths::FQuaternion::RotatePoint (model->GetBoundingSphere ().position , actorRotation) * radiusScale;
522+
523+ OvMaths::FVector3 boundingSphereCenter = actorPosition + sphereOffset;
524+
525+ for (float i = 0 ; i <= 360 .0f ; i += 10 .0f )
526+ {
527+ m_context.shapeDrawer ->DrawLine (boundingSphereCenter + actorRotation * (OvMaths::FVector3{ cos (i * (3 .14f / 180 .0f )), sin (i * (3 .14f / 180 .0f )), 0 .f } *scaledRadius), boundingSphereCenter + actorRotation * (OvMaths::FVector3{ cos ((i + 10 .0f ) * (3 .14f / 180 .0f )), sin ((i + 10 .0f ) * (3 .14f / 180 .0f )), 0 .f } *scaledRadius), OvMaths::FVector3{ 1 .f , 0 .f , 0 .f }, 1 .f );
528+ m_context.shapeDrawer ->DrawLine (boundingSphereCenter + actorRotation * (OvMaths::FVector3{ 0 .f , sin (i * (3 .14f / 180 .0f )), cos (i * (3 .14f / 180 .0f )) } *scaledRadius), boundingSphereCenter + actorRotation * (OvMaths::FVector3{ 0 .f , sin ((i + 10 .0f ) * (3 .14f / 180 .0f )), cos ((i + 10 .0f ) * (3 .14f / 180 .0f )) } *scaledRadius), OvMaths::FVector3{ 1 .f , 0 .f , 0 .f }, 1 .f );
529+ m_context.shapeDrawer ->DrawLine (boundingSphereCenter + actorRotation * (OvMaths::FVector3{ cos (i * (3 .14f / 180 .0f )), 0 .f , sin (i * (3 .14f / 180 .0f )) } *scaledRadius), boundingSphereCenter + actorRotation * (OvMaths::FVector3{ cos ((i + 10 .0f ) * (3 .14f / 180 .0f )), 0 .f , sin ((i + 10 .0f ) * (3 .14f / 180 .0f )) } *scaledRadius), OvMaths::FVector3{ 1 .f , 0 .f , 0 .f }, 1 .f );
530+ }
531+ }
532+ }
533+
534+ m_context.renderer ->SetCapability (OvRendering::Settings::ERenderingCapability::DEPTH_TEST, depthTestBackup);
535+ m_context.renderer ->SetRasterizationLinesWidth (1 .0f );
536+ }
537+
479538void OvEditor::Core::EditorRenderer::RenderModelAsset (OvRendering::Resources::Model& p_model)
480539{
481540 FMatrix4 model = OvMaths::FMatrix4::Scaling ({ 3 .f , 3 .f , 3 .f });
0 commit comments