Cesium for Unreal 2.24.1
Loading...
Searching...
No Matches
CesiumGlobeAnchorComponent.h
Go to the documentation of this file.
1// Copyright 2020-2024 CesiumGS, Inc. and Contributors
2
3#pragma once
4
5#include "Cesium3DTileset.h"
6#include "CesiumGeospatial/GlobeAnchor.h"
7#include "Components/ActorComponent.h"
8#include "Delegates/IDelegateInstance.h"
9#include "CesiumGlobeAnchorComponent.generated.h"
10
13
14/**
15 * The frame of reference from which to interpret a given height value.
16 */
17UENUM(BlueprintType)
18enum class ECesiumHeightReference : uint8 {
19 /**
20 * Height is interpreted relative to the ellipsoid.
21 */
23 /**
24 * Height is interpreted relative to the surface of a 3D tileset.
25 */
27 /**
28 * No specified Height Reference. Used only for HeightReferenceOverride
29 * in the CesiumGlobeAnchor Blueprints. Do not use otherwise.
30 */
32};
33
34/**
35 * This component can be added to a movable actor to anchor it to the globe
36 * and maintain precise placement. When the owning actor is transformed through
37 * normal Unreal Engine mechanisms, the internal geospatial coordinates will be
38 * automatically updated. The actor position can also be set in terms of
39 * Earth-Centered, Earth-Fixed coordinates (ECEF) or Longitude, Latitude, and
40 * Height relative to the ellipsoid.
41 */
42UCLASS(ClassGroup = Cesium, Meta = (BlueprintSpawnableComponent))
43class CESIUMRUNTIME_API UCesiumGlobeAnchorComponent : public UActorComponent {
44 GENERATED_BODY()
45
46#pragma region Properties
47private:
48 /**
49 * The designated georeference actor controlling how the owning actor's
50 * coordinate system relates to the coordinate system in this Unreal Engine
51 * level.
52 *
53 * If this is null, the Component will find and use the first Georeference
54 * Actor in the level, or create one if necessary. To get the active/effective
55 * Georeference from Blueprints or C++, use ResolvedGeoreference instead.
56 *
57 * If setting this property changes the CesiumGeoreference, the globe position
58 * will be maintained and the Actor's transform will be updated according to
59 * the new CesiumGeoreference.
60 */
61 UPROPERTY(
62 EditAnywhere,
63 BlueprintReadWrite,
64 BlueprintGetter = GetGeoreference,
65 BlueprintSetter = SetGeoreference,
66 Category = "Cesium",
67 Meta = (AllowPrivateAccess))
68 TSoftObjectPtr<ACesiumGeoreference> Georeference = nullptr;
69
70 /**
71 * The frame of reference in which to interpret the object's height.
72 *
73 * `Ellipsoid` indicates the object's height above the ellipsoid set on the
74 * CesiumGeoreference. The object will remain at this height unless it is
75 * otherwise changed.
76 *
77 * `Tileset` indicates a height above a given tileset. The object will move
78 * vertically to maintain the specified height.
79 */
80 UPROPERTY(
81 EditAnywhere,
82 BlueprintReadWrite,
83 BlueprintGetter = GetHeightReference,
84 BlueprintSetter = SetHeightReference,
85 Category = "Cesium",
86 Meta =
87 (AllowPrivateAccess,
88 ReturnDisplayName = "Height Reference",
89 InvalidEnumValues = "None"))
91
92 /**
93 * The tileset actor to use as a height reference for the object. The object
94 * will maintain its height relative to this tileset even through movement or
95 * level-of-detail transitions. Only used when `HeightReference` is set to
96 * `Tileset`.
97 */
98 UPROPERTY(
99 EditAnywhere,
100 BlueprintReadWrite,
101 BlueprintGetter = GetReferencedTileset,
102 BlueprintSetter = SetReferencedTileset,
103 Category = "Cesium",
104 Meta = (AllowPrivateAccess))
105 TSoftObjectPtr<ACesium3DTileset> ReferencedTileset = nullptr;
106
107 /**
108 * The interval, in Ticks, in which to update the object's height when
109 * `HeightReference` is set to `Tileset`.
110 *
111 * A value of 1 causes `Height` to be updated on every Tick.
112 */
113 UPROPERTY(
114 EditAnywhere,
115 BlueprintReadWrite,
116 BlueprintGetter = GetHeightUpdateInterval,
117 BlueprintSetter = SetHeightUpdateInterval,
118 Category = "Cesium",
119 Meta = (AllowPrivateAccess, ReturnDisplayName = "Height Update Interval"))
120 int HeightUpdateInterval = 1;
121
122 /**
123 * The resolved georeference used by this component. This is not serialized
124 * because it may point to a Georeference in the PersistentLevel while this
125 * component is in a sub-level. If the Georeference property is specified,
126 * however then this property will have the same value.
127 *
128 * This property will be null before ResolveGeoreference is called, which
129 * happens automatically when the component is registered.
130 */
131 UPROPERTY(
132 Transient,
133 VisibleAnywhere,
134 BlueprintReadOnly,
135 BlueprintGetter = GetResolvedGeoreference,
136 Category = "Cesium",
137 Meta = (AllowPrivateAccess))
138 ACesiumGeoreference* ResolvedGeoreference = nullptr;
139
140 /**
141 * Whether to adjust the Actor's orientation based on globe curvature as the
142 * Actor moves.
143 *
144 * The Earth is not flat, so as we move across its surface, the direction of
145 * "up" changes. If we ignore this fact and leave an object's orientation
146 * unchanged as it moves over the globe surface, the object will become
147 * increasingly tilted and eventually be completely upside-down when we arrive
148 * at the opposite side of the globe.
149 *
150 * When this setting is enabled, this Component will automatically apply a
151 * rotation to the Actor to account for globe curvature any time the Actor's
152 * position on the globe changes.
153 *
154 * This property should usually be enabled, but it may be useful to disable it
155 * when your application already accounts for globe curvature itself when it
156 * updates an Actor's position and orientation, because in that case the Actor
157 * would be over-rotated.
158 */
159 UPROPERTY(
160 EditAnywhere,
161 BlueprintReadWrite,
164 Category = "Cesium",
165 Meta = (AllowPrivateAccess))
166 bool AdjustOrientationForGlobeWhenMoving = true;
167
168 /**
169 * Whether to automatically detect changes in the Actor's root transform and
170 * update the precise globe coordinates accordingly.
171 *
172 * When this is property is false, the precise coordinates may become out of
173 * sync with the Actor's root transform. However, you can still directly set
174 * the precise coordinates, and its transform will update accordingly. You can
175 * also call Sync after changing the Actor's transform to manually update the
176 * precise coordinates.
177 *
178 * This property is ignored when `HeightReference` is set to `Tileset`.
179 */
180 UPROPERTY(
181 EditAnywhere,
182 BlueprintReadWrite,
183 BlueprintGetter = GetDetectTransformChanges,
184 BlueprintSetter = SetDetectTransformChanges,
185 Category = "Cesium",
186 Meta = (AllowPrivateAccess))
187 bool DetectTransformChanges = true;
188
189 /**
190 * Using the teleport flag will move objects to the updated transform
191 * immediately and without affecting their velocity. This is useful when
192 * working with physics actors that maintain an internal velocity which we do
193 * not want to change when updating location.
194 */
195 UPROPERTY(
196 EditAnywhere,
197 BlueprintReadWrite,
198 BlueprintGetter = GetTeleportWhenUpdatingTransform,
199 BlueprintSetter = SetTeleportWhenUpdatingTransform,
200 Category = "Cesium",
201 Meta = (AllowPrivateAccess))
202 bool TeleportWhenUpdatingTransform = true;
203
204 /**
205 * The 4x4 transformation matrix from the Actor's local coordinate system to
206 * the Earth-Centered, Earth-Fixed (ECEF) coordinate system.
207 *
208 * The ECEF coordinate system is a right-handed system located at the center
209 * of the Earth. The +X axis points to the intersection of the Equator and
210 * Prime Meridian (zero degrees longitude). The +Y axis points to the
211 * intersection of the Equator and +90 degrees longitude. The +Z axis points
212 * up through the North Pole.
213 *
214 * If `AdjustOrientationForGlobeWhenMoving` is enabled and this property is
215 * set, the Actor's orientation will also be adjusted to account for globe
216 * curvature.
217 */
218 UPROPERTY(
219 BlueprintReadWrite,
222 Category = "Cesium",
223 Meta = (AllowPrivateAccess))
224 FMatrix ActorToEarthCenteredEarthFixedMatrix;
225
226#pragma endregion
227
228#pragma region Property Accessors
229public:
230 /**
231 * Gets the designated georeference actor controlling how the owning actor's
232 * coordinate system relates to the coordinate system in this Unreal Engine
233 * level.
234 *
235 * If this is null, the Component will find and use the first Georeference
236 * Actor in the level, or create one if necessary. To get the active/effective
237 * Georeference from Blueprints or C++, use ResolvedGeoreference instead.
238 */
239 UFUNCTION(BlueprintGetter)
240 TSoftObjectPtr<ACesiumGeoreference> GetGeoreference() const;
241
242 /**
243 * Sets the designated georeference actor controlling how the owning actor's
244 * coordinate system relates to the coordinate system in this Unreal Engine
245 * level.
246 *
247 * If this is null, the Component will find and use the first Georeference
248 * Actor in the level, or create one if necessary. To get the active/effective
249 * Georeference from Blueprints or C++, use ResolvedGeoreference instead.
250 */
251 UFUNCTION(BlueprintSetter)
252 void
253 SetGeoreference(const TSoftObjectPtr<ACesiumGeoreference>& NewGeoreference);
254
255 UFUNCTION(BlueprintGetter, Category = "Cesium")
257
258 UFUNCTION(BlueprintSetter, Category = "Cesium")
260
261 UFUNCTION(
262 BlueprintGetter,
263 Category = "Cesium",
264 Meta = (ReturnDisplayName = "Referenced Tileset"))
265 TSoftObjectPtr<ACesium3DTileset> GetReferencedTileset() const;
266
267 UFUNCTION(BlueprintSetter, Category = "Cesium")
268 void SetReferencedTileset(const TSoftObjectPtr<ACesium3DTileset>& NewTileset);
269
270 UFUNCTION(BlueprintGetter, Category = "Cesium")
272
273 UFUNCTION(BlueprintSetter, Category = "Cesium")
274 void SetHeightUpdateInterval(int NewHeightReferenceUpdateInterval);
275
276 /**
277 * Gets the resolved georeference used by this component. This is not
278 * serialized because it may point to a Georeference in the PersistentLevel
279 * while this component is in a sub-level. If the Georeference property is
280 * manually specified, however, then this property will have the same value.
281 *
282 * This property will be null before ResolveGeoreference is called, which
283 * happens automatically when the component is registered.
284 */
285 UFUNCTION(BlueprintGetter, Category = "Cesium")
287
288 /**
289 * Resolves the Cesium Georeference to use with this Component. Returns
290 * the value of the Georeference property if it is set. Otherwise, finds a
291 * Georeference in the World and returns it, creating it if necessary. The
292 * resolved Georeference is cached so subsequent calls to this function will
293 * return the same instance, unless ForceReresolve is true.
294 */
295 UFUNCTION(BlueprintCallable, Category = "Cesium")
296 ACesiumGeoreference* ResolveGeoreference(bool bForceReresolve = false);
297
298 /**
299 * Obtains the (@ref UCesiumEllipsoid) set on the georeference used by this
300 * component.
301 */
302 UFUNCTION(BlueprintGetter, Category = "Cesium")
304
305 /**
306 * Gets the 4x4 transformation matrix from the Actor's local coordinate
307 * system to the Earth-Centered, Earth-Fixed (ECEF) coordinate system.
308 *
309 * The ECEF coordinate system is a right-handed system located at the center
310 * of the Earth. The +X axis points to the intersection of the Equator and
311 * Prime Meridian (zero degrees longitude). The +Y axis points to the
312 * intersection of the Equator and +90 degrees longitude. The +Z axis points
313 * up through the North Pole.
314 */
315 UFUNCTION(BlueprintGetter, Category = "Cesium")
317
318 /**
319 * Sets the 4x4 transformation matrix from the Actor's local coordinate
320 * system to the Earth-Centered, Earth-Fixed (ECEF) coordinate system.
321 *
322 * The ECEF coordinate system is a right-handed system located at the center
323 * of the Earth. The +X axis points to the intersection of the Equator and
324 * Prime Meridian (zero degrees longitude). The +Y axis points to the
325 * intersection of the Equator and +90 degrees longitude. The +Z axis points
326 * up through the North Pole.
327 *
328 * If `AdjustOrientationForGlobeWhenMoving` is enabled, the Actor's
329 * orientation will also be adjusted to account for globe curvature.
330 */
331 UFUNCTION(BlueprintSetter, Category = "Cesium")
332 void SetActorToEarthCenteredEarthFixedMatrix(const FMatrix& Value);
333
334 /**
335 * Gets a flag indicating whether to move objects to the updated transform
336 * immediately and without affecting their velocity. This is useful when
337 * working with physics actors that maintain an internal velocity which we do
338 * not want to change when updating location.
339 */
340 UFUNCTION(BlueprintGetter, Category = "Cesium")
342
343 /**
344 * Sets a flag indicating whether to move objects to the updated transform
345 * immediately and without affecting their velocity. This is useful when
346 * working with physics actors that maintain an internal velocity which we do
347 * not want to change when updating location.
348 */
349 UFUNCTION(BlueprintSetter, Category = "Cesium")
351
352 /**
353 * Gets a flag indicating whether to adjust the Actor's orientation based on
354 * globe curvature as the Actor moves.
355 *
356 * The Earth is not flat, so as we move across its surface, the direction of
357 * "up" changes. If we ignore this fact and leave an object's orientation
358 * unchanged as it moves over the globe surface, the object will become
359 * increasingly tilted and eventually be completely upside-down when we arrive
360 * at the opposite side of the globe.
361 *
362 * When this setting is enabled, this Component will automatically apply a
363 * rotation to the Actor to account for globe curvature any time the Actor's
364 * position on the globe changes.
365 *
366 * This property should usually be enabled, but it may be useful to disable it
367 * when your application already accounts for globe curvature itself when it
368 * updates an Actor's position and orientation, because in that case the Actor
369 * would be over-rotated.
370 */
371 UFUNCTION(BlueprintGetter, Category = "Cesium")
373
374 /**
375 * Sets a flag indicating whether to adjust the Actor's orientation based on
376 * globe curvature as the Actor moves.
377 *
378 * The Earth is not flat, so as we move across its surface, the direction of
379 * "up" changes. If we ignore this fact and leave an object's orientation
380 * unchanged as it moves over the globe surface, the object will become
381 * increasingly tilted and eventually be completely upside-down when we arrive
382 * at the opposite side of the globe.
383 *
384 * When this setting is enabled, this Component will automatically apply a
385 * rotation to the Actor to account for globe curvature any time the Actor's
386 * position on the globe changes.
387 *
388 * This property should usually be enabled, but it may be useful to disable it
389 * when your application already accounts for globe curvature itself when it
390 * updates an Actor's position and orientation, because in that case the Actor
391 * would be over-rotated.
392 */
393 UFUNCTION(BlueprintSetter, Category = "Cesium")
395
396 /**
397 * Gets a flag indicating whether to update the globe anchor when the Actor's
398 * transform changes.
399 *
400 * This property should usually be enabled, but it may be useful to disable it
401 * for performance reasons.
402 */
403 UFUNCTION(BlueprintGetter, Category = "Cesium")
405
406 /**
407 * Sets a flag indicating whether to update the globe anchor when the Actor's
408 * transform changes.
409 *
410 * This property should usually be enabled, but it may be useful to disable it
411 * for performance reasons.
412 */
413
414 UFUNCTION(BlueprintSetter, Category = "Cesium")
416
417#pragma endregion
418
419#pragma region Public Methods
421
422public:
423 /**
424 * Gets the longitude in degrees (X), latitude in degrees (Y), and height in
425 * meters relative to the specified height reference.
426 *
427 * `HeightReferenceOverride` can be optionally used to change the height
428 * reference in which the value is returned. When this is `None`, the
429 * `HeightReference` on the component will be used.
430 *
431 * For a `Tileset` height reference, if a `ReferencedTileset` is set, the
432 * returned value is the height in meters above the reference tileset.
433 *
434 * For an `Ellipsoid` height reference, the returned value is the height above
435 * the ellipsoid in meters. Do not confuse the ellipsoid height with a geoid
436 * height or height above mean sea level, which can be tens of meters higher
437 * or lower depending on where in the world the object is located.
438 */
439 UFUNCTION(
440 BlueprintPure,
441 Category = "Cesium",
442 Meta = (ReturnDisplayName = "LongitudeLatitudeHeight"))
444 const ECesiumHeightReference HeightReferenceOverride =
446
447 /**
448 * Gets the longitude in degrees.
449 */
450 UFUNCTION(
451 BlueprintPure,
452 Category = "Cesium",
453 Meta = (ReturnDisplayName = "Longitude"))
454 double GetLongitude() const { return this->GetLongitudeLatitudeHeight().X; }
455
456 /**
457 * Gets the latitude in degrees.
458 */
459 UFUNCTION(
460 BlueprintPure,
461 Category = "Cesium",
462 Meta = (ReturnDisplayName = "Latitude"))
463 double GetLatitude() const { return this->GetLongitudeLatitudeHeight().Y; }
464
465 /**
466 * Gets the height in meters above the specified height reference.
467 *
468 * `HeightReferenceOverride` can be optionally used to change the height
469 * reference in which the value is returned. When this is `None`, the
470 * `HeightReference` on the component will be used.
471 *
472 * For a `Tileset` height reference, if a `ReferencedTileset` is set, the
473 * returned value is the height in meters above the reference tileset.
474 *
475 * For an `Ellipsoid` height reference, the returned value is the height above
476 * the ellipsoid in meters. Do not confuse the ellipsoid height with a geoid
477 * height or height above mean sea level, which can be tens of meters higher
478 * or lower depending on where in the world the object is located.
479 */
480 UFUNCTION(
481 BlueprintPure,
482 Category = "Cesium",
483 Meta = (ReturnDisplayName = "Height"))
484 double GetHeight(
485 const ECesiumHeightReference HeightReferenceOverride =
487
488 /**
489 * Moves the Actor to which this component is attached to a given longitude in
490 * degrees (X), latitude in degrees (Y), and height in meters (Z) above the
491 * specified height reference.
492 *
493 * `HeightReferenceOverride` can be optionally used to change the height
494 * reference in which the value is returned. When this is `None`, the
495 * `HeightReference` on the component will be used.
496 *
497 * For a `Tileset` height reference, if a `ReferencedTileset` is set, the
498 * returned value is the height in meters above the reference tileset.
499 *
500 * For an `Ellipsoid` height reference, the returned value is the height above
501 * the ellipsoid in meters. Do not confuse the ellipsoid height with a geoid
502 * height or height above mean sea level, which can be tens of meters higher
503 * or lower depending on where in the world the object is located.
504 *
505 * If `AdjustOrientationForGlobeWhenMoving` is enabled, the Actor's
506 * orientation will also be adjusted to account for globe curvature.
507 */
508 UFUNCTION(BlueprintCallable, Category = "Cesium")
510 const FVector& LongitudeLatitudeHeight,
511 const ECesiumHeightReference HeightReferenceOverride =
513
514 /**
515 * Gets the Earth-Centered, Earth-Fixed (ECEF) coordinates of the Actor in
516 * meters.
517 */
518 UFUNCTION(
519 BlueprintPure,
520 Category = "Cesium",
521 meta = (ReturnDisplayName = "EarthCenteredEarthFixedPosition"))
523
524 /**
525 * Moves the Actor to which this component is attached to a given globe
526 * position in Earth-Centered, Earth-Fixed coordinates in meters.
527 *
528 * If AdjustOrientationForGlobeWhenMoving is enabled, this method will
529 * also update the orientation based on the globe curvature.
530 *
531 * @param EarthCenteredEarthFixedPosition The new position.
532 */
533 UFUNCTION(BlueprintCallable, Category = "Cesium")
535 const FVector& EarthCenteredEarthFixedPosition);
536
537 /**
538 * Gets the rotation of the Actor relative to a local coordinate system
539 * centered on this object where the +X points in the local East direction,
540 * the +Y axis points in the local South direction, and the +Z axis points in
541 * the local Up direction.
542 */
543 UFUNCTION(
544 BlueprintPure,
545 Category = "Cesium",
546 meta = (ReturnDisplayName = "EastSouthUpRotation"))
548
549 /**
550 * Sets the rotation of the Actor relative to a local coordinate system
551 * centered on this object where the +X points in the local East direction,
552 * the +Y axis points in the local South direction, and the +Z axis points in
553 * the local Up direction.
554 *
555 * When the rotation is set via this method, it is internally converted to
556 * and stored in the ActorToEarthCenteredEarthFixedMatrix property. As a
557 * result, getting this property will not necessarily return the exact value
558 * that was set.
559 */
560 UFUNCTION(BlueprintCallable, Category = "Cesium")
561 void SetEastSouthUpRotation(const FQuat& EastSouthUpRotation);
562
563 /**
564 * Gets the rotation of the Actor relative to the Earth-Centered, Earth-Fixed
565 * (ECEF) coordinate system.
566 *
567 * The ECEF coordinate system is a right-handed system located at the center
568 * of the Earth. The +X axis points from there to the intersection of the
569 * Equator and Prime Meridian (zero degrees longitude). The +Y axis points to
570 * the intersection of the Equator and +90 degrees longitude. The +Z axis
571 * points up through the North Pole.
572 */
573 UFUNCTION(
574 BlueprintPure,
575 Category = "Cesium",
576 meta = (ReturnDisplayName = "EarthCenteredEarthFixedRotation"))
578
579 /**
580 * Sets the rotation of the Actor relative to the Earth-Centered, Earth-Fixed
581 * (ECEF) coordinate system.
582 *
583 * The ECEF coordinate system is a right-handed system located at the center
584 * of the Earth. The +X axis points from there to the intersection of the
585 * Equator and Prime Meridian (zero degrees longitude). The +Y axis points to
586 * the intersection of the Equator and +90 degrees longitude. The +Z axis
587 * points up through the North Pole.
588 */
589 UFUNCTION(BlueprintCallable, Category = "Cesium")
591 const FQuat& EarthCenteredEarthFixedRotation);
592
593 /**
594 * Rotates the Actor so that its local +Z axis is aligned with the ellipsoid
595 * surface normal at its current location.
596 */
597 UFUNCTION(BlueprintCallable, Category = "Cesium")
599
600 /**
601 * Rotates the Actor so that its +X axis points in the local East direction,
602 * its +Y axis points in the local South direction, and its +Z axis points in
603 * the local Up direction.
604 */
605 UFUNCTION(BlueprintCallable, Category = "Cesium")
607
608 /**
609 * Synchronizes the properties of this globe anchor.
610 *
611 * It is usually not necessary to call this method because it is called
612 * automatically when needed.
613 *
614 * This method performs the following actions:
615 *
616 * - If the ActorToEarthCenteredEarthFixedMatrix has not yet been
617 * determined, it is computed from the Actor's current root transform.
618 * - If the Actor's root transform has changed since the last time this
619 * component was registered, this method updates the
620 * ActorToEarthCenteredEarthFixedMatrix from the current transform.
621 * - If the origin of the CesiumGeoreference has changed, the Actor's root
622 * transform is updated based on the ActorToEarthCenteredEarthFixedMatrix and
623 * the new georeference origin.
624 * - This synchronization works even if DetectTransformChanges is false.
625 */
626 UFUNCTION(BlueprintCallable, Category = "Cesium")
627 void Sync();
628
629#pragma endregion
630
631#pragma region Obsolete
632public:
633 /**
634 * @brief DEPRECATED
635 * @deprecated The resolved georeference can no longer be explicitly
636 * invalidated. To change the georeference, call SetGeoreference or
637 * ReregisterComponent.
638 */
639 UE_DEPRECATED(
640 "Cesium For Unreal v2.0",
641 "The resolved georeference can no longer be explicitly invalidated. To change the georeference, call SetGeoreference or ReregisterComponent.")
642 UFUNCTION(
643 BlueprintCallable,
644 Category = "Cesium",
645 Meta =
646 (DeprecatedFunction,
647 DeprecationMessage =
648 "The resolved georeference can no longer be explicitly invalidated. To change the georeference, call SetGeoreference or ReregisterComponent."))
650#pragma endregion
651
652#pragma region Unreal Lifecycle
653protected:
654 /**
655 * Handles reading, writing, and reference collecting using FArchive.
656 * This implementation handles all FProperty serialization, but can be
657 * overridden for native variables.
658 *
659 * This class overrides this method to ensure internal variables are
660 * immediately synchronized with newly-loaded values.
661 */
662 virtual void Serialize(FArchive& Ar) override;
663
664 /**
665 * Called when a component is created (not loaded). This can happen in the
666 * editor or during gameplay.
667 *
668 * This method is invoked after this component is pasted and just prior to
669 * registration. We mark the globe transform invalid here because we can't
670 * assume the globe transform is still valid when the component is pasted into
671 * another Actor, or even if the Actor was changed since the Component was
672 * copied.
673 */
674 virtual void OnComponentCreated() override;
675
676#if WITH_EDITOR
677 virtual void
678 PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
679#endif
680
681 /**
682 * Called when a component is registered. This can be viewed as "enabling"
683 * this Component on the Actor to which it is attached.
684 *
685 * In the Editor, this is called in a many different situations, such as on
686 * changes to properties.
687 */
688 virtual void OnRegister() override;
689
690 /**
691 * Called when a component is unregistered. This can be viewed as
692 * "disabling" this Component on the Actor to which it is attached.
693 *
694 * In the Editor, this is called in a many different situations, such as on
695 * changes to properties.
696 */
697 virtual void OnUnregister() override;
698#pragma endregion
699
700protected:
701 virtual void TickComponent(
702 float DeltaTime,
703 ELevelTick TickType,
704 FActorComponentTickFunction* ThisTickFunction) override;
705
706#pragma region Implementation Details
707private:
708 int _heightReferenceUpdateCounter = 0;
709
710 /**
711 * When HeightReference is Tileset, this is the target height
712 * above the tileset to maintain.
713 */
714 UPROPERTY()
715 float _fixedHeightAboveHeightReference = 0.0f;
716
717 /**
718 * Calculate correct Height from the actor's position based on the
719 * HeightReference and tileset.
720 */
721 bool _setHeightFromTilesetReference();
722
723 /**
724 * Determines if HeightReference is Tileset and ReferencedTileset is set.
725 */
726 bool _isUsingTilesetHeightReference(
727 const ECesiumHeightReference heightReferenceOverride =
729
730 /**
731 * Compute a down vector at the specified position in Unreal coordinates
732 */
733 FVector _computeLocalDown(
734 const ACesiumGeoreference* pGeoreference,
735 const FVector& unrealWorldPosition) const;
736
737 /**
738 * Project the component's position onto the tileset specified by
739 * ReferencedTileset, Returns whether an intersection was found.
740 *
741 * alternateActorPosition optionally specifies an alternate position from
742 * which to start the intersection test in Longitude/Latitude/Height
743 * coordinates.
744 */
745 bool _queryLongitudeLatitudeHeightPositionOnTileset(
746 FVector& groundIntersection,
747 const std::optional<FVector>& alternateStartPosition = std::nullopt);
748
749 CesiumGeospatial::GlobeAnchor _createNativeGlobeAnchor() const;
750
751 USceneComponent* _getRootComponent(bool warnIfNull) const;
752
753 FTransform _getCurrentRelativeTransform() const;
754
755 void _setCurrentRelativeTransform(const FTransform& relativeTransform);
756
757 CesiumGeospatial::GlobeAnchor
758 _createOrUpdateNativeGlobeAnchorFromRelativeTransform(
759 const FTransform& newRelativeTransform);
760
761 CesiumGeospatial::GlobeAnchor
762 _createOrUpdateNativeGlobeAnchorFromECEF(const FMatrix& newActorToECEFMatrix);
763
764 void _updateFromNativeGlobeAnchor(
765 const CesiumGeospatial::GlobeAnchor& nativeAnchor);
766
767 void _setNewActorToECEFFromRelativeTransform();
768
769#if WITH_EDITORONLY_DATA
770 // This is used only to preserve the transformation saved by old versions of
771 // Cesium for Unreal. See the Serialize method.
772 UPROPERTY(Meta = (DeprecatedProperty))
773 double _actorToECEF_Array_DEPRECATED[16];
774#endif
775
776 /**
777 * True if the globe transform is a valid and correct representation of the
778 * position and orientation of this Actor. False if the globe transform has
779 * not yet been computed and so the Actor transform is the only valid
780 * representation of the Actor's position and orientation.
781 */
782 UPROPERTY()
783 bool _actorToECEFIsValid = false;
784
785 /**
786 * Whether an update of the actor transform is currently in progress,
787 * and further calls that are received by _onActorTransformChanged
788 * should be ignored
789 */
790 bool _updatingActorTransform = false;
791
792 bool _lastRelativeTransformIsValid = false;
793 FTransform _lastRelativeTransform{};
794
795 /**
796 * Called when the root transform of the Actor to which this Component is
797 * attached has changed. So:
798 * * The globe (ECEF) position and orientation are computed from the new
799 * transform.
800 * * When `AdjustOrientationForGlobeWhenMoving` is enabled, the orientation
801 * will also be adjusted for globe curvature.
802 */
803 void _onActorTransformChanged(
804 USceneComponent* InRootComponent,
805 EUpdateTransformFlags UpdateTransformFlags,
806 ETeleportType Teleport);
807
808 /**
809 * Called when the Component switches to a new Georeference Actor or the
810 * existing Georeference is given a new origin Longitude, Latitude, or
811 * Height. The Actor's position and orientation are recomputed from the
812 * Component's globe (ECEF) position and orientation.
813 */
814 UFUNCTION(CallInEditor)
815 void _onGeoreferenceChanged();
816
818#pragma endregion
819};
ECesiumHeightReference
The frame of reference from which to interpret a given height value.
@ Tileset
Height is interpreted relative to the surface of a 3D tileset.
@ None
No specified Height Reference.
@ Ellipsoid
Height is interpreted relative to the ellipsoid.
Controls how global geospatial coordinates are mapped to coordinates in the Unreal Engine level.
void SetReferencedTileset(const TSoftObjectPtr< ACesium3DTileset > &NewTileset)
double GetHeight(const ECesiumHeightReference HeightReferenceOverride=ECesiumHeightReference::None) const
Gets the height in meters above the specified height reference.
FVector GetLongitudeLatitudeHeight(const ECesiumHeightReference HeightReferenceOverride=ECesiumHeightReference::None) const
Gets the longitude in degrees (X), latitude in degrees (Y), and height in meters relative to the spec...
FQuat GetEastSouthUpRotation() const
Gets the rotation of the Actor relative to a local coordinate system centered on this object where th...
FVector GetEarthCenteredEarthFixedPosition() const
Gets the Earth-Centered, Earth-Fixed (ECEF) coordinates of the Actor in meters.
void SetEastSouthUpRotation(const FQuat &EastSouthUpRotation)
Sets the rotation of the Actor relative to a local coordinate system centered on this object where th...
virtual void OnUnregister() override
Called when a component is unregistered.
TSoftObjectPtr< ACesium3DTileset > GetReferencedTileset() const
ECesiumHeightReference GetHeightReference() const
virtual void OnComponentCreated() override
Called when a component is created (not loaded).
void SetDetectTransformChanges(bool Value)
Sets a flag indicating whether to update the globe anchor when the Actor's transform changes.
void SetHeightReference(ECesiumHeightReference NewHeightReference)
void MoveToEarthCenteredEarthFixedPosition(const FVector &EarthCenteredEarthFixedPosition)
Moves the Actor to which this component is attached to a given globe position in Earth-Centered,...
int GetHeightUpdateInterval() const
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override
FMatrix GetActorToEarthCenteredEarthFixedMatrix() const
Gets the 4x4 transformation matrix from the Actor's local coordinate system to the Earth-Centered,...
virtual void Serialize(FArchive &Ar) override
Handles reading, writing, and reference collecting using FArchive.
void SetAdjustOrientationForGlobeWhenMoving(bool Value)
Sets a flag indicating whether to adjust the Actor's orientation based on globe curvature as the Acto...
bool GetTeleportWhenUpdatingTransform() const
Gets a flag indicating whether to move objects to the updated transform immediately and without affec...
void Sync()
Synchronizes the properties of this globe anchor.
void SnapLocalUpToEllipsoidNormal()
Rotates the Actor so that its local +Z axis is aligned with the ellipsoid surface normal at its curre...
void SetHeightUpdateInterval(int NewHeightReferenceUpdateInterval)
void SetActorToEarthCenteredEarthFixedMatrix(const FMatrix &Value)
Sets the 4x4 transformation matrix from the Actor's local coordinate system to the Earth-Centered,...
virtual void OnRegister() override
Called when a component is registered.
TSoftObjectPtr< ACesiumGeoreference > GetGeoreference() const
Gets the designated georeference actor controlling how the owning actor's coordinate system relates t...
void SetGeoreference(const TSoftObjectPtr< ACesiumGeoreference > &NewGeoreference)
Sets the designated georeference actor controlling how the owning actor's coordinate system relates t...
void SetTeleportWhenUpdatingTransform(bool Value)
Sets a flag indicating whether to move objects to the updated transform immediately and without affec...
void SetEarthCenteredEarthFixedRotation(const FQuat &EarthCenteredEarthFixedRotation)
Sets the rotation of the Actor relative to the Earth-Centered, Earth-Fixed (ECEF) coordinate system.
void InvalidateResolvedGeoreference()
DEPRECATED.
void MoveToLongitudeLatitudeHeight(const FVector &LongitudeLatitudeHeight, const ECesiumHeightReference HeightReferenceOverride=ECesiumHeightReference::None)
Moves the Actor to which this component is attached to a given longitude in degrees (X),...
bool GetDetectTransformChanges() const
Gets a flag indicating whether to update the globe anchor when the Actor's transform changes.
void SnapToEastSouthUp()
Rotates the Actor so that its +X axis points in the local East direction, its +Y axis points in the l...
bool GetAdjustOrientationForGlobeWhenMoving() const
Gets a flag indicating whether to adjust the Actor's orientation based on globe curvature as the Acto...
UCesiumEllipsoid * GetEllipsoid() const
Obtains the (UCesiumEllipsoid) set on the georeference used by this component.
ACesiumGeoreference * GetResolvedGeoreference() const
Gets the resolved georeference used by this component.
FQuat GetEarthCenteredEarthFixedRotation() const
Gets the rotation of the Actor relative to the Earth-Centered, Earth-Fixed (ECEF) coordinate system.
ACesiumGeoreference * ResolveGeoreference(bool bForceReresolve=false)
Resolves the Cesium Georeference to use with this Component.
double GetLatitude() const
Gets the latitude in degrees.
double GetLongitude() const
Gets the longitude in degrees.
STL namespace.