Skip to content

Commit 95f8d3c

Browse files
authored
Merge pull request #322 from De-Panther/optimizations_xri_demo
Optimizations for XR Interaction Toolkit demo
2 parents 12d7fb5 + 5ef4c19 commit 95f8d3c

35 files changed

+3429
-32
lines changed

Packages/webxr-interactions/Runtime/InputSystem/WebXRControllerModel.cs

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ public UpdateType updateType
169169
bool m_RotationBound;
170170
bool m_PositionBound;
171171
bool m_TrackingStateBound;
172-
private bool visualActionsInit;
172+
private bool visualActionsBound;
173+
private bool visualActionsUpdated;
173174
bool m_IsFirstUpdate = true;
174175

175176
private Transform xrControllerOldModel;
@@ -180,14 +181,15 @@ void BindActions()
180181
BindPosition();
181182
BindRotation();
182183
BindTrackingState();
183-
InitVisualActions();
184+
BindVisualActions();
184185
}
185186

186187
void UnbindActions()
187188
{
188189
UnbindPosition();
189190
UnbindRotation();
190191
UnbindTrackingState();
192+
UnbindVisualActions();
191193
}
192194

193195
void BindPosition()
@@ -232,9 +234,9 @@ void BindTrackingState()
232234
m_TrackingStateBound = true;
233235
}
234236

235-
void InitVisualActions()
237+
void BindVisualActions()
236238
{
237-
if (visualActionsInit)
239+
if (visualActionsBound)
238240
return;
239241

240242
buttonActions = new InputAction[6];
@@ -248,7 +250,18 @@ void InitVisualActions()
248250
axisActions[0] = touchpadActionProperty.action;
249251
axisActions[1] = thumbstickActionProperty.action;
250252

251-
visualActionsInit = true;
253+
for (int i = 0; i < buttonActions.Length; i++)
254+
{
255+
buttonActions[i].performed += OnVisualActionsPerformed;
256+
buttonActions[i].canceled += OnVisualActionsCanceled;
257+
}
258+
for (int i = 0; i < axisActions.Length; i++)
259+
{
260+
axisActions[i].performed += OnVisualActionsPerformed;
261+
axisActions[i].canceled += OnVisualActionsCanceled;
262+
}
263+
264+
visualActionsBound = true;
252265
}
253266

254267
void UnbindPosition()
@@ -290,6 +303,25 @@ void UnbindTrackingState()
290303
m_TrackingStateBound = false;
291304
}
292305

306+
void UnbindVisualActions()
307+
{
308+
if (!visualActionsBound)
309+
return;
310+
311+
for (int i = 0; i < buttonActions.Length; i++)
312+
{
313+
buttonActions[i].performed -= OnVisualActionsPerformed;
314+
buttonActions[i].canceled -= OnVisualActionsCanceled;
315+
}
316+
for (int i = 0; i < axisActions.Length; i++)
317+
{
318+
axisActions[i].performed -= OnVisualActionsPerformed;
319+
axisActions[i].canceled -= OnVisualActionsCanceled;
320+
}
321+
322+
visualActionsBound = false;
323+
}
324+
293325
void OnPositionPerformed(InputAction.CallbackContext context)
294326
{
295327
m_CurrentPosition = context.ReadValue<Vector3>();
@@ -328,6 +360,16 @@ void OnTrackingStateCanceled(InputAction.CallbackContext context)
328360
}
329361
}
330362

