Skip to content

Commit

Permalink
Add visual gizmo when paint fails due to NoPaintZone
Browse files Browse the repository at this point in the history
  • Loading branch information
vabrador committed Feb 22, 2018
1 parent 56dd77a commit 2e75c77
Show file tree
Hide file tree
Showing 7 changed files with 708 additions and 534 deletions.
2 changes: 1 addition & 1 deletion Assets/Editor/PanicButton/reloader.cs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
// e009d5ca-2f39-41dc-91cf-116ddd58134b 636548576660325877
// dadb192f-7f29-48c7-ac20-ab0789c7bc72 636548622047207485
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ Material:
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0.6397059, g: 0.6397059, b: 0.6397059, a: 0.90328586}
- _Color: {r: 0.6397059, g: 0.6397059, b: 0.6397059, a: 0.9890286}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ Material:
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0.38431376, g: 0.38431376, b: 0.38431376, a: 1}
- _Color: {r: 0.6392157, g: 0.10980393, b: 0.08627451, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
1,086 changes: 563 additions & 523 deletions Assets/archives/LeapPaint (v3 archive)/zzOld_LeapPaint/Scenes/LeapPaint.unity

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,19 @@ public class PinchStrokeProcessor : MonoBehaviour {
//}
}
// slightly better system
Collider noPaintZoneCollider = null;
{
var cursorPos = _paintCursor.transform.position;
float closestColliderSqrDist = float.PositiveInfinity;
foreach (var collider in NoPaintZone.noPaintColliders) {
var doesCollide = collider.ClosestPoint(cursorPos).ApproxEquals(cursorPos);
if (doesCollide) {
var testSqrDist = (collider.transform.position - cursorPos).sqrMagnitude;
if (testSqrDist < closestColliderSqrDist) {
noPaintZoneCollider = collider;
closestColliderSqrDist = testSqrDist;
}
_inDangerZone = true;
break;
}
}
}
Expand All @@ -139,15 +145,21 @@ public class PinchStrokeProcessor : MonoBehaviour {
bool isLoading = _ribbonIO.IsLoading;

bool possibleToActualize = false;
bool possibleToActualizeButForDangerZone = false;
Color drawColor = _paintCursor.Color;
if (drawColor.a > 0.99F
&& !_inDangerZone
&& !interactionHand.isGraspingObject
&& !isUIDisplayingOnThisHand
&& _handLifetime > MIN_HAND_DRAWING_LIFETIME
&& !isLoading
) {
possibleToActualize = true;
if (_inDangerZone) {
possibleToActualizeButForDangerZone = true;
possibleToActualize = false;
}
else {
possibleToActualize = true;
}
}
_paintCursor.NotifyPossibleToActualize(possibleToActualize);

Expand Down Expand Up @@ -177,13 +189,24 @@ public class PinchStrokeProcessor : MonoBehaviour {

// Drawing State //

if (_paintCursor.IsTracked && !_strokeProcessor.IsBufferingStroke && !_inDangerZone && possibleToActualize && possibleToBeginActualizing) {
BeginStroke();
if (_paintCursor.IsTracked && !_strokeProcessor.IsBufferingStroke && possibleToBeginActualizing) {
if (possibleToActualize) {
BeginStroke();
}
else if (possibleToActualizeButForDangerZone) {

}
}

if (_paintCursor.DidStartPinch && possibleToActualize && possibleToBeginActualizing && !_strokeProcessor.IsActualizingStroke) {
StartActualizingStroke();
_paintCursor.NotifyIsPainting(true);
if (_paintCursor.DidStartPinch && possibleToBeginActualizing && !_strokeProcessor.IsActualizingStroke) {
if (possibleToActualize) {
StartActualizingStroke();
_paintCursor.NotifyIsPainting(true);
}
else if (possibleToActualizeButForDangerZone) {
NoPaintZoneFeedbackDrawer.DrawFailedPaintGizmo(_paintCursor.transform.position,
noPaintZoneCollider);
}
}

if (_paintCursor.IsTracked && _strokeProcessor.IsBufferingStroke) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using InteractionEngineUtility;
using Leap.Unity.RuntimeGizmos;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Leap.Unity.LeapPaint_v3 {

public class NoPaintZoneFeedbackDrawer : MonoBehaviour, IRuntimeGizmoComponent {

private AnimationCurve _curve = DefaultCurve.SigmoidUp;

private static NoPaintZoneFeedbackDrawer _instance = null;
public static NoPaintZoneFeedbackDrawer instance {
get { return _instance; }
}

private void Awake() {
if (_instance == null) _instance = this;
}

public static void DrawFailedPaintGizmo(Vector3 pinchPos, Collider dueToCollider) {
instance.Draw(pinchPos, dueToCollider);
}

public void Draw(Vector3 pinchPos, Collider dueToCollider) {
var collider = dueToCollider;

//var surfacePos = collider.transform.TransformPoint(collider.ClosestPointOnSurface(
// collider.transform.InverseTransformPoint(pinchPos)));
//var normal = surfacePos - dueToCollider.transform.position;
var normal = collider.transform.position - pinchPos;

var newGizmo = new FailedPaintGizmo() {
position = pinchPos,
normal = normal,
colliderPos = dueToCollider.transform.position,
initRingSize = 0.01f,
finalRingSize = 0.06f,
duration = 0.6f,
t = 0f
};

_failedPaintGizmos.Add(newGizmo);
}

private List<FailedPaintGizmo> _failedPaintGizmos = new List<FailedPaintGizmo>();

public struct FailedPaintGizmo {
public Vector3 position;
public Vector3 normal;
public Vector3 colliderPos;
public float initRingSize;
public float finalRingSize;
public float duration;
public float t;

public bool isFinished;
}

public void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer) {
drawer.color = LeapColor.cyan;

var rDelta = 0.008f;
var dt = Time.deltaTime;
FailedPaintGizmo gizmo;
for (int i = 0; i < _failedPaintGizmos.Count; i++) {
gizmo = _failedPaintGizmos[i];

gizmo.t += dt;
if (gizmo.t > gizmo.duration) {
gizmo.t = gizmo.duration;
gizmo.isFinished = true;
}

var progress = _curve.Evaluate(gizmo.t / gizmo.duration);
drawer.color = drawer.color.WithAlpha(Mathf.Sin(progress * Mathf.PI));

for (int j = 0; j < 3; j++) {
var r = Mathf.Lerp(gizmo.initRingSize, gizmo.finalRingSize, progress)
- rDelta * j;

if (r > 0f) {
drawer.DrawWireArc(gizmo.position, gizmo.normal, gizmo.normal.Perpendicular(),
r, 1f, 32);
}
}
drawer.DrawDashedLine(gizmo.position, gizmo.colliderPos, segmentsPerMeter: 128);

_failedPaintGizmos[i] = gizmo;
}

_failedPaintGizmos.RemoveAll((g) => g.isFinished);
}

}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2e75c77

Please sign in to comment.