Meshes are fundamental, immutable shared resources within Azure Remote Rendering (ARR). These digital assets, created through a process of model conversion, serve a dual purpose: they are essential for the visual rendering of 3D scenes and also provide the necessary physics representation for conducting ray cast queries within the remote environment. To integrate a mesh into a 3D space, you need to attach a MeshComponent to an Entity.
Exploring Mesh Types in Azure Remote Rendering
Within ARR, meshes are categorized into two primary types, each serving distinct rendering needs: Triangular meshes and point clouds. Interestingly, both types are unified under the same API class, Mesh
. Despite some subtle differences in their behavior, particularly in how they handle materials and scene graphs, the core API functionality remains consistent across both mesh types.
The ARR conversion service intelligently determines the appropriate mesh type during the conversion process, primarily based on the source file extension. For instance, files in FBX format are invariably converted into triangular meshes, whereas PLY files are processed as point clouds. For a comprehensive list of file formats supported by the service, you can consult the source file formats documentation.
It’s important to note a couple of key distinctions between point cloud and triangular mesh conversions from a user perspective:
- Material Handling: Point cloud meshes are unique in that they do not utilize materials in the conventional sense. The visual characteristics of points in a point cloud are exclusively governed by their per-point color attributes.
- Scene Graph Structure: Point clouds also differ in their scene graph representation. Unlike triangular meshes that can have complex hierarchical scene graphs, point clouds do not expose a scene graph. Instead, all points within a point cloud are directly associated with the root node entity, simplifying their structure and management.
Understanding Mesh Resource Properties
The Mesh
class in ARR exposes several key properties that define its characteristics and usage:
- Materials: This property is presented as an array of materials. Each material in this array corresponds to a specific submesh within the larger mesh structure. It’s worth noting that multiple entries within this array can reference the same material resource, promoting efficient material reuse. While the material array itself is immutable at runtime, the properties of the materials it contains can be dynamically adjusted to achieve various visual effects. For point cloud meshes, this array remains empty due to their unique material handling.
- Bounds: This property defines the local-space axis-aligned bounding box (AABB) that encloses all vertices of the mesh. The bounds are crucial for spatial calculations and optimizations within the rendering engine.
MeshComponent: Instantiating Meshes in the Scene
To effectively utilize a mesh resource in a rendered scene, the MeshComponent
class is essential. This component serves as the mechanism to place an instance of a mesh resource within the 3D environment. Each MeshComponent
is linked to a single mesh resource, defining the geometry it will render. Importantly, MeshComponent
offers the flexibility to override the materials that are initially defined within the mesh resource for each submesh, allowing for instance-specific material variations.
Key Properties of MeshComponent
- Mesh: This is the core property of the
MeshComponent
, referencing the specific mesh resource that this component will utilize for rendering. Changing this property allows for dynamic swapping of the rendered mesh. - Materials: This property is an array of materials associated directly with the mesh component. The length of this array is always consistent with the Materials array found in the linked mesh resource. Within this array, you can specify materials to override the defaults from the mesh resource. If an entry is set to null, it indicates that the corresponding submesh should use its default material from the mesh resource.
- UsedMaterials: This read-only array provides insight into the materials that are actually being used for each submesh in the rendering process. For each submesh, if a non-null material is specified in the Materials array of the MeshComponent, UsedMaterials will reflect that material. Otherwise, it will contain the default material from the mesh resource’s Materials array. This property is valuable for understanding the final material configuration applied to the mesh instance.
Efficient Sharing of Mesh Resources
A significant advantage of ARR’s mesh resource management is the ability to share a single Mesh
resource across multiple instances of mesh components. This sharing mechanism is crucial for optimizing memory usage and rendering efficiency, especially in scenes with repeated geometry. Furthermore, the Mesh
resource assigned to a mesh component can be programmatically altered at any time, providing dynamic control over scene content.
The following code snippet demonstrates a practical example of how to clone an entity along with its associated mesh, effectively sharing the mesh resource:
Entity CloneEntityWithModel(RenderingConnection api, Entity sourceEntity)
{
MeshComponent meshComp = sourceEntity.FindComponentOfType<MeshComponent>();
if (meshComp != null)
{
Entity newEntity = api.CreateEntity();
MeshComponent newMeshComp = api.CreateComponent(ObjectType.MeshComponent, newEntity) as MeshComponent;
newMeshComp.Mesh = meshComp.Mesh; // share the mesh
return newEntity;
}
return null;
}
ApiHandle<Entity> CloneEntityWithModel(ApiHandle<RenderingConnection> api, ApiHandle<Entity> sourceEntity)
{
if (ApiHandle<MeshComponent> meshComp = sourceEntity->FindComponentOfType<MeshComponent>())
{
ApiHandle<Entity> newEntity = *api->CreateEntity();
ApiHandle<MeshComponent> newMeshComp = api->CreateComponent(ObjectType::MeshComponent, newEntity)->as<MeshComponent>();
newMeshComp->SetMesh(meshComp->GetMesh()); // share the mesh
return newEntity;
}
return nullptr;
}
This code efficiently duplicates entities while ensuring that the underlying mesh data is shared, thereby minimizing resource consumption and streamlining rendering processes, particularly beneficial in remote rendering scenarios where bandwidth and processing power are optimized for efficient streaming and interaction. The ability to remotely manage and efficiently render complex meshes has been significantly enhanced in recent advancements, allowing for more detailed and interactive 3D experiences delivered through cloud-based services.
API Documentation
For detailed information on the classes and functions discussed, please refer to the comprehensive API documentation.
Next Steps
To further explore related topics and expand your understanding of Azure Remote Rendering, consider reviewing the following resources: