I would like to change the material of all the spatial meshes at runtime:
If I start the application in Room1, then walk to Room2 and change the material to "newMaterial" I can do that with the following code:
foreach (SpatialAwarenessMeshObject meshObject in observer.Meshes.Values)
{
if (meshObject?.GameObject == null)
continue;
meshObject.Renderer.sharedMaterial = newMaterial;
}
But the above code changes only the visible meshes (so the meshes in Room2). Because if I walk back to Room1 I still have the old material.
So how I can ensure that the material is changed with all the meshes, and not only the visible ones?
To sets the Material to be used when displaying Meshes, it is recommended to change the configuration of Spatial Awareness Mesh Observer instead of change every mesh object. Please refer to the following code:
IMixedRealityDataProviderAccess dataProviderAccess =
CoreServices.SpatialAwarenessSystem as IMixedRealityDataProviderAccess;
if (dataProviderAccess != null)
{
IReadOnlyList<IMixedRealitySpatialAwarenessMeshObserver> observers =
dataProviderAccess.GetDataProviders<IMixedRealitySpatialAwarenessMeshObserver>();
foreach (IMixedRealitySpatialAwarenessMeshObserver observer in observers)
{
// Update the visible material
observer.VisibleMaterial = myMaterial;
}
}