Object Picking sample
The sample available as part of the Unity Metadata package demonstrates how the Metadata package and the Data Streaming package can interact together.
A typical example of audience for this guide is the developers who will use raycasting/object selection to select object to get the entity metadata.
Prerequisites
To use the Object Picking sample, you need the following:
- An installed Common package
- An installed Identity package
- An installed Storage package
- An installed Data-Streaming package
- A valid Unity ID
- At least one scene (associated to your Unity ID) that contains metadata and indexed texture. Refer to Publishing metadata and creating indexed texture for more information.
Installation
To install the sample, follow these steps:
- In your Unity project, go to Window > Package Manager > Metadata.
- Expand Samples and select Import beside the Object Picking sample.
After the import process completes, you can view the imported assets under the Assets/Samples/Cloud Metadata folder.
Run the sample
To run the sample, follow these steps:
- In your Unity project, go to File > Open Scene.
- Go to
Assets/Samples/Cloud Metadata/<package-version>/Object Picking Scene/ObjectPicking.unityand run the scene. - In the Game view, select Login if you are logged out. > Note: If you've previously logged in, the sample automatically logs you in so you can proceed to step 6.
- Log into the browser window that launches with your Unity ID account.
- Return to the sample scene to confirm that you are logged in. The Workspace field lists the workspaces associated with your account.
- Select a workspace from the Workspace field.
- Select a scene from the Scene field.
- Select Launch Scene to download and view the associated scene.
You can now navigate using the mouse and keyboard keys in the scene, and click on the model to view its attached metadata.
BIM Metadata window
The left-side window shows your metadata once you click on a 3D object in your scene. Root keys appear as title to the different categories, while key-values contained in your metadata appear on the same line. Use your mouse or the mouse wheel to navigate this window.
Main components
Metadata Raycaster
The MetadataRaycaster class demonstrates how the MetadataProvider and the DataStreamer are instantiated to launch a scene. The selected scene is provided as an IScene parameter.
The IScene parameter passes to the MetadataProvider to prepare the metadata queries. The same IScene is also passed to the DataStreamer, which loads and displays the associated scene.
When you left-click the streamed scene, the script calls RaycastAsync from the DataStreamer with the mouse position. The returned RaycastResult will contain the instance's id of the clicked object.
This id is then passed to the MetadataProvider to build a query and fetch its attached metadata, then displayed in the BIM Metadata window.
To open the metadata raycaster script, go to the Assets/Samples/Unity Cloud Metadata/<package-version>/Object Picking Scene/ObjectPicking.unity/Scripts/MetadataRaycaster.cs file.
Platform services script
The PlatformServices class initializes and disposes of the dependencies that the sample requires. The PlatformServices class exposes these services so that any component of the sample that requires access to a Unity Cloud service has easy access.
The PlatformServices class has two accompanying classes named PlatformServicesInitialization and PlatformServicesShutdown that call the initialization and shutdown methods through Unity's standard Monobehaviour methods Awake(), Start() and OnDestroy().
To open the platform services script, go to the Assets/Samples/Unity Cloud Metadata/<package-version>/Shared/Scripts/PlatformServices.cs file.
Publishing metadata and creating indexed texture
Because of the newness of the metadata and the data-streaming raycasting features, most of your "old" scenes will not contain metadata or index textures by default. The dashboard is set up to populate metadata and create index textures to all the new files that you will send through the dashboard.
To publish metadata and create indexed texture, follow these steps:
- Log into the Digital Twin Dashboard.
- Upload a file to the dashboard.
When using the default workflow, the cloud should automatically fill the database with metadata.
Troubleshooting
You can't see any models when the scene runs
To use the Data Streaming package, your project must use either the High Definition Render Pipeline (HDRP) or the Universal Render Pipeline (URP).
"Nothing Selected" appears in the BIM Metadata window
When you click an object in your scene and the BIM Metadata window is showing "Nothing selected!", this means that your scene was not uploaded recently enough.
Re-upload your model through the dashboard to enable the raycasting feature.
Only the object id appears in the BIM Metadata window
When you click an object in your scene and the BIM Metadata window is only showing the object id, this means that no metadata is attached to this object in your original file.