Skip to content

Instantly share code, notes, and snippets.

View Matt54's full-sized avatar

Matt Pfeiffer Matt54

View GitHub Profile
@Matt54
Matt54 / CenterExtrudedTextView.swift
Created June 2, 2025 04:43
RealityKit centering extruded text
import RealityKit
import SwiftUI
struct CenterExtrudedTextView: View {
let entity: Entity = try! getEntity()
var body: some View {
RealityView { content in
content.add(entity)
}
@Matt54
Matt54 / PancakeEffectView.swift
Created June 1, 2025 14:58
RealityKit LowLevelMesh pancake effect (smashing z position of vertices)
import SwiftUI
import RealityKit
import Metal
struct PancakeEffectView: View {
@State var entity: ModelEntity?
@State var lowLevelMesh: LowLevelMesh?
@State var originalVerticesBuffer: MTLBuffer?
@State var timer: Timer?
@State var isForward: Bool = true
@Matt54
Matt54 / HeightMapParams.h
Last active June 2, 2025 09:05
RealityKit HeightMap Image to Terrain with LowLevelMesh and LowLevelTexture
#ifndef HeightMapParams_h
#define HeightMapParams_h
struct HeightMapParams {
simd_float2 size;
simd_uint2 dimensions;
};
#endif /* HeightMapParams_h */
@Matt54
Matt54 / MorphModelToSphereView.swift
Last active June 6, 2025 19:51
RealityKit Morph To Sphere with LowLevelMesh and LowLevelTexture
import SwiftUI
import RealityKit
import Metal
struct MorphModelToSphereView: View {
@State var entity: ModelEntity?
@State var lowLevelMesh: LowLevelMesh?
@State var originalVertices: [VertexData] = []
@State var originalTexture: LowLevelTexture?
@State var processedTexture: LowLevelTexture?
@Matt54
Matt54 / CombineAndSplitView.swift
Last active May 10, 2025 18:12
visionOS combine and split window management idea
import SwiftUI
@main
struct CombineAndSplitViewExampleApp: App {
@State var viewStateManager = ViewStateManager()
var body: some Scene {
// Main Window allows us to launch first CombineAndSplitView Window with appropriate ViewWindowID value
// (if we just had CombineAndSplitView open initially, it would be associated with nil)
// There's probably a way to handle the nil case too, but this already covers my needs
@Matt54
Matt54 / CenterSlider.swift
Created March 15, 2025 16:35
SwiftUI Slider with track fill from center
import SwiftUI
#Preview {
@Previewable @State var value: Double = 0.0
VStack {
Text("Value: \(value)")
CenterSliderWithIcons(value: $value)
}
.foregroundStyle(.black)
.padding()
@Matt54
Matt54 / CustomSlider.swift
Created March 11, 2025 23:45
SwiftUI Slider Reskin
import SwiftUI
struct ContentView: View {
@State var sliderValue: Double = 0.5
var body: some View {
CustomSlider(value: $sliderValue)
}
}
struct CustomSlider<V: BinaryFloatingPoint>: View where V.Stride: BinaryFloatingPoint {
@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
Last active June 10, 2025 00:57
RealityKit comparison of Apple's LowLevelMesh plane example on CPU to a Metal GPU implementation
import Foundation
import RealityKit
import SwiftUI
// See: https://developer.apple.com/documentation/realitykit/creating-a-plane-with-low-level-mesh
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) {