Skip to content

Instantly share code, notes, and snippets.

View Matt54's full-sized avatar

Matt Pfeiffer Matt54

View GitHub Profile
@Matt54
Matt54 / IncrementallyUpdatingMultiPartData.swift
Last active June 30, 2025 15:25
RealityKit Multi-Branch LowLevelMesh with Incremental Growth
import RealityKit
import SwiftUI
struct IncrementallyUpdatingMultiPartData {
var settings: IncrementallyUpdatingMultiPartSettings
// Mesh buffer offsets (set once during initialization)
var vertexOffset: Int = 0
var indexOffset: Int = 0
@Matt54
Matt54 / MultiPartMeshView.swift
Created June 29, 2025 15:37
RealityKit Multi-Part LowLevelMesh with Material Indexing
import RealityKit
import SwiftUI
struct MultiPartMeshView: View {
let radius: Float = 0.25
var body: some View {
RealityView { content in
if let mesh = try? createMesh(),
let resource = try? MeshResource(from: mesh)
@Matt54
Matt54 / BranchSegment.swift
Last active June 28, 2025 16:29
RealityKit Growing/Shrinking Branch using LowLevelMesh
import Foundation
struct BranchSegment {
var startPosition: SIMD3<Float>
var endPosition: SIMD3<Float>
var radius: Float
init(startPosition: SIMD3<Float>, endPosition: SIMD3<Float>, radius: Float) {
self.startPosition = startPosition
self.endPosition = endPosition
@Matt54
Matt54 / MorphingSpherePlaneParams.h
Created June 22, 2025 14:26
RealityKit LowLevelMesh Sphere to Circular Plane Morph with Metal Compute Shader
#ifndef MorphingSpherePlaneParams_h
#define MorphingSpherePlaneParams_h
struct MorphingSpherePlaneParams {
int latitudeBands;
int longitudeBands;
float radius;
float morphAmount;
};
@Matt54
Matt54 / MorphingSpherePlaneParams.h
Last active June 22, 2025 01:04
RealityKit LowLevelMesh Sphere to Rectangular Plane Morph with Metal Compute Shader
#ifndef MorphingSpherePlaneParams_h
#define MorphingSpherePlaneParams_h
struct MorphingSpherePlaneParams {
int latitudeBands;
int longitudeBands;
float radius;
float morphAmount;
};
@Matt54
Matt54 / Branch.swift
Created June 14, 2025 14:46
Procedural tree RealityView with LowLevelMesh
import Foundation
struct Branch {
var segments: [BranchSegment] = []
var dynamicSegment: BranchSegment? // the end of the branch that's currently growing
var completedSegments: Int = 0
var currentGrowthProgress: Float = 0.0
var isActive: Bool = true
var branchId: UUID = UUID()
var parentBranchId: UUID?
@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 18, 2025 12:19
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 22, 2025 12:38
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?