3D attributes filtering
3D object scene layers can also include attributes to allow you to visualize the objects in the layer in a more meaningful way. 3D Object scene layers have attributes with values for each node. Depending on how the layer was authored, the cached attributes can have a slew of different information.
To see which attributes are included in the 3D Object scene layer you are using, you can open the URL in your web browser and reference the
field section of the service definition JSON. The New York building data in our sample found here shows all of its attributes which you can see (
Before you begin to write code, you need to know the attribute types you plan to use. By default, materials and the shaders that render them only support float and integer types in Unity. If you want to use an attribute of a different type, such as strings, you will need to convert these attributes into data that can be processed by the shader.
To learn more about Unity's materials and shaders, visit Unity's documentation.
In the image above is an example of what you can do with the 3D attributes functionality. In this image you see the buildings differently based on their
NUM_ attribute to show buildings with more than 100 floors in red, buildings with more than 20 floors in yellow and the remaining buildings in green.
The image above is an example of how to use the
NAME attribute to visualize the Empire State building in a unique way. Set up an Attribute transform so it can find the feature with the name of "Empire State Building". This gives you the ability to apply a different texture to that specific building. In this example you can also use more complicated textures than just solid colors to bring more realism to the 3D object scene layers that do not have textures baked in.
Once you know the type of attributes that you will work with, you need to include necessary namespaces and write scripts to filter attributes by the name, and pass the data to the materials.
Set allows you to specify which attributes will be published in a texture to the
Material. By default, no attributes are published to the material, so using the
Set allows you to set an array of the attributes you want to publish. This step requires you to have knowledge of the attributes in your layer.
When setting an attribute that is either a float or an integer, you can pass them directly to the shader. Doubles can also be passed directly to the shader however internally they are being converted to a float so expect some loss of precision.
GPUs generally do not support strings and other non-numeric data types. To use attributes with other types, you need to use the
ArcGISAttribute to convert these types into meaningful integer or floating point values that are compatible with the material.
Material property on the
ArcGIS3DObject allows you to specify a material to render the layer with. You can use this method without using any layer attributes to render the layer with a different material than the one used by default by the layer.
There are some helper functions provided in the ArcGIS Maps SDK for Unity that allow you to easily access the attribute data according to the data's type in the shader. These helper functions,
Read output the value of the attribute. Which one you use depends on the type of data being exposed in the shader.
You can use the attribute processor to convert custom data types into a suitable format that can be read by the GPU. If you don't use the attribute processor to convert data, you can use
Read depending on the data. See table below.
|Field type||Helper function (without attribute processor)|
You can convert the data to
Int32 with the attribute processor. Depending on data type, you should use either
Read helper function. You can also use the attribute processor with float, integer, and double type attributes if you want to process the original data.
You can find the sample script file that filters 3D attributes and apply different materials that are used in the 3DAttributesSample in the Sample3DAttributesComponent.cs file. You can find the file in:
Assets/Samples/ArcGIS Maps SDK for Unity/1.0.0/All Samples/Scripts/3DAttributesSample
You can also find the materials used in the 3DAttributesSample for both HDRP and URP in:
Assets/Samples/ArcGIS Maps SDK for Unity/1.0.0/All Samples/Resouces