// Adds a point to the line currently being drawn private void addPointToLine(Vector3 pointToAdd, bool overrideThreshold = false) { if (!overrideThreshold && (pointToAdd - prevPaintPoint).magnitude <= 0.01f) { Debug.Log("Change in distance not large enough. Start: " + prevPaintPoint + " End: " + pointToAdd); return; } if (prevPaintPoint == pointToAdd) { Debug.Log("Point to add is same as previous point: " + pointToAdd); return; } currLine.AddPoint(pointToAdd); prevPaintPoint = pointToAdd; // add to history without incrementing index int index = GetComponent <PaintController> ().drawingHistoryIndex; int layerNum = GetComponent <PaintController>().GetActiveLayerNum(); paintBrushSceneObject.GetComponent <DrawingHistoryManager> ().addDrawingCommand(index, 0, pointToAdd, currLine.GetColor(), paintLineThickness, lMat, lMat_texture, layerNum); // Make sure the trail is off if (brushTipObject.activeSelf) { brushTipObject.GetComponent <TrailRenderer>().enabled = false; } }
void Update() { SteamVR_Controller.Device device = SteamVR_Controller.Input((int)trackedObj.index); if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { GameObject go = new GameObject(); go.AddComponent <MeshFilter>(); go.AddComponent <MeshRenderer>(); currLine = go.AddComponent <GraphicsLineRenderer>(); currLine.lmat = new Material(lMat); currLine.SetWidth(.1f); } else if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { currLine.AddPoint(trackedObj.transform.position); numClicks++; } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { numClicks = 0; currLine = null; } if (currLine != null) { currLine.lmat.color = ColorManager.Instance.GetCurrentColor(); } }
// Update is called once per frame void Update() { SteamVR_Controller.Device device = SteamVR_Controller.Input((int)trackedObj.index); if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { GameObject go = new GameObject(); //currLine = go.AddComponent<LineRenderer> (); go.AddComponent <MeshFilter> (); go.AddComponent <MeshRenderer> (); currLine = go.AddComponent <GraphicsLineRenderer> (); currLine.lmat = lMat; //currLine.SetWidth (.1f, .1f); currLine.SetWidth(.1f); numClicks = 0; } else if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { //currLine.SetVertexCount (numClicks + 1); //currLine.SetPosition (numClicks, trackedObj.transform.position); currLine.AddPoint(trackedObj.transform.position); numClicks++; } }
void Update() { now = Pose.transform.position; float dist = Vector3.Distance(older, now); if (Squeeze.GetAxis(Pose.inputSource) > 0.1f && end == false) { if (GameObject.Find("LeftHand").GetComponent <UIIcon>().Eraser.activeSelf == true) { Nodelete = true;//TODO:這可能是個地雷,需要改名 & 想一下是不是全部考慮到 } end = true; DrawLineTest = new GameObject(); DrawLineTest.AddComponent <MeshFilter>(); DrawLineTest.AddComponent <MeshRenderer>(); DrawLineTest.AddComponent <Rigidbody>().useGravity = false; DrawLineTest.AddComponent <MeshCollider>().convex = true; DrawLineTest.AddComponent <MeshColiderAndSphere>(); DrawLineTest.transform.gameObject.tag = "test"; //DrawLineTest.GetComponent<MeshCollider>().isTrigger = true; draw = DrawLineTest.AddComponent <GraphicsLineRenderer>(); ChangeColor(); draw.Imat = gObjectMaterial; draw.setVectorCross(Pose.transform.up, Pose.transform.forward); draw.setwidth(LineWidth); draw.AddPoint(now); DrawLineTest.name = "TEST" + i; older = now; } else if (Squeeze.GetAxis(Pose.inputSource) > 0.1) { if (dist > 0.015) { draw.ErrorCheck = true; draw.setwidth2(Squeeze.GetAxis(Pose.inputSource)); draw.setVectorCross(Pose.transform.up, Pose.transform.forward); draw.AddPoint(now); older = now; } } if (Squeeze.GetAxis(Pose.inputSource) < 0.1f && end == true) //TODO: 加一下註解, 這個 if()是什麼意思 { Nodelete = false; //TODO:這可能是個地雷,需要改名 & 想一下是不是全部考慮到 if (MyDrawLine.Length < 1) { } else { //這塊其實是 myDrawOneMore() 或 myDrawAddOne() 之類的名字!!! MyDrawLine[i] = GameObject.Find("TEST" + i); bool DrawLineCheck = MyDrawLine[i].GetComponent <GraphicsLineRenderer>().Check(); //用來解決空按的問題, 它的意思 有空物件,刪掉了哦! if (DrawLineCheck == true) //TODO: 這個名字 DrawLineCheck 及前一行的 Check() 名字取得不好, 無法馬上知道它的意思,if()就很難想懂 { } else { //沒有空物件時,才建 KdTree 的爸爸 empty GameObject的transform, transform拿來用 KdTreeInstanceFunction(); //TODO: 名字看不懂,會忘記的名字,就要改成不會忘記/有意義的名字 } //Debug.Log(i); end = false;//TODO: 名字取得不好, 所以別人不好理解 } } //if (Squeeze.GetActive(Pose.inputSource)) { // Debug.Log("Squeeze:"+Squeeze.GetAxis(Pose.inputSource)); //} /* * if (SnapTurnRight.GetStateDown(Pose.inputSource)) * { * if (LineWidth > 0.1f) LineWidth = 0.09f; * LineWidth *= 1.2f; * Box.BoxControlWidth(LineWidth); * //Debug.Log(LineWidth); * //Debug.Log("Yes:" + LineWidth); * } * else if (SnapTurnLeft.GetStateDown(Pose.inputSource)) * { * if (LineWidth < 0.02f) LineWidth = 0.02f; * LineWidth *= 0.8f; * //Debug.Log("Yes:" + LineWidth); * Box.BoxControlWidth(LineWidth); * //Debug.Log(LineWidth); * }*/ }
// Update is called once per frame void Update() { Vector3 endPoint = getRayEndPoint(rayDist); //renderSphereAsBrushTip (endPoint); bool firstTouchCondition; bool whileTouchedCondition; GameObject currentSelection = eventSystemManager.currentSelectedGameObject; bool isPanelSelected = currentSelection == null; firstTouchCondition = (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Began && isPanelSelected); whileTouchedCondition = (Input.touchCount == 1 && isPanelSelected); if (firstTouchCondition == true) { // check if you're in drawing mode. if not, return. if (!paintPanel.activeSelf) { textLabel.text = "First Click Start Painting"; return; } Debug.Log("First touch"); // start drawing line GameObject go = new GameObject(); go.transform.position = endPoint; go.transform.parent = drawingRootSceneObject.transform; go.AddComponent <MeshFilter> (); go.AddComponent <MeshRenderer> (); currLine = go.AddComponent <GraphicsLineRenderer> (); currLine.lmat = new Material(lMat); currLine.SetWidth(paintLineThickness); Color newColor = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f)); //currLine.lmat.color = new Color (colorRed, colorGreen, colorBlue); currLine.lmat.color = newColor; numClicks = 0; prevPaintPoint = endPoint; // add to history and increment index Debug.Log("Adding History 1"); int index = arCanvas.GetComponent <PaintController> ().drawingHistoryIndex; index++; Debug.Log("Adding History 2"); paintBrushSceneObject.GetComponent <DrawingHistoryManager> ().addDrawingCommand(index, 0, endPoint, currLine.lmat.color, paintLineThickness); Debug.Log("Adding History 3"); arCanvas.GetComponent <PaintController> ().drawingHistoryIndex = index; Debug.Log("Done Adding History"); } else if (whileTouchedCondition == true) { if ((endPoint - prevPaintPoint).magnitude > 0.01f) { // continue drawing line //currLine.SetVertexCount (numClicks + 1); //currLine.SetPosition (numClicks, endPoint); currLine.AddPoint(endPoint); numClicks++; prevPaintPoint = endPoint; // add to history without incrementing index int index = arCanvas.GetComponent <PaintController> ().drawingHistoryIndex; paintBrushSceneObject.GetComponent <DrawingHistoryManager> ().addDrawingCommand(index, 0, endPoint, currLine.lmat.color, paintLineThickness); } } }
void Update() { //generate stroke mesh when dominant hand trigger is down if (!nav.teleportOn) //only draw if not in teleport mode { if (WaveVR_Controller.Input(DomFocusControllerType).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Trigger)) { GameObject go = new GameObject(); go.AddComponent <MeshFilter>(); go.AddComponent <MeshRenderer>(); currLine = go.AddComponent <GraphicsLineRenderer>(); currLine.lmat = new Material(lMat); currLine.SetWidth(width); numClicks = 0; } else if (WaveVR_Controller.Input(DomFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_Trigger)) { currLine.AddPoint(WaveVR_Controller.Input(DomFocusControllerType).transform.pos); numClicks++; } else if (WaveVR_Controller.Input(DomFocusControllerType).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Trigger)) { pastLines.Add(currLine); numClicks = 0; } } //scale sketch when both grips are down if (WaveVR_Controller.Input(DomFocusControllerType).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Grip) && WaveVR_Controller.Input(NonFocusControllerType).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Grip)) { WaveVR_Utils.RigidTransform _rpose = WaveVR_Controller.Input(DomFocusControllerType).transform; Vector3 posR = _rpose.pos; WaveVR_Utils.RigidTransform _lpose = WaveVR_Controller.Input(NonFocusControllerType).transform; Vector3 posL = _lpose.pos; prevDist = Vector3.Distance(posR, posL); } else if (WaveVR_Controller.Input(DomFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_Grip) && WaveVR_Controller.Input(NonFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_Grip)) { WaveVR_Utils.RigidTransform _rpose = WaveVR_Controller.Input(DomFocusControllerType).transform; Vector3 posR = _rpose.pos; WaveVR_Utils.RigidTransform _lpose = WaveVR_Controller.Input(NonFocusControllerType).transform; Vector3 posL = _lpose.pos; float dist = Vector3.Distance(posR, posL); float dDist = dist - prevDist; float scale = 1.05f; if (dDist < 0) { scale = 0.95f; } //get sketch center to use later to keep sketch around same position //(otherwise it floats up when it scales up) Vector3 sumVector = Vector3.zero; float count = 0.0f; foreach (GraphicsLineRenderer glr in pastLines) { foreach (Vector3 vec in glr.ml.vertices) { sumVector += vec; count++; } } Vector3 avgVector = sumVector / count; //scale each stroke (GraphicsLineRenderer) by scaling its mesh vertices foreach (GraphicsLineRenderer glr in pastLines) { Vector3[] vertices = glr.ml.vertices; for (int v = 0; v < vertices.Length; v++) //vertices being the array of vertices of your mesh { vertices[v] = (vertices[v] - avgVector) * scale + avgVector; } glr.ml.vertices = vertices; } prevDist = dist; } //rotate sketch when dominant hand grip is down else if (WaveVR_Controller.Input(DomFocusControllerType).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Grip)) { //store prev angle WaveVR_Utils.RigidTransform _rpose = WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.Dominant).transform; float prevYAngle = _rpose.rot.eulerAngles[1]; } else if (WaveVR_Controller.Input(DomFocusControllerType).GetPress(WVR_InputId.WVR_InputId_Alias1_Grip)) { WaveVR_Utils.RigidTransform _rpose = WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.Dominant).transform; float yAngle = _rpose.rot.eulerAngles[1]; float dyAngle = yAngle - prevYAngle; //rotate sketch based on change from previous angle Vector3 center = new Vector3(0, 0, 0); //any V3 you want as the pivot point. Quaternion newRotation = new Quaternion(); newRotation.eulerAngles = new Vector3(0, dyAngle, 0); //the degrees the vertices are to be rotated, for example (0,90,0) //rotate each stroke (GraphicsLineRenderer) by rotating its mesh vertices foreach (GraphicsLineRenderer glr in pastLines) { Vector3[] vertices = glr.ml.vertices; for (int v = 0; v < vertices.Length; v++) //vertices being the array of vertices of your mesh { vertices[v] = newRotation * (vertices[v] - center) + center; } glr.ml.vertices = vertices; } prevYAngle = yAngle; } //give current stroke color from color picker if (currLine != null) { currLine.lmat.color = ColorManager.Instance.GetCurrentColor(); } }
// Update is called once per frame void Update() { var device = SteamVR_Controller.Input((int)trackedObj.index); drawingCount = drawings.Count; if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { bool flag = FindObjectOfType <AudioManager>().drawing_playing; if (!flag) { FindObjectOfType <AudioManager>().Play("draw_sound"); FindObjectOfType <AudioManager>().drawing_playing = true; } go = new GameObject(); go.name = "drawing" + drawingCount; go.tag = "Drawing"; currLine = go.AddComponent <GraphicsLineRenderer>(); go.AddComponent <MeshFilter>(); go.AddComponent <MeshRenderer>(); go.AddComponent <MeshCollider>().convex = true; if (SceneManager.GetActiveScene().name != "secondRoom") { go.AddComponent <DrawingsAttach>(); } go.AddComponent <Interactable>(); Rigidbody rb = go.AddComponent <Rigidbody>(); go.AddComponent <DrawingStruct>().startTime = Time.time; rb.constraints = RigidbodyConstraints.FreezeAll; go.AddComponent <Throwable>(); drawings.Add(go); numClicks = 0; } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { bool flag = FindObjectOfType <AudioManager>().drawing_playing; if (flag) { FindObjectOfType <AudioManager>().Stop("draw_sound"); FindObjectOfType <AudioManager>().drawing_playing = false; } print("TOUCH UP"); if (SceneManager.GetActiveScene().name == "secondRoom") { print("adding mass dlm now"); go.AddComponent <Mass_DLM>(); go.GetComponent <Mass_DLM>().setMass(); } } else if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { currLine.AddPoint(trackedObj.transform.position); numClicks++; print("touched"); } if (device.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu)) { lineIndex += 1; lineIndex = lineIndex % (lineSizes.Count); sizeObject.transform.localScale += new Vector3(2.0f, 0f, 2.0f); if (sizeObject.transform.localScale.x > 12.0f) { sizeObject.transform.localScale = new Vector3(2.0f, 0.5000005f, 2.0f); } GraphicsLineRenderer.lineSize = lineSizes[lineIndex]; } }