Skip to content

Commit b708c12

Browse files
committed
WIP - Use Input Profiles
1 parent f8fef74 commit b708c12

File tree

16 files changed

+517
-13
lines changed

16 files changed

+517
-13
lines changed

MainProject/Assets/WebXR/Samples/ShaderVariants.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!200 &20000000
4+
ShaderVariantCollection:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_Name: GLTFShaderVariants
10+
m_Shaders:
11+
- first: {fileID: 4800000, guid: 99fa998bbbed3408aafa652b466d261d, type: 3}
12+
second:
13+
variants:
14+
- keywords: BILLBOARD_FACE_CAMERA_POS DIRECTIONAL LIGHTPROBE_SH SHADOWS_SCREEN
15+
SHADOWS_SOFT SHADOWS_SPLIT_SPHERES SOFTPARTICLES_ON UNITY_HDR_ON _METALLICGLOSSMAP
16+
passType: 4
17+
- keywords:
18+
passType: 8
19+
- keywords: _METALLICGLOSSMAP
20+
passType: 8
21+
- keywords: SHADOWS_DEPTH _METALLICGLOSSMAP
22+
passType: 8

MainProject/Assets/WebXR/Samples/ShaderVariants/GLTFShaderVariants.shadervariants.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MainProject/ProjectSettings/GraphicsSettings.asset

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ GraphicsSettings:
3838
- {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
3939
- {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0}
4040
- {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0}
41-
m_PreloadedShaders: []
41+
m_PreloadedShaders:
42+
- {fileID: 20000000, guid: 14ec05db04ad028438150751d08d01df, type: 2}
4243
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
4344
type: 0}
4445
m_CustomRenderPipeline: {fileID: 0}

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

Lines changed: 147 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using UnityEngine;
22
using System.Collections.Generic;
3+
#if WEBXR_INPUT_PROFILES
4+
using WebXRInputProfile;
5+
#endif
36

47
namespace WebXR.Interactions
58
{
@@ -16,12 +19,45 @@ public class ControllerInteraction : MonoBehaviour
1619

1720
public Transform handJointPrefab;
1821

22+
public GameObject inputProfileObject;
23+
public GameObject inputProfileModelParent;
24+
1925
private GameObject[] handJointsVisuals = new GameObject[25];
2026
private Dictionary<int, Transform> handJoints = new Dictionary<int, Transform>();
2127

28+
#if WEBXR_INPUT_PROFILES
29+
private InputProfileLoader inputProfileLoader;
30+
private InputProfileModel inputProfileModel;
31+
private bool hasProfileList = false;
32+
private bool loadedModel = false;
33+
private string loadedProfile = null;
34+
#endif
35+
2236
void Awake()
2337
{
2438
attachJoint = GetComponent<FixedJoint>();
39+
anim = gameObject.GetComponent<Animator>();
40+
controller = gameObject.GetComponent<WebXRController>();
41+
#if WEBXR_INPUT_PROFILES
42+
Debug.LogError("WEBXR_INPUT_PROFILES");
43+
if (inputProfileObject != null)
44+
{
45+
inputProfileLoader = inputProfileObject.GetComponent<InputProfileLoader>();
46+
if (inputProfileLoader == null)
47+
{
48+
inputProfileLoader = inputProfileObject.AddComponent<InputProfileLoader>();
49+
}
50+
if (InputProfileLoader.ProfilesPaths == null || InputProfileLoader.ProfilesPaths.Count == 0)
51+
{
52+
53+
inputProfileLoader.LoadProfilesList(HandleProfilesList);
54+
}
55+
else
56+
{
57+
HandleProfilesList(InputProfileLoader.ProfilesPaths);
58+
}
59+
}
60+
#endif
2561
}
2662

2763
void OnEnable()
@@ -38,12 +74,6 @@ void OnDisabled()
3874
controller.OnHandUpdate -= OnHandUpdate;
3975
}
4076

41-
void Start()
42-
{
43-
anim = gameObject.GetComponent<Animator>();
44-
controller = gameObject.GetComponent<WebXRController>();
45-
}
46-
4777
void Update()
4878
{
4979
controller.TryUpdateButtons();
@@ -67,6 +97,14 @@ void Update()
6797
Drop();
6898
}
6999

100+
#if WEBXR_INPUT_PROFILES
101+
if (loadedModel)
102+
{
103+
UpdateModelInput();
104+
return;
105+
}
106+
#endif
107+
70108
// Use the controller button or axis position to manipulate the playback time for hand model.
71109
anim.Play("Take", -1, normalizedTime);
72110
}
@@ -90,6 +128,23 @@ void OnTriggerExit(Collider other)
90128

