Skip to content

Instantly share code, notes, and snippets.

View ManjitBedi's full-sized avatar
💭
working on some projects using Unity & coding in c#

Manjit Bedi ManjitBedi

💭
working on some projects using Unity & coding in c#
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 November 21, 2025 20:55
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 / 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 / MorphSphere.metal
Last active May 26, 2025 16:41
RealityView - organic, wave-like sphere morphing using LowLevelMesh and Metal
#include <metal_stdlib>
using namespace metal;
struct VertexData {
float3 position;
float3 normal;
float2 uv;
};
struct MorphingSphereParams {
@Matt54
Matt54 / BubbleRealityView.swift
Last active December 21, 2024 01:16
A floating bubble (morphing transparent sphere) RealityView created from a LowLevelMesh
import RealityKit
import SwiftUI
struct BubbleRealityView: View {
@State private var currentEntity: Entity?
@State private var morphFactor: Float = 0.0
@State private var frameDuration: TimeInterval = 0.0
@State private var lastUpdateTime = CACurrentMediaTime()
static let animationFrameDuration: TimeInterval = 1.0 / 120.0
@samsonjs
samsonjs / MovieExporter.swift
Created June 21, 2024 15:15
AVAssetExportSession safety when using structured concurrency in Swift 5 and 6
import AVFoundation
/**
* AVAssetExportSession is initialized with an AVComposition, and that composition and all of its constituent
* components are not sendable. Because `composition` is isolated to the main actor here, the call to the
* non-isolated method `export(to:as:)` sends it across an isolation region and that is unsafe.
*/
@MainActor
class UnsafeMovieExporter {
let composition = AVMutableComposition()