Skip to content

Instantly share code, notes, and snippets.

View Matt54's full-sized avatar

Matt Pfeiffer Matt54

View GitHub Profile
@Matt54
Matt54 / TurkeyClonesAnimationView.swift
Created November 28, 2024 14:49
RealityView with a grid of animating cloned turkey model entities
import SwiftUI
import RealityKit
struct TurkeyClonesAnimationView: View {
let scale: Float = 0.02
let horizontalCount: Int = 4
let horizontalSpacing: Float = 0.0375
let verticalCount: Int = 2
let verticalSpacing: Float = 0.05
@Matt54
Matt54 / GaussianBlurParams.h
Created November 26, 2024 04:15
RealityView with LowLevelTexture and Gaussian Blur (separate compute shader passes)
// Don't forget to include this bridging header
#ifndef GaussianBlurParams_h
#define GaussianBlurParams_h
struct GaussianBlurParams {
int32_t kernelSize;
float intensity;
};
@Matt54
Matt54 / BreathingLeavesView.swift
Last active November 23, 2024 17:40
RealityView breathing leaves view (LowLevelMesh leaf, CGImage texture, fibonacci lattice, rotate + scale)
import RealityKit
import SwiftUI
struct BreathingLeavesView: View {
let rootEntity = Entity()
@State var children = [EntityPositionPair]()
@State private var rotationAngles: SIMD3<Float> = [0, 0, 0]
@State private var modulationTimer: Timer?
@State private var time: Double = 0.0
@State private var lastRotationUpdateTime = CACurrentMediaTime()
@Matt54
Matt54 / FlamesTextAnimationView.swift
Created November 21, 2024 00:15
RealityView with centered and spaced out extruded text that sequentially fades in/out and has flames for it's material texture
import SwiftUI
import RealityKit
struct FlamesTextAnimationView: View {
var textLines: [String] = ["WELCOME", "TO", "APP NAME"]
let commandQueue: MTLCommandQueue
let computePipeline: MTLComputePipelineState
@State private var texture: LowLevelTexture?
let timer = Timer.publish(every: 1.0 / 120.0, on: .main, in: .common).autoconnect()
@State private var time: Float = 0
@Matt54
Matt54 / LowLevelTextureTextView.swift
Created November 20, 2024 04:24
Animated LowLevelTexture extruded text RealityView that according to the text's bounds
import RealityKit
import SwiftUI
struct LowLevelTextureTextView: View {
let commandQueue: MTLCommandQueue
let computePipeline: MTLComputePipelineState
@State private var texture: LowLevelTexture?
let timer = Timer.publish(every: 1.0 / 120.0, on: .main, in: .common).autoconnect()
@State private var time: Float = 0
@Matt54
Matt54 / GameKitManager.swift
Created September 14, 2024 22:33
Trying to figure out the boilerplate for a simple GameKit implementation
import GameKit
import SwiftUI
struct GameTestView: View {
@StateObject private var gameKitManager = GameKitManager()
@State private var timer: Timer?
var body: some View {
VStack {
Text("Score: \(gameKitManager.score)")
@Matt54
Matt54 / TargetPracticeView.swift
Created September 14, 2024 14:28
RealityView where users practice target shooting by detecting finger gun gestures and using ray casting to hit virtual targets
import SwiftUI
import RealityKit
import ARKit
import HandVector
struct TargetPracticeView: View {
@State var jointPositions: [HandSkeleton.JointName: SIMD3<Float>] = [:]
@State var targets: [Target] = []
@State var laserBeamEntity: ModelEntity?
@Matt54
Matt54 / HandTrackingRaycastView.swift
Created September 14, 2024 05:11
RealityView that detects finger gun gestures and uses ray casting for hit detection
import SwiftUI
import RealityKit
import ARKit
import HandVector
struct HandTrackingRaycastView: View {
@State var jointPositions: [HandSkeleton.JointName: SIMD3<Float>] = [:]
@State var sphereEntity: ModelEntity?
@State var laserBeamEntity: ModelEntity?
@State var gunEntity: ModelEntity?
@Matt54
Matt54 / HandTrackingRaycastView.swift
Created September 14, 2024 03:19
RealityView that detects finger gun gestures and uses ray casting to interact with virtual objects.
import SwiftUI
import RealityKit
import ARKit
import HandVector
struct HandTrackingRaycastView: View {
@State var jointPositions: [HandSkeleton.JointName: SIMD3<Float>] = [:]
@State var sphereEntity: ModelEntity?
@State var laserBeamEntity: ModelEntity?
@State var gunEntity: ModelEntity?
@Matt54
Matt54 / HandTrackingRaycastView.swift
Created September 14, 2024 00:41
RealityView with raycasting from the index finger to a sphere, showing a color change on hit
import SwiftUI
import RealityKit
import ARKit
struct HandTrackingRaycastView: View {
@State var jointPositions: [HandSkeleton.JointName: SIMD3<Float>] = [:]
@State var sphereEntity: ModelEntity?
@State var debugCylinderEntity: ModelEntity?
let sphereRadius: Float = 0.1