Skip to content

Instantly share code, notes, and snippets.

View Matt54's full-sized avatar

Matt Pfeiffer Matt54

View GitHub Profile
@Matt54
Matt54 / MetalCubeExample.swift
Last active January 6, 2025 17:29
Cube / Sphere RealityView using LowLevelMesh with metal shader
import SwiftUI
import RealityKit
import Metal
struct CubeSphereState {
var size: SIMD3<Float> = [0.3, 0.3, 0.3]
var planeResolution: SIMD2<UInt32> = [16, 16]
var cubeSphereInterpolationRatio: Float = 0.0
}
@Matt54
Matt54 / CubeMeshExample.swift
Last active December 7, 2024 17:20
Cube LowLevelMesh RealityView
import Foundation
import RealityKit
import SwiftUI
struct CubeMeshExample: View {
@State private var rotationAngles: SIMD3<Float> = [0, 0, 0]
@State private var lastRotationUpdateTime = CACurrentMediaTime()
@State private var time: Double = 0.0
@State private var rootEntity: Entity?
@Matt54
Matt54 / ApplePlaneExample.swift
Created December 5, 2024 04:50
CPU and GPU implementation for Apple's LowLevelMesh plane example
import Foundation
import RealityKit
import SwiftUI
struct ApplePlaneExample: View {
var body: some View {
RealityView { content in
// Create a plane mesh.
if let planeMesh = try? PlaneMesh(size: [0.2, 0.2], dimensions: [16, 16]), let mesh = try? MeshResource(from: planeMesh.mesh) {
@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?