public static HmdType GetHmdType() { HmdType type = HmdType.Unsupported; #if (UNITY_ANDROID && VIVE_STEREO_WAVEVR) if (WaveVR_Render.Instance != null) { type = HmdType.WaveVR; } return(type); #else #if UNITY_2017_2_OR_NEWER string deviceName = UnityEngine.XR.XRSettings.loadedDeviceName; #else string deviceName = UnityEngine.VR.VRSettings.loadedDeviceName; #endif if (deviceName == "OpenVR") { type = HmdType.SteamVR; } else if (deviceName == "Oculus") { type = HmdType.OVR; } return(type); #endif }
public static HmdType GetHmdType() { HmdType type = HmdType.Unsupported; #if UNITY_5_3 string deviceName = VRSettings.loadedDevice.ToString(); // there is no "official" Vive support in Unity 5.3, thus refer to SteamVR plugin for checking hmd type if (deviceName == "None") { var steamCam = Object.FindObjectOfType <SteamVR_Camera>(); if (steamCam != null) { type = HmdType.SteamVR; } } #else string deviceName = UnityEngine.XR.XRSettings.loadedDeviceName; if (deviceName == "OpenVR") { type = HmdType.SteamVR; } #endif return(type); }
public static IDeviceParamFactory InitParamFactory(HmdType hmdType) { #if (VIVE_STEREO_STEAMVR) if (hmdType == HmdType.SteamVR) { return(new SteamVRParamFactory()); } #endif #if (VIVE_STEREO_OVR) if (hmdType == HmdType.OVR) { return(new OVRParamFactory()); } #endif #if (UNITY_ANDROID && VIVE_STEREO_WAVEVR) if (hmdType == HmdType.WaveVR) { return(new WaveVRParamFactory()); } #endif Debug.LogError("Cannot get suitable projection parameter for current HMD."); return(null); }
private static void VerifyValueProperties(String idString, HmdValueIDProperties valueIDProperties, ICountProperty expectedCountProperty, HmdType hmdType, String enumReferenceName, params String[] parentOverrideArray) { // Verify idString Assert.AreEqual(idString, valueIDProperties.idLowerCase); // Verify CountProperty is correct Assert.IsTrue(expectedCountProperty.Equals(valueIDProperties.CountProperty)); // Verify Parents are correct if (parentOverrideArray != null) { Assert.AreEqual(parentOverrideArray.Length, valueIDProperties.ParentOverrideCount); for (int i = 0; i < parentOverrideArray.Length; i++) { Assert.IsTrue(valueIDProperties.IsInParentOverrideList(parentOverrideArray[i])); } } // Verify HmdType is correct Assert.AreEqual(hmdType, valueIDProperties.hmdType); if (enumReferenceName == null) { Assert.IsNull(valueIDProperties.EnumReference); } else { Assert.AreEqual(enumReferenceName, valueIDProperties.EnumReference.Name); } }
public static IDeviceParamFactory InitParamFactory(HmdType hmdType) { if (hmdType == HmdType.SteamVR) { return(new SteamVRParamFactory()); } return(null); }
public void TestGeneralProperties() { HmdValueIDProperties valueIDProperties; ICountProperty defaultCountProperty = UnrestrictedCount.Instance; HmdType defaultHmdType = HmdType.String; //valueIDProperties = HmdParser.ParseValueProperties("test", "0-* enum(hey what)"); //TestUtil.VerifyValue(TestU, defaultCountProperty, IDProperties.rootParentReference, HmdType.Enumeration, "heywhat"); }
public HmdValueIDProperties(String idString, ICountProperty countProperty, HmdType hmdType, HmdEnumReference enumReference, HmdBlockIDProperties directParent, HmdParentReference[] parentOverrideList) : base(IsBlock, idString, countProperty, directParent, parentOverrideList) { if (hmdType == HmdType.Enumeration && enumReference == null) { throw new ArgumentNullException("For Enumeration types, must have an enumReference", "enumReference"); } this.hmdType = hmdType; this.enumReference = enumReference; }
public HmdProperties(ICountProperty defaultCountProperty, HmdType defaultHmdType) { this.defaultCountProperty = defaultCountProperty; this.defaultHmdType = defaultHmdType; this.root = new HmdBlockIDProperties(RootName, new StaticCount(1), null); this.valueIDTable = new HmdIDPropertiesTable <HmdValueIDProperties>(); this.blockIDTable = new HmdIDPropertiesTable <HmdBlockIDProperties>(); //AddPropertiesFromDefinition(root); // should I add this? this.enumList = null; //this.enumInlineList = null; }
public void InitParamFactory() { // if not yet initialized if (paramFactory == null) { // get device type hmdType = StereoRenderDevice.GetHmdType(); // create parameter factory paramFactory = StereoRenderDevice.InitParamFactory(hmdType); if (paramFactory == null) { Debug.LogError("Current VR device is unsupported."); } } }
public static String GenerateParsingCode(HmdType hmdType, String enumTypeReferenceName, GeneratorLanguage language, String variable) { if (language == GeneratorLanguage.CSharp) { switch (hmdType) { case HmdType.String: return(variable); case HmdType.Boolean: return(String.Format("Boolean.Parse({0})", variable)); /* * case HmdType.Integer: * IntegerDumType integerDumType = (IntegerDumType)dumType; * if (integerHmdType.byteSize == 1) * { * return String.Format(integerHmdType.isUnsigned ? "Byte" : "SByte" + ".Parse({0})", variable); * } * if (integerHmdType.byteSize == 2) * { * return String.Format(integerHmdType.isUnsigned ? "UInt16" : "Int16" + ".Parse({0})", variable); * } * if (integerHmdType.byteSize == 4) * { * return String.Format(integerHmdType.isUnsigned ? "UInt32" : "Int32" + ".Parse({0})", variable); * } * if (integerHmdType.byteSize == 8) * { * return String.Format(integerHmdType.isUnsigned ? "UInt64" : "Int64" + ".Parse({0})", variable); * } * throw new FormatException(String.Format("The Integer byte size {0}, is not supported by C#", integerHmdType.byteSize)); * case HmdType.Decimal: * throw new NotImplementedException(); * case HmdType.Enumeration: * EnumDumType enumDumType = (EnumDumType)dumType; * return String.Format("({0})Enum.Parse(typeof({0}), {1})",enumHmdType.name, variable); */ } throw new FormatException(String.Format("Unhandled Dum Type Enum \"{0}\" ({1})", hmdType, (Int32)hmdType)); } else { throw new ArgumentException(String.Format("Unrecognized GeneratorLanguage type \"{0}\"", language)); } }
public static String ToHmdTypeString(this HmdType hmdType) { Int32 index = (Int32)hmdType; if (index >= 0 && index < typeStrings.Length) { if (typeStrings[index] == null) { throw new InvalidOperationException( String.Format("Error, the typeStrings entry for hmdType \"{0}\" ({1}) was null?", hmdType.ToString(), index)); } return(typeStrings[index]); } throw new InvalidOperationException( String.Format("Error, unrecognized hmdType \"{0}\" ({1})", hmdType.ToString(), index)); }
internal HmdDesc(HmdDesc_Raw raw) { this.Handle = raw.Handle; this.Type = (HmdType)raw.Type; this.ProductName = Marshal.PtrToStringAnsi(raw.ProductName); this.Manufacturer = Marshal.PtrToStringAnsi(raw.Manufacturer); this.VendorId = raw.VendorId; this.ProductId = raw.ProductId; this.SerialNumber = raw.SerialNumber; this.FirmwareMajor = raw.FirmwareMajor; this.FirmwareMinor = raw.FirmwareMinor; this.CameraFrustumHFovInRadians = raw.CameraFrustumHFovInRadians; this.CameraFrustumVFovInRadians = raw.CameraFrustumVFovInRadians; this.CameraFrustumNearZInMeters = raw.CameraFrustumNearZInMeters; this.CameraFrustumFarZInMeters = raw.CameraFrustumFarZInMeters; this.HmdCaps = raw.HmdCaps; this.TrackingCaps = raw.TrackingCaps; this.DistortionCaps = raw.DistortionCaps; this.Resolution = raw.Resolution; this.WindowsPos = raw.WindowsPos; this.DefaultEyeFov = new FovPort[2] { raw.DefaultEyeFov_0, raw.DefaultEyeFov_1 }; this.MaxEyeFov = new FovPort[2] { raw.MaxEyeFov_0, raw.MaxEyeFov_1 }; this.EyeRenderOrder = new Eye[2] { Eye.Left, Eye.Right }; this.DisplayDeviceName = Marshal.PtrToStringAnsi(raw.DisplayDeviceName); this.DisplayId = raw.DisplayId; }
private static extern IntPtr ovrHmd_CreateDebug(HmdType type);
/// <summary> /// Creates a 'fake' HMD used for debugging only. This is not tied to specific hardware, /// but may be used to debug some of the related rendering. /// </summary> public static Hmd CreateDebug(HmdType type) { IntPtr hmdPtr = ovrHmd_CreateDebug(type); if (hmdPtr == IntPtr.Zero) return null; return new Hmd(hmdPtr); }
public static void TestPropertyParser(String propertyString, HmdType hmdType) { HmdValueIDProperties valueIDProperties = CallParserWithDefaults(propertyString, TestPropertyDictionary); VerifyValueProperties(String.Empty, valueIDProperties, UnrestrictedCount.Instance, hmdType, null); }
String ILanguageGenerator.GenerateStringToTypeParseCode(HmdType hmdType, String variableName) { switch (hmdType) { case HmdType.String: return(variableName); case HmdType.Boolean: return(String.Format("Boolean.Parse({0})", variableName)); case HmdType.Int: return(String.Format("Int32.Parse({0})", variableName)); case HmdType.Int1: return(String.Format("SByte.Parse({0})", variableName)); case HmdType.Int2: return(String.Format("Int16.Parse({0})", variableName)); case HmdType.Int3: case HmdType.Int4: return(String.Format("Int32.Parse({0})", variableName)); case HmdType.Int5: case HmdType.Int6: case HmdType.Int7: case HmdType.Int8: return(String.Format("Int64.Parse({0})", variableName)); case HmdType.Int9: case HmdType.Int10: case HmdType.Int11: case HmdType.Int12: case HmdType.Int13: case HmdType.Int14: case HmdType.Int15: case HmdType.Int16: throw new FormatException("The Integer byte sizes 9-16 are not supported by C#"); case HmdType.UInt: return(String.Format("UInt32.Parse({0})", variableName)); case HmdType.UInt1: return(String.Format("Byte.Parse({0})", variableName)); case HmdType.UInt2: return(String.Format("UInt16.Parse({0})", variableName)); case HmdType.UInt3: case HmdType.UInt4: return(String.Format("UInt32.Parse({0})", variableName)); case HmdType.UInt5: case HmdType.UInt6: case HmdType.UInt7: case HmdType.UInt8: return(String.Format("UInt64.Parse({0})", variableName)); case HmdType.UInt9: case HmdType.UInt10: case HmdType.UInt11: case HmdType.UInt12: case HmdType.UInt13: case HmdType.UInt14: case HmdType.UInt15: case HmdType.UInt16: throw new FormatException("The Integer byte sizes 9-16 are not supported by C#"); case HmdType.Decimal: throw new NotImplementedException(); case HmdType.Enumeration: throw new InvalidOperationException("You called the wrong function for this type"); case HmdType.Empty: throw new InvalidOperationException("You can't parse an empty type"); } throw new FormatException(String.Format("Unhandled Hmd Type Enum \"{0}\" ({1})", hmdType, (Int32)hmdType)); }
/// <summary> /// Creates a 'fake' HMD used for debugging only. This is not tied to specific hardware, /// but may be used to debug some of the related rendering. /// </summary> public Hmd(HmdType type) { this.HmdPtr = ovrHmd_CreateDebug(type); if (this.HmdPtr == IntPtr.Zero) throw new ArgumentException("Failed to create debug HMD of type " + type); }
// // Maybe change to pass in the string offset and length? // public static HmdValueIDProperties ParseValueProperties(String idString, String props, HmdBlockIDProperties definitionParent, HmdProperties hmdProperties) { if (idString == null) { throw new ArgumentNullException("idString"); } Boolean defaultCountPropertyOverriden = false; Boolean defaultHmdTypeOverriden = false; ICountProperty countProperty = hmdProperties.defaultCountProperty; HmdType hmdType = hmdProperties.defaultHmdType; HmdEnumReference enumReference = null; HmdParentReference[] parentOverrideList = null; Int32 offset = 0, saveOffset; // // TODO: To save on memory, maybe I'll add some type of hash lookup so I don't have to instantiate multiple HmdType classes? // while (true) { while (true) { if (offset >= props.Length) { return(new HmdValueIDProperties(idString, countProperty, hmdType, enumReference, definitionParent, parentOverrideList)); } if (!Char.IsWhiteSpace(props[offset])) { break; } offset++; } if (props[offset] >= '0' && props[offset] <= '9') { saveOffset = offset; // keep going while you see 0-9, '-' or '*' do { offset++; if (offset >= props.Length) { break; } } while ((props[offset] >= '0' && props[offset] <= '9') || props[offset] == '-' || props[offset] == '*'); // // Check that the 'count' property has not been specified Twice // if (defaultCountPropertyOverriden) { throw new FormatException("You've specified the 'count' property twice!"); } defaultCountPropertyOverriden = true; countProperty = CountProperty.Parse(props.Substring(saveOffset, offset - saveOffset)); } else if (props[offset] == 's') { if (offset + 6 > props.Length) // 6 = "string".Length { throw new FormatException(String.Format("Found character '{0}', expected to become \"{1}\", but there are some characters missing", HmdTypeClass.String[0], HmdTypeClass.String)); } if (props[offset + 1] != 't' || props[offset + 2] != 'r' || props[offset + 3] != 'i' || props[offset + 4] != 'n' || props[offset + 5] != 'g') { throw new FormatException(String.Format("Expected 'string', but got '{0}'", props.Substring(offset, 6))); } offset += 6; // // Check that the 'type' property has not been specified Twice // if (defaultHmdTypeOverriden) { throw new FormatException("You've specified the 'type' property twice!"); } defaultHmdTypeOverriden = true; hmdType = HmdType.String; } else if (props[offset] == HmdTypeClass.Boolean[0]) { if (offset + HmdTypeClass.Boolean.Length > props.Length) { throw new FormatException( String.Format("Found character '{0}', expected to become \"{1}\", but there are some characters missing", HmdTypeClass.Boolean[0], HmdTypeClass.Boolean)); } offset++; for (int i = 1; i < HmdTypeClass.Boolean.Length; i++) { if (props[offset] != HmdTypeClass.Boolean[i]) { throw new FormatException(String.Format("Expected \"{0}\", but got \"{1}\"", HmdTypeClass.Boolean, props.Substring(offset - i, HmdTypeClass.Boolean.Length))); } offset++; } // // Check that the 'type' property has not been specified Twice // if (defaultHmdTypeOverriden) { throw new FormatException("You've specified the 'type' property twice!"); } defaultHmdTypeOverriden = true; hmdType = HmdType.Boolean; } else if (props[offset] == 'i' || props[offset] == 'u') { Byte byteSize; Boolean isUnsigned = false; if (props[offset] == 'u') { isUnsigned = true; offset++; if (props[offset] != 'i') { throw new FormatException( String.Format("Found character 'u', expected to become \"uint\", but the next character was '{0}'", props[offset])); } } if (offset + 3 > props.Length) { throw new FormatException( String.Format("Found character '{0}', expected to become \"{1}\", but there are some characters missing", isUnsigned ? 'u' : 'i', isUnsigned ? "uint" : "int")); } if (props[offset + 1] != 'n' || props[offset + 2] != 't') { throw new FormatException(String.Format("Expected \"{0}\", but got \"{1}\"", isUnsigned ? "uint" : "int", isUnsigned ? props.Substring(offset - 1, 4) : props.Substring(offset, 3))); } offset += 3; if (offset < props.Length && props[offset] >= '0' && props[offset] <= '9') { saveOffset = offset; do { offset++; } while (offset < props.Length && props[offset] >= '0' && props[offset] <= '9'); byteSize = Byte.Parse(props.Substring(saveOffset, offset - saveOffset)); } else { byteSize = 0; } // // Check that the 'type' property has not been specified Twice // if (defaultHmdTypeOverriden) { throw new FormatException("You've specified the 'type' property twice!"); } defaultHmdTypeOverriden = true; hmdType = HmdTypeClass.GetIntegerType(isUnsigned, byteSize); } else if (props[offset] == 'e') { offset++; if (offset >= props.Length) { throw new FormatException("Found character 'e', expected to become \"enum\" or \"empty\" but the string abrubtly ended"); } if (props[offset] == HmdTypeClass.Empty[1]) { if (offset + HmdTypeClass.Empty.Length - 1 > props.Length) { throw new FormatException("Found \"em\", expected to become \"empty\", but there are some characters missing"); } offset++; for (int i = 2; i < HmdTypeClass.Empty.Length; i++) { if (props[offset] != HmdTypeClass.Empty[i]) { throw new FormatException(String.Format("Expected \"{0}\", but got \"{1}\"", HmdTypeClass.Empty, props.Substring(offset - i, HmdTypeClass.Empty.Length))); } offset++; } // // Check that the 'type' property has not been specified Twice // if (defaultHmdTypeOverriden) { throw new FormatException("You've specified the 'type' property twice!"); } defaultHmdTypeOverriden = true; hmdType = HmdType.Empty; } else if (props[offset] == HmdTypeClass.Enumeration[1]) { if (offset + HmdTypeClass.Enumeration.Length + 1 > props.Length) { throw new FormatException( String.Format("Found \"en\", expected to become \"{0}\", but there are some characters missing", HmdTypeClass.Enumeration)); } offset++; for (int i = 2; i < HmdTypeClass.Enumeration.Length; i++) { if (props[offset] != HmdTypeClass.Enumeration[i]) { throw new FormatException(String.Format("Expected \"{0}\", but got \"{1}\"", HmdTypeClass.Enumeration, props.Substring(offset - i, HmdTypeClass.Enumeration.Length))); } offset++; } // skip whitespace while (true) { if (offset >= props.Length) { throw new FormatException("Expected '(' or 'a-zA-Z', but got EOF"); } if (!Char.IsWhiteSpace(props[offset])) { break; } offset++; } if (props[offset] == '(') { saveOffset = offset + 1; // skip to the next whitespace or ';' while (true) { offset++; if (offset >= props.Length) { throw new FormatException("Expected ')' but reached end of string"); } if (props[offset] == ')') { break; } } String enumReferenceName = (definitionParent == null || definitionParent.definitionContext == null) ? idString.ToLower() : HmdIDProperties.CombineIDContext(definitionParent.idWithContext, idString.ToLower()); HmdEnum newInlineEnum = new HmdEnum(enumReferenceName, props.Substring(saveOffset, offset - saveOffset)); enumReference = newInlineEnum; if (hmdProperties != null) { hmdProperties.AddEnum(newInlineEnum); } offset++; if (defaultHmdTypeOverriden) { throw new FormatException("You've specified the 'type' property twice!"); } defaultHmdTypeOverriden = true; hmdType = HmdType.Enumeration; } else if ((props[offset] >= 'a' && props[offset] <= 'z') || (props[offset] >= 'A' && props[offset] <= 'Z')) { saveOffset = offset; // skip to the next whitespace or ';' while (true) { offset++; if (offset >= props.Length) { break; } if (Char.IsWhiteSpace(props[offset])) { break; } } if (offset - saveOffset <= 0) { throw new FormatException("Unable to parse enum type, the \"enum\" keyword must be either \"enum <type>\" (with only one space before <type>) or \"enum(<value> <value> ...)\""); } enumReference = new HmdEnumReferenceByString(props.Substring(saveOffset, offset - saveOffset)); if (defaultHmdTypeOverriden) { throw new FormatException("You've specified the 'type' property twice!"); } defaultHmdTypeOverriden = true; hmdType = HmdType.Enumeration; } else { throw new FormatException(String.Format("Expected '(' or 'a-zA-Z' after \"enum\", but got '{0}'", props[offset])); } } else { throw new FormatException(String.Format( "Found character 'e', expected to become \"enum\" or \"empty\" but the second character is '{0}'", props[offset])); } } else if (props[offset] == '(') { if (parentOverrideList != null) { throw new FormatException("You've specified the 'parents' property twice!"); } parentOverrideList = ParseParentList(props, ref offset); } else { throw new FormatException( String.Format("Could not recognize first character of property '{0}', of the props string \"{1}\"", props[offset], props)); } } }
public static bool IsNotUnityNativeSupport(HmdType type) { return(type == HmdType.WaveVR); }
String ILanguageGenerator.HmdTypeToLanguageType(HmdType hmdType) { switch (hmdType) { case HmdType.String: return("String"); case HmdType.Boolean: return("Boolean"); case HmdType.Int: return("Int32"); case HmdType.Int1: return("SByte"); case HmdType.Int2: return("Int16"); case HmdType.Int3: case HmdType.Int4: return("Int32"); case HmdType.Int5: case HmdType.Int6: case HmdType.Int7: case HmdType.Int8: return("Int64"); case HmdType.Int9: case HmdType.Int10: case HmdType.Int11: case HmdType.Int12: case HmdType.Int13: case HmdType.Int14: case HmdType.Int15: case HmdType.Int16: throw new FormatException("The Integer byte sizes 9-16 are not supported by C#"); case HmdType.UInt: return("UInt32"); case HmdType.UInt1: return("Byte"); case HmdType.UInt2: return("UInt16"); case HmdType.UInt3: case HmdType.UInt4: return("UInt32"); case HmdType.UInt5: case HmdType.UInt6: case HmdType.UInt7: case HmdType.UInt8: return("UInt64"); case HmdType.UInt9: case HmdType.UInt10: case HmdType.UInt11: case HmdType.UInt12: case HmdType.UInt13: case HmdType.UInt14: case HmdType.UInt15: case HmdType.UInt16: throw new FormatException("The Integer byte sizes 9-16 are not supported by C#"); case HmdType.Decimal: throw new NotImplementedException(); case HmdType.Enumeration: throw new InvalidOperationException("You called the wrong function for this type"); case HmdType.Empty: throw new FormatException("You can't get the type of an empty type."); } throw new FormatException(String.Format("Unhandled Hmd Type Enum \"{0}\" ({1})", hmdType, (Int32)hmdType)); }