// 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)) { currObj = new GameObject(); //just like make new object currObj.tag = "Draw"; currLine = currObj.AddComponent <MeshLineRenderer>(); currLine.lmat = lmat; currLine.setWidth(.1f); //static width numClicks = 0; } else if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { currLine.AddPoint(DrawBase.position, DrawTip.position); // while touch keep adding point currLine.AddPoint(DrawBaseEX.position, DrawTipEX.position); // while touch keep adding point experimental numClicks++; } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { currMesh = currObj.AddComponent <MeshCollider>(); currMesh.sharedMesh = currObj.GetComponent <MeshFilter>().mesh; if (Hand) { currObj.transform.parent = Vis.transform; } } }
// 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) && BrushManager.canpaint == true) { GameObject go = new GameObject(); go.AddComponent <MeshFilter> (); go.AddComponent <MeshRenderer> (); currLine = go.AddComponent <MeshLineRenderer> (); currLine.setWidth(BrushManager.cursorsize); currLine.lmat = new Material(matter); } else if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger) && BrushManager.canpaint == true) { // currLine.setVertexCount(numClicks +1); currLine.setWidth(BrushManager.cursorsize); currLine.AddPoint(trackedObj.transform.position); numClicks++; } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { // currLine.setVertexCount(numClicks +1); UndoManager.GetComponent <UndoManager>().strokes.Add(currLine.gameObject); numClicks = 0; currLine.transform.SetParent(meshparent); currLine = null; } if (currLine != null) { currLine.lmat.color = ColorManager.Instance.GetCurrentColor(); } }
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> (); go.AddComponent <MeshCollider> (); currLine = go.AddComponent <MeshLineRenderer> (); currLine.MyMat(); currLine.setWidth(meshWidth); currLine.tag = "MarkUp"; } 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; } else if (device.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu)) { meshes = GameObject.FindWithTag("MarkUp"); Destroy(meshes); } }
// 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)) { // this logic is taken from the MeshLineRenderer script GameObject go = new GameObject(); go.AddComponent <MeshFilter>(); go.AddComponent <MeshRenderer>(); currLine = go.AddComponent <MeshLineRenderer>(); //set the material to use when the trigger is touched currLine.lmat = lMat; } else if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { // currLine.SetVertexCount (numClicks + 1); // currLine.SetPosition(numClicks, trackedObj.transform.position); currLine.AddPoint(trackedObj.transform.position); numClicks++; } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) //if trigger is held { numClicks = 0; currLine = null; } if (currLine != null) //if current line does not equal null { currLine.lmat.color = ColorManager.Instance.GetCurrentColor(); //current line material color equals color manager's current color } }
public void DrawLine(Vector3 screenPoint) { isDrawing = true; cursor.transform.position = screenPoint;//Vector3.Lerp(cursor.transform.position, screenPoint, Time.deltaTime * 2f); currLine.AddPoint(sphereHigh.position, sphereLow.position); numClicks++; }
// Update is called once per frame void Update() { // Trigger Start if (triggerDown) { if (numClicks == 0) { GameObject go = new GameObject(); go.AddComponent <MeshFilter>(); go.AddComponent <MeshRenderer>(); currLine = go.AddComponent <MeshLineRenderer>(); currLine.lmat = new Material(activeMat); currLine.SetWidth(.1f); } currLine.AddPoint(controllerDevice.transform.position); numClicks++; List <float> data = ControllerVelocityAndAmplitude(); currLine.lmat.SetFloat("_SynthFrequency", data[0]); OSCHandler.Instance.SendMessageToClient("myClient", "/waveData/" + activeWave, data); } else if (!triggerDown) { numClicks = 0; currLine = null; } }
private void Update() { if (updating) { GameObjectPos currentObj = objects.Peek(); switch (bodyType) { case BodyType.Line: currentObj.obj.transform.position = (currentObj.startPos + fingertip.transform.position) / 2.0f; currentObj.obj.transform.LookAt(fingertip.transform.position); currentObj.obj.transform.localScale = new Vector3(0.1f, 0.1f, Vector3.Distance(currentObj.startPos, fingertip.transform.position)); break; case BodyType.Ellipse: currentObj.obj.transform.position = (currentObj.startPos + fingertip.transform.position) / 2.0f; currentObj.obj.transform.LookAt(fingertip.transform.position); currentObj.obj.transform.localScale = new Vector3(0.1f, 0.1f, Vector3.Distance(currentObj.startPos, fingertip.transform.position)); break; case BodyType.Free: if (Vector3.Distance(vertPositions[vertPositions.Count - 1], fingertip.transform.position) > 0.03) { currLine.AddPoint(fingertip.transform.position); vertPositions.Add(fingertip.transform.position); currLine.GetComponent <MeshCollider>().sharedMesh = currLine.ml; } break; default: break; } } }
// Update is called once per frame void Update() { if (Input.GetButtonDown("Fire1")) { GameObject line = new GameObject(); line.transform.parent = collection.transform; m_MeshFilter = line.AddComponent <MeshFilter>(); line.AddComponent <MeshRenderer>(); curLine = line.AddComponent <MeshLineRenderer>(); curLine.setWidth(0.05f); } if (Input.GetButton("Fire1")) { curLine.AddPoint(place.transform.position); } if (Input.GetButtonUp("Fire1")) { var lStream = new FileStream("C:/Users/apappu/Documents/NoBillBoardLines/Assets/line.obj", FileMode.Create); var lOBJData = m_MeshFilter.sharedMesh.EncodeOBJ(); OBJLoader.ExportOBJ(lOBJData, lStream); lStream.Close(); } }
// Update is called once per frame void Update() { SteamVR_Controller.Device device = SteamVR_Controller.Input((int)trackedObj.index); //if trigger pressed, create line if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { GameObject go = new GameObject(); go.AddComponent <MeshFilter>(); go.AddComponent <MeshRenderer>(); currLine = go.AddComponent <MeshLineRenderer>(); currLine.lmat = lMat; currLine.setWidth(0.1f); numClicks = 0; //if trigger pressed until click, set global position } else if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { //currLine.SetVertexCount(numClicks + 1); //currLine.SetPosition(numClicks, trackedObj.transform.position); currLine.AddPoint(trackedObj.transform.position); numClicks++; } }
// 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(); go.AddComponent <MeshFilter> (); go.AddComponent <MeshRenderer> (); currLine = go.AddComponent <MeshLineRenderer> (); currLine.lmat = new Material(lMat); currLine.setWidth(.1f); } else if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { //currLine.SetVertexCount (numClicks + 1); //currLine.SetPosition (numClicks, trackedObj.transform.position); 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.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)) { enableDraw = enableDraw ? false : true; Debug.Log(enableDraw); } if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger) && enableDraw) { //Master Line Object masterObj = new GameObject(); masterObj.tag = "Draw"; currObj = new GameObject(); //just like make new object currObj.tag = "Draw"; currObj.transform.parent = masterObj.transform; currLine = currObj.AddComponent <MeshLineRenderer>(); currObjEX = new GameObject(); //just like make new object currObjEX.tag = "Draw"; currObjEX.transform.parent = masterObj.transform; currLineEX = currObjEX.AddComponent <MeshLineRenderer>(); currObjEXTURBO = new GameObject(); //just like make new object currObjEXTURBO.tag = "Draw"; currObjEXTURBO.transform.parent = masterObj.transform; currLineEXTURBO = currObjEXTURBO.AddComponent <MeshLineRenderer>(); currLine.lmat = lmat; currLine.setWidth(.1f); //static width currLineEX.lmat = lmat; currLineEX.setWidth(.1f); //static width currLineEXTURBO.lmat = lmat; currLineEXTURBO.setWidth(.1f); //static width numClicks = 0; } else if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger) && enableDraw) { currLine.AddPoint(DrawBase.position, DrawTip.position); // while touch keep adding point currLineEX.AddPoint(DrawBaseEX.position, DrawTipEX.position); // while touch keep adding point experimental currLineEXTURBO.AddPoint(DrawBaseEXTURBO.position, DrawTipEXTURBO.position); // while touch keep adding point experimental numClicks++; } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger) && enableDraw) { currMesh = currObj.AddComponent <MeshCollider>(); currMesh.sharedMesh = currObj.GetComponent <MeshFilter>().mesh; if (Hand) { masterObj.transform.parent = Vis.transform; } } }
void Update() { if (HandData.HandStartedPointing(DeviceType)) { Debug.Log("first click"); init = true; GameObject go = new GameObject(); go.AddComponent <MeshFilter>(); go.AddComponent <MeshRenderer>(); go.tag = "PaintObject"; currLine = go.AddComponent <MeshLineRenderer>(); go.transform.position = go.GetComponent <MeshRenderer>().bounds.center; Debug.Log(go.GetComponent <MeshRenderer>().bounds.center); /* * //tried to use the InteractableItem component in order to move the items - failed.. * go.AddComponent<MeshCollider>(); * go.AddComponent<Rigidbody>(); * go.GetComponent<Rigidbody>().useGravity = false; * go.AddComponent<MeshCollider>(); * go.AddComponent<CollisionDetector>(); * go.AddComponent<CapsuleCollider>(); * go.AddComponent<BoxCollider>(); * go.GetComponent<MeshCollider>().convex = true; * go.AddComponent<objectDragger>(); * go.AddComponent<InteractablePaintedItem>(); * go.GetComponent<InteractablePaintedItem>().IsGrabbable = true; * go.GetComponent<InteractablePaintedItem>().GravityWhenGrabbed = false; * go.GetComponent<InteractablePaintedItem>().GravityWhenReleased = false; * go.GetComponent<InteractablePaintedItem>().KinematicWhenReleased = false; * go.GetComponent<InteractablePaintedItem>().AttachHandToItem = true; * go.GetComponent<InteractablePaintedItem>().DropDistance = (float)0.25; */ currLine.lmat = lMat; currLine.setWidth(.05f); } else if (HandData.HandPoints(DeviceType)) { Debug.Log(string.Format("Vector is {0} {1}, {2}", vec.x, vec.y, vec.z)); vec = fingerPos.position; currLine.AddPoint(vec); numClicks++; } //save obj as .stl if (Input.GetMouseButtonDown(1)) { if (currLine != null) { GameObject[] gos = { currLine.gameObject }; pb_Stl_Exporter.Export(string.Format("test{0}.stl", i++), gos, FileType.Ascii); } } }
// Update is called once per frame void Update() { float rightTriggerVal = OVRInput.Get(OVRInput.RawAxis1D.RIndexTrigger); //Debug.Log(rightTriggerVal); // Right Trigger Enter if (rightTriggerVal > 0 && rightTriggerVal < 0.35f && prevTriggerState == (int)triggerStates.standby) { prevTriggerState = (int)triggerStates.enter; GameObject go = new GameObject(); go.AddComponent <MeshRenderer>(); currLine = go.AddComponent <MeshLineRenderer>(); currLine.lmat = lMat; currLine.setWidth(.01f); numClicks = 0; } // Right Trigger Hold else if (rightTriggerVal > 0.35f) { prevTriggerState = (int)triggerStates.hold; // global position of right controller Vector3 rightControllerPos = GameObject.Find("OVRCameraRig").transform.position + OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTrackedRemote); //currLine.SetVertexCount(numClicks + 1); //currLine.SetPosition(numClicks, rightControllerPos); currLine.AddPoint(rightControllerPos); numClicks++; } // Right Trigger Standby else if (rightTriggerVal == 0) { prevTriggerState = (int)triggerStates.standby; } }
void cleanPoint(MeshLineRenderer currLine, Vector3 newPoint) { /* if the distance between the previous and the current point is below a threshold, then we do not add the point to the strip * but this approach did not work, because if we make the threshold large, then regular strip does not appear until the * distance is greater than the threshold, and if we make the threshold small we still have the problem of discontinuous * orientation of the strip * if ((_currPoint - _prevPoint).magnitude < 0.002f) { * } else { * currLine.AddPoint (_currPoint); * _prevPoint = _currPoint; * } */ /* Another experiment is a point is added to a strip only if the controller is moving at a velocity greater than a threshold. * This did not work out, because if the user is moving at a slow speed and then speeds up, it makes one strip which does not * look great * if(OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTouch).magnitude > 0.1f){ * currLine.AddPoint (_currPoint); * } */ /* Experiment where if the controller is moving fast, more points are added as opposed to when it is moving slow * float threshold = 0.005f/OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTouch).magnitude; * if ((_currPoint - _prevPoint).magnitude < threshold) { * } else { * currLine.AddPoint (_currPoint); * _prevPoint = _currPoint; * } */ currLine.AddPoint(_currPoint); /* * // Experiment: Do not draw a strip if the the displacement vector between the current and last frame coincides * // or is close to the orientation of the tracked controller. * Vector3 rot = new Vector3 (1,0,0); * Quaternion qu = OVRInput.GetLocalControllerRotation (OVRInput.Controller.RTouch); * rot = qu * Vector3.forward; * if (Vector3.Dot (_currPoint - _prevPoint, rot) < 0.5f) { * currLine.AddPoint (_currPoint); * _prevPoint = _currPoint; * } */ }
// 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 line = new GameObject(); line.AddComponent <MeshFilter> (); line.AddComponent <MeshRenderer> (); currLine = line.AddComponent <MeshLineRenderer> (); currLine.setWidth(0.02f); numClicks = 0; } else if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { //currLine.SetVertexCount (numClicks + 1); Vector3 pos = trackedObj.transform.position; //currLine.SetPosition (numClicks, pos); currLine.AddPoint(pos); numClicks++; } }
void Update() { SteamVR_Controller.Device device = SteamVR_Controller.Input((int)trackedObj.index); if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { // We create a new empty gameobject and we add meshfilter and meshrenderer GameObject go = new GameObject("line" + drawedObject); go.AddComponent<MeshFilter>(); go.AddComponent<MeshRenderer>(); //go.layer = LayerMask.NameToLayer("Ignore Light"); drawedList.Add(go); drawedObject++; currentLine = go.AddComponent<MeshLineRenderer>(); currentLine.material = new Material(material); currentLine.setWidth(lineWidth); //numClicks = 0; } else if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { currentLine.AddPoint(trackedObj.transform.position); numClicks++; } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)){ numClicks = 0; currentLine = null; } if (currentLine != null) { if (colorSelector.activeSelf) { colorLine = colorSelector.GetComponent<ColorSelector>().finalColor; } currentLine.material.color = colorLine; } if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Grip)) { DeletelastLine(); } }
// Update is called once per frame void Update() { // float RI = OVRInput.Get(OVRInput.Axis1D.SecondaryHandTrigger); // float RI = OVRInput.Get(OVRInput.Axis1D.SecondaryHandTrigger, OVRInput.Controller.Touch); bool clearA = OVRInput.GetDown(OVRInput.Button.One, OVRInput.Controller.Touch); bool undoX = OVRInput.GetDown(OVRInput.RawButton.X); bool saveY = OVRInput.GetDown(OVRInput.RawButton.Y); if (pressing == false && clearA == true) { Debug.Log("clear all"); GameObject[] delete = GameObject.FindGameObjectsWithTag("Dynamic_Line"); int deleteCount = delete.Length;//.Length(); for (int i = deleteCount - 1; i >= 0; i--) { Destroy(delete[i]); } } if (pressing == false && undoX == true) { GameObject[] delete = GameObject.FindGameObjectsWithTag("Dynamic_Line"); int deleteCount = delete.Length;//.Length(); if (deleteCount > 0) { Destroy(delete[deleteCount - 1]); } } if (pressing == false && saveY == true) { GameObject[] save = GameObject.FindGameObjectsWithTag("Dynamic_Line"); ObjExporter.DoExportsFromGame(save); Debug.LogError("Save " + save.Length + " Line!"); } if (pressing == false && OVRInput.GetDown(OVRInput.Button.SecondaryHandTrigger, OVRInput.Controller.Touch)) { pressing = true; GameObject go = new GameObject(); go.tag = "Dynamic_Line"; go.AddComponent <MeshFilter>(); go.AddComponent <MeshRenderer>(); currLine = go.AddComponent <MeshLineRenderer>(); currLine.lmat = new Material(lmat); currLine.setWidth(lwidth); } else if (OVRInput.Get(OVRInput.Button.SecondaryHandTrigger, OVRInput.Controller.Touch)) { pressing = true; currLine.AddPoint(anchor.position); } else if (OVRInput.GetUp(OVRInput.Button.SecondaryHandTrigger, OVRInput.Controller.Touch)) { pressing = false; currLine = null; } if (currLine != null) { currLine.lmat.color = ColorManager.Instance.GetCurrentColor(); } }
// Update is called once per frame void Update() { if (hover_status == 0) { if (pinchDetector.DidStartPinch) { GameObject go = new GameObject(); go.AddComponent <MeshFilter>(); go.AddComponent <MeshRenderer>(); currLine = go.AddComponent <MeshLineRenderer>(); in_game_go_objects.Add(currLine); drawing_list.Add(go); currLine.lmat = new Material(lMat); currLine.SetWidth(lineManager.lineWidth); } // If it is still pinching else if (pinchDetector.IsPinching) { currLine.AddPoint(index_transform.position); } else if (pinchDetector.DidEndPinch) { // We should synchronize the latest created object to the server // PhotonNetwork.Instantiate("MeshLineRenderer", currLine.transform.position, currLine.transform.rotation, 0); currLine = null; } } else { currLine = null; } // If undo is call, destroy the latest drawing if (undo > 0) { if (drawing_list.Count > 0) { GameObject tempO = drawing_list[drawing_list.Count - 1]; drawing_list.RemoveAt(drawing_list.Count - 1); Destroy(tempO); undo--; } else if (drawing_list.Count == 0) { undo = 0; } } // If reset is call, destroy all the drawing if (reset == 1) { //foreach (MeshLineRenderer temp in in_game_go_objects) //{ // temp.ClearMesh(); // in_game_go_objects.Remove(temp); //} int size = drawing_list.Count; for (int i = size - 1; i >= 0; i--) { GameObject tempO = drawing_list[i]; drawing_list.RemoveAt(i); Destroy(tempO); } reset = 0; } // Color Manager && Line Manager if (currLine != null) { currLine.lmat.color = ColorManager.Instance.GetCurrentColor(); currLine.SetWidth(lineManager.lineWidth); } }
public void DoExportsPointsFromGame(GameObject[] sketchs, GameObject[] reference, string folder, string filename) { int exportedObjects = 0; ArrayList PointsList = new ArrayList(); GameObject space = GameObject.Find("space"); for (int i = 0; i < sketchs.Length; i++) { LineRenderer lr = sketchs[i].GetComponent <LineRenderer>(); Vector3[] Pts = new Vector3[lr.positionCount]; lr.GetPositions(Pts); for (int j = 0; j < Pts.Length; j++) { Vector3 wv = sketchs[i].transform.TransformPoint(Pts[j]); Vector3 rv = space.transform.InverseTransformPoint(wv); PointsList.Add(rv); } exportedObjects++; } Vector3 point = new Vector3(); using (StreamWriter sw = new StreamWriter(folder + Path.DirectorySeparatorChar + filename + "_sketch.off")) { sw.Write("OFF\n"); sw.Write(PointsList.Count + " 0 0\n"); for (int i = 0; i < PointsList.Count; i++) { point = (Vector3)PointsList[i]; sw.WriteLine(point[0] + " " + point[1] + " " + point[2]); } } Debug.Log("Objects exported: " + "Exported " + exportedObjects + " objects to " + filename + " with " + PointsList.Count + "points."); if (reference[0].GetComponentInChildren <Renderer>().enabled) { // Add mesh of lines to meshfilter_obj List <MeshFilter> filter_list = new List <MeshFilter>(); for (int i = 0; i < sketchs.Length; i++) { GameObject go = new GameObject(); go.transform.SetParent(space.transform); go.tag = "Mesh_Line"; Mesh ml = go.AddComponent <MeshFilter>().mesh; go.AddComponent <MeshRenderer>(); currLine = go.AddComponent <MeshLineRenderer>(); currLine.lmat = GameObject.Find("DyLine").GetComponent <LineRenderer>().material; currLine.ml = ml; currLine.setWidth(0.01f); LineRenderer lr = sketchs[i].GetComponent <LineRenderer>(); Vector3[] points = new Vector3[lr.positionCount]; lr.GetPositions(points); for (int j = 0; j < points.Length; j++) { Vector3 wv = sketchs[i].transform.TransformPoint(points[j]); currLine.AddPoint(wv); } filter_list.Add(go.GetComponent <MeshFilter>()); } MeshFilter[] meshfilter_obj = reference[0].transform.GetComponentsInChildren <MeshFilter>(); //MeshFilter[] meshfilter_obj = space.transform.GetComponentsInChildren<MeshFilter>(); filter_list.AddRange(meshfilter_obj); //MeshesToFile(meshfilter_obj, folder, filename + "_ref"); MeshesToFile(filter_list.ToArray(), folder, filename + "_ref"); Debug.Log("Save Reference into OBJ: " + reference[0].name); //Delete Meshes of Lines GameObject[] delete = GameObject.FindGameObjectsWithTag("Mesh_Line"); int deleteCount = delete.Length;//.Length(); for (int i = deleteCount - 1; i >= 0; i--) { Destroy(delete[i]); } } }
// Update is called once per frame void Update() { #if UNITY_STANDALONE_WIN SteamVR_Controller.Device device = SteamVR_Controller.Input((int)trackedObj.index); if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger) && BrushManager.canpaint == true) { if (BrushManager.freeformbool == false) { GameObject go = new GameObject(); go.AddComponent <MeshFilter> (); go.AddComponent <MeshRenderer> (); currLine = go.AddComponent <MeshLineRenderer> (); go.AddComponent <MeshCollider> ().sharedMesh = meshparent.GetComponent <MeshFilter> ().mesh; currLine.setWidth(BrushManager.cursorsize); currLine.lmat = new Material(matter); if (currLine != null) { currLine.lmat.color = ColorManager.Instance.GetCurrentColor(); } } else { if (firstPointtime == true) { //cant get the line render making points up to the sphere, It works a point behind the point creator and is annoying because of the way the mesh line render works so you cant make the same point twice or else it really messes with it // currLine.setWidth (BrushManager.cursorsize); // currLine.AddPoint ((lastpos+ trackedObj.transform.position)/2); //currLine.AddPoint (trackedObj.transform.position); //numClicks++; // currLine.setWidth (BrushManager.cursorsize); // currLine.AddPoint (lastpos + (lastpos -sphere.transform.position)*.02f ); currLine.AddPoint(sphereHigh.position, sphereLow.position); numClicks++; // lastpos =sphere.transform.position; // numClicks++; } if (firstPointtime == false) { GameObject go = new GameObject(); go.AddComponent <MeshFilter> (); go.AddComponent <MeshRenderer> ().sharedMaterial = new Material(matter); currLine = go.AddComponent <MeshLineRenderer> (); currLine.setWidth(BrushManager.cursorsize); currLine.lmat = go.GetComponent <MeshRenderer> ().sharedMaterial; firstPointtime = true; } } } else if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger) && BrushManager.canpaint == true) { if (BrushManager.freeformbool == false) { // currLine.setVertexCount(numClicks +1); currLine.setWidth(BrushManager.cursorsize); currLine.AddPoint(sphereHigh.position, sphereLow.position); numClicks++; } } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { if (BrushManager.freeformbool == false) { // currLine.setVertexCount(numClicks +1); UndoManager.GetComponent <UndoManager> ().strokes.Add(currLine.gameObject); UndoManager.GetComponent <UndoManager> ().globalUndo.Add(0); StartCoroutine(delline()); } } #elif UNITY_ANDROID if (BrushManager.TangoPainting == true && BrushManager.canpaint == true) { if (BrushManager.freeformbool == false) { // currLine.setVertexCount(numClicks +1); if (BrushManager.brushswitchint == 1) { currLine.setWidth(BrushManager.cursorsize); currLine.AddPoint(sphereHigh.position, sphereLow.position); numClicks++; } else if (BrushManager.brushswitchint == 2) { //gotta write a method to make a square bursh currLine.setWidth(BrushManager.cursorsize); currLine.AddPoint(spherelh.position, spherell.position); numClicks++; currLine1.setWidth(BrushManager.cursorsize); currLine1.AddPoint(sphererh.position, sphererl.position); numClicks++; currLine2.setWidth(BrushManager.cursorsize); currLine2.AddPoint(spherelh.position, sphererh.position); numClicks++; currLine3.setWidth(BrushManager.cursorsize); currLine3.AddPoint(sphererl.position, spherell.position); numClicks++; } } } #endif if (currLine != null) { currLine.lmat.color = ColorManager.Instance.GetCurrentColor(); } if (currLine1 != null) { currLine1.lmat.color = ColorManager.Instance.GetCurrentColor(); } if (currLine2 != null) { currLine2.lmat.color = ColorManager.Instance.GetCurrentColor(); } if (currLine3 != null) { currLine3.lmat.color = ColorManager.Instance.GetCurrentColor(); } }
// Update is called once per frame void Update() { timer += Time.deltaTime; SteamVR_Controller.Device device = SteamVR_Controller.Input((int)trackedObj.index); if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { Vector2 trigger = device.GetAxis(EVRButtonId.k_EButton_SteamVR_Trigger); if (trigger.x > 0.1f && timer > 1.0f) { timer = 0; GameObject go = new GameObject(ColorManager.Instance.cloudLabel); go.AddComponent <MeshFilter>(); go.AddComponent <MeshRenderer>(); currLine = go.AddComponent <MeshLineRenderer>(); currLine.setColorManager(colMgr); currLine.setWidth(0.1f); currLine.lmat = this.lMat; GetComponent <MeshRenderer>().material.color = colMgr.color; Vector3 dir = trackedObj.transform.position - trackedObj.transform.forward * 2.0f; Vector3 left = Vector3.Cross(dir, Vector3.up).normalized; if (ColorManager.Instance.cloudLabel != "_None" && ColorManager.Instance.cloudLabel != null) { //trackedObj.transform.position + trackedObj.transform.forward * 2.0f GameObject label = Instantiate(Resources.Load(ColorManager.Instance.cloudLabel), drawingPoint.transform.position, Camera.main.transform.rotation) as GameObject; if (label.GetComponent <CloudLabelSelect>() != null) { Destroy(label.GetComponent <CloudLabelSelect>()); } label.transform.eulerAngles = new Vector3(label.transform.eulerAngles.x, label.transform.eulerAngles.y, 180); //label.transform.RotateAround(transform.position, transform.up, 180f); label.transform.localScale = new Vector3(0.5F, 0.5f, 0); label.transform.parent = go.transform; if (label.GetComponent <Collider>() != null) { Destroy(label.GetComponent <Collider>()); } } annotations.Add(go); numClicks = 0; } } else if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { //currLine.SetVertexCount(numClicks + 1); //currLine.SetPosition(numClicks, trackedObj.transform.position); if (currLine != null) { currLine.AddPoint(drawingPoint.transform.position); } //currLine.AddPoint(trackedObj.transform.position + trackedObj.transform.forward * 2.0f); } else if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip)) { if (annotations.Count > 0) { GameObject destroyed = annotations[annotations.Count - 1]; annotations.Remove(destroyed); Destroy(destroyed); } } }