Skip to content

Commit 279e0ed

Browse files
committed
Merge branch 'Unity5Refactor' into Distortion
2 parents d5afd25 + ef0f6e8 commit 279e0ed

4 files changed

Lines changed: 72 additions & 31 deletions

File tree

OSVR-Unity/Assets/OSVRUnity/src/DeviceDescriptor.cs

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,18 @@
2020

2121
using UnityEngine;
2222
using System.Collections;
23+
using System.Text;
2324

2425
//a class for storing information about a device based on it's json descriptor file
2526
public class DeviceDescriptor {
2627

28+
//filename
29+
private string _fileName = "";
30+
public string FileName
31+
{
32+
get { return _fileName; }
33+
set { _fileName = value; }
34+
}
2735
//hmd
2836
private string _vendor = "";
2937
public string Vendor
@@ -153,10 +161,11 @@ public int Rotate180
153161

154162
//constructors
155163
public DeviceDescriptor() { }
156-
public DeviceDescriptor(float monocularHorizontal, float monocularVertical, float overlapPercent, float pitchTilt,
164+
public DeviceDescriptor(string fileName, float monocularHorizontal, float monocularVertical, float overlapPercent, float pitchTilt,
157165
int width, int height, int videoInputs, string displayMode, float k1Red, float k1Green, float k1Blue, float leftRoll,
158166
float rightRoll, float centerProjX, float centerProjY, int rotate180)
159167
{
168+
this._fileName = fileName;
160169
this._monocularHorizontal = monocularHorizontal;
161170
this._monocularVertical = monocularVertical;
162171
this._overlapPercent = overlapPercent;
@@ -177,32 +186,41 @@ public DeviceDescriptor(float monocularHorizontal, float monocularVertical, floa
177186

178187
public override string ToString()
179188
{
180-
string deviceDescription = "Device Description:\n" + "HMD:\n";
181-
deviceDescription += "Vendor = " + Vendor + "\n";
182-
deviceDescription += "Model = " + Model + "\n";
183-
deviceDescription += "Version = " + Version + "\n";
184-
deviceDescription += "Note = " + Note + "\n";
185-
deviceDescription += "\nFIELD OF VIEW:\n";
186-
deviceDescription += "monocular_horizontal = " + MonocularHorizontal + "\n";
187-
deviceDescription += "monocular_vertical = " + MonocularVertical + "\n";
188-
deviceDescription += "overlap_percent = " + OverlapPercent + "\n";
189-
deviceDescription += "pitch_tilt = " + PitchTilt + "\n";
190-
deviceDescription += "\nRESOLUTION\n";
191-
deviceDescription += "width = " + Width + "\n";
192-
deviceDescription += "height = " + Height + "\n";
193-
deviceDescription += "video_inputs = " + VideoInputs + "\n";
194-
deviceDescription += "display_mode = " + DisplayMode + "\n";
195-
deviceDescription += "\nDISTORTION\n";
196-
deviceDescription += "k1_red = " + K1Red + "\n";
197-
deviceDescription += "k1_green = " + K1Green + "\n";
198-
deviceDescription += "k1_blue = " + K1Blue + "\n";
199-
deviceDescription += "\nRENDERING\n";
200-
deviceDescription += "left_roll = " + LeftRoll + "\n";
201-
deviceDescription += "right_roll = " + RightRoll + "\n";
202-
deviceDescription += "\nEYES\n";
203-
deviceDescription += "center_proj_x = " + CenterProjX + "\n";
204-
deviceDescription += "center_proj_y = " + CenterProjY + "\n";
205-
deviceDescription += "rotate_180 = " + Rotate180 + "\n";
206-
return deviceDescription;
189+
190+
if(FileName.Equals(""))
191+
{
192+
return "No json file has been provided.";
193+
}
194+
//print
195+
StringBuilder jsonPrinter = new StringBuilder(64);
196+
jsonPrinter.AppendLine("Json File Device Description:")
197+
.Append("filename = ").AppendLine(FileName)
198+
.Append("HMD\n")
199+
.Append("vendor = ").AppendLine(Vendor)
200+
.Append("model = ").AppendLine(Model)
201+
.Append("version = ").AppendLine(Version)
202+
.Append("notes = ").AppendLine(Note)
203+
.Append("\nFIELD OF VIEW\n")
204+
.Append("monocular_horizontal = ").AppendLine(MonocularHorizontal.ToString())
205+
.Append("monocular_vertical = ").AppendLine(MonocularVertical.ToString())
206+
.Append("overlap_percent = ").AppendLine(OverlapPercent.ToString())
207+
.Append("pitch_tilt = ").AppendLine(PitchTilt.ToString())
208+
.Append("\nRESOLUTION\n")
209+
.Append("width = ").AppendLine(Width.ToString())
210+
.Append("height = ").AppendLine(Height.ToString())
211+
.Append("video_inputs = ").AppendLine(VideoInputs.ToString())
212+
.Append("display_mode = ").AppendLine(DisplayMode)
213+
.Append("\nDISTORTION\n")
214+
.Append("k1_red = ").AppendLine(K1Red.ToString())
215+
.Append("k1_green = ").AppendLine(K1Green.ToString())
216+
.Append("k1_blue = ").AppendLine(K1Blue.ToString())
217+
.Append("\nRENDERING\n")
218+
.Append("left_roll = ").AppendLine(LeftRoll.ToString())
219+
.Append("right_roll = ").AppendLine(RightRoll.ToString())
220+
.Append("\nEYES\n")
221+
.Append("center_proj_x = ").AppendLine(CenterProjX.ToString())
222+
.Append("center_proj_y = ").AppendLine(CenterProjY.ToString())
223+
.Append("rotate_180 = ").AppendLine(Rotate180.ToString());
224+
return jsonPrinter.ToString();
207225
}
208226
}

OSVR-Unity/Assets/OSVRUnity/src/DisplayInterface.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ namespace Unity
3535
/// </summary>
3636
public class DisplayInterface : MonoBehaviour
3737
{
38-
private string _deviceDescriptorJson;
39-
public TextAsset JsonDescriptorFile;
38+
private string _deviceDescriptorJson; //a string that is the JSON file to be parsed
39+
public TextAsset JsonDescriptorFile; //drop the json file into this slot in the Unity inspector
4040
void Awake()
4141
{
4242
if (JsonDescriptorFile != null)
@@ -49,6 +49,8 @@ void Awake()
4949
}
5050
}
5151

52+
53+
5254
/// <summary>
5355
/// This function will parse the device parameters from a device descriptor json file.
5456
///
@@ -70,6 +72,7 @@ public DeviceDescriptor GetDeviceDescription()
7072
//create a device descriptor object for storing the parsed json in an object
7173
DeviceDescriptor deviceDescriptor;
7274
JsonTextReader reader;
75+
7376

7477
reader = new JsonTextReader(new StringReader(_deviceDescriptorJson));
7578
if(reader != null)
@@ -81,6 +84,15 @@ public DeviceDescriptor GetDeviceDescription()
8184
Debug.LogError("No Device Descriptor detected.");
8285
return null;
8386
}
87+
if(JsonDescriptorFile != null)
88+
{
89+
deviceDescriptor.FileName = JsonDescriptorFile.name;
90+
}
91+
else
92+
{
93+
deviceDescriptor.FileName = "No descriptor file has been assigned. Using parameters from /display";
94+
}
95+
8496
//parsey
8597
while (reader.Read())
8698
{
@@ -152,6 +164,7 @@ public DeviceDescriptor GetDeviceDescription()
152164
}
153165
}
154166
}
167+
155168
return deviceDescriptor;
156169
}
157170
}

