Cesium for Unity 1.15.2
Loading...
Searching...
No Matches
Cesium3DTileset.cs
Go to the documentation of this file.
1using Reinterop;
2using System;
3using System.Collections;
4using System.Collections.Generic;
5using System.Threading.Tasks;
6using Unity.Mathematics;
7using UnityEngine;
8
9namespace CesiumForUnity
10{
14 public enum CesiumDataSource
15 {
20
24 FromUrl,
25
30 }
31
49 [ExecuteInEditMode]
50 [ReinteropNativeImplementation("CesiumForUnityNative::Cesium3DTilesetImpl", "Cesium3DTilesetImpl.h")]
51 [AddComponentMenu("Cesium/Cesium 3D Tileset")]
52 [IconAttribute("Packages/com.cesium.unity/Editor/Resources/Cesium-24x24.png")]
53 public partial class Cesium3DTileset : MonoBehaviour, IDisposable, ISerializationCallbackReceiver
54 {
55 public void Dispose()
56 {
57 this.OnDisable();
58 this.DisposeImplementation();
59 }
60
61 #region Events and Delegates
62
67 public delegate void TilesetLoadFailureDelegate(
69
74
75 internal static void
76 BroadcastCesium3DTilesetLoadFailure(Cesium3DTilesetLoadFailureDetails details)
77 {
79 {
81 }
82 }
90 public event Action<GameObject> OnTileGameObjectCreated;
91
92 internal void BroadcastNewGameObjectCreated(GameObject go)
93 {
94 if (OnTileGameObjectCreated != null)
95 {
97 }
98 }
99
100 internal static event Action OnSetShowCreditsOnScreen;
101
102 #endregion
103
104 #region Fields
105 [SerializeField]
106 private bool _showCreditsOnScreen = false;
107
113 {
114 get => this._showCreditsOnScreen;
115 set
116 {
117 this._showCreditsOnScreen = value;
118 this.SetShowCreditsOnScreen(this._showCreditsOnScreen);
119 if (Cesium3DTileset.OnSetShowCreditsOnScreen != null)
120 {
121 Cesium3DTileset.OnSetShowCreditsOnScreen();
122 }
123 }
124 }
125
126
127 [SerializeField]
128 private CesiumDataSource _tilesetSource = CesiumDataSource.FromCesiumIon;
129
134 {
135 get => this._tilesetSource;
136 set
137 {
138 this._tilesetSource = value;
139 this.RecreateTileset();
140 }
141 }
142
143 [SerializeField]
144 private string _url = "";
145
150 public string url
151 {
152 get => this._url;
153 set
154 {
155 this._url = value;
156 this.RecreateTileset();
157 }
158 }
159
160 [SerializeField]
161 private long _ionAssetID = 0;
162
167 public long ionAssetID
168 {
169 get => this._ionAssetID;
170 set
171 {
172 this._ionAssetID = value;
173 this.RecreateTileset();
174 }
175 }
176
177 [SerializeField]
178 private string _ionAccessToken = "";
179
184 public string ionAccessToken
185 {
186 get => this._ionAccessToken;
187 set
188 {
189 this._ionAccessToken = value;
190 this.RecreateTileset();
191 }
192 }
193
194 [SerializeField]
195 private CesiumIonServer _ionServer = null;
196
201 {
202 get
203 {
204 if (this._ionServer == null)
205 {
206#if UNITY_EDITOR
207 // See OnAfterDeserialize.
208 if (this._useDefaultServer)
209 this._ionServer = CesiumIonServer.defaultServer;
210 else
211 this._ionServer = CesiumIonServer.serverForNewObjects;
212
213 this._useDefaultServer = false;
214#else
215 this._ionServer = CesiumIonServer.serverForNewObjects;
216#endif
217 }
218 return this._ionServer;
219 }
220 set
221 {
222 if (value == null) value = CesiumIonServer.serverForNewObjects;
223 this._ionServer = value;
224 this.RecreateTileset();
225 }
226 }
227
228 [SerializeField]
229 private float _maximumScreenSpaceError = 16.0f;
230
250 {
251 get => this._maximumScreenSpaceError;
252 set
253 {
254 this._maximumScreenSpaceError = value;
255 this.RecreateTileset();
256 }
257 }
258
259 [SerializeField]
260 private bool _preloadAncestors = true;
261
271 {
272 get => this._preloadAncestors;
273 set
274 {
275 this._preloadAncestors = value;
276 this.RecreateTileset();
277 }
278 }
279
280 [SerializeField]
281 private bool _preloadSiblings = true;
282
291 public bool preloadSiblings
292 {
293 get => this._preloadSiblings;
294 set
295 {
296 this._preloadSiblings = value;
297 this.RecreateTileset();
298 }
299 }
300
301 [SerializeField]
302 private bool _forbidHoles = false;
303
314 public bool forbidHoles
315 {
316 get => this._forbidHoles;
317 set
318 {
319 this._forbidHoles = value;
320 this.RecreateTileset();
321 }
322 }
323
324 [SerializeField]
325 private uint _maximumSimultaneousTileLoads = 20;
326
338 {
339 get => this._maximumSimultaneousTileLoads;
340 set
341 {
342 this._maximumSimultaneousTileLoads = value;
343 this.RecreateTileset();
344 }
345 }
346
347 [SerializeField]
348 private long _maximumCachedBytes = 512 * 1024 * 1024;
349
361 {
362 get => this._maximumCachedBytes;
363 set
364 {
365 this._maximumCachedBytes = value;
366 this.RecreateTileset();
367 }
368 }
369
370 [SerializeField]
371 private uint _loadingDescendantLimit = 20;
372
385 {
386 get => this._loadingDescendantLimit;
387 set
388 {
389 this._loadingDescendantLimit = value;
390 this.RecreateTileset();
391 }
392 }
393
394 [SerializeField]
395 private bool _enableFrustumCulling = true;
396
415 {
416 get => this._enableFrustumCulling;
417 set
418 {
419 this._enableFrustumCulling = value;
420 this.RecreateTileset();
421 }
422 }
423
424 [SerializeField]
425 private bool _enableFogCulling = true;
426
442 {
443 get => this._enableFogCulling;
444 set
445 {
446 this._enableFogCulling = value;
447 this.RecreateTileset();
448 }
449 }
450
451
452 [SerializeField]
453 private bool _enforceCulledScreenSpaceError = true;
454
481 {
482 get => this._enforceCulledScreenSpaceError;
483 set
484 {
485 this._enforceCulledScreenSpaceError = value;
486 this.RecreateTileset();
487 }
488 }
489
490 [SerializeField]
491 private float _culledScreenSpaceError = 64.0f;
492
518 {
519 get => this._culledScreenSpaceError;
520 set
521 {
522 this._culledScreenSpaceError = value;
523 this.RecreateTileset();
524 }
525 }
526
527 [SerializeField]
528 private Material _opaqueMaterial = null;
529
533 public Material opaqueMaterial
534 {
535 get => this._opaqueMaterial;
536 set
537 {
538 this._opaqueMaterial = value;
539 this.RecreateTileset();
540 }
541 }
542
543 //[SerializeField]
544 //private bool _useLodTransitions = false;
545
546 //public bool useLodTransitions
547 //{
548 // get => this._useLodTransitions;
549 // set
550 // {
551 // this._useLodTransitions = value;
552 // this.RecreateTileset();
553 // }
554 //}
555
556
557 //[SerializeField]
558 //private float _lodTransitionLength = 0.5f;
559
560 //public float lodTransitionLength
561 //{
562 // get => this._lodTransitionLength;
563 // set
564 // {
565 // this._lodTransitionLength = value;
566 // this.RecreateTileset();
567 // }
568 //}
569
570 [SerializeField]
571 private bool _generateSmoothNormals = false;
572
583 {
584 get => this._generateSmoothNormals;
585 set
586 {
587 this._generateSmoothNormals = value;
588 this.RecreateTileset();
589 }
590 }
591
592 [SerializeField]
593 private CesiumPointCloudShading _pointCloudShading;
594
601 {
602 get => this._pointCloudShading;
603 }
604
605 [SerializeField]
606 private bool _suspendUpdate = false;
607
611 public bool suspendUpdate
612 {
613 get => this._suspendUpdate;
614 set
615 {
616 this._suspendUpdate = value;
617 }
618 }
619
620 // Normally tilesets are destroyed when anything in the editor changes.
621 // But if suspendUpdate is the only value that has changed, the tileset
622 // should not be reloaded, and instead continue updating after the setting
623 // has been toggled. This variable saves the last value of suspendUpdate,
624 // so OnValidate() can determine if this property was modified. If so, it
625 // prevents the tileset from being destroyed.
626 private bool _previousSuspendUpdate = false;
627
628 internal bool previousSuspendUpdate
629 {
630 get => this._previousSuspendUpdate;
631 set
632 {
633 this._previousSuspendUpdate = value;
634 }
635 }
636
637 [SerializeField]
638 private bool _showTilesInHierarchy = false;
639
644 {
645 get => this._showTilesInHierarchy;
646 set
647 {
648 this._showTilesInHierarchy = value;
649 this.RecreateTileset();
650 }
651 }
652
653 [SerializeField]
654 private bool _updateInEditor = true;
655
659 public bool updateInEditor
660 {
661 get => this._updateInEditor;
662 set
663 {
664 this._updateInEditor = value;
665 this.RecreateTileset();
666 }
667 }
668
669 [SerializeField]
670 private bool _logSelectionStats = false;
671
676 {
677 get => this._logSelectionStats;
678 set { this._logSelectionStats = value; }
679 }
680
681 [SerializeField]
682 private bool _createPhysicsMeshes = true;
683
693 {
694 get => this._createPhysicsMeshes;
695 set
696 {
697 this._createPhysicsMeshes = value;
698 this.RecreateTileset();
699 }
700 }
701
702 #endregion
703
704 #region Public Methods
705
712 public partial float ComputeLoadProgress();
713
714
719 public partial void RecreateTileset();
720
724 public partial void FocusTileset();
725
748 public partial Task<CesiumSampleHeightResult> SampleHeightMostDetailed(params double3[] longitudeLatitudeHeightPositions);
749
750 #endregion
751
752 #region Private Methods
753
754 private partial void SetShowCreditsOnScreen(bool value);
755
756 private partial void Start();
757 private partial void Update();
758 private partial void OnValidate();
759
760 private partial void OnEnable();
761 private partial void OnDisable();
762
763 internal partial void UpdateOverlayMaterialKeys();
764
765 #endregion
766
767 #region Backward Compatibility
768
769 void ISerializationCallbackReceiver.OnBeforeSerialize()
770 {
771 }
772
773 void ISerializationCallbackReceiver.OnAfterDeserialize()
774 {
775#if UNITY_EDITOR
776 // For backward compatibility, tilesets loaded without a server should adopt
777 // the default one rather than the current one.
778 if (this._ionServer == null)
779 this._useDefaultServer = true;
780#endif
781 }
782
783#if UNITY_EDITOR
784 private bool _useDefaultServer = false;
785#endif
786 #endregion
787 }
788}
A tileset in the 3D Tiles format.
partial Task< CesiumSampleHeightResult > SampleHeightMostDetailed(params double3[] longitudeLatitudeHeightPositions)
Initiates an asynchronous query for the height of this tileset at a list of cartographic positions,...
bool logSelectionStats
Whether to log details about the tile selection process.
Action< GameObject > OnTileGameObjectCreated
Occurs when a new GameObject is instantiated for a Tile in the tileset.
static TilesetLoadFailureDelegate OnCesium3DTilesetLoadFailure
An event that is raised when the tileset encounters an error that prevents it from loading.
bool preloadAncestors
Whether to preload ancestor tiles.
CesiumPointCloudShading pointCloudShading
The CesiumPointCloudShading attached to this tileset.
CesiumDataSource tilesetSource
The source of the data for this tileset: Cesium ion or a regular URL.
bool enableFogCulling
Whether to cull tiles that are occluded by fog.
bool suspendUpdate
Pauses level-of-detail and culling updates of this tileset.
float maximumScreenSpaceError
The maximum number of pixels of error when rendering this tileset.
delegate void TilesetLoadFailureDelegate(Cesium3DTilesetLoadFailureDetails details)
Encapsulates a method that receives details of a tileset load failure.
bool enableFrustumCulling
Whether to cull tiles that are outside the frustum.
string ionAccessToken
The Cesium ion access token to use when loading the tileset from Cesium ion.
partial float ComputeLoadProgress()
Estimate the percentage of the tiles for the current view that have been loaded.
bool createPhysicsMeshes
Whether to generate physics meshes for this tileset.
partial void FocusTileset()
Zoom the Editor camera to this tileset.
Material opaqueMaterial
The Material to use to render opaque parts of tiles.
bool showTilesInHierarchy
Whether to show tiles as individual game objects in the hierarchy window.
float culledScreenSpaceError
The screen-space error to be enforced for tiles that are outside the frustum or hidden in fog.
long maximumCachedBytes
The maximum number of bytes that may be cached for this tileset.
bool enforceCulledScreenSpaceError
Whether a specified screen-space error should be enforced for tiles that are outside the frustum or h...
uint loadingDescendantLimit
The number of loading descendents a tile should allow before deciding to render itself instead of wai...
bool generateSmoothNormals
Whether to generate smooth normals when normals are missing in the glTF.
bool forbidHoles
Whether to prevent refinement of a parent tile when a child isn't done loading.
long ionAssetID
The Cesium ion asset ID from which to load the tileset.
CesiumIonServer ionServer
The Cesium ion server from which this tileset is loaded.
partial void RecreateTileset()
Destroy and recreate the tilset.
bool showCreditsOnScreen
Whether or not to force this tileset's credits to be shown on the main screen.
string url
The URL from which to load the tileset.
bool preloadSiblings
Whether to preload sibling tiles.
bool updateInEditor
If true, this tileset is ticked/updated in the editor.
uint maximumSimultaneousTileLoads
The maximum number of tiles that may be loaded simultaneously.
Defines a Cesium ion Server.
static CesiumIonServer serverForNewObjects
Gets the current Cesium ion server that should be assigned to newly-created objects.
static CesiumIonServer defaultServer
Gets the default Cesium ion Server (ion.cesium.com).
Options for adjusting how point clouds are rendered using 3D Tiles.
CesiumDataSource
Specifies the source of a Cesium dataset.
@ FromCesiumIon
The dataset is from Cesium ion.
@ FromEllipsoid
The dataset is generated from the georeference ellipsoid.
@ FromUrl
The dataset is from a regular web URL.
Holds details of a Cesium3DTileset load failure.