Files
sbox-public/engine/Sandbox.Engine/Scene/Components/VR/VRModelRenderer.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

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" );
}
}