Backports RealityView's init(make:update:attachments) to non-visionOS platforms.
- Use as a standard SPM dependency
- Import
AttachmentsEverywherein your code - Replace any
RealityViewthat usesinit(make:update:attachments:)withAttachableRealityView - Your code will probably (hopefully) compile, though it may not function properly without tweaking
In order to approach the usability of attachments on visionOS, AttachmentsEverywhere provides some
extensions on top of the RealityKit API. These extensions are not available on visionOS, and
therefore must be wrapped inside #if !os(visionOS).
By default, AttachmentsEverywhere adds a glass background (rather, a crude facsimile of it) to
attachments. Use the .glassBackgroundStyle(_:) modifier on Attachment with a
GlassBackgroundType in order to customize this behavior:
.capsule: The view's glass background will be a capsule (corner radius equal to half the height of the attachment)..roundedRectangle(cornerRadius:): The view's glass background will be a rounded rectangle, with a corner radius defined in points..none: The view will not have a glass background.
Use .onTapGesture(_:) on Attachment in order to respond to tap gestures. At this time, this is
the only supported gesture. Your closure will be passed a CGPoint which is the location of the tap
in your view's coordinate space.
By default, attachment view entities are scaled such that 300 points is equivalent to one
(RealityView) meter. In order to customize this scaling, apply the
.attachmentScale(pointsPerMeter:) view modifier outside your AttachableRealityView.
AttachmentsEverywhere relies on SwiftUI's current behavior regarding RealityView view updates.
This behavior could change in future OS releases (i.e., past iOS 18.0 and macOS 15.0) and some
features of this library may cease functioning. This library is intended as a stopgap solution until
Apple (hopefully) adds attachments to non-visionOS platforms. As such, this library has some quirks
regarding its functionality that should be taken into account.
Attachments will be re-rendered when ImageRenderer determines their state to have changed.
Crucially, this only seems to take into account States, Bindings, etc. held inside the
attachment views. State held outside of AttachableRealityView will not automatically re-render
attachment views. Such state must be passed into Attachments with Binding (and similar).
Every time RealityView would call the update closure, AttachmentsEverywhere reevaluates the
attachments closure. This means that Attachments can be dynamically added or removed (with
result builder control flow) in response to state changes, though your surrounding view must depend
on these state variables. Just like with RealityView, any attachments must be added to the scene
manually. Any attachments that are removed due to a state change will be automatically removed from
the scene.
At this time (until I find a clean way to make it function), ForEach is not supported
in the attachments closure. Instead, use a for-in loop, as it is supported.
- Support
ForEach(if possible) in order to bolster code compatibility - Support other gestures
- Create better glass material