@@ -24,6 +24,27 @@ public enum ObserverStates
2424 Stopped = 1
2525 }
2626
27+ /// <summary>
28+ /// Spatial Mapping Volume Type
29+ /// </summary>
30+ public enum ObserverVolumeTypes
31+ {
32+ /// <summary>
33+ /// The observed volume is an axis aligned box.
34+ /// </summary>
35+ AxisAlignedBox = 0 ,
36+
37+ /// <summary>
38+ /// The observed volume is an oriented box.
39+ /// </summary>
40+ OrientedBox = 1 ,
41+
42+ /// <summary>
43+ /// The observed volume is a sphere.
44+ /// </summary>
45+ Sphere = 2
46+ }
47+
2748 /// <summary>
2849 /// The SpatialMappingObserver class encapsulates the SurfaceObserver into an easy to use
2950 /// object that handles managing the observed surfaces and the rendering of surface geometry.
@@ -33,9 +54,6 @@ public class SpatialMappingObserver : SpatialMappingSource
3354 [ Tooltip ( "The number of triangles to calculate per cubic meter." ) ]
3455 public float TrianglesPerCubicMeter = 500f ;
3556
36- [ Tooltip ( "The extents of the observation volume." ) ]
37- public Vector3 Extents = Vector3 . one * 10.0f ;
38-
3957 [ Tooltip ( "How long to wait (in sec) between Spatial Mapping updates." ) ]
4058 public float TimeBetweenUpdates = 3.5f ;
4159
@@ -44,6 +62,27 @@ public class SpatialMappingObserver : SpatialMappingSource
4462 /// </summary>
4563 public ObserverStates ObserverState { get ; private set ; }
4664
65+ /// <summary>
66+ /// Indicates the current type of the observed volume
67+ /// </summary>
68+ [ SerializeField ] [ Tooltip ( "The shape of the observation volume." ) ]
69+ private ObserverVolumeTypes observerVolumeType = ObserverVolumeTypes . AxisAlignedBox ;
70+ public ObserverVolumeTypes ObserverVolumeType
71+ {
72+ get
73+ {
74+ return observerVolumeType ;
75+ }
76+ set
77+ {
78+ if ( observerVolumeType != value )
79+ {
80+ observerVolumeType = value ;
81+ SwitchObservedVolume ( ) ;
82+ }
83+ }
84+ }
85+
4786 /// <summary>
4887 /// Our Surface Observer object for generating/updating Spatial Mapping data.
4988 /// </summary>
@@ -73,6 +112,70 @@ public class SpatialMappingObserver : SpatialMappingSource
73112 /// </summary>
74113 private float updateTime ;
75114
115+ [ SerializeField ] [ Tooltip ( "The extents of the observation volume." ) ]
116+ private Vector3 extents = Vector3 . one * 10.0f ;
117+ public Vector3 Extents
118+ {
119+ get
120+ {
121+ return extents ;
122+ }
123+ set
124+ {
125+ if ( extents != value )
126+ {
127+ extents = value ;
128+ SwitchObservedVolume ( ) ;
129+ }
130+ }
131+ }
132+
133+ /// <summary>
134+ /// The origin of the observation volume.
135+ /// </summary>
136+ [ SerializeField ] [ Tooltip ( "The origin of the observation volume." ) ]
137+ private Vector3 origin = Vector3 . zero ;
138+ public Vector3 Origin
139+ {
140+ get
141+ {
142+ return origin ;
143+ }
144+ set
145+ {
146+ if ( origin != value )
147+ {
148+ origin = value ;
149+ SwitchObservedVolume ( ) ;
150+ }
151+ }
152+ }
153+
154+ /// <summary>
155+ /// The direction of the observed volume, if an oriented box is choosen.
156+ /// </summary>
157+ [ SerializeField ] [ Tooltip ( "The direction of the observation volume." ) ]
158+ private Quaternion orientation = Quaternion . identity ;
159+ public Quaternion Orientation
160+ {
161+ get
162+ {
163+ return orientation ;
164+ }
165+ set
166+ {
167+ if ( orientation != value )
168+ {
169+ orientation = value ;
170+ // Only needs to be changed if the corresponding mode is active.
171+ if ( ObserverVolumeType == ObserverVolumeTypes . OrientedBox )
172+ {
173+ SwitchObservedVolume ( ) ;
174+ }
175+ }
176+ }
177+ }
178+
76179 protected override void Awake ( )
77180 {
78181 base . Awake ( ) ;
@@ -97,7 +200,7 @@ private void Update()
97200
98201 SurfaceObject newSurface ;
99202 WorldAnchor worldAnchor ;
100-
203+
101204 if ( spareSurfaceObject == null )
102205 {
103206 newSurface = CreateSurfaceObject (
@@ -166,7 +269,7 @@ public void StartObserving()
166269 if ( observer == null )
167270 {
168271 observer = new SurfaceObserver ( ) ;
169- observer . SetVolumeAsAxisAlignedBox ( Vector3 . zero , Extents ) ;
272+ SwitchObservedVolume ( ) ;
170273 }
171274
172275 if ( ObserverState != ObserverStates . Running )
@@ -225,20 +328,49 @@ public void CleanupObserver()
225328
226329 /// <summary>
227330 /// Can be called to override the default origin for the observed volume. Can only be called while observer has been started.
331+ /// Kept for compatibility with Examples/SpatialUnderstanding
228332 /// </summary>
229333 public bool SetObserverOrigin ( Vector3 origin )
230334 {
231335 bool originUpdated = false ;
232336
233337 if ( observer != null )
234338 {
235- observer . SetVolumeAsAxisAlignedBox ( origin , Extents ) ;
339+ Origin = origin ;
236340 originUpdated = true ;
237341 }
238342
239343 return originUpdated ;
240344 }
241345
346+ /// <summary>
347+ /// Change the observed volume according to ObserverVolumeType.
348+ /// </summary>
349+ private void SwitchObservedVolume ( )
350+ {
351+ if ( observer == null )
352+ {
353+ return ;
354+ }
355+
356+ switch ( observerVolumeType )
357+ {
358+ case ObserverVolumeTypes . AxisAlignedBox :
359+ observer . SetVolumeAsAxisAlignedBox ( origin , extents ) ;
360+ break ;
361+ case ObserverVolumeTypes . OrientedBox :
362+ observer . SetVolumeAsOrientedBox ( origin , extents , orientation ) ;
363+ break ;
364+ case ObserverVolumeTypes . Sphere :
365+ observer . SetVolumeAsSphere ( origin , extents . magnitude ) ; //workaround
366+ break ;
367+ default :
368+ observer . SetVolumeAsAxisAlignedBox ( origin , extents ) ;
369+ break ;
370+ }
371+
372+ }
373+
242374 /// <summary>
243375 /// Handles the SurfaceObserver's OnDataReady event.
244376 /// </summary>
0 commit comments