Skip to content

Instantly share code, notes, and snippets.

View ynagatomo's full-sized avatar

Yasuhito Nagatomo ynagatomo

View GitHub Profile
@ynagatomo
ynagatomo / RealityRendererTest.swift
Last active March 2, 2024 07:32 — 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
@ynagatomo
ynagatomo / RealityDump.swift
Created January 13, 2024 06:15
A simple function that prints out the structure of RealityKit Entities in visionOS.
//
// RealityDump.swift
//
// Created by Yasuhito Nagatomo on 2024/01/13.
//
import Foundation
import RealityKit
import SwiftUI
@ynagatomo
ynagatomo / ContentView.swift
Created November 25, 2023 06:58
Custom Debug Window in visionOS
//
// ContentView.swift
// DebugWindow
//
// Created by Yasuhito Nagatomo on 2023/11/25.
//
import SwiftUI
import RealityKit
import RealityKitContent
@ynagatomo
ynagatomo / ContentView.swift
Created November 16, 2023 08:30
A sample of Head-up Display Component for visionOS
// ContentView.swift
import SwiftUI
import RealityKit
import RealityKitContent
struct ContentView: View {
@State private var showImmersiveSpace = false
@State private var immersiveSpaceIsShown = false
@ynagatomo
ynagatomo / BillboardComponent.swift
Created November 11, 2023 23:56
A sample BillboardComponent for RealityKit in visionOS
// BillboardComponent.swift
import ARKit
import RealityKit
import SwiftUI
public struct BillboardComponent: Component, Codable {
public init() {}
}
@ynagatomo
ynagatomo / ml-converting.txt
Created December 17, 2022 13:33
Console-output during converting CoreML-Stable-Diffusion models
# Converting Stable Diffusion v2 models to CoreML models, Dec 17,2022
#
# MacBook Air/M1/8GB memory, macOS 13.2 beta, Python 3.8
# apple/ml-stable-diffusion v0.1.0
#
(base) ynaga@YasuhitonoMacBook-Air ~ % conda activate coremlsd2_38
(coremlsd2_38) ynaga@YasuhitonoMacBook-Air ~ % cd Temp
(coremlsd2_38) ynaga@YasuhitonoMacBook-Air Temp % mkdir SD2ModelConvChunked
(coremlsd2_38) ynaga@YasuhitonoMacBook-Air Temp % cd SD2ModelConvChunked
(coremlsd2_38) ynaga@YasuhitonoMacBook-Air SD2ModelConvChunked % git clone https://github.com/apple/ml-stable-diffusion
@ynagatomo
ynagatomo / SD2ContentView.swift
Created December 4, 2022 08:56
An iOS app that generates images using Stable-Diffusion-v2 CoreML models.
//
// ContentView.swift
// coremlsd2test
//
// Created by Yasuhito Nagatomo on 2022/12/03.
//
// A sample code using Apple/ml-stable-diffusion library.
// Preparation:
// 1. convert the PyTorch Stable-Diffusion v2 model to coreml models using Apple's tools.
// 2. import the coreml models into the iOS project.
//
// ContentView.swift
// sfsymbols4sample
//
// Created by Yasuhito Nagatomo on 2022/06/16.
// Updated on 2022/06/17 with the advice of @kingatarthur.
//
import SwiftUI
import simd
// Initializers
simd_quatf()
simd_quatf(vector: simd_float4(0, 0, 0, 1)) // [0, 1, 2]: img, [3]: real
simd_quatf(simd_float3x3(SIMD3<Float>(cos(Float.pi/2), -sin(Float.pi/2), 0), SIMD3<Float>(sin(Float.pi/2), cos(Float.pi/2), 0), SIMD3<Float>(0, 0, 1))) // from 3x3 rotation matrix, which must be orthogonal and have a determinant of 1
simd_float3x3(SIMD3<Float>(cos(Float.pi/2), -sin(Float.pi/2), 0), SIMD3<Float>(sin(Float.pi/2), cos(Float.pi/2), 0), SIMD3<Float>(0, 0, 1)).determinant
simd_quatf(simd_float4x4(SIMD4<Float>(cos(Float.pi/2), -sin(Float.pi/2), 0, 0), SIMD4<Float>(sin(Float.pi/2), cos(Float.pi/2), 0, 0), SIMD4<Float>(0, 0, 1, 0), SIMD4<Float>(0, 0, 0, 1))) // from 4x4 rotation matrix, whose 3x3 part must be orthogonal and have a determinant of 1
simd_quatf(angle: Float.pi/2, axis: SIMD3<Float>(0, 0, -1)) // rotation about an axis
simd_quatf(from: SIMD3<Float>(0, 1, 0), to: SIMD3<Float>(1, 0, 0)) // rotation between two vectors. They should be normalized.
import simd
// Initializers
simd_float2x3()
simd_float2x3(1)
simd_float2x2(diagonal: SIMD2<Float>.one * 2)
simd_float2x3([SIMD3<Float>(1, 2, 3), SIMD3<Float>(4, 5, 6)])
simd_float2x3(SIMD3<Float>(1, 2, 3), SIMD3<Float>(4, 5, 6))
simd_float2x3(columns: (simd_float3.zero, simd_float3.one))
simd_float2x3(rows: [SIMD2<Float>.zero, SIMD2<Float>.one, SIMD2<Float>.zero])