mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-02 19:38:24 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
66 lines
1.3 KiB
C#
66 lines
1.3 KiB
C#
namespace Sandbox.VR;
|
|
|
|
/// <summary>
|
|
/// Renders a device-specific model for a VR device
|
|
/// </summary>
|
|
[Title( "VR Model Renderer" )]
|
|
[Category( "VR" )]
|
|
[Icon( "view_in_ar" )]
|
|
public class VRModelRenderer : Component
|
|
{
|
|
/// <summary>
|
|
/// Represents a controller to use when fetching the model (which device)
|
|
/// </summary>
|
|
public enum ModelSources
|
|
{
|
|
/// <summary>
|
|
/// The left controller
|
|
/// </summary>
|
|
LeftHand,
|
|
|
|
/// <summary>
|
|
/// The right controller
|
|
/// </summary>
|
|
RightHand
|
|
}
|
|
|
|
private ModelSources _modelSource = ModelSources.LeftHand;
|
|
|
|
/// <summary>
|
|
/// Which device should we use to fetch the model?
|
|
/// </summary>
|
|
[Property]
|
|
public ModelSources ModelSource
|
|
{
|
|
get => _modelSource;
|
|
set
|
|
{
|
|
_modelSource = value;
|
|
UpdateModel();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Which model renderer should we use as the target?
|
|
/// </summary>
|
|
[Property]
|
|
public ModelRenderer ModelRenderer { get; set; }
|
|
|
|
protected override void OnStart()
|
|
{
|
|
UpdateModel();
|
|
}
|
|
|
|
private void UpdateModel()
|
|
{
|
|
if ( !Enabled || Scene.IsEditor || !Game.IsRunningInVR )
|
|
return;
|
|
|
|
if ( ModelRenderer == null )
|
|
return;
|
|
|
|
var hand = (ModelSource == ModelSources.LeftHand) ? Input.VR.LeftHand : Input.VR.RightHand;
|
|
ModelRenderer.Model = hand.GetModel() ?? Model.Load( "models/dev/box.vmdl" );
|
|
}
|
|
}
|