/* * 根据头显类型刷新配置,当config.driverConfig.multiHmdSupport = true时有效 */ private bool refreshConfig(ClientList.Client client) { if (2 == client.deviceType) //Quest(设备类型:0:Unknown;1:Go;2:Quest) { config.driverConfig.hasTouch = true; //Quest双手柄 config.driverConfig.serialNumber = "WMHD000X000XXX"; config.driverConfig.trackingSystemName = "oculus"; config.driverConfig.modelNumber = "Oculus Rift S"; config.driverConfig.manufacturerName = "Oculus driver 1.38.0"; config.driverConfig.renderModelName = "generic_hmd"; config.driverConfig.registeredDeviceType = "oculus_rifts"; config.driverConfig.controllerTrackingSystemName = "oculus"; config.driverConfig.controllerManufacturerName = "Oculus"; config.driverConfig.controllerModelNumber = "Oculus Rift S"; config.driverConfig.controllerRenderModelNameLeft = "oculus_rifts_controller_left"; config.driverConfig.controllerRenderModelNameRight = "oculus_rifts_controller_right"; config.driverConfig.controllerSerialNumber = "WMHD000X000XXX_Controller"; config.driverConfig.controllerType = "oculus_touch"; config.driverConfig.controllerRegisteredDeviceType = "oculus_touch"; config.driverConfig.controllerLegacyInputProfile = "oculus_touch"; config.driverConfig.controllerInputProfilePath = "{cloudvr_server}/input/touch_profile.json"; config.driverConfig.renderWidth = client.renderWidth; //使用头盔侧上报的渲染画面的宽(pixel) config.driverConfig.renderHeight = client.renderHeight; //使用头盔侧上报的渲染画面的高(pixel) //config.driverConfig.renderWidth = 2880;//自行指定渲染画面的宽(pixel) //config.driverConfig.renderHeight = 1440;//自行指定渲染画面的高(pixel) config.driverConfig.eyeFov = new double[] { client.leftEyeFovLeft, client.leftEyeFovRight, client.leftEyeFovTop, client.leftEyeFovBottom, client.rightEyeFovLeft, client.rightEyeFovRight, client.rightEyeFovTop, client.rightEyeFovBottom };//使用头盔侧上报的FOV参数 //config.driverConfig.eyeFov = new double[] { 52, 42, 53, 47, 42, 52, 53, 47 };//注意:如画面显示不正常可尝试此配置,左、右眼四向FOV配置(单位:°){ 左眼:左FOV, 左眼:右FOV, 左眼:上FOV, 左眼:下FOV, 右眼:左FOV, 右眼:右FOV, 右眼:上FOV, 右眼:下FOV} } else if (1 == client.deviceType) //Go { config.driverConfig.hasTouch = false; //Go单手柄 config.driverConfig.serialNumber = "HTCVive-001"; config.driverConfig.trackingSystemName = "Vive Tracker"; config.driverConfig.modelNumber = "Cloud VR driver server"; config.driverConfig.manufacturerName = "HTC"; config.driverConfig.renderModelName = "generic_hmd"; config.driverConfig.registeredDeviceType = "vive"; config.driverConfig.controllerTrackingSystemName = "Cloud VR Remote Controller"; config.driverConfig.controllerManufacturerName = "Cloud VR "; config.driverConfig.controllerModelNumber = "Cloud VR Remote Controller"; config.driverConfig.controllerRenderModelNameLeft = "vr_controller_vive_1_5"; config.driverConfig.controllerRenderModelNameRight = "vr_controller_vive_1_5"; config.driverConfig.controllerSerialNumber = "Cloud VR Remote Controller"; config.driverConfig.controllerType = "vive_controller"; config.driverConfig.controllerRegisteredDeviceType = "vive_controller"; config.driverConfig.controllerLegacyInputProfile = "vive_controller"; config.driverConfig.controllerInputProfilePath = "{cloudvr_server}/input/vive_controller_profile.json"; config.driverConfig.renderWidth = client.renderWidth; //使用头盔侧上报的渲染画面的宽(pixel) config.driverConfig.renderHeight = client.renderHeight; //使用头盔侧上报的渲染画面的高(pixel) //config.driverConfig.renderWidth = 2560;//自行指定渲染画面的宽(pixel) //config.driverConfig.renderHeight = 1440;//自行指定渲染画面的高(pixel) config.driverConfig.eyeFov = new double[] { client.leftEyeFovLeft, client.leftEyeFovRight, client.leftEyeFovTop, client.leftEyeFovBottom, client.rightEyeFovLeft, client.rightEyeFovRight, client.rightEyeFovTop, client.rightEyeFovBottom };//使用头盔侧上报的FOV参数 //config.driverConfig.eyeFov = new double[] { 45, 45, 45, 45, 45, 45, 45, 45 };//左、右眼四向FOV配置(单位:°){ 左眼:左FOV, 左眼:右FOV, 左眼:上FOV, 左眼:下FOV, 右眼:左FOV, 右眼:右FOV, 右眼:上FOV, 右眼:下FOV} } else//其它头盔 { config.driverConfig.hasTouch = false;//Go单手柄 config.driverConfig.serialNumber = "HTCVive-001"; config.driverConfig.trackingSystemName = "Vive Tracker"; config.driverConfig.modelNumber = "Cloud VR driver server"; config.driverConfig.manufacturerName = "HTC"; config.driverConfig.renderModelName = "generic_hmd"; config.driverConfig.registeredDeviceType = "vive"; config.driverConfig.controllerTrackingSystemName = "Cloud VR Remote Controller"; config.driverConfig.controllerManufacturerName = "Cloud VR "; config.driverConfig.controllerModelNumber = "Cloud VR Remote Controller"; config.driverConfig.controllerRenderModelNameLeft = "vr_controller_vive_1_5"; config.driverConfig.controllerRenderModelNameRight = "vr_controller_vive_1_5"; config.driverConfig.controllerSerialNumber = "Cloud VR Remote Controller"; config.driverConfig.controllerType = "vive_controller"; config.driverConfig.controllerRegisteredDeviceType = "vive_controller"; config.driverConfig.controllerLegacyInputProfile = "vive_controller"; config.driverConfig.controllerInputProfilePath = "{cloudvr_server}/input/vive_controller_profile.json"; config.driverConfig.renderWidth = 2560; //自行指定渲染画面的宽(pixel) config.driverConfig.renderHeight = 1440; //自行指定渲染画面的高(pixel) config.driverConfig.eyeFov = new double[] { 45, 45, 45, 45, 45, 45, 45, 45 }; //左、右眼四向FOV配置(单位:°){ 左眼:左FOV, 左眼:右FOV, 左眼:上FOV, 左眼:下FOV, 右眼:左FOV, 右眼:右FOV, 右眼:上FOV, 右眼:下FOV} } return(config.Save(this)); //保存配置 }
//连接头盔 async private void UpdateClients() { if (!socket.Connected)//未与头显驱动取得连接 { //AosenUpdatelog("SteamVR is not running."); UpdateConnectionState(false); //更新连接状态为false clientStatus = "Disconnected"; //AosenUpdate //log("client Disconnected"); if (needToRestartSteamVR) //需要重启SteamVR { needToRestartSteamVR = false; LaunchServer();//启动SteamVR //log("Restart SteamVR."); } return; } string str = await socket.SendCommand("GetConfig"); //获取配置及头显接入等信息 if (str == "") //未能成功获取配置信息 { clientStatus = "Disconnected"; //AosenUpdate //log("client Disconnected"); //AosenUpdate UpdateConnectionState(false); //更新连接状态为false return; } string result = await socket.SendCommand("GetRestartingFlag");//获取SteamVR是否正在重启动过程中 if ("true" == result) { startingSteamVR = true; //log("SteamVR is still running, and it needs to be restarted."); } else { startingSteamVR = false; //log("SteamVR is running."); } var configs = ParsePacket(str); if (configs["Connected"] == "1")//已有头显接入 { deviceBrand = configs["ClientName"]; deviceID = configs["ClientId"]; clientStatus = "Connected"; //AosenUpdate //log("client Connected");//AosenUpdate UpdateConnectionState(true); //设置为已有头盔接入 //更新服务器状态 UpdateServerStatus("Connected!\r\n\r\n" + configs["ClientName"] + ":" + configs["ClientId"] + "\r\n" + "ServerPort:" + configs["ServerPort"] + "\r\n" + configs["RefreshRate"] + " FPS"); // UpdateClientStatistics(); //更新体验指标显示 return; } deviceBrand = ""; UpdateConnectionState(false);//更新状态为没有头盔接入 //next 2 lines AosenUpdate clientStatus = "Disconnected"; //log("client Disconnected"); string clientsStr = await socket.SendCommand("GetRequests");//获取等待接入的头盔信息 if ("" == clientsStr) { return; } var clients = clientList.ParseRequests(clientsStr);//解析当前有哪些头盔等待连接 //如果有头盔接入就直接把该头盔写入到自动连接列表 foreach (var client in clients) { if (client.Name == "" || client.Address == "") { break; } clientList.EnableAutoConnect = true; //设置自动连接头盔 if (!clientList.getList().Contains(client)) //该头盔之前在自动连接列表中不存在 { //增加该头盔到自动连接列表 clientList.AddAutoConnect(client); return;//这里只添加自动连接列表中的第一个头盔 } } //获取一个需要自动连接的头盔 var autoConnect = clientList.GetAutoConnectableClient(); if (autoConnect != null) { if (config.driverConfig.multiHmdSupport) //设置了支持多种头显 { if (null == previousHmd.Address || previousHmd.Equals(autoConnect)) //如果头盔型号不变或者从未连接过头盔则直接连接 { if (false == startingSteamVR) //如果SteamVR已启动完毕 { //连接头显前可以修改一些配置 refreshConfig(autoConnect); //根据不同种类的头显刷新 await clientList.Connect(socket, autoConnect); //与头盔建立连接 previousHmd = autoConnect.Copy() as ClientList.Client; //记录已连接的头盔型号 log("Try to connect HMD " + autoConnect.Name + "."); } } else//否则标记SteamVR需要重启 { startingSteamVR = true;//标记头显驱动正在启动 await socket.SendCommand("SetRestarting true"); //设置头显驱动内部重启标志位为true ShutDownSteamVR(); //关闭头显驱动 previousHmd = new ClientList.Client(); //重置已连接头显的信息 needToRestartSteamVR = true; //标记需要重启SteamVR log("Different HMD is detected, shutdown SteamVR in order to restart it."); } } else//不支持多种头显 { await clientList.Connect(socket, autoConnect);//与头盔建立连接 previousHmd = autoConnect.Copy() as ClientList.Client;//记录已连接的头盔型号 } } }