Skip to content

Instantly share code, notes, and snippets.

View Matt54's full-sized avatar

Matt Pfeiffer Matt54

View GitHub Profile
@Matt54
Matt54 / ModelIOLoader.swift
Last active October 14, 2025 07:33
PLY to RealityKit with Grid-Based Decimation (Example: HD Skeleton Scan)
import Foundation
import ModelIO
import simd
nonisolated func loadMeshWithModelIO(from url: URL) throws -> TriangleMesh {
let asset = MDLAsset(url: url)
guard asset.count > 0 else {
throw NSError(domain: "ModelIO", code: 1, userInfo: [NSLocalizedDescriptionKey: "No objects found in file"])
}
@Matt54
Matt54 / EasingCurve.swift
Created October 2, 2025 04:22
RealityKit SDF Falling Sand Animation (Metal + LowLevelMesh + Marching Cubes)
import Foundation
enum EasingCurve {
case linear
case easeIn(Float)
case easeOut(Float)
case easeInOut(Float)
func apply(_ t: Float) -> Float {
let t = max(0, min(1, t))
@Matt54
Matt54 / ExtrudedTextLowLevelMeshView.swift
Created September 25, 2025 02:50
RealityKit Extruded Text to LowLevelMesh animated by Metal compute shader
import Metal
import RealityKit
import SwiftUI
#Preview { ExtrudedTextLowLevelMeshView() }
struct ExtrudedTextLowLevelMeshView: View {
@State var lowLevelMesh: LowLevelMesh?
@State var originalVerticesBuffer: MTLBuffer?
@State var timer: Timer?
@Matt54
Matt54 / EasingCurve.swift
Last active October 5, 2025 18:27
RealityKit Explode and Assemble SDF Shape (Metal + LowLevelMesh + Marching Cubes)
import Foundation
enum EasingCurve {
case linear
case easeIn(Float)
case easeOut(Float)
case easeInOut(Float)
func apply(_ t: Float) -> Float {
let t = max(0, min(1, t))
@Matt54
Matt54 / MarchingCubesColorBlobParams.h
Last active October 9, 2025 12:19
RealityKit Color-Blending Metaballs (Metal + LowLevelMesh + Marching Cubes)
#ifndef MarchingCubesColorBlobParams_h
#define MarchingCubesColorBlobParams_h
#include <simd/simd.h>
typedef struct {
simd_float3 center;
float radius;
simd_float3 color;
float _pad;
@Matt54
Matt54 / MarchingCubesBlobParams.h
Created August 19, 2025 23:21
RealityKit Marching Cubes Blob (Metal + LowLevelMesh)
#ifndef MarchingCubesBlobParams_h
#define MarchingCubesBlobParams_h
#include <simd/simd.h>
typedef struct {
simd_float3 center;
float radius;
} Sphere;
@Matt54
Matt54 / SDFPrimitives.metal
Created August 13, 2025 03:45
LowLevelMesh shape shifting with Marching Cubes and SDF interpolation
#include <metal_stdlib>
using namespace metal;
#define SDFShapeTypeSphere 0u
#define SDFShapeTypeBox 1u
#define SDFShapeTypeTorus 2u
#define SDFShapeTypeRoundedBox 3u
#define SDFShapeTypeBoxFrame 4u
#define SDFShapeTypeLink 5u
#define SDFShapeTypeOctahedron 6u
@Matt54
Matt54 / MarchingCubesParams.h
Last active September 22, 2025 17:20
Marching Cubes Metaballs in RealityKit (Metal + LowLevelMesh)
#ifndef MarchingCubesParams_h
#define MarchingCubesParams_h
#include <simd/simd.h>
struct MarchingCubesParams {
simd_uint3 cells;
simd_float3 origin;
simd_float3 cellSize;
float isoLevel;
simd_float3 centerA;
@Matt54
Matt54 / BurnFadeParams.h
Created July 22, 2025 00:15
RealityKit burn fade sphere: LowLevelMesh, ShaderGraphMaterial, and compute shader
#ifndef BurnFadeParams_h
#define BurnFadeParams_h
struct BurnFadeParams {
float progress;
float scale;
float hueRotate;
float edgeWidth;
float emberRange;
};
@Matt54
Matt54 / AnimatingTorusSystem.swift
Created July 20, 2025 12:40
RealityKit LowLevelMesh Glowing Torus Spinner
import RealityKit
public struct AnimatingTorusSystem: System {
public init(scene: RealityKit.Scene) {}
public func update(context: SceneUpdateContext) {
let entities = context.entities(matching: Self.query,
updatingSystemWhen: .rendering)
for torus in entities.compactMap({ $0 as? LoopingTorusEntity }) {