public void queueServerCommand(StatefulMain.Command cmd) { //Debug.Log("Server said: "+cmd.ToString()+", queueing"); cmdQueue.Enqueue(cmd); }
// Update is called once per frame void Update() { if (DebugMode) { if (debugTextQueue.Count > 0) { debugText.text += '\n' + debugTextQueue.Dequeue(); } } updateSessionIDText(); Frame frame = m_leapController.Frame(); Vector3 tipPosition = new Vector3(0.5f, 0.5f, 0.0f); switch (getIntent()) { #region intend computing case INTEND.CREATESPHERE: voxel.createSphere(voxelFieldSize / 3); initMesh(false); break; case INTEND.CREATERND: voxel.createRandomGrid(); initMesh(false); break; case INTEND.CREATEBLOCK: voxel.createBlock(); initMesh(false); break; case INTEND.MOVEINIT: if (frame.Tools.Count != 0) { startMovePosition = frame.Tools[0].TipPosition.ToUnityScaled(false); startMovePosition = handController.transform.TransformPoint(startMovePosition); lastMoveOffset = posOffset; } else { moveObject = false; //debug nachricht das die leap sichtbar sein muss zum bewegen } break; case INTEND.MOVE: if (moveObject == true) { if (frame.Tools.Count == 0) { return; } tipPosition = frame.Tools[0].TipPosition.ToUnityScaled(false); tipPosition = handController.transform.TransformPoint(tipPosition); posOffset = lastMoveOffset + (tipPosition - startMovePosition); resetBoundingBoxPosition(); updateMesh(); } break; case INTEND.MOD: if (m_leapController.IsConnected) { if (frame.Tools.Count == 0) //only modify if there is a tool { return; } tipPosition = frame.Tools[0].TipPosition.ToUnityScaled(false); tipPosition = handController.transform.TransformPoint(tipPosition); } else { // for testing purposes //Debug.Log("modding at: " + tipPosition.x / scaling + ";" + tipPosition.y / scaling + ";" + tipPosition.z / scaling); } tipPosition -= posOffset; //apply modification voxelObjectGPU.applyToolAt(getRotatedPosition(tipPosition / scaling), currentTool, objectScaling); updateMesh(); break; case INTEND.RESETVIEW: UnityEngine.VR.InputTracking.Recenter(); break; case INTEND.RESETALL: //todo call function from server via websocket resetAll(false); break; case INTEND.NONE: break; #endregion } //check, if server has send any commands if (cmdQueue.Count > 0) { #region Webinterface StatefulMain.Command newCommand = cmdQueue.Dequeue(); addDebugText("Server Command recieved:" + newCommand.ToString()); switch (newCommand) { case StatefulMain.Command.RESET_ALL: { resetObjectTransformForScreeshot(); resetAll(true); voxelObjectGPU.resetTools(); //Debug.Log("(Servercmd) reseting everything"); } break; case StatefulMain.Command.RESET_SCREENSHOTS: { scmanager.ResetScreenshots(); //Debug.Log("(Servercmd) reseting screenshot-storage"); } break; case StatefulMain.Command.RESET_TOOLS: { voxelObjectGPU.resetTools(); updateRadiusText(); updateStrengthText(); toolMaterial.SetFloat("_Radius", voxelObjectGPU.modManager.getToolRadius()); //Debug.Log("(Servercmd) reseting tool parameter"); } break; case StatefulMain.Command.NEXT_USER: { userID += 1; resetObjectTransformForScreeshot(); //make screenshoot of user generated model scmanager.TakeScreenShoot(); //reset all for next user resetAll(true); voxelObjectGPU.resetTools(); //reset timer timeRemaining = timeMax; //Debug.Log("(Servercmd) preparing programm for next user"); } break; case StatefulMain.Command.TAKE_SCREENSHOT: { resetObjectTransformForScreeshot(); scmanager.TakeScreenShoot(); //Debug.Log("(Servercmd) rendering screenshot"); } break; case StatefulMain.Command.DELETE_LAST_SCREENSHOT: { scmanager.ResetLastScreenshot(); //Debug.Log("(Servercmd) rendering screenshot"); } break; case StatefulMain.Command.RESET_HMD_LOCATION: { UnityEngine.VR.InputTracking.Recenter(); //Debug.Log("(Servercmd) recenter HMD"); } break; case StatefulMain.Command.MAX_TIME_3_MINUTES: { this.timeMax = 180.0f; } break; case StatefulMain.Command.MAX_TIME_5_MINUTES: { this.timeMax = 300.0f; } break; case StatefulMain.Command.MAX_TIME_UNLIMITED: { this.timeMax = -1.0f; } break; default: { //Debug.Log("I should do something with this \"" + cmdQueue.Dequeue().ToString() + "\"command..."); } break; } #endregion } if (timeMax > 0 && timeRemaining >= 0) { this.timeRemaining -= Time.deltaTime; } if (timeRemaining < 60) { this.CountdownBox.SetActive(true); if (timeRemaining > 1) { this.countdownCanvas.text = "Countdown:\n" + timeRemaining.ToString("0.00"); } else { this.countdownCanvas.text = "Countdown:\n" + "0.00"; } } if (timeRemaining % 30 == 0) { //Debug.Log("time Left:" + timeRemaining); if (timeRemaining == 0) { // TODO alert user //Debug.Log("time is up, next user!"); } } // change tools manualy with keyboard for testing if (Input.GetKeyUp("1")) { setPullTool(); } if (Input.GetKeyUp("2")) { setPushTool(); } if (Input.GetKeyUp("3")) { setSmoothTool(); } }