Clone wiki

VRExpansionPlugin / VRExpansionFunctionLibrary

VR Expansion Function Library

  • 09/13/16 - Added two new functions*

Notes

  • Due to Epic having to manually load the OpenVR .dll I had to make this a component so that I could also load the .dll functions directly (otherwise it wouldn't work in shipping builds). When UE4 updates to the new steam version they intend to clean this up and I can move it into an actual static function library instead.

  • New in 4.13 OpenVR was updated and this uses the Async nodes now, due to being able to still support 4.12 with some compilation definitions it is up to the user to check back for loading to be complete. If the node returns AsyncLoading then call it again with the same parameters later on to check if it is finished loading the model/texture.

How do I use it?

  • Place in the Pawn or Player Controller class

  • On OnBeginPlay, OnPossessed, or in the construction script, call "OpenVRHandles"

  • On Unpossessed, EndPlay, or when no longer needed call "CloseVRHandles"

  • Use the functions

Blueprint Function Explanations

Get HMD Pure Yaw

Returns the unwound Yaw of the given Rotator

Get Is Actor Movable

Returns if the actor given is movable (only movable actors can be gripped)

Get Grip Slot In Range By Type Name

Can be used with the VRGripInterface to get a default implementation of the grip slots.

Get Is HMD Connected

Calls the c++ "IsHMDConnected()" function and returns the value

Get HMD Type NOTE Going away soon after 4.13 is stable as Epic added it by default

Returns an Enum representing the current HMD type connected

Open(Steam)VR Functions

Get VR Device Model and Texture

Gets the OpenVR model / texture of the designated device type currently in a tracking state. Returns true/false if it succeeded and a valid texture2D pointer to the models texture. This will pull custom skins from SteamVR so that they can be used.

TODO: Add full component system so that triggers an touchpads are seperate components, currently loads as a single component

  • DeviceType - Enum type of device to get the model for (uses first one of that type found)

  • ProceduralMeshComponentsToFill - List of ProceduralMeshComponents to fill with the mesh data and initialize (passing one for each hand with a controller type = two controllers).

  • bCreateCollision - If it should set the mesh components to create collision when generating them.

  • UTexture2D return - If it worked, this will be a valid UTexture2D that can be assigned to a material property.

Returns Succeeded if it has a valid model/texture, Failed if it is unable to retrieve the requested model/texture, AsyncLoading if using the async functions in 4.13 and above and the model/texture hasn't finished loading yet (in this case call the function with the same inputs again later to check if async loading is complete).

The default use of this would be to pass in two procedural mesh components, one attached to each motion controller, and set a texturesample property in a material with the returned texture and apply the material to the procedural mesh components.

GetVRDeviceProperty (Multiple Functions with different return types)

Gets OpenVR built in information properties about specific tracked devices. Each function has an Enum for available properties for the device type / return type that it handles.

VR Compositor

Error Codes (for reference)

  • VRCompositorError_None = 0,
  • VRCompositorError_RequestFailed = 1,
  • VRCompositorError_IncompatibleVersion = 100,
  • VRCompositorError_DoNotHaveFocus = 101,
  • VRCompositorError_InvalidTexture = 102,
  • VRCompositorError_IsNotSceneApplication = 103,
  • VRCompositorError_TextureIsOnWrongDevice = 104,
  • VRCompositorError_TextureUsesUnsupportedFormat = 105,
  • VRCompositorError_SharedTexturesNotSupported = 106,
  • VRCompositorError_IndexOutOfRange = 107,
  • VRCompositorError_AlreadySubmitted = 108,

Note that all textures passed in to these functions should use be an uncompressed RGBA format or error 105 will be thrown

bool SetSuspendRendering(bool bSuspendRendering)

Sets whether the compositor is allows to render or not (reverts to base compositor / grid when active)
Useful to place players out of the app during frame drops/hitches/loading and into the vr skybox.
Usually called after a SetSkyboxOverride function and before a ClearSkyboxOverride function.

bool SetSkyboxOverride_LatLong(UTexture2D * LatLongSkybox)

Override the standard skybox texture in steamVR - LatLong format - need to call ClearSkyboxOverride when finished

bool SetSkyboxOverride_LatLongStereoPair(UTexture2D * LatLongSkyboxL, UTexture2D * LatLongSkyboxR)

Override the standard skybox texture in steamVR - LatLong stereo pair - need to call ClearSkyboxOverride when finished

bool SetSkyboxOverride(UTexture * tFront, UTexture2D * tBack, UTexture * tLeft, UTexture * tRight, UTexture * tTop, UTexture * tBottom)

Override the standard skybox texture in steamVR - 6 cardinal textures - need to call ClearSkyboxOverride when finished

bool ClearSkyboxOverride()

Remove skybox override in steamVR

bool FadeHMDToColor(float fSeconds, FColor Color, bool bBackground = false)

Fades the view on the HMD to the specified color. The fade will take fSeconds, and the color values are between
0.0 and 1.0. This color is faded on top of the scene based on the alpha parameter. Removing the fade color instantly
would be FadeToColor( 0.0, 0.0, 0.0, 0.0, 0.0 ). Values are in un-premultiplied alpha space.

bool GetCurrentHMDFadeColor(FColor & ColorOut, bool bBackground = false)

Get current fade color value.

bool FadeVRGrid(float fSeconds, bool bFadeIn)

Fading the Grid in or out in fSeconds

bool GetCurrentVRGripAlpha(float & VRGridAlpha)

Get current alpha value of grid

Updated