Пример #1
0
    private void Awake()
    {
        if (!latk)
        {
            latk = GetComponent <LightningArtist>();
        }
        if (latk)
        {
            if (latkSettings == LatkSettings.COPY_TO_LATK)
            {
                latk.brushPrefab = brushPrefab;
                latk.mainColor   = color;
                latk.brushSize   = brushSize;
                latk.minDistance = minDistance;
            }
            else if (latkSettings == LatkSettings.COPY_FROM_LATK)
            {
                brushPrefab = latk.brushPrefab;
                color       = latk.mainColor;
                brushSize   = latk.brushSize;
                minDistance = latk.minDistance;
            }
        }

        updateTransformMatrix();
    }
Пример #2
0
    public BrushStroke makeLine(Vector3 v1, Vector3 v2)
    {
        BrushStroke brush = makeLineCore(v1, v2);

        strokes.Add(brush);
        return(brush);
    }
Пример #3
0
    public BrushStroke makeEmpty()
    {
        BrushStroke brush = makeEmptyCore();

        strokes.Add(brush);
        return(brush);
    }
Пример #4
0
    public BrushStroke makeCurve(List <Vector3> points)
    {
        BrushStroke brush = makeCurveCore(points);

        strokes.Add(brush);
        return(brush);
    }
Пример #5
0
    public BrushStroke makeLine(List <Vector3> points)
    {
        BrushStroke brush = makeLineCore(points[0], points[points.Count - 1]);

        strokes.Add(brush);
        return(brush);
    }
Пример #6
0
    // ~ ~ ~ ~ ~
    // II. LINE

    public BrushStroke makeLineCore(Vector3 v1, Vector3 v2)
    {
        BrushStroke brush = makeEmptyCore();

        brush.points.Add(v1);
        brush.points.Add(v2);
        return(brush);
    }
Пример #7
0
 void randomStroke(BrushStroke _b, int _num, float _range)
 {
     for (int i = 0; i < _num; i++)
     {
         Vector3 v = new Vector3(Random.Range(-_range, _range), Random.Range(-_range, _range), Random.Range(-_range, _range));
         _b.points.Add(v);
     }
 }
Пример #8
0
    public BrushStroke getLastStroke()
    {
        BrushLayer  layer  = layerList[currentLayer];
        BrushFrame  frame  = layer.frameList[layer.currentFrame];
        BrushStroke stroke = frame.brushStrokeList[frame.brushStrokeList.Count - 1];

        return(stroke);
    }
Пример #9
0
    public BrushStroke makeLine(Vector3 v1, Vector3 v2, bool selfDestruct, float lifeTime)
    {
        BrushStroke brush = makeLineCore(v1, v2);

        brush.selfDestruct = selfDestruct;
        brush.lifeTime     = lifeTime;

        strokes.Add(brush);
        return(brush);
    }
Пример #10
0
    public BrushStroke makeCurve(List <Vector3> points, bool selfDestruct, float lifeTime)
    {
        BrushStroke brush = makeCurveCore(points);

        brush.selfDestruct = selfDestruct;
        brush.lifeTime     = lifeTime;

        strokes.Add(brush);
        return(brush);
    }
Пример #11
0
    // ~ ~ ~ ~ ~
    // III. CURVE

    public BrushStroke makeCurveCore(List <Vector3> points)
    {
        BrushStroke brush = makeEmptyCore();

        if (minDistance > 0f)
        {
            points = filterMinDistance(points);
        }
        brush.points = points;
        return(brush);
    }
Пример #12
0
    public void makeTimeStroke()
    {
        BrushStroke b = makeEmpty();

        if (brushMat[(int)brushMode])
        {
            b.mat = brushMat[(int)brushMode];
        }
        b.setBrushColor(strokesRaw[strokeCounter].color);
        b.setBrushSize(brushSize);
        strokes.Add(b);
    }
Пример #13
0
    public BrushStroke makeCurve(List <Vector3> points, bool closed)
    {
        if (closed && points.Count > 10)
        {
            points.Add(points[1]);
        }
        BrushStroke brush = makeCurveCore(points);


        strokes.Add(brush);
        return(brush);
    }
