Example #1
0
    // Allows a line to be redrawn from history
    // Used by DrawingHistoryManager
    public void addReplayLineSegment(bool toContinue, float lineThickness, Vector3 position, Color color, Material primaryMaterial, Material secondaryMaterial, int layerNum)
    {
        if (toContinue == false)
        {
            // Start drawing a new line
            GameObject go = new GameObject();
            go.transform.position = position;
            go.transform.parent   = drawingRootSceneObject.transform;

            go.AddComponent <MeshFilter> ();
            go.AddComponent <MeshRenderer> ();
            currLine = go.AddComponent <GraphicsLineRenderer> ();
            currLine.SetLayerNum(layerNum);

            currLine.SetPrimaryMaterial(new Material(primaryMaterial));
            currLine.SetSecondaryMaterial(new Material(secondaryMaterial));
            currLine.SetWidth(lineThickness);
            currLine.SetColor(color);
        }
        else
        {
            // Continue drawing on the same line
            currLine.AddPoint(position);
        }
    }
Example #2
0
    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();
        }
    }
Example #3
0
    public void addReplayLineSegment(bool toContinue, float lineThickness, Vector3 position, Color color)
    {
        if (toContinue == false)
        {
            // start drawing line
            GameObject go = new GameObject();
            go.transform.position = position;
            go.transform.parent   = drawingRootSceneObject.transform;

            go.AddComponent <MeshFilter> ();
            go.AddComponent <MeshRenderer> ();
            currLine = go.AddComponent <GraphicsLineRenderer> ();

            currLine.lmat = new Material(lMat);
            currLine.SetWidth(lineThickness);
            currLine.lmat.color = color;
            numReplayClicks     = 0;
        }
        else
        {
            // continue line
            currLine.AddPoint(position);
            numReplayClicks++;
        }
    }
Example #4
0
    // 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++;
        }
    }
Example #5
0
    } // _UpdateFeature()

    // Starts drawing a new line with the given point
    private void startNewLine(Vector3 firstPoint)
    {
        Debug.Log("startNewLine()");

        // Make sure we are in drawing mode
        if (!paintPanel.activeSelf && !snapToSurfaceBrushTipObject.activeSelf)
        {
            return;
        }

        // Create a new line object
        GameObject go = new GameObject();

        go.transform.position = firstPoint;
        go.transform.parent   = drawingRootSceneObject.transform;
        go.AddComponent <MeshFilter> ();
        go.AddComponent <MeshRenderer> ();

        int layerNum = GetComponent <PaintController>().GetActiveLayerNum();

        // Keep track of this line
        currLine = go.AddComponent <GraphicsLineRenderer>();
        currLine.SetLayerNum(layerNum);

        // Configure the color, etc. of the line
        currLine.SetPrimaryMaterial(new Material(lMat));
        if (lMat_texture)
        {
            currLine.SetSecondaryMaterial(new Material(lMat_texture));
        }
        currLine.SetWidth(paintLineThickness);
        currLine.SetColor(colorPicker.GetColor());


        // Keep track of the last point on the line
        prevPaintPoint = firstPoint;

        // Add to history and increment index
        Debug.Log("Adding History 1");
        int index = GetComponent <PaintController> ().drawingHistoryIndex;

        index++;

        Debug.Log("Adding History 2");
        paintBrushSceneObject.GetComponent <DrawingHistoryManager> ().addDrawingCommand(index, 0, firstPoint, currLine.GetColor(), paintLineThickness, lMat, lMat_texture, layerNum);

        Debug.Log("Adding History 3");
        GetComponent <PaintController>().drawingHistoryIndex = index;

        Debug.Log("Done Adding History");

        // Make sure the trail is off
        if (brushTipObject.activeSelf)
        {
            brushTipObject.GetComponent <TrailRenderer>().enabled = false;
        }
    }
Example #6
0
    // 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);
            }
        }
    }
Example #7
0
    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();
        }
    }