ModelComponent
A component that contains a mesh and materials for the visual appearance of an entity.
Declaration
struct ModelComponentMentioned in
Overview
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 generateBox(size:cornerRadius:), and SimpleMaterial:
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)[Image]
Make different primitive shapes, like spheres with generateSphere(radius:), or cylinders with generateCylinder(height:radius:), or create custom shapes with MeshDescriptor. For more information about materials, see Applying realistic material and lighting effects to entities
Use other components like CollisionComponent, PhysicsBodyComponent, PhysicsMotionComponent, and InputTargetComponent to make entities interactive and dynamic.