Пример #14
0
    private void Update()
    {
        if (!_realtime.connected)
        {
            return;
        }

        // Start by figuring out which hand we're tracking
        XRNode node         = _hand == Hand.LeftHand ? XRNode.LeftHand : XRNode.RightHand;
        string leftTrigger  = "Oculus_CrossPlatform_PrimaryIndexTrigger";
        string rightTrigger = "Oculus_CrossPlatform_SecondaryIndexTrigger";

        // Get the position & rotation of the hand
        bool handIsTracking = UpdatePose(node, ref _handPosition, ref _handRotation);

        // Figure out if the trigger is pressed or not
        bool triggerPressed = Input.GetAxisRaw(leftTrigger) > 0.1f || Input.GetAxisRaw(rightTrigger) > 0.1f;

        // If we lose tracking, stop drawing
        if (!handIsTracking)
        {
            triggerPressed = false;
        }

        // If the trigger is pressed and we haven't created a new brush stroke to draw, create one!
        if (triggerPressed && _activeBrushStroke == null)
        {
            // Instantiate a copy of the Brush Stroke prefab.
            // GameObject brushStrokeGameObject = Instantiate(_brushStrokePrefab);
            GameObject brushStrokeGameObject = Realtime.Instantiate(_brushStrokePrefab.name, ownedByClient: true, useInstance: _realtime);
            brushStrokeGameObject.tag = "brushStroke";

            // Grab the BrushStroke component from it
            _activeBrushStroke = brushStrokeGameObject.GetComponent <BrushStroke>();

            // Tell the BrushStroke to begin drawing at the current brush position
            _activeBrushStroke.BeginBrushStrokeWithBrushTipPoint(transform.position, transform.rotation);
        }

        // If the trigger is pressed, and we have a brush stroke, move the brush stroke to the new brush tip position
        if (triggerPressed)
        {
            _activeBrushStroke.MoveBrushTipToPoint(transform.position, transform.rotation);
        }

        // If the trigger is no longer pressed, and we still have an active brush stroke, mark it as finished and clear it.
        if (!triggerPressed && _activeBrushStroke != null)
        {
            _activeBrushStroke.EndBrushStrokeWithBrushTipPoint(transform.position, transform.rotation);
            _activeBrushStroke = null;
        }
    }
Пример #15
0
    // ~ ~ ~ ~ ~
    // I. EMPTY

    public BrushStroke makeEmptyCore()
    {
        BrushStroke brush = Instantiate(brushPrefab);

        if (brushMat[(int)brushMode])
        {
            brush.mat = brushMat[(int)brushMode];
        }
        brush.transform.SetParent(transform);
        brush.brushColor = color;
        brush.brushSize  = brushSize;
        return(brush);
    }
Пример #16
0
    public void makeMeshEdge()
    {
        List <Vector3> points = getVertices.getSource();

        Debug.Log(points.Count);
        BrushStroke b = makeCurve(points);

        //b.refine();
        for (int i = 0; i < smoothReps; i++)
        {
            //b.smoothStroke(b.points);
        }
        //b.reduceStroke(b.points);
        strokes.Add(b);
    }
Пример #17
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        if (GUILayout.Button("Load tilt file"))
        {
            string tiltPath = ResolveTiltFileDirectory();
            string path     = EditorUtility.OpenFilePanel("Open sketch", tiltPath, "tilt");
            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            EditorPrefs.SetString(kLastTiltFileDirectory, Directory.GetParent(path).ToString());

            Sketch sketch = target as Sketch;
            foreach (var s in sketch.GetComponentsInChildren <BrushStroke>())
            {
                DestroyImmediate(s.gameObject);
            }

            BrushStroke bruskStrokeTemplate = sketch.fakeStroke;
            TBFile      tiltFile            = new TBFile(path);
            foreach (var brushStroke in tiltFile.brushStrokes)
            {
                BrushStroke stroke = Instantiate(bruskStrokeTemplate);
                stroke.transform.position = brushStroke.startPosition;
                stroke.transform.parent   = sketch.transform;

                stroke.sharedMesh = CreateMesh(stroke, brushStroke);
            }
            sketch.tiltFile = tiltFile;
        }

        if (GUILayout.Button("Animate"))
        {
            Sketch sketch = target as Sketch;
            new SketchAnimator(sketch.GetComponentsInChildren <BrushStroke>()).Start();
        }
    }
