Skip to content

Instantly share code, notes, and snippets.

@Matt54
Matt54 / SphereMeshTextureComparisonView.swift
Created August 10, 2024 23:00
RealityView comparing built-in generateSphere with LowLevelMesh implementation - both having and excluding uv data in vertex attributes
import SwiftUI
import RealityKit
struct SphereMeshTextureComparisonView: View {
let latitudeBands = 128
let longitudeBands = 80
let radius: Float = 0.1
// Metal-related properties
let device: MTLDevice
@Matt54
Matt54 / LightBeamSynthView.swift
Last active August 11, 2024 15:29
RealityView of light beam synth with touch gesture interactions
import AVFoundation
import SwiftUI
import RealityKit
#Preview { LightBeamSynthView() }
struct LightBeamSynthView: View {
@Environment(\.physicalMetrics) var physicalMetrics
@State var outerCylinderEntity: Entity?
@State var innerCylinderEntity: Entity?
@State var touchEntity: Entity?
@Matt54
Matt54 / LaserSynthView.swift
Last active August 8, 2024 17:52
RealityView where a cylinder's detected SpatialEventGesture modulates a signal generator's output
import AVFoundation
import SwiftUI
import RealityKit
struct LaserSynthView: View {
@Environment(\.physicalMetrics) var physicalMetrics
let signalGenerator = SignalGenerator()
@State var outerCylinderEntity: Entity?
@State var innerCylinderEntity: Entity?
@Matt54
Matt54 / FireballCirclesAddBlendView.swift
Created August 6, 2024 02:16
RealityView resembling a fireball spell created from many low opacity spheres swarming around with add blend mode applied
import RealityKit
import SwiftUI
struct FireballCirclesAddBlendView: View {
@State var rootEntity: Entity?
@State var sphereTargets: [Entity: SIMD3<Float>] = [:]
@State private var rotationAngles: SIMD3<Float> = [0, 0, 0]
@State private var modulationTimer: Timer?
@State private var lastRotationUpdateTime = CACurrentMediaTime()
@Matt54
Matt54 / LowLevelMeshNormalsComparisonView.swift
Created August 4, 2024 14:48
RealityView comparing LowLevelMesh spheres with and without surface normal data
import SwiftUI
import RealityKit
struct LowLevelMeshNormalsComparisonView: View {
var body: some View {
RealityView { content in
let sphereWithoutNormals = try! sphereEntity(includeNormals: false)
sphereWithoutNormals.position.x = -0.11
let sphereWithNormals = try! sphereEntity(includeNormals: true)
@Matt54
Matt54 / MetalWavyPlaneView.swift
Created July 31, 2024 04:23
RealityView comparing a wave plane animation of a LowLevelMesh between a pure Swift and a Metal shader implementation
import SwiftUI
import RealityKit
import Metal
struct MetalWavyPlaneView: View {
@State private var phase: Float = 0.0
@State private var mesh: LowLevelMesh?
@State private var timer: Timer?
let resolution = 250
@Matt54
Matt54 / WavyPlaneView.swift
Created July 29, 2024 04:05
RealityView with a plane (modulated by a sine wave) and a point light
import SwiftUI
import RealityKit
struct WavyPlaneView: View {
@State private var phase: Float = 0.0
@State private var mesh: LowLevelMesh?
@State private var timer: Timer?
let resolution = 60
var body: some View {
@Matt54
Matt54 / SpotLightBoxView.swift
Last active July 21, 2024 20:06
RealityKit View showcasing a SpotLightComponent using a rotating cone inside a box with a transparent front face
import RealityKit
import SwiftUI
struct SpotLightBoxView: View {
@State private var rootEntity: Entity?
@State private var timer: Timer?
@State private var childEntityPosition: SIMD3<Float> = [0, 0, 0]
@State private var childEntityTargetPosition: SIMD3<Float> = [0, 0, 0]
@State private var childEntityMoveSpeed: Float = 0.0005
@State private var rotationAngles: SIMD3<Float> = [0, 0, 0]
@ynagatomo
ynagatomo / RealityRendererTest.swift
Last active October 12, 2024 20:57 — forked from arthurschiller/RealityRendererTest.swift
RealityRenderer Test (visionOS)
//
// RealityRendererView.swift
// RealityRendererTest
//
// Created by Arthur Schiller on 11.01.24.
//
// Change Log: by Yasuhito Nagatomo
// - Added ImageBasedLighting, Mar 2, 2024
// - Added Camera a rotation animation, Mar 2, 2024
@drewolbrich
drewolbrich / Entity+MoveAsync.swift
Last active November 6, 2024 00:31
An async version of RealityKit's Entity/move that returns when the animation completes
//
// Entity+MoveAsync.swift
//
// Created by Drew Olbrich on 1/15/24.
// Copyright © 2024 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal