namespace Sandbox.VR; /// /// Renders a device-specific model for a VR device /// [Title( "VR Model Renderer" )] [Category( "VR" )] [Icon( "view_in_ar" )] public class VRModelRenderer : Component { /// /// Represents a controller to use when fetching the model (which device) /// public enum ModelSources { /// /// The left controller /// LeftHand, /// /// The right controller /// RightHand } private ModelSources _modelSource = ModelSources.LeftHand; /// /// Which device should we use to fetch the model? /// [Property] public ModelSources ModelSource { get => _modelSource; set { _modelSource = value; UpdateModel(); } } /// /// Which model renderer should we use as the target? /// [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" ); } }