@@ -51,6 +51,39 @@ public class CompositionLayerEditor : Editor
5151 static GUIContent Label_QuadHeight = new GUIContent ( "Height" , "Height of a Quad Layer" ) ;
5252 SerializedProperty Property_QuadHeight ;
5353
54+ static string PropertyName_EquirectRadius = "m_EquirectRadius" ;
55+ static GUIContent Label_EquirectRadius = new GUIContent ( "Radius" , "Radius of Equirect Layer" ) ;
56+ SerializedProperty Property_EquirectRadius ;
57+
58+ static string PropertyName_EquirectScaleX = "m_EquirectScaleX" ;
59+ static GUIContent Label_EquirectScaleX = new GUIContent ( "scale.x" , "Scale.X of Equirect Layer" ) ;
60+ SerializedProperty Property_EquirectScaleX ;
61+
62+ static string PropertyName_EquirectScaleY = "m_EquirectScaleY" ;
63+ static GUIContent Label_EquirectScaleY = new GUIContent ( "scale.y" , "Scale.Y of Equirect Layer" ) ;
64+ SerializedProperty Property_EquirectScaleY ;
65+
66+ static string PropertyName_EquirectBiasX = "m_EquirectBiasX" ;
67+ static GUIContent Label_EquirectBiasX = new GUIContent ( "bias.x" , "Bias.X of Equirect Layer" ) ;
68+ SerializedProperty Property_EquirectBiasX ;
69+
70+ static string PropertyName_EquirectBiasY = "m_EquirectBiasY" ;
71+ static GUIContent Label_EquirectBiasY = new GUIContent ( "bias.y" , "Bias.Y of Equirect Layer" ) ;
72+ SerializedProperty Property_EquirectBiasY ;
73+
74+ static string PropertyName_EquirectCentralHorizontalAngle = "m_EquirectCentralHorizontalAngle" ;
75+ static GUIContent Label_EquirectCentralHorizontalAngle = new GUIContent ( "CentralHorizontalAngle" , "Central Horizontal Angle of Equirect Layer" ) ;
76+ SerializedProperty Property_EquirectCentralHorizontalAngle ;
77+
78+ static string PropertyName_EquirectUpperVerticalAngle = "m_EquirectUpperVerticalAngle" ;
79+ static GUIContent Label_EquirectUpperVerticalAngle = new GUIContent ( "UpperVerticalAngle" , "Upper Vertical Angle of Equirect Layer" ) ;
80+ SerializedProperty Property_EquirectUpperVerticalAngle ;
81+
82+ static string PropertyName_EquirectLowerVerticalAngle = "m_EquirectLowerVerticalAngle" ;
83+ static GUIContent Label_EquirectLowerVerticalAngle = new GUIContent ( "LowerVerticalAngle" , "Lower Vertical Angle of Equirect Layer" ) ;
84+ SerializedProperty Property_EquirectLowerVerticalAngle ;
85+
86+
5487 static string PropertyName_CylinderHeight = "m_CylinderHeight" ;
5588 static GUIContent Label_CylinderHeight = new GUIContent ( "Height" , "Height of Cylinder Layer" ) ;
5689 SerializedProperty Property_CylinderHeight ;
@@ -138,6 +171,14 @@ public override void OnInspectorGUI()
138171 if ( Property_LockMode == null ) Property_LockMode = serializedObject . FindProperty ( PropertyName_LockMode ) ;
139172 if ( Property_QuadWidth == null ) Property_QuadWidth = serializedObject . FindProperty ( PropertyName_QuadWidth ) ;
140173 if ( Property_QuadHeight == null ) Property_QuadHeight = serializedObject . FindProperty ( PropertyName_QuadHeight ) ;
174+ if ( Property_EquirectRadius == null ) Property_EquirectRadius = serializedObject . FindProperty ( PropertyName_EquirectRadius ) ;
175+ if ( Property_EquirectScaleX == null ) Property_EquirectScaleX = serializedObject . FindProperty ( PropertyName_EquirectScaleX ) ;
176+ if ( Property_EquirectScaleY == null ) Property_EquirectScaleY = serializedObject . FindProperty ( PropertyName_EquirectScaleY ) ;
177+ if ( Property_EquirectBiasX == null ) Property_EquirectBiasX = serializedObject . FindProperty ( PropertyName_EquirectBiasX ) ;
178+ if ( Property_EquirectBiasY == null ) Property_EquirectBiasY = serializedObject . FindProperty ( PropertyName_EquirectBiasY ) ;
179+ if ( Property_EquirectCentralHorizontalAngle == null ) Property_EquirectCentralHorizontalAngle = serializedObject . FindProperty ( PropertyName_EquirectCentralHorizontalAngle ) ;
180+ if ( Property_EquirectUpperVerticalAngle == null ) Property_EquirectUpperVerticalAngle = serializedObject . FindProperty ( PropertyName_EquirectUpperVerticalAngle ) ;
181+ if ( Property_EquirectLowerVerticalAngle == null ) Property_EquirectLowerVerticalAngle = serializedObject . FindProperty ( PropertyName_EquirectLowerVerticalAngle ) ;
141182 if ( Property_CylinderHeight == null ) Property_CylinderHeight = serializedObject . FindProperty ( PropertyName_CylinderHeight ) ;
142183 if ( Property_CylinderArcLength == null ) Property_CylinderArcLength = serializedObject . FindProperty ( PropertyName_CylinderArcLength ) ;
143184 if ( Property_CylinderRadius == null ) Property_CylinderRadius = serializedObject . FindProperty ( PropertyName_CylinderRadius ) ;
@@ -171,6 +212,138 @@ public override void OnInspectorGUI()
171212 EditorGUILayout . PropertyField ( Property_LayerShape , new GUIContent ( Label_LayerShape ) ) ;
172213 serializedObject . ApplyModifiedProperties ( ) ;
173214
215+ if ( Property_LayerShape . intValue == ( int ) CompositionLayer . LayerShape . Equirect || Property_LayerShape . intValue == ( int ) CompositionLayer . LayerShape . Equirect2 )
216+ {
217+ if ( targetCompositionLayer . isPreviewingQuad )
218+ {
219+ targetCompositionLayer . isPreviewingQuad = false ;
220+ if ( targetCompositionLayer . generatedPreview != null )
221+ {
222+ DestroyImmediate ( targetCompositionLayer . generatedPreview ) ;
223+ }
224+ }
225+
226+ if ( targetCompositionLayer . isPreviewingCylinder )
227+ {
228+ targetCompositionLayer . isPreviewingCylinder = false ;
229+ if ( targetCompositionLayer . generatedPreview != null )
230+ {
231+ DestroyImmediate ( targetCompositionLayer . generatedPreview ) ;
232+ }
233+ }
234+
235+ if ( ! FeatureHelpers . GetFeatureWithIdForBuildTarget ( BuildTargetGroup . Android , ViveCompositionLayerEquirect . featureId ) . enabled )
236+ {
237+ EditorGUILayout . HelpBox ( "The Composition Layer Equirect feature is not enabled in OpenXR Settings.\n Enable it to use Equirect layers." , MessageType . Warning ) ;
238+ }
239+
240+ EditorGUI . indentLevel ++ ;
241+ showLayerParams = EditorGUILayout . Foldout ( showLayerParams , "Equirect Parameters" ) ;
242+ if ( showLayerParams )
243+ {
244+ EditorGUILayout . PropertyField ( Property_EquirectRadius , new GUIContent ( Label_EquirectRadius ) ) ;
245+
246+ if ( Property_LayerShape . intValue == ( int ) CompositionLayer . LayerShape . Equirect )
247+ {
248+ EditorGUILayout . PropertyField ( Property_EquirectScaleX , new GUIContent ( Label_EquirectScaleX ) ) ;
249+ EditorGUILayout . PropertyField ( Property_EquirectScaleY , new GUIContent ( Label_EquirectScaleY ) ) ;
250+ EditorGUILayout . PropertyField ( Property_EquirectBiasX , new GUIContent ( Label_EquirectBiasX ) ) ;
251+ EditorGUILayout . PropertyField ( Property_EquirectBiasY , new GUIContent ( Label_EquirectBiasY ) ) ;
252+ }
253+
254+ else if ( Property_LayerShape . intValue == ( int ) CompositionLayer . LayerShape . Equirect2 )
255+ {
256+ EditorGUILayout . PropertyField ( Property_EquirectCentralHorizontalAngle , new GUIContent ( Label_EquirectCentralHorizontalAngle ) ) ;
257+ EditorGUILayout . PropertyField ( Property_EquirectUpperVerticalAngle , new GUIContent ( Label_EquirectUpperVerticalAngle ) ) ;
258+ EditorGUILayout . PropertyField ( Property_EquirectLowerVerticalAngle , new GUIContent ( Label_EquirectLowerVerticalAngle ) ) ;
259+ }
260+ serializedObject . ApplyModifiedProperties ( ) ;
261+ }
262+ EditorGUI . indentLevel -- ;
263+
264+ bool EquirectParamsChanged = targetCompositionLayer . LayerDimensionsChanged ( ) ;
265+ if ( targetCompositionLayer . isPreviewingEquirect )
266+ {
267+ Transform generatedPreviewTransform = targetCompositionLayer . transform . Find ( CompositionLayer . EquirectPreviewName ) ;
268+
269+ if ( generatedPreviewTransform != null )
270+ {
271+ targetCompositionLayer . generatedPreview = generatedPreviewTransform . gameObject ;
272+
273+ if ( EquirectParamsChanged )
274+ {
275+ MeshFilter equirectMeshFilter = targetCompositionLayer . generatedPreview . GetComponent < MeshFilter > ( ) ;
276+
277+ //Generate vertices
278+ equirectMeshFilter . mesh = CompositionLayer . MeshGenerationHelper . GenerateEquirectMesh ( targetCompositionLayer . hmd , targetCompositionLayer . EquirectRadius ) ;
279+
280+ targetCompositionLayer . generatedPreview . transform . localPosition = Vector3 . zero ;
281+ targetCompositionLayer . generatedPreview . transform . localRotation = Quaternion . identity ;
282+
283+ targetCompositionLayer . generatedPreview . transform . localScale = targetCompositionLayer . GetNormalizedLocalScale ( targetCompositionLayer . transform , Vector3 . one ) ;
284+ }
285+
286+ if ( targetCompositionLayer . generatedPreview . GetComponent < MeshRenderer > ( ) . sharedMaterial . mainTexture != targetCompositionLayer . texture )
287+ {
288+ targetCompositionLayer . generatedPreview . GetComponent < MeshRenderer > ( ) . sharedMaterial . mainTexture = targetCompositionLayer . texture ;
289+ }
290+
291+ if ( GUILayout . Button ( "Hide Equirect Preview" ) )
292+ {
293+ targetCompositionLayer . isPreviewingEquirect = false ;
294+ if ( targetCompositionLayer . generatedPreview != null )
295+ {
296+ DestroyImmediate ( targetCompositionLayer . generatedPreview ) ;
297+ }
298+ }
299+ }
300+ else
301+ {
302+ targetCompositionLayer . isPreviewingEquirect = false ;
303+ }
304+ }
305+ else
306+ {
307+ if ( GUILayout . Button ( "Show Equirect Preview" ) )
308+ {
309+ Rect srcRectLeft = FullRect ;
310+ if ( targetCompositionLayer . isCustomRects && targetCompositionLayer . customRects == CompositionLayer . CustomRectsType . LeftRight )
311+ srcRectLeft = LeftRightRect ;
312+ if ( targetCompositionLayer . isCustomRects && targetCompositionLayer . customRects == CompositionLayer . CustomRectsType . TopDown )
313+ srcRectLeft = TopDownRect ;
314+
315+ targetCompositionLayer . isPreviewingEquirect = true ;
316+ //Vector3[] cylinderVertices = CompositionLayer.MeshGenerationHelper.GenerateCylinderVertex(targetCompositionLayer.CylinderAngleOfArc, targetCompositionLayer.CylinderRadius, targetCompositionLayer.CylinderHeight);
317+ //Add components to Game Object
318+ targetCompositionLayer . generatedPreview = new GameObject ( ) ;
319+ targetCompositionLayer . generatedPreview . hideFlags = HideFlags . HideAndDontSave ;
320+ targetCompositionLayer . generatedPreview . name = CompositionLayer . EquirectPreviewName ;
321+ targetCompositionLayer . generatedPreview . transform . SetParent ( targetCompositionLayer . gameObject . transform ) ;
322+ targetCompositionLayer . generatedPreview . transform . localPosition = Vector3 . zero ;
323+ targetCompositionLayer . generatedPreview . transform . localRotation = Quaternion . identity ;
324+
325+ targetCompositionLayer . generatedPreview . transform . localScale = targetCompositionLayer . GetNormalizedLocalScale ( targetCompositionLayer . transform , Vector3 . one ) ;
326+
327+ MeshRenderer equirectMeshRenderer = targetCompositionLayer . generatedPreview . AddComponent < MeshRenderer > ( ) ;
328+ MeshFilter equirectMeshFilter = targetCompositionLayer . generatedPreview . AddComponent < MeshFilter > ( ) ;
329+ equirectMeshRenderer . sharedMaterial = new Material ( Shader . Find ( "Unlit/Transparent" ) ) ;
330+
331+ if ( targetCompositionLayer . texture != null )
332+ {
333+ equirectMeshRenderer . sharedMaterial . mainTexture = targetCompositionLayer . texture ;
334+ equirectMeshRenderer . sharedMaterial . mainTextureOffset = srcRectLeft . position ;
335+ equirectMeshRenderer . sharedMaterial . mainTextureScale = srcRectLeft . size ;
336+ }
337+
338+ //Generate Mesh
339+ equirectMeshFilter . mesh = CompositionLayer . MeshGenerationHelper . GenerateEquirectMesh ( targetCompositionLayer . hmd , targetCompositionLayer . EquirectRadius ) ;
340+ }
341+ }
342+
343+ EditorGUILayout . Space ( 10 ) ;
344+ serializedObject . ApplyModifiedProperties ( ) ;
345+
346+ }
174347 if ( Property_LayerShape . intValue == ( int ) CompositionLayer . LayerShape . Cylinder )
175348 {
176349 if ( ! FeatureHelpers . GetFeatureWithIdForBuildTarget ( BuildTargetGroup . Android , ViveCompositionLayerCylinder . featureId ) . enabled )
@@ -187,6 +360,15 @@ public override void OnInspectorGUI()
187360 }
188361 }
189362
363+ if ( targetCompositionLayer . isPreviewingEquirect )
364+ {
365+ targetCompositionLayer . isPreviewingEquirect = false ;
366+ if ( targetCompositionLayer . generatedPreview != null )
367+ {
368+ DestroyImmediate ( targetCompositionLayer . generatedPreview ) ;
369+ }
370+ }
371+
190372 Transform generatedQuadTransform = targetCompositionLayer . transform . Find ( CompositionLayer . QuadUnderlayMeshName ) ;
191373 if ( generatedQuadTransform != null )
192374 {
@@ -280,6 +462,7 @@ public override void OnInspectorGUI()
280462
281463 if ( targetCompositionLayer . isPreviewingCylinder )
282464 {
465+
283466 Transform generatedPreviewTransform = targetCompositionLayer . transform . Find ( CompositionLayer . CylinderPreviewName ) ;
284467
285468 if ( generatedPreviewTransform != null )
@@ -372,6 +555,15 @@ public override void OnInspectorGUI()
372555 }
373556 }
374557
558+ if ( targetCompositionLayer . isPreviewingEquirect )
559+ {
560+ targetCompositionLayer . isPreviewingEquirect = false ;
561+ if ( targetCompositionLayer . generatedPreview != null )
562+ {
563+ DestroyImmediate ( targetCompositionLayer . generatedPreview ) ;
564+ }
565+ }
566+
375567 EditorGUI . indentLevel ++ ;
376568 showLayerParams = EditorGUILayout . Foldout ( showLayerParams , "Quad Parameters" ) ;
377569 if ( showLayerParams )
@@ -507,7 +699,7 @@ public override void OnInspectorGUI()
507699 EditorGUI.indentLevel--;
508700 }*/
509701
510- if ( targetCompositionLayer . textureLeft == targetCompositionLayer . textureRight || targetCompositionLayer . textureRight == null )
702+ if ( ( Property_LayerShape . intValue != ( int ) CompositionLayer . LayerShape . Equirect && Property_LayerShape . intValue != ( int ) CompositionLayer . LayerShape . Equirect2 ) && ( targetCompositionLayer . textureLeft == targetCompositionLayer . textureRight || targetCompositionLayer . textureRight == null ) )
511703 {
512704 EditorGUILayout . PropertyField ( Property_IsCustomRects , Label_IsCustomRects ) ;
513705 serializedObject . ApplyModifiedProperties ( ) ;
0 commit comments