Sample: Display Metadata Based on Ray Casting
The sample available as part of the Unity Cloud Metadata package demonstrates how the Metadata package and the Unity Cloud 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.
Important
This sample is designed to work on PC. It may not behave as expected on other platforms, such as iOS or Android.
Before you start
To use the Object Picking sample, you need the following:
- Installed Unity Cloud Common package
- Installed Identity package
- Installed Assets package
- Installed Data-Streaming package
- A valid Unity ID
- At least one asset in your organization where the dataset has went through
3d-data-streaming
workflow transformation.
Install the sample
To install the sample, follow these steps:
- In your Unity Editor Project, go to Window > Package Manager > Metadata.
- Expand the Samples section.
- On the right of the Object Picking sample, select Import.
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.unity
and 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.
From the Organization field, select an organization.
From the Project field, select a project.
From the Asset field, select an asset.
From the Dataset field, select the dataset called
3D data streaming
.Select Launch to download and view the associated dataset. You can now query the metadata attached to the dataset.
Note
You can now navigate using the mouse and keyboard keys in the scene, and select the model to view its attached metadata.
BIM Metadata window
The left-side window shows your metadata once you select a 3D object in your dataset. 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 MetadataRepository
and the DataStreamer
are instantiated to launch a scene. The selected dataset is provided as an IDataset
parameter.
The IDataset
parameter passes to the MetadataRepository
to prepare the metadata queries. The same IDataset
is also passed to the DataStreamer
, which loads and displays the associated dataset.
When you select the streamed dataset, the script calls RaycastAsync
from the DataStreamer
with the mouse position. The returned RaycastResult
will contain the instance's id of the selected object.
This id is then passed to the MetadataRepository
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
To publish metadata and create indexed texture, follow these steps:
- Log in to cloud.unity.com.
- Create an asset in your Organization's dashboard.
- Upload a BIM file containing metadata in your asset.
- Apply the
cloud-3d-3dds
workflow transformation.
Troubleshooting
Refer to the troubleshooting section for help with the Object Picking sample.