One Logo Pool Ball
RealityFoundation · IOS API REFERENCE

ModelComponent

struct · iOS 13.0+ · SDK 27.1

struct ModelComponent

A component that contains a mesh and materials for the visual appearance of an entity. This component is a foundational component for all visual content in RealityKit. Use `ModelComponent` to render 3D models by attaching it to any ``Entity`` in your RealityKit scene. To create a `ModelComponent`, you need a mesh and the number of materials that mesh expects, which is typically one. For example, here's how to create a simple blue, metallic box using ``MeshResource/generateBox(size:cornerRadius:)-8em0v``, and ``SimpleMaterial``: ```swift let mesh = MeshResource.generateBox(size: 1, cornerRadius: 0.05) let material = SimpleMaterial(color: .blue, isMetallic: true) let modelComponent = ModelComponent(mesh: mesh, materials: [material]) let entity = Entity() entity.components.set(modelComponent) ``` ![A screenshot of a reflective, metallic blue cube centered on the screen with a plain background.](modelcomponent-cube-simple) Make different primitive shapes, like spheres with ``MeshResource/generateSphere(radius:)-5v3w2``, or cylinders with ``MeshResource/generateCylinder(height:radius:)``, or create custom shapes with ``MeshDescriptor``. For more information about materials, see <doc:applying-realistic-material-and-lighting-effects-to-entities> > Tip: To load a USDZ or reality file to your app, use an entity initializer such as ``Entity/init(named:in:)`` or ``Entity/init(contentsOf:withName:)``. Use other components like ``CollisionComponent``, ``PhysicsBodyComponent``, ``PhysicsMotionComponent``, and ``InputTargetComponent`` to make entities interactive and dynamic.

Members (7)

get · iOS 15.0+

boundsMargin

TypeScript
get boundsMargin(): number
Swift declaration
var boundsMargin: Float { get set }

A margin applied to an entity’s bounding box that determines object visibility. When determining which entities are currently visible, RealityKit tests each entity’s bounding box to see if it overlaps with the camera’s field of view (also known as the camera’s _frustum_). For efficiency, entities with a bounding box that don’t overlap the camera’s frustum aren’t rendered. Use this property to prevent RealityKit from incorrectly culling entities that use a ``CustomMaterial`` with a geometry modifier that moves vertices outside of the entity’s bounding box. RealityKit adds the value of `boundsMargin` to the bounding box before determining which entities are visible. - Note: On visionOS, if a mesh has an incorrect axis-aligned bounding box (AABB), you might see pixelated passthrough artifacts on the mesh due to inaccurate depth reprojection. Provide a correct AABB for your virtual content, or if the mesh is animated by a shader, make the AABB more conservative using this property.

set · iOS 15.0+

boundsMargin

TypeScript
set boundsMargin(value: number)
Swift declaration
var boundsMargin: Float { get set }

A margin applied to an entity’s bounding box that determines object visibility. When determining which entities are currently visible, RealityKit tests each entity’s bounding box to see if it overlaps with the camera’s field of view (also known as the camera’s _frustum_). For efficiency, entities with a bounding box that don’t overlap the camera’s frustum aren’t rendered. Use this property to prevent RealityKit from incorrectly culling entities that use a ``CustomMaterial`` with a geometry modifier that moves vertices outside of the entity’s bounding box. RealityKit adds the value of `boundsMargin` to the bounding box before determining which entities are visible. - Note: On visionOS, if a mesh has an incorrect axis-aligned bounding box (AABB), you might see pixelated passthrough artifacts on the mesh due to inaccurate depth reprojection. Provide a correct AABB for your virtual content, or if the mesh is animated by a shader, make the AABB more conservative using this property.

init · iOS 13.0+

init

TypeScript
static init(mesh: MeshResource, materials: Array<SDKHandle>): ModelComponent
Swift declaration
init(mesh: MeshResource, materials: [any Material])

Creates a model component from a mesh and a collection of materials. - Parameters: - mesh: The mesh that describes the shape of the model. - materials: Materials used to give the mesh a certain visual appearance.

get · iOS 13.0+

mesh

TypeScript
get mesh(): MeshResource
Swift declaration
var mesh: MeshResource

The mesh that defines the model's shape.

set · iOS 13.0+

mesh

TypeScript
set mesh(value: MeshResource)
Swift declaration
var mesh: MeshResource

The mesh that defines the model's shape.

get · iOS 13.0+

materials

TypeScript
get materials(): Array<SDKHandle>
Swift declaration
var materials: [any Material]

The materials that define the model's visual appearance. Each ``RealityKit/MeshResource`` requires a set of materials. An entity that has no materials renders using a magenta striped material. To determine the number of materials a mesh requires, use ``MeshResource/expectedMaterialCount``.

set · iOS 13.0+

materials

TypeScript
set materials(value: Array<SDKHandle>)
Swift declaration
var materials: [any Material]

The materials that define the model's visual appearance. Each ``RealityKit/MeshResource`` requires a set of materials. An entity that has no materials renders using a magenta striped material. To determine the number of materials a mesh requires, use ``MeshResource/expectedMaterialCount``.

Skipped declarations

No declarations were skipped in this snapshot.

All RealityFoundation types →