Skip to content

Commit bf475bd

Browse files
authored
Merge pull request #154 from De-Panther/option_use_colliders_for_hand_joints
Added an option to disable/enable useCollidersForHandJoints
2 parents 2f4d736 + f2f2286 commit bf475bd

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

Packages/webxr-interactions/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Added
9+
- An option to disable/enable useCollidersForHandJoints in ControllerInteraction.
810

911
## [0.10.0] - 2021-05-06
1012
### Added

Packages/webxr-interactions/Runtime/Scripts/ControllerInteraction.cs

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class ControllerInteraction : MonoBehaviour
2222

2323
public Transform handJointPrefab;
2424
private bool handJointsVisible = false;
25+
[SerializeField] private bool useCollidersForHandJoints = true;
2526

2627
[SerializeField] private bool useInputProfile = true;
2728

@@ -155,6 +156,37 @@ private void OnTriggerExit(Collider other)
155156
contactRigidBodies.Remove(other.gameObject.GetComponent<Rigidbody>());
156157
}
157158

159+
public void SetUseCollidersForHandJoints(bool value)
160+
{
161+
useCollidersForHandJoints = value;
162+
for (int i = 0; i <= (int)WebXRHandJoint.pinky_finger_tip; i++)
163+
{
164+
if (handJoints.ContainsKey(i))
165+
{
166+
var collider = handJoints[i].GetComponent<Collider>();
167+
if (collider != null)
168+
{
169+
collider.enabled = useCollidersForHandJoints;
170+
}
171+
}
172+
#if WEBXR_INPUT_PROFILES
173+
if (handModelJoints.ContainsKey(i))
174+
{
175+
var collider = handModelJoints[i].GetComponent<Collider>();
176+
if (collider != null)
177+
{
178+
collider.enabled = useCollidersForHandJoints;
179+
}
180+
}
181+
#endif
182+
}
183+
}
184+
185+
public bool GetUseCollidersForHandJoints()
186+
{
187+
return useCollidersForHandJoints;
188+
}
189+
158190
public void SetUseInputProfile(bool value)
159191
{
160192
useInputProfile = value;
@@ -290,6 +322,11 @@ private void OnHandUpdate(WebXRHandData handData)
290322
{
291323
clone.localScale = new Vector3(0.005f, 0.005f, 0.005f);
292324
}
325+
var collider = clone.GetComponent<Collider>();
326+
if (collider != null)
327+
{
328+
collider.enabled = useCollidersForHandJoints;
329+
}
293330
handJoints.Add(i, clone);
294331
handJointsVisuals[i] = clone.gameObject;
295332
}
@@ -413,9 +450,12 @@ private void HandleHandModelLoaded(bool success)
413450
if (handJoints.ContainsKey(i))
414451
{
415452
handModelJoints[i].SetPositionAndRotation(handJoints[i].position, handJoints[i].rotation);
416-
var collider = handModelJoints[i].gameObject.AddComponent<SphereCollider>();
417-
collider.radius = handJoints[i].localScale.x;
418-
collider.isTrigger = true;
453+
if (useCollidersForHandJoints)
454+
{
455+
var collider = handModelJoints[i].gameObject.AddComponent<SphereCollider>();
456+
collider.radius = handJoints[i].localScale.x;
457+
collider.isTrigger = true;
458+
}
419459
}
420460
}
421461
if (handJointsVisible)

0 commit comments

Comments
 (0)