Skip to content

Instantly share code, notes, and snippets.

@drewolbrich
drewolbrich / View+WindowGeometryPreferences.swift
Last active April 29, 2024 14:34
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 / WindowBarGestureModifier.swift
Last active April 17, 2024 15:26
A visionOS RealityView view modifier that handles drag gestures
//
// WindowBarGestureModifier.swift
//
// Created by Drew Olbrich on 10/25/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
//
// 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 / Entity+Opacity.swift
Last active April 5, 2024 13:58
An Entity extension that supports animated changes the opacity of an entity and its descendants
//
// Entity+Opacity.swift
//
// Created by Drew Olbrich on 10/25/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 / SIMD+LookAt.swift
Created November 17, 2023 05:30
SIMD look-at functions
import simd
/// Creates a 4x4 matrix that orients the +Z axis in the direction of `at`, and the
/// +Y axis toward `up`.
func simd_look(at: SIMD3<Float>, up: SIMD3<Float> = SIMD3<Float>(0, 1, 0)) -> simd_float4x4 {
let zAxis = normalize(at)
let xAxis = normalize(cross(up, zAxis))
let yAxis = normalize(cross(zAxis, xAxis))
return simd_float4x4(
@drewolbrich
drewolbrich / Entity+LoadFileAsync.swift
Last active March 11, 2024 20:04
A wrapper around iOS Entity/loadAsync(named:in:) and visionOS Entity(named:in:) async that works on both platforms
//
// Entity+LoadFileAsync.swift
//
// Created by Drew Olbrich on 8/4/23.
//
import Foundation
import RealityKit
import Combine
@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
@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 / Entity+GenerateGroundingShadowComponents.swift
Last active March 6, 2024 15:48
Add GroundingShadowComponent to all model entities in a hierarchy
//
// Entity+GenerateGroundingShadowComponents.swift
//
// Created by Drew Olbrich on 10/18/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