From cc4abbdb74c4fc6388dce4fdf5add2834c59eb1d Mon Sep 17 00:00:00 2001 From: Janine Liu Date: Tue, 30 Jan 2024 11:55:27 -0500 Subject: [PATCH 1/2] Update samples for metadata changes --- .../Scenes/01_CesiumWorld.unity | 16 +- .../Scenes/05_CesiumMetadata.unity | 16 +- .../Scenes/VR02_CesiumMetadata.unity | 13 -- .../Scripts/CesiumSamplesMetadataPicking.cs | 66 +++--- .../Scripts/CesiumSamplesMetadataPickingVR.cs | 200 ++++++++++-------- 5 files changed, 153 insertions(+), 158 deletions(-) diff --git a/Assets/CesiumForUnitySamples/Scenes/01_CesiumWorld.unity b/Assets/CesiumForUnitySamples/Scenes/01_CesiumWorld.unity index 26e867d..8f4a0c5 100644 --- a/Assets/CesiumForUnitySamples/Scenes/01_CesiumWorld.unity +++ b/Assets/CesiumForUnitySamples/Scenes/01_CesiumWorld.unity @@ -133,7 +133,6 @@ GameObject: m_Component: - component: {fileID: 126742915} - component: {fileID: 126742916} - - component: {fileID: 126742917} m_Layer: 0 m_Name: Cesium OSM Buildings m_TagString: Untagged @@ -185,6 +184,7 @@ MonoBehaviour: _enforceCulledScreenSpaceError: 0 _culledScreenSpaceError: 64 _opaqueMaterial: {fileID: 0} + _generateSmoothNormals: 0 _pointCloudShading: _attenuation: 0 _geometricErrorScale: 1 @@ -195,18 +195,6 @@ MonoBehaviour: _updateInEditor: 1 _logSelectionStats: 0 _createPhysicsMeshes: 1 ---- !u!114 &126742917 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 126742914} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7b1942b8938da484cab4fe52e17a3cc7, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!1 &161818292 GameObject: m_ObjectHideFlags: 0 @@ -273,6 +261,7 @@ MonoBehaviour: _enforceCulledScreenSpaceError: 0 _culledScreenSpaceError: 64 _opaqueMaterial: {fileID: 0} + _generateSmoothNormals: 0 _pointCloudShading: _attenuation: 0 _geometricErrorScale: 1 @@ -449,6 +438,7 @@ MonoBehaviour: _ecefX: -2702161.656027028 _ecefY: -4261531.553813732 _ecefZ: 3888494.7188496506 + _scale: 1 --- !u!4 &819515654 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/CesiumForUnitySamples/Scenes/05_CesiumMetadata.unity b/Assets/CesiumForUnitySamples/Scenes/05_CesiumMetadata.unity index e43575f..d7ae839 100644 --- a/Assets/CesiumForUnitySamples/Scenes/05_CesiumMetadata.unity +++ b/Assets/CesiumForUnitySamples/Scenes/05_CesiumMetadata.unity @@ -283,7 +283,6 @@ GameObject: m_Component: - component: {fileID: 126742915} - component: {fileID: 126742916} - - component: {fileID: 126742917} m_Layer: 0 m_Name: NYC Buildings m_TagString: Untagged @@ -335,6 +334,7 @@ MonoBehaviour: _enforceCulledScreenSpaceError: 1 _culledScreenSpaceError: 64 _opaqueMaterial: {fileID: 0} + _generateSmoothNormals: 0 _pointCloudShading: _attenuation: 0 _geometricErrorScale: 1 @@ -345,18 +345,6 @@ MonoBehaviour: _updateInEditor: 1 _logSelectionStats: 0 _createPhysicsMeshes: 1 ---- !u!114 &126742917 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 126742914} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7b1942b8938da484cab4fe52e17a3cc7, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!1 &161818292 GameObject: m_ObjectHideFlags: 0 @@ -423,6 +411,7 @@ MonoBehaviour: _enforceCulledScreenSpaceError: 1 _culledScreenSpaceError: 64 _opaqueMaterial: {fileID: 0} + _generateSmoothNormals: 0 _pointCloudShading: _attenuation: 0 _geometricErrorScale: 1 @@ -651,6 +640,7 @@ MonoBehaviour: _ecefX: 1334024.061125777 _ecefY: -4654541.47408277 _ecefZ: 4138350.2623599432 + _scale: 1 --- !u!4 &819515654 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/CesiumForUnitySamples/Scenes/VR02_CesiumMetadata.unity b/Assets/CesiumForUnitySamples/Scenes/VR02_CesiumMetadata.unity index 565e782..a3759db 100644 --- a/Assets/CesiumForUnitySamples/Scenes/VR02_CesiumMetadata.unity +++ b/Assets/CesiumForUnitySamples/Scenes/VR02_CesiumMetadata.unity @@ -294,7 +294,6 @@ GameObject: m_Component: - component: {fileID: 217227925} - component: {fileID: 217227927} - - component: {fileID: 217227926} - component: {fileID: 217227928} m_Layer: 0 m_Name: Cesium OSM Buildings @@ -318,18 +317,6 @@ Transform: m_Father: {fileID: 304459247} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &217227926 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 217227924} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7b1942b8938da484cab4fe52e17a3cc7, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!114 &217227927 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/CesiumForUnitySamples/Scripts/CesiumSamplesMetadataPicking.cs b/Assets/CesiumForUnitySamples/Scripts/CesiumSamplesMetadataPicking.cs index 81792fd..911f5c9 100644 --- a/Assets/CesiumForUnitySamples/Scripts/CesiumSamplesMetadataPicking.cs +++ b/Assets/CesiumForUnitySamples/Scripts/CesiumSamplesMetadataPicking.cs @@ -1,6 +1,8 @@ using CesiumForUnity; using UnityEngine; using UnityEngine.UI; +using System; +using System.Collections.Generic; #if ENABLE_INPUT_SYSTEM using UnityEngine.InputSystem; @@ -15,6 +17,10 @@ public class CesiumSamplesMetadataPicking : MonoBehaviour // The text to display the metadata properties. public Text metadataText; + // Cached Dictionary of metadata values. This prevents reallocation every + // time metadata is sampled from the tileset. + private Dictionary _metadataValues; + void Start() { // Fix the cursor to the center of the screen and hide it. @@ -25,56 +31,64 @@ void Start() { metadataPanel.SetActive(false); } + + this._metadataValues = new Dictionary(); } void Update() { #if ENABLE_INPUT_SYSTEM - bool getMetadata = false; + bool receivedInput = false; + if (Mouse.current != null) { - getMetadata = Mouse.current.leftButton.isPressed; + receivedInput = Mouse.current.leftButton.isPressed; } - else if(Gamepad.current != null) + else if (Gamepad.current != null) { - getMetadata = Gamepad.current.rightShoulder.isPressed; + receivedInput = Gamepad.current.rightShoulder.isPressed; } - #else - bool getMetadata = Input.GetMouseButtonDown(0); - #endif +#else + bool receivedInput = Input.GetMouseButtonDown(0); +#endif - if (getMetadata && metadataText != null) + if (receivedInput && metadataText != null) { - metadataText.text = ""; + metadataText.text = String.Empty; RaycastHit hit; if (Physics.Raycast( - Camera.main.transform.position, - Camera.main.transform.TransformDirection(Vector3.forward), - out hit, - Mathf.Infinity)) + Camera.main.transform.position, + Camera.main.transform.TransformDirection(Vector3.forward), + out hit, + Mathf.Infinity)) { - CesiumMetadata metadata = hit.transform.GetComponentInParent(); - if (metadata != null) + CesiumPrimitiveFeatures features = hit.transform.GetComponent(); + CesiumModelMetadata metadata = hit.transform.GetComponentInParent(); + + if (features != null && features.featureIdSets.Length > 0) { - CesiumFeature[] features = metadata.GetFeatures(hit.transform, hit.triangleIndex); - // List out each metadata property in the UI. - foreach (var feature in features) + CesiumFeatureIdSet featureIdSet = features.featureIdSets[0]; + Int64 propertyTableIndex = featureIdSet.propertyTableIndex; + if (metadata != null && propertyTableIndex >= 0 && propertyTableIndex < metadata.propertyTables.Length) + { + CesiumPropertyTable propertyTable = metadata.propertyTables[propertyTableIndex]; + Int64 featureID = featureIdSet.GetFeatureIdFromRaycastHit(hit); + propertyTable.GetMetadataValuesForFeature(this._metadataValues, featureID); + } + + foreach (var valuePair in this._metadataValues) { - foreach (var propertyName in feature.properties) + string valueAsString = valuePair.Value.GetString(); + if (!String.IsNullOrEmpty(valueAsString) && valueAsString != "null") { - string propertyValue = feature.GetString(propertyName, "null"); - if (propertyValue != "null" && propertyValue != "") - { - metadataText.text += "" + propertyName + "" + ": " - + propertyValue + "\n"; - } + metadataText.text += "" + valuePair.Key + "" + ": " + valueAsString + "\n"; } } } } - if(metadataPanel != null) + if (metadataPanel != null) { metadataPanel.SetActive(metadataText.text.Length > 0); } diff --git a/Assets/CesiumForUnitySamples/Scripts/CesiumSamplesMetadataPickingVR.cs b/Assets/CesiumForUnitySamples/Scripts/CesiumSamplesMetadataPickingVR.cs index 1fe0935..50b6343 100644 --- a/Assets/CesiumForUnitySamples/Scripts/CesiumSamplesMetadataPickingVR.cs +++ b/Assets/CesiumForUnitySamples/Scripts/CesiumSamplesMetadataPickingVR.cs @@ -5,94 +5,94 @@ using System.Collections.Generic; using UnityEngine.UI; using UnityEngine.InputSystem; +using System; public class MetadataInteractable : XRBaseInteractable { public TextMeshProUGUI metadataText; public GameObject canvas; - static HashSet ignoreProperties = new HashSet() { - "addr:city", - "addr:country", - "addr:housenumber", - "addr:postcode", - "addr:state", - "addr:street", - "building:colour", - "cesium#color", - "cesium#estimatedHeight", - "cesium#latitude", - "cesium#longitude", - "ele", - "elementId", - "elementType", - "gnis:county_id", - "gnis:created", - "gnis:edited", - "gnis:feature_id", - "gnis:state_id", - "layer", - "name", - "name:ar", - "name:de", - "name:el", - "name:es", - "name:etymology", - "name:fr", - "name:he", - "name:hi", - "name:hr", - "name:ja", - "name:ko", - "name:pl", - "name:uk", - "name:zh", - "name:zh_pinyin", - "nycdoitt:bin", - "part#elementId", - "part#elementType", - "part#building:colour", - "part#roof:colour", - "part#roof:direction", - "part#addr:city", - "part#addr:country", - "part#addr:housenumber", - "part#addr:postcode", - "part#addr:state", - "part#addr:street", - "part#wikidata", - "part#nycdoitt:bin", - "roof:colour", - "type", - "wikidata", - }; + private static HashSet ignoreProperties = new HashSet() { + "addr:city", + "addr:country", + "addr:housenumber", + "addr:postcode", + "addr:state", + "addr:street", + "building:colour", + "cesium#color", + "cesium#estimatedHeight", + "cesium#latitude", + "cesium#longitude", + "ele", + "elementId", + "elementType", + "gnis:county_id", + "gnis:created", + "gnis:edited", + "gnis:feature_id", + "gnis:state_id", + "layer", + "name", + "name:ar", + "name:de", + "name:el", + "name:es", + "name:etymology", + "name:fr", + "name:he", + "name:hi", + "name:hr", + "name:ja", + "name:ko", + "name:pl", + "name:uk", + "name:zh", + "name:zh_pinyin", + "nycdoitt:bin", + "part#elementId", + "part#elementType", + "part#building:colour", + "part#roof:colour", + "part#roof:direction", + "part#addr:city", + "part#addr:country", + "part#addr:housenumber", + "part#addr:postcode", + "part#addr:state", + "part#addr:street", + "part#wikidata", + "part#nycdoitt:bin", + "roof:colour", + "type", + "wikidata", + }; - string GetInterestingProperties(CesiumFeature feature) + private string GetInterestingProperties(CesiumPropertyTable propertyTable, Int64 featureID) { - string ret = ""; - foreach (var propertyName in feature.properties) + string result = ""; + foreach (var propertyName in propertyTable.properties.Keys) { if (!ignoreProperties.Contains(propertyName)) { - string propertyValue = feature.GetString(propertyName, "null"); - if (propertyValue != "null") + string propertyValue = propertyTable.properties[propertyName].GetString(featureID); + if (!String.IsNullOrEmpty(propertyValue) && propertyValue != "null") { - ret += $"{propertyName}: {propertyValue}\n"; + result += $"{propertyName}: {propertyValue}\n"; } } } - return ret; + return result; } - Vector3 GetTopOfBuilding(Vector3 hitLocation, CesiumFeature feature) + private Vector3 GetTopOfBuilding(Vector3 hitLocation, float buildingHeight) { var georeference = GetComponentInParent(); - if(georeference != null) + if (georeference != null) { - float buildingHeight = feature.GetFloat32("cesium#estimatedHeight", 0.0f); - foreach(RaycastHit hit in Physics.RaycastAll(hitLocation, Vector3.down, 100.0f)) + foreach (RaycastHit hit in Physics.RaycastAll(hitLocation, Vector3.down, 100.0f)) { - if(!hit.transform.parent.name.Contains("CesiumWorldTerrain")) + if (!hit.transform.parent.name.Contains("CesiumWorldTerrain")) { continue; } @@ -104,6 +104,8 @@ Vector3 GetTopOfBuilding(Vector3 hitLocation, CesiumFeature feature) return Vector3.zero; } + const string estimatedHeightKey = "cesium#estimatedHeight"; + protected override void OnActivated(ActivateEventArgs args) { RaycastHit hit; @@ -112,36 +114,47 @@ protected override void OnActivated(ActivateEventArgs args) interactorTransform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity)) { - CesiumMetadata metadata = - hit.transform.GetComponentInParent(); - if (metadata != null) + CesiumPrimitiveFeatures features = hit.transform.GetComponent(); + CesiumModelMetadata metadata = + hit.transform.GetComponentInParent(); + if (features != null && metadata != null && metadata.propertyTables.Length > 0) { - CesiumFeature[] features = - metadata.GetFeatures(hit.transform, hit.triangleIndex); - if (features.Length > 0) + CesiumPropertyTable propertyTable = metadata.propertyTables[0]; + + Int64 featureID = features.GetFeatureIdFromRaycastHit(hit); + + float estimatedHeight = 0.0f; + if (propertyTable.properties.ContainsKey(estimatedHeightKey)) { - CesiumFeature feature = features[0]; + estimatedHeight = propertyTable.properties[estimatedHeightKey].GetFloat(featureID); + } - Vector3 topOfBuilding = GetTopOfBuilding(hit.point, feature); - canvas.transform.position = topOfBuilding; - Vector3 camPos = Camera.main.transform.position; - float distance = Vector3.Distance(camPos, topOfBuilding); - if(distance > 1.0f) - { - canvas.transform.localScale = distance * Vector3.one; - } - canvas.transform.rotation = Quaternion.LookRotation(new Vector3(topOfBuilding.x - camPos.x, 0, topOfBuilding.z - camPos.z), Vector3.up); + Vector3 topOfBuilding = GetTopOfBuilding(hit.point, estimatedHeight); + canvas.transform.position = topOfBuilding; + Vector3 camPos = Camera.main.transform.position; + float distance = Vector3.Distance(camPos, topOfBuilding); + if (distance > 1.0f) + { + canvas.transform.localScale = distance * Vector3.one; + } + canvas.transform.rotation = Quaternion.LookRotation( + new Vector3(topOfBuilding.x - camPos.x, 0, topOfBuilding.z - camPos.z), Vector3.up); - string name = feature.GetString("name", null); - if (name == "null") - { - name = "Name N/A"; - } - metadataText.text = - $"{name}\n{GetInterestingProperties(feature)}"; + string name = String.Empty; + if (propertyTable.properties.ContainsKey("name")) + { + name = propertyTable.properties["name"].GetString(featureID); + } - canvas.SetActive(true); + if (String.IsNullOrEmpty(name) || name == "null") + { + name = "Name N/A"; } + + metadataText.text = + $"{name}\n{GetInterestingProperties(propertyTable, featureID)}"; + + canvas.SetActive(true); } } } @@ -157,14 +170,15 @@ public class CesiumSamplesMetadataPickingVR : MonoBehaviour public XRRayInteractor rayInteractor; void Start() { - if(activateButton != null) + if (activateButton != null) { activateButton.action.performed += Action_performed; } if (tileset != null && characterController != null && metadataText != null) { - tileset.OnTileGameObjectCreated += go => { + tileset.OnTileGameObjectCreated += go => + { foreach (Transform child in go.transform) { var mc = child.GetComponent(); From 584d21bcc8df9809b5ac4e710791f86939b0a0be Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Fri, 1 Mar 2024 15:15:37 +1100 Subject: [PATCH 2/2] Release updates. - Use Cesium for Unity v1.8.0. - Bump project version to v1.8.0. - Update ion key. --- .../Resources/CesiumIonServers/ion.cesium.com.asset | 2 +- Packages/manifest.json | 2 +- ProjectSettings/ProjectSettings.asset | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/CesiumSettings/Resources/CesiumIonServers/ion.cesium.com.asset b/Assets/CesiumSettings/Resources/CesiumIonServers/ion.cesium.com.asset index a5bf2a8..953fabd 100644 --- a/Assets/CesiumSettings/Resources/CesiumIonServers/ion.cesium.com.asset +++ b/Assets/CesiumSettings/Resources/CesiumIonServers/ion.cesium.com.asset @@ -16,4 +16,4 @@ MonoBehaviour: apiUrl: https://api.cesium.com oauth2ApplicationID: 381 defaultIonAccessTokenId: - defaultIonAccessToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI2NzMyYTIyOC0wM2JiLTQwNzAtYjY0Mi1jMmM4MmI0YWIzZDgiLCJpZCI6MjU5LCJpYXQiOjE2OTYyMDA1ODd9.xWZMTjLkKl8JoUJgLzJzhqHGAp2petCmAx5pBZo-nXY + defaultIonAccessToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI5ZDY1MDlhOS1jMTZlLTQ4YzgtYTk3OC1hOWRkNWFjNzJmOGEiLCJpZCI6MjU5LCJpYXQiOjE3MDkyNjY0NTd9.yTTNkwMLrjGZ5hqBGNVzQO2-Mr85ZM5iMhzwsmCWrfk diff --git a/Packages/manifest.json b/Packages/manifest.json index bff180d..7bba002 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -9,7 +9,7 @@ } ], "dependencies": { - "com.cesium.unity": "1.7.1", + "com.cesium.unity": "1.8.0", "com.unity.cinemachine": "2.8.9", "com.unity.collab-proxy": "1.17.2", "com.unity.ide.rider": "3.0.15", diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 2477284..e99dc22 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -134,7 +134,7 @@ PlayerSettings: 16:10: 1 16:9: 1 Others: 1 - bundleVersion: 1.7.1 + bundleVersion: 1.8.0 preloadedAssets: [] metroInputSource: 0 wsaTransparentSwapchain: 0