Skip to content

Commit 295ff75

Browse files
authored
Merge pull request #283 from darax/master
Fix issues #280 and #282
2 parents eff14ed + 8e443a5 commit 295ff75

File tree

2 files changed

+41
-45
lines changed

2 files changed

+41
-45
lines changed

Assets/HoloToolkit/Input/Scripts/GazeStabilizer.cs

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public class GazeStabilizer : MonoBehaviour
4444

4545
public struct GazeSample
4646
{
47-
public Vector3 position;
48-
public Vector3 direction;
49-
public float timestamp;
47+
public Vector3 Position;
48+
public Vector3 Direction;
49+
public float Timestamp;
5050
};
5151

5252
private LinkedList<GazeSample> stabilitySamples = new LinkedList<GazeSample>();
@@ -96,9 +96,9 @@ private void AddGazeSample(Vector3 positionSample, Vector3 directionSample)
9696
{
9797
// Record and save sample data.
9898
GazeSample newStabilitySample;
99-
newStabilitySample.position = positionSample;
100-
newStabilitySample.direction = directionSample;
101-
newStabilitySample.timestamp = Time.time;
99+
newStabilitySample.Position = positionSample;
100+
newStabilitySample.Direction = directionSample;
101+
newStabilitySample.Timestamp = Time.time;
102102

103103
if (stabilitySamples != null)
104104
{
@@ -114,19 +114,6 @@ private void AddGazeSample(Vector3 positionSample, Vector3 directionSample)
114114

115115
private void UpdateInstability(out float positionInstability, out float directionInstability)
116116
{
117-
GazeSample mostRecentSample;
118-
119-
float positionDeltaMin = 0.0f;
120-
float positionDeltaMax = 0.0f;
121-
float positionDeltaMean = 0.0f;
122-
123-
float directionDeltaMin = 0.0f;
124-
float directionDeltaMax = 0.0f;
125-
float directionDeltaMean = 0.0f;
126-
127-
float positionDelta = 0.0f;
128-
float directionDelta = 0.0f;
129-
130117
positionInstability = 0.0f;
131118
directionInstability = 0.0f;
132119

@@ -136,37 +123,39 @@ private void UpdateInstability(out float positionInstability, out float directio
136123
return;
137124
}
138125

139-
mostRecentSample = stabilitySamples.Last.Value;
126+
GazeSample mostRecentSample = stabilitySamples.Last.Value;
140127

141-
bool first = true;
142-
foreach(GazeSample sample in stabilitySamples)
143-
{
144-
// Calculate difference between current sample and most recent sample.
145-
positionDelta = Vector3.Magnitude(sample.position - mostRecentSample.position);
128+
float positionDeltaMin = float.MaxValue;
129+
float positionDeltaMax = float.MinValue;
130+
float positionDeltaMean = 0.0f;
146131

147-
directionDelta = Vector3.Angle(sample.direction, mostRecentSample.direction) * Mathf.Deg2Rad;
132+
float directionDeltaMin = float.MaxValue;
133+
float directionDeltaMax = float.MinValue;
134+
float directionDeltaMean = 0.0f;
148135

149-
// Initialize max and min on first sample.
150-
if (first)
136+
float positionDelta = 0.0f;
137+
float directionDelta = 0.0f;
138+
139+
foreach (GazeSample sample in stabilitySamples)
140+
{
141+
if (sample.Timestamp == mostRecentSample.Timestamp)
151142
{
152-
positionDeltaMin = positionDelta;
153-
positionDeltaMax = positionDelta;
154-
directionDeltaMin = directionDelta;
155-
directionDeltaMax = directionDelta;
156-
first = false;
143+
continue;
157144
}
158-
else
159-
{
160-
// Update maximum, minimum and mean differences from most recent sample.
161-
positionDeltaMin = Mathf.Min(positionDelta, positionDeltaMin);
162-
positionDeltaMax = Mathf.Max(positionDelta, positionDeltaMax);
163145

164-
directionDeltaMin = Mathf.Min(directionDelta, directionDeltaMin);
165-
directionDeltaMax = Mathf.Max(directionDelta, directionDeltaMax);
166-
}
146+
// Calculate difference between current sample and most recent sample.
147+
positionDelta = Vector3.Magnitude(sample.Position - mostRecentSample.Position);
148+
directionDelta = Vector3.Angle(sample.Direction, mostRecentSample.Direction) * Mathf.Deg2Rad;
149+
150+
// Update maximum, minimum and mean differences from most recent sample.
151+
positionDeltaMin = Mathf.Min(positionDelta, positionDeltaMin);
152+
positionDeltaMax = Mathf.Max(positionDelta, positionDeltaMax);
153+
154+
directionDeltaMin = Mathf.Min(directionDelta, directionDeltaMin);
155+
directionDeltaMax = Mathf.Max(directionDelta, directionDeltaMax);
167156

168157
positionDeltaMean += positionDelta;
169-
directionDeltaMean += directionDelta;
158+
directionDeltaMean += directionDelta;
170159
}
171160

172161
positionDeltaMean = positionDeltaMean / (stabilitySamples.Count - 1);

Assets/HoloToolkit/SpatialMapping/Scripts/SpatialProcessing/RemoveSurfaceVertices.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,15 @@ private IEnumerator RemoveSurfaceVerticesWithinBoundsRoutine()
135135
}
136136

137137
Mesh mesh = filter.sharedMesh;
138-
139-
if (mesh != null && !mesh.bounds.Intersects(bounds))
138+
MeshRenderer renderer = filter.GetComponent<MeshRenderer>();
139+
140+
// The mesh renderer bounds are in world space.
141+
// If the mesh is null there is nothing to process
142+
// If the renderer is null we can't get the renderer bounds
143+
// If the renderer's bounds aren't contained inside of the current
144+
// bounds from the bounds queue there is no reason to process
145+
// If any of the above conditions are met, then we should go to the next meshfilter.
146+
if (mesh == null || renderer == null || !renderer.bounds.Intersects(bounds))
140147
{
141148
// We don't need to do anything to this mesh, move to the next one.
142149
continue;
@@ -149,7 +156,7 @@ private IEnumerator RemoveSurfaceVerticesWithinBoundsRoutine()
149156
// Find which mesh vertices are within the bounds.
150157
for (int i = 0; i < verts.Length; ++i)
151158
{
152-
if (bounds.Contains(verts[i]))
159+
if (bounds.Contains(filter.transform.TransformPoint(verts[i])))
153160
{
154161
// These vertices are within bounds, so mark them for removal.
155162
vertsToRemove.Add(i);

0 commit comments

Comments
 (0)