Ejemplo n.º 1
0
        private void OnStrokeStart()
        {
            player.Stop();

            var currentPatternColorIndex = pattern.length;

            if (currentPatternColorIndex > 0)
            {
                currentPatternColorIndex = erasing ? -2 : pattern.getNextUnusedColorIndex(pattern.strokes);
            }

            if (currentPaintingTool is PaintingTool.ReflectionPainting painting)
            {
                var reflected = new Stroke.Stroke(currentPatternColorIndex);

                pattern.AddStroke(reflected);
                reflectedStroke          = reflected;
                painting.reflectedStroke = reflectedStroke;
            }
            else
            {
                reflectedStroke = null;
            }

            var stroke = new Stroke.Stroke(currentPatternColorIndex);

            if (reflectedStroke != null)
            {
            }

            pattern.AddStroke(stroke);

            strokeTime = timeline.time;
            selectStroke(stroke);
        }
Ejemplo n.º 2
0
        private void OnStrokeEnd()
        {
            if (hmdDisplay != null)
            {
                hmdDisplay.SetStrokingInfo(0f);
            }
            reflectedStroke = null;

            currentPaintingTool.finishPainting();
        }
Ejemplo n.º 3
0
        private void OnStrokeAdded(Stroke.Stroke stroke)
        {
            var lineRenderer = Instantiate(prefab, transform);

            lineRenderer.enabled = true;

            lineRenderers.Add(stroke, lineRenderer);

            selectStroke(stroke);

            Paint(stroke);
        }
Ejemplo n.º 4
0
        private void selectStroke(Stroke.Stroke stroke)
        {
            // unselect all others
            foreach (var myStroke in pattern.strokes.Where(myStroke => myStroke.myMarker != null))
            {
                myStroke.myMarker.Select(false);
                setGradientAlpha(myStroke, 0.4f);
            }

            currentStroke = stroke;
            if (currentStroke.myMarker != null)
            {
                currentStroke.myMarker.Select(true);
            }
        }
Ejemplo n.º 5
0
        private void setGradientAlpha(Stroke.Stroke myStroke, float alpha)
        {
            if (myStroke == null || !lineRenderers.ContainsKey(myStroke))
            {
                return;
            }
            var lineRenderer = lineRenderers[myStroke];

            if (lineRenderer == null)
            {
                return;
            }
            var gradient = lineRenderer.colorGradient;

            gradient.SetKeys(gradient.colorKeys, new[] { new GradientAlphaKey(alpha, 0) });

            lineRenderer.colorGradient = gradient;
        }
Ejemplo n.º 6
0
            public override float[] OnStroke(RaycastHit hit, Stroke.Stroke currentStroke, float strokeTime,
                                             float strokingValue)
            {
                if (reflectedStroke == null)
                {
                    Debug.Log("ERROR in PaintingTool:ReflectionPainting - reflectedStroke is still null!");
                }

                var keyOrigin = new Key
                {
                    time      = strokeTime,
                    position  = hit.point,
                    intensity = strokingValue * 2
                };

                var reflectedPosition = hit.point;

                reflectedPosition.x *= -1;

                var keyReflected = new Key
                {
                    time      = strokeTime,
                    position  = reflectedPosition,
                    intensity = strokingValue * 2,
                    deleted   = false
                };

                // set all intensities to 0
                for (var i = 0; i < intensities.Length; i++)
                {
                    intensities[i] = 0;
                }
                evaluator.CalculateIntensitiesForKey(keyOrigin, intensities);
                evaluator.CalculateIntensitiesForKey(keyReflected, intensities);

                if (currentStroke == null)
                {
                    return(intensities);
                }
                currentStroke.AddKey(keyOrigin);
                reflectedStroke.AddKey(keyReflected);

                return(intensities);
            }
Ejemplo n.º 7
0
        private void OnStrokeRemoved(Stroke.Stroke stroke)
        {
            player.Stop();

            SelectStrokeByCurrentWithOffset(-1);

            if (currentStroke == stroke)
            {
                currentStroke = null;
            }

            var lineRenderer = lineRenderers[stroke];

            lineRenderers.Remove(stroke);
            stroke.DestroyStroke();

            Destroy(lineRenderer.gameObject);
            player.SetTime(Math.Min(timeline.time, pattern.getDuration()));
            timeline.SetDuration(pattern.getDuration());
        }
Ejemplo n.º 8
0
            public override float[] OnStroke(RaycastHit hit, Stroke.Stroke currentStroke, float strokeTime,
                                             float strokingValue)
            {
                var key = new Key
                {
                    time      = strokeTime,
                    position  = hit.point,
                    intensity = strokingValue * 2,
                    deleted   = false
                };

                // set all intensities to 0
                for (var i = 0; i < intensities.Length; i++)
                {
                    intensities[i] = 0;
                }

                evaluator.CalculateIntensitiesForKey(key, intensities);

                currentStroke?.AddKey(key);

                return(intensities);
            }
Ejemplo n.º 9
0
        private void Paint(Stroke.Stroke stroke)
        {
            if (!lineRenderers.ContainsKey(stroke))
            {
                return;
            }
            var keys         = stroke.keys;
            var lineRenderer = lineRenderers[stroke];

            var gradient = new Gradient();

            gradient.SetKeys(
                new[] { new GradientColorKey(stroke.color, 0) },
                new[] { new GradientAlphaKey(1, 0) }
                );

            lineRenderer.colorGradient = gradient;
            lineRenderer.positionCount = keys.Count;

            if (keys.Count <= 0)
            {
                return;
            }
            var startTime  = keys[0].time;
            var endTime    = keys[keys.Count - 1].time;
            var duration   = endTime - startTime;
            var widthCurve = new AnimationCurve();

            for (var i = 0; i < keys.Count; i++)
            {
                lineRenderer.SetPosition(i, keys[i].position * 1.05f);
                widthCurve.AddKey((keys[i].time - startTime) / duration, keys[i].intensity);
            }

            lineRenderer.widthCurve      = widthCurve;
            lineRenderer.widthMultiplier = 0.01f;
        }
Ejemplo n.º 10
0
 /// <summary>
 ///     Call this on stroking
 /// </summary>
 /// <param name="originToTarget">The origin ray</param>
 /// <param name="currentStroke">Current drawing stroke</param>
 /// <param name="strokeTime">Current player time for next key</param>
 /// <param name="strokingValue">The intensitiy</param>
 /// <returns>Returns intensities for controlling HapticHead</returns>
 public abstract float[] OnStroke(RaycastHit hit, Stroke.Stroke currentStroke, float strokeTime,
                                  float strokingValue);
Ejemplo n.º 11
0
 public override void finishPainting()
 {
     reflectedStroke = null;
 }