Пример #18
0
    void instantiateStroke(Color c)
    {
        BrushStroke b = Instantiate(brushPrefab);

        //b.brushMode = (BrushStroke.BrushMode) brushMode;
        if (brushMat[(int)brushMode])
        {
            b.mat = brushMat[(int)brushMode];
        }
        b.brushSize  = brushSize;
        b.brushColor = c;
        if (useEndColor)
        {
            b.brushEndColor = endColor;
        }
        else
        {
            b.brushEndColor = c;
        }
        b.transform.SetParent(layerList[currentLayer].frameList[layerList[currentLayer].currentFrame].transform);
        layerList[currentLayer].frameList[layerList[currentLayer].currentFrame].brushStrokeList.Add(b);
    }
Пример #19
0
    public void makeMeshFill()
    {
        List <Vector3> points = getVertices.getSource();

        Debug.Log(points.Count);
        for (int h = 0; h < fillLines; h++)
        {
            Vector3     p1      = points[(int)Random.Range(0f, points.Count)];
            Vector3     p2      = points[(int)Random.Range(0f, points.Count)];
            Vector3     p3      = (p1 + p2) / 2f;
            Vector3[]   newLine = { p1, p2, p3 };
            BrushStroke b       = makeLine(newLine.ToList());
            b.refine();
            b.randomize(randomize);
            b.refine();
            for (int i = 0; i < smoothReps / 10; i++)
            {
                b.smoothStroke(b.points);
            }
            //b.reduceStroke(b.points);
            strokes.Add(b);
        }
    }