91129
void SetControllerVisible(bool visible)
92130
{
131+
#if WEBXR_INPUT_PROFILES
132+
loadedModel = false;
133+
if (visible)
134+
{
135+
inputProfileModelParent.SetActive(true);
136+
if (inputProfileModel != null)
137+
{
138+
loadedModel = true;
139+
return;
140+
}
141+
LoadInputProfile();
142+
}
143+
else
144+
{
145+
inputProfileModelParent.SetActive(false);
146+
}
147+
#endif
93148
foreach (var visual in controllerVisuals)
94149
{
95150
visual.SetActive(visible);
@@ -138,6 +193,92 @@ private void OnHandUpdate(WebXRHandData handData)
138193
}
139194
}
140195

196+
#if WEBXR_INPUT_PROFILES
197+
void HandleProfilesList(Dictionary<string, string> profilesList)
198+
{
199+
if (profilesList == null || profilesList.Count == 0)
200+
{
201+
return;
202+
}
203+
hasProfileList = true;
204+
}
205+
206+
void LoadInputProfile()
207+
{
208+
var profiles = controller.GetProfiles();
209+
Debug.LogError($"LoadInputProfile {hasProfileList} {profiles != null}");
210+
if (hasProfileList && profiles != null && profiles.Length > 0)
211+
{
212+
for (int i = 0; i < profiles.Length; i++)
213+
{
214+
Debug.LogError(profiles[i]);
215+
}
216+
loadedProfile = profiles[0];
217+
inputProfileLoader.LoadProfile(profiles, OnProfileLoaded);
218+
}
219+
}
220+
221+
private void OnProfileLoaded(bool success)
222+
{
223+
if (success)
224+
{
225+
LoadInputModel();
226+
}
227+
}
228+
229+
void LoadInputModel()
230+
{
231+
inputProfileModel = inputProfileLoader.LoadModelForHand(loadedProfile, (InputProfileLoader.Handedness)controller.hand, HandleModelLoaded);
232+
if (inputProfileModel != null)
233+
{
234+
var inputProfileModelTransform = inputProfileModel.transform;
235+
inputProfileModelTransform.SetParent(inputProfileModelParent.transform);
236+
inputProfileModelTransform.localPosition = Vector3.zero;
237+
inputProfileModelTransform.rotation = Quaternion.identity;
238+
inputProfileModelTransform.localScale = Vector3.one;
239+
UpdateModelInput();
240+
}
241+
}
242+
243+
void HandleModelLoaded(bool success)
244+
{
245+
loadedModel = success;
246+
if (loadedModel)
247+
{
248+
foreach (var visual in controllerVisuals)
249+
{
250+
visual.SetActive(false);
251+
}
252+
}
253+
else
254+
{
255+
Destroy(inputProfileModel.gameObject);
256+
}
257+
}
258+
259+
void UpdateModelInput()
260+
{
261+
for (int i = 0; i < 6; i++)
262+
{
263+
SetButtonValue(i);
264+
}
265+
for (int i = 0; i < 4; i++)
266+
{
267+
SetAxisValue(i);
268+
}
269+
}
270+
271+
void SetButtonValue(int index)
272+
{
273+
inputProfileModel.SetButtonValue(index, controller.GetButtonIndexValue(index));
274+
}
275+
276+
public void SetAxisValue(int index)
277+
{
278+
inputProfileModel.SetAxisValue(index, controller.GetAxisIndexValue(index));
279+
}
280+
#endif
281+
141282
public void Pickup()
142283
{
143284
currentRigidBody = GetNearestRigidBody();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"name": "WebXR.Samples.Scripts",
33
"references": [
4-
"GUID:fd4abe4ffe74ef1448afe15c6cb36bb7"
4+
"GUID:fd4abe4ffe74ef1448afe15c6cb36bb7",
5+
"GUID:84a2d09f0bb073f40922f5ea5362abe7"
56
],
67
"includePlatforms": [],
78
"excludePlatforms": [],
@@ -13,7 +14,7 @@
1314
"versionDefines": [
1415
{
1516
"name": "com.de-panther.webxr-input-profiles-loader",
16-
"expression": "0.2.0",
17+
"expression": "[0.2.0]",
1718
"define": "WEBXR_INPUT_PROFILES"
1819
}
1920
],

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,7 @@ Transform:
12951295
m_Children:
12961296
- {fileID: 4603535410349480}
12971297
- {fileID: 4925627231713262}
1298+
- {fileID: 1218315907877956796}
12981299
m_Father: {fileID: 4545079059221816}
12991300
m_RootOrder: 0
13001301
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -1393,6 +1394,8 @@ MonoBehaviour:
13931394
- {fileID: 1664295426898042}
13941395
handJointPrefab: {fileID: 8513787482403080262, guid: 67541c9d1fd5e2c4798986ee73c07923,
13951396
type: 3}
1397+
inputProfileObject: {fileID: 1611361787474004}
1398+
inputProfileModelParent: {fileID: 1469228564561163144}
13961399
--- !u!114 &7185579886917944061
13971400
MonoBehaviour:
13981401
m_ObjectHideFlags: 0
@@ -1785,6 +1788,7 @@ Transform:
17851788
m_Children:
17861789
- {fileID: 4817586320957540}
17871790
- {fileID: 4974700127051642}
1791+
- {fileID: 3819867499605581648}
17881792
m_Father: {fileID: 4545079059221816}
17891793
m_RootOrder: 1
17901794
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -1883,6 +1887,8 @@ MonoBehaviour:
18831887
- {fileID: 1091283458777958}
18841888
handJointPrefab: {fileID: 8513787482403080262, guid: 67541c9d1fd5e2c4798986ee73c07923,
18851889
type: 3}
1890+
inputProfileObject: {fileID: 1611361787474004}
1891+
inputProfileModelParent: {fileID: 599836867309221058}
18861892
--- !u!114 &1966769163579045322
18871893
MonoBehaviour:
18881894
m_ObjectHideFlags: 0
@@ -1901,6 +1907,66 @@ MonoBehaviour:
19011907
m_TrackingType: 0
19021908
m_UpdateType: 0
19031909
m_UseRelativeTransform: 0
1910+
--- !u!1 &599836867309221058
1911+
GameObject:
1912+
m_ObjectHideFlags: 0
1913+
m_CorrespondingSourceObject: {fileID: 0}
1914+
m_PrefabInstance: {fileID: 0}
1915+
m_PrefabAsset: {fileID: 0}
1916+
serializedVersion: 6
1917+
m_Component:
1918+
- component: {fileID: 3819867499605581648}
1919+
m_Layer: 0
1920+
m_Name: InputModel
1921+
m_TagString: Untagged
1922+
m_Icon: {fileID: 0}
1923+
m_NavMeshLayer: 0
1924+
m_StaticEditorFlags: 0
1925+
m_IsActive: 1
1926+
--- !u!4 &3819867499605581648
1927+
Transform:
1928+
m_ObjectHideFlags: 0
1929+
m_CorrespondingSourceObject: {fileID: 0}
1930+
m_PrefabInstance: {fileID: 0}
1931+
m_PrefabAsset: {fileID: 0}
1932+
m_GameObject: {fileID: 599836867309221058}
1933+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
1934+
m_LocalPosition: {x: 0, y: 0, z: 0}
1935+
m_LocalScale: {x: 1, y: 1, z: 1}
1936+
m_Children: []
1937+
m_Father: {fileID: 4446684710817404}
1938+
m_RootOrder: 2
1939+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
1940+
--- !u!1 &1469228564561163144
1941+
GameObject:
1942+
m_ObjectHideFlags: 0
1943+
m_CorrespondingSourceObject: {fileID: 0}
1944+
m_PrefabInstance: {fileID: 0}
1945+
m_PrefabAsset: {fileID: 0}
1946+
serializedVersion: 6
1947+
m_Component:
1948+
- component: {fileID: 1218315907877956796}
1949+
m_Layer: 0
1950+
m_Name: InputModel
1951+
m_TagString: Untagged
1952+
m_Icon: {fileID: 0}
1953+
m_NavMeshLayer: 0
1954+
m_StaticEditorFlags: 0
1955+
m_IsActive: 1
1956+
--- !u!4 &1218315907877956796
1957+
Transform:
1958+
m_ObjectHideFlags: 0
1959+
m_CorrespondingSourceObject: {fileID: 0}
1960+
m_PrefabInstance: {fileID: 0}
1961+
m_PrefabAsset: {fileID: 0}
1962+
m_GameObject: {fileID: 1469228564561163144}
1963+
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
1964+
m_LocalPosition: {x: 0, y: 0, z: 0}
1965+
m_LocalScale: {x: 1, y: 1, z: 1}
1966+
m_Children: []
1967+
m_Father: {fileID: 4427160273819458}
1968+
m_RootOrder: 2
1969+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
19041970
--- !u!1 &3250837035476248814
19051971
GameObject:
19061972
m_ObjectHideFlags: 0

0 commit comments

Comments
 (0)