Skip to content

Commit 11a016e

Browse files
authored
Merge pull request #280 from De-Panther/pos_rot_performance
Added the 2021.3 cycle to the SetPositionAndRotation fix
2 parents bc3d2ab + ddeb2ea commit 11a016e

File tree

9 files changed

+48
-21
lines changed

9 files changed

+48
-21
lines changed

Packages/webxr-interactions/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Added
1010
- An option to set pickup buttons in ControllerInteraction.
1111

12+
### Changed
13+
- Improve performance.
14+
1215
### Fixed
1316
- Lighting after threshold test in ChromaKeyUnlit.
1417

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ private void SetControllerVisible(bool visible)
257257

258258
private void SetInputProfileModelPose(bool alwaysUseGrip)
259259
{
260-
#if UNITY_2022_3_OR_NEWER
260+
#if HAS_POSITION_AND_ROTATION
261261
inputProfileModelParent.transform.SetLocalPositionAndRotation(alwaysUseGrip ? Vector3.zero : controller.gripPosition,
262262
alwaysUseGrip ? Quaternion.identity : controller.gripRotation);
263263
#else
@@ -331,7 +331,7 @@ private void OnHandUpdate(WebXRHandData handData)
331331
{
332332
if (handJoints.ContainsKey(i))
333333
{
334-
#if UNITY_2022_3_OR_NEWER
334+
#if HAS_POSITION_AND_ROTATION
335335
handJoints[i].SetLocalPositionAndRotation(rotationOffset * (handData.joints[i].position - handData.joints[0].position), rotationOffset * handData.joints[i].rotation);
336336
#else
337337
handJoints[i].localPosition = rotationOffset * (handData.joints[i].position - handData.joints[0].position);
@@ -345,7 +345,7 @@ private void OnHandUpdate(WebXRHandData handData)
345345
else
346346
{
347347
var clone = Instantiate(handJointPrefab, transform);
348-
#if UNITY_2022_3_OR_NEWER
348+
#if HAS_POSITION_AND_ROTATION
349349
clone.SetLocalPositionAndRotation(rotationOffset * (handData.joints[i].position - handData.joints[0].position), rotationOffset * handData.joints[i].rotation);
350350
#else
351351
clone.localPosition = rotationOffset * (handData.joints[i].position - handData.joints[0].position);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ private void Ended()
278278
webcamParent.gameObject.SetActive(storedWebcamParentActive);
279279
stackCameras.SetActive(false);
280280
ClearRenderTextures();
281-
#if UNITY_2022_3_OR_NEWER
281+
#if HAS_POSITION_AND_ROTATION
282282
spectatorCameraParent.SetPositionAndRotation(storedSpectatorParentPosition, storedSpectatorParentRotation);
283283
spectatorCameraTransform.SetPositionAndRotation(storedSpectatorPosition, storedSpectatorRotation);
284284
#else
@@ -294,7 +294,7 @@ private void Ended()
294294
spectatorCamera.farClipPlane = sotredSpectatorFarClipPlane;
295295
spectatorCamera.orthographic = storedSpectatorOrthographic;
296296
spectatorCamera.orthographicSize = storedSpectatorOrthographicSize;
297-
#if UNITY_2022_3_OR_NEWER
297+
#if HAS_POSITION_AND_ROTATION
298298
webcamParent.SetPositionAndRotation(storedWebcamParentPosition, storedWebcamParentRotation);
299299
#else
300300
webcamParent.position = storedWebcamParentPosition;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void Update()
7777

7878
private void HandleOnXRChange(WebXRState state, int viewsCount, Rect leftRect, Rect rightRect)
7979
{
80-
#if UNITY_2022_3_OR_NEWER
80+
#if HAS_POSITION_AND_ROTATION
8181
WebXRManager.Instance.transform.SetLocalPositionAndRotation(originPosition, originRotation);
8282
#else
8383
WebXRManager.Instance.transform.localPosition = originPosition;
@@ -101,7 +101,7 @@ void HandleOnViewerHitTestUpdate(WebXRHitPoseData hitPoseData)
101101
if (hitPoseData.available)
102102
{
103103
isFollowing = true;
104-
#if UNITY_2022_3_OR_NEWER
104+
#if HAS_POSITION_AND_ROTATION
105105
transform.SetLocalPositionAndRotation(hitPoseData.position, hitPoseData.rotation);
106106
#else
107107
transform.localPosition = hitPoseData.position;
@@ -114,7 +114,7 @@ void HandleOnViewerHitTestUpdate(WebXRHitPoseData hitPoseData)
114114
void FollowByHitRotation(WebXRHitPoseData hitPoseData)
115115
{
116116
Quaternion rotationOffset = Quaternion.Inverse(hitPoseData.rotation);
117-
#if UNITY_2022_3_OR_NEWER
117+
#if HAS_POSITION_AND_ROTATION
118118
WebXRManager.Instance.transform.SetLocalPositionAndRotation(rotationOffset * (originPosition - hitPoseData.position), rotationOffset);
119119
#else
120120
WebXRManager.Instance.transform.localPosition = rotationOffset * (originPosition - hitPoseData.position);
@@ -127,7 +127,7 @@ void FollowByViewRotation(WebXRHitPoseData hitPoseData)
127127
Vector2 diff = new Vector2(hitPoseData.position.x, hitPoseData.position.z) - new Vector2(arCameraTransform.localPosition.x, arCameraTransform.localPosition.z);
128128
float angle = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg - 90f;
129129
Quaternion rotationOffset = Quaternion.Euler(0, angle, 0);
130-
#if UNITY_2022_3_OR_NEWER
130+
#if HAS_POSITION_AND_ROTATION
131131
WebXRManager.Instance.transform.SetLocalPositionAndRotation(rotationOffset * (originPosition - hitPoseData.position), rotationOffset);
132132
#else
133133
WebXRManager.Instance.transform.localPosition = rotationOffset * (originPosition - hitPoseData.position);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "WebXR.Samples.Scripts",
3+
"rootNamespace": "",
34
"references": [
45
"GUID:fd4abe4ffe74ef1448afe15c6cb36bb7",
56
"GUID:84a2d09f0bb073f40922f5ea5362abe7"
@@ -16,6 +17,16 @@
1617
"name": "com.de-panther.webxr-input-profiles-loader",
1718
"expression": "0.4.0",
1819
"define": "WEBXR_INPUT_PROFILES"
20+
},
21+
{
22+
"name": "Unity",
23+
"expression": "[2021.3.11,2022.1)",
24+
"define": "HAS_POSITION_AND_ROTATION"
25+
},
26+
{
27+
"name": "Unity",
28+
"expression": "2022.3",
29+
"define": "HAS_POSITION_AND_ROTATION"
1930
}
2031
],
2132
"noEngineReferences": false

Packages/webxr/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Changed
10+
- Improve performance.
11+
912
## [0.16.1] - 2023-05-27
1013
### Fixed
1114
- Issues when using more than one WebXRManager components.

Packages/webxr/Runtime/Scripts/WebXRCamera.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private void UpdateFollower()
8989
switch (xrState)
9090
{
9191
case WebXRState.AR:
92-
#if UNITY_2022_3_OR_NEWER
92+
#if HAS_POSITION_AND_ROTATION
9393
cameraFollower.SetLocalPositionAndRotation(viewsCount > 1 ? (cameraARL.transform.localPosition + cameraARR.transform.localPosition) * 0.5f : cameraARL.transform.localPosition,
9494
cameraARL.transform.localRotation);
9595
#else
@@ -98,7 +98,7 @@ private void UpdateFollower()
9898
#endif
9999
return;
100100
case WebXRState.VR:
101-
#if UNITY_2022_3_OR_NEWER
101+
#if HAS_POSITION_AND_ROTATION
102102
cameraFollower.SetLocalPositionAndRotation((cameraL.transform.localPosition + cameraR.transform.localPosition) * 0.5f,
103103
cameraL.transform.localRotation);
104104
#else
@@ -107,7 +107,7 @@ private void UpdateFollower()
107107
#endif
108108
return;
109109
}
110-
#if UNITY_2022_3_OR_NEWER
110+
#if HAS_POSITION_AND_ROTATION
111111
cameraFollower.SetLocalPositionAndRotation(cameraMain.transform.localPosition,
112112
cameraMain.transform.localRotation);
113113
#else
@@ -179,15 +179,15 @@ private void OnHeadsetUpdate(
179179
{
180180
if (xrState == WebXRState.VR)
181181
{
182-
#if UNITY_2022_3_OR_NEWER
182+
#if HAS_POSITION_AND_ROTATION
183183
cameraL.transform.SetLocalPositionAndRotation(leftPosition, leftRotation);
184184
#else
185185
cameraL.transform.localPosition = leftPosition;
186186
cameraL.transform.localRotation = leftRotation;
187187
#endif
188188
cameraL.projectionMatrix = leftProjectionMatrix;
189189

190-
#if UNITY_2022_3_OR_NEWER
190+
#if HAS_POSITION_AND_ROTATION
191191
cameraR.transform.SetLocalPositionAndRotation(rightPosition, rightRotation);
192192
#else
193193
cameraR.transform.localPosition = rightPosition;
@@ -197,14 +197,14 @@ private void OnHeadsetUpdate(
197197
}
198198
else if (xrState == WebXRState.AR)
199199
{
200-
#if UNITY_2022_3_OR_NEWER
200+
#if HAS_POSITION_AND_ROTATION
201201
cameraARL.transform.SetLocalPositionAndRotation(leftPosition, leftRotation);
202202
#else
203203
cameraARL.transform.localPosition = leftPosition;
204204
cameraARL.transform.localRotation = leftRotation;
205205
#endif
206206
cameraARL.projectionMatrix = leftProjectionMatrix;
207-
#if UNITY_2022_3_OR_NEWER
207+
#if HAS_POSITION_AND_ROTATION
208208
cameraARR.transform.SetLocalPositionAndRotation(rightPosition, rightRotation);
209209
#else
210210
cameraARR.transform.localPosition = rightPosition;

Packages/webxr/Runtime/Scripts/WebXRController.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ private void OnControllerUpdate(WebXRControllerData controllerData)
371371
gripPosition = controllerData.gripPosition;
372372
if (alwaysUseGrip)
373373
{
374-
#if UNITY_2022_3_OR_NEWER
374+
#if HAS_POSITION_AND_ROTATION
375375
transform.SetLocalPositionAndRotation(controllerData.rotation * (controllerData.position + controllerData.gripPosition),
376376
controllerData.rotation * controllerData.gripRotation);
377377
#else
@@ -381,7 +381,7 @@ private void OnControllerUpdate(WebXRControllerData controllerData)
381381
}
382382
else
383383
{
384-
#if UNITY_2022_3_OR_NEWER
384+
#if HAS_POSITION_AND_ROTATION
385385
transform.SetLocalPositionAndRotation(controllerData.position,
386386
controllerData.rotation);
387387
#else
@@ -438,7 +438,7 @@ private void HandleOculusLinkBug(WebXRControllerData controllerData)
438438
gripPosition = controllerData.gripPosition;
439439
if (alwaysUseGrip)
440440
{
441-
#if UNITY_2022_3_OR_NEWER
441+
#if HAS_POSITION_AND_ROTATION
442442
transform.SetLocalPositionAndRotation(controllerData.rotation * (controllerData.position + controllerData.gripPosition),
443443
controllerData.rotation * controllerData.gripRotation);
444444
#else
@@ -448,7 +448,7 @@ private void HandleOculusLinkBug(WebXRControllerData controllerData)
448448
}
449449
else
450450
{
451-
#if UNITY_2022_3_OR_NEWER
451+
#if HAS_POSITION_AND_ROTATION
452452
transform.SetLocalPositionAndRotation(controllerData.position,
453453
controllerData.rotation * oculusOffsetRay);
454454
#else
@@ -488,7 +488,7 @@ private void OnHandUpdateInternal(WebXRHandData handData)
488488
}
489489
SetControllerActive(false);
490490
SetHandActive(true);
491-
#if UNITY_2022_3_OR_NEWER
491+
#if HAS_POSITION_AND_ROTATION
492492
transform.SetLocalPositionAndRotation(handData.joints[0].position,
493493
handData.joints[0].rotation);
494494
#else

Packages/webxr/Runtime/WebXR.asmdef

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717
"name": "com.unity.xr.management",
1818
"expression": "4.3.1",
1919
"define": "UNITY_XR_MANAGEMENT_4_3_1_OR_NEWER"
20+
},
21+
{
22+
"name": "Unity",
23+
"expression": "[2021.3.11,2022.1)",
24+
"define": "HAS_POSITION_AND_ROTATION"
25+
},
26+
{
27+
"name": "Unity",
28+
"expression": "2022.3",
29+
"define": "HAS_POSITION_AND_ROTATION"
2030
}
2131
],
2232
"noEngineReferences": false

0 commit comments

Comments
 (0)