Пример #20
0
    void Update()
    {
        if (armReadFile)
        {
            if (textMesh != null)
            {
                textMesh.text = "READING...";
            }
            StartCoroutine(readBrushStrokes());
            armReadFile = false;
        }
        else if (armWriteFile)
        {
            if (textMesh != null)
            {
                textMesh.text = "WRITING...";
            }
            StartCoroutine(writeBrushStrokes());
            armWriteFile = false;
        }
        else if (!isReadingFile && !isWritingFile)
        {
            for (int i = 0; i < layerList.Count; i++)
            {
                if (layerList[i].frameList.Count > 0 && !layerList[i].frameList[layerList[i].currentFrame].isDuplicate)
                {
                    layerList[i].previousFrame = layerList[i].currentFrame;
                }
            }

            if (isPlaying)
            {
                float t = 0f;
                if (audio != null)
                {
                    t = markTime + audio.time;
                }
                else
                {
                    t = Time.realtimeSinceStartup;
                }

                if ((audio != null && Time.realtimeSinceStartup > markTime + audio.clip.length) || (layerList[longestLayer].frameList.Count > 1 && t > lastFrameTime + frameInterval))
                {
                    if (drawWhilePlaying)
                    {
                        endStroke();
                        isDrawing = false;
                    }

                    lastFrameTime = t;

                    animVal += normalizedFrameInterval;
                    if (animVal > 1f)
                    {
                        animVal = 1f;
                    }

                    for (int i = 0; i < layerList.Count; i++)
                    {
                        // ~ ~ ~ ~ ~
                        if (killStrokes)
                        {
                            if (layerList[i].frameList[layerList[i].currentFrame].brushStrokeList.Count > 0 && Time.realtimeSinceStartup > layerList[i].frameList[layerList[i].currentFrame].brushStrokeList[0].birthTime + strokeLife)
                            {
                                inputEraseFirstStroke();
                            }
                        }
                        // ~ ~ ~ ~ ~
                        layerList[i].frameList[layerList[i].currentFrame].showFrame(false);
                        layerList[i].currentFrame++;

                        if (layerList[i].currentFrame > layerList[i].frameList.Count - 1)
                        {
                            layerList[i].currentFrame = 0;

                            if (i == longestLayer)
                            {
                                animVal  = 0f;
                                markTime = Time.realtimeSinceStartup;
                                if (audio != null)
                                {
                                    audio.time = 0f;
                                    audio.Stop();
                                    audio.Play();
                                }
                            }
                        }

                        if (fillEmptyMethod == FillEmptyMethod.DISPLAY && layerList[i].frameList[layerList[i].currentFrame].isDuplicate)
                        {
                            layerList[i].frameList[layerList[i].previousFrame].showFrame(true);
                        }
                        else
                        {
                            layerList[i].frameList[layerList[i].previousFrame].showFrame(false);
                            layerList[i].frameList[layerList[i].currentFrame].showFrame(true);
                        }
                    }
                }
            }
            else
            {
                if (audio != null && audio.isPlaying && Time.realtimeSinceStartup > markTime + frameInterval)
                {
                    audio.Stop();
                }
            }

            if (animator != null)
            {
                animator.Play(clipName, clipLayer, animVal);
            }

            // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

            try {
                if (isDrawing && Vector3.Distance(lastTargetPos, target.position) > minDistance)
                {
                    buildStroke();
                }
            } catch (System.Exception e) {
                Debug.Log(e.Data);
            }

            if (clicked && !isDrawing)
            {
                beginStroke();
                if (drawWhilePlaying && isPlaying && layerList[currentLayer].frameList.Count > 1 && layerList[currentLayer].frameList[layerList[currentLayer].previousFrame].brushStrokeList.Count > 0)
                {
                    BrushStroke lastStroke = layerList[currentLayer].frameList[layerList[currentLayer].previousFrame].brushStrokeList[layerList[currentLayer].frameList[layerList[currentLayer].previousFrame].brushStrokeList.Count - 1];
                    for (int pts = lastStroke.points.Count / drawTrailLength; pts < lastStroke.points.Count - 1; pts++)
                    {
                        layerList[currentLayer].frameList[layerList[currentLayer].currentFrame].brushStrokeList[layerList[currentLayer].frameList[layerList[currentLayer].currentFrame].brushStrokeList.Count - 1].points.Add(lastStroke.points[pts]);
                    }
                }
            }

            if (!clicked && isDrawing)
            {
                endStroke();
            }

            if (textMesh != null)
            {
                textMesh.text = "frame " + (layerList [currentLayer].currentFrame + 1) + " / " + layerList [currentLayer].frameList.Count;
            }

            if (layerList.Count > 1 && textMesh != null)
            {
                textMesh.text = "" + (currentLayer + 1) + ". " + textMesh.text;
            }

            if (layerList[currentLayer].frameList.Count < layerList[longestLayer].frameList.Count && textMesh != null)
            {
                textMesh.text += " (" + layerList [longestLayer].frameList.Count + ")";
            }
        }

        lastTargetPos = target.position;
    }
    private void Update()
    {
        if (!_realtime.connected)
        {
            return;
        }

        if (_realtime.clientID == _rt.ownerID)
        {
            // Start by figuring out which hand we're tracking
            XRNode node     = _hand == Hand.LeftHand ? XRNode.LeftHand : XRNode.RightHand;
            string trigger  = _hand == Hand.LeftHand ? "Left Trigger" : "Right Trigger";
            string joyclick = _hand == Hand.LeftHand ? "Left Joyclick" : "Right Joyclick";
            string axisY    = _hand == Hand.LeftHand ? "Left AxisY" : "Right AxisY";
            string axisX    = _hand == Hand.LeftHand ? "Left AxisX" : "Right AxisX";

            // Get the position & rotation of the hand
            bool handIsTracking = true; _handPosition = transform.position; _handRotation = transform.rotation;

            // Figure out if the trigger is pressed or not
            bool triggerPressed = Input.GetAxisRaw(trigger) > 0.1f;
            //bool triggerReleased = Input.GetAxisRaw(trigger) < 0.1f;

            //Figure out if the joystick is clicked or not
            bool joyclickPressed = Input.GetButtonDown(joyclick);

            // Figure out if the joystick / touchpad is pressed or not
            bool axisYMoved = Input.GetAxisRaw(axisY) < -0.2f || Input.GetAxisRaw(axisY) > 0.2f;
            //Debug.Log(Input.GetAxisRaw(axisY));
            bool axisXMoved = Input.GetAxisRaw(axisX) < -0.2f || Input.GetAxisRaw(axisX) > 0.2f;

            if (joyclickPressed)
            {
                Debug.Log("You pressed the joystick!");
                NextAction();
            }

            if (!axisXMoved)
            {
                didOnceX = false;
            }

            if (joyclickPressed)
            {
                SceneChanger sc = GameObject.FindObjectOfType <SceneChanger>();
                sc.Restart();
            }


            //actions if moving stuff should be handled by GazeXR
            if (action == 1)
            {
                // return; maybe still do TRIGGER stuff here at least!
                if (triggerPressed && !didOnceTrig)
                {
                    didOnceTrig = true;
                }

                if (triggerPressed && !didOnceTrig)
                {
                }

                if (!triggerPressed)
                {
                    didOnceTrig = false;
                }
            }

            //actions if drawing
            if (action == 0)
            {
                // If we lose tracking, stop drawing

                /*
                 * if (!handIsTracking)
                 * {
                 *  triggerPressed = false;
                 *  axisYMoved = false;
                 * }
                 */

                if (!axisYMoved)
                {
                    //Debug.Log("The Y Axis has NOT Moved");
                    //_brushPos.GetComponent<MeshRenderer>().enabled = false;
                }

                //If you move the joystick up or down, you're chaning the brush tip location
                if (axisYMoved && _brushPos.localPosition.z > 0f)
                {
                    //Debug.Log("The Y Axis has Moved");
                    //_brushPos.GetComponent<MeshRenderer>().enabled = true;
                    _brushPos.localPosition = new Vector3(_brushPos.localPosition.x, _brushPos.localPosition.y, _brushPos.localPosition.z - (Input.GetAxisRaw(axisY) * _speed));
                    VibrateControllers(.1f, .1f, .15f);
                }
                if (axisYMoved && _brushPos.localPosition.z <= 0.05f)
                {
                    _brushPos.localPosition = new Vector3(_brushPos.localPosition.x, _brushPos.localPosition.y, 0.05f);
                }

                //if you move the joystick left or right, you're changing the color
                if (axisXMoved)
                {
                    //_brushStrokePrefab.GetComponent<BrushStroke>().ResizeWidth(Input.GetAxisRaw(axisY) * (_speed/2));

                    /*
                     * Color newColor = new Color(brushMat.color.r - (Input.GetAxisRaw(axisY) * _speed), Random.value, Random.value, 1.0f);
                     * // apply it on  material
                     * brushMat.color = newColor;
                     */
                }


                // If the trigger is pressed and we haven't created a new brush stroke to draw, create one!
                if (triggerPressed && _activeBrushStroke == null)
                {
                    // Instantiate a copy of the Brush Stroke prefab, set it to be owned by us.
                    GameObject brushStrokeGameObject = Realtime.Instantiate(_brushStrokePrefab.name, ownedByClient: true, useInstance: _realtime);

                    // Make that brush stroke a child of the current state
                    //brushStrokeGameObject.transform.parent = currentOption.transform;

                    // Grab the BrushStroke component from it
                    _activeBrushStroke = brushStrokeGameObject.GetComponent <BrushStroke>();

                    // Tell the BrushStroke to begin drawing at the current brush position
                    _activeBrushStroke.BeginBrushStrokeWithBrushTipPoint(_brushPos.position, _handRotation);
                    VibrateControllers(.12f, .12f, .2f);
                }

                // If the trigger is pressed, and we have a brush stroke, move the brush stroke to the new brush tip position
                if (triggerPressed)
                {
                    _activeBrushStroke.MoveBrushTipToPoint(_brushPos.position, _handRotation);
                    VibrateControllers(.12f, .12f, .2f);
                    //_brushPos.GetComponent<MeshRenderer>().enabled = true;
                }


                // If the trigger is no longer pressed, and we still have an active brush stroke, mark it as finished and clear it.
                if (!triggerPressed && _activeBrushStroke != null)
                {
                    _activeBrushStroke.EndBrushStrokeWithBrushTipPoint(_brushPos.position, _handRotation);
                    _activeBrushStroke = null;
                    //_ot.gr.VibrateControllers(.24f, .12f, .4f);
                }
            }

            //actions if mask swapping
            if (action == 2)
            {
                if (axisXMoved && Input.GetAxisRaw(axisX) > 0 && !didOnceX)
                {
                    didOnceX = true;
                    VibrateControllers(.12f, .2f, .2f);
                }
                if (axisXMoved && Input.GetAxisRaw(axisX) < 0 && !didOnceX)
                {
                    didOnceX = true;
                    VibrateControllers(.2f, .12f, .2f);
                }
            }

            //actions if stage swapping
            if (action == 3)
            {
                if (axisXMoved && Input.GetAxisRaw(axisX) > 0 && !didOnceX)
                {
                    didOnceX = true;
                }
                if (axisXMoved && Input.GetAxisRaw(axisX) < 0 && !didOnceX)
                {
                    didOnceX = true;
                }
            }

            //actions if just squeezing your hands

            /*
             * if (action == 4)
             * {
             *  if (Input.GetAxisRaw(trigger) > 0.5f)
             *  {
             *      _ps.SetHandState(1);
             *  }
             *  else
             *  {
             *      _ps.SetHandState(0);
             *  }
             * } */
        }
    }
