Files
sbox-public/engine/Sandbox.Engine/Scene/Components/Component.Gizmos.cs
Lorenz Junglas 2a3b5a22b0 Editor gizmo drawing optimization (#5152)
Just some easy wins, without touching any of the gizmo API surface.

MSC main scene gizmo time went went from 55ms to 19ms

* Actually cache GizmoDetails / GizmoHandles

Before the cache flag `handleBuilt` was never actually set to true 🫠 , so `BuilldGizmodDetails` would rerun every frame resulting in the majority of our Gizmo frame time.

* Gizmo pool vertex arrays

* Gizmo scene object pool uses struct keys instead of strings

* Gizmo cache vertex object render config, skip redundant native sets

* Cull decal direction arrow gizmo at distance

* Skip gizmo scope for components that don't draw gizmos

* Slim down decal direction arrow gizmo
2026-06-25 10:20:45 +02:00

25 lines
787 B
C#

using System.Reflection;
namespace Sandbox;
public abstract partial class Component
{
/// <summary>
/// Called in the editor to draw things like bounding boxes etc
/// </summary>
protected virtual void DrawGizmos() { }
static readonly ReflectionCache<Type, bool> _typeOverridesDrawGizmos = new(
t => t.GetMethod( nameof( DrawGizmos ), BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Type.EmptyTypes, null )?.DeclaringType != typeof( Component ) );
bool? _overridesDrawGizmos;
internal bool OverridesDrawGizmos => _overridesDrawGizmos ??= _typeOverridesDrawGizmos[GetType()];
internal void DrawGizmosInternal()
{
try { DrawGizmos(); }
catch ( System.Exception e ) { Log.Error( e, $"Exception when calling 'DrawGizmos' on {this}" ); }
}
}