Skip to content

Instantly share code, notes, and snippets.

@drewolbrich
drewolbrich / ResizingRestrictionsView.swift
Last active January 24, 2024 15:15
A SwiftUI view that sets UIWindowScene.ResizingRestrictions on its associated UIWindowScene
/// UPDATE: You may want to use this view modifier instead:
/// https://gist.github.com/drewolbrich/90f11b7170267674cbdcb4a0d71ce873
import SwiftUI
/// A view that, when included as a leaf node in a view hierarchy, sets
/// `UIWindowScene.ResizingRestrictions` for the view's `UIWindowScene`.
///
/// Example:
///
@drewolbrich
drewolbrich / View+WindowResizingRestrictions.swift
Last active January 30, 2024 21:49
A view modifier that sets the resizing restrictions for the view's window
// IMPORTANT: The following code doesn't support specifying a window's
// minimum and maximum size when used to constrain a window's aspect ratio.
// Please use this newer view modifier extension instead:
// https://gist.github.com/drewolbrich/03460fc1bb71b9a821fff722f17ec977
//
// View+WindowResizingRestrictions.swift
//
// Created by Drew Olbrich on 11/19/23.
//
@drewolbrich
drewolbrich / WindowBarGestureModifier.swift
Last active October 21, 2024 13:37
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
@drewolbrich
drewolbrich / SceneUpdateContext+EntitiesWhenRendering.swift
Last active March 6, 2024 15:47
A RealityKit SceneUpdateContext extension that wraps entities(matching:updateSystemWhen:) but works on both visionOS and iOS
//
// SceneUpdateContext+EntitiesWhenRendering.swift
//
// Created by Drew Olbrich on 7/27/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 / ModelEntity+ReverseTriangleIndices.swift
Last active August 11, 2024 03:41
A ModelEntity extension that reverses triangle indices
//
// ModelEntity+ReverseTriangleIndices.swift
//
// Created by Drew Olbrich on 12/10/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 / TextureResource+LoadFileAsync.swift
Last active March 6, 2024 15:47
A wrapper around iOS Entity/loadAsync(named:in:) and visionOS Entity(named:in:) async that works on both platforms
//
// TextureResource+LoadFileAsync.swift
//
// Created by Drew Olbrich on 12/24/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 / 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+MoveAsync.swift
Last active February 26, 2025 07:18
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 / ScaledVolumeContentView.swift
Last active April 1, 2025 23:56
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