Files
sbox-public/engine/Sandbox.Engine/Resources/Model/Model.Load.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

54 lines
1.3 KiB
C#

using Sandbox.Mounting;
namespace Sandbox;
public partial class Model
{
/// <summary>
/// Load a model by file path.
/// </summary>
/// <param name="filename">The file path to load as a model.</param>
/// <returns>The loaded model, or null</returns>
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 );
}
/// <summary>
/// Load a model by file path.
/// </summary>
/// <param name="filename">The file path to load as a model.</param>
/// <returns>The loaded model, or null</returns>
public static async Task<Model> 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 );
}
}