Skip to content

Commit 21e7c2f

Browse files
committed
Add nearClipPlane correction in VRView camera setup, in OnEnable()
1 parent dcd822a commit 21e7c2f

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

Scripts/Core/VRView.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,31 @@ public void OnEnable()
140140

141141
autoRepaintOnSceneChange = true;
142142
s_ActiveView = this;
143+
const float nearClipPlane = 0.01f;
144+
const float farClipPlane = 1000f;
143145

144146
var currentEditingContext = cameraSetupStarted != null ? cameraSetupStarted() : null;
145147
s_ExistingSceneMainCamera = Camera.main;
146148
if (currentEditingContext != null && currentEditingContext.copySceneCameraSettings && s_ExistingSceneMainCamera && s_ExistingSceneMainCamera.enabled)
147149
{
148150
GameObject cameraGO = EditorUtility.CreateGameObjectWithHideFlags(k_CameraName, HideFlags.HideAndDontSave);
149151
m_Camera = ObjectUtils.CopyComponent(s_ExistingSceneMainCamera, cameraGO);
152+
153+
if (m_Camera.nearClipPlane > nearClipPlane)
154+
{
155+
Debug.LogWarning("Copying settings from scene camera that is tagged 'MainCamera'." + Environment.NewLine +
156+
" Clipping issues may occur with NearClipPlane values is greater than " + nearClipPlane);
157+
158+
m_Camera.nearClipPlane = nearClipPlane;
159+
}
150160
}
151161
else
152162
{
153163
GameObject cameraGO = EditorUtility.CreateGameObjectWithHideFlags(k_CameraName, HideFlags.HideAndDontSave, typeof(Camera));
154164
m_Camera = cameraGO.GetComponent<Camera>();
165+
166+
m_Camera.nearClipPlane = nearClipPlane;
167+
m_Camera.farClipPlane = farClipPlane;
155168
}
156169

157170
if (s_ExistingSceneMainCamera)
@@ -166,8 +179,6 @@ public void OnEnable()
166179
GameObject rigGO = EditorUtility.CreateGameObjectWithHideFlags("VRCameraRig", HideFlags.HideAndDontSave, typeof(EditorMonoBehaviour));
167180
m_CameraRig = rigGO.transform;
168181
m_Camera.transform.parent = m_CameraRig;
169-
m_Camera.nearClipPlane = 0.01f;
170-
m_Camera.farClipPlane = 1000f;
171182
m_CameraRig.position = headCenteredOrigin;
172183
m_CameraRig.rotation = Quaternion.identity;
173184

0 commit comments

Comments
 (0)