27 private SplineContainer _splineContainer;
34 this._splineContainer = this.GetComponent<SplineContainer>();
35 this._globeAnchor = this.GetComponent<CesiumGlobeAnchor>();
40 if (this._splineContainer ==
null)
42 this._splineContainer = this.gameObject.AddComponent<SplineContainer>();
47 if (this._globeAnchor ==
null)
52#elif UNITY_2022_2_OR_NEWER
53 Debug.LogError(
"CesiumCartographicPolygon requires the Splines package, which is currently not installed " +
54 "in the project. Install the Splines package using the Package Manager.");
56 Debug.LogError(
"CesiumCartographicPolygon requires the Splines package, which is not available " +
57 "in this version of Unity.");
61#if SUPPORTS_SPLINES && UNITY_EDITOR
64 IReadOnlyList<Spline> splines = this._splineContainer.Splines;
65 for (
int i = splines.Count - 1; i >= 0; i--)
67 this._splineContainer.RemoveSpline(splines[i]);
70 Spline defaultSpline =
new Spline();
72 BezierKnot[] knots =
new BezierKnot[] {
73 new BezierKnot(
new float3(-100.0f, 0f, -100.0f)),
74 new BezierKnot(
new float3(100.0f, 0f, -100.0f)),
75 new BezierKnot(
new float3(100.0f, 0f, 100.0f)),
76 new BezierKnot(
new float3(-100.0f, 0f, 100.0f)),
79 defaultSpline.Knots = knots;
80 defaultSpline.Closed =
true;
81 defaultSpline.SetTangentMode(TangentMode.Linear);
83 this._splineContainer.AddSpline(defaultSpline);
87 static List<double2> emptyList =
new List<double2>();
89 internal List<double2> GetCartographicPoints(Matrix4x4 worldToTileset)
93 if (georeference ==
null)
98 IReadOnlyList<Spline> splines = this._splineContainer.Splines;
99 if (splines.Count == 0)
104 if (splines.Count > 1)
106 Debug.LogWarning(
"CesiumCartographicPolygon has multiple splines in its Spline component, " +
107 "but can only support one at a time. Only the first spline will be rasterized.");
110 Spline spline = splines[0];
113 Debug.LogError(
"Spline must be closed to be used as a cartographic polygon.");
117 BezierKnot[] knots = spline.ToArray();
118 List<double2> cartographicPoints =
new List<double2>(knots.Length);
120 float4x4 localToWorld = this.transform.localToWorldMatrix;
122 for (
int i = 0; i < knots.Length; i++)
124 if (spline.GetTangentMode(i) != TangentMode.Linear)
126 Debug.LogError(
"CesiumCartographicPolygon only supports linear splines.");
130 BezierKnot knot = knots[i];
138 float3 worldPosition = knot.Transform(localToWorld).Position;
139 float3 unityPosition = worldToTileset.MultiplyPoint3x4(worldPosition);
143 cartographicPoints.Add(cartographicPosition.xy);
146 return cartographicPoints;
partial double3 CenteredFixedToLongitudeLatitudeHeight(double3 ellipsoidCenteredEllipsoidFixed)
Convert Ellipsoid-Centered, Ellipsoid-Fixed (ECEF) coordinates to longitude, latitude,...