Cesium for Unity 1.18.0
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 bool _ignoreKhrMaterialsUnlit = false;
594
610 {
611 get => this._ignoreKhrMaterialsUnlit;
612 set
613 {
614 this._ignoreKhrMaterialsUnlit = value;
615 this.RecreateTileset();
616 }
617 }
618
619 [SerializeField]
620 private CesiumPointCloudShading _pointCloudShading = new CesiumPointCloudShading();
621
628 {
629 get => this._pointCloudShading;
630 }
631
632 [SerializeField]
633 private bool _suspendUpdate = false;
634
638 public bool suspendUpdate
639 {
640 get => this._suspendUpdate;
641 set
642 {
643 this._suspendUpdate = value;
644 }
645 }
646
647 // Normally tilesets are destroyed when anything in the editor changes.
648 // But if suspendUpdate is the only value that has changed, the tileset
649 // should not be reloaded, and instead continue updating after the setting
650 // has been toggled. This variable saves the last value of suspendUpdate,
651 // so OnValidate() can determine if this property was modified. If so, it
652 // prevents the tileset from being destroyed.
653 private bool _previousSuspendUpdate = false;
654
655 internal bool previousSuspendUpdate
656 {
657 get => this._previousSuspendUpdate;
658 set
659 {
660 this._previousSuspendUpdate = value;
661 }
662 }
663
664 [SerializeField]
665 private bool _showTilesInHierarchy = false;
666
671 {
672 get => this._showTilesInHierarchy;
673 set
674 {
675 this._showTilesInHierarchy = value;
676 this.RecreateTileset();
677 }
678 }
679
680 [SerializeField]
681 private bool _updateInEditor = true;
682
686 public bool updateInEditor
687 {
688 get => this._updateInEditor;
689 set
690 {
691 this._updateInEditor = value;
692 this.RecreateTileset();
693 }
694 }
695
696 [SerializeField]
697 private bool _logSelectionStats = false;
698
703 {
704 get => this._logSelectionStats;
705 set { this._logSelectionStats = value; }
706 }
707
708 [SerializeField]
709 private bool _createPhysicsMeshes = true;
710
720 {
721 get => this._createPhysicsMeshes;
722 set
723 {
724 this._createPhysicsMeshes = value;
725 this.RecreateTileset();
726 }
727 }
728
729 #endregion
730
731 #region Public Methods
732
739 public partial float ComputeLoadProgress();
740
741
746 public partial void RecreateTileset();
747
751 public partial void FocusTileset();
752
775 public partial Task<CesiumSampleHeightResult> SampleHeightMostDetailed(params double3[] longitudeLatitudeHeightPositions);
776
777 #endregion
778
779 #region Private Methods
780
781 private partial void SetShowCreditsOnScreen(bool value);
782
783 private partial void Start();
784 private partial void Update();
785 private partial void OnValidate();
786
787 private partial void OnEnable();
788 private partial void OnDisable();
789
790 internal partial void UpdateOverlayMaterialKeys();
791
792 #endregion
793
794 #region Backward Compatibility
795
796 void ISerializationCallbackReceiver.OnBeforeSerialize()
797 {
798 }
799
800 void ISerializationCallbackReceiver.OnAfterDeserialize()
801 {
802#if UNITY_EDITOR
803 // For backward compatibility, tilesets loaded without a server should adopt
804 // the default one rather than the current one.
805 if (this._ionServer == null)
806 this._useDefaultServer = true;
807#endif
808 }
809
810#if UNITY_EDITOR
811 private bool _useDefaultServer = false;
812#endif
813 #endregion
814 }
815}
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.
bool ignoreKhrMaterialsUnlit
Whether to ignore the KHR_materials_unlit extension on the glTF tiles in this tileset,...
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.