OSVR-Unity/Assets/OSVRUnity/src/VRHead.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void Init()
178178
private void GetDeviceDescription()
179179
{
180180
_deviceDescriptor = GetComponent<DisplayInterface>().GetDeviceDescription();
181-
// Debug.Log(deviceDescriptor.ToString());
181+
Debug.Log(_deviceDescriptor.ToString());
182182
if (_deviceDescriptor != null)
183183
{
184184
switch (_deviceDescriptor.DisplayMode)

OSVR-Unity/CHANGES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# OSVR Unity Plugin Changes
2+
3+
This is an abbreviated changelog for the OSVR Unity Plugin.
4+
5+
Use git for a full changelog.
6+
7+
##Recent Changes (updated 18-March-2015)
8+
- Refactored VRHead.cs and VREye.cs to be Unity 5-friendly (mostly instances of "camera" that needed to become GetComponent<Camera>()). Upgrading from Unity 4 to Unity 5 should be seamless.
9+
- VRDisplayTracked.prefab has been updated to use the json descriptor file for the HDK by default. If you are using another HMD, be sure to set the corresponding json file on the VRDisplayTracked prefab's DisplayInterface script.
10+
- Fixed issue with stereo overlap and roll for HMDs with multiple video inputs.

0 commit comments

Comments
 (0)