Skip to content

Commit f8fef74

Browse files
committed
WIP - Input Profiles Support:
Added com.de-panther.webxr-input-profiles-loader package to demo project. Updated WebXRController and ControllerInteraction to be more flexible.
1 parent 16ec8fa commit f8fef74

File tree

7 files changed

+177
-107
lines changed

7 files changed

+177
-107
lines changed

MainProject/Packages/manifest.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
{
2+
"scopedRegistries": [
3+
{
4+
"name": "OpenUPM",
5+
"url": "https://package.openupm.com",
6+
"scopes": [
7+
"com.de-panther",
8+
"com.atteneder"
9+
]
10+
}
11+
],
212
"dependencies": {
13+
"com.de-panther.webxr-input-profiles-loader": "0.2.0",
314
"com.unity.ide.rider": "2.0.5",
415
"com.unity.ide.vscode": "1.2.3",
516
"com.unity.test-framework": "1.1.16",

MainProject/Packages/packages-lock.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
{
22
"dependencies": {
3+
"com.atteneder.gltfast": {
4+
"version": "2.2.0",
5+
"depth": 1,
6+
"source": "registry",
7+
"dependencies": {
8+
"com.unity.mathematics": "1.2.1"
9+
},
10+
"url": "https://package.openupm.com"
11+
},
312
"com.de-panther.webxr": {
413
"version": "file:webxr",
514
"depth": 0,
@@ -8,6 +17,16 @@
817
"com.unity.xr.management": "3.2.13"
918
}
1019
},
20+
"com.de-panther.webxr-input-profiles-loader": {
21+
"version": "0.2.0",
22+
"depth": 0,
23+
"source": "registry",
24+
"dependencies": {
25+
"com.unity.nuget.newtonsoft-json": "2.0.0",
26+
"com.atteneder.gltfast": "2.2.0"
27+
},
28+
"url": "https://package.openupm.com"
29+
},
1130
"com.de-panther.webxr-interactions": {
1231
"version": "file:webxr-interactions",
1332
"depth": 0,
@@ -39,6 +58,20 @@
3958
"dependencies": {},
4059
"url": "https://packages.unity.com"
4160
},
61+
"com.unity.mathematics": {
62+
"version": "1.2.1",
63+
"depth": 2,
64+
"source": "registry",
65+
"dependencies": {},
66+
"url": "https://packages.unity.com"
67+
},
68+
"com.unity.nuget.newtonsoft-json": {
69+
"version": "2.0.0",
70+
"depth": 1,
71+
"source": "registry",
72+
"dependencies": {},
73+
"url": "https://packages.unity.com"
74+
},
4275
"com.unity.subsystemregistration": {
4376
"version": "1.0.6",
4477
"depth": 1,

Packages/webxr-interactions/Runtime/Prefabs/WebXRCameraSet.prefab

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -977,9 +977,6 @@ MonoBehaviour:
977977
m_Script: {fileID: 11500000, guid: 519f6ee6510174b44bbe9a8a2d3b6a6a, type: 3}
978978
m_Name:
979979
m_EditorClassIdentifier:
980-
dontDestroyOnLoad: 1
981-
DefaultHeight: 1.2
982-
xrState: 2
983980
--- !u!1 &1644691530447244
984981
GameObject:
985982
m_ObjectHideFlags: 0
@@ -1375,15 +1372,9 @@ MonoBehaviour:
13751372
m_Name:
13761373
m_EditorClassIdentifier:
13771374
hand: 1
1378-
inputMap: {fileID: 11400000, guid: f2b0e62590098b246823680b10d75b46, type: 2}
13791375
simulate3dof: 0
13801376
eyesToElbow: {x: 0.1, y: -0.4, z: 0.15}
13811377
elbowHand: {x: 0, y: 0, z: 0.25}
1382-
handJointPrefab: {fileID: 8513787482403080262, guid: 67541c9d1fd5e2c4798986ee73c07923,
1383-
type: 3}
1384-
showGOs:
1385-
- {fileID: 1136128897566686}
1386-
- {fileID: 1664295426898042}
13871378
--- !u!114 &114589835210473740
13881379
MonoBehaviour:
13891380
m_ObjectHideFlags: 0
@@ -1396,6 +1387,11 @@ MonoBehaviour:
13961387
m_Script: {fileID: 11500000, guid: 580e3dd931df2bd42b042a7e8fde2aa8, type: 3}
13971388
m_Name:
13981389
m_EditorClassIdentifier:
1390+
controllerVisuals:
1391+
- {fileID: 1136128897566686}
1392+
- {fileID: 1664295426898042}
1393+
handJointPrefab: {fileID: 8513787482403080262, guid: 67541c9d1fd5e2c4798986ee73c07923,
1394+
type: 3}
13991395
--- !u!1 &1836701339249518
14001396
GameObject:
14011397
m_ObjectHideFlags: 0
@@ -1828,15 +1824,9 @@ MonoBehaviour:
18281824
m_Name:
18291825
m_EditorClassIdentifier:
18301826
hand: 2
1831-
inputMap: {fileID: 11400000, guid: a37529c06e00da94091bc81a0193c815, type: 2}
18321827
simulate3dof: 0
18331828
eyesToElbow: {x: 0.1, y: -0.4, z: 0.15}
18341829
elbowHand: {x: 0, y: 0, z: 0.25}
1835-
handJointPrefab: {fileID: 8513787482403080262, guid: 67541c9d1fd5e2c4798986ee73c07923,
1836-
type: 3}
1837-
showGOs:
1838-
- {fileID: 1644997114004198}
1839-
- {fileID: 1091283458777958}
18401830
--- !u!114 &114372649503696970
18411831
MonoBehaviour:
18421832
m_ObjectHideFlags: 0
@@ -1849,6 +1839,11 @@ MonoBehaviour:
18491839
m_Script: {fileID: 11500000, guid: 580e3dd931df2bd42b042a7e8fde2aa8, type: 3}
18501840
m_Name:
18511841
m_EditorClassIdentifier:
1842+
controllerVisuals:
1843+
- {fileID: 1644997114004198}
1844+
- {fileID: 1091283458777958}
1845+
handJointPrefab: {fileID: 8513787482403080262, guid: 67541c9d1fd5e2c4798986ee73c07923,
1846+
type: 3}
18521847
--- !u!1 &3250837035476248814
18531848
GameObject:
18541849
m_ObjectHideFlags: 0

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,32 @@ public class ControllerInteraction : MonoBehaviour
1212
private Animator anim;
1313
private WebXRController controller;
1414

15+
public GameObject[] controllerVisuals;
16+
17+
public Transform handJointPrefab;
18+
19+
private GameObject[] handJointsVisuals = new GameObject[25];
20+
private Dictionary<int, Transform> handJoints = new Dictionary<int, Transform>();
21+
1522
void Awake()
1623
{
1724
attachJoint = GetComponent<FixedJoint>();
1825
}
1926

27+
void OnEnable()
28+
{
29+
controller.OnControllerActive += SetControllerVisible;
30+
controller.OnHandActive += SetHandJointsVisible;
31+
controller.OnHandUpdate += OnHandUpdate;
32+
}
33+
34+
void OnDisabled()
35+
{
36+
controller.OnControllerActive -= SetControllerVisible;
37+
controller.OnHandActive -= SetHandJointsVisible;
38+
controller.OnHandUpdate -= OnHandUpdate;
39+
}
40+
2041
void Start()
2142
{
2243
anim = gameObject.GetComponent<Animator>();
@@ -67,6 +88,56 @@ void OnTriggerExit(Collider other)
6788
contactRigidBodies.Remove(other.gameObject.GetComponent<Rigidbody>());
6889
}
6990

91+
void SetControllerVisible(bool visible)
92+
{
93+
foreach (var visual in controllerVisuals)
94+
{
95+
visual.SetActive(visible);
96+
}
97+
}
98+
99+
void SetHandJointsVisible(bool visible)
100+
{
101+
foreach (var visual in handJointsVisuals)
102+
{
103+
visual?.SetActive(visible);
104+
}
105+
}
106+
107+
private void OnHandUpdate(WebXRHandData handData)
108+
{
109+
Quaternion rotationOffset = Quaternion.Inverse(handData.joints[0].rotation);
110+
111+
for (int i = 0; i <= WebXRHandData.LITTLE_PHALANX_TIP; i++)
112+
{
113+
if (handData.joints[i].enabled)
114+
{
115+
if (handJoints.ContainsKey(i))
116+
{
117+
handJoints[i].localPosition = rotationOffset * (handData.joints[i].position - handData.joints[0].position);
118+
handJoints[i].localRotation = rotationOffset * handData.joints[i].rotation;
119+
}
120+
else
121+
{
122+
var clone = Instantiate(handJointPrefab,
123+
rotationOffset * (handData.joints[i].position - handData.joints[0].position),
124+
rotationOffset * handData.joints[i].rotation,
125+
transform);
126+
if (handData.joints[i].radius > 0f)
127+
{
128+
clone.localScale = new Vector3(handData.joints[i].radius, handData.joints[i].radius, handData.joints[i].radius);
129+
}
130+
else
131+
{
132+
clone.localScale = new Vector3(0.005f, 0.005f, 0.005f);
133+
}
134+
handJoints.Add(i, clone);
135+
handJointsVisuals[i] = clone.gameObject;
136+
}
137+
}
138+
}
139+
}
140+
70141
public void Pickup()
71142
{
72143
currentRigidBody = GetNearestRigidBody();

Packages/webxr-interactions/Runtime/Scripts/WebXR.Interactions.asmdef

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
"precompiledReferences": [],
1111
"autoReferenced": false,
1212
"defineConstraints": [],
13-
"versionDefines": [],
13+
"versionDefines": [
14+
{
15+
"name": "com.de-panther.webxr-input-profiles-loader",
16+
"expression": "0.2.0",
17+
"define": "WEBXR_INPUT_PROFILES"
18+
}
19+
],
1420
"noEngineReferences": false
1521
}

Packages/webxr-interactions/Samples~/Desert/Prefabs/WebXRCameraSet.prefab

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,11 +1376,6 @@ MonoBehaviour:
13761376
simulate3dof: 0
13771377
eyesToElbow: {x: 0.1, y: -0.4, z: 0.15}
13781378
elbowHand: {x: 0, y: 0, z: 0.25}
1379-
handJointPrefab: {fileID: 8513787482403080262, guid: 67541c9d1fd5e2c4798986ee73c07923,
1380-
type: 3}
1381-
showGOs:
1382-
- {fileID: 1136128897566686}
1383-
- {fileID: 1664295426898042}
13841379
--- !u!114 &114589835210473740
13851380
MonoBehaviour:
13861381
m_ObjectHideFlags: 0
@@ -1393,6 +1388,11 @@ MonoBehaviour:
13931388
m_Script: {fileID: 11500000, guid: 580e3dd931df2bd42b042a7e8fde2aa8, type: 3}
13941389
m_Name:
13951390
m_EditorClassIdentifier:
1391+
controllerVisuals:
1392+
- {fileID: 1136128897566686}
1393+
- {fileID: 1664295426898042}
1394+
handJointPrefab: {fileID: 8513787482403080262, guid: 67541c9d1fd5e2c4798986ee73c07923,
1395+
type: 3}
13961396
--- !u!114 &7185579886917944061
13971397
MonoBehaviour:
13981398
m_ObjectHideFlags: 0
@@ -1866,11 +1866,6 @@ MonoBehaviour:
18661866
simulate3dof: 0
18671867
eyesToElbow: {x: 0.1, y: -0.4, z: 0.15}
18681868
elbowHand: {x: 0, y: 0, z: 0.25}
1869-
handJointPrefab: {fileID: 8513787482403080262, guid: 67541c9d1fd5e2c4798986ee73c07923,
1870-
type: 3}
1871-
showGOs:
1872-
- {fileID: 1644997114004198}
1873-
- {fileID: 1091283458777958}
18741869
--- !u!114 &114372649503696970
18751870
MonoBehaviour:
18761871
m_ObjectHideFlags: 0
@@ -1883,6 +1878,11 @@ MonoBehaviour:
18831878
m_Script: {fileID: 11500000, guid: 580e3dd931df2bd42b042a7e8fde2aa8, type: 3}
18841879
m_Name:
18851880
m_EditorClassIdentifier:
1881+
controllerVisuals:
1882+
- {fileID: 1644997114004198}
1883+
- {fileID: 1091283458777958}
1884+
handJointPrefab: {fileID: 8513787482403080262, guid: 67541c9d1fd5e2c4798986ee73c07923,
1885+
type: 3}
18861886
--- !u!114 &1966769163579045322
18871887
MonoBehaviour:
18881888
m_ObjectHideFlags: 0

0 commit comments

Comments
 (0)