Skip to content

Commit 64aab76

Browse files
authored
Merge pull request #387 from leapmotion/Release-CoreAsset-4.1.3
Release core asset 4.1.3
2 parents 161784d + 81ebd27 commit 64aab76

File tree

68 files changed

+20686
-1946
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+20686
-1946
lines changed

Assets/LeapMotion/Scripts/Algorithms.meta

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/LeapMotion/Scripts/Algorithms/Editor.meta

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/LeapMotionModules/RealtimeGraph/Scripts/Editor/Tests.meta Assets/LeapMotion/Scripts/Algorithms/Editor/Tests.meta

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/LeapMotion/Scripts/Utils/SmoothedFloat.cs Assets/LeapMotion/Scripts/Algorithms/SmoothedFloat.cs

+7-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using UnityEngine;
22

3-
namespace Leap.Unity{
3+
namespace Leap.Unity {
44
/// <summary>
55
/// Time-step independent exponential smoothing.
66
/// </summary>
@@ -13,31 +13,19 @@ public class SmoothedFloat {
1313
public float delay = 0f; // Mean delay
1414
public bool reset = true; // Reset on Next Update
1515

16-
public float average_dt = 0f;
17-
18-
public void SetBlend(float blend, float deltaTime = 1f)
19-
{
16+
public void SetBlend(float blend, float deltaTime = 1f) {
2017
delay = deltaTime * blend / (1f - blend);
2118
}
22-
23-
public float Update(float input, float deltaTime = 1f)
24-
{
25-
if (deltaTime > 0f &&
26-
!reset) {
19+
20+
public float Update(float input, float deltaTime = 1f) {
21+
if (deltaTime > 0f && !reset) {
2722
float alpha = delay / deltaTime;
28-
float blend = alpha / (1f + alpha);
23+
float blend = alpha / (1f + alpha);
2924
// NOTE: If delay -> 0 then blend -> 0,
3025
// reducing the filter to this.value = value.
3126
// NOTE: If deltaTime -> 0 blend -> 1,
3227
// so the change in the filtered value will be suppressed
33-
var newValue = Mathf.Lerp(this.value, input, 1f - blend);
34-
35-
var new_dt = Mathf.Abs(newValue - value);
36-
if (average_dt * 10 < newValue - value)
37-
Debug.Log("Average dt was excessive!");
38-
39-
average_dt = Mathf.Lerp(average_dt, new_dt, 1f - blend);
40-
value = newValue;
28+
value = Mathf.Lerp(value, input, 1f - blend);
4129
} else {
4230
value = input;
4331
reset = false;

Assets/LeapMotion/Scripts/Utils/SmoothedQuaternion.cs Assets/LeapMotion/Scripts/Algorithms/SmoothedQuaternion.cs

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using UnityEngine;
22

3-
namespace Leap.Unity{
3+
namespace Leap.Unity {
44
/// <summary>
55
/// Time-step independent exponential smoothing.
66
/// </summary>
@@ -12,18 +12,15 @@ public class SmoothedQuaternion {
1212
public Quaternion value = Quaternion.identity; // Filtered value
1313
public float delay = 0f; // Mean delay
1414
public bool reset = true; // Reset on Next Update
15-
16-
public void SetBlend(float blend, float deltaTime = 1f)
17-
{
15+
16+
public void SetBlend(float blend, float deltaTime = 1f) {
1817
delay = deltaTime * blend / (1f - blend);
1918
}
20-
21-
public Quaternion Update(Quaternion input, float deltaTime = 1f)
22-
{
23-
if (deltaTime > 0f &&
24-
!reset) {
19+
20+
public Quaternion Update(Quaternion input, float deltaTime = 1f) {
21+
if (deltaTime > 0f && !reset) {
2522
float alpha = delay / deltaTime;
26-
float blend = alpha / (1f + alpha);
23+
float blend = alpha / (1f + alpha);
2724
// NOTE: If delay -> 0 then blend -> 0,
2825
// reducing the filter to this.value = value.
2926
// NOTE: If deltaTime -> 0 blend -> 1,

Assets/LeapMotion/Scripts/Utils/SmoothedVector3.cs Assets/LeapMotion/Scripts/Algorithms/SmoothedVector3.cs

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using UnityEngine;
22

3-
namespace Leap.Unity{
3+
namespace Leap.Unity {
44
/// <summary>
55
/// Time-step independent exponential smoothing.
66
/// </summary>
@@ -12,18 +12,15 @@ public class SmoothedVector3 {
1212
public Vector3 value = Vector3.zero; // Filtered value
1313
public float delay = 0f; // Mean delay
1414
public bool reset = true; // Reset on Next Update
15-
16-
public void SetBlend(float blend, float deltaTime = 1f)
17-
{
15+
16+
public void SetBlend(float blend, float deltaTime = 1f) {
1817
delay = deltaTime * blend / (1f - blend);
1918
}
20-
21-
public Vector3 Update(Vector3 input, float deltaTime = 1f)
22-
{
23-
if (deltaTime > 0f &&
24-
!reset) {
19+
20+
public Vector3 Update(Vector3 input, float deltaTime = 1f) {
21+
if (deltaTime > 0f && !reset) {
2522
float alpha = delay / deltaTime;
26-
float blend = alpha / (1f + alpha);
23+
float blend = alpha / (1f + alpha);
2724
// NOTE: If delay -> 0 then blend -> 0,
2825
// reducing the filter to this.value = value.
2926
// NOTE: If deltaTime -> 0 blend -> 1,

Assets/LeapMotion/Scripts/DataStructures.meta

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/LeapMotion/Scripts/DataStructures/Editor.meta

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/LeapMotionModules/RealtimeGraph/Scripts/Editor.meta Assets/LeapMotion/Scripts/DataStructures/Editor/Tests.meta

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/LeapMotion/Scripts/HandPool.cs

+60-33
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@
1010

1111
namespace Leap.Unity {
1212
/**
13-
* HandPool holds a pool of IHandModels and makes HandRepresentations
13+
* HandPool holds a pool of IHandModels and makes HandProxys
1414
* when given a Leap Hand and a model type of graphics or physics.
15-
* When a HandRepresentation is created, an IHandModel is removed from the pool.
16-
* When a HandRepresentation is finished, its IHandModel is returned to the pool.
15+
* When a HandProxy is created, an IHandModel is removed from the pool.
16+
* When a HandProxy is finished, its IHandModel is returned to the pool.
1717
*/
1818
public class HandPool :
1919
HandFactory {
2020
[SerializeField]
2121
private List<ModelGroup> ModelPool;
22-
private List<HandRepresentation> activeHandReps = new List<HandRepresentation>();
22+
private List<HandProxy> activeHandReps = new List<HandProxy>();
2323

2424
private Dictionary<IHandModel, ModelGroup> modelGroupMapping = new Dictionary<IHandModel, ModelGroup>();
25-
private Dictionary<IHandModel, HandRepresentation> modelToHandRepMapping = new Dictionary<IHandModel, HandRepresentation>();
25+
private Dictionary<IHandModel, HandProxy> modelToHandRepMapping = new Dictionary<IHandModel, HandProxy>();
2626

2727
/**
2828
* ModelGroup contains a left/right pair of IHandModel's
29-
* @param modelList The IHandModels available for use by HandRepresentations
30-
* @param modelsCheckedOut The IHandModels currently in use by active HandRepresentations
29+
* @param modelList The IHandModels available for use by HandProxys
30+
* @param modelsCheckedOut The IHandModels currently in use by active HandProxys
3131
* @param IsEnabled determines whether the ModelGroup is active at app Start(), though ModelGroup's are controlled with the EnableGroup() & DisableGroup methods.
3232
* @param CanDuplicate Allows a IHandModels in the ModelGroup to be cloned at runtime if a suitable IHandModel isn't available.
3333
*/
@@ -53,9 +53,7 @@ public class ModelGroup {
5353
* If not, one can be cloned*/
5454
public IHandModel TryGetModel(Chirality chirality, ModelType modelType) {
5555
for (int i = 0; i < modelList.Count; i++) {
56-
if (modelList[i].HandModelType == modelType
57-
&& modelList[i].Handedness == chirality
58-
|| modelList[i].Handedness == Chirality.Either) {
56+
if (modelList[i].HandModelType == modelType && modelList[i].Handedness == chirality) {
5957
IHandModel model = modelList[i];
6058
modelList.RemoveAt(i);
6159
modelsCheckedOut.Add(model);
@@ -64,9 +62,7 @@ public IHandModel TryGetModel(Chirality chirality, ModelType modelType) {
6462
}
6563
if (CanDuplicate) {
6664
for (int i = 0; i < modelsCheckedOut.Count; i++) {
67-
if (modelsCheckedOut[i].HandModelType == modelType
68-
&& modelsCheckedOut[i].Handedness == chirality
69-
|| modelsCheckedOut[i].Handedness == Chirality.Either) {
65+
if (modelsCheckedOut[i].HandModelType == modelType && modelsCheckedOut[i].Handedness == chirality) {
7066
IHandModel modelToSpawn = modelsCheckedOut[i];
7167
IHandModel spawnedModel = GameObject.Instantiate(modelToSpawn);
7268
spawnedModel.transform.parent = _handPool.transform;
@@ -87,10 +83,34 @@ public void ReturnToGroup(IHandModel model) {
8783
public void ReturnToPool(IHandModel model) {
8884
ModelGroup modelGroup;
8985
bool groupFound = modelGroupMapping.TryGetValue(model, out modelGroup);
90-
modelGroup.ReturnToGroup(model);
9186
Assert.IsTrue(groupFound);
87+
//First see if there is another active representation that can use this model
88+
for (int i = 0; i < activeHandReps.Count; i++) {
89+
HandProxy rep = activeHandReps[i];
90+
if (rep.RepChirality == model.Handedness && rep.RepType == model.HandModelType) {
91+
bool modelFromGroupFound = false;
92+
if (rep.handModels != null) {
93+
//And that represention does not contain a model from this model's modelGroup
94+
for (int j = 0; j < modelGroup.modelsCheckedOut.Count; j++) {
95+
IHandModel modelToCompare = modelGroup.modelsCheckedOut[j];
96+
for (int k = 0; k < rep.handModels.Count; k++) {
97+
if (rep.handModels[k] == modelToCompare) {
98+
modelFromGroupFound = true;
99+
}
100+
}
101+
}
102+
}
103+
if (!modelFromGroupFound) {
104+
rep.AddModel(model);
105+
modelToHandRepMapping[model] = rep;
106+
return;
107+
}
108+
}
109+
}
110+
//Otherwise return to pool
111+
modelGroup.ReturnToGroup(model);
92112
}
93-
public void RemoveHandRepresentation(HandRepresentation handRep) {
113+
public void RemoveHandRepresentation(HandProxy handRep) {
94114
activeHandReps.Remove(handRep);
95115
}
96116
/** Popuates the ModelPool with the contents of the ModelCollection */
@@ -104,8 +124,7 @@ void Start() {
104124
GameObject spawnedGO = GameObject.Instantiate(modelToSpawn.gameObject);
105125
leftModel = spawnedGO.GetComponent<IHandModel>();
106126
leftModel.transform.parent = transform;
107-
}
108-
else {
127+
} else {
109128
leftModel = collectionGroup.LeftModel;
110129
}
111130
collectionGroup.modelList.Add(leftModel);
@@ -116,8 +135,7 @@ void Start() {
116135
GameObject spawnedGO = GameObject.Instantiate(modelToSpawn.gameObject);
117136
rightModel = spawnedGO.GetComponent<IHandModel>();
118137
rightModel.transform.parent = transform;
119-
}
120-
else {
138+
} else {
121139
rightModel = collectionGroup.RightModel;
122140
}
123141
collectionGroup.modelList.Add(rightModel);
@@ -126,29 +144,31 @@ void Start() {
126144
}
127145

128146
/**
129-
* MakeHandRepresentation receives a Hand and combines that with an IHandModel to create a HandRepresentation
147+
* MakeHandRepresentation receives a Hand and combines that with an IHandModel to create a HandProxy
130148
* @param hand The Leap Hand data to be drive an IHandModel
131149
* @param modelType Filters for a type of hand model, for example, physics or graphics hands.
132150
*/
133151

134152
public override HandRepresentation MakeHandRepresentation(Hand hand, ModelType modelType) {
135153
Chirality handChirality = hand.IsRight ? Chirality.Right : Chirality.Left;
136-
HandRepresentation handRep = new HandProxy(this, hand, handChirality, modelType);
154+
HandProxy handRep = new HandProxy(this, hand, handChirality, modelType);
137155
for (int i = 0; i < ModelPool.Count; i++) {
138156
ModelGroup group = ModelPool[i];
139157
if (group.IsEnabled) {
140158
IHandModel model = group.TryGetModel(handChirality, modelType);
141-
if (model != null) {
159+
if (model != null ) {
142160
handRep.AddModel(model);
143-
modelToHandRepMapping.Add(model, handRep);
161+
if (!modelToHandRepMapping.ContainsKey(model)) {
162+
modelToHandRepMapping.Add(model, handRep);
163+
}
144164
}
145165
}
146166
}
147167
activeHandReps.Add(handRep);
148168
return handRep;
149169
}
150170
/**
151-
* EnableGroup finds suitable HandRepresentations and adds IHandModels from the ModelGroup, returns them to their ModelGroup and sets the groups IsEnabled to true.
171+
* EnableGroup finds suitable HandProxys and adds IHandModels from the ModelGroup, returns them to their ModelGroup and sets the groups IsEnabled to true.
152172
* @param groupName Takes a string that matches the ModelGroup's groupName serialized in the Inspector
153173
*/
154174
public void EnableGroup(string groupName) {
@@ -161,7 +181,7 @@ private IEnumerator enableGroup(string groupName) {
161181
if (ModelPool[i].GroupName == groupName) {
162182
group = ModelPool[i];
163183
for (int hp = 0; hp < activeHandReps.Count; hp++) {
164-
HandRepresentation handRep = activeHandReps[hp];
184+
HandProxy handRep = activeHandReps[hp];
165185
IHandModel model = group.TryGetModel(handRep.RepChirality, handRep.RepType);
166186
if (model != null) {
167187
handRep.AddModel(model);
@@ -176,7 +196,7 @@ private IEnumerator enableGroup(string groupName) {
176196
}
177197
}
178198
/**
179-
* DisableGroup finds and removes the ModelGroup's IHandModels from their HandRepresentations, returns them to their ModelGroup and sets the groups IsEnabled to false.
199+
* DisableGroup finds and removes the ModelGroup's IHandModels from their HandProxys, returns them to their ModelGroup and sets the groups IsEnabled to false.
180200
* @param groupName Takes a string that matches the ModelGroup's groupName serialized in the Inspector
181201
*/
182202
public void DisableGroup(string groupName) {
@@ -190,7 +210,7 @@ private IEnumerator disableGroup(string groupName) {
190210
group = ModelPool[i];
191211
for (int m = 0; m < group.modelsCheckedOut.Count; m++) {
192212
IHandModel model = group.modelsCheckedOut[m];
193-
HandRepresentation handRep;
213+
HandProxy handRep;
194214
if (modelToHandRepMapping.TryGetValue(model, out handRep)) {
195215
handRep.RemoveModel(model);
196216
group.ReturnToGroup(model);
@@ -215,13 +235,11 @@ private IEnumerator toggleGroup(string groupName) {
215235
if (modelGroup.IsEnabled == true) {
216236
DisableGroup(groupName);
217237
modelGroup.IsEnabled = false;
218-
}
219-
else {
238+
} else {
220239
EnableGroup(groupName);
221240
modelGroup.IsEnabled = true;
222241
}
223-
}
224-
else Debug.LogWarning("A group matching that name does not exisit in the modelPool");
242+
} else Debug.LogWarning("A group matching that name does not exisit in the modelPool");
225243
}
226244
public void AddNewGroup(string groupName, IHandModel leftModel, IHandModel rightModel) {
227245
ModelGroup newGroup = new ModelGroup();
@@ -247,15 +265,24 @@ void OnValidate() {
247265
for (int i = 0; i < ModelPool.Count; i++) {
248266
if (ModelPool[i] != null) {
249267
if (ModelPool[i].LeftModel) {
250-
ModelPool[i].IsLeftToBeSpawned = PrefabUtility.GetPrefabType(ModelPool[i].LeftModel) == PrefabType.Prefab;
268+
ModelPool[i].IsLeftToBeSpawned = shouldBeSpawned(ModelPool[i].LeftModel);
251269
}
252270
if (ModelPool[i].RightModel) {
253-
ModelPool[i].IsRightToBeSpawned = PrefabUtility.GetPrefabType(ModelPool[i].RightModel) == PrefabType.Prefab;
271+
ModelPool[i].IsRightToBeSpawned = shouldBeSpawned(ModelPool[i].RightModel);
254272
}
255273
}
256274
}
257275
}
258276

277+
private bool shouldBeSpawned(Object model) {
278+
var prefabType = PrefabUtility.GetPrefabType(model);
279+
if (PrefabUtility.GetPrefabType(this) != PrefabType.Prefab) {
280+
return prefabType == PrefabType.Prefab;
281+
} else {
282+
return PrefabUtility.GetPrefabObject(model) != PrefabUtility.GetPrefabObject(this);
283+
}
284+
}
285+
259286
#endif
260287
}
261288
}

0 commit comments

Comments
 (0)