Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Works
  • Loading branch information
ssridhar committed Jan 11, 2017
1 parent a1d5810 commit 475c3d4
Show file tree
Hide file tree
Showing 129 changed files with 31,619 additions and 25,215 deletions.
Binary file modified WoodenMan/.vs/WoodenMan/v14/.suo
Binary file not shown.
Binary file modified WoodenMan/Assets/CheckerboardScene.unity
Binary file not shown.
59 changes: 51 additions & 8 deletions WoodenMan/Assets/Scripts/WebSocketClient.cs
Expand Up @@ -2,13 +2,15 @@
using UnityEngine;
using WebSocketSharp;

public class WebSocketClient
public class WebSocketClient : MonoBehaviour
{
WebSocketSharp.WebSocket m_ws;
public string m_Message;
bool m_isWSConnected = false;

// Connect WebSocket
private bool m_isKFWMode = true;
private runLive m_AnyMethod;

void ConnectWS()
{
if (m_isWSConnected)
Expand All @@ -17,7 +19,8 @@ void ConnectWS()
m_Message = "No data.";

//using (m_ws = new WebSocket("ws://localhost:8080/"))
using (m_ws = new WebSocket("ws://139.19.40.35:8080/"))
//using (m_ws = new WebSocket("ws://139.19.111.138:8080/")) // Dell big machine
using (m_ws = new WebSocket("ws://139.19.111.107:8080/")) // Red machine
{
//m_ws.Log.Level = WebSocketSharp.LogLevel.TRACE;
//m_ws.Log.File = "D:\\ws_log.txt";
Expand Down Expand Up @@ -49,24 +52,64 @@ void ConnectWS()
}
}

// Use this for initialization
public void Start()
{
//Screen.SetResolution(1920, 1080, true);
Application.runInBackground = true;

m_isKFWMode = true;
ConnectWS();

if (m_isKFWMode)
m_AnyMethod = new runLiveKFW();
else
m_AnyMethod = new runLiveVNect();

if (gameObject.name == "FollowerCamera")
m_AnyMethod.m_isVRMode = false;
else
{
Debug.Log("Running in VR mode.");
m_AnyMethod.m_isVRMode = true;
}

m_AnyMethod.Start();
}

// Update is called once per frame
public void Update()
{
//Debug.Log(m_Message);
//// Parse message
//if (m_InputParser != null)
// m_InputParser.parse(m_Message);
if (m_AnyMethod == null)
return;

m_AnyMethod.Update(m_Message);
}

public void OnApplicationQuit()
{
if (m_ws != null && m_ws.ReadyState == WebSocketState.OPEN)
m_ws.Close();
}

void OnGUI()
{
if(GUI.Button(new Rect(Screen.currentResolution.width / 2, Screen.currentResolution.height / 20, Screen.currentResolution.width / 15, Screen.currentResolution.height / 20), "Recenter"))
{
Debug.Log("Recentering VR.");
if (m_AnyMethod != null)
m_AnyMethod.recenter();
}

Event e = Event.current;
if (e.isKey)
{
//Debug.Log("Detected key code: " + e.keyCode);
if(e.keyCode == KeyCode.R)
{
Debug.Log("Recentering VR.");
if (m_AnyMethod != null)
m_AnyMethod.recenter();
}
}
}
}
59 changes: 43 additions & 16 deletions WoodenMan/Assets/Scripts/loadKFWSkeleton.cs
Expand Up @@ -2,7 +2,8 @@
using System.IO;
using System.Collections.Generic;

