Uploaded by 03.dab.showy

RealityKitCamera

advertisement
Documentation / RealityKit / Cameras and lighting
Language: Swift API Changes: None
Cameras and lighting
Control the lighting and point of view for a scene.
Overview
In RealityKit, cameras define the point of view from which a scene is rendered. In AR mode,
RealityKit creates and controls the camera for you based on the location and orientation of
the device. In non-AR mode, control the camera by making changes to the transform
component of the PerspectiveCamera entity.
Topics
Cameras
class PerspectiveCamera
A virtual camera that establishes the rendering perspective.
struct PerspectiveCameraComponent
In AR applications, the camera is automatically provided by the system. In non-AR
scenarios, the camera needs to be set by the app. (If no camera is provided by the
app, the system will use default camera.)
Lighting
class PointLight
/
/ Cameras and
Documentation Realit…
lighting
/
PerspectiveCamera
Language: Swift API Changes: None
Class
PerspectiveCamera
A virtual camera that establishes the rendering perspective.
iOS 13.0+
iPadOS 13.0+
macOS 10.15+
Mac Catalyst 13.0+
visionOS 1.0+
@MainActor @preconcurrency
class PerspectiveCamera
Overview
During an AR session, RealityKit automatically uses the deviceʼs camera to define the
perspective from which to render the scene. When rendering a scene outside of an AR session
(with the viewʼs cameraMode property set to ARView.CameraMode.nonAR), RealityKit uses
a PerspectiveCamera instead. You can add a perspective camera anywhere in your scene to
control the point of view. If you donʼt explicitly provide one, RealityKit creates a default camera
for you.
Topics
Creating a Camera
init()
Creates a perspective camera entity.
Configuring the Camera
var camera: PerspectiveCameraComponent
A camera component for the perspective camera entity.
struct PerspectiveCameraComponent
In AR applications, the camera is automatically provided by the system. In non-AR
scenarios, the camera needs to be set by the app. (If no camera is provided by the app,
the system will use default camera.)
protocol HasPerspectiveCamera
An interface that enables you to configure a virtual camera that you can use to define the
rendering perspective when youʼre not in an AR session.
Positioning Entities in Space
The Transform Component
Synchronizing an Entity Among Peers
struct SynchronizationComponent
A component that synchronizes an entity between processes and networked applications.
Default Implementations
HasPerspectiveCamera Implementations
Relationships
Inherits From
Entity
Conforms To
CustomDebugStringConvertible
Equatable
EventSource
HasHierarchy
HasPerspectiveCamera
HasSynchronization
HasTransform
Hashable
Identifiable
RealityCoordinateSpace
Sendable
See Also
Cameras
struct PerspectiveCameraComponent
In AR applications, the camera is automatically provided by the system. In non-AR
scenarios, the camera needs to be set by the app. (If no camera is provided by the app,
the system will use default camera.)
/
/ Cameras and
Documentation Realit…
lighting
/
/
PerspectiveCamera
init()
Language: Swift API Changes: None
Initializer
init()
Creates a perspective camera entity.
iOS 13.0+
iPadOS 13.0+
@MainActor
required init()
macOS 10.15+
Mac Catalyst 13.0+
visionOS 1.0+
/
/ Cameras and
Documentation Reali…
lighting
/
/
PerspectiveCamera
camera
Language: Swift API Changes: Non
Instance Property
camera
A camera component for the perspective camera entity.
iOS 13.0+
iPadOS 13.0+
macOS 10.15+
Mac Catalyst 13.0+
visionOS 1.0+
@MainActor
var camera: PerspectiveCameraComponent { get set }
See Also
Configuring the Camera
struct PerspectiveCameraComponent
In AR applications, the camera is automatically provided by the system. In non-AR scenarios,
the camera needs to be set by the app. (If no camera is provided by the app, the system will
use default camera.)
protocol HasPerspectiveCamera
An interface that enables you to configure a virtual camera that you can use to define the
rendering perspective when youʼre not in an AR session.
/ PerspectiveCameraComponent
Documentation / Realit… / Component
Language: Swift API Changes: None
Structure
PerspectiveCameraComponent
In AR applications, the camera is automatically provided by the system. In non-AR
scenarios, the camera needs to be set by the app. (If no camera is provided by the
app, the system will use default camera.)
iOS 13.0+
iPadOS 13.0+
macOS 10.15+
Mac Catalyst 13.0+
visionOS 1.0+
struct PerspectiveCameraComponent
Topics
Creating a Camera Component
init(near: Float, far: Float, fieldOfViewInDegrees: Float)
Creates a new perspective camera component with the given settings.
Setting Focal Points
var far: Float
The maximum distance in meters from the camera that the camera can see.
var near: Float
The minimum distance in meters from the camera that the camera can see.
Setting the Field of View
var fieldOfViewInDegrees: Float
The cameraʼs total vertical field of view in degrees.
Registering a Component Type
static func registerComponent()
Registers a new component type.
Comparing Perspective Camera Components
static func == (PerspectiveCameraComponent, PerspectiveCamera
Component) -> Bool
Indicates whether two perspective camera components are equal.
static func != (Self, Self) -> Bool
Indicates whether two perspective camera components are not equal.
Default Implementations
Component Implementations
Equatable Implementations
Relationships
Conforms To
Component, Equatable
See Also
Simulations
struct CollisionComponent
A component that gives an entity the ability to collide with other entities that also have
collision components.
struct PhysicsBodyComponent
A component that defines an entityʼs behavior in physics body simulations.
struct PhysicsMotionComponent
A component that controls the motion of the body in physics simulations.
struct PhysicsSimulationComponent
A component that controls localized physics simulations.
struct ParticleEmitterComponent
/ PerspectiveCameraComponent
/ init(near:far:fieldOfViewInDegrees:)Language: Swift API Changes:
Documentation / Rea… / Component
Initializer
init(near:far:fieldOfViewInDegrees:)
Creates a new perspective camera component with the given settings.
iOS 13.0+
iPadOS 13.0+
macOS 10.15+
Mac Catalyst 13.0+
visionOS 1.0+
init(
near: Float = 0.01,
far: Float = .infinity,
fieldOfViewInDegrees: Float = 60.0
)
Discussion
near: The minimum distance in meters from the camera that the camera can see.
far: The maximum distance in meters from the camera that the camera can see.
fieldOfViewInDegrees: The cameraʼs field of view, given in degrees.
/ PerspectiveCameraComponent
/ far
Documentation / Realit… / Component
Language: Swift API Changes: None
Instance Property
far
The maximum distance in meters from the camera that the camera can see.
iOS 13.0+
iPadOS 13.0+
macOS 10.15+
Mac Catalyst 13.0+
visionOS 1.0+
var far: Float
Discussion
The value defaults to infinity. Always use a value greater than the value of near. The renderer
clips any surface beyond the far point.
See Also
Setting Focal Points
var near: Float
The minimum distance in meters from the camera that the camera can see.
/ PerspectiveCameraComponent
/ near
Documentation / Reali… / Component
Language: Swift API Changes: None
Instance Property
near
The minimum distance in meters from the camera that the camera can see.
iOS 13.0+
iPadOS 13.0+
macOS 10.15+
Mac Catalyst 13.0+
visionOS 1.0+
var near: Float
Discussion
The value defaults to 1 centimeter. Always use a value greater than 0 and less than the value of
far. The renderer clips any surface closer than the near point.
See Also
Setting Focal Points
var far: Float
The maximum distance in meters from the camera that the camera can see.
/ PerspectiveCameraComponent
/ fieldOfViewInDegrees
Documentation / Real… / Component
Language: Swift API Changes:
Instance Property
fieldOfViewInDegrees
The cameraʼs total vertical field of view in degrees.
iOS 13.0+
iPadOS 13.0+
macOS 10.15+
Mac Catalyst 13.0+
visionOS 1.0+
var fieldOfViewInDegrees: Float
Discussion
This property contains the entire vertifical field of view for the camera in degrees. The system
automatically calculates the horizontal field of view from this value to fit the aspect ratio of the
deviceʼs screen.
This property defaults to 60 degrees.
/ PerspectiveCameraComponent
/ registerComponent()
Documentation / Real… / Component
Language: Swift API Changes:
Type Method
registerComponent()
Registers a new component type.
iOS 13.0+
iPadOS 13.0+
macOS 10.15+
Mac Catalyst 13.0+
visionOS 1.0+
static func registerComponent()
Discussion
Call the registerComponent() method once for every custom component type that you use in
your app before you use it. You donʼt need to call the method for built-in component types, like
ModelComponent or AnchoringComponent.
/
/
/
/ ==
Documentation Reali… ComponentPerspectiveCameraComponent
(_:_:)
Language: Swift API Changes:
Operator
==(_:_:)
Indicates whether two perspective camera components are equal.
iOS 13.0+
iPadOS 13.0+
macOS 10.15+
Mac Catalyst 13.0+
visionOS 1.0+
static func == (a: PerspectiveCameraComponent, b: PerspectiveCameraComponent) -> Boo
Parameters
a
The first perspective camera component to compare.
b
The second perspective camera component to compare.
Return Value
A Boolean value set to true if the two perspective camera components are equal.
See Also
Comparing Perspective Camera Components
static func != (Self, Self) -> Bool
Indicates whether two perspective camera components are not equal.
/
/
/
/ !=
Documentation Reali… ComponentPerspectiveCameraComponent
(_:_:)
Language: Swift API Changes:
Operator
!=(_:_:)
Indicates whether two perspective camera components are not equal.
RealityKit
Swift
iOS 13.0+
iPadOS 13.0+
macOS 10.15+
static func != (lhs: Self, rhs: Self) -> Bool
Mac Catalyst 13.0+
visionOS 1.0+
Parameters
lhs
The first perspective camera component to compare.
rhs
The second perspective camera component to compare.
Return Value
A Boolean value set to true if the two perspective camera components are not equal.
See Also
Comparing Perspective Camera Components
static func == (PerspectiveCameraComponent, PerspectiveCameraComponent)
-> Bool
Indicates whether two perspective camera components are equal.
2/9/24, 8:59 PM
HasPerspectiveCamera | Apple Developer Documentation
/
/ Cameras and
Documentation Realit…
lighting
/
HasPerspectiveCamera
Language: Swift API Changes: No
Protocol
HasPerspectiveCamera
An interface that enables you to configure a virtual camera that you can use to
define the rendering perspective when you’re not in an AR session.
iOS 13.0+
iPadOS 13.0+
macOS 10.15+
Mac Catalyst 13.0+
visionOS 1.0+
Topics
Getting the Camera
var camera: PerspectiveCameraComponent
A camera component for the perspective camera entity.
struct PerspectiveCameraComponent
In AR applications, the camera is automatically provided by the system. In non-AR scenarios,
the camera needs to be set by the app. (If no camera is provided by the app, the system will
use default camera.)
Relationships
Inherits From
HasTransform
https://developer.apple.com/documentation/realitykit/hasperspectivecamera
1/2
2/9/24, 8:59 PM
HasPerspectiveCamera | Apple Developer Documentation
Conforming Types
PerspectiveCamera
See Also
Entity Compliance
protocol HasPointLight
An interface that defines a point light source component.
protocol HasDirectionalLight
An interface that defines a directional light source component.
protocol HasSpotLight
An interface that defines a spot light source component.
https://developer.apple.com/documentation/realitykit/hasperspectivecamera
2/2
2/9/24, 8:59 PM
camera | Apple Developer Documentation
/
/ Cameras and
Documentation Reali…
lighting
/
/
HasPerspectiveCamera
camera
Language: Swift API Changes: N
Instance Property
camera
A camera component for the perspective camera entity.
iOS 13.0+
iPadOS 13.0+
macOS 10.15+
Mac Catalyst 13.0+
visionOS 1.0+
See Also
Getting the Camera
struct PerspectiveCameraComponent
In AR applications, the camera is automatically provided by the system. In non-AR scenarios,
the camera needs to be set by the app. (If no camera is provided by the app, the system will
use default camera.)
https://developer.apple.com/documentation/realitykit/hasperspectivecamera/camera
1/1
2/9/24, 8:59 PM
PerspectiveCameraComponent | Apple Developer Documentation
Documentation / Realit… / Component/PerspectiveCameraComponent
Language: Swift API Changes: No
Structure
PerspectiveCameraComponent
In AR applications, the camera is automatically provided by the system. In non-AR
scenarios, the camera needs to be set by the app. (If no camera is provided by the
app, the system will use default camera.)
iOS 13.0+
iPadOS 13.0+
macOS 10.15+
Mac Catalyst 13.0+
visionOS 1.0+
Topics
Creating a Camera Component
init(near: Float, far: Float, fieldOfViewInDegrees: Float)
Creates a new perspective camera component with the given settings.
Setting Focal Points
var far: Float
The maximum distance in meters from the camera that the camera can see.
var near: Float
The minimum distance in meters from the camera that the camera can see.
Setting the Field of View
var fieldOfViewInDegrees: Float
The camera’s total vertical field of view in degrees.
https://developer.apple.com/documentation/realitykit/perspectivecameracomponent
1/3
2/9/24, 8:59 PM
PerspectiveCameraComponent | Apple Developer Documentation
Registering a Component Type
static func registerComponent()
Registers a new component type.
Comparing Perspective Camera Components
static func == (PerspectiveCameraComponent, PerspectiveCameraComponent)
-> Bool
Indicates whether two perspective camera components are equal.
static func != (Self, Self) -> Bool
Indicates whether two perspective camera components are not equal.
Default Implementations
Component Implementations
Equatable Implementations
Relationships
Conforms To
Component, Equatable
See Also
Simulations
struct CollisionComponent
A component that gives an entity the ability to collide with other entities that also have
collision components.
https://developer.apple.com/documentation/realitykit/perspectivecameracomponent
2/3
2/9/24, 8:59 PM
PerspectiveCameraComponent | Apple Developer Documentation
struct PhysicsBodyComponent
A component that defines an entity’s behavior in physics body simulations.
struct PhysicsMotionComponent
A component that controls the motion of the body in physics simulations.
struct PhysicsSimulationComponent
A component that controls localized physics simulations.
struct ParticleEmitterComponent
https://developer.apple.com/documentation/realitykit/perspectivecameracomponent
3/3
2/9/24, 8:59 PM
init(near:far:fieldOfViewInDegrees:) | Apple Developer Documentation
Documentation / Real… / Component
/ PerspectiveCameraComponent
/ init(near:far:fieldOfViewInDegrees:) Language: Swift API Chang
Initializer
init(near:far:fieldOfViewInDegrees:)
Creates a new perspective camera component with the given settings.
iOS 13.0+
iPadOS 13.0+
macOS 10.15+
Mac Catalyst 13.0+
visionOS 1.0+
Discussion
near: The minimum distance in meters from the camera that the camera can see.
far: The maximum distance in meters from the camera that the camera can see.
fieldOfViewInDegrees: The camera’s field of view, given in degrees.
https://developer.apple.com/documentation/realitykit/perspectivecameracomponent/init(near:far:fieldofviewindegrees:)
1/1
2/9/24, 9:00 PM
far | Apple Developer Documentation
Documentation / Realit… / Component
/ PerspectiveCameraComponent
/ far
Language: Swift API Changes: N
Instance Property
far
The maximum distance in meters from the camera that the camera can see.
iOS 13.0+
iPadOS 13.0+
macOS 10.15+
Mac Catalyst 13.0+
visionOS 1.0+
Discussion
The value defaults to infinity. Always use a value greater than the value of near. The renderer clips
any surface beyond the far point.
See Also
Setting Focal Points
var near: Float
The minimum distance in meters from the camera that the camera can see.
https://developer.apple.com/documentation/realitykit/perspectivecameracomponent/far
1/1
2/9/24, 9:00 PM
near | Apple Developer Documentation
Documentation / Realit… / Component
/ PerspectiveCameraComponent
/ near
Language: Swift API Changes: N
Instance Property
near
The minimum distance in meters from the camera that the camera can see.
iOS 13.0+
iPadOS 13.0+
macOS 10.15+
Mac Catalyst 13.0+
visionOS 1.0+
Discussion
The value defaults to 1 centimeter. Always use a value greater than 0 and less than the value of
far. The renderer clips any surface closer than the near point.
See Also
Setting Focal Points
var far: Float
The maximum distance in meters from the camera that the camera can see.
https://developer.apple.com/documentation/realitykit/perspectivecameracomponent/near
1/1
2/9/24, 9:00 PM
fieldOfViewInDegrees | Apple Developer Documentation
Documentation / Reali… / Component
/ PerspectiveCameraComponent
/ fieldOfViewInDegrees
Language: Swift API Changes
Instance Property
fieldOfViewInDegrees
The camera’s total vertical field of view in degrees.
iOS 13.0+
iPadOS 13.0+
macOS 10.15+
Mac Catalyst 13.0+
visionOS 1.0+
Discussion
This property contains the entire vertifical field of view for the camera in degrees. The system
automatically calculates the horizontal field of view from this value to fit the aspect ratio of the device’s
screen.
This property defaults to 60 degrees.
https://developer.apple.com/documentation/realitykit/perspectivecameracomponent/fieldofviewindegrees
1/1
2/9/24, 9:00 PM
registerComponent() | Apple Developer Documentation
Documentation / Reali… / Component
/ PerspectiveCameraComponent
/ registerComponent()
Language: Swift API Changes
Type Method
registerComponent()
Registers a new component type.
iOS 13.0+
iPadOS 13.0+
macOS 10.15+
Mac Catalyst 13.0+
visionOS 1.0+
Discussion
Call the registerComponent() method once for every custom component type that you use in your
app before you use it. You don’t need to call the method for built-in component types, like Model
Component or AnchoringComponent.
https://developer.apple.com/documentation/realitykit/perspectivecameracomponent/registercomponent()
1/1
2/9/24, 9:00 PM
==(_:_:) | Apple Developer Documentation
/
/
/
/ ==
Documentation Reali… ComponentPerspectiveCameraComponent
(_:_:)
Language: Swift API Changes: N
Operator
==(_:_:)
Indicates whether two perspective camera components are equal.
iOS 13.0+
iPadOS 13.0+
macOS 10.15+
Mac Catalyst 13.0+
visionOS 1.0+
Parameters
a
The first perspective camera component to compare.
b
The second perspective camera component to compare.
Return Value
A Boolean value set to true if the two perspective camera components are equal.
See Also
Comparing Perspective Camera Components
static func != (Self, Self) -> Bool
Indicates whether two perspective camera components are not equal.
https://developer.apple.com/documentation/realitykit/perspectivecameracomponent/==(_:_:)
1/1
2/9/24, 9:00 PM
!=(_:_:) | Apple Developer Documentation
/
/
/
/ !=
Documentation Reali… ComponentPerspectiveCameraComponent
(_:_:)
Language: Swift API Changes: N
Operator
!=(_:_:)
Indicates whether two perspective camera components are not equal.
RealityKit
Swift
iOS 13.0+
iPadOS 13.0+
macOS 10.15+
Mac Catalyst 13.0+
visionOS 1.0+
Parameters
lhs
The first perspective camera component to compare.
rhs
The second perspective camera component to compare.
Return Value
A Boolean value set to true if the two perspective camera components are not equal.
See Also
Comparing Perspective Camera Components
static func == (PerspectiveCameraComponent, PerspectiveCameraComponent)
-> Bool
Indicates whether two perspective camera components are equal.
https://developer.apple.com/documentation/realitykit/perspectivecameracomponent/!=(_:_:)
1/1
An entity that produces an omnidirectional light for virtual objects.
struct PointLightComponent
A component that defines a point light source.
class DirectionalLight
An entity that casts a virtual light in a particular direction.
struct DirectionalLightComponent
A component that defines a directional light source.
class SpotLight
An entity that illuminates virtual content in a cone-shaped volume.
struct SpotLightComponent
A component that defines a spotlight source.
struct ImageBasedLightComponent
struct ImageBasedLightReceiverComponent
struct GroundingShadowComponent
Entity Compliance
protocol HasPerspectiveCamera
An interface that enables you to configure a virtual camera that you can use to define
the rendering perspective when youʼre not in an AR session.
protocol HasPointLight
An interface that defines a point light source component.
protocol HasDirectionalLight
An interface that defines a directional light source component.
protocol HasSpotLight
An interface that defines a spot light source component.
See Also
Scene content
Models, shapes, and meshes
Use mesh-based models to display virtual objects in your scene.
Materials and shaders
Apply textures to the surface of your sceneʼs 3D objects to give each object a unique
appearance.
Anchors
Anchor an entity to an item in your scene, and specify the position, rotation, and scale
of the entityʼs content.
Scene reconstruction and understanding
Detect objects in an AR scene or create a detailed 3D reconstruction of the real world
environment.
Audio
Add immersive spatial audio to your RealityKit content.
Animation
Dynamically move, rotate, and scale objects at runtime.
protocol RealityCoordinateSpace
A 3D coordinate space that exists within a RealityKit hierarchy. Any Reality
CoordinateSpaceConverting can convert spatial data between SwiftUI
CoordinateSpaces and RealityCoordinateSpaces.
Related documents
Download