3using System.Collections.Generic;
4using Unity.Mathematics;
86 [ReinteropNativeImplementation(
"CesiumForUnityNative::CesiumGeoreferenceImpl",
"CesiumGeoreferenceImpl.h")]
87 [AddComponentMenu(
"Cesium/Cesium Georeference")]
88 [IconAttribute(
"Packages/com.cesium.unity/Editor/Resources/Cesium-24x24.png")]
102 private double _latitude = 39.736401;
105 private double _longitude = -105.25737;
109 private double _height = 2250.0;
113 private double _ecefX = 6378137.0;
117 private double _ecefY = 0.0;
121 private double _ecefZ = 0.0;
124 private double _scale = 1.0;
127 private double4x4 _localToEcef = double4x4.identity;
130 private double4x4 _ecefToLocal = double4x4.identity;
133 private bool _isInitialized =
false;
136 private HashSet<CesiumGlobeAnchor> _globeAnchors =
new HashSet<CesiumGlobeAnchor>();
157 get => this._originPlacement;
160 this._originPlacement = value;
174 get => this._originAuthority;
177 this._originAuthority = value;
194 get => this._latitude;
197 this._latitude = Math.Clamp(value, -90, 90);
214 get => this._longitude;
217 this._longitude = Math.Clamp(value, -180, 180);
239 this._height = value;
327 return this._localToEcef;
336 return this._ecefToLocal;
347 if (this._ellipsoid ==
null)
354 return this._ellipsoid;
358 this._ellipsoid = value;
365 [Tooltip(
"An event raised when the georeference origin changes.")]
419 this._globeAnchors.Add(globeAnchor);
433 this._globeAnchors.Remove(globeAnchor);
456 if (!this._isInitialized)
458 this._isInitialized =
true;
459 this.UpdateOtherCoordinates();
460 this.UpdateTransformations();
470 this._ellipsoid =
null;
471 this.UpdateTransformations();
472 this.UpdateOtherCoordinates();
474 Cesium3DTileset[] tilesets = GetComponentsInChildren<Cesium3DTileset>();
475 foreach (var tileset
in tilesets)
477 tileset.RecreateTileset();
481 private void UpdateTransformations()
483 this._localToEcef = this.ComputeLocalToEarthCenteredEarthFixedTransformation();
484 this._ecefToLocal = math.inverse(this._localToEcef);
493 if (!this._isInitialized)
494 throw new InvalidOperationException(
"The origin of a CesiumGeoreference must not be set before its Initialize method is called, either explicitly or via OnEnable.");
497 if (this._scale < 1e-8)
500 this.UpdateOtherCoordinates();
502 double4x4 oldLocalToEcef = this._localToEcef;
504 this.UpdateTransformations();
506 if (oldLocalToEcef.Equals(
this._localToEcef))
520 if (this.changed !=
null)
526 private void OnValidate()
528 if (this._isInitialized)
534 private void OnEnable()
539 private void OnDisable()
541 this._isInitialized =
false;
544 private void UpdateOtherCoordinates()
550 new double3(this._longitude, this._latitude, this._height));
551 this._ecefX = ecef.x;
552 this._ecefY = ecef.y;
553 this._ecefZ = ecef.z;
559 new double3(this._ecefX, this._ecefY, this._ecefZ));
560 this._longitude = llh.x;
561 this._latitude = llh.y;
562 this._height = llh.z;
578 return math.mul(this._localToEcef,
new double4(unityPosition, 1.0)).xyz;
593 return math.mul(this._ecefToLocal,
new double4(earthCenteredEarthFixed, 1.0)).xyz;
608 return math.mul(this._localToEcef,
new double4(unityDirection, 0.0)).xyz;
623 return math.mul(this._ecefToLocal,
new double4(earthCenteredEarthFixedDirection, 0.0)).xyz;
626 private partial double4x4 ComputeLocalToEarthCenteredEarthFixedTransformation();
A tileset in the 3D Tiles format.
static CesiumEllipsoid WGS84
Obtain a WGS84 ellipsoid.
partial double3 LongitudeLatitudeHeightToCenteredFixed(double3 longitudeLatitudeHeight)
Convert longitude, latitude, and height to Ellipsoid-Centered, Ellipsoid-Fixed (ECEF) coordinates.
partial void SetRadii(double3 newRadii)
Sets the radii of this ellipsoid to the given values.
partial double3 CenteredFixedToLongitudeLatitudeHeight(double3 ellipsoidCenteredEllipsoidFixed)
Convert Ellipsoid-Centered, Ellipsoid-Fixed (ECEF) coordinates to longitude, latitude,...
Controls how global geospatial coordinates are mapped to coordinates in the Unity scene.
double3 TransformEarthCenteredEarthFixedPositionToUnity(double3 earthCenteredEarthFixed)
Transform an Earth-Centered, Earth-Fixed position to Unity coordinates.
double scale
The scale of the globe in the Unity world.
void AddGlobeAnchor(CesiumGlobeAnchor globeAnchor)
Register a globe anchor with this georeference.
double ecefZ
The Earth-Centered, Earth-Fixed Z coordinate of the origin of the coordinate system,...
double3 TransformUnityDirectionToEarthCenteredEarthFixed(double3 unityDirection)
Transform a Unity direction to a direction in Earth-Centered, Earth-Fixed (ECEF) coordinates.
CesiumGeoreferenceOriginAuthority originAuthority
Identifies which set of coordinates authoritatively defines the origin of this georeference.
double ecefX
The Earth-Centered, Earth-Fixed X coordinate of the origin of the coordinate system,...
double4x4 ecefToLocalMatrix
void SetOriginLongitudeLatitudeHeight(double longitude, double latitude, double height)
Sets the origin of the coordinate system to a particular longitude, latitude, and height.
CesiumGeoreferenceOriginPlacement originPlacement
The placement of this GameObject's origin (coordinate 0,0,0) within the tileset.
double latitude
The latitude of the origin of the coordinate system, in degrees, in the range -90 to 90.
double ecefY
The Earth-Centered, Earth-Fixed Y coordinate of the origin of the coordinate system,...
void Initialize()
Initializes this georeference so that other objects may use it to locate the globe in the world.
CesiumEllipsoid ellipsoid
The CesiumEllipsoid that is referenced.
double longitude
The longitude of the origin of the coordinate system, in degrees, in the range -180 to 180.
double height
The height in the origin of the coordinate system, in meters above the ellipsoid.
double3 TransformUnityPositionToEarthCenteredEarthFixed(double3 unityPosition)
Transform a Unity position to Earth-Centered, Earth-Fixed (ECEF) coordinates.
Action changed
An event raised when the georeference changes.
void MoveOrigin()
Recomputes the coordinate system based on an updated origin.
double4x4 localToEcefMatrix
void RemoveGlobeAnchor(CesiumGlobeAnchor globeAnchor)
Deregisters a globe anchor with this georeference, so the globe anchor will no longer be updated when...
void ReloadEllipsoid()
Called when the ellipsoid override property has changed.
void SetOriginEarthCenteredEarthFixed(double x, double y, double z)
Sets the origin of the coordinate system to particular ecefX, ecefY, ecefZ coordinates in the Earth-C...
double3 TransformEarthCenteredEarthFixedDirectionToUnity(double3 earthCenteredEarthFixedDirection)
Transform an Earth-Centered, Earth-Fixed direction to Unity coordinates.
Anchors this game object to the globe.
void Sync()
Synchronizes the properties of this CesiumGlobeAnchor.
CesiumGeoreferenceOriginPlacement
An enumeration of the possible strategies for placing the origin of a CesiumGeoreference.
@ CartographicOrigin
Use a custom position within the tileset as the GameObject's origin.
@ TrueOrigin
Use the tileset's true origin as the GameObject's origin.
CesiumGeoreferenceOriginAuthority
Identifies the set of the coordinates that authoritatively define the origin of a CesiumGeoreference.
@ EarthCenteredEarthFixed
The CesiumGeoreference.ecefX, CesiumGeoreference.ecefY, and CesiumGeoreference.ecefZ properties autho...
@ LongitudeLatitudeHeight
The CesiumGeoreference.longitude, CesiumGeoreference.latitude, and CesiumGeoreference....