mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-16 02:09:20 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
54 lines
1.3 KiB
C#
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 );
|
|
}
|
|
}
|