mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-04-19 05:48:07 -04:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
44 lines
944 B
C#
44 lines
944 B
C#
|
|
namespace Editor.Assets;
|
|
|
|
[AssetPreview( "fbx" )]
|
|
[AssetPreview( "obj" )]
|
|
[AssetPreview( "dmx" )]
|
|
class PreviewMesh : AssetPreview
|
|
{
|
|
public override float PreviewWidgetCycleSpeed => 0.2f;
|
|
|
|
public PreviewMesh( Asset asset ) : base( asset )
|
|
{
|
|
}
|
|
|
|
public override async Task InitializeAsset()
|
|
{
|
|
await Task.Yield();
|
|
|
|
using ( Scene.Push() )
|
|
using ( EditorUtility.DisableTextureStreaming() )
|
|
{
|
|
// TODO - make async
|
|
var model = Asset.GetPreviewModel();
|
|
if ( model is null )
|
|
return;
|
|
|
|
if ( model.MeshCount == 0 )
|
|
return;
|
|
|
|
SceneCenter = model.RenderBounds.Center;
|
|
SceneSize = Vector3.Zero;
|
|
|
|
PrimaryObject = new GameObject( true, "preview mesh" );
|
|
PrimaryObject.WorldTransform = Transform.Zero;
|
|
|
|
var modelRenderer = PrimaryObject.AddComponent<ModelRenderer>();
|
|
modelRenderer.Model = model;
|
|
|
|
SceneSize = model.RenderBounds.Size;
|
|
SceneCenter = modelRenderer.WorldRotation * SceneCenter;
|
|
}
|
|
}
|
|
}
|