Skip to content

Commit

Permalink
Merge pull request #65 from CesiumGS/upgrade-metadata-scripts
Browse files Browse the repository at this point in the history
Update samples for metadata changes
  • Loading branch information
kring committed Mar 1, 2024
2 parents 4694a41 + f1ce8bb commit 6cdee13
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 161 deletions.
16 changes: 3 additions & 13 deletions Assets/CesiumForUnitySamples/Scenes/01_CesiumWorld.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -185,6 +184,7 @@ MonoBehaviour:
_enforceCulledScreenSpaceError: 0
_culledScreenSpaceError: 64
_opaqueMaterial: {fileID: 0}
_generateSmoothNormals: 0
_pointCloudShading:
_attenuation: 0
_geometricErrorScale: 1
Expand All @@ -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
Expand Down Expand Up @@ -273,6 +261,7 @@ MonoBehaviour:
_enforceCulledScreenSpaceError: 0
_culledScreenSpaceError: 64
_opaqueMaterial: {fileID: 0}
_generateSmoothNormals: 0
_pointCloudShading:
_attenuation: 0
_geometricErrorScale: 1
Expand Down Expand Up @@ -449,6 +438,7 @@ MonoBehaviour:
_ecefX: -2702161.656027028
_ecefY: -4261531.553813732
_ecefZ: 3888494.7188496506
_scale: 1
--- !u!4 &819515654
Transform:
m_ObjectHideFlags: 0
Expand Down
16 changes: 3 additions & 13 deletions Assets/CesiumForUnitySamples/Scenes/05_CesiumMetadata.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -335,6 +334,7 @@ MonoBehaviour:
_enforceCulledScreenSpaceError: 1
_culledScreenSpaceError: 64
_opaqueMaterial: {fileID: 0}
_generateSmoothNormals: 0
_pointCloudShading:
_attenuation: 0
_geometricErrorScale: 1
Expand All @@ -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
Expand Down Expand Up @@ -423,6 +411,7 @@ MonoBehaviour:
_enforceCulledScreenSpaceError: 1
_culledScreenSpaceError: 64
_opaqueMaterial: {fileID: 0}
_generateSmoothNormals: 0
_pointCloudShading:
_attenuation: 0
_geometricErrorScale: 1
Expand Down Expand Up @@ -651,6 +640,7 @@ MonoBehaviour:
_ecefX: 1334024.061125777
_ecefY: -4654541.47408277
_ecefZ: 4138350.2623599432
_scale: 1
--- !u!4 &819515654
Transform:
m_ObjectHideFlags: 0
Expand Down
13 changes: 0 additions & 13 deletions Assets/CesiumForUnitySamples/Scenes/VR02_CesiumMetadata.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using CesiumForUnity;
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections.Generic;

#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
Expand All @@ -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<String, CesiumMetadataValue> _metadataValues;

void Start()
{
// Fix the cursor to the center of the screen and hide it.
Expand All @@ -25,56 +31,64 @@ void Start()
{
metadataPanel.SetActive(false);
}

this._metadataValues = new Dictionary<String, CesiumMetadataValue>();
}

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<CesiumMetadata>();
if (metadata != null)
CesiumPrimitiveFeatures features = hit.transform.GetComponent<CesiumPrimitiveFeatures>();
CesiumModelMetadata metadata = hit.transform.GetComponentInParent<CesiumModelMetadata>();

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 += "<b>" + propertyName + "</b>" + ": "
+ propertyValue + "\n";
}
metadataText.text += "<b>" + valuePair.Key + "</b>" + ": " + valueAsString + "\n";
}
}
}
}

if(metadataPanel != null)
if (metadataPanel != null)
{
metadataPanel.SetActive(metadataText.text.Length > 0);
}
Expand Down
Loading

0 comments on commit 6cdee13

Please sign in to comment.