363+
void OnVisualActionsPerformed(InputAction.CallbackContext context)
364+
{
365+
visualActionsUpdated = true;
366+
}
367+
368+
void OnVisualActionsCanceled(InputAction.CallbackContext context)
369+
{
370+
visualActionsUpdated = true;
371+
}
372+
331373
private void Awake()
332374
{
333375
inputProfileLoader = rigOrigin.GetComponent<InputProfileLoader>();
@@ -472,7 +514,7 @@ protected virtual void OnBeforeRender()
472514
protected virtual void PerformUpdate()
473515
{
474516
SetLocalTransform(m_CurrentPosition, m_CurrentRotation);
475-
if (loadedModel && m_CurrentTrackingState != TrackingStates.None)
517+
if (loadedModel && visualActionsUpdated)
476518
{
477519
UpdateModelInput();
478520
}
@@ -513,6 +555,11 @@ protected virtual void SetLocalTransform(Vector3 newPosition, Quaternion newRota
513555

514556
private void UpdateModelInput()
515557
{
558+
if (m_CurrentTrackingState == TrackingStates.None)
559+
{
560+
return;
561+
}
562+
visualActionsUpdated = false;
516563
for (int i = 0; i < 6; i++)
517564
{
518565
inputProfileModel.SetButtonValue(i, buttonActions[i].ReadValue<float>());

Packages/webxr-interactions/Samples~/XRInteractionToolkit/Materials.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: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &-8120562580438748798
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 11
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
13+
m_Name:
14+
m_EditorClassIdentifier:
15+
version: 4
16+
--- !u!21 &2100000
17+
Material:
18+
serializedVersion: 8
19+
m_ObjectHideFlags: 0
20+
m_CorrespondingSourceObject: {fileID: 0}
21+
m_PrefabInstance: {fileID: 0}
22+
m_PrefabAsset: {fileID: 0}
23+
m_Name: AccentButton
24+
m_Shader: {fileID: 7, guid: 0000000000000000f000000000000000, type: 0}
25+
m_Parent: {fileID: 0}
26+
m_ModifiedSerializedProperties: 0
27+
m_ValidKeywords: []
28+
m_InvalidKeywords: []
29+
m_LightmapFlags: 4
30+
m_EnableInstancingVariants: 0
31+
m_DoubleSidedGI: 0
32+
m_CustomRenderQueue: -1
33+
stringTagMap: {}
34+
disabledShaderPasses: []
35+
m_LockedProperties:
36+
m_SavedProperties:
37+
serializedVersion: 3
38+
m_TexEnvs:
39+
- _BaseMap:
40+
m_Texture: {fileID: 0}
41+
m_Scale: {x: 1, y: 1}
42+
m_Offset: {x: 0, y: 0}
43+
- _BumpMap:
44+
m_Texture: {fileID: 0}
45+
m_Scale: {x: 1, y: 1}
46+
m_Offset: {x: 0, y: 0}
47+
- _DetailAlbedoMap:
48+
m_Texture: {fileID: 0}
49+
m_Scale: {x: 1, y: 1}
50+
m_Offset: {x: 0, y: 0}
51+
- _DetailMask:
52+
m_Texture: {fileID: 0}
53+
m_Scale: {x: 1, y: 1}
54+
m_Offset: {x: 0, y: 0}
55+
- _DetailNormalMap:
56+
m_Texture: {fileID: 0}
57+
m_Scale: {x: 1, y: 1}
58+
m_Offset: {x: 0, y: 0}
59+
- _EmissionMap:
60+
m_Texture: {fileID: 0}
61+
m_Scale: {x: 1, y: 1}
62+
m_Offset: {x: 0, y: 0}
63+
- _MainTex:
64+
m_Texture: {fileID: 0}
65+
m_Scale: {x: 1, y: 1}
66+
m_Offset: {x: 0, y: 0}
67+
- _MetallicGlossMap:
68+
m_Texture: {fileID: 0}
69+
m_Scale: {x: 1, y: 1}
70+
m_Offset: {x: 0, y: 0}
71+
- _OcclusionMap:
72+
m_Texture: {fileID: 0}
73+
m_Scale: {x: 1, y: 1}
74+
m_Offset: {x: 0, y: 0}
75+
- _ParallaxMap:
76+
m_Texture: {fileID: 0}
77+
m_Scale: {x: 1, y: 1}
78+
m_Offset: {x: 0, y: 0}
79+
- _SpecGlossMap:
80+
m_Texture: {fileID: 0}
81+
m_Scale: {x: 1, y: 1}
82+
m_Offset: {x: 0, y: 0}
83+
- unity_Lightmaps:
84+
m_Texture: {fileID: 0}
85+
m_Scale: {x: 1, y: 1}
86+
m_Offset: {x: 0, y: 0}
87+
- unity_LightmapsInd:
88+
m_Texture: {fileID: 0}
89+
m_Scale: {x: 1, y: 1}
90+
m_Offset: {x: 0, y: 0}
91+
- unity_ShadowMasks:
92+
m_Texture: {fileID: 0}
93+
m_Scale: {x: 1, y: 1}
94+
m_Offset: {x: 0, y: 0}
95+
m_Ints: []
96+
m_Floats:
97+
- _AlphaClip: 0
98+
- _Blend: 0
99+
- _BumpScale: 1
100+
- _ClearCoatMask: 0
101+
- _ClearCoatSmoothness: 0
102+
- _Cull: 2
103+
- _Cutoff: 0.5
104+
- _DetailAlbedoMapScale: 1
105+
- _DetailNormalMapScale: 1
106+
- _DstBlend: 0
107+
- _EnvironmentReflections: 1
108+
- _GlossMapScale: 1
109+
- _Glossiness: 0
110+
- _GlossyReflections: 1
111+
- _Metallic: 0
112+
- _Mode: 0
113+
- _OcclusionStrength: 1
114+
- _Parallax: 0.02
115+
- _QueueOffset: 0
116+
- _ReceiveShadows: 1
117+
- _Smoothness: 0.5
118+
- _SmoothnessTextureChannel: 0
119+
- _SpecularHighlights: 1
120+
- _SrcBlend: 1
121+
- _Surface: 0
122+
- _UVSec: 0
123+
- _WorkflowMode: 1
124+
- _ZWrite: 1
125+
m_Colors:
126+
- _BaseColor: {r: 0.9275999, g: 0.58167726, b: 0.58167726, a: 1}
127+
- _Color: {r: 0.7169812, g: 0.15218942, b: 0.15218942, a: 1}
128+
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
129+
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
130+
m_BuildTextureStacks: []

Packages/webxr-interactions/Samples~/XRInteractionToolkit/Materials/AccentButton.mat.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: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!21 &2100000
4+
Material:
5+
serializedVersion: 6
6+
m_ObjectHideFlags: 0
7+
m_CorrespondingSourceObject: {fileID: 0}
8+
m_PrefabInstance: {fileID: 0}
9+
m_PrefabAsset: {fileID: 0}
10+
m_Name: Blue
11+
m_Shader: {fileID: 7, guid: 0000000000000000f000000000000000, type: 0}
12+
m_ShaderKeywords:
13+
m_LightmapFlags: 4
14+
m_EnableInstancingVariants: 0
15+
m_DoubleSidedGI: 0
16+
m_CustomRenderQueue: -1
17+
stringTagMap: {}
18+
disabledShaderPasses: []
19+
m_SavedProperties:
20+
serializedVersion: 3
21+
m_TexEnvs:
22+
- _BumpMap:
23+
m_Texture: {fileID: 0}
24+
m_Scale: {x: 1, y: 1}
25+
m_Offset: {x: 0, y: 0}
26+
- _DetailAlbedoMap:
27+
m_Texture: {fileID: 0}
28+
m_Scale: {x: 1, y: 1}
29+
m_Offset: {x: 0, y: 0}
30+
- _DetailMask:
31+
m_Texture: {fileID: 0}
32+
m_Scale: {x: 1, y: 1}
33+
m_Offset: {x: 0, y: 0}
34+
- _DetailNormalMap:
35+
m_Texture: {fileID: 0}
36+
m_Scale: {x: 1, y: 1}
37+
m_Offset: {x: 0, y: 0}
38+
- _EmissionMap:
39+
m_Texture: {fileID: 0}
40+
m_Scale: {x: 1, y: 1}
41+
m_Offset: {x: 0, y: 0}
42+
- _MainTex:
43+
m_Texture: {fileID: 0}
44+
m_Scale: {x: 1, y: 1}
45+
m_Offset: {x: 0, y: 0}
46+
- _MetallicGlossMap:
47+
m_Texture: {fileID: 0}
48+
m_Scale: {x: 1, y: 1}
49+
m_Offset: {x: 0, y: 0}
50+
- _OcclusionMap:
51+
m_Texture: {fileID: 0}
52+
m_Scale: {x: 1, y: 1}
53+
m_Offset: {x: 0, y: 0}
54+
- _ParallaxMap:
55+
m_Texture: {fileID: 0}
56+
m_Scale: {x: 1, y: 1}
57+
m_Offset: {x: 0, y: 0}
58+
m_Floats:
59+
- _BumpScale: 1
60+
- _Cutoff: 0.5
61+
- _DetailNormalMapScale: 1
62+
- _DstBlend: 0
63+
- _GlossMapScale: 1
64+
- _Glossiness: 0.5
65+
- _GlossyReflections: 1
66+
- _Metallic: 0
67+
- _Mode: 0
68+
- _OcclusionStrength: 1
69+
- _Parallax: 0.02
70+
- _SmoothnessTextureChannel: 0
71+
- _SpecularHighlights: 1
72+
- _SrcBlend: 1
73+
- _UVSec: 0
74+
- _ZWrite: 1
75+
m_Colors:
76+
- _Color: {r: 0, g: 0.13166761, b: 1, a: 1}
77+
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

Packages/webxr-interactions/Samples~/XRInteractionToolkit/Materials/Blue.mat.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.

0 commit comments

Comments
 (0)