public class loadKFWSkeleton : MonoBehaviour {
public class loadKFWSkeleton : MonoBehaviour
{

private StreamReader m_3DPoseFileStream;

Expand All @@ -15,22 +16,28 @@ public class loadKFWSkeleton : MonoBehaviour {
private bool m_isKFWFingers = false;
private int m_FrameCtr = 0;
private bool m_isValid = false;
private bool m_isVRMode = false;
private bool m_isMoveFloor = false;

private bool m_isVNECTMode = true;
private List<int> m_ValidJointIdx;

private string m_SequenceName;

// Use this for initialization
void Start () {
void Start()
{
//Screen.SetResolution(1920, 1080, true);
Screen.SetResolution(1280, 720, true);
Application.runInBackground = true;

m_isVNECTMode = true;
m_SequenceName = "DCorridor_VNECT";
//m_isVNECTMode = false;
//m_SequenceName = "DCorridor_KFW";
m_isVRMode = true;
m_isMoveFloor = false;
m_isVNECTMode = false;

if (m_isVNECTMode)
m_SequenceName = "DCorridor_VNECT";
else
m_SequenceName = "DCorridor_KFW";
FileStream fs = new FileStream(UnityEngine.Application.streamingAssetsPath + "/" + m_SequenceName + ".txt", FileMode.Open, FileAccess.Read, FileShare.Read);
m_3DPoseFileStream = new StreamReader(fs);
if (m_3DPoseFileStream == null)
Expand Down Expand Up @@ -173,7 +180,8 @@ public class loadKFWSkeleton : MonoBehaviour {
}

// Update is called once per frame
void Update () {
void Update()
{
string Line = m_3DPoseFileStream.ReadLine();
m_isValid = false;

Expand All @@ -191,7 +199,7 @@ public class loadKFWSkeleton : MonoBehaviour {
if ((Tokens.Length - ParseOffset) / 3 != 58)
return;
float LowestY = 0.0f;
Vector3[] Joints = new Vector3[(Tokens.Length-ParseOffset) / 3];
Vector3[] Joints = new Vector3[(Tokens.Length - ParseOffset) / 3];
for (int i = 0; i < m_JointSpheres.Length; ++i)
{
int Idx = m_ValidJointIdx[i];
Expand All @@ -215,12 +223,22 @@ public class loadKFWSkeleton : MonoBehaviour {
float PlaneFootBuffer = 0.02f;
Vector3 OrigPos = Plane.transform.position;

Plane.transform.position = new Vector3(OrigPos[0], LowestY - PlaneFootBuffer, OrigPos[2]);
if(m_isMoveFloor)
Plane.transform.position = new Vector3(OrigPos[0], LowestY - PlaneFootBuffer, OrigPos[2]);

// Move camera with checkerboard plane
GameObject FollowerCamera = GameObject.Find("FollowerCamera");
OrigPos = FollowerCamera.transform.position;
FollowerCamera.transform.position = new Vector3(OrigPos[0], Plane.transform.position.y + 1, OrigPos[2]);
if (m_isVRMode)
{
// Align VR head pose with character
FollowerCamera.transform.position = Joints[6];
FollowerCamera.transform.rotation = GvrViewer.Controller.Head.transform.rotation;
}
else
{
// Move camera with checkerboard plane
OrigPos = FollowerCamera.transform.position;
FollowerCamera.transform.position = new Vector3(OrigPos[0], Plane.transform.position.y + 1, OrigPos[2]);
}
}

//0-root_rx, 1-spine_3_rx
Expand Down Expand Up @@ -311,12 +329,21 @@ public class loadKFWSkeleton : MonoBehaviour {
float PlaneFootBuffer = 0.02f;
Vector3 OrigPos = Plane.transform.position;

Plane.transform.position = new Vector3(OrigPos[0], LowestY - PlaneFootBuffer, OrigPos[2]);
if (m_isMoveFloor)
Plane.transform.position = new Vector3(OrigPos[0], LowestY - PlaneFootBuffer, OrigPos[2]);

// Move camera with checkerboard plane
GameObject FollowerCamera = GameObject.Find("FollowerCamera");
OrigPos = FollowerCamera.transform.position;
FollowerCamera.transform.position = new Vector3(OrigPos[0], Plane.transform.position.y + 1, OrigPos[2]);
if (m_isVRMode)
{
FollowerCamera.transform.position = Joints[3];
FollowerCamera.transform.rotation = GvrViewer.Controller.Head.transform.rotation;
}
else
{
OrigPos = FollowerCamera.transform.position;
FollowerCamera.transform.position = new Vector3(OrigPos[0], Plane.transform.position.y + 1, OrigPos[2]);
}
}

//0-SpineBase, 1-SpineMid
Expand Down

0 comments on commit 475c3d4

Please sign in to comment.