using Sandbox.Mounting; namespace Sandbox; public partial class Model { /// /// Load a model by file path. /// /// The file path to load as a model. /// The loaded model, or null public static Model Load( string filename ) { ThreadSafe.AssertIsMainThread(); if ( string.IsNullOrWhiteSpace( filename ) ) return Error; filename = filename?.Replace( ".vmdl_c", ".vmdl" ); if ( Sandbox.Mounting.Directory.TryLoad( filename, ResourceType.Model, out object model ) && model is Model m ) return m; return FromNative( NativeGlue.Resources.GetModel( filename ), name: filename ); } /// /// Load a model by file path. /// /// The file path to load as a model. /// The loaded model, or null public static async Task LoadAsync( string filename ) { ThreadSafe.AssertIsMainThread(); if ( string.IsNullOrWhiteSpace( filename ) ) return Error; filename = filename?.Replace( ".vmdl_c", ".vmdl" ); if ( await Sandbox.Mounting.Directory.TryLoadAsync( filename, ResourceType.Model ) is Model m ) return m; using var manifest = AsyncResourceLoader.Load( filename ); if ( manifest is not null ) { await manifest.WaitForLoad(); } // TODO - make async return Load( filename ); } }