Пример #22
0
    private Mesh CreateMesh(BrushStroke stroke, TBBrushStroke brushStroke)
    {
        var controlPoints = brushStroke.controlPoints;

        Mesh mesh           = new Mesh();
        int  vertexCount    = 2 * 2 * controlPoints.Count; // triangle strip is double-sided
        int  trianglesCount = 2 * (2 * controlPoints.Count - 2);

        Vector3[] vertices  = new Vector3[vertexCount];
        Color[]   colors    = new Color[vertexCount];
        int[]     triangles = new int[3 * trianglesCount];

        int vertexIndex = 0;

        // generate front side
        foreach (var point in controlPoints)
        {
            Vector3 v1 = point.position - stroke.transform.position;
            Vector3 v2 = v1 + brushStroke.brushSize * point.pressure * point.tangent;
            vertices[vertexIndex++] = v1;
            vertices[vertexIndex++] = v2;
        }
        // generate back side
        Array.Copy(vertices, 0, vertices, vertices.Length / 2, vertices.Length / 2);

        // set colors
        for (int i = 0; i < vertexCount; ++i)
        {
            colors[i] = brushStroke.brushColor;
        }

        // generate triangles
        vertexIndex = 0;
        for (int i = 0; i < triangles.Length / 2;)
        {
            int i1 = vertexIndex;
            int i2 = vertexIndex + 1;
            int i3 = vertexIndex + 2;
            int i4 = vertexIndex + 3;

            triangles[i++] = i1;
            triangles[i++] = i2;
            triangles[i++] = i3;
            triangles[i++] = i3;
            triangles[i++] = i2;
            triangles[i++] = i4;

            vertexIndex += 2;
        }

        for (int i = triangles.Length / 2; i < triangles.Length;)
        {
            int i1 = vertexIndex;
            int i2 = vertexIndex + 1;
            int i3 = vertexIndex + 2;
            int i4 = vertexIndex + 3;

            triangles[i++] = i1;
            triangles[i++] = i3;
            triangles[i++] = i2;
            triangles[i++] = i3;
            triangles[i++] = i4;
            triangles[i++] = i2;

            vertexIndex += 2;
        }

        mesh.vertices  = vertices;
        mesh.triangles = triangles;
        mesh.colors    = colors;
        mesh.RecalculateNormals();

        return(mesh);
    }
Пример #23
0
    public Vector3 getLastPoint()
    {
        BrushStroke stroke = getLastStroke();

        return(stroke.points[stroke.points.Count - 1]);
    }