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); }
private void OnStrokeEnd() { if (hmdDisplay != null) { hmdDisplay.SetStrokingInfo(0f); } reflectedStroke = null; currentPaintingTool.finishPainting(); }
private void OnStrokeAdded(Stroke.Stroke stroke) { var lineRenderer = Instantiate(prefab, transform); lineRenderer.enabled = true; lineRenderers.Add(stroke, lineRenderer); selectStroke(stroke); Paint(stroke); }
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); } }
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; }
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); }
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()); }
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); }
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; }
/// <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);
public override void finishPainting() { reflectedStroke = null; }