// 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; } } }
public void painterEnd() { if (this.enabled == true) { if (BrushManager.freeformbool == false) { // currLine.setVertexCount(numClicks +1); if (BrushManager.brushswitchint == 2) { //makes the square all one game object currLine1.gameObject.transform.SetParent(currLine.gameObject.transform); currLine2.gameObject.transform.SetParent(currLine.gameObject.transform); currLine3.gameObject.transform.SetParent(currLine.gameObject.transform); currLine1 = null; currLine2 = null; currLine3 = null; } UndoManager.GetComponent <UndoManager> ().strokes.Add(currLine.gameObject); UndoManager.GetComponent <UndoManager> ().globalUndo.Add(0); numClicks = 0; currLine.transform.SetParent(meshparent); currLine = null; } } }
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() { // 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; } }
// 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++; } }
public void pointbreaker() { if (BrushManager.brushswitchint == 2) { //makes the square all one game object if (currLine1 != null) { currLine1.gameObject.transform.SetParent(currLine.gameObject.transform); currLine2.gameObject.transform.SetParent(currLine.gameObject.transform); currLine3.gameObject.transform.SetParent(currLine.gameObject.transform); currLine1 = null; currLine2 = null; currLine3 = null; } } if (currLine != null) { firstPointtime = false; UndoManager.GetComponent <UndoManager> ().strokes.Add(currLine.gameObject); numClicks = 0; currLine.transform.SetParent(meshparent); } currLine = null; }
// 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(); } }
// 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 (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.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 DrawStop(Vector3 controllerPosition, GameObject slideToSave) { isDrawing = false; cursor.transform.position = controllerPosition; numClicks = 0; currLine.transform.SetParent(slideToSave.transform); currLine = null; }
// 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); } } }
public IEnumerator delline() { numClicks = 0; currLine.transform.SetParent(meshparent); currLine = null; if (BrushManager.brushswitchint == 2) { numClicks = 0; currLine1.transform.SetParent(meshparent); currLine1 = null; } yield return(null); }
public void DrawInitialize() { GameObject go = new GameObject(); go.AddComponent <MeshFilter>(); go.AddComponent <MeshRenderer>(); currLine = go.AddComponent <MeshLineRenderer>(); //go.AddComponent<MeshCollider>().sharedMesh = meshparent.GetComponent<MeshFilter>().mesh; currLine.setWidth(width); currLine.lmat = new Material(matter); if (currLine != null) { //currLine.lmat.color = ColorManager.Instance.GetCurrentColor(); } }
// 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(); } }
public void painterStart() { if (this.enabled == true) { if (BrushManager.freeformbool == false) { GameObject go = new GameObject(); go.AddComponent <MeshFilter> (); go.AddComponent <MeshRenderer> (); go.AddComponent <MeshCollider> ().sharedMesh = go.GetComponent <MeshFilter> ().mesh; currLine = go.AddComponent <MeshLineRenderer> (); currLine.setWidth(BrushManager.cursorsize); currLine.lmat = new Material(matter); if (BrushManager.brushswitchint == 2) { GameObject go1 = new GameObject(); go1.AddComponent <MeshFilter> (); go1.AddComponent <MeshRenderer> (); // go1.AddComponent < MeshCollider> ().sharedMesh = go.GetComponent<MeshFilter> ().mesh; currLine1 = go1.AddComponent <MeshLineRenderer> (); currLine1.setWidth(BrushManager.cursorsize); currLine1.lmat = new Material(matter); GameObject go2 = new GameObject(); go2.AddComponent <MeshFilter> (); go2.AddComponent <MeshRenderer> (); // go2.AddComponent < MeshCollider> ().sharedMesh = go.GetComponent<MeshFilter> ().mesh; currLine2 = go2.AddComponent <MeshLineRenderer> (); currLine2.setWidth(BrushManager.cursorsize); currLine2.lmat = new Material(matter); GameObject go3 = new GameObject(); go3.AddComponent <MeshFilter> (); go3.AddComponent <MeshRenderer> (); // go3.AddComponent < MeshCollider> ().sharedMesh = go.GetComponent<MeshFilter> ().mesh; currLine3 = go3.AddComponent <MeshLineRenderer> (); currLine3.setWidth(BrushManager.cursorsize); currLine3.lmat = new Material(matter); } } 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 ); if (BrushManager.brushswitchint == 1) { currLine.AddPoint(sphereHigh.position, sphereLow.position); numClicks++; } else if (BrushManager.brushswitchint == 2) { currLine.AddPoint(spherelh.position, spherell.position); numClicks++; currLine1.AddPoint(sphererh.position, sphererl.position); numClicks++; currLine2.AddPoint(spherelh.position, sphererh.position); numClicks++; currLine3.AddPoint(sphererl.position, spherell.position); numClicks++; } freeformRedo(); // lastpos =sphere.transform.position; // numClicks++; } if (firstPointtime == false) { GameObject go = new GameObject(); go.AddComponent <MeshFilter> (); go.AddComponent <MeshRenderer> (); currLine = go.AddComponent <MeshLineRenderer> (); go.AddComponent <MeshCollider> ().sharedMesh = go.GetComponent <MeshFilter> ().mesh; currLine.setWidth(BrushManager.cursorsize); currLine.lmat = new Material(matter); if (BrushManager.brushswitchint == 2) { GameObject go1 = new GameObject(); go1.AddComponent <MeshFilter> (); go1.AddComponent <MeshRenderer> (); currLine1 = go.AddComponent <MeshLineRenderer> (); currLine1.setWidth(BrushManager.cursorsize); currLine1.lmat = new Material(matter); GameObject go2 = new GameObject(); go2.AddComponent <MeshFilter> (); go2.AddComponent <MeshRenderer> (); currLine2 = go2.AddComponent <MeshLineRenderer> (); currLine2.setWidth(BrushManager.cursorsize); currLine2.lmat = new Material(matter); GameObject go3 = new GameObject(); go3.AddComponent <MeshFilter> (); go3.AddComponent <MeshRenderer> (); currLine3 = go3.AddComponent <MeshLineRenderer> (); currLine3.setWidth(BrushManager.cursorsize); currLine3.lmat = new Material(matter); } freeformRedo(); firstPointtime = true; } } } }
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() { findPlaneClosestTo3DCursor(); // the interaction cursor is positioned where the cursor is //interactionCursor.transform.position = calcInteractionCursorPosition (); // debugging purposes if (debugMode) { DrawDebug(); } DrawCursor(StripWidth); // change the orientation of the strip on the basis of the joystick press right if (OVRInput.Get(OVRInput.Button.PrimaryThumbstickRight, _dominantHand)) { CursorOrientationFactor += 0.02f; //StrokeOrientation = Vector3.RotateTowards (StrokeOrientation, OVRInput.GetLocalControllerRotation (OVRInput.Controller.RTouch) * Vector3.right, 0.05f, 0.0f); } else if (OVRInput.Get(OVRInput.Button.PrimaryThumbstickLeft, _dominantHand)) { CursorOrientationFactor -= 0.02f; //StrokeOrientation = Vector3.RotateTowards (StrokeOrientation, OVRInput.GetLocalControllerRotation (OVRInput.Controller.RTouch) * Vector3.up, 0.05f, 0.0f); } /* * // change the transparency of the avatar if the controller button 'A' is pressed. This was done so that I could see the 3D strokes that I have made more clearly * if (OVRInput.Get (OVRInput.Button.Two, OVRInput.Controller.RTouch)) { * _baseMeshRenderer.material.color = new Color(_baseMeshRenderer.material.color.r, _baseMeshRenderer.material.color.g, _baseMeshRenderer.material.color.b, 0.0f); * //baseMesh.SetActive (false); * } else { * //baseMesh.SetActive (true); * _baseMeshRenderer.material.color = new Color(_baseMeshRenderer.material.color.r, _baseMeshRenderer.material.color.g, _baseMeshRenderer.material.color.b, 1.0f); * } */ // Lets try giving the user a control on determining the distance of the 3D cursor from the controller. "A" button brings the cursor closer and "B" button pushes it away if (OVRInput.Get(OVRInput.Button.Two, _dominantHand)) { _cursorDistance += _cursorDistanceSpeed; } if (OVRInput.Get(OVRInput.Button.One, _dominantHand)) { _cursorDistance -= _cursorDistanceSpeed; } // Change the width of the strip on the basis of the joystick press down if (OVRInput.Get(OVRInput.Button.PrimaryThumbstickUp, _dominantHand)) { StripWidth += stripWidthChangeFactor; } else if (OVRInput.Get(OVRInput.Button.PrimaryThumbstickDown, _dominantHand)) { StripWidth -= stripWidthChangeFactor; } // Start and stop the strip drawing process // create the strip gameobject and setup initial parameters if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger, _dominantHand)) { GameObject go = createStrokeGameObject(); _currLine = go.AddComponent <MeshLineRenderer> (); _currLine.SetMaterial(new Material(strokeMat)); _currLine.setWidth(StripWidth); _currLine.SetOrientation(calcCursorOrientation()); //currLine.endWidth = 0.1f; numClicks = 0; _prevPoint = calcCursorPosition(); ModeDetermine = "drawing"; } // add strips to the existing stroke that you are drawing else if (OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger, _dominantHand)) { //currLine.positionCount = numClicks + 1; //currLine.SetPosition (numClicks, OVRInput.GetLocalControllerPosition (OVRInput.Controller.RTouch)); _currLine.setWidth(StripWidth); _currPoint = calcCursorPosition(); cleanPoint(_currLine, _currPoint); _currLine.SetOrientation(calcCursorOrientation()); _prevPoint = _currPoint; numClicks++; } // when you stop drawing change the mode to idle so that you can respond to ui changes again else if (OVRInput.GetUp(OVRInput.Button.PrimaryIndexTrigger, _dominantHand)) { ModeDetermine = "idle"; } /* * if (CollisionDetector.CollidingBodyPart != null) { * Debug.Log (CollisionDetector.CollidingBodyPart.transform.name); * }*/ // event system for detecting the frame where gripDown happens if (OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, _dominantHand) > 0.9f) { if (_gripDownCount == 0) { _gripDownCount = 1; _gripDown = true; } else { _gripDown = false; } } else { if (_gripDownCount == 1) { _gripDownCount = 0; } } // assigning the origin of the drawing surface as this origin's x,y has to be defined in order to use the magnified surface. if (_gripDown) { if (_originCursorPosition == new Vector3()) { _originCursorPosition = calcCursorPosition(); _originCursorRotation = OVRInput.GetLocalControllerRotation(_dominantHand); Vector3 scale = new Vector3(0.02f, 0.02f, 0.02f); GenerateGrid(_originCursorPosition, _originCursorRotation, scale); } else { _originCursorPosition = new Vector3(); _originCursorRotation = new Quaternion(); _grid.SetActive(false); } } }
// 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() { 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); } } }
// 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); } }
private void DoTriggerPressed(object sender, ControllerInteractionEventArgs e) { updating = true; GameObject obj; GameObjectPos objpos; switch (bodyType) { case BodyType.Line: Debug.Log(0); hand.SetActive(false); pencil.SetActive(true); obj = GameObject.CreatePrimitive(PrimitiveType.Cube); obj.name = "Weapon"; obj.AddComponent <BoxCollider>(); obj.AddComponent <VRTK_InteractableObject>(); obj.GetComponent <VRTK_InteractableObject>().precisionSnap = true; obj.GetComponent <VRTK_InteractableObject>().isGrabbable = true; obj.GetComponent <VRTK_InteractableObject>().grabAttachMechanic = VRTK_InteractableObject.GrabAttachType.Child_Of_Controller; obj.AddComponent <Rigidbody>(); obj.GetComponent <Rigidbody>().isKinematic = false; obj.transform.position = fingertip.position; objpos.obj = obj; objpos.startPos = obj.transform.position; objects.Push(objpos); break; case BodyType.Plane: Debug.Log(2); obj = Instantiate <GameObject>(paperPrefab); obj.name = "Weapon"; obj.transform.localScale = new Vector3(0.085f, 1, 0.110f); obj.transform.parent = this.transform; obj.transform.localRotation = Quaternion.identity; obj.transform.localPosition = new Vector3(0, 0, 1); obj.transform.parent = null; obj.transform.Rotate(new Vector3(90, 0, 0)); obj.SetActive(true); updating = false; return; case BodyType.Ellipse: Debug.Log(3); obj = GameObject.CreatePrimitive(PrimitiveType.Capsule); break; case BodyType.Free: Debug.Log(4); hand.SetActive(false); pencil.SetActive(true); obj = new GameObject(); obj.name = "Weapon"; obj.transform.position = fingertip.position; obj.AddComponent <MeshFilter>(); obj.AddComponent <MeshRenderer>(); obj.GetComponent <MeshRenderer>().material.color = Color.black; obj.AddComponent <Rigidbody>(); obj.GetComponent <Rigidbody>().isKinematic = true; obj.GetComponent <Rigidbody>().useGravity = false; currLine = obj.AddComponent <MeshLineRenderer>(); currLine.lmat = lMat; currLine.setWidth(0.035f); vertPositions.Add(fingertip.transform.position); obj.AddComponent <MeshCollider>().convex = true; obj.GetComponent <MeshCollider>().sharedMesh = currLine.ml; obj.AddComponent <VRTK_InteractableObject>(); obj.GetComponent <VRTK_InteractableObject>().precisionSnap = true; obj.GetComponent <VRTK_InteractableObject>().isGrabbable = true; obj.GetComponent <VRTK_InteractableObject>().grabAttachMechanic = VRTK_InteractableObject.GrabAttachType.Child_Of_Controller; objpos.obj = obj; objpos.startPos = obj.transform.position; objects.Push(objpos); break; default: Debug.Log(5); obj = GameObject.CreatePrimitive(PrimitiveType.Cube); break; } }
// 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(); } }
void MyRemoteMethod(MeshLineRenderer remoteMeshLineRenderer) { Debug.Log("CatCH Call this method"); game_objects_from_rpc.Add(remoteMeshLineRenderer); }