using NativeEngine; namespace Sandbox; public partial class Model { internal static readonly Dictionary> Loaded = new(); /// /// Cached instance from native, or creates /// internal static Model FromNative( IModel native, bool procedural = false, string name = null ) { if ( native.IsNull || !native.IsStrongHandleValid() ) return null; var instanceId = native.GetBindingPtr().ToInt64(); if ( NativeResourceCache.TryGetValue( instanceId, out var model ) ) { // If we're using a cached one we don't need this handle, we'll leak native.DestroyStrongHandle(); return model; } model = new Model( native, name ?? native.GetModelName(), procedural ); NativeResourceCache.Add( instanceId, model ); // Keeping this because some legacy game loop depends on this for logic, can't be fucked solving for legacy. Loaded[instanceId] = new WeakReference( model ); return model; } /// /// Returns a static instance, allowing for runtime model creation. /// public static ModelBuilder Builder => new(); /// /// A cube model /// public static Model Cube { get; internal set; } /// /// A sphere model /// public static Model Sphere { get; internal set; } /// /// A plane model /// public static Model Plane { get; internal set; } /// /// An error model /// public static Model Error { get; internal set; } internal static void Init() { Cube = Load( "models/dev/box.vmdl" ); Sphere = Load( "models/dev/sphere.vmdl" ); Plane = Load( "models/dev/plane.vmdl" ); Error = Load( "models/dev/error.vmdl" ); } }