Skip to content

Instantly share code, notes, and snippets.

//
// View+AttachmentPivot.swift
//
// Created by Drew Olbrich on 4/11/24.
// Copyright © 2024 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@drewolbrich
drewolbrich / View+WindowGeometryPreferences.swift
Last active April 8, 2024 11:00
A visionOS SwiftUI view modifier that can be used to hide a window's resize handles or to constrain a window's aspect ratio
//
// View+WindowGeometryPreferences.swift
//
// Created by Drew Olbrich on 1/30/24.
// Copyright © 2024 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@drewolbrich
drewolbrich / MeshEntity+GenerateSolidInteriorModel.swift
Last active March 6, 2024 15:46
A RealityKit ModelEntity extension that replaces its model with a new model with reversed triangle indices
//
// MeshEntity+GenerateSolidInteriorModel.swift
//
// Created by Drew Olbrich on 12/16/23.
// Copyright © 2023 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@drewolbrich
drewolbrich / ScaledVolumeContentView.swift
Last active March 20, 2024 22:22
An example of how to make visionOS volumes work correctly with Settings > Display > Appearance > Window Zoom
//
// ScaledVolumeContentView.swift
// VolumeScaleExample
//
// Created by Drew Olbrich on 11/6/23.
// Copyright © 2023 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@drewolbrich
drewolbrich / Entity+MoveAsync.swift
Last active March 6, 2024 15:47
An async version of RealityKit's Entity/move that returns when the animation completes
//
// Entity+MoveAsync.swift
//
// Created by Drew Olbrich on 1/15/24.
// Copyright © 2024 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@drewolbrich
drewolbrich / Entity+Move3.swift
Created January 16, 2024 04:05
Failed attempt #3 at Entity/move with a callback
extension Entity {
/// Animated `Entity/move` with a completion handler.
///
/// This implementation works but for some reason `timingFunction` appears to be
/// ignored and the timing function of the resulting animation is always linear.
func move(to target: Transform, relativeTo referenceEntity: Entity?, duration: TimeInterval, delay: TimeInterval = 0, timingFunction: AnimationTimingFunction = .default, completion: @escaping () -> Void) {
guard let scene else {
completion()
return
@drewolbrich
drewolbrich / Entity+Move2.swift
Created January 16, 2024 01:55
Failed attempt #2 at Entity/move with a callback
import Foundation
import RealityKit
import Combine
private var playbackCompletedSubscriptions: Set<AnyCancellable> = .init()
extension Entity {
/// Animated `Entity/move` with a completion handler.
///
@drewolbrich
drewolbrich / Entity+Move1.swift
Created January 16, 2024 01:54
Failed attempt #1 at Entity/move with a callback
import Foundation
import RealityKit
import Combine
private var playbackCompletedSubscriptions: Set<AnyCancellable> = .init()
extension Entity {
/// Animated `Entity/move` with a completion handler.
///
@drewolbrich
drewolbrich / simd_matrix4x4+VectorMultiply.swift
Last active March 6, 2024 15:50
RealityKit/SIMD multiply a 4x4 matrix by a 3-vector
//
// simd_matrix4x4+VectorMultiply.swift
//
// Created by Drew Olbrich on 1/3/24.
// Copyright © 2024 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@drewolbrich
drewolbrich / ARCamera+FieldOfView.swift
Last active March 6, 2024 15:50
The field of view of the ARKit device camera.
//
// ARCamera+FieldOfView.swift
//
// Created by Drew Olbrich on 1/3/24.
// Copyright © 2024 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal