ARLightEstimationData.cs
7.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using System;
namespace UnityEngine.XR.ARFoundation
{
/// <summary>
/// A structure for light estimation information provided by the AR device.
/// </summary>
public struct ARLightEstimationData : IEquatable<ARLightEstimationData>
{
/// <summary>
/// An estimate for the average brightness in the scene.
/// Use <c>averageBrightness.HasValue</c> to determine if this information is available.
/// </summary>
/// <remarks>
/// <see cref="averageBrightness"/> may be null when light estimation is not enabled in the <see cref="ARSession"/>,
/// or if a platform-specific error has occurred.
/// </remarks>
public float? averageBrightness
{
get
{
if (m_AverageBrightness.HasValue)
return m_AverageBrightness;
else if (m_AverageIntensityInLumens.HasValue)
return ConvertLumensToBrightness(m_AverageIntensityInLumens.Value);
return null;
}
set { m_AverageBrightness = value; }
}
/// <summary>
/// An estimate for the average color temperature of the scene.
/// Use <c>averageColorTemperature.HasValue</c> to determine if this information is available.
/// </summary>
/// <remarks>
/// <see cref="averageColorTemperature"/> may be null when light estimation is not enabled in the <see cref="ARSession"/>,
/// if the platform does not support it, or if a platform-specific error has occurred.
/// </remarks>
public float? averageColorTemperature { get; set; }
/// <summary>
/// The scaling factors used for color correction.
/// The RGB scale factors are used to match the color of the light
/// in the scene. The alpha channel value is platform-specific.
/// </summary>
/// <remarks>
/// <see cref="colorCorrection"/> may be null when light estimation is not enabled in the <see cref="ARSession"/>,
/// if the platform does not support it, or if a platform-specific error has occurred.
/// </remarks>
public Color? colorCorrection { get; set; }
/// <summary>
/// An estimate for the average intensity, in lumens, in the scene.
/// Use <c>averageIntensityInLumens.HasValue</c> to determine if this information is available.
/// </summary>
/// <remarks>
/// <see cref="averageIntensityInLumens"/> may be null when light estimation is not enabled in the <see cref="ARSession"/>,
/// or if a platform-specific error has occurred.
/// </remarks>
public float? averageIntensityInLumens
{
get
{
if (m_AverageIntensityInLumens.HasValue)
return m_AverageIntensityInLumens;
else if (m_AverageBrightness.HasValue)
return ConvertBrightnessToLumens(m_AverageBrightness.Value);
return null;
}
set { m_AverageIntensityInLumens = value; }
}
/// <summary>
/// Generates a hash code suitable for use in <c>HashSet</c> and <c>Dictionary</c>.
/// </summary>
/// <returns>A hash of the <see cref="ARLightEstimationData"/>.</returns>
public override int GetHashCode()
{
unchecked
{
return
((averageBrightness.GetHashCode() * 486187739 +
averageColorTemperature.GetHashCode()) * 486187739 +
colorCorrection.GetHashCode()) * 486187739 +
averageIntensityInLumens.GetHashCode() * 486187739;
}
}
/// <summary>
/// Compares for equality.
/// </summary>
/// <param name="obj">An <c>object</c> to compare against.</param>
/// <returns><c>true</c> if <paramref name="obj"/> is an <see cref="ARLightEstimationData"/> and
/// <see cref="Equals(ARLightEstimationData)"/> is also <c>true</c>. Otherwise, <c>false</c>.</returns>
public override bool Equals(object obj)
{
if (!(obj is ARLightEstimationData))
return false;
return Equals((ARLightEstimationData)obj);
}
public override string ToString()
{
return string.Format("(Avg. Brightness: {0}, Avg. Color Temperature: {1}, Color Correction: {2}, Avg. Intensity in Lumens: {3})",
averageBrightness, averageColorTemperature, colorCorrection, averageIntensityInLumens);
}
/// <summary>
/// Compares for equality.
/// </summary>
/// <param name="other">The other <see cref="ARLightEstimationData"/> to compare against.</param>
/// <returns><c>true</c> if the <see cref="ARLightEstimationData"/> represents the same object.</returns>
public bool Equals(ARLightEstimationData other)
{
return
(averageBrightness.Equals(other.averageBrightness)) &&
(averageColorTemperature.Equals(other.averageColorTemperature)) &&
(colorCorrection.Equals(other.colorCorrection)) &&
(averageIntensityInLumens.Equals(other.averageIntensityInLumens));
}
/// <summary>
/// Compares <paramref name="lhs"/> and <paramref name="rhs"/> for equality using <see cref="Equals(ARLightEstimationData)"/>.
/// </summary>
/// <param name="lhs">The left-hand-side <see cref="ARLightEstimationData"/> of the comparison.</param>
/// <param name="rhs">The right-hand-side <see cref="ARLightEstimationData"/> of the comparison.</param>
/// <returns><c>true</c> if <paramref name="lhs"/> compares equal to <paramref name="rhs"/>, <c>false</c> otherwise.</returns>
public static bool operator ==(ARLightEstimationData lhs, ARLightEstimationData rhs)
{
return lhs.Equals(rhs);
}
/// <summary>
/// Compares <paramref name="lhs"/> and <paramref name="rhs"/> for inequality using <see cref="Equals(ARLightEstimationData)"/>.
/// </summary>
/// <param name="lhs">The left-hand-side <see cref="ARLightEstimationData"/> of the comparison.</param>
/// <param name="rhs">The right-hand-side <see cref="ARLightEstimationData"/> of the comparison.</param>
/// <returns><c>false</c> if <paramref name="lhs"/> compares equal to <paramref name="rhs"/>, <c>true</c> otherwise.</returns>
public static bool operator !=(ARLightEstimationData lhs, ARLightEstimationData rhs)
{
return !lhs.Equals(rhs);
}
float ConvertBrightnessToLumens(float brightness)
{
return Mathf.Clamp(brightness*k_MaxLuminosity, 0f, k_MaxLuminosity);
}
float ConvertLumensToBrightness(float lumens)
{
return Mathf.Clamp(lumens/k_MaxLuminosity, 0f, 1f);
}
private float? m_AverageBrightness;
private float? m_AverageIntensityInLumens;
const float k_MaxLuminosity = 2000.0f;
}
}